2007-01-25 07:40:21 +01:00
|
|
|
/*
|
|
|
|
* ircd-ratbox: A slightly useful ircd.
|
|
|
|
* m_invite.c: Invites the user to join a channel.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
|
|
|
|
* 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-13 05:05:54 +02:00
|
|
|
using namespace ircd;
|
|
|
|
|
2016-03-09 08:29:41 +01:00
|
|
|
static const char invite_desc[] = "Provides facilities for invite and related notifications";
|
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
static void m_invite(struct MsgBuf *, client::client &, client::client &, int, const char **);
|
2016-03-05 09:49:10 +01:00
|
|
|
static unsigned int CAP_INVITE_NOTIFY = 0;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
struct Message invite_msgtab = {
|
2016-02-19 23:42:40 +01:00
|
|
|
"INVITE", 0, 0, 0, 0,
|
2007-01-25 07:40:21 +01:00
|
|
|
{mg_unreg, {m_invite, 3}, {m_invite, 3}, mg_ignore, mg_ignore, {m_invite, 3}}
|
|
|
|
};
|
2016-03-05 09:49:10 +01:00
|
|
|
|
2016-03-07 09:09:21 +01:00
|
|
|
mapi_clist_av1 invite_clist[] = { &invite_msgtab, NULL };
|
2016-03-05 09:49:10 +01:00
|
|
|
|
2016-03-07 09:09:21 +01:00
|
|
|
mapi_cap_list_av2 invite_cap_list[] = {
|
|
|
|
{ MAPI_CAP_CLIENT, "invite-notify", NULL, &CAP_INVITE_NOTIFY },
|
|
|
|
{ 0, NULL, NULL, NULL }
|
|
|
|
};
|
2016-03-05 09:49:10 +01:00
|
|
|
|
2016-03-07 09:09:21 +01:00
|
|
|
DECLARE_MODULE_AV2(invite, NULL, NULL, invite_clist, NULL, NULL, invite_cap_list, NULL, invite_desc);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-08-22 03:57:43 +02:00
|
|
|
static bool add_invite(chan::chan &, client::client &);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
/* m_invite()
|
|
|
|
* parv[1] - user to invite
|
|
|
|
* parv[2] - channel name
|
|
|
|
*/
|
2016-03-09 08:37:03 +01:00
|
|
|
static void
|
2016-08-23 02:37:07 +02:00
|
|
|
m_invite(struct MsgBuf *msgbuf_p, client::client &client, client::client &source, int parc, const char *parv[])
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-22 03:57:43 +02:00
|
|
|
client::client *target_p;
|
2016-08-18 07:33:38 +02:00
|
|
|
chan::chan *chptr;
|
|
|
|
chan::membership *msptr;
|
2007-01-25 07:40:21 +01:00
|
|
|
int store_invite = 0;
|
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if(my(source) && !is_flood_done(source))
|
2016-08-23 02:37:07 +02:00
|
|
|
flood_endgrace(&source);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if(my(source))
|
2016-08-22 03:57:43 +02:00
|
|
|
target_p = client::find_named_person(parv[1]);
|
2008-02-04 23:56:13 +01:00
|
|
|
else
|
2016-08-22 03:57:43 +02:00
|
|
|
target_p = client::find_person(parv[1]);
|
2008-02-04 23:56:13 +01:00
|
|
|
if(target_p == NULL)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-23 04:33:36 +02:00
|
|
|
if(!my(source) && rfc1459::is_digit(parv[1][0]))
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one_numeric(&source, ERR_NOSUCHNICK,
|
2014-03-03 05:25:47 +01:00
|
|
|
"* :Target left IRC. Failed to invite to %s",
|
2007-05-06 16:46:45 +02:00
|
|
|
parv[2]);
|
|
|
|
else
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one_numeric(&source, ERR_NOSUCHNICK,
|
2014-03-03 05:25:47 +01:00
|
|
|
form_str(ERR_NOSUCHNICK),
|
2007-05-06 16:46:45 +02:00
|
|
|
parv[1]);
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
2016-08-19 01:53:12 +02:00
|
|
|
if(chan::valid_name(parv[2]) == 0)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one_numeric(&source, ERR_BADCHANNAME,
|
2007-01-25 07:40:21 +01:00
|
|
|
form_str(ERR_BADCHANNAME),
|
|
|
|
parv[2]);
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Do not send local channel invites to users if they are not on the
|
2014-03-03 05:25:47 +01:00
|
|
|
* same server as the person sending the INVITE message.
|
2007-01-25 07:40:21 +01:00
|
|
|
*/
|
2016-08-23 04:33:36 +02:00
|
|
|
if(parv[2][0] == '&' && !my_connect(*target_p))
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one(&source, form_str(ERR_USERNOTONSERV),
|
|
|
|
me.name, source.name, target_p->name);
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if(((my_connect(source) && !is_exempt_resv(source)) ||
|
|
|
|
(my_connect(*target_p) && !is_exempt_resv(*target_p))) &&
|
2009-02-06 14:07:03 +01:00
|
|
|
hash_find_resv(parv[2]))
|
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one_numeric(&source, ERR_BADCHANNAME,
|
2009-02-06 14:07:03 +01:00
|
|
|
form_str(ERR_BADCHANNAME),
|
|
|
|
parv[2]);
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2009-02-06 14:07:03 +01:00
|
|
|
}
|
|
|
|
|
2016-08-20 04:51:37 +02:00
|
|
|
if((chptr = chan::get(parv[2], std::nothrow)) == NULL)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one_numeric(&source, ERR_NOSUCHCHANNEL,
|
2007-01-25 07:40:21 +01:00
|
|
|
form_str(ERR_NOSUCHCHANNEL), parv[2]);
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
msptr = get(chptr->members, source, std::nothrow);
|
2016-08-23 04:33:36 +02:00
|
|
|
if(my(source) && (msptr == NULL))
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one_numeric(&source, ERR_NOTONCHANNEL,
|
2007-01-25 07:40:21 +01:00
|
|
|
form_str(ERR_NOTONCHANNEL), parv[2]);
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
2016-08-18 07:33:38 +02:00
|
|
|
if(is_member(chptr, target_p))
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one_numeric(&source, ERR_USERONCHANNEL,
|
2007-01-25 07:40:21 +01:00
|
|
|
form_str(ERR_USERONCHANNEL),
|
|
|
|
target_p->name, parv[2]);
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
2007-03-13 17:09:28 +01:00
|
|
|
/* unconditionally require ops, unless the channel is +g */
|
|
|
|
/* treat remote clients as chanops */
|
2016-08-23 04:33:36 +02:00
|
|
|
if(my(source) && !is_chanop(msptr) &&
|
2016-08-17 05:01:20 +02:00
|
|
|
!(chptr->mode.mode & chan::mode::FREEINVITE))
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one(&source, form_str(ERR_CHANOPRIVSNEEDED),
|
|
|
|
me.name, source.name, parv[2]);
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
2007-03-15 19:09:08 +01:00
|
|
|
/* store invites when they could affect the ability to join
|
|
|
|
* for +l/+j just check if the mode is set, this varies over time
|
|
|
|
*/
|
2016-08-17 05:01:20 +02:00
|
|
|
if(chptr->mode.mode & chan::mode::INVITEONLY ||
|
2016-08-22 03:57:43 +02:00
|
|
|
(chptr->mode.mode & chan::mode::REGONLY && suser(user(*target_p)).empty()) ||
|
2007-03-15 19:09:08 +01:00
|
|
|
chptr->mode.limit || chptr->mode.join_num)
|
2007-03-13 17:09:28 +01:00
|
|
|
store_invite = 1;
|
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if(my_connect(source))
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-24 00:25:09 +02:00
|
|
|
if (ConfigFileEntry.target_change && !is(source, umode::OPER) &&
|
2016-08-23 02:37:07 +02:00
|
|
|
!find_allowing_channel(&source, target_p) &&
|
|
|
|
!add_target(&source, target_p))
|
2010-02-15 22:08:55 +01:00
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one(&source, form_str(ERR_TARGCHANGE),
|
|
|
|
me.name, source.name, target_p->name);
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2010-02-15 22:08:55 +01:00
|
|
|
}
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one(&source, form_str(RPL_INVITING),
|
|
|
|
me.name, source.name,
|
2007-01-25 07:40:21 +01:00
|
|
|
target_p->name, parv[2]);
|
2016-08-22 03:57:43 +02:00
|
|
|
if(away(user(*target_p)).size())
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one_numeric(&source, RPL_AWAY, form_str(RPL_AWAY),
|
2016-08-22 03:57:43 +02:00
|
|
|
target_p->name, away(user(*target_p)).c_str());
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
/* invite timestamp */
|
|
|
|
else if(parc > 3 && !EmptyString(parv[3]))
|
|
|
|
{
|
|
|
|
/* this should never be less than */
|
|
|
|
if(atol(parv[3]) > chptr->channelts)
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if(my_connect(*target_p))
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-24 00:25:09 +02:00
|
|
|
if(!is(source, umode::OPER) && (is(*target_p, umode::CALLERID) ||
|
|
|
|
(is(*target_p, umode::REGONLYMSG) && !suser(user(source))[0])) &&
|
2016-08-23 02:37:07 +02:00
|
|
|
!accept_message(&source, target_p))
|
2010-02-15 23:07:14 +01:00
|
|
|
{
|
2016-08-24 00:25:09 +02:00
|
|
|
if (is(*target_p, umode::REGONLYMSG) && !suser(user(source))[0])
|
2010-02-15 23:07:14 +01:00
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one_numeric(&source, ERR_NONONREG,
|
2010-02-15 23:07:14 +01:00
|
|
|
form_str(ERR_NONONREG),
|
|
|
|
target_p->name);
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2010-02-15 23:07:14 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* instead of sending RPL_UMODEGMSG,
|
|
|
|
* just let the invite through
|
|
|
|
*/
|
|
|
|
if((target_p->localClient->last_caller_id_time +
|
|
|
|
ConfigFileEntry.caller_id_wait) >= rb_current_time())
|
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one_numeric(&source, ERR_TARGUMODEG,
|
2010-02-15 23:07:14 +01:00
|
|
|
form_str(ERR_TARGUMODEG),
|
|
|
|
target_p->name);
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2010-02-15 23:07:14 +01:00
|
|
|
}
|
|
|
|
target_p->localClient->last_caller_id_time = rb_current_time();
|
|
|
|
}
|
|
|
|
}
|
2016-08-23 02:37:07 +02:00
|
|
|
add_reply_target(target_p, &source);
|
2014-03-03 05:25:47 +01:00
|
|
|
sendto_one(target_p, ":%s!%s@%s INVITE %s :%s",
|
2016-08-23 02:37:07 +02:00
|
|
|
source.name, source.username, source.host,
|
2016-08-18 07:33:38 +02:00
|
|
|
target_p->name, chptr->name.c_str());
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
if(store_invite)
|
2016-03-05 09:49:10 +01:00
|
|
|
{
|
2016-08-19 09:02:18 +02:00
|
|
|
if (!add_invite(*chptr, *target_p))
|
2016-06-17 03:20:50 +02:00
|
|
|
return;
|
2016-03-05 09:49:10 +01:00
|
|
|
|
2016-08-18 07:33:38 +02:00
|
|
|
sendto_channel_local_with_capability(chan::CHANOP, 0, CAP_INVITE_NOTIFY, chptr,
|
2016-03-05 09:49:10 +01:00
|
|
|
":%s NOTICE %s :%s is inviting %s to %s.",
|
2016-08-23 02:37:07 +02:00
|
|
|
me.name, chptr->name.c_str(), source.name, target_p->name, chptr->name.c_str());
|
2016-08-18 07:33:38 +02:00
|
|
|
sendto_channel_local_with_capability(chan::CHANOP, CAP_INVITE_NOTIFY, 0, chptr,
|
2016-08-23 02:37:07 +02:00
|
|
|
":%s!%s@%s INVITE %s %s", source.name, source.username,
|
|
|
|
source.host, target_p->name, chptr->name.c_str());
|
2016-03-05 09:49:10 +01:00
|
|
|
}
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
2016-03-05 09:39:11 +01:00
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_server(&source, chptr, CAP_TS6, 0, ":%s INVITE %s %s %lu",
|
|
|
|
use_id(&source), use_id(target_p),
|
2016-08-18 07:33:38 +02:00
|
|
|
chptr->name.c_str(), (unsigned long) chptr->channelts);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* add_invite()
|
|
|
|
*
|
|
|
|
* input - channel to add invite to, client to add
|
2016-06-17 03:20:50 +02:00
|
|
|
* output - true if it is a new invite, else false
|
2007-01-25 07:40:21 +01:00
|
|
|
* side effects - client is added to invite list.
|
|
|
|
*/
|
2016-06-17 03:20:50 +02:00
|
|
|
static bool
|
2016-08-22 03:57:43 +02:00
|
|
|
add_invite(chan::chan &chan, client::client &client)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-22 03:57:43 +02:00
|
|
|
if (invites(user(client)).size() >= ConfigChannel.max_chans_per_user)
|
2016-08-19 09:02:18 +02:00
|
|
|
return false;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-08-19 09:02:18 +02:00
|
|
|
if (chan.invites.size() >= ConfigChannel.max_chans_per_user)
|
|
|
|
return false;
|
2016-06-17 03:20:50 +02:00
|
|
|
|
2016-08-19 09:02:18 +02:00
|
|
|
chan.invites.emplace(&client);
|
2016-08-22 03:57:43 +02:00
|
|
|
invites(user(client)).emplace(&chan);
|
2016-06-17 03:20:50 +02:00
|
|
|
return true;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|