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 _sourcemod_included
ds@1952: #endinput
ds@1952: #endif
ds@1952: #define _sourcemod_included
ds@1952:
ds@1952: /**
ds@1952: * Plugin public information.
ds@1952: */
ds@1952: struct Plugin
ds@1952: {
ds@1952: const String:name[], /**< Plugin Name */
ds@1952: const String:description[], /**< Plugin Description */
ds@1952: const String:author[], /**< Plugin Author */
ds@1952: const String:version[], /**< Plugin Version */
ds@1952: const String:url[], /**< Plugin URL */
ds@1952: };
ds@1952:
ds@1952: #include
ds@1952: #include
ds@1952: #include
ds@1952: #include
ds@1952: #include
ds@1952: #include
ds@1952: #include
ds@1952: #include
ds@1952: #include
ds@1952: #include
ds@1952: #include
ds@1952: #include
ds@1952: #include
ds@1952: #include
ds@1952: #include
ds@1952: #include
ds@1952: #include
ds@1952: #include
ds@1952: #include
ds@1952: #include
ds@1952: #include
ds@1952: #include
ds@1952: #include
ds@1952: #include
ds@1952: #include
ds@1952:
ds@1952: /**
ds@1952: * Declare this as a struct in your plugin to expose its information.
ds@1952: * Example:
ds@1952: *
ds@1952: * public Plugin:myinfo =
ds@1952: * {
ds@1952: * name = "My Plugin",
ds@1952: * //etc
ds@1952: * };
ds@1952: */
ds@1952: public Plugin:myinfo;
ds@1952:
ds@1952: /**
ds@1952: * Called when the plugin is fully initialized and all known external references
ds@1952: * are resolved. This is only called once in the lifetime of the plugin, and is
ds@1952: * paired with OnPluginEnd().
ds@1952: *
ds@1952: * If any run-time error is thrown during this callback, the plugin will be marked
ds@1952: * as failed.
ds@1952: *
ds@1952: * It is not necessary to close any handles or remove hooks in this function.
ds@1952: * SourceMod guarantees that plugin shutdown automatically and correctly releases
ds@1952: * all resources.
ds@1952: *
ds@1952: * @noreturn
ds@1952: */
ds@1952: forward OnPluginStart();
ds@1952:
ds@1952: /**
ds@1952: * Called before OnPluginStart, in case the plugin wants to check for load failure.
ds@1952: * This is called even if the plugin type is "private." Any natives from modules are
ds@1952: * not available at this point. Thus, this forward should only be used for explicit
ds@1952: * pre-emptive things, such as adding dynamic natives, or setting certain types of load filters.
ds@1952: *
ds@1952: * @note It is not safe to call externally resolved natives until OnPluginStart().
ds@1952: * @note Any sort of RTE in this function will cause the plugin to fail loading.
ds@1952: * @note You MUST remember to return SOMETHING here. The act of not returning is
ds@1952: * equivalent to returning 0 (false). If you forgot to return, it will
ds@1952: * cause your plugin to not load with a very strange error message.
ds@1952: *
ds@1952: * @param myself Handle to the plugin.
ds@1952: * @param late Whether or not the plugin was loaded "late" (after map load).
ds@1952: * @param error Error message buffer in case load failed.
ds@1952: * @param err_max Maximum number of characters for error message buffer.
ds@1952: * @return True if load success, false otherwise.
ds@1952: */
ds@1952: forward bool:AskPluginLoad(Handle:myself, bool:late, String:error[], err_max);
ds@1952:
ds@1952: /**
ds@1952: * Called when the plugin is about to be unloaded.
ds@1952: *
ds@1952: * @noreturn
ds@1952: */
ds@1952: forward OnPluginEnd();
ds@1952:
ds@1952: /**
ds@1952: * Called when the plugin's pause status is changing.
ds@1952: *
ds@1952: * @param pause True if the plugin is being paused, false otherwise.
ds@1952: * @noreturn
ds@1952: */
ds@1952: forward OnPluginPauseChange(bool:pause);
ds@1952:
ds@1952: /**
ds@1952: * Called before every server frame. Note that you should avoid
ds@1952: * doing expensive computations here, and you should declare large
ds@1952: * local arrays using 'decl' instead of 'new'.
ds@1952: */
ds@1952: forward OnGameFrame();
ds@1952:
ds@1952: /**
ds@1952: * Called when the map is loaded.
ds@1952: *
ds@1952: * @note This used to be OnServerLoad(), which is now deprecated.
ds@1952: * Plugins still using the old forward will work.
ds@1952: */
ds@1952: forward OnMapStart();
ds@1952:
ds@1952: /**
ds@1952: * Called right before a map ends.
ds@1952: */
ds@1952: forward OnMapEnd();
ds@1952:
ds@1952: /**
ds@1952: * Called when the map has loaded, servercfgfile (server.cfg) has been
ds@1952: * executed, and all plugin configs are done executing. This is the best
ds@1952: * place to initialize plugin functions which are based on cvar data.
ds@1952: *
ds@1952: * @note This will always be called once and only once per map. It will be
ds@1952: * called after OnMapStart().
ds@1952: *
ds@1952: * @noreturn
ds@1952: */
ds@1952: forward OnConfigsExecuted();
ds@1952:
ds@1952: /**
ds@1952: * @deprecated Use OnConfigsExecuted() instead.
ds@1952: */
ds@1952: #pragma deprecated Use OnConfigsExecuted() instead
ds@1952: forward OnServerCfg();
ds@1952:
ds@1952: /**
ds@1952: * Called after all plugins have been loaded. This is called once for
ds@1952: * every plugin. If a plugin late loads, it will be called immediately
ds@1952: * after OnPluginStart().
ds@1952: */
ds@1952: forward OnAllPluginsLoaded();
ds@1952:
ds@1952: /**
ds@1952: * Returns the calling plugin's Handle.
ds@1952: *
ds@1952: * @return Handle of the calling plugin.
ds@1952: */
ds@1952: native Handle:GetMyHandle();
ds@1952:
ds@1952: /**
ds@1952: * Returns an iterator that can be used to search through plugins.
ds@1952: *
ds@1952: * @return Handle to iterate with. Must be closed via
ds@1952: * CloseHandle().
ds@1952: * @error Invalid Handle.
ds@1952: */
ds@1952: native Handle:GetPluginIterator();
ds@1952:
ds@1952: /**
ds@1952: * Returns whether there are more plugins available in the iterator.
ds@1952: *
ds@1952: * @param iter Handle to the plugin iterator.
ds@1952: * @return True on more plugins, false otherwise.
ds@1952: * @error Invalid Handle.
ds@1952: */
ds@1952: native bool:MorePlugins(Handle:iter);
ds@1952:
ds@1952: /**
ds@1952: * Returns the current plugin in the iterator and advances the iterator.
ds@1952: *
ds@1952: * @param iter Handle to the plugin iterator.
ds@1952: * @return Current plugin the iterator is at, before
ds@1952: * the iterator is advanced.
ds@1952: * @error Invalid Handle.
ds@1952: */
ds@1952: native Handle:ReadPlugin(Handle:iter);
ds@1952:
ds@1952: /**
ds@1952: * Returns a plugin's status.
ds@1952: *
ds@1952: * @param plugin Plugin Handle (INVALID_HANDLE uses the calling plugin).
ds@1952: * @return Status code for the plugin.
ds@1952: * @error Invalid Handle.
ds@1952: */
ds@1952: native PluginStatus:GetPluginStatus(Handle:plugin);
ds@1952:
ds@1952: /**
ds@1952: * Retrieves a plugin's file name relative to the plugins folder.
ds@1952: *
ds@1952: * @param plugin Plugin Handle (INVALID_HANDLE uses the calling plugin).
ds@1952: * @param buffer Buffer to the store the file name.
ds@1952: * @param maxlength Maximum length of the name buffer.
ds@1952: * @noreturn
ds@1952: * @error Invalid Handle.
ds@1952: */
ds@1952: native GetPluginFilename(Handle:plugin, String:buffer[], maxlength);
ds@1952:
ds@1952: /**
ds@1952: * Retrieves whether or not a plugin is being debugged.
ds@1952: *
ds@1952: * @param plugin Plugin Handle (INVALID_HANDLE uses the calling plugin).
ds@1952: * @return True if being debugged, false otherwise.
ds@1952: * @error Invalid Handle.
ds@1952: */
ds@1952: native bool:IsPluginDebugging(Handle:hndl);
ds@1952:
ds@1952: /**
ds@1952: * Retrieves a plugin's public info.
ds@1952: *
ds@1952: * @param plugin Plugin Handle (INVALID_HANDLE uses the calling plugin).
ds@1952: * @param info Plugin info property to retrieve.
ds@1952: * @param buffer Buffer to store info in.
ds@1952: * @param maxlength Maximum length of buffer.
ds@1952: * @return True on success, false if property is not available.
ds@1952: * @error Invalid Handle.
ds@1952: */
ds@1952: native bool:GetPluginInfo(Handle:plugin, PluginInfo:info, String:buffer[], maxlength);
ds@1952:
ds@1952: /**
ds@1952: * Finds a plugin by its order in the list from the "plugins list" server
ds@1952: * "sm" command. You should not use this function to loop through all plugins,
ds@1952: * use the iterator instead. Looping through all plugins using this native
ds@1952: * is O(n^2), whereas using the iterator is O(n).
ds@1952: *
ds@1952: * @param order_num Number of the plugin as it appears in "sm plugins list".
ds@1952: * @return Plugin Handle on success, INVALID_HANDLE if no plugin
ds@1952: * matches the given number.
ds@1952: */
ds@1952: native Handle:FindPluginByNumber(order_num);
ds@1952:
ds@1952: /**
ds@1952: * Causes the plugin to enter a failed state. An error will be thrown and
ds@1952: * the plugin will be paused until it is unloaded or reloaded.
ds@1952: *
ds@1952: * For backwards compatibility, if no extra arguments are passed, no
ds@1952: * formatting is applied. If one or more additional arguments is passed,
ds@1952: * the string is formatted using Format(). If any errors are encountered
ds@1952: * during formatting, both the format specifier string and an additional
ds@1952: * error message are written.
ds@1952: *
ds@1952: * This function does not return, and no further code in the plugin is
ds@1952: * executed.
ds@1952: *
ds@1952: * @param string Format specifier string.
ds@1952: * @param ... Formatting arguments.
ds@1952: * @noreturn
ds@1952: * @error Always throws SP_ERROR_ABORT.
ds@1952: */
ds@1952: native SetFailState(const String:string[], any:...);
ds@1952:
ds@1952: /**
ds@1952: * Aborts the current callback and throws an error. This function
ds@1952: * does not return in that no code is executed following it.
ds@1952: *
ds@1952: * @param format String format.
ds@1952: * @param ... Format arguments.
ds@1952: * @noreturn
ds@1952: * @error Always!
ds@1952: */
ds@1952: native ThrowError(const String:fmt[], any:...);
ds@1952:
ds@1952: /**
ds@1952: * Gets the system time as a unix timestamp.
ds@1952: *
ds@1952: * @param bigStamp Optional array to store the 64bit timestamp in.
ds@1952: * @return 32bit timestamp (number of seconds since unix epoch).
ds@1952: */
ds@1952: native GetTime(bigStamp[2]={0,0});
ds@1952:
ds@1952: /**
ds@1952: * Produces a date and/or time string value for a timestamp.
ds@1952: *
ds@1952: * See this URL for valid parameters:
ds@1952: * http://opengroup.org/onlinepubs/007908799/xsh/strftime.html
ds@1952: *
ds@1952: * @param buffer Destination string buffer.
ds@1952: * @param maxlength Maximum length of output string buffer.
ds@1952: * @param format Formatting rules (passing NULL_STRING will use the rules defined in sm_datetime_format).
ds@1952: * @param stamp Optional time stamp.
ds@1952: * @noreturn
ds@1952: * @error Buffer too small or invalid time format.
ds@1952: */
ds@1952: native FormatTime(String:buffer[], maxlength, const String:format[], stamp=-1);
ds@1952:
ds@1952: /**
ds@1952: * Loads a game config file.
ds@1952: *
ds@1952: * @param file File to load. The path must be relative to the 'gamedata' folder under the config folder
ds@1952: * and the extension should be omitted.
ds@1952: * @return A handle to the game config file or INVALID_HANDLE in failure.
ds@1952: */
ds@1952: native Handle:LoadGameConfigFile(const String:file[]);
ds@1952:
ds@1952: /**
ds@1952: * Returns an offset value.
ds@1952: *
ds@1952: * @param gc Game config handle.
ds@1952: * @param key Key to retrieve from the offset section.
ds@1952: * @return An offset, or -1 on failure.
ds@1952: */
ds@1952: native GameConfGetOffset(Handle:gc, const String:key[]);
ds@1952:
ds@1952: /**
ds@1952: * Gets the value of a key from the "Keys" section.
ds@1952: *
ds@1952: * @param gc Game config handle.
ds@1952: * @param key Key to retrieve from the Keys section.
ds@1952: * @param buffer Destination string buffer.
ds@1952: * @param maxlen Maximum length of output string buffer.
ds@1952: * @return True if key existed, false otherwise.
ds@1952: */
ds@1952: native bool:GameConfGetKeyValue(Handle:gc, const String:key[], String:buffer[], maxlen);
ds@1952:
ds@1952: /**
ds@1952: * Returns the operating system's "tick count," which is a number of
ds@1952: * milliseconds since the operating system loaded. This can be used
ds@1952: * for basic benchmarks.
ds@1952: *
ds@1952: * @return Tick count in milliseconds.
ds@1952: */
ds@1952: native GetSysTickCount();
ds@1952:
ds@1952: /**
ds@1952: * Specifies that the given config file should be executed after plugin load.
ds@1952: * OnConfigsExecuted() will not be called until the config file has executed,
ds@1952: * but it will be called if the execution fails.
ds@1952: *
ds@1952: * @param autoCreate If true, and the config file does not exist, such a config
ds@1952: * file will be automatically created and populated with
ds@1952: * information from the plugin's registered cvars.
ds@1952: * @param name Name of the config file, excluding the .cfg extension.
ds@1952: * If empty, is assumed.
ds@1952: * @param folder Folder under cfg/ to use. By default this is "sourcemod."
ds@1952: * @noreturn
ds@1952: */
ds@1952: native AutoExecConfig(bool:autoCreate=true, const String:name[]="", const String:folder[]="sourcemod");
ds@1952:
ds@1952: /**
ds@1952: * Sets a native as optional, such that if it is unloaded, removed,
ds@1952: * or otherwise non-existent, the plugin will still work. Calling
ds@1952: * removed natives results in a run-time error.
ds@1952: *
ds@1952: * @param name Native name.
ds@1952: * @noreturn
ds@1952: */
ds@1952: native MarkNativeAsOptional(const String:name[]);
ds@1952:
ds@1952: /**
ds@1952: * Registers a library name for identifying as a dependency to
ds@1952: * other plugins.
ds@1952: *
ds@1952: * @param name Library name.
ds@1952: * @noreturn
ds@1952: */
ds@1952: native RegPluginLibrary(const String:name[]);
ds@1952:
ds@1952: /**
ds@1952: * Returns whether a library exists. This function should be considered
ds@1952: * expensive; it should only be called on plugin to determine availability
ds@1952: * of resources. Use OnLibraryAdded()/OnLibraryRemoved() to detect changes
ds@1952: * in optional resources.
ds@1952: *
ds@1952: * @param name Library name of a plugin or extension.
ds@1952: * @return True if exists, false otherwise.
ds@1952: */
ds@1952: native bool:LibraryExists(const String:name[]);
ds@1952:
ds@1952: /**
ds@1952: * Returns the status of an extension, by filename.
ds@1952: *
ds@1952: * @param name Extension name (like "sdktools.ext").
ds@1952: * @param error Optional error message buffer.
ds@1952: * @param maxlength Length of optional error message buffer.
ds@1952: * @return -2 if the extension was not found.
ds@1952: * -1 if the extension was found but failed to load.
ds@1952: * 0 if the extension loaded but reported an error.
ds@1952: * 1 if the extension is running without error.
ds@1952: */
ds@1952: native GetExtensionFileStatus(const String:name[], String:error[]="", maxlength=0);
ds@1952:
ds@1952: /**
ds@1952: * Called after a library is added that the current plugin references
ds@1952: * optionally. A library is either a plugin name or extension name, as
ds@1952: * exposed via its include file.
ds@1952: *
ds@1952: * @param name Library name.
ds@1952: */
ds@1952: forward OnLibraryAdded(const String:name[]);
ds@1952:
ds@1952: /**
ds@1952: * Called right before a library is removed that the current plugin references
ds@1952: * optionally. A library is either a plugin name or extension name, as
ds@1952: * exposed via its include file.
ds@1952: *
ds@1952: * @param name Library name.
ds@1952: */
ds@1952: forward OnLibraryRemoved(const String:name[]);
ds@1952:
ds@1952: #define MAPLIST_FLAG_MAPSFOLDER (1<<0) /**< On failure, use all maps in the maps folder. */
ds@1952: #define MAPLIST_FLAG_CLEARARRAY (1<<1) /**< If an input array is specified, clear it before adding. */
ds@1952: #define MAPLIST_FLAG_NO_DEFAULT (1<<2) /**< Do not read "default" or "mapcyclefile" on failure. */
ds@1952:
ds@1952: /**
ds@1952: * Loads a map list to an ADT Array.
ds@1952: *
ds@1952: * A map list is a list of maps from a file. SourceMod allows easy configuration of
ds@1952: * maplists through addons/sourcemod/configs/maplists.cfg. Each entry is given a
ds@1952: * name and a file (for example, "rtv" => "rtv.cfg"), or a name and a redirection
ds@1952: * (for example, "rtv" => "default"). This native will read a map list entry,
ds@1952: * cache the file, and return the list of maps it holds.
ds@1952: *
ds@1952: * Serial change numbers are used to identify if a map list has changed. Thus, if
ds@1952: * you pass a serial change number and it's equal to what SourceMod currently knows
ds@1952: * about the map list, then SourceMod won't reparse the file.
ds@1952: *
ds@1952: * If the maps end up being read from the maps folder (MAPLIST_FLAG_MAPSFOLDER), they
ds@1952: * are automatically sorted in alphabetical, ascending order.
ds@1952: *
ds@1952: * Arrays created by this function are temporary and must be freed via CloseHandle().
ds@1952: * Modifying arrays created by this function will not affect future return values or
ds@1952: * or the contents of arrays returned to other plugins.
ds@1952: *
ds@1952: * @param array Array to store the map list. If INVALID_HANDLE, a new blank
ds@1952: * array will be created. The blocksize should be at least 16;
ds@1952: * otherwise results may be truncated. Items are added to the array
ds@1952: * as strings. The array is never checked for duplicates, and it is
ds@1952: * not read beforehand. Only the serial number is used to detect
ds@1952: * changes.
ds@1952: * @param serial Serial number to identify last known map list change. If -1, the
ds@1952: * the value will not be checked. If the map list has since changed,
ds@1952: * the serial is updated (even if -1 was passed). If there is an error
ds@1952: * finding a valid maplist, then the serial is set to -1.
ds@1952: * @param str Config name, or "default" for the default map list. Config names
ds@1952: * should be somewhat descriptive. For example, the admin menu uses
ds@1952: * a config name of "admin menu". The list names can be configured
ds@1952: * by users in addons/sourcemod/configs/maplists.cfg.
ds@1952: * @param flags MAPLIST_FLAG flags.
ds@1952: * @return On failure:
ds@1952: * INVALID_HANDLE is returned, the serial is set to -1, and the input
ds@1952: * array (if any) is left unchanged.
ds@1952: * On no change:
ds@1952: INVALID_HANDLE is returned, the serial is unchanged, and the input
ds@1952: array (if any) is left unchanged.
ds@1952: * On success:
ds@1952: * A valid array Handle is returned, containing at least one map string.
ds@1952: * If an array was passed, the return value is equal to the passed Array
ds@1952: * Handle. If the passed array was not cleared, it will have grown by at
ds@1952: * least one item. The serial number is updated to a positive number.
ds@1952: * @error Invalid array Handle that is not INVALID_HANDLE.
ds@1952: */
ds@1952: native Handle:ReadMapList(Handle:array=INVALID_HANDLE,
ds@1952: &serial=-1,
ds@1952: const String:str[]="default",
ds@1952: flags=MAPLIST_FLAG_CLEARARRAY);
ds@1952:
ds@1952: /**
ds@1952: * Makes a compatibility binding for map lists. For example, if a function previously used
ds@1952: * "clam.cfg" for map lists, this function will insert a "fake" binding to "clam.cfg" that
ds@1952: * will be overridden if it's in the maplists.cfg file.
ds@1952: *
ds@1952: * @param name Configuration name that would be used with ReadMapList().
ds@1952: * @param file Default file to use.
ds@1952: * @noreturn
ds@1952: */
ds@1952: native SetMapListCompatBind(const String:name[], const String:file[]);
ds@1952:
ds@1952: /**
ds@1952: * Called when a client has sent chat text. This must return either true or
ds@1952: * false to indicate that a client is or is not spamming the server.
ds@1952: *
ds@1952: * The return value is a hint only. Core or another plugin may decide
ds@1952: * otherwise.
ds@1952: *
ds@1952: * @param client Client index. The server (0) will never be passed.
ds@1952: * @return True if client is spamming the server, false otherwise.
ds@1952: */
ds@1952: forward bool:OnClientFloodCheck(client);
ds@1952:
ds@1952: /**
ds@1952: * Called after a client's flood check has been computed. This can be used
ds@1952: * by antiflood algorithms to decay/increase flooding weights.
ds@1952: *
ds@1952: * Since the result from "OnClientFloodCheck" isn't guaranteed to be the
ds@1952: * final result, it is generally a good idea to use this to play with other
ds@1952: * algorithms nicely.
ds@1952: *
ds@1952: * @param client Client index. The server (0) will never be passed.
ds@1952: * @param blocked True if client flooded last "say", false otherwise.
ds@1952: * @noreturn
ds@1952: */
ds@1952: forward OnClientFloodResult(client, bool:blocked);
ds@1952:
ds@1952: #include
ds@1952: #include
ds@1952: #include
ds@1952: