public/IAdminSystem.h
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
ds@1952
     5
 * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
ds@1952
     6
 * =============================================================================
ds@1952
     7
 *
ds@1952
     8
 * This program is free software; you can redistribute it and/or modify it under
ds@1952
     9
 * the terms of the GNU General Public License, version 3.0, as published by the
ds@1952
    10
 * Free Software Foundation.
ds@1952
    11
 * 
ds@1952
    12
 * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1952
    13
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1952
    14
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
ds@1952
    15
 * details.
ds@1952
    16
 *
ds@1952
    17
 * You should have received a copy of the GNU General Public License along with
ds@1952
    18
 * this program.  If not, see <http://www.gnu.org/licenses/>.
ds@1952
    19
 *
ds@1952
    20
 * As a special exception, AlliedModders LLC gives you permission to link the
ds@1952
    21
 * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1952
    22
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1952
    23
 * by the Valve Corporation.  You must obey the GNU General Public License in
ds@1952
    24
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
ds@1952
    25
 * this exception to all derivative works.  AlliedModders LLC defines further
ds@1952
    26
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1952
    27
 * or <http://www.sourcemod.net/license.php>.
ds@1952
    28
 *
ds@1952
    29
 * Version: $Id$
ds@1952
    30
 */
ds@1952
    31
ds@1952
    32
#ifndef _INCLUDE_SOURCEMOD_ADMINISTRATION_SYSTEM_H_
ds@1952
    33
#define _INCLUDE_SOURCEMOD_ADMINISTRATION_SYSTEM_H_
ds@1952
    34
ds@1952
    35
#include <IShareSys.h>
ds@1952
    36
ds@1952
    37
#define SMINTERFACE_ADMINSYS_NAME		"IAdminSys"
ds@1952
    38
#define SMINTERFACE_ADMINSYS_VERSION	5
ds@1952
    39
ds@1952
    40
/**
ds@1952
    41
 * @file IAdminSystem.h
ds@1952
    42
 * @brief Defines the interface to manage the Admin Users/Groups and Override caches.
ds@1952
    43
 *
ds@1952
    44
 *   The administration system is more of a volatile cache than a system.  It is designed to be 
ds@1952
    45
 * temporary rather than permanent, in order to compensate for more storage methods.  For example,
ds@1952
    46
 * a flat file might be read into the cache all at once.  But a MySQL-based system might only cache
ds@1952
    47
 * admin permissions when that specific admin connects.  
ds@1952
    48
 *
ds@1952
    49
 *   The override cache is the simplest to explain.  Any time an override is added, any existing 
ds@1952
    50
 * and all future commands will gain a new access level set by the override.  If unset, the default
ds@1952
    51
 * access level is restored.  This cache is dynamically changeable.
ds@1952
    52
 *
ds@1952
    53
 *   The group cache contains, for each group:
ds@1952
    54
 *	1] A set of inherent flags - fully readable/writable.
ds@1952
    55
 *  2] An immunity table - insertion and retrieval only.
ds@1952
    56
 *  3] An override table - insertion and retrieval only.
ds@1952
    57
 *   Individual groups can be invalidated entirely.  It should be considered an expensive
ds@1952
    58
 *  operation, since each admin needs to be patched up to not reference the group.
ds@1952
    59
 *
ds@1952
    60
 *   For more information, see the SourceMod Development wiki.
ds@1952
    61
 */
ds@1952
    62
ds@1952
    63
