Added amb<536> requested for using sm_kick without putting quotes around reason.
authorPhong Dang <teame06@gmail.com>
Sun Jul 29 19:20:42 2007 +0000 (2007-07-29)
changeset 1211990912ee1e1e
parent 1210 18e60c8737a2
child 1212 dd92d898ba63
Added amb<536> requested for using sm_kick without putting quotes around reason.
plugins/basecommands.sp
     1.1 --- a/plugins/basecommands.sp	Sun Jul 29 14:56:24 2007 +0000
     1.2 +++ b/plugins/basecommands.sp	Sun Jul 29 19:20:42 2007 +0000
     1.3 @@ -12,7 +12,7 @@
     1.4   * but WITHOUT ANY WARRANTY; without even the implied warranty of
     1.5   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     1.6   * GNU General Public License for more details.
     1.7 - * 
     1.8 + *
     1.9   * You should have received a copy of the GNU General Public License
    1.10   * along with this program; if not, write to the Free Software
    1.11   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    1.12 @@ -24,7 +24,7 @@
    1.13  
    1.14  #include <sourcemod>
    1.15  
    1.16 -public Plugin:myinfo = 
    1.17 +public Plugin:myinfo =
    1.18  {
    1.19  	name = "Basic Commands",
    1.20  	author = "AlliedModders LLC",
    1.21 @@ -40,7 +40,7 @@
    1.22  public OnPluginStart()
    1.23  {
    1.24  	LoadTranslations("common.phrases");
    1.25 -	
    1.26 +
    1.27  	RegAdminCmd("sm_kick", Command_Kick, ADMFLAG_KICK, "sm_kick <#userid|name> [reason]");
    1.28  	RegAdminCmd("sm_map", Command_Map, ADMFLAG_CHANGEMAP, "sm_map <map>");
    1.29  	RegAdminCmd("sm_rcon", Command_Rcon, ADMFLAG_RCON, "sm_rcon <args>");
    1.30 @@ -52,7 +52,7 @@
    1.31  	RegAdminCmd("sm_addban", Command_AddBan, ADMFLAG_RCON, "sm_addban <time> <steamid> [reason]");
    1.32  	RegAdminCmd("sm_banip", Command_BanIp, ADMFLAG_RCON, "sm_banip <time> <ip> [reason]");
    1.33  	RegAdminCmd("sm_reloadadmins", Command_ReloadAdmins, ADMFLAG_BAN, "sm_reloadadmins");
    1.34 -	
    1.35 +
    1.36  	hBanForward = CreateGlobalForward("OnClientBanned", ET_Hook, Param_Cell, Param_Cell, Param_Cell, Param_String);
    1.37  	hAddBanForward = CreateGlobalForward("OnBanAdded", ET_Hook, Param_Cell, Param_String, Param_Cell, Param_String);
    1.38  	hBanRemoved = CreateGlobalForward("OnBanRemoved", ET_Hook, Param_Cell, Param_String);
    1.39 @@ -63,10 +63,10 @@
    1.40  	/* Dump it all! */
    1.41  	DumpAdminCache(AdminCache_Groups, true);
    1.42  	DumpAdminCache(AdminCache_Overrides, true);
    1.43 -	
    1.44 +
    1.45  	LogMessage("\"%L\" refreshed the admin cache.", client);
    1.46  	ReplyToCommand(client, "[SM] %t", "Admin cache refreshed");
    1.47 -	
    1.48 +
    1.49  	return Plugin_Handled;
    1.50  }
    1.51  
    1.52 @@ -77,19 +77,19 @@
    1.53  		ReplyToCommand(client, "[SM] Usage: sm_banip <time> <ip> [reason]");
    1.54  		return Plugin_Handled;
    1.55  	}
    1.56 -	
    1.57 +
    1.58  	decl String:arg[50], String:time[20];
    1.59  	GetCmdArg(1, time, sizeof(time));
    1.60  	GetCmdArg(2, arg, sizeof(arg));
    1.61 -	
    1.62 +
    1.63  	new minutes = StringToInt(time);
    1.64 -	
    1.65 +
    1.66  	decl String:reason[128];
    1.67  	if (args >= 3)
    1.68  	{
    1.69  		GetCmdArg(3, reason, sizeof(reason));
    1.70  	}
    1.71 -	
    1.72 +
    1.73  	new Action:act = Plugin_Continue;
    1.74  	Call_StartForward(hAddBanForward);
    1.75  	Call_PushCell(client);
    1.76 @@ -97,19 +97,19 @@
    1.77  	Call_PushCell(minutes);
    1.78  	Call_PushString(reason);
    1.79  	Call_Finish(act);
    1.80 -	
    1.81 +
    1.82  	if (act < Plugin_Handled)
    1.83  	{
    1.84  		LogMessage("\"%L\" added ban (minutes \"%d\") (ip \"%s\") (reason \"%s\")", client, minutes, arg, reason);
    1.85  		ReplyToCommand(client, "[SM] %t", "Ban added");
    1.86  	}
    1.87 -	
    1.88 +
    1.89  	if (act < Plugin_Stop)
    1.90  	{
    1.91  		ServerCommand("banip %d %s", minutes, arg);
    1.92  		ServerCommand("writeip");
    1.93  	}
    1.94 -	
    1.95 +
    1.96  	return Plugin_Handled;
    1.97  }
    1.98  
    1.99 @@ -120,19 +120,19 @@
   1.100  		ReplyToCommand(client, "[SM] Usage: sm_addban <time> <steamid> [reason]");
   1.101  		return Plugin_Handled;
   1.102  	}
   1.103 -	
   1.104 +
   1.105  	decl String:arg[50], String:time[20];
   1.106  	GetCmdArg(1, time, sizeof(time));
   1.107  	GetCmdArg(2, arg, sizeof(arg));
   1.108 -	
   1.109 +
   1.110  	new minutes = StringToInt(time);
   1.111 -	
   1.112 +
   1.113  	decl String:reason[128];
   1.114  	if (args >= 3)
   1.115  	{
   1.116  		GetCmdArg(3, reason, sizeof(reason));
   1.117  	}
   1.118 -	
   1.119 +
   1.120  	new Action:act = Plugin_Continue;
   1.121  	Call_StartForward(hAddBanForward);
   1.122  	Call_PushCell(client);
   1.123 @@ -140,19 +140,19 @@
   1.124  	Call_PushCell(minutes);
   1.125  	Call_PushString(reason);
   1.126  	Call_Finish(act);
   1.127 -	
   1.128 +
   1.129  	if (act < Plugin_Handled)
   1.130  	{
   1.131  		LogMessage("\"%L\" added ban (minutes \"%d\") (id \"%s\") (reason \"%s\")", client, minutes, arg, reason);
   1.132  		ReplyToCommand(client, "[SM] %t", "Ban added");
   1.133  	}
   1.134 -	
   1.135 +
   1.136  	if (act < Plugin_Stop)
   1.137  	{
   1.138  		ServerCommand("banid %d %s", minutes, arg);
   1.139  		ServerCommand("writeid");
   1.140  	}
   1.141 -	
   1.142 +
   1.143  	return Plugin_Handled;
   1.144  }
   1.145  
   1.146 @@ -163,12 +163,12 @@
   1.147  		ReplyToCommand(client, "[SM] Usage: sm_unban <steamid>");
   1.148  		return Plugin_Handled;
   1.149  	}
   1.150 -	
   1.151 +
   1.152  	decl String:arg[50];
   1.153  	new start=0;
   1.154  	decl String:new_arg[50];
   1.155  	GetCmdArgString(arg, sizeof(arg));
   1.156 -	
   1.157 +
   1.158  	if (strncmp(arg, "STEAM_0:", 8) == 0)
   1.159  	{
   1.160  		start = 8;
   1.161 @@ -176,27 +176,27 @@
   1.162  	{
   1.163  		start = 2;
   1.164  	}
   1.165 -	
   1.166 +
   1.167  	Format(new_arg, sizeof(new_arg), "STEAM_0:%s", arg[start]);
   1.168 -	
   1.169 +
   1.170  	new Action:act = Plugin_Continue;
   1.171  	Call_StartForward(hBanRemoved);
   1.172  	Call_PushCell(client);
   1.173  	Call_PushString(new_arg);
   1.174  	Call_Finish(act);
   1.175 -	
   1.176 +
   1.177  	if (act < Plugin_Handled)
   1.178  	{
   1.179  		LogMessage("\"%L\" removed ban (filter \"%s\")", client, arg[start]);
   1.180  		ReplyToCommand(client, "[SM] %t", "Removed bans matching", arg);
   1.181  	}
   1.182 -	
   1.183 +
   1.184  	if (act < Plugin_Stop)
   1.185  	{
   1.186  		ServerCommand("removeid \"%s\"", arg[start]);
   1.187  		ServerCommand("writeid");
   1.188  	}
   1.189 -	
   1.190 +
   1.191  	return Plugin_Handled;
   1.192  }
   1.193  
   1.194 @@ -207,21 +207,21 @@
   1.195  		ReplyToCommand(client, "[SM] Usage: sm_ban <#userid|name> <minutes|0> [reason]");
   1.196  		return Plugin_Handled;
   1.197  	}
   1.198 -	
   1.199 +
   1.200  	decl String:arg[65];
   1.201  	GetCmdArg(1, arg, sizeof(arg));
   1.202 -	
   1.203 +
   1.204  	new target = FindTarget(client, arg, true);
   1.205  	if (target == -1)
   1.206  	{
   1.207  		return Plugin_Handled;
   1.208  	}
   1.209 -	
   1.210 +
   1.211  	decl String:s_time[12];
   1.212  	GetCmdArg(2, s_time, sizeof(s_time));
   1.213 -	
   1.214 +
   1.215  	new time = StringToInt(s_time);
   1.216 -	
   1.217 +
   1.218  	decl String:reason[128];
   1.219  	if (args >= 3)
   1.220  	{
   1.221 @@ -229,11 +229,11 @@
   1.222  	} else {
   1.223  		reason[0] = '\0';
   1.224  	}
   1.225 -	
   1.226 +
   1.227  	decl String:authid[64];
   1.228  	GetClientAuthString(target, authid, sizeof(authid));
   1.229  	GetClientName(target, arg, sizeof(arg));
   1.230 -	
   1.231 +
   1.232  	/* Fire the ban forward */
   1.233  	new Action:act = Plugin_Continue;
   1.234  	Call_StartForward(hBanForward);
   1.235 @@ -242,7 +242,7 @@
   1.236  	Call_PushCell(time);
   1.237  	Call_PushString(reason);
   1.238  	Call_Finish(act);
   1.239 -	
   1.240 +
   1.241  	if (act < Plugin_Handled)
   1.242  	{
   1.243  		if (!time)
   1.244 @@ -270,16 +270,16 @@
   1.245  		{
   1.246  			strcopy(reason, sizeof(reason), "Banned");
   1.247  		}
   1.248 -		
   1.249 +
   1.250  		ServerCommand("banid %d %s", time, authid);
   1.251  		KickClient(target, "%s", reason);
   1.252 -		
   1.253 +
   1.254  		if (time == 0)
   1.255  		{
   1.256  			ServerCommand("writeid");
   1.257  		}
   1.258  	}
   1.259 -	
   1.260 +
   1.261  	return Plugin_Handled;
   1.262  }
   1.263  
   1.264 @@ -306,7 +306,7 @@
   1.265  {
   1.266  	decl String:joins[FLAG_STRINGS][20];
   1.267  	new total;
   1.268 -	
   1.269 +
   1.270  	for (new i=0; i<FLAG_STRINGS; i++)
   1.271  	{
   1.272  		if (flags & (1<<i))
   1.273 @@ -314,7 +314,7 @@
   1.274  			strcopy(joins[total++], 20, g_FlagNames[i]);
   1.275  		}
   1.276  	}
   1.277 -	
   1.278 +
   1.279  	ImplodeStrings(joins, total, ", ", buffer, maxlength);
   1.280  }
   1.281  
   1.282 @@ -326,13 +326,13 @@
   1.283  		decl String:t_access[16], String:t_name[16];
   1.284  		Format(t_access, sizeof(t_access), "%t", "Access", client);
   1.285  		Format(t_name, sizeof(t_name), "%t", "Name", client);
   1.286 -		
   1.287 +
   1.288  		PrintToConsole(client, "%-24.23s %s", t_name, t_access);
   1.289 -		
   1.290 +
   1.291  		/* List all players */
   1.292  		new maxClients = GetMaxClients();
   1.293  		decl String:flagstring[255];
   1.294 -				
   1.295 +
   1.296  		for (new i=1; i<=maxClients; i++)
   1.297  		{
   1.298  			if (!IsClientInGame(i))
   1.299 @@ -352,21 +352,21 @@
   1.300  			GetClientName(i, name, sizeof(name));
   1.301  			PrintToConsole(client, "%d. %-24.23s %s", i, name, flagstring);
   1.302  		}
   1.303 -		
   1.304 +
   1.305  		if (GetCmdReplySource() == SM_REPLY_TO_CHAT)
   1.306  		{
   1.307  			ReplyToCommand(client, "[SM] %t", "See console for output");
   1.308  		}
   1.309 -		
   1.310 +
   1.311  		return Plugin_Handled;
   1.312  	}
   1.313 -	
   1.314 +
   1.315  	decl String:arg[65];
   1.316  	GetCmdArg(1, arg, sizeof(arg));
   1.317 -	
   1.318 +
   1.319  	new clients[2];
   1.320  	new numClients = SearchForClients(arg, clients, 2);
   1.321 -	
   1.322 +
   1.323  	if (numClients == 0)
   1.324  	{
   1.325  		ReplyToCommand(client, "[SM] %t", "No matching client");
   1.326 @@ -375,7 +375,7 @@
   1.327  		ReplyToCommand(client, "[SM] %t", "More than one client matches", arg);
   1.328  		return Plugin_Handled;
   1.329  	}
   1.330 -	
   1.331 +
   1.332  	new flags = GetUserFlagBits(clients[0]);
   1.333  	decl String:flagstring[255];
   1.334  	if (flags == 0)
   1.335 @@ -386,9 +386,9 @@
   1.336  	} else {
   1.337  		FlagsToString(flagstring, sizeof(flagstring), flags);
   1.338  	}
   1.339 -	
   1.340 +
   1.341  	ReplyToCommand(client, "[SM] %t: %s", "Access", flagstring);
   1.342 -	
   1.343 +
   1.344  	return Plugin_Handled;
   1.345  }
   1.346  
   1.347 @@ -399,22 +399,22 @@
   1.348  		ReplyToCommand(client, "[SM] Usage: sm_execcfg <filename>");
   1.349  		return Plugin_Handled;
   1.350  	}
   1.351 -	
   1.352 +
   1.353  	new String:path[64] = "cfg/";
   1.354  	GetCmdArg(1, path[4], sizeof(path)-4);
   1.355 -	
   1.356 +
   1.357  	if (!FileExists(path))
   1.358  	{
   1.359  		ReplyToCommand(client, "[SM] %t", "Config not found", path[4]);
   1.360  		return Plugin_Handled;
   1.361  	}
   1.362 -	
   1.363 +
   1.364  	ShowActivity(client, "%t", "Executed config", path[4]);
   1.365 -	
   1.366 +
   1.367  	LogMessage("\"%L\" executed config (file \"%s\")", client, path[4]);
   1.368 -		
   1.369 +
   1.370  	ServerCommand("exec \"%s\"", path[4]);
   1.371 -	
   1.372 +
   1.373  	return Plugin_Handled;
   1.374  }
   1.375  
   1.376 @@ -425,17 +425,17 @@
   1.377  		ReplyToCommand(client, "[SM] Usage: sm_cvar <cvar> [value]");
   1.378  		return Plugin_Handled;
   1.379  	}
   1.380 -	
   1.381 +
   1.382  	decl String:cvarname[33];
   1.383  	GetCmdArg(1, cvarname, sizeof(cvarname));
   1.384 -	
   1.385 +
   1.386  	new Handle:hndl = FindConVar(cvarname);
   1.387  	if (hndl == INVALID_HANDLE)
   1.388  	{
   1.389  		ReplyToCommand(client, "[SM] %t", "Unable to find cvar", cvarname);
   1.390  		return Plugin_Handled;
   1.391  	}
   1.392 -	
   1.393 +
   1.394  	new bool:allowed = false;
   1.395  	if (GetConVarFlags(hndl) & FCVAR_PROTECTED)
   1.396  	{
   1.397 @@ -449,7 +449,7 @@
   1.398  		{
   1.399  			allowed = true;
   1.400  		}
   1.401 -	} 
   1.402 +	}
   1.403  	/* Do a check for the cheat cvar */
   1.404  	else if (StrEqual(cvarname, "sv_cheats"))
   1.405  	{
   1.406 @@ -464,35 +464,35 @@
   1.407  	{
   1.408  		allowed = true;
   1.409  	}
   1.410 -	
   1.411 +
   1.412  	if (!allowed)
   1.413  	{
   1.414  		ReplyToCommand(client, "[SM] %t", "No access to cvar");
   1.415  		return Plugin_Handled;
   1.416  	}
   1.417 -	
   1.418 +
   1.419  	decl String:value[255];
   1.420  	if (args < 2)
   1.421  	{
   1.422  		GetConVarString(hndl, value, sizeof(value));
   1.423 -		
   1.424 +
   1.425  		ReplyToCommand(client, "[SM] %t", "Value of cvar", cvarname, value);
   1.426  		return Plugin_Handled;
   1.427  	}
   1.428 -	
   1.429 +
   1.430  	GetCmdArg(2, value, sizeof(value));
   1.431 -	
   1.432 +
   1.433  	if ((GetConVarFlags(hndl) & FCVAR_PROTECTED) != FCVAR_PROTECTED)
   1.434  	{
   1.435  		ShowActivity(client, "%t", "Cvar changed", cvarname, value);
   1.436  	} else {
   1.437  		ReplyToCommand(client, "[SM] %t", "Cvar changed", cvarname, value);
   1.438  	}
   1.439 -	
   1.440 +
   1.441  	LogMessage("\"%L\" changed cvar (cvar \"%s\") (value \"%s\")", client, cvarname, value);
   1.442 -	
   1.443 +
   1.444  	SetConVarString(hndl, value, true);
   1.445 -		
   1.446 +
   1.447  	return Plugin_Handled;
   1.448  }
   1.449  
   1.450 @@ -503,14 +503,14 @@
   1.451  		ReplyToCommand(client, "[SM] Usage: sm_rcon <args>");
   1.452  		return Plugin_Handled;
   1.453  	}
   1.454 -	
   1.455 +
   1.456  	decl String:argstring[255];
   1.457  	GetCmdArgString(argstring, sizeof(argstring));
   1.458 -	
   1.459 +
   1.460  	LogMessage("\"%L\" console command (cmdline \"%s\")", client, argstring);
   1.461 -	
   1.462 +
   1.463  	ServerCommand("%s", argstring);
   1.464 -	
   1.465 +
   1.466  	return Plugin_Handled;
   1.467  }
   1.468  
   1.469 @@ -521,36 +521,36 @@
   1.470  		ReplyToCommand(client, "[SM] Usage: sm_map <map>");
   1.471  		return Plugin_Handled;
   1.472  	}
   1.473 -	
   1.474 +
   1.475  	decl String:map[64];
   1.476  	GetCmdArg(1, map, sizeof(map));
   1.477 -	
   1.478 +
   1.479  	if (!IsMapValid(map))
   1.480  	{
   1.481  		ReplyToCommand(client, "[SM] %t", "Map was not found", map);
   1.482  		return Plugin_Handled;
   1.483  	}
   1.484 -	
   1.485 +
   1.486  	ShowActivity(client, "%t", "Changing map", map);
   1.487 -	
   1.488 +
   1.489  	LogMessage("\"%L\" changed map to \"%s\"", client, map);
   1.490 -	
   1.491 +
   1.492  	new Handle:dp;
   1.493  	CreateDataTimer(3.0, Timer_ChangeMap, dp);
   1.494  	WritePackString(dp, map);
   1.495 -	
   1.496 +
   1.497  	return Plugin_Handled;
   1.498  }
   1.499  
   1.500  public Action:Timer_ChangeMap(Handle:timer, Handle:dp)
   1.501  {
   1.502  	decl String:map[65];
   1.503 -	
   1.504 +
   1.505  	ResetPack(dp);
   1.506  	ReadPackString(dp, map, sizeof(map));
   1.507 -	
   1.508 +
   1.509  	ServerCommand("changelevel \"%s\"", map);
   1.510 -	
   1.511 +
   1.512  	return Plugin_Stop;
   1.513  }
   1.514  
   1.515 @@ -561,35 +561,37 @@
   1.516  		ReplyToCommand(client, "[SM] Usage: sm_kick <#userid|name> [reason]");
   1.517  		return Plugin_Handled;
   1.518  	}
   1.519 -	
   1.520 +
   1.521  	decl String:arg[65];
   1.522  	GetCmdArg(1, arg, sizeof(arg));
   1.523 -	
   1.524 -	
   1.525 +
   1.526  	new target = FindTarget(client, arg);
   1.527  	if (target == -1)
   1.528  	{
   1.529  		return Plugin_Handled;
   1.530  	}
   1.531 -	
   1.532 +
   1.533  	decl String:name[65];
   1.534 -	
   1.535  	GetClientName(target, name, sizeof(name));
   1.536 -	
   1.537 +
   1.538  	decl String:reason[256];
   1.539 +
   1.540 +
   1.541  	if (args < 2)
   1.542  	{
   1.543  		/* Safely null terminate */
   1.544  		reason[0] = '\0';
   1.545  	} else {
   1.546 -		GetCmdArg(2, reason, sizeof(reason));
   1.547 +		GetCmdArgString(reason, sizeof(reason));
   1.548 +		new len = BreakString(reason, arg, sizeof(arg));
   1.549 +
   1.550 +		strcopy(reason, sizeof(reason), reason[len]);
   1.551  	}
   1.552 -	
   1.553 +
   1.554  	ShowActivity(client, "%t", "Kicked player", name);
   1.555 -	
   1.556  	LogMessage("\"%L\" kicked \"%L\" (reason \"%s\")", client, target, reason);
   1.557 -	
   1.558 +
   1.559  	KickClient(target, "%s", reason);
   1.560 -	
   1.561 +
   1.562  	return Plugin_Handled;
   1.563  }