Skip to content

Instantly share code, notes, and snippets.

@TheByKotik
Created July 22, 2019 10:46
Show Gist options
  • Save TheByKotik/6aaa3fe5db778db6635c4f324e1925d6 to your computer and use it in GitHub Desktop.
Save TheByKotik/6aaa3fe5db778db6635c4f324e1925d6 to your computer and use it in GitHub Desktop.
public void SelectUnbanCallback (Database db, DBResultSet results, const char[] error, DataPack dataPack)
{
int admin;
char arg[30], adminAuth[30], unbanReason[256];
char reason[128];
dataPack.Reset();
admin = dataPack.ReadCell();
dataPack.ReadString(reason, sizeof(reason));
dataPack.ReadString(arg, sizeof(arg));
dataPack.ReadString(adminAuth, sizeof(adminAuth));
db.Escape(reason, unbanReason, sizeof(unbanReason));
// If error is not an empty string the query failed
if (results == null)
{
LogToFile(logFile, "Unban Select Query Failed: %s", error);
if (admin && IsClientInGame(admin))
{
PrintToChat(admin, "%ssm_unban failed", Prefix);
}
}
// If there was no results then a ban does not exist for that id
else if (!results.RowCount)
{
if (admin && IsClientInGame(admin))
{
PrintToChat(admin, "%sNo active bans found for that filter", Prefix);
} else {
PrintToServer("%sNo active bans found for that filter", Prefix);
}
}
// There is ban
else if (results.FetchRow())
{
// Get the values from the existing ban record
int bid = results.FetchInt(0);
char query[1000];
Format(query, sizeof(query), "UPDATE %s_bans SET RemovedBy = (SELECT aid FROM %s_admins WHERE authid = '%s' OR authid REGEXP '^STEAM_[0-9]:%s$'), RemoveType = 'U', RemovedOn = UNIX_TIMESTAMP(), ureason = '%s' WHERE bid = %d",
DatabasePrefix, DatabasePrefix, adminAuth, adminAuth[8], unbanReason, bid);
db.Query(InsertUnbanCallback, query, dataPack);
return;
}
delete dataPack;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment