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