plugins/include/admin.inc
author Scott Ehlert <ds@alliedmods.net>
Sun Mar 30 07:00:22 2008 +0000 (2008-03-30)
changeset 1952 b7aa2b626807
child 2289 44045ead61cd
permissions -rw-r--r--
Spring Cleaning, Part Ichi (1)
Various minor things done to project files
Updated sample extension project file and updated makefile to the new unified version (more changes likely on the way)
Updated regex project file and makefile
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 _admin_included
ds@1952
    34
 #endinput
ds@1952
    35
#endif
ds@1952
    36
#define _admin_included
ds@1952
    37
ds@1952
    38
/**
ds@1952
    39
 * Access levels (flags) for admins.
ds@1952
    40
 */
ds@1952
    41
enum AdminFlag
ds@1952
    42
{
ds@1952
    43
	Admin_Reservation = 0,	/**< Reserved slot */
ds@1952
    44
	Admin_Generic,			/**< Generic admin abilities */
ds@1952
    45
	Admin_Kick,				/**< Kick another user */
ds@1952
    46
	Admin_Ban,				/**< Ban another user */
ds@1952
    47
	Admin_Unban,			/**< Unban another user */
ds@1952
    48
	Admin_Slay,				/**< Slay/kill/damage another user */
ds@1952
    49
	Admin_Changemap,		/**< Change the map */
ds@1952
    50
	Admin_Convars,			/**< Change basic convars */
ds@1952
    51
	Admin_Config,			/**< Change configuration */
ds@1952
    52
	Admin_Chat,				/**< Special chat privileges */
ds@1952
    53
	Admin_Vote,				/**< Special vote privileges */
ds@1952
    54
	Admin_Password,			/**< Set a server password */
ds@1952
    55
	Admin_RCON,				/**< Use RCON */
ds@1952
    56
	Admin_Cheats,			/**< Change sv_cheats and use its commands */
ds@1952
    57
	Admin_Root,				/**< All access by default */
ds@1952
    58
	Admin_Custom1,			/**< First custom flag type */
ds@1952
    59
	Admin_Custom2,			/**< Second custom flag type */
ds@1952
    60
	Admin_Custom3,			/**< Third custom flag type */
ds@1952
    61
	Admin_Custom4,			/**< Fourth custom flag type */
ds@1952
    62
	Admin_Custom5,			/**< Fifth custom flag type */
ds@1952
    63
	Admin_Custom6,			/**< Sixth custom flag type */
ds@1952
    64
	/* --- */
ds@1952
    65
};
ds@1952
    66
ds@1952
    67
#define AdminFlags_TOTAL	21		/**< Total number of admin flags */
ds@1952
    68
ds@1952
    69
/**
ds@1952
    70
 * @section Bitwise values definitions for admin flags.
ds@1952
    71
 */
ds@1952
    72
#define ADMFLAG_RESERVATION			(1<<0)		/**< Convenience macro for Admin_Reservation as a FlagBit */
ds@1952
    73
#define ADMFLAG_GENERIC				(1<<1)		/**< Convenience macro for Admin_Generic as a FlagBit */
ds@1952
    74
#define ADMFLAG_KICK				(1<<2)		/**< Convenience macro for Admin_Kick as a FlagBit */
ds@1952
    75
#define ADMFLAG_BAN					(1<<3)		/**< Convenience macro for Admin_Ban as a FlagBit */
ds@1952
    76
#define ADMFLAG_UNBAN				(1<<4)		/**< Convenience macro for Admin_Unban as a FlagBit */
ds@1952
    77
#define ADMFLAG_SLAY				(1<<5)		/**< Convenience macro for Admin_Slay as a FlagBit */
ds@1952
    78
#define ADMFLAG_CHANGEMAP			(1<<6)		/**< Convenience macro for Admin_Changemap as a FlagBit */
ds@1952
    79
#define ADMFLAG_CONVARS				(1<<7)		/**< Convenience macro for Admin_Convars as a FlagBit */
ds@1952
    80
#define ADMFLAG_CONFIG				(1<<8)		/**< Convenience macro for Admin_Config as a FlagBit */
ds@1952
    81
#define ADMFLAG_CHAT				(1<<9)		/**< Convenience macro for Admin_Chat as a FlagBit */
ds@1952
    82
