]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_cycle.cpp
3ead72a453f1787b798f7e7aaca18f24a6ebf692
[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 /** Handle /CYCLE
24  */
25 class CommandCycle : public SplitCommand
26 {
27  public:
28         CommandCycle(Module* Creator)
29                 : SplitCommand(Creator, "CYCLE", 1)
30         {
31                 Penalty = 3; syntax = "<channel> :[reason]";
32         }
33
34         CmdResult HandleLocal(LocalUser* user, const Params& parameters) CXX11_OVERRIDE
35         {
36                 Channel* channel = ServerInstance->FindChan(parameters[0]);
37                 std::string reason = "Cycling";
38
39                 if (parameters.size() > 1)
40                 {
41                         /* reason provided, use it */
42                         reason = reason + ": " + parameters[1];
43                 }
44
45                 if (!channel)
46                 {
47                         user->WriteNumeric(Numerics::NoSuchChannel(parameters[0]));
48                         return CMD_FAILURE;
49                 }
50
51                 if (channel->HasUser(user))
52                 {
53                         if (channel->GetPrefixValue(user) < VOICE_VALUE && channel->IsBanned(user))
54                         {
55                                 // User is banned, send an error and don't cycle them
56                                 user->WriteNotice("*** You may not cycle, as you are banned on channel " + channel->name);
57                                 return CMD_FAILURE;
58                         }
59
60                         channel->PartUser(user, reason);
61                         Channel::JoinUser(user, parameters[0], true);
62
63                         return CMD_SUCCESS;
64                 }
65                 else
66                 {
67                         user->WriteNumeric(ERR_NOTONCHANNEL, channel->name, "You're not on that channel");
68                 }
69
70                 return CMD_FAILURE;
71         }
72 };
73
74
75 class ModuleCycle : public Module
76 {
77         CommandCycle cmd;
78
79  public:
80         ModuleCycle()
81                 : cmd(this)
82         {
83         }
84
85         Version GetVersion() CXX11_OVERRIDE
86         {
87                 return Version("Provides command CYCLE, acts as a server-side HOP command to part and rejoin a channel.", VF_VENDOR);
88         }
89 };
90
91 MODULE_INIT(ModuleCycle)