summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2017-03-19 18:36:03 -0400
committerAdam <Adam@anope.org>2017-03-19 18:36:03 -0400
commit2a886acbedb6b6386dbff3e591b0d4035d516b2a (patch)
tree765218b2fc476e9b1517d7f1e4aa78f57de87752
parentf237405a52f6b8efb606c5181ffe3bd75a6a6a8a (diff)
Get rid of relying on if(this) in WhoSends()
-rw-r--r--include/modules/chanserv/channel.h18
-rw-r--r--modules/chanserv/main/channel.cpp9
-rw-r--r--modules/chanserv/main/channel.h1
-rw-r--r--modules/chanserv/main/chanserv.cpp19
-rw-r--r--modules/chanserv/topic.cpp4
-rw-r--r--modules/nickserv/recover.cpp2
-rw-r--r--modules/operserv/mode.cpp4
-rw-r--r--modules/protocol/unreal.cpp12
-rw-r--r--src/channels.cpp5
-rw-r--r--src/logger.cpp2
-rw-r--r--src/modes.cpp6
-rw-r--r--src/servers.cpp6
12 files changed, 46 insertions, 42 deletions
diff --git a/include/modules/chanserv/channel.h b/include/modules/chanserv/channel.h
index 29e8ef9d7..474a4081a 100644
--- a/include/modules/chanserv/channel.h
+++ b/include/modules/chanserv/channel.h
@@ -138,23 +138,7 @@ class CoreExport Channel : public Serialize::Object
/** Find which bot should send mode/topic/etc changes for this channel
* @return The bot
*/
- ServiceBot *WhoSends()
- {
- if (this)
- if (ServiceBot *bi = GetBot())
- return bi;
-
- ServiceBot *ChanServ = Config->GetClient("ChanServ");
- if (ChanServ)
- return ChanServ;
-
-#warning "if(this)"
- //XXX
-// if (!BotListByNick->empty())
-// return BotListByNick->begin()->second;
-
- return NULL;
- }
+ virtual ServiceBot *WhoSends() anope_abstract;
/** Get an entry from the channel access list by index
*
diff --git a/modules/chanserv/main/channel.cpp b/modules/chanserv/main/channel.cpp
index d10abbc0d..25430656e 100644
--- a/modules/chanserv/main/channel.cpp
+++ b/modules/chanserv/main/channel.cpp
@@ -347,6 +347,15 @@ void ChannelImpl::SetPrivate(bool _private)
Set(&ChannelType::_private, _private);
}
+ServiceBot *ChannelImpl::WhoSends()
+{
+ BotInfo *bi = GetBI();
+ if (bi != nullptr)
+ return bi->bot;
+
+ return Config->GetClient("ChanServ");
+}
+
ChanServ::ChanAccess *ChannelImpl::GetAccess(unsigned index)
{
std::vector<ChanServ::ChanAccess *> a = GetRefs<ChanServ::ChanAccess *>();
diff --git a/modules/chanserv/main/channel.h b/modules/chanserv/main/channel.h
index bb79df3c5..1cc6dc408 100644
--- a/modules/chanserv/main/channel.h
+++ b/modules/chanserv/main/channel.h
@@ -141,6 +141,7 @@ class ChannelImpl : public ChanServ::Channel
void SetPrivate(bool) override;
bool IsFounder(const User *user) override;
+ ServiceBot *WhoSends() override;
ChanServ::ChanAccess *GetAccess(unsigned index) override;
ChanServ::AccessGroup AccessFor(const User *u, bool = true) override;
ChanServ::AccessGroup AccessFor(NickServ::Account *nc, bool = true) override;
diff --git a/modules/chanserv/main/chanserv.cpp b/modules/chanserv/main/chanserv.cpp
index dd6bdb472..be29c0ab8 100644
--- a/modules/chanserv/main/chanserv.cpp
+++ b/modules/chanserv/main/chanserv.cpp
@@ -380,17 +380,17 @@ class ChanServCore : public Module
return;
if (c->ci)
- c->SetMode(c->ci->WhoSends(), "REGISTERED", "", false);
+ c->SetMode(nullptr, "REGISTERED", "", false);
else
- c->RemoveMode(c->ci->WhoSends(), "REGISTERED", "", false);
+ c->RemoveMode(nullptr, "REGISTERED", "", false);
const Anope::string &require = Config->GetModule(this)->Get<Anope::string>("require");
if (!require.empty())
{
if (c->ci)
- c->SetModes(c->ci->WhoSends(), false, "+%s", require.c_str());
+ c->SetModes(nullptr, false, "+%s", require.c_str());
else
- c->SetModes(c->ci->WhoSends(), false, "-%s", require.c_str());
+ c->SetModes(nullptr, false, "-%s", require.c_str());
}
}
@@ -485,8 +485,13 @@ class ChanServCore : public Module
else
{
if (!ci->GetBot())
- ci->WhoSends()->Assign(NULL, ci);
- if (ci->c->FindUser(ci->GetBot()) == NULL)
+ {
+ ServiceBot *bi = ci->WhoSends();
+ if (bi != nullptr)
+ bi->Assign(nullptr, ci);
+ }
+
+ if (ci->GetBot() != nullptr && ci->c->FindUser(ci->GetBot()) == nullptr)
{
Anope::string botmodes = Config->GetModule("botserv/main")->Get<Anope::string>("botmodes",
Config->GetModule("chanserv/main")->Get<Anope::string>("botmodes"));
@@ -535,7 +540,7 @@ class ChanServCore : public Module
if (cu && cm && !cu->status.HasMode(cm->mchar))
{
/* Our -o and their mode change crossing, bounce their mode */
- c->RemoveMode(c->ci->WhoSends(), mode, param);
+ c->RemoveMode(nullptr, mode, param);
/* We don't set mlocks until after the join has finished processing, it will stack with this change,
* so there isn't much for the user to remove except -nt etc which is likely locked anyway.
*/
diff --git a/modules/chanserv/topic.cpp b/modules/chanserv/topic.cpp
index d3546562e..005bcaf22 100644
--- a/modules/chanserv/topic.cpp
+++ b/modules/chanserv/topic.cpp
@@ -261,7 +261,9 @@ class CSTopic : public Module
/* Update channel topic */
if ((c->ci->IsTopicLock() || c->ci->IsKeepTopic()) && c->ci->GetLastTopic() != c->topic)
{
- c->ChangeTopic(!c->ci->GetLastTopicSetter().empty() ? c->ci->GetLastTopicSetter() : c->ci->WhoSends()->nick, c->ci->GetLastTopic(), c->ci->GetLastTopicTime() ? c->ci->GetLastTopicTime() : Anope::CurTime);
+ 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);
}
}
}
diff --git a/modules/nickserv/recover.cpp b/modules/nickserv/recover.cpp
index 5c4f3ac1d..386542fc9 100644
--- a/modules/nickserv/recover.cpp
+++ b/modules/nickserv/recover.cpp
@@ -295,7 +295,7 @@ class NSRecover : public Module
if (it != ei->end())
{
for (size_t i = 0; i < it->second.Modes().length(); ++i)
- c->SetMode(c->ci->WhoSends(), ModeManager::FindChannelModeByChar(it->second.Modes()[i]), u->GetUID());
+ c->SetMode(nullptr, ModeManager::FindChannelModeByChar(it->second.Modes()[i]), u->GetUID());
ei->erase(it);
if (ei->empty())
diff --git a/modules/operserv/mode.cpp b/modules/operserv/mode.cpp
index 84b4ba6fb..2dd9b899e 100644
--- a/modules/operserv/mode.cpp
+++ b/modules/operserv/mode.cpp
@@ -53,7 +53,7 @@ class CommandOSMode : public Command
const Channel::ModeList chmodes = c->GetModes();
for (Channel::ModeList::const_iterator it = chmodes.begin(), it_end = chmodes.end(); it != it_end && c; ++it)
- c->RemoveMode(c->ci->WhoSends(), it->first, it->second, false);
+ c->RemoveMode(nullptr, it->first, it->second, false);
if (!c)
{
@@ -71,7 +71,7 @@ class CommandOSMode : public Command
continue;
for (size_t i = uc->status.Modes().length(); i > 0; --i)
- c->RemoveMode(c->ci->WhoSends(), ModeManager::FindChannelModeByChar(uc->status.Modes()[i - 1]), uc->user->GetUID(), false);
+ c->RemoveMode(nullptr, ModeManager::FindChannelModeByChar(uc->status.Modes()[i - 1]), uc->user->GetUID(), false);
}
source.Reply(_("All modes cleared on \002{0}\002."), c->name);
diff --git a/modules/protocol/unreal.cpp b/modules/protocol/unreal.cpp
index fd6e31875..0bca595df 100644
--- a/modules/protocol/unreal.cpp
+++ b/modules/protocol/unreal.cpp
@@ -104,10 +104,16 @@ void unreal::senders::MessageChannel::Send(Channel* c)
/* Unreal does not support updating a channels TS without actually joining a user,
* so we will join and part us now
*/
- ServiceBot *bi = c->ci->WhoSends();
+ ServiceBot *bi;
+ if (c->ci)
+ bi = c->ci->WhoSends();
+ else
+ bi = Config->GetClient("ChanServ");
+
if (!bi)
- ;
- else if (c->FindUser(bi) == NULL)
+ return;
+
+ if (c->FindUser(bi) == NULL)
{
bi->Join(c);
bi->Part(c);
diff --git a/src/channels.cpp b/src/channels.cpp
index 2b9ea438d..bf5b22183 100644
--- a/src/channels.cpp
+++ b/src/channels.cpp
@@ -767,9 +767,6 @@ bool Channel::Kick(User *source, User *u, const Anope::string &reason)
if (u->IsProtected())
return false;
- if (source == NULL)
- source = this->ci->WhoSends();
-
if (!this->KickInternal(source, u->nick, reason))
return false;
IRCD->SendKick(source, this, u, reason);
@@ -794,7 +791,7 @@ void Channel::ChangeTopic(const Anope::string &user, const Anope::string &newtop
this->topic_setter = user;
this->topic_ts = ts;
- IRCD->Send<messages::Topic>(this->ci->WhoSends(), this, newtopic, ts, user);
+ IRCD->Send<messages::Topic>(this->ci ? this->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;
diff --git a/src/logger.cpp b/src/logger.cpp
index 22e27d375..2e00ae049 100644
--- a/src/logger.cpp
+++ b/src/logger.cpp
@@ -235,7 +235,7 @@ void LogInfo::ProcessMessage(const Logger *l, const Anope::string &message)
User *bi = l->GetBot();
if (!bi)
bi = this->bot;
- if (!bi)
+ if (!bi && c->ci)
bi = c->ci->WhoSends();
if (bi)
IRCD->SendPrivmsg(bi, c->name, buffer);
diff --git a/src/modes.cpp b/src/modes.cpp
index f845f7408..0223a9c93 100644
--- a/src/modes.cpp
+++ b/src/modes.cpp
@@ -57,9 +57,7 @@ struct StackerInfo
/* Modes to be deleted */
std::list<std::pair<Mode *, Anope::string> > DelModes;
/* Bot this is sent from */
- User *bi;
-
- StackerInfo() : bi(NULL) { }
+ User *bi = nullptr;
/** Add a mode to this object
* @param mode The mode
@@ -598,7 +596,7 @@ void ModeManager::StackerAdd(User *bi, Channel *c, ChannelMode *cm, bool Set, co
s->AddMode(cm, Set, Param);
if (bi)
s->bi = bi;
- else
+ else if (c->ci)
s->bi = c->ci->WhoSends();
if (!modePipe)
diff --git a/src/servers.cpp b/src/servers.cpp
index 7747f4a69..d1fa2bf26 100644
--- a/src/servers.cpp
+++ b/src/servers.cpp
@@ -127,6 +127,8 @@ void Server::Burst()
bi->introduced = true;
}
+ ServiceBot *chanserv = Config->GetClient("ChanServ");
+
for (channel_map::const_iterator it = ChannelList.begin(), it_end = ChannelList.end(); it != it_end; ++it)
{
Channel *c = it->second;
@@ -142,11 +144,11 @@ void Server::Burst()
ChannelMode *cm = ModeManager::FindChannelModeByName(it2->first);
if (!cm || cm->type != MODE_LIST)
continue;
- ModeManager::StackerAdd(c->ci->WhoSends(), c, cm, true, it2->second);
+ ModeManager::StackerAdd(nullptr, c, cm, true, it2->second);
}
if (!c->topic.empty() && !c->topic_setter.empty())
- IRCD->Send<messages::Topic>(c->ci->WhoSends(), c, c->topic, c->topic_ts, c->topic_setter);
+ IRCD->Send<messages::Topic>(c->ci ? c->ci->WhoSends() : chanserv, c, c->topic, c->topic_ts, c->topic_setter);
c->syncing = true;
}