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 /src | |
parent | 793c4382868744f6a9522bd1a1865ffff1dbdb70 (diff) |
Cleanup after mode locks, badwords, akick, access, if destructed
Diffstat (limited to 'src')
-rw-r--r-- | src/access.cpp | 2 | ||||
-rw-r--r-- | src/modes.cpp | 33 | ||||
-rw-r--r-- | src/regchannel.cpp | 88 |
3 files changed, 84 insertions, 39 deletions
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(); } |