Raised This Month: $32 Target: $400
 8% 

Solved [L4D2]Sometimes my DB stats are being wiped, am I using the wrong forwards?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Morning
Member
Join Date: May 2021
Old 12-28-2022 , 07:03   [L4D2]Sometimes my DB stats are being wiped, am I using the wrong forwards?
Reply With Quote #1

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;
}

Last edited by Morning; 01-23-2023 at 15:57.
Morning is offline
Morning
Member
Join Date: May 2021
Old 01-23-2023 , 15:57   Re: [L4D2]Sometimes my DB stats are being wiped, am I using the wrong forwards?
Reply With Quote #2

Just in case this post is happened upon in future, what fixed it for me was to also reset to 0, the client DB primary key in function ResetTotalStats. I'm guessing that sometime, somewhere, the leftover ID is being used to poststats.

EDIT: I'll add that I found an unexpected PostStats occasionally gets called on a bot disconnect: (7)Tank disconnected: Kicked by Console : infected team is full

I have no idea how that's happening, since that bot never got connected in the first place. That's probably what was causing my problem.

Last edited by Morning; 01-27-2023 at 07:27.
Morning is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 14:50.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode