Triggering yet another build.
3 * =============================================================================
4 * SourceMod Basic Commands Plugin
5 * Implements basic admin commands.
7 * SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
8 * =============================================================================
10 * This program is free software; you can redistribute it and/or modify it under
11 * the terms of the GNU General Public License, version 3.0, as published by the
12 * Free Software Foundation.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
19 * You should have received a copy of the GNU General Public License along with
20 * this program. If not, see <http://www.gnu.org/licenses/>.
22 * As a special exception, AlliedModders LLC gives you permission to link the
23 * code of this program (as well as its derivative 1works) to "Half-Life 2," the
24 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
25 * by the Valve Corporation. You must obey the GNU General Public License in
26 * all respects for all other code used. Additionally, AlliedModders LLC grants
27 * this exception to all derivative works. AlliedModders LLC defines further
28 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
29 * or <http://www.sourcemod.net/license.php>.
40 public Plugin:myinfo =
42 name = "Basic Commands",
43 author = "AlliedModders LLC",
44 description = "Basic Admin Commands",
45 version = SOURCEMOD_VERSION,
46 url = "http://www.sourcemod.net/"
49 new Handle:hTopMenu = INVALID_HANDLE;
52 new Handle:g_ProtectedVars;
54 #include "basecommands/kick.sp"
55 #include "basecommands/reloadadmins.sp"
56 #include "basecommands/cancelvote.sp"
57 #include "basecommands/who.sp"
58 #include "basecommands/map.sp"
59 #include "basecommands/execcfg.sp"
61 public OnPluginStart()
63 LoadTranslations("common.phrases");
64 LoadTranslations("plugin.basecommands");
66 RegAdminCmd("sm_kick", Command_Kick, ADMFLAG_KICK, "sm_kick <#userid|name> [reason]");
67 RegAdminCmd("sm_map", Command_Map, ADMFLAG_CHANGEMAP, "sm_map <map>");
68 RegAdminCmd("sm_rcon", Command_Rcon, ADMFLAG_RCON, "sm_rcon <args>");
69 RegAdminCmd("sm_cvar", Command_Cvar, ADMFLAG_CONVARS, "sm_cvar <cvar> [value]");
70 RegAdminCmd("sm_execcfg", Command_ExecCfg, ADMFLAG_CONFIG, "sm_execcfg <filename>");
71 RegAdminCmd("sm_who", Command_Who, ADMFLAG_GENERIC, "sm_who [#userid|name]");
72 RegAdminCmd("sm_reloadadmins", Command_ReloadAdmins, ADMFLAG_BAN, "sm_reloadadmins");
73 RegAdminCmd("sm_cancelvote", Command_CancelVote, ADMFLAG_VOTE, "sm_cancelvote");
74 RegConsoleCmd("sm_revote", Command_ReVote);
76 /* Account for late loading */
78 if (LibraryExists("adminmenu") && ((topmenu = GetAdminTopMenu()) != INVALID_HANDLE))
80 OnAdminMenuReady(topmenu);
83 g_MapList = CreateMenu(MenuHandler_ChangeMap);
84 SetMenuTitle(g_MapList, "Please select a map");
85 SetMenuExitBackButton(g_MapList, true);
87 decl String:mapListPath[PLATFORM_MAX_PATH];
88 BuildPath(Path_SM, mapListPath, sizeof(mapListPath), "configs/adminmenu_maplist.ini");
89 SetMapListCompatBind("sm_map menu", mapListPath);
91 g_ProtectedVars = CreateTrie();
92 ProtectVar("rcon_password");
93 ProtectVar("sm_show_activity");
94 ProtectVar("sm_immunity_mode");
102 public OnConfigsExecuted()
104 LoadMapList(g_MapList);
107 ProtectVar(const String:cvar[])
109 SetTrieValue(g_ProtectedVars, cvar, 1);
112 bool:IsVarProtected(const String:cvar[])
115 return GetTrieValue(g_ProtectedVars, cvar, dummy_value);
118 public OnAdminMenuReady(Handle:topmenu)
120 /* Block us from being called twice */
121 if (topmenu == hTopMenu)
126 /* Save the Handle */
129 /* Build the "Player Commands" category */
130 new TopMenuObject:player_commands = FindTopMenuCategory(hTopMenu, ADMINMENU_PLAYERCOMMANDS);
132 if (player_commands != INVALID_TOPMENUOBJECT)
134 AddToTopMenu(hTopMenu,
142 AddToTopMenu(hTopMenu,
151 new TopMenuObject:server_commands = FindTopMenuCategory(hTopMenu, ADMINMENU_SERVERCOMMANDS);
153 if (server_commands != INVALID_TOPMENUOBJECT)
155 AddToTopMenu(hTopMenu,
158 AdminMenu_ReloadAdmins,
163 AddToTopMenu(hTopMenu,
171 AddToTopMenu(hTopMenu,
180 new TopMenuObject:voting_commands = FindTopMenuCategory(hTopMenu, ADMINMENU_VOTINGCOMMANDS);
182 if (voting_commands != INVALID_TOPMENUOBJECT)
184 AddToTopMenu(hTopMenu,
187 AdminMenu_CancelVote,
194 public OnLibraryRemoved(const String:name[])
196 if (strcmp(name, "adminmenu") == 0)
198 hTopMenu = INVALID_HANDLE;
202 #define FLAG_STRINGS 14
203 new String:g_FlagNames[FLAG_STRINGS][20] =
221 CustomFlagsToString(String:buffer[], maxlength, flags)
223 decl String:joins[6][6];
226 for (new i=_:Admin_Custom1; i<=_:Admin_Custom6; i++)
230 IntToString(i - _:Admin_Custom1 + 1, joins[total++], 6);
234 ImplodeStrings(joins, total, ",", buffer, maxlength);
239 FlagsToString(String:buffer[], maxlength, flags)
241 decl String:joins[FLAG_STRINGS+1][32];
244 for (new i=0; i<FLAG_STRINGS; i++)
248 strcopy(joins[total++], 32, g_FlagNames[i]);
252 decl String:custom_flags[32];
253 if (CustomFlagsToString(custom_flags, sizeof(custom_flags), flags))
255 Format(joins[total++], 32, "custom(%s)", custom_flags);
258 ImplodeStrings(joins, total, ", ", buffer, maxlength);
261 public Action:Command_Cvar(client, args)
267 ReplyToCommand(client, "[SM] Usage: sm_cvar <cvar|protect> [value]");
271 ReplyToCommand(client, "[SM] Usage: sm_cvar <cvar> [value]");
273 return Plugin_Handled;
276 decl String:cvarname[64];
277 GetCmdArg(1, cvarname, sizeof(cvarname));
279 if (client == 0 && StrEqual(cvarname, "protect"))
283 ReplyToCommand(client, "[SM] Usage: sm_cvar <protect> <cvar>");
284 return Plugin_Handled;
286 GetCmdArg(2, cvarname, sizeof(cvarname));
287 ProtectVar(cvarname);
288 ReplyToCommand(client, "[SM] %t", "Cvar is now protected", cvarname);
289 return Plugin_Handled;
292 new Handle:hndl = FindConVar(cvarname);
293 if (hndl == INVALID_HANDLE)
295 ReplyToCommand(client, "[SM] %t", "Unable to find cvar", cvarname);
296 return Plugin_Handled;
299 new bool:allowed = false;
300 new client_flags = client == 0 ? ADMFLAG_ROOT : GetUserFlagBits(client);
302 if (client_flags & ADMFLAG_ROOT)
308 if (GetConVarFlags(hndl) & FCVAR_PROTECTED)
310 allowed = ((client_flags & ADMFLAG_PASSWORD) == ADMFLAG_PASSWORD);
312 else if (StrEqual(cvarname, "sv_cheats"))
314 allowed = ((client_flags & ADMFLAG_CHEATS) == ADMFLAG_CHEATS);
316 else if (!IsVarProtected(cvarname))
324 ReplyToCommand(client, "[SM] %t", "No access to cvar");
325 return Plugin_Handled;
328 decl String:value[255];
331 GetConVarString(hndl, value, sizeof(value));
333 ReplyToCommand(client, "[SM] %t", "Value of cvar", cvarname, value);
334 return Plugin_Handled;
337 GetCmdArg(2, value, sizeof(value));
339 if ((GetConVarFlags(hndl) & FCVAR_PROTECTED) != FCVAR_PROTECTED)
341 ShowActivity2(client, "[SM] ", "%t", "Cvar changed", cvarname, value);
345 ReplyToCommand(client, "[SM] %t", "Cvar changed", cvarname, value);
348 LogAction(client, -1, "\"%L\" changed cvar (cvar \"%s\") (value \"%s\")", client, cvarname, value);
350 SetConVarString(hndl, value, true);
352 return Plugin_Handled;
355 public Action:Command_Rcon(client, args)
359 ReplyToCommand(client, "[SM] Usage: sm_rcon <args>");
360 return Plugin_Handled;
363 decl String:argstring[255];
364 GetCmdArgString(argstring, sizeof(argstring));
366 LogAction(client, -1, "\"%L\" console command (cmdline \"%s\")", client, argstring);
368 ServerCommand("%s", argstring);
370 return Plugin_Handled;
373 public Action:Command_ReVote(client, args)
377 ReplyToCommand(client, "[SM] %t", "Command is in-game only");
378 return Plugin_Handled;
381 if (!IsVoteInProgress())
383 ReplyToCommand(client, "[SM] %t", "Vote Not In Progress");
384 return Plugin_Handled;
387 if (!IsClientInVotePool(client))
389 ReplyToCommand(client, "[SM] %t", "Cannot participate in vote");
390 return Plugin_Handled;
393 if (!RedrawClientVoteMenu(client))
395 ReplyToCommand(client, "[SM] %t", "Cannot change vote");
398 return Plugin_Handled;