core/AdminCache.h
author David Anderson <dvander@alliedmods.net>
Thu Feb 08 01:11:45 2007 +0000 (2007-02-08)
changeset 453 7611078f11cd
parent 438 e6e11c82d87e
child 458 77520125ee67
permissions -rw-r--r--
added gameevents to the publicly available interfaces
     1 /**
     2  * vim: set ts=4 :
     3  * ===============================================================
     4  * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
     5  * ===============================================================
     6  *
     7  * This file is not open source and may not be copied without explicit
     8  * written permission of AlliedModders LLC.  This file may not be redistributed 
     9  * in whole or significant part.
    10  * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
    11  *
    12  * Version: $Id$
    13  */
    14 
    15 #ifndef _INCLUDE_SOURCEMOD_ADMINCACHE_H_
    16 #define _INCLUDE_SOURCEMOD_ADMINCACHE_H_
    17 
    18 #include "sm_memtable.h"
    19 #include <sm_trie.h>
    20 #include <sh_list.h>
    21 #include <sh_string.h>
    22 #include <IAdminSystem.h>
    23 #include "sm_globals.h"
    24 #include <IForwardSys.h>
    25 
    26 using namespace SourceHook;
    27 
    28 #define GRP_MAGIC_SET		0xDEADFADE
    29 #define GRP_MAGIC_UNSET		0xFACEFACE
    30 #define USR_MAGIC_SET		0xDEADFACE
    31 #define USR_MAGIC_UNSET		0xFADEDEAD
    32 
    33 struct AdminGroup
    34 {
    35 	uint32_t magic;					/* Magic flag, for memory validation (ugh) */
    36 	bool immune_global;				/* Global immunity? */
    37 	bool immune_default;			/* Default immunity? */
    38 	/* Immune from target table (-1 = nonexistant)
    39 	 * [0] = number of entries
    40 	 * [1...N] = immune targets
    41 	 */
    42 	int immune_table;			
    43 	Trie *pCmdTable;				/* Command override table (can be NULL) */
    44 	Trie *pCmdGrpTable;				/* Command group override table (can be NULL) */
    45 	int next_grp;					/* Next group in the chain */
    46 	int prev_grp;					/* Previous group in the chain */
    47 	int nameidx;					/* Name */
    48 	FlagBits addflags;				/* Additive flags */
    49 };
    50 
    51 struct AuthMethod
    52 {
    53 	String name;
    54 	Trie *table;
    55 };
    56 
    57 struct UserAuth
    58 {
    59 	unsigned int index;				/* Index into auth table */
    60 	int identidx;					/* Index into the string table */
    61 };
    62 
    63 struct AdminUser
    64 {
    65 	uint32_t magic;					/* Magic flag, for memory validation */
    66 	FlagBits flags;					/* Flags */
    67 	FlagBits eflags;				/* Effective flags */
    68 	int nameidx;					/* Name index */
    69 	int password;					/* Password index */
    70 	unsigned int grp_count;			/* Number of groups */
    71 	unsigned int grp_size;			/* Size of groups table */
    72 	int grp_table;					/* Group table itself */
    73 	int next_user;					/* Next user in ze list */
    74 	int prev_user;					/* Prev user in the list */
    75 	UserAuth auth;					/* Auth method for this user */
    76 	bool immune_global;				/* Whether globally immune */
    77 	bool immune_default;			/* Whether defaultly immune */
    78 };
    79 
    80 class AdminCache : 
    81 	public IAdminSystem,
    82 	public SMGlobalClass
    83 {
    84 public:
    85 	AdminCache();
    86 	~AdminCache();
    87 public: //SMGlobalClass
    88 	void OnSourceModStartup(bool late);
    89 	void OnSourceModAllInitialized();
    90 	void OnSourceModShutdown();
    91 public: //IAdminSystem
    92 	/** Command cache stuff */
    93 	void AddCommandOverride(const char *cmd, OverrideType type, FlagBits flags);
    94 	bool GetCommandOverride(const char *cmd, OverrideType type, FlagBits *flags);
    95 	void UnsetCommandOverride(const char *cmd, OverrideType type);
    96 	/** Group cache stuff */
    97 	GroupId AddGroup(const char *group_name);
    98 	GroupId FindGroupByName(const char *group_name);
    99 	void SetGroupAddFlag(GroupId id, AdminFlag flag, bool enabled);
   100 	bool GetGroupAddFlag(GroupId id, AdminFlag flag);
   101 	FlagBits GetGroupAddFlags(GroupId id);
   102 	void SetGroupGenericImmunity(GroupId id, ImmunityType type, bool enabled);
   103 	bool GetGroupGenericImmunity(GroupId id, ImmunityType type);
   104 	void InvalidateGroup(GroupId id);
   105 	void AddGroupImmunity(GroupId id, GroupId other_id);
   106 	unsigned int GetGroupImmunityCount(GroupId id);
   107 	GroupId GetGroupImmunity(GroupId id, unsigned int number);
   108 	void AddGroupCommandOverride(GroupId id, const char *name, OverrideType type, OverrideRule rule);
   109 	bool GetGroupCommandOverride(GroupId id, const char *name, OverrideType type, OverrideRule *pRule);
   110 	void DumpAdminCache(AdminCachePart part, bool rebuild);
   111 	void AddAdminListener(IAdminListener *pListener);
   112 	void RemoveAdminListener(IAdminListener *pListener);
   113 	/** User stuff */
   114 	void RegisterAuthIdentType(const char *name);
   115 	AdminId CreateAdmin(const char *name);
   116 	const char *GetAdminName(AdminId id);
   117 	bool BindAdminIdentity(AdminId id, const char *auth, const char *ident);
   118 	virtual void SetAdminFlag(AdminId id, AdminFlag flag, bool enabled);
   119 	bool GetAdminFlag(AdminId id, AdminFlag flag, AccessMode mode);
   120 	FlagBits GetAdminFlags(AdminId id, AccessMode mode);
   121 	bool AdminInheritGroup(AdminId id, GroupId gid);
   122 	unsigned int GetAdminGroupCount(AdminId id);
   123 	GroupId GetAdminGroup(AdminId id, unsigned int index, const char **name);
   124 	void SetAdminPassword(AdminId id, const char *password);
   125 	const char *GetAdminPassword(AdminId id);
   126 	AdminId FindAdminByIdentity(const char *auth, const char *identity);
   127 	bool InvalidateAdmin(AdminId id);
   128 	unsigned int FlagBitsToBitArray(FlagBits bits, bool array[], unsigned int maxSize);
   129 	FlagBits FlagBitArrayToBits(const bool array[], unsigned int maxSize);
   130 	FlagBits FlagArrayToBits(const AdminFlag array[], unsigned int numFlags);
   131 	unsigned int FlagBitsToArray(FlagBits bits, AdminFlag array[], unsigned int maxSize);
   132 	bool CheckAdminFlags(AdminId id, FlagBits bits);
   133 	bool CanAdminTarget(AdminId id, AdminId target);
   134 private:
   135 	void _UnsetCommandOverride(const char *cmd);
   136 	void _UnsetCommandGroupOverride(const char *group);
   137 	void InvalidateGroupCache();
   138 	void InvalidateAdminCache(bool unlink_admins);
   139 	void DumpCommandOverrideCache(OverrideType type);
   140 	Trie *GetMethodByIndex(unsigned int index);
   141 	bool GetMethodIndex(const char *name, unsigned int *_index);
   142 public:
   143 	BaseStringTable *m_pStrings;
   144 	BaseMemTable *m_pMemory;
   145 	Trie *m_pCmdOverrides;
   146 	Trie *m_pCmdGrpOverrides;
   147 	int m_FirstGroup;
   148 	int m_LastGroup;
   149 	int m_FreeGroupList;
   150 	Trie *m_pGroups;
   151 	List<IAdminListener *> m_hooks;
   152 	List<AuthMethod> m_AuthMethods;
   153 	Trie *m_pAuthTables;
   154 	IForward *m_pCacheFwd;
   155 	int m_FirstUser;
   156 	int m_LastUser;
   157 	int m_FreeUserList;
   158 };
   159 
   160 extern AdminCache g_Admins;
   161 
   162 #endif //_INCLUDE_SOURCEMOD_ADMINCACHE_H_