Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*=====================================================*
- * GM RP by: OuDayas
- * Version: 1.0
- *
- *======================================================*/
- // Sezione include
- #include <a_samp> // include base: NON ELIMINARE O NON PARTIÀ
- #include <a_mysql> // Include per la connessione al: MySQL
- // Sezione define
- // Connessione MySQL (in caso di editing cambia solo i campi tra le ""
- #define MYSQL_HOST "127.0.0.1" //IP del server host (es: localhost/127.0.0.1
- #define MYSQL_USER "root" //Username a cui accedere (di default è root)
- #define MYSQL_PASS "Pass123!" //Password per accedere al protocollo MySQL
- #define MYSQL_DBSE "dbrp" //Nome del database
- new MySQL:handle; // l'Handle di connessione per connettersi al databse
- // dialoghi registrazione/login
- #define DIALOG_REGISTER 1
- #define DIALOG_REGISTER_EMAIL 2
- #define DIALOG_LOGIN 10
- // lista denominazioni delle statistiche
- enum pDataEnum
- {
- p_id,
- bool:pLoggedIn,
- pName[MAX_PLAYER_NAME],
- pLevel,
- pMoney,
- pKills,
- pEmail[64],
- pDeaths
- }
- new PlayerInfo[MAX_PLAYERS][pDataEnum];
- // non cancellare
- // usercheck, controllo del giocatore
- forward OnUserCheck(playerid);
- public OnUserCheck(playerid)
- {
- //Query inizializzata con successo nella chache, passa al check
- new rows;
- cache_get_row_count(rows);
- if(rows == 0)
- {
- //Giocatore nont rovato nel database, quindi passa alla registrazione
- ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Registrazione", "Inserisci una password per iniziare la registrazione:", "Continua", "Annulla");
- }
- else
- {
- //Giocatore trovato, quindi passa al login
- ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", "Prego inserisci la password per entrare nel server:", "Login", "Esci");
- }
- return 1;
- }
- // non cancellare
- // onuserregister - quando il giocatore finisce di registrarsi
- forward OnUserRegister(playerid);
- public OnUserRegister(playerid)
- {
- //Der Spieler wurde in die Datenbank eingetragen, es wird die id ausgelesen
- PlayerInfo[playerid][p_id] = cache_insert_id();
- PlayerInfo[playerid][pLoggedIn] = true;
- SendClientMessage(playerid, 0x00FF00FF, "[SERVER:] Registrazione effettuata con successo.");
- return 1;
- }
- //non cancellare
- // quando un utente si collega al server
- forward OnUserLogin(playerid);
- public OnUserLogin(playerid)
- {
- //Query wurde ausgeführt und das Ergebnis im Cache gespeichert
- new rows;
- cache_get_row_count(rows);
- if(rows == 0)
- {
- //In caso di login l'utente inserisce una password errata
- ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", "{FF0000}ERRORE:\n{FF0000}Password errata\n{0F22FF}Riprova:!", "Login", "Esci");
- }
- else
- {
- //Es existiert ein Ergebnis, das heißt der Spieler hat das richtige Passwort eingegeben
- //Wir lesen nun die erste Zeile des Caches aus (ID 0)
- cache_get_value_name_int(0, "id", PlayerInfo[playerid][p_id]);
- cache_get_value_name_int(0, "level", PlayerInfo[playerid][pLevel]);
- cache_get_value_name_int(0, "money", PlayerInfo[playerid][pMoney]);
- cache_get_value_name_int(0, "kills", PlayerInfo[playerid][pKills]);
- cache_get_value_name_int(0, "deaths", PlayerInfo[playerid][pDeaths]);
- cache_get_value_name(0, "email", PlayerInfo[playerid][pEmail],64);
- PlayerInfo[playerid][pLoggedIn] = true;
- SendClientMessage(playerid, 0x00FF00FF, "[Konto] Eingeloggt.");
- GivePlayerMoney(playerid, PlayerInfo[playerid][pMoney]);
- }
- return 1;
- }
- // non cancellare
- // quando un utente si scollega salva prima le statistiche
- stock SaveUserStats(playerid)
- {
- //Wenn der Spieler nicht eingeloggt ist, dann speichere seine Statistiken nicht
- if(!PlayerInfo[playerid][pLoggedIn]) return 1;
- //Ansonsten speichere sie
- new playeremail[64];
- format(playeremail, 64, PlayerInfo[playerid][pEmail]);
- new livello = PlayerInfo[playerid][pLevel];
- new soldi = PlayerInfo[playerid][pMoney];
- new kills = PlayerInfo[playerid][pKills];
- new morti = PlayerInfo[playerid][pDeaths];
- new giocaotreid = PlayerInfo[playerid][p_id];
- new query[256];
- mysql_format(handle, query, sizeof(query),
- "UPDATE users SET email = '%s', level = '%d', money = '%d', kills = '%d', deaths = '%d' WHERE id = '%d'",
- playeremail, livello, soldi, kills, morti, giocaotreid);
- //Das Query wird abgesendet
- mysql_pquery(handle, query);
- return 1;
- }
- // non cancellare
- // setup della connessione al MySQL
- stock MySQL_SetupConnection(ttl = 3)
- {
- print("[MySQL] Verbindungsaufbau...");
- //mysql_log(); //<- Kommentar vor mysql_log entfernen um den MySQL Debug-Modus zu aktivieren
- handle = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_DBSE);
- //Prüfen und gegebenenfalls wiederholen
- if(mysql_errno(handle) != 0)
- {
- //Fehler im Verbindungsaufbau, prüfe ob ein weiterer Versuch gestartet werden soll
- if(ttl > 1)
- {
- //Versuche erneut eine Verbindung aufzubauen
- print("[MySQL] Es konnte keine Verbindung zur Datenbank hergestellt werden.");
- printf("[MySQL] Starte neuen Verbindungsversuch (TTL: %d).", ttl-1);
- return MySQL_SetupConnection(ttl-1);
- }
- else
- {
- //Abbrechen und Server schließen
- print("[MySQL] Es konnte keine Verbindung zur Datenbank hergestellt werden.");
- print("[MySQL] Bitte prüfen Sie die Verbindungsdaten.");
- print("[MySQL] Der Server wird heruntergefahren.");
- return SendRconCommand("exit");
- }
- }
- printf("[MySQL] Die Verbindung zur Datenbank wurde erfolgreich hergestellt! Handle: %d", _:handle);
- return 1;
- }
- #if defined FILTERSCRIPT
- public OnFilterScriptInit()
- {
- print("\n--------------------------------------");
- print(" Blank Filterscript by your name here");
- print("--------------------------------------\n");
- return 1;
- }
- public OnFilterScriptExit()
- {
- return 1;
- }
- #else
- main()
- {
- print("\n----------------------------------");
- print("GameMode RP By: OuDayas v1.0");
- print("Non modificare la GM dove lo trovi indicato");
- print("----------------------------------\n");
- }
- #endif
- public OnGameModeInit()
- {
- MySQL_SetupConnection(); // inizio della connessione al MySQL
- SetGameModeText("Blank Script");
- AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
- return 1;
- }
- public OnGameModeExit()
- {
- mysql_close(handle);
- return 1;
- }
- public OnPlayerRequestClass(playerid, classid)
- {
- // quando il player si connette setta dove la visuale deve guardare
- // modifica le coordinate a tuo piacimento
- SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
- SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
- SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
- // da qui non modificare
- //Quando il giocatore entra nella "request class" controlla se ha effettuato il login
- if(!PlayerInfo[playerid][pLoggedIn])
- {
- //In caso contrario controlla se ha un'account
- //Invia una query di controllo dove viene richiamata
- //%e sta per una stringa già verificata (usata al posto di %s nelle query)
- new query[128];
- mysql_format(handle, query, sizeof(query), "SELECT id FROM users WHERE name = '%e'", PlayerInfo[playerid][pName]);
- //La query dopo essere stata inviata, la passxa al "OnUserCheck"
- mysql_pquery(handle, query, "OnUserCheck", "d", playerid);
- }
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- PlayerInfo[playerid][p_id] = 0;
- PlayerInfo[playerid][pLoggedIn] = false;
- PlayerInfo[playerid][pLevel] = 0;
- PlayerInfo[playerid][pMoney] = 0;
- PlayerInfo[playerid][pKills] = 0;
- PlayerInfo[playerid][pDeaths] = 0;
- PlayerInfo[playerid][pEmail] = "";
- GetPlayerName(playerid, PlayerInfo[playerid][pName], MAX_PLAYER_NAME);
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- SaveUserStats(playerid);
- return 1;
- }
- public OnPlayerSpawn(playerid)
- {
- return 1;
- }
- public OnPlayerDeath(playerid, killerid, reason)
- {
- return 1;
- }
- public OnVehicleSpawn(vehicleid)
- {
- return 1;
- }
- public OnVehicleDeath(vehicleid, killerid)
- {
- return 1;
- }
- public OnPlayerText(playerid, text[])
- {
- return 1;
- }
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- if (strcmp("/mycommand", cmdtext, true, 10) == 0)
- {
- // Do something here
- return 1;
- }
- return 0;
- }
- public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
- {
- return 1;
- }
- public OnPlayerExitVehicle(playerid, vehicleid)
- {
- return 1;
- }
- public OnPlayerStateChange(playerid, newstate, oldstate)
- {
- return 1;
- }
- public OnPlayerEnterCheckpoint(playerid)
- {
- return 1;
- }
- public OnPlayerLeaveCheckpoint(playerid)
- {
- return 1;
- }
- public OnPlayerEnterRaceCheckpoint(playerid)
- {
- return 1;
- }
- public OnPlayerLeaveRaceCheckpoint(playerid)
- {
- return 1;
- }
- public OnRconCommand(cmd[])
- {
- return 1;
- }
- public OnPlayerRequestSpawn(playerid)
- {
- return 1;
- }
- public OnObjectMoved(objectid)
- {
- return 1;
- }
- public OnPlayerObjectMoved(playerid, objectid)
- {
- return 1;
- }
- public OnPlayerPickUpPickup(playerid, pickupid)
- {
- return 1;
- }
- public OnVehicleMod(playerid, vehicleid, componentid)
- {
- return 1;
- }
- public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
- {
- return 1;
- }
- public OnVehicleRespray(playerid, vehicleid, color1, color2)
- {
- return 1;
- }
- public OnPlayerSelectedMenuRow(playerid, row)
- {
- return 1;
- }
- public OnPlayerExitedMenu(playerid)
- {
- return 1;
- }
- public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
- {
- return 1;
- }
- public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
- {
- return 1;
- }
- public OnRconLoginAttempt(ip[], password[], success)
- {
- return 1;
- }
- public OnPlayerUpdate(playerid)
- {
- return 1;
- }
- public OnPlayerStreamIn(playerid, forplayerid)
- {
- return 1;
- }
- public OnPlayerStreamOut(playerid, forplayerid)
- {
- return 1;
- }
- public OnVehicleStreamIn(vehicleid, forplayerid)
- {
- return 1;
- }
- public OnVehicleStreamOut(vehicleid, forplayerid)
- {
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- if(dialogid == DIALOG_REGISTER)
- {
- //Se il giocatore seleziona Annulla/Esci
- if(!response) return Kick(playerid);
- //In tal caso l'utente inserisci una password troppo breve o non inserisce niente ritorna sullo stesso dialogo
- 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");
- //Se va tutto bene inizierà a creare il giocatore nel database
- //MD5 è il protocollo di criptografia per la password (puoi anche rimuoverlo dalla stringa lasciandolo: ('%e', '%e')
- new query[256];
- mysql_format(handle, query, sizeof(query), "INSERT INTO users (name, password) VALUES ('%e', MD5('%e'))", PlayerInfo[playerid][pName], inputtext);
- // new infopass[64];
- // format(infopass, sizeof(infopass), "{f8ff33}[INFO:]{00FF00} La tua password sarà: %s - puoi cambiarla con /cambiapassword", inputtext);
- //Dopo di chè la query viene inviata e passa al dialogo successivo
- // email
- 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");
- // mysql_pquery(handle, query, "OnUserRegister", "d", playerid);
- return 1;
- }
- if(dialogid == DIALOG_REGISTER_EMAIL)
- {
- //Se il giocatore seleziona Annulla/Esci
- if(!response) return Kick(playerid);
- //In tal caso l'utente inserisci una password troppo breve o non inserisce niente ritorna sullo stesso dialogo
- 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");
- //Se va tutto bene inizierà a creare il giocatore nel database
- //MD5 è il protocollo di criptografia per la password (puoi anche rimuoverlo dalla stringa lasciandolo: ('%e', '%e')
- new query[256];
- mysql_format(handle, query, sizeof(query), "INSERT INTO users (email) VALUES ('%e')", inputtext);
- //Dopo di chè la query viene inviata e passa al dialogo successivo
- // età
- mysql_pquery(handle, query, "OnUserRegister", "d", playerid);
- return 1;
- }
- if(dialogid == DIALOG_LOGIN)
- {
- //Spieler hat Abbrechen gewählt
- if(!response) return Kick(playerid);
- //se l'utente inserisce una password troppo corta o non inserisce niente
- if(strlen(inputtext) < 3) return ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", "ERRORE:\n{FF0000}Hai inserito una password troppo corta!", "Ok", "Abbrechen");
- //Wenn alles passt wird die Datenbank ausgelesen
- new query[256];
- mysql_format(handle, query, sizeof(query), "SELECT * FROM users WHERE name = '%e' AND password = MD5('%e')", PlayerInfo[playerid][pName], inputtext);
- //Das Query wird abgesendet und die playerid an OnUserLogin übergeben
- mysql_pquery(handle, query, "OnUserLogin", "d", playerid);
- return 1;
- }
- return 0;
- }
- public OnPlayerClickPlayer(playerid, clickedplayerid, source)
- {
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement