plugins/include/sourcemod.inc
author David Anderson <dvander@alliedmods.net>
Fri Aug 15 05:22:26 2008 +0000 (2008-08-15)
changeset 2226 d10b38524be3
parent 2133 cad0a5ea6742
child 2289 44045ead61cd
permissions -rw-r--r--
Landed sourcepawn-1.2. The big changes:

1) JIT compilation/optimization now occurs per-function, and only when functions are first used. We're now officially a whole-method JIT rather than an AOT compiler (albiet, still a simple JIT). This has two implications: Functions are now much better abstracted internally, and loading a plugin is now much less expensive. If a function contains calls to other functions, THOSE functions are only compiled when they're invoked as well.

2) I've removed debug mode. We always show full backtraces now, as there was a very cheap way to implement this which really cleaned up everything. This is great for a number of reasons -- there's less code, the JIT is better designed, we don't need to relocate debug tables, and best of all we no longer have to tell users to enable debug mode at their own expense.
ds@1952
     1
/**
ds@1952
     2
 * vim: set ts=4 :
ds@1952
     3
 * =============================================================================
ds@1952
     4
 * SourceMod (C)2004-2008 AlliedModders LLC.  All rights reserved.
ds@1952
     5
 * =============================================================================
ds@1952
     6
 *
ds@1952
     7
 * This file is part of the SourceMod/SourcePawn SDK.
ds@1952
     8
 *
ds@1952
     9
 * This program is free software; you can redistribute it and/or modify it under
ds@1952
    10
 * the terms of the GNU General Public License, version 3.0, as published by the
ds@1952
    11
 * Free Software Foundation.
ds@1952
    12
 * 
ds@1952
    13
 * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1952
    14
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1952
    15
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
ds@1952
    16
 * details.
ds@1952
    17
 *
ds@1952
    18
 * You should have received a copy of the GNU General Public License along with
ds@1952
    19
 * this program.  If not, see <http://www.gnu.org/licenses/>.
ds@1952
    20
 *
ds@1952
    21
 * As a special exception, AlliedModders LLC gives you permission to link the
ds@1952
    22
 * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1952
    23
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1952
    24
 * by the Valve Corporation.  You must obey the GNU General Public License in
ds@1952
    25
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
ds@1952
    26
 * this exception to all derivative works.  AlliedModders LLC defines further
ds@1952
    27
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1952
    28
 * or <http://www.sourcemod.net/license.php>.
ds@1952
    29
 *
ds@1952
    30
 * Version: $Id$
ds@1952
    31
 */
ds@1952
    32
ds@1952
    33
#if defined _sourcemod_included
ds@1952
    34
 #endinput
ds@1952
    35
#endif
ds@1952
    36
#define _sourcemod_included
ds@1952
    37
ds@1952
    38
/**
ds@1952
    39
 * Plugin public information.
ds@1952
    40
 */
ds@1952
    41
struct Plugin
ds@1952
    42
{
ds@1952
    43
   const String:name[],			/**< Plugin Name */
ds@1952
    44
   const String:description[],	/**< Plugin Description */
ds@1952
    45
   const String:author[],		/**< Plugin Author */
ds@1952
    46
   const String:version[],		/**< Plugin Version */
ds@1952
    47
   const String:url[],			/**< Plugin URL */
ds@1952
    48
};
ds@1952
    49
ds@1952
    50
#include <core>
ds@1952
    51
#include <float>
ds@1952
    52
#include <vector>
ds@1952
    53
#include <string>
ds@1952
    54
#include <handles>
ds@1952
    55
#include <functions>
ds@1952
    56
#include <files>
ds@1952
    57
#include <logging>
ds@1952
    58
#include <timers>
ds@1952
    59
#include <admin>
ds@1952
    60
#include <dbi>
ds@1952
    61
#include <lang>
ds@1952
    62
#include <sorting>
ds@1952
    63
#include <textparse>
ds@1952
    64
#include <clients>
ds@1952
    65
#include <console>
ds@1952
    66