#define ADMFLAG_VOTE				(1<<10)		/**< Convenience macro for Admin_Vote as a FlagBit */
ds@1952
    83
#define ADMFLAG_PASSWORD			(1<<11)		/**< Convenience macro for Admin_Password as a FlagBit */
ds@1952
    84
#define ADMFLAG_RCON				(1<<12)		/**< Convenience macro for Admin_RCON as a FlagBit */
ds@1952
    85
#define ADMFLAG_CHEATS				(1<<13)		/**< Convenience macro for Admin_Cheats as a FlagBit */
ds@1952
    86
#define ADMFLAG_ROOT				(1<<14)		/**< Convenience macro for Admin_Root as a FlagBit */
ds@1952
    87
#define ADMFLAG_CUSTOM1				(1<<15)		/**< Convenience macro for Admin_Custom1 as a FlagBit */
ds@1952
    88
#define ADMFLAG_CUSTOM2				(1<<16)		/**< Convenience macro for Admin_Custom2 as a FlagBit */
ds@1952
    89
#define ADMFLAG_CUSTOM3				(1<<17)		/**< Convenience macro for Admin_Custom3 as a FlagBit */
ds@1952
    90
#define ADMFLAG_CUSTOM4				(1<<18)		/**< Convenience macro for Admin_Custom4 as a FlagBit */
ds@1952
    91
#define ADMFLAG_CUSTOM5				(1<<19)		/**< Convenience macro for Admin_Custom5 as a FlagBit */
ds@1952
    92
#define ADMFLAG_CUSTOM6				(1<<20)		/**< Convenience macro for Admin_Custom6 as a FlagBit */
ds@1952
    93
ds@1952
    94
/**
ds@1952
    95
 * @endsection
ds@1952
    96
 */
ds@1952
    97
ds@1952
    98
/**
ds@1952
    99
 * @section Hardcoded authentication methods 
ds@1952
   100
 */
ds@1952
   101
#define AUTHMETHOD_STEAM			"steam"		/**< SteamID based authentication */
ds@1952
   102
#define AUTHMETHOD_IP				"ip"		/**< IP based authentication */
ds@1952
   103
#define AUTHMETHOD_NAME				"name"		/**< Name based authentication */
ds@1952
   104
ds@1952
   105
/**
ds@1952
   106
 * @endsection
ds@1952
   107
 */
ds@1952
   108
ds@1952
   109
/**
ds@1952
   110
 * Access override types.
ds@1952
   111
 */
ds@1952
   112
enum OverrideType
ds@1952
   113
{
ds@1952
   114
	Override_Command = 1,	/**< Command */
ds@1952
   115
	Override_CommandGroup,	/**< Command group */
ds@1952
   116
};
ds@1952
   117
ds@1952
   118
/**
ds@1952
   119
 * Access override rules.
ds@1952
   120
 */
ds@1952
   121
enum OverrideRule
ds@1952
   122
{
ds@1952
   123
	Command_Deny = 0,
ds@1952
   124
	Command_Allow = 1,
ds@1952
   125
};
ds@1952
   126
ds@1952
   127
/**
ds@1952
   128
 * DEPRECATED, do not use.
ds@1952
   129
 */
ds@1952
   130
enum ImmunityType
ds@1952
   131
{
ds@1952
   132
	Immunity_Default = 1,	/**< Deprecated. */
ds@1952
   133
	Immunity_Global,		/**< Deprecated. */
ds@1952
   134
};
ds@1952
   135
ds@1952
   136
/** 
ds@1952
   137
 * Identifies a unique entry in the group permissions cache.  These are not Handles.
ds@1952
   138
 */
ds@1952
   139
enum GroupId
ds@1952
   140
{
ds@1952
   141
	INVALID_GROUP_ID = -1,	/**< An invalid/nonexistant group */
ds@1952
   142
};
ds@1952
   143
ds@1952
   144
/** 
ds@1952
   145
 * Identifies a unique entry in the admin permissions cache.  These are not Handles.
ds@1952
   146
 */
ds@1952
   147
enum AdminId
ds@1952
   148
{
ds@1952
   149
	INVALID_ADMIN_ID = -1,	/**< An invalid/nonexistant admin */
ds@1952
   150
};
ds@1952
   151
