plugins/include/commandfilters.inc
author David Anderson <dvander@alliedmods.net>
Sat May 17 05:12:52 2008 +0000 (2008-05-17)
changeset 2056 f1fcde46ac7c
parent 2015 39c6f6f945db
child 2289 44045ead61cd
permissions -rw-r--r--
added amb1119 - sm_revote command
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod (C)2004-2008 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  * Note that you should use LoadTranslations("common.phrases") in OnPluginStart(), 
    61  * as that file is guaranteed to contain all of the translatable phrases that 
    62  * ProcessTargetString() will return.
    63  *
    64  * @param pattern		Pattern to find clients against.
    65  * @param admin			Admin performing the action, or 0 if the server.
    66  * @param targets		Array to hold targets.
    67  * @param max_targets	Maximum size of the targets array.
    68  * @param filter_flags	Filter flags.
    69  * @param target_name	Buffer to store the target name.
    70  * @param tn_maxlength	Maximum length of the target name buffer.
    71  * @param tn_is_ml		OUTPUT: Will be true if the target name buffer is an ML phrase,
    72  *						false if it is a normal string.
    73  * @return				If a multi-target pattern was used, the number of clients found 
    74  *						is returned.  If a single-target pattern was used, 1 is returned 
    75  *						if one valid client is found.  Otherwise, a COMMAND_TARGET reason 
    76  *						for failure is returned.
    77  */
    78 native ProcessTargetString(const String:pattern[],
    79 						   admin, 
    80 						   targets[],
    81 						   max_targets,
    82 						   filter_flags,
    83 						   String:target_name[],
    84 						   tn_maxlength,
    85 						   &bool:tn_is_ml);
    86 
    87 /**
    88  * Replies to a client with a given message describing a targetting 
    89  * failure reason.
    90  *
    91  * Note: The translation phrases are found in common.phrases.txt.
    92  *
    93  * @param client		Client index, or 0 for server.
    94  * @param reason		COMMAND_TARGET reason.
    95  * @noreturn
    96  */
    97 stock ReplyToTargetError(client, reason)
    98 {
    99 	switch (reason)
   100 	{
   101 		case COMMAND_TARGET_NONE:
   102 		{
   103 			ReplyToCommand(client, "[SM] %t", "No matching client");
   104 		}
   105 		case COMMAND_TARGET_NOT_ALIVE:
   106 		{
   107 			ReplyToCommand(client, "[SM] %t", "Target must be alive");
   108 		}
   109 		case COMMAND_TARGET_NOT_DEAD:
   110 		{
   111 			ReplyToCommand(client, "[SM] %t", "Target must be dead");
   112 		}
   113 		case COMMAND_TARGET_NOT_IN_GAME:
   114 		{
   115 			ReplyToCommand(client, "[SM] %t", "Target is not in game");
   116 		}
   117 		case COMMAND_TARGET_IMMUNE:
   118 		{
   119 			ReplyToCommand(client, "[SM] %t", "Unable to target");
   120 		}
   121 		case COMMAND_TARGET_EMPTY_FILTER:
   122 		{
   123 			ReplyToCommand(client, "[SM] %t", "No matching clients");
   124 		}
   125 		case COMMAND_TARGET_NOT_HUMAN:
   126 		{
   127 			ReplyToCommand(client, "[SM] %t", "Cannot target bot");
   128 		}
   129 		case COMMAND_TARGET_AMBIGUOUS:
   130 		{
   131 			ReplyToCommand(client, "[SM] %t", "More than one client matched");
   132 		}
   133 	}
   134 }