plugins/include/sdktools_stringtables.inc
author David Anderson <dvander@alliedmods.net>
Tue Sep 02 03:58:34 2008 +0000 (2008-09-02)
changeset 2245 d8518466c06c
parent 1952 b7aa2b626807
child 2289 44045ead61cd
permissions -rw-r--r--
Fixed amb1927 - client command case sensitivity did not match the server's logic.
ds@1952
     1
/**
ds@1952
     2
 * vim: set ts=4 :
ds@1952
     3
 * =============================================================================
ds@1952
     4
 * SourceMod (C)2004-2008 AlliedModders LLC.  All rights reserved.
ds@1952
     5
 * =============================================================================
ds@1952
     6
 *
ds@1952
     7
 * This file is part of the SourceMod/SourcePawn SDK.
ds@1952
     8
 *
ds@1952
     9
 * This program is free software; you can redistribute it and/or modify it under
ds@1952
    10
 * the terms of the GNU General Public License, version 3.0, as published by the
ds@1952
    11
 * Free Software Foundation.
ds@1952
    12
 * 
ds@1952
    13
 * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1952
    14
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1952
    15
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
ds@1952
    16
 * details.
ds@1952
    17
 *
ds@1952
    18
 * You should have received a copy of the GNU General Public License along with
ds@1952
    19
 * this program.  If not, see <http://www.gnu.org/licenses/>.
ds@1952
    20
 *
ds@1952
    21
 * As a special exception, AlliedModders LLC gives you permission to link the
ds@1952
    22
 * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1952
    23
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1952
    24
 * by the Valve Corporation.  You must obey the GNU General Public License in
ds@1952
    25
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
ds@1952
    26
 * this exception to all derivative works.  AlliedModders LLC defines further
ds@1952
    27
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1952
    28
 * or <http://www.sourcemod.net/license.php>.
ds@1952
    29
 *
ds@1952
    30
 * Version: $Id$
ds@1952
    31
 */
ds@1952
    32
ds@1952
    33
#if defined _sdktools_stringtables_included
ds@1952
    34
  #endinput
ds@1952
    35
#endif
ds@1952
    36
#define _sdktools_stringtables_included
ds@1952
    37
ds@1952
    38
#define INVALID_STRING_TABLE -1		/**< An invalid string table index */
ds@1952
    39
#define INVALID_STRING_INDEX -1		/**< An invalid string index in a table */
ds@1952
    40
ds@1952
    41
/**
ds@1952
    42
 * Searches for a string table.
ds@1952
    43
 *
ds@1952
    44
 * @param name			Name of string table to find.
ds@1952
    45
 * @return				A string table index number if found, INVALID_STRING_TABLE otherwise.
ds@1952
    46
 */
ds@1952
    47
native FindStringTable(const String:name[]);
ds@1952
    48
ds@1952
    49
/**
ds@1952
    50
 * Returns the number of string tables that currently exist.
ds@1952
    51
 *
ds@1952
    52
 * @return				Number of string tables that currently exist.
ds@1952
    53
 */
ds@1952
    54
native GetNumStringTables();
ds@1952
    55
ds@1952
    56
/**
ds@1952
    57
 * Returns the number of strings that currently exist in a given string table.
ds@1952
    58
 *
ds@1952
    59
 * @param tableidx		A string table index.
ds@1952
    60
 * @return				Number of strings that currently exist.
ds@1952
    61
 * @error				Invalid string table index.
ds@1952
    62
 */
ds@1952
    63
native GetStringTableNumStrings(tableidx);
ds@1952
    64
ds@1952
    65
/**
ds@1952
    66
 * Returns the maximum number of strings that are allowed in a given string table.
ds@1952
    67
 *
ds@1952
    68
 * @param tableidx		A string table index.
ds@1952
    69
 * @return				Maximum number of strings allowed.
ds@1952
    70
 * @error				Invalid string table index.
ds@1952
    71
 */
ds@1952
    72
native GetStringTableMaxStrings(tableidx);
ds@1952
    73
ds@1952
    74
/**
ds@1952
    75
 * Retrieves the name of a string table.
ds@1952
    76
 *
ds@1952
    77
 * @param tableidx		A string table index.
ds@1952
    78
 * @param name			Buffer to store the name of the string table.
ds@1952
    79
 * @param maxlength		Maximum length of string buffer.
ds@1952
    80
 * @return				Number of bytes written to the buffer (UTF-8 safe).
ds@1952
    81
 * @error				Invalid string table index.
ds@1952
    82
 */
ds@1952
    83
native GetStringTableName(tableidx, String:name[], maxlength);
ds@1952
    84
ds@1952
    85
/**
ds@1952
    86
 * Searches for the index of a given string in a string table.
ds@1952
    87
 *
ds@1952
    88
 * @param tableidx		A string table index.
ds@1952
    89
 * @param string		String to find.
ds@1952
    90
 * @return				String index if found, INVALID_STRING_INDEX otherwise.
ds@1952
    91
 * @error				Invalid string table index.
ds@1952
    92
 */