#include <events>
ds@1952
    67
#include <bitbuffer>
ds@1952
    68
#include <usermessages>
ds@1952
    69
#include <keyvalues>
ds@1952
    70
#include <menus>
ds@1952
    71
#include <halflife>
ds@1952
    72
#include <adt>
ds@1952
    73
#include <banning>
ds@1952
    74
#include <commandfilters>
pred@2133
    75
#include <nextmap>
ds@1952
    76
ds@1952
    77
/**
ds@1952
    78
 * Declare this as a struct in your plugin to expose its information.
ds@1952
    79
 * Example:
ds@1952
    80
 *
ds@1952
    81
 * public Plugin:myinfo =
ds@1952
    82
 * {
ds@1952
    83
 *    name = "My Plugin",
ds@1952
    84
 *    //etc
ds@1952
    85
 * };
ds@1952
    86
 */
ds@1952
    87
public Plugin:myinfo;
ds@1952
    88
 
ds@1952
    89
/**
ds@1952
    90
 * Called when the plugin is fully initialized and all known external references 
ds@1952
    91
 * are resolved. This is only called once in the lifetime of the plugin, and is 
ds@1952
    92
 * paired with OnPluginEnd().
ds@1952
    93
 *
ds@1952
    94
 * If any run-time error is thrown during this callback, the plugin will be marked 
ds@1952
    95
 * as failed.
ds@1952
    96
 *
ds@1952
    97
 * It is not necessary to close any handles or remove hooks in this function.  
ds@1952
    98
 * SourceMod guarantees that plugin shutdown automatically and correctly releases 
ds@1952
    99
 * all resources.
ds@1952
   100
 *
ds@1952
   101
 * @noreturn
ds@1952
   102
 */
ds@1952
   103
forward OnPluginStart();
ds@1952
   104
 
ds@1952
   105
/**
ds@1952
   106
 * Called before OnPluginStart, in case the plugin wants to check for load failure.
ds@1952
   107
 * This is called even if the plugin type is "private."  Any natives from modules are 
ds@1952
   108
 * not available at this point.  Thus, this forward should only be used for explicit 
ds@1952
   109
 * pre-emptive things, such as adding dynamic natives, or setting certain types of load filters.
ds@1952
   110
 * 
ds@1952
   111
 * @note It is not safe to call externally resolved natives until OnPluginStart().
ds@1952
   112
 * @note Any sort of RTE in this function will cause the plugin to fail loading.
ds@1952
   113
 * @note You MUST remember to return SOMETHING here.  The act of not returning is 
ds@1952
   114
 *       equivalent to returning 0 (false).  If you forgot to return, it will 
ds@1952
   115
 *       cause your plugin to not load with a very strange error message.
ds@1952
   116
 *
ds@1952
   117
 * @param myself	Handle to the plugin.
ds@1952
   118
 * @param late		Whether or not the plugin was loaded "late" (after map load).
ds@1952
   119
 * @param error		Error message buffer in case load failed.
ds@1952
   120
 * @param err_max	Maximum number of characters for error message buffer.
ds@1952
   121
 * @return			True if load success, false otherwise.
ds@1952
   122
 */
ds@1952
   123
forward bool:AskPluginLoad(Handle:myself, bool:late, String:error[], err_max);
ds@1952
   124
ds@1952
   125
/**
ds@1952
   126
 * Called when the plugin is about to be unloaded.
ds@1952
   127
 *
ds@1952
   128
 * @noreturn
ds@1952
   129
 */
ds@1952
   130
forward OnPluginEnd();
ds@1952
   131
ds@1952
   132
/**
ds@1952
   133
 * Called when the plugin's pause status is changing.
ds@1952
   134
 *
ds@1952
   135
 * @param pause			True if the plugin is being paused, false otherwise.
ds@1952
   136
 * @noreturn
ds@1952
   137
 */
ds@1952
   138
forward OnPluginPauseChange(bool:pause);
ds@1952
   139
ds@1952
   140
