Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <YSI\y_ini>
- #define DIALOG_REGISTER 1
- #define DIALOG_LOGIN 2
- forward LoadUser_data(playerid, name[], value[]);
- enum pInfo
- {
- pPass[65],
- pSalt[11],
- pAdmin
- }
- new PlayerInfo[MAX_PLAYERS][pInfo];
- #define PATH "/Server_Files/PlayerAccounts/%s.ini"
- public OnPlayerConnect(playerid)
- {
- if(fexist(AccountPath(playerid)))
- {
- INI_ParseFile(AccountPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
- ShowAccountLoginDialog(playerid);
- }
- else
- {
- ShowAccountRegisterDialog(playerid);
- }
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- new INI:File = INI_Open(AccountPath(playerid)), plr_IP[16];
- INI_SetTag(File, "---Player_Data---");
- INI_WriteInt(File, "Admin_Level:", PlayerInfo[playerid][pAdmin]);
- INI_Close(File);
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- switch(dialogid)
- {
- case DIALOG_REGISTER:
- {
- new string[128], salt[11];
- if(!response) return KickEx(playerid);
- if(response)
- {
- if(!strlen(inputtext)) return ShowRegisterFailureDialog(playerid);
- new INI:File = INI_Open(AccountPath(playerid));
- for(new i; i < 10; i++)
- {
- salt[i] = random(79) + 47;
- }
- INI_SetTag(File, "---Player_Data---");
- INI_WriteInt(File, "Password:", SHA256_PassHash(inputtext, salt, PlayerInfo[playerid][pPass], 65));
- INI_WriteString(File, "Pass_Salt:", salt);
- INI_WriteInt(File, "Admin_Level:", 0);
- INI_Close(File);
- format(string, sizeof(string), "You have successfully registered your account. You have been automatically logged in!");
- SendMessage(playerid, COLOR_ADMIN, string);
- salt[10] = 0;
- }
- }
- case DIALOG_LOGIN:
- {
- if(!response) return KickEx(playerid);
- if(response)
- {
- new hash[65];
- SHA256_PassHash(inputtext, PlayerInfo[playerid][pSalt], hash, 64);
- if(!strcmp(hash, PlayerInfo[playerid][pPass]))
- {
- INI_ParseFile(AccountPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
- }
- else
- {
- ShowLoginFailureDialog(playerid);
- }
- return 1;
- }
- }
- }
- return 1;
- }
- public KickEx_Func(playerid)
- {
- Kick(playerid);
- return 1;
- }
- public LoadUser_data(playerid, name[], value[])
- {
- INI_Int("Password:", PlayerInfo[playerid][pPass]);
- INI_Int("Pass_Salt", PlayerInfo[playerid][pSalt]);
- INI_Int("Admin_Level:", PlayerInfo[playerid][pAdmin]);
- return 1;
- }
- stock ShowAccountLoginDialog(playerid)
- {
- new string[200], plr_name[128];
- format(plr_name, sizeof(plr_name), "Welcome back, %s. We missed you!\n\n", PlayerName(playerid));
- strcat(string, plr_name);
- strcat(string, "Please type your password in the box below to login.\n");
- strcat(string, "Note: Passwords are case sensitive.");
- return ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Account Login", string, "Login", "Quit");
- }
- stock ShowAccountRegisterDialog(playerid)
- {
- new string[200], plr_name[128];
- format(plr_name, sizeof(plr_name), "Welcome to the server, %s!\n\n", PlayerName(playerid));
- strcat(string, plr_name);
- strcat(string, "Please type in your desired password into the box below to register your account.\n");
- strcat(string, "Note: Passwords are case sensitive.");
- return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Account Registration", string, "Register", "Quit");
- }
- stock ShowLoginFailureDialog(playerid)
- {
- new string[200], plr_name[128];
- format(plr_name, sizeof(plr_name), "Welcome back, %s.\n\n", PlayerName(playerid));
- strcat(string, plr_name);
- strcat(string, "It appears you got your password wrong. Please try again.\n");
- strcat(string, "Note: Passwords are case sensitive.");
- return ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Account Login", string, "Login", "Quit");
- }
- stock ShowRegisterFailureDialog(playerid)
- {
- new string[200], plr_name[128];
- format(plr_name, sizeof(plr_name), "Welcome to the server, %s!\n\n", PlayerName(playerid));
- strcat(string, plr_name);
- strcat(string, "You failed to type in an appropriate password. Please try again.\n");
- strcat(string, "Note: Passwords are case sensitive.");
- return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Account Registration", string, "Register", "Quit");
- }
- stock KickEx(playerid)
- {
- new string[128];
- format(string, sizeof(string), "%s(%d) has been kicked from the server. (Reason: Refused to register their account)", PlayerName(playerid), playerid);
- SendMessageToAll(COLOR_ADMIN, string);
- SetTimerEx("KickEx_Func", 600, false, "i", playerid);
- return 1;
- }
- stock AccountPath(playerid)
- {
- new string[128];
- format(string, sizeof(string), PATH, PlayerName(playerid));
- return string;
- }
- stock PlayerName(playerid)
- {
- new name[MAX_PLAYER_NAME];
- GetPlayerName(playerid, name, MAX_PLAYER_NAME);
- return name;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement