Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <DOF2>
- #define MAILER_URL "freesub.comuf.com/mailer.php"
- #include <Email>
- #include <regex>
- enum Pi
- {
- PName[MAX_PLAYER_NAME],
- File[64],
- IP[16],
- bool:PlayerLogin,
- Code
- }
- new pInfo[MAX_PLAYERS][Pi], String[184];
- #define GetName(%0) pInfo[%0][PName]
- #define PFile(%0) pInfo[%0][File]
- #define KickEx(%0) SetTimerEx("KickPlayer", 50, false, "i", %0)
- #define GetPIP(%0) pInfo[%0][IP]
- #define IsValidEmail(%1) \
- regex_match(%1, "[a-zA-Z0-9_\\.]+@([a-zA-Z0-9\\-]+\\.)+[a-zA-Z]{2,4}")
- // Dialogs
- #define DIALOG_REGISTER 100
- #define DIALOG_LOGIN 101
- #define DIALOG_EMAIL 102
- #define DIALOG_MESSAGES 103
- #define DIALOG_CEMAIL 104
- public OnPlayerConnect(playerid)
- {
- GetPlayerName(playerid, GetName(playerid), MAX_PLAYER_NAME);
- format(PFile(playerid), sizeof pInfo, "Users/%s.ini", GetName(playerid));
- GetPlayerIp(playerid, GetPIP(playerid), 16);
- if(!DOF2_FileExists(PFile(playerid)))
- ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Register", "Welcome !\nThe system not found your a registered user.\nType your password in the box.", "Continuation", "Cancel");
- else if(DOF2_FileExists(PFile(playerid)) && !strcmp(GetPIP(playerid), DOF2_GetString(PFile(playerid), "IP"), false))
- {
- pInfo[playerid][PlayerLogin] = true;
- ShowPlayerDialog(playerid, DIALOG_MESSAGES, DIALOG_STYLE_MSGBOX, "Auto Login", "Welcome !\nYou've been auto-logged in. [IP match]", "Ok", "");
- } else if(DOF2_FileExists(PFile(playerid)))
- return ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", "Welcome !\nPlease enter your password.", "Login", "Restore Password");
- return true;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- if(response)
- {
- switch(dialogid)
- {
- case DIALOG_REGISTER:
- {
- if(!strlen(inputtext))
- return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Register", "Welcome !\nThe system not found your a registered user.\nType your password in the box.\nType password !", "Continuation", "Cancel");
- if(strlen(inputtext) < 6)
- return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Register", "Welcome !\nThe system not found your a registered user.\nType your password in the box.\nInvalid entry for password. 6 characters minimum", "Continuation", "Cancel");
- if(strfind(inputtext, "%", true) != -1)
- return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Register", "Welcome !\nThe system not found your a registered user.\nType your password in the box.\nThe password can not contain the character: %", "Continuation", "Cancel");
- DOF2_CreateFile(PFile(playerid));
- DOF2_SetString(PFile(playerid), "Password", inputtext);
- DOF2_SetString(PFile(playerid), "IP", GetPIP(playerid));
- ShowPlayerDialog(playerid, DIALOG_EMAIL, DIALOG_STYLE_INPUT, "Register - Email", "Please enter your email to confirm your registration.\nNOTE!: Email will serve you well in the future password recovery.", "Continuation", "");
- return true;
- }
- case DIALOG_EMAIL:
- {
- if(!IsValidEmail(inputtext))
- return ShowPlayerDialog(playerid, DIALOG_EMAIL, DIALOG_STYLE_INPUT, "Register - Email", "Please enter your email to confirm your registration.\nNOTE!: Email will serve you well in the future password recovery.\nInvalid email.", "Continuation", "");
- DOF2_SetString(PFile(playerid), "Email", inputtext);
- pInfo[playerid][Code] = random(5000) + random(5000) + random(5000) + random(5000) + random(5000) + random(5000);
- format(String, sizeof String, "Your verification code is:\n\r%d", pInfo[playerid][Code]);
- ShowPlayerDialog(playerid, DIALOG_CEMAIL, DIALOG_STYLE_INPUT, "Email", "Enter the verification code that you received by email:", "Ok", "");
- return true;
- }
- case DIALOG_CEMAIL:
- {
- if(!strlen(inputtext) || !IsValidNumber(inputtext) || pInfo[playerid][Code] != strval(inputtext))
- return ShowPlayerDialog(playerid, DIALOG_CEMAIL, DIALOG_STYLE_INPUT, "Email", "The verification code is incorrect\nEnter the verification code that you received by email:", "Continuation", "");
- SendClientMessage(playerid, -1, "Registered successfully.");
- SendClientMessage(playerid, -1, "Email Password Recovery will serve you.");
- pInfo[playerid][PlayerLogin] = true;
- return true;
- }
- case DIALOG_LOGIN:
- {
- if(strfind(inputtext, "%", true) != -1)
- return ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login", "Welcome !\nPlease enter your password.\nInvalid password.", "Login", "Restore Password");
- if(!strlen(inputtext))
- return ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login", "Welcome !\nPlease enter your password.\nInvalid password.", "Login", "Restore Password");
- if(!strcmp(DOF2_GetString(PFile(playerid),"Password"), inputtext, false))
- {
- ShowPlayerDialog(playerid, DIALOG_MESSAGES, DIALOG_STYLE_MSGBOX, "Login", "you successfully connect.", "Ok", "");
- pInfo[playerid][PlayerLogin] = true;
- } else ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login", "Welcome !\nPlease enter your password.\nInvalid password.", "Login", "Restore Password");
- return true;
- }
- }
- }
- else if(!response)
- {
- switch(dialogid)
- {
- case DIALOG_LOGIN:
- {
- format(String, sizeof String, "Your player's password is:\n\r%s", DOF2_GetString(PFile(playerid), "Password"));
- SendMail(DOF2_GetString(PFile(playerid), "Email"), "[email protected]", "ModeName", "ModeName", String);
- ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", "Welcome !\nPlease enter your password.\nPassword has been sent to your email.", "Login", "Restore Password");
- return true;
- }
- case DIALOG_MESSAGES: return true;
- case DIALOG_REGISTER, DIALOG_EMAIL, DIALOG_CEMAIL: return KickEx(playerid);
- }
- }
- return DOF2_SaveFile();
- }
- public OnPlayerRequestSpawn(playerid)
- {
- if(!pInfo[playerid][PlayerLogin])
- return SendClientMessage(playerid, -1, "Log in to the server before spawn."), 0;
- return true;
- }
- forward KickPlayer(playerid);
- public KickPlayer(playerid) return Kick(playerid);
- stock IsValidNumber( string[ ] )
- {
- if ( !string[ 0 ] )
- return false;
- new
- iLength = strlen( string ),
- i
- ;
- if ( string[ 0 ] == '-' && string[ 1 ] )
- i = 1;
- for ( ; i < iLength; i++ )
- {
- if ( !( '0' <= string[ i ] <= '9' ) )
- return false;
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment