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 void OnSourceModPluginsLoaded();
92 public: //IAdminSystem
93 /** Command cache stuff */
94 void AddCommandOverride(const char *cmd, OverrideType type, FlagBits flags);
95 bool GetCommandOverride(const char *cmd, OverrideType type, FlagBits *flags);
96 void UnsetCommandOverride(const char *cmd, OverrideType type);
97 /** Group cache stuff */
98 GroupId AddGroup(const char *group_name);
99 GroupId FindGroupByName(const char *group_name);
100 void SetGroupAddFlag(GroupId id, AdminFlag flag, bool enabled);
101 bool GetGroupAddFlag(GroupId id, AdminFlag flag);
102 FlagBits GetGroupAddFlags(GroupId id);
103 void SetGroupGenericImmunity(GroupId id, ImmunityType type, bool enabled);
104 bool GetGroupGenericImmunity(GroupId id, ImmunityType type);
105 void InvalidateGroup(GroupId id);
106 void AddGroupImmunity(GroupId id, GroupId other_id);
107 unsigned int GetGroupImmunityCount(GroupId id);
108 GroupId GetGroupImmunity(GroupId id, unsigned int number);
109 void AddGroupCommandOverride(GroupId id, const char *name, OverrideType type, OverrideRule rule);
110 bool GetGroupCommandOverride(GroupId id, const char *name, OverrideType type, OverrideRule *pRule);
111 void DumpAdminCache(AdminCachePart part, bool rebuild);
112 void AddAdminListener(IAdminListener *pListener);
113 void RemoveAdminListener(IAdminListener *pListener);
115 void RegisterAuthIdentType(const char *name);
116 AdminId CreateAdmin(const char *name);
117 const char *GetAdminName(AdminId id);
118 bool BindAdminIdentity(AdminId id, const char *auth, const char *ident);
119 virtual void SetAdminFlag(AdminId id, AdminFlag flag, bool enabled);
120 bool GetAdminFlag(AdminId id, AdminFlag flag, AccessMode mode);
121 FlagBits GetAdminFlags(AdminId id, AccessMode mode);
122 bool AdminInheritGroup(AdminId id, GroupId gid);
123 unsigned int GetAdminGroupCount(AdminId id);
124 GroupId GetAdminGroup(AdminId id, unsigned int index, const char **name);
125 void SetAdminPassword(AdminId id, const char *password);
126 const char *GetAdminPassword(AdminId id);
127 AdminId FindAdminByIdentity(const char *auth, const char *identity);
128 bool InvalidateAdmin(AdminId id);
129 unsigned int FlagBitsToBitArray(FlagBits bits, bool array[], unsigned int maxSize);
130 FlagBits FlagBitArrayToBits(const bool array[], unsigned int maxSize);
131 FlagBits FlagArrayToBits(const AdminFlag array[], unsigned int numFlags);
132 unsigned int FlagBitsToArray(FlagBits bits, AdminFlag array[], unsigned int maxSize);
133 bool CheckAdminFlags(AdminId id, FlagBits bits);
134 bool CanAdminTarget(AdminId id, AdminId target);
135 void SetAdminFlags(AdminId id, AccessMode mode, FlagBits bits);
137 bool IsValidAdmin(AdminId id);
139 void _UnsetCommandOverride(const char *cmd);
140 void _UnsetCommandGroupOverride(const char *group);
141 void InvalidateGroupCache();
142 void InvalidateAdminCache(bool unlink_admins);
143 void DumpCommandOverrideCache(OverrideType type);
144 Trie *GetMethodByIndex(unsigned int index);
145 bool GetMethodIndex(const char *name, unsigned int *_index);
147 BaseStringTable *m_pStrings;
148 BaseMemTable *m_pMemory;
149 Trie *m_pCmdOverrides;
150 Trie *m_pCmdGrpOverrides;
155 List<IAdminListener *> m_hooks;
156 List<AuthMethod> m_AuthMethods;
158 IForward *m_pCacheFwd;
162 bool m_InvalidatingAdmins;
166 extern AdminCache g_Admins;
168 #endif //_INCLUDE_SOURCEMOD_ADMINCACHE_H_