/**
ds@1952
   141
 * Called before every server frame.  Note that you should avoid
ds@1952
   142
 * doing expensive computations here, and you should declare large
ds@1952
   143
 * local arrays using 'decl' instead of 'new'.
ds@1952
   144
 */
ds@1952
   145
forward OnGameFrame();
ds@1952
   146
ds@1952
   147
/**
ds@1952
   148
 * Called when the map is loaded.
ds@1952
   149
 *
ds@1952
   150
 * @note This used to be OnServerLoad(), which is now deprecated.
ds@1952
   151
 * Plugins still using the old forward will work.
ds@1952
   152
 */
ds@1952
   153
forward OnMapStart();
ds@1952
   154
ds@1952
   155
/**
ds@1952
   156
 * Called right before a map ends.
ds@1952
   157
 */
ds@1952
   158
forward OnMapEnd();
ds@1952
   159
ds@1952
   160
/**
ds@1952
   161
 * Called when the map has loaded, servercfgfile (server.cfg) has been 
ds@1952
   162
 * executed, and all plugin configs are done executing.  This is the best
ds@1952
   163
 * place to initialize plugin functions which are based on cvar data.  
ds@1952
   164
 *
ds@1952
   165
 * @note This will always be called once and only once per map.  It will be 
ds@1952
   166
 * called after OnMapStart().
ds@1952
   167
 *
ds@1952
   168
 * @noreturn
ds@1952
   169
 */
ds@1952
   170
forward OnConfigsExecuted();
ds@1952
   171
ds@1952
   172
/**
dvander@2065
   173
 * This is called once, right after OnMapStart() but any time before 
dvander@2065
   174
 * OnConfigsExecuted().  It is called after the "exec sourcemod.cfg" 
dvander@2065
   175
 * command and all AutoExecConfig() exec commands have been added to 
dvander@2065
   176
 * the ServerCommand() buffer.
dvander@2065
   177
 *
dvander@2065
   178
 * If you need to load per-map settings that override default values, 
dvander@2065
   179
 * adding commands to the ServerCommand() buffer here will guarantee 
dvander@2065
   180
 * that they're set before OnConfigsExecuted().
dvander@2065
   181
 *
dvander@2065
   182
 * Unlike OnMapStart() and OnConfigsExecuted(), this is not called on 
dvander@2065
   183
 * late loads that occur after OnMapStart().
dvander@2065
   184
 *
dvander@2065
   185
 * @noreturn
dvander@2065
   186
 */
dvander@2065
   187
forward OnAutoConfigsBuffered();
dvander@2065
   188
dvander@2065
   189
/**
ds@1952
   190
 * @deprecated Use OnConfigsExecuted() instead.
ds@1952
   191
 */
ds@1952
   192
#pragma deprecated Use OnConfigsExecuted() instead
ds@1952
   193
forward OnServerCfg();
ds@1952
   194
ds@1952
   195
/**
ds@1952
   196
 * Called after all plugins have been loaded.  This is called once for 
ds@1952
   197
 * every plugin.  If a plugin late loads, it will be called immediately 
ds@1952
   198
 * after OnPluginStart().
ds@1952
   199
 */
ds@1952
   200
forward OnAllPluginsLoaded();
ds@1952
   201
ds@1952
   202
/**
ds@1952
   203
 * Returns the calling plugin's Handle.
ds@1952
   204
 *
ds@1952
   205
 * @return				Handle of the calling plugin.
ds@1952
   206
 */
ds@1952
   207
native Handle:GetMyHandle();
ds@1952
   208
ds@1952
   209
/**
ds@1952
   210
 * Returns an iterator that can be used to search through plugins.
ds@1952
   211
 *
ds@1952
   212
 * @return				Handle to iterate with.  Must be closed via 
ds@1952
   213
 * 						CloseHandle().
ds@1952
   214
 * @error				Invalid Handle.
ds@1952
   215
 */
ds@1952
   216
native Handle:GetPluginIterator();
ds@1952
   217
ds@1952
   218
