Advertisement
Guest User

Untitled

a guest
Jan 20th, 2019
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.89 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.  
  10.  
  11. // Sezione define
  12. // Connessione MySQL (in caso di editing cambia solo i campi tra le ""
  13. #define MYSQL_HOST "127.0.0.1" //IP del server host (es: localhost/127.0.0.1
  14. #define MYSQL_USER "root" //Username a cui accedere (di default è root)
  15. #define MYSQL_PASS "Pass123!" //Password per accedere al protocollo MySQL
  16. #define MYSQL_DBSE "dbrp" //Nome del database
  17. new MySQL:handle; // l'Handle di connessione per connettersi al databse
  18.  
  19. // dialoghi registrazione/login
  20. #define DIALOG_REGISTER 1
  21. #define DIALOG_REGISTER_EMAIL 2
  22. #define DIALOG_LOGIN 10
  23.  
  24.  
  25.  
  26.  
  27.  
  28. // lista denominazioni delle statistiche
  29. enum pDataEnum
  30. {
  31. p_id,
  32. bool:pLoggedIn,
  33. pName[MAX_PLAYER_NAME],
  34. pLevel,
  35. pMoney,
  36. pKills,
  37. pEmail[64],
  38. pDeaths
  39. }
  40. new PlayerInfo[MAX_PLAYERS][pDataEnum];
  41.  
  42.  
  43.  
  44. // non cancellare
  45. // usercheck, controllo del giocatore
  46. forward OnUserCheck(playerid);
  47. public OnUserCheck(playerid)
  48. {
  49. //Query inizializzata con successo nella chache, passa al check
  50. new rows;
  51. cache_get_row_count(rows);
  52. if(rows == 0)
  53. {
  54. //Giocatore nont rovato nel database, quindi passa alla registrazione
  55. ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Registrazione", "Inserisci una password per iniziare la registrazione:", "Continua", "Annulla");
  56. }
  57. else
  58. {
  59. //Giocatore trovato, quindi passa al login
  60. ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", "Prego inserisci la password per entrare nel server:", "Login", "Esci");
  61. }
  62. return 1;
  63. }
  64.  
  65. // non cancellare
  66. // onuserregister - quando il giocatore finisce di registrarsi
  67. forward OnUserRegister(playerid);
  68. public OnUserRegister(playerid)
  69. {
  70. //L'utente ha finito la registrazione e viene inserito nel database
  71. //Una volta finito inserirà l'id nella cache e imposterà l'accesso su true (accesso effettuato)
  72. PlayerInfo[playerid][p_id] = cache_insert_id();
  73. PlayerInfo[playerid][pLoggedIn] = true;
  74. SendClientMessage(playerid, 0x00FF00FF, "[SERVER:] Registrazione effettuata con successo.");
  75. return 1;
  76. }
  77.  
  78. //non cancellare
  79. // quando un utente si collega al server
  80. forward OnUserLogin(playerid);
  81. public OnUserLogin(playerid)
  82. {
  83. //Query wurde ausgeführt und das Ergebnis im Cache gespeichert
  84. new rows;
  85. cache_get_row_count(rows);
  86. if(rows == 0)
  87. {
  88. //In caso di login l'utente inserisce una password errata
  89. ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", "{FF0000}ERRORE:\n{FF0000}Password errata\n{0F22FF}Riprova:!", "Login", "Esci");
  90. }
  91. else
  92. {
  93. //Es existiert ein Ergebnis, das heißt der Spieler hat das richtige Passwort eingegeben
  94. //Wir lesen nun die erste Zeile des Caches aus (ID 0)
  95. cache_get_value_name_int(0, "id", PlayerInfo[playerid][p_id]);
  96. cache_get_value_name_int(0, "level", PlayerInfo[playerid][pLevel]);
  97. cache_get_value_name_int(0, "money", PlayerInfo[playerid][pMoney]);
  98. cache_get_value_name_int(0, "kills", PlayerInfo[playerid][pKills]);
  99. cache_get_value_name_int(0, "deaths", PlayerInfo[playerid][pDeaths]);
  100. cache_get_value_name(0, "email", PlayerInfo[playerid][pEmail],64);
  101. PlayerInfo[playerid][pLoggedIn] = true;
  102. SendClientMessage(playerid, 0x00FF00FF, "[INFO:] Login con successo.");
  103. GivePlayerMoney(playerid, PlayerInfo[playerid][pMoney]);
  104. }
  105. return 1;
  106. }
  107. // non cancellare
  108. // quando un utente si scollega salva prima le statistiche
  109. stock SaveUserStats(playerid)
  110. {
  111. //Se non ha effettuato l'accesso il giocatore, non salva le statistiche
  112. if(!PlayerInfo[playerid][pLoggedIn]) return 1;
  113.  
  114. //Se ha già effettuato l'accesso salva le statistiche
  115.  
  116. new playeremail[64];
  117. format(playeremail, 64, PlayerInfo[playerid][pEmail]);
  118. new livello = PlayerInfo[playerid][pLevel];
  119. new soldi = PlayerInfo[playerid][pMoney];
  120. new kills = PlayerInfo[playerid][pKills];
  121. new morti = PlayerInfo[playerid][pDeaths];
  122. new giocaotreid = PlayerInfo[playerid][p_id];
  123.  
  124. new query[256];
  125. mysql_format(handle, query, sizeof(query),
  126. "UPDATE users SET email = '%s', level = '%d', money = '%d', kills = '%d', deaths = '%d' WHERE id = '%d'",
  127. playeremail, livello, soldi, kills, morti, giocaotreid);
  128.  
  129.  
  130. //Query inviata
  131. mysql_pquery(handle, query);
  132. return 1;
  133. }
  134. // non cancellare
  135. // setup della connessione al MySQL
  136. stock MySQL_SetupConnection(ttl = 3)
  137. {
  138. print("[MySQL] Verbindungsaufbau...");
  139. //mysql_log(); //<- Kommentar vor mysql_log entfernen um den MySQL Debug-Modus zu aktivieren
  140.  
  141. handle = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_DBSE);
  142.  
  143. //Prüfen und gegebenenfalls wiederholen
  144. if(mysql_errno(handle) != 0)
  145. {
  146. //Fehler im Verbindungsaufbau, prüfe ob ein weiterer Versuch gestartet werden soll
  147. if(ttl > 1)
  148. {
  149. //Versuche erneut eine Verbindung aufzubauen
  150. print("[MySQL] Es konnte keine Verbindung zur Datenbank hergestellt werden.");
  151. printf("[MySQL] Starte neuen Verbindungsversuch (TTL: %d).", ttl-1);
  152. return MySQL_SetupConnection(ttl-1);
  153. }
  154. else
  155. {
  156. //Abbrechen und Server schließen
  157. print("[MySQL] Es konnte keine Verbindung zur Datenbank hergestellt werden.");
  158. print("[MySQL] Bitte prüfen Sie die Verbindungsdaten.");
  159. print("[MySQL] Der Server wird heruntergefahren.");
  160. return SendRconCommand("exit");
  161. }
  162. }
  163. printf("[MySQL] Die Verbindung zur Datenbank wurde erfolgreich hergestellt! Handle: %d", _:handle);
  164. return 1;
  165. }
  166.  
  167. #if defined FILTERSCRIPT
  168.  
  169. public OnFilterScriptInit()
  170. {
  171. print("\n--------------------------------------");
  172. print(" Blank Filterscript by your name here");
  173. print("--------------------------------------\n");
  174. return 1;
  175. }
  176.  
  177. public OnFilterScriptExit()
  178. {
  179. return 1;
  180. }
  181.  
  182. #else
  183.  
  184. main()
  185. {
  186. print("\n----------------------------------");
  187. print("GameMode RP By: OuDayas v1.0");
  188. print("Non modificare la GM dove lo trovi indicato");
  189. print("----------------------------------\n");
  190. }
  191.  
  192. #endif
  193.  
  194. public OnGameModeInit()
  195. {
  196. MySQL_SetupConnection(); // inizio della connessione al MySQL
  197. SetGameModeText("Blank Script");
  198. AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
  199.  
  200. return 1;
  201. }
  202.  
  203. public OnGameModeExit()
  204. {
  205. mysql_close(handle);
  206. return 1;
  207. }
  208.  
  209. public OnPlayerRequestClass(playerid, classid)
  210. {
  211. // da qui non modificare
  212. //Quando il giocatore entra nella "request class" controlla se ha effettuato il login
  213. if(!PlayerInfo[playerid][pLoggedIn])
  214. {
  215. SendClientMessage(playerid, 0xFF0000, "[ERRORE:] Devi prima effettuare l'accesso per entrare");
  216. //In caso contrario controlla se ha un'account
  217. //Invia una query di controllo dove viene richiamata
  218. //%e sta per una stringa già verificata (usata al posto di %s nelle query)
  219. new query[128];
  220. mysql_format(handle, query, sizeof(query), "SELECT id FROM users WHERE name = '%e'", PlayerInfo[playerid][pName]);
  221.  
  222. //La query dopo essere stata inviata, la passxa al "OnUserCheck"
  223. mysql_pquery(handle, query, "OnUserCheck", "d", playerid);
  224. }
  225. return 1;
  226. }
  227.  
  228. public OnPlayerConnect(playerid)
  229. {
  230. PlayerInfo[playerid][p_id] = 0;
  231. PlayerInfo[playerid][pLoggedIn] = false;
  232. PlayerInfo[playerid][pLevel] = 0;
  233. PlayerInfo[playerid][pMoney] = 0;
  234. PlayerInfo[playerid][pKills] = 0;
  235. PlayerInfo[playerid][pDeaths] = 0;
  236. format(PlayerInfo[playerid][pEmail], 64, "");
  237. GetPlayerName(playerid, PlayerInfo[playerid][pName], MAX_PLAYER_NAME);
  238. return 1;
  239. }
  240.  
  241. public OnPlayerDisconnect(playerid, reason)
  242. {
  243. SaveUserStats(playerid);
  244. return 1;
  245. }
  246.  
  247. public OnPlayerSpawn(playerid)
  248. {
  249. return 1;
  250. }
  251.  
  252. public OnPlayerDeath(playerid, killerid, reason)
  253. {
  254. return 1;
  255. }
  256.  
  257. public OnVehicleSpawn(vehicleid)
  258. {
  259. return 1;
  260. }
  261.  
  262. public OnVehicleDeath(vehicleid, killerid)
  263. {
  264. return 1;
  265. }
  266.  
  267. public OnPlayerText(playerid, text[])
  268. {
  269. return 1;
  270. }
  271.  
  272. public OnPlayerCommandText(playerid, cmdtext[])
  273. {
  274. if (strcmp("/mycommand", cmdtext, true, 10) == 0)
  275. {
  276. // Do something here
  277. return 1;
  278. }
  279. return 0;
  280. }
  281.  
  282. public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
  283. {
  284. return 1;
  285. }
  286.  
  287. public OnPlayerExitVehicle(playerid, vehicleid)
  288. {
  289. return 1;
  290. }
  291.  
  292. public OnPlayerStateChange(playerid, newstate, oldstate)
  293. {
  294. return 1;
  295. }
  296.  
  297. public OnPlayerEnterCheckpoint(playerid)
  298. {
  299. return 1;
  300. }
  301.  
  302. public OnPlayerLeaveCheckpoint(playerid)
  303. {
  304. return 1;
  305. }
  306.  
  307. public OnPlayerEnterRaceCheckpoint(playerid)
  308. {
  309. return 1;
  310. }
  311.  
  312. public OnPlayerLeaveRaceCheckpoint(playerid)
  313. {
  314. return 1;
  315. }
  316.  
  317. public OnRconCommand(cmd[])
  318. {
  319. return 1;
  320. }
  321.  
  322. public OnPlayerRequestSpawn(playerid)
  323. {
  324. return 1;
  325. }
  326.  
  327. public OnObjectMoved(objectid)
  328. {
  329. return 1;
  330. }
  331.  
  332. public OnPlayerObjectMoved(playerid, objectid)
  333. {
  334. return 1;
  335. }
  336.  
  337. public OnPlayerPickUpPickup(playerid, pickupid)
  338. {
  339. return 1;
  340. }
  341.  
  342. public OnVehicleMod(playerid, vehicleid, componentid)
  343. {
  344. return 1;
  345. }
  346.  
  347. public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
  348. {
  349. return 1;
  350. }
  351.  
  352. public OnVehicleRespray(playerid, vehicleid, color1, color2)
  353. {
  354. return 1;
  355. }
  356.  
  357. public OnPlayerSelectedMenuRow(playerid, row)
  358. {
  359. return 1;
  360. }
  361.  
  362. public OnPlayerExitedMenu(playerid)
  363. {
  364. return 1;
  365. }
  366.  
  367. public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
  368. {
  369. return 1;
  370. }
  371.  
  372. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  373. {
  374. return 1;
  375. }
  376.  
  377. public OnRconLoginAttempt(ip[], password[], success)
  378. {
  379. return 1;
  380. }
  381.  
  382. public OnPlayerUpdate(playerid)
  383. {
  384. return 1;
  385. }
  386.  
  387. public OnPlayerStreamIn(playerid, forplayerid)
  388. {
  389. return 1;
  390. }
  391.  
  392. public OnPlayerStreamOut(playerid, forplayerid)
  393. {
  394. return 1;
  395. }
  396.  
  397. public OnVehicleStreamIn(vehicleid, forplayerid)
  398. {
  399. return 1;
  400. }
  401.  
  402. public OnVehicleStreamOut(vehicleid, forplayerid)
  403. {
  404. return 1;
  405. }
  406.  
  407. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  408. {
  409. if(dialogid == DIALOG_REGISTER)
  410. {
  411. //Se il giocatore seleziona Annulla/Esci
  412. if(!response) return Kick(playerid);
  413.  
  414. //In tal caso l'utente inserisci una password troppo breve o non inserisce niente ritorna sullo stesso dialogo
  415. 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");
  416. //Se va tutto bene inizierà a creare il giocatore nel database
  417. //MD5 è il protocollo di criptografia per la password (puoi anche rimuoverlo dalla stringa lasciandolo: ('%e', '%e')
  418. new query[256];
  419. mysql_format(handle, query, sizeof(query), "INSERT INTO users (name, password) VALUES ('%e', MD5('%e'))", PlayerInfo[playerid][pName], inputtext);
  420. new infopass[64];
  421. format(infopass, sizeof(infopass), "{f8ff33}[INFO:]{00FF00} La tua password sarà: %s - puoi cambiarla con /cambiapassword", inputtext);
  422. SendClientMessage(playerid, 0xFFFFFF, infopass);
  423. //Dopo di chè la query viene inviata e passa al dialogo successivo
  424. // email
  425. // mysql_pquery(handle, query, "OnUserRegister", "d", playerid);
  426. 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");
  427. return 1;
  428. }
  429.  
  430. if(dialogid == DIALOG_REGISTER_EMAIL)
  431. {
  432.  
  433. //Se il giocatore seleziona Annulla/Esci
  434. if(!response) return Kick(playerid);
  435. //In tal caso l'utente inserisci una password troppo breve o non inserisce niente ritorna sullo stesso dialogo
  436. 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");
  437. format(PlayerInfo[playerid][pEmail], 64, inputtext);
  438. //Dopo di chè la query viene inviata e passa al dialogo successivo
  439. // età
  440. new query[256];
  441. mysql_pquery(handle, query, "OnUserRegister", "d", playerid)
  442. return 1;
  443. }
  444.  
  445. if(dialogid == DIALOG_LOGIN)
  446. {
  447. //Spieler hat Abbrechen gewählt
  448. if(!response) return Kick(playerid);
  449.  
  450. //se l'utente inserisce una password troppo corta o non inserisce niente
  451. if(strlen(inputtext) < 3) return ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", "ERRORE:\n{FF0000}Hai inserito una password troppo corta!", "Ok", "Abbrechen");
  452.  
  453. //Wenn alles passt wird die Datenbank ausgelesen
  454. new query[256];
  455. mysql_format(handle, query, sizeof(query), "SELECT * FROM users WHERE name = '%e' AND password = MD5('%e')", PlayerInfo[playerid][pName], inputtext);
  456.  
  457. //Das Query wird abgesendet und die playerid an OnUserLogin übergeben
  458. mysql_pquery(handle, query, "OnUserLogin", "d", playerid);
  459. return 1;
  460. }
  461. return 0;
  462. }
  463.  
  464. public OnPlayerClickPlayer(playerid, clickedplayerid, source)
  465. {
  466. return 1;
  467. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement