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