Guest User

Untitled

a guest
Jan 20th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.61 KB | None | 0 0
  1. /*=====================================================*
  2. * GM RP by: OuDayas
  3. * Version: 1.0
  4. *
  5. *======================================================*/
  6. // Sezione include
  7. #include <a_samp> // include base: NON ELIMINARE O NON PARTIÀ
  8. #include <a_mysql> // Include per la connessione al: MySQL
  9. #include <sscanf> // Include per sscanf
  10. #include <zcmd> // Include per i comandi
  11.  
  12. // Sezione define
  13. // Connessione MySQL (in caso di editing cambia solo i campi tra le ""
  14. #define MYSQL_HOST "127.0.0.1" //IP del server host (es: localhost/127.0.0.1
  15. #define MYSQL_USER "root" //Username a cui accedere (di default è root)
  16. #define MYSQL_PASS "Pass123!" //Password per accedere al protocollo MySQL
  17. #define MYSQL_DBSE "dbrp" //Nome del database
  18. new MySQL:handle; // l'Handle di connessione per connettersi al databse
  19.  
  20. // dialoghi registrazione/login
  21. #define DIALOG_REGISTER 1
  22. #define DIALOG_REGISTER_EMAIL 2
  23. #define DIALOG_REGISTER_AGE 3
  24. #define DIALOG_LOGIN 10
  25.  
  26. // colori
  27. // system color
  28. #define COLOR_SYSTEM_ERROR 0xAA3333AA
  29. #define COLOR_SYSTEM_TITLE 0xFFFFFFAA
  30. #define COLOR_SYSTEM_TEXT 0xFFFFFFAA
  31. #define COLOR_SYSTEM_SUCCESS 0x33AA33AA
  32. #define COLOR_SYSTEM_INFO 0xAFAFAFAA
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39. // protocollo di controllo se una string è numerica
  40. IsNumeric(const string[])
  41. {
  42. for (new i = 0, j = strlen(string); i < j; i++)
  43. {
  44. if (string[i] > '9' || string[i] < '0') return 0;
  45. }
  46. return 1;
  47. }
  48.  
  49. // lista denominazioni delle statistiche
  50. enum pDataEnum
  51. {
  52. p_id,
  53. bool:pLoggedIn,
  54. pName[MAX_PLAYER_NAME],
  55. pLevel,
  56. pMoney,
  57. pKills,
  58. pAge,
  59. pPassTmp[128],
  60. pEmail[64],
  61. pDeaths
  62. }
  63. new PlayerInfo[MAX_PLAYERS][pDataEnum];
  64.  
  65.  
  66.  
  67. // non cancellare
  68. // usercheck, controllo del giocatore
  69. forward OnUserCheck(playerid);
  70. public OnUserCheck(playerid)
  71. {
  72. //Query inizializzata con successo nella chache, passa al check
  73. new rows;
  74. cache_get_row_count(rows);
  75. if(rows == 0)
  76. {
  77. //Giocatore nont rovato nel database, quindi passa alla registrazione
  78. ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Registrazione", "Inserisci una password per iniziare la registrazione:", "Continua", "Annulla");
  79. }
  80. else
  81. {
  82. //Giocatore trovato, quindi passa al login
  83. ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", "Prego inserisci la password per entrare nel server:", "Login", "Esci");
  84. }
  85. return 1;
  86. }
  87.  
  88. // non cancellare
  89. // onuserregister - quando il giocatore finisce di registrarsi
  90. forward OnUserRegister(playerid);
  91. public OnUserRegister(playerid)
  92. {
  93. //L'utente ha finito la registrazione e viene inserito nel database
  94. //Una volta finito inserirà l'id nella cache e imposterà l'accesso su true (accesso effettuato)
  95. PlayerInfo[playerid][p_id] = cache_insert_id();
  96. PlayerInfo[playerid][pLoggedIn] = true;
  97. SendClientMessage(playerid, 0x00FF00FF, "[SERVER:] Registrazione effettuata con successo.");
  98. return 1;
  99. }
  100.  
  101. //non cancellare
  102. // quando un utente si collega al server
  103. forward OnUserLogin(playerid);
  104. public OnUserLogin(playerid)
  105. {
  106. //Query wurde ausgeführt und das Ergebnis im Cache gespeichert
  107. new rows;
  108. cache_get_row_count(rows);
  109. if(rows == 0)
  110. {
  111. //In caso di login l'utente inserisce una password errata
  112. ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", "{FF0000}ERRORE:\n{FF0000}Password errata\n{0F22FF}Riprova:!", "Login", "Esci");
  113. }
  114. else
  115. {
  116. //Es existiert ein Ergebnis, das heißt der Spieler hat das richtige Passwort eingegeben
  117. //Wir lesen nun die erste Zeile des Caches aus (ID 0)
  118. cache_get_value_name_int(0, "id", PlayerInfo[playerid][p_id]);
  119. cache_get_value_name_int(0, "level", PlayerInfo[playerid][pLevel]);
  120. cache_get_value_name_int(0, "money", PlayerInfo[playerid][pMoney]);
  121. cache_get_value_name_int(0, "kills", PlayerInfo[playerid][pKills]);
  122. cache_get_value_name_int(0, "age", PlayerInfo[playerid][pAge]);
  123. cache_get_value_name_int(0, "deaths", PlayerInfo[playerid][pDeaths]);
  124. cache_get_value_name(0, "email", PlayerInfo[playerid][pEmail],64);
  125. PlayerInfo[playerid][pLoggedIn] = true;
  126. SendClientMessage(playerid, 0x00FF00FF, "[INFO:] Login con successo.");
  127. GivePlayerMoney(playerid, PlayerInfo[playerid][pMoney]);
  128. }
  129. return 1;
  130. }
  131. // non cancellare
  132. // quando un utente si scollega salva prima le statistiche
  133. stock SaveUserStats(playerid)
  134. {
  135. //Se non ha effettuato l'accesso il giocatore, non salva le statistiche
  136. if(!PlayerInfo[playerid][pLoggedIn]) return 1;
  137.  
  138. //Se ha già effettuato l'accesso salva le statistiche
  139.  
  140. new playeremail[64];
  141. format(playeremail, 64, PlayerInfo[playerid][pEmail]);
  142. new livello = PlayerInfo[playerid][pLevel];
  143. new soldi = PlayerInfo[playerid][pMoney];
  144. new kills = PlayerInfo[playerid][pKills];
  145. new morti = PlayerInfo[playerid][pDeaths];
  146. new giocaotreid = PlayerInfo[playerid][p_id];
  147. new etagiocatore = PlayerInfo[playerid][pAge];
  148.  
  149. new query[256];
  150. mysql_format(handle, query, sizeof(query),
  151. "UPDATE users SET age = '%d', email = '%s', level = '%d', money = '%d', kills = '%d', deaths = '%d' WHERE id = '%d'",
  152. etagiocatore, playeremail, livello, soldi, kills, morti, giocaotreid);
  153.  
  154.  
  155. //Query inviata
  156. mysql_pquery(handle, query);
  157. return 1;
  158. }
  159. // non cancellare/modificare
  160. // setup della connessione al MySQL
  161. stock MySQL_SetupConnection(ttl = 3)
  162. {
  163. print("[MySQL] Connessione in corso...");
  164. //mysql_log(); //<- Rimuovi il commento antecedente a mysql_log per attivare la modalità debug
  165.  
  166. handle = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_DBSE);
  167.  
  168. //Inizio della procedura di controllo e riconnessione se necessario ripeterla
  169. if(mysql_errno(handle) != 0)
  170. {
  171. //In caso di errore della configurazione del MySQL verifica se necessario un nuovo tentativo
  172. if(ttl > 1)
  173. {
  174. //Prova di riconnessione
  175. print("[MySQL] Impossibile collegarsi al database.");
  176. printf("[MySQL] Inizio nuovo tentativo di connessione in corso (TTL: %d).", ttl-1);
  177. return MySQL_SetupConnection(ttl-1);
  178. }
  179. else
  180. {
  181. //Annulla e chiude il server
  182. print("[MySQL] Impossibile collegarsi al database.");
  183. print("[MySQL] Verifica i dati di connessione.");
  184. print("[MySQL] Erresto server in corso.");
  185. return SendRconCommand("exit");
  186. }
  187. }
  188. printf("[MySQL] Connessione al MySQL con successo Handle: %d", _:handle);
  189. return 1;
  190. }
  191.  
  192. #if defined FILTERSCRIPT
  193.  
  194. public OnFilterScriptInit()
  195. {
  196. print("\n---------------------");
  197. print(" Non è un filterscript ");
  198. print("---------------------\n");
  199. return 1;
  200. }
  201.  
  202. public OnFilterScriptExit()
  203. {
  204. return 1;
  205. }
  206.  
  207. #else
  208.  
  209. main()
  210. {
  211. print("\n-------------------------------------------------------------------------------");
  212. print("GameMode RP By: OuDayas v1.0");
  213. print("Non modificare la GM dove lo trovi indicato");
  214. print("In tal caso vuoiu spegnere il server usa il comando in console 'exit'");
  215. print("Per effettuare un riavvio usa invece 'gmx'(Fallo solo se strettamente necessario)");
  216. print("Per ogni cosa trovi un piccolo aiuto dove puoi editare la GM su pawno");
  217. print("--------------------------------------------------------------------------------\n");
  218. }
  219.  
  220. #endif
  221.  
  222. public OnGameModeInit()
  223. {
  224. MySQL_SetupConnection(); // inizio della connessione al MySQL
  225. SetGameModeText("Blank Script");
  226. AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
  227.  
  228. return 1;
  229. }
  230.  
  231. public OnGameModeExit()
  232. {
  233. mysql_close(handle);
  234. return 1;
  235. }
  236.  
  237. public OnPlayerRequestClass(playerid, classid)
  238. {
  239. // da qui non modificare
  240. //Quando il giocatore entra nella "request class" controlla se ha effettuato il login
  241. if(!PlayerInfo[playerid][pLoggedIn])
  242. {
  243. SendClientMessage(playerid, 0xFF0000, "[ERRORE:] Devi prima effettuare l'accesso per entrare");
  244. //In caso contrario controlla se ha un'account
  245. //Invia una query di controllo dove viene richiamata
  246. //%e sta per una stringa già verificata (usata al posto di %s nelle query)
  247. new query[128];
  248. mysql_format(handle, query, sizeof(query), "SELECT id FROM users WHERE name = '%e'", PlayerInfo[playerid][pName]);
  249.  
  250. //La query dopo essere stata inviata, la passxa al "OnUserCheck"
  251. mysql_pquery(handle, query, "OnUserCheck", "d", playerid);
  252. }
  253. return 1;
  254. }
  255.  
  256. public OnPlayerConnect(playerid)
  257. {
  258. PlayerInfo[playerid][p_id] = 0;
  259. PlayerInfo[playerid][pLoggedIn] = false;
  260. PlayerInfo[playerid][pLevel] = 0;
  261. PlayerInfo[playerid][pMoney] = 0;
  262. PlayerInfo[playerid][pKills] = 0;
  263. PlayerInfo[playerid][pDeaths] = 0;
  264. format(PlayerInfo[playerid][pPassTmp], 128, "");
  265. format(PlayerInfo[playerid][pEmail], 64, "");
  266. GetPlayerName(playerid, PlayerInfo[playerid][pName], MAX_PLAYER_NAME);
  267. return 1;
  268. }
  269.  
  270. public OnPlayerDisconnect(playerid, reason)
  271. {
  272. SaveUserStats(playerid);
  273. return 1;
  274. }
  275.  
  276. public OnPlayerSpawn(playerid)
  277. {
  278. return 1;
  279. }
  280.  
  281. public OnPlayerDeath(playerid, killerid, reason)
  282. {
  283. return 1;
  284. }
  285.  
  286. public OnVehicleSpawn(vehicleid)
  287. {
  288. return 1;
  289. }
  290.  
  291. public OnVehicleDeath(vehicleid, killerid)
  292. {
  293. return 1;
  294. }
  295.  
  296. public OnPlayerText(playerid, text[])
  297. {
  298. return 1;
  299. }
  300. // comandi
  301.  
  302. // comando: pm
  303. CMD:pm(playerid, params[])
  304. {
  305. new str[256], str2[256], id, Name1[MAX_PLAYER_NAME], Name2[MAX_PLAYER_NAME];
  306. if(sscanf(params, "us", id, str2))
  307. {
  308. SendClientMessage(playerid, 0xFF0000FF, "Usage: /pm <id> <message>");
  309. return 1;
  310. }
  311. if(!IsPlayerConnected(id)) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: Player not connected");
  312. if(playerid == id) return SendClientMessage(playerid, 0xFF0000FF, "[ERRORE:]{AFAFAFAA} Npon puoi mandare un pm a te stesso!");
  313. {
  314. GetPlayerName(playerid, Name1, sizeof(Name1));
  315. GetPlayerName(id, Name2, sizeof(Name2));
  316. format(str, sizeof(str), "PM To %s(ID %d): %s", Name2, id, str2);
  317. SendClientMessage(playerid, 0xFF0000FF, str);
  318. format(str, sizeof(str), "PM From %s(ID %d): %s", Name1, playerid, str2);
  319. SendClientMessage(id, 0xFF0000FF, str);
  320. }
  321. return 1;
  322. }
  323.  
  324. public OnPlayerCommandText(playerid, cmdtext[])
  325. {/*
  326. if (strcmp("/mycommand", cmdtext, true, 10) == 0)
  327. {
  328. // Do something here
  329. return 1;
  330. }*/
  331. new Messaggio[256];
  332. format(Messaggio, sizeof (Messaggio), "[INFO]: Il comando %s non esiste usa /comandi per aiuto", cmdtext);
  333. SendClientMessage(playerid, COLOR_SYSTEM_INFO, Messaggio);
  334. return SendClientMessage(playerid, -1, Messaggio);
  335. }
  336.  
  337. public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
  338. {
  339. return 1;
  340. }
  341.  
  342. public OnPlayerExitVehicle(playerid, vehicleid)
  343. {
  344. return 1;
  345. }
  346.  
  347. public OnPlayerStateChange(playerid, newstate, oldstate)
  348. {
  349. return 1;
  350. }
  351.  
  352. public OnPlayerEnterCheckpoint(playerid)
  353. {
  354. return 1;
  355. }
  356.  
  357. public OnPlayerLeaveCheckpoint(playerid)
  358. {
  359. return 1;
  360. }
  361.  
  362. public OnPlayerEnterRaceCheckpoint(playerid)
  363. {
  364. return 1;
  365. }
  366.  
  367. public OnPlayerLeaveRaceCheckpoint(playerid)
  368. {
  369. return 1;
  370. }
  371.  
  372. public OnRconCommand(cmd[])
  373. {
  374. return 1;
  375. }
  376.  
  377. public OnPlayerRequestSpawn(playerid)
  378. {
  379. return 1;
  380. }
  381.  
  382. public OnObjectMoved(objectid)
  383. {
  384. return 1;
  385. }
  386.  
  387. public OnPlayerObjectMoved(playerid, objectid)
  388. {
  389. return 1;
  390. }
  391.  
  392. public OnPlayerPickUpPickup(playerid, pickupid)
  393. {
  394. return 1;
  395. }
  396.  
  397. public OnVehicleMod(playerid, vehicleid, componentid)
  398. {
  399. return 1;
  400. }
  401.  
  402. public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
  403. {
  404. return 1;
  405. }
  406.  
  407. public OnVehicleRespray(playerid, vehicleid, color1, color2)
  408. {
  409. return 1;
  410. }
  411.  
  412. public OnPlayerSelectedMenuRow(playerid, row)
  413. {
  414. return 1;
  415. }
  416.  
  417. public OnPlayerExitedMenu(playerid)
  418. {
  419. return 1;
  420. }
  421.  
  422. public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
  423. {
  424. return 1;
  425. }
  426.  
  427. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  428. {
  429. return 1;
  430. }
  431.  
  432. public OnRconLoginAttempt(ip[], password[], success)
  433. {
  434. return 1;
  435. }
  436.  
  437. public OnPlayerUpdate(playerid)
  438. {
  439. return 1;
  440. }
  441.  
  442. public OnPlayerStreamIn(playerid, forplayerid)
  443. {
  444. return 1;
  445. }
  446.  
  447. public OnPlayerStreamOut(playerid, forplayerid)
  448. {
  449. return 1;
  450. }
  451.  
  452. public OnVehicleStreamIn(vehicleid, forplayerid)
  453. {
  454. return 1;
  455. }
  456.  
  457. public OnVehicleStreamOut(vehicleid, forplayerid)
  458. {
  459. return 1;
  460. }
  461.  
  462. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  463. {
  464. // registrazione password (fase 1)
  465. if(dialogid == DIALOG_REGISTER)
  466. {
  467. //Se il giocatore seleziona Annulla/Esci
  468. if(!response) return Kick(playerid);
  469.  
  470. //In tal caso l'utente inserisci una password troppo breve o non inserisce niente ritorna sullo stesso dialogo
  471. if(strlen(inputtext) < 3) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Registrazione", "{FF0000}ERRORE:\n{000000}Hai inserito una password troppo corta\n{00FF00}Consiglio: Usa almeno 3 caratteri ed una password sicura!", "Continua", "Annulla");
  472. //Se va tutto bene inizierà a creare il giocatore nel database
  473. //MD5 è il protocollo di criptografia per la password (puoi anche rimuoverlo dalla stringa lasciandolo: ('%e', '%e')
  474. new infopass[145];
  475. format(infopass, sizeof(infopass), "{f8ff33}[INFO:]{00FF00} La tua password sarà: %s - puoi cambiarla con /cambiapass", inputtext);
  476. SendClientMessage(playerid, 0xFFFFFF, infopass);
  477. format(PlayerInfo[playerid][pPassTmp], 128, inputtext);
  478. //Dopo di chè la query viene inviata e passa al dialogo successivo
  479. // email
  480. ShowPlayerDialog(playerid, DIALOG_REGISTER_EMAIL, DIALOG_STYLE_INPUT, "Registrazione", "{00FF00}Non manca molto:\n{000000}Inserisci una email per continuare\n{00FF00}INFO: Serve per proteggere il tuo account!", "Continua", "Annulla");
  481. return 1;
  482. }
  483. // registrazione email (fase 2)
  484. if(dialogid == DIALOG_REGISTER_EMAIL)
  485. {
  486.  
  487. //Se il giocatore seleziona Annulla/Esci
  488. if(!response) return Kick(playerid);
  489. //In tal caso l'utente inserisci una password troppo breve o non inserisce niente ritorna sullo stesso dialogo
  490. if(strlen(inputtext) < 5) return ShowPlayerDialog(playerid, DIALOG_REGISTER_EMAIL, DIALOG_STYLE_PASSWORD, "Registrazione", "{FF0000}ERRORE:\n{000000}Devi inserire una mail valide\n{00FF00}INFO: Servirà per proteggere meglio il tuo account!", "Continua", "Annulla");
  491. format(PlayerInfo[playerid][pEmail], 64, inputtext);
  492. new query[256];
  493. mysql_format(handle, query, sizeof(query), "INSERT INTO users (name, password, email) VALUES ('%e', MD5('%e'), '%e')", PlayerInfo[playerid][pName], PlayerInfo[playerid][pPassTmp], inputtext);
  494. format(PlayerInfo[playerid][pPassTmp], 128, "");
  495. //Dopo di chè la query viene inviata e passa al dialogo successivo
  496. // età
  497. ShowPlayerDialog(playerid, DIALOG_REGISTER_AGE, DIALOG_STYLE_INPUT, "Registrazione", "Inserisci l'età che vuoi avere nel server\nNon influenzerà il gioco.", "Continua", "Annulla");
  498. return 1;
  499. }
  500. // registrazione età (fase 3)
  501. if(dialogid == DIALOG_REGISTER_AGE)
  502. {
  503.  
  504. //Se il giocatore seleziona Annulla/Esci
  505. if(!response) return Kick(playerid);
  506. //In tal caso l'utente inserisci una password troppo breve o non inserisce niente ritorna sullo stesso dialogo
  507. if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER_EMAIL, DIALOG_STYLE_PASSWORD, "Registrazione", "{FF0000}ERRORE:\n{000000}Devi inserire una mail valide\n{00FF00}INFO: Servirà per proteggere meglio il tuo account!", "Continua", "Annulla");
  508. if(!IsNumeric(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER_AGE, DIALOG_STYLE_INPUT, "Registrazione", "{FF0000}Devi inserire un numero per l'età\n{FFFFFF}Inserisci l'età che vuoi avere nel server\nNon influenzerà il gioco.", "Continua", "Annulla");
  509. // format(PlayerInfo[playerid][pAge], inputtext);
  510. //Dopo di chè la query viene inviata e passa al dialogo successivo
  511. // età
  512. new query[256];
  513. mysql_format(handle, query, sizeof(query), "INSERT INTO users (name, password, email, age) VALUES ('%e', MD5('%e'), '%e', '%d')", PlayerInfo[playerid][pName], PlayerInfo[playerid][pPassTmp], PlayerInfo[playerid][pEmail], inputtext);
  514. mysql_pquery(handle, query, "OnUserRegister", "d", playerid);
  515. format(PlayerInfo[playerid][pPassTmp], 128, "");
  516. return 1;
  517. }
  518.  
  519. if(dialogid == DIALOG_LOGIN)
  520. {
  521. //Spieler hat Abbrechen gewählt
  522. if(!response) return Kick(playerid);
  523.  
  524. //se l'utente inserisce una password troppo corta o non inserisce niente
  525. if(strlen(inputtext) < 3) return ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", "ERRORE:\n{FF0000}Hai inserito una password troppo corta!", "Ok", "Abbrechen");
  526.  
  527. //Wenn alles passt wird die Datenbank ausgelesen
  528. new query[256];
  529. mysql_format(handle, query, sizeof(query), "SELECT * FROM users WHERE name = '%e' AND password = MD5('%e')", PlayerInfo[playerid][pName], inputtext);
  530.  
  531. //Das Query wird abgesendet und die playerid an OnUserLogin übergeben
  532. mysql_pquery(handle, query, "OnUserLogin", "d", playerid);
  533. return 1;
  534. }
  535. return 0;
  536. }
  537.  
  538. public OnPlayerClickPlayer(playerid, clickedplayerid, source)
  539. {
  540. return 1;
  541. }
Advertisement
Add Comment
Please, Sign In to add comment