Skip to content

Commit

Permalink
Add wipeplayer command (#311)
Browse files Browse the repository at this point in the history
Source/Credits: qawery-just-sad@ad18ac2
  • Loading branch information
Bara committed Sep 22, 2021
1 parent 4318cbe commit eec596a
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 0 deletions.
20 changes: 20 additions & 0 deletions addons/sourcemod/scripting/surftimer/admin.sp
Original file line number Diff line number Diff line change
Expand Up @@ -644,3 +644,23 @@ public Action Admin_RefreshProfile(int client, int args)
}
return Plugin_Handled;
}

public Action Admin_ResetRecords(int client, int args)
{
if (args < 1)
{
ReplyToCommand(client, "%s Usage: sm_wipeplayer <steamid>", g_szChatPrefix);
return Plugin_Handled;
}
else
{
char szArg[32];
GetCmdArgString(szArg, sizeof(szArg));

StripQuotes(szArg);
TrimString(szArg);
PrintToChat(client, "Output test: %s", szArg);
db_WipePlayer(client, szArg);
}
return Plugin_Handled;
}
1 change: 1 addition & 0 deletions addons/sourcemod/scripting/surftimer/commands.sp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ void CreateCommands()
// Delete records
RegAdminCmd("sm_deleterecords", Command_DeleteRecords, g_ZonerFlag, "[surftimer] [zoner] Delete records");
RegAdminCmd("sm_dr", Command_DeleteRecords, g_ZonerFlag, "[surftimer] [zoner] Delete records");
RegAdminCmd("sm_wipeplayer", Admin_ResetRecords, ADMFLAG_ROOT, "[surfTimer] Removes all database entries of the specific steamid - requires z flag");

// Setting Commands
RegConsoleCmd("sm_pre", Command_Prestrafe, "[surftimer] [settings] Toggles prestrafe messages for player");
Expand Down
85 changes: 85 additions & 0 deletions addons/sourcemod/scripting/surftimer/sql.sp
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,91 @@ public int callback_Confirm(Menu menu, MenuAction action, int client, int key)
delete menu;
}

public void db_WipePlayer(int client, char szSteamID[32])
{
Transaction tTransaction = new Transaction();
char szQuery[256];

Format(szQuery, sizeof(szQuery), "DELETE FROM ck_playertimes WHERE steamid = \"%s\";", szSteamID);
tTransaction.AddQuery(szQuery, 1);
Format(szQuery, sizeof(szQuery), "DELETE FROM ck_bonus WHERE steamid = \"%s\";", szSteamID);
tTransaction.AddQuery(szQuery, 2);
Format(szQuery, sizeof(szQuery), "DELETE FROM ck_checkpoints WHERE steamid = \"%s\";", szSteamID);
tTransaction.AddQuery(szQuery, 3);
Format(szQuery, sizeof(szQuery), "DELETE FROM ck_playerrank WHERE steamid = \"%s\";", szSteamID);
tTransaction.AddQuery(szQuery, 4);
Format(szQuery, sizeof(szQuery), "DELETE FROM ck_wrcps WHERE steamid = \"%s\";", szSteamID);
tTransaction.AddQuery(szQuery, 5);
Format(szQuery, sizeof(szQuery), "DELETE FROM ck_playeroptions2 WHERE steamid = \"%s\";", szSteamID);
tTransaction.AddQuery(szQuery, 6);
Format(szQuery, sizeof(szQuery), "DELETE FROM ck_latestrecords WHERE steamid = \"%s\";", szSteamID);
tTransaction.AddQuery(szQuery, 7);
Format(szQuery, sizeof(szQuery), "DELETE FROM ck_playertemp WHERE steamid = \"%s\";", szSteamID);
tTransaction.AddQuery(szQuery, 8);

DataPack pack = new DataPack();
pack.WriteCell(GetClientUserId(client));
pack.WriteString(szSteamID);
SQL_ExecuteTransaction(g_hDb ,tTransaction, SQLTxn_WipePlayerSuccess, SQLTxn_WipePlayerFailed, pack, DBPrio_High);
}

public void SQLTxn_WipePlayerSuccess(Handle db, DataPack pack, int numQueries, Handle[] results, any[] queryData)
{
pack.Reset();

int client = GetClientOfUserId(pack.ReadCell());

char szSteamID[32];
pack.ReadString(szSteamID, sizeof(szSteamID));

delete pack;


if (IsValidClient(client))
{
PrintToChat(client, "Player %s has been wiped!", szSteamID);
PrintToConsole(client, "Player %s has been wiped!", szSteamID);
}

char sBuffer[32];

for(int i = 1; i <= MaxClients; i++)
{
if (!IsClientInGame(i))
continue;

GetClientAuthId(i, AuthId_Steam2, sBuffer, sizeof(sBuffer));
if (StrEqual(sBuffer, szSteamID, false))
{
g_bSettingsLoaded[client] = false;
g_bLoadingSettings[client] = true;
g_iSettingToLoad[client] = 0;
LoadClientSetting(client, g_iSettingToLoad[client]);
break;
}
}
}

public void SQLTxn_WipePlayerFailed(Handle db, DataPack pack, int numQueries, const char[] error, int failIndex, any[] queryData)
{
pack.Reset();

int client = GetClientOfUserId(pack.ReadCell());

char szSteamID[32];
pack.ReadString(szSteamID, sizeof(szSteamID));

delete pack;


LogError("[SurfTimer] Wipe of player %s failed! Error (Query: %d): %s", szSteamID, queryData[failIndex], error);

if (IsValidClient(client))
{
PrintToChat(client, "[SurfTimer] Wipe of player %s failed! Error (Query: %d): %s", szSteamID, queryData[failIndex], error);
PrintToConsole(client, "[SurfTimer] Wipe of player %s failed! Error (Query: %d): %s", szSteamID, queryData[failIndex], error);
}
}

/*==================================
= SPAWN LOCATION =
Expand Down

0 comments on commit eec596a

Please sign in to comment.