diff options
author | attilamolnar <attilamolnar@hush.com> | 2013-07-09 20:21:33 +0200 |
---|---|---|
committer | attilamolnar <attilamolnar@hush.com> | 2013-08-27 18:32:32 +0200 |
commit | 261d5bb566f6383efea99e73c933a2af6f408341 (patch) | |
tree | 7c96f8b89fa2efb043b66c4f93eb8d202e6d9c84 /src/modules | |
parent | 86f8294c2de86b8d060abbb02f7c51c0ca0d9ead (diff) |
m_permchannels Add the ability to save listmodes
Diffstat (limited to 'src/modules')
-rw-r--r-- | src/modules/m_permchannels.cpp | 74 |
1 files changed, 70 insertions, 4 deletions
diff --git a/src/modules/m_permchannels.cpp b/src/modules/m_permchannels.cpp index 1bcb2ac17..04171585b 100644 --- a/src/modules/m_permchannels.cpp +++ b/src/modules/m_permchannels.cpp @@ -22,9 +22,15 @@ /* $ModDesc: Provides support for channel mode +P to provide permanent channels */ +struct ListModeData +{ + std::string modes; + std::string params; +}; + // Not in a class due to circular dependancy hell. static std::string permchannelsconf; -static bool WriteDatabase() +static bool WriteDatabase(Module* mod, bool save_listmodes) { FILE *f; @@ -58,6 +64,44 @@ static bool WriteDatabase() if (!chan->IsModeSet('P')) continue; + std::string chanmodes = chan->ChanModes(true); + if (save_listmodes) + { + ListModeData lm; + + // Bans are managed by the core, so we have to process them separately + lm.modes = std::string(chan->bans.size(), 'b'); + for (BanList::const_iterator j = chan->bans.begin(); j != chan->bans.end(); ++j) + { + lm.params += j->data; + lm.params += ' '; + } + + // All other listmodes are managed by modules, so we need to ask them (call their + // OnSyncChannel() handler) to give our ProtoSendMode() a list of modes that are + // set on the channel. The ListModeData struct is passed as an opaque pointer + // that will be passed back to us by the module handling the mode. + FOREACH_MOD(I_OnSyncChannel, OnSyncChannel(chan, mod, &lm)); + + if (!lm.modes.empty()) + { + // Remove the last space + lm.params.erase(lm.params.end()-1); + + // If there is at least a space in chanmodes (that is, a non-listmode has a parameter) + // insert the listmode mode letters before the space. Otherwise just append them. + std::string::size_type p = chanmodes.find(' '); + if (p == std::string::npos) + chanmodes += lm.modes; + else + chanmodes.insert(p, lm.modes); + + // Append the listmode parameters (the masks themselves) + chanmodes += ' '; + chanmodes += lm.params; + } + } + std::string chants = ConvToStr(chan->age); std::string topicts = ConvToStr(chan->topicset); const char* items[] = @@ -73,7 +117,7 @@ static bool WriteDatabase() " topicsetby=", chan->setby.c_str(), " modes=", - chan->ChanModes(true), + chanmodes.c_str(), ">\n" }; @@ -170,6 +214,7 @@ class ModulePermanentChannels : public Module { PermChannel p; bool dirty; + bool save_listmodes; public: ModulePermanentChannels() : p(this), dirty(false) @@ -213,7 +258,9 @@ public: virtual void OnRehash(User *user) { - permchannelsconf = ServerInstance->Config->ConfValue("permchanneldb")->getString("filename"); + ConfigTag* tag = ServerInstance->Config->ConfValue("permchanneldb"); + permchannelsconf = tag->getString("filename"); + save_listmodes = tag->getBool("listmodes"); } void LoadDatabase() @@ -296,7 +343,7 @@ public: void OnBackgroundTimer(time_t) { if (dirty) - WriteDatabase(); + WriteDatabase(this, save_listmodes); dirty = false; } @@ -332,6 +379,25 @@ public: } } + void ProtoSendMode(void* opaque, TargetTypeFlags type, void* target, const std::vector<std::string>& modes, const std::vector<TranslateType>& translate) + { + // We never pass an empty modelist but better be sure + if (modes.empty()) + return; + + ListModeData* lm = static_cast<ListModeData*>(opaque); + + // Append the mode letters without the trailing '+' (for example "IIII", "gg") + lm->modes.append(modes[0].begin()+1, modes[0].end()); + + // Append the parameters + for (std::vector<std::string>::const_iterator i = modes.begin()+1; i != modes.end(); ++i) + { + lm->params += *i; + lm->params += ' '; + } + } + virtual Version GetVersion() { return Version("Provides support for channel mode +P to provide permanent channels",VF_VENDOR); |