plugins/include/sourcemod.inc
author Borja Ferrer <faluco@alliedmods.net>
Sun Aug 19 16:54:06 2007 +0000 (2007-08-19)
changeset 1359 c93c61f32568
parent 1334 9db842b7a9fe
child 1378 115ba755bcdf
permissions -rw-r--r--
added amb805, time formatting cvar
     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.
     8  *
     9  * This program is free software; you can redistribute it and/or modify it under
    10  * the terms of the GNU General Public License, version 3.0, as published by the
    11  * Free Software Foundation.
    12  * 
    13  * This program is distributed in the hope that it will be useful, but WITHOUT
    14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    15  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    16  * details.
    17  *
    18  * You should have received a copy of the GNU General Public License along with
    19  * this program.  If not, see <http://www.gnu.org/licenses/>.
    20  *
    21  * As a special exception, AlliedModders LLC gives you permission to link the
    22  * code of this program (as well as its derivative works) to "Half-Life 2," the
    23  * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    24  * by the Valve Corporation.  You must obey the GNU General Public License in
    25  * all respects for all other code used.  Additionally, AlliedModders LLC grants
    26  * this exception to all derivative works.  AlliedModders LLC defines further
    27  * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    28  * or <http://www.sourcemod.net/license.php>.
    29  *
    30  * Version: $Id$
    31  */
    32 
    33 #if defined _sourcemod_included
    34  #endinput
    35 #endif
    36 #define _sourcemod_included
    37 
    38 /**
    39  * Plugin public information.
    40  */
    41 struct Plugin
    42 {
    43    const String:name[],			/**< Plugin Name */
    44    const String:description[],	/**< Plugin Description */
    45    const String:author[],		/**< Plugin Author */
    46    const String:version[],		/**< Plugin Version */
    47    const String:url[],			/**< Plugin URL */
    48 };
    49 
    50 #include <core>
    51 #include <float>
    52 #include <vector>
    53 #include <string>
    54 #include <handles>
    55 #include <functions>
    56 #include <files>
    57 #include <timers>
    58 #include <admin>
    59 #include <dbi>
    60 #include <lang>
    61 #include <sorting>
    62 #include <textparse>
    63 #include <clients>
    64 #include <console>
    65 #include <events>
    66 #include <bitbuffer>
    67 #include <usermessages>
    68 #include <keyvalues>
    69 #include <menus>
    70 #include <halflife>
    71 #include <adt>
    72 
    73 /**
    74  * Declare this as a struct in your plugin to expose its information.
    75  * Example:
    76  *
    77  * public Plugin:myinfo =
    78  * {
    79  *    name = "My Plugin",
    80  *    //etc
    81  * };
    82  */
    83 public Plugin:myinfo;
    84  
    85 /**
    86  * Called when the plugin is fully initialized and all known external references are resolved.
    87  * This is called even if the plugin type is "private."
    88  * @note Errors in this function will cause the plugin to stop running.
    89  *
    90  * @noreturn
    91  */
    92 forward OnPluginStart();
    93  
    94 /**
    95  * Called before OnPluginStart, in case the plugin wants to check for load failure.
    96  * This is called even if the plugin type is "private."  Any natives from modules are 
    97  * not available at this point.  Thus, this forward should only be used for explicit 
    98  * pre-emptive things, such as adding dynamic natives, or setting certain types of load filters.
    99  * 
   100  * @note It is not safe to call externally resolved natives until OnPluginStart().
   101  * @note Any sort of RTE in this function will cause the plugin to fail loading.
   102  *
   103  * @param myself	Handle to the plugin.
   104  * @param late		Whether or not the plugin was loaded "late" (after map load).
   105  * @param error		Error message buffer in case load failed.
   106  * @param err_max	Maximum number of characters for error message buffer.
   107  * @return			True if load success, false otherwise.
   108  */
   109 forward bool:AskPluginLoad(Handle:myself, bool:late, String:error[], err_max);
   110 
   111 /**
   112  * Called when the plugin is about to be unloaded.
   113  *
   114  * @noreturn
   115  */
   116 forward OnPluginEnd();
   117 
   118 /**
   119  * Called when the plugin's pause status is changing.
   120  *
   121  * @param pause			True if the plugin is being paused, false otherwise.
   122  * @noreturn
   123  */
   124 forward OnPluginPauseChange(bool:pause);
   125 
   126 /**
   127  * Called before every server frame.  Note that you should avoid
   128  * doing expensive computations here, and you should declare large
   129  * local arrays using 'decl' instead of 'new'.
   130  */
   131 forward OnGameFrame();
   132 
   133 /**
   134  * Called when the map is loaded.
   135  *
   136  * @note This used to be OnServerLoad(), which is now deprecated.
   137  * Plugins still using the old forward will work.
   138  */
   139 forward OnMapStart();
   140 
   141 /**
   142  * Called right before a map ends.
   143  */
   144 forward OnMapEnd();
   145 
   146 /**
   147  * Called when the map has loaded, servercfgfile (server.cfg) has been 
   148  * executed, and all plugin configs are done executing.  This is the best
   149  * place to inialize plugin functions which are based on cvar data.  
   150  *
   151  * @note This will always be called once and only once per map.  It will be 
   152  * called after OnMapStart().
   153  *
   154  * @noreturn
   155  */
   156 forward OnConfigsExecuted();
   157 
   158 /**
   159  * @deprecated Use OnConfigsExecuted() instead.
   160  */
   161 #pragma deprecated Use OnConfigsExecuted() instead
   162 forward OnServerCfg();
   163 
   164 /**
   165  * Called after all plugins have been loaded.
   166  */
   167 forward OnAllPluginsLoaded();
   168 
   169 /**
   170  * Returns the calling plugin's Handle.
   171  *
   172  * @return				Handle of the calling plugin.
   173  */
   174 native Handle:GetMyHandle();
   175 
   176 /**
   177  * Returns an iterator that can be used to search through plugins.
   178  *
   179  * @return				Handle to iterate with.  Must be closed via 
   180  * 						CloseHandle().
   181  * @error				Invalid Handle.
   182  */
   183 native Handle:GetPluginIterator();
   184 
   185 /**
   186  * Returns whether there are more plugins available in the iterator.
   187  *
   188  * @param iter			Handle to the plugin iterator.
   189  * @return				True on more plugins, false otherwise.
   190  * @error				Invalid Handle.
   191  */
   192 native bool:MorePlugins(Handle:iter);
   193 
   194 /**
   195  * Returns the current plugin in the iterator and advances the iterator.
   196  *
   197  * @param iter			Handle to the plugin iterator.
   198  * @return				Current plugin the iterator is at, before
   199  *						the iterator is advanced.
   200  * @error				Invalid Handle.
   201  */
   202 native Handle:ReadPlugin(Handle:iter);
   203 
   204 /**
   205  * Returns a plugin's status.
   206  *
   207  * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
   208  * @return				Status code for the plugin.
   209  * @error				Invalid Handle.
   210  */
   211 native PluginStatus:GetPluginStatus(Handle:plugin);
   212 
   213 /**
   214  * Retrieves a plugin's file name relative to the plugins folder.
   215  *
   216  * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
   217  * @param buffer		Buffer to the store the file name.
   218  * @param maxlength		Maximum length of the name buffer.
   219  * @noreturn
   220  * @error				Invalid Handle.
   221  */
   222 native GetPluginFilename(Handle:plugin, String:buffer[], maxlength);
   223 
   224 /**
   225  * Retrieves whether or not a plugin is being debugged.
   226  *
   227  * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
   228  * @return				True if being debugged, false otherwise.
   229  * @error				Invalid Handle.
   230  */
   231 native bool:IsPluginDebugging(Handle:hndl);
   232 
   233 /**
   234  * Retrieves a plugin's public info.
   235  *
   236  * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
   237  * @param info			Plugin info property to retrieve.
   238  * @param buffer		Buffer to store info in.
   239  * @param maxlength		Maximum length of buffer.
   240  * @return				True on success, false if property is not available.
   241  * @error				Invalid Handle.
   242  */
   243 native bool:GetPluginInfo(Handle:plugin, PluginInfo:info, String:buffer[], maxlength);
   244 
   245 /**
   246  * Causes the plugin to enter a failed state.  An error will be thrown and
   247  * the plugin will be paused until it is unloaded or reloaded.
   248  *
   249  * @param string		Message to print.
   250  * @noreturn
   251  * @error				Always throws SP_ERROR_ABORT.
   252  */
   253 native SetFailState(const String:string[]);
   254 
   255 /**
   256  * Aborts the current callback and throws an error.  This function
   257  * does not return in that no code is executed following it.
   258  *
   259  * @param format		String format.
   260  * @param ...			Format arguments.
   261  * @noreturn
   262  * @error				Always!
   263  */
   264 native ThrowError(const String:fmt[], any:...);
   265 
   266 /**
   267  * Logs a plugin message to the SourceMod logs.
   268  *
   269  * @param format		String format.
   270  * @param ...			Format arguments.
   271  * @noreturn
   272  */
   273 native LogMessage(const String:format[], any:...);
   274 
   275 /**
   276  * Logs a plugin error message to the SourceMod logs.
   277  *
   278  * @param format		String format.
   279  * @param ...			Format arguments.
   280  * @noreturn
   281  */
   282 native LogError(const String:format[], any:...);
   283 
   284 /**
   285  * Gets the system time as a unix timestamp.
   286  *
   287  * @param bigStamp		Optional array to store the 64bit timestamp in.
   288  * @return				32bit timestamp (number of seconds since unix epoch).
   289  */
   290 native GetTime(bigStamp[2]={0,0});
   291 
   292 /**
   293  * Produces a date and/or time string value for a timestamp.
   294  *
   295  * See this URL for valid parameters: 
   296  * http://opengroup.org/onlinepubs/007908799/xsh/strftime.html
   297  *
   298  * @param buffer		Destination string buffer.
   299  * @param maxlength		Maximum length of output string buffer.
   300  * @param format		Formatting rules (passing NULL_STRING will use the rules defined in sm_datetime_format).
   301  * @param stamp			Optional time stamp.
   302  * @noreturn
   303  * @error			Buffer too small or invalid time format.
   304  */
   305 native FormatTime(String:buffer[], maxlength, const String:format[], stamp=-1);
   306 
   307 /**
   308  * Loads a game config file.
   309  *
   310  * @param file			File to load.  The path must be relative to the 'gamedata' folder under the config folder 
   311  *					and the extension should be omitted.
   312  * @return			A handle to the game config file or INVALID_HANDLE in failure.
   313  */
   314 native Handle:LoadGameConfigFile(const String:file[]);
   315 
   316 /**
   317  * Returns an offset value.
   318  *
   319  * @param gc			Game config handle.
   320  * @param key			Key to retrieve from the offset section.
   321  * @return			An offset, or -1 on failure.
   322  */
   323 native GameConfGetOffset(Handle:gc, const String:key[]);
   324 
   325 /**
   326  * Gets the value of a key from the "Keys" section.
   327  *
   328  * @param gc			Game config handle.
   329  * @param key			Key to retrieve from the Keys section.
   330  * @param buffer		Destination string buffer.
   331  * @param maxlen		Maximum length of output string buffer.
   332  * @return				True if key existed, false otherwise.
   333  */
   334 native bool:GameConfGetKeyValue(Handle:gc, const String:key[], String:buffer[], maxlen);
   335 
   336 /**
   337  * Returns the operating system's "tick count," which is a number of 
   338  * milliseconds since the operating system loaded.  This can be used
   339  * for basic benchmarks.
   340  *
   341  * @return				Tick count in milliseconds.
   342  */
   343 native GetSysTickCount();
   344 
   345 /**
   346  * Specifies that the given config file should be executed after plugin load.
   347  * OnConfigsExecuted() will not be called until the config file has executed, 
   348  * but it will be called if the execution fails.
   349  *
   350  * @param autoCreate	If true, and the config file does not exist, such a config
   351  *						file will be automatically created and populated with
   352  *						information from the plugin's registered cvars.
   353  * @param name			Name of the config file, excluding the .cfg extension.
   354  *						If empty, <plugin.filename.cfg> is assumed.
   355  * @param folder		Folder under cfg/ to use.  By default this is "sourcemod."
   356  * @noreturn
   357  */
   358 native AutoExecConfig(bool:autoCreate=true, const String:name[]="", const String:folder[]="sourcemod");
   359 
   360 /**
   361  * Sets a native as optional, such that if it is unloaded, removed,
   362  * or otherwise non-existent, the plugin will still work.  Calling
   363  * removed natives results in a run-time error.
   364  *
   365  * @param name			Native name.
   366  * @noreturn
   367  */
   368 native MarkNativeAsOptional(const String:name[]);
   369 
   370 /**
   371  * Registers a library name for identifying as a dependency to 
   372  * other plugins.
   373  *
   374  * @param name			Library name.
   375  * @noreturn
   376  */
   377 native RegPluginLibrary(const String:name[]);
   378 
   379 /**
   380  * Returns whether a library exists.
   381  *
   382  * @param name			Library name.
   383  * @return				True if exists, false otherwise.
   384  */
   385 native bool:LibraryExists(const String:name[]);
   386 
   387 /**
   388  * Called after a library (plugin) is added that the 
   389  * current plugin references optionally.
   390  *
   391  * @param name			Library name.
   392  */
   393 forward OnLibraryAdded(const String:name[]);
   394 
   395 /**
   396  * Called right before a library (plugin) is removed that the 
   397  * current plugin references optionally.
   398  *
   399  * @param name			Library name.
   400  */
   401 forward OnLibraryRemoved(const String:name[]);
   402 
   403 #include <helpers>
   404 #include <entity>