Update CS:GO team score gamedata.
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_resetcvar", Command_ResetCvar, ADMFLAG_CONVARS, "sm_resetcvar <cvar>");
71 RegAdminCmd("sm_execcfg", Command_ExecCfg, ADMFLAG_CONFIG, "sm_execcfg <filename>");
72 RegAdminCmd("sm_who", Command_Who, ADMFLAG_GENERIC, "sm_who [#userid|name]");
73 RegAdminCmd("sm_reloadadmins", Command_ReloadAdmins, ADMFLAG_BAN, "sm_reloadadmins");
74 RegAdminCmd("sm_cancelvote", Command_CancelVote, ADMFLAG_VOTE, "sm_cancelvote");
75 RegConsoleCmd("sm_revote", Command_ReVote);
77 /* Account for late loading */
79 if (LibraryExists("adminmenu") && ((topmenu = GetAdminTopMenu()) != INVALID_HANDLE))
81 OnAdminMenuReady(topmenu);
84 g_MapList = CreateMenu(MenuHandler_ChangeMap, MenuAction_Display);
85 SetMenuTitle(g_MapList, "%T", "Please select a map", LANG_SERVER);
86 SetMenuExitBackButton(g_MapList, true);
88 decl String:mapListPath[PLATFORM_MAX_PATH];
89 BuildPath(Path_SM, mapListPath, sizeof(mapListPath), "configs/adminmenu_maplist.ini");
90 SetMapListCompatBind("sm_map menu", mapListPath);
92 g_ProtectedVars = CreateTrie();
93 ProtectVar("rcon_password");
94 ProtectVar("sm_show_activity");
95 ProtectVar("sm_immunity_mode");
103 public OnConfigsExecuted()
105 LoadMapList(g_MapList);
108 ProtectVar(const String:cvar[])
110 SetTrieValue(g_ProtectedVars, cvar, 1);
113 bool:IsVarProtected(const String:cvar[])
116 return GetTrieValue(g_ProtectedVars, cvar, dummy_value);
119 bool:IsClientAllowedToChangeCvar(client, const String:cvarname[])
121 new Handle:hndl = FindConVar(cvarname);
123 new bool:allowed = false;
124 new client_flags = client == 0 ? ADMFLAG_ROOT : GetUserFlagBits(client);
126 if (client_flags & ADMFLAG_ROOT)
132 if (GetConVarFlags(hndl) & FCVAR_PROTECTED)
134 allowed = ((client_flags & ADMFLAG_PASSWORD) == ADMFLAG_PASSWORD);
136 else if (StrEqual(cvarname, "sv_cheats"))
138 allowed = ((client_flags & ADMFLAG_CHEATS) == ADMFLAG_CHEATS);
140 else if (!IsVarProtected(cvarname))
149 public OnAdminMenuReady(Handle:topmenu)
151 /* Block us from being called twice */
152 if (topmenu == hTopMenu)
157 /* Save the Handle */
160 /* Build the "Player Commands" category */
161 new TopMenuObject:player_commands = FindTopMenuCategory(hTopMenu, ADMINMENU_PLAYERCOMMANDS);
163 if (player_commands != INVALID_TOPMENUOBJECT)
165 AddToTopMenu(hTopMenu,
173 AddToTopMenu(hTopMenu,
182 new TopMenuObject:server_commands = FindTopMenuCategory(hTopMenu, ADMINMENU_SERVERCOMMANDS);
184 if (server_commands != INVALID_TOPMENUOBJECT)
186 AddToTopMenu(hTopMenu,
189 AdminMenu_ReloadAdmins,
194 AddToTopMenu(hTopMenu,
202 AddToTopMenu(hTopMenu,
211 new TopMenuObject:voting_commands = FindTopMenuCategory(hTopMenu, ADMINMENU_VOTINGCOMMANDS);
213 if (voting_commands != INVALID_TOPMENUOBJECT)
215 AddToTopMenu(hTopMenu,
218 AdminMenu_CancelVote,
225 public OnLibraryRemoved(const String:name[])
227 if (strcmp(name, "adminmenu") == 0)
229 hTopMenu = INVALID_HANDLE;
233 #define FLAG_STRINGS 14
234 new String:g_FlagNames[FLAG_STRINGS][20] =
252 CustomFlagsToString(String:buffer[], maxlength, flags)
254 decl String:joins[6][6];
257 for (new i=_:Admin_Custom1; i<=_:Admin_Custom6; i++)
261 IntToString(i - _:Admin_Custom1 + 1, joins[total++], 6);
265 ImplodeStrings(joins, total, ",", buffer, maxlength);
270 FlagsToString(String:buffer[], maxlength, flags)
272 decl String:joins[FLAG_STRINGS+1][32];
275 for (new i=0; i<FLAG_STRINGS; i++)
279 strcopy(joins[total++], 32, g_FlagNames[i]);
283 decl String:custom_flags[32];
284 if (CustomFlagsToString(custom_flags, sizeof(custom_flags), flags))
286 Format(joins[total++], 32, "custom(%s)", custom_flags);
289 ImplodeStrings(joins, total, ", ", buffer, maxlength);
292 public Action:Command_Cvar(client, args)
298 ReplyToCommand(client, "[SM] Usage: sm_cvar <cvar|protect> [value]");
302 ReplyToCommand(client, "[SM] Usage: sm_cvar <cvar> [value]");
304 return Plugin_Handled;
307 decl String:cvarname[64];
308 GetCmdArg(1, cvarname, sizeof(cvarname));
310 if (client == 0 && StrEqual(cvarname, "protect"))
314 ReplyToCommand(client, "[SM] Usage: sm_cvar <protect> <cvar>");
315 return Plugin_Handled;
317 GetCmdArg(2, cvarname, sizeof(cvarname));
318 ProtectVar(cvarname);
319 ReplyToCommand(client, "[SM] %t", "Cvar is now protected", cvarname);
320 return Plugin_Handled;
323 new Handle:hndl = FindConVar(cvarname);
324 if (hndl == INVALID_HANDLE)
326 ReplyToCommand(client, "[SM] %t", "Unable to find cvar", cvarname);
327 return Plugin_Handled;
330 if (!IsClientAllowedToChangeCvar(client, cvarname))
332 ReplyToCommand(client, "[SM] %t", "No access to cvar");
333 return Plugin_Handled;
336 decl String:value[255];
339 GetConVarString(hndl, value, sizeof(value));
341 ReplyToCommand(client, "[SM] %t", "Value of cvar", cvarname, value);
342 return Plugin_Handled;
345 GetCmdArg(2, value, sizeof(value));
347 if ((GetConVarFlags(hndl) & FCVAR_PROTECTED) != FCVAR_PROTECTED)
349 ShowActivity2(client, "[SM] ", "%t", "Cvar changed", cvarname, value);
353 ReplyToCommand(client, "[SM] %t", "Cvar changed", cvarname, value);
356 LogAction(client, -1, "\"%L\" changed cvar (cvar \"%s\") (value \"%s\")", client, cvarname, value);
358 SetConVarString(hndl, value, true);
360 return Plugin_Handled;
363 public Action:Command_ResetCvar(client, args)
367 ReplyToCommand(client, "[SM] Usage: sm_resetcvar <cvar>");
369 return Plugin_Handled;
372 decl String:cvarname[64];
373 GetCmdArg(1, cvarname, sizeof(cvarname));
375 new Handle:hndl = FindConVar(cvarname);
376 if (hndl == INVALID_HANDLE)
378 ReplyToCommand(client, "[SM] %t", "Unable to find cvar", cvarname);
379 return Plugin_Handled;
382 if (!IsClientAllowedToChangeCvar(client, cvarname))
384 ReplyToCommand(client, "[SM] %t", "No access to cvar");
385 return Plugin_Handled;
390 decl String:value[255];
391 GetConVarString(hndl, value, sizeof(value));
393 if ((GetConVarFlags(hndl) & FCVAR_PROTECTED) != FCVAR_PROTECTED)
395 ShowActivity2(client, "[SM] ", "%t", "Cvar changed", cvarname, value);
399 ReplyToCommand(client, "[SM] %t", "Cvar changed", cvarname, value);
402 LogAction(client, -1, "\"%L\" reset cvar (cvar \"%s\") (value \"%s\")", client, cvarname, value);
404 return Plugin_Handled;
407 public Action:Command_Rcon(client, args)
411 ReplyToCommand(client, "[SM] Usage: sm_rcon <args>");
412 return Plugin_Handled;
415 decl String:argstring[255];
416 GetCmdArgString(argstring, sizeof(argstring));
418 LogAction(client, -1, "\"%L\" console command (cmdline \"%s\")", client, argstring);
420 if (client == 0) // They will already see the response in the console.
422 ServerCommand("%s", argstring);
424 new String:responseBuffer[4096];
425 ServerCommandEx(responseBuffer, sizeof(responseBuffer), "%s", argstring);
426 ReplyToCommand(client, responseBuffer);
429 return Plugin_Handled;
432 public Action:Command_ReVote(client, args)
436 ReplyToCommand(client, "[SM] %t", "Command is in-game only");
437 return Plugin_Handled;
440 if (!IsVoteInProgress())
442 ReplyToCommand(client, "[SM] %t", "Vote Not In Progress");
443 return Plugin_Handled;
446 if (!IsClientInVotePool(client))
448 ReplyToCommand(client, "[SM] %t", "Cannot participate in vote");
449 return Plugin_Handled;
452 if (!RedrawClientVoteMenu(client))
454 ReplyToCommand(client, "[SM] %t", "Cannot change vote");
457 return Plugin_Handled;