commited overhaul of a large number of commands and phrases, which largely included basecomm. also re-implemented FindTarget() with ProcessTargetString()

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401633
This commit is contained in:
David Anderson 2007-10-22 02:54:27 +00:00
parent f3e7bf4a16
commit b4896ecada
5 changed files with 279 additions and 164 deletions

View File

@ -116,26 +116,42 @@ public Action:Command_BanIp(client, args)
return Plugin_Handled; return Plugin_Handled;
} }
new clients[1]; decl String:target_name[MAX_TARGET_LENGTH];
new numClients = SearchForClients(arg, clients, 1); decl target_list[1], bool:tn_is_ml;
new found_client = -1;
if (ProcessTargetString(
arg,
client,
target_list,
1,
COMMAND_FILTER_CONNECTED|COMMAND_FILTER_NO_MULTI,
target_name,
sizeof(target_name),
tn_is_ml) > 0)
{
found_client = target_list[0];
}
new bool:has_rcon; new bool:has_rcon;
if (client == 0 || (client == 1 && !IsDedicatedServer())) if (client == 0 || (client == 1 && !IsDedicatedServer()))
{ {
has_rcon = true; has_rcon = true;
} else { }
else
{
new AdminId:id = GetUserAdmin(client); new AdminId:id = GetUserAdmin(client);
has_rcon = (id == INVALID_ADMIN_ID) ? false : GetAdminFlag(id, Admin_RCON); has_rcon = (id == INVALID_ADMIN_ID) ? false : GetAdminFlag(id, Admin_RCON);
} }
new hit_client = -1; new hit_client = -1;
if (numClients == 1 if (found_client != -1
&& !IsFakeClient(clients[0]) && !IsFakeClient(found_client)
&& (has_rcon || CanUserTarget(client, clients[0]))) && (has_rcon || CanUserTarget(client, found_client)))
{ {
GetClientIP(clients[0], arg, sizeof(arg)); GetClientIP(found_client, arg, sizeof(arg));
hit_client = clients[0]; hit_client = found_client;
} }
if (hit_client == -1 && !has_rcon) if (hit_client == -1 && !has_rcon)
@ -146,7 +162,7 @@ public Action:Command_BanIp(client, args)
new minutes = StringToInt(time); new minutes = StringToInt(time);
decl String:reason[128]; new String:reason[128];
if (args >= 3) if (args >= 3)
{ {
GetCmdArg(3, reason, sizeof(reason)); GetCmdArg(3, reason, sizeof(reason));
@ -159,6 +175,9 @@ public Action:Command_BanIp(client, args)
minutes, minutes,
arg, arg,
reason); reason);
ReplyToCommand(client, "[SM] %t", "Ban added");
BanIdentity(arg, BanIdentity(arg,
minutes, minutes,
BANFLAG_IP, BANFLAG_IP,
@ -166,7 +185,10 @@ public Action:Command_BanIp(client, args)
"sm_banip", "sm_banip",
client); client);
ReplyToCommand(client, "[SM] %t", "Ban added"); if (hit_client != -1)
{
KickClient(hit_client, "Banned: %s", reason);
}
return Plugin_Handled; return Plugin_Handled;
} }

View File

@ -10,7 +10,7 @@
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* * 1
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more

View File

