in unloze zones fixing warnings and using onmapinit forward for initializing the global variable to be used by natives

This commit is contained in:
jenz 2025-01-09 16:57:01 +01:00
parent 79999ec8aa
commit b57d4982c4
2 changed files with 81 additions and 31 deletions

View File

@ -1,7 +1,7 @@
#pragma semicolon 1
#define DEBUG
#define PLUGIN_AUTHOR "jenz"
#define PLUGIN_VERSION "1.8"
#define PLUGIN_VERSION "1.9"
#define g_dLength 400
#define g_dIndex 65
#include <sourcemod>
@ -96,12 +96,13 @@ public Action allow_leaving_again(Handle hTimer, int Serial)
int client;
if ((client = GetClientFromSerial(Serial)) == 0)
{
return;
return Plugin_Handled;
}
if (IsValidClient(client))
{
g_bClient_allowed_to_leave_again[client] = true;
}
return Plugin_Handled;
}
public Action Timer_alter_tables(Handle hTimer)
{
@ -109,6 +110,7 @@ public Action Timer_alter_tables(Handle hTimer)
{
startTimer();
}
return Plugin_Handled;
}
public void trigger_teleport(const char[] output, int entity_index, int client, float delay)
@ -257,62 +259,95 @@ public void SQL_FinishedQuery(Database db, DBResultSet results, const char[] err
delete data;
}
//a mysql table can max have 64 keys attached to it without recompiling. Therefore dropping and attaching binary tree index on the given map start, map end,
//PluginStart Database connection and PluginEnd.
//Adding and removing indexes should be pretty cheap so creating/removing them for only the specific map should be ok
//a mysql table can max have 64 keys attached to it without recompiling. Therefore dropping and attaching binary tree index on the given map start
//also check that racezones actually exist before making a binary tree index
//also handles if the column ends with just mapname or with mapnameS1, mapnameS2 etc etc
//its only relevant for sourcemod scripting part, the java backend making rest endpoints uses a cache and does select * statements so it does not need indexing
//2025: i eventually want to remake most of the race timer but i dont really have time. therefore i am changing this
// with the simple assumption that the plugin only needs to index columns on main ze (port 27015) i will just skip deleting and creating indexes
//for dev and ze2 server.
public void AddBinarySearchIndex()
{
int i_port = GetConVarInt(FindConVar("hostport"));
//only do stuff on ze
if (i_port != 27015)
{
return;
}
int race_zone_count = GetTotalRaceZones();
int l_iZoneCount = unloze_zoneCount();
int l_iZoneCount = unloze_zoneCount(); //need this to check if its one zone or actually two zones with a ZONE_PREFIX_RACE and ZONE_PREFIX_START
char sQuery[g_dLength];
GetCurrentMap(g_cMapname, sizeof(g_cMapname));
//if admins dont make dumb random zones without any meaning it works fine
if (race_zone_count == 1 && l_iZoneCount == 1)
//LogError("race_zone_count: %i. map: %s. l_iZoneCount: %i", race_zone_count, g_cMapname, l_iZoneCount);
//if admins dont make dumb random zones without any meaning it works fine probably(?)
if (race_zone_count == 1 && l_iZoneCount == 1) //there is a ZONE_PREFIX_RACE and its also the only zone on the map.
{
Format(sQuery, sizeof(sQuery), "ALTER TABLE `zetimer_table_new` add INDEX if not exists `%s` (`%s`)", g_cMapname, g_cMapname);
DataPack hDataPack = new DataPack();
hDataPack.WriteString(sQuery);
g_dDatabase.Query(SQL_FinishedQuery, sQuery, hDataPack, DBPrio_Normal);
//LogError("Create index query: %s", sQuery);
g_dDatabase.Query(SQL_FinishedQuery, sQuery, hDataPack, DBPrio_High);
}
else
else if (race_zone_count > 0) //finally fixing the false created indexes.
{
for (int i = 1; i <= race_zone_count; i++)
{
Format(sQuery, sizeof(sQuery), "ALTER TABLE `zetimer_table_new` add INDEX if not exists `%sS%i` (`%sS%i`)", g_cMapname, i, g_cMapname, i);
//LogError("Create index query iteration: %s", sQuery);
DataPack hDataPack = new DataPack();
hDataPack.WriteString(sQuery);
g_dDatabase.Query(SQL_FinishedQuery, sQuery, hDataPack, DBPrio_Normal);
g_dDatabase.Query(SQL_FinishedQuery, sQuery, hDataPack, DBPrio_High);
}
}
}
//if ze1 and ze2 both play the same map and one leaves the map then the other will not have index anymore, but otherwise its fine.
//2025 edit: as said above its not great, will be kept however until the eventual remake of the racetimer.
public void RemoveBinarySearchIndex()
{
char sQuery[g_dLength];
int race_zone_count = GetTotalRaceZones();
int l_iZoneCount = unloze_zoneCount();
GetCurrentMap(g_cMapname, sizeof(g_cMapname));
if (race_zone_count == 1 && l_iZoneCount == 1)
int i_port = GetConVarInt(FindConVar("hostport"));
//only do stuff on ze
if (i_port != 27015)
{
Format(sQuery, sizeof(sQuery), "ALTER TABLE `zetimer_table_new` drop INDEX if exists `%s`", g_cMapname);
return;
}
//lazy change, just take all indexes from the table that are not the primary key. its what we care about.
char sQuery[g_dLength];
Format(sQuery, sizeof(sQuery), "SELECT `INDEX_NAME` FROM `information_schema`.`STATISTICS` WHERE `TABLE_SCHEMA` = 'unloze_racetimer_css' AND `TABLE_NAME` = 'zetimer_table_new' AND `INDEX_NAME` != 'PRIMARY'");
DataPack hDataPack = new DataPack();
hDataPack.WriteString(sQuery);
g_dDatabase.Query(SQL_GetAllIndexes, sQuery, hDataPack, DBPrio_Normal);
}
public void SQL_GetAllIndexes(Database db, DBResultSet results, const char[] error, DataPack data)
{
ResetPack(data);
if (!db || strlen(error))
{
char sQuery[g_dLength];
data.ReadString(sQuery, sizeof(sQuery));
LogError("Query error in SQL_GetAllIndexes: %s", error);
LogError("actual query: %s", sQuery);
delete data;
delete results;
return;
}
delete data;
while (results.RowCount && results.FetchRow())
{
char index_name[256];
results.FetchString(0, index_name, sizeof(index_name));
//LogError("here mapname: %s", index_name);
//just drop the indexes
char sQuery[g_dLength];
Format(sQuery, sizeof(sQuery), "ALTER TABLE `zetimer_table_new` drop INDEX if exists `%s`", index_name);
DataPack hDataPack = new DataPack();
hDataPack.WriteString(sQuery);
g_dDatabase.Query(SQL_FinishedQuery, sQuery, hDataPack, DBPrio_Normal);
}
else
{
for (int i = 1; i <= race_zone_count; i++)
{
Format(sQuery, sizeof(sQuery), "ALTER TABLE `zetimer_table_new` drop INDEX if exists `%sS%i`", g_cMapname, i);
DataPack hDataPack = new DataPack();
hDataPack.WriteString(sQuery);
g_dDatabase.Query(SQL_FinishedQuery, sQuery, hDataPack, DBPrio_Normal);
}
}
delete results;
}
public void OnMapEnd()
@ -1090,6 +1125,7 @@ public int MenuHandler1(Menu menu, MenuAction action, int param1, int param2)
{
if (action == MenuAction_End)
delete menu;
return 0;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
@ -1123,6 +1159,7 @@ public Action cmd_hideTimerHUD(int client, int args)
SetClientCookie(client, g_hClientCookie, "1");
PrintToChat(client, "Disabled timer HUD");
} else { g_bHideTimer[client] = false; PrintToChat(client, "Enabled timer HUD"); SetClientCookie(client, g_hClientCookie, "0"); }
return Plugin_Handled;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
@ -1203,6 +1240,7 @@ public int Stage_menu(Menu menu, MenuAction action, int client, int selection)
{
delete(menu);
}
return 0;
}
//----------------------------------------------------------------------------------------------------
// Purpose:

