add Shavit_DeleteWR. refactor run deletion & wipeplayer

This commit is contained in:
rtldg 2021-03-04 05:42:01 +00:00
parent 45dd960d3e
commit ee11fa10d4
4 changed files with 250 additions and 232 deletions

View File

@ -643,7 +643,7 @@ forward void Shavit_OnWorldRecord(int client, int style, float time, int jumps,
* @param id Record ID. -1 if mass deletion. * @param id Record ID. -1 if mass deletion.
* @param track Timer track. * @param track Timer track.
* @param accountid The account ID of the wr holder * @param accountid The account ID of the wr holder
* @param mapname Hey KidFearless please do me a favor * @param mapname The map name.
* @noreturn * @noreturn
*/ */
forward void Shavit_OnWRDeleted(int style, int id, int track, int accountid, const char[] mapname); forward void Shavit_OnWRDeleted(int style, int id, int track, int accountid, const char[] mapname);
@ -2152,6 +2152,20 @@ native void Shavit_SetPlayerTimerFrame(int client, int TimerPreFrame);
*/ */
native void Shavit_GetPlainChatrank(int client, char[] buf, int buflen, bool includename=false); native void Shavit_GetPlainChatrank(int client, char[] buf, int buflen, bool includename=false);
/*
* Used to delete a WR. Used to ensure Shavit_OnWRDeleted is ran.
*
* @param style Record style.
* @param track Record track.
* @param map Record map.
* @param accountid -1 if recordid is -1. Otherwise you need the WR holder's Steam account ID. ([U:1:x])
* @param recordid -1 to pull ID & accountid from the database.
* @param delete_sql If this function should delete the record from the database. False might be useful if you're deleting things in bulk like sm_wipeplayer does.
* @param update_cache If this function should update the WR cache & record info. False might be useful if you're deleting things in bulk like sm_wipeplayer does.
* @noreturn
*/
native void Shavit_DeleteWR(int style, int track, const char[] map, int accountid, int recordid, bool delete_sql, bool update_cache);
// same as Shavit_PrintToChat() but loops through the whole server // same as Shavit_PrintToChat() but loops through the whole server
// code stolen from the base halflife.inc file // code stolen from the base halflife.inc file
stock void Shavit_PrintToChatAll(const char[] format, any ...) stock void Shavit_PrintToChatAll(const char[] format, any ...)
@ -2187,11 +2201,13 @@ public void __pl_shavit_SetNTVOptional()
MarkNativeAsOptional("Shavit_CanPause"); MarkNativeAsOptional("Shavit_CanPause");
MarkNativeAsOptional("Shavit_ChangeClientStyle"); MarkNativeAsOptional("Shavit_ChangeClientStyle");
MarkNativeAsOptional("Shavit_DeleteReplay"); MarkNativeAsOptional("Shavit_DeleteReplay");
MarkNativeAsOptional("Shavit_DeleteWR");
MarkNativeAsOptional("Shavit_FinishMap"); MarkNativeAsOptional("Shavit_FinishMap");
MarkNativeAsOptional("Shavit_ForceHUDUpdate"); MarkNativeAsOptional("Shavit_ForceHUDUpdate");
MarkNativeAsOptional("Shavit_FormatChat"); MarkNativeAsOptional("Shavit_FormatChat");
MarkNativeAsOptional("Shavit_GetBhopStyle"); MarkNativeAsOptional("Shavit_GetBhopStyle");
MarkNativeAsOptional("Shavit_GetChatStrings"); MarkNativeAsOptional("Shavit_GetChatStrings");
MarkNativeAsOptional("Shavit_GetClientCompletions");
MarkNativeAsOptional("Shavit_GetClientJumps"); MarkNativeAsOptional("Shavit_GetClientJumps");
MarkNativeAsOptional("Shavit_GetClientPB"); MarkNativeAsOptional("Shavit_GetClientPB");
MarkNativeAsOptional("Shavit_GetClientTime"); MarkNativeAsOptional("Shavit_GetClientTime");
@ -2267,6 +2283,7 @@ public void __pl_shavit_SetNTVOptional()
MarkNativeAsOptional("Shavit_RestartTimer"); MarkNativeAsOptional("Shavit_RestartTimer");
MarkNativeAsOptional("Shavit_ResumeTimer"); MarkNativeAsOptional("Shavit_ResumeTimer");
MarkNativeAsOptional("Shavit_SaveSnapshot"); MarkNativeAsOptional("Shavit_SaveSnapshot");
MarkNativeAsOptional("Shavit_SetClientPB");
MarkNativeAsOptional("Shavit_SetPracticeMode"); MarkNativeAsOptional("Shavit_SetPracticeMode");
MarkNativeAsOptional("Shavit_SetReplayData"); MarkNativeAsOptional("Shavit_SetReplayData");
MarkNativeAsOptional("Shavit_StartReplay"); MarkNativeAsOptional("Shavit_StartReplay");

View File

@ -920,180 +920,103 @@ public Action Command_WipePlayer(int client, int args)
return Plugin_Handled; return Plugin_Handled;
} }
void DeleteUserData(int client, const int iSteamID) public void Trans_DeleteRestOfUserSuccess(Database db, DataPack hPack, int numQueries, DBResultSet[] results, any[] queryData)
{ {
if(gB_Replay)
{
char sQueryGetWorldRecords[256];
FormatEx(sQueryGetWorldRecords, 256,
"SELECT map, id, style, track FROM %splayertimes WHERE auth = %d;",
gS_MySQLPrefix, iSteamID);
DataPack hPack = new DataPack();
hPack.WriteCell(client);
hPack.WriteCell(iSteamID);
gH_SQL.Query(SQL_DeleteUserData_GetRecords_Callback, sQueryGetWorldRecords, hPack, DBPrio_High);
}
else
{
char sQueryDeleteUserTimes[256];
FormatEx(sQueryDeleteUserTimes, 256,
"DELETE FROM %splayertimes WHERE auth = %d;",
gS_MySQLPrefix, iSteamID);
DataPack hSteamPack = new DataPack();
hSteamPack.WriteCell(iSteamID);
hSteamPack.WriteCell(client);
gH_SQL.Query(SQL_DeleteUserTimes_Callback, sQueryDeleteUserTimes, hSteamPack, DBPrio_High);
}
}
public void SQL_DeleteUserData_GetRecords_Callback(Database db, DBResultSet results, const char[] error, any data)
{
DataPack hPack = view_as<DataPack>(data);
hPack.Reset(); hPack.Reset();
int client = hPack.ReadCell(); int client = hPack.ReadCell();
int iSteamID = hPack.ReadCell(); int iSteamID = hPack.ReadCell();
delete hPack; delete hPack;
if(gB_WR)
{
Shavit_ReloadLeaderboards();
}
Shavit_LogMessage("%L - wiped user data for [U:1:%d].", client, iSteamID);
Shavit_PrintToChat(client, "Finished wiping timer data for user %s[U:1:%d]%s.", gS_ChatStrings.sVariable, iSteamID, gS_ChatStrings.sText);
}
public void Trans_DeleteRestOfUserFailed(Database db, DataPack hPack, int numQueries, const char[] error, int failIndex, any[] queryData)
{
hPack.Reset();
hPack.ReadCell();
int iSteamID = hPack.ReadCell();
delete hPack;
LogError("Timer error! Failed to wipe user data (wipe | delete user data/times, id [U:1:%d]). Reason: %s", iSteamID, error);
}
void DeleteRestOfUser(int iSteamID, DataPack hPack)
{
Transaction hTransaction = new Transaction();
char sQuery[256];
FormatEx(sQuery, 256, "DELETE FROM %splayertimes WHERE auth = %d;", gS_MySQLPrefix, iSteamID);
hTransaction.AddQuery(sQuery);
FormatEx(sQuery, 256, "DELETE FROM %susers WHERE auth = %d;", gS_MySQLPrefix, iSteamID);
hTransaction.AddQuery(sQuery);
gH_SQL.Execute(hTransaction, Trans_DeleteRestOfUserSuccess, Trans_DeleteRestOfUserFailed, hPack);
}
void DeleteUserData(int client, const int iSteamID)
{
DataPack hPack = new DataPack();
hPack.WriteCell(client);
hPack.WriteCell(iSteamID);
char sQuery[512];
if(gB_WR)
{
if(gB_MySQL)
{
FormatEx(sQuery, 512,
"SELECT p1.id, p1.style, p1.track, p1.map FROM %splayertimes p1 " ...
"JOIN (SELECT map, style, track, MIN(time) time FROM %splayertimes GROUP BY map, style, track) p2 " ...
"ON p1.style = p2.style AND p1.track = p2.track AND p1.time = p2.time " ...
"WHERE p1.auth = %d;",
gS_MySQLPrefix, gS_MySQLPrefix, iSteamID);
}
else
{
FormatEx(sQuery, 512,
"SELECT p.id, p.style, p.track, p.map FROM %splayertimes p JOIN(SELECT style, MIN(time) time, map, track FROM %splayertimes GROUP BY map, style, track) s ON p.style = s.style AND p.time = s.time AND p.map = s.map AND s.track = p.track GROUP BY p.map, p.style, p.track WHERE p.auth = %d;",
gS_MySQLPrefix, gS_MySQLPrefix, iSteamID);
}
gH_SQL.Query(SQL_DeleteUserData_GetRecords_Callback, sQuery, hPack, DBPrio_High);
}
else
{
DeleteRestOfUser(iSteamID, hPack);
}
}
public void SQL_DeleteUserData_GetRecords_Callback(Database db, DBResultSet results, const char[] error, DataPack hPack)
{
hPack.Reset();
hPack.ReadCell(); /*int client = */
int iSteamID = hPack.ReadCell();
if(results == null) if(results == null)
{ {
LogError("Timer error! Failed to wipe user data (wipe | get player records). Reason: %s", error); LogError("Timer error! Failed to wipe user data (wipe | get player records). Reason: %s", error);
delete hPack;
return; return;
} }
Transaction hTransaction = new Transaction(); char map[PLATFORM_MAX_PATH];
while(results.FetchRow()) while(results.FetchRow())
{ {
char map[160]; int id = results.FetchInt(0);
results.FetchString(0, map, 160); int style = results.FetchInt(1);
int track = results.FetchInt(2);
results.FetchString(3, map, sizeof(map));
int id = results.FetchInt(1); Shavit_DeleteWR(style, track, map, iSteamID, id, false, false);
int style = results.FetchInt(2);
int track = results.FetchInt(3);
char sQueryGetWorldRecordID[256];
FormatEx(sQueryGetWorldRecordID, 256,
"SELECT id FROM %splayertimes WHERE map = '%s' AND style = %d AND track = %d ORDER BY time LIMIT 1;",
gS_MySQLPrefix, map, style, track);
DataPack hTransPack = new DataPack();
hTransPack.WriteString(map);
hTransPack.WriteCell(id);
hTransPack.WriteCell(style);
hTransPack.WriteCell(track);
hTransaction.AddQuery(sQueryGetWorldRecordID, hTransPack);
} }
DataPack hSteamPack = new DataPack(); DeleteRestOfUser(iSteamID, hPack);
hSteamPack.WriteCell(iSteamID);
hSteamPack.WriteCell(client);
gH_SQL.Execute(hTransaction, Trans_OnRecordCompare, INVALID_FUNCTION, hSteamPack, DBPrio_High);
}
public void Trans_OnRecordCompare(Database db, any data, int numQueries, DBResultSet[] results, any[] queryData)
{
DataPack hPack = view_as<DataPack>(data);
hPack.Reset();
int iSteamID = hPack.ReadCell();
int client = 0;
// Check if the target is in game
for(int index = 1; index <= MaxClients; index++)
{
if(IsValidClient(index) && !IsFakeClient(index))
{
if(iSteamID == GetSteamAccountID(index))
{
client = index;
break;
}
}
}
for(int i = 0; i < numQueries; i++)
{
DataPack hQueryPack = view_as<DataPack>(queryData[i]);
hQueryPack.Reset();
char sMap[32];
hQueryPack.ReadString(sMap, 32);
int iRecordID = hQueryPack.ReadCell();
int iStyle = hQueryPack.ReadCell();
int iTrack = hQueryPack.ReadCell();
delete hQueryPack;
if(client > 0)
{
Shavit_SetClientPB(client, iStyle, iTrack, 0.0);
}
if(results[i] != null && results[i].FetchRow())
{
int iWR = results[i].FetchInt(0);
if(iWR == iRecordID)
{
Shavit_DeleteReplay(sMap, iStyle, iTrack, iSteamID);
}
}
}
char sQueryDeleteUserTimes[256];
FormatEx(sQueryDeleteUserTimes, 256,
"DELETE FROM %splayertimes WHERE auth = %d;",
gS_MySQLPrefix, iSteamID);
gH_SQL.Query(SQL_DeleteUserTimes_Callback, sQueryDeleteUserTimes, hPack, DBPrio_High);
}
public void SQL_DeleteUserTimes_Callback(Database db, DBResultSet results, const char[] error, any data)
{
DataPack hPack = view_as<DataPack>(data);
hPack.Reset();
int iSteamID = hPack.ReadCell();
if(results == null)
{
LogError("Timer error! Failed to wipe user data (wipe | delete user times). Reason: %s", error);
delete hPack;
return;
}
char sQueryDeleteUsers[256];
FormatEx(sQueryDeleteUsers, 256, "DELETE FROM %susers WHERE auth = %d;",
gS_MySQLPrefix, iSteamID);
gH_SQL.Query(SQL_DeleteUserData_Callback, sQueryDeleteUsers, hPack, DBPrio_High);
}
public void SQL_DeleteUserData_Callback(Database db, DBResultSet results, const char[] error, any data)
{
DataPack hPack = view_as<DataPack>(data);
hPack.Reset();
int iSteamID = hPack.ReadCell();
int client = hPack.ReadCell();
delete hPack;
if(results == null)
{
LogError("Timer error! Failed to wipe user data (wipe | delete user data, id [U:1:%d]). Reason: %s", error, iSteamID);
return;
}
Shavit_LogMessage("%L - wiped user data for [U:1:%d].", client, iSteamID);
Shavit_ReloadLeaderboards();
Shavit_PrintToChat(client, "Finished wiping timer data for user %s[U:1:%d]%s.", gS_ChatStrings.sVariable, iSteamID, gS_ChatStrings.sText);
} }
public Action Command_AutoBhop(int client, int args) public Action Command_AutoBhop(int client, int args)

