From 2312f1fbd06ac01bb55e1d99070cde05a09a5a17 Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 7 Oct 2017 21:10:47 -0400 Subject: No longer expose c->ci and ci->c --- include/channels.h | 6 ++- include/modules/chanserv/channel.h | 4 +- modules/botserv/assign.cpp | 22 ++++---- modules/botserv/control.cpp | 6 ++- modules/botserv/kick.cpp | 15 +++--- modules/botserv/main/botserv.cpp | 31 ++++++----- modules/chanserv/access.cpp | 8 +-- modules/chanserv/akick.cpp | 13 ++--- modules/chanserv/ban.cpp | 4 +- modules/chanserv/clone.cpp | 16 +++--- modules/chanserv/drop.cpp | 2 +- modules/chanserv/enforce.cpp | 48 +++++++++-------- modules/chanserv/entrymsg.cpp | 7 +-- modules/chanserv/getkey.cpp | 2 +- modules/chanserv/invite.cpp | 2 +- modules/chanserv/list.cpp | 2 +- modules/chanserv/main/channel.cpp | 16 ++---- modules/chanserv/main/chanserv.cpp | 86 ++++++++++++++++--------------- modules/chanserv/mode.cpp | 73 ++++++++++++++------------ modules/chanserv/register.cpp | 3 -- modules/chanserv/set.cpp | 102 +++++++++++++++++++++---------------- modules/chanserv/statusupdate.cpp | 9 ++-- modules/chanserv/suspend.cpp | 9 ++-- modules/chanserv/sync.cpp | 7 +-- modules/chanserv/topic.cpp | 41 ++++++++------- modules/chanserv/unban.cpp | 12 ++--- modules/chanserv/updown.cpp | 22 ++++---- modules/database/old.cpp | 4 +- modules/fantasy.cpp | 16 +++--- modules/greet.cpp | 9 ++-- modules/helpchan.cpp | 4 +- modules/memoserv/main/memoserv.cpp | 14 ++--- modules/nickserv/ajoin.cpp | 7 +-- modules/nickserv/set.cpp | 2 +- modules/protocol/charybdis.cpp | 17 ++++--- modules/protocol/inspircd20.cpp | 82 ++++++++++++++++------------- modules/protocol/unreal.cpp | 27 ++++++---- src/bots.cpp | 7 +-- src/channels.cpp | 27 +++++++--- src/logger.cpp | 7 ++- src/modes.cpp | 12 ++++- src/servers.cpp | 3 +- 42 files changed, 446 insertions(+), 360 deletions(-) diff --git a/include/channels.h b/include/channels.h index 63e0559c3..d04a63bcf 100644 --- a/include/channels.h +++ b/include/channels.h @@ -53,8 +53,6 @@ class CoreExport Channel : public Base, public Extensible public: /* Channel name */ Anope::string name; - /* Set if this channel is registered. ci->c == this. Contains information relevant to the registered channel */ - Serialize::Reference ci; /* When the channel was created */ time_t creation_time; /* If the channel has just been created in a netjoin */ @@ -98,6 +96,10 @@ class CoreExport Channel : public Base, public Extensible */ ~Channel(); + /** Get the chanserv channel for this channel + */ + ChanServ::Channel *GetChannel(); + /** Gets the channels name * @return the channel name */ diff --git a/include/modules/chanserv/channel.h b/include/modules/chanserv/channel.h index a3b06b350..aab95de67 100644 --- a/include/modules/chanserv/channel.h +++ b/include/modules/chanserv/channel.h @@ -25,12 +25,12 @@ namespace ChanServ class CoreExport Channel : public Serialize::Object { public: - ::Channel *c = nullptr; /* Pointer to channel, if the channel exists */ - static constexpr const char *const NAME = "channel"; using Serialize::Object::Object; + ::Channel *GetChannel() { return ::Channel::Find(GetName()); } + virtual Anope::string GetName() anope_abstract; virtual void SetName(const Anope::string &) anope_abstract; diff --git a/modules/botserv/assign.cpp b/modules/botserv/assign.cpp index 26a448216..469f1f051 100644 --- a/modules/botserv/assign.cpp +++ b/modules/botserv/assign.cpp @@ -248,20 +248,22 @@ class BSAssign : public Module void OnInvite(User *source, Channel *c, User *targ) override { - ServiceBot *bi; - if (Anope::ReadOnly || !c->ci || targ->server != Me || !(bi = ServiceBot::Find(targ->nick, true))) + ServiceBot *bi = ServiceBot::Find(targ->nick, true); + ChanServ::Channel *ci = c->GetChannel(); + + if (Anope::ReadOnly || !ci || targ->server != Me || !bi) return; - ChanServ::AccessGroup access = c->ci->AccessFor(source); + ChanServ::AccessGroup access = ci->AccessFor(source); if (!access.HasPriv("ASSIGN") && !source->HasPriv("botserv/administration")) { - targ->SendMessage(bi, _("Access denied. You do not have privilege \002ASSIGN\002 on \002{0}\002."), c->ci->GetName()); + targ->SendMessage(bi, _("Access denied. You do not have privilege \002ASSIGN\002 on \002{0}\002."), ci->GetName()); return; } - if (nobot.HasExt(c->ci)) + if (nobot.HasExt(ci)) { - targ->SendMessage(bi, _("Access denied. \002{0}\002 may not have a bot assigned to it because a Services Operator has disallowed it."), c->ci->GetName()); + targ->SendMessage(bi, _("Access denied. \002{0}\002 may not have a bot assigned to it because a Services Operator has disallowed it."), ci->GetName()); return; } @@ -271,14 +273,14 @@ class BSAssign : public Module return; } - if (c->ci->GetBot() == bi) + if (ci->GetBot() == bi) { - targ->SendMessage(bi, _("Bot \002{0}\002 is already assigned to \002{1}\002."), bi->nick, c->ci->GetName()); + targ->SendMessage(bi, _("Bot \002{0}\002 is already assigned to \002{1}\002."), bi->nick, ci->GetName()); return; } - bi->Assign(source, c->ci); - targ->SendMessage(bi, _("Bot \002{0}\002 has been assigned to \002{1}\002."), bi->nick, c->ci->GetName()); + bi->Assign(source, ci); + targ->SendMessage(bi, _("Bot \002{0}\002 has been assigned to \002{1}\002."), bi->nick, ci->GetName()); } void OnServiceBot(CommandSource &source, ServiceBot *bi, ChanServ::Channel *ci, InfoFormatter &info) override diff --git a/modules/botserv/control.cpp b/modules/botserv/control.cpp index 584e8eded..758f795f2 100644 --- a/modules/botserv/control.cpp +++ b/modules/botserv/control.cpp @@ -59,7 +59,8 @@ class CommandBSSay : public Command return; } - if (!ci->c || !ci->c->FindUser(ci->GetBot())) + Channel *c = ci->GetChannel(); + if (!c || !c->FindUser(ci->GetBot())) { source.Reply(_("Bot \002{0}\002 is not on channel \002{1}\002."), ci->GetBot()->nick, ci->GetName()); return; @@ -130,7 +131,8 @@ class CommandBSAct : public Command return; } - if (!ci->c || !ci->c->FindUser(ci->GetBot())) + Channel *c = ci->GetChannel(); + if (!c || !c->FindUser(ci->GetBot())) { source.Reply(_("Bot \002{0}\002 is not on channel \002{1}\002."), ci->GetBot()->nick, ci->GetName()); return; diff --git a/modules/botserv/kick.cpp b/modules/botserv/kick.cpp index b90a6e48e..2fbaf4c1b 100644 --- a/modules/botserv/kick.cpp +++ b/modules/botserv/kick.cpp @@ -1323,7 +1323,8 @@ class BSKick : public Module if (u->IsProtected()) return; - BanData::Data &bd = this->GetBanData(u, ci->c); + Channel *c = ci->GetChannel(); + BanData::Data &bd = this->GetBanData(u, c); ++bd.ttb[ttbtype]; if (ttb && bd.ttb[ttbtype] >= ttb) @@ -1332,15 +1333,15 @@ class BSKick : public Module Anope::string mask = ci->GetIdealBan(u); - ci->c->SetMode(NULL, "BAN", mask); + c->SetMode(NULL, "BAN", mask); EventManager::Get()->Dispatch(&Event::BotBan::OnBotBan, u, ci, mask); } - if (!ci->c->FindUser(u)) + if (!c->FindUser(u)) return; Anope::string buf = Anope::Format(message, std::forward(args)...); - ci->c->Kick(ci->GetBot(), u, buf); + c->Kick(ci->GetBot(), u, buf); } public: @@ -1518,10 +1519,10 @@ class BSKick : public Module * But FIRST we check whether the user is protected in any * way. */ - ChanServ::Channel *ci = c->ci; + ChanServ::Channel *ci = c->GetChannel(); if (ci == NULL) return; - KickerData *kd = c->ci->GetRef(); + KickerData *kd = ci->GetRef(); if (kd == NULL) return; @@ -1734,7 +1735,7 @@ class BSKick : public Module Channel *chan = it->second->chan; ++it; - if (chan->ci && kd->GetAmsgs() && !chan->ci->AccessFor(u).HasPriv("NOKICK")) + if (chan->GetChannel() && kd->GetAmsgs() && !chan->GetChannel()->AccessFor(u).HasPriv("NOKICK")) { TakeAction(ci, u, kd->GetTTBAmsgs(), TTB_AMSGS, _("Don't use AMSGs!")); return; diff --git a/modules/botserv/main/botserv.cpp b/modules/botserv/main/botserv.cpp index 8fb71f498..59a3e0ee1 100644 --- a/modules/botserv/main/botserv.cpp +++ b/modules/botserv/main/botserv.cpp @@ -52,21 +52,22 @@ class BotServCore : public Module, public BotServ::BotServService void OnSetCorrectModes(User *user, Channel *chan, ChanServ::AccessGroup &access, bool &give_modes, bool &take_modes) override { /* Do not allow removing bot modes on our service bots */ - if (chan->ci && chan->ci->GetBot() == user) + ChanServ::Channel *ci = chan->GetChannel(); + if (ci && ci->GetBot() == user) { const Anope::string &botmodes = Config->GetModule(this)->Get("botmodes"); for (unsigned i = 0; i < botmodes.length(); ++i) - chan->SetMode(chan->ci->GetBot(), ModeManager::FindChannelModeByChar(botmodes[i]), chan->ci->GetBot()->GetUID()); + chan->SetMode(ci->GetBot(), ModeManager::FindChannelModeByChar(botmodes[i]), ci->GetBot()->GetUID()); } } void OnBotAssign(User *sender, ChanServ::Channel *ci, ServiceBot *bi) override { - printf("on bot assign !\n"); - if (ci->c && ci->c->users.size() >= Config->GetModule(this)->Get("minusers")) + Channel *c = ci->GetChannel(); + if (c && c->users.size() >= Config->GetModule(this)->Get("minusers")) { ChannelStatus status(Config->GetModule(this)->Get("botmodes")); - bi->Join(ci->c, &status); + bi->Join(c, &status); } } @@ -108,7 +109,8 @@ class BotServCore : public Module, public BotServ::BotServService ModeManager::ProcessModes(); } - if (user->server != Me && c->ci && c->ci->GetBot()) + ChanServ::Channel *ci = c->GetChannel(); + if (user->server != Me && ci && ci->GetBot()) { /** * We let the bot join even if it was an ignored user, as if we don't, @@ -117,18 +119,20 @@ class BotServCore : public Module, public BotServ::BotServService * legit users - Rob **/ /* This is before the user has joined the channel, so check usercount + 1 */ - if (c->users.size() + 1 >= Config->GetModule(this)->Get("minusers") && !c->FindUser(c->ci->GetBot())) + if (c->users.size() + 1 >= Config->GetModule(this)->Get("minusers") && !c->FindUser(ci->GetBot())) { ChannelStatus status(Config->GetModule(this)->Get("botmodes")); - c->ci->GetBot()->Join(c, &status); + ci->GetBot()->Join(c, &status); } } } void OnLeaveChannel(User *u, Channel *c) override { + ChanServ::Channel *ci = c->GetChannel(); + /* Channel is persistent, it shouldn't be deleted and the service bot should stay */ - if (c->ci && c->ci->IsPersist()) + if (ci && ci->IsPersist()) return; /* Channel is syncing from a netburst, don't destroy it as more users are probably wanting to join immediately @@ -141,9 +145,9 @@ class BotServCore : public Module, public BotServ::BotServService if (inhabit && inhabit->HasExt(c)) return; - if (c->ci) + if (ci) { - ServiceBot *bot = c->ci->GetBot(); + ServiceBot *bot = ci->GetBot(); /* This is called prior to removing the user from the channnel, so c->users.size() - 1 should be safe */ if (bot && u != bot && c->users.size() - 1 <= Config->GetModule(this)->Get("minusers") && c->FindUser(bot)) @@ -203,9 +207,10 @@ class BotServCore : public Module, public BotServ::BotServService EventReturn OnChannelModeSet(Channel *c, const MessageSource &source, ChannelMode *mode, const Anope::string ¶m) override { - if (source.GetUser() && !source.GetBot() && Config->GetModule(this)->Get("smartjoin") && mode->name == "BAN" && c->ci && c->ci->GetBot() && c->FindUser(c->ci->GetBot())) + ChanServ::Channel *ci = c->GetChannel(); + if (source.GetUser() && !source.GetBot() && Config->GetModule(this)->Get("smartjoin") && mode->name == "BAN" && ci && ci->GetBot() && c->FindUser(ci->GetBot())) { - ServiceBot *bi = c->ci->GetBot(); + ServiceBot *bi = ci->GetBot(); Entry ban("BAN", param); if (ban.Matches(bi)) diff --git a/modules/chanserv/access.cpp b/modules/chanserv/access.cpp index c68af6e6f..32a6422cb 100644 --- a/modules/chanserv/access.cpp +++ b/modules/chanserv/access.cpp @@ -344,8 +344,8 @@ class CommandCSAccess : public Command ChanServ::ChanAccess *access = ci->GetAccess(number - 1); Anope::string timebuf; - if (ci->c) - for (Channel::ChanUserList::const_iterator cit = ci->c->users.begin(), cit_end = ci->c->users.end(); cit != cit_end; ++cit) + if (Channel *c = ci->GetChannel()) + for (Channel::ChanUserList::const_iterator cit = c->users.begin(), cit_end = c->users.end(); cit != cit_end; ++cit) { if (access->Matches(cit->second->user, cit->second->user->Account())) timebuf = "Now"; @@ -378,8 +378,8 @@ class CommandCSAccess : public Command continue; Anope::string timebuf; - if (ci->c) - for (Channel::ChanUserList::const_iterator cit = ci->c->users.begin(), cit_end = ci->c->users.end(); cit != cit_end; ++cit) + if (Channel *c = ci->GetChannel()) + for (Channel::ChanUserList::const_iterator cit = c->users.begin(), cit_end = c->users.end(); cit != cit_end; ++cit) { if (access->Matches(cit->second->user, cit->second->user->Account())) timebuf = "Now"; diff --git a/modules/chanserv/akick.cpp b/modules/chanserv/akick.cpp index d49a63ca5..9014ad9d6 100644 --- a/modules/chanserv/akick.cpp +++ b/modules/chanserv/akick.cpp @@ -209,9 +209,9 @@ class CommandCSAKick : public Command } /* Check excepts BEFORE we get this far */ - if (ci->c) + if (Channel *c = ci->GetChannel()) { - std::vector modes = ci->c->GetModeList("EXCEPT"); + std::vector modes = c->GetModeList("EXCEPT"); for (unsigned int i = 0; i < modes.size(); ++i) { if (Anope::Match(modes[i], mask)) @@ -510,7 +510,7 @@ class CommandCSAKick : public Command void DoEnforce(CommandSource &source, ChanServ::Channel *ci) { - Channel *c = ci->c; + Channel *c = ci->GetChannel(); int count = 0; if (!c) @@ -696,12 +696,13 @@ class CSAKick : public Module EventReturn OnCheckKick(User *u, Channel *c, Anope::string &mask, Anope::string &reason) override { - if (!c->ci || c->MatchesList(u, "EXCEPT")) + ChanServ::Channel *ci = c->GetChannel(); + if (!ci || c->MatchesList(u, "EXCEPT")) return EVENT_CONTINUE; - for (unsigned j = 0, end = c->ci->GetAkickCount(); j < end; ++j) + for (unsigned j = 0, end = ci->GetAkickCount(); j < end; ++j) { - AutoKick *ak = c->ci->GetAkick(j); + AutoKick *ak = ci->GetAkick(j); bool kick = false; if (ak->GetAccount()) diff --git a/modules/chanserv/ban.cpp b/modules/chanserv/ban.cpp index cd6b70b1f..4e8c0ded7 100644 --- a/modules/chanserv/ban.cpp +++ b/modules/chanserv/ban.cpp @@ -61,7 +61,7 @@ class CommandCSBan : public Command return; } - Channel *c = ci->c; + Channel *c = ci->GetChannel(); if (c == NULL) { source.Reply(_("Channel \002{0}\002 doesn't exist."), ci->GetName()); @@ -213,7 +213,7 @@ class CommandCSBan : public Command continue; if (u != uc->user && ci->IsPeace() && u2_access >= u_access) continue; - else if (ci->c->MatchesList(uc->user, "EXCEPT")) + else if (c->MatchesList(uc->user, "EXCEPT")) continue; else if (uc->user->IsProtected()) continue; diff --git a/modules/chanserv/clone.cpp b/modules/chanserv/clone.cpp index c0ed04a64..341d80944 100644 --- a/modules/chanserv/clone.cpp +++ b/modules/chanserv/clone.cpp @@ -101,27 +101,25 @@ public: target_ci->SetTimeRegistered(Anope::CurTime); ChanServ::registered_channel_map& map = ChanServ::service->GetChannels(); map[target_ci->GetName()] = target_ci; - target_ci->c = Channel::Find(target_ci->GetName()); + Channel *target_channel = Channel::Find(target_ci->GetName()); if (ci->GetBot()) ci->GetBot()->Assign(u, target_ci); else target_ci->SetBot(nullptr); - if (target_ci->c) + if (target_channel) { - target_ci->c->ci = target_ci; + target_channel->CheckModes(); - target_ci->c->CheckModes(); - - target_ci->c->SetCorrectModes(u, true); + target_channel->SetCorrectModes(u, true); } - if (target_ci->c && !target_ci->c->topic.empty()) + if (target_channel && !target_channel->topic.empty()) { target_ci->SetLastTopic(target_ci->GetLastTopic()); - target_ci->SetLastTopicSetter(target_ci->c->topic_setter); - target_ci->SetLastTopicTime(target_ci->c->topic_time); + target_ci->SetLastTopicSetter(target_channel->topic_setter); + target_ci->SetLastTopicTime(target_channel->topic_time); } else { diff --git a/modules/chanserv/drop.cpp b/modules/chanserv/drop.cpp index cd8718801..d85e5390d 100644 --- a/modules/chanserv/drop.cpp +++ b/modules/chanserv/drop.cpp @@ -65,7 +65,7 @@ class CommandCSDrop : public Command logger.Command(source, ci, _("{source} used {command} on {channel} (founder was: {0})"), ci->GetFounder() ? ci->GetFounder()->GetDisplay() : "none"); - Reference c = ci->c; + Reference c = ci->GetChannel(); ci->Delete(); source.Reply(_("Channel \002{0}\002 has been dropped."), chan); diff --git a/modules/chanserv/enforce.cpp b/modules/chanserv/enforce.cpp index 85649f662..c9ca14acf 100644 --- a/modules/chanserv/enforce.cpp +++ b/modules/chanserv/enforce.cpp @@ -34,11 +34,12 @@ class CommandCSEnforce : public Command bool hadsecureops = ci->IsSecureOps(); ci->SetSecureOps(true); - for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it) + Channel *c = ci->GetChannel(); + for (Channel::ChanUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ++it) { ChanUserContainer *uc = it->second; - ci->c->SetCorrectModes(uc->user, false); + c->SetCorrectModes(uc->user, false); } if (!hadsecureops) @@ -51,8 +52,9 @@ class CommandCSEnforce : public Command { logger.Command(source, ci, _("{source} used {command} on {channel} to enforce restricted")); + Channel *c = ci->GetChannel(); std::vector users; - for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it) + for (Channel::ChanUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ++it) { ChanUserContainer *uc = it->second; User *user = uc->user; @@ -70,8 +72,8 @@ class CommandCSEnforce : public Command Anope::string mask = ci->GetIdealBan(user); Anope::string reason = Language::Translate(user, _("RESTRICTED enforced by ")) + source.GetNick(); - ci->c->SetMode(NULL, "BAN", mask); - ci->c->Kick(NULL, user, reason); + c->SetMode(NULL, "BAN", mask); + c->Kick(NULL, user, reason); } source.Reply(_("\002Restricted\002 enforced on \002{0}\002."), ci->GetName()); @@ -81,8 +83,9 @@ class CommandCSEnforce : public Command { logger.Command(source, ci, _("{source} used {command} on {channel} to enforce registered only")); + Channel *c = ci->GetChannel(); std::vector users; - for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it) + for (Channel::ChanUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ++it) { ChanUserContainer *uc = it->second; User *user = uc->user; @@ -100,9 +103,9 @@ class CommandCSEnforce : public Command Anope::string mask = ci->GetIdealBan(user); Anope::string reason = Language::Translate(user, _("REGONLY enforced by ")) + source.GetNick(); - if (!ci->c->HasMode("REGISTEREDONLY")) - ci->c->SetMode(NULL, "BAN", mask); - ci->c->Kick(NULL, user, reason); + if (!c->HasMode("REGISTEREDONLY")) + c->SetMode(NULL, "BAN", mask); + c->Kick(NULL, user, reason); } source.Reply(_("\002Registered only\002 enforced on \002{0}\002."), ci->GetName()); @@ -112,8 +115,9 @@ class CommandCSEnforce : public Command { logger.Command(source, ci, _("{source} used {command} on {channel} to enforce SSL only")); + Channel *c = ci->GetChannel(); std::vector users; - for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it) + for (Channel::ChanUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ++it) { ChanUserContainer *uc = it->second; User *user = uc->user; @@ -131,9 +135,9 @@ class CommandCSEnforce : public Command Anope::string mask = ci->GetIdealBan(user); Anope::string reason = Language::Translate(user, _("SSLONLY enforced by ")) + source.GetNick(); - if (!ci->c->HasMode("SSL")) - ci->c->SetMode(NULL, "BAN", mask); - ci->c->Kick(NULL, user, reason); + if (!c->HasMode("SSL")) + c->SetMode(NULL, "BAN", mask); + c->Kick(NULL, user, reason); } source.Reply(_("\002SSL only\002 enforced on %s."), ci->GetName().c_str()); @@ -143,8 +147,9 @@ class CommandCSEnforce : public Command { logger.Command(source, ci, _("{source} used {command} on {channel} to enforce bans")); + Channel *c = ci->GetChannel(); std::vector users; - for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it) + for (Channel::ChanUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ++it) { ChanUserContainer *uc = it->second; User *user = uc->user; @@ -152,7 +157,7 @@ class CommandCSEnforce : public Command if (user->IsProtected()) continue; - if (ci->c->MatchesList(user, "BAN") && !ci->c->MatchesList(user, "EXCEPT")) + if (c->MatchesList(user, "BAN") && !c->MatchesList(user, "EXCEPT")) users.push_back(user); } @@ -161,7 +166,7 @@ class CommandCSEnforce : public Command User *user = users[i]; Anope::string reason = Language::Translate(user, _("BANS enforced by ")) + source.GetNick(); - ci->c->Kick(NULL, user, reason); + c->Kick(NULL, user, reason); } source.Reply(_("\002Bans\002 enforced on %s."), ci->GetName().c_str()); @@ -171,8 +176,9 @@ class CommandCSEnforce : public Command { logger.Command(source, ci, _("{source} used {command} on {channel} to enforce limit")); + Channel *c = ci->GetChannel(); Anope::string l_str; - if (!ci->c->GetParam("LIMIT", l_str)) + if (!c->GetParam("LIMIT", l_str)) { source.Reply(_("There is no limit is set on \002{0}\002."), ci->GetName()); return; @@ -193,7 +199,7 @@ class CommandCSEnforce : public Command std::vector users; /* The newer users are at the end of the list, so kick users starting from the end */ - for (Channel::ChanUserList::reverse_iterator it = ci->c->users.rbegin(), it_end = ci->c->users.rend(); it != it_end; ++it) + for (Channel::ChanUserList::reverse_iterator it = c->users.rbegin(), it_end = c->users.rend(); it != it_end; ++it) { ChanUserContainer *uc = it->second; User *user = uc->user; @@ -204,7 +210,7 @@ class CommandCSEnforce : public Command if (!ci->AccessFor(user).empty()) continue; - if (ci->c->users.size() - users.size() <= static_cast(l)) + if (c->users.size() - users.size() <= static_cast(l)) continue; users.push_back(user); @@ -215,7 +221,7 @@ class CommandCSEnforce : public Command User *user = users[i]; Anope::string reason = Language::Translate(user, _("LIMIT enforced by ")) + source.GetNick(); - ci->c->Kick(NULL, user, reason); + c->Kick(NULL, user, reason); } source.Reply(_("LIMIT enforced on \002{0}\002, \002{1]\002 users removed."), ci->GetName(), users.size()); @@ -240,7 +246,7 @@ class CommandCSEnforce : public Command return; } - if (!ci->c) + if (!ci->GetChannel()) { source.Reply(_("Channel \002{0}\002 doesn't exist."), ci->GetName()); return; diff --git a/modules/chanserv/entrymsg.cpp b/modules/chanserv/entrymsg.cpp index ec3f833fd..efcea8e9d 100644 --- a/modules/chanserv/entrymsg.cpp +++ b/modules/chanserv/entrymsg.cpp @@ -285,9 +285,10 @@ class CSEntryMessage : public Module void OnJoinChannel(User *u, Channel *c) override { - if (u && c && c->ci && u->server->IsSynced()) - for (EntryMsg *msg : c->ci->GetRefs()) - u->SendMessage(c->ci->WhoSends(), "[{0}] {1}", c->ci->GetName(), msg->GetMessage()); + ChanServ::Channel *ci = c->GetChannel(); + if (ci && u->server->IsSynced()) + for (EntryMsg *msg : ci->GetRefs()) + u->SendMessage(ci->WhoSends(), "[{0}] {1}", ci->GetName(), msg->GetMessage()); } }; diff --git a/modules/chanserv/getkey.cpp b/modules/chanserv/getkey.cpp index a1a3dd587..1f280ee52 100644 --- a/modules/chanserv/getkey.cpp +++ b/modules/chanserv/getkey.cpp @@ -46,7 +46,7 @@ class CommandCSGetKey : public Command } Anope::string key; - if (!ci->c || !ci->c->GetParam("KEY", key)) + if (!ci->GetChannel() || !ci->GetChannel()->GetParam("KEY", key)) { source.Reply(_("Channel \002{0}\002 does not have a key."), ci->GetName()); return; diff --git a/modules/chanserv/invite.cpp b/modules/chanserv/invite.cpp index 2f236b6c6..df8bee8f9 100644 --- a/modules/chanserv/invite.cpp +++ b/modules/chanserv/invite.cpp @@ -41,7 +41,7 @@ class CommandCSInvite : public Command return; } - ChanServ::Channel *ci = c->ci; + ChanServ::Channel *ci = c->GetChannel(); if (!ci) { source.Reply(_("Channel \002{0}\002 isn't registered."), c->name); diff --git a/modules/chanserv/list.cpp b/modules/chanserv/list.cpp index 6f9f06e60..1f89b0274 100644 --- a/modules/chanserv/list.cpp +++ b/modules/chanserv/list.cpp @@ -98,7 +98,7 @@ class CommandCSList : public Command { if (ci->IsPrivate() || ci->HasFieldS("CS_SUSPENDED")) continue; - if (ci->c && ci->c->HasMode("SECRET")) + if (ci->GetChannel() && ci->GetChannel()->HasMode("SECRET")) continue; if (mlocks) diff --git a/modules/chanserv/main/channel.cpp b/modules/chanserv/main/channel.cpp index a2d56b6ec..f4b0e2578 100644 --- a/modules/chanserv/main/channel.cpp +++ b/modules/chanserv/main/channel.cpp @@ -32,19 +32,13 @@ void ChannelImpl::Delete() Anope::Logger.Debug("Deleting channel {0}", this->GetName()); - if (this->c) + ::Channel *c = this->GetChannel(); + if (c) { - if (this->GetBot() && this->c->FindUser(this->GetBot())) - this->GetBot()->Part(this->c); - - /* Parting the service bot can cause the channel to go away */ - - if (this->c) + if (this->GetBot() && c->FindUser(this->GetBot())) { - if (this->c && this->c->CheckDelete()) - this->c->QueueForDeletion(); - - this->c = NULL; + this->GetBot()->Part(c); + c = nullptr; } } diff --git a/modules/chanserv/main/chanserv.cpp b/modules/chanserv/main/chanserv.cpp index 17716c3d4..2521ee22e 100644 --- a/modules/chanserv/main/chanserv.cpp +++ b/modules/chanserv/main/chanserv.cpp @@ -32,7 +32,6 @@ class ChanServCore : public Module , public ChanServ::ChanServService - , public EventHook , public EventHook , public EventHook , public EventHook @@ -61,7 +60,6 @@ class ChanServCore : public Module public: ChanServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR) , ChanServService(this) - , EventHook(this) , EventHook(this) , EventHook(this) , EventHook(this) @@ -115,15 +113,21 @@ class ChanServCore : public Module /** Constructor * @param chan The channel */ - ChanServTimer(Reference &cs, ExtensibleItem &i, Module *m, Channel *chan) : Timer(m, Config->GetModule(m)->Get("inhabit", "15s")), ChanServ(cs), inhabit(i), c(chan) + ChanServTimer(Reference &cs, ExtensibleItem &i, Module *m, Channel *chan) : Timer(m, Config->GetModule(m)->Get("inhabit", "15s")) + , ChanServ(cs) + , inhabit(i) + , c(chan) { if (!ChanServ || !c) return; + inhabit.Set(c, true); - if (!c->ci || !c->ci->GetBot()) + + ChanServ::Channel *ci = c->GetChannel(); + if (!ci || !ci->GetBot()) ChanServ->Join(c); - else if (!c->FindUser(c->ci->GetBot())) - c->ci->GetBot()->Join(c); + else if (!c->FindUser(ci->GetBot())) + ci->GetBot()->Join(c); /* Set +ntsi to prevent rejoin */ c->SetMode(NULL, "NOEXTERNAL"); @@ -146,14 +150,17 @@ class ChanServCore : public Module c->RemoveMode(NULL, "SECRET"); c->RemoveMode(NULL, "INVITE"); - if (!c->ci || !c->ci->GetBot()) + ChanServ::Channel *ci = c->GetChannel(); + if (!ci || !ci->GetBot()) { if (ChanServ) ChanServ->Part(c); } /* If someone has rejoined this channel in the meantime, don't part the bot */ else if (c->users.size() <= 1) - c->ci->GetBot()->Part(c); + { + ci->GetBot()->Part(c); + } } }; @@ -248,13 +255,6 @@ class ChanServCore : public Module defaults.clear(); } - void OnChannelCreate(Channel *c) override - { - c->ci = Find(c->name); - if (c->ci) - c->ci->c = c; - } - void OnBotDelete(ServiceBot *bi) override { if (bi == ChanServ) @@ -324,14 +324,15 @@ class ChanServCore : public Module void OnDelChan(ChanServ::Channel *ci) override { - if (ci->c) - { - ci->c->RemoveMode(ci->WhoSends(), "REGISTERED", "", false); + Channel *c = ci->GetChannel(); + if (c == nullptr) + return; - const Anope::string &require = Config->GetModule(this)->Get("require"); - if (!require.empty()) - ci->c->SetModes(ci->WhoSends(), false, "-%s", require.c_str()); - } + c->RemoveMode(ci->WhoSends(), "REGISTERED", "", false); + + const Anope::string &require = Config->GetModule(this)->Get("require"); + if (!require.empty()) + c->SetModes(ci->WhoSends(), false, "-%s", require.c_str()); } EventReturn OnPreHelp(CommandSource &source, const std::vector ¶ms) override @@ -371,7 +372,8 @@ class ChanServCore : public Module if (!c) return; - if (c->ci) + ChanServ::Channel *ci = c->GetChannel(); + if (ci) c->SetMode(nullptr, "REGISTERED", "", false); else c->RemoveMode(nullptr, "REGISTERED", "", false); @@ -379,7 +381,7 @@ class ChanServCore : public Module const Anope::string &require = Config->GetModule(this)->Get("require"); if (!require.empty()) { - if (c->ci) + if (ci) c->SetModes(nullptr, false, "+%s", require.c_str()); else c->SetModes(nullptr, false, "-%s", require.c_str()); @@ -396,7 +398,8 @@ class ChanServCore : public Module void OnChannelSync(Channel *c) override { - bool perm = c->HasMode("PERM") || (c->ci && c->ci->IsPersist()); + ChanServ::Channel *ci = c->GetChannel(); + bool perm = c->HasMode("PERM") || (ci && ci->IsPersist()); if (!perm && !c->botchannel && (c->users.empty() || (c->users.size() == 1 && c->users.begin()->second->user->server == Me))) { this->Hold(c); @@ -425,10 +428,11 @@ class ChanServCore : public Module if (Anope::CurTime - ci->GetLastUsed() >= chanserv_expire) { - if (ci->c) + Channel *c = ci->GetChannel(); + if (c) { time_t last_used = ci->GetLastUsed(); - for (Channel::ChanUserList::const_iterator cit = ci->c->users.begin(), cit_end = ci->c->users.end(); cit != cit_end && last_used == ci->GetLastUsed(); ++cit) + for (Channel::ChanUserList::const_iterator cit = c->users.begin(), cit_end = c->users.end(); cit != cit_end && last_used == ci->GetLastUsed(); ++cit) ci->AccessFor(cit->second->user); expire = last_used == ci->GetLastUsed(); } @@ -465,14 +469,14 @@ class ChanServCore : public Module { if (ci->IsPersist()) { - bool c; - ci->c = Channel::FindOrCreate(ci->GetName(), c, ci->GetTimeRegistered()); + bool created; + Channel *c = Channel::FindOrCreate(ci->GetName(), created, ci->GetTimeRegistered()); if (ModeManager::FindChannelModeByName("PERM") != NULL) { - if (c) - IRCD->Send(ci->c); - ci->c->SetMode(NULL, "PERM"); + if (created) + IRCD->Send(c); + c->SetMode(NULL, "PERM"); } else { @@ -483,12 +487,12 @@ class ChanServCore : public Module bi->Assign(nullptr, ci); } - if (ci->GetBot() != nullptr && ci->c->FindUser(ci->GetBot()) == nullptr) + if (ci->GetBot() != nullptr && c->FindUser(ci->GetBot()) == nullptr) { Anope::string botmodes = Config->GetModule("botserv/main")->Get("botmodes", Config->GetModule("chanserv/main")->Get("botmodes")); ChannelStatus status(botmodes); - ci->GetBot()->Join(ci->c, &status); + ci->GetBot()->Join(c, &status); } } } @@ -502,24 +506,26 @@ class ChanServCore : public Module for (unsigned i = 0; i < defaults.size(); ++i) ci->SetS(defaults[i].upper(), true); - if (!ci->c) + Channel *c = ci->GetChannel(); + if (!c) return; /* Mark the channel as persistent */ - if (ci->c->HasMode("PERM")) + if (c->HasMode("PERM")) ci->SetPersist(true); /* Persist may be in def cflags, set it here */ else if (ci->IsPersist()) - ci->c->SetMode(NULL, "PERM"); + c->SetMode(NULL, "PERM"); } void OnJoinChannel(User *u, Channel *c) override { - if (!c->ci) + ChanServ::Channel *ci = c->GetChannel(); + if (!ci) return; - time_t ts = c->ci->GetChannelTS(); + time_t ts = ci->GetChannelTS(); if (ts == 0) - ts = c->ci->GetTimeRegistered(); + ts = ci->GetTimeRegistered(); if (c->creation_time > ts) { diff --git a/modules/chanserv/mode.cpp b/modules/chanserv/mode.cpp index 686b97514..7d7f7c85d 100644 --- a/modules/chanserv/mode.cpp +++ b/modules/chanserv/mode.cpp @@ -270,7 +270,7 @@ class CommandCSMode : public Command return source.AccessFor(ci).HasPriv(cm->name + (self ? "ME" : "")); } - void DoLock(CommandSource &source, ChanServ::Channel *ci, const std::vector ¶ms) + void DoLock(CommandSource &source, ChanServ::Channel *ci, Channel *c, const std::vector ¶ms) { User *u = source.GetUser(); const Anope::string &subcommand = params[2]; @@ -340,7 +340,7 @@ class CommandCSMode : public Command break; } - if (cm->type == MODE_LIST && ci->c && IRCD->GetMaxListFor(ci->c) && ci->c->HasMode(cm->name) >= IRCD->GetMaxListFor(ci->c)) + if (cm->type == MODE_LIST && c && IRCD->GetMaxListFor(c) && c->HasMode(cm->name) >= IRCD->GetMaxListFor(c)) { source.Reply(_("List for mode \002{0}\002 is full."), cm->mchar); break; @@ -386,8 +386,8 @@ class CommandCSMode : public Command source.Reply(_("Nothing to do.")); } - if (ci->c) - ci->c->CheckModes(); + if (c) + c->CheckModes(); } else if (subcommand.equals_ci("DEL") && !param.empty()) { @@ -489,7 +489,7 @@ class CommandCSMode : public Command } } - void DoSet(CommandSource &source, ChanServ::Channel *ci, const std::vector ¶ms) + void DoSet(CommandSource &source, ChanServ::Channel *ci, Channel *c, const std::vector ¶ms) { User *u = source.GetUser(); @@ -512,7 +512,7 @@ class CommandCSMode : public Command case '*': if (adding == -1 || !has_access) break; - for (unsigned j = 0; j < ModeManager::GetChannelModes().size() && ci->c; ++j) + for (unsigned j = 0; j < ModeManager::GetChannelModes().size() && c; ++j) { ChannelMode *cm = ModeManager::GetChannelModes()[j]; @@ -521,9 +521,9 @@ class CommandCSMode : public Command if (cm->type == MODE_REGULAR || (!adding && cm->type == MODE_PARAM)) { if (adding) - ci->c->SetMode(NULL, cm); + c->SetMode(NULL, cm); else - ci->c->RemoveMode(NULL, cm); + c->RemoveMode(NULL, cm); } } } @@ -540,9 +540,9 @@ class CommandCSMode : public Command if (!has_access) break; if (adding) - ci->c->SetMode(NULL, cm); + c->SetMode(NULL, cm); else - ci->c->RemoveMode(NULL, cm); + c->RemoveMode(NULL, cm); break; case MODE_PARAM: if (!has_access) @@ -550,9 +550,9 @@ class CommandCSMode : public Command if (adding && !sep.GetToken(param)) break; if (adding) - ci->c->SetMode(NULL, cm, param); + c->SetMode(NULL, cm, param); else - ci->c->RemoveMode(NULL, cm); + c->RemoveMode(NULL, cm); break; case MODE_STATUS: { @@ -569,7 +569,7 @@ class CommandCSMode : public Command break; } - for (Channel::ChanUserList::const_iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it) + for (Channel::ChanUserList::const_iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ++it) { ChanUserContainer *uc = it->second; @@ -584,9 +584,9 @@ class CommandCSMode : public Command if (Anope::Match(uc->user->GetMask(), param)) { if (adding) - ci->c->SetMode(NULL, cm, uc->user->GetUID()); + c->SetMode(NULL, cm, uc->user->GetUID()); else - ci->c->RemoveMode(NULL, cm, uc->user->GetUID()); + c->RemoveMode(NULL, cm, uc->user->GetUID()); } } } @@ -622,9 +622,9 @@ class CommandCSMode : public Command } if (adding) - ci->c->SetMode(NULL, cm, target->GetUID()); + c->SetMode(NULL, cm, target->GetUID()); else - ci->c->RemoveMode(NULL, cm, target->GetUID()); + c->RemoveMode(NULL, cm, target->GetUID()); } break; } @@ -635,15 +635,15 @@ class CommandCSMode : public Command break; if (adding) { - if (IRCD->GetMaxListFor(ci->c) && ci->c->HasMode(cm->name) < IRCD->GetMaxListFor(ci->c)) - ci->c->SetMode(NULL, cm, param); + if (IRCD->GetMaxListFor(c) && c->HasMode(cm->name) < IRCD->GetMaxListFor(c)) + c->SetMode(NULL, cm, param); } else { - std::vector v = ci->c->GetModeList(cm->name); + std::vector v = c->GetModeList(cm->name); for (unsigned j = 0; j < v.size(); ++j) if (Anope::Match(v[j], param)) - ci->c->RemoveMode(NULL, cm, v[j]); + c->RemoveMode(NULL, cm, v[j]); } } } @@ -664,7 +664,7 @@ class CommandCSMode : public Command new_params.push_back(params[0]); new_params.push_back("SET"); new_params.push_back("-*"); - this->DoSet(source, ci, new_params); + this->DoSet(source, ci, ci->GetChannel(), new_params); return; } @@ -697,7 +697,7 @@ class CommandCSMode : public Command new_params.push_back("SET"); new_params.push_back("-" + stringify(cm->mchar)); new_params.push_back("*"); - this->DoSet(source, ci, new_params); + this->DoSet(source, ci, ci->GetChannel(), new_params); } public: @@ -721,6 +721,8 @@ class CommandCSMode : public Command return; } + Channel *c = ci->GetChannel(); + if (subcommand.equals_ci("LOCK") && params.size() > 2) { if (!source.AccessFor(ci).HasPriv("MODE") && !source.HasOverridePriv("chanserv/administration")) @@ -729,15 +731,19 @@ class CommandCSMode : public Command return; } - this->DoLock(source, ci, params); + this->DoLock(source, ci, c, params); + return; } - else if (!ci->c) + + if (!c) { source.Reply(_("Channel \002{0}\002 doesn't exist."), ci->GetName()); + return; } - else if (subcommand.equals_ci("SET") && params.size() > 2) + + if (subcommand.equals_ci("SET") && params.size() > 2) { - this->DoSet(source, ci, params); + this->DoSet(source, ci, c, params); } else if (subcommand.equals_ci("CLEAR")) { @@ -807,7 +813,8 @@ class CommandCSModes : public Command return; } - if (!ci->c) + Channel *c = ci->GetChannel(); + if (!c) { source.Reply(_("Channel \002%s\002 doesn't exist."), ci->GetName()); return; @@ -838,16 +845,16 @@ class CommandCSModes : public Command } } - if (!ci->c->FindUser(targ)) + if (!c->FindUser(targ)) { source.Reply(_("User \002{0}\002 is not on channel \002{1}\002."), targ->nick, ci->GetName()); return; } if (m.first) - ci->c->SetMode(NULL, m.second, targ->GetUID()); + c->SetMode(NULL, m.second, targ->GetUID()); else - ci->c->RemoveMode(NULL, m.second, targ->GetUID()); + c->RemoveMode(NULL, m.second, targ->GetUID()); logger.Command(source, ci, _("{source} used {command} on {channel} on {3}"), targ->nick); } @@ -935,10 +942,10 @@ class CSMode : public Module void OnCheckModes(Reference &c) override { - if (!c || !c->ci) + if (!c || !c->GetChannel()) return; - ModeLocks::ModeList locks = modelock.GetMLock(c->ci); + ModeLocks::ModeList locks = modelock.GetMLock(c->GetChannel()); for (ModeLock *ml : locks) { ChannelMode *cm = ModeManager::FindChannelModeByName(ml->GetName()); diff --git a/modules/chanserv/register.cpp b/modules/chanserv/register.cpp index de3e555bc..00fc00927 100644 --- a/modules/chanserv/register.cpp +++ b/modules/chanserv/register.cpp @@ -107,9 +107,6 @@ class CommandCSRegister : public Command ci->SetLastUsed(Anope::CurTime); ci->SetBanType(2); - ci->c = c; - c->ci = ci; - if (c && !c->topic.empty()) { ci->SetLastTopic(c->topic); diff --git a/modules/chanserv/set.cpp b/modules/chanserv/set.cpp index b35d3ae51..bab6da8bc 100644 --- a/modules/chanserv/set.cpp +++ b/modules/chanserv/set.cpp @@ -384,8 +384,8 @@ class CommandCSSetKeepModes : public Command ci->SetKeepModes(true); source.Reply(_("Keep modes for \002{0}\002 is now \002on\002."), ci->GetName()); - if (ci->c) - for (const std::pair &p : ci->c->GetModes()) + if (Channel *c = ci->GetChannel()) + for (const std::pair &p : c->GetModes()) { ChanServ::Mode *mode = Serialize::New(); mode->SetChannel(ci); @@ -538,10 +538,11 @@ class CommandCSSetPersist : public Command ci->SetPersist(true); /* Channel doesn't exist, create it */ - if (!ci->c) + Channel *c = ci->GetChannel(); + if (!c) { bool created; - Channel *c = Channel::FindOrCreate(ci->GetName(), created); + c = Channel::FindOrCreate(ci->GetName(), created); if (ci->GetBot()) { ChannelStatus status(BotModes()); @@ -554,8 +555,8 @@ class CommandCSSetPersist : public Command /* Set the perm mode */ if (cm) { - if (ci->c && !ci->c->HasMode("PERM")) - ci->c->SetMode(NULL, cm); + if (c && !c->HasMode("PERM")) + c->SetMode(NULL, cm); /* Add it to the channels mlock */ if (mlocks) mlocks->SetMLock(ci, cm, true, "", source.GetNick()); @@ -573,10 +574,10 @@ class CommandCSSetPersist : public Command } ChanServ->Assign(NULL, ci); - if (!ci->c->FindUser(ChanServ)) + if (!c->FindUser(ChanServ)) { ChannelStatus status(BotModes()); - ChanServ->Join(ci->c, &status); + ChanServ->Join(c, &status); } } } @@ -597,8 +598,9 @@ class CommandCSSetPersist : public Command /* Unset perm mode */ if (cm) { - if (ci->c && ci->c->HasMode("PERM")) - ci->c->RemoveMode(NULL, cm); + Channel *c = ci->GetChannel(); + if (c && c->HasMode("PERM")) + c->RemoveMode(NULL, cm); /* Remove from mlock */ if (mlocks) mlocks->RemoveMLock(ci, cm, true); @@ -1130,17 +1132,20 @@ class CSSet : public Module void OnChannelSync(Channel *c) override { - if (c->ci && c->ci->IsKeepModes()) - for (ChanServ::Mode *m : c->ci->GetRefs()) - c->SetMode(c->ci->WhoSends(), m->GetMode(), m->GetParam()); + ChanServ::Channel *ci = c->GetChannel(); + if (ci && ci->IsKeepModes()) + for (ChanServ::Mode *m : ci->GetRefs()) + c->SetMode(ci->WhoSends(), m->GetMode(), m->GetParam()); } EventReturn OnCheckKick(User *u, Channel *c, Anope::string &mask, Anope::string &reason) override { - if (!c->ci || !c->ci->IsRestricted() || c->MatchesList(u, "EXCEPT")) + ChanServ::Channel *ci = c->GetChannel(); + + if (!ci || !ci->IsRestricted() || c->MatchesList(u, "EXCEPT")) return EVENT_CONTINUE; - if (c->ci->AccessFor(u).empty() && (!c->ci->GetFounder() || u->Account() != c->ci->GetFounder())) + if (ci->AccessFor(u).empty() && (!ci->GetFounder() || u->Account() != ci->GetFounder())) return EVENT_STOP; return EVENT_CONTINUE; @@ -1148,30 +1153,32 @@ class CSSet : public Module void OnDelChan(ChanServ::Channel *ci) override { - if (ci->c && ci->IsPersist()) + Channel *c = ci->GetChannel(); + if (c && ci->IsPersist()) { - ci->c->RemoveMode(ci->WhoSends(), "PERM", "", false); + c->RemoveMode(ci->WhoSends(), "PERM", "", false); ci->SetPersist(false); } } EventReturn OnChannelModeSet(Channel *c, const MessageSource &setter, ChannelMode *mode, const Anope::string ¶m) override { - if (c->ci) - { - /* Channel mode +P or so was set, mark this channel as persistent */ - if (mode->name == "PERM") - c->ci->SetPersist(true); + ChanServ::Channel *ci = c->GetChannel(); + if (ci == nullptr) + return EVENT_CONTINUE; - if (mode->type != MODE_STATUS && !c->syncing && Me->IsSynced() && (!inhabit || !inhabit->HasExt(c))) + /* Channel mode +P or so was set, mark this channel as persistent */ + if (mode->name == "PERM") + ci->SetPersist(true); + + if (mode->type != MODE_STATUS && !c->syncing && Me->IsSynced() && (!inhabit || !inhabit->HasExt(c))) + { + ChanServ::Mode *m = Serialize::New(); + if (m != nullptr) { - ChanServ::Mode *m = Serialize::New(); - if (m != nullptr) - { - m->SetChannel(c->ci); - m->SetMode(mode->name); - m->SetParam(param); - } + m->SetChannel(ci); + m->SetMode(mode->name); + m->SetParam(param); } } @@ -1180,14 +1187,16 @@ class CSSet : public Module EventReturn OnChannelModeUnset(Channel *c, const MessageSource &setter, ChannelMode *mode, const Anope::string ¶m) override { + ChanServ::Channel *ci = c->GetChannel(); + if (mode->name == "PERM") { - if (c->ci) - c->ci->SetPersist(false); + if (ci) + ci->SetPersist(false); } - if (c->ci && mode->type != MODE_STATUS && !c->syncing && Me->IsSynced() && (!inhabit || !inhabit->HasExt(c))) - for (ChanServ::Mode *m : c->ci->GetRefs()) + if (ci && mode->type != MODE_STATUS && !c->syncing && Me->IsSynced() && (!inhabit || !inhabit->HasExt(c))) + for (ChanServ::Mode *m : ci->GetRefs()) if (m->GetMode() == mode->name && m->GetParam().equals_ci(param)) m->Delete(); @@ -1196,10 +1205,12 @@ class CSSet : public Module void OnJoinChannel(User *u, Channel *c) override { - if (persist_lower_ts && c->ci && c->ci->IsPersist() && c->creation_time > c->ci->GetTimeRegistered()) + ChanServ::Channel *ci = c->GetChannel(); + + if (persist_lower_ts && ci && ci->IsPersist() && c->creation_time > ci->GetTimeRegistered()) { - logger.Debug("Changing TS of {0} from {1} to {2}", c->name, c->creation_time, c->ci->GetTimeRegistered()); - c->creation_time = c->ci->GetTimeRegistered(); + logger.Debug("Changing TS of {0} from {1} to {2}", c->name, c->creation_time, ci->GetTimeRegistered()); + c->creation_time = ci->GetTimeRegistered(); IRCD->Send(c); c->Reset(); } @@ -1207,14 +1218,15 @@ class CSSet : public Module void OnSetCorrectModes(User *user, Channel *chan, ChanServ::AccessGroup &access, bool &give_modes, bool &take_modes) override { - if (chan->ci) - { - if (chan->ci->IsNoAutoop()) - give_modes = false; - if (chan->ci->IsSecureOps() && !user->HasPriv("chanserv/administration")) - // This overrides what chanserv does because it is loaded after chanserv - take_modes = true; - } + ChanServ::Channel *ci = chan->GetChannel(); + if (ci == nullptr) + return; + + if (ci->IsNoAutoop()) + give_modes = false; + if (ci->IsSecureOps() && !user->HasPriv("chanserv/administration")) + // This overrides what chanserv does because it is loaded after chanserv + take_modes = true; } void OnPreChanExpire(ChanServ::Channel *ci, bool &expire) override diff --git a/modules/chanserv/statusupdate.cpp b/modules/chanserv/statusupdate.cpp index 32918f1d3..90586daea 100644 --- a/modules/chanserv/statusupdate.cpp +++ b/modules/chanserv/statusupdate.cpp @@ -25,10 +25,11 @@ class StatusUpdate : public Module { void ApplyModes(ChanServ::Channel *ci, ChanServ::ChanAccess *access, bool set) { - if (ci->c == nullptr) + Channel *c = ci->GetChannel(); + if (c == nullptr) return; - for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it) + for (Channel::ChanUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ++it) { User *user = it->second->user; @@ -40,11 +41,11 @@ class StatusUpdate : public Module { ChannelModeStatus *cms = ModeManager::GetStatusChannelModesByRank()[i]; if (!ag.HasPriv("AUTO" + cms->name)) - ci->c->RemoveMode(NULL, cms, user->GetUID()); + c->RemoveMode(NULL, cms, user->GetUID()); } if (set) - ci->c->SetCorrectModes(user, true); + c->SetCorrectModes(user, true); } } } diff --git a/modules/chanserv/suspend.cpp b/modules/chanserv/suspend.cpp index e730ddf49..2d72924e3 100644 --- a/modules/chanserv/suspend.cpp +++ b/modules/chanserv/suspend.cpp @@ -173,11 +173,11 @@ class CommandCSSuspend : public Command si->SetWhen(Anope::CurTime); si->SetExpires(expiry_secs ? expiry_secs + Anope::CurTime : 0); - if (ci->c) + if (Channel *c = ci->GetChannel()) { std::vector users; - for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it) + for (Channel::ChanUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ++it) { ChanUserContainer *uc = it->second; User *user = uc->user; @@ -186,7 +186,7 @@ class CommandCSSuspend : public Command } for (unsigned i = 0; i < users.size(); ++i) - ci->c->Kick(NULL, users[i], !reason.empty() ? reason : Language::Translate(users[i], _("This channel has been suspended."))); + c->Kick(NULL, users[i], !reason.empty() ? reason : Language::Translate(users[i], _("This channel has been suspended."))); } logger.Admin(source, ci, _("{source} used {command} on {channel} ({0}), expires on {1}"), @@ -329,7 +329,8 @@ class CSSuspend : public Module EventReturn OnCheckKick(User *u, Channel *c, Anope::string &mask, Anope::string &reason) override { - if (u->HasMode("OPER") || !c->ci || !c->ci->GetRef()) + ChanServ::Channel *ci = c->GetChannel(); + if (u->HasMode("OPER") || !ci || !ci->GetRef()) return EVENT_CONTINUE; reason = Language::Translate(u, _("This channel may not be used.")); diff --git a/modules/chanserv/sync.cpp b/modules/chanserv/sync.cpp index 117003577..0ff7ebdd0 100644 --- a/modules/chanserv/sync.cpp +++ b/modules/chanserv/sync.cpp @@ -39,7 +39,8 @@ class CommandCSSync : public Command return; } - if (ci->c == NULL) + Channel *c = ci->GetChannel(); + if (c == nullptr) { source.Reply(_("Channel \002{0}\002 doesn't exist."), ci->GetName()); return; @@ -53,8 +54,8 @@ class CommandCSSync : public Command logger.Command(source, ci, _("{source} used {command} on {channel}")); - for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it) - ci->c->SetCorrectModes(it->second->user, true); + for (Channel::ChanUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ++it) + c->SetCorrectModes(it->second->user, true); source.Reply(_("All user modes on \002{0}\002 have been synced.")); } diff --git a/modules/chanserv/topic.cpp b/modules/chanserv/topic.cpp index 93c990507..85bcf1426 100644 --- a/modules/chanserv/topic.cpp +++ b/modules/chanserv/topic.cpp @@ -129,7 +129,7 @@ class CommandCSTopic : public Command { bool has_topiclock = ci->IsTopicLock(); ci->SetTopicLock(false); - ci->c->ChangeTopic(source.GetNick(), topic, Anope::CurTime); + ci->GetChannel()->ChangeTopic(source.GetNick(), topic, Anope::CurTime); if (has_topiclock) ci->SetTopicLock(true); @@ -144,9 +144,9 @@ class CommandCSTopic : public Command const Anope::string &topic = params[2]; Anope::string new_topic; - if (!ci->c->topic.empty()) + if (!ci->GetChannel()->topic.empty()) { - new_topic = ci->c->topic + " " + topic; + new_topic = ci->GetChannel()->topic + " " + topic; ci->SetLastTopic(""); } else @@ -192,7 +192,7 @@ class CommandCSTopic : public Command { this->Unlock(source, ci, params); } - else if (!ci->c) + else if (!ci->GetChannel()) { source.Reply(_("Channel \002{0}\002 doesn't exist."), ci->GetName()); } @@ -256,21 +256,23 @@ class CSTopic : public Module void OnChannelSync(Channel *c) override { - if (c->ci) + ChanServ::Channel *ci = c->GetChannel(); + if (!ci) + return; + + /* Update channel topic */ + if ((ci->IsTopicLock() || ci->IsKeepTopic()) && ci->GetLastTopic() != c->topic) { - /* Update channel topic */ - if ((c->ci->IsTopicLock() || c->ci->IsKeepTopic()) && c->ci->GetLastTopic() != c->topic) - { - ServiceBot *sender = c->ci->WhoSends(); - c->ChangeTopic(!c->ci->GetLastTopicSetter().empty() ? c->ci->GetLastTopicSetter() : (sender ? sender->nick : Me->GetName()), - c->ci->GetLastTopic(), c->ci->GetLastTopicTime() ? c->ci->GetLastTopicTime() : Anope::CurTime); - } + ServiceBot *sender = ci->WhoSends(); + c->ChangeTopic(!ci->GetLastTopicSetter().empty() ? ci->GetLastTopicSetter() : (sender ? sender->nick : Me->GetName()), + ci->GetLastTopic(), ci->GetLastTopicTime() ? ci->GetLastTopicTime() : Anope::CurTime); } } void OnTopicUpdated(User *source, Channel *c, const Anope::string &user, const Anope::string &topic) override { - if (!c->ci) + ChanServ::Channel *ci = c->GetChannel(); + if (!ci) return; /* We only compare the topics here, not the time or setter. This is because some (old) IRCds do not @@ -278,15 +280,15 @@ class CSTopic : public Module * This desyncs what is really set with what we have stored, and we end up resetting the topic often when * it is not required */ - if (c->ci->IsTopicLock() && c->ci->GetLastTopic() != c->topic && (!source || !c->ci->AccessFor(source).HasPriv("TOPIC"))) + if (ci->IsTopicLock() && ci->GetLastTopic() != c->topic && (!source || !ci->AccessFor(source).HasPriv("TOPIC"))) { - c->ChangeTopic(c->ci->GetLastTopicSetter(), c->ci->GetLastTopic(), c->ci->GetLastTopicTime()); + c->ChangeTopic(ci->GetLastTopicSetter(), ci->GetLastTopic(), ci->GetLastTopicTime()); } else { - c->ci->SetLastTopic(c->topic); - c->ci->SetLastTopicSetter(c->topic_setter); - c->ci->SetLastTopicTime(c->topic_ts); + ci->SetLastTopic(c->topic); + ci->SetLastTopicSetter(c->topic_setter); + ci->SetLastTopicTime(c->topic_ts); } } @@ -298,7 +300,8 @@ class CSTopic : public Module info.AddOption(_("Topic lock")); ModeLock *secret = mlocks ? mlocks->GetMLock(ci, "SECRET") : nullptr; - if (!ci->GetLastTopic().empty() && (show_all || ((!secret || secret->GetSet() == false) && (!ci->c || !ci->c->HasMode("SECRET"))))) + Channel *c = ci->GetChannel(); + if (!ci->GetLastTopic().empty() && (show_all || ((!secret || secret->GetSet() == false) && (!c || !c->HasMode("SECRET"))))) { info[_("Last topic")] = ci->GetLastTopic(); info[_("Topic set by")] = ci->GetLastTopicSetter(); diff --git a/modules/chanserv/unban.cpp b/modules/chanserv/unban.cpp index 56d13758d..716b2f576 100644 --- a/modules/chanserv/unban.cpp +++ b/modules/chanserv/unban.cpp @@ -46,11 +46,11 @@ class CommandCSUnban : public Command for (ChanServ::Channel *ci : source.GetAccount()->GetRefs()) { - if (!ci->c || !source.AccessFor(ci).HasPriv("UNBAN")) + if (!ci->GetChannel() || !source.AccessFor(ci).HasPriv("UNBAN")) continue; for (unsigned int j = 0; j < modes.size(); ++j) - if (ci->c->Unban(source.GetUser(), modes[j]->name, true)) + if (ci->GetChannel()->Unban(source.GetUser(), modes[j]->name, true)) ++count; } @@ -68,7 +68,7 @@ class CommandCSUnban : public Command return; } - if (ci->c == NULL) + if (ci->GetChannel() == NULL) { source.Reply(_("Channel \002{0}\002 doesn't exist."), ci->GetName()); return; @@ -94,12 +94,12 @@ class CommandCSUnban : public Command logger.Command(source, _("{source} used {command} on {channel} to unban {0}"), u2->nick); for (unsigned i = 0; i < modes.size(); ++i) - ci->c->Unban(u2, modes[i]->name, source.GetUser() == u2); + ci->GetChannel()->Unban(u2, modes[i]->name, source.GetUser() == u2); if (u2 == source.GetUser()) - source.Reply(_("You have been unbanned from \002{0}\002."), ci->c->name); + source.Reply(_("You have been unbanned from \002{0}\002."), ci->GetChannel()->name); else - source.Reply(_("\002{0}\002 has been unbanned from \002{1}\002."), u2->nick, ci->c->name); + source.Reply(_("\002{0}\002 has been unbanned from \002{1}\002."), u2->nick, ci->GetChannel()->name); } bool OnHelp(CommandSource &source, const Anope::string &subcommand) override diff --git a/modules/chanserv/updown.cpp b/modules/chanserv/updown.cpp index 0909fa35c..44dd9dc55 100644 --- a/modules/chanserv/updown.cpp +++ b/modules/chanserv/updown.cpp @@ -23,14 +23,15 @@ class CommandCSUp : public Command { void SetModes(User *u, Channel *c) { - if (!c->ci) + ChanServ::Channel *ci = c->GetChannel(); + if (!ci) return; /* whether or not we are giving modes */ bool giving = true; /* whether or not we have given a mode */ bool given = false; - ChanServ::AccessGroup u_access = c->ci->AccessFor(u); + ChanServ::AccessGroup u_access = ci->AccessFor(u); for (unsigned i = 0; i < ModeManager::GetStatusChannelModesByRank().size(); ++i) { @@ -83,7 +84,8 @@ class CommandCSUp : public Command return; } - if (ci->c == NULL) + Channel *c = ci->GetChannel(); + if (c == nullptr) { source.Reply(_("Channel \002{0}\002 doesn't exist."), ci->GetName()); return; @@ -91,7 +93,6 @@ class CommandCSUp : public Command User *u = User::Find(nick, true); User *srcu = source.GetUser(); - Channel *c = ci->c; if (u == NULL) { @@ -111,9 +112,9 @@ class CommandCSUp : public Command return; } - if (source.GetUser() && u != source.GetUser() && c->ci->IsPeace()) + if (source.GetUser() && u != source.GetUser() && ci->IsPeace()) { - if (c->ci->AccessFor(u) >= c->ci->AccessFor(source.GetUser())) + if (ci->AccessFor(u) >= ci->AccessFor(source.GetUser())) { if (!source.HasOverridePriv("chanserv/administration")) { @@ -179,15 +180,14 @@ class CommandCSDown : public Command return; } - if (ci->c == NULL) + Channel *c = ci->GetChannel(); + if (c == nullptr) { source.Reply(_("Channel \002{0}\002 doesn't exist."), ci->GetName()); return; } User *u = User::Find(nick, true); - Channel *c = ci->c; - User *srcu = source.GetUser(); if (u == NULL) @@ -208,9 +208,9 @@ class CommandCSDown : public Command return; } - if (source.GetUser() && u != source.GetUser() && c->ci->IsPeace()) + if (source.GetUser() && u != source.GetUser() && ci->IsPeace()) { - if (c->ci->AccessFor(u) >= c->ci->AccessFor(source.GetUser())) + if (ci->AccessFor(u) >= ci->AccessFor(source.GetUser())) { if (!source.HasPriv("chanserv/administration")) { diff --git a/modules/database/old.cpp b/modules/database/old.cpp index 80e179637..c647cb4e8 100644 --- a/modules/database/old.cpp +++ b/modules/database/old.cpp @@ -1465,8 +1465,8 @@ class DBOld : public Module mlock_limit.Unset(ci); mlock_key.Unset(ci); - if (ci->c) - ci->c->CheckModes(); + if (ci->GetChannel()) + ci->GetChannel()->CheckModes(); } } }; diff --git a/modules/fantasy.cpp b/modules/fantasy.cpp index 9c6a50664..e3556716c 100644 --- a/modules/fantasy.cpp +++ b/modules/fantasy.cpp @@ -106,10 +106,12 @@ class Fantasy : public Module void OnPrivmsg(User *u, Channel *c, Anope::string &msg) override { - if (!u || !c || !c->ci || !c->ci->GetBot() || msg.empty() || msg[0] == '\1') + if (!u || !c || !c->GetChannel() || !c->GetChannel()->GetBot() || msg.empty() || msg[0] == '\1') return; - if (Config->GetClient("BotServ") && !c->ci->IsFantasy()) + ChanServ::Channel *ci = c->GetChannel(); + + if (Config->GetClient("BotServ") && !ci->IsFantasy()) return; std::vector params; @@ -121,7 +123,7 @@ class Fantasy : public Module Anope::string normalized_param0 = Anope::NormalizeBuffer(params[0]); Anope::string fantasy_chars = Config->GetModule(this)->Get("fantasycharacter", "!"); - if (!normalized_param0.find(c->ci->GetBot()->nick)) + if (!normalized_param0.find(ci->GetBot()->nick)) { params.erase(params.begin()); } @@ -185,21 +187,21 @@ class Fantasy : public Module if (params.size() < cmd->min_params) return; - CommandSource source(u->nick, u, u->Account(), u, c->ci->GetBot()); + CommandSource source(u->nick, u, u->Account(), u, ci->GetBot()); source.c = c; source.SetCommandInfo(info); - ChanServ::AccessGroup ag = c->ci->AccessFor(u); + ChanServ::AccessGroup ag = ci->AccessFor(u); bool has_fantasia = ag.HasPriv("FANTASIA") || source.HasPriv("botserv/fantasy"); EventReturn MOD_RESULT; if (has_fantasia) { - MOD_RESULT = EventManager::Get()->Dispatch(&Event::BotFantasy::OnBotFantasy, source, cmd, c->ci, params); + MOD_RESULT = EventManager::Get()->Dispatch(&Event::BotFantasy::OnBotFantasy, source, cmd, ci, params); } else { - MOD_RESULT = EventManager::Get()->Dispatch(&Event::BotNoFantasyAccess::OnBotNoFantasyAccess, source, cmd, c->ci, params); + MOD_RESULT = EventManager::Get()->Dispatch(&Event::BotNoFantasyAccess::OnBotNoFantasyAccess, source, cmd, ci, params); } if (MOD_RESULT == EVENT_STOP || !has_fantasia) diff --git a/modules/greet.cpp b/modules/greet.cpp index 2c1531dc1..e4026825b 100644 --- a/modules/greet.cpp +++ b/modules/greet.cpp @@ -190,14 +190,15 @@ class Greet : public Module * to has synced, or we'll get greet-floods when the net * recovers from a netsplit. -GD */ - if (!c->ci || !c->ci->GetBot() || !user->server->IsSynced() || !user->Account()) + ChanServ::Channel *ci = c->GetChannel(); + if (!ci || !ci->GetBot() || !user->server->IsSynced() || !user->Account()) return; Anope::string greet = user->Account()->GetGreet(); - if (c->ci->IsGreet() && !greet.empty() && c->FindUser(c->ci->GetBot()) && c->ci->AccessFor(user).HasPriv("GREET")) + if (ci->IsGreet() && !greet.empty() && c->FindUser(ci->GetBot()) && ci->AccessFor(user).HasPriv("GREET")) { - IRCD->SendPrivmsg(c->ci->GetBot(), c->name, "[{0}] {1}", user->Account()->GetDisplay(), greet); - c->ci->GetBot()->lastmsg = Anope::CurTime; + IRCD->SendPrivmsg(ci->GetBot(), c->name, "[{0}] {1}", user->Account()->GetDisplay(), greet); + ci->GetBot()->lastmsg = Anope::CurTime; } } diff --git a/modules/helpchan.cpp b/modules/helpchan.cpp index 08a5d22d1..947fbe1d5 100644 --- a/modules/helpchan.cpp +++ b/modules/helpchan.cpp @@ -30,11 +30,11 @@ class HelpChannel : public Module EventReturn OnChannelModeSet(Channel *c, const MessageSource &, ChannelMode *mode, const Anope::string ¶m) override { - if (mode->name == "OP" && c && c->ci && c->name.equals_ci(Config->GetModule(this)->Get("helpchannel"))) + if (mode->name == "OP" && c && c->GetChannel() && c->name.equals_ci(Config->GetModule(this)->Get("helpchannel"))) { User *u = User::Find(param); - if (u && c->ci->AccessFor(u).HasPriv("OPME")) + if (u && c->GetChannel()->AccessFor(u).HasPriv("OPME")) u->SetMode(Config->GetClient("OperServ"), "HELPOP"); } diff --git a/modules/memoserv/main/memoserv.cpp b/modules/memoserv/main/memoserv.cpp index 3cea9100e..5de40526e 100644 --- a/modules/memoserv/main/memoserv.cpp +++ b/modules/memoserv/main/memoserv.cpp @@ -135,10 +135,11 @@ class MemoServCore : public Module, public MemoServ::MemoServService if (ischan) { ChanServ::Channel *ci = ChanServ::Find(target); + Channel *c = ci->GetChannel(); - if (ci->c) + if (c) { - for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it) + for (Channel::ChanUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ++it) { ChanUserContainer *cu = it->second; @@ -273,12 +274,13 @@ class MemoServCore : public Module, public MemoServ::MemoServService void OnJoinChannel(User *u, Channel *c) override { - if (u->server && u->server->IsSynced() && c->ci && c->ci->GetMemos() && !c->ci->GetMemos()->GetMemos().empty() && c->ci->AccessFor(u).HasPriv("MEMO")) + ChanServ::Channel *ci = c->GetChannel(); + if (u->server && u->server->IsSynced() && ci && ci->GetMemos() && !ci->GetMemos()->GetMemos().empty() && ci->AccessFor(u).HasPriv("MEMO")) { - if (c->ci->GetMemos()->GetMemos().size() == 1) - u->SendMessage(*MemoServ, _("There is \002{0}\002 memo on channel \002{1}\002."), c->ci->GetMemos()->GetMemos().size(), c->ci->GetName()); + if (ci->GetMemos()->GetMemos().size() == 1) + u->SendMessage(*MemoServ, _("There is \002{0}\002 memo on channel \002{1}\002."), ci->GetMemos()->GetMemos().size(), ci->GetName()); else - u->SendMessage(*MemoServ, _("There are \002{0}\002 memos on channel \002{1}\002."), c->ci->GetMemos()->GetMemos().size(), c->ci->GetName()); + u->SendMessage(*MemoServ, _("There are \002{0}\002 memos on channel \002{1}\002."), ci->GetMemos()->GetMemos().size(), ci->GetName()); } } diff --git a/modules/nickserv/ajoin.cpp b/modules/nickserv/ajoin.cpp index d7689205d..79ca271c3 100644 --- a/modules/nickserv/ajoin.cpp +++ b/modules/nickserv/ajoin.cpp @@ -321,12 +321,7 @@ class NSAJoin : public Module for (AutoJoin *entry : channels) { Channel *c = Channel::Find(entry->GetChannel()); - ChanServ::Channel *ci; - - if (c) - ci = c->ci; - else - ci = ChanServ::Find(entry->GetChannel()); + ChanServ::Channel *ci = ChanServ::Find(entry->GetChannel()); bool need_invite = false; Anope::string key = entry->GetKey(); diff --git a/modules/nickserv/set.cpp b/modules/nickserv/set.cpp index 33882f110..31c41c7ad 100644 --- a/modules/nickserv/set.cpp +++ b/modules/nickserv/set.cpp @@ -1118,7 +1118,7 @@ class NSSet : public Module void OnSetCorrectModes(User *user, Channel *chan, ChanServ::AccessGroup &access, bool &give_modes, bool &take_modes) override { - if (chan->ci) + if (chan->GetChannel()) { /* Only give modes if autoop is set */ give_modes &= !user->Account() || user->Account()->IsAutoOp(); diff --git a/modules/protocol/charybdis.cpp b/modules/protocol/charybdis.cpp index 028babe73..adb8b0a54 100644 --- a/modules/protocol/charybdis.cpp +++ b/modules/protocol/charybdis.cpp @@ -409,13 +409,14 @@ class ProtoCharybdis : public Module void OnChannelSync(Channel *c) override { - if (!c->ci || !mlocks) + ChanServ::Channel *ci = c->GetChannel(); + if (!ci || !mlocks) return; if (use_server_side_mlock && Servers::Capab.count("MLOCK") > 0) { - Anope::string modes = mlocks->GetMLockAsString(c->ci, false).replace_all_cs("+", "").replace_all_cs("-", ""); - Uplink::Send(Me, "MLOCK", c->creation_time, c->ci->GetName(), modes); + Anope::string modes = mlocks->GetMLockAsString(ci, false).replace_all_cs("+", "").replace_all_cs("-", ""); + Uplink::Send(Me, "MLOCK", c->creation_time, ci->GetName(), modes); } } @@ -424,11 +425,12 @@ class ProtoCharybdis : public Module if (!mlocks) return EVENT_CONTINUE; + Channel *c = ci->GetChannel(); ChannelMode *cm = ModeManager::FindChannelModeByName(lock->GetName()); - if (use_server_side_mlock && cm && ci->c && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM) && Servers::Capab.count("MLOCK") > 0) + if (use_server_side_mlock && cm && c && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM) && Servers::Capab.count("MLOCK") > 0) { Anope::string modes = mlocks->GetMLockAsString(ci, false).replace_all_cs("+", "").replace_all_cs("-", "") + cm->mchar; - Uplink::Send(Me, "MLOCK", ci->c->creation_time, ci->GetName(), modes); + Uplink::Send(Me, "MLOCK", c->creation_time, ci->GetName(), modes); } return EVENT_CONTINUE; @@ -439,11 +441,12 @@ class ProtoCharybdis : public Module if (!mlocks) return EVENT_CONTINUE; + Channel *c = ci->GetChannel(); ChannelMode *cm = ModeManager::FindChannelModeByName(lock->GetName()); - if (use_server_side_mlock && cm && ci->c && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM) && Servers::Capab.count("MLOCK") > 0) + if (use_server_side_mlock && cm && c && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM) && Servers::Capab.count("MLOCK") > 0) { Anope::string modes = mlocks->GetMLockAsString(ci, false).replace_all_cs("+", "").replace_all_cs("-", "").replace_all_cs(cm->mchar, ""); - Uplink::Send(Me, "MLOCK", ci->c->creation_time, ci->GetName(), modes); + Uplink::Send(Me, "MLOCK", c->creation_time, ci->GetName(), modes); } return EVENT_CONTINUE; diff --git a/modules/protocol/inspircd20.cpp b/modules/protocol/inspircd20.cpp index 96ada4666..6baebb34c 100644 --- a/modules/protocol/inspircd20.cpp +++ b/modules/protocol/inspircd20.cpp @@ -990,26 +990,30 @@ void inspircd20::Metadata::Run(MessageSource &source, const std::vectorIsSynced())) { Channel *c = Channel::Find(params[0]); - if (c && c->ci) + if (c == nullptr) + return; + + ChanServ::Channel *ci = c->GetChannel(); + if (ci == nullptr) + return; + + if ((do_mlock) && (params[1] == "mlock")) { - if ((do_mlock) && (params[1] == "mlock")) - { - ModeLocks *modelocks = c->ci->GetExt("modelocks"); - Anope::string modes; - if (modelocks) - modes = modelocks->GetMLockAsString(c->ci, false).replace_all_cs("+", "").replace_all_cs("-", ""); - - // Mode lock string is not what we say it is? - if (modes != params[2]) - Uplink::Send(Me, "METADATA", c->name, "mlock", modes); - } - else if ((do_topiclock) && (params[1] == "topiclock")) - { - bool mystate = c->ci->IsTopicLock(); - bool serverstate = (params[2] == "1"); - if (mystate != serverstate) - Uplink::Send(Me, "METADATA", c->name, "topiclock", mystate ? "1" : ""); - } + ModeLocks *modelocks = ci->GetExt("modelocks"); + Anope::string modes; + if (modelocks) + modes = modelocks->GetMLockAsString(ci, false).replace_all_cs("+", "").replace_all_cs("-", ""); + + // Mode lock string is not what we say it is? + if (modes != params[2]) + Uplink::Send(Me, "METADATA", c->name, "mlock", modes); + } + else if ((do_topiclock) && (params[1] == "topiclock")) + { + bool mystate = ci->IsTopicLock(); + bool serverstate = (params[2] == "1"); + if (mystate != serverstate) + Uplink::Send(Me, "METADATA", c->name, "topiclock", mystate ? "1" : ""); } } else if (params[0] == "*") @@ -1495,41 +1499,45 @@ class ProtoInspIRCd20 : public Module void OnChannelSync(Channel *c) override { - if (c->ci) - this->OnChanRegistered(c->ci); + ChanServ::Channel *ci = c->GetChannel(); + if (ci) + this->OnChanRegistered(ci); } void OnChanRegistered(ChanServ::Channel *ci) override { - if (use_server_side_mlock && ci->c && mlocks && !mlocks->GetMLockAsString(ci, false).empty()) + Channel *c = ci->GetChannel(); + if (use_server_side_mlock && c && mlocks && !mlocks->GetMLockAsString(ci, false).empty()) { Anope::string modes = mlocks->GetMLockAsString(ci, false).replace_all_cs("+", "").replace_all_cs("-", ""); - SendChannelMetadata(ci->c, "mlock", modes); + SendChannelMetadata(c, "mlock", modes); } - if (use_server_side_topiclock && Servers::Capab.count("TOPICLOCK") && ci->c) + if (use_server_side_topiclock && Servers::Capab.count("TOPICLOCK") && c) { if (ci->IsTopicLock()) - SendChannelMetadata(ci->c, "topiclock", "1"); + SendChannelMetadata(c, "topiclock", "1"); } } void OnDelChan(ChanServ::Channel *ci) override { - if (use_server_side_mlock && ci->c) - SendChannelMetadata(ci->c, "mlock", ""); + Channel *c = ci->GetChannel(); + if (use_server_side_mlock && c) + SendChannelMetadata(c, "mlock", ""); - if (use_server_side_topiclock && Servers::Capab.count("TOPICLOCK") && ci->c) - SendChannelMetadata(ci->c, "topiclock", ""); + if (use_server_side_topiclock && Servers::Capab.count("TOPICLOCK") && c) + SendChannelMetadata(c, "topiclock", ""); } EventReturn OnMLock(ChanServ::Channel *ci, ModeLock *lock) override { + Channel *c = ci->GetChannel(); ChannelMode *cm = ModeManager::FindChannelModeByName(lock->GetName()); - if (use_server_side_mlock && cm && ci->c && mlocks && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM)) + if (use_server_side_mlock && cm && c && mlocks && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM)) { Anope::string modes = mlocks->GetMLockAsString(ci, false).replace_all_cs("+", "").replace_all_cs("-", "") + cm->mchar; - SendChannelMetadata(ci->c, "mlock", modes); + SendChannelMetadata(c, "mlock", modes); } return EVENT_CONTINUE; @@ -1537,11 +1545,12 @@ class ProtoInspIRCd20 : public Module EventReturn OnUnMLock(ChanServ::Channel *ci, ModeLock *lock) override { + Channel *c = ci->GetChannel(); ChannelMode *cm = ModeManager::FindChannelModeByName(lock->GetName()); - if (use_server_side_mlock && cm && ci->c && mlocks && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM)) + if (use_server_side_mlock && cm && c && mlocks && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM)) { Anope::string modes = mlocks->GetMLockAsString(ci, false).replace_all_cs("+", "").replace_all_cs("-", "").replace_all_cs(cm->mchar, ""); - SendChannelMetadata(ci->c, "mlock", modes); + SendChannelMetadata(c, "mlock", modes); } return EVENT_CONTINUE; @@ -1549,12 +1558,13 @@ class ProtoInspIRCd20 : public Module EventReturn OnSetChannelOption(CommandSource &source, Command *cmd, ChanServ::Channel *ci, const Anope::string &setting) override { - if (cmd->GetName() == "chanserv/topic" && ci->c) + Channel *c = ci->GetChannel(); + if (cmd->GetName() == "chanserv/topic" && c) { if (setting == "topiclock on") - SendChannelMetadata(ci->c, "topiclock", "1"); + SendChannelMetadata(c, "topiclock", "1"); else if (setting == "topiclock off") - SendChannelMetadata(ci->c, "topiclock", "0"); + SendChannelMetadata(c, "topiclock", "0"); } return EVENT_CONTINUE; diff --git a/modules/protocol/unreal.cpp b/modules/protocol/unreal.cpp index d8d685e14..44a5d1a41 100644 --- a/modules/protocol/unreal.cpp +++ b/modules/protocol/unreal.cpp @@ -1301,38 +1301,42 @@ class ProtoUnreal : public Module void OnChannelSync(Channel *c) override { - if (!c->ci) + ChanServ::Channel *ci = c->GetChannel(); + if (!ci) return; if (use_server_side_mlock && Servers::Capab.count("MLOCK") > 0 && mlocks) { - Anope::string modes = mlocks->GetMLockAsString(c->ci, false).replace_all_cs("+", "").replace_all_cs("-", ""); - Uplink::Send(Me, "MLOCK", c->creation_time, c->ci->GetName(), modes); + Anope::string modes = mlocks->GetMLockAsString(ci, false).replace_all_cs("+", "").replace_all_cs("-", ""); + Uplink::Send(Me, "MLOCK", c->creation_time, ci->GetName(), modes); } } void OnChanRegistered(ChanServ::Channel *ci) override { - if (!ci->c || !use_server_side_mlock || !mlocks || !Servers::Capab.count("MLOCK")) + Channel *c = ci->GetChannel(); + if (!c || !use_server_side_mlock || !mlocks || !Servers::Capab.count("MLOCK")) return; Anope::string modes = mlocks->GetMLockAsString(ci, false).replace_all_cs("+", "").replace_all_cs("-", ""); - Uplink::Send(Me, "MLOCK", ci->c->creation_time, ci->GetName(), modes); + Uplink::Send(Me, "MLOCK", c->creation_time, ci->GetName(), modes); } void OnDelChan(ChanServ::Channel *ci) override { - if (!ci->c || !use_server_side_mlock || !Servers::Capab.count("MLOCK")) + Channel *c = ci->GetChannel(); + if (!c || !use_server_side_mlock || !Servers::Capab.count("MLOCK")) return; - Uplink::Send(Me, "MLOCK", ci->c->creation_time, ci->GetName(), ""); + Uplink::Send(Me, "MLOCK", c->creation_time, ci->GetName(), ""); } EventReturn OnMLock(ChanServ::Channel *ci, ModeLock *lock) override { + Channel *c = ci->GetChannel(); ChannelMode *cm = ModeManager::FindChannelModeByName(lock->GetName()); - if (use_server_side_mlock && cm && mlocks && ci->c && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM) && Servers::Capab.count("MLOCK") > 0) + if (use_server_side_mlock && cm && mlocks && c && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM) && Servers::Capab.count("MLOCK") > 0) { Anope::string modes = mlocks->GetMLockAsString(ci, false).replace_all_cs("+", "").replace_all_cs("-", "") + cm->mchar; - Uplink::Send(Me, "MLOCK", ci->c->creation_time, ci->GetName(), modes); + Uplink::Send(Me, "MLOCK", c->creation_time, ci->GetName(), modes); } return EVENT_CONTINUE; @@ -1340,11 +1344,12 @@ class ProtoUnreal : public Module EventReturn OnUnMLock(ChanServ::Channel *ci, ModeLock *lock) override { + Channel *c = ci->GetChannel(); ChannelMode *cm = ModeManager::FindChannelModeByName(lock->GetName()); - if (use_server_side_mlock && cm && mlocks && ci->c && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM) && Servers::Capab.count("MLOCK") > 0) + if (use_server_side_mlock && cm && mlocks && c && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM) && Servers::Capab.count("MLOCK") > 0) { Anope::string modes = mlocks->GetMLockAsString(ci, false).replace_all_cs("+", "").replace_all_cs("-", "").replace_all_cs(cm->mchar, ""); - Uplink::Send(Me, "MLOCK", ci->c->creation_time, ci->GetName(), modes); + Uplink::Send(Me, "MLOCK", c->creation_time, ci->GetName(), modes); } return EVENT_CONTINUE; diff --git a/src/bots.cpp b/src/bots.cpp index 35b390ed4..eaa0d045d 100644 --- a/src/bots.cpp +++ b/src/bots.cpp @@ -139,12 +139,13 @@ void ServiceBot::UnAssign(User *u, ChanServ::Channel *ci) if (MOD_RESULT == EVENT_STOP) return; - if (ci->c && ci->c->FindUser(ci->GetBot())) + Channel *c = ci->GetChannel(); + if (c && c->FindUser(ci->GetBot())) { if (u) - ci->GetBot()->Part(ci->c, "UNASSIGN from " + u->nick); + ci->GetBot()->Part(c, "UNASSIGN from " + u->nick); else - ci->GetBot()->Part(ci->c); + ci->GetBot()->Part(c); } ci->SetBot(nullptr); diff --git a/src/channels.cpp b/src/channels.cpp index 48e27f323..cc642103b 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -59,12 +59,14 @@ Channel::~Channel() if (Me && Me->IsSynced()) logger.Category("destroy").Log("Channel {0} was destroyed", this->GetName()); - if (this->ci) - this->ci->c = NULL; - ChannelList.erase(this->name); } +ChanServ::Channel *Channel::GetChannel() +{ + return ChanServ::Find(this->name); +} + const Anope::string &Channel::GetName() const { return name; @@ -791,7 +793,8 @@ void Channel::ChangeTopic(const Anope::string &user, const Anope::string &newtop this->topic_setter = user; this->topic_ts = ts; - IRCD->Send(this->ci ? this->ci->WhoSends() : Config->GetClient("ChanServ"), this, newtopic, ts, user); + ChanServ::Channel *ci = this->GetChannel(); + IRCD->Send(ci ? ci->WhoSends() : Config->GetClient("ChanServ"), this, newtopic, ts, user); /* Now that the topic is set update the time set. This is *after* we set it so the protocol modules are able to tell the old last set time */ this->topic_time = Anope::CurTime; @@ -804,7 +807,8 @@ void Channel::SetCorrectModes(User *user, bool give_modes) if (user == NULL) return; - if (!this->ci) + ChanServ::Channel *ci = this->GetChannel(); + if (!ci) return; Anope::Logger.Debug("Setting correct user modes for {0} on {1} ({2}giving modes)", user->nick, this->name, give_modes ? "" : "not "); @@ -890,7 +894,18 @@ bool Channel::CheckKick(User *user) return false; if (mask.empty()) - mask = this->ci->GetIdealBan(user); + { + ChanServ::Channel *ci = this->GetChannel(); + if (ci) + { + mask = ci->GetIdealBan(user); + } + } + if (mask.empty()) + { + return false; + } + if (reason.empty()) reason = Language::Translate(user->Account(), _("You are not permitted to be on this channel.")); diff --git a/src/logger.cpp b/src/logger.cpp index ec2cf2f67..adb880065 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -237,8 +237,11 @@ void LogInfo::ProcessMessage(const Logger *l, const Anope::string &message) User *bi = l->GetBot(); if (!bi) bi = this->bot; - if (!bi && c->ci) - bi = c->ci->WhoSends(); + if (!bi) + { + ChanServ::Channel *ci = c->GetChannel(); + bi = ci->WhoSends(); + } if (bi) IRCD->SendPrivmsg(bi, c->name, buffer); } diff --git a/src/modes.cpp b/src/modes.cpp index 274cb2713..ce46aad8a 100644 --- a/src/modes.cpp +++ b/src/modes.cpp @@ -595,9 +595,17 @@ void ModeManager::StackerAdd(User *bi, Channel *c, ChannelMode *cm, bool Set, co StackerInfo *s = GetInfo(ChannelStackerObjects, c); s->AddMode(cm, Set, Param); if (bi) + { s->bi = bi; - else if (c->ci) - s->bi = c->ci->WhoSends(); + } + else + { + ChanServ::Channel *ci = c->GetChannel(); + if (ci) + { + s->bi = ci->WhoSends(); + } + } if (!modePipe) modePipe = new ModePipe(); diff --git a/src/servers.cpp b/src/servers.cpp index 2c89c92ea..35f066f4a 100644 --- a/src/servers.cpp +++ b/src/servers.cpp @@ -147,8 +147,9 @@ void Server::Burst() ModeManager::StackerAdd(nullptr, c, cm, true, it2->second); } + ChanServ::Channel *ci = c->GetChannel(); if (!c->topic.empty() && !c->topic_setter.empty()) - IRCD->Send(c->ci ? c->ci->WhoSends() : chanserv, c, c->topic, c->topic_ts, c->topic_setter); + IRCD->Send(ci ? ci->WhoSends() : chanserv, c, c->topic, c->topic_ts, c->topic_setter); c->syncing = true; } -- cgit