fixing where the previous session gets updated, now only update it in case of it being inserted inside the last 10 minutes

This commit is contained in:
jenz
2026-08-25 16:44:31 +02:00
parent f260578def
commit ab481d6d65
@@ -1,6 +1,6 @@
#pragma semicolon 1 #pragma semicolon 1
#define PLUGIN_AUTHOR "jenz" #define PLUGIN_AUTHOR "jenz"
#define PLUGIN_VERSION "1.0" #define PLUGIN_VERSION "1.1"
#include <sourcemod> #include <sourcemod>
#include <geoip> #include <geoip>
#include <unloze_playtime> #include <unloze_playtime>
@@ -128,7 +128,7 @@ public void SQL_FinishedQuerySelectUserSession(Database db, DBResultSet results,
{ {
//new session that we insert //new session that we insert
//chaining the calls //chaining the calls
upsert_player(client); insert_player(client);
} }
delete results; delete results;
} }
@@ -138,12 +138,14 @@ public void update_play_session(int client, int client_hours, int client_minutes
char sSID[64]; char sSID[64];
GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID)); GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
//we only update the latest session row if it actually was updated inside the last 10 minutes. otherwise its an old session that should not be updated.
char sQuery[512]; char sQuery[512];
Format(sQuery, sizeof(sQuery), "UPDATE `playtime_display_sessions` SET session_end_playtime_minutes='%i', session_end_dt=NOW() WHERE steamid = '%s' order by session_id desc limit 1", (client_hours * 60) + client_minutes, sSID); Format(sQuery, sizeof(sQuery), "UPDATE `playtime_display_sessions` SET session_end_playtime_minutes='%i', session_end_dt=NOW() WHERE steamid = '%s' and session_end_dt > NOW() - INTERVAL 10 MINUTE order by session_id desc limit 1", (client_hours * 60) + client_minutes, sSID);
g_hDatabase.Query(SQL_FinishedQuery, sQuery, _, DBPrio_Normal); g_hDatabase.Query(SQL_FinishedQuery, sQuery, _, DBPrio_Normal);
} }
public void upsert_player(int client) public void insert_player(int client)
{ {
char sName[MAX_NAME_LENGTH]; char sName[MAX_NAME_LENGTH];
GetClientName(client, sName, sizeof(sName)); GetClientName(client, sName, sizeof(sName));