changed how the admin cache is rebuilt

renamed the plugin and fixed compilation errors

--HG--
rename : plugins/admin-flatfile/admin-base.sp => plugins/admin-flatfile/admin-flatfile.sp
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40444
This commit is contained in:
David Anderson 2007-02-06 05:13:24 +00:00
parent 0186e26344
commit 8860ff6224
10 changed files with 101 additions and 72 deletions

View File

@ -35,11 +35,12 @@ AdminCache::AdminCache()
AdminCache::~AdminCache()
{
DumpAdminCache(AdminCache_Overrides, false);
DumpAdminCache(AdminCache_Groups, false);
sm_trie_destroy(m_pCmdGrpOverrides);
sm_trie_destroy(m_pCmdOverrides);
DumpAdminCache(0xFFFFFFFF, false);
if (m_pGroups)
{
sm_trie_destroy(m_pGroups);
@ -759,39 +760,52 @@ void AdminCache::InvalidateAdminCache(bool unlink_admins)
}
}
void AdminCache::DumpAdminCache(int cache_flags, bool rebuild)
void AdminCache::DumpAdminCache(AdminCachePart part, bool rebuild)
{
if (cache_flags & ADMIN_CACHE_OVERRIDES)
List<IAdminListener *>::iterator iter;
IAdminListener *pListener;
cell_t result;
if (part == AdminCache_Overrides)
{
DumpCommandOverrideCache(Override_Command);
DumpCommandOverrideCache(Override_CommandGroup);
}
/* This will auto-invalidate the admin cache */
if (cache_flags & ADMIN_CACHE_GROUPS)
{
InvalidateGroupCache();
}
/* If we only requested an admin rebuild, re-use the internal memory */
if (((cache_flags & ADMIN_CACHE_ADMINS) == ADMIN_CACHE_ADMINS)
&& ((cache_flags & (1<<2)) != (1<<2)))
{
InvalidateAdminCache(true);
}
if (rebuild)
{
List<IAdminListener *>::iterator iter;
IAdminListener *pListener;
cell_t result;
for (iter=m_hooks.begin(); iter!=m_hooks.end(); iter++)
if (rebuild)
{
pListener = (*iter);
pListener->OnRebuildAdminCache(cache_flags);
for (iter=m_hooks.begin(); iter!=m_hooks.end(); iter++)
{
pListener = (*iter);
pListener->OnRebuildOverrideCache();
}
m_pCacheFwd->PushCell(part);
m_pCacheFwd->Execute(&result);
}
} else if (part == AdminCache_Groups || part == AdminCache_Admins) {
if (part == AdminCache_Groups)
{
InvalidateGroupCache();
if (rebuild)
{
for (iter=m_hooks.begin(); iter!=m_hooks.end(); iter++)
{
pListener = (*iter);
pListener->OnRebuildGroupCache();
}
m_pCacheFwd->PushCell(part);
m_pCacheFwd->Execute(&result);
}
}
InvalidateAdminCache(true);
if (rebuild)
{
for (iter=m_hooks.begin(); iter!=m_hooks.end(); iter++)
{
pListener = (*iter);
pListener->OnRebuildAdminCache((part == AdminCache_Groups));
}
m_pCacheFwd->PushCell(AdminCache_Admins);
m_pCacheFwd->Execute(&result);
}
m_pCacheFwd->PushCell(cache_flags);
m_pCacheFwd->Execute(&result);
}
}

View File

@ -107,7 +107,7 @@ public: //IAdminSystem
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 DumpAdminCache(AdminCachePart part, bool rebuild);
void AddAdminListener(IAdminListener *pListener);
void RemoveAdminListener(IAdminListener *pListener);
/** User stuff */

View File

@ -17,7 +17,7 @@
static cell_t DumpAdminCache(IPluginContext *pContext, const cell_t *params)
{
g_Admins.DumpAdminCache(params[1], (params[2] == 1) ? true : false);
g_Admins.DumpAdminCache((AdminCachePart)params[1], (params[2] == 1) ? true : false);
return 1;
}

