From 51a25533707413e4ae846e48889fd8fc93d36628 Mon Sep 17 00:00:00 2001 From: Dogan Date: Sat, 19 Oct 2019 15:49:25 +0200 Subject: [PATCH] PlaytimeStats: update for all servers --- PlaytimeStats/scripting/PlaytimeStats.sp | 63 +++++++++++++++++++++--- 1 file changed, 56 insertions(+), 7 deletions(-) diff --git a/PlaytimeStats/scripting/PlaytimeStats.sp b/PlaytimeStats/scripting/PlaytimeStats.sp index 24d84d63..d8f1bf50 100644 --- a/PlaytimeStats/scripting/PlaytimeStats.sp +++ b/PlaytimeStats/scripting/PlaytimeStats.sp @@ -8,12 +8,15 @@ Database g_hDatabase; int g_iConnectionTime[MAXPLAYERS + 1]; bool g_bPlayerValid[MAXPLAYERS + 1]; +ConVar g_cvServerType; +int g_iServerType; + public Plugin myinfo = { name = "PlaytimeStats", author = "Dogan", description = "Retreives total playtime on multiple servers for clients", - version = "1.1.0", + version = "2.0.0", url = "" } @@ -25,12 +28,27 @@ public void OnPluginStart() RegConsoleCmd("sm_topplaytime", Command_TopTime, "retreives top 12 playtime highscores on all connected servers"); } +public void OnAllPluginsLoaded() +{ + if((g_cvServerType = FindConVar("sm_server_type")) == INVALID_HANDLE) + SetFailState("Failed to find sm_server_type cvar."); + else + g_iServerType = g_cvServerType.IntValue; +} + public Action Command_Time(int client, int args) { int iAuthID = GetSteamAccountID(client); char sQuery[512]; - Format(sQuery, sizeof(sQuery), "SELECT time FROM playtime WHERE auth = '%d'", iAuthID); + + if(g_iServerType == 1) + Format(sQuery, sizeof(sQuery), "SELECT time FROM playtimeze WHERE auth = '%d'", iAuthID); + else if(g_iServerType == 2) + Format(sQuery, sizeof(sQuery), "SELECT time FROM playtimemg WHERE auth = '%d'", iAuthID); + else if(g_iServerType == 3) + Format(sQuery, sizeof(sQuery), "SELECT time FROM playtimezr WHERE auth = '%d'", iAuthID); + g_hDatabase.Query(SQL_OnQueryCompletedTime, sQuery, GetClientSerial(client)); return Plugin_Handled; @@ -39,7 +57,14 @@ public Action Command_Time(int client, int args) public Action Command_TopTime(int client, int args) { char sQuery[255]; - Format(sQuery, sizeof(sQuery), "SELECT * from playtime order by time desc limit 12"); + + if(g_iServerType == 1) + Format(sQuery, sizeof(sQuery), "SELECT * from playtimeze order by time desc limit 12"); + else if(g_iServerType == 2) + Format(sQuery, sizeof(sQuery), "SELECT * from playtimemg order by time desc limit 12"); + else if(g_iServerType == 3) + Format(sQuery, sizeof(sQuery), "SELECT * from playtimezr order by time desc limit 12"); + g_hDatabase.Query(SQL_OnQueryCompletedTopTime, sQuery, GetClientSerial(client)); return Plugin_Handled; @@ -74,7 +99,13 @@ public void OnClientDisconnect(int client) g_hDatabase.Escape(sName, sSafeName, sizeof(sSafeName)); char sQuery[512]; - Format(sQuery, sizeof(sQuery), "INSERT INTO playtime (auth,name,time) VALUES ('%u', '%s', '%d') ON DUPLICATE KEY UPDATE time=time+%d", iAuthID, sSafeName, iPlayTime, iPlayTime); + + if(g_iServerType == 1) + Format(sQuery, sizeof(sQuery), "INSERT INTO playtimeze (auth,name,time) VALUES ('%u', '%s', '%d') ON DUPLICATE KEY UPDATE time=time+%d", iAuthID, sSafeName, iPlayTime, iPlayTime); + else if(g_iServerType == 2) + Format(sQuery, sizeof(sQuery), "INSERT INTO playtimemg (auth,name,time) VALUES ('%u', '%s', '%d') ON DUPLICATE KEY UPDATE time=time+%d", iAuthID, sSafeName, iPlayTime, iPlayTime); + else if(g_iServerType == 3) + Format(sQuery, sizeof(sQuery), "INSERT INTO playtimezr (auth,name,time) VALUES ('%u', '%s', '%d') ON DUPLICATE KEY UPDATE time=time+%d", iAuthID, sSafeName, iPlayTime, iPlayTime); g_hDatabase.Query(SQL_OnQueryCompleted, sQuery, _, DBPrio_Low); } @@ -90,7 +121,13 @@ public void SQL_OnDatabaseConnect(Database db, const char[] error, any data) g_hDatabase = db; char sQuery[512]; - Format(sQuery, sizeof(sQuery), "CREATE TABLE IF NOT EXISTS playtime (`auth` INTEGER UNSIGNED, `name` varchar(128), `time` INTEGER, PRIMARY KEY (`auth`), INDEX (`time`))"); + + if(g_iServerType == 1) + Format(sQuery, sizeof(sQuery), "CREATE TABLE IF NOT EXISTS playtimeze (`auth` INTEGER UNSIGNED, `name` varchar(128), `time` INTEGER, PRIMARY KEY (`auth`), INDEX (`time`))"); + else if(g_iServerType == 2) + Format(sQuery, sizeof(sQuery), "CREATE TABLE IF NOT EXISTS playtimemg (`auth` INTEGER UNSIGNED, `name` varchar(128), `time` INTEGER, PRIMARY KEY (`auth`), INDEX (`time`))"); + else if(g_iServerType == 3) + Format(sQuery, sizeof(sQuery), "CREATE TABLE IF NOT EXISTS playtimezr (`auth` INTEGER UNSIGNED, `name` varchar(128), `time` INTEGER, PRIMARY KEY (`auth`), INDEX (`time`))"); g_hDatabase.Query(SQL_OnQueryCompleted, sQuery, _, DBPrio_Low); } @@ -141,7 +178,12 @@ public void SQL_OnQueryCompletedTime(Database db, DBResultSet results, const cha Format(sTime, sizeof(sTime), "%d Seconds", iSeconds); char sTitle[64]; - Format(sTitle, sizeof(sTitle), "[UNLOZE Playtime] Player %N:", client); + if(g_iServerType == 1) + Format(sTitle, sizeof(sTitle), "[UNLOZE Playtime Zombie Escape] Player %N:", client); + else if(g_iServerType == 2) + Format(sTitle, sizeof(sTitle), "[UNLOZE Playtime Minigames] Player %N:", client); + else if(g_iServerType == 3) + Format(sTitle, sizeof(sTitle), "[UNLOZE Playtime Zombie Riot] Player %N:", client); Panel mSayPanel = new Panel(GetMenuStyleHandle(MenuStyle_Radio)); @@ -175,7 +217,14 @@ public void SQL_OnQueryCompletedTopTime(Database db, DBResultSet results, const char sBuffer[12][128]; Panel mSayPanel = new Panel(GetMenuStyleHandle(MenuStyle_Radio)); - mSayPanel.SetTitle("[UNLOZE Playtime] Record Holders:"); + + if(g_iServerType == 1) + mSayPanel.SetTitle("[UNLOZE Playtime] Record Holders Zombie Escape:"); + else if(g_iServerType == 2) + mSayPanel.SetTitle("[UNLOZE Playtime] Record Holders Minigames:"); + else if(g_iServerType == 3) + mSayPanel.SetTitle("[UNLOZE Playtime] Record Holders Zombie Riot:"); + mSayPanel.DrawItem("", ITEMDRAW_SPACER); for(int i = 1; i <= 12; i++)