There is a problem somewhere in my stats / databasing code which is causing individual player stats to be erased from the database. It's a fairly rare problem, happening once in a few days, so it must be some kind of edge case which I have not accounted for.
Stats must be being posted after they have been reset but before database stats have been loaded for that client. I'm guessing this is due to me misunderstanding the order in which things are being done with the forwards.
This is the code taken from the plugin I wrote (and clarified):
Code:
int ga_i_kills[MAXPLAYERS + 1]; // Some stats
int ga_i_deaths[MAXPLAYERS + 1];
int ga_i_ID[MAXPLAYERS + 1]; // DB Primary key
char ga_s_steamid[64][MAXPLAYERS + 1]; //Steam ID
public OnMapStart()
{
for(int i = 1; i <= MaxClients; i++)
{
ResetTotalStats(i); // Reset global var stats
}
CalcRank(db); // Runs a query to populate player Rank column in DB. ~1s
}
public OnClientPostAdminCheck(int client)
{
ResetTotalStats(client);
if(!IsFakeClient(client))
{
GetClientAuthId(client, AuthId_Engine, ga_s_steamid[client], 64);
InitPlayer(db, ga_s_steamid[client], client); // populate global vars from DB stats using steamid
}
}
public void OnClientDisconnect(int client) // Called directly before OnMapEnd for every client?
{
if(!IsFakeClient(client) && IsClientInGame(client)) // if disconnect not between OnMapEnd and when client re-enters game
{
PostStats(db, client);
ResetTotalStats(client);
}
}
public void PostStats(Database hdb, int client)
{
// update player row in DB with global var stats.
}
public void ResetTotalStats(int client)
{
ga_i_kills[client] = 0;
ga_i_deaths[client] = 0;
}