]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_topic.cpp
Rename <connect:nouserdns> to <connect:resolvehostnames>.
[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         ChanModeReference secretmode;
33         ChanModeReference topiclockmode;
34
35  public:
36         /** Constructor for topic.
37          */
38         CommandTopic(Module* parent)
39                 : Command(parent, "TOPIC", 1, 2)
40                 , secretmode(parent, "secret")
41                 , topiclockmode(parent, "topiclock")
42         {
43                 syntax = "<channel> [<topic>]";
44                 Penalty = 2;
45         }
46
47         /** Handle command.
48          * @param parameters The parameters to the comamnd
49          * @param pcnt The number of parameters passed to teh command
50          * @param user The user issuing the command
51          * @return A value from CmdResult to indicate command success or failure.
52          */
53         CmdResult Handle(const std::vector<std::string>& parameters, User *user);
54         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
55         {
56                 return (IS_LOCAL(user) ? ROUTE_LOCALONLY : ROUTE_BROADCAST);
57         }
58 };
59
60 CmdResult CommandTopic::Handle (const std::vector<std::string>& parameters, User *user)
61 {
62         Channel* c = ServerInstance->FindChan(parameters[0]);
63         if (!c)
64         {
65                 user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), parameters[0].c_str());
66                 return CMD_FAILURE;
67         }
68
69         if (parameters.size() == 1)
70         {
71                 if (c)
72                 {
73                         if ((c->IsModeSet(secretmode)) && (!c->HasUser(user)))
74                         {
75                                 user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), c->name.c_str());
76                                 return CMD_FAILURE;
77                         }
78
79                         if (c->topic.length())
80                         {
81                                 user->WriteNumeric(332, "%s %s :%s", user->nick.c_str(), c->name.c_str(), c->topic.c_str());
82                                 user->WriteNumeric(333, "%s %s %s %lu", user->nick.c_str(), c->name.c_str(), c->setby.c_str(), (unsigned long)c->topicset);
83                         }
84                         else
85                         {
86                                 user->WriteNumeric(RPL_NOTOPICSET, "%s %s :No topic is set.", user->nick.c_str(), c->name.c_str());
87                         }
88                 }
89                 return CMD_SUCCESS;
90         }
91
92         // Access checks are skipped for non-local users
93         if (!IS_LOCAL(user))
94         {
95                 c->SetTopic(user, parameters[1]);
96                 return CMD_SUCCESS;
97         }
98
99         std::string t = parameters[1]; // needed, in case a module wants to change it
100         ModResult res;
101         FIRST_MOD_RESULT(OnPreTopicChange, res, (user,c,t));
102
103         if (res == MOD_RES_DENY)
104                 return CMD_FAILURE;
105         if (res != MOD_RES_ALLOW)
106         {
107                 if (!c->HasUser(user))
108                 {
109                         user->WriteNumeric(442, "%s %s :You're not on that channel!", user->nick.c_str(), c->name.c_str());
110                         return CMD_FAILURE;
111                 }
112                 if (c->IsModeSet(topiclockmode) && !ServerInstance->OnCheckExemption(user, c, "topiclock").check(c->GetPrefixValue(user) >= HALFOP_VALUE))
113                 {
114                         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());
115                         return CMD_FAILURE;
116                 }
117         }
118
119         c->SetTopic(user, t);
120         return CMD_SUCCESS;
121 }
122
123
124 COMMAND_INIT(CommandTopic)