From 43cb66b2d8d4887173fa9a2c5a9b33804b0a897f Mon Sep 17 00:00:00 2001 From: jenz Date: Wed, 10 Aug 2022 13:17:09 +0200 Subject: [PATCH] remade sql statement for altering table to just run every 10 seconds --- RaceTimer/scripting/unloze_racetimer_redux.sp | 77 +++++++++++-------- 1 file changed, 43 insertions(+), 34 deletions(-) diff --git a/RaceTimer/scripting/unloze_racetimer_redux.sp b/RaceTimer/scripting/unloze_racetimer_redux.sp index 7646b43d..da613d3d 100644 --- a/RaceTimer/scripting/unloze_racetimer_redux.sp +++ b/RaceTimer/scripting/unloze_racetimer_redux.sp @@ -37,6 +37,7 @@ Database g_dDatabase; Handle hText; int player_stage[MAXPLAYERS + 1]; +Handle g_hAlterTableTimer = null; public Plugin myinfo = { @@ -66,6 +67,8 @@ public void OnPluginStart() HookEntityOutput("trigger_teleport", "OnStartTouch", trigger_teleport); //HUD hText = CreateHudSynchronizer(); + //Just constantly reruns the alter table query to handle new zones, less lazy solution would just be adding a forward for when zones were renamed + g_hAlterTableTimer = CreateTimer(10.00, Timer_alter_tables, _, TIMER_REPEAT); //cookies g_hClientCookie = RegClientCookie("hide_timer_cookie", "Hides the timer HUD", CookieAccess_Private); for (int i = MaxClients; i > 0; --i) @@ -77,6 +80,18 @@ public void OnPluginStart() g_bDisplaySpecial = unloze_gBSpecialMapDisplay(); } +public Action Timer_alter_tables(Handle hTimer) +{ + if (!g_dDatabase) + { + Database.Connect(SQL_OnDatabaseConnect, "racetimercss"); + } + else + { + startTimer(); + } +} + public void trigger_teleport(const char[] output, int entity_index, int client, float delay) { if (IsValidEdict(entity_index) && IsValidClient(client) && g_bHumansAllowedTime[client]) @@ -173,31 +188,31 @@ public void SQL_OnConnectFinished(Database db, DBResultSet results, const char[] public void MYSQLCheckMapEntry() { - int l_iRaceCount; - int l_iZoneCount = unloze_zoneCount(); - char sQuery[g_dLength]; - char l_cZoneIndexName[g_dIndex][g_dLength]; - if (l_iZoneCount == 1) - { - Format(sQuery, sizeof(sQuery), "ALTER TABLE `zetimer_table_new` ADD COLUMN IF NOT EXISTS `%s` REAL DEFAULT 0.000 NOT NULL", g_cMapname); - DataPack hDataPack = new DataPack(); - hDataPack.WriteString(sQuery); - g_dDatabase.Query(SQL_FinishedQuery, sQuery, hDataPack, DBPrio_High); - } - else - { - for (int iterator = 0; iterator <= l_iZoneCount; iterator++) - { - if (IsCorrectZone(iterator, l_cZoneIndexName[iterator][g_dLength -1], "ZONE_PREFIX_RACE")) - { - l_iRaceCount++; - Format(sQuery, sizeof(sQuery), "ALTER TABLE `zetimer_table_new` ADD COLUMN IF NOT EXISTS `%sS%i` REAL DEFAULT 0.000 NOT NULL", g_cMapname, l_iRaceCount); - DataPack hDataPack = new DataPack(); - hDataPack.WriteString(sQuery); - g_dDatabase.Query(SQL_FinishedQuery, sQuery, hDataPack, DBPrio_High); - } - } - } + int l_iRaceCount; + int l_iZoneCount = unloze_zoneCount(); + char sQuery[g_dLength]; + char l_cZoneIndexName[g_dIndex][g_dLength]; + if (l_iZoneCount == 1) + { + Format(sQuery, sizeof(sQuery), "ALTER TABLE `zetimer_table_new` ADD COLUMN IF NOT EXISTS `%s` REAL DEFAULT 0.000 NOT NULL", g_cMapname); + DataPack hDataPack = new DataPack(); + hDataPack.WriteString(sQuery); + g_dDatabase.Query(SQL_FinishedQuery, sQuery, hDataPack, DBPrio_High); + } + else + { + for (int iterator = 0; iterator <= l_iZoneCount; iterator++) + { + if (IsCorrectZone(iterator, l_cZoneIndexName[iterator][g_dLength -1], "ZONE_PREFIX_RACE")) + { + l_iRaceCount++; + Format(sQuery, sizeof(sQuery), "ALTER TABLE `zetimer_table_new` ADD COLUMN IF NOT EXISTS `%sS%i` REAL DEFAULT 0.000 NOT NULL", g_cMapname, l_iRaceCount); + DataPack hDataPack = new DataPack(); + hDataPack.WriteString(sQuery); + g_dDatabase.Query(SQL_FinishedQuery, sQuery, hDataPack, DBPrio_High); + } + } + } } public void SQL_FinishedQuery(Database db, DBResultSet results, const char[] error, DataPack data) @@ -230,7 +245,6 @@ public void OnMapStart() g_bEventBool = false; g_bDisplaySpecial = unloze_gBSpecialMapDisplay(); GetCurrentMap(g_cMapname, sizeof(g_cMapname)); - startTimer(); } Format(g_cSpecialMapStart, sizeof(g_cSpecialMapStart), ""); Format(g_cSpecialMapEnd, sizeof(g_cSpecialMapEnd), ""); @@ -241,7 +255,9 @@ public void OnMapStart() //---------------------------------------------------------------------------------------------------- public void OnPluginEnd() { - CloseHandle(hText); + CloseHandle(hText); + if (g_hAlterTableTimer != null) + delete g_hAlterTableTimer; } //---------------------------------------------------------------------------------------------------- // Purpose: @@ -561,13 +577,6 @@ public void unloze_zoneLeave(int client, char[] zone) } } -//---------------------------------------------------------------------------------------------------- -// Purpose: -//---------------------------------------------------------------------------------------------------- -public void unloze_zoneCreated() -{ - startTimer(); -} //---------------------------------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------------------------------