2007-01-25 07:40:21 +01:00
|
|
|
/*
|
|
|
|
* ircd-ratbox: A slightly useful ircd.
|
|
|
|
* m_part.c: Parts a user from 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-07 08:02:19 +01:00
|
|
|
static const char part_desc[] = "Provides the PART command to leave a channel";
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
static void m_part(struct MsgBuf *, client::client &, client::client &, int, const char **);
|
2016-03-09 08:29:41 +01:00
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
struct Message part_msgtab = {
|
2016-02-19 23:42:40 +01:00
|
|
|
"PART", 0, 0, 0, 0,
|
2007-01-25 07:40:21 +01:00
|
|
|
{mg_unreg, {m_part, 2}, {m_part, 2}, mg_ignore, mg_ignore, {m_part, 2}}
|
|
|
|
};
|
|
|
|
|
|
|
|
mapi_clist_av1 part_clist[] = { &part_msgtab, NULL };
|
|
|
|
|
2016-03-07 08:02:19 +01:00
|
|
|
DECLARE_MODULE_AV2(part, NULL, NULL, part_clist, NULL, NULL, NULL, NULL, part_desc);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
static void part_one_client(client::client &client,
|
|
|
|
client::client &source, char *name,
|
2014-02-23 22:55:22 +01:00
|
|
|
const char *reason);
|
2016-08-23 02:37:07 +02:00
|
|
|
static bool can_send_part(client::client &source, chan::chan *chptr, chan::membership *msptr);
|
|
|
|
static bool do_message_hook(client::client &source, chan::chan *chptr, const char **reason);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
** m_part
|
|
|
|
** parv[1] = channel
|
|
|
|
** parv[2] = reason
|
|
|
|
*/
|
2016-03-09 08:37:03 +01:00
|
|
|
static void
|
2016-08-23 02:37:07 +02:00
|
|
|
m_part(struct MsgBuf *msgbuf_p, client::client &client, client::client &source, int parc, const char *parv[])
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
char *p, *name;
|
|
|
|
char reason[REASONLEN + 1];
|
|
|
|
char *s = LOCAL_COPY(parv[1]);
|
|
|
|
|
|
|
|
reason[0] = '\0';
|
|
|
|
|
|
|
|
if(parc > 2)
|
2008-04-20 06:40:40 +02:00
|
|
|
rb_strlcpy(reason, parv[2], sizeof(reason));
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2008-04-20 07:20:25 +02:00
|
|
|
name = rb_strtok_r(s, ",", &p);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
/* Finish the flood grace period... */
|
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
|
|
|
|
|
|
|
while(name)
|
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
part_one_client(client, source, name, reason);
|
2008-04-20 07:20:25 +02:00
|
|
|
name = rb_strtok_r(NULL, ",", &p);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* part_one_client
|
|
|
|
*
|
|
|
|
* inputs - pointer to server
|
|
|
|
* - pointer to source client to remove
|
|
|
|
* - char pointer of name of channel to remove from
|
|
|
|
* output - none
|
2014-03-03 05:25:47 +01:00
|
|
|
* side effects - remove ONE client given the channel name
|
2007-01-25 07:40:21 +01:00
|
|
|
*/
|
|
|
|
static void
|
2016-08-23 02:37:07 +02:00
|
|
|
part_one_client(client::client &client, client::client &source, char *name, const char *reason)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-18 07:33:38 +02:00
|
|
|
chan::chan *chptr;
|
|
|
|
chan::membership *msptr;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-08-20 04:51:37 +02:00
|
|
|
if((chptr = chan::get(name, 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, form_str(ERR_NOSUCHCHANNEL), name);
|
2007-01-25 07:40:21 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
msptr = get(chptr->members, source, std::nothrow);
|
2007-01-25 07:40:21 +01:00
|
|
|
if(msptr == NULL)
|
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one_numeric(&source, ERR_NOTONCHANNEL, form_str(ERR_NOTONCHANNEL), name);
|
2007-01-25 07:40:21 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-24 00:25:09 +02:00
|
|
|
if(my_connect(source) && !is(source, umode::OPER) && !is_exempt_spambot(source))
|
2016-08-23 02:37:07 +02:00
|
|
|
chan::check_spambot_warning(&source, NULL);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove user from the old channel (if any)
|
|
|
|
* only allow /part reasons in -m chans
|
|
|
|
*/
|
2012-04-07 05:03:07 +02:00
|
|
|
if(!EmptyString(reason) &&
|
2016-08-23 04:33:36 +02:00
|
|
|
(!my_connect(source) ||
|
2016-08-23 02:37:07 +02:00
|
|
|
(can_send_part(source, chptr, msptr) && do_message_hook(source, chptr, &reason))
|
2012-04-07 05:03:07 +02:00
|
|
|
)
|
|
|
|
)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2012-04-07 05:03:07 +02:00
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_server(&client, chptr, CAP_TS6, NOCAPS,
|
2016-08-18 07:33:38 +02:00
|
|
|
":%s PART %s :%s",
|
2016-08-23 02:37:07 +02:00
|
|
|
use_id(&source),
|
2016-08-18 07:33:38 +02:00
|
|
|
chptr->name.c_str(),
|
|
|
|
reason);
|
|
|
|
|
|
|
|
sendto_channel_local(chan::ALL_MEMBERS, chptr,
|
|
|
|
":%s!%s@%s PART %s :%s",
|
2016-08-23 02:37:07 +02:00
|
|
|
source.name,
|
|
|
|
source.username,
|
|
|
|
source.host,
|
2016-08-18 07:33:38 +02:00
|
|
|
chptr->name.c_str(),
|
|
|
|
reason);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_server(&client, chptr, CAP_TS6, NOCAPS,
|
2016-08-18 07:33:38 +02:00
|
|
|
":%s PART %s",
|
2016-08-23 02:37:07 +02:00
|
|
|
use_id(&source),
|
2016-08-18 07:33:38 +02:00
|
|
|
chptr->name.c_str());
|
|
|
|
|
|
|
|
sendto_channel_local(chan::ALL_MEMBERS, chptr,
|
|
|
|
":%s!%s@%s PART %s",
|
2016-08-23 02:37:07 +02:00
|
|
|
source.name,
|
|
|
|
source.username,
|
|
|
|
source.host,
|
2016-08-18 07:33:38 +02:00
|
|
|
chptr->name.c_str());
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
2016-08-18 07:33:38 +02:00
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
del(*chptr, source);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
2012-04-07 05:03:07 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* can_send_part - whether a part message can be sent.
|
|
|
|
*
|
|
|
|
* inputs:
|
|
|
|
* - client parting
|
|
|
|
* - channel being parted
|
|
|
|
* - membership pointer
|
|
|
|
* outputs:
|
2016-03-09 08:37:03 +01:00
|
|
|
* - true if message allowed
|
|
|
|
* - false if message denied
|
2012-04-07 05:03:07 +02:00
|
|
|
* side effects:
|
|
|
|
* - none.
|
|
|
|
*/
|
2016-03-09 08:37:03 +01:00
|
|
|
static bool
|
2016-08-23 02:37:07 +02:00
|
|
|
can_send_part(client::client &source, chan::chan *chptr, chan::membership *msptr)
|
2012-04-07 05:03:07 +02:00
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
if (!can_send(chptr, &source, msptr))
|
2016-03-09 08:37:03 +01:00
|
|
|
return false;
|
2012-04-07 05:03:07 +02:00
|
|
|
/* Allow chanops to bypass anti_spam_exit_message_time for part messages. */
|
|
|
|
if (is_chanop(msptr))
|
2016-03-09 08:37:03 +01:00
|
|
|
return true;
|
2016-08-23 02:37:07 +02:00
|
|
|
return (source.localClient->firsttime + ConfigFileEntry.anti_spam_exit_message_time) < rb_current_time();
|
2012-04-07 05:03:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* do_message_hook - execute the message hook on a part message reason.
|
|
|
|
*
|
|
|
|
* inputs:
|
|
|
|
* - client parting
|
|
|
|
* - channel being parted
|
|
|
|
* - pointer to reason
|
|
|
|
* outputs:
|
2016-03-09 08:37:03 +01:00
|
|
|
* - true if message is allowed
|
|
|
|
* - false if message is denied or message is now empty
|
2012-04-07 05:03:07 +02:00
|
|
|
* side effects:
|
|
|
|
* - reason may be modified.
|
|
|
|
*/
|
2016-03-09 08:37:03 +01:00
|
|
|
static bool
|
2016-08-23 02:37:07 +02:00
|
|
|
do_message_hook(client::client &source, chan::chan *chptr, const char **reason)
|
2012-04-07 05:03:07 +02:00
|
|
|
{
|
|
|
|
hook_data_privmsg_channel hdata;
|
|
|
|
|
|
|
|
hdata.msgtype = MESSAGE_TYPE_PART;
|
2016-08-23 02:37:07 +02:00
|
|
|
hdata.source_p = &source;
|
2012-04-07 05:03:07 +02:00
|
|
|
hdata.chptr = chptr;
|
|
|
|
hdata.text = *reason;
|
|
|
|
hdata.approved = 0;
|
|
|
|
|
|
|
|
call_hook(h_privmsg_channel, &hdata);
|
|
|
|
|
|
|
|
/* The reason may have been changed by a hook... */
|
|
|
|
*reason = hdata.text;
|
|
|
|
|
|
|
|
return (hdata.approved == 0 && !EmptyString(*reason));
|
|
|
|
}
|