mirror of
https://github.com/shavitush/bhoptimer.git
synced 2025-12-07 18:38:26 +00:00
Add account id validation when deleting replays
* Fixed bugs * Make it optional * no empty line * Update shavit-core.sp * How can I didn't notice this before
This commit is contained in:
commit
c52c3c3e79
@ -611,9 +611,10 @@ forward void Shavit_OnWorldRecord(int client, int style, float time, int jumps,
|
||||
* @param style Style the record was done on.
|
||||
* @param id Record ID. -1 if mass deletion.
|
||||
* @param track Timer track.
|
||||
* @param accountid The account ID of the wr holder
|
||||
* @noreturn
|
||||
*/
|
||||
forward void Shavit_OnWRDeleted(int style, int id, int track);
|
||||
forward void Shavit_OnWRDeleted(int style, int id, int track, int accountid);
|
||||
|
||||
/**
|
||||
* Called when a player's timer paused.
|
||||
@ -1167,6 +1168,17 @@ native void Shavit_GetPlayerPB(int client, int style, float &time, int track);
|
||||
*/
|
||||
native float Shavit_GetClientPB(int client, int style, int track);
|
||||
|
||||
/**
|
||||
* Sets the cached pb directly for the given client, style and track.
|
||||
*
|
||||
* @param client Client index.
|
||||
* @param style Style to get the PB for.
|
||||
* @param track Timer track.
|
||||
* @param time Time to set
|
||||
* @noreturn
|
||||
*/
|
||||
native void Shavit_SetClientPB(int client, int style, int track, float time);
|
||||
|
||||
/**
|
||||
* Retrieves the completions of a player.
|
||||
*
|
||||
@ -1302,9 +1314,10 @@ native float Shavit_GetDistanceOffset(int client, int zonetype);
|
||||
* @param map Map display name.
|
||||
* @param style Bhop style.
|
||||
* @param track Timer track.
|
||||
* @return true if replay existed, false otherwise.
|
||||
* @param accountid Account ID to validate against, 0 to skip validation.
|
||||
* @return true if replay existed, false if the steam id didn't match or the file didn't exist.
|
||||
*/
|
||||
native bool Shavit_DeleteReplay(const char[] map, int style, int track);
|
||||
native bool Shavit_DeleteReplay(const char[] map, int style, int track, int accountid = 0);
|
||||
|
||||
/**
|
||||
* Retrieves the engine time of the replay bot's first frame.
|
||||
|
||||
@ -943,6 +943,21 @@ public void Trans_OnRecordCompare(Database db, any data, int numQueries, DBResul
|
||||
hPack.Reset();
|
||||
int iSteamID = hPack.ReadCell();
|
||||
|
||||
int client = 0;
|
||||
char szSteamid[32];
|
||||
// Just use the client index in the pack?
|
||||
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]);
|
||||
@ -955,13 +970,18 @@ public void Trans_OnRecordCompare(Database db, any data, int numQueries, DBResul
|
||||
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);
|
||||
Shavit_DeleteReplay(sMap, iStyle, iTrack, iSteamID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -44,6 +44,7 @@
|
||||
#define HUD2_MAPTIER (1 << 9)
|
||||
#define HUD2_TIMEDIFFERENCE (1 << 10)
|
||||
#define HUD2_PERFS (1 << 11)
|
||||
#define HUD2_TOPLEFT_RANK (1 << 12)
|
||||
|
||||
#define HUD_DEFAULT (HUD_MASTER|HUD_CENTER|HUD_ZONEHUD|HUD_OBSERVE|HUD_TOPLEFT|HUD_SYNC|HUD_TIMELEFT|HUD_2DVEL|HUD_SPECTATORS)
|
||||
#define HUD_DEFAULT2 (HUD2_PERFS)
|
||||
@ -234,7 +235,8 @@ public void OnPluginStart()
|
||||
..."HUD2_SPLITPB 256\n"
|
||||
..."HUD2_MAPTIER 512\n"
|
||||
..."HUD2_TIMEDIFFERENCE 1024\n"
|
||||
..."HUD2_PERFS 2048");
|
||||
..."HUD2_PERFS 2048\n"
|
||||
..."HUD2_TOPLEFT_RANK 4096");
|
||||
|
||||
Convar.AutoExecConfig();
|
||||
|
||||
@ -727,6 +729,10 @@ Action ShowHUDMenu(int client, int item)
|
||||
FormatEx(sHudItem, 64, "%T", "HudSplitPbText", client);
|
||||
menu.AddItem(sInfo, sHudItem);
|
||||
|
||||
FormatEx(sInfo, 16, "@%d", HUD2_TOPLEFT_RANK);
|
||||
FormatEx(sHudItem, 64, "%T", "HudTopLeftRankText", client);
|
||||
menu.AddItem(sInfo, sHudItem);
|
||||
|
||||
if(gB_Rankings)
|
||||
{
|
||||
FormatEx(sInfo, 16, "@%d", HUD2_MAPTIER);
|
||||
@ -1709,12 +1715,26 @@ void UpdateTopLeftHUD(int client, bool wait)
|
||||
{
|
||||
if(fTargetPB != 0.0)
|
||||
{
|
||||
Format(sTopLeft, 128, "%s\n%s (%N)", sTopLeft, sTargetPB, target);
|
||||
if((gI_HUD2Settings[client]& HUD2_TOPLEFT_RANK) == 0)
|
||||
{
|
||||
Format(sTopLeft, 128, "%s\n%s (#%d) (%N)", sTopLeft, sTargetPB, Shavit_GetRankForTime(style, fTargetPB, track), target);
|
||||
}
|
||||
else
|
||||
{
|
||||
Format(sTopLeft, 128, "%s\n%s (%N)", sTopLeft, sTargetPB, target);
|
||||
}
|
||||
}
|
||||
|
||||
if(fSelfPB != 0.0)
|
||||
{
|
||||
Format(sTopLeft, 128, "%s\n%s (%N)", sTopLeft, sSelfPB, client);
|
||||
if((gI_HUD2Settings[client]& HUD2_TOPLEFT_RANK) == 0)
|
||||
{
|
||||
Format(sTopLeft, 128, "%s\n%s (#%d) (%N)", sTopLeft, sSelfPB, Shavit_GetRankForTime(style, fSelfPB, track), client);
|
||||
}
|
||||
else
|
||||
{
|
||||
Format(sTopLeft, 128, "%s\n%s (%N)", sTopLeft, sSelfPB, client);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -465,6 +465,7 @@ public int Native_DeleteReplay(Handle handler, int numParams)
|
||||
|
||||
int iStyle = GetNativeCell(2);
|
||||
int iTrack = GetNativeCell(3);
|
||||
int iSteamID = GetNativeCell(4);
|
||||
|
||||
char sTrack[4];
|
||||
FormatEx(sTrack, 4, "_%d", iTrack);
|
||||
@ -472,16 +473,11 @@ public int Native_DeleteReplay(Handle handler, int numParams)
|
||||
char sPath[PLATFORM_MAX_PATH];
|
||||
FormatEx(sPath, PLATFORM_MAX_PATH, "%s/%d/%s%s.replay", gS_ReplayFolder, iStyle, gS_Map, (iTrack > 0)? sTrack:"");
|
||||
|
||||
if(!FileExists(sPath) || !DeleteFile(sPath))
|
||||
if(!DeleteReplay(iStyle, iTrack, StrEqual(sMap, gS_Map), iSteamID))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(StrEqual(sMap, gS_Map))
|
||||
{
|
||||
UnloadReplay(iStyle, iTrack);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1348,7 +1344,7 @@ bool SaveReplay(int style, int track, float time, int steamid, char[] name, int
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DeleteReplay(int style, int track)
|
||||
bool DeleteReplay(int style, int track, bool unload_replay = false, int accountid = 0)
|
||||
{
|
||||
char sTrack[4];
|
||||
FormatEx(sTrack, 4, "_%d", track);
|
||||
@ -1356,12 +1352,58 @@ bool DeleteReplay(int style, int track)
|
||||
char sPath[PLATFORM_MAX_PATH];
|
||||
FormatEx(sPath, PLATFORM_MAX_PATH, "%s/%d/%s%s.replay", gS_ReplayFolder, style, gS_Map, (track > 0)? sTrack:"");
|
||||
|
||||
if(!FileExists(sPath) || !DeleteFile(sPath))
|
||||
if(!FileExists(sPath))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
UnloadReplay(style, track);
|
||||
if(accountid != 0)
|
||||
{
|
||||
File file = OpenFile(sPath, "wb");
|
||||
|
||||
char szTemp[160];
|
||||
file.ReadString(szTemp, 160);
|
||||
|
||||
int iTemp = 0;
|
||||
file.ReadUint8(iTemp);
|
||||
file.ReadUint8(iTemp);
|
||||
file.ReadInt32(iTemp);
|
||||
file.ReadInt32(iTemp);
|
||||
int iSteamID = 0;
|
||||
|
||||
if(gA_FrameCache[style][track].iReplayVersion >= 0x04)
|
||||
{
|
||||
file.ReadInt32(iSteamID);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
char sAuthID[32];
|
||||
file.ReadString(sAuthID, 32);
|
||||
ReplaceString(sAuthID, 32, "[U:1:", "");
|
||||
ReplaceString(sAuthID, 32, "]", "");
|
||||
iSteamID = StringToInt(sAuthID);
|
||||
}
|
||||
|
||||
delete file;
|
||||
|
||||
if(accountid == iSteamID && !DeleteFile(sPath))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!DeleteFile(sPath))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if(unload_replay)
|
||||
{
|
||||
UnloadReplay(style, track);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -2242,13 +2284,13 @@ void ClearFrames(int client)
|
||||
gI_PlayerTimerStartFrames[client] = 0;
|
||||
}
|
||||
|
||||
public void Shavit_OnWRDeleted(int style, int id, int track)
|
||||
public void Shavit_OnWRDeleted(int style, int id, int track, int accountid)
|
||||
{
|
||||
float time = Shavit_GetWorldRecord(style, track);
|
||||
|
||||
if(gA_FrameCache[style][track].iFrameCount > 0 && GetReplayLength(style, track) - gF_Tickrate <= time) // -0.1 to fix rounding issues
|
||||
{
|
||||
DeleteReplay(style, track);
|
||||
DeleteReplay(style, track, true, accountid);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2877,4 +2919,4 @@ bool File_Copy(const char[] source, const char[] destination)
|
||||
delete file_destination;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -101,6 +101,7 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max
|
||||
{
|
||||
// natives
|
||||
CreateNative("Shavit_GetClientPB", Native_GetClientPB);
|
||||
CreateNative("Shavit_SetClientPB", Native_SetClientPB);
|
||||
CreateNative("Shavit_GetPlayerPB", Native_GetPlayerPB);
|
||||
CreateNative("Shavit_GetClientCompletions", Native_GetClientCompletions);
|
||||
CreateNative("Shavit_GetRankForTime", Native_GetRankForTime);
|
||||
@ -135,7 +136,7 @@ public void OnPluginStart()
|
||||
// forwards
|
||||
gH_OnWorldRecord = CreateGlobalForward("Shavit_OnWorldRecord", ET_Event, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell);
|
||||
gH_OnFinish_Post = CreateGlobalForward("Shavit_OnFinish_Post", ET_Event, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell);
|
||||
gH_OnWRDeleted = CreateGlobalForward("Shavit_OnWRDeleted", ET_Event, Param_Cell, Param_Cell, Param_Cell);
|
||||
gH_OnWRDeleted = CreateGlobalForward("Shavit_OnWRDeleted", ET_Event, Param_Cell, Param_Cell, Param_Cell, Param_Cell);
|
||||
gH_OnWorstRecord = CreateGlobalForward("Shavit_OnWorstRecord", ET_Event, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell);
|
||||
gH_OnFinishMessage = CreateGlobalForward("Shavit_OnFinishMessage", ET_Event, Param_Cell, Param_CellByRef, Param_Array, Param_Cell, Param_Cell, Param_String, Param_Cell);
|
||||
|
||||
@ -576,6 +577,16 @@ public int Native_GetClientPB(Handle handler, int numParams)
|
||||
return view_as<int>(gF_PlayerRecord[GetNativeCell(1)][GetNativeCell(2)][GetNativeCell(3)]);
|
||||
}
|
||||
|
||||
public int Native_SetClientPB(Handle handler, int numParams)
|
||||
{
|
||||
int client = GetNativeCell(1);
|
||||
int style = GetNativeCell(2);
|
||||
int track = GetNativeCell(3);
|
||||
float time = GetNativeCell(4);
|
||||
|
||||
gF_PlayerRecord[client][style][track] = time;
|
||||
}
|
||||
|
||||
public int Native_GetPlayerPB(Handle handler, int numParams)
|
||||
{
|
||||
SetNativeCellRef(3, gF_PlayerRecord[GetNativeCell(1)][GetNativeCell(2)][GetNativeCell(4)]);
|
||||
@ -1234,6 +1245,7 @@ public void DeleteConfirm_Callback(Database db, DBResultSet results, const char[
|
||||
Call_PushCell(iStyle);
|
||||
Call_PushCell(iRecordID);
|
||||
Call_PushCell(iTrack);
|
||||
Call_PushCell(iSteamID);
|
||||
Call_Finish();
|
||||
}
|
||||
|
||||
|
||||
@ -157,6 +157,10 @@
|
||||
{
|
||||
"en" "Time Difference"
|
||||
}
|
||||
"HudTopLeftRankText"
|
||||
{
|
||||
"en" "Top left Rank"
|
||||
}
|
||||
// ---------- Record Bots ---------- //
|
||||
"ReplayText"
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user