Hallo,
wie der Titel bereits schon sagt geht es um ein Login & Register System, basierend auf Y_INI.
Das hier ist die Funktion, die die Spielerdaten lädt, mitsamt Define für den Pfad und dem dazugehörigen enum mit der Variable, die darauf zugreift.
#define UserPath "Users/%s.ini"
enum PlayerInfo
{
Password[129],
IP[16],
bool:JustLoggedIn, //doesn't need to be saved
bool:JustRegistered, //doesn't need to be saved
AdminLevel,
Money,
Bank,
Score,
Kills,
Deaths,
Language,
bool:Desynced
}
new pInfo[MAX_PLAYERS][PlayerInfo];
forward loadaccount_user(playerid, name[], value[]);
public loadaccount_user(playerid, name[], value[])
{
print("loadaccount_user executed."); //Debug Line
INI_String("Password", pInfo[playerid][Password], 129);
INI_String("IP", pInfo[playerid][IP], 16);
INI_Int("AdminLevel", pInfo[playerid][AdminLevel]);
INI_Int("Money", pInfo[playerid][Money]);
INI_Int("Bank", pInfo[playerid][Bank]);
INI_Int("Score", pInfo[playerid][Score]);
INI_Int("Kills", pInfo[playerid][Kills]);
INI_Int("Deaths", pInfo[playerid][Deaths]);
INI_Int("Language", pInfo[playerid][Language]);
return 1;
}
Folgendes steht unter OnPlayerDisconnect. (Das ganze ist gehookt)
public OnPlayerDisconnect(playerid, reason)
{
print("OnPlayerDisconnect executed."); //Debug Line
new INI:file = INI_Open(Path(playerid));
INI_SetTag(file, "User Data");
INI_WriteString(file, "IP", pInfo[playerid][IP]);
INI_WriteInt(file, "AdminLevel", pInfo[playerid][AdminLevel]);
INI_WriteInt(file, "Money", GetPlayerMoney(playerid));
INI_WriteInt(file, "Bank", pInfo[playerid][Bank]);
INI_WriteInt(file, "Score", GetPlayerScore(playerid));
INI_WriteInt(file, "Kills", pInfo[playerid][Kills]);
INI_WriteInt(file, "Deaths", pInfo[playerid][Deaths]);
INI_WriteInt(file, "Language", pInfo[playerid][Language]);
INI_Close(file);
return SAVE_OnPlayerDisconnect(playerid, reason);
}
forward SAVE_OnPlayerDisconnect(playerid, reason);
#if defined _ALS_OnPlayerDisconnect
#undef OnPlayerDisconnect
#else
#define _ALS_OnPlayerDisconnect
#endif
#define OnPlayerDisconnect SAVE_OnPlayerDisconnect
Alle Spielerdaten werden jeweils beim Connect, DIsconnect, sowie beim Login-Dialog und Register-Dialog mittels
INI_ParseFile(Path(playerid), "loadaccount_%s", .bExtra = true, .extra = playerid);
abgerufen.
Was noch von Relevanz sein könnte, wären die zwei Callbacks hier aus dem Main Script.
public OnPlayerSpawn(playerid)
{
SetPlayerColor(playerid, C_BLUE);
new VirtualWorld = GetPlayerVirtualWorld(playerid);
switch(VirtualWorld)
{
case 0:
{
print("The player is in the virtual world 0. Proceed with the code."); //Debug Line
if(pInfo[playerid][JustLoggedIn] == true)
{
print("JustLoggedIn == true, executing code."); //Debug Line
SetCameraBehindPlayer(playerid);
GivePlayerMoneyEx(playerid, pInfo[playerid][Money]);
SetPlayerScore(playerid, pInfo[playerid][Score]);
pInfo[playerid][JustLoggedIn] = false;
}
else if(pInfo[playerid][JustLoggedIn] == false)
{
print("JustLoggedIn == false, executing code."); //Debug Line
GivePlayerMoneyEx(playerid, 5000);
}
if(pInfo[playerid][JustRegistered] == true)
{
print("JustRegistered == true, executing code."); //Debug Line
cmd_rules(playerid, "");
pInfo[playerid][JustRegistered] = false;
GivePlayerMoneyEx(playerid, 5000);
}
print("UseTeleports = true, Spawnprotection set."); //Debug Line
UseTeleports[playerid] = true;
SetSpawnProtection(playerid);
}
}
return 1;
}
public OnPlayerDeath(playerid, killerid, reason)
{
SendDeathMessage(killerid, playerid, reason);
new cash = GetPlayerMoney(playerid);
if(killerid != INVALID_PLAYER_ID) //Killed by another player
{
GivePlayerMoneyEx(killerid, cash);
GivePlayerMoneyEx(playerid, -cash);
pInfo[killerid][Score] += 1;
pInfo[killerid][Kills] += 1;
}
if(killerid == INVALID_PLAYER_ID) //Suicide
{
GivePlayerMoneyEx(playerid, -cash);
}
pInfo[playerid][Deaths] += 1;
return 1;
}
Das ganze passiert, seit ich auf die YSI 4.0 Beta aufgestockt habe.
___________________________________________________________________________________________________________________________________________
EDIT: Ich habe den Code mit den Debug Nachrichten geupdated. Hier ist, was in der Console ausgegeben wird.
[13:45:03] Incoming connection: 127.0.0.1:56637
[13:45:03] [join] Test has joined the server (0:127.0.0.1)
[13:45:05] Parsing Userfile.
[13:45:07] The player is in the virtual world 0. Proceed with the code.
[13:45:07] JustLoggedIn == true, executing code.
[13:45:07] UseTeleports = true, Spawnprotection set.
[13:45:13] OnPlayerDisconnect executed.
[13:45:13] [part] Test has left the server (0:1)