2007-01-24 22:40:21 -08:00
|
|
|
/*
|
|
|
|
* ircd-ratbox: A slightly useful ircd.
|
|
|
|
* m_knock.c: Requests to be invited to a channel.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1996-2002 Hybrid Development Team
|
|
|
|
* Copyright (C) 2002-2005 ircd-ratbox development team
|
|
|
|
*
|
|
|
|
* This program 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; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA
|
|
|
|
*/
|
|
|
|
|
2016-08-12 20:05:54 -07:00
|
|
|
using namespace ircd;
|
|
|
|
|
2016-03-09 01:29:41 -06:00
|
|
|
static const char knock_desc[] = "Provides the KNOCK command to ask for an invite to an invite-only channel";
|
|
|
|
|
2016-08-22 17:37:07 -07:00
|
|
|
static void m_knock(struct MsgBuf *, client::client &, client::client &, int, const char **);
|
2007-01-24 22:40:21 -08:00
|
|
|
|
|
|
|
struct Message knock_msgtab = {
|
2016-02-19 16:42:40 -06:00
|
|
|
"KNOCK", 0, 0, 0, 0,
|
2007-01-24 22:40:21 -08:00
|
|
|
{mg_unreg, {m_knock, 2}, {m_knock, 2}, mg_ignore, mg_ignore, {m_knock, 2}}
|
|
|
|
};
|
|
|
|
|
2015-12-26 22:41:09 -06:00
|
|
|
static int
|
|
|
|
_modinit(void)
|
|
|
|
{
|
2016-08-25 00:59:58 -07:00
|
|
|
supported::add("KNOCK", []
|
|
|
|
{
|
|
|
|
return ConfigChannel.use_knock;
|
|
|
|
});
|
|
|
|
|
2015-12-26 22:41:09 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_moddeinit(void)
|
|
|
|
{
|
2016-08-25 00:59:58 -07:00
|
|
|
supported::del("KNOCK");
|
2015-12-26 22:41:09 -06:00
|
|
|
}
|
|
|
|
|
2007-01-24 22:40:21 -08:00
|
|
|
mapi_clist_av1 knock_clist[] = { &knock_msgtab, NULL };
|
2016-03-07 02:11:50 -06:00
|
|
|
|
|
|
|
DECLARE_MODULE_AV2(knock, _modinit, _moddeinit, knock_clist, NULL, NULL, NULL, NULL, knock_desc);
|
2007-01-24 22:40:21 -08:00
|
|
|
|
|
|
|
/* m_knock
|
|
|
|
* parv[1] = channel
|
|
|
|
*
|
|
|
|
* The KNOCK command has the following syntax:
|
|
|
|
* :<sender> KNOCK <channel>
|
|
|
|
*
|
|
|
|
* If a user is not banned from the channel they can use the KNOCK
|
|
|
|
* command to have the server NOTICE the channel operators notifying
|
|
|
|
* they would like to join. Helpful if the channel is invite-only, the
|
|
|
|
* key is forgotten, or the channel is full (INVITE can bypass each one
|
|
|
|
* of these conditions. Concept by Dianora <db@db.net> and written by
|
|
|
|
* <anonymous>
|
|
|
|
*/
|
2016-03-09 01:37:03 -06:00
|
|
|
static void
|
2016-08-22 17:37:07 -07:00
|
|
|
m_knock(struct MsgBuf *msgbuf_p, client::client &client, client::client &source, int parc, const char *parv[])
|
2007-01-24 22:40:21 -08:00
|
|
|
{
|
2016-08-17 22:33:38 -07:00
|
|
|
chan::chan *chptr;
|
2007-01-24 22:40:21 -08:00
|
|
|
char *p, *name;
|
|
|
|
|
2016-08-22 19:33:36 -07:00
|
|
|
if(my(source) && ConfigChannel.use_knock == 0)
|
2007-01-24 22:40:21 -08:00
|
|
|
{
|
2016-08-22 17:37:07 -07:00
|
|
|
sendto_one(&source, form_str(ERR_KNOCKDISABLED),
|
|
|
|
me.name, source.name);
|
2016-03-09 01:37:03 -06:00
|
|
|
return;
|
2007-01-24 22:40:21 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
name = LOCAL_COPY(parv[1]);
|
|
|
|
|
|
|
|
/* dont allow one knock to multiple chans */
|
|
|
|
if((p = strchr(name, ',')))
|
|
|
|
*p = '\0';
|
|
|
|
|
2016-08-19 19:51:37 -07:00
|
|
|
if((chptr = chan::get(name, std::nothrow)) == NULL)
|
2007-01-24 22:40:21 -08:00
|
|
|
{
|
2016-08-22 17:37:07 -07:00
|
|
|
sendto_one_numeric(&source, ERR_NOSUCHCHANNEL,
|
2007-01-24 22:40:21 -08:00
|
|
|
form_str(ERR_NOSUCHCHANNEL), name);
|
2016-03-09 01:37:03 -06:00
|
|
|
return;
|
2007-01-24 22:40:21 -08:00
|
|
|
}
|
|
|
|
|
2016-08-22 17:37:07 -07:00
|
|
|
if(is_member(chptr, &source))
|
2007-01-24 22:40:21 -08:00
|
|
|
{
|
2016-08-22 19:33:36 -07:00
|
|
|
if(my(source))
|
2016-08-22 17:37:07 -07:00
|
|
|
sendto_one(&source, form_str(ERR_KNOCKONCHAN),
|
|
|
|
me.name, source.name, name);
|
2016-03-09 01:37:03 -06:00
|
|
|
return;
|
2007-01-24 22:40:21 -08:00
|
|
|
}
|
|
|
|
|
2016-08-16 20:01:20 -07:00
|
|
|
if(!((chptr->mode.mode & chan::mode::INVITEONLY) || (*chptr->mode.key) ||
|
2014-03-03 04:25:47 +00:00
|
|
|
(chptr->mode.limit &&
|
2016-08-19 17:32:26 -07:00
|
|
|
size(chptr->members) >= (unsigned long)chptr->mode.limit)))
|
2007-01-24 22:40:21 -08:00
|
|
|
{
|
2016-08-22 17:37:07 -07:00
|
|
|
sendto_one_numeric(&source, ERR_CHANOPEN,
|
2007-01-24 22:40:21 -08:00
|
|
|
form_str(ERR_CHANOPEN), name);
|
2016-03-09 01:37:03 -06:00
|
|
|
return;
|
2007-01-24 22:40:21 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* cant knock to a +p channel */
|
2016-08-18 16:33:46 -07:00
|
|
|
if(is_hidden(chptr))
|
2007-01-24 22:40:21 -08:00
|
|
|
{
|
2016-08-22 17:37:07 -07:00
|
|
|
sendto_one_numeric(&source, ERR_CANNOTSENDTOCHAN,
|
2007-01-24 22:40:21 -08:00
|
|
|
form_str(ERR_CANNOTSENDTOCHAN), name);
|
2016-03-09 01:37:03 -06:00
|
|
|
return;
|
2007-01-24 22:40:21 -08:00
|
|
|
}
|
|
|
|
|
2014-03-03 04:25:47 +00:00
|
|
|
|
2016-08-22 19:33:36 -07:00
|
|
|
if(my(source))
|
2007-01-24 22:40:21 -08:00
|
|
|
{
|
2016-08-18 22:58:17 -07:00
|
|
|
// don't allow a knock if the user is banned
|
2016-08-22 17:37:07 -07:00
|
|
|
if (check(*chptr, chan::mode::BAN, source) ||
|
|
|
|
check(*chptr, chan::mode::QUIET, source))
|
2007-01-24 22:40:21 -08:00
|
|
|
{
|
2016-08-22 17:37:07 -07:00
|
|
|
sendto_one_numeric(&source, ERR_CANNOTSENDTOCHAN, form_str(ERR_CANNOTSENDTOCHAN), name);
|
2016-03-09 01:37:03 -06:00
|
|
|
return;
|
2007-01-24 22:40:21 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* local flood protection:
|
|
|
|
* allow one knock per user per knock_delay
|
|
|
|
* allow one knock per channel per knock_delay_channel
|
|
|
|
*/
|
2016-08-23 15:25:09 -07:00
|
|
|
if(!is(source, umode::OPER) &&
|
2016-08-22 17:37:07 -07:00
|
|
|
(source.localClient->last_knock + ConfigChannel.knock_delay) > rb_current_time())
|
2007-01-24 22:40:21 -08:00
|
|
|
{
|
2016-08-22 17:37:07 -07:00
|
|
|
sendto_one(&source, form_str(ERR_TOOMANYKNOCK),
|
|
|
|
me.name, source.name, name, "user");
|
2016-03-09 01:37:03 -06:00
|
|
|
return;
|
2007-01-24 22:40:21 -08:00
|
|
|
}
|
2008-04-02 03:53:20 +04:00
|
|
|
else if((chptr->last_knock + ConfigChannel.knock_delay_channel) > rb_current_time())
|
2007-01-24 22:40:21 -08:00
|
|
|
{
|
2016-08-22 17:37:07 -07:00
|
|
|
sendto_one(&source, form_str(ERR_TOOMANYKNOCK),
|
|
|
|
me.name, source.name, name, "channel");
|
2016-03-09 01:37:03 -06:00
|
|
|
return;
|
2007-01-24 22:40:21 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ok, we actually can send the knock, tell client */
|
2016-08-22 17:37:07 -07:00
|
|
|
source.localClient->last_knock = rb_current_time();
|
2007-01-24 22:40:21 -08:00
|
|
|
|
2016-08-22 17:37:07 -07:00
|
|
|
sendto_one(&source, form_str(RPL_KNOCKDLVR),
|
|
|
|
me.name, source.name, name);
|
2007-01-24 22:40:21 -08:00
|
|
|
}
|
|
|
|
|
2008-04-02 03:53:20 +04:00
|
|
|
chptr->last_knock = rb_current_time();
|
2007-01-24 22:40:21 -08:00
|
|
|
|
|
|
|
if(ConfigChannel.use_knock)
|
2016-08-17 22:33:38 -07:00
|
|
|
sendto_channel_local(chptr->mode.mode & chan::mode::FREEINVITE ? chan::ALL_MEMBERS : chan::ONLY_CHANOPS,
|
2007-09-09 12:19:23 -07:00
|
|
|
chptr, form_str(RPL_KNOCK),
|
2016-08-22 17:37:07 -07:00
|
|
|
me.name, name, name, source.name,
|
|
|
|
source.username, source.host);
|
2007-01-24 22:40:21 -08:00
|
|
|
|
2016-08-22 17:37:07 -07:00
|
|
|
sendto_server(&client, chptr, CAP_KNOCK|CAP_TS6, NOCAPS,
|
|
|
|
":%s KNOCK %s", use_id(&source), name);
|
|
|
|
sendto_server(&client, chptr, CAP_KNOCK, CAP_TS6,
|
|
|
|
":%s KNOCK %s", source.name, name);
|
2007-01-24 22:40:21 -08:00
|
|
|
}
|
|
|
|
|