ds@1952
   152
/**
ds@1952
   153
 * Methods of computing access permissions.
ds@1952
   154
 */
ds@1952
   155
enum AdmAccessMode
ds@1952
   156
{
ds@1952
   157
	Access_Real,		/**< Access the user has inherently */
ds@1952
   158
	Access_Effective,	/**< Access the user has from their groups */
ds@1952
   159
};
ds@1952
   160
ds@1952
   161
/**
ds@1952
   162
 * Represents the various cache regions.
ds@1952
   163
 */
ds@1952
   164
enum AdminCachePart
ds@1952
   165
{
ds@1952
   166
	AdminCache_Overrides = 0,		/**< Global overrides */
ds@1952
   167
	AdminCache_Groups = 1,			/**< All groups (automatically invalidates admins too) */
ds@1952
   168
	AdminCache_Admins = 2,			/**< All admins */
ds@1952
   169
};
ds@1952
   170
ds@1952
   171
/**
ds@1952
   172
 * Called when part of the cache which needs to be rebuilt.
ds@1952
   173
 *
ds@1952
   174
 * @param part			Part of the admin cache to rebuild.
ds@1952
   175
 */
ds@1952
   176
forward OnRebuildAdminCache(AdminCachePart:part);
ds@1952
   177
ds@1952
   178
/**
ds@1952
   179
 * Tells the admin system to dump a portion of the cache.
ds@1952
   180
 *
ds@1952
   181
 * @param part			Part of the cache to dump.  Specifying groups also dumps admins.
ds@1952
   182
 * @param rebuild		If true, the rebuild forwards will fire.
ds@1952
   183
 * @noreturn
ds@1952
   184
 */
ds@1952
   185
native DumpAdminCache(AdminCachePart:part, bool:rebuild);
ds@1952
   186
ds@1952
   187
/**
ds@1952
   188
 * Adds a global command flag override.  Any command registered with this name
ds@1952
   189
 * will assume the new flag.  This is applied retroactively as well.
ds@1952
   190
 *
ds@1952
   191
 * @param cmd			String containing command name (case sensitive).
ds@1952
   192
 * @param type			Override type (specific command or group).
ds@1952
   193
 * @param flags			New admin flag.
ds@1952
   194
 * @noreturn
ds@1952
   195
 */
ds@1952
   196
native AddCommandOverride(const String:cmd[], OverrideType:type, flags);
ds@1952
   197
ds@1952
   198
/**
ds@1952
   199
 * Returns a command override.
ds@1952
   200
 *
ds@1952
   201
 * @param cmd			String containing command name (case sensitive).
ds@1952
   202
 * @param type			Override type (specific command or group).
ds@1952
   203
 * @param flags			By-reference cell to store the flag (undefined if not found).
ds@1952
   204
 * @return				True if there is an override, false otherwise.
ds@1952
   205
 */
ds@1952
   206
native bool:GetCommandOverride(const String:cmd[], OverrideType:type, &flags);
ds@1952
   207
ds@1952
   208
/**
ds@1952
   209
 * Unsets a command override.
ds@1952
   210
 *
ds@1952
   211
 * @param cmd			String containing command name (case sensitive).
ds@1952
   212
 * @param type			Override type (specific command or group).
ds@1952
   213
 * @noreturn
ds@1952
   214
 */
ds@1952
   215
native UnsetCommandOverride(const String:cmd[], OverrideType:type);
ds@1952
   216
ds@1952
   217
/**
ds@1952
   218
 * Adds a new group.  Name must be unique.
ds@1952
   219
 *
ds@1952
   220
 * @param group_name	String containing the group name.
ds@1952
   221
 * @return				A new group id, INVALID_GROUP_ID if it already exists.
ds@1952
   222
 */
ds@1952
   223
native GroupId:CreateAdmGroup(const String:group_name[]);
ds@1952
   224
ds@1952
   225
/**
ds@1952
   226
 * Finds a group by name.
ds@1952
   227
 *
ds@1952
   228
 * @param group_name	String containing the group name.
ds@1952
   229
 * @return				A group id, or INVALID_GROUP_ID if not found.
ds@1952
   230
 */
ds@1952
   231
native GroupId:FindAdmGroup(const String:group_name[]);
ds@1952
   232
ds@1952
   233
