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."); SetFailState("shavit-wr is required for the plugin to work.");
} }
Shavit_OnDatabaseLoaded(); if(gH_SQL == null)
{
Shavit_OnDatabaseLoaded();
}
} }
public void OnPluginStart() public void OnPluginStart()
@ -248,7 +251,7 @@ void SQL_DBConnect()
char[] sQuery = new char[256]; 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); 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; return;
} }
#if defined DEBUG
PrintToServer("DEBUG: 0 (SQL_CreateTable_Callback)");
#endif
if(gI_Styles == 0)
{
Shavit_OnStyleConfigLoaded(-1);
}
OnMapStart(); OnMapStart();
if(gB_Late) if(gB_Late)
@ -298,12 +310,11 @@ public void OnMapStart()
return; return;
} }
UpdateRankedPlayers(); #if defined DEBUG
PrintToServer("DEBUG: 1 (OnMapStart)");
#endif
if(gB_Late) UpdateRankedPlayers();
{
Shavit_OnStyleConfigLoaded(-1);
}
GetCurrentMap(gS_Map, 160); GetCurrentMap(gS_Map, 160);
GetMapDisplayName(gS_Map, gS_Map, 160); GetMapDisplayName(gS_Map, gS_Map, 160);
@ -312,20 +323,17 @@ public void OnMapStart()
// I won't repeat the same mistake blacky has done with tier 3 being default.. // I won't repeat the same mistake blacky has done with tier 3 being default..
gI_Tier = 1; gI_Tier = 1;
if(gH_SQL != null) char[] sDriver = new char[8];
gH_SQL.Driver.GetIdentifier(sDriver, 8);
if(!StrEqual(sDriver, "mysql", false))
{ {
char[] sDriver = new char[8]; SetFailState("Rankings will only support MySQL for the moment. Sorry.");
gH_SQL.Driver.GetIdentifier(sDriver, 8);
if(!StrEqual(sDriver, "mysql", false))
{
SetFailState("Rankings will only support MySQL for the moment. Sorry.");
}
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);
} }
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) 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; return;
} }
#if defined DEBUG
PrintToServer("DEBUG: 2 (SQL_GetMapTier_Callback)");
#endif
if(results.RowCount > 0 && results.FetchRow()) if(results.RowCount > 0 && results.FetchRow())
{ {
gI_Tier = results.FetchInt(0); gI_Tier = results.FetchInt(0);
#if defined DEBUG
PrintToServer("DEBUG: 3 (tier: %d) (SQL_GetMapTier_Callback)", gI_Tier);
#endif
RecalculateAll(gS_Map, gI_Tier); RecalculateAll(gS_Map, gI_Tier);
UpdateAllPoints(); UpdateAllPoints();
#if defined DEBUG
PrintToServer("DEBUG: 4 (SQL_GetMapTier_Callback)");
#endif
char[] sQuery = new char[256]; char[] sQuery = new char[256];
FormatEx(sQuery, 256, "SELECT map, tier FROM %smaptiers;", gS_MySQLPrefix, gS_Map); FormatEx(sQuery, 256, "SELECT map, tier FROM %smaptiers;", gS_MySQLPrefix, gS_Map);
gH_SQL.Query(SQL_FillTierCache_Callback, sQuery, 0, DBPrio_High); 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) 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 i = 0; i < TRACKS_SIZE; i++)
{ {
for(int j = 0; j < gI_Styles; j++) 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 // this takes a while, needs to be ran manually or on map start, in a transaction
void UpdateAllPoints() void UpdateAllPoints()
{ {
#if defined DEBUG
LogError("DEBUG: 6 (UpdateAllPoints)");
#endif
char[] sQuery = new char[128]; char[] sQuery = new char[128];
FormatEx(sQuery, 128, "SELECT auth FROM %splayertimes WHERE points > 0.0 GROUP BY auth;", gS_MySQLPrefix); 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); 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."); SetFailState("shavit-wr is required for the plugin to work.");
} }
Shavit_OnDatabaseLoaded(); if(gH_SQL == null)
{
Shavit_OnDatabaseLoaded();
}
} }
public void OnPluginStart() public void OnPluginStart()

View File

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

View File

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

View File

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