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