ds@1952
    93
native FindStringIndex(tableidx, const String:str[]);
ds@1952
    94
ds@1952
    95
/**
ds@1952
    96
 * Retrieves the string at a given index of a string table.
ds@1952
    97
 *
ds@1952
    98
 * @param tableidx		A string table index.
ds@1952
    99
 * @param stringidx		A string index.
ds@1952
   100
 * @param name			Buffer to store the string value.
ds@1952
   101
 * @param maxlength		Maximum length of string buffer.
ds@1952
   102
 * @return				Number of bytes written to the buffer (UTF-8 safe).
ds@1952
   103
 * @error				Invalid string table index or string index.
ds@1952
   104
 */
ds@1952
   105
native ReadStringTable(tableidx, stringIdx, String:str[], maxlength);
ds@1952
   106
ds@1952
   107
/**
ds@1952
   108
 * Returns the length of the user data associated with a given string index.
ds@1952
   109
 *
ds@1952
   110
 * @param tableidx		A string table index.
ds@1952
   111
 * @param stringidx		A string index.
ds@1952
   112
 * @return				Length of user data. This will be 0 if there is no user data.
ds@1952
   113
 * @error				Invalid string table index or string index.
ds@1952
   114
 */
ds@1952
   115
native GetStringTableDataLength(tableidx, stringidx);
ds@1952
   116
ds@1952
   117
/**
ds@1952
   118
 * Retrieves the user data associated with a given string index.
ds@1952
   119
 *
ds@1952
   120
 * @param tableidx		A string table index.
ds@1952
   121
 * @param stringidx		A string index.
ds@1952
   122
 * @param userdata		Buffer to store the user data. This will be set to "" if there is no user data.
ds@1952
   123
 * @param maxlength		Maximum length of string buffer.
ds@1952
   124
 * @return				Number of bytes written to the buffer (UTF-8 safe).
ds@1952
   125
 * @error				Invalid string table index or string index.
ds@1952
   126
 */
ds@1952
   127
native GetStringTableData(tableidx, stringIdx, String:userdata[], maxlength);
ds@1952
   128
ds@1952
   129
/**
ds@1952
   130
 * Sets the user data associated with a given string index.
ds@1952
   131
 *
ds@1952
   132
 * @param tableidx		A string table index.
ds@1952
   133
 * @param stringidx		A string index.
ds@1952
   134
 * @param userdata		User data string that will be set.
ds@1952
   135
 * @param length		Length of user data string. This should include the null terminator.
ds@1952
   136
 * @return				Number of bytes written to the buffer (UTF-8 safe).
ds@1952
   137
 * @error				Invalid string table index or string index.
ds@1952
   138
 */
ds@1952
   139
native SetStringTableData(tableidx, stringIdx, const String:userdata[], length);
ds@1952
   140
ds@1952
   141
/**
ds@1952
   142
 * Adds a string to a given string table.
ds@1952
   143
 *
ds@1952
   144
 * @param tableidx		A string table index.
ds@1952
   145
 * @param string		String to add.
ds@1952
   146
 * @param userdata		An optional user data string.
ds@1952
   147
 * @param length		Length of user data string. This should include the null terminator.
ds@1952
   148
 *						If set to -1, then user data will be not be altered if the specified string
ds@1952
   149
 *						already exists in the string table.
ds@1952
   150
 */
ds@1952
   151
native AddToStringTable(tableidx, const String:str[], const String:userdata[]="", length=-1);
ds@1952
   152
ds@1952
   153
/**
ds@1952
   154
 * Locks or unlocks the network string tables.
ds@1952
   155
 *
ds@1952
   156
 * @param lock			Determines whether network string tables should be locked.
ds@1952
   157
 *						True means the tables should be locked for writing; false means unlocked.
ds@1952
   158
 * @return				Previous lock state.
ds@1952
   159
 */
ds@1952
   160
native bool:LockStringTables(bool:lock);
ds@1952
   161
ds@1952
   162
/**
ds@1952
   163
 * Adds a file to the downloadables network string table.
ds@1952
   164
 * This forces a client to download the file if they do not already have it.
ds@1952
   165
 *
ds@1952
   166
 * @param filename		File that will be added to downloadables table.
ds@1952
   167
 */
ds@1952
   168
stock AddFileToDownloadsTable(const String:filename[])
ds@1952
   169
{
ds@1952
   170
	static table = INVALID_STRING_TABLE;
ds@1952
   171
	
ds@1952
   172
	if (table == INVALID_STRING_TABLE)
ds@1952
   173
	{
ds@1952
   174
		table = FindStringTable("downloadables");
ds@1952
   175
	}
ds@1952
   176
	
ds@1952
   177
	new bool:save = LockStringTables(false);
ds@1952
   178
	AddToStringTable(table, filename);
ds@1952
   179
	LockStringTables(save);
ds@1952
   180
}