3 * ===============================================================
4 * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
5 * ===============================================================
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
15 #ifndef _INCLUDE_SOURCEMOD_ADMINCACHE_H_
16 #define _INCLUDE_SOURCEMOD_ADMINCACHE_H_
18 #include "sm_memtable.h"
21 #include <sh_string.h>
22 #include <IAdminSystem.h>
23 #include "sm_globals.h"
24 #include <IForwardSys.h>
26 using namespace SourceHook;
28 #define GRP_MAGIC_SET 0xDEADFADE
29 #define GRP_MAGIC_UNSET 0xFACEFACE
30 #define USR_MAGIC_SET 0xDEADFACE
31 #define USR_MAGIC_UNSET 0xFADEDEAD
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
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 */
59 unsigned int index; /* Index into auth table */
60 int identidx; /* Index into the string table */
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 */
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);
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);
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);
143 BaseStringTable *m_pStrings;
144 BaseMemTable *m_pMemory;
145 Trie *m_pCmdOverrides;
146 Trie *m_pCmdGrpOverrides;
151 List<IAdminListener *> m_hooks;
152 List<AuthMethod> m_AuthMethods;
154 IForward *m_pCacheFwd;
160 extern AdminCache g_Admins;
162 #endif //_INCLUDE_SOURCEMOD_ADMINCACHE_H_