]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_cycle.cpp
Replace hardcoded mode letters passed to IsModeSet() and GetModeParameter() with...
[user/henk/code/inspircd.git] / src / modules / m_cycle.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
5  *   Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
6  *
7  * This file is part of InspIRCd.  InspIRCd is free software: you can
8  * redistribute it and/or modify it under the terms of the GNU General Public
9  * License as published by the Free Software Foundation, version 2.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20
21 #include "inspircd.h"
22
23 /* $ModDesc: Provides command CYCLE, acts as a server-side HOP command to part and rejoin a channel. */
24
25 /** Handle /CYCLE
26  */
27 class CommandCycle : public SplitCommand
28 {
29  public:
30         CommandCycle(Module* Creator)
31                 : SplitCommand(Creator, "CYCLE", 1)
32         {
33                 Penalty = 3; syntax = "<channel> :[reason]";
34         }
35
36         CmdResult HandleLocal(const std::vector<std::string> &parameters, LocalUser* user)
37         {
38                 Channel* channel = ServerInstance->FindChan(parameters[0]);
39                 std::string reason = ConvToStr("Cycling");
40
41                 if (parameters.size() > 1)
42                 {
43                         /* reason provided, use it */
44                         reason = reason + ": " + parameters[1];
45                 }
46
47                 if (!channel)
48                 {
49                         user->WriteNumeric(403, "%s %s :No such channel", user->nick.c_str(), parameters[0].c_str());
50                         return CMD_FAILURE;
51                 }
52
53                 if (channel->HasUser(user))
54                 {
55                         /*
56                          * technically, this is only ever sent locally, but pays to be safe ;p
57                          */
58                         if (IS_LOCAL(user))
59                         {
60                                 if (channel->GetPrefixValue(user) < VOICE_VALUE && channel->IsBanned(user))
61                                 {
62                                         /* banned, boned. drop the message. */
63                                         user->WriteNotice("*** You may not cycle, as you are banned on channel " + channel->name);
64                                         return CMD_FAILURE;
65                                 }
66
67                                 channel->PartUser(user, reason);
68                                 Channel::JoinUser(user, parameters[0], true);
69                         }
70
71                         return CMD_SUCCESS;
72                 }
73                 else
74                 {
75                         user->WriteNumeric(442, "%s %s :You're not on that channel", user->nick.c_str(), channel->name.c_str());
76                 }
77
78                 return CMD_FAILURE;
79         }
80 };
81
82
83 class ModuleCycle : public Module
84 {
85         CommandCycle cmd;
86
87  public:
88         ModuleCycle()
89                 : cmd(this)
90         {
91         }
92
93         void init() CXX11_OVERRIDE
94         {
95                 ServerInstance->Modules->AddService(cmd);
96         }
97
98         Version GetVersion() CXX11_OVERRIDE
99         {
100                 return Version("Provides command CYCLE, acts as a server-side HOP command to part and rejoin a channel.", VF_VENDOR);
101         }
102 };
103
104 MODULE_INIT(ModuleCycle)