/**
ds@1952
   219
 * Returns whether there are more plugins available in the iterator.
ds@1952
   220
 *
ds@1952
   221
 * @param iter			Handle to the plugin iterator.
ds@1952
   222
 * @return				True on more plugins, false otherwise.
ds@1952
   223
 * @error				Invalid Handle.
ds@1952
   224
 */
ds@1952
   225
native bool:MorePlugins(Handle:iter);
ds@1952
   226
ds@1952
   227
/**
ds@1952
   228
 * Returns the current plugin in the iterator and advances the iterator.
ds@1952
   229
 *
ds@1952
   230
 * @param iter			Handle to the plugin iterator.
ds@1952
   231
 * @return				Current plugin the iterator is at, before
ds@1952
   232
 *						the iterator is advanced.
ds@1952
   233
 * @error				Invalid Handle.
ds@1952
   234
 */
ds@1952
   235
native Handle:ReadPlugin(Handle:iter);
ds@1952
   236
ds@1952
   237
/**
ds@1952
   238
 * Returns a plugin's status.
ds@1952
   239
 *
ds@1952
   240
 * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
ds@1952
   241
 * @return				Status code for the plugin.
ds@1952
   242
 * @error				Invalid Handle.
ds@1952
   243
 */
ds@1952
   244
native PluginStatus:GetPluginStatus(Handle:plugin);
ds@1952
   245
ds@1952
   246
/**
ds@1952
   247
 * Retrieves a plugin's file name relative to the plugins folder.
ds@1952
   248
 *
ds@1952
   249
 * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
ds@1952
   250
 * @param buffer		Buffer to the store the file name.
ds@1952
   251
 * @param maxlength		Maximum length of the name buffer.
ds@1952
   252
 * @noreturn
ds@1952
   253
 * @error				Invalid Handle.
ds@1952
   254
 */
ds@1952
   255
native GetPluginFilename(Handle:plugin, String:buffer[], maxlength);
ds@1952
   256
ds@1952
   257
/**
ds@1952
   258
 * Retrieves whether or not a plugin is being debugged.
ds@1952
   259
 *
ds@1952
   260
 * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
ds@1952
   261
 * @return				True if being debugged, false otherwise.
ds@1952
   262
 * @error				Invalid Handle.
ds@1952
   263
 */
ds@1952
   264
native bool:IsPluginDebugging(Handle:hndl);
ds@1952
   265
ds@1952
   266
/**
ds@1952
   267
 * Retrieves a plugin's public info.
ds@1952
   268
 *
ds@1952
   269
 * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
ds@1952
   270
 * @param info			Plugin info property to retrieve.
ds@1952
   271
 * @param buffer		Buffer to store info in.
ds@1952
   272
 * @param maxlength		Maximum length of buffer.
ds@1952
   273
 * @return				True on success, false if property is not available.
ds@1952
   274
 * @error				Invalid Handle.
ds@1952
   275
 */
ds@1952
   276
native bool:GetPluginInfo(Handle:plugin, PluginInfo:info, String:buffer[], maxlength);
ds@1952
   277
ds@1952
   278
/**
ds@1952
   279
 * Finds a plugin by its order in the list from the "plugins list" server 
ds@1952
   280
 * "sm" command.  You should not use this function to loop through all plugins, 
ds@1952
   281
 * use the iterator instead.  Looping through all plugins using this native 
ds@1952
   282
 * is O(n^2), whereas using the iterator is O(n).
ds@1952
   283
 *
ds@1952
   284
 * @param order_num		Number of the plugin as it appears in "sm plugins list".
ds@1952
   285
 * @return				Plugin Handle on success, INVALID_HANDLE if no plugin 
ds@1952
   286
 *						matches the given number.
ds@1952
   287
 */
ds@1952
   288
native Handle:FindPluginByNumber(order_num);
ds@1952
   289
ds@1952
   290