/**
ds@1952
   234
 * Adds or removes a flag from a group's flag set.
ds@1952
   235
 * @note These are called "add flags" because they add to a user's flags.
ds@1952
   236
 *
ds@1952
   237
 * @param id			Group id.
ds@1952
   238
 * @param flag			Admin flag to toggle.
ds@1952
   239
 * @param enabled		True to set the flag, false to unset/disable.
ds@1952
   240
 * @noreturn
ds@1952
   241
 */
ds@1952
   242
native SetAdmGroupAddFlag(GroupId:id, AdminFlag:flag, bool:enabled);
ds@1952
   243
ds@1952
   244
/**
ds@1952
   245
 * Gets the set value of an add flag on a group's flag set.
ds@1952
   246
 * @note These are called "add flags" because they add to a user's flags.
ds@1952
   247
 *
ds@1952
   248
 * @param id			Group id.
ds@1952
   249
 * @param flag			Admin flag to retrieve.
ds@1952
   250
 * @return				True if enabled, false otherwise,
ds@1952
   251
 */
ds@1952
   252
native bool:GetAdmGroupAddFlag(GroupId:id, AdminFlag:flag);
ds@1952
   253
ds@1952
   254
/**
ds@1952
   255
 * Returns the flag set that is added to a user from their group.
ds@1952
   256
 * @note These are called "add flags" because they add to a user's flags.
ds@1952
   257
 *
ds@1952
   258
 * @param id			GroupId of the group.
ds@1952
   259
 * @return				Bitstring containing the flags enabled.
ds@1952
   260
 */
ds@1952
   261
native GetAdmGroupAddFlags(GroupId:id);
ds@1952
   262
ds@1952
   263
/**
ds@1952
   264
 * @deprecated			Functionality removed.
ds@1952
   265
 */
ds@1952
   266
#pragma deprecated Use SetAdmGroupImmunityLevel() instead.
ds@1952
   267
native SetAdmGroupImmunity(GroupId:id, ImmunityType:type, bool:enabled);
ds@1952
   268
ds@1952
   269
/**
ds@1952
   270
 * @deprecated			Functionality removed.
ds@1952
   271
 */
ds@1952
   272
#pragma deprecated Use GetAdmGroupImmunityLevel() instead.
ds@1952
   273
native bool:GetAdmGroupImmunity(GroupId:id, ImmunityType:type);
ds@1952
   274
ds@1952
   275
/**
ds@1952
   276
 * Adds immunity to a specific group.
ds@1952
   277
 *
ds@1952
   278
 * @param id			Group id.
ds@1952
   279
 * @param other_id		Group id to receive immunity to.
ds@1952
   280
 * @noreturn
ds@1952
   281
 */
ds@1952
   282
native SetAdmGroupImmuneFrom(GroupId:id, GroupId:other_id);
ds@1952
   283
ds@1952
   284
/**
ds@1952
   285
 * Returns the number of specific group immunities.
ds@1952
   286
 *
ds@1952
   287
 * @param id			Group id.
ds@1952
   288
 * @return				Number of group immunities.
ds@1952
   289
 */
ds@1952
   290
native GetAdmGroupImmuneCount(GroupId:id);
ds@1952
   291
ds@1952
   292
/**
ds@1952
   293
 * Returns a group that this group is immune to given an index.
ds@1952
   294
 *
ds@1952
   295
 * @param id			Group id.
ds@1952
   296
 * @param number		Index from 0 to N-1, from GetAdmGroupImmuneCount().
ds@1952
   297
 * @return				GroupId that this group is immune to, or INVALID_GROUP_ID on failure.
ds@1952
   298
 */
ds@1952
   299
native GroupId:GetAdmGroupImmuneFrom(GroupId:id, number); 
ds@1952
   300
ds@1952
   301
/**
ds@1952
   302
 * Adds a group-specific override type.
ds@1952
   303
 *
ds@1952
   304
 * @param id			Group id.
ds@1952
   305
 * @param name			String containing command name (case sensitive).
ds@1952
   306
 * @param type			Override type (specific command or group).
ds@1952
   307
 * @param rule			Override allow/deny setting.
ds@1952
   308
 * @noreturn
ds@1952
   309
 */
ds@1952
   310
