Daemon666 / CSB Admin Password Herkese açık

amx_lock sets sv_password (random or given) and shows it to admins only; amx_unlock clears it. A HUD reminder keeps admins aware the server is locked.

v1.0.0 147 indirme GPL-3.0 Son güncelleme Aug 23, 2026
csb_admin_password.sma v1.0.0 161 satır · 3.9 KB Ham
1 /*
2 * CSB Admin Password
3 * Copyright (C) 2026 counter-strike-boost.com
4 *
5 * amx_lock [password] sets sv_password to a given or randomly generated string
6 * and prints it only to admins; amx_unlock clears it. Handy for locking a server
7 * for a clan war. While locked, a HUD reminder is shown to admins and the state
8 * change is written to the AMXX log.
9 *
10 * This program is free software: you can redistribute it and/or modify it under
11 * the terms of the GNU General Public License as published by the Free Software
12 * Foundation, either version 3 of the License, or (at your option) any later
13 * version. It is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See <https://www.gnu.org/licenses/> for details.
16 */
17
18 #include <amxmodx>
19 #include <amxmisc>
20
21 new const PLUGIN[] = "CSB Admin Password"
22 new const VERSION[] = "1.0.0"
23 new const AUTHOR[] = "counter-strike-boost.com"
24
25 new const CHARSET[] = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"
26
27 new g_pLen
28 new bool:g_bLocked = false
29 new g_szCurrent[32]
30
31 public plugin_init()
32 {
33 register_plugin(PLUGIN, VERSION, AUTHOR)
34
35 g_pLen = register_cvar("csb_lock_len", "6")
36
37 register_concmd("amx_lock", "cmdLock", ADMIN_PASSWORD, "[password] - lock the server (random if omitted)")
38 register_concmd("amx_unlock", "cmdUnlock", ADMIN_PASSWORD, "- unlock the server")
39
40 set_task(30.0, "taskReminder", 0, _, _, "b")
41 }
42
43 randomPassword(out[], len)
44 {
45 new setLen = charsmax(CHARSET) /* index of terminator = length-1 */
46 new i = 0
47
48 for (; i < len; i++)
49 out[i] = CHARSET[random_num(0, setLen - 1)]
50
51 out[i] = 0
52 }
53
54 public cmdLock(id, level, cid)
55 {
56 if (!cmd_access(id, level, cid, 1))
57 return PLUGIN_HANDLED
58
59 new pw[32]
60
61 if (read_argc() > 1)
62 {
63 read_argv(1, pw, charsmax(pw))
64 }
65 else
66 {
67 new n = get_pcvar_num(g_pLen)
68 if (n < 4) n = 4
69 if (n > 20) n = 20
70 randomPassword(pw, n)
71 }
72
73 set_cvar_string("sv_password", pw)
74 copy(g_szCurrent, charsmax(g_szCurrent), pw)
75 g_bLocked = true
76
77 new aname[32]
78 getName(id, aname, charsmax(aname))
79
80 announceAdmins("^x04[CSB]^x03 %s^x01 locked the server. Password:^x04 %s", aname, pw)
81 log_amx("[CSB Lock] %s locked the server", aname)
82 return PLUGIN_HANDLED
83 }
84
85 public cmdUnlock(id, level, cid)
86 {
87 if (!cmd_access(id, level, cid, 1))
88 return PLUGIN_HANDLED
89
90 set_cvar_string("sv_password", "")
91 g_bLocked = false
92 g_szCurrent[0] = 0
93
94 new aname[32]
95 getName(id, aname, charsmax(aname))
96
97 announceAdmins("^x04[CSB]^x03 %s^x01 unlocked the server.", aname)
98 log_amx("[CSB Lock] %s unlocked the server", aname)
99 return PLUGIN_HANDLED
100 }
101
102 public taskReminder()
103 {
104 if (!g_bLocked)
105 return
106
107 /* the current sv_password may have been changed by hand - resync state */
108 new live[32]
109 get_cvar_string("sv_password", live, charsmax(live))
110
111 if (!live[0])
112 {
113 g_bLocked = false
114 return
115 }
116
117 new players[32], num, pid
118 get_players(players, num, "ch")
119
120 for (new i = 0; i < num; i++)
121 {
122 pid = players[i]
123
124 if (!(get_user_flags(pid) & ADMIN_PASSWORD))
125 continue
126
127 set_hudmessage(255, 80, 80, 0.02, 0.05, 0, 0.0, 4.0, 0.0, 0.0, -1)
128 show_hudmessage(pid, "SERVER LOCKED - password: %s", live)
129 }
130 }
131
132 announceAdmins(const fmt[], any:...)
133 {
134 new msg[192]
135 vformat(msg, charsmax(msg), fmt, 2)
136
137 new players[32], num, pid, msgid = get_user_msgid("SayText")
138 get_players(players, num, "ch")
139
140 for (new i = 0; i < num; i++)
141 {
142 pid = players[i]
143
144 if (!(get_user_flags(pid) & ADMIN_PASSWORD))
145 continue
146
147 message_begin(MSG_ONE, msgid, _, pid)
148 write_byte(pid)
149 write_string(msg)
150 message_end()
151 }
152 }
153
154 getName(id, name[], len)
155 {
156 if (id)
157 get_user_name(id, name, len)
158 else
159 copy(name, len, "CONSOLE")
160 }
161