core/AdminCache.h
branchsourcemod-1.1.0
changeset 2283 03a67e41afbc
parent 1951 c7b4237fff50
child 2287 017a725c9d17
     1.1 --- a/core/AdminCache.h	Fri Mar 28 06:21:34 2008 +0000
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,201 +0,0 @@
     1.4 -/**
     1.5 - * vim: set ts=4 :
     1.6 - * =============================================================================
     1.7 - * SourceMod
     1.8 - * Copyright (C) 2004-2007 AlliedModders LLC.  All rights reserved.
     1.9 - * =============================================================================
    1.10 - *
    1.11 - * This program is free software; you can redistribute it and/or modify it under
    1.12 - * the terms of the GNU General Public License, version 3.0, as published by the
    1.13 - * Free Software Foundation.
    1.14 - * 
    1.15 - * This program is distributed in the hope that it will be useful, but WITHOUT
    1.16 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    1.17 - * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    1.18 - * details.
    1.19 - *
    1.20 - * You should have received a copy of the GNU General Public License along with
    1.21 - * this program.  If not, see <http://www.gnu.org/licenses/>.
    1.22 - *
    1.23 - * As a special exception, AlliedModders LLC gives you permission to link the
    1.24 - * code of this program (as well as its derivative works) to "Half-Life 2," the
    1.25 - * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    1.26 - * by the Valve Corporation.  You must obey the GNU General Public License in
    1.27 - * all respects for all other code used.  Additionally, AlliedModders LLC grants
    1.28 - * this exception to all derivative works.  AlliedModders LLC defines further
    1.29 - * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    1.30 - * or <http://www.sourcemod.net/license.php>.
    1.31 - *
    1.32 - * Version: $Id$
    1.33 - */
    1.34 -
    1.35 -#ifndef _INCLUDE_SOURCEMOD_ADMINCACHE_H_
    1.36 -#define _INCLUDE_SOURCEMOD_ADMINCACHE_H_
    1.37 -
    1.38 -#include "sm_memtable.h"
    1.39 -#include <sm_trie.h>
    1.40 -#include <sh_list.h>
    1.41 -#include <sh_string.h>
    1.42 -#include <IAdminSystem.h>
    1.43 -#include "sm_globals.h"
    1.44 -#include <IForwardSys.h>
    1.45 -
    1.46 -using namespace SourceHook;
    1.47 -
    1.48 -#define GRP_MAGIC_SET		0xDEADFADE
    1.49 -#define GRP_MAGIC_UNSET		0xFACEFACE
    1.50 -#define USR_MAGIC_SET		0xDEADFACE
    1.51 -#define USR_MAGIC_UNSET		0xFADEDEAD
    1.52 -
    1.53 -struct AdminGroup
    1.54 -{
    1.55 -	uint32_t magic;					/* Magic flag, for memory validation (ugh) */
    1.56 -	unsigned int immunity_level;	/* Immunity level */
    1.57 -	/* Immune from target table (-1 = nonexistent)
    1.58 -	 * [0] = number of entries
    1.59 -	 * [1...N] = immune targets
    1.60 -	 */
    1.61 -	int immune_table;			
    1.62 -	Trie *pCmdTable;				/* Command override table (can be NULL) */
    1.63 -	Trie *pCmdGrpTable;				/* Command group override table (can be NULL) */
    1.64 -	int next_grp;					/* Next group in the chain */
    1.65 -	int prev_grp;					/* Previous group in the chain */
    1.66 -	int nameidx;					/* Name */
    1.67 -	FlagBits addflags;				/* Additive flags */
    1.68 -};
    1.69 -
    1.70 -struct AuthMethod
    1.71 -{
    1.72 -	String name;
    1.73 -	Trie *table;
    1.74 -};
    1.75 -
    1.76 -struct UserAuth
    1.77 -{
    1.78 -	unsigned int index;				/* Index into auth table */
    1.79 -	int identidx;					/* Index into the string table */
    1.80 -};
    1.81 -
    1.82 -struct AdminUser
    1.83 -{
    1.84 -	uint32_t magic;					/* Magic flag, for memory validation */
    1.85 -	FlagBits flags;					/* Flags */
    1.86 -	FlagBits eflags;				/* Effective flags */
    1.87 -	int nameidx;					/* Name index */
    1.88 -	int password;					/* Password index */
    1.89 -	unsigned int grp_count;			/* Number of groups */
    1.90 -	unsigned int grp_size;			/* Size of groups table */
    1.91 -	int grp_table;					/* Group table itself */
    1.92 -	int next_user;					/* Next user in the list */
    1.93 -	int prev_user;					/* Previous user in the list */
    1.94 -	UserAuth auth;					/* Auth method for this user */
    1.95 -	unsigned int immunity_level;	/* Immunity level */
    1.96 -	unsigned int serialchange;		/* Serial # for changes */
    1.97 -};
    1.98 -
    1.99 -class AdminCache : 
   1.100 -	public IAdminSystem,
   1.101 -	public SMGlobalClass
   1.102 -{
   1.103 -public:
   1.104 -	AdminCache();
   1.105 -	~AdminCache();
   1.106 -public: //SMGlobalClass
   1.107 -	void OnSourceModStartup(bool late);
   1.108 -	void OnSourceModAllInitialized();
   1.109 -	void OnSourceModLevelChange(const char *mapName);
   1.110 -	void OnSourceModShutdown();
   1.111 -	void OnSourceModPluginsLoaded();
   1.112 -public: //IAdminSystem
   1.113 -	/** Command cache stuff */
   1.114 -	void AddCommandOverride(const char *cmd, OverrideType type, FlagBits flags);
   1.115 -	bool GetCommandOverride(const char *cmd, OverrideType type, FlagBits *flags);
   1.116 -	void UnsetCommandOverride(const char *cmd, OverrideType type);
   1.117 -	/** Group cache stuff */
   1.118 -	GroupId AddGroup(const char *group_name);
   1.119 -	GroupId FindGroupByName(const char *group_name);
   1.120 -	void SetGroupAddFlag(GroupId id, AdminFlag flag, bool enabled);
   1.121 -	bool GetGroupAddFlag(GroupId id, AdminFlag flag);
   1.122 -	FlagBits GetGroupAddFlags(GroupId id);
   1.123 -	void SetGroupGenericImmunity(GroupId id, ImmunityType type, bool enabled);
   1.124 -	bool GetGroupGenericImmunity(GroupId id, ImmunityType type);
   1.125 -	void InvalidateGroup(GroupId id);
   1.126 -	void AddGroupImmunity(GroupId id, GroupId other_id);
   1.127 -	unsigned int GetGroupImmunityCount(GroupId id);
   1.128 -	GroupId GetGroupImmunity(GroupId id, unsigned int number);
   1.129 -	void AddGroupCommandOverride(GroupId id, const char *name, OverrideType type, OverrideRule rule);
   1.130 -	bool GetGroupCommandOverride(GroupId id, const char *name, OverrideType type, OverrideRule *pRule);
   1.131 -	void DumpAdminCache(AdminCachePart part, bool rebuild);
   1.132 -	void AddAdminListener(IAdminListener *pListener);
   1.133 -	void RemoveAdminListener(IAdminListener *pListener);
   1.134 -	/** User stuff */
   1.135 -	void RegisterAuthIdentType(const char *name);
   1.136 -	AdminId CreateAdmin(const char *name);
   1.137 -	const char *GetAdminName(AdminId id);
   1.138 -	bool BindAdminIdentity(AdminId id, const char *auth, const char *ident);
   1.139 -	virtual void SetAdminFlag(AdminId id, AdminFlag flag, bool enabled);
   1.140 -	bool GetAdminFlag(AdminId id, AdminFlag flag, AccessMode mode);
   1.141 -	FlagBits GetAdminFlags(AdminId id, AccessMode mode);
   1.142 -	bool AdminInheritGroup(AdminId id, GroupId gid);
   1.143 -	unsigned int GetAdminGroupCount(AdminId id);
   1.144 -	GroupId GetAdminGroup(AdminId id, unsigned int index, const char **name);
   1.145 -	void SetAdminPassword(AdminId id, const char *password);
   1.146 -	const char *GetAdminPassword(AdminId id);
   1.147 -	AdminId FindAdminByIdentity(const char *auth, const char *identity);
   1.148 -	bool InvalidateAdmin(AdminId id);
   1.149 -	unsigned int FlagBitsToBitArray(FlagBits bits, bool array[], unsigned int maxSize);
   1.150 -	FlagBits FlagBitArrayToBits(const bool array[], unsigned int maxSize);
   1.151 -	FlagBits FlagArrayToBits(const AdminFlag array[], unsigned int numFlags);
   1.152 -	unsigned int FlagBitsToArray(FlagBits bits, AdminFlag array[], unsigned int maxSize);
   1.153 -	bool CheckAdminFlags(AdminId id, FlagBits bits);
   1.154 -	bool CanAdminTarget(AdminId id, AdminId target);
   1.155 -	void SetAdminFlags(AdminId id, AccessMode mode, FlagBits bits);
   1.156 -	bool FindFlag(const char *str, AdminFlag *pFlag);
   1.157 -	bool FindFlag(char c, AdminFlag *pAdmFlag);
   1.158 -	FlagBits ReadFlagString(const char *flags, const char **end);
   1.159 -	unsigned int GetAdminSerialChange(AdminId id);
   1.160 -	bool CanAdminUseCommand(int client, const char *cmd);
   1.161 -	const char *GetGroupName(GroupId gid);
   1.162 -	unsigned int SetGroupImmunityLevel(GroupId gid, unsigned int level);
   1.163 -	unsigned int GetGroupImmunityLevel(GroupId gid);
   1.164 -	unsigned int SetAdminImmunityLevel(AdminId id, unsigned int level);
   1.165 -	unsigned int GetAdminImmunityLevel(AdminId id);
   1.166 -	bool CheckAccess(int client, 
   1.167 -		const char *cmd, 
   1.168 -		FlagBits flags, 
   1.169 -		bool override_only);
   1.170 -public:
   1.171 -	bool IsValidAdmin(AdminId id);
   1.172 -private:
   1.173 -	void _UnsetCommandOverride(const char *cmd);
   1.174 -	void _UnsetCommandGroupOverride(const char *group);
   1.175 -	void InvalidateGroupCache();
   1.176 -	void InvalidateAdminCache(bool unlink_admins);
   1.177 -	void DumpCommandOverrideCache(OverrideType type);
   1.178 -	Trie *GetMethodByIndex(unsigned int index);
   1.179 -	bool GetMethodIndex(const char *name, unsigned int *_index);
   1.180 -	void NameFlag(const char *str, AdminFlag flag);
   1.181 -public:
   1.182 -	BaseStringTable *m_pStrings;
   1.183 -	BaseMemTable *m_pMemory;
   1.184 -	Trie *m_pCmdOverrides;
   1.185 -	Trie *m_pCmdGrpOverrides;
   1.186 -	int m_FirstGroup;
   1.187 -	int m_LastGroup;
   1.188 -	int m_FreeGroupList;
   1.189 -	Trie *m_pGroups;
   1.190 -	List<IAdminListener *> m_hooks;
   1.191 -	List<AuthMethod> m_AuthMethods;
   1.192 -	Trie *m_pAuthTables;
   1.193 -	IForward *m_pCacheFwd;
   1.194 -	int m_FirstUser;
   1.195 -	int m_LastUser;
   1.196 -	int m_FreeUserList;
   1.197 -	bool m_InvalidatingAdmins;
   1.198 -	bool m_destroying;
   1.199 -	Trie *m_pLevelNames;
   1.200 -};
   1.201 -
   1.202 -extern AdminCache g_Admins;
   1.203 -
   1.204 -#endif //_INCLUDE_SOURCEMOD_ADMINCACHE_H_