/**
ds@1952
   291
 * Causes the plugin to enter a failed state.  An error will be thrown and
ds@1952
   292
 * the plugin will be paused until it is unloaded or reloaded.
ds@1952
   293
 *
ds@1952
   294
 * For backwards compatibility, if no extra arguments are passed, no 
ds@1952
   295
 * formatting is applied.  If one or more additional arguments is passed, 
ds@1952
   296
 * the string is formatted using Format().  If any errors are encountered 
ds@1952
   297
 * during formatting, both the format specifier string and an additional 
ds@1952
   298
 * error message are written.
ds@1952
   299
 *
ds@1952
   300
 * This function does not return, and no further code in the plugin is 
ds@1952
   301
 * executed.
ds@1952
   302
 *
ds@1952
   303
 * @param string		Format specifier string.
ds@1952
   304
 * @param ...			Formatting arguments.
ds@1952
   305
 * @noreturn
ds@1952
   306
 * @error				Always throws SP_ERROR_ABORT.
ds@1952
   307
 */
ds@1952
   308
native SetFailState(const String:string[], any:...);
ds@1952
   309
ds@1952
   310
/**
ds@1952
   311
 * Aborts the current callback and throws an error.  This function
ds@1952
   312
 * does not return in that no code is executed following it.
ds@1952
   313
 *
ds@1952
   314
 * @param format		String format.
ds@1952
   315
 * @param ...			Format arguments.
ds@1952
   316
 * @noreturn
ds@1952
   317
 * @error				Always!
ds@1952
   318
 */
ds@1952
   319
native ThrowError(const String:fmt[], any:...);
ds@1952
   320
ds@1952
   321
/**
ds@1952
   322
 * Gets the system time as a unix timestamp.
ds@1952
   323
 *
ds@1952
   324
 * @param bigStamp		Optional array to store the 64bit timestamp in.
ds@1952
   325
 * @return				32bit timestamp (number of seconds since unix epoch).
ds@1952
   326
 */
ds@1952
   327
native GetTime(bigStamp[2]={0,0});
ds@1952
   328
ds@1952
   329
/**
ds@1952
   330
 * Produces a date and/or time string value for a timestamp.
ds@1952
   331
 *
ds@1952
   332
 * See this URL for valid parameters: 
dvander@1972
   333
 * http://cplusplus.com/reference/clibrary/ctime/strftime.html
ds@1952
   334
 *
ds@1952
   335
 * @param buffer		Destination string buffer.
ds@1952
   336
 * @param maxlength		Maximum length of output string buffer.
ds@1952
   337
 * @param format		Formatting rules (passing NULL_STRING will use the rules defined in sm_datetime_format).
ds@1952
   338
 * @param stamp			Optional time stamp.
ds@1952
   339
 * @noreturn
ds@1952
   340
 * @error			Buffer too small or invalid time format.
ds@1952
   341
 */
ds@1952
   342
native FormatTime(String:buffer[], maxlength, const String:format[], stamp=-1);
ds@1952
   343
ds@1952
   344
/**
ds@1952
   345
 * Loads a game config file.
ds@1952
   346
 *
ds@1952
   347
 * @param file			File to load.  The path must be relative to the 'gamedata' folder under the config folder 
ds@1952
   348
 *					and the extension should be omitted.
ds@1952
   349
 * @return			A handle to the game config file or INVALID_HANDLE in failure.
ds@1952
   350
 */
ds@1952
   351
native Handle:LoadGameConfigFile(const String:file[]);
ds@1952
   352
ds@1952
   353
/**
ds@1952
   354
 * Returns an offset value.
ds@1952
   355
 *
ds@1952
   356
 * @param gc			Game config handle.
ds@1952
   357
 * @param key			Key to retrieve from the offset section.
ds@1952
   358
 * @return			An offset, or -1 on failure.
ds@1952
   359
 */
ds@1952
   360
native GameConfGetOffset(Handle:gc, const String:key[]);
ds@1952
   361
ds@1952
   362
