From b4896ecada9bc087330a58b166ddf84c0e3c23c7 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Mon, 22 Oct 2007 02:54:27 +0000 Subject: [PATCH] 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 --- plugins/basebans.sp | 46 ++++-- plugins/basecomm.sp | 2 +- plugins/basecomm/gag.sp | 321 ++++++++++++++++++++++++------------ plugins/basecommands/who.sp | 14 +- plugins/include/helpers.inc | 60 ++++--- 5 files changed, 279 insertions(+), 164 deletions(-) diff --git a/plugins/basebans.sp b/plugins/basebans.sp index bdb4e608..bbf1ec9e 100644 --- a/plugins/basebans.sp +++ b/plugins/basebans.sp @@ -116,26 +116,42 @@ public Action:Command_BanIp(client, args) return Plugin_Handled; } - new clients[1]; - new numClients = SearchForClients(arg, clients, 1); - + decl String:target_name[MAX_TARGET_LENGTH]; + 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; if (client == 0 || (client == 1 && !IsDedicatedServer())) { has_rcon = true; - } else { + } + else + { new AdminId:id = GetUserAdmin(client); has_rcon = (id == INVALID_ADMIN_ID) ? false : GetAdminFlag(id, Admin_RCON); } new hit_client = -1; - if (numClients == 1 - && !IsFakeClient(clients[0]) - && (has_rcon || CanUserTarget(client, clients[0]))) + if (found_client != -1 + && !IsFakeClient(found_client) + && (has_rcon || CanUserTarget(client, found_client))) { - GetClientIP(clients[0], arg, sizeof(arg)); - hit_client = clients[0]; + GetClientIP(found_client, arg, sizeof(arg)); + hit_client = found_client; } if (hit_client == -1 && !has_rcon) @@ -146,7 +162,7 @@ public Action:Command_BanIp(client, args) new minutes = StringToInt(time); - decl String:reason[128]; + new String:reason[128]; if (args >= 3) { GetCmdArg(3, reason, sizeof(reason)); @@ -159,14 +175,20 @@ public Action:Command_BanIp(client, args) minutes, arg, reason); + + ReplyToCommand(client, "[SM] %t", "Ban added"); + BanIdentity(arg, minutes, BANFLAG_IP, reason, "sm_banip", client); - - ReplyToCommand(client, "[SM] %t", "Ban added"); + + if (hit_client != -1) + { + KickClient(hit_client, "Banned: %s", reason); + } return Plugin_Handled; } diff --git a/plugins/basecomm.sp b/plugins/basecomm.sp index 372a3f6f..e74eacda 100644 --- a/plugins/basecomm.sp +++ b/plugins/basecomm.sp @@ -10,7 +10,7 @@ * 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 * Free Software Foundation. - * + * 1 * 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 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more diff --git a/plugins/basecomm/gag.sp b/plugins/basecomm/gag.sp index f33101df..b899ad52 100644 --- a/plugins/basecomm/gag.sp +++ b/plugins/basecomm/gag.sp @@ -138,46 +138,55 @@ public MenuHandler_GagTypes(Handle:menu, MenuAction:action, param1, param2) GetMenuItem(menu, param2, info, sizeof(info)); type = CommType:StringToInt(info); + + decl String:name[MAX_NAME_LENGTH]; + GetClientName(g_GagTarget[param1], name, sizeof(name)); switch (type) { - case CommType_Mute: PerformMute(param1, g_GagTarget[param1]); - case CommType_UnMute: PerformUnMute(param1, g_GagTarget[param1]); - case CommType_Gag: PerformGag(param1, g_GagTarget[param1]); - case CommType_UnGag: PerformUnGag(param1, g_GagTarget[param1]); - case CommType_Silence: PerformSilence(param1, g_GagTarget[param1]); - case CommType_UnSilence: PerformUnSilence(param1, g_GagTarget[param1]); + case CommType_Mute: + { + PerformMute(param1, g_GagTarget[param1]); + ShowActivity2(param1, "[SM] ", "%t", "Muted target", "_s", name); + } + 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) { - if (g_Muted[target]) - { - ReplyToCommand(client, "%t", "Already Muted"); - return; - } - g_Muted[target] = true; - 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); + SetClientListeningFlags(target, VOICE_MUTED); LogAction(client, target, "\"%L\" muted \"%L\"", client, target); } PerformUnMute(client, target) { - if (!g_Muted[target]) - { - ReplyToCommand(client, "%t", "Player Not Muted"); - return; - } - g_Muted[target] = false; if (GetConVarInt(g_Cvar_Deadtalk) == 1 && !IsPlayerAlive(target)) { @@ -192,99 +201,42 @@ PerformUnMute(client, target) 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); } PerformGag(client, target) { - if (g_Gagged[target]) - { - ReplyToCommand(client, "%t", "Already Gagged"); - return; - } - 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); } PerformUnGag(client, target) { - if (!g_Gagged[target]) - { - ReplyToCommand(client, "%t", "Player Not Gagged"); - return; - } - 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); } 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]) { 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]) { g_Muted[target] = true; 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) { - 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]) { 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]) @@ -302,12 +254,10 @@ PerformUnSilence(client, target) else { 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) @@ -321,13 +271,38 @@ public Action:Command_Mute(client, args) decl String:arg[64]; GetCmdArg(1, arg, sizeof(arg)); - new target = FindTarget(client, arg); - if (target == -1) + decl String:target_name[MAX_TARGET_LENGTH]; + 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; } - PerformMute(client, target); + for (new i = 0; i < target_count; i++) + { + new target = target_list[i]; + + 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; } @@ -343,13 +318,38 @@ public Action:Command_Gag(client, args) decl String:arg[64]; GetCmdArg(1, arg, sizeof(arg)); - new target = FindTarget(client, arg); - if (target == -1) + decl String:target_name[MAX_TARGET_LENGTH]; + 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; } - PerformGag(client, target); + for (new i = 0; i < target_count; i++) + { + new target = target_list[i]; + + 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; } @@ -365,13 +365,38 @@ public Action:Command_Silence(client, args) decl String:arg[64]; GetCmdArg(1, arg, sizeof(arg)); - new target = FindTarget(client, arg); - if (target == -1) + decl String:target_name[MAX_TARGET_LENGTH]; + 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; } - PerformSilence(client, target); + for (new i = 0; i < target_count; i++) + { + new target = target_list[i]; + + 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; } @@ -387,13 +412,43 @@ public Action:Command_Unmute(client, args) decl String:arg[64]; GetCmdArg(1, arg, sizeof(arg)); - new target = FindTarget(client, arg); - if (target == -1) + decl String:target_name[MAX_TARGET_LENGTH]; + 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; } - PerformUnMute(client, target); + for (new i = 0; i < target_count; i++) + { + new target = target_list[i]; + + if (g_Muted[target]) + { + continue; + } + + 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; } @@ -409,13 +464,38 @@ public Action:Command_Ungag(client, args) decl String:arg[64]; GetCmdArg(1, arg, sizeof(arg)); - new target = FindTarget(client, arg); - if (target == -1) + decl String:target_name[MAX_TARGET_LENGTH]; + 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; } - PerformUnGag(client, target); + for (new i = 0; i < target_count; i++) + { + new target = target_list[i]; + + 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; } @@ -431,13 +511,38 @@ public Action:Command_Unsilence(client, args) decl String:arg[64]; GetCmdArg(1, arg, sizeof(arg)); - new target = FindTarget(client, arg); - if (target == -1) + decl String:target_name[MAX_TARGET_LENGTH]; + 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; } - PerformUnSilence(client, target); + for (new i = 0; i < target_count; i++) + { + new target = target_list[i]; + + 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; -} \ No newline at end of file +} diff --git a/plugins/basecommands/who.sp b/plugins/basecommands/who.sp index fb6cf7d0..ea53bd55 100644 --- a/plugins/basecommands/who.sp +++ b/plugins/basecommands/who.sp @@ -183,21 +183,13 @@ public Action:Command_Who(client, args) decl String:arg[65]; GetCmdArg(1, arg, sizeof(arg)); - new clients[2]; - new numClients = SearchForClients(arg, clients, 2); - - if (numClients == 0) + new target = FindTarget(client, arg); + if (target == -1) { - 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; } - PerformWho(client, clients[0], GetCmdReplySource()); + PerformWho(client, target, GetCmdReplySource()); return Plugin_Handled; } diff --git a/plugins/include/helpers.inc b/plugins/include/helpers.inc index 1ed03664..8ba81d7f 100644 --- a/plugins/include/helpers.inc +++ b/plugins/include/helpers.inc @@ -94,17 +94,9 @@ stock Handle:FindPluginByFile(const String:filename[]) } /** - * Searches for clients that match an input string. - * - * Allowed patterns: - * 1) # or # - * 2) - * - * @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. + * @deprecated Use FindTarget() or ProcessTargetString(). */ +#pragma deprecated Use FindTarget() or ProcessTargetString() stock SearchForClients(const String:pattern[], clients[], maxClients) { new maxclients = GetMaxClients(); @@ -166,45 +158,49 @@ 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. * * @param client Client who issued command * @param target Client's target argument * @param nobots Optional. Set to true if bots should NOT be targetted * @param immunity Optional. Set to false to ignore target immunity. - * @return Index of target client, or -1 on error. + * @return Index of target client, or -1 on error. */ stock FindTarget(client, const String:target[], bool:nobots = false, bool:immunity = true) { - new clients[2]; - new numClients = SearchForClients(target, clients, 2); + decl String:target_name[MAX_TARGET_LENGTH]; + 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"); - return -1; + flags |= COMMAND_FILTER_NO_BOTS; } - else if (numClients > 1) + if (!immunity) { - ReplyToCommand(client, "[SM] %t", "More than one client matches", target); - 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; + flags |= COMMAND_FILTER_NO_IMMUNITY; } - 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 * a cvar containing a file name. If the file in the cvar is bad, it will use mapcyclefile. The fileTime