plugins/basecommands.sp
author David Anderson <dvander@alliedmods.net>
Thu Jun 07 21:36:24 2007 +0000 (2007-06-07)
changeset 918 d498a233accf
parent 917 2a9cf4e74620
child 920 d66cf93ef5e3
permissions -rw-r--r--
added sm_rcon
     1 /**
     2  * basecommands.sp
     3  * Implements basic admin commands.
     4  * This file is part of SourceMod, Copyright (C) 2004-2007 AlliedModders LLC
     5  *
     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.
    10  *
    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.
    15  * 
    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.
    19  *
    20  * Version: $Id$
    21  */
    22 
    23 #include <sourcemod>
    24 
    25 #pragma semicolon 1
    26 
    27 public Plugin:myinfo = 
    28 {
    29 	name = "Basic Commands",
    30 	author = "AlliedModders LLC",
    31 	description = "Basic Admin Commands",
    32 	version = SOURCEMOD_VERSION,
    33 	url = "http://www.sourcemod.net/"
    34 };
    35 
    36 public OnPluginStart()
    37 {
    38 	LoadTranslations("common.cfg");
    39 	RegAdminCmd("sm_kick", Command_Kick, ADMFLAG_KICK, "sm_kick <#userid|name> [reason]");
    40 	RegAdminCmd("sm_map", Command_Map, ADMFLAG_CHANGEMAP, "sm_map <map>");
    41 	RegAdminCmd("sm_rcon", Command_Rcon, ADMFLAG_RCON, "sm_rcon <args>");
    42 }
    43 
    44 public Action:Command_Rcon(client, args)
    45 {
    46 	if (args < 1)
    47 	{
    48 		ReplyToCommand(client, "[SM] Usage: sm_rcon <args>");
    49 		return Plugin_Handled;
    50 	}
    51 	
    52 	decl String:argstring[255];
    53 	GetCmdArgString(argstring, sizeof(argstring));
    54 	
    55 	LogMessage("\"%L\" console command (cmdline \"%s\")", client, argstring);
    56 	ServerCommand("%s", argstring);
    57 	
    58 	return Plugin_Handled;
    59 }
    60 
    61 public Action:Command_Map(client, args)
    62 {
    63 	if (args < 1)
    64 	{
    65 		ReplyToCommand(client, "[SM] Usage: sm_map <map>");
    66 		return Plugin_Handled;
    67 	}
    68 	
    69 	new String:map[64];
    70 	GetCmdArg(1, map, sizeof(map));
    71 	
    72 	if (!IsMapValid(map))
    73 	{
    74 		ReplyToCommand(client, "[SM] %t", "Map was not found", map);
    75 		return Plugin_Handled;
    76 	}
    77 	
    78 	LogMessage("\"%L\" changed map to \"%s\"", client, map);
    79 	ShowActivity(client, "%t", "Changing map", map);
    80 	ReplyToCommand(client, "%t", "Changing map", map);
    81 	
    82 	new Handle:dp;
    83 	CreateDataTimer(3.0, Timer_ChangeMap, dp);
    84 	WritePackString(dp, map);
    85 	
    86 	return Plugin_Handled;
    87 }
    88 
    89 public Action:Timer_ChangeMap(Handle:timer, Handle:dp)
    90 {
    91 	new String:map[65];
    92 	
    93 	ResetPack(dp);
    94 	ReadPackString(dp, map, sizeof(map));
    95 	
    96 	ServerCommand("changelevel \"%s\"", map);
    97 	
    98 	return Plugin_Stop;
    99 }
   100 
   101 public Action:Command_Kick(client, args)
   102 {
   103 	if (args < 1)
   104 	{
   105 		ReplyToCommand(client, "[SM] Usage: sm_kick <#userid|name> [reason]");
   106 		return Plugin_Handled;
   107 	}
   108 	
   109 	new String:arg[65];
   110 	GetCmdArg(1, arg, sizeof(arg));
   111 	
   112 	new clients[2];
   113 	new numClients = SearchForClients(arg, clients, 2);
   114 	
   115 	if (numClients == 0)
   116 	{
   117 		ReplyToCommand(client, "[SM] %t", "No matching client");
   118 		return Plugin_Handled;
   119 	} else if (numClients > 1) {
   120 		ReplyToCommand(client, "[SM] %t", "More than one client matches", arg);
   121 		return Plugin_Handled;
   122 	}
   123 	
   124 	new userid = GetClientUserId(clients[0]);
   125 	new String:name[65];
   126 	
   127 	GetClientName(clients[0], name, sizeof(name));
   128 	
   129 	decl String:reason[256];
   130 	if (args < 2)
   131 	{
   132 		/* Safely null terminate */
   133 		reason[0] = '\0';
   134 	} else {
   135 		GetCmdArg(2, reason, sizeof(reason));
   136 	}
   137 	
   138 	LogMessage("\"%L\" kicked \"%L\" (reason \"%s\")", client, clients[0], reason);
   139 	ShowActivity(client, "%t", "Kicked player", name);
   140 	
   141 	if (args < 2)
   142 	{
   143 		ServerCommand("kickid %d", userid);
   144 	} else {
   145 		ServerCommand("kickid %d \"%s\"", userid, reason);
   146 	}
   147 	
   148 	ReplyToCommand(client, "[SM] %t", "Client kicked", name);
   149 	
   150 	return Plugin_Handled;
   151 }