remade sql statement for altering table to just run every 10 seconds

This commit is contained in:
jenz 2022-08-10 13:17:09 +02:00
parent 2c55476ea3
commit 43cb66b2d8

View File

@ -37,6 +37,7 @@ Database g_dDatabase;
Handle hText; Handle hText;
int player_stage[MAXPLAYERS + 1]; int player_stage[MAXPLAYERS + 1];
Handle g_hAlterTableTimer = null;
public Plugin myinfo = public Plugin myinfo =
{ {
@ -66,6 +67,8 @@ public void OnPluginStart()
HookEntityOutput("trigger_teleport", "OnStartTouch", trigger_teleport); HookEntityOutput("trigger_teleport", "OnStartTouch", trigger_teleport);
//HUD //HUD
hText = CreateHudSynchronizer(); 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 //cookies
g_hClientCookie = RegClientCookie("hide_timer_cookie", "Hides the timer HUD", CookieAccess_Private); g_hClientCookie = RegClientCookie("hide_timer_cookie", "Hides the timer HUD", CookieAccess_Private);
for (int i = MaxClients; i > 0; --i) for (int i = MaxClients; i > 0; --i)
@ -77,6 +80,18 @@ public void OnPluginStart()
g_bDisplaySpecial = unloze_gBSpecialMapDisplay(); 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) public void trigger_teleport(const char[] output, int entity_index, int client, float delay)
{ {
if (IsValidEdict(entity_index) && IsValidClient(client) && g_bHumansAllowedTime[client]) 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() public void MYSQLCheckMapEntry()
{ {
int l_iRaceCount; int l_iRaceCount;
int l_iZoneCount = unloze_zoneCount(); int l_iZoneCount = unloze_zoneCount();
char sQuery[g_dLength]; char sQuery[g_dLength];
char l_cZoneIndexName[g_dIndex][g_dLength]; char l_cZoneIndexName[g_dIndex][g_dLength];
if (l_iZoneCount == 1) 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); 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(); DataPack hDataPack = new DataPack();
hDataPack.WriteString(sQuery); hDataPack.WriteString(sQuery);
g_dDatabase.Query(SQL_FinishedQuery, sQuery, hDataPack, DBPrio_High); g_dDatabase.Query(SQL_FinishedQuery, sQuery, hDataPack, DBPrio_High);
} }
else else
{ {
for (int iterator = 0; iterator <= l_iZoneCount; iterator++) for (int iterator = 0; iterator <= l_iZoneCount; iterator++)
{ {
if (IsCorrectZone(iterator, l_cZoneIndexName[iterator][g_dLength -1], "ZONE_PREFIX_RACE")) if (IsCorrectZone(iterator, l_cZoneIndexName[iterator][g_dLength -1], "ZONE_PREFIX_RACE"))
{ {
l_iRaceCount++; 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); 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(); DataPack hDataPack = new DataPack();
hDataPack.WriteString(sQuery); hDataPack.WriteString(sQuery);
g_dDatabase.Query(SQL_FinishedQuery, sQuery, hDataPack, DBPrio_High); g_dDatabase.Query(SQL_FinishedQuery, sQuery, hDataPack, DBPrio_High);
} }
} }
} }
} }
public void SQL_FinishedQuery(Database db, DBResultSet results, const char[] error, DataPack data) public void SQL_FinishedQuery(Database db, DBResultSet results, const char[] error, DataPack data)
@ -230,7 +245,6 @@ public void OnMapStart()
g_bEventBool = false; g_bEventBool = false;
g_bDisplaySpecial = unloze_gBSpecialMapDisplay(); g_bDisplaySpecial = unloze_gBSpecialMapDisplay();
GetCurrentMap(g_cMapname, sizeof(g_cMapname)); GetCurrentMap(g_cMapname, sizeof(g_cMapname));
startTimer();
} }
Format(g_cSpecialMapStart, sizeof(g_cSpecialMapStart), ""); Format(g_cSpecialMapStart, sizeof(g_cSpecialMapStart), "");
Format(g_cSpecialMapEnd, sizeof(g_cSpecialMapEnd), ""); Format(g_cSpecialMapEnd, sizeof(g_cSpecialMapEnd), "");
@ -241,7 +255,9 @@ public void OnMapStart()
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
public void OnPluginEnd() public void OnPluginEnd()
{ {
CloseHandle(hText); CloseHandle(hText);
if (g_hAlterTableTimer != null)
delete g_hAlterTableTimer;
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
// Purpose: // Purpose:
@ -561,13 +577,6 @@ public void unloze_zoneLeave(int client, char[] zone)
} }
} }
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void unloze_zoneCreated()
{
startTimer();
}
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
// Purpose: // Purpose:
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------