diff options
author | Adam <Adam@anope.org> | 2012-12-29 20:29:41 -0500 |
---|---|---|
committer | Adam <Adam@anope.org> | 2012-12-29 20:29:41 -0500 |
commit | 326f1a9c8bfe0024883b5dd0da66ec7b9f1ac36f (patch) | |
tree | a129c46c40f1d5068bcbeba9030e24412e38fd8d | |
parent | 793c4382868744f6a9522bd1a1865ffff1dbdb70 (diff) |
Cleanup after mode locks, badwords, akick, access, if destructed
-rw-r--r-- | include/modes.h | 3 | ||||
-rw-r--r-- | include/regchannel.h | 13 | ||||
-rw-r--r-- | modules/commands/cs_register.cpp | 14 | ||||
-rw-r--r-- | modules/protocol/inspircd12.cpp | 2 | ||||
-rw-r--r-- | src/access.cpp | 2 | ||||
-rw-r--r-- | src/modes.cpp | 33 | ||||
-rw-r--r-- | src/regchannel.cpp | 88 |
7 files changed, 103 insertions, 52 deletions
diff --git a/include/modes.h b/include/modes.h index b38ef3dc1..e8c8b2f2b 100644 --- a/include/modes.h +++ b/include/modes.h @@ -350,7 +350,8 @@ class CoreExport ModeManager /* Number of generic channel and user modes we are tracking */ static unsigned GenericChannelModes, GenericUserModes; /* Default channel mode lock */ - static std::multimap<ChannelModeName, ModeLock *> DefaultModeLocks; + static std::list<std::pair<ChannelModeName, Anope::string> > ModeLockOn; + static std::list<ChannelModeName> ModeLockOff; /* Default modes bots have on channels */ static ChannelStatus DefaultBotModes; diff --git a/include/regchannel.h b/include/regchannel.h index 1cefe27dd..6c1b618b2 100644 --- a/include/regchannel.h +++ b/include/regchannel.h @@ -138,11 +138,12 @@ enum BadWordType /* Structure used to contain bad words. */ struct CoreExport BadWord : Serializable { - ChannelInfo *ci; + Serialize::Reference<ChannelInfo> ci; Anope::string word; BadWordType type; - BadWord() : Serializable("BadWord") { } + BadWord(); + ~BadWord(); void Serialize(Serialize::Data &data) const anope_override; static Serializable* Unserialize(Serializable *obj, Serialize::Data &); }; @@ -172,6 +173,7 @@ class CoreExport AutoKick : public Flags<AutoKickFlag>, public Serializable time_t last_used; AutoKick(); + ~AutoKick(); void Serialize(Serialize::Data &data) const anope_override; static Serializable* Unserialize(Serializable *obj, Serialize::Data &); }; @@ -187,6 +189,7 @@ struct CoreExport ModeLock : Serializable time_t created; ModeLock(ChannelInfo *ch, bool s, ChannelModeName n, const Anope::string &p, const Anope::string &se = "", time_t c = Anope::CurTime); + ~ModeLock(); void Serialize(Serialize::Data &data) const anope_override; static Serializable* Unserialize(Serializable *obj, Serialize::Data &); @@ -357,6 +360,8 @@ class CoreExport ChannelInfo : public Serializable, public Extensible, public Fl */ unsigned GetAkickCount() const; + void EraseAkick(const AutoKick *akick); + /** Erase an entry from the channel akick list * @param index The index of the akick */ @@ -384,6 +389,8 @@ class CoreExport ChannelInfo : public Serializable, public Extensible, public Fl */ unsigned GetBadWordCount() const; + void EraseBadWord(const BadWord *bw); + /** Remove a badword * @param index The index of the badword */ @@ -419,6 +426,8 @@ class CoreExport ChannelInfo : public Serializable, public Extensible, public Fl */ bool RemoveMLock(ChannelMode *mode, bool status, const Anope::string ¶m = ""); + void RemoveMLock(ModeLock *mlock); + /** Clear all mlocks on the channel */ void ClearMLock(); diff --git a/modules/commands/cs_register.cpp b/modules/commands/cs_register.cpp index d1ada3c19..92c5ec6f9 100644 --- a/modules/commands/cs_register.cpp +++ b/modules/commands/cs_register.cpp @@ -54,16 +54,12 @@ class CommandCSRegister : public Command { ci = new ChannelInfo(chan); ci->SetFounder(nc); - if (!chdesc.empty()) - ci->desc = chdesc; + ci->desc = chdesc; - for (ChannelInfo::ModeList::iterator it = ModeManager::DefaultModeLocks.begin(), it_end = ModeManager::DefaultModeLocks.end(); it != it_end; ++it) - { - ModeLock *ml = new ModeLock(*it->second); - ml->setter = source.GetNick(); - ml->ci = ci; - ci->mode_locks->insert(std::make_pair(it->first, ml)); - } + for (std::list<std::pair<ChannelModeName, Anope::string> >::const_iterator it = ModeManager::ModeLockOn.begin(), it_end = ModeManager::ModeLockOn.end(); it != it_end; ++it) + ci->SetMLock(ModeManager::FindChannelModeByName(it->first), true, it->second, source.GetNick()); + for (std::list<ChannelModeName>::const_iterator it = ModeManager::ModeLockOff.begin(), it_end = ModeManager::ModeLockOff.end(); it != it_end; ++it) + ci->SetMLock(ModeManager::FindChannelModeByName(*it), false, "", source.GetNick()); if (c && !c->topic.empty()) { diff --git a/modules/protocol/inspircd12.cpp b/modules/protocol/inspircd12.cpp index 53ca4ec62..89540b6f4 100644 --- a/modules/protocol/inspircd12.cpp +++ b/modules/protocol/inspircd12.cpp @@ -847,7 +847,7 @@ struct IRCDMessageFJoin : IRCDMessage } time_t ts = Anope::string(params[1]).is_pos_number_only() ? convertTo<time_t>(params[1]) : Anope::CurTime; - Message::Join::SJoin(source, params[0], ts, "", users); + Message::Join::SJoin(source, params[0], ts, modes, users); } }; diff --git a/src/access.cpp b/src/access.cpp index c8cd3cf98..e710548c1 100644 --- a/src/access.cpp +++ b/src/access.cpp @@ -97,6 +97,8 @@ ChanAccess::ChanAccess(AccessProvider *p) : Serializable("ChanAccess"), provider ChanAccess::~ChanAccess() { + if (ci) + ci->EraseAccess(this); } void ChanAccess::Serialize(Serialize::Data &data) const diff --git a/src/modes.cpp b/src/modes.cpp index 5bc9e18f5..291d54444 100644 --- a/src/modes.cpp +++ b/src/modes.cpp @@ -26,7 +26,8 @@ std::vector<UserMode *> ModeManager::UserModes; unsigned ModeManager::GenericChannelModes = 0, ModeManager::GenericUserModes = 0; /* Default channel mode lock */ -ChannelInfo::ModeList ModeManager::DefaultModeLocks; +std::list<std::pair<ChannelModeName, Anope::string> > ModeManager::ModeLockOn; +std::list<ChannelModeName> ModeManager::ModeLockOff; /* Default modes bots have on channels */ ChannelStatus ModeManager::DefaultBotModes; @@ -613,9 +614,8 @@ void ModeManager::StackerDel(Mode *m) void ModeManager::UpdateDefaultMLock(ServerConfig *config) { - for (ChannelInfo::ModeList::iterator it = DefaultModeLocks.begin(), it_end = DefaultModeLocks.end(); it != it_end; ++it) - delete it->second; - DefaultModeLocks.clear(); + ModeLockOn.clear(); + ModeLockOff.clear(); Anope::string modes; spacesepstream sep(config->MLock); @@ -643,14 +643,25 @@ void ModeManager::UpdateDefaultMLock(ServerConfig *config) if (cm->type != MODE_LIST) // Only MODE_LIST can have duplicates { - ChannelInfo::ModeList::iterator it = DefaultModeLocks.find(cm->name); - if (it != DefaultModeLocks.end()) - { - delete it->second; - DefaultModeLocks.erase(it); - } + for (std::list<std::pair<ChannelModeName, Anope::string> >::iterator it = ModeLockOn.begin(), it_end = ModeLockOn.end(); it != it_end; ++it) + if (it->first == cm->name) + { + ModeLockOn.erase(it); + break; + } + + for (std::list<ChannelModeName>::iterator it = ModeLockOff.begin(), it_end = ModeLockOff.end(); it != it_end; ++it) + if (*it == cm->name) + { + ModeLockOff.erase(it); + break; + } } - DefaultModeLocks.insert(std::make_pair(cm->name, new ModeLock(NULL, adding == 1, cm->name, param))); + + if (adding) + ModeLockOn.push_back(std::make_pair(cm->name, param)); + else + ModeLockOff.push_back(cm->name); } } } diff --git a/src/regchannel.cpp b/src/regchannel.cpp index 13e0f16d5..cc76bc5ba 100644 --- a/src/regchannel.cpp +++ b/src/regchannel.cpp @@ -33,6 +33,16 @@ template<> const Anope::string* Flags<ChannelInfoFlag>::flags_strings = ChannelI static const Anope::string AutoKickFlagString[] = { "AK_ISNICK", "" }; template<> const Anope::string* Flags<AutoKickFlag>::flags_strings = AutoKickFlagString; +BadWord::BadWord() : Serializable("BadWord") +{ +} + +BadWord::~BadWord() +{ + if (ci) + ci->EraseBadWord(this); +} + void BadWord::Serialize(Serialize::Data &data) const { data["ci"] << this->ci->name; @@ -71,6 +81,12 @@ AutoKick::AutoKick() : Serializable("AutoKick") { } +AutoKick::~AutoKick() +{ + if (this->ci) + this->ci->EraseAkick(this); +} + void AutoKick::Serialize(Serialize::Data &data) const { data["ci"] << this->ci->name; @@ -137,6 +153,12 @@ ModeLock::ModeLock(ChannelInfo *ch, bool s, ChannelModeName n, const Anope::stri { } +ModeLock::~ModeLock() +{ + if (this->ci) + this->ci->RemoveMLock(this); +} + void ModeLock::Serialize(Serialize::Data &data) const { if (!this->ci) @@ -376,9 +398,8 @@ ChannelInfo::~ChannelInfo() this->log_settings->at(i)->Destroy(); this->log_settings->clear(); - for (ChannelInfo::ModeList::iterator it = this->mode_locks->begin(), it_end = this->mode_locks->end(); it != it_end; ++it) - it->second->Destroy(); - this->mode_locks->clear(); + while (!this->mode_locks->empty()) + this->mode_locks->begin()->second->Destroy(); if (!this->memos.memos->empty()) { @@ -609,26 +630,19 @@ void ChannelInfo::EraseAccess(unsigned index) return; this->access->at(index)->Destroy(); - this->access->erase(this->access->begin() + index); } void ChannelInfo::EraseAccess(const ChanAccess *taccess) { - for (unsigned i = 0, end = this->access->size(); i < end; ++i) - { - if (this->GetAccess(i) == taccess) - { - this->EraseAccess(i); - break; - } - } + std::vector<ChanAccess *>::iterator it = std::find(this->access->begin(), this->access->end(), taccess); + if (it != this->access->end()) + this->access->erase(it); } void ChannelInfo::ClearAccess() { for (unsigned i = this->access->size(); i > 0; --i) this->GetAccess(i - 1)->Destroy(); - this->access->clear(); } AutoKick *ChannelInfo::AddAkick(const Anope::string &user, NickCore *akicknc, const Anope::string &reason, time_t t, time_t lu) @@ -678,19 +692,25 @@ unsigned ChannelInfo::GetAkickCount() const return this->akick->size(); } +void ChannelInfo::EraseAkick(const AutoKick *takick) +{ + std::vector<AutoKick *>::iterator it = std::find(this->akick->begin(), this->akick->end(), takick); + if (it != this->akick->end()) + this->akick->erase(it); +} + void ChannelInfo::EraseAkick(unsigned index) { if (this->akick->empty() || index >= this->akick->size()) return; this->GetAkick(index)->Destroy(); - this->akick->erase(this->akick->begin() + index); } void ChannelInfo::ClearAkick() { while (!this->akick->empty()) - EraseAkick(0); + this->akick->back()->Destroy(); } BadWord* ChannelInfo::AddBadWord(const Anope::string &word, BadWordType type) @@ -722,6 +742,13 @@ unsigned ChannelInfo::GetBadWordCount() const return this->badwords->size(); } +void ChannelInfo::EraseBadWord(const BadWord *bw) +{ + std::vector<BadWord *>::iterator it = std::find(this->badwords->begin(), this->badwords->end(), bw); + if (it != this->badwords->end()) + this->badwords->erase(it); +} + void ChannelInfo::EraseBadWord(unsigned index) { if (this->badwords->empty() || index >= this->badwords->size()) @@ -729,14 +756,13 @@ void ChannelInfo::EraseBadWord(unsigned index) FOREACH_MOD(I_OnBadWordDel, OnBadWordDel(this, (*this->badwords)[index])); - delete (*this->badwords)[index]; - this->badwords->erase(this->badwords->begin() + index); + this->badwords->at(index)->Destroy(); } void ChannelInfo::ClearBadWords() { while (!this->badwords->empty()) - EraseBadWord(0); + this->badwords->back()->Destroy(); } bool ChannelInfo::HasMLock(ChannelMode *mode, const Anope::string ¶m, bool status) const @@ -776,13 +802,8 @@ bool ChannelInfo::SetMLock(ChannelMode *mode, bool status, const Anope::string & /* First, remove this */ if (mode->type == MODE_REGULAR || mode->type == MODE_PARAM) { - ChannelInfo::ModeList::const_iterator it = this->mode_locks->find(mode->name); - if (it != this->mode_locks->end()) - { - ChannelInfo::ModeList::const_iterator it_end = this->mode_locks->upper_bound(mode->name); - for (; it != it_end; ++it) - it->second->Destroy(); - } + for (ChannelInfo::ModeList::const_iterator it; (it = this->mode_locks->find(mode->name)) != this->mode_locks->end();) + it->second->Destroy(); this->mode_locks->erase(mode->name); } else @@ -798,7 +819,6 @@ bool ChannelInfo::SetMLock(ChannelMode *mode, bool status, const Anope::string & if (modelock->param == param) { it->second->Destroy(); - this->mode_locks->erase(it); break; } } @@ -829,7 +849,6 @@ bool ChannelInfo::RemoveMLock(ChannelMode *mode, bool status, const Anope::strin if (MOD_RESULT != EVENT_STOP) { it->second->Destroy(); - this->mode_locks->erase(it); return true; } } @@ -852,7 +871,6 @@ bool ChannelInfo::RemoveMLock(ChannelMode *mode, bool status, const Anope::strin if (MOD_RESULT == EVENT_STOP) return false; it->second->Destroy(); - this->mode_locks->erase(it); return true; } } @@ -862,8 +880,22 @@ bool ChannelInfo::RemoveMLock(ChannelMode *mode, bool status, const Anope::strin } } +void ChannelInfo::RemoveMLock(ModeLock *mlock) +{ + ChannelInfo::ModeList::iterator it = this->mode_locks->find(mlock->name); + if (it != this->mode_locks->end()) + for (; it != this->mode_locks->upper_bound(mlock->name); ++it) + if (it->second == mlock) + { + this->mode_locks->erase(it); + break; + } +} + void ChannelInfo::ClearMLock() { + while (!this->mode_locks->empty()) + this->mode_locks->begin()->second->Destroy(); this->mode_locks->clear(); } |