@ -139,45 +139,54 @@ public MenuHandler_GagTypes(Handle:menu, MenuAction:action, param1, param2)
GetMenuItem(menu, param2, info, sizeof(info)); GetMenuItem(menu, param2, info, sizeof(info));
type = CommType:StringToInt(info); type = CommType:StringToInt(info);
decl String:name[MAX_NAME_LENGTH];
GetClientName(g_GagTarget[param1], name, sizeof(name));
switch (type) switch (type)
{ {
case CommType_Mute: PerformMute(param1, g_GagTarget[param1]); case CommType_Mute:
case CommType_UnMute: PerformUnMute(param1, g_GagTarget[param1]); {
case CommType_Gag: PerformGag(param1, g_GagTarget[param1]); PerformMute(param1, g_GagTarget[param1]);
case CommType_UnGag: PerformUnGag(param1, g_GagTarget[param1]); ShowActivity2(param1, "[SM] ", "%t", "Muted target", "_s", name);
case CommType_Silence: PerformSilence(param1, g_GagTarget[param1]); }
case CommType_UnSilence: PerformUnSilence(param1, g_GagTarget[param1]); case CommType_UnMute:
{
PerformUnMute(param1, g_GagTarget[param1]);
ShowActivity2(param1, "[SM] ", "%t", "Unmuted target", "_s", name);
}
case CommType_Gag:
{
PerformGag(param1, g_GagTarget[param1]);
ShowActivity2(param1, "[SM] ", "%t", "Gagged target", "_s", name);
}
case CommType_UnGag:
{
PerformUnGag(param1, g_GagTarget[param1]);
ShowActivity2(param1, "[SM] ", "%t", "Ungagged target", "_s", name);
}
case CommType_Silence:
{
PerformSilence(param1, g_GagTarget[param1]);
ShowActivity2(param1, "[SM] ", "%t", "Silenced target", "_s", name);
}
case CommType_UnSilence:
{
PerformUnSilence(param1, g_GagTarget[param1]);
ShowActivity2(param1, "[SM] ", "%t", "Unsilenced target", "_s", name);
}
} }
} }
} }
PerformMute(client, target) PerformMute(client, target)
{ {
if (g_Muted[target])
{
ReplyToCommand(client, "%t", "Already Muted");
return;
}
g_Muted[target] = true; g_Muted[target] = true;
SetClientListeningFlags(target, VOICE_MUTED); SetClientListeningFlags(target, VOICE_MUTED);
decl String:name[64];
GetClientName(target, name, sizeof(name));
ShowActivity(client, "%t", "Player Muted", name);
ReplyToCommand(client, "%t", "Player Muted", name);
LogAction(client, target, "\"%L\" muted \"%L\"", client, target); LogAction(client, target, "\"%L\" muted \"%L\"", client, target);
} }
PerformUnMute(client, target) PerformUnMute(client, target)
{ {
if (!g_Muted[target])
{
ReplyToCommand(client, "%t", "Player Not Muted");
return;
}
g_Muted[target] = false; g_Muted[target] = false;
if (GetConVarInt(g_Cvar_Deadtalk) == 1 && !IsPlayerAlive(target)) if (GetConVarInt(g_Cvar_Deadtalk) == 1 && !IsPlayerAlive(target))
{ {
@ -192,99 +201,42 @@ PerformUnMute(client, target)
SetClientListeningFlags(target, VOICE_NORMAL); SetClientListeningFlags(target, VOICE_NORMAL);
} }
decl String:name[64];
GetClientName(target, name, sizeof(name));
ShowActivity(client, "%t", "Player Unmuted", name);
ReplyToCommand(client, "%t", "Player Unmuted", name);
LogAction(client, target, "\"%L\" unmuted \"%L\"", client, target); LogAction(client, target, "\"%L\" unmuted \"%L\"", client, target);
} }
PerformGag(client, target) PerformGag(client, target)
{ {
if (g_Gagged[target])
{
ReplyToCommand(client, "%t", "Already Gagged");
return;
}
g_Gagged[target] = true; g_Gagged[target] = true;
decl String:name[64];
GetClientName(target, name, sizeof(name));
ShowActivity(client, "%t", "Player Gagged", name);
ReplyToCommand(client, "%t", "Player Gagged", name);
LogAction(client, target, "\"%L\" gagged \"%L\"", client, target); LogAction(client, target, "\"%L\" gagged \"%L\"", client, target);
} }
PerformUnGag(client, target) PerformUnGag(client, target)
{ {
if (!g_Gagged[target])
{
ReplyToCommand(client, "%t", "Player Not Gagged");
return;
}
g_Gagged[target] = false; g_Gagged[target] = false;
decl String:name[64];
GetClientName(target, name, sizeof(name));
ShowActivity(client, "%t", "Player Ungagged", name);
ReplyToCommand(client, "%t", "Player Ungagged", name);
LogAction(client, target, "\"%L\" ungagged \"%L\"", client, target); LogAction(client, target, "\"%L\" ungagged \"%L\"", client, target);
} }
PerformSilence(client, target) PerformSilence(client, target)
{ {
if (g_Gagged[target] && g_Muted[target])
{
ReplyToCommand(client, "%t", "Already Silenced");
return;
}
decl String:name[64];
GetClientName(target, name, sizeof(name));
if (!g_Gagged[target]) if (!g_Gagged[target])
{ {
g_Gagged[target] = true; g_Gagged[target] = true;
ShowActivity(client, "%t", "Player Gagged", name);
ReplyToCommand(client, "%t", "Player Gagged", name);
LogAction(client, target, "\"%L\" gagged \"%L\"", client, target);
} }
if (!g_Muted[target]) if (!g_Muted[target])
{ {
g_Muted[target] = true; g_Muted[target] = true;
SetClientListeningFlags(target, VOICE_MUTED); SetClientListeningFlags(target, VOICE_MUTED);
ShowActivity(client, "%t", "Player Muted", name);
ReplyToCommand(client, "%t", "Player Muted", name);
LogAction(client, target, "\"%L\" muted \"%L\"", client, target);
} }
LogAction(client, target, "\"%L\" silenced \"%L\"", client, target);
} }
PerformUnSilence(client, target) PerformUnSilence(client, target)
{ {
if (!g_Gagged[target] && !g_Muted[target])
{
ReplyToCommand(client, "%t", "Player Not Silenced");
return;
}
decl String:name[64];
GetClientName(target, name, sizeof(name));
if (g_Gagged[target]) if (g_Gagged[target])
{ {
g_Gagged[target] = false; g_Gagged[target] = false;
ShowActivity(client, "%t", "Player Ungagged", name);
ReplyToCommand(client, "%t", "Player Ungagged", name);
LogAction(client, target, "\"%L\" ungagged \"%L\"", client, target);
} }
if (g_Muted[target]) if (g_Muted[target])
@ -303,11 +255,9 @@ PerformUnSilence(client, target)
{ {
SetClientListeningFlags(target, VOICE_NORMAL); SetClientListeningFlags(target, VOICE_NORMAL);
} }
ShowActivity(client, "%t", "Player Unmuted", name);
ReplyToCommand(client, "%t", "Player Unmuted", name);
LogAction(client, target, "\"%L\" unmuted \"%L\"", client, target);
} }
LogAction(client, target, "\"%L\" unsilenced \"%L\"", client, target);
} }
public Action:Command_Mute(client, args) public Action:Command_Mute(client, args)
@ -321,13 +271,38 @@ public Action:Command_Mute(client, args)
decl String:arg[64]; decl String:arg[64];
GetCmdArg(1, arg, sizeof(arg)); GetCmdArg(1, arg, sizeof(arg));
new target = FindTarget(client, arg); decl String:target_name[MAX_TARGET_LENGTH];
if (target == -1) decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
if ((target_count = ProcessTargetString(
arg,
client,
target_list,
MAXPLAYERS,
0,
target_name,
sizeof(target_name),
tn_is_ml)) <= 0)
{ {
ReplyToTargetError(client, target_count);
return Plugin_Handled; return Plugin_Handled;
} }
for (new i = 0; i < target_count; i++)
{
new target = target_list[i];
PerformMute(client, target); PerformMute(client, target);
}
if (tn_is_ml)
{
ShowActivity2(client, "[SM] ", "%t", "Muted target", target_name);
}
else
{
ShowActivity2(client, "[SM] ", "%t", "Muted target", "_s", target_name);
}
return Plugin_Handled; return Plugin_Handled;
} }
@ -343,13 +318,38 @@ public Action:Command_Gag(client, args)
decl String:arg[64]; decl String:arg[64];
GetCmdArg(1, arg, sizeof(arg)); GetCmdArg(1, arg, sizeof(arg));
new target = FindTarget(client, arg); decl String:target_name[MAX_TARGET_LENGTH];
if (target == -1) decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
if ((target_count = ProcessTargetString(
arg,
client,
target_list,
MAXPLAYERS,
0,
target_name,
sizeof(target_name),
tn_is_ml)) <= 0)
{ {
ReplyToTargetError(client, target_count);
return Plugin_Handled; return Plugin_Handled;
} }
for (new i = 0; i < target_count; i++)
{
new target = target_list[i];
PerformGag(client, target); PerformGag(client, target);
}
if (tn_is_ml)
{
ShowActivity2(client, "[SM] ", "%t", "Gagged target", target_name);
}
else
{
ShowActivity2(client, "[SM] ", "%t", "Gagged target", "_s", target_name);
}
return Plugin_Handled; return Plugin_Handled;
} }
@ -365,13 +365,38 @@ public Action:Command_Silence(client, args)
decl String:arg[64]; decl String:arg[64];
GetCmdArg(1, arg, sizeof(arg)); GetCmdArg(1, arg, sizeof(arg));
new target = FindTarget(client, arg); decl String:target_name[MAX_TARGET_LENGTH];
if (target == -1) decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
if ((target_count = ProcessTargetString(
arg,
client,
target_list,
MAXPLAYERS,
0,
target_name,
sizeof(target_name),
tn_is_ml)) <= 0)
{ {
ReplyToTargetError(client, target_count);
return Plugin_Handled; return Plugin_Handled;
} }
for (new i = 0; i < target_count; i++)
{
new target = target_list[i];
PerformSilence(client, target); PerformSilence(client, target);
}
if (tn_is_ml)
{
ShowActivity2(client, "[SM] ", "%t", "Silenced target", target_name);
}
else
{
ShowActivity2(client, "[SM] ", "%t", "Silenced target", "_s", target_name);
}
return Plugin_Handled; return Plugin_Handled;
} }
@ -387,13 +412,43 @@ public Action:Command_Unmute(client, args)
decl String:arg[64]; decl String:arg[64];
GetCmdArg(1, arg, sizeof(arg)); GetCmdArg(1, arg, sizeof(arg));
new target = FindTarget(client, arg); decl String:target_name[MAX_TARGET_LENGTH];
if (target == -1) decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
if ((target_count = ProcessTargetString(
arg,
client,
target_list,
MAXPLAYERS,
0,
target_name,
sizeof(target_name),
tn_is_ml)) <= 0)
{ {
ReplyToTargetError(client, target_count);
return Plugin_Handled; return Plugin_Handled;
} }
for (new i = 0; i < target_count; i++)
{
new target = target_list[i];
if (g_Muted[target])
{
continue;
}
PerformUnMute(client, target); PerformUnMute(client, target);
}
if (tn_is_ml)
{
ShowActivity2(client, "[SM] ", "%t", "Unmuted target", target_name);
}
else
{
ShowActivity2(client, "[SM] ", "%t", "Unmuted target", "_s", target_name);
}
return Plugin_Handled; return Plugin_Handled;
} }
@ -409,13 +464,38 @@ public Action:Command_Ungag(client, args)
decl String:arg[64]; decl String:arg[64];
GetCmdArg(1, arg, sizeof(arg)); GetCmdArg(1, arg, sizeof(arg));
new target = FindTarget(client, arg); decl String:target_name[MAX_TARGET_LENGTH];
if (target == -1) decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
if ((target_count = ProcessTargetString(
arg,
client,
target_list,
MAXPLAYERS,
0,
target_name,
sizeof(target_name),
tn_is_ml)) <= 0)
{ {
ReplyToTargetError(client, target_count);
return Plugin_Handled; return Plugin_Handled;
} }
for (new i = 0; i < target_count; i++)
{
new target = target_list[i];
PerformUnGag(client, target); PerformUnGag(client, target);
}
if (tn_is_ml)
{
ShowActivity2(client, "[SM] ", "%t", "Ungagged target", target_name);
}
else
{
ShowActivity2(client, "[SM] ", "%t", "Ungagged target", "_s", target_name);
}
return Plugin_Handled; return Plugin_Handled;
} }
@ -431,13 +511,38 @@ public Action:Command_Unsilence(client, args)
decl String:arg[64]; decl String:arg[64];
GetCmdArg(1, arg, sizeof(arg)); GetCmdArg(1, arg, sizeof(arg));
new target = FindTarget(client, arg); decl String:target_name[MAX_TARGET_LENGTH];
if (target == -1) decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
if ((target_count = ProcessTargetString(
arg,
client,
target_list,
MAXPLAYERS,
0,
target_name,
sizeof(target_name),
tn_is_ml)) <= 0)
{ {
ReplyToTargetError(client, target_count);
return Plugin_Handled; return Plugin_Handled;
} }
for (new i = 0; i < target_count; i++)
{
new target = target_list[i];
PerformUnSilence(client, target); PerformUnSilence(client, target);
}
if (tn_is_ml)
{
ShowActivity2(client, "[SM] ", "%t", "Unsilenced target", target_name);
}
else
{
ShowActivity2(client, "[SM] ", "%t", "Unsilenced target", "_s", target_name);
}
return Plugin_Handled; return Plugin_Handled;
} }

