/*
* Admin Demo Recorder (olds.ro workshop card LIB-0831)
*
* An admin starts or stops a demo on a chosen player's own client, for
* example to capture suspected cheating. The demo is written in the
* player's game folder (cstrike/<file>.dem), not on the server.
*
* amx_demostart <name or #userid> [file] start recording (ADMIN_BAN)
* amx_demostop <name or #userid> stop recording (ADMIN_BAN)
* amx_demolist who is being recorded (ADMIN_BAN)
*
* File: letters, digits, '_' and '-' only, up to 48 characters, without an
* extension; anything with '/', '\', '.' or ':' is rejected. Without a
* name: <olds_demo_prefix><map>_<date>_<time>. The prefix follows the same
* rule (an invalid prefix falls back to "olds_").
*
* Every start and stop is written to the AMXX log with the admin and the
* target (names and SteamIDs). Bots, HLTV, unknown names and immune admins
* get a clear console error and nothing is logged.
*
* Cvars: olds_demo_prefix "olds_", olds_demo_notify 1 (1 = the player sees a
* chat line that a demo is being recorded, and when it stops).
*
* Copyright (C) 2026 daemon (olds.ro)
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#include <amxmodx>
#include <amxmisc>
#define PLUGIN "Admin Demo Recorder"
#define VERSION "1.0.0"
#define AUTHOR "olds.ro"
const FILE_LENGTH = 49
const TARGET_FLAGS = CMDTARGET_OBEY_IMMUNITY | CMDTARGET_ALLOW_SELF | CMDTARGET_NO_BOTS
new g_file[MAX_PLAYERS + 1][FILE_LENGTH] // empty = not recording through this plugin
new g_prefix[24]
new g_notify
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_dictionary("olds_demo.txt")
bind_pcvar_string(create_cvar("olds_demo_prefix", "olds_", FCVAR_NONE,
"Start of automatic demo names (letters, digits, _ and -)."), g_prefix, charsmax(g_prefix))
bind_pcvar_num(create_cvar("olds_demo_notify", "1", FCVAR_NONE,
"1 = the player is told when a demo starts and stops.", true, 0.0, true, 1.0), g_notify)
AutoExecConfig(true, "olds_demo")
register_concmd("amx_demostart", "cmd_start", ADMIN_BAN, "<name or #userid> [file] - record a demo on the player's client")
register_concmd("amx_demostop", "cmd_stop", ADMIN_BAN, "<name or #userid> - stop that player's demo")
register_concmd("amx_demolist", "cmd_list", ADMIN_BAN, "- players being recorded")
}
/* Letters, digits, '_' and '-'; nothing that could leave the game folder. */
bool:safe_name(const text[], maxLength)
{
new length = strlen(text)
if (!length || length > maxLength)
return false
for (new i = 0; i < length; i++)
if (!isalnum(text[i]) && text[i] != '_' && text[i] != '-')
return false
return true
}
public cmd_start(id, level, cid)
{
if (!cmd_access(id, level, cid, 2))
return PLUGIN_HANDLED
new arg[32], file[64]
read_argv(1, arg, charsmax(arg))
read_argv(2, file, charsmax(file))
trim(file)
// The file name first: a bad one is refused before anything else.
if (file[0] && !safe_name(file, FILE_LENGTH - 1))
{
console_print(id, "[Demo] file name rejected: use letters, digits, _ and - only (up to %d), no path or extension",
FILE_LENGTH - 1)
return PLUGIN_HANDLED
}
new target = cmd_target(id, arg, TARGET_FLAGS)
if (!target)
return PLUGIN_HANDLED
if (is_user_hltv(target))
{
console_print(id, "[Demo] that client is HLTV: record on the HLTV itself")
return PLUGIN_HANDLED
}
if (g_file[target][0])
{
console_print(id, "[Demo] already recording %s.dem on that player; amx_demostop first", g_file[target])
return PLUGIN_HANDLED
}
if (!file[0])
auto_name(file, charsmax(file))
copy(g_file[target], charsmax(g_file[]), file)
client_cmd(target, "record ^"%s^"", file)
if (g_notify)
client_print_color(target, print_team_default, "^4[Demo]^1 %L", target, "DEMO_STARTED", file)
new admin[MAX_NAME_LENGTH], adminId[MAX_AUTHID_LENGTH], name[MAX_NAME_LENGTH], authId[MAX_AUTHID_LENGTH]
describe(id, admin, adminId)
get_user_name(target, name, charsmax(name))
get_user_authid(target, authId, charsmax(authId))
log_amx("Demo: ^"%s<%s>^" started recording %s.dem on ^"%s<%s>^"", admin, adminId, file, name, authId)
console_print(id, "[Demo] recording %s.dem on %s (in their cstrike folder)", file, name)
return PLUGIN_HANDLED
}
public cmd_stop(id, level, cid)
{
if (!cmd_access(id, level, cid, 2))
return PLUGIN_HANDLED
new arg[32]
read_argv(1, arg, charsmax(arg))
new target = cmd_target(id, arg, TARGET_FLAGS)
if (!target)
return PLUGIN_HANDLED
new name[MAX_NAME_LENGTH]
get_user_name(target, name, charsmax(name))
if (!g_file[target][0])
{
console_print(id, "[Demo] %s is not being recorded by this plugin", name)
return PLUGIN_HANDLED
}
client_cmd(target, "stop")
if (g_notify)
client_print_color(target, print_team_default, "^4[Demo]^1 %L", target, "DEMO_STOPPED", g_file[target])
new admin[MAX_NAME_LENGTH], adminId[MAX_AUTHID_LENGTH], authId[MAX_AUTHID_LENGTH]
describe(id, admin, adminId)
get_user_authid(target, authId, charsmax(authId))
log_amx("Demo: ^"%s<%s>^" stopped recording %s.dem on ^"%s<%s>^"", admin, adminId, g_file[target], name, authId)
console_print(id, "[Demo] stopped %s.dem on %s", g_file[target], name)
g_file[target][0] = EOS
return PLUGIN_HANDLED
}
public cmd_list(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
new count, name[MAX_NAME_LENGTH]
for (new p = 1; p <= MaxClients; p++)
{
if (!g_file[p][0] || !is_user_connected(p))
continue
get_user_name(p, name, charsmax(name))
console_print(id, "[Demo] %s: %s.dem", name, g_file[p])
count++
}
console_print(id, "[Demo] %d player(s) being recorded", count)
return PLUGIN_HANDLED
}
auto_name(file[], maxLength)
{
new prefix[24], map[32], stamp[20]
copy(prefix, charsmax(prefix), g_prefix)
if (!safe_name(prefix, 20))
copy(prefix, charsmax(prefix), "olds_")
get_mapname(map, charsmax(map))
// Map names may hold dots or other characters: keep only the safe ones.
for (new i = 0; map[i]; i++)
if (!isalnum(map[i]) && map[i] != '_' && map[i] != '-')
map[i] = '_'
get_time("%Y%m%d_%H%M%S", stamp, charsmax(stamp))
formatex(file, maxLength, "%s%s_%s", prefix, map, stamp)
file[FILE_LENGTH - 1] = EOS
}
describe(id, name[MAX_NAME_LENGTH], authId[MAX_AUTHID_LENGTH])
{
if (!id)
{
copy(name, charsmax(name), "SERVER")
copy(authId, charsmax(authId), "CONSOLE")
return
}
get_user_name(id, name, charsmax(name))
get_user_authid(id, authId, charsmax(authId))
}
public client_disconnected(id)
{
if (g_file[id][0])
{
new name[MAX_NAME_LENGTH]
get_user_name(id, name, charsmax(name))
log_amx("Demo: ^"%s^" left while recording %s.dem (the client closes the demo)", name, g_file[id])
}
g_file[id][0] = EOS
}