summaryrefslogtreecommitdiff
path: root/source/sourcemod-1.5-dev/scripting/include/commandfilters.inc
blob: 6ea447cfc87dae172a3685b2e64d25a8fcce5e3c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/**
 * vim: set ts=4 :
 * =============================================================================
 * SourceMod (C)2004-2008 AlliedModders LLC.  All rights reserved.
 * =============================================================================
 *
 * This file is part of the SourceMod/SourcePawn SDK.
 *
 * 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.
 * 
 * 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
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * As a special exception, AlliedModders LLC gives you permission to link the
 * code of this program (as well as its derivative works) to "Half-Life 2," the
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
 * by the Valve Corporation.  You must obey the GNU General Public License in
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
 * this exception to all derivative works.  AlliedModders LLC defines further
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
 * or <http://www.sourcemod.net/license.php>.
 *
 * Version: $Id$
 */
 
#if defined _commandfilters_included
 #endinput
#endif
#define _commandfilters_included

#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_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 
 * of clients or one client, based on filtering rules and a pattern.
 *
 * Note that you should use LoadTranslations("common.phrases") in OnPluginStart(), 
 * as that file is guaranteed to contain all of the translatable phrases that 
 * ProcessTargetString() will return.
 *
 * @param pattern		Pattern to find clients against.
 * @param admin			Admin performing the action, or 0 if the server.
 * @param targets		Array to hold targets.
 * @param max_targets	Maximum size of the targets array.
 * @param filter_flags	Filter flags.
 * @param target_name	Buffer to store the target name.
 * @param tn_maxlength	Maximum length of the target name buffer.
 * @param tn_is_ml		OUTPUT: Will be true if the target name buffer is an ML phrase,
 *						false if it is a normal string.
 * @return				If a multi-target pattern was used, the number of clients found 
 *						is returned.  If a single-target pattern was used, 1 is returned 
 *						if one valid client is found.  Otherwise, a COMMAND_TARGET reason 
 *						for failure is returned.
 */
native ProcessTargetString(const String:pattern[],
						   admin, 
						   targets[],
						   max_targets,
						   filter_flags,
						   String:target_name[],
						   tn_maxlength,
						   &bool:tn_is_ml);

/**
 * Replies to a client with a given message describing a targetting 
 * failure reason.
 *
 * Note: The translation phrases are found in common.phrases.txt.
 *
 * @param client		Client index, or 0 for server.
 * @param reason		COMMAND_TARGET reason.
 * @noreturn
 */
stock ReplyToTargetError(client, reason)
{
	switch (reason)
	{
		case COMMAND_TARGET_NONE:
		{
			ReplyToCommand(client, "[SM] %t", "No matching client");
		}
		case COMMAND_TARGET_NOT_ALIVE:
		{
			ReplyToCommand(client, "[SM] %t", "Target must be alive");
		}
		case COMMAND_TARGET_NOT_DEAD:
		{
			ReplyToCommand(client, "[SM] %t", "Target must be dead");
		}
		case COMMAND_TARGET_NOT_IN_GAME:
		{
			ReplyToCommand(client, "[SM] %t", "Target is not in game");
		}
		case COMMAND_TARGET_IMMUNE:
		{
			ReplyToCommand(client, "[SM] %t", "Unable to target");
		}
		case COMMAND_TARGET_EMPTY_FILTER:
		{
			ReplyToCommand(client, "[SM] %t", "No matching clients");
		}
		case COMMAND_TARGET_NOT_HUMAN:
		{
			ReplyToCommand(client, "[SM] %t", "Cannot target bot");
		}
		case COMMAND_TARGET_AMBIGUOUS:
		{
			ReplyToCommand(client, "[SM] %t", "More than one client matched");
		}
	}
}

/**
 * Adds clients to a multi-target filter.
 *
 * @param pattern       Pattern name.
 * @param clients       Array to fill with unique, valid client indexes.
 * @return              True if pattern was recognized, false otherwise.
 */
functag public bool:MultiTargetFilter(const String:pattern[], Handle:clients);

/**
 * Adds a multi-target filter function for ProcessTargetString().
 *
 * @param pattern       Pattern to match (case sensitive).
 * @param filter        Filter function.
 * @param phrase        Descriptive phrase to display on successful match.
 * @param phraseIsML    True if phrase is multi-lingual, false otherwise.
 * @noreturn
 */
native AddMultiTargetFilter(const String:pattern[], MultiTargetFilter:filter,
                            const String:phrase[], bool:phraseIsML);

/**
 * Removes a multi-target filter function from ProcessTargetString().
 *
 * @param pattern       Pattern to match (case sensitive).
 * @param filter        Filter function.
 * @noreturn
 */
native RemoveMultiTargetFilter(const String:pattern[], MultiTargetFilter:filter);