plugins/include/commandfilters.inc
author David Anderson <dvander@alliedmods.net>
Tue Jan 08 03:06:33 2008 +0000 (2008-01-08)
changeset 1839 1f3aaf8fbd12
parent 1832 1f97873475e8
child 1947 e73a1e51833b
permissions -rw-r--r--
- added amb1332, new cvar protection mechanism for rcon_password
- removed FCVAR_PROTECTED from Core cvars
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
     5  * =============================================================================
     6  *
     7  * This file is part of the SourceMod/SourcePawn SDK.
     8  *
     9  * This program is free software; you can redistribute it and/or modify it under
    10  * the terms of the GNU General Public License, version 3.0, as published by the
    11  * Free Software Foundation.
    12  * 
    13  * This program is distributed in the hope that it will be useful, but WITHOUT
    14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    15  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    16  * details.
    17  *
    18  * You should have received a copy of the GNU General Public License along with
    19  * this program.  If not, see <http://www.gnu.org/licenses/>.
    20  *
    21  * As a special exception, AlliedModders LLC gives you permission to link the
    22  * code of this program (as well as its derivative works) to "Half-Life 2," the
    23  * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    24  * by the Valve Corporation.  You must obey the GNU General Public License in
    25  * all respects for all other code used.  Additionally, AlliedModders LLC grants
    26  * this exception to all derivative works.  AlliedModders LLC defines further
    27  * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    28  * or <http://www.sourcemod.net/license.php>.
    29  *
    30  * Version: $Id$
    31  */
    32  
    33 #if defined _commandfilters_included
    34  #endinput
    35 #endif
    36 #define _commandfilters_included
    37 
    38 #define MAX_TARGET_LENGTH			64
    39 
    40 #define COMMAND_FILTER_ALIVE		(1<<0)		/**< Only allow alive players */
    41 #define COMMAND_FILTER_DEAD			(1<<1)		/**< Only filter dead players */
    42 #define COMMAND_FILTER_CONNECTED	(1<<2)		/**< Allow players not fully in-game */
    43 #define COMMAND_FILTER_NO_IMMUNITY	(1<<3)		/**< Ignore immunity rules */
    44 #define COMMAND_FILTER_NO_MULTI		(1<<4)		/**< Do not allow multiple target patterns */
    45 #define COMMAND_FILTER_NO_BOTS		(1<<5)		/**< Do not allow bots to be targetted */
    46 
    47 #define COMMAND_TARGET_NONE			0			/**< No target was found */
    48 #define COMMAND_TARGET_NOT_ALIVE	-1			/**< Single client is not alive */
    49 #define COMMAND_TARGET_NOT_DEAD		-2			/**< Single client is not dead */
    50 #define COMMAND_TARGET_NOT_IN_GAME	-3			/**< Single client is not in game */
    51 #define COMMAND_TARGET_IMMUNE		-4			/**< Single client is immune */
    52 #define COMMAND_TARGET_EMPTY_FILTER	-5			/**< A multi-filter (such as @all) had no targets */
    53 #define COMMAND_TARGET_NOT_HUMAN	-6			/**< Target was not human */
    54 #define COMMAND_TARGET_AMBIGUOUS	-7			/**< Partial name had too many targets */
    55 
    56 /**
    57  * Processes a generic command target string, and resolves it to a list 
    58  * of clients or one client, based on filtering rules and a pattern.
    59  *
    60  * @param pattern		Pattern to find clients against.
    61  * @param admin			Admin performing the action, or 0 if the server.
    62  * @param targets		Array to hold targets.
    63  * @param max_targets	Maximum size of the targets array.
    64  * @param filter_flags	Filter flags.
    65  * @param target_name	Buffer to store the target name.
    66  * @param tn_maxlength	Maximum length of the target name buffer.
    67  * @param tn_is_ml		Set to true if the target name buffer is an ML phrase,
    68  *						false if it is a normal string.
    69  * @return				If a multi-target pattern was used, the number of clients found 
    70  *						is returned.  If a single-target pattern was used, 1 is returned 
    71  *						if one valid client is found.  Otherwise, a CLIENT_TARGET reason 
    72  *						for failure is returned.
    73  */
    74 native ProcessTargetString(const String:pattern[],
    75 						   admin, 
    76 						   targets[],
    77 						   max_targets,
    78 						   filter_flags,
    79 						   String:target_name[],
    80 						   tn_maxlength,
    81 						   &bool:tn_is_ml);
    82 
    83 /**
    84  * Replies to a client with a given message describing a targetting 
    85  * failure reason.
    86  *
    87  * Note: The translation phrases are found in common.phrases.txt.
    88  *
    89  * @param client		Client index, or 0 for server.
    90  * @param reason		COMMAND_TARGET reason.
    91  * @noreturn
    92  */
    93 stock ReplyToTargetError(client, reason)
    94 {
    95 	switch (reason)
    96 	{
    97 		case COMMAND_TARGET_NONE:
    98 		{
    99 			ReplyToCommand(client, "[SM] %t", "No matching client");
   100 		}
   101 		case COMMAND_TARGET_NOT_ALIVE:
   102 		{
   103 			ReplyToCommand(client, "[SM] %t", "Target must be alive");
   104 		}
   105 		case COMMAND_TARGET_NOT_DEAD:
   106 		{
   107 			ReplyToCommand(client, "[SM] %t", "Target must be dead");
   108 		}
   109 		case COMMAND_TARGET_NOT_IN_GAME:
   110 		{
   111 			ReplyToCommand(client, "[SM] %t", "Target is not in game");
   112 		}
   113 		case COMMAND_TARGET_IMMUNE:
   114 		{
   115 			ReplyToCommand(client, "[SM] %t", "Unable to target");
   116 		}
   117 		case COMMAND_TARGET_EMPTY_FILTER:
   118 		{
   119 			ReplyToCommand(client, "[SM] %t", "No matching clients");
   120 		}
   121 		case COMMAND_TARGET_NOT_HUMAN:
   122 		{
   123 			ReplyToCommand(client, "[SM] %t", "Cannot target bot");
   124 		}
   125 		case COMMAND_TARGET_AMBIGUOUS:
   126 		{
   127 			ReplyToCommand(client, "[SM] %t", "More than one client matched");
   128 		}
   129 	}
   130 }