· 8 years ago · Feb 24, 2018, 09:58 AM
1#include <a_samp>
2#include <a_mysql>
3#include <foreach>
4#include <zcmd>
5
6
7#define MYSQL_HOST "s1.justhost.lt"
8#define MYSQL_USER "s394"
9#define MYSQL_PASS "justhost_XB4wdH"
10#define MYSQL_DATABASE "s394"
11
12
13#define DIALOG_REGISTRACIJA (0)
14#define DIALOG_PRISIJUNGIMAS (1)
15
16
17main()
18{
19}
20
21new MySQL: Duomenubaze, Corrupt_Check[MAX_PLAYERS];
22
23
24
25//==============================================================================
26
27enum ENUM_ZAIDEJO_DUOMENYS
28{
29 ID,
30 Vardas[25],
31
32 Slaptazodis[65],
33 Slaptazodiokodas[11],
34
35 Neteisingasslaptazodis,
36
37 Nuzudimai,
38 Mirimai,
39
40 Patirtis,
41 Pinigai,
42
43 Cache: Player_Cache,
44 bool:Prisijunges
45}
46
47new pInfo[MAX_PLAYERS][ENUM_ZAIDEJO_DUOMENYS];
48
49//==============================================================================
50
51public OnGameModeInit()
52{
53 new MySQLOpt: option_id = mysql_init_options();
54 mysql_set_option(option_id, AUTO_RECONNECT, true);
55
56 Duomenubaze = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_DATABASE, option_id);
57
58 if(Duomenubaze == MYSQL_INVALID_HANDLE || mysql_errno(Duomenubaze) != 0)
59 {
60 print("[ x ] - MySQL neprisijungÄ—!");
61
62 SendRconCommand("exit");
63 return 1;
64 }
65
66 print("[ ! ] - MySQL prisijungÄ—!");
67
68 //sukuriam sql failÄ…
69
70 mysql_tquery(Duomenubaze, "CREATE TABLE IF NOT EXISTS `VARTOTOJAI` (`ID` int(11) NOT NULL AUTO_INCREMENT,`VARDAS` varchar(24) NOT NULL,`SLAPTAZODIS` char(65) NOT NULL,`SLAPTAZODIOKODAS` char(11) NOT NULL,`PATIRTIS` mediumint(7), `NUZUDIMAI` mediumint(7), `PINIGAI` mediumint(7) NOT NULL DEFAULT '0',`MIRIMAI` mediumint(7) NOT NULL DEFAULT '0', PRIMARY KEY (`ID`), UNIQUE KEY `VARDAS` (`VARDAS`))");
71
72 return 1;
73}
74
75public OnGameModeExit()
76{
77 foreach(new i: Player)
78 {
79 if(IsPlayerConnected(i))
80 {
81 OnPlayerDisconnect(i, 1);
82 }
83 }
84
85 mysql_close(Duomenubaze);
86 return 1;
87}
88
89public OnPlayerConnect(playerid)
90{
91 mysql_log();
92 new DB_Query[115];
93
94 //Nunulinam žaidėjo informacija.
95 pInfo[playerid][Nuzudimai] = 0;
96 pInfo[playerid][Mirimai] = 0;
97 pInfo[playerid][Neteisingasslaptazodis] = 0;
98
99 GetPlayerName(playerid, pInfo[playerid][Vardas], MAX_PLAYER_NAME);
100 Corrupt_Check[playerid]++;
101
102 mysql_format(Duomenubaze, DB_Query, sizeof(DB_Query), "SELECT * FROM `VARTOTOJAI` WHERE `VARDAS` = '%e' LIMIT 1", pInfo[playerid][Vardas]);
103 mysql_tquery(Duomenubaze, DB_Query, "OnPlayerDataCheckį", "ii", playerid, Corrupt_Check[playerid]);
104
105
106 return 1;
107}
108
109public OnPlayerDisconnect(playerid, reason)
110{
111 Corrupt_Check[playerid]++;
112
113 new DB_Query[256];
114 mysql_format(Duomenubaze, DB_Query, sizeof(DB_Query), "UPDATE `VARTOTOJAI` SET `PATIRTIS` = %d, `PINIGAI` = %d, `NUZUDIMAI` = %d, `MIRIMAI` = %d WHERE `ID` = %d LIMIT 1",
115 pInfo[playerid][Patirtis], pInfo[playerid][Pinigai], pInfo[playerid][Nuzudimai], pInfo[playerid][Mirimai], pInfo[playerid][ID]);
116
117 mysql_tquery(Duomenubaze, DB_Query);
118
119 if(cache_is_valid(pInfo[playerid][Player_Cache]))
120 {
121 cache_delete(pInfo[playerid][Player_Cache]);
122 pInfo[playerid][Player_Cache] = MYSQL_INVALID_CACHE;
123 }
124
125 pInfo[playerid][Prisijunges] = false;
126 print("[ ! ] - OnPlayerDisconnect Callback buvo iškviestas.");
127 return 1;
128}
129
130public OnPlayerDeath(playerid, killerid, reason)
131{
132 if(killerid != INVALID_PLAYER_ID)
133 {
134
135 pInfo[killerid][Nuzudimai]++;
136 pInfo[playerid][Mirimai]++;
137 }
138 return 1;
139}
140
141public OnPlayerRequestSpawn(playerid)
142{
143 if(pInfo[playerid][Prisijunges] == false) return 0;
144 return 1;
145}
146
147public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
148{
149 switch (dialogid)
150 {
151 case DIALOG_PRISIJUNGIMAS:
152 {
153 if(!response) return Kick(playerid);
154
155 new Salted_Key[65];
156 SHA256_PassHash(inputtext, pInfo[playerid][Slaptazodiokodas], Salted_Key, 65);
157
158 if(strcmp(Salted_Key, pInfo[playerid][Slaptazodis]) == 0)
159 {
160
161 cache_set_active(pInfo[playerid][Player_Cache]);
162
163 // Okay, we are retrieving the information now..
164 cache_get_value_int(0, "ID", pInfo[playerid][ID]);
165
166 cache_get_value_int(0, "NUZUDIMAI", pInfo[playerid][Nuzudimai]);
167 cache_get_value_int(0, "MIRIMAI", pInfo[playerid][Mirimai]);
168
169 cache_get_value_int(0, "PATIRTIS", pInfo[playerid][Patirtis]);
170 cache_get_value_int(0, "PINIGAI", pInfo[playerid][Pinigai]);
171
172 SetPlayerScore(playerid, pInfo[playerid][Patirtis]);
173
174 ResetPlayerMoney(playerid);
175 GivePlayerMoney(playerid, pInfo[playerid][Pinigai]);
176
177 cache_delete(pInfo[playerid][Player_Cache]);
178 pInfo[playerid][Player_Cache] = MYSQL_INVALID_CACHE;
179
180 pInfo[playerid][Prisijunges] = true;
181 SendClientMessage(playerid, 0x00FF00FF, "SÄ—kmingai prisijungÄ—te!");
182 }
183 else
184 {
185 new String[150];
186
187 pInfo[playerid][Neteisingasslaptazodis] += 1;
188 printf("%s neteisingas įvestas slaptažodis liko: (%d)", pInfo[playerid][Vardas], pInfo[playerid][Neteisingasslaptazodis]);
189 // Printing the message that someone has failed to login to his account.
190
191 if (pInfo[playerid][Neteisingasslaptazodis] >= 3) // If the fails exceeded the limit we kick the player.
192 {
193 format(String, sizeof(String), "%s buvo išmestas, ne suvedė: {FF0000}(%d/3) kartus neteisingą slaptažodį.", pInfo[playerid][Vardas], pInfo[playerid][Neteisingasslaptazodis]);
194 SendClientMessageToAll(0x969696FF, String);
195 Kick(playerid);
196 }
197 else
198 {
199 // If the player didn't exceed the limits we send him a message that the password is wrong.
200 format(String, sizeof(String), "Neteisingas slaptažodis, turite %d/3 bandymus..", pInfo[playerid][Neteisingasslaptazodis]);
201 SendClientMessage(playerid, 0xFF0000FF, String);
202
203 format(String, sizeof(String), "{FFFFFF}Sveikas sugrįžęs, %s.\n\n{0099FF}Šis vartotojas jau registruotas.\n\
204 {0099FF}Prašome įrašyti savo slaptažodį.\n\n", pInfo[playerid][Vardas]);
205 ShowPlayerDialog(playerid, DIALOG_PRISIJUNGIMAS, DIALOG_STYLE_PASSWORD, "PRISIJUNGIMAS", String, "Prisijungti", "Išeiti");
206 }
207 }
208 }
209 case DIALOG_REGISTRACIJA:
210 {
211 if(!response) return Kick(playerid);
212
213 if(strlen(inputtext) <= 5 || strlen(inputtext) > 60)
214 {
215
216
217 SendClientMessage(playerid, 0x969696FF, "Slaptazodis turi sudaryti nuo 5 - 60 simbolių");
218
219 new String[190];
220
221 format(String, sizeof(String), "{FFFFFF}Sveikas %s.\n\n{0099FF}Jūs dar nesate užsiregistravęs.\n\
222 {0099FF}prašome įvesti savo sugalvotą slaptažodį.\n\n", pInfo[playerid][Vardas]);
223 ShowPlayerDialog(playerid, DIALOG_REGISTRACIJA, DIALOG_STYLE_PASSWORD, "REGISTRACIJA", String, "Registruois", "Išeiti");
224 }
225 else
226 {
227
228 // užkoduojam slaptažodį
229
230 for (new i = 0; i < 10; i++)
231 {
232 pInfo[playerid][Slaptazodiokodas][i] = random(79) + 47;
233 }
234
235 pInfo[playerid][Slaptazodiokodas][10] = 0;
236 SHA256_PassHash(inputtext, pInfo[playerid][Slaptazodiokodas], pInfo[playerid][Slaptazodis], 65);
237
238 new DB_Query[256];
239
240 // Storing player's information if everything goes right.
241 mysql_format(Duomenubaze, DB_Query, sizeof(DB_Query), "INSERT INTO `VARTOTOJAI` (`VARDAS`, `SLAPTAZODIS`, `SLAPTAZODIOKODAS`, `PATIRTIS`, `NUZUDIMAI`, `PINIGAI`, `MIRIMAI`)\
242 VALUES ('%e', '%s', '%e', '20', '0', '0', '0')", pInfo[playerid][Vardas], pInfo[playerid][Slaptazodis], pInfo[playerid][Slaptazodiokodas]);
243 mysql_tquery(Duomenubaze, DB_Query, "OnPlayerRegister", "d", playerid);
244 }
245 }
246 }
247 return 1;
248}
249
250forward public OnPlayerDataCheck(playerid, corrupt_check);
251public OnPlayerDataCheck(playerid, corrupt_check)
252{
253 if (corrupt_check != Corrupt_Check[playerid]) return Kick(playerid);
254
255 new String[150];
256
257 if(cache_num_rows() > 0)
258 {
259
260 cache_get_value(0, "SLAPTAZODIS", pInfo[playerid][Slaptazodis], 65);
261 cache_get_value(0, "SLAPTAZODIOKODAS", pInfo[playerid][Slaptazodiokodas], 11);
262
263 pInfo[playerid][Player_Cache] = cache_save();
264//
265 format(String, sizeof(String), "{FFFFFF}Sveikas sugrįžęs, %s.\n\n{0099FF}Šis vartotojas jau registruotas.\n\
266 {0099FF}Prašome įrašyti savo slaptažodį.\n\n", pInfo[playerid][Vardas]);
267 ShowPlayerDialog(playerid, DIALOG_PRISIJUNGIMAS, DIALOG_STYLE_PASSWORD, "PRISIJUNGIMAS", String, "Prisijungti", "Išeiti");
268
269 }
270 else
271 {
272 format(String, sizeof(String), "{FFFFFF}Sveikas %s.\n\n{0099FF}Jūs dar nesate užsiregistravęs.\n\
273 {0099FF}Įveskite savo sugalvota slaptažodį, kad galėtumėte žaisti.\n\n", pInfo[playerid][Vardas]);
274 ShowPlayerDialog(playerid, DIALOG_REGISTRACIJA, DIALOG_STYLE_PASSWORD, "REGISTRACIJA", String, "Registruotis", "Išeiti");
275 }
276 return 1;
277}
278
279forward public OnPlayerRegister(playerid);
280public OnPlayerRegister(playerid)
281{
282 SendClientMessage(playerid, 0x00FF00FF, "Sėkmingai užsiregistravote ir prisijungėte!");
283 pInfo[playerid][Prisijunges] = true;
284 return 1;
285}
286/*
287forward KraunamZaideja(playerid);
288public KraunamZaideja(playerid) {
289 new Float:Pos[3], Patirtis;
290
291 cache_get_value_float (0, "PosX", Pos[0]);
292 cache_get_value_float (0, "PosY", Pos[1]);
293 cache_get_value_float (0, "PosZ", Pos[2]);
294
295 cache_get_value_float (0, "PINIGAI", pInfo[playerid][Pinigai]);
296 //cache_get_value_float (0, "drink", pData[playerid][drink]);
297 //cache_get_value_float (0, "hunger", pData[playerid][hunger]);
298
299 cache_get_value_int (0, "APRANGA", pInfo[playerid][Apranga]);
300 cache_get_value_int (0, "LYTIS", pInfo[playerid][Lytis]);
301 cache_get_value_int (0, "PATIRTIS", Patirtis);
302
303 // cache_get_value_bool (0, "gps", pData[playerid][gps]);
304
305 SetPlayerPos (playerid, Pos[0], Pos[1], Pos[2]);
306 SetPlayerSkin (playerid, pInfo[playerid][Apranga]);
307 SetPlayerScore (playerid, Patiris);
308
309 return 1;
310}*/