#include <dini>
public OnPlayerConnect(playerid)
{
new String[64];
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid,name,sizeof(name));
format(String,sizeof(String),"/Accounts/PlNm.txt",name);
if(dini_Exists(String))
{
ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_INPUT,"Logging in","This account was found in data base,please type in your password to log in.","Login","Cancel");
}
else
{
ShowPlayerDialog(playerid,DIALOG_REGISTER,DIALOG_STYLE_INPUT,"Registration","Type in your password","Register","Cancel");
}
new pname[MAX_PLAYER_NAME],string[22+MAX_PLAYER_NAME];
GetPlayerName(playerid,pname,sizeof(pname));
format(string,sizeof(string),"%s has joined the server",pname);
SendClientMessageToAll(COLOR_GREY,string);
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid==DIALOG_LOGIN)
{
if(response==0)
{
SendClientMessage(playerid,COLOR_RED,"You have been kicked for not loging in.");
Kick(playerid);
return 1;
}
if(response==1)
{
if(!strlen(inputtext))
{
SendClientMessage(playerid,COLOR_RED,"This password is too short");
ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_INPUT,"Logging in","This account was found in data base,please type in your password to log in.","Login","Cancel");
return 1;
}
else
{
Login(playerid,inputtext);
return 1;
}
}
}
if(dialogid==DIALOG_REGISTER)
{
if(response==0)
{
SendClientMessage(playerid,COLOR_RED,"You have been kicked for not registering in.");
Kick(playerid);
return 1;
}
if(response==1)
{
if(!strlen(inputtext))
{
SendClientMessage(playerid,COLOR_RED,"This password is too short");
ShowPlayerDialog(playerid,DIALOG_REGISTER,DIALOG_STYLE_INPUT,"Registration","Type in your password","Register","Cancel");
return 1;
}
else
{
Register(playerid,inputtext);
return 1;
}
}
}
return 1;
}
stock Register(playerid,key[])
{
new String[64];
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid,name,sizeof(name));
format(String,sizeof(String),"/Accounts/PlNm.txt",name);
dini_Create(String);
dini_Set(String,"Password",key);
SendClientMessage(playerid,COLOR_GREEN,"Successfully registered");
dini_IntSet(String,"Level",0);
GivePlayerMoney(playerid,2000);
return 1;
}
stock Login(playerid,key[])
{
new String[64];
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid,name,sizeof(name));
format(String,sizeof(String),"/Accounts/PlNm.txt",name);
if(!strcmp(key,dini_Get(String,"Password"),false))
{
SetPlayerScore(playerid,dini_Int(String,"Level"));
SendClientMessage(playerid,COLOR_GREEN,"Successfully logged");
PlayerPlaySound(playerid,1057,0,0,0);
GivePlayerMoney(playerid,2000);
return 1;
}
else
{
SendClientMessage(playerid,COLOR_RED,"Wrong password.");
PlayerPlaySound(playerid,1055,0,0,0);
ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_INPUT,"Logging in","This account was found in data base,please type in your password to log in.","Login","Cancel");
return 1;
}
}
I made a login system with dini,following a tutorial on *******:
pawn Код:
1)In-game is working perfectly,there's a single problem,if someone types in a wrong password several times(as he's doing that the class selecton shows up),if he presses spawn he can spawn without logging in.How to make so that if he selects "Spawn",and he is not logged yet he can't spawn. 2)How to make a saving system(saves the score and money of a player,so when he logs in he spawns with the money and his score. 3)You may see somewhere at "stock Login" - GivePlayerMoney(playerid,2000) and I'm not sure if that's right,as I want to set 2000$ as start-in ammount money(every new player that joins will spawn with that start ammount of money) WARNING!!!EVERY USER OF Y_INI IS ASKED NICELY NOT TO ANSWER THIS TOPIC IF HE CAN'T/NOT TELL ME SWITCH TO Y_INI BECAUSE IT'S EASIER!!! |
new gPlayerLogged[MAX_PLAYERS];
public OnPlayerConnect(playerid)
{
gPlayerLogged[playerid] = 0;
return 1;
}
stock Register(playerid,key[])
{
new String[64];
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid,name,sizeof(name));
format(String,sizeof(String),"/Accounts/PlNm.txt",name);
dini_Create(String);
dini_Set(String,"Password",key);
SendClientMessage(playerid,COLOR_GREEN,"Successfully registered");
dini_IntSet(String,"Level",0);
gPlayerLogged[playerid] = 1;
GivePlayerMoney(playerid,2000);
return 1;
}
stock Login(playerid,key[])
{
new String[64];
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid,name,sizeof(name));
format(String,sizeof(String),"/Accounts/PlNm.txt",name);
if(!strcmp(key,dini_Get(String,"Password"),false))
{
SetPlayerScore(playerid,dini_Int(String,"Level"));
SendClientMessage(playerid,COLOR_GREEN,"Successfully logged");
PlayerPlaySound(playerid,1057,0,0,0);
GivePlayerMoney(playerid,2000);
gPlayerLogged[playerid] = 1;
return 1;
}
else
{
SendClientMessage(playerid,COLOR_RED,"Wrong password.");
PlayerPlaySound(playerid,1055,0,0,0);
ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_INPUT,"Logging in","This account was found in data base,please type in your password to log in.","Login","Cancel");
return 1;
}
}
public OnPlayerSpawn(playerid)
{
if(gPlayerLogged[playerid] == 0) return Kick(playerid);//So we can kick that player
return 1;
}
public OnPlayerDisconnect(playerid)
{
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid,name,sizeof(name));
format(String,sizeof(String),"/Accounts/PlNm.txt",name);
dini_IntSet(string,"level",GetPlayerScore(playerid));//We took the player's score and saved it to "level"
return 1;
}
stock Login(playerid,key[])
{
new String[64];
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid,name,sizeof(name));
format(String,sizeof(String),"/Accounts/PlNm.txt",name);
if(!strcmp(key,dini_Get(String,"Password"),false))
{
SetPlayerScore(playerid,dini_Int(String,"level"));//Get the value from "level" and set it as his score
SendClientMessage(playerid,COLOR_GREEN,"Successfully logged");
PlayerPlaySound(playerid,1057,0,0,0);
GivePlayerMoney(playerid,2000);
return 1;
}
else
{
SendClientMessage(playerid,COLOR_RED,"Wrong password.");
PlayerPlaySound(playerid,1055,0,0,0);
ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_INPUT,"Logging in","This account was found in data base,please type in your password to log in.","Login","Cancel");
return 1;
}
}
new spawned[MAX_PLAYERS];
spawned[playerid] = 0;
spawned[playerid] = 1;
if(spawned[playerid] == 0) return SendClientMessage(playerid,0xFFFFFFFF,"You Must Login To Spawn!");