diff --git a/scripting/FartsysAss.sp b/scripting/FartsysAss.sp index f78e416..10b107c 100644 --- a/scripting/FartsysAss.sp +++ b/scripting/FartsysAss.sp @@ -18,21 +18,10 @@ #include #include #include +#include #pragma newdecls required #pragma semicolon 1 -Database Get_Ass_Database() { - return Ass_Database; -} -COREDATA GetCoreData() { - return core; -} -BOSSHANDLER Get_Boss_Handler() { - return BossHandler; -} -int GetGameMode() { - return core.gamemode; -} public Plugin myinfo = { name = "Fartsy's Ass - Framework", @@ -53,6 +42,7 @@ public void OnPluginStart() { CPrintToChatAll("{darkred}Plugin Reloaded. If you do not hear music, please do !sounds and configure your preferences."); cvarSNDDefault = CreateConVar("sm_fartsysass_sound", "3", "Default sound for new users, 3 = Everything, 2 = Sounds Only, 1 = Music Only, 0 = Nothing"); AssLogger(LOGLVL_INFO, "####### STARTUP COMPLETE (v%s) #######", PLUGIN_VERSION); + CreateTimer(15.0, StatsTracker); } //Begin executing IO when ready diff --git a/scripting/include/fartsy/ass_bosshandler.inc b/scripting/include/fartsy/ass_bosshandler.inc index f755ae4..36f57b8 100644 --- a/scripting/include/fartsy/ass_bosshandler.inc +++ b/scripting/include/fartsy/ass_bosshandler.inc @@ -386,7 +386,9 @@ enum struct BOSSHANDLER { } } BOSSHANDLER BossHandler; - +BOSSHANDLER Get_Boss_Handler() { + return BossHandler; +} //Player specific async tick process public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3], float angles[3], int &weapon){ if (BossHandler.shouldTick) BossHandler.TickForClient(client); diff --git a/scripting/include/fartsy/ass_enhancer.inc b/scripting/include/fartsy/ass_enhancer.inc index 413adcd..7d24a63 100644 --- a/scripting/include/fartsy/ass_enhancer.inc +++ b/scripting/include/fartsy/ass_enhancer.inc @@ -90,7 +90,7 @@ enum struct AUDIOMANAGER { this.refireBGM = BGMArray[this.indexBGM].refireTime; this.ticksBGM = (this.tickBGMOffset ? BGMArray[this.indexBGM].ticksOffset : 0); for (int i = 0; i < MaxClients; i++){ - //if(tacobell && isClientInEvent(i)) return;// To test if client is experiencing anything odd..... + //if(core.gamemode > 0 && isClientInEvent(i)) continue;// To test if client is experiencing anything odd..... CSEClient(i, BGMArray[this.indexBGM].realPath, BGMArray[this.indexBGM].SNDLVL, true, 1, 1.0, 100); } //CustomSoundEmitter(BGMArray[this.indexBGM].realPath, BGMArray[this.indexBGM].SNDLVL, true, 1, 1.0, 100); diff --git a/scripting/include/fartsy/ass_helper.inc b/scripting/include/fartsy/ass_helper.inc index 5dbfc83..915e1f7 100644 --- a/scripting/include/fartsy/ass_helper.inc +++ b/scripting/include/fartsy/ass_helper.inc @@ -99,7 +99,18 @@ enum struct COREDATA { } } COREDATA core; +COREDATA GetCoreData() { + return core; +} + +int GetGameMode() { + return core.gamemode; +} + Database Ass_Database; +Database Get_Ass_Database() { + return Ass_Database; +} int attemptSpawn = 0; bool isGoobbue = false; bool CircleAOEenabled[] = { @@ -944,6 +955,7 @@ void RegisterAllCommands(){ //Connect to database public void OnConfigsExecuted() { if (!Ass_Database) Database.Connect(Database_OnConnect, "ass"); + if (!Get_Ass_Database_ServerMetrics()) Database.Connect(Database_OnMetricsConnect, "ass_servermetrics"); } //Format database if needed public void Database_OnConnect(Database db, char[] error, any data) { @@ -969,6 +981,21 @@ public void Database_OnConnect(Database db, char[] error, any data) { } } } +//Connect to metrics db +public void Database_OnMetricsConnect(Database db, char[] error, any data) { + if (!db) { + AssLogger(3, error); + return; + } + char buffer[64]; + db.Driver.GetIdentifier(buffer, sizeof(buffer)); + if (!StrEqual(buffer, "mysql", false)) { + delete db; + AssLogger(3, "Could not connect to the database: expected mysql database."); + return; + } + Set_Ass_Database_ServerMetrics(db); +} //Database Fastquery Manager public void Database_FastQuery(Database db, DBResultSet results, const char[] error, any data) { diff --git a/scripting/include/fartsy/ass_serverutils.inc b/scripting/include/fartsy/ass_serverutils.inc new file mode 100644 index 0000000..58b9e46 --- /dev/null +++ b/scripting/include/fartsy/ass_serverutils.inc @@ -0,0 +1,83 @@ +// ASS Utilities - Advanced server features +Database Ass_Database_ServerMetrics; +void Set_Ass_Database_ServerMetrics(Database db) { + Ass_Database_ServerMetrics = db; +} +Database Get_Ass_Database_ServerMetrics() { + return Ass_Database_ServerMetrics; +} +//Gets the server time as an int array, 0 = hour, 1 = minute, 2 = AM/PM(0/1 respectively) +void GetServerTime(int retVal[3]) { + char buffer[8]; + FormatTime(buffer, sizeof(buffer), "%I", GetTime()); + int hour = StringToInt(buffer); + FormatTime(buffer, sizeof(buffer), "%M", GetTime()); + int minute = StringToInt(buffer); + FormatTime(buffer, sizeof(buffer), "%p", GetTime()); + int ampm = (StrEqual(buffer, "AM")) ? 0 : 1; + retVal[0] = hour; + retVal[1] = minute; + retVal[2] = ampm; +} +//Gets the server stats and display it in the server +public Action StatsTracker(Handle timer) { + int time[3]; + GetServerTime(time); + char hour[4], minute[4], ampm[4]; + Format(hour, sizeof(hour), "%i", time[0]); + Format(minute, sizeof(minute), "%i", time[1]); + Format(ampm, sizeof(ampm), "%i", time[2]); + FastFire2("FBMetric.TimeHH", "SetTextureIndex", hour, 0.0, false); + FastFire2("FBMetric.TimeMM", "SetTextureIndex", minute, 0.0, false); + FastFire2("FBMetric.TimeAMPM", "SetTextureIndex", ampm, 0.0, false); + PrintToChatAll("Current time is %s:%s %s", hour, minute, StringToInt(ampm) == 0 ? "AM" : "PM"); + CreateTimer(15.0, StatsTracker); + if (!Get_Ass_Database()) return Plugin_Stop; + char query[512]; + query[0] = '\0'; // Clear buffer + StrCat(query, sizeof(query), "SELECT 'memory_used_gib' AS name, value FROM memory_used_gib WHERE id = 1 "); + StrCat(query, sizeof(query), "UNION ALL SELECT 'memory_total_gib', value FROM memory_total_gib WHERE id = 1 "); + StrCat(query, sizeof(query), "UNION ALL SELECT 'cpu_usage_percent', value FROM cpu_usage_percent WHERE id = 1 "); + StrCat(query, sizeof(query), "UNION ALL SELECT 'cpu_frequency_x10', value FROM cpu_frequency_x10 WHERE id = 1 "); + StrCat(query, sizeof(query), "UNION ALL SELECT 'cpu_temperature_c', value FROM cpu_temperature_c WHERE id = 1"); + SQL_TQuery(Ass_Database_ServerMetrics, OnMetricsFetch, query); + return Plugin_Stop; +} + +public void OnMetricsFetch(Database db, DBResultSet results, const char[] error, any data) +{ + if (results == null) + { + LogError("Stat fetch failed: %s", error); + return; + } + + while (results.FetchRow()) + { + char name[32]; + int value; + results.FetchString(0, name, sizeof(name)); + value = results.FetchInt(1); + char val[32]; + if (StrEqual(name, "memory_used_gib")) { + Format(val, sizeof(val), "%i", value); + FastFire2("FBMetric.RAMUtil", "SetTextureIndex", val, 0.0, false); + } else if (StrEqual(name, "memory_total_gib")) { + Format(val, sizeof(val), "%i", value); + FastFire2("FBMetric.RAMTotal", "SetTextureIndex", val, 0.0, false); + } else if (StrEqual(name, "cpu_usage_percent")) { + Format(val, sizeof(val), "%i", value); + FastFire2("FBMetric.CPUUtil", "SetTextureIndex", val, 0.0, false); + //PrintToServer("CPU Usage: %d%%", value); + } else if (StrEqual(name, "cpu_frequency_x10")) { + Format(val, sizeof(val), "%i", value); + FastFire2("FBMetric.CPUFreq", "SetTextureIndex", val, 0.0, false); + //PrintToServer("CPU Freq: %.1f GHz", value / 10.0); + } else if (StrEqual(name, "cpu_temperature_c")) { + Format(val, sizeof(val), "%i", value); + FastFire2("FBMetric.CPUTemp", "SetTextureIndex", val, 0.0, false); + //PrintToServer("CPU Temp: %d°C", value); + } + } + FastFire2("FBMetrics.*", "Enable", "", 0.0, false); +} \ No newline at end of file diff --git a/scripting/include/fartsy/ass_sudo.inc b/scripting/include/fartsy/ass_sudo.inc index b3c9405..489ae65 100644 --- a/scripting/include/fartsy/ass_sudo.inc +++ b/scripting/include/fartsy/ass_sudo.inc @@ -1,4 +1,4 @@ -public char PLUGIN_VERSION[8] = "8.2.0a"; +public char PLUGIN_VERSION[8] = "8.2.0c"; void sudo(int task) { AssLogger(LOGLVL_DEBUG, "Calling sudo with %i", task); switch (task) {