native AddAdmGroupCmdOverride(GroupId:id, const String:name[], OverrideType:type, OverrideRule:rule);
ds@1952
   311
ds@1952
   312
/**
ds@1952
   313
 * Retrieves a group-specific command override.
ds@1952
   314
 *
ds@1952
   315
 * @param id			Group id.
ds@1952
   316
 * @param name			String containing command name (case sensitive).
ds@1952
   317
 * @param type			Override type (specific command or group).
ds@1952
   318
 * @param rule			Optional pointer to store allow/deny setting.
ds@1952
   319
 * @return				True if an override exists, false otherwise.
ds@1952
   320
 */
ds@1952
   321
native bool:GetAdmGroupCmdOverride(GroupId:id, const String:name[], OverrideType:type, &OverrideRule:rule);
ds@1952
   322
ds@1952
   323
/**
ds@1952
   324
 * Registers an authentication identity type.  You normally never need to call this except for 
ds@1952
   325
 * very specific systems.
ds@1952
   326
 *
ds@1952
   327
 * @param codename		Codename to use for your authentication type.
ds@1952
   328
 * @noreturn
ds@1952
   329
 */
ds@1952
   330
native RegisterAuthIdentType(const String:name[]);
ds@1952
   331
ds@1952
   332
/**
ds@1952
   333
 * Creates a new admin entry in the permissions cache.
ds@1952
   334
 *
ds@1952
   335
 * @param name			Name for this entry (does not have to be unique).
ds@1952
   336
 * 						Specify an empty string for an anonymous admin.
ds@1952
   337
 */
ds@1952
   338
native AdminId:CreateAdmin(const String:name[]="");
ds@1952
   339
ds@1952
   340
/**
ds@1952
   341
 * Retrieves an admin's user name as made with CreateAdmin().
ds@1952
   342
 *
ds@1952
   343
 * @note This function can return UTF-8 strings, and will safely chop UTF-8 strings.
ds@1952
   344
 *
ds@1952
   345
 * @param id			AdminId of the admin.
ds@1952
   346
 * @param name			String buffer to store name.
ds@1952
   347
 * @param maxlength		Maximum size of string buffer.
ds@1952
   348
 * @return				Number of bytes written.
ds@1952
   349
 */
ds@1952
   350
native GetAdminUsername(AdminId:id, const String:name[], maxlength);
ds@1952
   351
ds@1952
   352
/**
ds@1952
   353
 * Binds an admin to an identity for fast lookup later on.  The bind must be unique.
ds@1952
   354
 *
ds@1952
   355
 * @param id			AdminId of the admin.
ds@1952
   356
 * @param auth			Auth method to use, predefined or from RegisterAuthIdentType().
ds@1952
   357
 * @param ident			String containing the arbitrary, unique identity.
ds@1952
   358
 * @return				True on success, false if the auth method was not found,
ds@1952
   359
 *						or ident was already taken.
ds@1952
   360
 */
ds@1952
   361
native bool:BindAdminIdentity(AdminId:id, const String:auth[], const String:ident[]);
ds@1952
   362
ds@1952
   363
/**
ds@1952
   364
 * Sets whether or not a flag is enabled on an admin.
ds@1952
   365
 *
ds@1952
   366
 * @param id			AdminId index of the admin.
ds@1952
   367
 * @param flag			Admin flag to use.
ds@1952
   368
 * @param enabled		True to enable, false to disable.
ds@1952
   369
 * @noreturn
ds@1952
   370
 */
ds@1952
   371
native SetAdminFlag(AdminId:id, AdminFlag:flag, bool:enabled);
ds@1952
   372
ds@1952
   373
/**
ds@1952
   374
 * Returns whether or not a flag is enabled on an admin.
ds@1952
   375
 *
ds@1952
   376
 * @param id			AdminId index of the admin.
ds@1952
   377
 * @param flag			Admin flag to use.
ds@1952
   378
 * @param mode			Access mode to check.
ds@1952
   379
 * @return				True if enabled, false otherwise.
ds@1952
   380
 */
ds@1952
   381
native bool:GetAdminFlag(AdminId:id, AdminFlag:flag, AdmAccessMode:mode=Access_Effective);
ds@1952
   382
ds@1952
   383
