]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_satopic.cpp
b3aec8592382e62a59f57b99ad9a2fb2fe12edc0
[user/henk/code/inspircd.git] / src / modules / m_satopic.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2008 Oliver Lupton <oliverlupton@gmail.com>
5  *
6  * This file is part of InspIRCd.  InspIRCd is free software: you can
7  * redistribute it and/or modify it under the terms of the GNU General Public
8  * License as published by the Free Software Foundation, version 2.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
13  * details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19
20 #include "inspircd.h"
21
22 /** Handle /SATOPIC
23  */
24 class CommandSATopic : public Command
25 {
26  public:
27         CommandSATopic(Module* Creator) : Command(Creator,"SATOPIC", 2, 2)
28         {
29                 flags_needed = 'o'; syntax = "<channel> :<topic>";
30         }
31
32         CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
33         {
34                 /*
35                  * Handles a SATOPIC request. Notifies all +s users.
36                  */
37                 Channel* target = ServerInstance->FindChan(parameters[0]);
38
39                 if(target)
40                 {
41                         const std::string newTopic(parameters[1], 0, ServerInstance->Config->Limits.MaxTopic);
42                         if (target->topic == newTopic)
43                         {
44                                 user->WriteNotice(InspIRCd::Format("The topic on %s is already what you are trying to change it to.", target->name.c_str()));
45                                 return CMD_SUCCESS;
46                         }
47
48                         target->SetTopic(user, newTopic, ServerInstance->Time(), NULL);
49                         ServerInstance->SNO->WriteGlobalSno('a', user->nick + " used SATOPIC on " + target->name + ", new topic: " + newTopic);
50
51                         return CMD_SUCCESS;
52                 }
53                 else
54                 {
55                         user->WriteNumeric(Numerics::NoSuchChannel(parameters[0]));
56                         return CMD_FAILURE;
57                 }
58         }
59 };
60
61 class ModuleSATopic : public Module
62 {
63         CommandSATopic cmd;
64  public:
65         ModuleSATopic()
66         : cmd(this)
67         {
68         }
69
70         Version GetVersion() CXX11_OVERRIDE
71         {
72                 return Version("Provides a SATOPIC command", VF_VENDOR);
73         }
74 };
75
76 MODULE_INIT(ModuleSATopic)