2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2017 B00mX0r <b00mx0r@aureus.pw>
5 * Copyright (C) 2013, 2018, 2020 Sadie Powell <sadie@witchery.services>
6 * Copyright (C) 2012-2013, 2016, 2018 Attila Molnar <attilamolnar@hush.com>
7 * Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
8 * Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
9 * Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
10 * Copyright (C) 2008 Craig Edwards <brain@inspircd.org>
11 * Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
12 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
14 * This file is part of InspIRCd. InspIRCd is free software: you can
15 * redistribute it and/or modify it under the terms of the GNU General Public
16 * License as published by the Free Software Foundation, version 2.
18 * This program is distributed in the hope that it will be useful, but WITHOUT
19 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
33 ERR_CANNOTKNOCK = 480,
42 /** Handles the /KNOCK command
44 class CommandKnock : public Command
46 SimpleChannelModeHandler& noknockmode;
47 ChanModeReference inviteonlymode;
52 CommandKnock(Module* Creator, SimpleChannelModeHandler& Noknockmode)
53 : Command(Creator,"KNOCK", 2, 2)
54 , noknockmode(Noknockmode)
55 , inviteonlymode(Creator, "inviteonly")
57 syntax = "<channel> :<reason>";
61 CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
63 Channel* c = ServerInstance->FindChan(parameters[0]);
66 user->WriteNumeric(Numerics::NoSuchChannel(parameters[0]));
72 user->WriteNumeric(ERR_KNOCKONCHAN, c->name, InspIRCd::Format("Can't KNOCK on %s, you are already on that channel.", c->name.c_str()));
76 if (c->IsModeSet(noknockmode))
78 user->WriteNumeric(ERR_CANNOTKNOCK, InspIRCd::Format("Can't KNOCK on %s, +K is set.", c->name.c_str()));
82 if (!c->IsModeSet(inviteonlymode))
84 user->WriteNumeric(ERR_CHANOPEN, c->name, InspIRCd::Format("Can't KNOCK on %s, channel is not invite only so knocking is pointless!", c->name.c_str()));
90 c->WriteNotice(InspIRCd::Format("User %s is KNOCKing on %s (%s)", user->nick.c_str(), c->name.c_str(), parameters[1].c_str()));
91 user->WriteNotice("KNOCKing on " + c->name);
96 Numeric::Numeric numeric(RPL_KNOCK);
97 numeric.push(c->name).push(user->GetFullHost()).push("is KNOCKing: " + parameters[1]);
99 ClientProtocol::Messages::Numeric numericmsg(numeric, c->name);
100 c->Write(ServerInstance->GetRFCEvents().numeric, numericmsg);
102 user->WriteNumeric(RPL_KNOCKDLVR, c->name, "KNOCKing on channel");
108 RouteDescriptor GetRouting(User* user, const Params& parameters) CXX11_OVERRIDE
110 return ROUTE_OPT_BCAST;
114 class ModuleKnock : public Module
116 SimpleChannelModeHandler kn;
121 : kn(this, "noknock", 'K')
126 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
128 std::string knocknotify = ServerInstance->Config->ConfValue("knock")->getString("notify");
129 if (stdalgo::string::equalsci(knocknotify, "numeric"))
131 cmd.sendnotice = false;
132 cmd.sendnumeric = true;
134 else if (stdalgo::string::equalsci(knocknotify, "both"))
136 cmd.sendnotice = true;
137 cmd.sendnumeric = true;
141 cmd.sendnotice = true;
142 cmd.sendnumeric = false;
146 Version GetVersion() CXX11_OVERRIDE
148 return Version("Adds the /KNOCK command which allows users to request access to an invite-only channel and channel mode K (noknock) which allows channels to disable usage of this command.", VF_OPTCOMMON | VF_VENDOR);
152 MODULE_INIT(ModuleKnock)