· 6 years ago · May 03, 2019, 12:22 PM
1#include <a_samp>
2#include <a_mysql>
3#include <foreach>
4#include <zcmd>
5#include <sscanf2>
6
7//==============================================================================
8
9#define MYSQL_HOST "sa-mp.me" // Change this to your MySQL Remote IP or "localhost".
10#define MYSQL_USER "219127" // Change this to your MySQL Database username.
11#define MYSQL_PASS "9J20n&O%fxsS9nMlY" // Change this to your MySQL Database password.
12#define MYSQL_DATABASE "219127" // Change this to your MySQL Database name.
13//==============================================================================
14
15#define COLOR_ERROR (0xDE3838FF)
16#define COLOR_WHITE (0xFFFFFFFF)
17
18//==============================================================================
19
20#define DIALOG_REGISTER (0)
21#define DIALOG_LOGIN (1)
22//==============================================================================
23
24
25
26new MySQL: Database, Corrupt_Check[MAX_PLAYERS];
27
28
29
30enum ENUM_PLAYER_DATA
31{
32 ID,
33 Name[25],
34
35 Password[65],
36 Salt[11],
37
38 PasswordFails,
39
40 Kills,
41 Deaths,
42
43 Score,
44 Cash,
45 Skin,
46
47 Cache: Player_Cache,
48 bool:LoggedIn
49}
50
51new pInfo[MAX_PLAYERS][ENUM_PLAYER_DATA];
52
53//==============================================================================
54
55public OnGameModeInit()
56{
57 new MySQLOpt: option_id = mysql_init_options();
58 mysql_set_option(option_id, AUTO_RECONNECT, true);
59
60 Database = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_DATABASE, option_id);
61
62 if(Database == MYSQL_INVALID_HANDLE || mysql_errno(Database) != 0)
63 {
64 print("MySQL : OFF");
65
66 SendRconCommand("exit");
67 return 1;
68 }
69
70 print("MySQL : ON");
71
72 mysql_tquery(Database, "CREATE TABLE IF NOT EXISTS `PLAYERS` (`ID` int(11) NOT NULL AUTO_INCREMENT,`USERNAME` varchar(24) NOT NULL,`PASSWORD` char(65) NOT NULL,`SALT` char(11) NOT NULL,`SCORE` mediumint(7), `KILLS` mediumint(7), `CASH` mediumint(7) NOT NULL DEFAULT '0',`DEATHS` mediumint(7) NOT NULL DEFAULT '0', PRIMARY KEY (`ID`), UNIQUE KEY `USERNAME` (`USERNAME`))");
73
74 return 1;
75}
76
77public OnGameModeExit()
78{
79 foreach(new i: Player)
80 {
81 if(IsPlayerConnected(i))
82 {
83 OnPlayerDisconnect(i, 1);
84 }
85 }
86
87 mysql_close(Database);
88 return 1;
89}
90
91public OnPlayerConnect(playerid)
92{
93 new DB_Query[115];
94
95 //Resetting player information.
96 pInfo[playerid][Kills] = 0;
97 pInfo[playerid][Deaths] = 0;
98 pInfo[playerid][PasswordFails] = 0;
99 pInfo[playerid][Skin] = 30;
100
101
102 GetPlayerName(playerid, pInfo[playerid][Name], MAX_PLAYER_NAME);
103 Corrupt_Check[playerid]++;
104
105 mysql_format(Database, DB_Query, sizeof(DB_Query), "SELECT * FROM `PLAYERS` WHERE `USERNAME` = '%e' LIMIT 1", pInfo[playerid][Name]);
106 mysql_tquery(Database, DB_Query, "OnPlayerDataCheck", "ii", playerid, Corrupt_Check[playerid]);
107
108 SetPlayerPos(playerid, 1341.320312, -1544.97563, 10037.317382);
109 SetWeather(2);
110 return 1;
111}
112
113public OnPlayerSpawn(playerid) {
114 SetPlayerPos(playerid, 1341.320312, -1544.97563, 10037.317382);
115 SetPlayerHealth(playerid, 75);
116 SetPlayerVirtualWorld(playerid, 0);
117
118 return true;
119}
120
121public OnPlayerCommandPerformed(playerid, cmdtext[], success)
122{
123 if(!success) return SendClientMessage(playerid, COLOR_ERROR,"Commande inconnue, tappez /aide pour voir la liste des commandes.");
124 return 1;
125}
126
127public OnPlayerDisconnect(playerid, reason)
128{
129 Corrupt_Check[playerid]++;
130
131 new DB_Query[256];
132 mysql_format(Database, DB_Query, sizeof(DB_Query), "UPDATE `PLAYERS` SET `SCORE` = %d, `CASH` = %d, `SKIN` = %d `KILLS` = %d, `DEATHS` = %d WHERE `ID` = %d LIMIT 1",
133 pInfo[playerid][Score], pInfo[playerid][Cash], pInfo[playerid][Skin], pInfo[playerid][Kills], pInfo[playerid][Deaths], pInfo[playerid][ID]);
134
135 mysql_tquery(Database, DB_Query);
136
137 if(cache_is_valid(pInfo[playerid][Player_Cache]))
138 {
139 cache_delete(pInfo[playerid][Player_Cache]);
140 pInfo[playerid][Player_Cache] = MYSQL_INVALID_CACHE;
141 }
142
143 pInfo[playerid][LoggedIn] = false;
144 print("OnPlayerDisconnect has been called.");
145 return 1;
146}
147
148public OnPlayerDeath(playerid, killerid, reason)
149{
150 if(killerid != INVALID_PLAYER_ID)
151 {
152 pInfo[killerid][Kills]++;
153 pInfo[playerid][Deaths]++;
154 }
155 return 1;
156}
157
158public OnPlayerRequestSpawn(playerid)
159{
160 if(pInfo[playerid][LoggedIn] == false) return 0;
161 return 1;
162}
163
164public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
165{
166 switch (dialogid)
167 {
168 case DIALOG_LOGIN:
169 {
170 if(!response) return Kick(playerid);
171
172 new Salted_Key[65];
173 SHA256_PassHash(inputtext, pInfo[playerid][Salt], Salted_Key, 65);
174
175 if(strcmp(Salted_Key, pInfo[playerid][Password]) == 0)
176 {
177 cache_set_active(pInfo[playerid][Player_Cache]);
178
179 cache_get_value_int(0, "ID", pInfo[playerid][ID]);
180
181 cache_get_value_int(0, "KILLS", pInfo[playerid][Kills]);
182 cache_get_value_int(0, "DEATHS", pInfo[playerid][Deaths]);
183
184 cache_get_value_int(0, "SCORE", pInfo[playerid][Score]);
185 cache_get_value_int(0, "CASH", pInfo[playerid][Cash]);
186 cache_get_value_int(0, "SKIN", pInfo[playerid][Skin]);
187
188
189 SetPlayerScore(playerid, pInfo[playerid][Score]);
190
191 SetPlayerSkin(playerid, pInfo[playerid][Skin]);
192
193
194 ResetPlayerMoney(playerid);
195 GivePlayerMoney(playerid, pInfo[playerid][Cash]);
196
197
198 cache_delete(pInfo[playerid][Player_Cache]);
199 pInfo[playerid][Player_Cache] = MYSQL_INVALID_CACHE;
200
201 pInfo[playerid][LoggedIn] = true;
202 SendClientMessage(playerid, COLOR_WHITE, "{ffffAA}[Serveur]:{ffffff} Tu viens de te connecter avec succès !");
203 SendClientMessage(playerid, COLOR_WHITE, "Bienvenue sur mon {ffffAA}Gamemode{ffffff} ! ");
204 SendClientMessage( playerid, COLOR_WHITE, "Si tu as besoin d'aide n'hésite pas à contacter un membre de {ffffAA}l'équipe administrative{ffffff} !" );
205 SendClientMessageToAll(-1, "{ffffAA}[Serveur]:{ffffff} Un nouveau joueur vient de se connecter !");
206
207 }
208 else
209 {
210 new String[150];
211
212 pInfo[playerid][PasswordFails] += 1;
213 printf("%s n'a pas réussi à se connecter. (%d)", pInfo[playerid][Name], pInfo[playerid][PasswordFails]);
214
215 if (pInfo[playerid][PasswordFails] >= 3)
216 {
217 format(String, sizeof(String), "%s has a été exclu du serveur, motif : {FF0000}(%d/3) essaies.", pInfo[playerid][Name], pInfo[playerid][PasswordFails]);
218 SendClientMessageToAll(0x969696FF, String);
219 Kick(playerid);
220 }
221 else
222 {
223 format(String, sizeof(String), "Wrong password, you have %d out of 3 tries.", pInfo[playerid][PasswordFails]);
224 SendClientMessage(playerid, 0xFF0000FF, String);
225
226 format(String, sizeof(String), "Bon retour, %s.\n\nVotre compte a été trouvé dans notre base de donnée.\n\
227 Tappez votre mot de passe, afin d'acceder au serveur.\n\n", pInfo[playerid][Name]);
228 ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login System", String, "Login", "Leave");
229 }
230 }
231 }
232 case DIALOG_REGISTER:
233 {
234 if(!response) return Kick(playerid);
235
236 if(strlen(inputtext) <= 5 || strlen(inputtext) > 60)
237 {
238 // If the password length is less than or equal to 5 and more than 60
239 // It repeats the process and shows error message as seen below.
240
241 SendClientMessage(playerid, 0x969696FF, "Invalid password length, should be 5 - 60.");
242
243 new String[150];
244
245 format(String, sizeof(String), "{FFFFFF}Bienvenue %s.\n\n{0099FF}Ce compte n'est pas inscrit.\n\
246 {0099FF}Veuillez saisir votre mot de passe ci-dessous pour continuer.\n\n", pInfo[playerid][Name]);
247 ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Registration System", String, "Register", "Leave");
248 }
249 else
250 {
251
252 // Salting the player's password using SHA256 for a better security.
253
254 for (new i = 0; i < 10; i++)
255 {
256 pInfo[playerid][Salt][i] = random(79) + 47;
257 }
258
259 pInfo[playerid][Salt][10] = 0;
260 SHA256_PassHash(inputtext, pInfo[playerid][Salt], pInfo[playerid][Password], 65);
261
262 new DB_Query[225];
263
264 // Storing player's information if everything goes right.
265 mysql_format(Database, DB_Query, sizeof(DB_Query), "INSERT INTO `PLAYERS` (`USERNAME`, `PASSWORD`, `SALT`, `SCORE`, `KILLS`, `CASH`, `SKIN`,`DEATHS`)\
266 VALUES ('%e', '%s', '%e', '20', '0', '0', '0')", pInfo[playerid][Name], pInfo[playerid][Password], pInfo[playerid][Salt]);
267 mysql_tquery(Database, DB_Query, "OnPlayerRegister", "d", playerid);
268 }
269 }
270 }
271 return 1;
272}
273
274forward public OnPlayerDataCheck(playerid, corrupt_check);
275public OnPlayerDataCheck(playerid, corrupt_check)
276{
277 if (corrupt_check != Corrupt_Check[playerid]) return Kick(playerid);
278
279 new String[150];
280
281 if(cache_num_rows() > 0)
282 {
283
284 cache_get_value(0, "PASSWORD", pInfo[playerid][Password], 65);
285 cache_get_value(0, "SALT", pInfo[playerid][Salt], 11);
286
287 pInfo[playerid][Player_Cache] = cache_save();
288
289 format(String, sizeof(String), "Bon retour, %s.\n\n Votre compte a été trouvé dans notre base de donnée.\n\
290 Veuillez saisir votre mot de passe ci-dessous pour continuer.\n\n", pInfo[playerid][Name]);
291 ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login System", String, "Login", "Leave");
292 }
293 else
294 {
295 format(String, sizeof(String), "Bienvenue à toi %s !\n\n Ce compte n'est pas enregistré.\n\
296 Veuillez saisir votre mot de passe ci-dessous pour continuer.\n\n", pInfo[playerid][Name]);
297 ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Registration System", String, "Register", "Leave");
298 }
299 return 1;
300}
301
302forward public OnPlayerRegister(playerid);
303public OnPlayerRegister(playerid)
304{
305 SendClientMessage( playerid, COLOR_WHITE, "Si tu as besoin d'aide n'hésite pas à contacter un membre de {ffffAA}l'équipe administrative{ffffff} !" );
306 SendClientMessageToAll(-1, "{ffffAA}[Serveur]:{ffffff} Un nouveau joueur vient de se connecter !");
307 pInfo[playerid][LoggedIn] = true;
308 return 1;
309}
310
311CMD:aide(playerid, params[])
312 {
313 SendClientMessage(playerid, COLOR_WHITE, "{ffffAA}[Commande joueurs] :{ffffff} /combat | /pm");
314 SendClientMessage(playerid, COLOR_WHITE, "{ffffAA}[Commande développement] :{ffffff} /setskin | /setweather | /sethp | /veh | /setmoney | /rename");
315 SendClientMessage(playerid, COLOR_WHITE, "{ffffAA}[Commande modération] :{ffffff} /kick | /goto | /setvw");
316
317 return true;
318 }
319
320CMD:getpos(playerid, params[]) {
321
322 new
323 Float:x,
324 Float:y,
325 Float:z;
326
327 GetPlayerPos(playerid, x, y, z);
328
329 new
330 fmat[64];
331
332 format(fmat, sizeof(fmat), "%f, %f, %f", x, y, z);
333
334 SendClientMessage(playerid, -1, fmat);
335
336 return true;
337}
338
339CMD:combat(playerid, params[]) {
340 switch(strval(params)) {
341 case 1: {
342 SetPlayerFightingStyle (playerid, FIGHT_STYLE_NORMAL);
343 SendClientMessage(playerid, COLOR_WHITE, "{ffffAA}[Serveur]:{ffffff}Vous avez changez de style de combat {ffffAA}(Poings){ffffff} avec succès.");
344 }
345 case 2: {
346 SetPlayerFightingStyle (playerid, FIGHT_STYLE_BOXING);
347 SendClientMessage(playerid, COLOR_WHITE, "{ffffAA}[Serveur]:{ffffff} Vous avez changez de style de combat {ffffAA}(Boxe){ffffff} avec succès. ");
348
349 }
350 case 3: {
351 SetPlayerFightingStyle (playerid, FIGHT_STYLE_GRABKICK);
352 SendClientMessage(playerid, COLOR_WHITE, "{ffffAA}[Serveur]:{ffffff} Vous avez changez de style de combat {ffffAA}(GrabKick){ffffff} avec succès.");
353
354 }
355 case 4: {
356 SetPlayerFightingStyle (playerid, FIGHT_STYLE_KUNGFU);
357 SendClientMessage(playerid, COLOR_WHITE, "{ffffAA}[Serveur]:{ffffff} Vous avez changez de style de combat {ffffAA}(Kungfu){ffffff} avec succès.");
358
359 }
360 default: SendClientMessage(playerid, COLOR_WHITE, "{ffffAA}[Serveur]:{ffffff} /combat [1-4]");
361 }
362
363 return true;
364}
365
366 CMD:kick(playerid, params[]) {
367 new
368 id;
369
370 if(sscanf(params, "u", id)) return SendClientMessage(playerid, COLOR_WHITE, "{ffffAA}[Admin]:{ffffff} /kick [PlayerID]");
371
372 Kick(id);
373
374 return true;
375}
376
377
378CMD:nitro(playerid, params[])
379{
380 AddVehicleComponent(GetPlayerVehicleID(playerid), 1010);
381 SendClientMessage(playerid, COLOR_WHITE,"{ffffAA}[Admin]:{ffffff} Vous avez ajouté du nitro à votre véhicule !");
382 return true;
383}
384
385CMD:slap(playerid,params[])
386{
387 new
388
389 id,
390 x,
391 y,
392 z,
393 string[128];
394 if(sscanf(params,"i", id)) return SendClientMessage(playerid, -1, "{ffffAA}[Serveur]:{ffffff} /slap [PlayerID]");
395 if(!IsPlayerConnected(id)) return SendClientMessage(playerid, COLOR_ERROR, "Ce joueur est inexistant ou n'est pas connecté !");
396 GetPlayerPos(id, Float:x, Float:y, Float:z);
397 SetPlayerPos(id, Float:x, Float:y, Float:z + 10.0);
398 SendClientMessage(playerid, COLOR_WHITE, "{ffffAA}[Serveur]:{ffffff} Vous venez de slap ce joueur.");
399 format(string, sizeof(string), "{ffffAA}[Serveur]:{ffffff} Vous avez été slap par un membre de l'équipe.", id);
400 SendClientMessage(id, COLOR_WHITE, string);
401
402 return true;
403}
404
405CMD:setskin(playerid,params[])
406{
407 new targetid, skinid, string[128];
408 if(sscanf(params,"ui",targetid, skinid)) return SendClientMessage(playerid,COLOR_WHITE,"{ffffAA}[Serveur]:{ffffff} /setskin [PlayerID] [Skin]");
409 else if(targetid == INVALID_PLAYER_ID) return SendClientMessage(playerid,COLOR_ERROR,"Ce jouer n'est pas en connecté.");
410 {
411 SetPlayerSkin(targetid, skinid);
412 format(string, sizeof(string), "{ffffAA}[Admin]:{ffffff} Votre skin a été remplacé par le skin {ffffAA}%i{ffffff}.", skinid);
413 SendClientMessage(targetid, COLOR_WHITE, string);
414 }
415 return 1;
416}
417
418
419
420CMD:setmoney(playerid, params[])
421{
422 new
423
424 id,
425 dollars,
426 string[128];
427
428 if(sscanf(params,"ui", id, dollars)) return SendClientMessage(playerid, -1, "{ffffAA}[Serveur]:{ffffff} /setmoney [PlayerID] [Money]");
429 if(!IsPlayerConnected(id)) return SendClientMessage(playerid, COLOR_ERROR, "Ce joueur est inexistant ou n'est pas connecté !");
430 GivePlayerMoney(id, dollars);
431 format(string, sizeof(string), "{ffffAA}[Serveur]:{ffffff} Vous avez reçu {ffffAA}%d${ffffff}.", dollars);
432 SendClientMessage(id, COLOR_WHITE, string);
433 format(string, sizeof(string), "{ffffAA}[Serveur]:{ffffff} Vous venez de donner {ffffAA}%d${ffffff} Ã ce joueur.", dollars);
434 SendClientMessage(playerid, COLOR_WHITE, string);
435 return true;
436}
437
438CMD:setweather(playerid, params[])
439{
440 if ( isnull ( params ) ) return SendClientMessage( playerid, COLOR_WHITE, "{ffffAA}[Admin]:{ffffff} /setweather [WeatherID]");
441 SetWeather( strval ( params ) );
442 return true;
443}
444
445CMD:pm( playerid, params[ ] )
446{
447
448 new
449 iTarget,
450 szMsg[ 100 ];
451
452 if ( sscanf( params, "rs[100]", iTarget, szMsg ) )
453 {
454 return SendClientMessage( playerid, COLOR_WHITE, "{ffffAA}[Serveur]:{ffffff} /pm [PlayerID] [Message]" );
455
456 }
457
458 if ( iTarget == INVALID_PLAYER_ID )
459 {
460 return SendClientMessage( playerid, COLOR_ERROR, "Ce joueur est inexistant ou n'est pas connecté." );
461
462 }
463
464 new
465 szStr[ 128 ];
466
467 new
468 pName[ MAX_PLAYER_NAME ],
469 tName[ MAX_PLAYER_NAME ];
470
471 GetPlayerName( playerid, pName, MAX_PLAYER_NAME );
472
473 GetPlayerName( iTarget, tName, MAX_PLAYER_NAME );
474
475 format( szStr, sizeof ( szStr ), "{ffffAA}[PM reçu de %s]:{ffffff} %s", pName, szMsg );
476
477 SendClientMessage( iTarget, COLOR_WHITE, szStr );
478
479 format( szStr, sizeof ( szStr ), "{ffffAA}[PM envoyé à %s]:{ffffff} %s", tName, szMsg );
480
481 SendClientMessage( playerid, COLOR_WHITE, szStr );
482
483 return true;
484}
485
486CMD:rename(playerid, params[])
487{
488 new id, nom[MAX_PLAYER_NAME], string[128];
489 if(sscanf(params,"P< >us[25]", id, nom)) return SendClientMessage(playerid, -1, "{ffffAA}[Serveur]:{ffffff} /rename [PlayerID] [Pseudo]");
490 if(!IsPlayerConnected(id)) return SendClientMessage(playerid, COLOR_ERROR, "Ce joueur est inexistant ou n'est pas connecté !");
491 SetPlayerName(id, nom);
492 format(string, sizeof(string), "{ffffAA}[Serveur]:{ffffff} Votre nouveau pseudo est désormais :{ffffAA} %s{ffffff}.", nom);
493 SendClientMessage(id, COLOR_WHITE, string);
494 return true;
495}
496
497CMD:hidetags(playerid, params[])
498 {
499 for(new i = 0; i < MAX_PLAYERS; i++)
500 {
501 ShowPlayerNameTagForPlayer(playerid, i, false);
502 SendClientMessage(playerid, COLOR_WHITE, "{ffffAA}[Serveur]:{ffffff} Vous ne voyez désormais plus les nametags des joueurs.");
503 }
504
505
506 return 1;
507}
508
509CMD:showtags(playerid, params[])
510 {
511 for(new i = 0; i < MAX_PLAYERS; i++)
512 {
513 ShowPlayerNameTagForPlayer(playerid, i, true);
514 }
515 SendClientMessage(playerid, COLOR_WHITE, "{ffffAA}[Serveur]:{ffffff} Vous voyez désormais les nametags des joueurs.");
516 return 1;
517 }
518
519CMD:gethere(playerid, params[])
520{
521 new
522
523 id,
524 x,
525 y,
526 z,
527 string[128];
528 if(sscanf(params,"i",id)) return SendClientMessage(playerid, -1, "{ffffAA}[Serveur]:{ffffff} /gethere [PlayerID]");
529 if(!IsPlayerConnected(id)) return SendClientMessage(playerid, COLOR_ERROR, "Ce joueur est inexistant ou n'est pas connecté !");
530 GetPlayerPos(playerid, Float:x, Float:y, Float:z);
531 SetPlayerPos(id, Float:x+2, Float:y, Float:z);
532 format(string, sizeof(string), "{ffffAA}[Serveur]:{ffffff} Un membre de l'équipe vient de vous téléporter à lui.", id);
533 SendClientMessage(id, COLOR_WHITE, string);
534 return true;
535 }
536
537 CMD:goto(playerid, params[])
538{
539 new
540
541 id,
542 x,
543 y,
544 z,
545 string[128];
546 if(sscanf(params,"i",id)) return SendClientMessage(playerid, -1, "{ffffAA}[Serveur]:{ffffff} /goto [PlayerID]");
547 if(!IsPlayerConnected(id)) return SendClientMessage(playerid, COLOR_ERROR, "Ce joueur est inexistant ou n'est pas connecté !");
548 GetPlayerPos(id, Float:x, Float:y, Float:z);
549 SetPlayerPos(playerid, Float:x+2, Float:y, Float:z);
550 format(string, sizeof(string), "{ffffAA}[Serveur]:{ffffff} Un membre de l'équipe vient de se téléporter à toi.", id);
551 SendClientMessage(id, COLOR_WHITE, string);
552 return true;
553 }
554
555CMD:suicide(playerid, params[])
556{
557 SetPlayerHealth(playerid, 0.0);
558 SendClientMessage(playerid, COLOR_WHITE, "{ffffAA}[Serveur]:{ffffff} Vous avez décidez de vous suicidez.");
559 return 1;
560}