diff options
-rw-r--r-- | include/channels.h | 7 | ||||
-rw-r--r-- | src/channels.cpp | 26 | ||||
-rw-r--r-- | src/commands/cmd_topic.cpp | 33 | ||||
-rw-r--r-- | src/modules/m_permchannels.cpp | 2 | ||||
-rw-r--r-- | src/modules/m_satopic.cpp | 6 |
5 files changed, 34 insertions, 40 deletions
diff --git a/include/channels.h b/include/channels.h index 2aff3f7a8..566eb5cfb 100644 --- a/include/channels.h +++ b/include/channels.h @@ -142,11 +142,10 @@ class CoreExport Channel : public Extensible, public InviteBase std::string GetModeParameter(ModeHandler* mode); /** Sets the channel topic. - * @param u The user setting the topic - * @param t The topic to set it to. Non-const, as it may be modified by a hook. - * @param forceset If set to true then all access checks will be bypassed. + * @param user The user setting the topic. + * @param topic The topic to set it to. */ - int SetTopic(User *u, std::string &t, bool forceset = false); + void SetTopic(User* user, const std::string& topic); /** Obtain the channel "user counter" * This returns the number of users on this channel diff --git a/src/channels.cpp b/src/channels.cpp index b8629bf2c..09b4e8dc9 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -89,38 +89,14 @@ std::string Channel::GetModeParameter(ModeHandler* mode) return ""; } -int Channel::SetTopic(User *u, std::string &ntopic, bool forceset) +void Channel::SetTopic(User* u, const std::string& ntopic) { - if (IS_LOCAL(u) && !forceset) - { - ModResult res; - FIRST_MOD_RESULT(OnPreTopicChange, res, (u,this,ntopic)); - - if (res == MOD_RES_DENY) - return CMD_FAILURE; - if (res != MOD_RES_ALLOW) - { - if (!this->HasUser(u)) - { - u->WriteNumeric(442, "%s %s :You're not on that channel!",u->nick.c_str(), this->name.c_str()); - return CMD_FAILURE; - } - if (IsModeSet('t') && !ServerInstance->OnCheckExemption(u,this,"topiclock").check(GetPrefixValue(u) >= HALFOP_VALUE)) - { - u->WriteNumeric(482, "%s %s :You do not have access to change the topic on this channel", u->nick.c_str(), this->name.c_str()); - return CMD_FAILURE; - } - } - } - this->topic.assign(ntopic, 0, ServerInstance->Config->Limits.MaxTopic); this->setby.assign(ServerInstance->Config->FullHostInTopic ? u->GetFullHost() : u->nick, 0, 128); this->WriteChannel(u, "TOPIC %s :%s", this->name.c_str(), this->topic.c_str()); this->topicset = ServerInstance->Time(); FOREACH_MOD(I_OnPostTopicChange,OnPostTopicChange(u, this, this->topic)); - - return CMD_SUCCESS; } Membership* Channel::AddUser(User* user) diff --git a/src/commands/cmd_topic.cpp b/src/commands/cmd_topic.cpp index b96ebcfe7..e8c555e90 100644 --- a/src/commands/cmd_topic.cpp +++ b/src/commands/cmd_topic.cpp @@ -48,9 +48,7 @@ class CommandTopic : public Command CmdResult CommandTopic::Handle (const std::vector<std::string>& parameters, User *user) { - Channel* c; - - c = ServerInstance->FindChan(parameters[0]); + Channel* c = ServerInstance->FindChan(parameters[0]); if (!c) { user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), parameters[0].c_str()); @@ -79,12 +77,35 @@ CmdResult CommandTopic::Handle (const std::vector<std::string>& parameters, User } return CMD_SUCCESS; } - else if (parameters.size()>1) + + // Access checks are skipped for non-local users + if (!IS_LOCAL(user)) + { + c->SetTopic(user, parameters[1]); + return CMD_SUCCESS; + } + + std::string t = parameters[1]; // needed, in case a module wants to change it + ModResult res; + FIRST_MOD_RESULT(OnPreTopicChange, res, (user,c,t)); + + if (res == MOD_RES_DENY) + return CMD_FAILURE; + if (res != MOD_RES_ALLOW) { - std::string t = parameters[1]; // needed, in case a module wants to change it - c->SetTopic(user, t); + if (!c->HasUser(user)) + { + user->WriteNumeric(442, "%s %s :You're not on that channel!", user->nick.c_str(), c->name.c_str()); + return CMD_FAILURE; + } + if (c->IsModeSet('t') && !ServerInstance->OnCheckExemption(user, c, "topiclock").check(c->GetPrefixValue(user) >= HALFOP_VALUE)) + { + user->WriteNumeric(482, "%s %s :You do not have access to change the topic on this channel", user->nick.c_str(), c->name.c_str()); + return CMD_FAILURE; + } } + c->SetTopic(user, t); return CMD_SUCCESS; } diff --git a/src/modules/m_permchannels.cpp b/src/modules/m_permchannels.cpp index ff1a35ba9..0b4d96c0f 100644 --- a/src/modules/m_permchannels.cpp +++ b/src/modules/m_permchannels.cpp @@ -197,7 +197,7 @@ public: c = new Channel(channel, ServerInstance->Time()); if (!topic.empty()) { - c->SetTopic(ServerInstance->FakeClient, topic, true); + c->SetTopic(ServerInstance->FakeClient, topic); /* * Due to the way protocol works in 1.2, we need to hack the topic TS in such a way that this diff --git a/src/modules/m_satopic.cpp b/src/modules/m_satopic.cpp index c15c9e91b..56098635b 100644 --- a/src/modules/m_satopic.cpp +++ b/src/modules/m_satopic.cpp @@ -40,10 +40,8 @@ class CommandSATopic : public Command if(target) { - std::string newTopic = parameters[1]; - - // 3rd parameter overrides access checks - target->SetTopic(user, newTopic, true); + const std::string& newTopic = parameters[1]; + target->SetTopic(user, newTopic); ServerInstance->SNO->WriteGlobalSno('a', user->nick + " used SATOPIC on " + target->name + ", new topic: " + newTopic); return CMD_SUCCESS; |