]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/coremods/core_channel/cmd_topic.cpp
8d65d764a1a7aac3e75854cf3723d4134a8bb0bf
[user/henk/code/inspircd.git] / src / coremods / core_channel / 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 #include "core_channel.h"
25
26 CommandTopic::CommandTopic(Module* parent)
27         : SplitCommand(parent, "TOPIC", 1, 2)
28         , secretmode(parent, "secret")
29         , topiclockmode(parent, "topiclock")
30 {
31         syntax = "<channel> [<topic>]";
32         Penalty = 2;
33 }
34
35 CmdResult CommandTopic::HandleLocal(const std::vector<std::string>& parameters, LocalUser* user)
36 {
37         Channel* c = ServerInstance->FindChan(parameters[0]);
38         if (!c)
39         {
40                 user->WriteNumeric(ERR_NOSUCHNICK, "%s :No such nick/channel", parameters[0].c_str());
41                 return CMD_FAILURE;
42         }
43
44         if (parameters.size() == 1)
45         {
46                 if ((c->IsModeSet(secretmode)) && (!c->HasUser(user)))
47                 {
48                         user->WriteNumeric(ERR_NOSUCHNICK, "%s :No such nick/channel", c->name.c_str());
49                         return CMD_FAILURE;
50                 }
51
52                 if (c->topic.length())
53                 {
54                         Topic::ShowTopic(user, c);
55                 }
56                 else
57                 {
58                         user->WriteNumeric(RPL_NOTOPICSET, "%s :No topic is set.", c->name.c_str());
59                 }
60                 return CMD_SUCCESS;
61         }
62
63         std::string t = parameters[1]; // needed, in case a module wants to change it
64         ModResult res;
65         FIRST_MOD_RESULT(OnPreTopicChange, res, (user,c,t));
66
67         if (res == MOD_RES_DENY)
68                 return CMD_FAILURE;
69         if (res != MOD_RES_ALLOW)
70         {
71                 if (!c->HasUser(user))
72                 {
73                         user->WriteNumeric(ERR_NOTONCHANNEL, "%s :You're not on that channel!", c->name.c_str());
74                         return CMD_FAILURE;
75                 }
76                 if (c->IsModeSet(topiclockmode) && !ServerInstance->OnCheckExemption(user, c, "topiclock").check(c->GetPrefixValue(user) >= HALFOP_VALUE))
77                 {
78                         user->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s :You do not have access to change the topic on this channel", c->name.c_str());
79                         return CMD_FAILURE;
80                 }
81         }
82
83         c->SetTopic(user, t);
84         return CMD_SUCCESS;
85 }
86
87 void Topic::ShowTopic(LocalUser* user, Channel* chan)
88 {
89         user->WriteNumeric(RPL_TOPIC, "%s :%s", chan->name.c_str(), chan->topic.c_str());
90         user->WriteNumeric(RPL_TOPICTIME, "%s %s %lu", chan->name.c_str(), chan->setby.c_str(), (unsigned long)chan->topicset);
91 }