Added initial admin system natives

Added a few API changes to the admin system
Exposed more interfaces

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40341
This commit is contained in:
David Anderson
2007-01-24 23:43:31 +00:00
parent ffd308f42c
commit 0b8b26042e
11 changed files with 349 additions and 28 deletions
+58 -9
View File
@@ -2,6 +2,7 @@
#include <assert.h>
#include "AdminCache.h"
#include "ShareSys.h"
#include "ForwardSys.h"
AdminCache g_Admins;
@@ -13,6 +14,7 @@ AdminCache::AdminCache()
m_pMemory = m_pStrings->GetMemTable();
m_FreeGroupList = m_FirstGroup = m_LastGroup = INVALID_GROUP_ID;
m_pGroups = sm_trie_create();
m_pCacheFwd = NULL;
}
AdminCache::~AdminCache()
@@ -39,9 +41,16 @@ AdminCache::~AdminCache()
void AdminCache::OnSourceModAllInitialized()
{
m_pCacheFwd = g_Forwards.CreateForward("OnRebuildAdminCache", ET_Ignore, 1, NULL, Param_Cell);
g_ShareSys.AddInterface(NULL, this);
}
void AdminCache::OnSourceModShutdown()
{
g_Forwards.ReleaseForward(m_pCacheFwd);
m_pCacheFwd = NULL;
}
void AdminCache::AddCommandOverride(const char *cmd, OverrideType type, AdminFlag flag)
{
if (type == Override_Command)
@@ -273,7 +282,7 @@ bool AdminCache::GetGroupAddFlag(GroupId id, AdminFlag flag)
return pGroup->addflags[flag];
}
unsigned int AdminCache::GetGroupAddFlags(GroupId id, AdminFlag flags[], unsigned int total)
unsigned int AdminCache::GetGroupAddFlagBits(GroupId id, bool flags[], unsigned int total)
{
AdminGroup *pGroup = (AdminGroup *)m_pMemory->GetAddress(id);
if (!pGroup || pGroup->magic != GRP_MAGIC_SET)
@@ -281,19 +290,16 @@ unsigned int AdminCache::GetGroupAddFlags(GroupId id, AdminFlag flags[], unsigne
return 0;
}
unsigned int r = 0;
unsigned int i;
for (unsigned int i = Admin_None + 1;
i < AdminFlags_TOTAL && r < total;
for (i = Admin_None;
i < AdminFlags_TOTAL && i < total;
i++)
{
if (pGroup->addflags[i])
{
flags[r++] = (AdminFlag)i;
}
flags[i] = pGroup->addflags[i];
}
return r;
return i;
}
void AdminCache::SetGroupGenericImmunity(GroupId id, ImmunityType type, bool enabled)
@@ -566,3 +572,46 @@ void AdminCache::InvalidateGroupCache()
/* Reset the memory table */
m_pMemory->Reset();
}
void AdminCache::AddAdminListener(IAdminListener *pListener)
{
m_hooks.push_back(pListener);
}
void AdminCache::RemoveAdminListener(IAdminListener *pListener)
{
m_hooks.remove(pListener);
}
void AdminCache::DumpAdminCache(int cache_flags, bool rebuild)
{
if (cache_flags & ADMIN_CACHE_OVERRIDES)
{
DumpCommandOverrideCache(Override_Command);
DumpCommandOverrideCache(Override_CommandGroup);
}
if ((cache_flags & ADMIN_CACHE_ADMINS) ||
(cache_flags & ADMIN_CACHE_GROUPS))
{
/* Make sure the flag is set */
cache_flags |= ADMIN_CACHE_ADMINS;
/* :TODO: Dump admin cache */
}
if (cache_flags & ADMIN_CACHE_GROUPS)
{
InvalidateGroupCache();
}
if (rebuild)
{
List<IAdminListener *>::iterator iter;
IAdminListener *pListener;
for (iter=m_hooks.begin(); iter!=m_hooks.end(); iter++)
{
pListener = (*iter);
pListener->OnRebuildAdminCache(cache_flags);
}
}
}
+13 -3
View File
@@ -3,8 +3,12 @@
#include "sm_memtable.h"
#include <sm_trie.h>
#include <sh_list.h>
#include <IAdminSystem.h>
#include "sm_globals.h"
#include <IForwardSys.h>
using namespace SourceHook;
#define GRP_MAGIC_SET 0xDEADFADE
#define GRP_MAGIC_UNSET 0xFACEFACE
@@ -36,27 +40,29 @@ public:
~AdminCache();
public: //SMGlobalClass
void OnSourceModAllInitialized();
void OnSourceModShutdown();
public: //IAdminSystem
/** Command cache stuff */
void AddCommandOverride(const char *cmd, OverrideType type, AdminFlag flag);
bool GetCommandOverride(const char *cmd, OverrideType type, AdminFlag *pFlag);
void UnsetCommandOverride(const char *cmd, OverrideType type);
void DumpCommandOverrideCache(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);
unsigned int GetGroupAddFlags(GroupId Id, AdminFlag flags[], unsigned int total);
unsigned int GetGroupAddFlagBits(GroupId id, bool flags[], unsigned int total);
void SetGroupGenericImmunity(GroupId id, ImmunityType type, bool enabled);
bool GetGroupGenericImmunity(GroupId id, ImmunityType type);
void InvalidateGroup(GroupId id);
void InvalidateGroupCache();
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);
void DumpAdminCache(int cache_flags, bool rebuild);
void AddAdminListener(IAdminListener *pListener);
void RemoveAdminListener(IAdminListener *pListener);
private:
void _AddCommandOverride(const char *cmd, AdminFlag flag);
void _AddCommandGroupOverride(const char *group, AdminFlag flag);
@@ -64,6 +70,8 @@ private:
bool _GetCommandGroupOverride(const char *group, AdminFlag *pFlag);
void _UnsetCommandOverride(const char *cmd);
void _UnsetCommandGroupOverride(const char *group);
void InvalidateGroupCache();
void DumpCommandOverrideCache(OverrideType type);
public:
BaseStringTable *m_pStrings;
BaseMemTable *m_pMemory;
@@ -73,6 +81,8 @@ public:
int m_LastGroup;
int m_FreeGroupList;
Trie *m_pGroups;
List<IAdminListener *> m_hooks;
IForward *m_pCacheFwd;
};
extern AdminCache g_Admins;
+6
View File
@@ -5,6 +5,7 @@
#include <stdlib.h>
#include <assert.h>
#include "CTextParsers.h"
#include "ShareSys.h"
CTextParsers g_TextParser;
@@ -29,6 +30,11 @@ CTextParsers::CTextParsers()
g_ws_chartable[' '] = 1;
}
void CTextParsers::OnSourceModAllInitialized()
{
g_ShareSys.AddInterface(NULL, this);
}
unsigned int CTextParsers::GetUTF8CharBytes(const char *stream)
{
return _GetUTF8CharBytes(stream);
+6 -1
View File
@@ -2,6 +2,7 @@
#define _INCLUDE_SOURCEMOD_TEXTPARSERS_H_
#include <ITextParsers.h>
#include "sm_globals.h"
using namespace SourceMod;
@@ -32,10 +33,14 @@ inline unsigned int _GetUTF8CharBytes(const char *stream)
*/
typedef bool (*STREAMREADER)(void *, char *, size_t, unsigned int *);
class CTextParsers : public ITextParsers
class CTextParsers :
public ITextParsers,
public SMGlobalClass
{
public:
CTextParsers();
public: //SMGlobalClass
void OnSourceModAllInitialized();
public:
bool ParseFile_INI(const char *file,
ITextListener_INI *ini_listener,
+4
View File
@@ -227,6 +227,10 @@
RelativePath="..\sm_trie.cpp"
>
</File>
<File
RelativePath="..\..\public\smn_admin.cpp"
>
</File>
<File
RelativePath="..\smn_filesystem.cpp"
>
+1
View File
@@ -244,6 +244,7 @@ void CExtensionManager::OnSourceModAllInitialized()
g_ExtType = g_ShareSys.CreateIdentType("EXTENSION");
g_PluginSys.AddPluginsListener(this);
g_RootMenu.AddRootConsoleCommand("exts", "Manage extensions", this);
g_ShareSys.AddInterface(NULL, this);
}
void CExtensionManager::OnSourceModShutdown()
+2
View File
@@ -1,6 +1,7 @@
#include <assert.h>
#include "ForwardSys.h"
#include "PluginSys.h"
#include "ShareSys.h"
CForwardManager g_Forwards;
@@ -19,6 +20,7 @@ CForwardManager g_Forwards;
void CForwardManager::OnSourceModAllInitialized()
{
g_PluginSys.AddPluginsListener(this);
g_ShareSys.AddInterface(NULL, this);
}
void CForwardManager::OnSourceModShutdown()
+2
View File
@@ -1249,6 +1249,8 @@ void CPluginManager::OnSourceModAllInitialized()
g_PluginIdent = g_ShareSys.CreateIdentType("PLUGIN");
g_RootMenu.AddRootConsoleCommand("plugins", "Manage Plugins", this);
g_ShareSys.AddInterface(NULL, this);
}
void CPluginManager::OnSourceModShutdown()
+3 -1
View File
@@ -1,6 +1,7 @@
#include "ShareSys.h"
#include "HandleSys.h"
#include "ExtensionSys.h"
#include "LibrarySys.h"
ShareSystem g_ShareSys;
@@ -35,8 +36,9 @@ void ShareSystem::OnSourceModStartup(bool late)
/* Initialize our static identity handle */
m_IdentRoot.ident = g_HandleSys.CreateHandle(m_TypeRoot, NULL, NULL, GetIdentRoot(), NULL);
/* Add the Handle System... it's too innocent and pure to do it itself */
/* Add the Handle System and others... they are too innocent and pure to do it themselves */
AddInterface(NULL, &g_HandleSys);
AddInterface(NULL, &g_LibSys);
}
void ShareSystem::OnSourceModShutdown()