17.10.2011, 14:52
I tried to make a dialog when a player connect to ask for password and if it's correct to spawn if else to be kicked, but I Failed.
Register and Login
I want something like this, I tried it I change it but still got errors
Can anyone help me
pawn Код:
enum PlayerData
{
Registered,
Loggedin,
Level,
Muted,
Jailed
}
new PData[MAX_PLAYERS][PlayerData];
pawn Код:
public OnPlayerConnect(playerid)
{
SCM(playerid, yellow, "Welcome. Type /register to register your account, or /login if you already have one.");
GetPlayerName(playerid, pname, sizeof(pname));
PData[playerid][Registered] = 0;
PData[playerid][Level] = 0;
PData[playerid][Loggedin] = 0;
PData[playerid][Jailed] = 0;
PData[playerid][Muted] = 0;
GetPlayerIp(playerid, pip, sizeof(pip));
format(str, sizeof(str), "%s.banned", pname);
if(dini_Int("banned-ips.txt", pip))
{
printf("%s (%s) detected as banned. Kicking...", pname, pip);
format(banstr1, sizeof(banstr1), "{FFFFFF}If you think you were banned for no reason, visit us at {FF0000}%s{FFFFFF} and post a ban appeal. Make sure you have a screenshot of this.", YOUR_SITE);
format(banstr, sizeof(banstr),"{FFFFFF}Ban information:\r\n{FF0000}Your name: {FFFFFF}%s\r\n{FF0000}Original banned name: {FFFFFF}%s\r\n{FF0000}Banned by: {FFFFFF}%s\r\n{FF0000}Ban time:{FFFFFF} %s\r\n{FF0000}Your IP: {FFFFFF}%s \r\n{FF0000}Reason:{FFFFFF} %s \r\n%s", pname, dini_Get(str, "ban-orgname"), dini_Get(str, "ban-admin"), dini_Get(str, "ban-date"), pip, dini_Get(str, "ban-reason"), banstr1);
ShowPlayerDialog(playerid, 1337, DIALOG_STYLE_MSGBOX, "{FF0000}You are banned from this server!", banstr, "Close", "");
Kick(playerid);
}
loginattempts[playerid] = 0;
return 1;
}
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
GetPlayerName(playerid, pname, sizeof(pname));
format(str, sizeof(str), "%s.user", pname);
if(dini_Exists(str) && PData[playerid][Loggedin])
{
dini_IntSet(str, "registered", 1);
dini_IntSet(str, "level", PData[playerid][Level]);
dini_IntSet(str, "muted", PData[playerid][Muted]);
dini_IntSet(str, "jailed", PData[playerid][Jailed]);
}
PData[playerid][Level] = 0;
KillTimer(mutetimer[playerid]);
KillTimer(jailtimer[playerid]);
loginattempts[playerid] = 0;
return 1;
}
pawn Код:
C(register)
{
new pass[128];
GetPlayerName(playerid, pname, sizeof(pname));
format(str, sizeof(str), "%s.user", pname);
if(dini_Exists(str)) return SCM(playerid, red, "ERROR: This nickname is already registered. Please reconnect with another nickname.");
else if(strlen(params) < 5) return SCM(playerid, red, "ERROR: Your password must be at least 5 characters long!");
else if(sscanf(params, "s[128]", pass)) return SCM(playerid, yellow, "SYNTAX: /register <password>");
WP_Hash(buf, sizeof(buf), pass);
dini_Create(str);
dini_IntSet(str, "registered", 1);
dini_IntSet(str, "level", 0);
dini_IntSet(str, "muted", PData[playerid][Muted]);
dini_IntSet(str, "jailed", PData[playerid][Jailed]);
dini_Set(str, "password", buf);
format(str2, sizeof(str2), "You have successfully registered your nickname with the password \"%s\" - please write it down incase you forget it.", pass);
SCM(playerid, green, str2);
SCM(playerid, green, "Don't worry, your password is saved hashed (whirlpool), and admins cannot see it. You have also been automatically logged in!");
PData[playerid][Loggedin] = 1;
PData[playerid][Registered] = 1;
dini_Set(str, "lastip", pip);
return 1;
}
C(login)
{
new pass[128];
GetPlayerName(playerid, pname, sizeof(pname));
format(str, sizeof(str), "%s.user", pname);
if(dini_Int(str, "registered") == 0) return SCM(playerid, red, "ERROR: This nickname isn't registered! Use /register first.");
else if(PData[playerid][Loggedin] == 1) return SCM(playerid, red, "ERROR: You are already logged in!");
else if(sscanf(params, "s[128]", pass)) return SCM(playerid, yellow, "SYNTAX: /login <password>");
WP_Hash(buf, sizeof(buf), pass);
if(strcmp(dini_Get(str, "password"), buf))
{
if(loginattempts[playerid] < 2)
{
SCM(playerid, red, "ERROR: Invalid password.");
loginattempts[playerid] ++;
}
else
{
SCM(playerid, red, "ERROR: Invalid password.");
format(str2, sizeof(str2), "Kicking %s for too many failed logins...", pname);
MessageAdmins(red, str2);
format(str3, sizeof(str3),"{FFFFFF}Kick information:\r\n{FF0000}Kicked by:{FFFFFF} SERVER\r\n{FF0000}Reason:{FFFFFF} Too many failed logins.\r\n{FFFFFF}Feel free to rejoin!");
ShowPlayerDialog(playerid, 13337, DIALOG_STYLE_MSGBOX, "{FF0000}You have been kicked.", str3, "Close", "");
loginattempts[playerid] = 0;
Kick(playerid);
}
}
else
{
PData[playerid][Muted] = dini_Int(str, "muted");
dini_IntSet(str, "registered", 1);
PData[playerid][Jailed] = dini_Int(str, "jailed");
GetPlayerIp(playerid, pip, sizeof(pip));
PData[playerid][Loggedin] = 1;
PData[playerid][Level] = dini_Int(str, "level");
PData[playerid][Registered] = 1;
format(str2, sizeof(str2), "You have been successfully logged in as level %d admin! Welcome back, %s!", PData[playerid][Level], pname);
SCM(playerid, green, str2);
GetPlayerIp(playerid, pip, sizeof(pip));
dini_Set(str, "lastip", pip);
}
return 1;
}
pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == 1) {
new name[MAX_PLAYER_NAME], file[256], string[128];
GetPlayerName(playerid, name, sizeof(name));
format(file, sizeof(file), SERVER_USER_FILE, name);
if(!response) return Kick(playerid);
if(!strlen(inputtext)) return
ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "Hi your not registered", "Welcome, your not a member,Input your PW below","Register","Kick Me");
dini_Create(file);
dini_IntSet(file, "Password", udb_hash(inputtext));
format(string, 128, "[SYSTEM]: You succesfully registered the nickname %s with password %s, you have been auto logged in.", name, inputtext);
SendClientMessage(playerid, 0xFF0000FF, string);
gPlayerLogged[playerid] = 1;
}
if(dialogid == 2) {
new name[MAX_PLAYER_NAME], file[256], string[128];
GetPlayerName(playerid, name, sizeof(name));
format(file, sizeof(file), SERVER_USER_FILE, name);
if(!response) return Kick(playerid);
if(!strlen(inputtext)) return ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Hi your registered,Welcome, your a member","Input your PW below","Register","Kick Me");
new tmp;
tmp = dini_Int(file, "Password");
if(udb_hash(inputtext) !=tmp) {
SendClientMessage(playerid, 0xFF0000FF, "Wrong Password");
ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Hi your registered", "Welcome, your not member,Input your PW below","Register","Kick Me");
}
else {
gPlayerLogged[playerid] = 1;
SendClientMessage(playerid, 0xFF0000FF, "[SYSTEM]: Successfully logged in!");
}
}
return 1;
}
pawn Код:
public OnPlayerConnect(playerid)
{
gPlayerLogged[playerid] = 0;
new name[MAX_PLAYER_NAME], file[256];
GetPlayerName(playerid, name, sizeof(name));
format(file, sizeof(file), SERVER_USER_FILE, name);
{
if(!dini_Exists(file)) {
ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "Hi your not registered", "Welcome, your not a member,Input your PW below","Register","Kick Me");
}
if(fexist(file)) {
ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Hi your registered", "Welcome, your a member,Input your PW below","Register","Kick Me");
}
}
return 1;
}