3 * ================================================================
5 * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
6 * ================================================================
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License,
10 * version 3.0, as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to
21 * link the code of this program (as well as its derivative works) to
22 * "Half-Life 2," the "Source Engine," the "SourcePawn JIT," and any
23 * Game MODs that run on software by the Valve Corporation. You must
24 * obey the GNU General Public License in all respects for all other
25 * code used. Additionally, AlliedModders LLC grants this exception
26 * to all derivative works. AlliedModders LLC defines further
27 * exceptions, found in LICENSE.txt (as of this writing, version
28 * JULY-31-2007), or <http://www.sourcemod.net/license.php>.
33 #ifndef _INCLUDE_SOURCEMOD_ADMINCACHE_H_
34 #define _INCLUDE_SOURCEMOD_ADMINCACHE_H_
36 #include "sm_memtable.h"
39 #include <sh_string.h>
40 #include <IAdminSystem.h>
41 #include "sm_globals.h"
42 #include <IForwardSys.h>
44 using namespace SourceHook;
46 #define GRP_MAGIC_SET 0xDEADFADE
47 #define GRP_MAGIC_UNSET 0xFACEFACE
48 #define USR_MAGIC_SET 0xDEADFACE
49 #define USR_MAGIC_UNSET 0xFADEDEAD
53 uint32_t magic; /* Magic flag, for memory validation (ugh) */
54 bool immune_global; /* Global immunity? */
55 bool immune_default; /* Default immunity? */
56 /* Immune from target table (-1 = nonexistent)
57 * [0] = number of entries
58 * [1...N] = immune targets
61 Trie *pCmdTable; /* Command override table (can be NULL) */
62 Trie *pCmdGrpTable; /* Command group override table (can be NULL) */
63 int next_grp; /* Next group in the chain */
64 int prev_grp; /* Previous group in the chain */
65 int nameidx; /* Name */
66 FlagBits addflags; /* Additive flags */
77 unsigned int index; /* Index into auth table */
78 int identidx; /* Index into the string table */
83 uint32_t magic; /* Magic flag, for memory validation */
84 FlagBits flags; /* Flags */
85 FlagBits eflags; /* Effective flags */
86 int nameidx; /* Name index */
87 int password; /* Password index */
88 unsigned int grp_count; /* Number of groups */
89 unsigned int grp_size; /* Size of groups table */
90 int grp_table; /* Group table itself */
91 int next_user; /* Next user in the list */
92 int prev_user; /* Previous user in the list */
93 UserAuth auth; /* Auth method for this user */
94 bool immune_global; /* Whether globally immune */
95 bool immune_default; /* Whether defaultly immune */
105 public: //SMGlobalClass
106 void OnSourceModStartup(bool late);
107 void OnSourceModAllInitialized();
108 void OnSourceModShutdown();
109 void OnSourceModPluginsLoaded();
110 public: //IAdminSystem
111 /** Command cache stuff */
112 void AddCommandOverride(const char *cmd, OverrideType type, FlagBits flags);
113 bool GetCommandOverride(const char *cmd, OverrideType type, FlagBits *flags);
114 void UnsetCommandOverride(const char *cmd, OverrideType type);
115 /** Group cache stuff */
116 GroupId AddGroup(const char *group_name);
117 GroupId FindGroupByName(const char *group_name);
118 void SetGroupAddFlag(GroupId id, AdminFlag flag, bool enabled);
119 bool GetGroupAddFlag(GroupId id, AdminFlag flag);
120 FlagBits GetGroupAddFlags(GroupId id);
121 void SetGroupGenericImmunity(GroupId id, ImmunityType type, bool enabled);
122 bool GetGroupGenericImmunity(GroupId id, ImmunityType type);
123 void InvalidateGroup(GroupId id);
124 void AddGroupImmunity(GroupId id, GroupId other_id);
125 unsigned int GetGroupImmunityCount(GroupId id);
126 GroupId GetGroupImmunity(GroupId id, unsigned int number);
127 void AddGroupCommandOverride(GroupId id, const char *name, OverrideType type, OverrideRule rule);
128 bool GetGroupCommandOverride(GroupId id, const char *name, OverrideType type, OverrideRule *pRule);
129 void DumpAdminCache(AdminCachePart part, bool rebuild);
130 void AddAdminListener(IAdminListener *pListener);
131 void RemoveAdminListener(IAdminListener *pListener);
133 void RegisterAuthIdentType(const char *name);
134 AdminId CreateAdmin(const char *name);
135 const char *GetAdminName(AdminId id);
136 bool BindAdminIdentity(AdminId id, const char *auth, const char *ident);
137 virtual void SetAdminFlag(AdminId id, AdminFlag flag, bool enabled);
138 bool GetAdminFlag(AdminId id, AdminFlag flag, AccessMode mode);
139 FlagBits GetAdminFlags(AdminId id, AccessMode mode);
140 bool AdminInheritGroup(AdminId id, GroupId gid);
141 unsigned int GetAdminGroupCount(AdminId id);
142 GroupId GetAdminGroup(AdminId id, unsigned int index, const char **name);
143 void SetAdminPassword(AdminId id, const char *password);
144 const char *GetAdminPassword(AdminId id);
145 AdminId FindAdminByIdentity(const char *auth, const char *identity);
146 bool InvalidateAdmin(AdminId id);
147 unsigned int FlagBitsToBitArray(FlagBits bits, bool array[], unsigned int maxSize);
148 FlagBits FlagBitArrayToBits(const bool array[], unsigned int maxSize);
149 FlagBits FlagArrayToBits(const AdminFlag array[], unsigned int numFlags);
150 unsigned int FlagBitsToArray(FlagBits bits, AdminFlag array[], unsigned int maxSize);
151 bool CheckAdminFlags(AdminId id, FlagBits bits);
152 bool CanAdminTarget(AdminId id, AdminId target);
153 void SetAdminFlags(AdminId id, AccessMode mode, FlagBits bits);
155 bool IsValidAdmin(AdminId id);
157 void _UnsetCommandOverride(const char *cmd);
158 void _UnsetCommandGroupOverride(const char *group);
159 void InvalidateGroupCache();
160 void InvalidateAdminCache(bool unlink_admins);
161 void DumpCommandOverrideCache(OverrideType type);
162 Trie *GetMethodByIndex(unsigned int index);
163 bool GetMethodIndex(const char *name, unsigned int *_index);
165 BaseStringTable *m_pStrings;
166 BaseMemTable *m_pMemory;
167 Trie *m_pCmdOverrides;
168 Trie *m_pCmdGrpOverrides;
173 List<IAdminListener *> m_hooks;
174 List<AuthMethod> m_AuthMethods;
176 IForward *m_pCacheFwd;
180 bool m_InvalidatingAdmins;
184 extern AdminCache g_Admins;
186 #endif //_INCLUDE_SOURCEMOD_ADMINCACHE_H_