/**
ds@1952
   384
 * Returns the bitstring of access flags on an admin.
ds@1952
   385
 *
ds@1952
   386
 * @param id			AdminId index of the admin.
ds@1952
   387
 * @param mode			Access mode to use.
ds@1952
   388
 * @return				A bitstring containing which flags are enabled.
ds@1952
   389
 */
ds@1952
   390
native GetAdminFlags(AdminId:id, AdmAccessMode:mode);
ds@1952
   391
ds@1952
   392
/**
ds@1952
   393
 * Adds a group to an admin's inherited group list.  Any flags the group has 
ds@1952
   394
 * will be added to the admin's effective flags.
ds@1952
   395
 *
ds@1952
   396
 * @param id			AdminId index of the admin.
ds@1952
   397
 * @param gid			GroupId index of the group.
ds@1952
   398
 * @return				True on success, false on invalid input or duplicate membership.
ds@1952
   399
 */
ds@1952
   400
native bool:AdminInheritGroup(AdminId:id, GroupId:gid);
ds@1952
   401
ds@1952
   402
/**
ds@1952
   403
 * Returns the number of groups this admin is a member of.
ds@1952
   404
 * 
ds@1952
   405
 * @param id			AdminId index of the admin.
ds@1952
   406
 * @return				Number of groups this admin is a member of.
ds@1952
   407
 */
ds@1952
   408
native GetAdminGroupCount(AdminId:id);
ds@1952
   409
ds@1952
   410
/**
ds@1952
   411
 * Returns group information from an admin.
ds@1952
   412
 *
ds@1952
   413
 * @param id        	AdminId index of the admin.
ds@1952
   414
 * @param index			Group number to retrieve, from 0 to N-1, where N
ds@1952
   415
 *						is the value of GetAdminGroupCount(id).
ds@1952
   416
 * @param name			Buffer to store the group's name.
ds@1952
   417
 *						Note: This will safely chop UTF-8 strings.
ds@1952
   418
 * @param maxlength		Maximum size of the output name buffer.
ds@1952
   419
 * @return				A GroupId index and a name pointer, or
ds@1952
   420
 *						INVALID_GROUP_ID and NULL if an error occurred.
ds@1952
   421
*/
ds@1952
   422
native GroupId:GetAdminGroup(AdminId:id, index, const String:name[], maxlength);
ds@1952
   423
ds@1952
   424
/**
ds@1952
   425
 * Sets a password on an admin.
ds@1952
   426
 *
ds@1952
   427
 * @param id			AdminId index of the admin.
ds@1952
   428
 * @param passwd		String containing the password.
ds@1952
   429
 * @noreturn
ds@1952
   430
 */
ds@1952
   431
native SetAdminPassword(AdminId:id, const String:password[]);
ds@1952
   432
ds@1952
   433
/**
ds@1952
   434
 * Gets an admin's password.
ds@1952
   435
 *
ds@1952
   436
 * @param id			AdminId index of the admin.
ds@1952
   437
 * @param name			Optional buffer to store the admin's password.
ds@1952
   438
 * @param maxlength		Maximum size of the output name buffer.
ds@1952
   439
 *						Note: This will safely chop UTF-8 strings.
ds@1952
   440
 * @return				True if there was a password set, false otherwise.
ds@1952
   441
 */
ds@1952
   442
native bool:GetAdminPassword(AdminId:id, const String:buffer[]="", maxlength=0);
ds@1952
   443
ds@1952
   444
/**
ds@1952
   445
 * Attempts to find an admin by an auth method and an identity.
ds@1952
   446
 *
ds@1952
   447
 * @param auth			Auth method to try.
ds@1952
   448
 * @param identity		Identity string to look up.
ds@1952
   449
 * @return				An AdminId index if found, INVALID_ADMIN_ID otherwise.
ds@1952
   450
 */
ds@1952
   451
native AdminId:FindAdminByIdentity(const String:auth[], const String:identity[]);
ds@1952
   452
ds@1952
   453
/**
ds@1952
   454
 * Removes an admin entry from the cache.
ds@1952
   455
 *
ds@1952
   456
 * @note This will remove any bindings to a specific user.
ds@1952
   457
 *
ds@1952
   458
 * @param id			AdminId index to remove/invalidate.
ds@1952
   459
 * @return				True on success, false otherwise.
ds@1952
   460
 */
