#include <a_samp>
#include <YSI\y_ini>
#include <zcmd>
#include <sscanf2>
#include "../include/gl_common.inc"
enum PlayerInfo
{
Pass[129],
Adminlevel,
Premlevel,
CharSkin,
CharMoney,
CharScore,
CharKills,
CharDeaths,
IsJailed,
}
forward loadaccount_user(playerid, name[], value[]);
public loadaccount_user(playerid, name[], value[])
{
printf("%s -> %s", name, value);
INI_String("Password", pInfo[playerid][Pass], 129);
INI_Int("Adminlevel" ,pInfo[playerid][Adminlevel]);
INI_Int("Premlevel", pInfo[playerid][Premlevel]);
INI_Int("CharSkin", pInfo[playerid][CharSkin]);
INI_Int("CharMoney", pInfo[playerid][CharMoney]);
INI_Int("CharScore", pInfo[playerid][CharScore]);
INI_Int("CharKills", pInfo[playerid][CharKills]);
INI_Int("CharDeaths", pInfo[playerid][CharDeaths]);
INI_Int("IsJailed", pInfo[playerid][IsJailed]);
return 1;
}
public OnPlayerConnect(playerid)
{
format(string2, sizeof(string2), "{A9C4E4}# [Server] %s {EAEAEA}has connected to the server.", GetName(playerid));
SendClientMessageToAll(COLOR_SERVER ,string2);
SetTimerEx("ClearScreen", 1, false, "i", playerid);
new string1[300]; new registerid; new loginid; new name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
if(fexist(Path(playerid)))
{
INI_ParseFile(Path(playerid), "loadaccount_%s", .bExtra = true, .extra = playerid);
format(string1, sizeof(string1), "{EAEAEA}Enter your password below to login!", GetName(loginid), loginid);
ShowPlayerDialog(playerid, LOGIN_DIALOG, DIALOG_STYLE_PASSWORD, "{A9C4E4}Server {EAEAEA}- Login:", string1, "Login", "Quit");
}
else
{
format(string, sizeof(string), "{EAEAEA}Enter a password below to register!", GetName(registerid), registerid);
ShowPlayerDialog(playerid, REGISTER_DIALOG, DIALOG_STYLE_PASSWORD, "{A9C4E4}Server {EAEAEA}- Register:", string, "Register", "Quit");
return 1;
}
stock save(playerid)
{
new INI:file = INI_Open(Path(playerid));
INI_SetTag(file, "Character");
INI_WriteInt(file, "Adminlevel", pInfo[playerid][Adminlevel]);
INI_WriteInt(file, "Premlevel", pInfo[playerid][Premlevel]);
INI_WriteInt(file, "CharSkin", pInfo[playerid][CharSkin]);
INI_WriteInt(file, "CharMoney", GetPlayerMoney(playerid));
INI_WriteInt(file, "CharScore", GetPlayerScore(playerid));
INI_WriteInt(file, "CharKills", pInfo[playerid][CharKills]);
INI_WriteInt(file, "CharDeaths", pInfo[playerid][CharDeaths]);
INI_WriteInt(file, "IsJailed", pInfo[playerid][IsJailed]);
INI_Close(file);
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == REGISTER_DIALOG)
{
if(!response)return Kick(playerid);
if(response)
{
if(!strlen(inputtext))
{
new string[300];
new registerid;
format(string, sizeof(string), "{EAEAEA}Hello, {A9C4E4}%s{EAEAEA}.\n\nPlease enter a password below.", GetName(registerid));
ShowPlayerDialog(playerid, REGISTER_DIALOG, DIALOG_STYLE_PASSWORD, "{A9C4E4}Server {EAEAEA}- Register:", string, "Register", "Quit");
return 1;
}
new hashpass[129];
WP_Hash(hashpass, sizeof(hashpass), inputtext);
new INI:file = INI_Open(Path(playerid));
INI_SetTag(file, "Character");
INI_WriteString(file, "Password", hashpass);
INI_WriteInt(file, "Adminlevel", 0);
INI_WriteInt(file, "Premlevel", 0);
INI_WriteInt(file, "CharSkin", 60);
INI_WriteInt(file, "CharMoney", 15000);
INI_WriteInt(file, "CharScore", 1);
INI_WriteInt(file, "CharKills", 1);
INI_WriteInt(file, "CharDeaths", 1);
INI_WriteInt(file, "IsJailed", 0);
INI_Close(file);
new rstring[200];
new registerid;
format(rstring, sizeof(rstring), "{A9C4E4}Server {EAEAEA}- You have successfully registered, {A9C4E4}%s{EAEAEA}!", GetName(registerid));
SendClientMessage(playerid, COLOR_SERVER, "Reminder: {EAEAEA}The server is currently underdevelopment - You might experience bugs");
SendClientMessage(playerid, COLOR_GREEN, rstring);
muted[playerid] = 0;
return 1;
}
}
if(dialogid == LOGIN_DIALOG)
{
if(!response)return Kick(playerid);
if(response)
{
new hashpass[129];
WP_Hash(hashpass, sizeof(hashpass), inputtext);
if(!strcmp(hashpass, pInfo[playerid][Pass]))
{
new loginid = playerid;
new lstring[300];
INI_ParseFile(Path(playerid), "loadaccount_%s", .bExtra = true, .extra = playerid);
SetPlayerScore(playerid, pInfo[playerid][CharScore]);
GivePlayerMoney(playerid, pInfo[playerid][CharMoney]);
format(lstring, sizeof(lstring), "{EAEAEA}Welcome Back, {A9C4E4}%s{EAEAEA}. {EAEAEA}You have successfully logged in!", GetName(loginid));
SendClientMessage(playerid, COLOR_SERVER, "Reminder: {EAEAEA}The server is currently underdevelopment - You might experience bugs");
SendClientMessage(playerid, COLOR_GREEN, lstring);
muted[playerid] = 0;
}
else
{
new string1[300];
format(string1, sizeof(string1), "{EAEAEA}Enter your password below to login!", GetName(playerid), playerid);
ShowPlayerDialog(playerid, LOGIN_DIALOG, DIALOG_STYLE_PASSWORD, "{A9C4E4}Server - {EAEAEA}Login:", string1, "Login", "Quit");
SendClientMessage(playerid, COLOR_RED, "{ff6347}Error: Wrong Password!");
}
}
return 1; // We handled a dialog, so return 1. Just like OnPlayerCommandText.
}
return 0; // You MUST return 0 here! Just like OnPlayerCommandText.
}
[Character] IsJailed = 0 CharDeaths = 0 CharKills = 0 CharScore = 60 CharMoney = 15000 CharSkin = 3 Premlevel = 1 Adminlevel = 5 Password = 1542..-
try to check if player logged onplayerdisconnect if yes save all stats then set logged to false or zero
|
[1] Register // Working
[2] Spawn // Working (add pInfo)
[6] Disconnect // Working (save pInfo)
[4] Connect // Allows you to use incorrect password
[5] Spawn // Working (excluding [4])
[6] Disconnect // Working (saved pInfo: excluding [4])
[7] Follow with GMX: // Working (saved pInfo: excluding [4])
[8] Connect // All reset; [1]