View File

@ -185,7 +185,8 @@ bool SourceModBase::LevelInit(char const *pMapName, char const *pMapEntities, ch
m_IsMapLoading = false;
g_Admins.DumpAdminCache(ADMIN_CACHE_GROUPS|ADMIN_CACHE_ADMINS|ADMIN_CACHE_OVERRIDES, true);
g_Admins.DumpAdminCache(AdminCache_Overrides, true);
g_Admins.DumpAdminCache(AdminCache_Groups, true);
RETURN_META_VALUE(MRES_IGNORED, true);
}

View File

@ -19,14 +19,13 @@ new g_ErrorCount = 0;
#include "admin-overrides.sp"
#include "admin-groups.sp"
public OnRebuildAdminCache(cache_flags)
public OnRebuildAdminCache(AdminCachePart:part)
{
RefreshLevels();
if (cache_flags & ADMIN_CACHE_OVERRIDES)
if (part == AdminCache_Overrides)
{
ReadOverrides();
}
if (cache_flags & ADMIN_CACHE_GROUPS)
} else if (part == AdminCache_Groups)
{
ReadGroups();
}

View File

@ -81,10 +81,6 @@ public SMCResult:ReadGroups_KeyValue(Handle:smc,
continue;
}
flag = g_FlagLetters[value[i] - 'a'];
if (flag == Admin_None)
{
continue;
}
SetAdmGroupAddFlag(g_CurGrp, flag, true);
}
} else if (StrEqual(key, "immunity")) {

View File

@ -9,12 +9,6 @@ static g_LevelState = LEVEL_STATE_NONE;
LoadDefaultLetters()
{
/* Clear letters first */
for (new i='a'; i<='z'; i++)
{
g_FlagLetters[i-'a'] = Admin_None;
}
g_FlagLetters['a'-'a'] = Admin_Reservation;
g_FlagLetters['b'-'a'] = Admin_Kick;
g_FlagLetters['c'-'a'] = Admin_Ban;
@ -22,7 +16,7 @@ LoadDefaultLetters()
g_FlagLetters['e'-'a'] = Admin_Slay;
g_FlagLetters['f'-'a'] = Admin_Changemap;
g_FlagLetters['g'-'a'] = Admin_Convars;
g_FlagLetters['h'-'a'] = Admin_Configs;
g_FlagLetters['h'-'a'] = Admin_Config;
g_FlagLetters['i'-'a'] = Admin_Chat;
g_FlagLetters['j'-'a'] = Admin_Vote;
g_FlagLetters['h'-'a'] = Admin_Password;
@ -78,7 +72,7 @@ public SMCResult:ReadLevels_KeyValue(Handle:smc, const String:key[], const Strin
chr -= 'a';
new AdminFlag:flag = Admin_None;
new AdminFlag:flag;
if (StrEqual(key, "reservation"))
{
@ -95,8 +89,8 @@ public SMCResult:ReadLevels_KeyValue(Handle:smc, const String:key[], const Strin
flag = Admin_Changemap;
} else if (StrEqual(key, "cvars")) {
flag = Admin_Convars;
} else if (StrEqual(key, "configs")) {
flag = Admin_Configs;
} else if (StrEqual(key, "config")) {
flag = Admin_Config;
} else if (StrEqual(key, "chat")) {
flag = Admin_Chat;
} else if (StrEqual(key, "vote")) {

View File

@ -50,7 +50,7 @@ public SMCResult:ReadOverrides_KeyValue(Handle:smc,
return SMCParse_Continue;
}
new AdminFlag:flag = Admin_None;
new AdminFlag:flag;
if (strlen(value) > 1)
{
@ -65,9 +65,9 @@ public SMCResult:ReadOverrides_KeyValue(Handle:smc,
if (key[0] == '@')
{
AddCommandOverride(key[1], Override_CommandGroup, flag);
AddCommandOverride(key[1], Override_CommandGroup, FlagToBit(flag));
} else {
AddCommandOverride(key, Override_Command, flag);
AddCommandOverride(key, Override_Command, FlagToBit(flag));
}
return SMCParse_Continue;

View File

@ -113,26 +113,31 @@ enum AdmAccessMode
Access_Effective, /**< Access the user has from their groups */
};
#define ADMIN_CACHE_OVERRIDES (1<<0)
#define ADMIN_CACHE_ADMINS (1<<1)
#define ADMIN_CACHE_GROUPS ((1<<2)|ADMIN_CACHE_ADMINS)
/**
* @brief Represents the various cache regions.
*/
enum AdminCachePart
{
AdminCache_Overrides = 0, /**< Global overrides */
AdminCache_Groups = 1, /**< All groups (automatically invalidates admins too) */
AdminCache_Admins = 2, /**< All admins */
};
/**
* Called when part of the admin cache needs to be rebuilt.
* @note Groups should always be rebuilt before admins.
* Called when part of the cache which needs to be rebuilt.
*
* @param cache_flags Flags for which cache to dump.
* @param part Part of the admin cache to rebuild.
*/
forward OnRebuildAdminCache(cache_flags);
forward OnRebuildAdminCache(AdminCachePart:part);
/**
* Tells the admin system to dump a portion of the cache.
*
* @param cache_flags Flags for which cache to dump. Specifying groups also dumps admins.
* @param part Part of the cache to dump. Specifying groups also dumps admins.
* @param rebuild If true, the rebuild forwards will fire.
* @noreturn
*/
native DumpAdminCache(cache_flags, bool:rebuild);
native DumpAdminCache(AdminCachePart:part, bool:rebuild);
/**
* Adds a global command flag override. Any command registered with this name

View File

@ -147,10 +147,6 @@ namespace SourceMod
*/
typedef int AdminId;
#define ADMIN_CACHE_OVERRIDES (1<<0)
#define ADMIN_CACHE_ADMINS (1<<1)
#define ADMIN_CACHE_GROUPS ((1<<2)|ADMIN_CACHE_ADMINS)
/**
* @brief Represents an invalid/nonexistant group or an erroneous operation.
*/
@ -161,19 +157,43 @@ namespace SourceMod
*/
#define INVALID_ADMIN_ID -1
/**
* @brief Represents the various cache regions.
*/
enum AdminCachePart
{
AdminCache_Overrides = 0, /**< Global overrides */
AdminCache_Groups = 1, /**< All groups (automatically invalidates admins too) */
AdminCache_Admins = 2, /**< All admins */
};
/**
* @brief Provides callbacks for admin cache operations.
*/
class IAdminListener
{
public:
virtual unsigned int GetInterfaceVersion()
{
return SMINTERFACE_ADMINSYS_VERSION;
}
public:
/**
* Called when part of the admin cache needs to be rebuilt.
* Groups should always be rebuilt before admins.
* @brief Called when the admin cache needs to be rebuilt.
*
* @param cache_flags Flags for which cache to dump.
* @param auto_rebuild True if this is being called because of a group rebuild.
*/
virtual void OnRebuildAdminCache(int cache_flags) =0;
virtual void OnRebuildAdminCache(bool auto_rebuild) =0;
/**
* @brief Called when the group cache needs to be rebuilt.
*/
virtual void OnRebuildGroupCache() =0;
/**
* @brief Called when the global override cache needs to be rebuilt.
*/
virtual void OnRebuildOverrideCache() =0;
};
typedef unsigned int FlagBits;
@ -339,10 +359,10 @@ namespace SourceMod
* @brief Tells the admin system to dump a portion of the cache.
* This calls into plugin forwards to rebuild the cache.
*
* @param cache_flags Flags for which cache to dump. Specifying groups also dumps admins.
* @param part Portion of the cache to dump.
* @param rebuild If true, the rebuild forwards/events will fire.
*/
virtual void DumpAdminCache(int cache_flags, bool rebuild) =0;
virtual void DumpAdminCache(AdminCachePart part, bool rebuild) =0;
/**
* @brief Adds an admin interface listener.