2007-01-25 23:36:38 +01:00
|
|
|
/**
|
2007-01-29 08:01:26 +01:00
|
|
|
* vim: set ts=4 :
|
2007-01-25 23:36:38 +01:00
|
|
|
* ===============================================================
|
|
|
|
* SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
|
|
|
|
* ===============================================================
|
|
|
|
*
|
|
|
|
* This file is not open source and may not be copied without explicit
|
|
|
|
* written permission of AlliedModders LLC. This file may not be redistributed
|
|
|
|
* in whole or significant part.
|
|
|
|
* For information, see LICENSE.txt or http://www.sourcemod.net/license.php
|
|
|
|
*
|
|
|
|
* Version: $Id$
|
|
|
|
*/
|
|
|
|
|
2007-01-24 22:51:49 +01:00
|
|
|
#ifndef _INCLUDE_SOURCEMOD_ADMINCACHE_H_
|
|
|
|
#define _INCLUDE_SOURCEMOD_ADMINCACHE_H_
|
|
|
|
|
|
|
|
#include "sm_memtable.h"
|
|
|
|
#include <sm_trie.h>
|
2007-01-25 00:43:31 +01:00
|
|
|
#include <sh_list.h>
|
2007-01-29 05:19:14 +01:00
|
|
|
#include <sh_string.h>
|
2007-01-24 22:51:49 +01:00
|
|
|
#include <IAdminSystem.h>
|
|
|
|
#include "sm_globals.h"
|
2007-01-25 00:43:31 +01:00
|
|
|
#include <IForwardSys.h>
|
|
|
|
|
|
|
|
using namespace SourceHook;
|
2007-01-24 22:51:49 +01:00
|
|
|
|
|
|
|
#define GRP_MAGIC_SET 0xDEADFADE
|
|
|
|
#define GRP_MAGIC_UNSET 0xFACEFACE
|
2007-01-29 05:19:14 +01:00
|
|
|
#define USR_MAGIC_SET 0xDEADFACE
|
|
|
|
#define USR_MAGIC_UNSET 0xFADEDEAD
|
2007-01-24 22:51:49 +01:00
|
|
|
|
|
|
|
struct AdminGroup
|
|
|
|
{
|
|
|
|
uint32_t magic; /* Magic flag, for memory validation (ugh) */
|
|
|
|
bool immune_global; /* Global immunity? */
|
|
|
|
bool immune_default; /* Default immunity? */
|
|
|
|
/* Immune from target table (-1 = nonexistant)
|
|
|
|
* [0] = number of entries
|
|
|
|
* [1...N] = immune targets
|
|
|
|
*/
|
|
|
|
int immune_table;
|
|
|
|
Trie *pCmdTable; /* Command override table (can be NULL) */
|
|
|
|
Trie *pCmdGrpTable; /* Command group override table (can be NULL) */
|
|
|
|
int next_grp; /* Next group in the chain */
|
|
|
|
int prev_grp; /* Previous group in the chain */
|
|
|
|
int nameidx; /* Name */
|
2007-02-05 10:14:40 +01:00
|
|
|
FlagBits addflags; /* Additive flags */
|
2007-01-24 22:51:49 +01:00
|
|
|
};
|
|
|
|
|
2007-01-29 05:19:14 +01:00
|
|
|
struct AuthMethod
|
|
|
|
{
|
|
|
|
String name;
|
|
|
|
Trie *table;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct UserAuth
|
|
|
|
{
|
|
|
|
unsigned int index; /* Index into auth table */
|
|
|
|
int identidx; /* Index into the string table */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct AdminUser
|
|
|
|
{
|
2007-02-05 10:14:40 +01:00
|
|
|
uint32_t magic; /* Magic flag, for memory validation */
|
|
|
|
FlagBits flags; /* Flags */
|
|
|
|
FlagBits eflags; /* Effective flags */
|
2007-01-29 05:19:14 +01:00
|
|
|
int nameidx; /* Name index */
|
|
|
|
int password; /* Password index */
|
|
|
|
unsigned int grp_count; /* Number of groups */
|
|
|
|
unsigned int grp_size; /* Size of groups table */
|
|
|
|
int grp_table; /* Group table itself */
|
|
|
|
int next_user; /* Next user in ze list */
|
|
|
|
int prev_user; /* Prev user in the list */
|
2007-01-29 06:02:44 +01:00
|
|
|
UserAuth auth; /* Auth method for this user */
|
2007-02-05 11:34:58 +01:00
|
|
|
bool immune_global; /* Whether globally immune */
|
|
|
|
bool immune_default; /* Whether defaultly immune */
|
2007-01-29 05:19:14 +01:00
|
|
|
};
|
|
|
|
|
2007-01-24 22:51:49 +01:00
|
|
|
class AdminCache :
|
|
|
|
public IAdminSystem,
|
|
|
|
public SMGlobalClass
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
AdminCache();
|
|
|
|
~AdminCache();
|
|
|
|
public: //SMGlobalClass
|
2007-01-29 05:19:14 +01:00
|
|
|
void OnSourceModStartup(bool late);
|
2007-01-24 22:51:49 +01:00
|
|
|
void OnSourceModAllInitialized();
|
2007-01-25 00:43:31 +01:00
|
|
|
void OnSourceModShutdown();
|
2007-01-24 22:51:49 +01:00
|
|
|
public: //IAdminSystem
|
|
|
|
/** Command cache stuff */
|
2007-02-05 10:14:40 +01:00
|
|
|
void AddCommandOverride(const char *cmd, OverrideType type, FlagBits flags);
|
|
|
|
bool GetCommandOverride(const char *cmd, OverrideType type, FlagBits *flags);
|
2007-01-24 22:51:49 +01:00
|
|
|
void UnsetCommandOverride(const char *cmd, OverrideType type);
|
|
|
|
/** Group cache stuff */
|
|
|
|
GroupId AddGroup(const char *group_name);
|
|
|
|
GroupId FindGroupByName(const char *group_name);
|
|
|
|
void SetGroupAddFlag(GroupId id, AdminFlag flag, bool enabled);
|
|
|
|
bool GetGroupAddFlag(GroupId id, AdminFlag flag);
|
2007-02-05 10:14:40 +01:00
|
|
|
FlagBits GetGroupAddFlags(GroupId id);
|
2007-01-24 22:51:49 +01:00
|
|
|
void SetGroupGenericImmunity(GroupId id, ImmunityType type, bool enabled);
|
|
|
|
bool GetGroupGenericImmunity(GroupId id, ImmunityType type);
|
|
|
|
void InvalidateGroup(GroupId id);
|
|
|
|
void AddGroupImmunity(GroupId id, GroupId other_id);
|
|
|
|
unsigned int GetGroupImmunityCount(GroupId id);
|
|
|
|
GroupId GetGroupImmunity(GroupId id, unsigned int number);
|
|
|
|
void AddGroupCommandOverride(GroupId id, const char *name, OverrideType type, OverrideRule rule);
|
|
|
|
bool GetGroupCommandOverride(GroupId id, const char *name, OverrideType type, OverrideRule *pRule);
|
2007-01-25 00:43:31 +01:00
|
|
|
void DumpAdminCache(int cache_flags, bool rebuild);
|
|
|
|
void AddAdminListener(IAdminListener *pListener);
|
|
|
|
void RemoveAdminListener(IAdminListener *pListener);
|
2007-01-29 05:19:14 +01:00
|
|
|
/** User stuff */
|
|
|
|
void RegisterAuthIdentType(const char *name);
|
|
|
|
AdminId CreateAdmin(const char *name);
|
|
|
|
const char *GetAdminName(AdminId id);
|
|
|
|
bool BindAdminIdentity(AdminId id, const char *auth, const char *ident);
|
|
|
|
virtual void SetAdminFlag(AdminId id, AdminFlag flag, bool enabled);
|
|
|
|
bool GetAdminFlag(AdminId id, AdminFlag flag, AccessMode mode);
|
2007-02-05 10:14:40 +01:00
|
|
|
FlagBits GetAdminFlags(AdminId id, AccessMode mode);
|
2007-01-29 05:19:14 +01:00
|
|
|
bool AdminInheritGroup(AdminId id, GroupId gid);
|
|
|
|
unsigned int GetAdminGroupCount(AdminId id);
|
|
|
|
GroupId GetAdminGroup(AdminId id, unsigned int index, const char **name);
|
|
|
|
void SetAdminPassword(AdminId id, const char *password);
|
|
|
|
const char *GetAdminPassword(AdminId id);
|
|
|
|
AdminId FindAdminByIdentity(const char *auth, const char *identity);
|
|
|
|
bool InvalidateAdmin(AdminId id);
|
2007-02-05 10:14:40 +01:00
|
|
|
unsigned int FlagBitsToBitArray(FlagBits bits, bool array[], unsigned int maxSize);
|
|
|
|
FlagBits FlagBitArrayToBits(const bool array[], unsigned int maxSize);
|
|
|
|
FlagBits FlagArrayToBits(const AdminFlag array[], unsigned int numFlags);
|
|
|
|
unsigned int FlagBitsToArray(FlagBits bits, AdminFlag array[], unsigned int maxSize);
|
2007-02-05 11:34:58 +01:00
|
|
|
bool CheckAdminFlags(AdminId id, FlagBits bits);
|
|
|
|
bool CanAdminTarget(AdminId id, AdminId target);
|
2007-01-24 22:51:49 +01:00
|
|
|
private:
|
|
|
|
void _UnsetCommandOverride(const char *cmd);
|
|
|
|
void _UnsetCommandGroupOverride(const char *group);
|
2007-01-25 00:43:31 +01:00
|
|
|
void InvalidateGroupCache();
|
2007-01-29 05:19:14 +01:00
|
|
|
void InvalidateAdminCache(bool unlink_admins);
|
2007-01-25 00:43:31 +01:00
|
|
|
void DumpCommandOverrideCache(OverrideType type);
|
2007-01-29 05:19:14 +01:00
|
|
|
Trie *GetMethodByIndex(unsigned int index);
|
2007-01-29 06:02:44 +01:00
|
|
|
bool GetMethodIndex(const char *name, unsigned int *_index);
|
2007-01-24 22:51:49 +01:00
|
|
|
public:
|
|
|
|
BaseStringTable *m_pStrings;
|
|
|
|
BaseMemTable *m_pMemory;
|
|
|
|
Trie *m_pCmdOverrides;
|
|
|
|
Trie *m_pCmdGrpOverrides;
|
|
|
|
int m_FirstGroup;
|
|
|
|
int m_LastGroup;
|
|
|
|
int m_FreeGroupList;
|
|
|
|
Trie *m_pGroups;
|
2007-01-25 00:43:31 +01:00
|
|
|
List<IAdminListener *> m_hooks;
|
2007-01-29 05:19:14 +01:00
|
|
|
List<AuthMethod> m_AuthMethods;
|
|
|
|
Trie *m_pAuthTables;
|
2007-01-25 00:43:31 +01:00
|
|
|
IForward *m_pCacheFwd;
|
2007-01-29 05:19:14 +01:00
|
|
|
int m_FirstUser;
|
|
|
|
int m_LastUser;
|
|
|
|
int m_FreeUserList;
|
2007-01-24 22:51:49 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
extern AdminCache g_Admins;
|
|
|
|
|
|
|
|
#endif //_INCLUDE_SOURCEMOD_ADMINCACHE_H_
|