/*
* Admin Abuse Reports (olds.ro)
* Copyright (C) 2026 daemon (olds.ro), written by daemon's plugin agent
*
* This program is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details: <https://www.gnu.org/licenses/>.
*
* A player types /reportadmin, picks an online admin from a menu (never himself) and types the
* reason (messagemode olds_abuse_reason). The report is appended to
* configs/olds_abuse_reports.ini with the time, both names and both Steam IDs; the fields are
* escaped (% " ; | \ and control characters become %XX), so quotes and semicolons cannot break
* the file. One report per olds_abuse_cooldown seconds per Steam ID (kept across reconnects);
* a reason is cut to olds_abuse_maxlen characters. Online ADMIN_RCON holders (except the
* reported admin) are told in chat; the owner reads the list with amx_abuselist [n].
*
* Cvars: olds_abuse_cooldown 300, olds_abuse_maxlen 120
* Commands: say /reportadmin; owner: amx_abuselist [n] (ADMIN_RCON)
*/
#include <amxmodx>
#include <amxmisc>
#pragma semicolon 0
#define PLUGIN "Admin Abuse Reports"
#define VERSION "1.0.0"
#define AUTHOR "daemon (olds.ro)"
#define PENDING_SECONDS 90
#define LIST_MAX 50
#define LINE_LEN 700
#define FIELD_LEN 400
new g_cooldown
new g_maxLen
new g_path[PLATFORM_MAX_PATH]
new Trie:g_lastReport
new g_pendingTarget[MAX_PLAYERS + 1]
new g_pendingTime[MAX_PLAYERS + 1]
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_dictionary("olds_abuse.txt")
bind_pcvar_num(create_cvar("olds_abuse_cooldown", "300", FCVAR_NONE,
"Seconds between two reports of one player", true, 0.0, true, 86400.0), g_cooldown)
bind_pcvar_num(create_cvar("olds_abuse_maxlen", "120", FCVAR_NONE,
"Longest reason kept (characters)", true, 10.0, true, 190.0), g_maxLen)
AutoExecConfig(true, "olds_abuse")
register_clcmd("say /reportadmin", "cmd_report")
register_clcmd("say_team /reportadmin", "cmd_report")
register_clcmd("olds_abuse_reason", "cmd_reason")
register_concmd("amx_abuselist", "cmd_list", ADMIN_RCON, "[n] - shows the last n admin abuse reports")
get_configsdir(g_path, charsmax(g_path))
add(g_path, charsmax(g_path), "/olds_abuse_reports.ini")
g_lastReport = TrieCreate()
}
public plugin_end()
{
TrieDestroy(g_lastReport)
}
public client_disconnected(id)
{
g_pendingTarget[id] = 0
}
/* ------------------------------------------------------------ helpers */
bool:is_admin(id)
{
return (get_user_flags(id) & ~ADMIN_USER) != 0
}
/* Seconds this player still has to wait, 0 when a report is allowed. */
wait_left(id)
{
new auth[40], last
get_user_authid(id, auth, charsmax(auth))
if (!TrieGetCell(g_lastReport, auth, last))
return 0
return max(last + g_cooldown - get_systime(), 0)
}
escape_field(const text[], out[], len)
{
new o, hex[] = "0123456789ABCDEF"
for (new i = 0; text[i] && o < len; i++)
{
new c = text[i]
if (c == '%' || c == '"' || c == ';' || c == '|' || c == '\' || c < ' ')
{
if (o + 3 > len)
break
out[o++] = '%'
out[o++] = hex[(c >> 4) & 15]
out[o++] = hex[c & 15]
}
else
out[o++] = c
}
out[o] = EOS
}
hex_value(c)
{
if ('0' <= c <= '9')
return c - '0'
if ('A' <= c <= 'F')
return c - 'A' + 10
if ('a' <= c <= 'f')
return c - 'a' + 10
return -1
}
unescape_field(const text[], out[], len)
{
new o
for (new i = 0; text[i] && o < len; i++)
{
if (text[i] == '%' && text[i + 1] && text[i + 2])
{
new a = hex_value(text[i + 1]), b = hex_value(text[i + 2])
if (a >= 0 && b >= 0)
{
new c = a * 16 + b
/* Show control characters as a space when reading back. */
if (c < ' ')
c = ' '
out[o++] = c
i += 2
continue
}
}
out[o++] = text[i]
}
out[o] = EOS
}
/* ------------------------------------------------------------ reporting */
public cmd_report(id)
{
if (!is_user_connected(id))
return PLUGIN_HANDLED
new left = wait_left(id)
if (left > 0)
{
client_print(id, print_chat, "%L", id, "ABUSE_WAIT", left)
return PLUGIN_HANDLED
}
new players[MAX_PLAYERS], count
get_players_ex(players, count, GetPlayers_ExcludeHLTV)
new menu = menu_create("Report an admin for abuse", "menu_pick")
new name[MAX_NAME_LENGTH], info[8], listed[256], shown
for (new i = 0; i < count; i++)
{
new target = players[i]
/* Nobody can report himself. */
if (target == id || !is_admin(target))
continue
get_user_name(target, name, charsmax(name))
num_to_str(get_user_userid(target), info, charsmax(info))
menu_additem(menu, name, info)
if (shown)
add(listed, charsmax(listed), ", ")
add(listed, charsmax(listed), name)
shown++
}
new opener[MAX_NAME_LENGTH]
get_user_name(id, opener, charsmax(opener))
if (!shown)
{
menu_destroy(menu)
client_print(id, print_chat, "%L", id, "ABUSE_NO_ADMINS")
server_print("[Abuse] menu for %s: no admins to report", opener)
return PLUGIN_HANDLED
}
server_print("[Abuse] menu for %s: %s", opener, listed)
menu_display(id, menu)
return PLUGIN_HANDLED
}
public menu_pick(id, menu, key)
{
if (key < 0)
{
menu_destroy(menu)
return PLUGIN_HANDLED
}
new info[8], access, callback
menu_item_getinfo(menu, key, access, info, charsmax(info), _, _, callback)
menu_destroy(menu)
if (!is_user_connected(id))
return PLUGIN_HANDLED
new target = find_player_ex(FindPlayer_MatchUserId, str_to_num(info))
if (!target || target == id || !is_admin(target))
{
client_print(id, print_chat, "%L", id, "ABUSE_GONE")
return PLUGIN_HANDLED
}
g_pendingTarget[id] = get_user_userid(target)
g_pendingTime[id] = get_systime()
client_print(id, print_chat, "%L", id, "ABUSE_TYPE_REASON")
client_cmd(id, "messagemode olds_abuse_reason")
return PLUGIN_HANDLED
}
public cmd_reason(id)
{
if (!is_user_connected(id) || !g_pendingTarget[id])
return PLUGIN_HANDLED
new userid = g_pendingTarget[id]
g_pendingTarget[id] = 0
if (get_systime() - g_pendingTime[id] > PENDING_SECONDS)
{
client_print(id, print_chat, "%L", id, "ABUSE_EXPIRED")
return PLUGIN_HANDLED
}
new left = wait_left(id)
if (left > 0)
{
client_print(id, print_chat, "%L", id, "ABUSE_WAIT", left)
return PLUGIN_HANDLED
}
new target = find_player_ex(FindPlayer_MatchUserId, userid)
if (!target || target == id)
{
client_print(id, print_chat, "%L", id, "ABUSE_GONE")
return PLUGIN_HANDLED
}
new reason[192]
read_args(reason, charsmax(reason))
remove_quotes(reason)
trim(reason)
if (!reason[0])
{
client_print(id, print_chat, "%L", id, "ABUSE_EMPTY")
return PLUGIN_HANDLED
}
new maxLen = clamp(g_maxLen, 10, charsmax(reason))
if (strlen(reason) > maxLen)
{
reason[maxLen] = EOS
client_print(id, print_chat, "%L", id, "ABUSE_CUT", maxLen)
}
store_report(id, target, reason)
return PLUGIN_HANDLED
}
store_report(id, target, const reason[])
{
new when[24], rName[MAX_NAME_LENGTH], rAuth[40], aName[MAX_NAME_LENGTH], aAuth[40]
format_time(when, charsmax(when), "%Y-%m-%d %H:%M:%S")
get_user_name(id, rName, charsmax(rName))
get_user_authid(id, rAuth, charsmax(rAuth))
get_user_name(target, aName, charsmax(aName))
get_user_authid(target, aAuth, charsmax(aAuth))
new eaName[100], eaAuth[100], erName[100], erAuth[100], eReason[FIELD_LEN]
escape_field(aName, eaName, charsmax(eaName))
escape_field(aAuth, eaAuth, charsmax(eaAuth))
escape_field(rName, erName, charsmax(erName))
escape_field(rAuth, erAuth, charsmax(erAuth))
escape_field(reason, eReason, charsmax(eReason))
new existed = file_exists(g_path)
new file = fopen(g_path, "at")
if (!file)
{
log_amx("Cannot write %s: report by %s on %s lost", g_path, rAuth, aAuth)
client_print(id, print_chat, "%L", id, "ABUSE_FAILED")
return
}
if (!existed)
fputs(file, "; Admin abuse reports: time|admin|admin Steam ID|reporter|reporter Steam ID|reason (%XX escaped)^n")
fprintf(file, "%s|%s|%s|%s|%s|%s^n", when, eaName, eaAuth, erName, erAuth, eReason)
fclose(file)
TrieSetCell(g_lastReport, rAuth, get_systime())
log_amx("Abuse report: %s <%s> reported %s <%s>: %s|%s", rName, rAuth, aName, aAuth, when, eReason)
client_print(id, print_chat, "%L", id, "ABUSE_STORED", aName)
new players[MAX_PLAYERS], count
get_players_ex(players, count, GetPlayers_ExcludeBots | GetPlayers_ExcludeHLTV)
for (new i = 0; i < count; i++)
{
new owner = players[i]
if (owner != target && (get_user_flags(owner) & ADMIN_RCON))
client_print(owner, print_chat, "%L", owner, "ABUSE_NOTICE", rName, aName)
}
}
/* ------------------------------------------------------------ the owner's list */
public cmd_list(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
new arg[8], wanted = 10
if (read_argc() > 1)
{
read_argv(1, arg, charsmax(arg))
if (!is_str_num(arg))
{
console_print(id, "Usage: amx_abuselist [n] (1-%d)", LIST_MAX)
return PLUGIN_HANDLED
}
wanted = str_to_num(arg)
}
wanted = clamp(wanted, 1, LIST_MAX)
new file = fopen(g_path, "rt")
if (!file)
{
console_print(id, "No admin abuse reports.")
return PLUGIN_HANDLED
}
/* Keep the last `wanted` lines in a ring. */
new Array:ring = ArrayCreate(LINE_LEN)
new line[LINE_LEN], total
while (fgets(file, line, charsmax(line)))
{
trim(line)
if (!line[0] || line[0] == ';')
continue
if (ArraySize(ring) >= wanted)
ArrayDeleteItem(ring, 0)
ArrayPushString(ring, line)
total++
}
fclose(file)
new shown = ArraySize(ring)
console_print(id, "Admin abuse reports: last %d of %d", shown, total)
new part[6][FIELD_LEN], text[6][FIELD_LEN]
for (new i = 0; i < shown; i++)
{
ArrayGetString(ring, i, line, charsmax(line))
if (explode_string(line, "|", part, 6, FIELD_LEN - 1) != 6)
continue
for (new k = 0; k < 6; k++)
unescape_field(part[k], text[k], FIELD_LEN - 1)
console_print(id, "%d. %s %s <%s> by %s <%s>: %s", total - shown + i + 1, text[0], text[1], text[2], text[3], text[4], text[5])
}
ArrayDestroy(ring)
return PLUGIN_HANDLED
}