]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Always set the topic in Channel::SetTopic(), move access checks into cmd_topic
authorattilamolnar <attilamolnar@hush.com>
Sun, 16 Jun 2013 19:53:05 +0000 (21:53 +0200)
committerattilamolnar <attilamolnar@hush.com>
Sun, 16 Jun 2013 19:53:05 +0000 (21:53 +0200)
include/channels.h
src/channels.cpp
src/commands/cmd_topic.cpp
src/modules/m_permchannels.cpp
src/modules/m_satopic.cpp

index 2aff3f7a87f5f9e6da81b5da30bda0077ab62988..566eb5cfb54d392200bf0ee4e55b12f3dafe44f2 100644 (file)
@@ -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
index b8629bf2c01181b470ffea49f63676bc54880aa3..09b4e8dc98929c0c2f07e17b9d5856af3c3ecf57 100644 (file)
@@ -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)
index b96ebcfe73647d0b9c0477c7564cd2b3823177e8..e8c555e90637021f5713bee99f8c70675a991c41 100644 (file)
@@ -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;
 }
 
index ff1a35ba913e62bbe3ed1cf1cb4daac0daa703ed..0b4d96c0f421b6b4b938513cb6746fa0bdbe0bbe 100644 (file)
@@ -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
index c15c9e91bcb4e2e911e509c108f36b5d3240fc21..56098635b37949d8aa8779c9bfbf21a00eaab192 100644 (file)
@@ -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;