ds@1952: /**
ds@1952: * vim: set ts=4 :
ds@1952: * =============================================================================
ds@1952: * SourceMod
ds@1952: * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
ds@1952: * =============================================================================
ds@1952: *
ds@1952: * This program is free software; you can redistribute it and/or modify it under
ds@1952: * the terms of the GNU General Public License, version 3.0, as published by the
ds@1952: * Free Software Foundation.
ds@1952: *
ds@1952: * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1952: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1952: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
ds@1952: * details.
ds@1952: *
ds@1952: * You should have received a copy of the GNU General Public License along with
ds@1952: * this program. If not, see .
ds@1952: *
ds@1952: * As a special exception, AlliedModders LLC gives you permission to link the
ds@1952: * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1952: * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1952: * by the Valve Corporation. You must obey the GNU General Public License in
ds@1952: * all respects for all other code used. Additionally, AlliedModders LLC grants
ds@1952: * this exception to all derivative works. AlliedModders LLC defines further
ds@1952: * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1952: * or .
ds@1952: *
ds@1952: * Version: $Id$
ds@1952: */
ds@1952:
ds@1952: #ifndef _INCLUDE_SOURCEMOD_ADMINCACHE_H_
ds@1952: #define _INCLUDE_SOURCEMOD_ADMINCACHE_H_
ds@1952:
ds@1952: #include "sm_memtable.h"
ds@1952: #include
ds@1952: #include
ds@1952: #include
ds@1952: #include
ds@1952: #include "sm_globals.h"
ds@1952: #include
ds@1952:
ds@1952: using namespace SourceHook;
ds@1952:
ds@1952: #define GRP_MAGIC_SET 0xDEADFADE
ds@1952: #define GRP_MAGIC_UNSET 0xFACEFACE
ds@1952: #define USR_MAGIC_SET 0xDEADFACE
ds@1952: #define USR_MAGIC_UNSET 0xFADEDEAD
ds@1952:
ds@1952: struct AdminGroup
ds@1952: {
ds@1952: uint32_t magic; /* Magic flag, for memory validation (ugh) */
ds@1952: unsigned int immunity_level; /* Immunity level */
ds@1952: /* Immune from target table (-1 = nonexistent)
ds@1952: * [0] = number of entries
ds@1952: * [1...N] = immune targets
ds@1952: */
ds@1952: int immune_table;
ds@1952: Trie *pCmdTable; /* Command override table (can be NULL) */
ds@1952: Trie *pCmdGrpTable; /* Command group override table (can be NULL) */
ds@1952: int next_grp; /* Next group in the chain */
ds@1952: int prev_grp; /* Previous group in the chain */
ds@1952: int nameidx; /* Name */
ds@1952: FlagBits addflags; /* Additive flags */
ds@1952: };
ds@1952:
ds@1952: struct AuthMethod
ds@1952: {
ds@1952: String name;
ds@1952: Trie *table;
ds@1952: };
ds@1952:
ds@1952: struct UserAuth
ds@1952: {
ds@1952: unsigned int index; /* Index into auth table */
ds@1952: int identidx; /* Index into the string table */
ds@1952: };
ds@1952:
ds@1952: struct AdminUser
ds@1952: {
ds@1952: uint32_t magic; /* Magic flag, for memory validation */
ds@1952: FlagBits flags; /* Flags */
ds@1952: FlagBits eflags; /* Effective flags */
ds@1952: int nameidx; /* Name index */
ds@1952: int password; /* Password index */
ds@1952: unsigned int grp_count; /* Number of groups */
ds@1952: unsigned int grp_size; /* Size of groups table */
ds@1952: int grp_table; /* Group table itself */
ds@1952: int next_user; /* Next user in the list */
ds@1952: int prev_user; /* Previous user in the list */
ds@1952: UserAuth auth; /* Auth method for this user */
ds@1952: unsigned int immunity_level; /* Immunity level */
ds@1952: unsigned int serialchange; /* Serial # for changes */
ds@1952: };
ds@1952:
ds@1952: class AdminCache :
ds@1952: public IAdminSystem,
ds@1952: public SMGlobalClass
ds@1952: {
ds@1952: public:
ds@1952: AdminCache();
ds@1952: ~AdminCache();
ds@1952: public: //SMGlobalClass
ds@1952: void OnSourceModStartup(bool late);
ds@1952: void OnSourceModAllInitialized();
ds@1952: void OnSourceModLevelChange(const char *mapName);
ds@1952: void OnSourceModShutdown();
ds@1952: void OnSourceModPluginsLoaded();
ds@1952: public: //IAdminSystem
ds@1952: /** Command cache stuff */
ds@1952: void AddCommandOverride(const char *cmd, OverrideType type, FlagBits flags);
ds@1952: bool GetCommandOverride(const char *cmd, OverrideType type, FlagBits *flags);
ds@1952: void UnsetCommandOverride(const char *cmd, OverrideType type);
ds@1952: /** Group cache stuff */
ds@1952: GroupId AddGroup(const char *group_name);
ds@1952: GroupId FindGroupByName(const char *group_name);
ds@1952: void SetGroupAddFlag(GroupId id, AdminFlag flag, bool enabled);
ds@1952: bool GetGroupAddFlag(GroupId id, AdminFlag flag);
ds@1952: FlagBits GetGroupAddFlags(GroupId id);
ds@1952: void SetGroupGenericImmunity(GroupId id, ImmunityType type, bool enabled);
ds@1952: bool GetGroupGenericImmunity(GroupId id, ImmunityType type);
ds@1952: void InvalidateGroup(GroupId id);
ds@1952: void AddGroupImmunity(GroupId id, GroupId other_id);
ds@1952: unsigned int GetGroupImmunityCount(GroupId id);
ds@1952: GroupId GetGroupImmunity(GroupId id, unsigned int number);
ds@1952: void AddGroupCommandOverride(GroupId id, const char *name, OverrideType type, OverrideRule rule);
ds@1952: bool GetGroupCommandOverride(GroupId id, const char *name, OverrideType type, OverrideRule *pRule);
ds@1952: void DumpAdminCache(AdminCachePart part, bool rebuild);
ds@1952: void AddAdminListener(IAdminListener *pListener);
ds@1952: void RemoveAdminListener(IAdminListener *pListener);
ds@1952: /** User stuff */
ds@1952: void RegisterAuthIdentType(const char *name);
ds@1952: AdminId CreateAdmin(const char *name);
ds@1952: const char *GetAdminName(AdminId id);
ds@1952: bool BindAdminIdentity(AdminId id, const char *auth, const char *ident);
ds@1952: virtual void SetAdminFlag(AdminId id, AdminFlag flag, bool enabled);
ds@1952: bool GetAdminFlag(AdminId id, AdminFlag flag, AccessMode mode);
ds@1952: FlagBits GetAdminFlags(AdminId id, AccessMode mode);
ds@1952: bool AdminInheritGroup(AdminId id, GroupId gid);
ds@1952: unsigned int GetAdminGroupCount(AdminId id);
ds@1952: GroupId GetAdminGroup(AdminId id, unsigned int index, const char **name);
ds@1952: void SetAdminPassword(AdminId id, const char *password);
ds@1952: const char *GetAdminPassword(AdminId id);
ds@1952: AdminId FindAdminByIdentity(const char *auth, const char *identity);
ds@1952: bool InvalidateAdmin(AdminId id);
ds@1952: unsigned int FlagBitsToBitArray(FlagBits bits, bool array[], unsigned int maxSize);
ds@1952: FlagBits FlagBitArrayToBits(const bool array[], unsigned int maxSize);
ds@1952: FlagBits FlagArrayToBits(const AdminFlag array[], unsigned int numFlags);
ds@1952: unsigned int FlagBitsToArray(FlagBits bits, AdminFlag array[], unsigned int maxSize);
ds@1952: bool CheckAdminFlags(AdminId id, FlagBits bits);
ds@1952: bool CanAdminTarget(AdminId id, AdminId target);
ds@1952: void SetAdminFlags(AdminId id, AccessMode mode, FlagBits bits);
ds@1952: bool FindFlag(const char *str, AdminFlag *pFlag);
ds@1952: bool FindFlag(char c, AdminFlag *pAdmFlag);
ds@1952: FlagBits ReadFlagString(const char *flags, const char **end);
dvander@1965: size_t FillFlagString(FlagBits bits, char *buffer, size_t maxlen);
ds@1952: unsigned int GetAdminSerialChange(AdminId id);
ds@1952: bool CanAdminUseCommand(int client, const char *cmd);
ds@1952: const char *GetGroupName(GroupId gid);
ds@1952: unsigned int SetGroupImmunityLevel(GroupId gid, unsigned int level);
ds@1952: unsigned int GetGroupImmunityLevel(GroupId gid);
ds@1952: unsigned int SetAdminImmunityLevel(AdminId id, unsigned int level);
ds@1952: unsigned int GetAdminImmunityLevel(AdminId id);
ds@1952: bool CheckAccess(int client,
ds@1952: const char *cmd,
ds@1952: FlagBits flags,
ds@1952: bool override_only);
dvander@1965: bool FindFlagChar(AdminFlag flag, char *c);
ds@1952: public:
ds@1952: bool IsValidAdmin(AdminId id);
dvander@1965: void DumpCache(FILE *fp);
dvander@1965: AdminGroup *GetGroup(GroupId gid);
dvander@1965: AdminUser *GetUser(AdminId id);
dvander@1965: const char *GetString(int idx);
ds@1952: private:
ds@1952: void _UnsetCommandOverride(const char *cmd);
ds@1952: void _UnsetCommandGroupOverride(const char *group);
ds@1952: void InvalidateGroupCache();
ds@1952: void InvalidateAdminCache(bool unlink_admins);
ds@1952: void DumpCommandOverrideCache(OverrideType type);
ds@1952: Trie *GetMethodByIndex(unsigned int index);
ds@1952: bool GetMethodIndex(const char *name, unsigned int *_index);
dvander@1965: const char *GetMethodName(unsigned int index);
ds@1952: void NameFlag(const char *str, AdminFlag flag);
ds@1952: public:
ds@1952: BaseStringTable *m_pStrings;
ds@1952: BaseMemTable *m_pMemory;
ds@1952: Trie *m_pCmdOverrides;
ds@1952: Trie *m_pCmdGrpOverrides;
ds@1952: int m_FirstGroup;
ds@1952: int m_LastGroup;
ds@1952: int m_FreeGroupList;
ds@1952: Trie *m_pGroups;
ds@1952: List m_hooks;
ds@1952: List m_AuthMethods;
ds@1952: Trie *m_pAuthTables;
ds@1952: IForward *m_pCacheFwd;
ds@1952: int m_FirstUser;
ds@1952: int m_LastUser;
ds@1952: int m_FreeUserList;
ds@1952: bool m_InvalidatingAdmins;
ds@1952: bool m_destroying;
ds@1952: Trie *m_pLevelNames;
ds@1952: };
ds@1952:
ds@1952: extern AdminCache g_Admins;
ds@1952:
ds@1952: #endif //_INCLUDE_SOURCEMOD_ADMINCACHE_H_