]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_cycle.cpp
ca8d8a374cf131187243d302f02d7baaf397a685
[user/henk/code/inspircd.git] / src / modules / m_cycle.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2017 B00mX0r <b00mx0r@aureus.pw>
5  *   Copyright (C) 2013, 2018 Sadie Powell <sadie@witchery.services>
6  *   Copyright (C) 2012-2014, 2016 Attila Molnar <attilamolnar@hush.com>
7  *   Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
8  *   Copyright (C) 2010 Craig Edwards <brain@inspircd.org>
9  *   Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
10  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
11  *   Copyright (C) 2007-2008 Dennis Friis <peavey@inspircd.org>
12  *   Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
13  *   Copyright (C) 2007 John Brooks <special@inspircd.org>
14  *
15  * This file is part of InspIRCd.  InspIRCd is free software: you can
16  * redistribute it and/or modify it under the terms of the GNU General Public
17  * License as published by the Free Software Foundation, version 2.
18  *
19  * This program is distributed in the hope that it will be useful, but WITHOUT
20  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
21  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
22  * details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
26  */
27
28
29 #include "inspircd.h"
30
31 /** Handle /CYCLE
32  */
33 class CommandCycle : public SplitCommand
34 {
35  public:
36         CommandCycle(Module* Creator)
37                 : SplitCommand(Creator, "CYCLE", 1)
38         {
39                 Penalty = 3; syntax = "<channel> [:<reason>]";
40         }
41
42         CmdResult HandleLocal(LocalUser* user, const Params& parameters) CXX11_OVERRIDE
43         {
44                 Channel* channel = ServerInstance->FindChan(parameters[0]);
45                 std::string reason = "Cycling";
46
47                 if (parameters.size() > 1)
48                 {
49                         /* reason provided, use it */
50                         reason = reason + ": " + parameters[1];
51                 }
52
53                 if (!channel)
54                 {
55                         user->WriteNumeric(Numerics::NoSuchChannel(parameters[0]));
56                         return CMD_FAILURE;
57                 }
58
59                 if (channel->HasUser(user))
60                 {
61                         if (channel->GetPrefixValue(user) < VOICE_VALUE && channel->IsBanned(user))
62                         {
63                                 // User is banned, send an error and don't cycle them
64                                 user->WriteNotice("*** You may not cycle, as you are banned on channel " + channel->name);
65                                 return CMD_FAILURE;
66                         }
67
68                         channel->PartUser(user, reason);
69                         Channel::JoinUser(user, parameters[0], true);
70
71                         return CMD_SUCCESS;
72                 }
73                 else
74                 {
75                         user->WriteNumeric(ERR_NOTONCHANNEL, channel->name, "You're not on that channel");
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         Version GetVersion() CXX11_OVERRIDE
94         {
95                 return Version("Provides the CYCLE command, acts as a server-side HOP command to part and rejoin a channel", VF_VENDOR);
96         }
97 };
98
99 MODULE_INIT(ModuleCycle)