From 8860ff6224ad3a0fbea732f1f9b95da44caf7bd1 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Tue, 6 Feb 2007 05:13:24 +0000 Subject: [PATCH] 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 --- core/AdminCache.cpp | 72 +++++++++++-------- core/AdminCache.h | 2 +- core/smn_admin.cpp | 2 +- core/sourcemod.cpp | 3 +- .../{admin-base.sp => admin-flatfile.sp} | 7 +- plugins/admin-flatfile/admin-groups.sp | 4 -- plugins/admin-flatfile/admin-levels.sp | 14 ++-- plugins/admin-flatfile/admin-overrides.sp | 6 +- plugins/include/admin.inc | 23 +++--- public/IAdminSystem.h | 40 ++++++++--- 10 files changed, 101 insertions(+), 72 deletions(-) rename plugins/admin-flatfile/{admin-base.sp => admin-flatfile.sp} (78%) diff --git a/core/AdminCache.cpp b/core/AdminCache.cpp index 05074b8e..43580376 100644 --- a/core/AdminCache.cpp +++ b/core/AdminCache.cpp @@ -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::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::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); } } diff --git a/core/AdminCache.h b/core/AdminCache.h index 504be115..11b452ea 100644 --- a/core/AdminCache.h +++ b/core/AdminCache.h @@ -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 */ diff --git a/core/smn_admin.cpp b/core/smn_admin.cpp index b3c799ab..67f1addc 100644 --- a/core/smn_admin.cpp +++ b/core/smn_admin.cpp @@ -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; } diff --git a/core/sourcemod.cpp b/core/sourcemod.cpp index 016f325a..a09ccbc5 100644 --- a/core/sourcemod.cpp +++ b/core/sourcemod.cpp @@ -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); } diff --git a/plugins/admin-flatfile/admin-base.sp b/plugins/admin-flatfile/admin-flatfile.sp similarity index 78% rename from plugins/admin-flatfile/admin-base.sp rename to plugins/admin-flatfile/admin-flatfile.sp index af9ffb5e..261d7ebb 100644 --- a/plugins/admin-flatfile/admin-base.sp +++ b/plugins/admin-flatfile/admin-flatfile.sp @@ -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(); } diff --git a/plugins/admin-flatfile/admin-groups.sp b/plugins/admin-flatfile/admin-groups.sp index 22e27f59..73cb778d 100644 --- a/plugins/admin-flatfile/admin-groups.sp +++ b/plugins/admin-flatfile/admin-groups.sp @@ -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")) { diff --git a/plugins/admin-flatfile/admin-levels.sp b/plugins/admin-flatfile/admin-levels.sp index ed23529c..81dc3a16 100644 --- a/plugins/admin-flatfile/admin-levels.sp +++ b/plugins/admin-flatfile/admin-levels.sp @@ -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")) { diff --git a/plugins/admin-flatfile/admin-overrides.sp b/plugins/admin-flatfile/admin-overrides.sp index cd3a522f..6bb54b61 100644 --- a/plugins/admin-flatfile/admin-overrides.sp +++ b/plugins/admin-flatfile/admin-overrides.sp @@ -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; diff --git a/plugins/include/admin.inc b/plugins/include/admin.inc index 843aa44e..9d3ce6f5 100644 --- a/plugins/include/admin.inc +++ b/plugins/include/admin.inc @@ -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 diff --git a/public/IAdminSystem.h b/public/IAdminSystem.h index db4820d2..af5309ff 100644 --- a/public/IAdminSystem.h +++ b/public/IAdminSystem.h @@ -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.