ds@1952
   461
native bool:RemoveAdmin(AdminId:id);
ds@1952
   462
ds@1952
   463
/**
ds@1952
   464
 * Converts a flag bit string to a bit array.
ds@1952
   465
 *
ds@1952
   466
 * @param bits			Bit string containing the flags.
ds@1952
   467
 * @param array			Array to write the flags to.  Enabled flags will be 'true'.
ds@1952
   468
 * @param maxSize		Maximum number of flags the array can store.
ds@1952
   469
 * @return				Number of flags written.
ds@1952
   470
 */
ds@1952
   471
native FlagBitsToBitArray(bits, bool:array[], maxSize);
ds@1952
   472
ds@1952
   473
/**
ds@1952
   474
 * Converts a flag array to a bit string.
ds@1952
   475
 *
ds@1952
   476
 * @param array			Array containing true or false for each AdminFlag.
ds@1952
   477
 * @param maxSize		Maximum size of the flag array.
ds@1952
   478
 * @return				A bit string composed of the array bits.
ds@1952
   479
 */
ds@1952
   480
native FlagBitArrayToBits(const bool:array[], maxSize);
ds@1952
   481
ds@1952
   482
/**
ds@1952
   483
 * Converts an array of flags to bits.
ds@1952
   484
 *
ds@1952
   485
 * @param array			Array containing flags that are enabled.
ds@1952
   486
 * @param numFlags		Number of flags in the array.
ds@1952
   487
 * @return				A bit string composed of the array flags.
ds@1952
   488
 */
ds@1952
   489
native FlagArrayToBits(const AdminFlag:array[], numFlags);
ds@1952
   490
ds@1952
   491
/**
ds@1952
   492
 * Converts a bit string to an array of flags.
ds@1952
   493
 *
ds@1952
   494
 * @param bits			Bit string containing the flags.
ds@1952
   495
 * @param array			Output array to write flags.
ds@1952
   496
 * @param maxSize		Maximum size of the flag array.
ds@1952
   497
 * @return				Number of flags written.
ds@1952
   498
 */
ds@1952
   499
native FlagBitsToArray(bits, AdminFlag:array[], maxSize);
ds@1952
   500
ds@1952
   501
/**
ds@1952
   502
 * Finds a flag by its string name.
ds@1952
   503
 *
ds@1952
   504
 * @param name			Flag name (like "kick"), case sensitive.
ds@1952
   505
 * @param flag			Variable to store flag in.
ds@1952
   506
 * @return				True on success, false if not found.
ds@1952
   507
 */
ds@1952
   508
native bool:FindFlagByName(const String:name[], &AdminFlag:flag);
ds@1952
   509
ds@1952
   510
/**
ds@1952
   511
 * Finds a flag by a given character.
ds@1952
   512
 *
ds@1952
   513
 * @param c				Flag ASCII character/token.
ds@1952
   514
 * @param flag			Variable to store flag in.
ds@1952
   515
 * @return				True on success, false if not found.
ds@1952
   516
 */
ds@1952
   517
native bool:FindFlagByChar(c, &AdminFlag:flag);
ds@1952
   518
ds@1952
   519
/**
ds@1952
   520
 * Converts a string of flag characters to a bit string.
ds@1952
   521
 *
ds@1952
   522
 * @param flags			Flag ASCII string.
ds@1952
   523
 * @param numchars		Optional variable to store the number of bytes read.
ds@1952
   524
 * @return				Bit string of ADMFLAG values.
ds@1952
   525
 */
ds@1952
   526
native ReadFlagString(const String:flags[], &numchars=0);
ds@1952
   527
ds@1952
   528
