Fix rankings only working after late-loading. (#474)

This commit is contained in:
shavitush 2017-09-11 19:19:35 +03:00
parent 813a3c2b0a
commit 292dc8f2fe
5 changed files with 63 additions and 23 deletions

View File

@ -108,7 +108,10 @@ public void OnAllPluginsLoaded()
SetFailState("shavit-wr is required for the plugin to work.");
}
if(gH_SQL == null)
{
Shavit_OnDatabaseLoaded();
}
}
public void OnPluginStart()
@ -248,7 +251,7 @@ void SQL_DBConnect()
char[] sQuery = new char[256];
FormatEx(sQuery, 256, "CREATE TABLE IF NOT EXISTS `%smaptiers` (`map` VARCHAR(160), `tier` INT NOT NULL DEFAULT 1, PRIMARY KEY (`map`));", gS_MySQLPrefix);
gH_SQL.Query(SQL_CreateTable_Callback, sQuery, 0, DBPrio_High);
gH_SQL.Query(SQL_CreateTable_Callback, sQuery, 0);
}
}
@ -261,6 +264,15 @@ public void SQL_CreateTable_Callback(Database db, DBResultSet results, const cha
return;
}
#if defined DEBUG
PrintToServer("DEBUG: 0 (SQL_CreateTable_Callback)");
#endif
if(gI_Styles == 0)
{
Shavit_OnStyleConfigLoaded(-1);
}
OnMapStart();
if(gB_Late)
@ -298,12 +310,11 @@ public void OnMapStart()
return;
}
UpdateRankedPlayers();
#if defined DEBUG
PrintToServer("DEBUG: 1 (OnMapStart)");
#endif
if(gB_Late)
{
Shavit_OnStyleConfigLoaded(-1);
}
UpdateRankedPlayers();
GetCurrentMap(gS_Map, 160);
GetMapDisplayName(gS_Map, gS_Map, 160);
@ -312,8 +323,6 @@ public void OnMapStart()
// I won't repeat the same mistake blacky has done with tier 3 being default..
gI_Tier = 1;
if(gH_SQL != null)
{
char[] sDriver = new char[8];
gH_SQL.Driver.GetIdentifier(sDriver, 8);
@ -325,7 +334,6 @@ public void OnMapStart()
char[] sQuery = new char[256];
FormatEx(sQuery, 256, "SELECT tier FROM %smaptiers WHERE map = '%s';", gS_MySQLPrefix, gS_Map);
gH_SQL.Query(SQL_GetMapTier_Callback, sQuery, 0, DBPrio_High);
}
}
public void SQL_GetMapTier_Callback(Database db, DBResultSet results, const char[] error, any data)
@ -337,13 +345,25 @@ public void SQL_GetMapTier_Callback(Database db, DBResultSet results, const char
return;
}
#if defined DEBUG
PrintToServer("DEBUG: 2 (SQL_GetMapTier_Callback)");
#endif
if(results.RowCount > 0 && results.FetchRow())
{
gI_Tier = results.FetchInt(0);
#if defined DEBUG
PrintToServer("DEBUG: 3 (tier: %d) (SQL_GetMapTier_Callback)", gI_Tier);
#endif
RecalculateAll(gS_Map, gI_Tier);
UpdateAllPoints();
#if defined DEBUG
PrintToServer("DEBUG: 4 (SQL_GetMapTier_Callback)");
#endif
char[] sQuery = new char[256];
FormatEx(sQuery, 256, "SELECT map, tier FROM %smaptiers;", gS_MySQLPrefix, gS_Map);
gH_SQL.Query(SQL_FillTierCache_Callback, sQuery, 0, DBPrio_High);
@ -552,6 +572,10 @@ public Action Command_RecalcMap(int client, int args)
void RecalculateAll(const char[] map, const int tier)
{
#if defined DEBUG
LogError("DEBUG: 5 (RecalculateAll)");
#endif
for(int i = 0; i < TRACKS_SIZE; i++)
{
for(int j = 0; j < gI_Styles; j++)
@ -660,6 +684,10 @@ public void SQL_UpdatePlayerPoints_Callback(Database db, DBResultSet results, co
// this takes a while, needs to be ran manually or on map start, in a transaction
void UpdateAllPoints()
{
#if defined DEBUG
LogError("DEBUG: 6 (UpdateAllPoints)");
#endif
char[] sQuery = new char[128];
FormatEx(sQuery, 128, "SELECT auth FROM %splayertimes WHERE points > 0.0 GROUP BY auth;", gS_MySQLPrefix);
gH_SQL.Query(SQL_UpdateAllPoints_Callback, sQuery, 0, DBPrio_Low);

View File

@ -98,7 +98,10 @@ public void OnAllPluginsLoaded()
SetFailState("shavit-wr is required for the plugin to work.");
}
if(gH_SQL == null)
{
Shavit_OnDatabaseLoaded();
}
}
public void OnPluginStart()

View File

@ -80,7 +80,10 @@ public void OnAllPluginsLoaded()
SetFailState("shavit-wr is required for the plugin to work.");
}
if(gH_SQL == null)
{
Shavit_OnDatabaseLoaded();
}
}
public void OnPluginStart()

View File

@ -111,7 +111,10 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max
public void OnAllPluginsLoaded()
{
if(gH_SQL == null)
{
Shavit_OnDatabaseLoaded();
}
}
public void OnPluginStart()

View File

@ -172,7 +172,10 @@ public void OnAllPluginsLoaded()
OnAdminMenuReady(null);
}
if(gH_SQL == null)
{
Shavit_OnDatabaseLoaded();
}
}
public void OnPluginStart()