View File

@ -470,12 +470,7 @@ public int Native_DeleteReplay(Handle handler, int numParams)
int iTrack = GetNativeCell(3); int iTrack = GetNativeCell(3);
int iSteamID = GetNativeCell(4); int iSteamID = GetNativeCell(4);
if(!DeleteReplay(iStyle, iTrack, StrEqual(sMap, gS_Map), iSteamID, sMap)) return DeleteReplay(iStyle, iTrack, iSteamID, sMap);
{
return false;
}
return true;
} }
public int Native_GetReplayBotFirstFrame(Handle handler, int numParams) public int Native_GetReplayBotFirstFrame(Handle handler, int numParams)
@ -1387,7 +1382,7 @@ void SaveReplay(int style, int track, float time, int steamid, char[] name, int
gA_FrameCache[style][track].iPreFrames = timerstartframe - preframes; gA_FrameCache[style][track].iPreFrames = timerstartframe - preframes;
} }
bool DeleteReplay(int style, int track, bool unload_replay = false, int accountid = 0, const char[] mapname = gS_Map) bool DeleteReplay(int style, int track, int accountid = 0, const char[] mapname = gS_Map)
{ {
char sTrack[4]; char sTrack[4];
FormatEx(sTrack, 4, "_%d", track); FormatEx(sTrack, 4, "_%d", track);
@ -1443,7 +1438,7 @@ bool DeleteReplay(int style, int track, bool unload_replay = false, int accounti
} }
} }
if(unload_replay) if(StrEqual(mapname, gS_Map))
{ {
UnloadReplay(style, track); UnloadReplay(style, track);
} }
@ -2371,12 +2366,7 @@ void ClearFrames(int client)
public void Shavit_OnWRDeleted(int style, int id, int track, int accountid, const char[] mapname) public void Shavit_OnWRDeleted(int style, int id, int track, int accountid, const char[] mapname)
{ {
float time = Shavit_GetWorldRecord(style, track); DeleteReplay(style, track, accountid, mapname);
if(gA_FrameCache[style][track].iFrameCount > 0 && GetReplayLength(style, track) - gF_Tickrate <= time) // -0.1 to fix rounding issues
{
DeleteReplay(style, track, StrEqual(gS_Map, mapname), accountid, mapname);
}
} }
public Action Command_DeleteReplay(int client, int args) public Action Command_DeleteReplay(int client, int args)

