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