diff options
| author | Adam- <Adam-@5417fbe8-f217-4b02-8779-1006273d7864> | 2009-11-19 01:53:03 +0000 |
|---|---|---|
| committer | Adam- <Adam-@5417fbe8-f217-4b02-8779-1006273d7864> | 2009-11-19 01:53:03 +0000 |
| commit | e514a3793d251409428caf53cbb75f0be90a6f38 (patch) | |
| tree | 349c4cfc9fc45735999fd81d39a515560ab0e083 /src/regchannel.cpp | |
| parent | 68381e69d94735010df986b22c8e758981b50995 (diff) | |
Changed the mode param handling code to be more into the general mode handling code, this cleans up and fixes some small problems with mlocking params. This also helps clarify that the ChannelInfo mode functions are for mlock only. Also, this adds the OnMLock and OnUnMLock events which can be used to control if something can be (un)mlocked
git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@2660 5417fbe8-f217-4b02-8779-1006273d7864
Diffstat (limited to 'src/regchannel.cpp')
| -rw-r--r-- | src/regchannel.cpp | 75 |
1 files changed, 45 insertions, 30 deletions
diff --git a/src/regchannel.cpp b/src/regchannel.cpp index 6bf2c64fe..4d1e1cf7d 100644 --- a/src/regchannel.cpp +++ b/src/regchannel.cpp @@ -416,29 +416,67 @@ const bool ChannelInfo::HasMLock(ChannelModeName Name, bool status) /** Set a mlock * @param Name The mode * @param status True for mlock on, false for mlock off + * @param param The param to use for this mode, if required + * @return true on success, false on failure (module blocking) */ -void ChannelInfo::SetMLock(ChannelModeName Name, bool status) +bool ChannelInfo::SetMLock(ChannelModeName Name, bool status, const std::string param) { size_t value = Name; + if (!status && !param.empty()) + throw CoreException("Was told to mlock a mode negatively with a param?"); + + EventReturn MOD_RESULT; + FOREACH_MOD(I_OnMLock, OnMLock(Name, status, param)); + if (MOD_RESULT == EVENT_STOP) + return false; + + /* First, remove this everywhere */ + mlock_on[value] = false; + mlock_off[value] = false; + + std::map<ChannelModeName, std::string>::iterator it = Params.find(Name); + if (it != Params.end()) + { + Params.erase(it); + } + if (status) mlock_on[value] = true; else mlock_off[value] = true; + + if (status && !param.empty()) + { + Params.insert(std::make_pair(Name, param)); + } + + return true; } /** Remove a mlock * @param Name The mode - * @param status True for mlock on, false for mlock off + * @return true on success, false on failure (module blocking) */ -void ChannelInfo::RemoveMLock(ChannelModeName Name, bool status) +bool ChannelInfo::RemoveMLock(ChannelModeName Name) { size_t value = Name; - if (status) - mlock_on[value] = false; - else - mlock_off[value] = false; + EventReturn MOD_RESULT; + FOREACH_MOD(I_OnUnMLock, OnUnMLock(Name)); + if (MOD_RESULT == EVENT_STOP) + return false; + + mlock_on[value] = false; + mlock_off[value] = false; + + std::map<ChannelModeName, std::string>::iterator it = Params.find(Name); + if (it != Params.end()) + { + Params.erase(it); + } + + return true; } /** Clear all mlocks on the channel @@ -461,29 +499,6 @@ const size_t ChannelInfo::GetMLockCount(bool status) const return mlock_off.count(); } -/** Set a channel mode param on the channel - * @param Name The mode - * @param param The param - * @param true on success - */ -bool ChannelInfo::SetParam(ChannelModeName Name, std::string Value) -{ - return Params.insert(std::make_pair(Name, Value)).second; -} - -/** Unset a param from the channel - * @param Name The mode - */ -void ChannelInfo::UnsetParam(ChannelModeName Name) -{ - std::map<ChannelModeName, std::string>::iterator it = Params.find(Name); - - if (it != Params.end()) - { - Params.erase(it); - } -} - /** Get a param from the channel * @param Name The mode * @param Target a string to put the param into |
