1.1 --- a/plugins/include/sourcemod.inc Fri Jul 11 06:51:21 2008 +0000
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,555 +0,0 @@
1.4 -/**
1.5 - * vim: set ts=4 :
1.6 - * =============================================================================
1.7 - * SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
1.8 - * =============================================================================
1.9 - *
1.10 - * This file is part of the SourceMod/SourcePawn SDK.
1.11 - *
1.12 - * This program is free software; you can redistribute it and/or modify it under
1.13 - * the terms of the GNU General Public License, version 3.0, as published by the
1.14 - * Free Software Foundation.
1.15 - *
1.16 - * This program is distributed in the hope that it will be useful, but WITHOUT
1.17 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.18 - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
1.19 - * details.
1.20 - *
1.21 - * You should have received a copy of the GNU General Public License along with
1.22 - * this program. If not, see <http://www.gnu.org/licenses/>.
1.23 - *
1.24 - * As a special exception, AlliedModders LLC gives you permission to link the
1.25 - * code of this program (as well as its derivative works) to "Half-Life 2," the
1.26 - * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
1.27 - * by the Valve Corporation. You must obey the GNU General Public License in
1.28 - * all respects for all other code used. Additionally, AlliedModders LLC grants
1.29 - * this exception to all derivative works. AlliedModders LLC defines further
1.30 - * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
1.31 - * or <http://www.sourcemod.net/license.php>.
1.32 - *
1.33 - * Version: $Id$
1.34 - */
1.35 -
1.36 -#if defined _sourcemod_included
1.37 - #endinput
1.38 -#endif
1.39 -#define _sourcemod_included
1.40 -
1.41 -/**
1.42 - * Plugin public information.
1.43 - */
1.44 -struct Plugin
1.45 -{
1.46 - const String:name[], /**< Plugin Name */
1.47 - const String:description[], /**< Plugin Description */
1.48 - const String:author[], /**< Plugin Author */
1.49 - const String:version[], /**< Plugin Version */
1.50 - const String:url[], /**< Plugin URL */
1.51 -};
1.52 -
1.53 -#include <core>
1.54 -#include <float>
1.55 -#include <vector>
1.56 -#include <string>
1.57 -#include <handles>
1.58 -#include <functions>
1.59 -#include <files>
1.60 -#include <logging>
1.61 -#include <timers>
1.62 -#include <admin>
1.63 -#include <dbi>
1.64 -#include <lang>
1.65 -#include <sorting>
1.66 -#include <textparse>
1.67 -#include <clients>
1.68 -#include <console>
1.69 -#include <events>
1.70 -#include <bitbuffer>
1.71 -#include <usermessages>
1.72 -#include <keyvalues>
1.73 -#include <menus>
1.74 -#include <halflife>
1.75 -#include <adt>
1.76 -#include <banning>
1.77 -#include <commandfilters>
1.78 -#include <nextmap>
1.79 -
1.80 -/**
1.81 - * Declare this as a struct in your plugin to expose its information.
1.82 - * Example:
1.83 - *
1.84 - * public Plugin:myinfo =
1.85 - * {
1.86 - * name = "My Plugin",
1.87 - * //etc
1.88 - * };
1.89 - */
1.90 -public Plugin:myinfo;
1.91 -
1.92 -/**
1.93 - * Called when the plugin is fully initialized and all known external references
1.94 - * are resolved. This is only called once in the lifetime of the plugin, and is
1.95 - * paired with OnPluginEnd().
1.96 - *
1.97 - * If any run-time error is thrown during this callback, the plugin will be marked
1.98 - * as failed.
1.99 - *
1.100 - * It is not necessary to close any handles or remove hooks in this function.
1.101 - * SourceMod guarantees that plugin shutdown automatically and correctly releases
1.102 - * all resources.
1.103 - *
1.104 - * @noreturn
1.105 - */
1.106 -forward OnPluginStart();
1.107 -
1.108 -/**
1.109 - * Called before OnPluginStart, in case the plugin wants to check for load failure.
1.110 - * This is called even if the plugin type is "private." Any natives from modules are
1.111 - * not available at this point. Thus, this forward should only be used for explicit
1.112 - * pre-emptive things, such as adding dynamic natives, or setting certain types of load filters.
1.113 - *
1.114 - * @note It is not safe to call externally resolved natives until OnPluginStart().
1.115 - * @note Any sort of RTE in this function will cause the plugin to fail loading.
1.116 - * @note You MUST remember to return SOMETHING here. The act of not returning is
1.117 - * equivalent to returning 0 (false). If you forgot to return, it will
1.118 - * cause your plugin to not load with a very strange error message.
1.119 - *
1.120 - * @param myself Handle to the plugin.
1.121 - * @param late Whether or not the plugin was loaded "late" (after map load).
1.122 - * @param error Error message buffer in case load failed.
1.123 - * @param err_max Maximum number of characters for error message buffer.
1.124 - * @return True if load success, false otherwise.
1.125 - */
1.126 -forward bool:AskPluginLoad(Handle:myself, bool:late, String:error[], err_max);
1.127 -
1.128 -/**
1.129 - * Called when the plugin is about to be unloaded.
1.130 - *
1.131 - * @noreturn
1.132 - */
1.133 -forward OnPluginEnd();
1.134 -
1.135 -/**
1.136 - * Called when the plugin's pause status is changing.
1.137 - *
1.138 - * @param pause True if the plugin is being paused, false otherwise.
1.139 - * @noreturn
1.140 - */
1.141 -forward OnPluginPauseChange(bool:pause);
1.142 -
1.143 -/**
1.144 - * Called before every server frame. Note that you should avoid
1.145 - * doing expensive computations here, and you should declare large
1.146 - * local arrays using 'decl' instead of 'new'.
1.147 - */
1.148 -forward OnGameFrame();
1.149 -
1.150 -/**
1.151 - * Called when the map is loaded.
1.152 - *
1.153 - * @note This used to be OnServerLoad(), which is now deprecated.
1.154 - * Plugins still using the old forward will work.
1.155 - */
1.156 -forward OnMapStart();
1.157 -
1.158 -/**
1.159 - * Called right before a map ends.
1.160 - */
1.161 -forward OnMapEnd();
1.162 -
1.163 -/**
1.164 - * Called when the map has loaded, servercfgfile (server.cfg) has been
1.165 - * executed, and all plugin configs are done executing. This is the best
1.166 - * place to initialize plugin functions which are based on cvar data.
1.167 - *
1.168 - * @note This will always be called once and only once per map. It will be
1.169 - * called after OnMapStart().
1.170 - *
1.171 - * @noreturn
1.172 - */
1.173 -forward OnConfigsExecuted();
1.174 -
1.175 -/**
1.176 - * This is called once, right after OnMapStart() but any time before
1.177 - * OnConfigsExecuted(). It is called after the "exec sourcemod.cfg"
1.178 - * command and all AutoExecConfig() exec commands have been added to
1.179 - * the ServerCommand() buffer.
1.180 - *
1.181 - * If you need to load per-map settings that override default values,
1.182 - * adding commands to the ServerCommand() buffer here will guarantee
1.183 - * that they're set before OnConfigsExecuted().
1.184 - *
1.185 - * Unlike OnMapStart() and OnConfigsExecuted(), this is not called on
1.186 - * late loads that occur after OnMapStart().
1.187 - *
1.188 - * @noreturn
1.189 - */
1.190 -forward OnAutoConfigsBuffered();
1.191 -
1.192 -/**
1.193 - * @deprecated Use OnConfigsExecuted() instead.
1.194 - */
1.195 -#pragma deprecated Use OnConfigsExecuted() instead
1.196 -forward OnServerCfg();
1.197 -
1.198 -/**
1.199 - * Called after all plugins have been loaded. This is called once for
1.200 - * every plugin. If a plugin late loads, it will be called immediately
1.201 - * after OnPluginStart().
1.202 - */
1.203 -forward OnAllPluginsLoaded();
1.204 -
1.205 -/**
1.206 - * Returns the calling plugin's Handle.
1.207 - *
1.208 - * @return Handle of the calling plugin.
1.209 - */
1.210 -native Handle:GetMyHandle();
1.211 -
1.212 -/**
1.213 - * Returns an iterator that can be used to search through plugins.
1.214 - *
1.215 - * @return Handle to iterate with. Must be closed via
1.216 - * CloseHandle().
1.217 - * @error Invalid Handle.
1.218 - */
1.219 -native Handle:GetPluginIterator();
1.220 -
1.221 -/**
1.222 - * Returns whether there are more plugins available in the iterator.
1.223 - *
1.224 - * @param iter Handle to the plugin iterator.
1.225 - * @return True on more plugins, false otherwise.
1.226 - * @error Invalid Handle.
1.227 - */
1.228 -native bool:MorePlugins(Handle:iter);
1.229 -
1.230 -/**
1.231 - * Returns the current plugin in the iterator and advances the iterator.
1.232 - *
1.233 - * @param iter Handle to the plugin iterator.
1.234 - * @return Current plugin the iterator is at, before
1.235 - * the iterator is advanced.
1.236 - * @error Invalid Handle.
1.237 - */
1.238 -native Handle:ReadPlugin(Handle:iter);
1.239 -
1.240 -/**
1.241 - * Returns a plugin's status.
1.242 - *
1.243 - * @param plugin Plugin Handle (INVALID_HANDLE uses the calling plugin).
1.244 - * @return Status code for the plugin.
1.245 - * @error Invalid Handle.
1.246 - */
1.247 -native PluginStatus:GetPluginStatus(Handle:plugin);
1.248 -
1.249 -/**
1.250 - * Retrieves a plugin's file name relative to the plugins folder.
1.251 - *
1.252 - * @param plugin Plugin Handle (INVALID_HANDLE uses the calling plugin).
1.253 - * @param buffer Buffer to the store the file name.
1.254 - * @param maxlength Maximum length of the name buffer.
1.255 - * @noreturn
1.256 - * @error Invalid Handle.
1.257 - */
1.258 -native GetPluginFilename(Handle:plugin, String:buffer[], maxlength);
1.259 -
1.260 -/**
1.261 - * Retrieves whether or not a plugin is being debugged.
1.262 - *
1.263 - * @param plugin Plugin Handle (INVALID_HANDLE uses the calling plugin).
1.264 - * @return True if being debugged, false otherwise.
1.265 - * @error Invalid Handle.
1.266 - */
1.267 -native bool:IsPluginDebugging(Handle:hndl);
1.268 -
1.269 -/**
1.270 - * Retrieves a plugin's public info.
1.271 - *
1.272 - * @param plugin Plugin Handle (INVALID_HANDLE uses the calling plugin).
1.273 - * @param info Plugin info property to retrieve.
1.274 - * @param buffer Buffer to store info in.
1.275 - * @param maxlength Maximum length of buffer.
1.276 - * @return True on success, false if property is not available.
1.277 - * @error Invalid Handle.
1.278 - */
1.279 -native bool:GetPluginInfo(Handle:plugin, PluginInfo:info, String:buffer[], maxlength);
1.280 -
1.281 -/**
1.282 - * Finds a plugin by its order in the list from the "plugins list" server
1.283 - * "sm" command. You should not use this function to loop through all plugins,
1.284 - * use the iterator instead. Looping through all plugins using this native
1.285 - * is O(n^2), whereas using the iterator is O(n).
1.286 - *
1.287 - * @param order_num Number of the plugin as it appears in "sm plugins list".
1.288 - * @return Plugin Handle on success, INVALID_HANDLE if no plugin
1.289 - * matches the given number.
1.290 - */
1.291 -native Handle:FindPluginByNumber(order_num);
1.292 -
1.293 -/**
1.294 - * Causes the plugin to enter a failed state. An error will be thrown and
1.295 - * the plugin will be paused until it is unloaded or reloaded.
1.296 - *
1.297 - * For backwards compatibility, if no extra arguments are passed, no
1.298 - * formatting is applied. If one or more additional arguments is passed,
1.299 - * the string is formatted using Format(). If any errors are encountered
1.300 - * during formatting, both the format specifier string and an additional
1.301 - * error message are written.
1.302 - *
1.303 - * This function does not return, and no further code in the plugin is
1.304 - * executed.
1.305 - *
1.306 - * @param string Format specifier string.
1.307 - * @param ... Formatting arguments.
1.308 - * @noreturn
1.309 - * @error Always throws SP_ERROR_ABORT.
1.310 - */
1.311 -native SetFailState(const String:string[], any:...);
1.312 -
1.313 -/**
1.314 - * Aborts the current callback and throws an error. This function
1.315 - * does not return in that no code is executed following it.
1.316 - *
1.317 - * @param format String format.
1.318 - * @param ... Format arguments.
1.319 - * @noreturn
1.320 - * @error Always!
1.321 - */
1.322 -native ThrowError(const String:fmt[], any:...);
1.323 -
1.324 -/**
1.325 - * Gets the system time as a unix timestamp.
1.326 - *
1.327 - * @param bigStamp Optional array to store the 64bit timestamp in.
1.328 - * @return 32bit timestamp (number of seconds since unix epoch).
1.329 - */
1.330 -native GetTime(bigStamp[2]={0,0});
1.331 -
1.332 -/**
1.333 - * Produces a date and/or time string value for a timestamp.
1.334 - *
1.335 - * See this URL for valid parameters:
1.336 - * http://cplusplus.com/reference/clibrary/ctime/strftime.html
1.337 - *
1.338 - * @param buffer Destination string buffer.
1.339 - * @param maxlength Maximum length of output string buffer.
1.340 - * @param format Formatting rules (passing NULL_STRING will use the rules defined in sm_datetime_format).
1.341 - * @param stamp Optional time stamp.
1.342 - * @noreturn
1.343 - * @error Buffer too small or invalid time format.
1.344 - */
1.345 -native FormatTime(String:buffer[], maxlength, const String:format[], stamp=-1);
1.346 -
1.347 -/**
1.348 - * Loads a game config file.
1.349 - *
1.350 - * @param file File to load. The path must be relative to the 'gamedata' folder under the config folder
1.351 - * and the extension should be omitted.
1.352 - * @return A handle to the game config file or INVALID_HANDLE in failure.
1.353 - */
1.354 -native Handle:LoadGameConfigFile(const String:file[]);
1.355 -
1.356 -/**
1.357 - * Returns an offset value.
1.358 - *
1.359 - * @param gc Game config handle.
1.360 - * @param key Key to retrieve from the offset section.
1.361 - * @return An offset, or -1 on failure.
1.362 - */
1.363 -native GameConfGetOffset(Handle:gc, const String:key[]);
1.364 -
1.365 -/**
1.366 - * Gets the value of a key from the "Keys" section.
1.367 - *
1.368 - * @param gc Game config handle.
1.369 - * @param key Key to retrieve from the Keys section.
1.370 - * @param buffer Destination string buffer.
1.371 - * @param maxlen Maximum length of output string buffer.
1.372 - * @return True if key existed, false otherwise.
1.373 - */
1.374 -native bool:GameConfGetKeyValue(Handle:gc, const String:key[], String:buffer[], maxlen);
1.375 -
1.376 -/**
1.377 - * Returns the operating system's "tick count," which is a number of
1.378 - * milliseconds since the operating system loaded. This can be used
1.379 - * for basic benchmarks.
1.380 - *
1.381 - * @return Tick count in milliseconds.
1.382 - */
1.383 -native GetSysTickCount();
1.384 -
1.385 -/**
1.386 - * Specifies that the given config file should be executed after plugin load.
1.387 - * OnConfigsExecuted() will not be called until the config file has executed,
1.388 - * but it will be called if the execution fails.
1.389 - *
1.390 - * @param autoCreate If true, and the config file does not exist, such a config
1.391 - * file will be automatically created and populated with
1.392 - * information from the plugin's registered cvars.
1.393 - * @param name Name of the config file, excluding the .cfg extension.
1.394 - * If empty, <plugin.filename.cfg> is assumed.
1.395 - * @param folder Folder under cfg/ to use. By default this is "sourcemod."
1.396 - * @noreturn
1.397 - */
1.398 -native AutoExecConfig(bool:autoCreate=true, const String:name[]="", const String:folder[]="sourcemod");
1.399 -
1.400 -/**
1.401 - * Sets a native as optional, such that if it is unloaded, removed,
1.402 - * or otherwise non-existent, the plugin will still work. Calling
1.403 - * removed natives results in a run-time error.
1.404 - *
1.405 - * @param name Native name.
1.406 - * @noreturn
1.407 - */
1.408 -native MarkNativeAsOptional(const String:name[]);
1.409 -
1.410 -/**
1.411 - * Registers a library name for identifying as a dependency to
1.412 - * other plugins.
1.413 - *
1.414 - * @param name Library name.
1.415 - * @noreturn
1.416 - */
1.417 -native RegPluginLibrary(const String:name[]);
1.418 -
1.419 -/**
1.420 - * Returns whether a library exists. This function should be considered
1.421 - * expensive; it should only be called on plugin to determine availability
1.422 - * of resources. Use OnLibraryAdded()/OnLibraryRemoved() to detect changes
1.423 - * in optional resources.
1.424 - *
1.425 - * @param name Library name of a plugin or extension.
1.426 - * @return True if exists, false otherwise.
1.427 - */
1.428 -native bool:LibraryExists(const String:name[]);
1.429 -
1.430 -/**
1.431 - * Returns the status of an extension, by filename.
1.432 - *
1.433 - * @param name Extension name (like "sdktools.ext").
1.434 - * @param error Optional error message buffer.
1.435 - * @param maxlength Length of optional error message buffer.
1.436 - * @return -2 if the extension was not found.
1.437 - * -1 if the extension was found but failed to load.
1.438 - * 0 if the extension loaded but reported an error.
1.439 - * 1 if the extension is running without error.
1.440 - */
1.441 -native GetExtensionFileStatus(const String:name[], String:error[]="", maxlength=0);
1.442 -
1.443 -/**
1.444 - * Called after a library is added that the current plugin references
1.445 - * optionally. A library is either a plugin name or extension name, as
1.446 - * exposed via its include file.
1.447 - *
1.448 - * @param name Library name.
1.449 - */
1.450 -forward OnLibraryAdded(const String:name[]);
1.451 -
1.452 -/**
1.453 - * Called right before a library is removed that the current plugin references
1.454 - * optionally. A library is either a plugin name or extension name, as
1.455 - * exposed via its include file.
1.456 - *
1.457 - * @param name Library name.
1.458 - */
1.459 -forward OnLibraryRemoved(const String:name[]);
1.460 -
1.461 -#define MAPLIST_FLAG_MAPSFOLDER (1<<0) /**< On failure, use all maps in the maps folder. */
1.462 -#define MAPLIST_FLAG_CLEARARRAY (1<<1) /**< If an input array is specified, clear it before adding. */
1.463 -#define MAPLIST_FLAG_NO_DEFAULT (1<<2) /**< Do not read "default" or "mapcyclefile" on failure. */
1.464 -
1.465 -/**
1.466 - * Loads a map list to an ADT Array.
1.467 - *
1.468 - * A map list is a list of maps from a file. SourceMod allows easy configuration of
1.469 - * maplists through addons/sourcemod/configs/maplists.cfg. Each entry is given a
1.470 - * name and a file (for example, "rtv" => "rtv.cfg"), or a name and a redirection
1.471 - * (for example, "rtv" => "default"). This native will read a map list entry,
1.472 - * cache the file, and return the list of maps it holds.
1.473 - *
1.474 - * Serial change numbers are used to identify if a map list has changed. Thus, if
1.475 - * you pass a serial change number and it's equal to what SourceMod currently knows
1.476 - * about the map list, then SourceMod won't reparse the file.
1.477 - *
1.478 - * If the maps end up being read from the maps folder (MAPLIST_FLAG_MAPSFOLDER), they
1.479 - * are automatically sorted in alphabetical, ascending order.
1.480 - *
1.481 - * Arrays created by this function are temporary and must be freed via CloseHandle().
1.482 - * Modifying arrays created by this function will not affect future return values or
1.483 - * or the contents of arrays returned to other plugins.
1.484 - *
1.485 - * @param array Array to store the map list. If INVALID_HANDLE, a new blank
1.486 - * array will be created. The blocksize should be at least 16;
1.487 - * otherwise results may be truncated. Items are added to the array
1.488 - * as strings. The array is never checked for duplicates, and it is
1.489 - * not read beforehand. Only the serial number is used to detect
1.490 - * changes.
1.491 - * @param serial Serial number to identify last known map list change. If -1, the
1.492 - * the value will not be checked. If the map list has since changed,
1.493 - * the serial is updated (even if -1 was passed). If there is an error
1.494 - * finding a valid maplist, then the serial is set to -1.
1.495 - * @param str Config name, or "default" for the default map list. Config names
1.496 - * should be somewhat descriptive. For example, the admin menu uses
1.497 - * a config name of "admin menu". The list names can be configured
1.498 - * by users in addons/sourcemod/configs/maplists.cfg.
1.499 - * @param flags MAPLIST_FLAG flags.
1.500 - * @return On failure:
1.501 - * INVALID_HANDLE is returned, the serial is set to -1, and the input
1.502 - * array (if any) is left unchanged.
1.503 - * On no change:
1.504 - INVALID_HANDLE is returned, the serial is unchanged, and the input
1.505 - array (if any) is left unchanged.
1.506 - * On success:
1.507 - * A valid array Handle is returned, containing at least one map string.
1.508 - * If an array was passed, the return value is equal to the passed Array
1.509 - * Handle. If the passed array was not cleared, it will have grown by at
1.510 - * least one item. The serial number is updated to a positive number.
1.511 - * @error Invalid array Handle that is not INVALID_HANDLE.
1.512 - */
1.513 -native Handle:ReadMapList(Handle:array=INVALID_HANDLE,
1.514 - &serial=-1,
1.515 - const String:str[]="default",
1.516 - flags=MAPLIST_FLAG_CLEARARRAY);
1.517 -
1.518 -/**
1.519 - * Makes a compatibility binding for map lists. For example, if a function previously used
1.520 - * "clam.cfg" for map lists, this function will insert a "fake" binding to "clam.cfg" that
1.521 - * will be overridden if it's in the maplists.cfg file.
1.522 - *
1.523 - * @param name Configuration name that would be used with ReadMapList().
1.524 - * @param file Default file to use.
1.525 - * @noreturn
1.526 - */
1.527 -native SetMapListCompatBind(const String:name[], const String:file[]);
1.528 -
1.529 -/**
1.530 - * Called when a client has sent chat text. This must return either true or
1.531 - * false to indicate that a client is or is not spamming the server.
1.532 - *
1.533 - * The return value is a hint only. Core or another plugin may decide
1.534 - * otherwise.
1.535 - *
1.536 - * @param client Client index. The server (0) will never be passed.
1.537 - * @return True if client is spamming the server, false otherwise.
1.538 - */
1.539 -forward bool:OnClientFloodCheck(client);
1.540 -
1.541 -/**
1.542 - * Called after a client's flood check has been computed. This can be used
1.543 - * by antiflood algorithms to decay/increase flooding weights.
1.544 - *
1.545 - * Since the result from "OnClientFloodCheck" isn't guaranteed to be the
1.546 - * final result, it is generally a good idea to use this to play with other
1.547 - * algorithms nicely.
1.548 - *
1.549 - * @param client Client index. The server (0) will never be passed.
1.550 - * @param blocked True if client flooded last "say", false otherwise.
1.551 - * @noreturn
1.552 - */
1.553 -forward OnClientFloodResult(client, bool:blocked);
1.554 -
1.555 -#include <helpers>
1.556 -#include <entity>
1.557 -#include <entity_prop_stocks>
1.558 -