View File

@ -90,6 +90,7 @@ public int Native_ZoneNameBasedOnIndex(Handle handler, int numParams)
{
int i = GetNativeCell(1);
SetNativeString(2, g_cZones[i], sizeof(g_cZones), true);
return 0;
}
//----------------------------------------------------------------------------------------------------
// Purpose: Displayes zones
@ -176,6 +177,7 @@ public int MenuHandler1(Menu menu, MenuAction action, int param1, int choice)
{
delete menu;
}
return 0;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
@ -203,7 +205,7 @@ public Action MenuZoneCounter(int client)
public int MenuHandler2(Menu menu, MenuAction action, int param1, int choice)
{
if (!IsValidClient(param1))
return;
return 0;
float l_fMiddle[MAXZONES][3];
float l_fMin1[MAXZONES][3], l_fMax1[MAXZONES][3];
if (action == MenuAction_Select)
@ -263,6 +265,7 @@ public int MenuHandler2(Menu menu, MenuAction action, int param1, int choice)
//experimental
g_iAdminSelectOpion[param1] = 0;
}
return 0;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
@ -440,6 +443,7 @@ public int MenuEditExistingZones(Menu menu, MenuAction action, int param1, int c
}
}
}
return 0;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
@ -465,6 +469,7 @@ public Action cmd_menuFinishZone(int client)
menu.AddItem("", "Restart new Zone");
menu.ExitButton = true;
menu.Display(client, 0);
return Plugin_Handled;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
@ -494,6 +499,7 @@ public int MenuHandlerfinishzone(Menu menu, MenuAction action, int param1, int c
cmd_menuFinishZone(param1);
}
}
return 0;
}
//----------------------------------------------------------------------------------------------------
// Purpose: simple say hook
@ -792,6 +798,12 @@ public bool TraceFilter_NoClients(int entity, int contentsMask, any data)
//----------------------------------------------------------------------------------------------------
// Purpose: Mapstart
//----------------------------------------------------------------------------------------------------
public void OnMapInit()
{
resetZones();
ReadZoneFile(); //loading zones a bit earlier for the natives sake.
}
public void OnMapStart()
{
g_bAdminNewZone = false;