/**
ds@1952
   363
 * Gets the value of a key from the "Keys" section.
ds@1952
   364
 *
ds@1952
   365
 * @param gc			Game config handle.
ds@1952
   366
 * @param key			Key to retrieve from the Keys section.
ds@1952
   367
 * @param buffer		Destination string buffer.
ds@1952
   368
 * @param maxlen		Maximum length of output string buffer.
ds@1952
   369
 * @return				True if key existed, false otherwise.
ds@1952
   370
 */
ds@1952
   371
native bool:GameConfGetKeyValue(Handle:gc, const String:key[], String:buffer[], maxlen);
ds@1952
   372
ds@1952
   373
/**
ds@1952
   374
 * Returns the operating system's "tick count," which is a number of 
ds@1952
   375
 * milliseconds since the operating system loaded.  This can be used
ds@1952
   376
 * for basic benchmarks.
ds@1952
   377
 *
ds@1952
   378
 * @return				Tick count in milliseconds.
ds@1952
   379
 */
ds@1952
   380
native GetSysTickCount();
ds@1952
   381
ds@1952
   382
/**
ds@1952
   383
 * Specifies that the given config file should be executed after plugin load.
ds@1952
   384
 * OnConfigsExecuted() will not be called until the config file has executed, 
ds@1952
   385
 * but it will be called if the execution fails.
ds@1952
   386
 *
ds@1952
   387
 * @param autoCreate	If true, and the config file does not exist, such a config
ds@1952
   388
 *						file will be automatically created and populated with
ds@1952
   389
 *						information from the plugin's registered cvars.
ds@1952
   390
 * @param name			Name of the config file, excluding the .cfg extension.
ds@1952
   391
 *						If empty, <plugin.filename.cfg> is assumed.
ds@1952
   392
 * @param folder		Folder under cfg/ to use.  By default this is "sourcemod."
ds@1952
   393
 * @noreturn
ds@1952
   394
 */
ds@1952
   395
native AutoExecConfig(bool:autoCreate=true, const String:name[]="", const String:folder[]="sourcemod");
ds@1952
   396
ds@1952
   397
/**
ds@1952
   398
 * Sets a native as optional, such that if it is unloaded, removed,
ds@1952
   399
 * or otherwise non-existent, the plugin will still work.  Calling
ds@1952
   400
 * removed natives results in a run-time error.
ds@1952
   401
 *
ds@1952
   402
 * @param name			Native name.
ds@1952
   403
 * @noreturn
ds@1952
   404
 */
ds@1952
   405
native MarkNativeAsOptional(const String:name[]);
ds@1952
   406
ds@1952
   407
/**
ds@1952
   408
 * Registers a library name for identifying as a dependency to 
ds@1952
   409
 * other plugins.
ds@1952
   410
 *
ds@1952
   411
 * @param name			Library name.
ds@1952
   412
 * @noreturn
ds@1952
   413
 */
ds@1952
   414
native RegPluginLibrary(const String:name[]);
ds@1952
   415
ds@1952
   416
/**
ds@1952
   417
 * Returns whether a library exists.  This function should be considered 
ds@1952
   418
 * expensive; it should only be called on plugin to determine availability 
ds@1952
   419
 * of resources.  Use OnLibraryAdded()/OnLibraryRemoved() to detect changes 
ds@1952
   420
 * in optional resources.
ds@1952
   421
 *
ds@1952
   422
 * @param name			Library name of a plugin or extension.
ds@1952
   423
 * @return				True if exists, false otherwise.
ds@1952
   424
 */
ds@1952
   425
native bool:LibraryExists(const String:name[]);
ds@1952
   426
ds@1952
   427
/**
ds@1952
   428
 * Returns the status of an extension, by filename.
ds@1952
   429
 *
ds@1952
   430
 * @param name			Extension name (like "sdktools.ext").
ds@1952
   431
 * @param error			Optional error message buffer.
ds@1952
   432
 * @param maxlength		Length of optional error message buffer.
ds@1952
   433
 * @return				-2 if the extension was not found.
ds@1952
   434
 *						-1 if the extension was found but failed to load.
ds@1952
   435
 * 						 0 if the extension loaded but reported an error.
ds@1952
   436
 * 						 1 if the extension is running without error.
ds@1952
   437
 */
