ds@1952: /** ds@1952: * vim: set ts=4 : ds@1952: * ============================================================================= ds@1952: * SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved. ds@1952: * ============================================================================= ds@1952: * ds@1952: * This file is part of the SourceMod/SourcePawn SDK. ds@1952: * ds@1952: * This program is free software; you can redistribute it and/or modify it under ds@1952: * the terms of the GNU General Public License, version 3.0, as published by the ds@1952: * Free Software Foundation. ds@1952: * ds@1952: * This program is distributed in the hope that it will be useful, but WITHOUT ds@1952: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS ds@1952: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ds@1952: * details. ds@1952: * ds@1952: * You should have received a copy of the GNU General Public License along with ds@1952: * this program. If not, see . ds@1952: * ds@1952: * As a special exception, AlliedModders LLC gives you permission to link the ds@1952: * code of this program (as well as its derivative works) to "Half-Life 2," the ds@1952: * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software ds@1952: * by the Valve Corporation. You must obey the GNU General Public License in ds@1952: * all respects for all other code used. Additionally, AlliedModders LLC grants ds@1952: * this exception to all derivative works. AlliedModders LLC defines further ds@1952: * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), ds@1952: * or . ds@1952: * ds@1952: * Version: $Id$ ds@1952: */ ds@1952: ds@1952: #if defined _sdktools_stringtables_included ds@1952: #endinput ds@1952: #endif ds@1952: #define _sdktools_stringtables_included ds@1952: ds@1952: #define INVALID_STRING_TABLE -1 /**< An invalid string table index */ ds@1952: #define INVALID_STRING_INDEX -1 /**< An invalid string index in a table */ ds@1952: ds@1952: /** ds@1952: * Searches for a string table. ds@1952: * ds@1952: * @param name Name of string table to find. ds@1952: * @return A string table index number if found, INVALID_STRING_TABLE otherwise. ds@1952: */ ds@1952: native FindStringTable(const String:name[]); ds@1952: ds@1952: /** ds@1952: * Returns the number of string tables that currently exist. ds@1952: * ds@1952: * @return Number of string tables that currently exist. ds@1952: */ ds@1952: native GetNumStringTables(); ds@1952: ds@1952: /** ds@1952: * Returns the number of strings that currently exist in a given string table. ds@1952: * ds@1952: * @param tableidx A string table index. ds@1952: * @return Number of strings that currently exist. ds@1952: * @error Invalid string table index. ds@1952: */ ds@1952: native GetStringTableNumStrings(tableidx); ds@1952: ds@1952: /** ds@1952: * Returns the maximum number of strings that are allowed in a given string table. ds@1952: * ds@1952: * @param tableidx A string table index. ds@1952: * @return Maximum number of strings allowed. ds@1952: * @error Invalid string table index. ds@1952: */ ds@1952: native GetStringTableMaxStrings(tableidx); ds@1952: ds@1952: /** ds@1952: * Retrieves the name of a string table. ds@1952: * ds@1952: * @param tableidx A string table index. ds@1952: * @param name Buffer to store the name of the string table. ds@1952: * @param maxlength Maximum length of string buffer. ds@1952: * @return Number of bytes written to the buffer (UTF-8 safe). ds@1952: * @error Invalid string table index. ds@1952: */ ds@1952: native GetStringTableName(tableidx, String:name[], maxlength); ds@1952: ds@1952: /** ds@1952: * Searches for the index of a given string in a string table. ds@1952: * ds@1952: * @param tableidx A string table index. ds@1952: * @param string String to find. ds@1952: * @return String index if found, INVALID_STRING_INDEX otherwise. ds@1952: * @error Invalid string table index. ds@1952: */ ds@1952: native FindStringIndex(tableidx, const String:str[]); ds@1952: ds@1952: /** ds@1952: * Retrieves the string at a given index of a string table. ds@1952: * ds@1952: * @param tableidx A string table index. ds@1952: * @param stringidx A string index. ds@1952: * @param name Buffer to store the string value. ds@1952: * @param maxlength Maximum length of string buffer. ds@1952: * @return Number of bytes written to the buffer (UTF-8 safe). ds@1952: * @error Invalid string table index or string index. ds@1952: */ ds@1952: native ReadStringTable(tableidx, stringIdx, String:str[], maxlength); ds@1952: ds@1952: /** ds@1952: * Returns the length of the user data associated with a given string index. ds@1952: * ds@1952: * @param tableidx A string table index. ds@1952: * @param stringidx A string index. ds@1952: * @return Length of user data. This will be 0 if there is no user data. ds@1952: * @error Invalid string table index or string index. ds@1952: */ ds@1952: native GetStringTableDataLength(tableidx, stringidx); ds@1952: ds@1952: /** ds@1952: * Retrieves the user data associated with a given string index. ds@1952: * ds@1952: * @param tableidx A string table index. ds@1952: * @param stringidx A string index. ds@1952: * @param userdata Buffer to store the user data. This will be set to "" if there is no user data. ds@1952: * @param maxlength Maximum length of string buffer. ds@1952: * @return Number of bytes written to the buffer (UTF-8 safe). ds@1952: * @error Invalid string table index or string index. ds@1952: */ ds@1952: native GetStringTableData(tableidx, stringIdx, String:userdata[], maxlength); ds@1952: ds@1952: /** ds@1952: * Sets the user data associated with a given string index. ds@1952: * ds@1952: * @param tableidx A string table index. ds@1952: * @param stringidx A string index. ds@1952: * @param userdata User data string that will be set. ds@1952: * @param length Length of user data string. This should include the null terminator. ds@1952: * @return Number of bytes written to the buffer (UTF-8 safe). ds@1952: * @error Invalid string table index or string index. ds@1952: */ ds@1952: native SetStringTableData(tableidx, stringIdx, const String:userdata[], length); ds@1952: ds@1952: /** ds@1952: * Adds a string to a given string table. ds@1952: * ds@1952: * @param tableidx A string table index. ds@1952: * @param string String to add. ds@1952: * @param userdata An optional user data string. ds@1952: * @param length Length of user data string. This should include the null terminator. ds@1952: * If set to -1, then user data will be not be altered if the specified string ds@1952: * already exists in the string table. ds@1952: */ ds@1952: native AddToStringTable(tableidx, const String:str[], const String:userdata[]="", length=-1); ds@1952: ds@1952: /** ds@1952: * Locks or unlocks the network string tables. ds@1952: * ds@1952: * @param lock Determines whether network string tables should be locked. ds@1952: * True means the tables should be locked for writing; false means unlocked. ds@1952: * @return Previous lock state. ds@1952: */ ds@1952: native bool:LockStringTables(bool:lock); ds@1952: ds@1952: /** ds@1952: * Adds a file to the downloadables network string table. ds@1952: * This forces a client to download the file if they do not already have it. ds@1952: * ds@1952: * @param filename File that will be added to downloadables table. ds@1952: */ ds@1952: stock AddFileToDownloadsTable(const String:filename[]) ds@1952: { ds@1952: static table = INVALID_STRING_TABLE; ds@1952: ds@1952: if (table == INVALID_STRING_TABLE) ds@1952: { ds@1952: table = FindStringTable("downloadables"); ds@1952: } ds@1952: ds@1952: new bool:save = LockStringTables(false); ds@1952: AddToStringTable(table, filename); ds@1952: LockStringTables(save); ds@1952: }