]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_topic.cpp
e8c555e90637021f5713bee99f8c70675a991c41
[user/henk/code/inspircd.git] / src / commands / cmd_topic.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5  *   Copyright (C) 2007-2008 Robin Burchell <robin+git@viroteck.net>
6  *   Copyright (C) 2008 Craig Edwards <craigedwards@brainbox.cc>
7  *   Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
8  *
9  * This file is part of InspIRCd.  InspIRCd is free software: you can
10  * redistribute it and/or modify it under the terms of the GNU General Public
11  * License as published by the Free Software Foundation, version 2.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20  */
21
22
23 #include "inspircd.h"
24
25 /** Handle /TOPIC. These command handlers can be reloaded by the core,
26  * and handle basic RFC1459 commands. Commands within modules work
27  * the same way, however, they can be fully unloaded, where these
28  * may not.
29  */
30 class CommandTopic : public Command
31 {
32  public:
33         /** Constructor for topic.
34          */
35         CommandTopic ( Module* parent) : Command(parent,"TOPIC",1, 2) { syntax = "<channel> [<topic>]"; Penalty = 2; }
36         /** Handle command.
37          * @param parameters The parameters to the comamnd
38          * @param pcnt The number of parameters passed to teh command
39          * @param user The user issuing the command
40          * @return A value from CmdResult to indicate command success or failure.
41          */
42         CmdResult Handle(const std::vector<std::string>& parameters, User *user);
43         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
44         {
45                 return (IS_LOCAL(user) ? ROUTE_LOCALONLY : ROUTE_BROADCAST);
46         }
47 };
48
49 CmdResult CommandTopic::Handle (const std::vector<std::string>& parameters, User *user)
50 {
51         Channel* c = ServerInstance->FindChan(parameters[0]);
52         if (!c)
53         {
54                 user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), parameters[0].c_str());
55                 return CMD_FAILURE;
56         }
57
58         if (parameters.size() == 1)
59         {
60                 if (c)
61                 {
62                         if ((c->IsModeSet('s')) && (!c->HasUser(user)))
63                         {
64                                 user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), c->name.c_str());
65                                 return CMD_FAILURE;
66                         }
67
68                         if (c->topic.length())
69                         {
70                                 user->WriteNumeric(332, "%s %s :%s", user->nick.c_str(), c->name.c_str(), c->topic.c_str());
71                                 user->WriteNumeric(333, "%s %s %s %lu", user->nick.c_str(), c->name.c_str(), c->setby.c_str(), (unsigned long)c->topicset);
72                         }
73                         else
74                         {
75                                 user->WriteNumeric(RPL_NOTOPICSET, "%s %s :No topic is set.", user->nick.c_str(), c->name.c_str());
76                         }
77                 }
78                 return CMD_SUCCESS;
79         }
80
81         // Access checks are skipped for non-local users
82         if (!IS_LOCAL(user))
83         {
84                 c->SetTopic(user, parameters[1]);
85                 return CMD_SUCCESS;
86         }
87
88         std::string t = parameters[1]; // needed, in case a module wants to change it
89         ModResult res;
90         FIRST_MOD_RESULT(OnPreTopicChange, res, (user,c,t));
91
92         if (res == MOD_RES_DENY)
93                 return CMD_FAILURE;
94         if (res != MOD_RES_ALLOW)
95         {
96                 if (!c->HasUser(user))
97                 {
98                         user->WriteNumeric(442, "%s %s :You're not on that channel!", user->nick.c_str(), c->name.c_str());
99                         return CMD_FAILURE;
100                 }
101                 if (c->IsModeSet('t') && !ServerInstance->OnCheckExemption(user, c, "topiclock").check(c->GetPrefixValue(user) >= HALFOP_VALUE))
102                 {
103                         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());
104                         return CMD_FAILURE;
105                 }
106         }
107
108         c->SetTopic(user, t);
109         return CMD_SUCCESS;
110 }
111
112
113 COMMAND_INIT(CommandTopic)