Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define PATH "/Giocatori/%s.ini"
- forward CaricaDati_data(playerid,name[],value[]);
- enum Giocatore
- {
- Password,
- Soldi,
- Admin,
- Banned,
- Score,
- bool:Loggato[MAX_PLAYERS]
- }
- new InfoGiocatore[MAX_PLAYERS][Giocatore];
- PercorsoUtente(playerid)
- {
- new string[128],playername[MAX_PLAYER_NAME];
- GetPlayerName(playerid,playername,sizeof(playername));
- format(string,sizeof(string),PATH,playername);
- return string;
- }
- udb_hash(buf[])
- {
- new length=strlen(buf);
- new s1 = 1;
- new s2 = 0;
- new n;
- for (n=0; n<length; n++)
- {
- s1 = (s1 + buf[n]) % 65521;
- s2 = (s2 + s1) % 65521;
- }
- return (s2 << 16) + s1;
- }
- public CaricaDati_data(playerid,name[],value[])
- {
- INI_Int("Password", InfoGiocatore[playerid][Password]);
- INI_Int("Soldi", InfoGiocatore[playerid][Soldi]);
- INI_Int("Admin", InfoGiocatore[playerid][Admin]);
- INI_Int("Banned", InfoGiocatore[playerid][Banned]);
- INI_Int("Score", InfoGiocatore[playerid][Score]);
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- if(InfoGiocatore[playerid][Loggato])
- {
- INI_SetTag(File,"data");
- INI_WriteInt(File,"Soldi",GetPlayerMoney(playerid));
- INI_WriteInt(File,"Admin",InfoGiocatore[playerid][Admin]);
- INI_WriteInt(File,"Banned",InfoGiocatore[playerid][Banned]);
- INI_WriteInt(File,"Score",InfoGiocatore[playerid][Score]);
- INI_Close(File);
- }
- return 1;
- }
- //Registration
- /*Registazione */
- if(dialogid == REGISTRAZIONE)
- {
- if(!response) return Kick(playerid);
- if(response)
- {
- if(!strlen(inputtext) || strlen(inputtext) < 4 || strlen(inputtext) > 16) return ShowPlayerDialog(playerid, REGISTRAZIONE, DIALOG_STYLE_INPUT, "Registrazione", "ERRORE: La password deve essere compresa fra i 4 e 16 caratteri.\nDigita la password:", "Avanti", "Esci");
- new INI:File = INI_Open(PercorsoUtente(playerid));
- INI_WriteInt(File, "Password", udb_hash(inputtext));
- INI_WriteInt(File, "Soldi",0);
- INI_WriteInt(File, "Admin",0);
- INI_WriteInt(File, "Banned",0);
- INI_WriteInt(File, "Score",0);
- INI_Close(File);
- InfoGiocatore[playerid][Loggato] = true;
- }
- }
- /* Login */
- if(dialogid == LOGIN)
- {
- if(!response) return Kick(playerid);
- if(response)
- {
- if(udb_hash(inputtext) == InfoGiocatore[playerid][Password])
- {
- INI_ParseFile(PercorsoUtente(playerid), "CaricaDati_%s", .bExtra = true, .extra = playerid);
- if(InfoGiocatore[playerid][Banned] == 1) return Kick(playerid);
- GivePlayerMoney(playerid, InfoGiocatore[playerid][Soldi]);
- SetPlayerScore(playerid, InfoGiocatore[playerid][Score]);
- InfoGiocatore[playerid][Loggato] = true;
- }
- else ShowPlayerDialog(playerid, LOGIN, DIALOG_STYLE_INPUT, "Login", "Digita la password:", "Avanti", "Esci");
- }
- }
- return 1;
- }
- CMD:punti(playerid, params[])
- {
- new targetid, score;
- if(InfoGiocatore[playerid][Admin] > 0)
- {
- if(sscanf(params,"ui", targetid, score)) return print("Giocatore ggo");
- SetPlayerScore(targetid, score);
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment