From 4e07200cfb54ace3ce404d7fb6eb88462192bb6c Mon Sep 17 00:00:00 2001 From: David Anderson Date: Fri, 4 Jan 2008 16:05:26 +0000 Subject: [PATCH] - added AddTargetsToMenu2() for using COMMAND_FILTER flags - fixed amb1350 - sm_voteban/menu ban on fake clients would crash - fake clients can no longer be banned and do not appear on ban menus --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401838 --- core/smn_banning.cpp | 5 ++++ plugins/adminmenu.sp | 48 +++++++++++++++++++++++++++--- plugins/basebans/ban.sp | 2 +- plugins/basevotes/voteban.sp | 2 +- plugins/include/adminmenu.inc | 19 +++++++++++- plugins/include/commandfilters.inc | 28 ++++++++--------- 6 files changed, 83 insertions(+), 21 deletions(-) diff --git a/core/smn_banning.cpp b/core/smn_banning.cpp index 2cf5888e..876e31fd 100644 --- a/core/smn_banning.cpp +++ b/core/smn_banning.cpp @@ -256,6 +256,11 @@ static cell_t BanClient(IPluginContext *pContext, const cell_t *params) return pContext->ThrowNativeError("Client index %d is invalid", client); } + if (pPlayer->IsFakeClient()) + { + return pContext->ThrowNativeError("Cannot ban fake client %d", client); + } + pContext->LocalToString(params[4], &ban_reason); pContext->LocalToString(params[5], (char **)&kick_message); pContext->LocalToString(params[6], &ban_cmd); diff --git a/plugins/adminmenu.sp b/plugins/adminmenu.sp index 9d21bc84..8a68b46c 100644 --- a/plugins/adminmenu.sp +++ b/plugins/adminmenu.sp @@ -61,6 +61,7 @@ public bool:AskPluginLoad(Handle:myself, bool:late, String:error[], err_max) { CreateNative("GetAdminTopMenu", __GetAdminTopMenu); CreateNative("AddTargetsToMenu", __AddTargetsToMenu); + CreateNative("AddTargetsToMenu2", __AddTargetsToMenu2); RegPluginLibrary("adminmenu"); return true; } @@ -181,6 +182,11 @@ public __AddTargetsToMenu(Handle:plugin, numParams) return UTIL_AddTargetsToMenu(GetNativeCell(1), GetNativeCell(2), GetNativeCell(3), alive_only); } +public __AddTargetsToMenu2(Handle:plugin, numParams) +{ + return UTIL_AddTargetsToMenu2(GetNativeCell(1), GetNativeCell(2), GetNativeCell(3)); +} + public Action:Command_DisplayMenu(client, args) { if (client == 0) @@ -194,7 +200,7 @@ public Action:Command_DisplayMenu(client, args) return Plugin_Handled; } -stock UTIL_AddTargetsToMenu(Handle:menu, source_client, bool:in_game_only, bool:alive_only) +stock UTIL_AddTargetsToMenu2(Handle:menu, source_client, flags) { new max_clients = GetMaxClients(); decl String:user_id[12]; @@ -210,17 +216,34 @@ stock UTIL_AddTargetsToMenu(Handle:menu, source_client, bool:in_game_only, bool: continue; } - if (in_game_only && !IsClientInGame(i)) + PrintToServer("%d, %d, %d", i, flags, IsFakeClient(i)); + + if (((flags & COMMAND_FILTER_NO_BOTS) == COMMAND_FILTER_NO_BOTS) + && IsFakeClient(i)) { continue; } - if (alive_only && !IsPlayerAlive(i)) + if (((flags & COMMAND_FILTER_CONNECTED) != COMMAND_FILTER_CONNECTED) + && !IsClientInGame(i)) { continue; } - if (source_client && !CanUserTarget(source_client, i)) + if (((flags & COMMAND_FILTER_ALIVE) == COMMAND_FILTER_ALIVE) + && !IsPlayerAlive(i)) + { + continue; + } + + if (((flags & COMMAND_FILTER_DEAD) == COMMAND_FILTER_DEAD) + && IsPlayerAlive(i)) + { + continue; + } + + if ((source_client && ((flags & COMMAND_FILTER_NO_IMMUNITY) != COMMAND_FILTER_NO_IMMUNITY)) + && !CanUserTarget(source_client, i)) { continue; } @@ -235,3 +258,20 @@ stock UTIL_AddTargetsToMenu(Handle:menu, source_client, bool:in_game_only, bool: return num_clients; } +stock UTIL_AddTargetsToMenu(Handle:menu, source_client, bool:in_game_only, bool:alive_only) +{ + new flags = 0; + + if (!in_game_only) + { + flags |= COMMAND_FILTER_CONNECTED; + } + + if (alive_only) + { + flags |= COMMAND_FILTER_ALIVE; + } + + return UTIL_AddTargetsToMenu2(menu, source_client, flags); +} + diff --git a/plugins/basebans/ban.sp b/plugins/basebans/ban.sp index 3ce206be..40c698da 100644 --- a/plugins/basebans/ban.sp +++ b/plugins/basebans/ban.sp @@ -75,7 +75,7 @@ DisplayBanTargetMenu(client) SetMenuTitle(menu, title); SetMenuExitBackButton(menu, true); - AddTargetsToMenu(menu, client, false, false); + AddTargetsToMenu2(menu, client, COMMAND_FILTER_NO_BOTS|COMMAND_FILTER_CONNECTED); DisplayMenu(menu, client, MENU_TIME_FOREVER); } diff --git a/plugins/basevotes/voteban.sp b/plugins/basevotes/voteban.sp index fa220f71..1827c0c6 100644 --- a/plugins/basevotes/voteban.sp +++ b/plugins/basevotes/voteban.sp @@ -167,7 +167,7 @@ public Action:Command_Voteban(client, args) client, target_list, MAXPLAYERS, - COMMAND_FILTER_NO_MULTI, + COMMAND_FILTER_NO_MULTI|COMMAND_FILTER_NO_BOTS, target_name, sizeof(target_name), tn_is_ml)) <= 0) diff --git a/plugins/include/adminmenu.inc b/plugins/include/adminmenu.inc index 619165e5..dcac5c4f 100644 --- a/plugins/include/adminmenu.inc +++ b/plugins/include/adminmenu.inc @@ -94,7 +94,23 @@ native Handle:GetAdminTopMenu(); * @param alive_only True to only select alive players. * @return Number of clients added. */ -native AddTargetsToMenu(Handle:menu, source_client, bool:in_game_only=true, bool:alive_only=false); +native AddTargetsToMenu(Handle:menu, + source_client, + bool:in_game_only=true, + bool:alive_only=false); + +/** + * Adds targets to an admin menu. + * + * Each client is displayed as: name (userid) + * Each item contains the userid as a string for its info. + * + * @param menu Menu Handle. + * @param source_client Source client, or 0 to ignore immunity. + * @param flags COMMAND_FILTER flags from commandfilters.inc. + * @return Number of clients added. + */ +native AddTargetsToMenu2(Handle:menu, source_client, flags); /** * Re-displays the admin menu to a client after selecting an item. @@ -132,5 +148,6 @@ public __pl_adminmenu_SetNTVOptional() { MarkNativeAsOptional("GetAdminTopMenu"); MarkNativeAsOptional("AddTargetsToMenu"); + MarkNativeAsOptional("AddTargetsToMenu2"); } #endif diff --git a/plugins/include/commandfilters.inc b/plugins/include/commandfilters.inc index fa8829a9..914982a8 100644 --- a/plugins/include/commandfilters.inc +++ b/plugins/include/commandfilters.inc @@ -37,21 +37,21 @@ #define MAX_TARGET_LENGTH 64 -#define COMMAND_FILTER_ALIVE (1<<0) /* Only allow alive players */ -#define COMMAND_FILTER_DEAD (1<<1) /* Only filter dead players */ -#define COMMAND_FILTER_CONNECTED (1<<2) /* Allow players not fully in-game */ -#define COMMAND_FILTER_NO_IMMUNITY (1<<3) /* Ignore immunity rules */ -#define COMMAND_FILTER_NO_MULTI (1<<4) /* Do not allow multiple target patterns */ -#define COMMAND_FILTER_NO_BOTS (1<<5) /* Do not allow bots to be targetted */ +#define COMMAND_FILTER_ALIVE (1<<0) /**< Only allow alive players */ +#define COMMAND_FILTER_DEAD (1<<1) /**< Only filter dead players */ +#define COMMAND_FILTER_CONNECTED (1<<2) /**< Allow players not fully in-game */ +#define COMMAND_FILTER_NO_IMMUNITY (1<<3) /**< Ignore immunity rules */ +#define COMMAND_FILTER_NO_MULTI (1<<4) /**< Do not allow multiple target patterns */ +#define COMMAND_FILTER_NO_BOTS (1<<5) /**< Do not allow bots to be targetted */ -#define COMMAND_TARGET_NONE 0 /* No target was found */ -#define COMMAND_TARGET_NOT_ALIVE -1 /* Single client is not alive */ -#define COMMAND_TARGET_NOT_DEAD -2 /* Single client is not dead */ -#define COMMAND_TARGET_NOT_IN_GAME -3 /* Single client is not in game */ -#define COMMAND_TARGET_IMMUNE -4 /* Single client is immune */ -#define COMMAND_TARGET_EMPTY_FILTER -5 /* A multi-filter (such as @all) had no targets */ -#define COMMAND_TARGET_NOT_HUMAN -6 /* Target was not human */ -#define COMMAND_TARGET_AMBIGUOUS -7 /* Partial name had too many targets */ +#define COMMAND_TARGET_NONE 0 /**< No target was found */ +#define COMMAND_TARGET_NOT_ALIVE -1 /**< Single client is not alive */ +#define COMMAND_TARGET_NOT_DEAD -2 /**< Single client is not dead */ +#define COMMAND_TARGET_NOT_IN_GAME -3 /**< Single client is not in game */ +#define COMMAND_TARGET_IMMUNE -4 /**< Single client is immune */ +#define COMMAND_TARGET_EMPTY_FILTER -5 /**< A multi-filter (such as @all) had no targets */ +#define COMMAND_TARGET_NOT_HUMAN -6 /**< Target was not human */ +#define COMMAND_TARGET_AMBIGUOUS -7 /**< Partial name had too many targets */ /** * Processes a generic command target string, and resolves it to a list