diff options
-rw-r--r-- | include/channels.h | 4 | ||||
-rw-r--r-- | src/bots.cpp | 5 | ||||
-rw-r--r-- | src/channels.cpp | 22 | ||||
-rw-r--r-- | src/messages.cpp | 8 | ||||
-rw-r--r-- | src/uplink.cpp | 1 |
5 files changed, 26 insertions, 14 deletions
diff --git a/include/channels.h b/include/channels.h index 80459d357..23867c792 100644 --- a/include/channels.h +++ b/include/channels.h @@ -32,6 +32,8 @@ struct ChanUserContainer : public Extensible class CoreExport Channel : public Base, public Extensible { + static std::vector<Channel *> deleting; + public: typedef std::multimap<Anope::string, Anope::string> ModeList; private: @@ -300,6 +302,8 @@ class CoreExport Channel : public Base, public Extensible * @param ts The time the channel was created */ static Channel *FindOrCreate(const Anope::string &name, bool &created, time_t ts = Anope::CurTime); + + static void DeleteChannels(); }; #endif // CHANNELS_H diff --git a/src/bots.cpp b/src/bots.cpp index c6a726855..bc8b75594 100644 --- a/src/bots.cpp +++ b/src/bots.cpp @@ -219,12 +219,9 @@ void BotInfo::Part(Channel *c, const Anope::string &reason) IRCD->SendPart(this, c, "%s", !reason.empty() ? reason.c_str() : ""); - Anope::string cname = c->name; - Reference<Channel> cref = c; - c->DeleteUser(this); - FOREACH_MOD(OnPartChannel, (this, cref, cname, reason)); + FOREACH_MOD(OnPartChannel, (this, c, c->name, reason)); } void BotInfo::OnMessage(User *u, const Anope::string &message) diff --git a/src/channels.cpp b/src/channels.cpp index a794f5126..8e9b3be94 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -27,6 +27,7 @@ #include "uplink.h" channel_map ChannelList; +std::vector<Channel *> Channel::deleting; Channel::Channel(const Anope::string &nname, time_t ts) { @@ -168,8 +169,8 @@ void Channel::DeleteUser(User *user) Log(LOG_DEBUG) << "Channel::DeleteUser() tried to delete non-existent channel " << this->name << " from " << user->nick << "'s channel list"; delete cu; - if (this->CheckDelete()) - delete this; + if (std::find(deleting.begin(), deleting.end(), this) == deleting.end()) + deleting.push_back(this); } ChanUserContainer *Channel::FindUser(User *u) const @@ -759,12 +760,11 @@ void Channel::KickInternal(const MessageSource &source, const Anope::string &nic return; } - Anope::string this_name = this->name; ChannelStatus status = cu->status; FOREACH_MOD(OnPreUserKicked, (source, cu, reason)); - this->DeleteUser(target); /* This can delete this; */ - FOREACH_MOD(OnUserKicked, (source, target, this_name, status, reason)); + this->DeleteUser(target); + FOREACH_MOD(OnUserKicked, (source, target, this->name, status, reason)); } bool Channel::Kick(BotInfo *bi, User *u, const char *reason, ...) @@ -939,3 +939,15 @@ Channel *Channel::FindOrCreate(const Anope::string &name, bool &created, time_t return chan; } +void Channel::DeleteChannels() +{ + for (unsigned int i = 0; i < deleting.size(); ++i) + { + Channel *c = deleting[i]; + + if (c->CheckDelete()) + delete c; + } + deleting.clear(); +} + diff --git a/src/messages.cpp b/src/messages.cpp index 4e1bcd0db..1c035238f 100644 --- a/src/messages.cpp +++ b/src/messages.cpp @@ -84,10 +84,9 @@ void Join::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) ChanUserContainer *cc = it->second; ++it; - Anope::string channame = cc->chan->name; FOREACH_MOD(OnPrePartChannel, (user, cc->chan)); cc->chan->DeleteUser(user); - FOREACH_MOD(OnPartChannel, (user, Channel::Find(channame), channame, "")); + FOREACH_MOD(OnPartChannel, (user, cc->chan, cc->chan->name, "")); } continue; } @@ -284,16 +283,15 @@ void Part::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) while (sep.GetToken(channel)) { - Reference<Channel> c = Channel::Find(channel); + Channel *c = Channel::Find(channel); if (!c || !u->FindChannel(c)) continue; Log(u, c, "part") << "Reason: " << (!reason.empty() ? reason : "No reason"); FOREACH_MOD(OnPrePartChannel, (u, c)); - Anope::string ChannelName = c->name; c->DeleteUser(u); - FOREACH_MOD(OnPartChannel, (u, c, ChannelName, !reason.empty() ? reason : "")); + FOREACH_MOD(OnPartChannel, (u, c, c->name, !reason.empty() ? reason : "")); } } diff --git a/src/uplink.cpp b/src/uplink.cpp index 86851fc50..6171e2353 100644 --- a/src/uplink.cpp +++ b/src/uplink.cpp @@ -136,6 +136,7 @@ bool UplinkSocket::ProcessRead() { Anope::Process(buf); User::QuitUsers(); + Channel::DeleteChannels(); } return b; } |