View File

@ -112,6 +112,7 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max
CreateNative("Shavit_GetWRTime", Native_GetWRTime); CreateNative("Shavit_GetWRTime", Native_GetWRTime);
CreateNative("Shavit_ReloadLeaderboards", Native_ReloadLeaderboards); CreateNative("Shavit_ReloadLeaderboards", Native_ReloadLeaderboards);
CreateNative("Shavit_WR_DeleteMap", Native_WR_DeleteMap); CreateNative("Shavit_WR_DeleteMap", Native_WR_DeleteMap);
CreateNative("Shavit_DeleteWR", Native_DeleteWR);
// registers library, check "bool LibraryExists(const char[] name)" in order to use with other plugins // registers library, check "bool LibraryExists(const char[] name)" in order to use with other plugins
RegPluginLibrary("shavit-wr"); RegPluginLibrary("shavit-wr");
@ -326,6 +327,7 @@ public void OnMapStart()
{ {
Shavit_OnStyleConfigLoaded(-1); Shavit_OnStyleConfigLoaded(-1);
Shavit_OnChatConfigLoaded(); Shavit_OnChatConfigLoaded();
gB_Late = false;
} }
} }
@ -481,8 +483,20 @@ public void SQL_UpdateCache_Callback(Database db, DBResultSet results, const cha
gA_WRCache[client].bLoadedCache = true; gA_WRCache[client].bLoadedCache = true;
} }
void UpdateWRCache() void UpdateWRCache(int client = -1)
{ {
if (client == -1)
{
for (int i = 1; i <= MaxClients; i++)
{
OnClientPutInServer(i);
}
}
else
{
OnClientPutInServer(client);
}
char sQuery[512]; char sQuery[512];
if(gB_MySQL) if(gB_MySQL)
@ -502,7 +516,7 @@ void UpdateWRCache()
gS_MySQLPrefix, gS_MySQLPrefix, gS_Map, gS_MySQLPrefix); gS_MySQLPrefix, gS_MySQLPrefix, gS_Map, gS_MySQLPrefix);
} }
gH_SQL.Query(SQL_UpdateWRCache_Callback, sQuery); gH_SQL.Query(SQL_UpdateWRCache_Callback, sQuery, client);
} }
public void SQL_UpdateWRCache_Callback(Database db, DBResultSet results, const char[] error, any data) public void SQL_UpdateWRCache_Callback(Database db, DBResultSet results, const char[] error, any data)
@ -556,7 +570,7 @@ public int Native_GetWRTime(Handle handler, int numParams)
public int Native_ReloadLeaderboards(Handle handler, int numParams) public int Native_ReloadLeaderboards(Handle handler, int numParams)
{ {
UpdateLeaderboards(); //UpdateLeaderboards(); // Called by UpdateWRCache->SQL_UpdateWRCache_Callback
UpdateWRCache(); UpdateWRCache();
} }
@ -641,6 +655,115 @@ public int Native_WR_DeleteMap(Handle handler, int numParams)
gH_SQL.Query(SQL_DeleteMap_Callback, sQuery, StrEqual(gS_Map, sMap, false), DBPrio_High); gH_SQL.Query(SQL_DeleteMap_Callback, sQuery, StrEqual(gS_Map, sMap, false), DBPrio_High);
} }
void DeleteWRFinal(int style, int track, const char[] map, int steamid, int recordid, bool update_cache)
{
Call_StartForward(gH_OnWRDeleted);
Call_PushCell(style);
Call_PushCell(recordid);
Call_PushCell(track);
Call_PushCell(steamid);
Call_PushString(map);
Call_Finish();
if (update_cache)
{
UpdateWRCache();
}
}
public void DeleteWR_Callback(Database db, DBResultSet results, const char[] error, DataPack hPack)
{
hPack.Reset();
int style = hPack.ReadCell();
int track = hPack.ReadCell();
char map[PLATFORM_MAX_PATH];
hPack.ReadString(map, sizeof(map));
int steamid = hPack.ReadCell();
int recordid = hPack.ReadCell();
bool update_cache = view_as<bool>(hPack.ReadCell());
delete hPack;
if(results == null)
{
LogError("Timer (WR DeleteWR) SQL query failed. Reason: %s", error);
return;
}
if (recordid == -1)
{
results.FetchRow();
if (results.IsFieldNull(0) || results.IsFieldNull(1))
{
LogError("Timer (WR DeleteWR) SQL query failed. Reason: @deletewrid or @deletewrauth is NULL");
return;
}
recordid = results.FetchInt(0);
steamid = results.FetchInt(1);
}
DeleteWRFinal(style, track, map, steamid, recordid, update_cache);
}
void DeleteWR(int style, int track, const char[] map, int steamid, int recordid, bool delete_sql, bool update_cache)
{
if (delete_sql)
{
DataPack hPack = new DataPack();
hPack.WriteCell(style);
hPack.WriteCell(track);
hPack.WriteString(map);
hPack.WriteCell(steamid);
hPack.WriteCell(recordid);
hPack.WriteCell(update_cache);
char sQuery[512];
if (recordid == -1) // missing WR recordid thing...
{
// TODO: probably doesn't work well with sqlite...
FormatEx(sQuery, sizeof(sQuery),
"SELECT p1.id, p1.auth INTO @deletewrid, @deletewrauth FROM %splayertimes p1 " ...
"JOIN (SELECT style, track, MIN(time) time FROM %splayertimes WHERE " ...
"map = '%s' AND style = %d AND track = %d) p2 " ...
"ON p1.style = p2.style AND p1.track = p2.track AND p1.time = p2.time; " ...
"DELETE FROM %splayertimes WHERE id = @deletewrid; " ...
"SELECT @deletewrid, @deletewrauth;",
gS_MySQLPrefix, gS_MySQLPrefix, map, style, track, gS_MySQLPrefix);
}
else
{
FormatEx(sQuery, sizeof(sQuery),
"DELETE FROM %splayertimes WHERE id = %d;",
gS_MySQLPrefix, recordid);
}
gH_SQL.Query(DeleteWR_Callback, sQuery, hPack, DBPrio_High);
}
else
{
DeleteWRFinal(style, track, map, steamid, recordid, update_cache);
}
}
public int Native_DeleteWR(Handle handle, int numParams)
{
int style = GetNativeCell(1);
int track = GetNativeCell(2);
char map[PLATFORM_MAX_PATH];
GetNativeString(3, map, sizeof(map));
int steamid = GetNativeCell(4);
int recordid = GetNativeCell(5);
bool delete_sql = view_as<bool>(GetNativeCell(6));
bool update_cache = view_as<bool>(GetNativeCell(7));
DeleteWR(style, track, map, steamid, recordid, delete_sql, update_cache);
}
public void SQL_DeleteMap_Callback(Database db, DBResultSet results, const char[] error, any data) public void SQL_DeleteMap_Callback(Database db, DBResultSet results, const char[] error, any data)
{ {
if(results == null) if(results == null)
@ -653,11 +776,6 @@ public void SQL_DeleteMap_Callback(Database db, DBResultSet results, const char[
if(view_as<bool>(data)) if(view_as<bool>(data))
{ {
OnMapStart(); OnMapStart();
for(int i = 1; i <= MaxClients; i++)
{
OnClientPutInServer(i);
}
} }
} }
@ -953,7 +1071,12 @@ public int MenuHandler_DeleteAll(Menu menu, MenuAction action, int param1, int p
FormatEx(sQuery, 256, "DELETE FROM %splayertimes WHERE map = '%s' AND style = %d AND track = %d;", FormatEx(sQuery, 256, "DELETE FROM %splayertimes WHERE map = '%s' AND style = %d AND track = %d;",
gS_MySQLPrefix, gS_Map, gA_WRCache[param1].iLastStyle, gA_WRCache[param1].iLastTrack); gS_MySQLPrefix, gS_Map, gA_WRCache[param1].iLastStyle, gA_WRCache[param1].iLastTrack);
gH_SQL.Query(DeleteAll_Callback, sQuery, GetClientSerial(param1), DBPrio_High); DataPack hPack = new DataPack();
hPack.WriteCell(GetClientSerial(param1));
hPack.WriteCell(gA_WRCache[param1].iLastStyle);
hPack.WriteCell(gA_WRCache[param1].iLastTrack);
gH_SQL.Query(DeleteAll_Callback, sQuery, hPack, DBPrio_High);
} }
else if(action == MenuAction_End) else if(action == MenuAction_End)
@ -1123,9 +1246,10 @@ public int DeleteConfirm_Handler(Menu menu, MenuAction action, int param1, int p
return 0; return 0;
} }
char sQuery[256]; char sQuery[512];
FormatEx(sQuery, 256, "SELECT u.auth, u.name, p.map, p.time, p.sync, p.perfs, p.jumps, p.strafes, p.id, p.date, "... FormatEx(sQuery, sizeof(sQuery),
"(SELECT id from %splayertimes where style = %d AND track = %d AND map = p.map) "... "SELECT u.auth, u.name, p.map, p.time, p.sync, p.perfs, p.jumps, p.strafes, p.id, p.date, "...
"(SELECT id FROM %splayertimes WHERE style = %d AND track = %d AND map = p.map ORDER BY time, date ASC LIMIT 1) "...
"FROM %susers u LEFT JOIN %splayertimes p ON u.auth = p.auth WHERE p.id = %d;", "FROM %susers u LEFT JOIN %splayertimes p ON u.auth = p.auth WHERE p.id = %d;",
gS_MySQLPrefix, gA_WRCache[param1].iLastStyle, gA_WRCache[param1].iLastTrack, gS_MySQLPrefix, gS_MySQLPrefix, iRecordID); gS_MySQLPrefix, gA_WRCache[param1].iLastStyle, gA_WRCache[param1].iLastTrack, gS_MySQLPrefix, gS_MySQLPrefix, iRecordID);
@ -1156,6 +1280,7 @@ public void GetRecordDetails_Callback(Database db, DBResultSet results, const ch
return; return;
} }
// TODO: work DeleteWR() into here...
if(results.FetchRow()) if(results.FetchRow())
{ {
int iSteamID = results.FetchInt(0); int iSteamID = results.FetchInt(0);
@ -1206,9 +1331,8 @@ public void GetRecordDetails_Callback(Database db, DBResultSet results, const ch
} }
} }
public void DeleteConfirm_Callback(Database db, DBResultSet results, const char[] error, any data) public void DeleteConfirm_Callback(Database db, DBResultSet results, const char[] error, DataPack hPack)
{ {
DataPack hPack = view_as<DataPack>(data);
hPack.Reset(); hPack.Reset();
int iSerial = hPack.ReadCell(); int iSerial = hPack.ReadCell();
@ -1243,20 +1367,7 @@ public void DeleteConfirm_Callback(Database db, DBResultSet results, const char[
if(bWRDeleted) if(bWRDeleted)
{ {
Call_StartForward(gH_OnWRDeleted); DeleteWR(iStyle, iTrack, sMap, iSteamID, iRecordID, false, true);
Call_PushCell(iStyle);
Call_PushCell(iRecordID);
Call_PushCell(iTrack);
Call_PushCell(iSteamID);
Call_PushString(sMap);
Call_Finish();
}
UpdateWRCache();
for(int i = 1; i <= MaxClients; i++)
{
OnClientPutInServer(i);
} }
int client = GetClientFromSerial(iSerial); int client = GetClientFromSerial(iSerial);
@ -1279,8 +1390,14 @@ public void DeleteConfirm_Callback(Database db, DBResultSet results, const char[
Shavit_PrintToChat(client, "%T", "DeletedRecord", client); Shavit_PrintToChat(client, "%T", "DeletedRecord", client);
} }
public void DeleteAll_Callback(Database db, DBResultSet results, const char[] error, any data) public void DeleteAll_Callback(Database db, DBResultSet results, const char[] error, DataPack hPack)
{ {
hPack.Reset();
int client = GetClientFromSerial(hPack.ReadCell());
int style = hPack.ReadCell();
int track = hPack.ReadCell();
delete hPack;
if(results == null) if(results == null)
{ {
LogError("Timer (WR DeleteAll) SQL query failed. Reason: %s", error); LogError("Timer (WR DeleteAll) SQL query failed. Reason: %s", error);
@ -1288,25 +1405,7 @@ public void DeleteAll_Callback(Database db, DBResultSet results, const char[] er
return; return;
} }
UpdateWRCache(); DeleteWR(style, track, gS_Map, 0, -1, false, true);
for(int i = 1; i <= MaxClients; i++)
{
OnClientPutInServer(i);
}
int client = GetClientFromSerial(data);
if(client == 0)
{
return;
}
Call_StartForward(gH_OnWRDeleted);
Call_PushCell(gA_WRCache[client].iLastStyle);
Call_PushCell(-1);
Call_PushCell(gA_WRCache[client].iLastTrack);
Call_Finish();
Shavit_PrintToChat(client, "%T", "DeletedRecordsMap", client, gS_ChatStrings.sVariable, gS_Map, gS_ChatStrings.sText); Shavit_PrintToChat(client, "%T", "DeletedRecordsMap", client, gS_ChatStrings.sVariable, gS_Map, gS_ChatStrings.sText);
} }
@ -1968,18 +2067,8 @@ public void SQL_CreateTable_Callback(Database db, DBResultSet results, const cha
return; return;
} }
if(gB_Late)
{
for(int i = 1; i <= MaxClients; i++)
{
OnClientPutInServer(i);
}
gB_Late = false;
}
gB_Connected = true; gB_Connected = true;
OnMapStart(); OnMapStart();
} }
@ -2211,8 +2300,7 @@ public void SQL_OnFinish_Callback(Database db, DBResultSet results, const char[]
return; return;
} }
UpdateWRCache(); UpdateWRCache(client);
UpdateClientCache(client);
} }
void UpdateLeaderboards() void UpdateLeaderboards()