plugins/include/keyvalues.inc
author David Anderson <dvander@alliedmods.net>
Fri Sep 14 02:11:10 2007 +0000 (2007-09-14)
changeset 1423 e73b3563f254
parent 1401 e3b761515c0a
child 1707 05af94444cc8
child 1715 f9ecab642e25
permissions -rw-r--r--
- added 3 new natives for banning/unbanning and interception
- moved banning commands into new plugin, basebans
- improved quality and input methods of ban commands
- corrected svn props on a few files
- added an IsLANServer() to IGameHelpers API
- completely deprecated and removed old banning forwards
     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 _keyvalues_included
    34  #endinput
    35 #endif
    36 #define _keyvalues_included
    37 
    38 /**
    39  * KeyValue data value types
    40  */
    41 enum KvDataTypes
    42 {
    43 	KvData_None = 0,	/**< Type could not be identified, or no type */
    44 	KvData_String,		/**< String value */
    45 	KvData_Int,			/**< Integer value */
    46 	KvData_Float,		/**< Floating point value */
    47 	KvData_Ptr,			/**< Pointer value (sometimes called "long") */
    48 	KvData_WString,		/**< Wide string value */
    49 	KvData_Color,		/**< Color value */
    50 	KvData_UInt64,		/**< Large integer value */
    51 	/* --- */
    52 	KvData_NUMTYPES, 
    53 };
    54 
    55 /**
    56  * Creates a new KeyValues structure.  The Handle must always be closed.
    57  *
    58  * @param name			Name of the root section.
    59  * @param firstKey		If non-empty, specifies the first key value.
    60  * @param firstValue	If firstKey is non-empty, specifies the first key's value.
    61  * @return				A Handle to a new KeyValues structure.
    62  */
    63 native Handle:CreateKeyValues(const String:name[], const String:firstkey[]="", const String:firstValue[]="");
    64 
    65 /** 
    66  * Sets a string value of a KeyValues key.
    67  *
    68  * @param kv			KeyValues Handle.
    69  * @param key			Name of the key, or NULL_STRING.
    70  * @param value			String value.
    71  * @noreturn
    72  * @error				Invalid Handle.
    73  */
    74 native KvSetString(Handle:kv, const String:key[], const String:value[]);
    75 
    76 /** 
    77  * Sets an integer value of a KeyValues key.
    78  *
    79  * @param kv			KeyValues Handle.
    80  * @param key			Name of the key, or NULL_STRING.
    81  * @param value			Value number.
    82  * @noreturn
    83  * @error				Invalid Handle.
    84  */
    85 native KvSetNum(Handle:kv, const String:key[], value);
    86 
    87 /** 
    88  * Sets a large integer value of a KeyValues key.
    89  *
    90  * @param kv			KeyValues Handle.
    91  * @param key			Name of the key, or NULL_STRING.
    92  * @param value			Large integer value (0=High bits, 1=Low bits)
    93  * @noreturn
    94  * @error				Invalid Handle.
    95  */
    96 native KvSetUInt64(Handle:kv, const String:key[], const value[2]);
    97 
    98 /** 
    99  * Sets a floating point value of a KeyValues key.
   100  *
   101  * @param kv			KeyValues Handle.
   102  * @param key			Name of the key, or NULL_STRING.
   103  * @param value			Floating point value.
   104  * @noreturn
   105  * @error				Invalid Handle.
   106  */
   107 native KvSetFloat(Handle:kv, const String:key[], Float:value);
   108 
   109 /** 
   110  * Sets a set of color values of a KeyValues key.
   111  *
   112  * @param kv			KeyValues Handle.
   113  * @param key			Name of the key, or NULL_STRING.
   114  * @param r				Red value.
   115  * @param g				Green value.
   116  * @param b				Blue value.
   117  * @param a				Alpha value.
   118  * @noreturn
   119  * @error				Invalid Handle.
   120  */
   121 native KvSetColor(Handle:kv, const String:key[], r, g, b, a=0);
   122 
   123 /** 
   124  * Retrieves a string value from a KeyValues key.
   125  *
   126  * @param kv			KeyValues Handle.
   127  * @param key			Name of the key, or NULL_STRING.
   128  * @param value			Buffer to store key value in.
   129  * @param maxlength		Maximum length of the value buffer.
   130  * @param defvalue		Optional default value to use if the key is not found.
   131  * @noreturn
   132  * @error				Invalid Handle.
   133  */
   134 native KvGetString(Handle:kv, const String:key[], String:value[], maxlength, const String:defvalue[]="");
   135 
   136 /** 
   137  * Retrieves an integer value from a KeyValues key.
   138  *
   139  * @param kv			KeyValues Handle.
   140  * @param key			Name of the key, or NULL_STRING.
   141  * @param defvalue		Optional default value to use if the key is not found.
   142  * @return				Integer value of the key.
   143  * @error				Invalid Handle.
   144  */
   145 native KvGetNum(Handle:kv, const String:key[], defvalue=0);
   146 
   147 /** 
   148  * Retrieves a floating point value from a KeyValues key.
   149  *
   150  * @param kv			KeyValues Handle.
   151  * @param key			Name of the key, or NULL_STRING.
   152  * @param defvalue		Optional default value to use if the key is not found.
   153  * @return				Floating point value of the key.
   154  * @error				Invalid Handle.
   155  */
   156 native Float:KvGetFloat(Handle:kv, const String:key[], Float:defvalue=0.0);
   157 
   158 /** 
   159  * Retrieves a set of color values from a KeyValues key.
   160  *
   161  * @param kv			KeyValues Handle.
   162  * @param key			Name of the key, or NULL_STRING.
   163  * @param r				Red value, set by reference.
   164  * @param g				Green value, set by reference. 
   165  * @param b				Blue value, set by reference. 
   166  * @param a				Alpha value, set by reference. 
   167  * @noreturn
   168  * @error				Invalid Handle.
   169  */
   170 native KvGetColor(Handle:kv, const String:key[], &r, &g, &b, &a);
   171 
   172 /** 
   173  * Retrieves a large integer value from a KeyValues key.
   174  *
   175  * @param kv			KeyValues Handle.
   176  * @param key			Name of the key, or NULL_STRING.
   177  * @param value			Array to represent the large integer.
   178  * @param defvalue		Optional default value to use if the key is not found.
   179  * @noreturn
   180  * @error				Invalid Handle.
   181  */
   182 native KvGetUInt64(Handle:kv, const String:key[], value[2], defvalue[2]={0,0});
   183 
   184 /**
   185  * Sets the current position in the KeyValues tree to the given key.
   186  *
   187  * @param kv			KeyValues Handle.
   188  * @param key			Name of the key.
   189  * @param create		If true, and the key does not exist, it will be created.
   190  * @return				True if the key exists, false if it does not and was not created.
   191  */
   192 native bool:KvJumpToKey(Handle:kv, const String:key[], bool:create=false);
   193 
   194 /**
   195  * Sets the current position in the KeyValues tree to the first sub key.
   196  * This native adds to the internal traversal stack.
   197  *
   198  * @param kv			KeyValues Handle.
   199  * @param keyOnly		If false, non-keys will be traversed (values).
   200  * @return				True on success, false if there was no first sub key.
   201  * @error				Invalid Handle.
   202  */
   203 native bool:KvGotoFirstSubKey(Handle:kv, bool:keyOnly=true);
   204 
   205 /**
   206  * Sets the current position in the KeyValues tree to the next sub key.
   207  * This native does NOT add to the internal traversal stack, and thus
   208  * KvGoBack() is not needed for each successive call to this function.
   209  *
   210  * @param kv			KeyValues Handle.
   211  * @param keyOnly		If false, non-keys will be traversed (values).
   212  * @return				True on success, false if there was no next sub key.
   213  * @error				Invalid Handle.
   214  */
   215 native bool:KvGotoNextKey(Handle:kv, bool:keyOnly=true);
   216 
   217 /**
   218  * Saves the current position in the traversal stack onto the traversal
   219  * stack.  This can be useful if you wish to use KvGotoNextKey() and 
   220  * have the previous key saved for backwards traversal.
   221  *
   222  * @param kv			KeyValues Handle.
   223  * @noreturn
   224  * @error				Invalid Handle.
   225  */
   226 native KvSavePosition(Handle:kv);
   227 
   228 /**
   229  * Removes the given key from the current position.
   230  *
   231  * @param kv			KeyValues Handle.
   232  * @param key			Name of the key.
   233  * @return				True on success, false if key did not exist.
   234  * @error				Invalid Handle.
   235  */
   236 native bool:KvDeleteKey(Handle:kv, const String:key[]);
   237 
   238 /**
   239  * Removes the current sub-key and attempts to set the position
   240  * to the sub-key after the removed one.  If no such sub-key exists,
   241  * the position will be the parent key in the traversal stack.
   242  * Given the sub-key having position "N" in the traversal stack, the 
   243  * removal will always take place from position "N-1."
   244  *
   245  * @param kv			KeyValues Handle.
   246  * @return				1 if removal succeeded and there was another key.
   247  *						0 if the current node was not contained in the
   248  *						  previous node, or no previous node exists.
   249  *						-1 if removal succeeded and there were no more keys,
   250  *						  thus the state is as if KvGoBack() was called.
   251  * @error				Invalid Handle.
   252  */
   253 native KvDeleteThis(Handle:kv);
   254 
   255 /**
   256  * Jumps back to the previous position.  Returns false if there are no
   257  * previous positions (i.e., at the root node).  This should be called
   258  * once for each successful Jump call, in order to return to the top node.
   259  * This function pops one node off the internal traversal stack.
   260  *
   261  * @param kv			KeyValues Handle.
   262  * @return				True on success, false if there is no higher node.
   263  * @error				Invalid Handle.
   264  */
   265 native bool:KvGoBack(Handle:kv);
   266 
   267 /**
   268  * Sets the position back to the top node, emptying the entire node 
   269  * traversal history.  This can be used instead of looping KvGoBack()
   270  * if recursive iteration is not important.
   271  *
   272  * @param kv			KeyValues Handle.
   273  * @noreturn
   274  * @error				Invalid Handle.
   275  */
   276 native KvRewind(Handle:kv);
   277 
   278 /**
   279  * Retrieves the current section name.
   280  * 
   281  * @param kv			KeyValues Handle.
   282  * @param section		Buffer to store the section name.
   283  * @param maxlength		Maximum length of the name buffer.
   284  * @return				True on success, false on failure.
   285  * @error				Invalid Handle.
   286  */
   287 native bool:KvGetSectionName(Handle:kv, String:section[], maxlength);
   288 
   289 /**
   290  * Sets the current section name.
   291  * 
   292  * @param kv			KeyValues Handle.
   293  * @param section		Section name.
   294  * @noreturn
   295  * @error				Invalid Handle.
   296  */
   297 native KvSetSectionName(Handle:kv, const String:section[]);
   298 
   299 /**
   300  * Returns the data type at a key.
   301  *
   302  * @param kv			KeyValues Handle.
   303  * @param key			Key name.
   304  * @return				KvDataType value of the key.
   305  * @error				Invalid Handle.
   306  */
   307 native KvDataTypes:KvGetDataType(Handle:kv, const String:key[]);
   308 
   309 /**
   310  * Converts a KeyValues tree to a file.  The tree is dumped
   311  * from the current position.
   312  *
   313  * @param kv			KeyValues Handle.
   314  * @param file			File to dump write to.
   315  * @return				True on success, false otherwise.
   316  * @error				Invalid Handle.
   317  */
   318 native bool:KeyValuesToFile(Handle:kv, const String:file[]);
   319 
   320 /**
   321  * Converts a file to a KeyValues tree.  The file is read into
   322  * the current position of the tree.
   323  *
   324  * @param kv			KeyValues Handle.
   325  * @param file			File to read from.
   326  * @return				True on success, false otherwise.
   327  * @error				Invalid Handle.
   328  */
   329 native bool:FileToKeyValues(Handle:kv, const String:file[]);
   330 
   331 /**
   332  * Sets whether or not the KeyValues parser will read escape sequences.
   333  * For example, \n would be read as a literal newline.  This defaults
   334  * to false for new KeyValues structures.
   335  *
   336  * @param kv			KeyValues Handle.
   337  * @param useEscapes	Whether or not to read escape sequences.
   338  * @noreturn
   339  * @error				Invalid Handle.
   340  */
   341 native KvSetEscapeSequences(Handle:kv, bool:useEscapes);
   342 
   343 /**
   344  * Returns the position in the jump stack; I.e. the number of calls
   345  * required for KvGoBack to return to the root node.  If at the root node,
   346  * 0 is returned.
   347  *
   348  * @param kv			KeyValues Handle.
   349  * @return				Number of non-root nodes in the jump stack.
   350  * @error				Invalid Handle.
   351  */
   352 native KvNodesInStack(Handle:kv);
   353 
   354 /**
   355  * Makes a new copy of all subkeys in the origin KeyValues to
   356  * the destination KeyValues.
   357  * NOTE: All KeyValues are processed from the current location not the root one.
   358  *
   359  * @param origin		Origin KeyValues Handle.
   360  * @param dest			Destination KeyValues Handlee.
   361  * @noreturn
   362  * @error				Invalid Handle.
   363  */
   364 native KvCopySubkeys(Handle:origin, Handle:dest);
   365 
   366 /** 
   367  * Finds a KeyValues name by id.
   368  *
   369  * @param kv			KeyValues Handle.
   370  * @param id			KeyValues id.
   371  * @param name			Buffer to store the name.
   372  * @param maxlength		Maximum length of the value buffer.
   373  * @return			True on success, false if id not found.
   374  * @error				Invalid Handle.
   375  */
   376 native bool:KvFindKeyById(Handle:kv, id, String:name[], maxlength);
   377 
   378 /** 
   379  * Finds a KeyValues id inside a KeyValues tree.
   380  *
   381  * @param kv			KeyValues Handle.
   382  * @param key			Key name.
   383  * @param id			Id of the found KeyValue.
   384  * @return			True on success, false if key not found.
   385  * @error				Invalid Handle.
   386  */
   387 native bool:KvGetNameSymbol(Handle:kv, const String:key[], &id);