2007-01-25 07:40:21 +01:00
|
|
|
/*
|
|
|
|
* ircd-ratbox: A slightly useful ircd.
|
|
|
|
* send.c: Functions for sending messages.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
namespace ircd {
|
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
/* send the message to the link the target is attached to */
|
|
|
|
#define send_linebuf(a,b) _send_linebuf((a->from ? a->from : a) ,b)
|
|
|
|
|
2008-04-01 23:51:34 +02:00
|
|
|
static void send_queued_write(rb_fde_t *F, void *data);
|
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
unsigned long current_serial = 0L;
|
|
|
|
|
2016-08-22 03:57:43 +02:00
|
|
|
client::client *remote_rehash_oper_p;
|
2009-03-07 01:27:05 +01:00
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
/* send_linebuf()
|
|
|
|
*
|
|
|
|
* inputs - client to send to, linebuf to attach
|
|
|
|
* outputs -
|
|
|
|
* side effects - linebuf is attached to client
|
|
|
|
*/
|
|
|
|
static int
|
2016-08-22 03:57:43 +02:00
|
|
|
_send_linebuf(client::client *to, buf_head_t *linebuf)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-23 04:33:36 +02:00
|
|
|
if(is_me(*to))
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-26 13:50:12 +02:00
|
|
|
sendto_realops_snomask(sno::GENERAL, L_ALL, "Trying to send message to myself!");
|
2007-01-25 07:40:21 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if(!my_connect(*to) || is_io_error(*to))
|
2007-01-25 07:40:21 +01:00
|
|
|
return 0;
|
|
|
|
|
2016-01-21 04:27:33 +01:00
|
|
|
if(rb_linebuf_len(&to->localClient->buf_sendq) > get_sendq(to))
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-23 04:33:36 +02:00
|
|
|
if(is_server(*to))
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-26 13:50:12 +02:00
|
|
|
sendto_realops_snomask(sno::GENERAL, L_ALL,
|
2016-01-21 04:27:33 +01:00
|
|
|
"Max SendQ limit exceeded for %s: %u > %lu",
|
2008-06-28 12:13:50 +02:00
|
|
|
to->name,
|
2014-03-03 05:25:47 +01:00
|
|
|
rb_linebuf_len(&to->localClient->buf_sendq),
|
2016-01-21 04:27:33 +01:00
|
|
|
get_sendq(to));
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-01-21 04:27:33 +01:00
|
|
|
ilog(L_SERVER, "Max SendQ limit exceeded for %s: %u > %lu",
|
2007-01-25 07:40:21 +01:00
|
|
|
log_client_name(to, SHOW_IP),
|
2014-03-03 05:25:47 +01:00
|
|
|
rb_linebuf_len(&to->localClient->buf_sendq),
|
2016-01-21 04:27:33 +01:00
|
|
|
get_sendq(to));
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
2009-12-21 16:58:25 +01:00
|
|
|
dead_link(to, 1);
|
2007-01-25 07:40:21 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* just attach the linebuf to the sendq instead of
|
|
|
|
* generating a new one
|
|
|
|
*/
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_linebuf_attach(&to->localClient->buf_sendq, linebuf);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Update statistics. The following is slightly incorrect
|
|
|
|
** because it counts messages even if queued, but bytes
|
|
|
|
** only really sent. Queued bytes get updated in SendQueued.
|
|
|
|
*/
|
|
|
|
to->localClient->sendM += 1;
|
|
|
|
me.localClient->sendM += 1;
|
2008-04-01 23:51:34 +02:00
|
|
|
if(rb_linebuf_len(&to->localClient->buf_sendq) > 0)
|
|
|
|
send_queued(to);
|
2007-01-25 07:40:21 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* send_linebuf_remote()
|
|
|
|
*
|
|
|
|
* inputs - client to attach to, sender, linebuf
|
|
|
|
* outputs -
|
|
|
|
* side effects - client has linebuf attached
|
|
|
|
*/
|
|
|
|
static void
|
2016-08-22 03:57:43 +02:00
|
|
|
send_linebuf_remote(client::client *to, client::client *from, buf_head_t *linebuf)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
if(to->from)
|
|
|
|
to = to->from;
|
|
|
|
|
2008-01-17 01:06:32 +01:00
|
|
|
/* we assume the caller has already tested for fake direction */
|
2007-01-25 07:40:21 +01:00
|
|
|
_send_linebuf(to, linebuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* send_queued_write()
|
|
|
|
*
|
|
|
|
* inputs - fd to have queue sent, client we're sending to
|
|
|
|
* outputs - contents of queue
|
|
|
|
* side effects - write is rescheduled if queue isnt emptied
|
|
|
|
*/
|
|
|
|
void
|
2016-08-22 03:57:43 +02:00
|
|
|
send_queued(client::client *to)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
int retlen;
|
2016-02-20 19:02:49 +01:00
|
|
|
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_fde_t *F = to->localClient->F;
|
2007-12-22 23:28:05 +01:00
|
|
|
if (!F)
|
|
|
|
return;
|
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
/* cant write anything to a dead socket. */
|
2016-08-23 04:33:36 +02:00
|
|
|
if(is_io_error(*to))
|
2007-01-25 07:40:21 +01:00
|
|
|
return;
|
|
|
|
|
2008-04-13 17:54:23 +02:00
|
|
|
/* try to flush later when the write event resets this */
|
|
|
|
if(IsFlush(to))
|
2008-04-06 16:52:42 +02:00
|
|
|
return;
|
|
|
|
|
2008-04-01 23:51:34 +02:00
|
|
|
if(rb_linebuf_len(&to->localClient->buf_sendq))
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
while ((retlen =
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_linebuf_flush(F, &to->localClient->buf_sendq)) > 0)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
/* We have some data written .. update counters */
|
2008-04-06 16:52:42 +02:00
|
|
|
ClearFlush(to);
|
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
to->localClient->sendB += retlen;
|
|
|
|
me.localClient->sendB += retlen;
|
|
|
|
if(to->localClient->sendB > 1023)
|
|
|
|
{
|
|
|
|
to->localClient->sendK += (to->localClient->sendB >> 10);
|
|
|
|
to->localClient->sendB &= 0x03ff; /* 2^10 = 1024, 3ff = 1023 */
|
|
|
|
}
|
|
|
|
else if(me.localClient->sendB > 1023)
|
|
|
|
{
|
|
|
|
me.localClient->sendK += (me.localClient->sendB >> 10);
|
|
|
|
me.localClient->sendB &= 0x03ff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-01 23:51:34 +02:00
|
|
|
if(retlen == 0 || (retlen < 0 && !rb_ignore_errno(errno)))
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2009-12-21 16:58:25 +01:00
|
|
|
dead_link(to, 0);
|
2007-01-25 07:40:21 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2008-04-06 16:52:42 +02:00
|
|
|
|
2008-04-13 17:54:23 +02:00
|
|
|
if(rb_linebuf_len(&to->localClient->buf_sendq))
|
|
|
|
{
|
|
|
|
SetFlush(to);
|
|
|
|
rb_setselect(to->localClient->F, RB_SELECT_WRITE,
|
|
|
|
send_queued_write, to);
|
|
|
|
}
|
|
|
|
else
|
2008-04-06 16:52:42 +02:00
|
|
|
ClearFlush(to);
|
|
|
|
}
|
|
|
|
|
2008-04-13 17:54:23 +02:00
|
|
|
void
|
2016-08-22 03:57:43 +02:00
|
|
|
send_pop_queue(client::client *to)
|
2008-04-13 17:54:23 +02:00
|
|
|
{
|
|
|
|
if(to->from != NULL)
|
|
|
|
to = to->from;
|
2016-08-23 04:33:36 +02:00
|
|
|
if(!my_connect(*to) || is_io_error(*to))
|
2008-04-13 17:54:23 +02:00
|
|
|
return;
|
|
|
|
if(rb_linebuf_len(&to->localClient->buf_sendq) > 0)
|
|
|
|
send_queued(to);
|
2008-04-01 23:51:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* send_queued_write()
|
|
|
|
*
|
|
|
|
* inputs - fd to have queue sent, client we're sending to
|
|
|
|
* outputs - contents of queue
|
|
|
|
* side effects - write is scheduled if queue isnt emptied
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
send_queued_write(rb_fde_t *F, void *data)
|
|
|
|
{
|
2016-08-22 03:57:43 +02:00
|
|
|
client::client *to = (client::client *)data;
|
2008-04-06 16:52:42 +02:00
|
|
|
ClearFlush(to);
|
2008-04-01 23:51:34 +02:00
|
|
|
send_queued(to);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
2016-02-20 23:37:19 +01:00
|
|
|
/*
|
|
|
|
* linebuf_put_msgvbuf
|
2016-02-20 22:49:41 +01:00
|
|
|
*
|
|
|
|
* inputs - msgbuf header, linebuf object, capability mask, pattern, arguments
|
|
|
|
* outputs - none
|
|
|
|
* side effects - the linebuf object is cleared, then populated using rb_linebuf_putmsg().
|
|
|
|
*/
|
|
|
|
static void
|
2016-02-20 23:37:19 +01:00
|
|
|
linebuf_put_msgvbuf(struct MsgBuf *msgbuf, buf_head_t *linebuf, unsigned int capmask, const char *pattern, va_list *va)
|
2016-02-20 22:49:41 +01:00
|
|
|
{
|
2016-03-23 15:22:55 +01:00
|
|
|
char buf[BUFSIZE];
|
2016-02-20 22:49:41 +01:00
|
|
|
|
|
|
|
rb_linebuf_newbuf(linebuf);
|
|
|
|
msgbuf_unparse_prefix(buf, sizeof buf, msgbuf, capmask);
|
2016-02-20 23:37:19 +01:00
|
|
|
rb_linebuf_putprefix(linebuf, pattern, va, buf);
|
2016-03-23 03:53:56 +01:00
|
|
|
}
|
2016-02-20 23:37:19 +01:00
|
|
|
|
|
|
|
/* linebuf_put_msgbuf
|
|
|
|
*
|
|
|
|
* inputs - msgbuf header, linebuf object, capability mask, pattern, arguments
|
|
|
|
* outputs - none
|
|
|
|
* side effects - the linebuf object is cleared, then populated using rb_linebuf_putmsg().
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
linebuf_put_msgbuf(struct MsgBuf *msgbuf, buf_head_t *linebuf, unsigned int capmask, const char *pattern, ...)
|
|
|
|
{
|
|
|
|
va_list va;
|
2016-02-20 22:49:41 +01:00
|
|
|
|
|
|
|
va_start(va, pattern);
|
2016-02-20 23:37:19 +01:00
|
|
|
linebuf_put_msgvbuf(msgbuf, linebuf, capmask, pattern, &va);
|
2016-02-20 22:49:41 +01:00
|
|
|
va_end(va);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* build_msgbuf_from
|
|
|
|
*
|
|
|
|
* inputs - msgbuf object, client the message is from
|
|
|
|
* outputs - none
|
|
|
|
* side effects - a msgbuf object is populated with an origin and relevant tags
|
|
|
|
* notes - to make this reentrant, find a solution for `buf` below
|
|
|
|
*/
|
|
|
|
static void
|
2016-08-22 03:57:43 +02:00
|
|
|
build_msgbuf_from(struct MsgBuf *msgbuf, client::client *from, const char *cmd)
|
2016-02-20 22:49:41 +01:00
|
|
|
{
|
|
|
|
static char buf[BUFSIZE];
|
|
|
|
hook_data hdata;
|
|
|
|
|
|
|
|
msgbuf_init(msgbuf);
|
|
|
|
|
|
|
|
msgbuf->origin = buf;
|
2016-02-20 23:37:19 +01:00
|
|
|
msgbuf->cmd = cmd;
|
2016-02-20 22:49:41 +01:00
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if (from != NULL && is_person(*from))
|
2016-02-20 22:49:41 +01:00
|
|
|
snprintf(buf, sizeof buf, "%s!%s@%s", from->name, from->username, from->host);
|
2016-02-27 09:56:44 +01:00
|
|
|
else if (from != NULL)
|
2016-02-20 22:49:41 +01:00
|
|
|
rb_strlcpy(buf, from->name, sizeof buf);
|
2016-02-27 09:56:44 +01:00
|
|
|
else
|
|
|
|
rb_strlcpy(buf, me.name, sizeof buf);
|
2016-02-20 22:49:41 +01:00
|
|
|
|
|
|
|
hdata.client = from;
|
|
|
|
hdata.arg1 = msgbuf;
|
|
|
|
|
|
|
|
call_hook(h_outbound_msgbuf, &hdata);
|
|
|
|
}
|
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
/* sendto_one()
|
|
|
|
*
|
|
|
|
* inputs - client to send to, va_args
|
|
|
|
* outputs - client has message put into its queue
|
2014-03-03 05:25:47 +01:00
|
|
|
* side effects -
|
2007-01-25 07:40:21 +01:00
|
|
|
*/
|
|
|
|
void
|
2016-08-22 03:57:43 +02:00
|
|
|
sendto_one(client::client *target_p, const char *pattern, ...)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
buf_head_t linebuf;
|
|
|
|
|
|
|
|
/* send remote if to->from non NULL */
|
|
|
|
if(target_p->from != NULL)
|
|
|
|
target_p = target_p->from;
|
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if(is_io_error(*target_p))
|
2007-01-25 07:40:21 +01:00
|
|
|
return;
|
|
|
|
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_linebuf_newbuf(&linebuf);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
va_start(args, pattern);
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_linebuf_putmsg(&linebuf, pattern, &args, NULL);
|
2007-01-25 07:40:21 +01:00
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
_send_linebuf(target_p, &linebuf);
|
|
|
|
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_linebuf_donebuf(&linebuf);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* sendto_one_prefix()
|
|
|
|
*
|
|
|
|
* inputs - client to send to, va_args
|
|
|
|
* outputs - client has message put into its queue
|
|
|
|
* side effects - source(us)/target is chosen based on TS6 capability
|
|
|
|
*/
|
|
|
|
void
|
2016-08-22 03:57:43 +02:00
|
|
|
sendto_one_prefix(client::client *target_p, client::client *source_p,
|
2007-01-25 07:40:21 +01:00
|
|
|
const char *command, const char *pattern, ...)
|
|
|
|
{
|
2016-08-22 03:57:43 +02:00
|
|
|
client::client *dest_p;
|
2007-01-25 07:40:21 +01:00
|
|
|
va_list args;
|
|
|
|
buf_head_t linebuf;
|
|
|
|
|
|
|
|
/* send remote if to->from non NULL */
|
|
|
|
if(target_p->from != NULL)
|
|
|
|
dest_p = target_p->from;
|
|
|
|
else
|
|
|
|
dest_p = target_p;
|
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if(is_io_error(*dest_p))
|
2007-01-25 07:40:21 +01:00
|
|
|
return;
|
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if(is_me(*dest_p))
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-26 13:50:12 +02:00
|
|
|
sendto_realops_snomask(sno::GENERAL, L_ALL, "Trying to send to myself!");
|
2007-01-25 07:40:21 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_linebuf_newbuf(&linebuf);
|
2007-01-25 07:40:21 +01:00
|
|
|
va_start(args, pattern);
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_linebuf_putmsg(&linebuf, pattern, &args,
|
2007-01-25 07:40:21 +01:00
|
|
|
":%s %s %s ",
|
|
|
|
get_id(source_p, target_p),
|
|
|
|
command, get_id(target_p, target_p));
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
_send_linebuf(dest_p, &linebuf);
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_linebuf_donebuf(&linebuf);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* sendto_one_notice()
|
|
|
|
*
|
|
|
|
* inputs - client to send to, va_args
|
|
|
|
* outputs - client has a NOTICE put into its queue
|
|
|
|
* side effects - source(us)/target is chosen based on TS6 capability
|
|
|
|
*/
|
|
|
|
void
|
2016-08-22 03:57:43 +02:00
|
|
|
sendto_one_notice(client::client *target_p, const char *pattern, ...)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-22 03:57:43 +02:00
|
|
|
client::client *dest_p;
|
2007-01-25 07:40:21 +01:00
|
|
|
va_list args;
|
|
|
|
buf_head_t linebuf;
|
2007-01-25 08:23:01 +01:00
|
|
|
char *to;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
/* send remote if to->from non NULL */
|
|
|
|
if(target_p->from != NULL)
|
|
|
|
dest_p = target_p->from;
|
|
|
|
else
|
|
|
|
dest_p = target_p;
|
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if(is_io_error(*dest_p))
|
2007-01-25 07:40:21 +01:00
|
|
|
return;
|
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if(is_me(*dest_p))
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-26 13:50:12 +02:00
|
|
|
sendto_realops_snomask(sno::GENERAL, L_ALL, "Trying to send to myself!");
|
2007-01-25 07:40:21 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_linebuf_newbuf(&linebuf);
|
2007-01-25 07:40:21 +01:00
|
|
|
va_start(args, pattern);
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_linebuf_putmsg(&linebuf, pattern, &args,
|
2007-01-25 07:40:21 +01:00
|
|
|
":%s NOTICE %s ",
|
2007-01-25 08:23:01 +01:00
|
|
|
get_id(&me, target_p), *(to = get_id(target_p, target_p)) != '\0' ? to : "*");
|
2007-01-25 07:40:21 +01:00
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
_send_linebuf(dest_p, &linebuf);
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_linebuf_donebuf(&linebuf);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* sendto_one_numeric()
|
|
|
|
*
|
|
|
|
* inputs - client to send to, va_args
|
|
|
|
* outputs - client has message put into its queue
|
|
|
|
* side effects - source/target is chosen based on TS6 capability
|
|
|
|
*/
|
|
|
|
void
|
2016-08-22 03:57:43 +02:00
|
|
|
sendto_one_numeric(client::client *target_p, int numeric, const char *pattern, ...)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-22 03:57:43 +02:00
|
|
|
client::client *dest_p;
|
2007-01-25 07:40:21 +01:00
|
|
|
va_list args;
|
|
|
|
buf_head_t linebuf;
|
2007-01-25 08:23:01 +01:00
|
|
|
char *to;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
/* send remote if to->from non NULL */
|
|
|
|
if(target_p->from != NULL)
|
|
|
|
dest_p = target_p->from;
|
|
|
|
else
|
|
|
|
dest_p = target_p;
|
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if(is_io_error(*dest_p))
|
2007-01-25 07:40:21 +01:00
|
|
|
return;
|
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if(is_me(*dest_p))
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-26 13:50:12 +02:00
|
|
|
sendto_realops_snomask(sno::GENERAL, L_ALL, "Trying to send to myself!");
|
2007-01-25 07:40:21 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_linebuf_newbuf(&linebuf);
|
2007-01-25 07:40:21 +01:00
|
|
|
va_start(args, pattern);
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_linebuf_putmsg(&linebuf, pattern, &args,
|
2007-01-25 07:40:21 +01:00
|
|
|
":%s %03d %s ",
|
|
|
|
get_id(&me, target_p),
|
2007-01-25 08:23:01 +01:00
|
|
|
numeric, *(to = get_id(target_p, target_p)) != '\0' ? to : "*");
|
2007-01-25 07:40:21 +01:00
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
_send_linebuf(dest_p, &linebuf);
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_linebuf_donebuf(&linebuf);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* sendto_server
|
2014-03-03 05:25:47 +01:00
|
|
|
*
|
2007-01-25 07:40:21 +01:00
|
|
|
* inputs - pointer to client to NOT send to
|
|
|
|
* - caps or'd together which must ALL be present
|
|
|
|
* - caps or'd together which must ALL NOT be present
|
|
|
|
* - printf style format string
|
|
|
|
* - args to format string
|
|
|
|
* output - NONE
|
|
|
|
* side effects - Send a message to all connected servers, except the
|
|
|
|
* client 'one' (if non-NULL), as long as the servers
|
|
|
|
* support ALL capabs in 'caps', and NO capabs in 'nocaps'.
|
2014-03-03 05:25:47 +01:00
|
|
|
*
|
2007-01-25 07:40:21 +01:00
|
|
|
* This function was written in an attempt to merge together the other
|
|
|
|
* billion sendto_*serv*() functions, which sprung up with capabs, uids etc
|
|
|
|
* -davidt
|
|
|
|
*/
|
|
|
|
void
|
2016-08-22 03:57:43 +02:00
|
|
|
sendto_server(client::client *one, chan::chan *chptr, unsigned long caps,
|
2007-01-25 07:40:21 +01:00
|
|
|
unsigned long nocaps, const char *format, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
2016-08-22 03:57:43 +02:00
|
|
|
client::client *target_p;
|
2008-04-01 22:41:52 +02:00
|
|
|
rb_dlink_node *ptr;
|
2008-04-02 00:47:17 +02:00
|
|
|
rb_dlink_node *next_ptr;
|
2007-01-25 07:40:21 +01:00
|
|
|
buf_head_t linebuf;
|
|
|
|
|
|
|
|
/* noone to send to.. */
|
2008-04-01 22:41:52 +02:00
|
|
|
if(rb_dlink_list_length(&serv_list) == 0)
|
2007-01-25 07:40:21 +01:00
|
|
|
return;
|
|
|
|
|
2016-08-18 07:33:38 +02:00
|
|
|
if(chptr != NULL && chptr->name[0] != '#')
|
2007-01-25 07:40:21 +01:00
|
|
|
return;
|
|
|
|
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_linebuf_newbuf(&linebuf);
|
2007-01-25 07:40:21 +01:00
|
|
|
va_start(args, format);
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_linebuf_putmsg(&linebuf, format, &args, NULL);
|
2007-01-25 07:40:21 +01:00
|
|
|
va_end(args);
|
|
|
|
|
2008-04-02 00:47:17 +02:00
|
|
|
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, serv_list.head)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-22 03:57:43 +02:00
|
|
|
target_p = (client::client *)ptr->data;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
/* check against 'one' */
|
|
|
|
if(one != NULL && (target_p == one->from))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* check we have required capabs */
|
|
|
|
if(!IsCapable(target_p, caps))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* check we don't have any forbidden capabs */
|
|
|
|
if(!NotCapable(target_p, nocaps))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
_send_linebuf(target_p, &linebuf);
|
|
|
|
}
|
|
|
|
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_linebuf_donebuf(&linebuf);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* sendto_channel_flags()
|
|
|
|
*
|
|
|
|
* inputs - server not to send to, flags needed, source, channel, va_args
|
|
|
|
* outputs - message is sent to channel members
|
|
|
|
* side effects -
|
|
|
|
*/
|
|
|
|
void
|
2016-08-22 03:57:43 +02:00
|
|
|
sendto_channel_flags(client::client *one, int type, client::client *source_p,
|
2016-08-18 07:33:38 +02:00
|
|
|
chan::chan *chptr, const char *pattern, ...)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-03-23 15:22:55 +01:00
|
|
|
char buf[BUFSIZE];
|
2007-01-25 07:40:21 +01:00
|
|
|
va_list args;
|
2008-04-01 23:51:34 +02:00
|
|
|
buf_head_t rb_linebuf_local;
|
|
|
|
buf_head_t rb_linebuf_id;
|
2008-04-01 22:41:52 +02:00
|
|
|
rb_dlink_node *ptr;
|
2008-04-02 00:47:17 +02:00
|
|
|
rb_dlink_node *next_ptr;
|
2016-03-23 03:53:56 +01:00
|
|
|
int current_capmask = 0;
|
2016-02-21 01:27:15 +01:00
|
|
|
struct MsgBuf msgbuf;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_linebuf_newbuf(&rb_linebuf_local);
|
|
|
|
rb_linebuf_newbuf(&rb_linebuf_id);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
current_serial++;
|
|
|
|
|
2016-02-21 01:27:15 +01:00
|
|
|
build_msgbuf_from(&msgbuf, source_p, NULL);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-02-21 01:27:15 +01:00
|
|
|
va_start(args, pattern);
|
2016-02-21 01:32:09 +01:00
|
|
|
vsnprintf(buf, sizeof buf, pattern, args);
|
|
|
|
va_end(args);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-02-21 01:32:09 +01:00
|
|
|
linebuf_put_msgbuf(&msgbuf, &rb_linebuf_local, NOCAPS, "%s", buf);
|
|
|
|
rb_linebuf_putmsg(&rb_linebuf_id, NULL, NULL, ":%s %s", use_id(source_p), buf);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-08-20 02:32:26 +02:00
|
|
|
for(const auto &pair : chptr->members.global)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-20 02:32:26 +02:00
|
|
|
auto *const target_p(pair.first);
|
|
|
|
const auto &member(pair.second);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if(!my(*source_p) && (is_io_error(*target_p->from) || target_p->from == one))
|
2016-02-27 09:48:37 +01:00
|
|
|
continue;
|
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if(my(*source_p) && !IsCapable(source_p, CLICAP_ECHO_MESSAGE) && target_p == one)
|
2007-01-25 07:40:21 +01:00
|
|
|
continue;
|
|
|
|
|
2016-08-20 02:32:26 +02:00
|
|
|
if(type && ((member.flags & type) == 0))
|
2007-01-25 07:40:21 +01:00
|
|
|
continue;
|
|
|
|
|
2016-08-24 00:25:09 +02:00
|
|
|
if(is(*target_p, umode::DEAF))
|
2007-01-25 07:40:21 +01:00
|
|
|
continue;
|
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if(!my(*target_p))
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
/* if we've got a specific type, target must support
|
|
|
|
* CHW.. --fl
|
|
|
|
*/
|
|
|
|
if(type && NotCapable(target_p->from, CAP_CHW))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if(target_p->from->serial != current_serial)
|
|
|
|
{
|
2008-06-14 02:30:30 +02:00
|
|
|
send_linebuf_remote(target_p, source_p, &rb_linebuf_id);
|
2007-01-25 07:40:21 +01:00
|
|
|
target_p->from->serial = current_serial;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2016-02-21 01:27:15 +01:00
|
|
|
{
|
|
|
|
if (target_p->localClient->caps != current_capmask)
|
|
|
|
{
|
|
|
|
/* reset the linebuf */
|
|
|
|
rb_linebuf_donebuf(&rb_linebuf_local);
|
|
|
|
rb_linebuf_newbuf(&rb_linebuf_local);
|
|
|
|
|
|
|
|
/* render the new linebuf and attach it */
|
2016-02-21 01:32:09 +01:00
|
|
|
linebuf_put_msgbuf(&msgbuf, &rb_linebuf_local, target_p->localClient->caps, "%s", buf);
|
2016-02-21 01:27:15 +01:00
|
|
|
current_capmask = target_p->localClient->caps;
|
|
|
|
}
|
|
|
|
|
2008-04-01 23:51:34 +02:00
|
|
|
_send_linebuf(target_p, &rb_linebuf_local);
|
2016-02-21 01:27:15 +01:00
|
|
|
}
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_linebuf_donebuf(&rb_linebuf_local);
|
|
|
|
rb_linebuf_donebuf(&rb_linebuf_id);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
2009-03-29 15:48:07 +02:00
|
|
|
/* sendto_channel_flags()
|
|
|
|
*
|
|
|
|
* inputs - server not to send to, flags needed, source, channel, va_args
|
|
|
|
* outputs - message is sent to channel members
|
|
|
|
* side effects -
|
|
|
|
*/
|
|
|
|
void
|
2016-08-22 03:57:43 +02:00
|
|
|
sendto_channel_opmod(client::client *one, client::client *source_p,
|
2016-08-18 07:33:38 +02:00
|
|
|
chan::chan *chptr, const char *command,
|
2009-03-29 15:48:07 +02:00
|
|
|
const char *text)
|
|
|
|
{
|
|
|
|
buf_head_t rb_linebuf_local;
|
|
|
|
buf_head_t rb_linebuf_old;
|
|
|
|
buf_head_t rb_linebuf_new;
|
|
|
|
rb_dlink_node *ptr;
|
|
|
|
rb_dlink_node *next_ptr;
|
|
|
|
|
|
|
|
rb_linebuf_newbuf(&rb_linebuf_local);
|
|
|
|
rb_linebuf_newbuf(&rb_linebuf_old);
|
|
|
|
rb_linebuf_newbuf(&rb_linebuf_new);
|
|
|
|
|
|
|
|
current_serial++;
|
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if(is_server(*source_p))
|
2009-03-29 15:48:07 +02:00
|
|
|
rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL,
|
|
|
|
":%s %s %s :%s",
|
2016-08-18 07:33:38 +02:00
|
|
|
source_p->name, command, chptr->name.c_str(), text);
|
2009-03-29 15:48:07 +02:00
|
|
|
else
|
|
|
|
rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL,
|
|
|
|
":%s!%s@%s %s %s :%s",
|
2014-03-03 05:25:47 +01:00
|
|
|
source_p->name, source_p->username,
|
2016-08-18 07:33:38 +02:00
|
|
|
source_p->host, command, chptr->name.c_str(), text);
|
2009-03-29 15:48:07 +02:00
|
|
|
|
2016-08-17 05:01:20 +02:00
|
|
|
if (chptr->mode.mode & chan::mode::MODERATED)
|
2009-03-29 15:48:07 +02:00
|
|
|
rb_linebuf_putmsg(&rb_linebuf_old, NULL, NULL,
|
|
|
|
":%s %s %s :%s",
|
2016-08-18 07:33:38 +02:00
|
|
|
use_id(source_p), command, chptr->name.c_str(), text);
|
2009-03-29 15:48:07 +02:00
|
|
|
else
|
|
|
|
rb_linebuf_putmsg(&rb_linebuf_old, NULL, NULL,
|
|
|
|
":%s NOTICE @%s :<%s:%s> %s",
|
2016-08-18 07:33:38 +02:00
|
|
|
use_id(source_p->servptr), chptr->name.c_str(),
|
|
|
|
source_p->name, chptr->name.c_str(), text);
|
2009-03-29 15:48:07 +02:00
|
|
|
rb_linebuf_putmsg(&rb_linebuf_new, NULL, NULL,
|
|
|
|
":%s %s =%s :%s",
|
2016-08-18 07:33:38 +02:00
|
|
|
use_id(source_p), command, chptr->name.c_str(), text);
|
2009-03-29 15:48:07 +02:00
|
|
|
|
2016-08-20 02:32:26 +02:00
|
|
|
for(const auto &pair : chptr->members.global)
|
2009-03-29 15:48:07 +02:00
|
|
|
{
|
2016-08-20 02:32:26 +02:00
|
|
|
auto *const target_p(pair.first);
|
|
|
|
const auto &member(pair.second);
|
2009-03-29 15:48:07 +02:00
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if(!my(*source_p) && (is_io_error(*target_p->from) || target_p->from == one))
|
2016-02-27 09:48:37 +01:00
|
|
|
continue;
|
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if(my(*source_p) && !IsCapable(source_p, CLICAP_ECHO_MESSAGE) && target_p == one)
|
2009-03-29 15:48:07 +02:00
|
|
|
continue;
|
|
|
|
|
2016-08-20 02:32:26 +02:00
|
|
|
if((member.flags & chan::CHANOP) == 0)
|
2009-03-29 15:48:07 +02:00
|
|
|
continue;
|
|
|
|
|
2016-08-24 00:25:09 +02:00
|
|
|
if(is(*target_p, umode::DEAF))
|
2009-03-29 15:48:07 +02:00
|
|
|
continue;
|
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if(!my(*target_p))
|
2009-03-29 15:48:07 +02:00
|
|
|
{
|
|
|
|
/* if we've got a specific type, target must support
|
|
|
|
* CHW.. --fl
|
|
|
|
*/
|
|
|
|
if(NotCapable(target_p->from, CAP_CHW))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if(target_p->from->serial != current_serial)
|
|
|
|
{
|
|
|
|
if (IsCapable(target_p->from, CAP_EOPMOD))
|
|
|
|
send_linebuf_remote(target_p, source_p, &rb_linebuf_new);
|
|
|
|
else
|
|
|
|
send_linebuf_remote(target_p, source_p, &rb_linebuf_old);
|
|
|
|
target_p->from->serial = current_serial;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
_send_linebuf(target_p, &rb_linebuf_local);
|
|
|
|
}
|
|
|
|
|
|
|
|
rb_linebuf_donebuf(&rb_linebuf_local);
|
|
|
|
rb_linebuf_donebuf(&rb_linebuf_old);
|
|
|
|
rb_linebuf_donebuf(&rb_linebuf_new);
|
|
|
|
}
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
/* sendto_channel_local()
|
|
|
|
*
|
|
|
|
* inputs - flags to send to, channel to send to, va_args
|
|
|
|
* outputs - message to local channel members
|
|
|
|
* side effects -
|
|
|
|
*/
|
|
|
|
void
|
2016-08-18 07:33:38 +02:00
|
|
|
sendto_channel_local(int type, chan::chan *chptr, const char *pattern, ...)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
buf_head_t linebuf;
|
2014-03-03 05:25:47 +01:00
|
|
|
|
|
|
|
rb_linebuf_newbuf(&linebuf);
|
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
va_start(args, pattern);
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_linebuf_putmsg(&linebuf, pattern, &args, NULL);
|
2007-01-25 07:40:21 +01:00
|
|
|
va_end(args);
|
|
|
|
|
2016-08-20 02:32:26 +02:00
|
|
|
for (const auto &pair : chptr->members.global)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-20 02:32:26 +02:00
|
|
|
auto *const target_p(pair.first);
|
|
|
|
const auto &member(pair.second);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if(is_io_error(*target_p))
|
2007-01-25 07:40:21 +01:00
|
|
|
continue;
|
|
|
|
|
2016-08-18 07:33:38 +02:00
|
|
|
if(type == chan::ONLY_OPERS)
|
2016-01-13 23:34:27 +01:00
|
|
|
{
|
2016-08-24 00:25:09 +02:00
|
|
|
if (!is(*target_p, umode::OPER))
|
2016-01-13 23:34:27 +01:00
|
|
|
continue;
|
|
|
|
}
|
2016-08-20 02:32:26 +02:00
|
|
|
else if(type && ((member.flags & type) == 0))
|
2007-01-25 07:40:21 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
_send_linebuf(target_p, &linebuf);
|
2010-12-16 07:19:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
rb_linebuf_donebuf(&linebuf);
|
|
|
|
}
|
|
|
|
|
2011-11-12 15:41:01 +01:00
|
|
|
/*
|
|
|
|
* _sendto_channel_local_with_capability_butone()
|
2010-12-16 07:19:24 +01:00
|
|
|
*
|
2011-11-12 15:41:01 +01:00
|
|
|
* Shared implementation of sendto_channel_local_with_capability and sendto_channel_local_with_capability_butone
|
2010-12-16 07:19:24 +01:00
|
|
|
*/
|
2011-11-12 15:41:01 +01:00
|
|
|
static void
|
2016-08-22 03:57:43 +02:00
|
|
|
_sendto_channel_local_with_capability_butone(client::client *one, int type, int caps, int negcaps, chan::chan *chptr,
|
2011-11-12 15:41:01 +01:00
|
|
|
const char *pattern, va_list * args)
|
2010-12-16 07:19:24 +01:00
|
|
|
{
|
|
|
|
buf_head_t linebuf;
|
2014-03-03 05:25:47 +01:00
|
|
|
|
2011-11-12 15:41:01 +01:00
|
|
|
rb_linebuf_newbuf(&linebuf);
|
|
|
|
rb_linebuf_putmsg(&linebuf, pattern, args, NULL);
|
2014-03-03 05:25:47 +01:00
|
|
|
|
2016-08-20 02:32:26 +02:00
|
|
|
for(const auto &member : chptr->members.local)
|
2010-12-16 07:19:24 +01:00
|
|
|
{
|
2016-08-20 02:32:26 +02:00
|
|
|
const auto target_p(member->git->first);
|
2010-12-16 07:19:24 +01:00
|
|
|
|
2011-11-12 15:41:01 +01:00
|
|
|
if (target_p == one)
|
|
|
|
continue;
|
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if(is_io_error(*target_p) ||
|
2010-12-16 07:19:24 +01:00
|
|
|
!IsCapable(target_p, caps) ||
|
2011-01-11 00:26:05 +01:00
|
|
|
!NotCapable(target_p, negcaps))
|
2010-12-16 07:19:24 +01:00
|
|
|
continue;
|
|
|
|
|
2016-08-20 02:32:26 +02:00
|
|
|
if(type && ((member->flags & type) == 0))
|
2010-12-16 07:19:24 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
_send_linebuf(target_p, &linebuf);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_linebuf_donebuf(&linebuf);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
2011-11-12 15:41:01 +01:00
|
|
|
/* sendto_channel_local_with_capability()
|
|
|
|
*
|
|
|
|
* inputs - flags to send to, caps, negate caps, channel to send to, va_args
|
|
|
|
* outputs - message to local channel members
|
|
|
|
* side effects -
|
|
|
|
*/
|
|
|
|
void
|
2016-08-18 07:33:38 +02:00
|
|
|
sendto_channel_local_with_capability(int type, int caps, int negcaps, chan::chan *chptr, const char *pattern, ...)
|
2011-11-12 15:41:01 +01:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, pattern);
|
|
|
|
_sendto_channel_local_with_capability_butone(NULL, type, caps, negcaps, chptr, pattern, &args);
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* sendto_channel_local_with_capability()
|
|
|
|
*
|
|
|
|
* inputs - flags to send to, caps, negate caps, channel to send to, va_args
|
|
|
|
* outputs - message to local channel members
|
|
|
|
* side effects -
|
|
|
|
*/
|
|
|
|
void
|
2016-08-22 03:57:43 +02:00
|
|
|
sendto_channel_local_with_capability_butone(client::client *one, int type, int caps, int negcaps, chan::chan *chptr,
|
2011-11-12 15:41:01 +01:00
|
|
|
const char *pattern, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, pattern);
|
|
|
|
_sendto_channel_local_with_capability_butone(one, type, caps, negcaps, chptr, pattern, &args);
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
/* sendto_channel_local_butone()
|
|
|
|
*
|
|
|
|
* inputs - flags to send to, channel to send to, va_args
|
|
|
|
* - user to ignore when sending
|
|
|
|
* outputs - message to local channel members
|
|
|
|
* side effects -
|
|
|
|
*/
|
|
|
|
void
|
2016-08-22 03:57:43 +02:00
|
|
|
sendto_channel_local_butone(client::client *one, int type, chan::chan *chptr, const char *pattern, ...)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
buf_head_t linebuf;
|
2016-02-20 23:37:19 +01:00
|
|
|
struct MsgBuf msgbuf;
|
2008-04-01 22:41:52 +02:00
|
|
|
rb_dlink_node *ptr;
|
2008-04-02 00:47:17 +02:00
|
|
|
rb_dlink_node *next_ptr;
|
2014-03-03 05:25:47 +01:00
|
|
|
|
|
|
|
rb_linebuf_newbuf(&linebuf);
|
|
|
|
|
2016-02-20 23:37:19 +01:00
|
|
|
build_msgbuf_from(&msgbuf, one, NULL);
|
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
va_start(args, pattern);
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_linebuf_putmsg(&linebuf, pattern, &args, NULL);
|
2016-02-21 01:35:35 +01:00
|
|
|
va_end(args);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-08-20 02:32:26 +02:00
|
|
|
for(const auto &member : chptr->members.local)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-20 02:32:26 +02:00
|
|
|
const auto target_p(member->git->first);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
if(target_p == one)
|
|
|
|
continue;
|
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if(is_io_error(*target_p))
|
2007-01-25 07:40:21 +01:00
|
|
|
continue;
|
|
|
|
|
2016-08-20 02:32:26 +02:00
|
|
|
if(type && ((member->flags & type) == 0))
|
2007-01-25 07:40:21 +01:00
|
|
|
continue;
|
|
|
|
|
2016-02-20 23:37:19 +01:00
|
|
|
/* attach the present linebuf to the target */
|
2007-01-25 07:40:21 +01:00
|
|
|
_send_linebuf(target_p, &linebuf);
|
|
|
|
}
|
|
|
|
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_linebuf_donebuf(&linebuf);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* sendto_common_channels_local()
|
|
|
|
*
|
|
|
|
* inputs - pointer to client
|
2010-12-16 05:55:05 +01:00
|
|
|
* - capability mask
|
2015-11-20 05:43:45 +01:00
|
|
|
* - negated capability mask
|
2007-01-25 07:40:21 +01:00
|
|
|
* - pattern to send
|
|
|
|
* output - NONE
|
|
|
|
* side effects - Sends a message to all people on local server who are
|
2014-03-03 05:25:47 +01:00
|
|
|
* in same channel with user.
|
2007-01-25 07:40:21 +01:00
|
|
|
* used by m_nick.c and exit_one_client.
|
|
|
|
*/
|
|
|
|
void
|
2016-08-22 03:57:43 +02:00
|
|
|
sendto_common_channels_local(client::client *client, int cap, int negcap, const char *pattern, ...)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
va_list args;
|
2008-04-01 22:41:52 +02:00
|
|
|
rb_dlink_node *ptr;
|
2008-04-02 00:47:17 +02:00
|
|
|
rb_dlink_node *next_ptr;
|
2008-04-01 22:41:52 +02:00
|
|
|
rb_dlink_node *uptr;
|
|
|
|
rb_dlink_node *next_uptr;
|
2016-08-18 07:33:38 +02:00
|
|
|
chan::chan *chptr;
|
2016-08-22 03:57:43 +02:00
|
|
|
client::client *target_p;
|
2016-08-18 07:33:38 +02:00
|
|
|
chan::membership *msptr;
|
|
|
|
chan::membership *mscptr;
|
2007-01-25 07:40:21 +01:00
|
|
|
buf_head_t linebuf;
|
|
|
|
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_linebuf_newbuf(&linebuf);
|
2007-01-25 07:40:21 +01:00
|
|
|
va_start(args, pattern);
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_linebuf_putmsg(&linebuf, pattern, &args, NULL);
|
2007-01-25 07:40:21 +01:00
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
++current_serial;
|
|
|
|
|
2016-08-22 03:57:43 +02:00
|
|
|
for(const auto &pit : chans(user(*client)))
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-20 02:32:26 +02:00
|
|
|
auto &chptr(pit.first);
|
|
|
|
auto &mscptr(pit.second);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-08-20 02:32:26 +02:00
|
|
|
for(const auto &msptr : chptr->members.local)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-20 02:32:26 +02:00
|
|
|
const auto target_p(msptr->git->first);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if(is_io_error(*target_p) ||
|
2010-12-16 05:55:05 +01:00
|
|
|
target_p->serial == current_serial ||
|
2015-11-20 05:43:45 +01:00
|
|
|
!IsCapable(target_p, cap) ||
|
|
|
|
!NotCapable(target_p, negcap))
|
2007-01-25 07:40:21 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
target_p->serial = current_serial;
|
|
|
|
send_linebuf(target_p, &linebuf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* this can happen when the user isnt in any channels, but we still
|
|
|
|
* need to send them the data, ie a nick change
|
|
|
|
*/
|
2016-08-23 04:33:36 +02:00
|
|
|
if(my_connect(*client) && (client->serial != current_serial))
|
2016-08-22 03:57:43 +02:00
|
|
|
send_linebuf(client, &linebuf);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_linebuf_donebuf(&linebuf);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* sendto_common_channels_local_butone()
|
|
|
|
*
|
|
|
|
* inputs - pointer to client
|
2010-12-16 05:55:05 +01:00
|
|
|
* - capability mask
|
2015-11-20 05:43:45 +01:00
|
|
|
* - negated capability mask
|
2007-01-25 07:40:21 +01:00
|
|
|
* - pattern to send
|
|
|
|
* output - NONE
|
|
|
|
* side effects - Sends a message to all people on local server who are
|
|
|
|
* in same channel with user, except for user itself.
|
|
|
|
*/
|
|
|
|
void
|
2016-08-22 03:57:43 +02:00
|
|
|
sendto_common_channels_local_butone(client::client *client, int cap, int negcap, const char *pattern, ...)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-18 07:33:38 +02:00
|
|
|
using chan::membership;
|
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
va_list args;
|
2008-04-01 22:41:52 +02:00
|
|
|
rb_dlink_node *ptr;
|
2008-04-02 00:47:17 +02:00
|
|
|
rb_dlink_node *next_ptr;
|
2008-04-01 22:41:52 +02:00
|
|
|
rb_dlink_node *uptr;
|
|
|
|
rb_dlink_node *next_uptr;
|
2016-08-18 07:33:38 +02:00
|
|
|
chan::chan *chptr;
|
2016-08-22 03:57:43 +02:00
|
|
|
client::client *target_p;
|
2016-08-18 07:33:38 +02:00
|
|
|
membership *msptr;
|
|
|
|
membership *mscptr;
|
2007-01-25 07:40:21 +01:00
|
|
|
buf_head_t linebuf;
|
|
|
|
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_linebuf_newbuf(&linebuf);
|
2016-02-20 23:37:19 +01:00
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
va_start(args, pattern);
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_linebuf_putmsg(&linebuf, pattern, &args, NULL);
|
2007-01-25 07:40:21 +01:00
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
++current_serial;
|
|
|
|
/* Skip them -- jilles */
|
2016-08-22 03:57:43 +02:00
|
|
|
client->serial = current_serial;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-08-22 03:57:43 +02:00
|
|
|
for(const auto &pit : chans(user(*client)))
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-20 02:32:26 +02:00
|
|
|
auto &chptr(pit.first);
|
|
|
|
auto &mscptr(pit.second);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-08-20 02:32:26 +02:00
|
|
|
for(const auto &msptr : chptr->members.local)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-20 02:32:26 +02:00
|
|
|
const auto target_p(msptr->git->first);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if(is_io_error(*target_p) ||
|
2010-12-16 05:55:05 +01:00
|
|
|
target_p->serial == current_serial ||
|
2015-11-20 05:43:45 +01:00
|
|
|
!IsCapable(target_p, cap) ||
|
|
|
|
!NotCapable(target_p, negcap))
|
2007-01-25 07:40:21 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
target_p->serial = current_serial;
|
|
|
|
send_linebuf(target_p, &linebuf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_linebuf_donebuf(&linebuf);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* sendto_match_butone()
|
|
|
|
*
|
|
|
|
* inputs - server not to send to, source, mask, type of mask, va_args
|
|
|
|
* output -
|
|
|
|
* side effects - message is sent to matching clients
|
|
|
|
*/
|
|
|
|
void
|
2016-08-22 03:57:43 +02:00
|
|
|
sendto_match_butone(client::client *one, client::client *source_p,
|
2007-01-25 07:40:21 +01:00
|
|
|
const char *mask, int what, const char *pattern, ...)
|
|
|
|
{
|
|
|
|
static char buf[BUFSIZE];
|
|
|
|
va_list args;
|
2016-08-22 03:57:43 +02:00
|
|
|
client::client *target_p;
|
2008-04-01 22:41:52 +02:00
|
|
|
rb_dlink_node *ptr;
|
2008-04-02 00:47:17 +02:00
|
|
|
rb_dlink_node *next_ptr;
|
2008-04-01 23:51:34 +02:00
|
|
|
buf_head_t rb_linebuf_local;
|
|
|
|
buf_head_t rb_linebuf_id;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_linebuf_newbuf(&rb_linebuf_local);
|
|
|
|
rb_linebuf_newbuf(&rb_linebuf_id);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
va_start(args, pattern);
|
2016-02-10 02:25:32 +01:00
|
|
|
vsnprintf(buf, sizeof(buf), pattern, args);
|
2007-01-25 07:40:21 +01:00
|
|
|
va_end(args);
|
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if(is_server(*source_p))
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL,
|
2007-01-25 07:40:21 +01:00
|
|
|
":%s %s", source_p->name, buf);
|
|
|
|
else
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL,
|
2007-01-25 07:40:21 +01:00
|
|
|
":%s!%s@%s %s",
|
2014-03-03 05:25:47 +01:00
|
|
|
source_p->name, source_p->username,
|
2007-01-25 07:40:21 +01:00
|
|
|
source_p->host, buf);
|
|
|
|
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_linebuf_putmsg(&rb_linebuf_id, NULL, NULL, ":%s %s", use_id(source_p), buf);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
if(what == MATCH_HOST)
|
|
|
|
{
|
2008-04-02 00:47:17 +02:00
|
|
|
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, lclient_list.head)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-22 03:57:43 +02:00
|
|
|
target_p = (client::client *)ptr->data;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
if(match(mask, target_p->host))
|
2008-04-01 23:51:34 +02:00
|
|
|
_send_linebuf(target_p, &rb_linebuf_local);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* what = MATCH_SERVER, if it doesnt match us, just send remote */
|
|
|
|
else if(match(mask, me.name))
|
|
|
|
{
|
2008-04-02 00:47:17 +02:00
|
|
|
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, lclient_list.head)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-22 03:57:43 +02:00
|
|
|
target_p = (client::client *)ptr->data;
|
2008-04-01 23:51:34 +02:00
|
|
|
_send_linebuf(target_p, &rb_linebuf_local);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-01 22:43:10 +02:00
|
|
|
RB_DLINK_FOREACH(ptr, serv_list.head)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-22 03:57:43 +02:00
|
|
|
target_p = (client::client *)ptr->data;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
if(target_p == one)
|
|
|
|
continue;
|
|
|
|
|
2008-06-14 02:30:30 +02:00
|
|
|
send_linebuf_remote(target_p, source_p, &rb_linebuf_id);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_linebuf_donebuf(&rb_linebuf_local);
|
|
|
|
rb_linebuf_donebuf(&rb_linebuf_id);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* sendto_match_servs()
|
|
|
|
*
|
|
|
|
* inputs - source, mask to send to, caps needed, va_args
|
2014-03-03 05:25:47 +01:00
|
|
|
* outputs -
|
2007-01-25 07:40:21 +01:00
|
|
|
* side effects - message is sent to matching servers with caps.
|
|
|
|
*/
|
|
|
|
void
|
2016-08-22 03:57:43 +02:00
|
|
|
sendto_match_servs(client::client *source_p, const char *mask, int cap,
|
2007-01-25 07:40:21 +01:00
|
|
|
int nocap, const char *pattern, ...)
|
|
|
|
{
|
|
|
|
static char buf[BUFSIZE];
|
|
|
|
va_list args;
|
2008-04-01 22:41:52 +02:00
|
|
|
rb_dlink_node *ptr;
|
2016-08-22 03:57:43 +02:00
|
|
|
client::client *target_p;
|
2008-04-01 23:51:34 +02:00
|
|
|
buf_head_t rb_linebuf_id;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
if(EmptyString(mask))
|
|
|
|
return;
|
|
|
|
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_linebuf_newbuf(&rb_linebuf_id);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
va_start(args, pattern);
|
2016-02-10 02:25:32 +01:00
|
|
|
vsnprintf(buf, sizeof(buf), pattern, args);
|
2007-01-25 07:40:21 +01:00
|
|
|
va_end(args);
|
|
|
|
|
2014-03-03 05:25:47 +01:00
|
|
|
rb_linebuf_putmsg(&rb_linebuf_id, NULL, NULL,
|
2007-01-25 07:40:21 +01:00
|
|
|
":%s %s", use_id(source_p), buf);
|
|
|
|
|
|
|
|
current_serial++;
|
|
|
|
|
2008-04-01 22:43:10 +02:00
|
|
|
RB_DLINK_FOREACH(ptr, global_serv_list.head)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-22 03:57:43 +02:00
|
|
|
target_p = (client::client *)ptr->data;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
/* dont send to ourselves, or back to where it came from.. */
|
2016-08-23 04:33:36 +02:00
|
|
|
if(is_me(*target_p) || target_p->from == source_p->from)
|
2007-01-25 07:40:21 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if(target_p->from->serial == current_serial)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if(match(mask, target_p->name))
|
|
|
|
{
|
|
|
|
/* if we set the serial here, then we'll never do
|
|
|
|
* a match() again if !IsCapable()
|
|
|
|
*/
|
|
|
|
target_p->from->serial = current_serial;
|
|
|
|
|
|
|
|
if(cap && !IsCapable(target_p->from, cap))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if(nocap && !NotCapable(target_p->from, nocap))
|
|
|
|
continue;
|
|
|
|
|
2008-06-14 02:30:30 +02:00
|
|
|
_send_linebuf(target_p->from, &rb_linebuf_id);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_linebuf_donebuf(&rb_linebuf_id);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
2015-03-01 07:44:34 +01:00
|
|
|
/* sendto_local_clients_with_capability()
|
|
|
|
*
|
|
|
|
* inputs - caps needed, pattern, va_args
|
|
|
|
* outputs -
|
|
|
|
* side effects - message is sent to matching local clients with caps.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
sendto_local_clients_with_capability(int cap, const char *pattern, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
rb_dlink_node *ptr;
|
2016-08-22 03:57:43 +02:00
|
|
|
client::client *target_p;
|
2015-03-01 07:44:34 +01:00
|
|
|
buf_head_t linebuf;
|
|
|
|
|
|
|
|
rb_linebuf_newbuf(&linebuf);
|
|
|
|
|
|
|
|
va_start(args, pattern);
|
|
|
|
rb_linebuf_putmsg(&linebuf, pattern, &args, NULL);
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
RB_DLINK_FOREACH(ptr, lclient_list.head)
|
|
|
|
{
|
2016-08-22 03:57:43 +02:00
|
|
|
target_p = (client::client *)ptr->data;
|
2015-03-01 07:44:34 +01:00
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if(is_io_error(*target_p) || !IsCapable(target_p, cap))
|
2015-03-01 07:44:34 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
send_linebuf(target_p, &linebuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
rb_linebuf_donebuf(&linebuf);
|
|
|
|
}
|
|
|
|
|
2007-07-01 00:15:35 +02:00
|
|
|
/* sendto_monitor()
|
|
|
|
*
|
|
|
|
* inputs - monitor nick to send to, format, va_args
|
|
|
|
* outputs - message to local users monitoring the given nick
|
|
|
|
* side effects -
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
sendto_monitor(struct monitor *monptr, const char *pattern, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
buf_head_t linebuf;
|
2016-08-22 03:57:43 +02:00
|
|
|
client::client *target_p;
|
2008-04-01 22:41:52 +02:00
|
|
|
rb_dlink_node *ptr;
|
2008-04-02 00:47:17 +02:00
|
|
|
rb_dlink_node *next_ptr;
|
2014-03-03 05:25:47 +01:00
|
|
|
|
|
|
|
rb_linebuf_newbuf(&linebuf);
|
|
|
|
|
2007-07-01 00:15:35 +02:00
|
|
|
va_start(args, pattern);
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_linebuf_putmsg(&linebuf, pattern, &args, NULL);
|
2007-07-01 00:15:35 +02:00
|
|
|
va_end(args);
|
|
|
|
|
2008-04-02 00:47:17 +02:00
|
|
|
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, monptr->users.head)
|
2007-07-01 00:15:35 +02:00
|
|
|
{
|
2016-08-22 03:57:43 +02:00
|
|
|
target_p = (client::client *)ptr->data;
|
2007-07-01 00:15:35 +02:00
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if(is_io_error(*target_p))
|
2007-07-01 00:15:35 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
_send_linebuf(target_p, &linebuf);
|
|
|
|
}
|
|
|
|
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_linebuf_donebuf(&linebuf);
|
2007-07-01 00:15:35 +02:00
|
|
|
}
|
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
/* sendto_anywhere()
|
|
|
|
*
|
|
|
|
* inputs - target, source, va_args
|
|
|
|
* outputs -
|
|
|
|
* side effects - client is sent message with correct prefix.
|
|
|
|
*/
|
|
|
|
void
|
2016-08-22 03:57:43 +02:00
|
|
|
sendto_anywhere(client::client *target_p, client::client *source_p,
|
2007-01-25 07:40:21 +01:00
|
|
|
const char *command, const char *pattern, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
buf_head_t linebuf;
|
|
|
|
|
2016-02-21 01:12:46 +01:00
|
|
|
rb_linebuf_newbuf(&linebuf);
|
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
va_start(args, pattern);
|
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if(my(*target_p))
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-23 04:33:36 +02:00
|
|
|
if(is_server(*source_p))
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_linebuf_putmsg(&linebuf, pattern, &args, ":%s %s %s ",
|
2014-03-03 05:25:47 +01:00
|
|
|
source_p->name, command,
|
2007-01-25 07:40:21 +01:00
|
|
|
target_p->name);
|
|
|
|
else
|
2016-02-20 23:37:19 +01:00
|
|
|
{
|
|
|
|
struct MsgBuf msgbuf;
|
|
|
|
|
|
|
|
build_msgbuf_from(&msgbuf, source_p, command);
|
2016-02-21 00:59:38 +01:00
|
|
|
msgbuf.target = target_p->name;
|
|
|
|
|
2016-02-20 23:37:19 +01:00
|
|
|
linebuf_put_msgvbuf(&msgbuf, &linebuf, target_p->localClient->caps, pattern, &args);
|
|
|
|
}
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
else
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_linebuf_putmsg(&linebuf, pattern, &args, ":%s %s %s ",
|
2007-01-25 07:40:21 +01:00
|
|
|
get_id(source_p, target_p), command,
|
|
|
|
get_id(target_p, target_p));
|
|
|
|
va_end(args);
|
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if(my(*target_p))
|
2007-01-25 07:40:21 +01:00
|
|
|
_send_linebuf(target_p, &linebuf);
|
|
|
|
else
|
|
|
|
send_linebuf_remote(target_p, source_p, &linebuf);
|
|
|
|
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_linebuf_donebuf(&linebuf);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* sendto_realops_snomask()
|
|
|
|
*
|
|
|
|
* inputs - snomask needed, level (opers/admin), va_args
|
|
|
|
* output -
|
|
|
|
* side effects - message is sent to opers with matching snomasks
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
sendto_realops_snomask(int flags, int level, const char *pattern, ...)
|
|
|
|
{
|
|
|
|
static char buf[BUFSIZE];
|
2016-08-22 03:57:43 +02:00
|
|
|
client::client *client_p;
|
2008-04-01 22:41:52 +02:00
|
|
|
rb_dlink_node *ptr;
|
2008-04-02 00:47:17 +02:00
|
|
|
rb_dlink_node *next_ptr;
|
2007-01-25 07:40:21 +01:00
|
|
|
va_list args;
|
|
|
|
buf_head_t linebuf;
|
|
|
|
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_linebuf_newbuf(&linebuf);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
/* Be very sure not to do things like "Trying to send to myself"
|
|
|
|
* L_NETWIDE, otherwise infinite recursion may result! -- jilles */
|
|
|
|
if (level & L_NETWIDE && ConfigFileEntry.global_snotices)
|
|
|
|
{
|
|
|
|
/* rather a lot of copying around, oh well -- jilles */
|
|
|
|
va_start(args, pattern);
|
2016-02-10 02:25:32 +01:00
|
|
|
vsnprintf(buf, sizeof(buf), pattern, args);
|
2007-01-25 07:40:21 +01:00
|
|
|
va_end(args);
|
2014-03-03 05:25:47 +01:00
|
|
|
rb_linebuf_putmsg(&linebuf, pattern, NULL,
|
2007-01-25 07:40:21 +01:00
|
|
|
":%s NOTICE * :*** Notice -- %s", me.name, buf);
|
2016-08-26 13:50:12 +02:00
|
|
|
|
|
|
|
static char snobuf[128];
|
|
|
|
if(*delta(sno::table, 0, flags, snobuf))
|
2007-01-25 07:40:21 +01:00
|
|
|
sendto_server(NULL, NULL, CAP_ENCAP|CAP_TS6, NOCAPS,
|
2016-08-26 13:50:12 +02:00
|
|
|
":%s ENCAP * SNOTE %c :%s",
|
|
|
|
me.id,
|
|
|
|
snobuf[1],
|
|
|
|
buf);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
2009-03-07 01:27:05 +01:00
|
|
|
else if (remote_rehash_oper_p != NULL)
|
|
|
|
{
|
|
|
|
/* rather a lot of copying around, oh well -- jilles */
|
|
|
|
va_start(args, pattern);
|
2016-02-10 02:25:32 +01:00
|
|
|
vsnprintf(buf, sizeof(buf), pattern, args);
|
2009-03-07 01:27:05 +01:00
|
|
|
va_end(args);
|
2014-03-03 05:25:47 +01:00
|
|
|
rb_linebuf_putmsg(&linebuf, pattern, NULL,
|
2009-03-07 01:27:05 +01:00
|
|
|
":%s NOTICE * :*** Notice -- %s", me.name, buf);
|
|
|
|
sendto_one_notice(remote_rehash_oper_p, ":*** Notice -- %s", buf);
|
|
|
|
}
|
2007-01-25 07:40:21 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
va_start(args, pattern);
|
2014-03-03 05:25:47 +01:00
|
|
|
rb_linebuf_putmsg(&linebuf, pattern, &args,
|
2007-01-25 07:40:21 +01:00
|
|
|
":%s NOTICE * :*** Notice -- ", me.name);
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
level &= ~L_NETWIDE;
|
|
|
|
|
2008-04-02 00:47:17 +02:00
|
|
|
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, local_oper_list.head)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-22 03:57:43 +02:00
|
|
|
client_p = (client::client *)ptr->data;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
/* If we're sending it to opers and theyre an admin, skip.
|
|
|
|
* If we're sending it to admins, and theyre not, skip.
|
|
|
|
*/
|
|
|
|
if(((level == L_ADMIN) && !IsOperAdmin(client_p)) ||
|
|
|
|
((level == L_OPER) && IsOperAdmin(client_p)))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if(client_p->snomask & flags)
|
|
|
|
_send_linebuf(client_p, &linebuf);
|
|
|
|
}
|
|
|
|
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_linebuf_donebuf(&linebuf);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
/* sendto_realops_snomask_from()
|
|
|
|
*
|
|
|
|
* inputs - snomask needed, level (opers/admin), source server, va_args
|
|
|
|
* output -
|
|
|
|
* side effects - message is sent to opers with matching snomask
|
|
|
|
*/
|
|
|
|
void
|
2016-08-22 03:57:43 +02:00
|
|
|
sendto_realops_snomask_from(int flags, int level, client::client *source_p,
|
2007-01-25 07:40:21 +01:00
|
|
|
const char *pattern, ...)
|
|
|
|
{
|
2016-08-22 03:57:43 +02:00
|
|
|
client::client *client_p;
|
2008-04-01 22:41:52 +02:00
|
|
|
rb_dlink_node *ptr;
|
2008-04-02 00:47:17 +02:00
|
|
|
rb_dlink_node *next_ptr;
|
2007-01-25 07:40:21 +01:00
|
|
|
va_list args;
|
|
|
|
buf_head_t linebuf;
|
|
|
|
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_linebuf_newbuf(&linebuf);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
va_start(args, pattern);
|
2014-03-03 05:25:47 +01:00
|
|
|
rb_linebuf_putmsg(&linebuf, pattern, &args,
|
2007-01-25 07:40:21 +01:00
|
|
|
":%s NOTICE * :*** Notice -- ", source_p->name);
|
|
|
|
va_end(args);
|
|
|
|
|
2008-04-02 00:47:17 +02:00
|
|
|
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, local_oper_list.head)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-22 03:57:43 +02:00
|
|
|
client_p = (client::client *)ptr->data;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
/* If we're sending it to opers and theyre an admin, skip.
|
|
|
|
* If we're sending it to admins, and theyre not, skip.
|
|
|
|
*/
|
|
|
|
if(((level == L_ADMIN) && !IsOperAdmin(client_p)) ||
|
|
|
|
((level == L_OPER) && IsOperAdmin(client_p)))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if(client_p->snomask & flags)
|
|
|
|
_send_linebuf(client_p, &linebuf);
|
|
|
|
}
|
|
|
|
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_linebuf_donebuf(&linebuf);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* sendto_wallops_flags
|
|
|
|
*
|
|
|
|
* inputs - flag types of messages to show to real opers
|
|
|
|
* - client sending request
|
|
|
|
* - var args input message
|
|
|
|
* output - NONE
|
|
|
|
* side effects - Send a wallops to local opers
|
|
|
|
*/
|
|
|
|
void
|
2016-08-22 03:57:43 +02:00
|
|
|
sendto_wallops_flags(int flags, client::client *source_p, const char *pattern, ...)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-22 03:57:43 +02:00
|
|
|
client::client *client_p;
|
2008-04-01 22:41:52 +02:00
|
|
|
rb_dlink_node *ptr;
|
2008-04-02 00:47:17 +02:00
|
|
|
rb_dlink_node *next_ptr;
|
2007-01-25 07:40:21 +01:00
|
|
|
va_list args;
|
|
|
|
buf_head_t linebuf;
|
|
|
|
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_linebuf_newbuf(&linebuf);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
va_start(args, pattern);
|
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if(is_person(*source_p))
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_linebuf_putmsg(&linebuf, pattern, &args,
|
2007-01-25 07:40:21 +01:00
|
|
|
":%s!%s@%s WALLOPS :", source_p->name,
|
|
|
|
source_p->username, source_p->host);
|
|
|
|
else
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_linebuf_putmsg(&linebuf, pattern, &args, ":%s WALLOPS :", source_p->name);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
va_end(args);
|
|
|
|
|
2016-08-24 00:25:09 +02:00
|
|
|
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, is_person(*source_p) && flags == umode::WALLOP ? lclient_list.head : local_oper_list.head)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-22 03:57:43 +02:00
|
|
|
client_p = (client::client *)ptr->data;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-08-24 00:25:09 +02:00
|
|
|
if (is(*client_p, umode(flags)))
|
2007-01-25 07:40:21 +01:00
|
|
|
_send_linebuf(client_p, &linebuf);
|
|
|
|
}
|
|
|
|
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_linebuf_donebuf(&linebuf);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* kill_client()
|
|
|
|
*
|
|
|
|
* input - client to send kill to, client to kill, va_args
|
|
|
|
* output -
|
|
|
|
* side effects - we issue a kill for the client
|
|
|
|
*/
|
|
|
|
void
|
2016-08-22 03:57:43 +02:00
|
|
|
kill_client(client::client *target_p, client::client *diedie, const char *pattern, ...)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
buf_head_t linebuf;
|
|
|
|
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_linebuf_newbuf(&linebuf);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
va_start(args, pattern);
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_linebuf_putmsg(&linebuf, pattern, &args, ":%s KILL %s :",
|
2007-01-25 07:40:21 +01:00
|
|
|
get_id(&me, target_p), get_id(diedie, target_p));
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
send_linebuf(target_p, &linebuf);
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_linebuf_donebuf(&linebuf);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* kill_client_serv_butone
|
|
|
|
*
|
|
|
|
* inputs - pointer to client to not send to
|
|
|
|
* - pointer to client to kill
|
|
|
|
* output - NONE
|
|
|
|
* side effects - Send a KILL for the given client
|
|
|
|
* message to all connected servers
|
|
|
|
* except the client 'one'. Also deal with
|
|
|
|
* client being unknown to leaf, as in lazylink...
|
|
|
|
*/
|
|
|
|
void
|
2016-08-22 03:57:43 +02:00
|
|
|
kill_client_serv_butone(client::client *one, client::client *target_p, const char *pattern, ...)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
static char buf[BUFSIZE];
|
|
|
|
va_list args;
|
2016-08-22 03:57:43 +02:00
|
|
|
client::client *client_p;
|
2008-04-01 22:41:52 +02:00
|
|
|
rb_dlink_node *ptr;
|
2008-04-02 00:47:17 +02:00
|
|
|
rb_dlink_node *next_ptr;
|
2008-04-01 23:51:34 +02:00
|
|
|
buf_head_t rb_linebuf_id;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_linebuf_newbuf(&rb_linebuf_id);
|
2014-03-03 05:25:47 +01:00
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
va_start(args, pattern);
|
2016-02-10 02:25:32 +01:00
|
|
|
vsnprintf(buf, sizeof(buf), pattern, args);
|
2007-01-25 07:40:21 +01:00
|
|
|
va_end(args);
|
|
|
|
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_linebuf_putmsg(&rb_linebuf_id, NULL, NULL, ":%s KILL %s :%s",
|
2007-01-25 07:40:21 +01:00
|
|
|
use_id(&me), use_id(target_p), buf);
|
|
|
|
|
2008-04-02 00:47:17 +02:00
|
|
|
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, serv_list.head)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-22 03:57:43 +02:00
|
|
|
client_p = (client::client *)ptr->data;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
/* ok, if the client we're supposed to not send to has an
|
|
|
|
* ID, then we still want to issue the kill there..
|
|
|
|
*/
|
|
|
|
if(one != NULL && (client_p == one->from) &&
|
|
|
|
(!has_id(client_p) || !has_id(target_p)))
|
|
|
|
continue;
|
|
|
|
|
2008-06-14 02:30:30 +02:00
|
|
|
_send_linebuf(client_p, &rb_linebuf_id);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
2008-04-01 23:51:34 +02:00
|
|
|
rb_linebuf_donebuf(&rb_linebuf_id);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
2016-08-13 05:05:54 +02:00
|
|
|
|
|
|
|
} // namespace ircd
|