diff options
author | attilamolnar <attilamolnar@hush.com> | 2013-09-02 12:33:28 +0200 |
---|---|---|
committer | attilamolnar <attilamolnar@hush.com> | 2013-09-12 14:44:17 +0200 |
commit | 7ba25076818e42b4eac9199477a01101cf57e848 (patch) | |
tree | 35c2c547fc992b58592a3b5f89d63cb53d589cbb | |
parent | 52e4d9c96c83ca4bbbeb487966ac2897a384907d (diff) |
Keep lists of mode handlers by type
-rw-r--r-- | include/mode.h | 26 | ||||
-rw-r--r-- | src/mode.cpp | 26 | ||||
-rw-r--r-- | src/modules/m_autoop.cpp | 8 | ||||
-rw-r--r-- | src/modules/m_exemptchanops.cpp | 8 |
4 files changed, 55 insertions, 13 deletions
diff --git a/include/mode.h b/include/mode.h index bfe4041b9..68f792f3a 100644 --- a/include/mode.h +++ b/include/mode.h @@ -497,6 +497,19 @@ class CoreExport ModeParser */ ModeHandler* modehandlers[256]; + /** Lists of mode handlers by type + */ + struct + { + /** List of mode handlers that inherit from ListModeBase + */ + std::vector<ListModeBase*> list; + + /** List of mode handlers that inherit from PrefixMode + */ + std::vector<PrefixMode*> prefix; + } mhlist; + /** Mode watcher classes */ std::multimap<std::string, ModeWatcher*> modewatchermap; @@ -545,6 +558,9 @@ class CoreExport ModeParser std::string Cached004ModeList; public: + typedef std::vector<ListModeBase*> ListModeList; + typedef std::vector<PrefixMode*> PrefixModeList; + typedef unsigned int ModeProcessFlag; enum ModeProcessFlags { @@ -676,6 +692,16 @@ class CoreExport ModeParser * just the "@%+" part if the parameter false */ std::string BuildPrefixes(bool lettersAndModes = true); + + /** Get a list of all mode handlers that inherit from ListModeBase + * @return A list containing ListModeBase modes + */ + const ListModeList& GetListModes() const { return mhlist.list; } + + /** Get a list of all prefix modes + * @return A list containing all prefix modes + */ + const PrefixModeList& GetPrefixModes() const { return mhlist.prefix; } }; inline const std::string& ModeParser::GetModeListFor004Numeric() diff --git a/src/mode.cpp b/src/mode.cpp index e89cd72ef..4d7f0c655 100644 --- a/src/mode.cpp +++ b/src/mode.cpp @@ -618,7 +618,13 @@ bool ModeParser::AddMode(ModeHandler* mh) if (modehandlers[pos]) return false; + // Everything is fine, add the mode modehandlers[pos] = mh; + if (pm) + mhlist.prefix.push_back(pm); + else if (mh->IsListModeBase()) + mhlist.list.push_back(mh->IsListModeBase()); + RecreateModeListFor004Numeric(); return true; } @@ -672,8 +678,12 @@ bool ModeParser::DelMode(ModeHandler* mh) } modehandlers[pos] = NULL; - RecreateModeListFor004Numeric(); + if (mh->IsPrefixMode()) + mhlist.prefix.erase(std::find(mhlist.prefix.begin(), mhlist.prefix.end(), mh->IsPrefixMode())); + else if (mh->IsListModeBase()) + mhlist.list.erase(std::find(mhlist.list.begin(), mhlist.list.end(), mh->IsListModeBase())); + RecreateModeListFor004Numeric(); return true; } @@ -722,10 +732,11 @@ void ModeParser::RecreateModeListFor004Numeric() PrefixMode* ModeParser::FindPrefix(unsigned const char pfxletter) { - for (unsigned char mode = 'A'; mode <= 'z'; mode++) + const PrefixModeList& list = GetPrefixModes(); + for (PrefixModeList::const_iterator i = list.begin(); i != list.end(); ++i) { - PrefixMode* pm = FindPrefixMode(mode); - if ((pm) && (pm->GetPrefix() == pfxletter)) + PrefixMode* pm = *i; + if (pm->GetPrefix() == pfxletter) return pm; } return NULL; @@ -785,10 +796,11 @@ std::string ModeParser::BuildPrefixes(bool lettersAndModes) std::string mprefixes; std::map<int,std::pair<char,char> > prefixes; - for (unsigned char mode = 'A'; mode <= 'z'; mode++) + const PrefixModeList& list = GetPrefixModes(); + for (PrefixModeList::const_iterator i = list.begin(); i != list.end(); ++i) { - PrefixMode* pm = FindPrefixMode(mode); - if (pm && pm->GetPrefix()) + PrefixMode* pm = *i; + if (pm->GetPrefix()) prefixes[pm->GetPrefixRank()] = std::make_pair(pm->GetPrefix(), pm->GetModeChar()); } diff --git a/src/modules/m_autoop.cpp b/src/modules/m_autoop.cpp index d195345ca..a1b72714b 100644 --- a/src/modules/m_autoop.cpp +++ b/src/modules/m_autoop.cpp @@ -36,10 +36,12 @@ class AutoOpList : public ListModeBase { if (mid.length() == 1) return ServerInstance->Modes->FindPrefixMode(mid[0]); - for(char c='A'; c < 'z'; c++) + + const ModeParser::PrefixModeList& pmlist = ServerInstance->Modes->GetPrefixModes(); + for (ModeParser::PrefixModeList::const_iterator i = pmlist.begin(); i != pmlist.end(); ++i) { - PrefixMode* mh = ServerInstance->Modes->FindPrefixMode(c); - if (mh && mh->name == mid) + PrefixMode* mh = *i; + if (mh->name == mid) return mh; } return NULL; diff --git a/src/modules/m_exemptchanops.cpp b/src/modules/m_exemptchanops.cpp index 5d8958665..a733fa475 100644 --- a/src/modules/m_exemptchanops.cpp +++ b/src/modules/m_exemptchanops.cpp @@ -65,10 +65,12 @@ class ExemptHandler : public HandlerBase3<ModResult, User*, Channel*, const std: { if (mid.length() == 1) return ServerInstance->Modes->FindPrefixMode(mid[0]); - for(char c='A'; c < 'z'; c++) + + const ModeParser::PrefixModeList& pmlist = ServerInstance->Modes->GetPrefixModes(); + for (ModeParser::PrefixModeList::const_iterator i = pmlist.begin(); i != pmlist.end(); ++i) { - PrefixMode* mh = ServerInstance->Modes->FindPrefixMode(c); - if (mh && mh->name == mid) + PrefixMode* mh = *i; + if (mh->name == mid) return mh; } return NULL; |