]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_cycle.cpp
Add support for blocking tag messages with the deaf mode.
[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, 2020 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;
40                 syntax = "<channel> [:<reason>]";
41         }
42
43         CmdResult HandleLocal(LocalUser* user, const Params& parameters) CXX11_OVERRIDE
44         {
45                 Channel* channel = ServerInstance->FindChan(parameters[0]);
46                 std::string reason = "Cycling";
47
48                 if (parameters.size() > 1)
49                 {
50                         /* reason provided, use it */
51                         reason = reason + ": " + parameters[1];
52                 }
53
54                 if (!channel)
55                 {
56                         user->WriteNumeric(Numerics::NoSuchChannel(parameters[0]));
57                         return CMD_FAILURE;
58                 }
59
60                 if (channel->HasUser(user))
61                 {
62                         if (channel->GetPrefixValue(user) < VOICE_VALUE && channel->IsBanned(user))
63                         {
64                                 // User is banned, send an error and don't cycle them
65                                 user->WriteNotice("*** You may not cycle, as you are banned on channel " + channel->name);
66                                 return CMD_FAILURE;
67                         }
68
69                         channel->PartUser(user, reason);
70                         Channel::JoinUser(user, parameters[0], true);
71
72                         return CMD_SUCCESS;
73                 }
74                 else
75                 {
76                         user->WriteNumeric(ERR_NOTONCHANNEL, channel->name, "You're not on that channel");
77                 }
78
79                 return CMD_FAILURE;
80         }
81 };
82
83
84 class ModuleCycle : public Module
85 {
86         CommandCycle cmd;
87
88  public:
89         ModuleCycle()
90                 : cmd(this)
91         {
92         }
93
94         Version GetVersion() CXX11_OVERRIDE
95         {
96                 return Version("Allows channel members to part and rejoin a channel without needing to worry about channel modes such as +i (inviteonly) which might prevent rejoining.", VF_VENDOR);
97         }
98 };
99
100 MODULE_INIT(ModuleCycle)