public/IAdminSystem.h

Go to the documentation of this file.
00001 /**
00002  * vim: set ts=4 :
00003  * =============================================================================
00004  * SourceMod
00005  * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
00006  * =============================================================================
00007  *
00008  * This program is free software; you can redistribute it and/or modify it under
00009  * the terms of the GNU General Public License, version 3.0, as published by the
00010  * Free Software Foundation.
00011  * 
00012  * This program is distributed in the hope that it will be useful, but WITHOUT
00013  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00014  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
00015  * details.
00016  *
00017  * You should have received a copy of the GNU General Public License along with
00018  * this program.  If not, see <http://www.gnu.org/licenses/>.
00019  *
00020  * As a special exception, AlliedModders LLC gives you permission to link the
00021  * code of this program (as well as its derivative works) to "Half-Life 2," the
00022  * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
00023  * by the Valve Corporation.  You must obey the GNU General Public License in
00024  * all respects for all other code used.  Additionally, AlliedModders LLC grants
00025  * this exception to all derivative works.  AlliedModders LLC defines further
00026  * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
00027  * or <http://www.sourcemod.net/license.php>.
00028  *
00029  * Version: $Id$
00030  */
00031 
00032 #ifndef _INCLUDE_SOURCEMOD_ADMINISTRATION_SYSTEM_H_
00033 #define _INCLUDE_SOURCEMOD_ADMINISTRATION_SYSTEM_H_
00034 
00035 #include <IShareSys.h>
00036 
00037 #define SMINTERFACE_ADMINSYS_NAME                 "IAdminSys"
00038 #define SMINTERFACE_ADMINSYS_VERSION    5
00039 
00040 /**
00041  * @file IAdminSystem.h
00042  * @brief Defines the interface to manage the Admin Users/Groups and Override caches.
00043  *
00044  *   The administration system is more of a volatile cache than a system.  It is designed to be 
00045  * temporary rather than permanent, in order to compensate for more storage methods.  For example,
00046  * a flat file might be read into the cache all at once.  But a MySQL-based system might only cache
00047  * admin permissions when that specific admin connects.  
00048  *
00049  *   The override cache is the simplest to explain.  Any time an override is added, any existing 
00050  * and all future commands will gain a new access level set by the override.  If unset, the default
00051  * access level is restored.  This cache is dynamically changeable.
00052  *
00053  *   The group cache contains, for each group:
00054  *        1] A set of inherent flags - fully readable/writable.
00055  *  2] An immunity table - insertion and retrieval only.
00056  *  3] An override table - insertion and retrieval only.
00057  *   Individual groups can be invalidated entirely.  It should be considered an expensive
00058  *  operation, since each admin needs to be patched up to not reference the group.
00059  *
00060  *   For more information, see the SourceMod Development wiki.
00061  */
00062 
00063 namespace SourceMod
00064 {
00065           /**
00066            * @brief Access levels (flags) for admins.
00067            */
00068           enum AdminFlag
00069           {
00070                     Admin_Reservation = 0,        /**< Reserved slot */
00071                     Admin_Generic,                          /**< Generic admin abilities */
00072                     Admin_Kick,                                       /**< Kick another user */
00073                     Admin_Ban,                                        /**< Ban another user */
00074                     Admin_Unban,                            /**< Unban another user */
00075                     Admin_Slay,                                       /**< Slay/kill/damage another user */
00076                     Admin_Changemap,              /**< Change the map */
00077                     Admin_Convars,                          /**< Change basic convars */
00078                     Admin_Config,                           /**< Change configuration */
00079                     Admin_Chat,                                       /**< Special chat privileges */
00080                     Admin_Vote,                                       /**< Special vote privileges */
00081                     Admin_Password,                         /**< Set a server password */
00082                     Admin_RCON,                                       /**< Use RCON */
00083                     Admin_Cheats,                           /**< Change sv_cheats and use its commands */
00084                     Admin_Root,                                       /**< All access by default */
00085                     Admin_Custom1,                          /**< First custom flag type */
00086                     Admin_Custom2,                          /**< Second custom flag type */
00087                     Admin_Custom3,                          /**< Third custom flag type */
00088                     Admin_Custom4,                          /**< Fourth custom flag type */
00089                     Admin_Custom5,                          /**< Fifth custom flag type */
00090                     Admin_Custom6,                          /**< Sixth custom flag type */
00091                     /* --- */
00092                     AdminFlags_TOTAL,
00093           };
00094 
00095           #define ADMFLAG_RESERVATION                       (1<<0)              /**< Convenience macro for Admin_Reservation as a FlagBit */
00096           #define ADMFLAG_GENERIC                                     (1<<1)              /**< Convenience macro for Admin_Generic as a FlagBit */
00097           #define ADMFLAG_KICK                                        (1<<2)              /**< Convenience macro for Admin_Kick as a FlagBit */
00098           #define ADMFLAG_BAN                                         (1<<3)              /**< Convenience macro for Admin_Ban as a FlagBit */
00099           #define ADMFLAG_UNBAN                                       (1<<4)              /**< Convenience macro for Admin_Unban as a FlagBit */
00100           #define ADMFLAG_SLAY                                        (1<<5)              /**< Convenience macro for Admin_Slay as a FlagBit */
00101           #define ADMFLAG_CHANGEMAP                         (1<<6)              /**< Convenience macro for Admin_Changemap as a FlagBit */
00102           #define ADMFLAG_CONVARS                                     (1<<7)              /**< Convenience macro for Admin_Convars as a FlagBit */
00103           #define ADMFLAG_CONFIG                                      (1<<8)              /**< Convenience macro for Admin_Config as a FlagBit */
00104           #define ADMFLAG_CHAT                                        (1<<9)              /**< Convenience macro for Admin_Chat as a FlagBit */
00105           #define ADMFLAG_VOTE                                        (1<<10)             /**< Convenience macro for Admin_Vote as a FlagBit */
00106           #define ADMFLAG_PASSWORD                          (1<<11)             /**< Convenience macro for Admin_Password as a FlagBit */
00107           #define ADMFLAG_RCON                                        (1<<12)             /**< Convenience macro for Admin_RCON as a FlagBit */
00108           #define ADMFLAG_CHEATS                                      (1<<13)             /**< Convenience macro for Admin_Cheats as a FlagBit */
00109           #define ADMFLAG_ROOT                                        (1<<14)             /**< Convenience macro for Admin_Root as a FlagBit */
00110           #define ADMFLAG_CUSTOM1                                     (1<<15)             /**< Convenience macro for Admin_Custom1 as a FlagBit */
00111           #define ADMFLAG_CUSTOM2                                     (1<<16)             /**< Convenience macro for Admin_Custom2 as a FlagBit */
00112           #define ADMFLAG_CUSTOM3                                     (1<<17)             /**< Convenience macro for Admin_Custom3 as a FlagBit */
00113           #define ADMFLAG_CUSTOM4                                     (1<<18)             /**< Convenience macro for Admin_Custom4 as a FlagBit */
00114           #define ADMFLAG_CUSTOM5                                     (1<<19)             /**< Convenience macro for Admin_Custom5 as a FlagBit */
00115           #define ADMFLAG_CUSTOM6                                     (1<<20)             /**< Convenience macro for Admin_Custom6 as a FlagBit */
00116 
00117           /**
00118            * @brief Specifies which type of command to override (command or command group).
00119            */
00120           enum OverrideType
00121           {
00122                     Override_Command = 1,         /**< Command */
00123                     Override_CommandGroup,        /**< Command group */
00124           };
00125 
00126           /**
00127            * @brief Specifies how a command is overridden for a user group.
00128            */
00129           enum OverrideRule
00130           {
00131                     Command_Deny = 0,             /**< Deny access */
00132                     Command_Allow = 1,            /**< Allow access */
00133           };
00134 
00135           /**
00136            * @brief DEPRECATED.  Specifies a generic immunity type.
00137            */
00138           enum ImmunityType
00139           {
00140                     Immunity_Default = 1,         /**< Immunity value of 1 */
00141                     Immunity_Global,              /**< Immunity value of 2 */
00142           };
00143 
00144           /**
00145            * @brief Defines user access modes.
00146            */
00147           enum AccessMode
00148           {
00149                     Access_Real,                  /**< Access the user has inherently */
00150                     Access_Effective,   /**< Access the user has from their groups */
00151           };
00152 
00153           /**
00154            * @brief Represents an index to one group.
00155            */
00156           typedef int                   GroupId;
00157 
00158           /**
00159            * @brief Represents an index to one user entry.
00160            */
00161           typedef int                   AdminId;
00162 
00163           /**
00164            * @brief Represents an invalid/nonexistent group or an erroneous operation.
00165            */
00166           #define INVALID_GROUP_ID      -1
00167 
00168           /**
00169            * @brief Represents an invalid/nonexistent user or an erroneous operation.
00170            */
00171           #define INVALID_ADMIN_ID      -1
00172 
00173           /**
00174            * @brief Represents the various cache regions.
00175            */
00176           enum AdminCachePart
00177           {
00178                     AdminCache_Overrides = 0,               /**< Global overrides */
00179                     AdminCache_Groups = 1,                            /**< All groups (automatically invalidates admins too) */
00180                     AdminCache_Admins = 2,                            /**< All admins */
00181           };
00182 
00183           /**
00184            * @brief Provides callbacks for admin cache operations.
00185            */
00186           class IAdminListener
00187           {
00188           public:
00189                     virtual unsigned int GetInterfaceVersion()
00190                     {
00191                               return SMINTERFACE_ADMINSYS_VERSION;
00192                     }
00193           public:
00194                     /**
00195                      * @brief Called when the admin cache needs to be rebuilt.  
00196                      *
00197                      * @param auto_rebuild                  True if this is being called because of a group rebuild.
00198                      */
00199                     virtual void OnRebuildAdminCache(bool auto_rebuild) =0;
00200 
00201                     /**
00202                      * @brief Called when the group cache needs to be rebuilt.
00203                      */
00204                     virtual void OnRebuildGroupCache() =0;
00205                     
00206                     /**
00207                      * @brief Called when the global override cache needs to be rebuilt.
00208                      */
00209                     virtual void OnRebuildOverrideCache() =0;
00210           };
00211 
00212           /**
00213            * @brief Admin permission levels.
00214            */
00215           typedef unsigned int FlagBits;
00216 
00217           /**
00218            * @brief Provides functions for manipulating the admin options cache.
00219            */
00220           class IAdminSystem : public SMInterface
00221           {
00222           public:
00223                     const char *GetInterfaceName()
00224                     {
00225                               return SMINTERFACE_ADMINSYS_NAME;
00226                     }
00227                     unsigned int GetInterfaceVersion()
00228                     {
00229                               return SMINTERFACE_ADMINSYS_VERSION;
00230                     }
00231           public:
00232                     /**
00233                      * @brief Adds a global command flag override.  Any command registered with this name
00234                      * will assume the new flag.  This is applied retroactively as well.
00235                      *
00236                      * @param cmd                           String containing command name (case sensitive).
00237                      * @param type                          Override type (specific command or group).
00238                      * @param flags                         New admin flag.
00239                      */
00240                     virtual void AddCommandOverride(const char *cmd, OverrideType type, FlagBits flags) =0;
00241 
00242                     /**
00243                      * @brief Returns a command override.
00244                      *
00245                      * @param cmd                           String containing command name (case sensitive).
00246                      * @param type                          Override type (specific command or group).
00247                      * @param pFlags              Optional pointer to the set flag.
00248                      * @return                                        True if there is an override, false otherwise.
00249                      */
00250                     virtual bool GetCommandOverride(const char *cmd, OverrideType type, FlagBits *pFlags) =0;
00251 
00252                     /**
00253                      * @brief Unsets a command override.
00254                      *
00255                      * @param cmd                           String containing command name (case sensitive).
00256                      * @param type                          Override type (specific command or group).
00257                      */
00258                     virtual void UnsetCommandOverride(const char *cmd, OverrideType type) =0;
00259 
00260                     /**
00261                      * @brief Adds a new group.  Name must be unique.
00262                      *
00263                      * @param group_name          String containing the group name.
00264                      * @return                                        A new group id, INVALID_GROUP_ID if it already exists.
00265                      */
00266                     virtual GroupId AddGroup(const char *group_name) =0;
00267 
00268                     /**
00269                      * @brief Finds a group by name.
00270                      *
00271                      * @param group_name          String containing the group name.
00272                      * @return                                        A group id, or INVALID_GROUP_ID if not found.
00273                      */
00274                     virtual GroupId FindGroupByName(const char *group_name) =0;
00275 
00276                     /**
00277                      * @brief Adds or removes a flag from a group's flag set.
00278                      * Note: These are called "add flags" because they add to a user's flags.
00279                      *
00280                      * @param id                            Group id.
00281                      * @param flag                          Admin flag to toggle.
00282                      * @param enabled             True to set the flag, false to unset/disable.
00283                      */
00284                     virtual void SetGroupAddFlag(GroupId id, AdminFlag flag, bool enabled) =0;
00285 
00286                     /**
00287                      * @brief Gets the set value of an add flag on a group's flag set.
00288                      *
00289                      * @param id                            Group id.
00290                      * @param flag                          Admin flag to retrieve.
00291                      * @return                                        True if enabled, false otherwise,
00292                      */
00293                     virtual bool GetGroupAddFlag(GroupId id, AdminFlag flag) =0;
00294 
00295                     /**
00296                      * @brief Returns an array of flag bits that are added to a user from their group.
00297                      * Note: These are called "add flags" because they add to a user's flags.
00298                      *
00299                      * @param id                            GroupId of the group.
00300                      * @return                                        Bit string containing the bits of each flag.
00301                      */
00302                     virtual FlagBits GetGroupAddFlags(GroupId id) =0;
00303 
00304                     /**
00305                      * @brief DEPRECATED.  Sets a group's immunity level using backwards 
00306                      * compatible types.  
00307                      *
00308                      * If the new level being set is lower than the group's actual immunity 
00309                      * level, no operation takes place.
00310                      *
00311                      * @param id                            Group id.
00312                      * @param type                          Immunity type which will be converted to a 
00313                      *                                                          numerical level.
00314                      * @param enabled             True to set the level.  False sets the 
00315                      *                                                          group's immunity value to 0.
00316                      */
00317                     virtual void SetGroupGenericImmunity(GroupId id, ImmunityType type, bool enabled) =0;
00318 
00319                     /**
00320                      * @brief DEPRECATED.  Returns whether a group has an immunity level
00321                      * using backwards compatible types.
00322                      * 
00323                      * This simply checks whether the group's immunity value is greater 
00324                      * than or equal to the new-style value for the old type.
00325                      *
00326                      * @param id                            Group id.
00327                      * @param type                          Generic immunity type.
00328                      * @return                                        True if the group has this immunity, false 
00329                      *                                                          otherwise.
00330                      */
00331                     virtual bool GetGroupGenericImmunity(GroupId id, ImmunityType type) =0;
00332 
00333                     /**
00334                      * @brief Adds immunity to a specific group.
00335                      *
00336                      * @param id                            Group id.
00337                      * @param other_id            Group id to receive immunity to.
00338                      */
00339                     virtual void AddGroupImmunity(GroupId id, GroupId other_id) =0;
00340 
00341                     /**
00342                      * @brief Returns the number of specific group immunities.
00343                      *
00344                      * @param id                            Group id.
00345                      * @return                                        Number of group immunities.
00346                      */
00347                     virtual unsigned int GetGroupImmunityCount(GroupId id) =0;
00348 
00349                     /**
00350                      * @brief Returns a group that this group is immune to given an index.
00351                      *
00352                      * @param id                            Group id.
00353                      * @param number              Index from 0 to N-1, from GetGroupImmunities().
00354                      * @return                                        GroupId that this group is immune to.
00355                      */
00356                     virtual GroupId GetGroupImmunity(GroupId id, unsigned int number) =0;
00357 
00358                     /**
00359                      * @brief Adds a group-specific override type.
00360                      *
00361                      * @param id                            Group id.
00362                      * @param name                          String containing command name (case sensitive).
00363                      * @param type                          Override type (specific command or group).
00364                      * @param rule                          Override allow/deny setting.
00365                      */
00366                     virtual void AddGroupCommandOverride(GroupId id,
00367                                                                                                                const char *name,
00368                                                                                                                OverrideType type,
00369                                                                                                                OverrideRule rule) =0;
00370 
00371                     /**
00372                      * @brief Retrieves a group-specific command override.
00373                      *
00374                      * @param id                            Group id.
00375                      * @param name                          String containing command name (case sensitive).
00376                      * @param type                          Override type (specific command or group).
00377                      * @param pRule                         Optional pointer to store allow/deny setting.
00378                      * @return                                        True if an override exists, false otherwise.
00379                      */
00380                     virtual bool GetGroupCommandOverride(GroupId id,
00381                                                                                                                const char *name,
00382                                                                                                                OverrideType type,
00383                                                                                                                OverrideRule *pRule) =0;
00384 
00385                     /**
00386                      * @brief Tells the admin system to dump a portion of the cache.  
00387                      * This calls into plugin forwards to rebuild the cache.
00388                      *
00389                      * @param part                          Portion of the cache to dump.
00390                      * @param rebuild             If true, the rebuild forwards/events will fire.
00391                      */
00392                     virtual void DumpAdminCache(AdminCachePart part, bool rebuild) =0;
00393 
00394                     /**
00395                      * @brief Adds an admin interface listener.
00396                      *
00397                      * @param pListener           Pointer to an IAdminListener to add.
00398                      */
00399                     virtual void AddAdminListener(IAdminListener *pListener) =0;
00400 
00401                     /**
00402                      * @brief Removes an admin interface listener.
00403                      *
00404                      * @param pListener           Pointer to an IAdminListener to remove.
00405                      */
00406                     virtual void RemoveAdminListener(IAdminListener *pListener) =0;
00407 
00408                     /**
00409                      * @brief Registers an authentication identity type.
00410                      * Note: Default types are "steam," "name," and "ip."
00411                      *
00412                      * @param name                          String containing the type name.
00413                      */
00414                     virtual void RegisterAuthIdentType(const char *name) =0;
00415 
00416                     /**
00417                      * @brief Creates a new user entry.
00418                      *
00419                      * @param name                Name for this entry (does not have to be unique).
00420                      *                                                Specify NULL for an anonymous admin.
00421                      * @return                              A new AdminId index.
00422                      */
00423                     virtual AdminId CreateAdmin(const char *name) =0;
00424 
00425                     /**
00426                      * @brief Gets an admin's user name.
00427                      *
00428                      * @param id                  AdminId index for this admin.
00429                      * @return                              A string containing the admin's name, or NULL
00430                      *                                                if the admin was created anonymously.
00431                      */
00432                     virtual const char *GetAdminName(AdminId id) =0;
00433 
00434                     /**
00435                      * @brief Binds a user entry to a particular auth method.
00436                      * This bind must be unique.
00437                      *
00438                      * @param id                  AdminId index of the admin.
00439                      * @param auth                Auth method to use.
00440                      * @param ident               Identity string to bind to.
00441                      * @return                              True on success, false if auth method was not found,
00442                      *                                                id was invalid, or ident was already taken.
00443                      */
00444                     virtual bool BindAdminIdentity(AdminId id, const char *auth, const char *ident) =0;
00445 
00446                     /**
00447                      * @brief Sets whether or not a flag is enabled on an admin.
00448                      *
00449                      * @param id                  AdminId index of the admin.
00450                      * @param flag                Admin flag to use.
00451                      * @param enabled   True to enable, false to disable.
00452                      */
00453                     virtual void SetAdminFlag(AdminId id, AdminFlag flag, bool enabled) =0;
00454 
00455                     /**
00456                      * @brief Returns whether or not a flag is enabled on an admin.
00457                      *
00458                      * @param id                  AdminId index of the admin.
00459                      * @param flag                Admin flag to use.
00460                      * @param mode                Access mode to check.
00461                      * @return                              True if enabled, false otherwise.
00462                      */
00463                     virtual bool GetAdminFlag(AdminId id, AdminFlag flag, AccessMode mode) =0;
00464 
00465                     /**
00466                      * @brief Returns the bitstring of access flags on an admin.
00467                      *
00468                      * @param id                  AdminId index of the admin.
00469                      * @param mode                Access mode to use.
00470                      * @return                              A bit string containing which flags are enabled.
00471                      */
00472                     virtual FlagBits GetAdminFlags(AdminId id, AccessMode mode) =0;
00473 
00474                     /**
00475                      * @brief Sets the bitstring of access flags on an admin.
00476                      *
00477                      * @param id                  AdminId index of the admin.
00478                      * @param mode                Access mode to use (real affects both).
00479                      * @param bits                Bitstring to set.
00480                      */
00481                     virtual void SetAdminFlags(AdminId id, AccessMode mode, FlagBits bits) =0;
00482 
00483                     /**
00484                      * @brief Adds a group to an admin's inherited group list.  
00485                      * Any flags the group has will be added to the admin's effective flags.
00486                      *
00487                      * @param id                  AdminId index of the admin.
00488                      * @param gid                 GroupId index of the group.
00489                      * @return                              True on success, false on invalid input or duplicate membership.
00490                      */
00491                     virtual bool AdminInheritGroup(AdminId id, GroupId gid) =0;
00492 
00493                     /**
00494                      * @brief Returns the number of groups this admin is a member of.
00495                      * 
00496                      * @param id                  AdminId index of the admin.
00497                      * @return                              Number of groups this admin is a member of.
00498                      */
00499                     virtual unsigned int GetAdminGroupCount(AdminId id) =0;
00500 
00501                     /**
00502                      * @brief Returns group information from an admin.
00503                      *
00504                      * @param id                  AdminId index of the admin.
00505                      * @param index               Group number to retrieve, from 0 to N-1, where N
00506                      *                                                is the value of GetAdminGroupCount(id).
00507                      * @param name                Optional pointer to store the group's name.
00508                      * @return                              A GroupId index and a name pointer, or
00509                      *                                                INVALID_GROUP_ID and NULL if an error occurred.
00510                      */
00511                     virtual GroupId GetAdminGroup(AdminId id, unsigned int index, const char **name) =0;
00512                     
00513                     /**
00514                      * @brief Sets a password on an admin.
00515                      *
00516                      * @param id                  AdminId index of the admin.
00517                      * @param password  String containing the password.
00518                      */
00519                     virtual void SetAdminPassword(AdminId id, const char *password) =0;
00520 
00521                     /**
00522                      * @brief Gets an admin's password.
00523                      *
00524                      * @param id                  AdminId index of the admin.
00525                      * @return                              Password of the admin, or NULL if none.
00526                      */
00527                     virtual const char *GetAdminPassword(AdminId id) =0;
00528                     
00529                     /**
00530                      * @brief Attempts to find an admin by an auth method and an identity.
00531                      *
00532                      * @param auth                Auth method to try.
00533                      * @param identity  Identity string to look up.
00534                      * @return                              An AdminId index if found, INVALID_ADMIN_ID otherwise.
00535                      */
00536                     virtual AdminId FindAdminByIdentity(const char *auth, const char *identity) =0;
00537 
00538                     /**
00539                      * @brief Invalidates an admin from the cache so its resources can be re-used.
00540                      *
00541                      * @param id                  AdminId index to invalidate.
00542                      * @return                              True on success, false otherwise.
00543                      */
00544                     virtual bool InvalidateAdmin(AdminId id) =0;
00545 
00546                     /**
00547                      * @brief Converts a flag bit string to a bit array.
00548                      *
00549                      * @param bits                Bit string containing the flags.
00550                      * @param array               Array to write the flags to.  Enabled flags will be 'true'.
00551                      * @param maxSize   Maximum number of flags the array can store.
00552                      * @return                              Number of flags written.
00553                      */
00554                     virtual unsigned int FlagBitsToBitArray(FlagBits bits, bool array[], unsigned int maxSize) =0;
00555 
00556                     /**
00557                      * @brief Converts a flag array to a bit string.
00558                      *
00559                      * @param array               Array containing true or false for each AdminFlag.
00560                      * @param maxSize   Maximum size of the flag array.
00561                      * @return                              A bit string composed of the array bits.
00562                      */
00563                     virtual FlagBits FlagBitArrayToBits(const bool array[], unsigned int maxSize) =0;
00564 
00565                     /**
00566                      * @brief Converts an array of flags to bits.
00567                      *
00568                      * @param array               Array containing flags that are enabled.
00569                      * @param numFlags  Number of flags in the array.
00570                      * @return                              A bit string composed of the array flags.
00571                      */
00572                     virtual FlagBits FlagArrayToBits(const AdminFlag array[], unsigned int numFlags) =0;
00573 
00574                     /**
00575                      * @brief Converts a bit string to an array of flags.
00576                      *
00577                      * @param bits                Bit string containing the flags.
00578                      * @param array               Output array to write flags.
00579                      * @param maxSize   Maximum size of the flag array.
00580                      * @return                              Number of flags written.
00581                      */
00582                     virtual unsigned int FlagBitsToArray(FlagBits bits, AdminFlag array[], unsigned int maxSize) =0;
00583 
00584                     /**
00585                      * @brief Checks whether a user has access to a given set of flag bits.
00586                      * Note: This is a wrapper around GetAdminFlags().
00587                      *
00588                      * @param id                  AdminId index of admin.
00589                      * @param bits                Bitstring containing the permissions to check.
00590                      * @return                              True if user has permission, false otherwise.
00591                      */
00592                     virtual bool CheckAdminFlags(AdminId id, FlagBits bits) =0;
00593 
00594                     /**
00595                      * @brief Checks whether an AdminId can target another AdminId.
00596                      * 
00597                      * The hueristics for this check are as follows:
00598                      * 0. If the targeting AdminId is INVALID_ADMIN_ID, targeting fails.
00599                      * 1. If the targeted AdminId is INVALID_ADMIN_ID, targeting succeeds.
00600                      * 2. If the targeted AdminId is the same as the targeting AdminId,
00601                      *    (self) targeting succeeds.
00602                      * 3. If the targeting admin is root, targeting succeeds.
00603                      * 4. If the targeted admin has access higher (as interpreted by 
00604                      *    (sm_immunity_mode) than the targeting admin, then targeting fails.
00605                      * 5. If the targeted admin has specific immunity from the
00606                      *    targeting admin via group immunities, targeting fails.
00607                      * 6. Targeting succeeds.
00608                      *
00609                      * @param id                  AdminId index of admin doing the targeting.  Can be INVALID_ADMIN_ID.
00610                      * @param target    AdminId index of the target admin.  Can be INVALID_ADMIN_ID.
00611                      * @return                              True if this admin has permission to target the other admin.
00612                      */
00613                     virtual bool CanAdminTarget(AdminId id, AdminId target) =0;
00614 
00615                     /**
00616                      * @brief Returns a flag from a named string.
00617                      *
00618                      * @param flagname  Case sensitive flag name string (like "kick").
00619                      * @param pAdmFlag  Pointer to store the found admin flag in.
00620                      * @return                              True on success, false on failure.
00621                      */
00622                     virtual bool FindFlag(const char *flagname, AdminFlag *pAdmFlag) =0;
00623 
00624                     /**
00625                      * @brief Reads a single character as a flag.
00626                      *
00627                      * @param c                             Flag character.
00628                      * @param pAdmFlag  Pointer to store the admin flag.
00629                      * @return                              True on success, false if invalid.
00630                      */
00631                     virtual bool FindFlag(char c, AdminFlag *pAdmFlag) =0;
00632 
00633                     /**
00634                      * @brief Reads a string of flag letters and returns its access value.
00635                      *
00636                      * @param flags               Flag string.
00637                      * @param end                 Pointer to store the last value read.  On success, 
00638                      *                                                this will store a pointer to the null terminator.
00639                      * @return                              FlagBits value of the flags.
00640                      */
00641                     virtual FlagBits ReadFlagString(const char *flags, const char **end) =0;
00642 
00643                     /**
00644                      * @brief Returns a "serial number" for an AdminId.  If the serial 
00645                      * number has changed for a given AdminId, it means the permissions 
00646                      * have changed.
00647                      *
00648                      * @param id                  AdminId value.
00649                      * @return                              Serial number, or 0 on failure.
00650                      */
00651                     virtual unsigned int GetAdminSerialChange(AdminId id) =0;
00652 
00653                     /**
00654                      * @brief Checks whether an admin can use the given command name.
00655                      *
00656                      * If the command does not exist, this will return true.
00657                      *
00658                      * @param client    Client index.
00659                      * @param cmd                 Command name.
00660                      * @return                              True on success, false on failure.
00661                      */
00662                     virtual bool CanAdminUseCommand(int client, const char *cmd) =0;
00663 
00664                     /**
00665                      * @brief Returns the name of a group.
00666                      *
00667                      * @param gid                 Group Id.
00668                      * @return                              Group name, or NULL on failure.
00669                      */
00670                     virtual const char *GetGroupName(GroupId gid) =0;
00671 
00672                     /**
00673                      * @brief Sets the immunity level of a group.
00674                      * 
00675                      * @param gid                 Group Id.
00676                      * @param level               Immunity level value.
00677                      * @return                              Old immunity level.
00678                      */
00679                     virtual unsigned int SetGroupImmunityLevel(GroupId gid, unsigned int level) =0;
00680 
00681                     /**
00682                      * @brief Retrieves the immunity level of a group.
00683                      *
00684                      * @param gid                 Group Id.
00685                      * @return                              Immunity level value.
00686                      */
00687                     virtual unsigned int GetGroupImmunityLevel(GroupId gid) =0;
00688 
00689                     /**
00690                      * @brief Sets the immunity level of an admin.
00691                      *
00692                      * @param id                  Admin Id.
00693                      * @param level               Immunity level value.
00694                      * @return                              Old immunity level.
00695                      */
00696                     virtual unsigned int SetAdminImmunityLevel(AdminId id, unsigned int level) =0;
00697 
00698                     /**
00699                      * @brief Retrieves the immunity level of an admin.
00700                      *
00701                      * @param id                  Admin Id.
00702                      * @return                              Immunity level value.
00703                      */
00704                     virtual unsigned int GetAdminImmunityLevel(AdminId id) =0;
00705 
00706                     /**
00707                      * @brief Computers access to an override.
00708                      *
00709                      * @param client              Client index.
00710                      * @param cmd                           Override name.
00711                      * @param flags                         Default flags.
00712                      * @param override_only       If false, if a command matches the override, 
00713                      *                                                          then its flags will override the default.
00714                      * @return                                        True if the client has access, false otherwise.
00715                      */
00716                     virtual bool CheckAccess(int client, 
00717                               const char *cmd, 
00718                               FlagBits flags, 
00719                               bool override_only) =0;
00720           };
00721 }
00722 
00723 #endif //_INCLUDE_SOURCEMOD_ADMINISTRATION_SYSTEM_H_
00724 

Generated on Sun Dec 28 23:26:25 2008 for SourceMod SDK by  doxygen 1.5.1