· 7 years ago · Jan 23, 2019, 11:14 AM
1#include <a_samp>
2// change MAX_PLAYERS to the amount of players (slots) you want
3// It is by default 1000 (as of 0.3.7 version)
4#undef MAX_PLAYERS
5#define MAX_PLAYERS 50
6//----------
7// INCLUDE
8#include <a_mysql>
9#include <zcmd>
10
11
12// Define
13// stili dialogo
14#define d_input DIALOG_STYLE_INPUT
15#define d_list DIALOG_STYLE_LIST
16
17// Configurazione MySQL
18#define MYSQL_HOST "127.0.0.1"
19#define MYSQL_USER "root"
20#define MYSQL_PASSWORD "Pass123!"
21#define MYSQL_DATABASE "dbrp"
22
23//-------------
24// info server
25#define emailserver "asd@gmail.com"
26#define nomeserver "server bello"
27
28
29// domande di sicurezza
30// per modificare la password con il comando /cambia -> password
31#define MAX_SECURITY_QUESTION_SIZE 128
32new const SECURITY_QUESTIONS[][MAX_SECURITY_QUESTION_SIZE] =
33{
34 "What was your childhood nickname?",
35 "What is the name of your favorite childhood friend?",
36 "In what city or town did your mother and father meet?",
37 "What is the middle name of your oldest child?",
38 "What is your favorite team?",
39 "What is your favorite movie?",
40 "What is the first name of the boy or girl that you first kissed?",
41 "What was the make and model of your first car?",
42 "What was the name of the hospital where you were born?",
43 "Who is your childhood sports hero?",
44 "In what town was your first job?",
45 "What was the name of the company where you had your first job?",
46 "What school did you attend for sixth grade?",
47 "What was the last name of your third grade teacher?"
48};
49
50// colori
51// system color
52#define COLOR_SYSTEM_ERROR 0xAA3333AA
53#define COLOR_SYSTEM_TITLE 0xFFFFFFAA
54#define COLOR_SYSTEM_TEXT 0xFFFFFFAA
55#define COLOR_SYSTEM_SUCCESS 0x33AA33AA
56#define COLOR_SYSTEM_INFO 0xAFAFAFAA
57/*
58#define COLOR_GREY 0xAFAFAFAA
59#define COLOR_GREEN 0x33AA33AA
60#define COLOR_RED 0xAA3333AA
61#define COLOR_YELLOW 0xFFFF00AA
62#define COLOR_WHITE 0xFFFFFFAA
63#define COLOR_BLUE 0x0000BBAA
64#define COLOR_LIGHTBLUE 0x33CCFFAA
65#define COLOR_ORANGE 0xFF9900AA
66#define COLOR_INFO 0xFFFFE1FF
67
68*/
69
70#define COLOR_WHITE (0xFFFFFFFF)
71#define COL_WHITE "{FFFFFF}"
72
73#define COLOR_TOMATO (0xFF6347FF)
74#define COL_TOMATO "{FF6347}"
75
76#define COLOR_YELLOW (0xFFDD00FF)
77#define COL_YELLOW "{FFDD00}"
78
79#define COLOR_GREEN (0x00FF00FF)
80#define COL_GREEN "{00FF00}"
81
82#define COLOR_DEFAULT (0xA9C4E4FF)
83#define COL_DEFAULT "{A9C4E4}"
84
85// how many seconds until it kicks the player for taking too long to login
86#define SECONDS_TO_LOGIN 30
87#define NAME_CHECKER1 30
88
89// default spawn point: Las Venturas (The High Roller)
90#define DEFAULT_POS_X 1958.3783
91#define DEFAULT_POS_Y 1343.1572
92#define DEFAULT_POS_Z 15.3746
93#define DEFAULT_POS_A 270.1425
94
95// MySQL connection handle
96new MySQL: g_SQL;
97
98// player data
99enum E_PLAYERS
100{
101 ID,
102 Name[MAX_PLAYER_NAME],
103 Password[65], // the output of SHA256_PassHash function (which was added in 0.3.7 R1 version) is always 256 bytes in length, or the equivalent of 64 Pawn cells
104 Salt[17],
105 Kills,
106 Admin,
107 Age,
108 Sex,
109 Deaths,
110 USER_SECURITY_QUESTION[MAX_SECURITY_QUESTION_SIZE],
111 USER_SECURITY_ANSWER,
112 PlayerEmail,
113 Float: X_Pos,
114 Float: Y_Pos,
115 Float: Z_Pos,
116 Float: A_Pos,
117 Interior,
118
119 Cache: Cache_ID,
120 bool: IsLoggedIn,
121 LoginAttempts,
122 LoginTimer
123};
124new Player[MAX_PLAYERS][E_PLAYERS];
125
126new g_MysqlRaceCheck[MAX_PLAYERS];
127
128// dialog data
129enum
130{
131 DIALOG_UNUSED,
132 DIALOG_LOGIN,
133 DIALOG_REGISTER,
134 DIALOG_REGISTER_AGE,
135 DIALOG_REGISTER_SEX,
136 DIALOG_REGISTER_DOMANDASEC,
137 DIALOG_REGISTER_RISPOSTASEC,
138 DIALOG_REGISTER_EMAIL
139};
140
141// protocollo controllo nome RP
142stock RPnamecheck(playerid)
143{
144 new pname[MAX_PLAYER_NAME],underline=0;
145 GetPlayerName(playerid, pname, sizeof(pname));
146 if(strfind(pname,"[",true) != (-1)) return 0;
147 else if(strfind(pname,"]",true) != (-1)) return 0;
148 else if(strfind(pname,"$",true) != (-1)) return 0;
149 else if(strfind(pname,"(",true) != (-1)) return 0;
150 else if(strfind(pname,")",true) != (-1)) return 0;
151 else if(strfind(pname,"=",true) != (-1)) return 0;
152 else if(strfind(pname,"@",true) != (-1)) return 0;
153 else if(strfind(pname,"1",true) != (-1)) return 0;
154 else if(strfind(pname,"2",true) != (-1)) return 0;
155 else if(strfind(pname,"3",true) != (-1)) return 0;
156 else if(strfind(pname,"4",true) != (-1)) return 0;
157 else if(strfind(pname,"5",true) != (-1)) return 0;
158 else if(strfind(pname,"6",true) != (-1)) return 0;
159 else if(strfind(pname,"7",true) != (-1)) return 0;
160 else if(strfind(pname,"8",true) != (-1)) return 0;
161 else if(strfind(pname,"9",true) != (-1)) return 0;
162 else if(strfind(pname,"fuck",true) != (-1)) return 0;
163 else if(strfind(pname,"FUCK",true) != (-1)) return 0;
164 else if(strfind(pname,"Boobies",true) != (-1)) return 0;
165 else if(strfind(pname,"Tupac_Shakur",true) != (-1)) return 0;
166 else if(strfind(pname,"Pussy",true) != (-1)) return 0;
167 else if(strfind(pname,"Rape",true) != (-1)) return 0;
168 else if(strfind(pname,"kill",true) != (-1)) return 0;
169 else if(strfind(pname,"shit",true) != (-1)) return 0;
170 else if(strfind(pname,"ass",true) != (-1)) return 0;
171 else if(strfind(pname,"Jack_Black",true) != (-1)) return 0;
172 else if(strfind(pname,"Max_Kenton",true) != (-1)) return 0;
173 else if(strfind(pname,"Will_Smith",true) != (-1)) return 0;
174 else if(strfind(pname,"Jaden_Smith",true) != (-1)) return 0;
175 else if(strfind(pname,"Megan_Fox",true) != (-1)) return 0;
176 else if(strfind(pname,"Charlie_Kenton",true) != (-1)) return 0;
177 else if(strfind(pname,"Hugh_Hefner",true) != (-1)) return 0;
178 else if(strfind(pname,"Paris_Hilton",true) != (-1)) return 0;
179 else if(strfind(pname,"Marshall_Mathers",true) != (-1)) return 0;
180 else if(strfind(pname,"Sheldon_Cooper",true) != (-1)) return 0;
181 else if(strfind(pname,"Jet_Lee",true) != (-1)) return 0;
182 else if(strfind(pname,"Jackie_Chan",true) != (-1)) return 0;
183 else if(strfind(pname,"Chuck_Norris",true) != (-1)) return 0;
184 else if(strfind(pname,"Peter_Parker",true) != (-1)) return 0;
185 else if(strfind(pname,"Spider_Man",true) != (-1)) return 0;
186 else if(strfind(pname,"Bat_Man",true) != (-1)) return 0;
187 else if(strfind(pname,"Emma_Stone",true) != (-1)) return 0;
188 else if(strfind(pname,"whore",true) != (-1)) return 0;
189 else if(strfind(pname,"Hugh_Jackman",true) != (-1)) return 0;
190 else if(strfind(pname,"Charles_Kenton",true) != (-1)) return 0;
191 else if(strfind(pname,"Harry_Potter",true) != (-1)) return 0;
192 else if(strfind(pname,"Chris_Hemsworth",true) != (-1)) return 0;
193 else if(strfind(pname,"Penis",true) != (-1)) return 0;
194 else if(strfind(pname,"_Dick",true) != (-1)) return 0;
195 else if(strfind(pname,"Vagina",true) != (-1)) return 0;
196 else if(strfind(pname,"Cock",true) != (-1)) return 0;
197 else if(strfind(pname,"Rectum",true) != (-1)) return 0;
198 else if(strfind(pname,"Sperm",true) != (-1)) return 0;
199 else if(strfind(pname,"Rektum",true) != (-1)) return 0;
200 else if(strfind(pname,"Pistol",true) != (-1)) return 0;
201 else if(strfind(pname,"AK47",true) != (-1)) return 0;
202 else if(strfind(pname,"Shotgun",true) != (-1)) return 0;
203 else if(strfind(pname,"Cum",true) != (-1)) return 0;
204 else if(strfind(pname,"Hitler",true) != (-1)) return 0;
205 else if(strfind(pname,"Jesus",true) != (-1)) return 0;
206 else if(strfind(pname,"God",true) != (-1)) return 0;
207 else if(strfind(pname,"Shotgun",true) != (-1)) return 0;
208 else if(strfind(pname,"Desert_Eagle",true) != (-1)) return 0;
209 else if(strfind(pname,"fucker",true) != (-1)) return 0;
210 else if(strfind(pname,"Retard",true) != (-1)) return 0;
211 else if(strfind(pname,"Tarded",true) != (-1)) return 0;
212 else if(strfind(pname,"fanny",true) != (-1)) return 0;
213 else if(strfind(pname,"Daniel_Hardy",true) != (-1)) return 0;
214 else if(strfind(pname,"abcdefghijklmnopqrstuvwxyz",true) != (-1)) return 0;
215 new maxname = strlen(pname);
216 for(new i=0; i<maxname; i++)
217 {
218 if(pname[i] == '_') underline ++;
219 }
220 if(underline != 1) return 0;
221 pname[0] = toupper(pname[0]);
222 for(new x=1; x<maxname; x++)
223 {
224 if(pname[x] == '_') pname[x+1] = toupper(pname[x+1]);
225 else if(pname[x] != '_' && pname[x-1] != '_') pname[x] = tolower(pname[x]);
226 }
227 SetPlayerName(playerid, "New_Name");
228 SetPlayerName(playerid, pname);
229 return 1;
230}
231
232
233
234
235
236
237main() {}
238
239
240public OnGameModeInit()
241{
242 new MySQLOpt: option_id = mysql_init_options();
243
244 mysql_set_option(option_id, AUTO_RECONNECT, true); // it automatically reconnects when loosing connection to mysql server
245
246 g_SQL = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DATABASE, option_id); // AUTO_RECONNECT is enabled for this connection handle only
247 if (g_SQL == MYSQL_INVALID_HANDLE || mysql_errno(g_SQL) != 0)
248 {
249 print("MySQL connection failed. Server is shutting down.");
250 SendRconCommand("exit"); // close the server if there is no connection
251 return 1;
252 }
253
254 print("MySQL connection is successful.");
255
256 // if the table has been created, the "SetupPlayerTable" function does not have any purpose so you may remove it completely
257 SetupPlayerTable();
258 return 1;
259}
260
261public OnGameModeExit()
262{
263 // save all player data before closing connection
264 for (new i = 0, j = GetPlayerPoolSize(); i <= j; i++) // GetPlayerPoolSize function was added in 0.3.7 version and gets the highest playerid currently in use on the server
265 {
266 if (IsPlayerConnected(i))
267 {
268 // reason is set to 1 for normal 'Quit'
269 OnPlayerDisconnect(i, 1);
270 }
271 }
272
273 mysql_close(g_SQL);
274 return 1;
275}
276
277// quando l'utente si connette al server
278public OnPlayerConnect(playerid)
279{
280 if(!RPnamecheck(playerid))
281 {
282 SetTimerEx("KickTimerNameRP", 3000, 0, "d", playerid);
283 SetPlayerPos(playerid, 982.1890, -1624.2583, 14.9526);
284 SetPlayerFacingAngle(playerid, 90);
285 new string[128], pname[MAX_PLAYER_NAME];
286 GetPlayerName(playerid, pname, MAX_PLAYER_NAME);
287 format(string, sizeof(string), "{FF0000}[INFO] Devi inserire un nome {00FF00}RP per entrare nel server");
288 SendClientMessage(playerid, COLOR_SYSTEM_ERROR, string);
289 format(string, sizeof(string), "{AFAFAF}Il nome {FF0000}%s non è valido.{AFAFAF} (devi usare tipo {00FF00}Nome_Cognome{AFAFAF})", Player[playerid][Name]);
290 SendClientMessage(playerid, COLOR_SYSTEM_ERROR, string);
291 }
292 else if(RPnamecheck(playerid))
293 {
294 g_MysqlRaceCheck[playerid]++;
295 // reset player data
296 static const empty_player[E_PLAYERS];
297 Player[playerid] = empty_player;
298
299 GetPlayerName(playerid, Player[playerid][Name], MAX_PLAYER_NAME);
300
301 // send a query to recieve all the stored player data from the table
302 new query[103];
303 mysql_format(g_SQL, query, sizeof query, "SELECT * FROM `players` WHERE `username` = '%e' LIMIT 1", Player[playerid][Name]);
304 mysql_tquery(g_SQL, query, "OnPlayerDataLoaded", "dd", playerid, g_MysqlRaceCheck[playerid]);
305 }
306 return 1;
307}
308
309public OnPlayerDisconnect(playerid, reason)
310{
311 g_MysqlRaceCheck[playerid]++;
312
313 UpdatePlayerData(playerid, reason);
314
315 // if the player was kicked (either wrong password or taking too long) during the login part, remove the data from the memory
316 if (cache_is_valid(Player[playerid][Cache_ID]))
317 {
318 cache_delete(Player[playerid][Cache_ID]);
319 Player[playerid][Cache_ID] = MYSQL_INVALID_CACHE;
320 }
321
322 // if the player was kicked before the time expires (30 seconds), kill the timer
323 if (Player[playerid][LoginTimer])
324 {
325 KillTimer(Player[playerid][LoginTimer]);
326 Player[playerid][LoginTimer] = 0;
327 }
328
329 // sets "IsLoggedIn" to false when the player disconnects, it prevents from saving the player data twice when "gmx" is used
330 Player[playerid][IsLoggedIn] = false;
331 return 1;
332}
333
334public OnPlayerSpawn(playerid)
335{
336 // spawn the player to their last saved position
337 SetPlayerInterior(playerid, Player[playerid][Interior]);
338 SetPlayerPos(playerid, Player[playerid][X_Pos], Player[playerid][Y_Pos], Player[playerid][Z_Pos]);
339 SetPlayerFacingAngle(playerid, Player[playerid][A_Pos]);
340
341 SetCameraBehindPlayer(playerid);
342 return 1;
343}
344
345public OnPlayerDeath(playerid, killerid, reason)
346{
347 UpdatePlayerDeaths(playerid);
348 UpdatePlayerKills(killerid);
349 return 1;
350}
351
352
353//-------------------------------------------
354// dialoghi
355public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
356{
357 switch (dialogid)
358 {
359 case DIALOG_UNUSED: return 1; // Useful for dialogs that contain only information and we do nothing depending on whether they responded or not
360
361 case DIALOG_LOGIN:
362 {
363 if (!response) return Kick(playerid);
364
365 new hashed_pass[65];
366 SHA256_PassHash(inputtext, Player[playerid][Salt], hashed_pass, 65);
367
368 if (strcmp(hashed_pass, Player[playerid][Password]) == 0)
369 {
370 //correct password, spawn the player
371 ShowPlayerDialog(playerid, DIALOG_UNUSED, DIALOG_STYLE_MSGBOX, "Login", "Login con successo.", "Okay", "");
372 // sets the specified cache as the active cache so we can retrieve the rest player data
373 cache_set_active(Player[playerid][Cache_ID]);
374 AssignPlayerData(playerid);
375 // remove the active cache from memory and unsets the active cache as well
376 cache_delete(Player[playerid][Cache_ID]);
377 Player[playerid][Cache_ID] = MYSQL_INVALID_CACHE;
378
379 KillTimer(Player[playerid][LoginTimer]);
380 Player[playerid][LoginTimer] = 0;
381 Player[playerid][IsLoggedIn] = true;
382
383 // spawn the player to their last saved position after login
384 SetSpawnInfo(playerid, NO_TEAM, 0, Player[playerid][X_Pos], Player[playerid][Y_Pos], Player[playerid][Z_Pos], Player[playerid][A_Pos], 0, 0, 0, 0, 0, 0);
385 SpawnPlayer(playerid);
386 }
387 else
388 {
389 Player[playerid][LoginAttempts]++;
390
391 if (Player[playerid][LoginAttempts] >= 3)
392 {
393 ShowPlayerDialog(playerid, DIALOG_UNUSED, DIALOG_STYLE_MSGBOX, "Login", "Hai superato i tentativi di accesso (3 tentativi).", "Okay", "");
394 DelayedKick(playerid);
395 }
396 else ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", "{FF0000}Password errata!\n{AFAFAF}Inserisci la password per entrare:", "Login", "Annulla");
397 }
398 }
399 // Dialog - registrazione 1/6 password
400 case DIALOG_REGISTER:
401 {
402 if (!response)
403 {
404 Kick(playerid);
405 return 1;
406 }
407
408 if (strlen(inputtext) <= 5) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Registrazione... [Step: 1/6]", "{FF0000}[ERRORE:]Hai inserito una password troppo corta, usa almeno 5 caratteri!\n{AFAFAF}Inserisci una password per registrarti:", "Continua", "Annulla");
409
410 // 16 random characters from 33 to 126 (in ASCII) for the salt
411 for (new i = 0; i < 16; i++) Player[playerid][Salt][i] = random(94) + 33;
412 SHA256_PassHash(inputtext, Player[playerid][Salt], Player[playerid][Password], 65);
413 new query[221];
414 mysql_format(g_SQL, query, sizeof query, "INSERT INTO `players` (`username`, `password`, `salt`) VALUES ('%e', '%s', '%e')", Player[playerid][Name], Player[playerid][Password], Player[playerid][Salt]);
415// mysql_tquery(g_SQL, query, "OnPlayerRegister", "d", playerid);
416 new string[128];
417 format(string, sizeof(string), "{AFAFAF}[INFO:] Ricorda la tua password è: {f4b642}'%s'", inputtext);
418 SendClientMessage(playerid, COLOR_SYSTEM_INFO, string);
419 format(string, sizeof(string), "{AFAFAF}[INFO:] Puoi cambiarla in game con il comando {ff0000}/cambia -> PASSWORD");
420 SendClientMessage(playerid, COLOR_SYSTEM_INFO, string);
421 ShowPlayerDialog(playerid, DIALOG_REGISTER_AGE, DIALOG_STYLE_INPUT, "Registrazione... [Step: 2/6]", "Inserisci l'età che vuoi avere nel server\nNon influenzerà il gioco", "Continua", "Annulla");
422 }
423 // Dialog - registrazione 2/6 etÃ
424 case DIALOG_REGISTER_AGE:
425 {
426 if (!response)
427 {
428 Kick(playerid);
429 return 1;
430 }
431
432 if (!strlen(inputtext))
433 {
434 ShowPlayerDialog(playerid, DIALOG_REGISTER_AGE, DIALOG_STYLE_INPUT, "Registrazione... età [Step: 2/6]", "{FF0000}[ERRORE:]Devi inserire l'età per continuare!\n{AFAFAF}Non influenzerà il gioco:", "Continua", "Annulla");
435 return 1;
436 }
437 else if (strlen(inputtext))
438 {
439 if (!IsNumeric(inputtext))
440 {
441 ShowPlayerDialog(playerid, DIALOG_REGISTER_AGE, DIALOG_STYLE_INPUT, "Registrazione... età [Step: 2/6]", "{FF0000}[ERRORE:]Devi inserire un numero per l'età !\n{AFAFAF}Non influenzerà il gioco:", "Continua", "Annulla");
442 return 1;
443 }
444 else if (IsNumeric(inputtext))
445 {
446 new query[221];
447 Player[playerid][Age] = strlen(inputtext);
448// mysql_format(g_SQL, query, sizeof query, "INSERT INTO `players` (`username`, `password`, `salt`, `age`) VALUES ('%e', '%s', '%e', 'd')", Player[playerid][Name], Player[playerid][Password], Player[playerid][Salt], Player[playerid][Age]);
449 mysql_format(g_SQL, query, sizeof query, "UPDATE `players` SET `age` = %d WHERE `id` = %d LIMIT 1", Player[playerid][Age], Player[playerid][ID]);
450 new string[128];
451 format(string, sizeof(string), "{AFAFAF}[INFO:] Hai %d anni.", inputtext);
452 SendClientMessage(playerid, COLOR_SYSTEM_INFO, string);
453 ShowPlayerDialog(playerid, DIALOG_REGISTER_SEX, DIALOG_STYLE_LIST, "Seleziona il sesso", "{FF6666}Donna\n{0000cc}Uomo", "Continua", "");
454 }
455 }
456 }
457 // Dialog - registrazione 3/6 sesso
458 case DIALOG_REGISTER_SEX:
459 {
460
461 if (!response)
462 {
463 Kick(playerid);
464 return 1;
465 }
466 switch(listitem)// Dialog: registrazione fase 3: sesso
467 {
468 case 0: // Registrazione sesso: selezionato: donna
469 {
470 Player[playerid][Sex] = 1; // 1 = donna
471 new query[221];
472 mysql_format(g_SQL, query, sizeof query, "INSERT INTO `players` (`username`, `password`, `salt`, `age`, `sex`) VALUES ('%e', '%s', '%e', '%d', '%d')", Player[playerid][Name], Player[playerid][Password], Player[playerid][Salt], Player[playerid][Age], Player[playerid][Sex]);
473// mysql_tquery(g_SQL, query, "OnPlayerRegister", "d", playerid);
474 new Messaggio[256];
475 format(Messaggio, sizeof (Messaggio), "{AFAFAF}[INFO]: %s sei {FF6666}una donna", Player[playerid][Name]);
476 SendClientMessage(playerid, COLOR_SYSTEM_INFO, Messaggio);
477
478 ShowPlayerDialog(playerid, DIALOG_REGISTER_RISPOSTASEC, DIALOG_STYLE_INPUT, "Registrazione...", "Inserisci un codice di recupero per la password", "Continua", "Annulla");
479 PlayerPlaySound(playerid, 1054, 0.0, 0.0, 0.0);
480
481 }
482 case 1: // Registrazione sesso: selezionato: uomo
483 {
484 Player[playerid][Sex] = 2; // 2 = uomo
485 new query[221];
486 mysql_format(g_SQL, query, sizeof query, "INSERT INTO `players` (`username`, `password`, `salt`, `age`, `sex`) VALUES ('%e', '%s', '%e', '%d', '%d')", Player[playerid][Name], Player[playerid][Password], Player[playerid][Salt], Player[playerid][Age], Player[playerid][Sex]);
487// mysql_tquery(g_SQL, query, "OnPlayerRegister", "d", playerid);
488 new Messaggio[256];
489 format(Messaggio, sizeof (Messaggio), "[INFO]: %s sei {0000cc}un uomo", Player[playerid][Name]);
490 SendClientMessage(playerid, COLOR_SYSTEM_INFO, Messaggio);
491 SendClientMessage(playerid, COLOR_SYSTEM_INFO, "Inserisci una chiave di sicurezza per recuperare la password");
492
493 ShowPlayerDialog(playerid, DIALOG_REGISTER_RISPOSTASEC, DIALOG_STYLE_INPUT, "Registrazione...", "Inserisci un codice di recupero per la password", "Continua", "Annulla");
494 PlayerPlaySound(playerid, 1054, 0.0, 0.0, 0.0);
495
496
497 }
498 }
499 }
500 case DIALOG_REGISTER_RISPOSTASEC:
501 {
502 if (!response)
503 {
504 Kick(playerid);
505 return 1;
506 }
507 else
508 {
509 new query[221];
510 mysql_format(g_SQL, query, sizeof query, "INSERT INTO `players` (`username`, `password`, `salt`, `age`, `sex`, `rispostasec`) VALUES ('%e', '%s', '%e', '%d', '%d', '%s')", Player[playerid][Name], Player[playerid][Password], Player[playerid][Salt], Player[playerid][Age], Player[playerid][Sex], inputtext);
511 mysql_tquery(g_SQL, query, "OnPlayerRegister", "d", playerid);
512 }
513 }
514
515
516
517 default: return 0; // dialog ID was not found, search in other scripts
518 }
519 return 1;
520}
521
522//-----------------------------------------------------
523
524// controllo se una string è numerica
525IsNumeric(const string[])
526{
527 for (new i = 0, j = strlen(string); i < j; i++)
528 {
529 if (string[i] > '9' || string[i] < '0') return 0;
530 }
531 return 1;
532}
533
534forward OnPlayerDataLoaded(playerid, race_check);
535public OnPlayerDataLoaded(playerid, race_check)
536{
537 /* race condition check:
538 player A connects -> SELECT query is fired -> this query takes very long
539 while the query is still processing, player A with playerid 2 disconnects
540 player B joins now with playerid 2 -> our laggy SELECT query is finally finished, but for the wrong player
541 what do we do against it?
542 we create a connection count for each playerid and increase it everytime the playerid connects or disconnects
543 we also pass the current value of the connection count to our OnPlayerDataLoaded callback
544 then we check if current connection count is the same as connection count we passed to the callback
545 if yes, everything is okay, if not, we just kick the player
546 */
547 if (race_check != g_MysqlRaceCheck[playerid]) return Kick(playerid);
548
549 new string[115];
550 if(cache_num_rows() > 0)// Giocatore registrato sul server
551 {
552 cache_get_value(0, "password", Player[playerid][Password], 65);
553 cache_get_value(0, "salt", Player[playerid][Salt], 17);
554 Player[playerid][Cache_ID] = cache_save();
555
556 format(string, sizeof string, "%s risulta registrato sul server.\nInserisci la password per entrare:", Player[playerid][Name]);
557 ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", string, "Login", "Annulla");
558 Player[playerid][LoginTimer] = SetTimerEx("OnLoginTimeout", SECONDS_TO_LOGIN * 1000, false, "d", playerid);
559 }
560 else // Giocatore non registrato sul server
561 {
562 format(string, sizeof string, "Benvenuto %s,\nPer iniziare a registrarti su %s, inserisci una password", Player[playerid][Name], nomeserver);
563 ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Registrazione [1/6]", string, "Continua", "Annulla");
564 }
565 return 1;
566}
567
568forward OnLoginTimeout(playerid);
569public OnLoginTimeout(playerid)
570{
571 // reset the variable that stores the timerid
572 Player[playerid][LoginTimer] = 0;
573
574 ShowPlayerDialog(playerid, DIALOG_UNUSED, DIALOG_STYLE_MSGBOX, "Login", "Sei stato kickato dal server per aver impiegato troppo tempo nel loggarti.", "Okay", "");
575 DelayedKick(playerid);
576 return 1;
577}
578
579// prova timer
580forward KickTimerNameRP(playerid);
581public KickTimerNameRP(playerid)
582{
583 Kick(playerid);
584}
585
586forward OnPlayerRegister(playerid);
587public OnPlayerRegister(playerid)
588{
589 // retrieves the ID generated for an AUTO_INCREMENT column by the sent query
590 Player[playerid][ID] = cache_insert_id();
591
592 ShowPlayerDialog(playerid, DIALOG_UNUSED, DIALOG_STYLE_MSGBOX, "Registration", "Account successfully registered, you have been automatically logged in.", "Okay", "");
593
594 Player[playerid][IsLoggedIn] = true;
595
596 Player[playerid][X_Pos] = DEFAULT_POS_X;
597 Player[playerid][Y_Pos] = DEFAULT_POS_Y;
598 Player[playerid][Z_Pos] = DEFAULT_POS_Z;
599 Player[playerid][A_Pos] = DEFAULT_POS_A;
600
601 SetSpawnInfo(playerid, NO_TEAM, 0, Player[playerid][X_Pos], Player[playerid][Y_Pos], Player[playerid][Z_Pos], Player[playerid][A_Pos], 0, 0, 0, 0, 0, 0);
602 SpawnPlayer(playerid);
603 return 1;
604}
605
606forward _KickPlayerDelayed(playerid);
607public _KickPlayerDelayed(playerid)
608{
609 Kick(playerid);
610 return 1;
611}
612
613
614//-----------------------------------------------------
615
616AssignPlayerData(playerid)
617{
618 cache_get_value_int(0, "id", Player[playerid][ID]);
619
620 cache_get_value_int(0, "kills", Player[playerid][Kills]);
621 cache_get_value_int(0, "deaths", Player[playerid][Deaths]);
622 cache_get_value_int(0, "admin", Player[playerid][Admin]);
623 cache_get_value_int(0, "sex", Player[playerid][Sex]);
624// cache_get_value_int(0, "age", Player[playerid][Age]);
625 cache_get_value(0, "age", Player[playerid][Age], 65);
626 cache_get_value_float(0, "x", Player[playerid][X_Pos]);
627 cache_get_value_float(0, "y", Player[playerid][Y_Pos]);
628 cache_get_value_float(0, "z", Player[playerid][Z_Pos]);
629 cache_get_value_float(0, "angle", Player[playerid][A_Pos]);
630 cache_get_value_int(0, "interior", Player[playerid][Interior]);
631 return 1;
632}
633
634DelayedKick(playerid, time = 500)
635{
636 SetTimerEx("_KickPlayerDelayed", time, false, "d", playerid);
637 return 1;
638}
639
640SetupPlayerTable()
641{
642 mysql_tquery(g_SQL, "CREATE TABLE IF NOT EXISTS `players` (`id` int(11) NOT NULL AUTO_INCREMENT,`username` varchar(24) NOT NULL,`password` char(64) NOT NULL,`salt` char(16) NOT NULL,`kills` mediumint(8) NOT NULL DEFAULT '0',`deaths` mediumint(8) NOT NULL DEFAULT '0',`x` float NOT NULL DEFAULT '0',`y` float NOT NULL DEFAULT '0',`z` float NOT NULL DEFAULT '0',`angle` float NOT NULL DEFAULT '0',`interior` tinyint(3) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), UNIQUE KEY `username` (`username`))");
643 return 1;
644}
645
646UpdatePlayerData(playerid, reason)
647{
648 if (Player[playerid][IsLoggedIn] == false) return 0;
649
650 // if the client crashed, it's not possible to get the player's position in OnPlayerDisconnect callback
651 // so we will use the last saved position (in case of a player who registered and crashed/kicked, the position will be the default spawn point)
652 if (reason == 1)
653 {
654 GetPlayerPos(playerid, Player[playerid][X_Pos], Player[playerid][Y_Pos], Player[playerid][Z_Pos]);
655 GetPlayerFacingAngle(playerid, Player[playerid][A_Pos]);
656 }
657
658 new query[145];
659 mysql_format(g_SQL, query, sizeof query, "UPDATE `players` SET `x` = %f, `y` = %f, `z` = %f, `angle` = %f, `interior` = %d WHERE `id` = %d LIMIT 1", Player[playerid][X_Pos], Player[playerid][Y_Pos], Player[playerid][Z_Pos], Player[playerid][A_Pos], GetPlayerInterior(playerid), Player[playerid][ID]);
660 mysql_tquery(g_SQL, query);
661 return 1;
662}
663
664UpdatePlayerDeaths(playerid)
665{
666 if (Player[playerid][IsLoggedIn] == false) return 0;
667
668 Player[playerid][Deaths]++;
669
670 new query[70];
671 mysql_format(g_SQL, query, sizeof query, "UPDATE `players` SET `deaths` = %d WHERE `id` = %d LIMIT 1", Player[playerid][Deaths], Player[playerid][ID]);
672 mysql_tquery(g_SQL, query);
673 return 1;
674}
675
676UpdatePlayerKills(killerid)
677{
678 // we must check before if the killer wasn't valid (connected) player to avoid run time error 4
679 if (killerid == INVALID_PLAYER_ID) return 0;
680 if (Player[killerid][IsLoggedIn] == false) return 0;
681
682 Player[killerid][Kills]++;
683
684 new query[70];
685 mysql_format(g_SQL, query, sizeof query, "UPDATE `players` SET `kills` = %d WHERE `id` = %d LIMIT 1", Player[killerid][Kills], Player[killerid][ID]);
686 mysql_tquery(g_SQL, query);
687 return 1;
688}
689//-----------------------------------------------------------------------
690// comandi - zcmd
691
692CMD:admin(playerid, params[])
693{
694 if(Player[playerid][Admin] == 0)
695 {
696 SendClientMessage(playerid, COLOR_SYSTEM_ERROR, "asd");
697 return 1;
698 }
699 else if(Player[playerid][Admin] >= 1)
700 {
701 SendClientMessage(playerid, COLOR_SYSTEM_SUCCESS, "123");
702 return 1;
703 }
704 return 1;
705}
706
707CMD:suicidio(playerid, params[])
708{
709 SetPlayerHealth(playerid, 0);
710 return 1;
711}
712
713public OnPlayerRequestClass(playerid,classid)
714{
715 SetPlayerPos(playerid, 982.1890, -1624.2583, 14.9526);
716 SetPlayerFacingAngle(playerid, 90);
717 return 1;
718}