ds@1952
   438
native GetExtensionFileStatus(const String:name[], String:error[]="", maxlength=0);
ds@1952
   439
ds@1952
   440
/**
ds@1952
   441
 * Called after a library is added that the current plugin references 
ds@1952
   442
 * optionally. A library is either a plugin name or extension name, as 
ds@1952
   443
 * exposed via its include file.
ds@1952
   444
 *
ds@1952
   445
 * @param name			Library name.
ds@1952
   446
 */
ds@1952
   447
forward OnLibraryAdded(const String:name[]);
ds@1952
   448
ds@1952
   449
/**
ds@1952
   450
 * Called right before a library is removed that the current plugin references 
ds@1952
   451
 * optionally.  A library is either a plugin name or extension name, as 
ds@1952
   452
 * exposed via its include file.
ds@1952
   453
 *
ds@1952
   454
 * @param name			Library name.
ds@1952
   455
 */
ds@1952
   456
forward OnLibraryRemoved(const String:name[]);
ds@1952
   457
ds@1952
   458
#define MAPLIST_FLAG_MAPSFOLDER		(1<<0)		/**< On failure, use all maps in the maps folder. */
ds@1952
   459
#define MAPLIST_FLAG_CLEARARRAY		(1<<1)		/**< If an input array is specified, clear it before adding. */
ds@1952
   460
#define MAPLIST_FLAG_NO_DEFAULT		(1<<2)		/**< Do not read "default" or "mapcyclefile" on failure. */
ds@1952
   461
ds@1952
   462
/**
ds@1952
   463
 * Loads a map list to an ADT Array.
ds@1952
   464
 *
ds@1952
   465
 * A map list is a list of maps from a file.  SourceMod allows easy configuration of 
ds@1952
   466
 * maplists through addons/sourcemod/configs/maplists.cfg.  Each entry is given a 
ds@1952
   467
 * name and a file (for example, "rtv" => "rtv.cfg"), or a name and a redirection 
ds@1952
   468
 * (for example, "rtv" => "default").  This native will read a map list entry, 
ds@1952
   469
 * cache the file, and return the list of maps it holds.  
ds@1952
   470
 *
ds@1952
   471
 * Serial change numbers are used to identify if a map list has changed.  Thus, if 
ds@1952
   472
 * you pass a serial change number and it's equal to what SourceMod currently knows 
ds@1952
   473
 * about the map list, then SourceMod won't reparse the file.
ds@1952
   474
 *
ds@1952
   475
 * If the maps end up being read from the maps folder (MAPLIST_FLAG_MAPSFOLDER), they 
ds@1952
   476
 * are automatically sorted in alphabetical, ascending order.
ds@1952
   477
 *
ds@1952
   478
 * Arrays created by this function are temporary and must be freed via CloseHandle().
ds@1952
   479
 * Modifying arrays created by this function will not affect future return values or 
ds@1952
   480
 * or the contents of arrays returned to other plugins.
ds@1952
   481
 *
ds@1952
   482
 * @param array			Array to store the map list.  If INVALID_HANDLE, a new blank 
ds@1952
   483
 *						array will be created.  The blocksize should be at least 16; 
ds@1952
   484
 *						otherwise results may be truncated.  Items are added to the array 
ds@1952
   485
 *						as strings.  The array is never checked for duplicates, and it is 
ds@1952
   486
 *						not read beforehand.  Only the serial number is used to detect 
ds@1952
   487
 *						changes.
ds@1952
   488
 * @param serial		Serial number to identify last known map list change.  If -1, the 
ds@1952
   489
 *						the value will not be checked.  If the map list has since changed, 
ds@1952
   490
 *						the serial is updated (even if -1 was passed).  If there is an error 
ds@1952
   491
 *						finding a valid maplist, then the serial is set to -1.
ds@1952
   492
 * @param str			Config name, or "default" for the default map list.  Config names 
ds@1952
   493
 *						should be somewhat descriptive.  For example, the admin menu uses 
ds@1952
   494
 *						a config name of "admin menu".  The list names can be configured 
ds@1952
   495
 *						by users in addons/sourcemod/configs/maplists.cfg.
ds@1952
   496
 * @param flags			MAPLIST_FLAG flags.
ds@1952
   497
 * @return				On failure:
ds@1952
   498
 *						 INVALID_HANDLE is returned, the serial is set to -1, and the input 
ds@1952
   499
 *						 array (if any) is left unchanged.
ds@1952
   500
 *						On no change:
ds@1952
   501
 						 INVALID_HANDLE is returned, the serial is unchanged, and the input 
ds@1952
   502
 						 array (if any) is left unchanged.
ds@1952
   503
 *						On success:
ds@1952
   504
 *						 A valid array Handle is returned, containing at least one map string.  
ds@1952
   505
 *						 If an array was passed, the return value is equal to the passed Array 
ds@1952
   506
 *						 Handle.  If the passed array was not cleared, it will have grown by at 
ds@1952
   507
 *						 least one item.  The serial number is updated to a positive number.
ds@1952
   508
 * @error				Invalid array Handle that is not INVALID_HANDLE.
ds@1952
   509
 */
