02.09.2010, 18:58
(
Last edited by Sky4D; 02/09/2010 at 07:16 PM.
)
Yeah, i've never been good with these things.. What am I doing wrong? (I used djson, by the way)
OnDialogResponse:
Login & Register publics:
OnDialogResponse:
pawn Code:
if(dialogid == 1) { //Register
if(response) {
new PlayerName[MAX_PLAYER_NAME], string[128];
GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
format(string, sizeof(string), "Elimination/Accounts/%s.json", PlayerName);
if(!djIsSet(string,"Key"))
{
registerPlayer(playerid,inputtext);
PlayerPlaySound(playerid,1057,0.0,0.0,0.0);
return 1;
}
else return ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "Invalid Password!", "Warning: This server contains alot of action, and is not for the faint of heart.\nBe advised.\nPlease enter your password below:", "Submit", "Cancel");
}
else
{
ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "Invalid Password!", "Warning: This server contains alot of action, and is not for the faint of heart.\nBe advised.\nPlease enter your password below:", "Submit", "Cancel");
}
}
else if(dialogid == 2) { //Login
if(response) {
new PlayerName[MAX_PLAYER_NAME], string[128];
GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
format(string, sizeof(string), "Elimination/Accounts/%s.json", PlayerName);
if(djIsSet(string,"Key"))
{
if(playerLoggedIn[playerid] == 1) return SendClientMessage(playerid, sc_LightRed, "ERROR: You are already logged in.");
loginPlayer(playerid,inputtext);
return 1;
}
else return ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Invalid Password!", "Warning: This server contains alot of action, and is not for the faint of heart.\nBe advised.\nPlease enter your password below:", "Submit", "Cancel");
}
else
{
ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Invalid Password!", "Warning: This server contains alot of action, and is not for the faint of heart.\nBe advised.\nPlease enter your password below:", "Submit", "Cancel");
}
}
pawn Code:
public loginPlayer(playerid,password[])
{
new string[80], CharName[MAX_PLAYER_NAME];
GetPlayerName(playerid, CharName, sizeof(CharName));
format(string, sizeof(string), "Elimination/Accounts/%s.json", CharName);
if(strcmp(dj(string,"Key"),password, true ) == 0 )
{
playerInfo[playerid][IsRegistered]=djInt(string,"IsRegistered");
playerInfo[playerid][Administrator]=djInt(string,"Administrator");
playerInfo[playerid][Cash]=djInt(string,"Cash");
playerInfo[playerid][Skin]=djInt(string,"Skin");
playerInfo[playerid][Experience]=djInt(string,"Experience");
playerInfo[playerid][TimeOnline]=djInt(string,"TimeOnline");
playerInfo[playerid][AccountStatus]=djInt(string,"AccountStatus");
}
else { GameTextForPlayer(playerid, "~w~Authentication~n~~r~rejected", 3000, 1); return 1; }
if(playerInfo[playerid][IsRegistered] == 0)
{
playerInfo[playerid][Cash]=250;
playerInfo[playerid][IsRegistered] = 1;
playerInfo[playerid][AccountStatus] = 0;
playerInfo[playerid][Administrator] = 0;
playerInfo[playerid][TimeOnline] = 0;
playerInfo[playerid][Experience] = 0;
playerInfo[playerid][Skin] = random(300);
}
playerLoggedIn[playerid] = 1;
format(string, sizeof(string), "[script] %s has logged in.", ReturnPlayerName(playerid));
printf(string);
SetPlayerColor(playerid, sc_White);
SetPlayerScore(playerid, playerInfo[playerid][Experience]);
SendClientMessage(playerid, sc_White, " Account found...");
SendClientMessage(playerid, sc_White, " Password correct...");
format(string, sizeof(string), " You have been logged in as '%s'!", ReturnPlayerName(playerid));
SendClientMessage(playerid, sc_Lime, string);
return 1;
}
public registerPlayer(playerid, password[])
{
new string[50], CharName[MAX_PLAYER_NAME];
GetPlayerName(playerid, CharName, sizeof(CharName));
format(string, sizeof(string), "Elimination/Accounts/%s.json", CharName);
djCreateFile(string);
djSet(string,"Key",password);
djSetInt(string,"IsRegistered\n",playerInfo[playerid][IsRegistered]);
djSetInt(string,"AdminLevel\n",playerInfo[playerid][Administrator]);
djSetInt(string,"Cash\n",playerInfo[playerid][Cash]);
djSetInt(string,"Skin\n",playerInfo[playerid][Skin]);
djSetInt(string,"TimeOnline\n",playerInfo[playerid][TimeOnline]);
djSetInt(string,"Experience\n",playerInfo[playerid][Experience]);
djSetInt(string,"AccountStatus\n",playerInfo[playerid][AccountStatus]);
djCommit(string);
loginPlayer(playerid,password);
return 1;
}