2012-04-19 20:58:29 +02:00
|
|
|
/*
|
|
|
|
* InspIRCd -- Internet Relay Chat Daemon
|
2007-07-16 17:30:04 +00:00
|
|
|
*
|
2020-01-11 22:02:47 +00:00
|
|
|
* Copyright (C) 2017 B00mX0r <b00mx0r@aureus.pw>
|
2020-01-31 12:48:25 +00:00
|
|
|
* Copyright (C) 2013, 2018, 2020 Sadie Powell <sadie@witchery.services>
|
2020-01-11 22:02:47 +00:00
|
|
|
* Copyright (C) 2012-2013, 2016, 2018 Attila Molnar <attilamolnar@hush.com>
|
|
|
|
* Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
|
|
|
|
* Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
|
|
|
|
* Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
|
|
|
|
* Copyright (C) 2008 Craig Edwards <brain@inspircd.org>
|
2012-04-19 20:58:29 +02:00
|
|
|
* Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
|
2020-01-11 22:02:47 +00:00
|
|
|
* Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
|
2007-07-16 17:30:04 +00:00
|
|
|
*
|
2012-04-19 20:58:29 +02:00
|
|
|
* This file is part of InspIRCd. InspIRCd is free software: you can
|
|
|
|
* redistribute it and/or modify it under the terms of the GNU General Public
|
|
|
|
* License as published by the Free Software Foundation, version 2.
|
2007-07-16 17:30:04 +00:00
|
|
|
*
|
2012-04-19 20:58:29 +02:00
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
* details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2007-07-16 17:30:04 +00:00
|
|
|
*/
|
|
|
|
|
2012-04-19 20:58:29 +02:00
|
|
|
|
2007-07-16 17:30:04 +00:00
|
|
|
#include "inspircd.h"
|
|
|
|
|
2018-01-27 12:24:47 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
// From UnrealIRCd.
|
2018-04-22 14:31:28 +01:00
|
|
|
ERR_CANNOTKNOCK = 480,
|
|
|
|
|
|
|
|
// From ircd-ratbox.
|
|
|
|
ERR_CHANOPEN = 713,
|
|
|
|
ERR_KNOCKONCHAN = 714
|
2018-01-27 12:24:47 +00:00
|
|
|
};
|
|
|
|
|
2007-07-16 17:30:04 +00:00
|
|
|
/** Handles the /KNOCK command
|
|
|
|
*/
|
2007-10-21 21:43:48 +00:00
|
|
|
class CommandKnock : public Command
|
2007-07-16 17:30:04 +00:00
|
|
|
{
|
2013-06-18 18:30:10 +02:00
|
|
|
SimpleChannelModeHandler& noknockmode;
|
|
|
|
ChanModeReference inviteonlymode;
|
|
|
|
|
2007-07-16 17:30:04 +00:00
|
|
|
public:
|
2012-09-13 01:15:44 +02:00
|
|
|
bool sendnotice;
|
|
|
|
bool sendnumeric;
|
2013-06-18 18:30:10 +02:00
|
|
|
CommandKnock(Module* Creator, SimpleChannelModeHandler& Noknockmode)
|
|
|
|
: Command(Creator,"KNOCK", 2, 2)
|
|
|
|
, noknockmode(Noknockmode)
|
|
|
|
, inviteonlymode(Creator, "inviteonly")
|
2007-07-16 17:30:04 +00:00
|
|
|
{
|
2019-02-17 15:58:31 +01:00
|
|
|
syntax = "<channel> :<reason>";
|
2010-01-31 19:54:33 +00:00
|
|
|
Penalty = 5;
|
2007-07-16 17:30:04 +00:00
|
|
|
}
|
2008-06-11 11:35:23 +00:00
|
|
|
|
2018-07-26 19:43:54 +01:00
|
|
|
CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
|
2007-07-16 17:30:04 +00:00
|
|
|
{
|
2007-10-15 20:59:05 +00:00
|
|
|
Channel* c = ServerInstance->FindChan(parameters[0]);
|
2007-07-16 17:30:04 +00:00
|
|
|
if (!c)
|
|
|
|
{
|
2017-12-19 14:15:30 -08:00
|
|
|
user->WriteNumeric(Numerics::NoSuchChannel(parameters[0]));
|
2007-07-16 17:30:04 +00:00
|
|
|
return CMD_FAILURE;
|
|
|
|
}
|
|
|
|
|
2008-01-30 01:07:14 +00:00
|
|
|
if (c->HasUser(user))
|
2007-07-16 17:30:04 +00:00
|
|
|
{
|
2016-02-25 16:12:09 +01:00
|
|
|
user->WriteNumeric(ERR_KNOCKONCHAN, c->name, InspIRCd::Format("Can't KNOCK on %s, you are already on that channel.", c->name.c_str()));
|
2007-07-16 17:30:04 +00:00
|
|
|
return CMD_FAILURE;
|
|
|
|
}
|
|
|
|
|
2013-06-18 18:30:10 +02:00
|
|
|
if (c->IsModeSet(noknockmode))
|
2007-07-16 17:30:04 +00:00
|
|
|
{
|
2018-01-27 12:24:47 +00:00
|
|
|
user->WriteNumeric(ERR_CANNOTKNOCK, InspIRCd::Format("Can't KNOCK on %s, +K is set.", c->name.c_str()));
|
2008-01-30 01:07:14 +00:00
|
|
|
return CMD_FAILURE;
|
2007-07-16 17:30:04 +00:00
|
|
|
}
|
|
|
|
|
2013-06-18 18:30:10 +02:00
|
|
|
if (!c->IsModeSet(inviteonlymode))
|
2007-07-16 17:30:04 +00:00
|
|
|
{
|
2016-02-25 16:12:09 +01:00
|
|
|
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()));
|
2007-07-16 17:30:04 +00:00
|
|
|
return CMD_FAILURE;
|
|
|
|
}
|
|
|
|
|
2012-09-13 01:15:44 +02:00
|
|
|
if (sendnotice)
|
2020-01-29 14:14:25 +00:00
|
|
|
c->WriteNotice(InspIRCd::Format("User %s is KNOCKing on %s (%s)", user->nick.c_str(), c->name.c_str(), parameters[1].c_str()));
|
2012-09-13 01:15:44 +02:00
|
|
|
|
|
|
|
if (sendnumeric)
|
2018-08-13 20:17:46 +01:00
|
|
|
{
|
|
|
|
Numeric::Numeric numeric(710);
|
|
|
|
numeric.push(c->name).push(user->GetFullHost()).push("is KNOCKing: " + parameters[1]);
|
|
|
|
|
|
|
|
ClientProtocol::Messages::Numeric numericmsg(numeric, c->name);
|
|
|
|
c->Write(ServerInstance->GetRFCEvents().numeric, numericmsg);
|
|
|
|
}
|
2012-09-13 01:15:44 +02:00
|
|
|
|
2013-04-28 12:17:53 +01:00
|
|
|
user->WriteNotice("KNOCKing on " + c->name);
|
2007-07-16 17:30:04 +00:00
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
2009-09-03 15:53:15 +00:00
|
|
|
|
2018-07-26 19:43:54 +01:00
|
|
|
RouteDescriptor GetRouting(User* user, const Params& parameters) CXX11_OVERRIDE
|
2009-09-03 15:53:15 +00:00
|
|
|
{
|
2010-01-19 15:16:24 +00:00
|
|
|
return ROUTE_OPT_BCAST;
|
2009-09-03 15:53:15 +00:00
|
|
|
}
|
2007-07-16 17:30:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class ModuleKnock : public Module
|
|
|
|
{
|
2013-06-18 18:30:10 +02:00
|
|
|
SimpleChannelModeHandler kn;
|
2009-09-02 00:43:04 +00:00
|
|
|
CommandKnock cmd;
|
2013-06-18 18:30:10 +02:00
|
|
|
|
2007-07-16 17:30:04 +00:00
|
|
|
public:
|
2013-06-18 18:30:10 +02:00
|
|
|
ModuleKnock()
|
|
|
|
: kn(this, "noknock", 'K')
|
|
|
|
, cmd(this, kn)
|
2012-10-13 03:12:29 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-08-16 12:10:55 +02:00
|
|
|
void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
|
2007-07-16 17:30:04 +00:00
|
|
|
{
|
2012-09-13 01:15:44 +02:00
|
|
|
std::string knocknotify = ServerInstance->Config->ConfValue("knock")->getString("notify");
|
2016-08-22 16:46:44 +02:00
|
|
|
if (stdalgo::string::equalsci(knocknotify, "numeric"))
|
2012-09-13 01:15:44 +02:00
|
|
|
{
|
|
|
|
cmd.sendnotice = false;
|
|
|
|
cmd.sendnumeric = true;
|
|
|
|
}
|
2016-08-22 16:46:44 +02:00
|
|
|
else if (stdalgo::string::equalsci(knocknotify, "both"))
|
2012-09-13 01:15:44 +02:00
|
|
|
{
|
|
|
|
cmd.sendnotice = true;
|
|
|
|
cmd.sendnumeric = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cmd.sendnotice = true;
|
|
|
|
cmd.sendnumeric = false;
|
|
|
|
}
|
2007-07-16 17:30:04 +00:00
|
|
|
}
|
|
|
|
|
2013-04-30 08:38:33 +01:00
|
|
|
Version GetVersion() CXX11_OVERRIDE
|
2007-07-16 17:30:04 +00:00
|
|
|
{
|
2019-04-28 10:14:21 +02:00
|
|
|
return Version("Provides the KNOCK command and channel mode +K", VF_OPTCOMMON | VF_VENDOR);
|
2007-07-16 17:30:04 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_INIT(ModuleKnock)
|