plugins/include/sdktools_stringtables.inc
author David Anderson <dvander@alliedmods.net>
Tue Jan 22 16:47:10 2008 +0000 (2008-01-22)
changeset 1853 b046cf080755
parent 1330 ab94316bb52b
child 1947 e73a1e51833b
permissions -rw-r--r--
fire requires timebomb
     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 _sdktools_stringtables_included
    34   #endinput
    35 #endif
    36 #define _sdktools_stringtables_included
    37 
    38 #define INVALID_STRING_TABLE -1		/**< An invalid string table index */
    39 #define INVALID_STRING_INDEX -1		/**< An invalid string index in a table */
    40 
    41 /**
    42  * Searches for a string table.
    43  *
    44  * @param name			Name of string table to find.
    45  * @return				A string table index number if found, INVALID_STRING_TABLE otherwise.
    46  */
    47 native FindStringTable(const String:name[]);
    48 
    49 /**
    50  * Returns the number of string tables that currently exist.
    51  *
    52  * @return				Number of string tables that currently exist.
    53  */
    54 native GetNumStringTables();
    55 
    56 /**
    57  * Returns the number of strings that currently exist in a given string table.
    58  *
    59  * @param tableidx		A string table index.
    60  * @return				Number of strings that currently exist.
    61  * @error				Invalid string table index.
    62  */
    63 native GetStringTableNumStrings(tableidx);
    64 
    65 /**
    66  * Returns the maximum number of strings that are allowed in a given string table.
    67  *
    68  * @param tableidx		A string table index.
    69  * @return				Maximum number of strings allowed.
    70  * @error				Invalid string table index.
    71  */
    72 native GetStringTableMaxStrings(tableidx);
    73 
    74 /**
    75  * Retrieves the name of a string table.
    76  *
    77  * @param tableidx		A string table index.
    78  * @param name			Buffer to store the name of the string table.
    79  * @param maxlength		Maximum length of string buffer.
    80  * @return				Number of bytes written to the buffer (UTF-8 safe).
    81  * @error				Invalid string table index.
    82  */
    83 native GetStringTableName(tableidx, String:name[], maxlength);
    84 
    85 /**
    86  * Searches for the index of a given string in a string table.
    87  *
    88  * @param tableidx		A string table index.
    89  * @param string		String to find.
    90  * @return				String index if found, INVALID_STRING_INDEX otherwise.
    91  * @error				Invalid string table index.
    92  */
    93 native FindStringIndex(tableidx, const String:str[]);
    94 
    95 /**
    96  * Retrieves the string at a given index of a string table.
    97  *
    98  * @param tableidx		A string table index.
    99  * @param stringidx		A string index.
   100  * @param name			Buffer to store the string value.
   101  * @param maxlength		Maximum length of string buffer.
   102  * @return				Number of bytes written to the buffer (UTF-8 safe).
   103  * @error				Invalid string table index or string index.
   104  */
   105 native ReadStringTable(tableidx, stringIdx, String:str[], maxlength);
   106 
   107 /**
   108  * Returns the length of the user data associated with a given string index.
   109  *
   110  * @param tableidx		A string table index.
   111  * @param stringidx		A string index.
   112  * @return				Length of user data. This will be 0 if there is no user data.
   113  * @error				Invalid string table index or string index.
   114  */
   115 native GetStringTableDataLength(tableidx, stringidx);
   116 
   117 /**
   118  * Retrieves the user data associated with a given string index.
   119  *
   120  * @param tableidx		A string table index.
   121  * @param stringidx		A string index.
   122  * @param userdata		Buffer to store the user data. This will be set to "" if there is no user data.
   123  * @param maxlength		Maximum length of string buffer.
   124  * @return				Number of bytes written to the buffer (UTF-8 safe).
   125  * @error				Invalid string table index or string index.
   126  */
   127 native GetStringTableData(tableidx, stringIdx, String:userdata[], maxlength);
   128 
   129 /**
   130  * Sets the user data associated with a given string index.
   131  *
   132  * @param tableidx		A string table index.
   133  * @param stringidx		A string index.
   134  * @param userdata		User data string that will be set.
   135  * @param length		Length of user data string. This should include the null terminator.
   136  * @return				Number of bytes written to the buffer (UTF-8 safe).
   137  * @error				Invalid string table index or string index.
   138  */
   139 native SetStringTableData(tableidx, stringIdx, const String:userdata[], length);
   140 
   141 /**
   142  * Adds a string to a given string table.
   143  *
   144  * @param tableidx		A string table index.
   145  * @param string		String to add.
   146  * @param userdata		An optional user data string.
   147  * @param length		Length of user data string. This should include the null terminator.
   148  *						If set to -1, then user data will be not be altered if the specified string
   149  *						already exists in the string table.
   150  */
   151 native AddToStringTable(tableidx, const String:str[], const String:userdata[]="", length=-1);
   152 
   153 /**
   154  * Locks or unlocks the network string tables.
   155  *
   156  * @param lock			Determines whether network string tables should be locked.
   157  *						True means the tables should be locked for writing; false means unlocked.
   158  * @return				Previous lock state.
   159  */
   160 native bool:LockStringTables(bool:lock);
   161 
   162 /**
   163  * Adds a file to the downloadables network string table.
   164  * This forces a client to download the file if they do not already have it.
   165  *
   166  * @param filename		File that will be added to downloadables table.
   167  */
   168 stock AddFileToDownloadsTable(const String:filename[])
   169 {
   170 	static table = INVALID_STRING_TABLE;
   171 	
   172 	if (table == INVALID_STRING_TABLE)
   173 	{
   174 		table = FindStringTable("downloadables");
   175 	}
   176 	
   177 	new bool:save = LockStringTables(false);
   178 	AddToStringTable(table, filename);
   179 	LockStringTables(save);
   180 }