Added check to make sure player are alive to perform sm_slap, sm_burn, sm_slay.
3 * ================================================================
5 * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
6 * ================================================================
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License,
10 * version 3.0, as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to
21 * link the code of this program (as well as its derivative works) to
22 * "Half-Life 2," the "Source Engine," the "SourcePawn JIT," and any
23 * Game MODs that run on software by the Valve Corporation. You must
24 * obey the GNU General Public License in all respects for all other
25 * code used. Additionally, AlliedModders LLC grants this exception
26 * to all derivative works. AlliedModders LLC defines further
27 * exceptions, found in LICENSE.txt (as of this writing, version
28 * JULY-31-2007), or <http://www.sourcemod.net/license.php>.
33 #ifndef _INCLUDE_SOURCEMOD_TEXTPARSERS_INTERFACE_H_
34 #define _INCLUDE_SOURCEMOD_TEXTPARSERS_INTERFACE_H_
37 * @file ITextParsers.h
38 * @brief Defines various text/file parsing functions, as well as UTF-8 support code.
41 #include <IShareSys.h>
46 * The INI file format is defined as:
47 * WHITESPACE: 0x20, \n, \t, \r
48 * IDENTIFIER: A-Z a-z 0-9 _ - , + . $ ? /
49 * STRING: Any set of symbols
51 * Basic syntax is comprised of SECTIONs.
52 * A SECTION is defined as:
58 * SECTIONNAME is an IDENTIFIER.
59 * OPTION can be repeated any number of times, once per line.
60 * OPTION is defined as one of:
64 * Where KEY is an IDENTIFIER and VALUE is a STRING.
66 * WHITESPACE should always be omitted.
67 * COMMENTS should be stripped, and are defined as text occurring in:
70 * Example file below. Note that
71 * The second line is technically invalid. The event handler
72 * must decide whether this should be allowed.
85 * @brief Contains parse events for INI files.
87 class ITextListener_INI
91 * @brief Called when a new section is encountered in an INI file.
93 * @param section Name of section in between the [ and ] characters.
94 * @param invalid_tokens True if invalid tokens were detected in the name.
95 * @param close_bracket True if a closing bracket was detected, false otherwise.
96 * @param extra_tokens True if extra tokens were detected on the line.
97 * @param curtok Contains current token in the line where the section name starts.
98 * You can add to this offset when failing to point to a token.
99 * @return True to keep parsing, false otherwise.
101 virtual bool ReadINI_NewSection(const char *section,
105 unsigned int *curtok)
111 * @brief Called when encountering a key/value pair in an INI file.
113 * @param key Name of key.
114 * @param value String containing value (with quotes stripped, if any).
115 * @param invalid_tokens Whether or not the key contained invalid tokens.
116 * @param equal_token There was an '=' sign present (in case the value is missing).
117 * @param quotes Whether value was enclosed in quotes.
118 * @param curtok Contains the token index of the start of the value string.
119 * This can be changed when returning false.
120 * @return True to keep parsing, false otherwise.
122 virtual bool ReadINI_KeyValue(const char *key,
127 unsigned int *curtok)
133 * @brief Called after a line has been preprocessed, if it has text.
135 * @param line Contents of line.
136 * @param curtok Pointer to optionally store failed position in string.
137 * @return True to keep parsing, false otherwise.
139 virtual bool ReadINI_RawLine(const char *line, unsigned int *curtok)
146 * :TODO: write this in CFG (context free grammar) format so it makes sense
148 * The SMC file format is defined as:
149 * WHITESPACE: 0x20, \n, \t, \r
150 * IDENTIFIER: Any ASCII character EXCLUDING ", {, }, ;, //, / *, or WHITESPACE.
151 * STRING: Any set of symbols enclosed in quotes.
152 * Note: if a STRING does not have quotes, it is parsed as an IDENTIFIER.
154 * Basic syntax is comprised of SECTIONBLOCKs.
155 * A SECTIONBLOCK defined as:
162 * OPTION can be repeated any number of times inside a SECTIONBLOCK.
163 * A new line will terminate an OPTION, but there can be more than one OPTION per line.
164 * OPTION is defined any of:
168 * SECTIONNAME, KEY, VALUE, and SINGLEKEY are strings
169 * SECTIONNAME cannot have trailing characters if quoted, but the quotes can be optionally removed.
170 * If SECTIONNAME is not enclosed in quotes, the entire sectionname string is used (minus surrounding whitespace).
171 * If KEY is not enclosed in quotes, the key is terminated at first whitespace.
172 * If VALUE is not properly enclosed in quotes, the entire value string is used (minus surrounding whitespace).
173 * The VALUE may have inner quotes, but the key string may not.
175 * For an example, see configs/permissions.cfg
177 * WHITESPACE should be ignored.
178 * Comments are text occurring inside the following tokens, and should be stripped
179 * unless they are inside literal strings:
185 * @brief Lists actions to take when an SMC parse hook is done.
189 SMCParse_Continue, /**< Continue parsing */
190 SMCParse_Halt, /**< Stop parsing here */
191 SMCParse_HaltFail /**< Stop parsing and return SMCParseError_Custom */
195 * @brief Lists error codes possible from parsing an SMC file.
199 SMCParse_Okay = 0, /**< No error */
200 SMCParse_StreamOpen, /**< Stream failed to open */
201 SMCParse_StreamError, /**< The stream died... somehow */
202 SMCParse_Custom, /**< A custom handler threw an error */
203 SMCParse_InvalidSection1, /**< A section was declared without quotes, and had extra tokens */
204 SMCParse_InvalidSection2, /**< A section was declared without any header */
205 SMCParse_InvalidSection3, /**< A section ending was declared with too many unknown tokens */
206 SMCParse_InvalidSection4, /**< A section ending has no matching beginning */
207 SMCParse_InvalidSection5, /**< A section beginning has no matching ending */
208 SMCParse_InvalidTokens, /**< There were too many unidentifiable strings on one line */
209 SMCParse_TokenOverflow, /**< The token buffer overflowed */
210 SMCParse_InvalidProperty1, /**< A property was declared outside of any section */
214 * @brief Describes the events available for reading an SMC stream.
216 class ITextListener_SMC
220 * @brief Called when starting parsing.
222 virtual void ReadSMC_ParseStart()
227 * @brief Called when ending parsing.
229 * @param halted True if abnormally halted, false otherwise.
230 * @param failed True if parsing failed, false otherwise.
232 virtual void ReadSMC_ParseEnd(bool halted, bool failed)
237 * @brief Called when a warning occurs.
238 * @param error By-reference variable containing the error message of the warning.
239 * @param tokens Pointer to the token stream causing the error.
240 * @return SMCParseResult directive.
242 virtual SMCParseResult ReadSMC_OnWarning(SMCParseError &error, const char *tokens)
244 return SMCParse_HaltFail;
248 * @brief Called when entering a new section
250 * @param name Name of section, with the colon omitted.
251 * @param opt_quotes Whether or not the option string was enclosed in quotes.
252 * @return SMCParseResult directive.
254 virtual SMCParseResult ReadSMC_NewSection(const char *name, bool opt_quotes)
256 return SMCParse_Continue;
260 * @brief Called when encountering a key/value pair in a section.
262 * @param key Key string.
263 * @param value Value string. If no quotes were specified, this will be NULL,
264 and key will contain the entire string.
265 * @param key_quotes Whether or not the key was in quotation marks.
266 * @param value_quotes Whether or not the value was in quotation marks.
267 * @return SMCParseResult directive.
269 virtual SMCParseResult ReadSMC_KeyValue(const char *key,
274 return SMCParse_Continue;
278 * @brief Called when leaving the current section.
280 * @return SMCParseResult directive.
282 virtual SMCParseResult ReadSMC_LeavingSection()
284 return SMCParse_Continue;
288 * @brief Called after an input line has been preprocessed.
290 * @param line String containing line input.
291 * @param curline Number of line in file.
292 * @return SMCParseResult directive.
294 virtual SMCParseResult ReadSMC_RawLine(const char *line, unsigned int curline)
296 return SMCParse_Continue;
300 #define SMINTERFACE_TEXTPARSERS_NAME "ITextParsers"
301 #define SMINTERFACE_TEXTPARSERS_VERSION 1
304 * @brief Contains various text stream parsing functions.
306 class ITextParsers : public SMInterface
309 virtual const char *GetInterfaceName()
311 return SMINTERFACE_TEXTPARSERS_NAME;
313 virtual unsigned int GetInterfaceVersion()
315 return SMINTERFACE_TEXTPARSERS_VERSION;
319 * @brief Parses an INI-format file.
321 * @param file Path to file.
322 * @param ini_listener Event handler for reading file.
323 * @param line If non-NULL, will contain last line parsed (0 if file could not be opened).
324 * @param col If non-NULL, will contain last column parsed (undefined if file could not be opened).
325 * @return True if parsing succeeded, false if file couldn't be opened or there was a syntax error.
327 virtual bool ParseFile_INI(const char *file,
328 ITextListener_INI *ini_listener,
330 unsigned int *col) =0;
333 * @brief Parses an SMC-format text file.
334 * Note that the parser makes every effort to obey broken syntax.
335 * For example, if an open brace is missing, but the section name has a colon,
336 * it will let you know. It is up to the event handlers to decide whether to be strict or not.
338 * @param file Path to file.
339 * @param smc_listener Event handler for reading file.
340 * @param line If non-NULL, will contain last line parsed (0 if file could not be opened).
341 * @param col If non-NULL, will contain last column parsed (undefined if file could not be opened).
342 * @return An SMCParseError result code.
344 virtual SMCParseError ParseFile_SMC(const char *file,
345 ITextListener_SMC *smc_listener,
347 unsigned int *col) =0;
350 * @brief Converts an SMCParseError to a string.
352 * @param err SMCParseError.
353 * @return String error message, or NULL if none.
355 virtual const char *GetSMCErrorString(SMCParseError err) =0;
359 * @brief Returns the number of bytes that a multi-byte character contains in a UTF-8 stream.
360 * If the current character is not multi-byte, the function returns 1.
362 * @param stream Pointer to multi-byte ANSI character string.
363 * @return Number of bytes in current character.
365 virtual unsigned int GetUTF8CharBytes(const char *stream) =0;
369 #endif //_INCLUDE_SOURCEMOD_TEXTPARSERS_INTERFACE_H_