/*
* CSB Admin Password
* Copyright (C) 2026 counter-strike-boost.com
*
* amx_lock [password] sets sv_password to a given or randomly generated string
* and prints it only to admins; amx_unlock clears it. Handy for locking a server
* for a clan war. While locked, a HUD reminder is shown to admins and the state
* change is written to the AMXX log.
*
* 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. It 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 for details.
*/
#include
#include
new const PLUGIN[] = "CSB Admin Password"
new const VERSION[] = "1.0.0"
new const AUTHOR[] = "counter-strike-boost.com"
new const CHARSET[] = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"
new g_pLen
new bool:g_bLocked = false
new g_szCurrent[32]
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
g_pLen = register_cvar("csb_lock_len", "6")
register_concmd("amx_lock", "cmdLock", ADMIN_PASSWORD, "[password] - lock the server (random if omitted)")
register_concmd("amx_unlock", "cmdUnlock", ADMIN_PASSWORD, "- unlock the server")
set_task(30.0, "taskReminder", 0, _, _, "b")
}
randomPassword(out[], len)
{
new setLen = charsmax(CHARSET) /* index of terminator = length-1 */
new i = 0
for (; i < len; i++)
out[i] = CHARSET[random_num(0, setLen - 1)]
out[i] = 0
}
public cmdLock(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
new pw[32]
if (read_argc() > 1)
{
read_argv(1, pw, charsmax(pw))
}
else
{
new n = get_pcvar_num(g_pLen)
if (n < 4) n = 4
if (n > 20) n = 20
randomPassword(pw, n)
}
set_cvar_string("sv_password", pw)
copy(g_szCurrent, charsmax(g_szCurrent), pw)
g_bLocked = true
new aname[32]
getName(id, aname, charsmax(aname))
announceAdmins("^x04[CSB]^x03 %s^x01 locked the server. Password:^x04 %s", aname, pw)
log_amx("[CSB Lock] %s locked the server", aname)
return PLUGIN_HANDLED
}
public cmdUnlock(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
set_cvar_string("sv_password", "")
g_bLocked = false
g_szCurrent[0] = 0
new aname[32]
getName(id, aname, charsmax(aname))
announceAdmins("^x04[CSB]^x03 %s^x01 unlocked the server.", aname)
log_amx("[CSB Lock] %s unlocked the server", aname)
return PLUGIN_HANDLED
}
public taskReminder()
{
if (!g_bLocked)
return
/* the current sv_password may have been changed by hand - resync state */
new live[32]
get_cvar_string("sv_password", live, charsmax(live))
if (!live[0])
{
g_bLocked = false
return
}
new players[32], num, pid
get_players(players, num, "ch")
for (new i = 0; i < num; i++)
{
pid = players[i]
if (!(get_user_flags(pid) & ADMIN_PASSWORD))
continue
set_hudmessage(255, 80, 80, 0.02, 0.05, 0, 0.0, 4.0, 0.0, 0.0, -1)
show_hudmessage(pid, "SERVER LOCKED - password: %s", live)
}
}
announceAdmins(const fmt[], any:...)
{
new msg[192]
vformat(msg, charsmax(msg), fmt, 2)
new players[32], num, pid, msgid = get_user_msgid("SayText")
get_players(players, num, "ch")
for (new i = 0; i < num; i++)
{
pid = players[i]
if (!(get_user_flags(pid) & ADMIN_PASSWORD))
continue
message_begin(MSG_ONE, msgid, _, pid)
write_byte(pid)
write_string(msg)
message_end()
}
}
getName(id, name[], len)
{
if (id)
get_user_name(id, name, len)
else
copy(name, len, "CONSOLE")
}