public/IAdminSystem.h
changeset 335 02cc96355b09
child 336 3f4073018d76
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/public/IAdminSystem.h	Wed Jan 24 21:51:49 2007 +0000
     1.3 @@ -0,0 +1,254 @@
     1.4 +#ifndef _INCLUDE_SOURCEMOD_ADMINISTRATION_SYSTEM_H_
     1.5 +#define _INCLUDE_SOURCEMOD_ADMINISTRATION_SYSTEM_H_
     1.6 +
     1.7 +#include <IShareSys.h>
     1.8 +
     1.9 +#define SMINTERFACE_ADMINSYS_NAME		"IAdminSys"
    1.10 +#define SMINTERFACE_ADMINSYS_VERSION	1
    1.11 +
    1.12 +/**
    1.13 + * Detailed notes:
    1.14 + * ---------------
    1.15 + *   The administration system is more of a volatile cache than a system.  It is designed to be 
    1.16 + * temporary rather than permanent, in order to compensate for more storage methods.  For example,
    1.17 + * a flat file might be read into the cache all at once.  But a MySQL-based system might only cache
    1.18 + * admin permissions when that specific admin connects.  
    1.19 + *
    1.20 + *   The override cache is the simplest to explain.  Any time an override is added, any existing 
    1.21 + * and all future commands will gain a new access level set by the override.  If unset, the default
    1.22 + * access level is restored.  This cache is dynamically changeable.
    1.23 + *
    1.24 + *   The group cache contains, for each group:
    1.25 + *	1] A set of inherent flags - fully readable/writable.
    1.26 + *  2] An immunity table - insertion and retrieval only.
    1.27 + *  3] An override table - insertion and retrieval only.
    1.28 + *   Individual groups can be invalidated entirely.  It should be considered an expensive
    1.29 + *  operation, since each admin needs to be patched up to not reference the group.
    1.30 + */
    1.31 +
    1.32 +namespace SourceMod
    1.33 +{
    1.34 +	enum AdminFlag
    1.35 +	{
    1.36 +		Admin_None = 0,
    1.37 +		Admin_Reservation,		/* Reserved slot */
    1.38 +		Admin_Kick,				/* Kick another user */
    1.39 +		Admin_Ban,				/* Ban another user */
    1.40 +		Admin_Unban,			/* Unban another user */
    1.41 +		Admin_Slay,				/* Slay/kill/damage another user */
    1.42 +		Admin_Changemap,		/* Change the map */
    1.43 +		Admin_Convars,			/* Change basic convars */
    1.44 +		Admin_Configs,			/* Change configs */
    1.45 +		Admin_Chat,				/* Special chat privileges */
    1.46 +		Admin_Vote,				/* Special vote privileges */
    1.47 +		Admin_Password,			/* Set a server password */
    1.48 +		Admin_RCON,				/* Use RCON */
    1.49 +		Admin_Cheats,			/* Change sv_cheats and use its commands */
    1.50 +		/* --- */
    1.51 +		AdminFlags_TOTAL,
    1.52 +	};
    1.53 +
    1.54 +	enum OverrideType
    1.55 +	{
    1.56 +		Override_Command = 1,	/* Command */
    1.57 +		Override_CommandGroup,	/* Command group */
    1.58 +	};
    1.59 +
    1.60 +	enum OverrideRule
    1.61 +	{
    1.62 +		Command_Deny = 0,
    1.63 +		Command_Allow = 1,
    1.64 +	};
    1.65 +
    1.66 +	enum ImmunityType
    1.67 +	{
    1.68 +		Immunity_Default = 1,		/* Immune from everyone with no immunity */
    1.69 +		Immunity_Global,		/* Immune from everyone (except root admins) */
    1.70 +	};
    1.71 +
    1.72 +	typedef int		GroupId;
    1.73 +
    1.74 +	#define INVALID_GROUP_ID	-1
    1.75 +
    1.76 +	/**
    1.77 +	 * @brief This is the administration options cache.
    1.78 +	 */
    1.79 +	class IAdminSystem : public SMInterface
    1.80 +	{
    1.81 +	public:
    1.82 +		const char *GetInterfaceName()
    1.83 +		{
    1.84 +			return SMINTERFACE_ADMINSYS_NAME;
    1.85 +		}
    1.86 +		unsigned int GetInterfaceVersion()
    1.87 +		{
    1.88 +			return SMINTERFACE_ADMINSYS_VERSION;
    1.89 +		}
    1.90 +	public:
    1.91 +		/**
    1.92 +		 * @brief Adds a global command flag override.  Any command registered with this name
    1.93 +		 * will assume the new flag.  This is applied retroactively as well.
    1.94 +		 *
    1.95 +		 * @param cmd			String containing command name (case sensitive).
    1.96 +		 * @param type			Override type (specific command or group).
    1.97 +		 * @param flag			New admin flag.
    1.98 +		 */
    1.99 +		virtual void AddCommandOverride(const char *cmd, OverrideType type, AdminFlag flag) =0;
   1.100 +
   1.101 +		/**
   1.102 +		 * @brief Returns a command override.
   1.103 +		 *
   1.104 +		 * @param cmd			String containing command name (case sensitive).
   1.105 +		 * @param type			Override type (specific command or group).
   1.106 +		 * @param pFlag			Optional pointer to the set flag.
   1.107 +		 * @return				True if there is an override, false otherwise.
   1.108 +		 */
   1.109 +		virtual bool GetCommandOverride(const char *cmd, OverrideType type, AdminFlag *pFlag) =0;
   1.110 +
   1.111 +		/**
   1.112 +		 * @brief Unsets a command override.
   1.113 +		 *
   1.114 +		 * @param cmd			String containing command name (case sensitive).
   1.115 +		 * @param type			Override type (specific command or group).
   1.116 +		 */
   1.117 +		virtual void UnsetCommandOverride(const char *cmd, OverrideType type) =0;
   1.118 +
   1.119 +		/**
   1.120 +		 * @brief Dumps the global command override cache (unset all).
   1.121 +		 * 
   1.122 +		 * @param type			Override type (specific command or group).
   1.123 +		 */
   1.124 +		virtual void DumpCommandOverrideCache(OverrideType type) =0;
   1.125 +
   1.126 +		/**
   1.127 +		 * @brief Adds a new group.  Name must be unique.
   1.128 +		 *
   1.129 +		 * @param group_name	String containing the group name.
   1.130 +		 * @return				A new group id, INVALID_GROUP_ID if it already exists.
   1.131 +		 */
   1.132 +		virtual GroupId AddGroup(const char *group_name) =0;
   1.133 +
   1.134 +		/**
   1.135 +		 * @brief Finds a group by name.
   1.136 +		 *
   1.137 +		 * @param group_name	String containing the group name.
   1.138 +		 * @return				A group id, or INVALID_GROUP_ID if not found.
   1.139 +		 */
   1.140 +		virtual GroupId FindGroupByName(const char *group_name) =0;
   1.141 +
   1.142 +		/**
   1.143 +		 * @brief Adds or removes a flag from a group's flag set.
   1.144 +		 * Note: These are called "add flags" because they add to a user's flags.
   1.145 +		 *
   1.146 +		 * @param id			Group id.
   1.147 +		 * @param flag			Admin flag to toggle.
   1.148 +		 * @param enabled		True to set the flag, false to unset/disable.
   1.149 +		 */
   1.150 +		virtual void SetGroupAddFlag(GroupId id, AdminFlag flag, bool enabled) =0;
   1.151 +
   1.152 +		/**
   1.153 +		 * @brief Gets the set value of an add flag on a group's flag set.
   1.154 +		 *
   1.155 +		 * @param id			Group id.
   1.156 +		 * @param flag			Admin flag to retrieve.
   1.157 +		 * @return				True if enabled, false otherwise,
   1.158 +		 */
   1.159 +		virtual bool GetGroupAddFlag(GroupId id, AdminFlag flag) =0;
   1.160 +
   1.161 +		/**
   1.162 +		 * @brief Returns the flag set that is added to a user from their group.
   1.163 +		 * Note: These are called "add flags" because they add to a user's flags.
   1.164 +		 *
   1.165 +		 * @param id			GroupId of the group.
   1.166 +		 * @param flags			Array to store flags in.
   1.167 +		 * @param total			Total number of flags that can be stored in the array.
   1.168 +		 * @return				Number of flags that were written to the array.
   1.169 +		 */
   1.170 +		virtual unsigned int GetGroupAddFlags(GroupId id, AdminFlag flags[], unsigned int total) =0;
   1.171 +
   1.172 +		/**
   1.173 +		 * @brief Toggles a generic immunity type.
   1.174 +		 *
   1.175 +		 * @param id			Group id.
   1.176 +		 * @param type			Generic immunity type.
   1.177 +		 * @param enabled		True to enable, false otherwise.
   1.178 +		 */
   1.179 +		virtual void SetGroupGenericImmunity(GroupId id, ImmunityType type, bool enabled) =0;
   1.180 +
   1.181 +		/**
   1.182 +		 * @brief Returns whether or not a group has global immunity.
   1.183 +		 *
   1.184 +		 * @param id			Group id.
   1.185 +		 * @param type			Generic immunity type.
   1.186 +		 * @return				True if the group has this immunity, false otherwise.
   1.187 +		 */
   1.188 +		virtual bool GetGroupGenericImmunity(GroupId id, ImmunityType type) =0;
   1.189 +
   1.190 +		/**
   1.191 +		 * @brief Adds immunity to a specific group.
   1.192 +		 *
   1.193 +		 * @param id			Group id.
   1.194 +		 * @param other_id		Group id to receive immunity to.
   1.195 +		 */
   1.196 +		virtual void AddGroupImmunity(GroupId id, GroupId other_id) =0;
   1.197 +
   1.198 +		/**
   1.199 +		 * @brief Returns the number of specific group immunities.
   1.200 +		 *
   1.201 +		 * @param id			Group id.
   1.202 +		 * @return				Number of group immunities.
   1.203 +		 */
   1.204 +		virtual unsigned int GetGroupImmunityCount(GroupId id) =0;
   1.205 +
   1.206 +		/**
   1.207 +		 * @brief Returns a group that this group is immune to given an index.
   1.208 +		 *
   1.209 +		 * @param id			Group id.
   1.210 +		 * @param number		Index from 0 to N-1, from GetGroupImmunities().
   1.211 +		 * @return				GroupId that this group is immune to.
   1.212 +		 */
   1.213 +		virtual GroupId GetGroupImmunity(GroupId id, unsigned int number) =0;
   1.214 +
   1.215 +		/**
   1.216 +		 * @brief Adds a group-specific override type.
   1.217 +		 *
   1.218 +		 * @param id			Group id.
   1.219 +		 * @param name			String containing command name (case sensitive).
   1.220 +		 * @param type			Override type (specific command or group).
   1.221 +		 * @param rule			Override allow/deny setting.
   1.222 +		 */
   1.223 +		virtual void AddGroupCommandOverride(GroupId id,
   1.224 +											 const char *name,
   1.225 +											 OverrideType type,
   1.226 +											 OverrideRule rule) =0;
   1.227 +
   1.228 +		/**
   1.229 +		 * @brief Retrieves a group-specific command override.
   1.230 +		 *
   1.231 +		 * @param id			Group id.
   1.232 +		 * @param name			String containing command name (case sensitive).
   1.233 +		 * @param type			Override type (specific command or group).
   1.234 +		 * @param rule			Optional pointer to store allow/deny setting.
   1.235 +		 * @return				True if an override exists, false otherwise.
   1.236 +		 */
   1.237 +		virtual bool GetGroupCommandOverride(GroupId id,
   1.238 +											 const char *name,
   1.239 +											 OverrideType type,
   1.240 +											 OverrideRule *pRule) =0;
   1.241 +
   1.242 +		/**
   1.243 +		 * @brief Invalidates and removes a group from the group cache.
   1.244 +		 *
   1.245 +		 * @param id			Group id.
   1.246 +		 */
   1.247 +		virtual void InvalidateGroup(GroupId id) =0;
   1.248 +
   1.249 +		/**
   1.250 +		 * @brief Invalidates the entire group cache.  WARNING: This will trigger 
   1.251 +		 * an admin cache dump as well!
   1.252 +		 */
   1.253 +		virtual void InvalidateGroupCache() =0;
   1.254 +	};
   1.255 +};
   1.256 +
   1.257 +#endif //_INCLUDE_SOURCEMOD_ADMINISTRATION_SYSTEM_H_