Guest User

Untitled

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