added feature requested by bigode
This commit is contained in:
parent
a0c253c980
commit
7a53fd7faf
@ -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)
|
||||
@ -245,11 +273,11 @@ public void insert_client(int client)
|
||||
|
||||
public void SQL_FinishedQuery(Database db, DBResultSet results, const char[] error, any data)
|
||||
{
|
||||
if (!db || strlen(error))
|
||||
{
|
||||
LogError("Query error 3: %s", error);
|
||||
}
|
||||
delete results;
|
||||
if (!db || strlen(error))
|
||||
{
|
||||
LogError("Query error 3: %s", error);
|
||||
}
|
||||
delete results;
|
||||
}
|
||||
|
||||
stock bool IsValidClient(int client)
|
||||
@ -261,37 +289,37 @@ stock bool IsValidClient(int client)
|
||||
|
||||
public void OnMapStart()
|
||||
{
|
||||
if (!g_hDatabase)
|
||||
{
|
||||
Database.Connect(SQL_OnDatabaseConnect, "unloze_playtimestats");
|
||||
return;
|
||||
}
|
||||
char sQuery[512];
|
||||
char sServer[32];
|
||||
if (!g_hDatabase)
|
||||
{
|
||||
Database.Connect(SQL_OnDatabaseConnect, "unloze_playtimestats");
|
||||
return;
|
||||
}
|
||||
char sQuery[512];
|
||||
char sServer[32];
|
||||
|
||||
int i_port = GetConVarInt(FindConVar("hostport"));
|
||||
if (i_port == 27015 || i_port == 27019)
|
||||
{
|
||||
Format(sServer, sizeof(sServer), "ze_time");
|
||||
}
|
||||
else if (i_port == 27016)
|
||||
{
|
||||
Format(sServer, sizeof(sServer), "zr_time");
|
||||
}
|
||||
else if (i_port == 27017)
|
||||
{
|
||||
Format(sServer, sizeof(sServer), "mg_time");
|
||||
}
|
||||
else if (i_port == 27023)
|
||||
{
|
||||
Format(sServer, sizeof(sServer), "jb_time");
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
Format(sQuery, sizeof(sQuery), "select player_name, sum(%s) as %s_total from unloze_playtimestats.player_time GROUP BY steam_id order by %s_total desc limit 100", sServer, sServer, sServer);
|
||||
g_hDatabase.Query(SQL_OnQueryCompletedTopTime, sQuery);
|
||||
int i_port = GetConVarInt(FindConVar("hostport"));
|
||||
if (i_port == 27015 || i_port == 27019)
|
||||
{
|
||||
Format(sServer, sizeof(sServer), "ze_time");
|
||||
}
|
||||
else if (i_port == 27016)
|
||||
{
|
||||
Format(sServer, sizeof(sServer), "zr_time");
|
||||
}
|
||||
else if (i_port == 27017)
|
||||
{
|
||||
Format(sServer, sizeof(sServer), "mg_time");
|
||||
}
|
||||
else if (i_port == 27023)
|
||||
{
|
||||
Format(sServer, sizeof(sServer), "jb_time");
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
Format(sQuery, sizeof(sQuery), "select player_name, sum(%s) as %s_total from unloze_playtimestats.player_time GROUP BY steam_id order by %s_total desc limit 100", sServer, sServer, sServer);
|
||||
g_hDatabase.Query(SQL_OnQueryCompletedTopTime, sQuery);
|
||||
}
|
||||
|
||||
public Action Command_TopTime(int client, int args)
|
||||
|
Loading…
Reference in New Issue
Block a user