Advertisement
Guest User

Untitled

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