View difference between Paste ID: cvA3S8Nh and MuP5RVts
SHOW: | | - or go back to the newest paste.
1
#include <a_samp>
2
#include <DOF2>
3
#define MAILER_URL "freesub.comuf.com/mailer.php"
4
#include <Email>
5
#include <regex>
6
7
enum Pi
8
{
9
	PName[MAX_PLAYER_NAME],
10
	File[64],
11
	IP[16],
12
	bool:PlayerLogin,
13
	Code
14
}
15
new pInfo[MAX_PLAYERS][Pi], String[184];
16
17
#define GetName(%0)                   	pInfo[%0][PName]
18
#define PFile(%0)                       pInfo[%0][File]
19
#define KickEx(%0)                      SetTimerEx("KickPlayer", 50, false, "i", %0)
20
#define GetPIP(%0)                      pInfo[%0][IP]
21
#define IsValidEmail(%1) \
22
    regex_match(%1, "[a-zA-Z0-9_\\.]+@([a-zA-Z0-9\\-]+\\.)+[a-zA-Z]{2,4}")
23
24
// Dialogs
25
#define DIALOG_REGISTER                 100
26
#define DIALOG_LOGIN                    101
27
#define DIALOG_EMAIL                    102
28
#define DIALOG_MESSAGES                 103
29
#define DIALOG_CEMAIL                   104
30
31
public OnPlayerConnect(playerid)
32
{
33
	GetPlayerName(playerid, GetName(playerid), MAX_PLAYER_NAME);
34
	format(PFile(playerid), sizeof pInfo, "Users/%s.ini", GetName(playerid));
35
	GetPlayerIp(playerid, GetPIP(playerid), 16);
36
	if(!DOF2_FileExists(PFile(playerid)))
37
	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");
38
	else if(DOF2_FileExists(PFile(playerid)) && !strcmp(GetPIP(playerid), DOF2_GetString(PFile(playerid), "IP"), false))
39
	{
40
		pInfo[playerid][PlayerLogin] = true;
41
	    ShowPlayerDialog(playerid, DIALOG_MESSAGES, DIALOG_STYLE_MSGBOX, "Auto Login", "Welcome !\nYou've been auto-logged in. [IP match]", "Ok", "");
42
	} else if(DOF2_FileExists(PFile(playerid)))
43
		return ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", "Welcome !\nPlease enter your password.", "Login", "Restore Password");
44
	return true;
45
}
46
47
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
48
{
49
	if(response)
50
	{
51
		switch(dialogid)
52
		{
53
		    case DIALOG_REGISTER:
54
		    {
55
		        if(!strlen(inputtext))
56
					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");
57
				if(strlen(inputtext) < 6)
58
					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");
59
	            if(strfind(inputtext, "%", true) != -1)
60
	            	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");
61
				DOF2_CreateFile(PFile(playerid));
62
				DOF2_SetString(PFile(playerid), "Password", inputtext);
63
				DOF2_SetString(PFile(playerid), "IP", GetPIP(playerid));
64
	            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", "");
65
				return true;
66
			}
67
			case DIALOG_EMAIL:
68
			{
69
			    if(!IsValidEmail(inputtext))
70
					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", "");
71
				DOF2_SetString(PFile(playerid), "Email", inputtext);
72
				pInfo[playerid][Code] = random(5000) + random(5000) + random(5000) + random(5000) + random(5000) + random(5000);
73-
				format(String, sizeof String, "[b][u]Your verification code is[/u]:\n\r[color=red]%d[/color][/b]", pInfo[playerid][Code]);
73+
				format(String, sizeof String, "Your verification code is:\n\r%d", pInfo[playerid][Code]);
74
				SendMail(inputtext, "[email protected]", "ModeName", "ModeName", String);
75
				ShowPlayerDialog(playerid, DIALOG_CEMAIL, DIALOG_STYLE_INPUT, "Email", "Enter the verification code that you received by email:", "Ok", "");
76
	            return true;
77
			}
78
			case DIALOG_CEMAIL:
79
			{
80
				if(!strlen(inputtext) || !IsValidNumber(inputtext) || pInfo[playerid][Code] != strval(inputtext))
81
					return ShowPlayerDialog(playerid, DIALOG_CEMAIL, DIALOG_STYLE_INPUT, "Email", "The verification code is incorrect\nEnter the verification code that you received by email:", "Continuation", "");
82
				SendClientMessage(playerid, -1, "Registered successfully.");
83
				SendClientMessage(playerid, -1, "Email Password Recovery will serve you.");
84
				pInfo[playerid][PlayerLogin] = true;
85
				return true;
86
			}
87
			case DIALOG_LOGIN:
88
			{
89
                if(strfind(inputtext, "%", true) != -1)
90
					return ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login", "Welcome !\nPlease enter your password.\nInvalid password.", "Login", "Restore Password");
91
   				if(!strlen(inputtext))
92
					return ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login", "Welcome !\nPlease enter your password.\nInvalid password.", "Login", "Restore Password");
93
		        if(!strcmp(DOF2_GetString(PFile(playerid),"Password"), inputtext, false))
94
		        {
95
		            ShowPlayerDialog(playerid, DIALOG_MESSAGES, DIALOG_STYLE_MSGBOX, "Login", "you successfully connect.", "Ok", "");
96
		    		pInfo[playerid][PlayerLogin] = true;
97
		        } else ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login", "Welcome !\nPlease enter your password.\nInvalid password.", "Login", "Restore Password");
98
			    return true;
99
			}
100
		}
101
	}
102
	else if(!response)
103
	{
104
	    switch(dialogid)
105
	    {
106
	        case DIALOG_LOGIN:
107
	        {
108-
				format(String, sizeof String, "Your player's password is: %s", DOF2_GetString(PFile(playerid), "Password"));
108+
				format(String, sizeof String, "Your player's password is:\n\r%s", DOF2_GetString(PFile(playerid), "Password"));
109
				SendMail(DOF2_GetString(PFile(playerid), "Email"), "[email protected]", "ModeName", "ModeName", String);
110
				ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", "Welcome !\nPlease enter your password.\nPassword has been sent to your email.", "Login", "Restore Password");
111
				return true;
112
			}
113
			case DIALOG_MESSAGES: return true;
114
			case DIALOG_REGISTER, DIALOG_EMAIL, DIALOG_CEMAIL: return KickEx(playerid);
115
	    }
116
	}
117
	return DOF2_SaveFile();
118
}
119
120
public OnPlayerRequestSpawn(playerid)
121
{
122
	if(!pInfo[playerid][PlayerLogin])
123
		return SendClientMessage(playerid, -1, "Log in to the server before spawn."), 0;
124
	return true;
125
}
126
127
forward KickPlayer(playerid);
128
public KickPlayer(playerid) return Kick(playerid);
129
130
stock IsValidNumber( string[ ] )
131
{
132
    if ( !string[ 0 ] )
133
        return false;
134
135
    new
136
        iLength = strlen( string ),
137
        i
138
    ;
139
140
    if ( string[ 0 ] == '-' && string[ 1 ] )
141
        i = 1;
142
143
    for ( ; i < iLength; i++ )
144
    {
145
        if ( !( '0' <= string[ i ] <= '9' ) )
146
            return false;
147
    }
148
149
    return true;
150
}