Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- :::::::::::::::::::::::::::::::::::::::::::::::::
- ::
- :: Register/Login
- :: System
- ::
- ::
- :::::::::::::::::::::::::::::::::::::::::::::::::
- */
- #include <a_samp>
- #include <dini>
- #define DIALOG_REGISTER 1
- #define DIALOG_LOGIN 2
- public OnPlayerConnect(playerid)
- {
- new data[64];
- new name[MAX_PLAYER_NAME];
- GetPlayerName(playerid, name, sizeof(name));
- format(data, sizeof(data), "/Accounts/%s.txt", name);
- if(dini_Exists(data))
- {
- ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login", "Please login by typing you password below.", "Login", "Cancel");
- SetPlayerScore(playerid, dini_Int(data, "Score"));
- return 1;
- }
- ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Register", "Please register by typing you password below.", "Register", "Cancel");
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- new data[64];
- new name[MAX_PLAYER_NAME];
- GetPlayerName(playerid, name, sizeof(name));
- format(data, sizeof(data), "/Accounts/%s.txt", name);
- if(dini_Exists(data))
- {
- dini_IntSet(data, "Score", GetPlayerScore(playerid));
- }
- else
- {
- dini_Create(data);
- dini_IntSet(data, "Score", GetPlayerScore(playerid));
- }
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem,inputtext[])
- {
- if(dialogid == DIALOG_LOGIN)
- {
- if(response == 0)
- {
- SendClientMessage(playerid,0xFFFFFFFF, "You choosed to not login!");
- Kick(playerid);
- return 1;
- }
- if(response == 1)
- {
- if(!strlen(inputtext))
- {
- SendClientMessage(playerid,0xFFFFFFFF, "You havent filled in a password!");
- ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login", "Please login by typing you password below.", "Login", "Cancel");
- return 1;
- }
- Login(playerid, inputtext);
- return 1;
- }
- }
- if(dialogid == DIALOG_REGISTER)
- {
- if(response == 0)
- {
- SendClientMessage(playerid,0xFFFFFFFF, "You choosed to not register!");
- Kick(playerid);
- return 1;
- }
- if(response == 1)
- {
- if(!strlen(inputtext))
- {
- SendClientMessage(playerid,0xFFFFFFFF, "You havent filled in a password!");
- ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Register", "Please register by typing you password below.", "Register", "Cancel");
- return 1;
- }
- Register(playerid, inputtext);
- return 1;
- }
- }
- return 1;
- }
- stock Register(playerid,key[])
- {
- new data[64];
- new name[MAX_PLAYER_NAME];
- GetPlayerName(playerid, name, sizeof(name));
- format(data, sizeof(data), "/Accounts/%s.txt", name);
- dini_Create(data);
- dini_Set(data, "Password", key);
- SendClientMessage(playerid,0xFFFFFFFF, "Account Registered!");
- dini_IntSet(data, "Score",0);
- return 1;
- }
- stock Login(playerid,key[])
- {
- new data[64];
- new name[MAX_PLAYER_NAME];
- GetPlayerName(playerid, name, sizeof(name));
- format(data, sizeof(data), "/Accounts/#s.txt", name);
- if(!strcmp(key,dini_Get(data,"Password"),false))
- {
- SetPlayerScore(playerid, dini_Int(data, "Score"));
- SendClientMessage(playerid,0xFFFFFFFF, "Login Successful!");
- return 1;
- }
- else
- {
- SendClientMessage(playerid,0xFF0000FF, "Wrong Password!");
- ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login", "Please login by typing you password below.", "Login", "Cancel");
- return 1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment