added feature requested by bigode

This commit is contained in:
jenz 2023-04-23 20:21:28 +02:00
parent 63585069d1
commit 901cc232eb

View File

@ -22,6 +22,9 @@ public Plugin myinfo =
url = "www.unloze.com"
};
//timer
Handle g_hTimer_avg_hour_count = null;
public Action time_query_activity(Handle timer, any data)
{
if (!g_hDatabase)
@ -85,6 +88,22 @@ public void OnPluginStart()
HookConVarChange((cvar = CreateConVar("sm_mapchooser_afk_detect_time", "120", "Time in seconds until a player is considered as AFK and therefore excluded from player average time.")), Cvar_playerAFKTime);
g_iPlayerAFKTime = cvar.IntValue;
delete cvar;
g_hTimer_avg_hour_count = CreateTimer(1800.0, log_average_hour_count, _, TIMER_REPEAT);
}
public Action log_average_hour_count(Handle timer, any data)
{
int i_port = GetConVarInt(FindConVar("hostport"));
int avg_hour = GetAveragePlayerActiveTimeServer();
if (!g_hDatabase)
{
Database.Connect(SQL_OnDatabaseConnect, "unloze_playtimestats");
return Plugin_Handled;
}
char sQuery[512];
Format(sQuery, sizeof(sQuery), "INSERT INTO `average_hours` (`avg_hour`, `server_port`) VALUES ('%i', '%i')", avg_hour, i_port);
g_hDatabase.Query(SQL_FinishedQuery, sQuery, _, DBPrio_Low);
return Plugin_Continue;
}
public void Cvar_playerAFKTime(ConVar convar, const char[] oldValue, const char[] newValue)
@ -98,7 +117,7 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char [] error, int err_ma
return APLRes_Success;
}
public int Native_GetAveragePlayerActiveTimeServer(Handle plugin, int numParams)
public int GetAveragePlayerActiveTimeServer()
{
int total_hours = 0;
int total_players = 0;
@ -116,10 +135,19 @@ public int Native_GetAveragePlayerActiveTimeServer(Handle plugin, int numParams)
}
return total_hours / total_players;
}
public int Native_GetAveragePlayerActiveTimeServer(Handle plugin, int numParams)
{
return GetAveragePlayerActiveTimeServer();
}
public void OnPluginEnd()
{
if (g_h_time_activity != null)
delete g_h_time_activity;
if (g_hTimer_avg_hour_count != null)
{
delete g_hTimer_avg_hour_count;
}
}
public void SQL_OnDatabaseConnect(Database db, const char[] error, any data)