plugins/include/sdktools_stringtables.inc
author David Anderson <dvander@alliedmods.net>
Wed Aug 08 02:27:10 2007 +0000 (2007-08-08)
changeset 1269 27397584df9c
parent 1115 13d96df8ead8
child 1330 ab94316bb52b
permissions -rw-r--r--
- massive overhaul of the voting subsystem
- NOTE: menu API compatibility was COMPLETELY broken for C++!
- cleaned up various aspects of the menu API
- implemented new extended vote results callback
- extended the debug reporter a tiny bit
     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.  This file may only be used 
     8  * or modified under the Terms and Conditions of its License Agreement, which is found 
     9  * in LICENSE.txt.  The Terms and Conditions for making SourceMod extensions/plugins 
    10  * may change at any time.  To view the latest information, see:
    11  *   http://www.sourcemod.net/license.php
    12  *
    13  * Version: $Id$
    14  */
    15 
    16 #if defined _sdktools_stringtables_included
    17   #endinput
    18 #endif
    19 #define _sdktools_stringtables_included
    20 
    21 #define INVALID_STRING_TABLE -1		/**< An invalid string table index */
    22 #define INVALID_STRING_INDEX -1		/**< An invalid string index in a table */
    23 
    24 /**
    25  * Searches for a string table.
    26  *
    27  * @param name			Name of string table to find.
    28  * @return				A string table index number if found, INVALID_STRING_TABLE otherwise.
    29  */
    30 native FindStringTable(const String:name[]);
    31 
    32 /**
    33  * Returns the number of string tables that currently exist.
    34  *
    35  * @return				Number of string tables that currently exist.
    36  */
    37 native GetNumStringTables();
    38 
    39 /**
    40  * Returns the number of strings that currently exist in a given string table.
    41  *
    42  * @param tableidx		A string table index.
    43  * @return				Number of strings that currently exist.
    44  * @error				Invalid string table index.
    45  */
    46 native GetStringTableNumStrings(tableidx);
    47 
    48 /**
    49  * Returns the maximum number of strings that are allowed in a given string table.
    50  *
    51  * @param tableidx		A string table index.
    52  * @return				Maximum number of strings allowed.
    53  * @error				Invalid string table index.
    54  */
    55 native GetStringTableMaxStrings(tableidx);
    56 
    57 /**
    58  * Retrieves the name of a string table.
    59  *
    60  * @param tableidx		A string table index.
    61  * @param name			Buffer to store the name of the string table.
    62  * @param maxlength		Maximum length of string buffer.
    63  * @return				Number of bytes written to the buffer (UTF-8 safe).
    64  * @error				Invalid string table index.
    65  */
    66 native GetStringTableName(tableidx, String:name[], maxlength);
    67 
    68 /**
    69  * Searches for the index of a given string in a string table.
    70  *
    71  * @param tableidx		A string table index.
    72  * @param string		String to find.
    73  * @return				String index if found, INVALID_STRING_INDEX otherwise.
    74  * @error				Invalid string table index.
    75  */
    76 native FindStringIndex(tableidx, const String:str[]);
    77 
    78 /**
    79  * Retrieves the string at a given index of a string table.
    80  *
    81  * @param tableidx		A string table index.
    82  * @param stringidx		A string index.
    83  * @param name			Buffer to store the string value.
    84  * @param maxlength		Maximum length of string buffer.
    85  * @return				Number of bytes written to the buffer (UTF-8 safe).
    86  * @error				Invalid string table index or string index.
    87  */
    88 native ReadStringTable(tableidx, stringIdx, String:str[], maxlength);
    89 
    90 /**
    91  * Returns the length of the user data associated with a given string index.
    92  *
    93  * @param tableidx		A string table index.
    94  * @param stringidx		A string index.
    95  * @return				Length of user data. This will be 0 if there is no user data.
    96  * @error				Invalid string table index or string index.
    97  */
    98 native GetStringTableDataLength(tableidx, stringidx);
    99 
   100 /**
   101  * Retrieves the user data associated with a given string index.
   102  *
   103  * @param tableidx		A string table index.
   104  * @param stringidx		A string index.
   105  * @param userdata		Buffer to store the user data. This will be set to "" if there is no user data.
   106  * @param maxlength		Maximum length of string buffer.
   107  * @return				Number of bytes written to the buffer (UTF-8 safe).
   108  * @error				Invalid string table index or string index.
   109  */
   110 native GetStringTableData(tableidx, stringIdx, String:userdata[], maxlength);
   111 
   112 /**
   113  * Sets the user data associated with a given string index.
   114  *
   115  * @param tableidx		A string table index.
   116  * @param stringidx		A string index.
   117  * @param userdata		User data string that will be set.
   118  * @param length		Length of user data string. This should include the null terminator.
   119  * @return				Number of bytes written to the buffer (UTF-8 safe).
   120  * @error				Invalid string table index or string index.
   121  */
   122 native SetStringTableData(tableidx, stringIdx, const String:userdata[], length);
   123 
   124 /**
   125  * Adds a string to a given string table.
   126  *
   127  * @param tableidx		A string table index.
   128  * @param string		String to add.
   129  * @param userdata		An optional user data string.
   130  * @param length		Length of user data string. This should include the null terminator.
   131  *						If set to -1, then user data will be not be altered if the specified string
   132  *						already exists in the string table.
   133  */
   134 native AddToStringTable(tableidx, const String:str[], const String:userdata[]="", length=-1);
   135 
   136 /**
   137  * Locks or unlocks the network string tables.
   138  *
   139  * @param lock			Determines whether network string tables should be locked.
   140  *						True means the tables should be locked for writing; false means unlocked.
   141  * @return				Previous lock state.
   142  */
   143 native bool:LockStringTables(bool:lock);
   144 
   145 /**
   146  * Adds a file to the downloadables network string table.
   147  * This forces a client to download the file if they do not already have it.
   148  *
   149  * @param filename		File that will be added to downloadables table.
   150  */
   151 stock AddFileToDownloadsTable(const String:filename[])
   152 {
   153 	static table = INVALID_STRING_TABLE;
   154 	
   155 	if (table == INVALID_STRING_TABLE)
   156 	{
   157 		table = FindStringTable("downloadables");
   158 	}
   159 	
   160 	new bool:save = LockStringTables(false);
   161 	AddToStringTable(table, filename);
   162 	LockStringTables(save);
   163 }