plugins/basecommands.sp
branchsourcemod-1.1.0
changeset 2283 03a67e41afbc
parent 1951 c7b4237fff50
child 2287 017a725c9d17
     1.1 --- a/plugins/basecommands.sp	Fri Mar 28 06:21:34 2008 +0000
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,333 +0,0 @@
     1.4 -/**
     1.5 - * vim: set ts=4 :
     1.6 - * =============================================================================
     1.7 - * SourceMod Basic Commands Plugin
     1.8 - * Implements basic admin commands.
     1.9 - *
    1.10 - * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
    1.11 - * =============================================================================
    1.12 - *
    1.13 - * This program is free software; you can redistribute it and/or modify it under
    1.14 - * the terms of the GNU General Public License, version 3.0, as published by the
    1.15 - * Free Software Foundation.
    1.16 - * 
    1.17 - * This program is distributed in the hope that it will be useful, but WITHOUT
    1.18 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    1.19 - * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    1.20 - * details.
    1.21 - *
    1.22 - * You should have received a copy of the GNU General Public License along with
    1.23 - * this program.  If not, see <http://www.gnu.org/licenses/>.
    1.24 - *
    1.25 - * As a special exception, AlliedModders LLC gives you permission to link the
    1.26 - * code of this program (as well as its derivative 1works) to "Half-Life 2," the
    1.27 - * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    1.28 - * by the Valve Corporation.  You must obey the GNU General Public License in
    1.29 - * all respects for all other code used.  Additionally, AlliedModders LLC grants
    1.30 - * this exception to all derivative works.  AlliedModders LLC defines further
    1.31 - * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    1.32 - * or <http://www.sourcemod.net/license.php>.
    1.33 - *
    1.34 - * Version: $Id$
    1.35 - */
    1.36 -
    1.37 -#pragma semicolon 1
    1.38 -
    1.39 -#include <sourcemod>
    1.40 -#undef REQUIRE_PLUGIN
    1.41 -#include <adminmenu>
    1.42 -
    1.43 -public Plugin:myinfo =
    1.44 -{
    1.45 -	name = "Basic Commands",
    1.46 -	author = "AlliedModders LLC",
    1.47 -	description = "Basic Admin Commands",
    1.48 -	version = SOURCEMOD_VERSION,
    1.49 -	url = "http://www.sourcemod.net/"
    1.50 -};
    1.51 -
    1.52 -new Handle:hTopMenu = INVALID_HANDLE;
    1.53 -
    1.54 -new Handle:g_MapList;
    1.55 -new g_mapFileTime;
    1.56 -
    1.57 -#include "basecommands/kick.sp"
    1.58 -#include "basecommands/reloadadmins.sp"
    1.59 -#include "basecommands/cancelvote.sp"
    1.60 -#include "basecommands/who.sp"
    1.61 -#include "basecommands/map.sp"
    1.62 -#include "basecommands/execcfg.sp"
    1.63 -
    1.64 -public OnPluginStart()
    1.65 -{
    1.66 -	LoadTranslations("common.phrases");
    1.67 -	LoadTranslations("plugin.basecommands");
    1.68 -
    1.69 -	RegAdminCmd("sm_kick", Command_Kick, ADMFLAG_KICK, "sm_kick <#userid|name> [reason]");
    1.70 -	RegAdminCmd("sm_map", Command_Map, ADMFLAG_CHANGEMAP, "sm_map <map>");
    1.71 -	RegAdminCmd("sm_rcon", Command_Rcon, ADMFLAG_RCON, "sm_rcon <args>");
    1.72 -	RegAdminCmd("sm_cvar", Command_Cvar, ADMFLAG_CONVARS, "sm_cvar <cvar> [value]");
    1.73 -	RegAdminCmd("sm_execcfg", Command_ExecCfg, ADMFLAG_CONFIG, "sm_execcfg <filename>");
    1.74 -	RegAdminCmd("sm_who", Command_Who, ADMFLAG_GENERIC, "sm_who [#userid|name]");
    1.75 -	RegAdminCmd("sm_reloadadmins", Command_ReloadAdmins, ADMFLAG_BAN, "sm_reloadadmins");
    1.76 -	RegAdminCmd("sm_cancelvote", Command_CancelVote, ADMFLAG_VOTE, "sm_cancelvote");
    1.77 -	
    1.78 -	/* Account for late loading */
    1.79 -	new Handle:topmenu;
    1.80 -	if (LibraryExists("adminmenu") && ((topmenu = GetAdminTopMenu()) != INVALID_HANDLE))
    1.81 -	{
    1.82 -		OnAdminMenuReady(topmenu);
    1.83 -	}
    1.84 -	
    1.85 -	g_MapList = CreateMenu(MenuHandler_ChangeMap);
    1.86 -	SetMenuTitle(g_MapList, "Please select a map");
    1.87 -	SetMenuExitBackButton(g_MapList, true);
    1.88 -}
    1.89 -
    1.90 -public OnMapStart()
    1.91 -{
    1.92 -	LoadMapList(g_MapList);
    1.93 -	
    1.94 -	ParseConfigs();
    1.95 -}
    1.96 -
    1.97 -public OnAdminMenuReady(Handle:topmenu)
    1.98 -{
    1.99 -	/* Block us from being called twice */
   1.100 -	if (topmenu == hTopMenu)
   1.101 -	{
   1.102 -		return;
   1.103 -	}
   1.104 -	
   1.105 -	/* Save the Handle */
   1.106 -	hTopMenu = topmenu;
   1.107 -	
   1.108 -	/* Build the "Player Commands" category */
   1.109 -	new TopMenuObject:player_commands = FindTopMenuCategory(hTopMenu, ADMINMENU_PLAYERCOMMANDS);
   1.110 -	
   1.111 -	if (player_commands != INVALID_TOPMENUOBJECT)
   1.112 -	{
   1.113 -		AddToTopMenu(hTopMenu, 
   1.114 -			"sm_kick",
   1.115 -			TopMenuObject_Item,
   1.116 -			AdminMenu_Kick,
   1.117 -			player_commands,
   1.118 -			"sm_kick",
   1.119 -			ADMFLAG_KICK);
   1.120 -			
   1.121 -		AddToTopMenu(hTopMenu,
   1.122 -			"sm_who",
   1.123 -			TopMenuObject_Item,
   1.124 -			AdminMenu_Who,
   1.125 -			player_commands,
   1.126 -			"sm_who",
   1.127 -			ADMFLAG_GENERIC);
   1.128 -	}
   1.129 -
   1.130 -	new TopMenuObject:server_commands = FindTopMenuCategory(hTopMenu, ADMINMENU_SERVERCOMMANDS);
   1.131 -
   1.132 -	if (server_commands != INVALID_TOPMENUOBJECT)
   1.133 -	{
   1.134 -		AddToTopMenu(hTopMenu,
   1.135 -			"sm_reloadadmins",
   1.136 -			TopMenuObject_Item,
   1.137 -			AdminMenu_ReloadAdmins,
   1.138 -			server_commands,
   1.139 -			"sm_reloadadmins",
   1.140 -			ADMFLAG_BAN);
   1.141 -			
   1.142 -		AddToTopMenu(hTopMenu,
   1.143 -			"sm_map",
   1.144 -			TopMenuObject_Item,
   1.145 -			AdminMenu_Map,
   1.146 -			server_commands,
   1.147 -			"sm_map",
   1.148 -			ADMFLAG_CHANGEMAP);
   1.149 -			
   1.150 -		AddToTopMenu(hTopMenu,
   1.151 -			"sm_execcfg",
   1.152 -			TopMenuObject_Item,
   1.153 -			AdminMenu_ExecCFG,
   1.154 -			server_commands,
   1.155 -			"sm_execcfg",
   1.156 -			ADMFLAG_CONFIG);		
   1.157 -	}
   1.158 -
   1.159 -	new TopMenuObject:voting_commands = FindTopMenuCategory(hTopMenu, ADMINMENU_VOTINGCOMMANDS);
   1.160 -
   1.161 -	if (voting_commands != INVALID_TOPMENUOBJECT)
   1.162 -	{
   1.163 -		AddToTopMenu(hTopMenu,
   1.164 -			"sm_cancelvote",
   1.165 -			TopMenuObject_Item,
   1.166 -			AdminMenu_CancelVote,
   1.167 -			voting_commands,
   1.168 -			"sm_cancelvote",
   1.169 -			ADMFLAG_VOTE);
   1.170 -	}
   1.171 -}
   1.172 -
   1.173 -public OnLibraryRemoved(const String:name[])
   1.174 -{
   1.175 -	if (strcmp(name, "adminmenu") == 0)
   1.176 -	{
   1.177 -		hTopMenu = INVALID_HANDLE;
   1.178 -	}
   1.179 -}
   1.180 -
   1.181 -#define FLAG_STRINGS		14
   1.182 -new String:g_FlagNames[FLAG_STRINGS][20] =
   1.183 -{
   1.184 -	"res",
   1.185 -	"admin",
   1.186 -	"kick",
   1.187 -	"ban",
   1.188 -	"unban",
   1.189 -	"slay",
   1.190 -	"map",
   1.191 -	"cvars",
   1.192 -	"cfg",
   1.193 -	"chat",
   1.194 -	"vote",
   1.195 -	"pass",
   1.196 -	"rcon",
   1.197 -	"cheat"
   1.198 -};
   1.199 -
   1.200 -CustomFlagsToString(String:buffer[], maxlength, flags)
   1.201 -{
   1.202 -	decl String:joins[6][6];
   1.203 -	new total;
   1.204 -	
   1.205 -	for (new i=_:Admin_Custom1; i<=_:Admin_Custom6; i++)
   1.206 -	{
   1.207 -		if (flags & (1<<i))
   1.208 -		{
   1.209 -			IntToString(i - _:Admin_Custom1 + 1, joins[total++], 6);
   1.210 -		}
   1.211 -	}
   1.212 -	
   1.213 -	ImplodeStrings(joins, total, ",", buffer, maxlength);
   1.214 -	
   1.215 -	return total;
   1.216 -}
   1.217 -
   1.218 -FlagsToString(String:buffer[], maxlength, flags)
   1.219 -{
   1.220 -	decl String:joins[FLAG_STRINGS+1][32];
   1.221 -	new total;
   1.222 -
   1.223 -	for (new i=0; i<FLAG_STRINGS; i++)
   1.224 -	{
   1.225 -		if (flags & (1<<i))
   1.226 -		{
   1.227 -			strcopy(joins[total++], 32, g_FlagNames[i]);
   1.228 -		}
   1.229 -	}
   1.230 -	
   1.231 -	decl String:custom_flags[32];
   1.232 -	if (CustomFlagsToString(custom_flags, sizeof(custom_flags), flags))
   1.233 -	{
   1.234 -		Format(joins[total++], 32, "custom(%s)", custom_flags);
   1.235 -	}
   1.236 -
   1.237 -	ImplodeStrings(joins, total, ", ", buffer, maxlength);
   1.238 -}
   1.239 -
   1.240 -public Action:Command_Cvar(client, args)
   1.241 -{
   1.242 -	if (args < 1)
   1.243 -	{
   1.244 -		ReplyToCommand(client, "[SM] Usage: sm_cvar <cvar> [value]");
   1.245 -		return Plugin_Handled;
   1.246 -	}
   1.247 -
   1.248 -	decl String:cvarname[64];
   1.249 -	GetCmdArg(1, cvarname, sizeof(cvarname));
   1.250 -
   1.251 -	new Handle:hndl = FindConVar(cvarname);
   1.252 -	if (hndl == INVALID_HANDLE)
   1.253 -	{
   1.254 -		ReplyToCommand(client, "[SM] %t", "Unable to find cvar", cvarname);
   1.255 -		return Plugin_Handled;
   1.256 -	}
   1.257 -
   1.258 -	new bool:allowed = false;
   1.259 -	if (GetConVarFlags(hndl) & FCVAR_PROTECTED)
   1.260 -	{
   1.261 -		/* If they're root, allow anything */
   1.262 -		if ((GetUserFlagBits(client) & ADMFLAG_ROOT) == ADMFLAG_ROOT)
   1.263 -		{
   1.264 -			allowed = true;
   1.265 -		}
   1.266 -		/* If they're not root, and getting sv_password, see if they have ADMFLAG_PASSWORD */
   1.267 -		else if (StrEqual(cvarname, "sv_password") && (GetUserFlagBits(client) & ADMFLAG_PASSWORD))
   1.268 -		{
   1.269 -			allowed = true;
   1.270 -		}
   1.271 -	}
   1.272 -	/* Do a check for the cheat cvar */
   1.273 -	else if (StrEqual(cvarname, "sv_cheats"))
   1.274 -	{
   1.275 -		if (GetUserFlagBits(client) & ADMFLAG_CHEATS
   1.276 -			|| GetUserFlagBits(client) & ADMFLAG_ROOT)
   1.277 -		{
   1.278 -			allowed = true;
   1.279 -		}
   1.280 -	}
   1.281 -	/* If we drop down to here, it was a normal cvar. */
   1.282 -	else
   1.283 -	{
   1.284 -		allowed = true;
   1.285 -	}
   1.286 -
   1.287 -	if (!allowed)
   1.288 -	{
   1.289 -		ReplyToCommand(client, "[SM] %t", "No access to cvar");
   1.290 -		return Plugin_Handled;
   1.291 -	}
   1.292 -
   1.293 -	decl String:value[255];
   1.294 -	if (args < 2)
   1.295 -	{
   1.296 -		GetConVarString(hndl, value, sizeof(value));
   1.297 -
   1.298 -		ReplyToCommand(client, "[SM] %t", "Value of cvar", cvarname, value);
   1.299 -		return Plugin_Handled;
   1.300 -	}
   1.301 -
   1.302 -	GetCmdArg(2, value, sizeof(value));
   1.303 -
   1.304 -	if ((GetConVarFlags(hndl) & FCVAR_PROTECTED) != FCVAR_PROTECTED)
   1.305 -	{
   1.306 -		ShowActivity2(client, "[SM] ", "%t", "Cvar changed", cvarname, value);
   1.307 -	}
   1.308 -	else
   1.309 -	{
   1.310 -		ReplyToCommand(client, "[SM] %t", "Cvar changed", cvarname, value);
   1.311 -	}
   1.312 -
   1.313 -	LogAction(client, -1, "\"%L\" changed cvar (cvar \"%s\") (value \"%s\")", client, cvarname, value);
   1.314 -
   1.315 -	SetConVarString(hndl, value, true);
   1.316 -
   1.317 -	return Plugin_Handled;
   1.318 -}
   1.319 -
   1.320 -public Action:Command_Rcon(client, args)
   1.321 -{
   1.322 -	if (args < 1)
   1.323 -	{
   1.324 -		ReplyToCommand(client, "[SM] Usage: sm_rcon <args>");
   1.325 -		return Plugin_Handled;
   1.326 -	}
   1.327 -
   1.328 -	decl String:argstring[255];
   1.329 -	GetCmdArgString(argstring, sizeof(argstring));
   1.330 -
   1.331 -	LogAction(client, -1, "\"%L\" console command (cmdline \"%s\")", client, argstring);
   1.332 -
   1.333 -	ServerCommand("%s", argstring);
   1.334 -
   1.335 -	return Plugin_Handled;
   1.336 -}