namespace SourceMod
ds@1952
    64
{
ds@1952
    65
	/**
ds@1952
    66
	 * @brief Access levels (flags) for admins.
ds@1952
    67
	 */
ds@1952
    68
	enum AdminFlag
ds@1952
    69
	{
ds@1952
    70
		Admin_Reservation = 0,	/**< Reserved slot */
ds@1952
    71
		Admin_Generic,			/**< Generic admin abilities */
ds@1952
    72
		Admin_Kick,				/**< Kick another user */
ds@1952
    73
		Admin_Ban,				/**< Ban another user */
ds@1952
    74
		Admin_Unban,			/**< Unban another user */
ds@1952
    75
		Admin_Slay,				/**< Slay/kill/damage another user */
ds@1952
    76
		Admin_Changemap,		/**< Change the map */
ds@1952
    77
		Admin_Convars,			/**< Change basic convars */
ds@1952
    78
		Admin_Config,			/**< Change configuration */
ds@1952
    79
		Admin_Chat,				/**< Special chat privileges */
ds@1952
    80
		Admin_Vote,				/**< Special vote privileges */
ds@1952
    81
		Admin_Password,			/**< Set a server password */
ds@1952
    82
		Admin_RCON,				/**< Use RCON */
ds@1952
    83
		Admin_Cheats,			/**< Change sv_cheats and use its commands */
ds@1952
    84
		Admin_Root,				/**< All access by default */
ds@1952
    85
		Admin_Custom1,			/**< First custom flag type */
ds@1952
    86
		Admin_Custom2,			/**< Second custom flag type */
ds@1952
    87
		Admin_Custom3,			/**< Third custom flag type */
ds@1952
    88
		Admin_Custom4,			/**< Fourth custom flag type */
ds@1952
    89
		Admin_Custom5,			/**< Fifth custom flag type */
ds@1952
    90
		Admin_Custom6,			/**< Sixth custom flag type */
ds@1952
    91
		/* --- */
ds@1952
    92
		AdminFlags_TOTAL,
ds@1952
    93
	};
ds@1952
    94
ds@1952
    95
	#define ADMFLAG_RESERVATION			(1<<0)		/**< Convenience macro for Admin_Reservation as a FlagBit */
ds@1952
    96
	#define ADMFLAG_GENERIC				(1<<1)		/**< Convenience macro for Admin_Generic as a FlagBit */
ds@1952
    97
	#define ADMFLAG_KICK				(1<<2)		/**< Convenience macro for Admin_Kick as a FlagBit */
ds@1952
    98
	#define ADMFLAG_BAN					(1<<3)		/**< Convenience macro for Admin_Ban as a FlagBit */
ds@1952
    99
	#define ADMFLAG_UNBAN				(1<<4)		/**< Convenience macro for Admin_Unban as a FlagBit */
ds@1952
   100
	#define ADMFLAG_SLAY				(1<<5)		/**< Convenience macro for Admin_Slay as a FlagBit */
ds@1952
   101
	#define ADMFLAG_CHANGEMAP			(1<<6)		/**< Convenience macro for Admin_Changemap as a FlagBit */
ds@1952
   102
	#define ADMFLAG_CONVARS				(1<<7)		/**< Convenience macro for Admin_Convars as a FlagBit */
ds@1952
   103
	#define ADMFLAG_CONFIG				(1<<8)		/**< Convenience macro for Admin_Config as a FlagBit */
ds@1952
   104
	#define ADMFLAG_CHAT				(1<<9)		/**< Convenience macro for Admin_Chat as a FlagBit */
ds@1952
   105
	#define ADMFLAG_VOTE				(1<<10)		/**< Convenience macro for Admin_Vote as a FlagBit */
ds@1952
   106
	#define ADMFLAG_PASSWORD			(1<<11)		/**< Convenience macro for Admin_Password as a FlagBit */
ds@1952
   107
	#define ADMFLAG_RCON				(1<<12)		/**< Convenience macro for Admin_RCON as a FlagBit */
ds@1952
   108
	#define ADMFLAG_CHEATS				(1<<13)		/**< Convenience macro for Admin_Cheats as a FlagBit */
ds@1952
   109
	#define ADMFLAG_ROOT				(1<<14)		/**< Convenience macro for Admin_Root as a FlagBit */
ds@1952
   110
	#define ADMFLAG_CUSTOM1				(1<<15)		/**< Convenience macro for Admin_Custom1 as a FlagBit */
ds@1952
   111
	#define ADMFLAG_CUSTOM2				(1<<16)		/**< Convenience macro for Admin_Custom2 as a FlagBit */
ds@1952
   112
	#define ADMFLAG_CUSTOM3				(1<<17)		/**< Convenience macro for Admin_Custom3 as a FlagBit */
ds@1952
   113
	#define ADMFLAG_CUSTOM4				(1<<18)		/**< Convenience macro for Admin_Custom4 as a FlagBit */
ds@1952
   114
	#define ADMFLAG_CUSTOM5				(1<<19)		/**< Convenience macro for Admin_Custom5 as a FlagBit */
ds@1952
   115
	#define ADMFLAG_CUSTOM6				(1<<20)		/**< Convenience macro for Admin_Custom6 as a FlagBit */
ds@1952
   116
ds@1952
   117
	/**
ds@1952
   118
	 * @brief Specifies which type of command to override (command or command group).
ds@1952
   119
	 */
ds@1952
   120
	enum OverrideType
ds@1952
   121
	{
ds@1952
   122
		Override_Command = 1,	/**< Command */
ds@1952
   123
		Override_CommandGroup,	/**< Command group */
ds@1952
   124
	};
ds@1952
   125
ds@1952
   126
	/**
ds@1952
   127
	 * @brief Specifies how a command is overridden for a user group.
ds@1952
   128
	 */
ds@1952
   129
	enum OverrideRule
ds@1952
   130
	{
ds@1952
   131
		Command_Deny = 0,		/**< Deny access */
ds@1952
   132
		Command_Allow = 1,		/**< Allow access */
ds@1952
   133
	};
ds@1952
   134
ds@1952
   135
	/**
ds@1952
   136
	 * @brief DEPRECATED.  Specifies a generic immunity type.
ds@1952
   137
	 */
ds@1952
   138
	enum ImmunityType
ds@1952
   139
	{
ds@1952
   140
		Immunity_Default = 1,	/**< Immunity value of 1 */
ds@1952
   141
		Immunity_Global,		/**< Immunity value of 2 */
ds@1952
   142
	};
ds@1952
   143
ds@1952
   144
	/**
ds@1952
   145
	 * @brief Defines user access modes.
ds@1952
   146
	 */
ds@1952
   147
	enum AccessMode
ds@1952
   148
	{
ds@1952
   149
		Access_Real,		/**< Access the user has inherently */
ds@1952
   150
		Access_Effective,	/**< Access the user has from their groups */
ds@1952
   151
	};
ds@1952
   152
ds@1952
   153
	/**
ds@1952
   154
	 * @brief Represents an index to one group.
ds@1952
   155
	 */
ds@1952
   156
	typedef int		GroupId;
ds@1952
   157
ds@1952
   158
	/**
ds@1952
   159
	 * @brief Represents an index to one user entry.
ds@1952
   160
	 */
ds@1952
   161
	typedef int		AdminId;
ds@1952
   162
ds@1952
   163
	/**
ds@1952
   164
	 * @brief Represents an invalid/nonexistent group or an erroneous operation.
ds@1952
   165
	 */
ds@1952
   166
	#define INVALID_GROUP_ID	-1
ds@1952
   167
ds@1952
   168
	/**
ds@1952
   169
	 * @brief Represents an invalid/nonexistent user or an erroneous operation.
ds@1952
   170
	 */
ds@1952
   171
	#define INVALID_ADMIN_ID	-1
ds@1952
   172
ds@1952
   173
	/**
ds@1952
   174
	 * @brief Represents the various cache regions.
ds@1952
   175
	 */
ds@1952
   176
	enum AdminCachePart
ds@1952
   177
	{
ds@1952
   178
		AdminCache_Overrides = 0,		/**< Global overrides */
ds@1952
   179
		AdminCache_Groups = 1,			/**< All groups (automatically invalidates admins too) */
ds@1952
   180
		AdminCache_Admins = 2,			/**< All admins */
ds@1952
   181
	};
ds@1952
   182
ds@1952
   183
	/**
ds@1952
   184
	 * @brief Provides callbacks for admin cache operations.
ds@1952
   185
	 */
ds@1952
   186
	class IAdminListener
ds@1952
   187
	{
ds@1952
   188
	public:
ds@1952
   189
		virtual unsigned int GetInterfaceVersion()
ds@1952
   190
		{
ds@1952
   191
			return SMINTERFACE_ADMINSYS_VERSION;
ds@1952
   192
		}
ds@1952
   193
	public:
ds@1952
   194
		/**
ds@1952
   195
		 * @brief Called when the admin cache needs to be rebuilt.  
ds@1952
   196
		 *
ds@1952
   197
		 * @param auto_rebuild		True if this is being called because of a group rebuild.
ds@1952
   198
		 */
ds@1952
   199
		virtual void OnRebuildAdminCache(bool auto_rebuild) =0;
ds@1952
   200
ds@1952
   201
		/**
ds@1952
   202
		 * @brief Called when the group cache needs to be rebuilt.
ds@1952
   203
		 */
ds@1952
   204
		virtual void OnRebuildGroupCache() =0;
ds@1952
   205
		
ds@1952
   206
		/**
ds@1952
   207
		 * @brief Called when the global override cache needs to be rebuilt.
ds@1952
   208
		 */
ds@1952
   209
		virtual void OnRebuildOverrideCache() =0;
ds@1952
   210
	};
ds@1952
   211
ds@1952
   212
	/**
ds@1952
   213
	 * @brief Admin permission levels.
ds@1952
   214
	 */
ds@1952
   215
	typedef unsigned int FlagBits;
ds@1952
   216
ds@1952
   217
	/**
ds@1952
   218
	 * @brief Provides functions for manipulating the admin options cache.
ds@1952
   219
	 */
ds@1952
   220
	class IAdminSystem : public SMInterface
ds@1952
   221
	{
ds@1952
   222
	public:
ds@1952
   223
		const char *GetInterfaceName()
ds@1952
   224
		{
ds@1952
   225
			return SMINTERFACE_ADMINSYS_NAME;
ds@1952
   226
		}
ds@1952
   227
		unsigned int GetInterfaceVersion()
ds@1952
   228
		{
ds@1952
   229
			return SMINTERFACE_ADMINSYS_VERSION;
ds@1952
   230
		}
ds@1952
   231
	public:
ds@1952
   232
		/**
ds@1952
   233
		 * @brief Adds a global command flag override.  Any command registered with this name
ds@1952
   234
		 * will assume the new flag.  This is applied retroactively as well.
ds@1952
   235
		 *
ds@1952
   236
		 * @param cmd			String containing command name (case sensitive).
ds@1952
   237
		 * @param type			Override type (specific command or group).
ds@1952
   238
		 * @param flags			New admin flag.
ds@1952
   239
		 */
ds@1952
   240
		virtual void AddCommandOverride(const char *cmd, OverrideType type, FlagBits flags) =0;
ds@1952
   241
ds@1952
   242
		/**
ds@1952
   243
		 * @brief Returns a command override.
ds@1952
   244
		 *
ds@1952
   245
		 * @param cmd			String containing command name (case sensitive).
ds@1952
   246
		 * @param type			Override type (specific command or group).
ds@1952
   247
		 * @param pFlags		Optional pointer to the set flag.
ds@1952
   248
		 * @return				True if there is an override, false otherwise.
ds@1952
   249
		 */
ds@1952
   250
		virtual bool GetCommandOverride(const char *cmd, OverrideType type, FlagBits *pFlags) =0;
ds@1952
   251
ds@1952
   252
		/**
ds@1952
   253
		 * @brief Unsets a command override.
ds@1952
   254
		 *
ds@1952
   255
		 * @param cmd			String containing command name (case sensitive).
ds@1952
   256
		 * @param type			Override type (specific command or group).
ds@1952
   257
		 */
ds@1952
   258
		virtual void UnsetCommandOverride(const char *cmd, OverrideType type) =0;
ds@1952
   259
ds@1952
   260
		/**
ds@1952
   261
		 * @brief Adds a new group.  Name must be unique.
ds@1952
   262
		 *
ds@1952
   263
		 * @param group_name	String containing the group name.
ds@1952
   264
		 * @return				A new group id, INVALID_GROUP_ID if it already exists.
ds@1952
   265
		 */
ds@1952
   266
		virtual GroupId AddGroup(const char *group_name) =0;
ds@1952
   267
ds@1952
   268
		/**
ds@1952
   269
		 * @brief Finds a group by name.
ds@1952
   270
		 *
ds@1952
   271
		 * @param group_name	String containing the group name.
ds@1952
   272
		 * @return				A group id, or INVALID_GROUP_ID if not found.
ds@1952
   273
		 */
ds@1952
   274
		virtual GroupId FindGroupByName(const char *group_name) =0;
ds@1952
   275
ds@1952
   276
		/**
ds@1952
   277
		 * @brief Adds or removes a flag from a group's flag set.
ds@1952
   278
		 * Note: These are called "add flags" because they add to a user's flags.
ds@1952
   279
		 *
ds@1952
   280
		 * @param id			Group id.
ds@1952
   281
		 * @param flag			Admin flag to toggle.
ds@1952
   282
		 * @param enabled		True to set the flag, false to unset/disable.
ds@1952
   283
		 */
ds@1952
   284
		virtual void SetGroupAddFlag(GroupId id, AdminFlag flag, bool enabled) =0;
ds@1952
   285
ds@1952
   286
		/**
ds@1952
   287
		 * @brief Gets the set value of an add flag on a group's flag set.
ds@1952
   288
		 *
ds@1952
   289
		 * @param id			Group id.
ds@1952
   290
		 * @param flag			Admin flag to retrieve.
ds@1952
   291
		 * @return				True if enabled, false otherwise,
ds@1952
   292
		 */
ds@1952
   293
		virtual bool GetGroupAddFlag(GroupId id, AdminFlag flag) =0;
ds@1952
   294
ds@1952
   295
		/**
ds@1952
   296
		 * @brief Returns an array of flag bits that are added to a user from their group.
ds@1952
   297
		 * Note: These are called "add flags" because they add to a user's flags.
ds@1952
   298
		 *
ds@1952
   299
		 * @param id			GroupId of the group.
ds@1952
   300
		 * @return				Bit string containing the bits of each flag.
ds@1952
   301
		 */
ds@1952
   302
		virtual FlagBits GetGroupAddFlags(GroupId id) =0;
ds@1952
   303
ds@1952
   304
		/**
ds@1952
   305
		 * @brief DEPRECATED.  Sets a group's immunity level using backwards 
ds@1952
   306
		 * compatible types.  
ds@1952
   307
		 *
ds@1952
   308
		 * If the new level being set is lower than the group's actual immunity 
ds@1952
   309
		 * level, no operation takes place.
ds@1952
   310
		 *
ds@1952
   311
		 * @param id			Group id.
ds@1952
   312
		 * @param type			Immunity type which will be converted to a 
ds@1952
   313
		 * 						numerical level.
ds@1952
   314
		 * @param enabled		True to set the level.  False sets the 
ds@1952
   315
		 * 						group's immunity value to 0.
ds@1952
   316
		 */
ds@1952
   317
		virtual void SetGroupGenericImmunity(GroupId id, ImmunityType type, bool enabled) =0;
ds@1952
   318
ds@1952
   319
		/**
ds@1952
   320
		 * @brief DEPRECATED.  Returns whether a group has an immunity level
ds@1952
   321
		 * using backwards compatible types.
ds@1952
   322
		 * 
ds@1952
   323
		 * This simply checks whether the group's immunity value is greater 
ds@1952
   324
		 * than or equal to the new-style value for the old type.
ds@1952
   325
		 *
ds@1952
   326
		 * @param id			Group id.
ds@1952
   327
		 * @param type			Generic immunity type.
ds@1952
   328
		 * @return				True if the group has this immunity, false 
ds@1952
   329
		 * 						otherwise.
ds@1952
   330
		 */
ds@1952
   331
		virtual bool GetGroupGenericImmunity(GroupId id, ImmunityType type) =0;
ds@1952
   332
ds@1952
   333
		/**
ds@1952
   334
		 * @brief Adds immunity to a specific group.
ds@1952
   335
		 *
ds@1952
   336
		 * @param id			Group id.
ds@1952
   337
		 * @param other_id		Group id to receive immunity to.
ds@1952
   338
		 */
ds@1952
   339
		virtual void AddGroupImmunity(GroupId id, GroupId other_id) =0;
ds@1952
   340
ds@1952
   341
		/**
ds@1952
   342
		 * @brief Returns the number of specific group immunities.
ds@1952
   343
		 *
ds@1952
   344
		 * @param id			Group id.
ds@1952
   345
		 * @return				Number of group immunities.
ds@1952
   346
		 */
ds@1952
   347
		virtual unsigned int GetGroupImmunityCount(GroupId id) =0;
ds@1952
   348
ds@1952
   349
		/**
ds@1952
   350
		 * @brief Returns a group that this group is immune to given an index.
ds@1952
   351
		 *
ds@1952
   352
		 * @param id			Group id.
ds@1952
   353
		 * @param number		Index from 0 to N-1, from GetGroupImmunities().
ds@1952
   354
		 * @return				GroupId that this group is immune to.
ds@1952
   355
		 */
ds@1952
   356
		virtual GroupId GetGroupImmunity(GroupId id, unsigned int number) =0;
ds@1952
   357
ds@1952
   358
		/**
ds@1952
   359
		 * @brief Adds a group-specific override type.
ds@1952
   360
		 *
ds@1952
   361
		 * @param id			Group id.
ds@1952
   362
		 * @param name			String containing command name (case sensitive).
ds@1952
   363
		 * @param type			Override type (specific command or group).
ds@1952
   364
		 * @param rule			Override allow/deny setting.
ds@1952
   365
		 */
ds@1952
   366
		virtual void AddGroupCommandOverride(GroupId id,
ds@1952
   367
											 const char *name,
ds@1952
   368
											 OverrideType type,
ds@1952
   369
											 OverrideRule rule) =0;
ds@1952
   370
ds@1952
   371
		/**
ds@1952
   372
		 * @brief Retrieves a group-specific command override.
ds@1952
   373
		 *
ds@1952
   374
		 * @param id			Group id.
ds@1952
   375
		 * @param name			String containing command name (case sensitive).
ds@1952
   376
		 * @param type			Override type (specific command or group).
ds@1952
   377
		 * @param pRule			Optional pointer to store allow/deny setting.
ds@1952
   378
		 * @return				True if an override exists, false otherwise.
ds@1952
   379
		 */
ds@1952
   380
		virtual bool GetGroupCommandOverride(GroupId id,
ds@1952
   381
											 const char *name,
ds@1952
   382
											 OverrideType type,
ds@1952
   383
											 OverrideRule *pRule) =0;
ds@1952
   384
ds@1952
   385
		/**
ds@1952
   386
		 * @brief Tells the admin system to dump a portion of the cache.  
ds@1952
   387
		 * This calls into plugin forwards to rebuild the cache.
ds@1952
   388
		 *
ds@1952
   389
		 * @param part			Portion of the cache to dump.
ds@1952
   390
		 * @param rebuild		If true, the rebuild forwards/events will fire.
ds@1952
   391
		 */
ds@1952
   392
		virtual void DumpAdminCache(AdminCachePart part, bool rebuild) =0;
ds@1952
   393
ds@1952
   394
		/**
ds@1952
   395
		 * @brief Adds an admin interface listener.
ds@1952
   396
		 *
ds@1952
   397
		 * @param pListener		Pointer to an IAdminListener to add.
ds@1952
   398
		 */
ds@1952
   399
		virtual void AddAdminListener(IAdminListener *pListener) =0;
ds@1952
   400
ds@1952
   401
		/**
ds@1952
   402
		 * @brief Removes an admin interface listener.
ds@1952
   403
		 *
ds@1952
   404
		 * @param pListener		Pointer to an IAdminListener to remove.
ds@1952
   405
		 */
ds@1952
   406
		virtual void RemoveAdminListener(IAdminListener *pListener) =0;
ds@1952
   407
ds@1952
   408
		/**
ds@1952
   409
		 * @brief Registers an authentication identity type.
ds@1952
   410
		 * Note: Default types are "steam," "name," and "ip."
ds@1952
   411
		 *
ds@1952
   412
		 * @param name			String containing the type name.
ds@1952
   413
		 */
ds@1952
   414
		virtual void RegisterAuthIdentType(const char *name) =0;
ds@1952
   415
ds@1952
   416
		/**
ds@1952
   417
		 * @brief Creates a new user entry.
ds@1952
   418
		 *
ds@1952
   419
		 * @param name		Name for this entry (does not have to be unique).
ds@1952
   420
		 *					Specify NULL for an anonymous admin.
ds@1952
   421
		 * @return			A new AdminId index.
ds@1952
   422
		 */
ds@1952
   423
		virtual AdminId CreateAdmin(const char *name) =0;
ds@1952
   424
ds@1952
   425
		/**
ds@1952
   426
		 * @brief Gets an admin's user name.
ds@1952
   427
		 *
ds@1952
   428
		 * @param id		AdminId index for this admin.
ds@1952
   429
		 * @return			A string containing the admin's name, or NULL
ds@1952
   430
		 *					if the admin was created anonymously.
ds@1952
   431
		 */
ds@1952
   432
		virtual const char *GetAdminName(AdminId id) =0;
ds@1952
   433
ds@1952
   434
		/**
ds@1952
   435
		 * @brief Binds a user entry to a particular auth method.
ds@1952
   436
		 * This bind must be unique.
ds@1952
   437
		 *
ds@1952
   438
		 * @param id		AdminId index of the admin.
ds@1952
   439
		 * @param auth		Auth method to use.
ds@1952
   440
		 * @param ident		Identity string to bind to.
ds@1952
   441
		 * @return			True on success, false if auth method was not found,
ds@1952
   442
		 *					id was invalid, or ident was already taken.
ds@1952
   443
		 */
ds@1952
   444
		virtual bool BindAdminIdentity(AdminId id, const char *auth, const char *ident) =0;
ds@1952
   445
ds@1952
   446
		/**
ds@1952
   447
		 * @brief Sets whether or not a flag is enabled on an admin.
ds@1952
   448
		 *
ds@1952
   449
		 * @param id		AdminId index of the admin.
ds@1952
   450
		 * @param flag		Admin flag to use.
ds@1952
   451
		 * @param enabled	True to enable, false to disable.
ds@1952
   452
		 */
ds@1952
   453
		virtual void SetAdminFlag(AdminId id, AdminFlag flag, bool enabled) =0;
ds@1952
   454
ds@1952
   455
		/**
ds@1952
   456
		 * @brief Returns whether or not a flag is enabled on an admin.
ds@1952
   457
		 *
ds@1952
   458
		 * @param id		AdminId index of the admin.
ds@1952
   459
		 * @param flag		Admin flag to use.
ds@1952
   460
		 * @param mode		Access mode to check.
ds@1952
   461
		 * @return			True if enabled, false otherwise.
ds@1952
   462
		 */
ds@1952
   463
		virtual bool GetAdminFlag(AdminId id, AdminFlag flag, AccessMode mode) =0;
ds@1952
   464
ds@1952
   465
		/**
ds@1952
   466
		 * @brief Returns the bitstring of access flags on an admin.
ds@1952
   467
		 *
ds@1952
   468
		 * @param id		AdminId index of the admin.
ds@1952
   469
		 * @param mode		Access mode to use.
ds@1952
   470
		 * @return			A bit string containing which flags are enabled.
ds@1952
   471
		 */
ds@1952
   472
		virtual FlagBits GetAdminFlags(AdminId id, AccessMode mode) =0;
ds@1952
   473
ds@1952
   474
		/**
ds@1952
   475
		 * @brief Sets the bitstring of access flags on an admin.
ds@1952
   476
		 *
ds@1952
   477
		 * @param id		AdminId index of the admin.
ds@1952
   478
		 * @param mode		Access mode to use (real affects both).
ds@1952
   479
		 * @param bits		Bitstring to set.
ds@1952
   480
		 */
ds@1952
   481
		virtual void SetAdminFlags(AdminId id, AccessMode mode, FlagBits bits) =0;
ds@1952
   482
ds@1952
   483
		/**
ds@1952
   484
		 * @brief Adds a group to an admin's inherited group list.  
ds@1952
   485
		 * Any flags the group has will be added to the admin's effective flags.
ds@1952
   486
		 *
ds@1952
   487
		 * @param id		AdminId index of the admin.
ds@1952
   488
		 * @param gid		GroupId index of the group.
ds@1952
   489
		 * @return			True on success, false on invalid input or duplicate membership.
ds@1952
   490
		 */
ds@1952
   491
		virtual bool AdminInheritGroup(AdminId id, GroupId gid) =0;
ds@1952
   492
ds@1952
   493
		/**
ds@1952
   494
		 * @brief Returns the number of groups this admin is a member of.
ds@1952
   495
		 * 
ds@1952
   496
		 * @param id		AdminId index of the admin.
ds@1952
   497
		 * @return			Number of groups this admin is a member of.
ds@1952
   498
		 */
ds@1952
   499
		virtual unsigned int GetAdminGroupCount(AdminId id) =0;
ds@1952
   500
ds@1952
   501
		/**
ds@1952
   502
		 * @brief Returns group information from an admin.
ds@1952
   503
		 *
ds@1952
   504
		 * @param id		AdminId index of the admin.
ds@1952
   505
		 * @param index		Group number to retrieve, from 0 to N-1, where N
ds@1952
   506
		 *					is the value of GetAdminGroupCount(id).
ds@1952
   507
		 * @param name		Optional pointer to store the group's name.
ds@1952
   508
		 * @return			A GroupId index and a name pointer, or
ds@1952
   509
		 *					INVALID_GROUP_ID and NULL if an error occurred.
ds@1952
   510
		 */
ds@1952
   511
		virtual GroupId GetAdminGroup(AdminId id, unsigned int index, const char **name) =0;
ds@1952
   512
		
ds@1952
   513
		/**
ds@1952
   514
		 * @brief Sets a password on an admin.
ds@1952
   515
		 *
ds@1952
   516
		 * @param id		AdminId index of the admin.
ds@1952
   517
		 * @param password	String containing the password.
ds@1952
   518
		 */
ds@1952
   519
		virtual void SetAdminPassword(AdminId id, const char *password) =0;
ds@1952
   520
ds@1952
   521
		/**
ds@1952
   522
		 * @brief Gets an admin's password.
ds@1952
   523
		 *
ds@1952
   524
		 * @param id		AdminId index of the admin.
ds@1952
   525
		 * @return			Password of the admin, or NULL if none.
ds@1952
   526
		 */
ds@1952
   527
		virtual const char *GetAdminPassword(AdminId id) =0;
ds@1952
   528
		
ds@1952
   529
		/**
ds@1952
   530
		 * @brief Attempts to find an admin by an auth method and an identity.
ds@1952
   531
		 *
ds@1952
   532
		 * @param auth		Auth method to try.
ds@1952
   533
		 * @param identity	Identity string to look up.
ds@1952
   534
		 * @return			An AdminId index if found, INVALID_ADMIN_ID otherwise.
ds@1952
   535
		 */
ds@1952
   536
		virtual AdminId FindAdminByIdentity(const char *auth, const char *identity) =0;
ds@1952
   537
ds@1952
   538
		/**
ds@1952
   539
		 * @brief Invalidates an admin from the cache so its resources can be re-used.
ds@1952
   540
		 *
ds@1952
   541
		 * @param id		AdminId index to invalidate.
ds@1952
   542
		 * @return			True on success, false otherwise.
ds@1952
   543
		 */
ds@1952
   544
		virtual bool InvalidateAdmin(AdminId id) =0;
ds@1952
   545
ds@1952
   546
		/**
ds@1952
   547
		 * @brief Converts a flag bit string to a bit array.
ds@1952
   548
		 *
ds@1952
   549
		 * @param bits		Bit string containing the flags.
ds@1952
   550
		 * @param array		Array to write the flags to.  Enabled flags will be 'true'.
ds@1952
   551
		 * @param maxSize	Maximum number of flags the array can store.
ds@1952
   552
		 * @return			Number of flags written.
ds@1952
   553
		 */
ds@1952
   554
		virtual unsigned int FlagBitsToBitArray(FlagBits bits, bool array[], unsigned int maxSize) =0;
ds@1952
   555
ds@1952
   556
		/**
ds@1952
   557
		 * @brief Converts a flag array to a bit string.
ds@1952
   558
		 *
ds@1952
   559
		 * @param array		Array containing true or false for each AdminFlag.
ds@1952
   560
		 * @param maxSize	Maximum size of the flag array.
ds@1952
   561
		 * @return			A bit string composed of the array bits.
ds@1952
   562
		 */
ds@1952
   563
		virtual FlagBits FlagBitArrayToBits(const bool array[], unsigned int maxSize) =0;
ds@1952
   564
ds@1952
   565
		/**
ds@1952
   566
		 * @brief Converts an array of flags to bits.
ds@1952
   567
		 *
ds@1952
   568
		 * @param array		Array containing flags that are enabled.
ds@1952
   569
		 * @param numFlags	Number of flags in the array.
ds@1952
   570
		 * @return			A bit string composed of the array flags.
ds@1952
   571
		 */
ds@1952
   572
		virtual FlagBits FlagArrayToBits(const AdminFlag array[], unsigned int numFlags) =0;
ds@1952
   573
ds@1952
   574
		/**
ds@1952
   575
		 * @brief Converts a bit string to an array of flags.
ds@1952
   576
		 *
ds@1952
   577
		 * @param bits		Bit string containing the flags.
ds@1952
   578
		 * @param array		Output array to write flags.
ds@1952
   579
		 * @param maxSize	Maximum size of the flag array.
ds@1952
   580
		 * @return			Number of flags written.
ds@1952
   581
		 */
ds@1952
   582
		virtual unsigned int FlagBitsToArray(FlagBits bits, AdminFlag array[], unsigned int maxSize) =0;
ds@1952
   583
ds@1952
   584
		/**
ds@1952
   585
		 * @brief Checks whether a user has access to a given set of flag bits.
ds@1952
   586
		 * Note: This is a wrapper around GetAdminFlags().
ds@1952
   587
		 *
ds@1952
   588
		 * @param id		AdminId index of admin.
ds@1952
   589
		 * @param bits		Bitstring containing the permissions to check.
ds@1952
   590
		 * @return			True if user has permission, false otherwise.
ds@1952
   591
		 */
ds@1952
   592
		virtual bool CheckAdminFlags(AdminId id, FlagBits bits) =0;
ds@1952
   593
ds@1952
   594
		/**
ds@1952
   595
		 * @brief Checks whether an AdminId can target another AdminId.
ds@1952
   596
		 * 
ds@1952
   597
		 * The hueristics for this check are as follows:
ds@1952
   598
		 * 0. If the targeting AdminId is INVALID_ADMIN_ID, targeting fails.
ds@1952
   599
		 * 1. If the targeted AdminId is INVALID_ADMIN_ID, targeting succeeds.
ds@1952
   600
		 * 2. If the targeted AdminId is the same as the targeting AdminId,
ds@1952
   601
		 *    (self) targeting succeeds.
ds@1952
   602
		 * 3. If the targeting admin is root, targeting succeeds.
ds@1952
   603
		 * 4. If the targeted admin has access higher (as interpreted by 
ds@1952
   604
		 *    (sm_immunity_mode) than the targeting admin, then targeting fails.
ds@1952
   605
		 * 5. If the targeted admin has specific immunity from the
ds@1952
   606
		 *    targeting admin via group immunities, targeting fails.
ds@1952
   607
		 * 6. Targeting succeeds.
ds@1952
   608
		 *
ds@1952
   609
		 * @param id		AdminId index of admin doing the targeting.  Can be INVALID_ADMIN_ID.
ds@1952
   610
		 * @param target	AdminId index of the target admin.  Can be INVALID_ADMIN_ID.
ds@1952
   611
		 * @return			True if this admin has permission to target the other admin.
ds@1952
   612
		 */
ds@1952
   613
		virtual bool CanAdminTarget(AdminId id, AdminId target) =0;
ds@1952
   614
ds@1952
   615
		/**
ds@1952
   616
		 * @brief Returns a flag from a named string.
ds@1952
   617
		 *
ds@1952
   618
		 * @param flagname	Case sensitive flag name string (like "kick").
ds@1952
   619
		 * @param pAdmFlag	Pointer to store the found admin flag in.
ds@1952
   620
		 * @return			True on success, false on failure.
ds@1952
   621
		 */
ds@1952
   622
		virtual bool FindFlag(const char *flagname, AdminFlag *pAdmFlag) =0;
ds@1952
   623
ds@1952
   624
		/**
ds@1952
   625
		 * @brief Reads a single character as a flag.
ds@1952
   626
		 *
ds@1952
   627
		 * @param c			Flag character.
ds@1952
   628
		 * @param pAdmFlag	Pointer to store the admin flag.
ds@1952
   629
		 * @return			True on success, false if invalid.
ds@1952
   630
		 */
ds@1952
   631
		virtual bool FindFlag(char c, AdminFlag *pAdmFlag) =0;
ds@1952
   632
ds@1952
   633
		/**
ds@1952
   634
		 * @brief Reads a string of flag letters and returns its access value.
ds@1952
   635
		 *
ds@1952
   636
		 * @param flags		Flag string.
ds@1952
   637
		 * @param end		Pointer to store the last value read.  On success, 
ds@1952
   638
		 *					this will store a pointer to the null terminator.
ds@1952
   639
		 * @return			FlagBits value of the flags.
ds@1952
   640
		 */
ds@1952
   641
		virtual FlagBits ReadFlagString(const char *flags, const char **end) =0;
ds@1952
   642
ds@1952
   643
		/**
ds@1952
   644
		 * @brief Returns a "serial number" for an AdminId.  If the serial 
ds@1952
   645
		 * number has changed for a given AdminId, it means the permissions 
ds@1952
   646
		 * have changed.
ds@1952
   647
		 *
ds@1952
   648
		 * @param id		AdminId value.
ds@1952
   649
		 * @return			Serial number, or 0 on failure.
ds@1952
   650
		 */
ds@1952
   651
		virtual unsigned int GetAdminSerialChange(AdminId id) =0;
ds@1952
   652
ds@1952
   653
		/**
ds@1952
   654
		 * @brief Checks whether an admin can use the given command name.
ds@1952
   655
		 *
ds@1952
   656
		 * If the command does not exist, this will return true.
ds@1952
   657
		 *
ds@1952
   658
		 * @param client	Client index.
ds@1952
   659
		 * @param cmd		Command name.
ds@1952
   660
		 * @return			True on success, false on failure.
ds@1952
   661
		 */
ds@1952
   662
		virtual bool CanAdminUseCommand(int client, const char *cmd) =0;
ds@1952
   663
ds@1952
   664
		/**
ds@1952
   665
		 * @brief Returns the name of a group.
ds@1952
   666
		 *
ds@1952
   667
		 * @param gid		Group Id.
ds@1952
   668
		 * @return			Group name, or NULL on failure.
ds@1952
   669
		 */
ds@1952
   670
		virtual const char *GetGroupName(GroupId gid) =0;
ds@1952
   671
ds@1952
   672
		/**
ds@1952
   673
		 * @brief Sets the immunity level of a group.
ds@1952
   674
		 * 
ds@1952
   675
		 * @param gid		Group Id.
ds@1952
   676
		 * @param level		Immunity level value.
ds@1952
   677
		 * @return			Old immunity level.
ds@1952
   678
		 */
ds@1952
   679
		virtual unsigned int SetGroupImmunityLevel(GroupId gid, unsigned int level) =0;
ds@1952
   680
ds@1952
   681
		/**
ds@1952
   682
		 * @brief Retrieves the immunity level of a group.
ds@1952
   683
		 *
ds@1952
   684
		 * @param gid		Group Id.
ds@1952
   685
		 * @return			Immunity level value.
ds@1952
   686
		 */
ds@1952
   687
		virtual unsigned int GetGroupImmunityLevel(GroupId gid) =0;
ds@1952
   688
ds@1952
   689
		/**
ds@1952
   690
		 * @brief Sets the immunity level of an admin.
ds@1952
   691
		 *
ds@1952
   692
		 * @param id		Admin Id.
ds@1952
   693
		 * @param level		Immunity level value.
ds@1952
   694
		 * @return			Old immunity level.
ds@1952
   695
		 */
ds@1952
   696
		virtual unsigned int SetAdminImmunityLevel(AdminId id, unsigned int level) =0;
ds@1952
   697
ds@1952
   698
		/**
ds@1952
   699
		 * @brief Retrieves the immunity level of an admin.
ds@1952
   700
		 *
ds@1952
   701
		 * @param id		Admin Id.
ds@1952
   702
		 * @return			Immunity level value.
ds@1952
   703
		 */
ds@1952
   704
		virtual unsigned int GetAdminImmunityLevel(AdminId id) =0;
ds@1952
   705
ds@1952
   706
		/**
ds@1952
   707
		 * @brief Computers access to an override.
ds@1952
   708
		 *
ds@1952
   709
		 * @param client		Client index.
ds@1952
   710
		 * @param cmd			Override name.
ds@1952
   711
		 * @param flags			Default flags.
ds@1952
   712
		 * @param override_only	If false, if a command matches the override, 
ds@1952
   713
		 *						then its flags will override the default.
ds@1952
   714
		 * @return				True if the client has access, false otherwise.
ds@1952
   715
		 */
ds@1952
   716
		virtual bool CheckAccess(int client, 
ds@1952
   717
			const char *cmd, 
ds@1952
   718
			FlagBits flags, 
ds@1952
   719
			bool override_only) =0;
ds@1952
   720
	};
ds@1952
   721
}
ds@1952
   722
ds@1952
   723
#endif //_INCLUDE_SOURCEMOD_ADMINISTRATION_SYSTEM_H_
ds@1952
   724