3 * Implements basic admin commands.
4 * This file is part of SourceMod, Copyright (C) 2004-2007 AlliedModders LLC
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27 public Plugin:myinfo =
29 name = "Basic Commands",
30 author = "AlliedModders LLC",
31 description = "Basic Admin Commands",
32 version = SOURCEMOD_VERSION,
33 url = "http://www.sourcemod.net/"
36 public OnPluginStart()
38 LoadTranslations("common.cfg");
39 LoadTranslations("plugin.basecommands.cfg");
40 RegAdminCmd("sm_kick", Command_Kick, ADMFLAG_KICK, "sm_kick <#userid|name> [reason]");
41 RegAdminCmd("sm_map", Command_Map, ADMFLAG_CHANGEMAP, "sm_map <map>");
42 RegAdminCmd("sm_rcon", Command_Rcon, ADMFLAG_RCON, "sm_rcon <args>");
43 RegAdminCmd("sm_cvar", Command_Cvar, ADMFLAG_CONVARS, "sm_cvar <cvar> [value]");
44 RegAdminCmd("sm_execcfg", Command_ExecCfg, ADMFLAG_CONFIG, "sm_execcfg <filename>");
47 public Action:Command_ExecCfg(client, args)
51 ReplyToCommand(client, "[SM] Usage: sm_execcfg <filename>");
52 return Plugin_Handled;
55 new String:path[64] = "cfg/";
56 GetCmdArg(1, path[4], sizeof(path)-4);
58 if (!FileExists(path))
60 ReplyToCommand(client, "[SM] %t", "Config not found", path[4]);
61 return Plugin_Handled;
64 LogMessage("\"%L\" executed config (file \"%s\")", client, path[4]);
65 ShowActivity(client, "%t", "Executed config", path[4]);
67 ServerCommand("exec \"%s\"", path[4]);
69 ReplyToCommand(client, "[SM] %t", "Executed config", path[4]);
71 return Plugin_Handled;
74 public Action:Command_Cvar(client, args)
78 ReplyToCommand(client, "[SM] Usage: sm_cvar <cvar> [value]");
79 return Plugin_Handled;
82 new String:cvarname[33];
83 GetCmdArg(1, cvarname, sizeof(cvarname));
85 new Handle:hndl = FindConVar(cvarname);
86 if (hndl == INVALID_HANDLE)
88 ReplyToCommand(client, "[SM] %t", "Unable to find cvar", cvarname);
89 return Plugin_Handled;
92 new bool:allowed = false;
93 if (GetConVarFlags(hndl) & FCVAR_PROTECTED)
95 /* If they're root, allow anything */
96 if ((GetUserFlagBits(client) & ADMFLAG_ROOT) == ADMFLAG_ROOT)
100 /* If they're not root, and getting sv_password, see if they have ADMFLAG_PASSWORD */
101 else if (StrEqual(cvarname, "sv_password") && (GetUserFlagBits(client) & ADMFLAG_PASSWORD))
106 /* Do a check for the cheat cvar */
107 else if (StrEqual(cvarname, "sv_cheats"))
109 if (GetUserFlagBits(client) & ADMFLAG_CHEATS)
114 /* If we drop down to here, it was a normal cvar. */
122 ReplyToCommand(client, "[SM] %t", "No access to cvar");
123 return Plugin_Handled;
126 decl String:value[255];
129 GetConVarString(hndl, value, sizeof(value));
131 ReplyToCommand(client, "[SM] %t", "Value of cvar", cvarname, value);
132 return Plugin_Handled;
135 GetCmdArg(2, value, sizeof(value));
137 LogMessage("\"%L\" changed cvar (cvar \"%s\") (value \"%s\")", client, cvarname, value);
138 if ((GetConVarFlags(hndl) & FCVAR_PROTECTED) != FCVAR_PROTECTED)
140 ShowActivity(client, "%t", "Cvar changed", cvarname, value);
143 SetConVarString(hndl, value);
144 ReplyToCommand(client, "[SM] %t", "Cvar changed", cvarname, value);
146 return Plugin_Handled;
149 public Action:Command_Rcon(client, args)
153 ReplyToCommand(client, "[SM] Usage: sm_rcon <args>");
154 return Plugin_Handled;
157 decl String:argstring[255];
158 GetCmdArgString(argstring, sizeof(argstring));
160 LogMessage("\"%L\" console command (cmdline \"%s\")", client, argstring);
161 ServerCommand("%s", argstring);
163 return Plugin_Handled;
166 public Action:Command_Map(client, args)
170 ReplyToCommand(client, "[SM] Usage: sm_map <map>");
171 return Plugin_Handled;
175 GetCmdArg(1, map, sizeof(map));
177 if (!IsMapValid(map))
179 ReplyToCommand(client, "[SM] %t", "Map was not found", map);
180 return Plugin_Handled;
183 LogMessage("\"%L\" changed map to \"%s\"", client, map);
184 ShowActivity(client, "%t", "Changing map", map);
185 ReplyToCommand(client, "%t", "Changing map", map);
188 CreateDataTimer(3.0, Timer_ChangeMap, dp);
189 WritePackString(dp, map);
191 return Plugin_Handled;
194 public Action:Timer_ChangeMap(Handle:timer, Handle:dp)
199 ReadPackString(dp, map, sizeof(map));
201 ServerCommand("changelevel \"%s\"", map);
206 public Action:Command_Kick(client, args)
210 ReplyToCommand(client, "[SM] Usage: sm_kick <#userid|name> [reason]");
211 return Plugin_Handled;
215 GetCmdArg(1, arg, sizeof(arg));
218 new numClients = SearchForClients(arg, clients, 2);
222 ReplyToCommand(client, "[SM] %t", "No matching client");
223 return Plugin_Handled;
224 } else if (numClients > 1) {
225 ReplyToCommand(client, "[SM] %t", "More than one client matches", arg);
226 return Plugin_Handled;
229 new userid = GetClientUserId(clients[0]);
232 GetClientName(clients[0], name, sizeof(name));
234 decl String:reason[256];
237 /* Safely null terminate */
240 GetCmdArg(2, reason, sizeof(reason));
243 LogMessage("\"%L\" kicked \"%L\" (reason \"%s\")", client, clients[0], reason);
244 ShowActivity(client, "%t", "Kicked player", name);
248 ServerCommand("kickid %d", userid);
250 ServerCommand("kickid %d \"%s\"", userid, reason);
253 ReplyToCommand(client, "[SM] %t", "Client kicked", name);
255 return Plugin_Handled;