]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_topic.cpp
b96ebcfe73647d0b9c0477c7564cd2b3823177e8
[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;
52
53         c = ServerInstance->FindChan(parameters[0]);
54         if (!c)
55         {
56                 user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), parameters[0].c_str());
57                 return CMD_FAILURE;
58         }
59
60         if (parameters.size() == 1)
61         {
62                 if (c)
63                 {
64                         if ((c->IsModeSet('s')) && (!c->HasUser(user)))
65                         {
66                                 user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), c->name.c_str());
67                                 return CMD_FAILURE;
68                         }
69
70                         if (c->topic.length())
71                         {
72                                 user->WriteNumeric(332, "%s %s :%s", user->nick.c_str(), c->name.c_str(), c->topic.c_str());
73                                 user->WriteNumeric(333, "%s %s %s %lu", user->nick.c_str(), c->name.c_str(), c->setby.c_str(), (unsigned long)c->topicset);
74                         }
75                         else
76                         {
77                                 user->WriteNumeric(RPL_NOTOPICSET, "%s %s :No topic is set.", user->nick.c_str(), c->name.c_str());
78                         }
79                 }
80                 return CMD_SUCCESS;
81         }
82         else if (parameters.size()>1)
83         {
84                 std::string t = parameters[1]; // needed, in case a module wants to change it
85                 c->SetTopic(user, t);
86         }
87
88         return CMD_SUCCESS;
89 }
90
91
92 COMMAND_INIT(CommandTopic)