View File

@ -183,21 +183,13 @@ public Action:Command_Who(client, args)
decl String:arg[65]; decl String:arg[65];
GetCmdArg(1, arg, sizeof(arg)); GetCmdArg(1, arg, sizeof(arg));
new clients[2]; new target = FindTarget(client, arg);
new numClients = SearchForClients(arg, clients, 2); if (target == -1)
if (numClients == 0)
{ {
ReplyToCommand(client, "[SM] %t", "No matching client");
return Plugin_Handled;
}
else if (numClients > 1)
{
ReplyToCommand(client, "[SM] %t", "More than one client matches", arg);
return Plugin_Handled; return Plugin_Handled;
} }
PerformWho(client, clients[0], GetCmdReplySource()); PerformWho(client, target, GetCmdReplySource());
return Plugin_Handled; return Plugin_Handled;
} }

View File

@ -94,17 +94,9 @@ stock Handle:FindPluginByFile(const String:filename[])
} }
/** /**
* Searches for clients that match an input string. * @deprecated Use FindTarget() or ProcessTargetString().
*
* Allowed patterns:
* 1) #<userid> or #<exact name>
* 2) <partial or full name>
*
* @param pattern Pattern to search for.
* @param clients Array to store matching clients in.
* @param maxClients Maximum clients in the array.
* @return Number of clients found.
*/ */
#pragma deprecated Use FindTarget() or ProcessTargetString()
stock SearchForClients(const String:pattern[], clients[], maxClients) stock SearchForClients(const String:pattern[], clients[], maxClients)
{ {
new maxclients = GetMaxClients(); new maxclients = GetMaxClients();
@ -166,7 +158,7 @@ stock SearchForClients(const String:pattern[], clients[], maxClients)
} }
/** /**
* Wraps SearchForClients and handles producing error messages for * Wraps ProcessTargetString() and handles producing error messages for
* bad targets. * bad targets.
* *
* @param client Client who issued command * @param client Client who issued command
@ -177,34 +169,38 @@ stock SearchForClients(const String:pattern[], clients[], maxClients)
*/ */
stock FindTarget(client, const String:target[], bool:nobots = false, bool:immunity = true) stock FindTarget(client, const String:target[], bool:nobots = false, bool:immunity = true)
{ {
new clients[2]; decl String:target_name[MAX_TARGET_LENGTH];
new numClients = SearchForClients(target, clients, 2); decl target_list[1], target_count, bool:tn_is_ml;
if (numClients == 0) new flags = COMMAND_FILTER_NO_MULTI;
if (nobots)
{ {
ReplyToCommand(client, "[SM] %t", "No matching client"); flags |= COMMAND_FILTER_NO_BOTS;
return -1;
} }
else if (numClients > 1) if (!immunity)
{ {
ReplyToCommand(client, "[SM] %t", "More than one client matches", target); flags |= COMMAND_FILTER_NO_IMMUNITY;
return -1;
}
else if (immunity && !CanUserTarget(client, clients[0]))
{
ReplyToCommand(client, "[SM] %t", "Unable to target");
return -1;
}
else if (nobots && IsFakeClient(clients[0]))
{
ReplyToCommand(client, "[SM] %t", "Cannot target bot");
return -1;
} }
return clients[0]; if ((target_count = ProcessTargetString(
target,
client,
target_list,
1,
flags,
target_name,
sizeof(target_name),
tn_is_ml)) > 0)
{
return target_list[0];
}
else
{
ReplyToTargetError(client, target_count);
return -1;
}
} }
/** /**
* Loads a specified array with maps. The maps will be either loaded from mapcyclefile, or if supplied * Loads a specified array with maps. The maps will be either loaded from mapcyclefile, or if supplied
* a cvar containing a file name. If the file in the cvar is bad, it will use mapcyclefile. The fileTime * a cvar containing a file name. If the file in the cvar is bad, it will use mapcyclefile. The fileTime