/**
ds@1952
   529
 * Tests whether one admin can target another.
ds@1952
   530
 *
ds@1952
   531
 * The hueristics for this check are as follows:
ds@1952
   532
 * 0. If the targeting AdminId is INVALID_ADMIN_ID, targeting fails.
ds@1952
   533
 * 1. If the targeted AdminId is INVALID_ADMIN_ID, targeting succeeds.
ds@1952
   534
 * 2. If the targeted AdminId is the same as the targeting AdminId,
ds@1952
   535
 *    (self) targeting succeeds.
ds@1952
   536
 * 3. If the targeting admin is root, targeting succeeds.
ds@1952
   537
 * 4. If the targeted admin has access higher (as interpreted by 
ds@1952
   538
 *    (sm_immunity_mode) than the targeting admin, then targeting fails.
ds@1952
   539
 * 5. If the targeted admin has specific immunity from the
ds@1952
   540
 *    targeting admin via group immunities, targeting fails.
ds@1952
   541
 * 6. Targeting succeeds.
ds@1952
   542
 *
ds@1952
   543
 * @param admin			Admin doing the targetting (may be INVALID_ADMIN_ID).
ds@1952
   544
 * @param target		Target admin (may be INVALID_ADMIN_ID).
ds@1952
   545
 * @return				True if targetable, false if immune.
ds@1952
   546
 */
ds@1952
   547
native CanAdminTarget(AdminId:admin, AdminId:target);
ds@1952
   548
ds@1952
   549
/**
ds@1952
   550
 * Creates an admin auth method.  This does not need to be called more than once
ds@1952
   551
 * per method, ever.
ds@1952
   552
 *
ds@1952
   553
 * @param method		Name of the authentication method.
ds@1952
   554
 * @return				True on success, false on failure.
ds@1952
   555
 */
ds@1952
   556
native bool:CreateAuthMethod(const String:method[]);
ds@1952
   557
ds@1952
   558
/**
ds@1952
   559
 * Sets a group's immunity level.
ds@1952
   560
 *
ds@1952
   561
 * @param gid			Group Id.
ds@1952
   562
 * @param level			Immunity level value.
ds@1952
   563
 * @return				Old immunity level value.
ds@1952
   564
 */
ds@1952
   565
native SetAdmGroupImmunityLevel(GroupId:gid, level);
ds@1952
   566
ds@1952
   567
/**
ds@1952
   568
 * Gets a group's immunity level (defaults to 0).
ds@1952
   569
 *
ds@1952
   570
 * @param gid			Group Id.
ds@1952
   571
 * @return				Immunity level value.
ds@1952
   572
 */
ds@1952
   573
native GetAdmGroupImmunityLevel(GroupId:gid);
ds@1952
   574
ds@1952
   575
/**
ds@1952
   576
 * Sets an admin's immunity level.
ds@1952
   577
 *
ds@1952
   578
 * @param id			Admin Id.
ds@1952
   579
 * @param level			Immunity level value.
ds@1952
   580
 * @return				Old immunity level value.
ds@1952
   581
 */
ds@1952
   582
native SetAdminImmunityLevel(AdminId:id, level);
ds@1952
   583
ds@1952
   584
/**
ds@1952
   585
 * Gets an admin's immunity level.
ds@1952
   586
 *
ds@1952
   587
 * @param id			Admin Id.
ds@1952
   588
 * @return				Immunity level value.
ds@1952
   589
 */
ds@1952
   590
native GetAdminImmunityLevel(AdminId:id);
ds@1952
   591
ds@1952
   592
/**
ds@1952
   593
 * Converts a flag to its single bit.
ds@1952
   594
 * 
ds@1952
   595
 * @param flag			Flag to convert.
ds@1952
   596
 * @return				Bit representation of the flag.
ds@1952
   597
 */
ds@1952
   598
stock FlagToBit(AdminFlag:flag)
ds@1952
   599
{
ds@1952
   600
	return (1<<_:flag);
ds@1952
   601
}
ds@1952
   602
ds@1952
   603
/**
ds@1952
   604
 * Converts a bit to an AdminFlag.
ds@1952
   605
 *
ds@1952
   606
 * @param bit			Bit to convert.
ds@1952
   607
 * @param flag			Stores the converted flag by reference.
ds@1952
   608
 * @return				True on success, false otherwise.
ds@1952
   609
 */
ds@1952
   610
stock bool:BitToFlag(bit, &AdminFlag:flag)
ds@1952
   611
{
ds@1952
   612
	new AdminFlag:array[1];
ds@1952
   613
	
ds@1952
   614
	if (FlagBitsToArray(bit, array, 1))
ds@1952
   615
	{
ds@1952
   616
		flag = array[0];
ds@1952
   617
		return true;
ds@1952
   618
	}
ds@1952
   619
	
ds@1952
   620
	return false;
ds@1952
   621
}
ds@1952
   622