Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define PATH "Utenza/%s.ini" // definisco la directory dove verra salvato il file ini riguardante il singolo giocatore
- forward Spawn(playerid);
- forward CaricaDatiUtente(playerid,name[],value[]); //forward della funzione CaricaDatiUtente a finchè possa essere ricordata
- new Loggato[MAX_PLAYERS];
- stock ClearChat(playerid, times) //Pulisce la chat al giocatore
- {
- for(new j=0; j<times; j++)
- {
- SendClientMessage(playerid, -1, "");
- }
- return 1;
- }
- stock PathUtente(playerid)// Creo una funzione di immagazinamento per i file dati del singolo utente
- {
- new stringa[128],nomeplayer[MAX_PLAYER_NAME]; //Dichiaro una stringa grande 128, e nomeplayer grande il massimo possibile per il nome di un giocatore
- GetPlayerName(playerid,nomeplayer,sizeof(nomeplayer)); //Getto il nome del player nella mia variabile nomeplayer
- format(stringa,sizeof(stringa),PATH,nomeplayer); //formatto una stringa che sarà l'equivalente di nomeplayer nel PATH di destinazione
- return stringa; //Quindi ritorno la stringa
- }
- enum Utente // definisco un contenitore enum che conterrà le informazione del singolo giocatore
- {
- Password, // contenitore della password
- Soldi, // contenitore dei soldi
- Skin, //contenitore della skin
- Admin // contenitore del livello admin
- }
- new Info[MAX_PLAYERS][Utente];
- // Credits to Dracoblue - la funzione d'immagazzinamento serve per creare una stringra criptata.
- stock 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 CaricaDatiUtente(playerid,name[],value[])
- {
- INI_Int("Password",Info[playerid][Password]); //INI_Int legge l'intero salvato nel contenitore gPassword,
- INI_Int("Soldi",Info[playerid][Soldi]);
- INI_Int("Skin",Info[playerid][Skin]);
- INI_Int("LivelloAdmin",Info[playerid][Admin]);
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- switch(dialogid)
- {
- case 1: //Login
- {
- if(!response)
- {
- Kick(playerid);
- }
- if(response)
- {
- if(strlen(inputtext) < 3 || strlen(inputtext) > 12) return ShowPlayerDialog(playerid,Registrazione,DIALOG_STYLE_INPUT,"Registrazione!","La tua password deve avere minimo 3 caratteri e massimo 12!","Registrati!","Esci");
- new INI:File = INI_Open(PathUtente(playerid)); // inizio la scrittura del file ini all'interno della directori utenza
- INI_SetTag(File,"Informazioni Account"); // Do un intestazione al file ini
- INI_WriteInt(File,"Password",udb_hash(inputtext)); //Scrivo la Password data dall'utente e con la funzione udb_hash la cripto
- INI_WriteInt(File,"Soldi",0); // Scrivo i soldi del player
- INI_WriteInt(File,"Skin", 0); // Scrivo la skin del player
- INI_WriteInt(File,"Admin",0); //Scrivo il livello di admin
- INI_Close(File);
- }
- }
- case 2: //Registrazione
- {
- if(!response)
- {
- Kick(playerid);
- }
- if(response)
- {
- if(udb_hash(inputtext) == Info[playerid][Password])
- {
- INI_ParseFile(PathUtente(playerid),"CaricamentoDatiUtente_%s", .bExtra = true, .extra = playerid);
- GivePlayerMoney(playerid,Info[playerid][Soldi]);
- SetPlayerSkin(playerid,Info[playerid][Skin]);
- Loggato[playerid] = 1;
- SendClientMessage(playerid, Azzurro, "Hai loggato con successo!");
- }
- }
- }
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement