Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <zcmd>
- #include <YSI\y_ini>
- #include <sscanf2>
- #define COLOR_BLACK 0x2C2727AA
- #define COLOR_GREEN 0x33AA33AA
- #define COLOR_PINK 0xFF66FFAA
- #define COLOR_BLUE 0x0000BBAA
- #define COLOR_WHITE 0xFFFFFFAA
- #define COLOR_LIGHTYELLOW 0x99FF9900
- #define COLOR_GREY 0xAFAFAFAA
- #define COLOR_GREEN 0x33AA33AA
- #define COLOR_RED 0xAA3333AA
- #define COLOR_YELLOW 0xFFFF00AA
- #define COLOR_PINK 0xFF66FFAA
- #define COLOR_BLUE 0x0000BBAA
- #define COLOR_ORANGE 0xFF9900AA
- #define COLOR_PURPLE 0x990099AA
- #define COLOR_BROWN 0x663300AA
- #define COLOR_LIGHTBLUE 0x33CCFFAA
- #define COLOR_DARKRED 0x660000AA
- #define COLOR_DARKBLUE 0x000066AA
- #define DIALOG_RULES 1
- #define DIALOG_TELETRASPORTI 2
- #define REGISTRAZIONE 3
- #define LOGIN 4
- #define PATH "/Giocatori/%s.ini"
- forward CaricaDati_data(playerid,name[],value[]);
- enum Giocatore
- {
- Password,
- Soldi,
- Admin,
- 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]);
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- new pname[MAX_PLAYER_NAME], string[22 + MAX_PLAYER_NAME], INI:File = INI_Open(PercorsoUtente(playerid));
- GetPlayerName(playerid, pname, sizeof(pname));
- format(string, sizeof(string), "%s Si รจ disconnesso.", pname);
- SendClientMessageToAll(COLOR_RED, string);
- if(InfoGiocatore[playerid][Loggato])
- {
- INI_SetTag(File,"data");
- INI_WriteInt(File,"Soldi",GetPlayerMoney(playerid));
- INI_WriteInt(File,"Admin",InfoGiocatore[playerid][Admin]);
- INI_Close(File);
- }
- return 1;
- }
- //Dialog about registration and login
- 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_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);
- GivePlayerMoney(playerid, InfoGiocatore[playerid][Soldi]);
- InfoGiocatore[playerid][Loggato] = true;
- }
- else ShowPlayerDialog(playerid, LOGIN, DIALOG_STYLE_INPUT, "Login", "Digita la password:", "Avanti", "Esci");
- }
- }
- /*---------------------------------------------------------------*/
Advertisement
Add Comment
Please, Sign In to add comment