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,
40 /** Handles the /KNOCK command
42 class CommandKnock : public Command
44 SimpleChannelModeHandler& noknockmode;
45 ChanModeReference inviteonlymode;
50 CommandKnock(Module* Creator, SimpleChannelModeHandler& Noknockmode)
51 : Command(Creator,"KNOCK", 2, 2)
52 , noknockmode(Noknockmode)
53 , inviteonlymode(Creator, "inviteonly")
55 syntax = "<channel> :<reason>";
59 CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
61 Channel* c = ServerInstance->FindChan(parameters[0]);
64 user->WriteNumeric(Numerics::NoSuchChannel(parameters[0]));
70 user->WriteNumeric(ERR_KNOCKONCHAN, c->name, InspIRCd::Format("Can't KNOCK on %s, you are already on that channel.", c->name.c_str()));
74 if (c->IsModeSet(noknockmode))
76 user->WriteNumeric(ERR_CANNOTKNOCK, InspIRCd::Format("Can't KNOCK on %s, +K is set.", c->name.c_str()));
80 if (!c->IsModeSet(inviteonlymode))
82 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()));
87 c->WriteNotice(InspIRCd::Format("User %s is KNOCKing on %s (%s)", user->nick.c_str(), c->name.c_str(), parameters[1].c_str()));
91 Numeric::Numeric numeric(710);
92 numeric.push(c->name).push(user->GetFullHost()).push("is KNOCKing: " + parameters[1]);
94 ClientProtocol::Messages::Numeric numericmsg(numeric, c->name);
95 c->Write(ServerInstance->GetRFCEvents().numeric, numericmsg);
98 user->WriteNotice("KNOCKing on " + c->name);
102 RouteDescriptor GetRouting(User* user, const Params& parameters) CXX11_OVERRIDE
104 return ROUTE_OPT_BCAST;
108 class ModuleKnock : public Module
110 SimpleChannelModeHandler kn;
115 : kn(this, "noknock", 'K')
120 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
122 std::string knocknotify = ServerInstance->Config->ConfValue("knock")->getString("notify");
123 if (stdalgo::string::equalsci(knocknotify, "numeric"))
125 cmd.sendnotice = false;
126 cmd.sendnumeric = true;
128 else if (stdalgo::string::equalsci(knocknotify, "both"))
130 cmd.sendnotice = true;
131 cmd.sendnumeric = true;
135 cmd.sendnotice = true;
136 cmd.sendnumeric = false;
140 Version GetVersion() CXX11_OVERRIDE
142 return Version("Provides the KNOCK command and channel mode +K", VF_OPTCOMMON | VF_VENDOR);
146 MODULE_INIT(ModuleKnock)