ds@1952
   510
native Handle:ReadMapList(Handle:array=INVALID_HANDLE,
ds@1952
   511
						  &serial=-1,
ds@1952
   512
						  const String:str[]="default",
ds@1952
   513
						  flags=MAPLIST_FLAG_CLEARARRAY);
ds@1952
   514
						  
ds@1952
   515
/**
ds@1952
   516
 * Makes a compatibility binding for map lists.  For example, if a function previously used 
ds@1952
   517
 * "clam.cfg" for map lists, this function will insert a "fake" binding to "clam.cfg" that 
ds@1952
   518
 * will be overridden if it's in the maplists.cfg file.
ds@1952
   519
 *
ds@1952
   520
 * @param name			Configuration name that would be used with ReadMapList().
ds@1952
   521
 * @param file			Default file to use.
ds@1952
   522
 * @noreturn
ds@1952
   523
 */
ds@1952
   524
native SetMapListCompatBind(const String:name[], const String:file[]);
ds@1952
   525
ds@1952
   526
/**
ds@1952
   527
 * Called when a client has sent chat text.  This must return either true or 
ds@1952
   528
 * false to indicate that a client is or is not spamming the server.
ds@1952
   529
 *
ds@1952
   530
 * The return value is a hint only.  Core or another plugin may decide 
ds@1952
   531
 * otherwise.
ds@1952
   532
 *
ds@1952
   533
 * @param client		Client index.  The server (0) will never be passed.
ds@1952
   534
 * @return				True if client is spamming the server, false otherwise.
ds@1952
   535
 */
ds@1952
   536
forward bool:OnClientFloodCheck(client);
ds@1952
   537
ds@1952
   538
/**
ds@1952
   539
 * Called after a client's flood check has been computed.  This can be used 
ds@1952
   540
 * by antiflood algorithms to decay/increase flooding weights.
ds@1952
   541
 *
ds@1952
   542
 * Since the result from "OnClientFloodCheck" isn't guaranteed to be the 
ds@1952
   543
 * final result, it is generally a good idea to use this to play with other 
ds@1952
   544
 * algorithms nicely.
ds@1952
   545
 *
ds@1952
   546
 * @param client		Client index.  The server (0) will never be passed.
ds@1952
   547
 * @param blocked		True if client flooded last "say", false otherwise.
ds@1952
   548
 * @noreturn
ds@1952
   549
 */
ds@1952
   550
forward OnClientFloodResult(client, bool:blocked);
ds@1952
   551
ds@1952
   552
#include <helpers>
ds@1952
   553
#include <entity>
ds@1952
   554
#include <entity_prop_stocks>
ds@1952
   555