pawn Код:
enum pInfo
{
pKills,
pDeaths,
pVisits
}
new PlayerInfo[MAX_PLAYERS][pInfo];
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, 100, DIALOG_STYLE_INPUT, "Test", "Welcome, your not registered!", "Register", "Leave");
}
if(fexist(file))
{
ShowPlayerDialog(playerid, 200, DIALOG_STYLE_INPUT, "Test", "Welcome back to server!", "Login", "Leave");
}
PlayerInfo[playerid][pVisits]++;
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
new name[MAX_PLAYER_NAME], file[256];
GetPlayerName(playerid, name, sizeof(name));
format(file, sizeof(file), SERVER_USER_FILE, name);
if(gPlayerLogged[playerid] == 1)
{
dini_IntSet(file, "Kills",PlayerInfo[playerid][pKills]);
dini_IntSet(file, "Deaths",PlayerInfo[playerid][pDeaths]);
dini_IntSet(file, "Visits", PlayerInfo[playerid][pVisits]);
}
gPlayerLogged[playerid] = 0;
return 1;
}
public OnPlayerSpawn(playerid)
{
gPlayerLogged[playerid] = 1;
new name[MAX_PLAYER_NAME], file[256];
GetPlayerName(playerid, name, sizeof(name));
format(file, sizeof(file), SERVER_USER_FILE, name);
return 1;
}
public OnPlayerDeath(playerid, killerid, reason)
{
PlayerInfo[killerid][pKills]++;
PlayerInfo[playerid][pDeaths]++;
SendDeathMessage(killerid, playerid, reason);
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
// |-------| |---------| REGISTER / LOGIN |-----------| |----------|
if (dialogid == 100)
{
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, "Test", "Welcome, your not registered!", "Register", "Leave");
dini_Create(file);
dini_IntSet(file, "Password", udb_hash(inputtext));
dini_IntSet(file, "Kills",PlayerInfo[playerid][pKills] = 0);
dini_IntSet(file, "Deaths",PlayerInfo[playerid][pDeaths] = 0);
dini_IntSet(file, "Visits", PlayerInfo[playerid][pVisits] = 0);
format(string, 128, ""COL_ORANGE"You succesfully registered the nickname "COL_VIOLET"%s "COL_ORANGE"with password "COL_VIOLET"%s"COL_ORANGE", you have been auto logged in.", name, inputtext);
SendClientMessage(playerid, -1, string);
gPlayerLogged[playerid] = 1;
}
if (dialogid == 200)
{
new name[MAX_PLAYER_NAME], file[256];
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, "Test", "Welcome back to server!", "Login", "Leave");
new tmp;
tmp = dini_Int(file, "Password");
if(udb_hash(inputtext) != tmp) {
SendClientMessage(playerid, -1, ""COL_RED"[Error] "COL_WHITE"Wrong password!");
ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Test", "Welcome back to server!", "Login", "Leave");
}
else
{
gPlayerLogged[playerid] = 1;
PlayerInfo[playerid][pKills] = dini_Int(file, "Kills");
PlayerInfo[playerid][pDeaths] = dini_Int(file, "Deaths");
PlayerInfo[playerid][pVisits] = dini_Int(file, "Visits");
SendClientMessage(playerid, -1, ""COL_ORANGE"Successfully logged in!");
}
}
return 1;
}