2007-01-25 06:40:21 +00: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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stdinc.h"
|
|
|
|
#include "send.h"
|
|
|
|
#include "channel.h"
|
|
|
|
#include "class.h"
|
|
|
|
#include "client.h"
|
2008-04-20 05:47:38 +00:00
|
|
|
#include "match.h"
|
2007-01-25 06:40:21 +00:00
|
|
|
#include "ircd.h"
|
|
|
|
#include "numeric.h"
|
2016-11-23 21:43:33 +00:00
|
|
|
#include "s_assert.h"
|
2007-01-25 06:40:21 +00:00
|
|
|
#include "s_serv.h"
|
|
|
|
#include "s_conf.h"
|
|
|
|
#include "s_newconf.h"
|
2008-04-03 02:52:01 +00:00
|
|
|
#include "logger.h"
|
2007-01-25 06:40:21 +00:00
|
|
|
#include "hook.h"
|
2007-06-30 22:15:35 +00:00
|
|
|
#include "monitor.h"
|
2016-02-20 21:49:41 +00:00
|
|
|
#include "msgbuf.h"
|
2007-01-25 06:40:21 +00: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)
|
|
|
|
|
2017-08-06 11:05:24 +00:00
|
|
|
#define CLIENT_CAPS_ONLY(x) ((IsClient((x)) && (x)->localClient) ? (x)->localClient->caps : 0)
|
|
|
|
|
2008-04-01 21:51:34 +00:00
|
|
|
static void send_queued_write(rb_fde_t *F, void *data);
|
|
|
|
|
2007-01-25 06:40:21 +00:00
|
|
|
unsigned long current_serial = 0L;
|
|
|
|
|
2009-03-07 00:27:05 +00:00
|
|
|
struct Client *remote_rehash_oper_p;
|
|
|
|
|
2007-01-25 06:40:21 +00:00
|
|
|
/* send_linebuf()
|
|
|
|
*
|
|
|
|
* inputs - client to send to, linebuf to attach
|
|
|
|
* outputs -
|
|
|
|
* side effects - linebuf is attached to client
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
_send_linebuf(struct Client *to, buf_head_t *linebuf)
|
|
|
|
{
|
|
|
|
if(IsMe(to))
|
|
|
|
{
|
|
|
|
sendto_realops_snomask(SNO_GENERAL, L_ALL, "Trying to send message to myself!");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!MyConnect(to) || IsIOError(to))
|
|
|
|
return 0;
|
|
|
|
|
2016-01-21 03:27:33 +00:00
|
|
|
if(rb_linebuf_len(&to->localClient->buf_sendq) > get_sendq(to))
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
if(IsServer(to))
|
|
|
|
{
|
|
|
|
sendto_realops_snomask(SNO_GENERAL, L_ALL,
|
2016-01-21 03:27:33 +00:00
|
|
|
"Max SendQ limit exceeded for %s: %u > %lu",
|
2008-06-28 10:13:50 +00:00
|
|
|
to->name,
|
2014-03-03 04:25:47 +00:00
|
|
|
rb_linebuf_len(&to->localClient->buf_sendq),
|
2016-01-21 03:27:33 +00:00
|
|
|
get_sendq(to));
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2016-01-21 03:27:33 +00:00
|
|
|
ilog(L_SERVER, "Max SendQ limit exceeded for %s: %u > %lu",
|
2007-01-25 06:40:21 +00:00
|
|
|
log_client_name(to, SHOW_IP),
|
2014-03-03 04:25:47 +00:00
|
|
|
rb_linebuf_len(&to->localClient->buf_sendq),
|
2016-01-21 03:27:33 +00:00
|
|
|
get_sendq(to));
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
|
2009-12-21 15:58:25 +00:00
|
|
|
dead_link(to, 1);
|
2007-01-25 06:40:21 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* just attach the linebuf to the sendq instead of
|
|
|
|
* generating a new one
|
|
|
|
*/
|
2008-04-01 21:51:34 +00:00
|
|
|
rb_linebuf_attach(&to->localClient->buf_sendq, linebuf);
|
2007-01-25 06:40:21 +00: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 21:51:34 +00:00
|
|
|
if(rb_linebuf_len(&to->localClient->buf_sendq) > 0)
|
|
|
|
send_queued(to);
|
2007-01-25 06:40:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* send_linebuf_remote()
|
|
|
|
*
|
|
|
|
* inputs - client to attach to, sender, linebuf
|
|
|
|
* outputs -
|
|
|
|
* side effects - client has linebuf attached
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
send_linebuf_remote(struct Client *to, struct Client *from, buf_head_t *linebuf)
|
|
|
|
{
|
|
|
|
if(to->from)
|
|
|
|
to = to->from;
|
|
|
|
|
2008-01-17 00:06:32 +00:00
|
|
|
/* we assume the caller has already tested for fake direction */
|
2007-01-25 06:40:21 +00: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
|
2008-04-01 21:51:34 +00:00
|
|
|
send_queued(struct Client *to)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
int retlen;
|
2016-02-20 18:02:49 +00:00
|
|
|
|
2008-04-01 21:51:34 +00:00
|
|
|
rb_fde_t *F = to->localClient->F;
|
2007-12-22 22:28:05 +00:00
|
|
|
if (!F)
|
|
|
|
return;
|
|
|
|
|
2007-01-25 06:40:21 +00:00
|
|
|
/* cant write anything to a dead socket. */
|
|
|
|
if(IsIOError(to))
|
|
|
|
return;
|
|
|
|
|
2008-04-13 15:54:23 +00:00
|
|
|
/* try to flush later when the write event resets this */
|
|
|
|
if(IsFlush(to))
|
2008-04-06 14:52:42 +00:00
|
|
|
return;
|
|
|
|
|
2008-04-01 21:51:34 +00:00
|
|
|
if(rb_linebuf_len(&to->localClient->buf_sendq))
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
while ((retlen =
|
2008-04-01 21:51:34 +00:00
|
|
|
rb_linebuf_flush(F, &to->localClient->buf_sendq)) > 0)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
/* We have some data written .. update counters */
|
2008-04-06 14:52:42 +00:00
|
|
|
ClearFlush(to);
|
|
|
|
|
2007-01-25 06:40:21 +00: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 21:51:34 +00:00
|
|
|
if(retlen == 0 || (retlen < 0 && !rb_ignore_errno(errno)))
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
2009-12-21 15:58:25 +00:00
|
|
|
dead_link(to, 0);
|
2007-01-25 06:40:21 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2008-04-06 14:52:42 +00:00
|
|
|
|
2008-04-13 15:54:23 +00: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 14:52:42 +00:00
|
|
|
ClearFlush(to);
|
|
|
|
}
|
|
|
|
|
2008-04-13 15:54:23 +00:00
|
|
|
void
|
|
|
|
send_pop_queue(struct Client *to)
|
|
|
|
{
|
|
|
|
if(to->from != NULL)
|
|
|
|
to = to->from;
|
|
|
|
if(!MyConnect(to) || IsIOError(to))
|
|
|
|
return;
|
|
|
|
if(rb_linebuf_len(&to->localClient->buf_sendq) > 0)
|
|
|
|
send_queued(to);
|
2008-04-01 21:51:34 +00: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)
|
|
|
|
{
|
|
|
|
struct Client *to = data;
|
2008-04-06 14:52:42 +00:00
|
|
|
ClearFlush(to);
|
2008-04-01 21:51:34 +00:00
|
|
|
send_queued(to);
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
|
2016-02-20 22:37:19 +00:00
|
|
|
/*
|
2017-08-06 11:05:24 +00:00
|
|
|
* linebuf_put_*
|
2016-02-20 21:49:41 +00:00
|
|
|
*
|
|
|
|
* inputs - msgbuf header, linebuf object, capability mask, pattern, arguments
|
|
|
|
* outputs - none
|
2017-08-06 11:05:24 +00:00
|
|
|
* side effects - the linebuf object is cleared, then populated
|
2016-02-20 21:49:41 +00:00
|
|
|
*/
|
|
|
|
static void
|
2017-08-06 11:05:24 +00:00
|
|
|
linebuf_put_tags(buf_head_t *linebuf, const struct MsgBuf *msgbuf, const struct Client *target_p, rb_strf_t *message)
|
2016-02-20 21:49:41 +00:00
|
|
|
{
|
2017-08-06 11:05:24 +00:00
|
|
|
struct MsgBuf_str_data msgbuf_str_data = { .msgbuf = msgbuf, .caps = CLIENT_CAPS_ONLY(target_p) };
|
|
|
|
rb_strf_t strings = { .func = msgbuf_unparse_linebuf_tags, .func_args = &msgbuf_str_data, .length = TAGSLEN + 1, .next = message };
|
2016-02-20 21:49:41 +00:00
|
|
|
|
2017-08-06 11:05:24 +00:00
|
|
|
message->length = DATALEN + 1;
|
|
|
|
rb_linebuf_put(linebuf, &strings);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
linebuf_put_tagsf(buf_head_t *linebuf, const struct MsgBuf *msgbuf, const struct Client *target_p, const rb_strf_t *message, const char *format, ...)
|
|
|
|
{
|
|
|
|
va_list va;
|
|
|
|
rb_strf_t strings = { .format = format, .format_args = &va, .next = message };
|
|
|
|
|
|
|
|
va_start(va, format);
|
|
|
|
linebuf_put_tags(linebuf, msgbuf, target_p, &strings);
|
|
|
|
va_end(va);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
linebuf_put_msg(buf_head_t *linebuf, rb_strf_t *message)
|
|
|
|
{
|
|
|
|
message->length = DATALEN + 1;
|
|
|
|
rb_linebuf_put(linebuf, message);
|
2016-03-23 02:53:56 +00:00
|
|
|
}
|
2016-02-20 22:37:19 +00:00
|
|
|
|
|
|
|
static void
|
2017-08-06 11:05:24 +00:00
|
|
|
linebuf_put_msgf(buf_head_t *linebuf, const rb_strf_t *message, const char *format, ...)
|
2016-02-20 22:37:19 +00:00
|
|
|
{
|
|
|
|
va_list va;
|
2017-08-06 11:05:24 +00:00
|
|
|
rb_strf_t strings = { .format = format, .format_args = &va, .next = message };
|
2016-02-20 21:49:41 +00:00
|
|
|
|
2017-08-06 11:05:24 +00:00
|
|
|
va_start(va, format);
|
|
|
|
linebuf_put_msg(linebuf, &strings);
|
2016-02-20 21:49:41 +00:00
|
|
|
va_end(va);
|
|
|
|
}
|
|
|
|
|
2017-08-06 11:05:24 +00:00
|
|
|
/* build_msgbuf_tags
|
2016-02-20 21:49:41 +00:00
|
|
|
*
|
|
|
|
* 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
|
2017-08-06 11:05:24 +00:00
|
|
|
build_msgbuf_tags(struct MsgBuf *msgbuf, struct Client *from)
|
2016-02-20 21:49:41 +00:00
|
|
|
{
|
|
|
|
hook_data hdata;
|
|
|
|
|
|
|
|
msgbuf_init(msgbuf);
|
|
|
|
|
|
|
|
hdata.client = from;
|
|
|
|
hdata.arg1 = msgbuf;
|
|
|
|
|
|
|
|
call_hook(h_outbound_msgbuf, &hdata);
|
|
|
|
}
|
|
|
|
|
2007-01-25 06:40:21 +00:00
|
|
|
/* sendto_one()
|
|
|
|
*
|
|
|
|
* inputs - client to send to, va_args
|
|
|
|
* outputs - client has message put into its queue
|
2014-03-03 04:25:47 +00:00
|
|
|
* side effects -
|
2007-01-25 06:40:21 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
sendto_one(struct Client *target_p, const char *pattern, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
2017-08-06 11:05:24 +00:00
|
|
|
struct MsgBuf msgbuf;
|
2007-01-25 06:40:21 +00:00
|
|
|
buf_head_t linebuf;
|
2017-08-06 11:05:24 +00:00
|
|
|
rb_strf_t strings = { .format = pattern, .format_args = &args, .next = NULL };
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
/* send remote if to->from non NULL */
|
|
|
|
if(target_p->from != NULL)
|
|
|
|
target_p = target_p->from;
|
|
|
|
|
|
|
|
if(IsIOError(target_p))
|
|
|
|
return;
|
|
|
|
|
2008-04-01 21:51:34 +00:00
|
|
|
rb_linebuf_newbuf(&linebuf);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2017-08-06 11:05:24 +00:00
|
|
|
build_msgbuf_tags(&msgbuf, &me);
|
2007-01-25 06:40:21 +00:00
|
|
|
va_start(args, pattern);
|
2017-08-06 11:05:24 +00:00
|
|
|
linebuf_put_tags(&linebuf, &msgbuf, target_p, &strings);
|
2007-01-25 06:40:21 +00:00
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
_send_linebuf(target_p, &linebuf);
|
|
|
|
|
2008-04-01 21:51:34 +00:00
|
|
|
rb_linebuf_donebuf(&linebuf);
|
2007-01-25 06:40:21 +00: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
|
|
|
|
sendto_one_prefix(struct Client *target_p, struct Client *source_p,
|
|
|
|
const char *command, const char *pattern, ...)
|
|
|
|
{
|
2017-07-29 18:25:11 +00:00
|
|
|
struct Client *dest_p = target_p->from;
|
2007-01-25 06:40:21 +00:00
|
|
|
va_list args;
|
2017-08-06 11:05:24 +00:00
|
|
|
struct MsgBuf msgbuf;
|
2007-01-25 06:40:21 +00:00
|
|
|
buf_head_t linebuf;
|
2017-08-06 11:05:24 +00:00
|
|
|
rb_strf_t strings = { .format = pattern, .format_args = &args, .next = NULL };
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
if(IsIOError(dest_p))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(IsMe(dest_p))
|
|
|
|
{
|
|
|
|
sendto_realops_snomask(SNO_GENERAL, L_ALL, "Trying to send to myself!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-08-06 11:05:24 +00:00
|
|
|
build_msgbuf_tags(&msgbuf, source_p);
|
|
|
|
|
2008-04-01 21:51:34 +00:00
|
|
|
rb_linebuf_newbuf(&linebuf);
|
2007-01-25 06:40:21 +00:00
|
|
|
va_start(args, pattern);
|
2017-08-06 11:05:24 +00:00
|
|
|
linebuf_put_tagsf(&linebuf, &msgbuf, target_p, &strings,
|
|
|
|
":%s %s %s ", get_id(source_p, target_p),
|
|
|
|
command, get_id(target_p, target_p));
|
2007-01-25 06:40:21 +00:00
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
_send_linebuf(dest_p, &linebuf);
|
2008-04-01 21:51:34 +00:00
|
|
|
rb_linebuf_donebuf(&linebuf);
|
2007-01-25 06:40:21 +00: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
|
|
|
|
sendto_one_notice(struct Client *target_p, const char *pattern, ...)
|
|
|
|
{
|
2017-07-29 19:41:37 +00:00
|
|
|
struct Client *dest_p = target_p->from;
|
2007-01-25 06:40:21 +00:00
|
|
|
va_list args;
|
2017-08-06 11:05:24 +00:00
|
|
|
struct MsgBuf msgbuf;
|
2007-01-25 06:40:21 +00:00
|
|
|
buf_head_t linebuf;
|
2017-08-06 11:05:24 +00:00
|
|
|
rb_strf_t strings = { .format = pattern, .format_args = &args, .next = NULL };
|
2007-01-25 07:23:01 +00:00
|
|
|
char *to;
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
if(IsIOError(dest_p))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(IsMe(dest_p))
|
|
|
|
{
|
|
|
|
sendto_realops_snomask(SNO_GENERAL, L_ALL, "Trying to send to myself!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-08-06 11:05:24 +00:00
|
|
|
build_msgbuf_tags(&msgbuf, &me);
|
|
|
|
|
2008-04-01 21:51:34 +00:00
|
|
|
rb_linebuf_newbuf(&linebuf);
|
2007-01-25 06:40:21 +00:00
|
|
|
va_start(args, pattern);
|
2017-08-06 11:05:24 +00:00
|
|
|
linebuf_put_tagsf(&linebuf, &msgbuf, target_p, &strings,
|
|
|
|
":%s NOTICE %s ", get_id(&me, target_p),
|
|
|
|
*(to = get_id(target_p, target_p)) != '\0' ? to : "*");
|
2007-01-25 06:40:21 +00:00
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
_send_linebuf(dest_p, &linebuf);
|
2008-04-01 21:51:34 +00:00
|
|
|
rb_linebuf_donebuf(&linebuf);
|
2007-01-25 06:40:21 +00: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
|
|
|
|
sendto_one_numeric(struct Client *target_p, int numeric, const char *pattern, ...)
|
|
|
|
{
|
2017-07-29 19:16:59 +00:00
|
|
|
struct Client *dest_p = target_p->from;
|
2007-01-25 06:40:21 +00:00
|
|
|
va_list args;
|
2017-08-06 11:05:24 +00:00
|
|
|
struct MsgBuf msgbuf;
|
2007-01-25 06:40:21 +00:00
|
|
|
buf_head_t linebuf;
|
2017-08-06 11:05:24 +00:00
|
|
|
rb_strf_t strings = { .format = pattern, .format_args = &args, .next = NULL };
|
2007-01-25 07:23:01 +00:00
|
|
|
char *to;
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
if(IsIOError(dest_p))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(IsMe(dest_p))
|
|
|
|
{
|
|
|
|
sendto_realops_snomask(SNO_GENERAL, L_ALL, "Trying to send to myself!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-08-06 11:05:24 +00:00
|
|
|
build_msgbuf_tags(&msgbuf, &me);
|
|
|
|
|
2008-04-01 21:51:34 +00:00
|
|
|
rb_linebuf_newbuf(&linebuf);
|
2007-01-25 06:40:21 +00:00
|
|
|
va_start(args, pattern);
|
2017-08-06 11:05:24 +00:00
|
|
|
linebuf_put_tagsf(&linebuf, &msgbuf, target_p, &strings,
|
|
|
|
":%s %03d %s ", get_id(&me, target_p), numeric,
|
|
|
|
*(to = get_id(target_p, target_p)) != '\0' ? to : "*");
|
2007-01-25 06:40:21 +00:00
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
_send_linebuf(dest_p, &linebuf);
|
2008-04-01 21:51:34 +00:00
|
|
|
rb_linebuf_donebuf(&linebuf);
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* sendto_server
|
2014-03-03 04:25:47 +00:00
|
|
|
*
|
2007-01-25 06:40:21 +00: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 04:25:47 +00:00
|
|
|
*
|
2007-01-25 06:40:21 +00: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
|
|
|
|
sendto_server(struct Client *one, struct Channel *chptr, unsigned long caps,
|
|
|
|
unsigned long nocaps, const char *format, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
struct Client *target_p;
|
2008-04-01 20:41:52 +00:00
|
|
|
rb_dlink_node *ptr;
|
2008-04-01 22:47:17 +00:00
|
|
|
rb_dlink_node *next_ptr;
|
2007-01-25 06:40:21 +00:00
|
|
|
buf_head_t linebuf;
|
2017-08-06 11:05:24 +00:00
|
|
|
rb_strf_t strings = { .format = format, .format_args = &args, .next = NULL };
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
/* noone to send to.. */
|
2008-04-01 20:41:52 +00:00
|
|
|
if(rb_dlink_list_length(&serv_list) == 0)
|
2007-01-25 06:40:21 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if(chptr != NULL && *chptr->chname != '#')
|
|
|
|
return;
|
|
|
|
|
2008-04-01 21:51:34 +00:00
|
|
|
rb_linebuf_newbuf(&linebuf);
|
2007-01-25 06:40:21 +00:00
|
|
|
va_start(args, format);
|
2017-08-06 11:05:24 +00:00
|
|
|
linebuf_put_msg(&linebuf, &strings);
|
2007-01-25 06:40:21 +00:00
|
|
|
va_end(args);
|
|
|
|
|
2008-04-01 22:47:17 +00:00
|
|
|
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, serv_list.head)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
target_p = ptr->data;
|
|
|
|
|
|
|
|
/* 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 21:51:34 +00:00
|
|
|
rb_linebuf_donebuf(&linebuf);
|
2007-01-25 06:40:21 +00: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
|
|
|
|
sendto_channel_flags(struct Client *one, int type, struct Client *source_p,
|
|
|
|
struct Channel *chptr, const char *pattern, ...)
|
|
|
|
{
|
2017-07-29 22:24:23 +00:00
|
|
|
static char buf[BUFSIZE];
|
2007-01-25 06:40:21 +00:00
|
|
|
va_list args;
|
2017-07-30 12:47:27 +00:00
|
|
|
buf_head_t rb_linebuf_remote;
|
2007-01-25 06:40:21 +00:00
|
|
|
struct Client *target_p;
|
|
|
|
struct membership *msptr;
|
2008-04-01 20:41:52 +00:00
|
|
|
rb_dlink_node *ptr;
|
2008-04-01 22:47:17 +00:00
|
|
|
rb_dlink_node *next_ptr;
|
2016-02-21 00:27:15 +00:00
|
|
|
struct MsgBuf msgbuf;
|
2017-08-06 11:05:24 +00:00
|
|
|
struct MsgBuf_cache msgbuf_cache;
|
|
|
|
rb_strf_t strings = { .format = buf, .format_args = NULL, .next = NULL };
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2017-07-30 12:47:27 +00:00
|
|
|
rb_linebuf_newbuf(&rb_linebuf_remote);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
current_serial++;
|
|
|
|
|
2017-08-06 11:05:24 +00:00
|
|
|
build_msgbuf_tags(&msgbuf, source_p);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2016-02-21 00:27:15 +00:00
|
|
|
va_start(args, pattern);
|
2016-02-21 00:32:09 +00:00
|
|
|
vsnprintf(buf, sizeof buf, pattern, args);
|
|
|
|
va_end(args);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2017-08-06 11:05:24 +00:00
|
|
|
linebuf_put_msgf(&rb_linebuf_remote, NULL, ":%s %s", use_id(source_p), buf);
|
|
|
|
msgbuf_cache_initf(&msgbuf_cache, &msgbuf, &strings,
|
|
|
|
IsPerson(source_p) ? ":%1$s!%2$s@%3$s " : ":%1$s ",
|
|
|
|
source_p->name, source_p->username, source_p->host);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2008-04-01 22:47:17 +00:00
|
|
|
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->members.head)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
msptr = ptr->data;
|
|
|
|
target_p = msptr->client_p;
|
|
|
|
|
2016-02-27 08:48:37 +00:00
|
|
|
if(!MyClient(source_p) && (IsIOError(target_p->from) || target_p->from == one))
|
|
|
|
continue;
|
|
|
|
|
2016-11-23 21:14:44 +00:00
|
|
|
if(MyClient(source_p) && target_p == one)
|
2007-01-25 06:40:21 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if(type && ((msptr->flags & type) == 0))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if(IsDeaf(target_p))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if(!MyClient(target_p))
|
|
|
|
{
|
|
|
|
/* 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)
|
|
|
|
{
|
2017-07-30 12:47:27 +00:00
|
|
|
send_linebuf_remote(target_p, source_p, &rb_linebuf_remote);
|
2007-01-25 06:40:21 +00:00
|
|
|
target_p->from->serial = current_serial;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2016-02-21 00:27:15 +00:00
|
|
|
{
|
2017-08-06 11:05:24 +00:00
|
|
|
_send_linebuf(target_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAPS_ONLY(target_p)));
|
2016-02-21 00:27:15 +00:00
|
|
|
}
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
|
2016-11-23 21:14:44 +00:00
|
|
|
/* source client may not be on the channel, send echo separately */
|
|
|
|
if(MyClient(source_p) && IsCapable(source_p, CLICAP_ECHO_MESSAGE))
|
|
|
|
{
|
|
|
|
target_p = one;
|
|
|
|
|
2017-08-06 11:05:24 +00:00
|
|
|
_send_linebuf(target_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAPS_ONLY(target_p)));
|
2016-11-23 21:14:44 +00:00
|
|
|
}
|
|
|
|
|
2017-07-30 12:47:27 +00:00
|
|
|
rb_linebuf_donebuf(&rb_linebuf_remote);
|
2017-08-06 11:05:24 +00:00
|
|
|
msgbuf_cache_free(&msgbuf_cache);
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
|
2009-03-29 13:48:07 +00: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
|
|
|
|
sendto_channel_opmod(struct Client *one, struct Client *source_p,
|
|
|
|
struct Channel *chptr, const char *command,
|
|
|
|
const char *text)
|
|
|
|
{
|
|
|
|
buf_head_t rb_linebuf_old;
|
|
|
|
buf_head_t rb_linebuf_new;
|
|
|
|
struct Client *target_p;
|
|
|
|
struct membership *msptr;
|
|
|
|
rb_dlink_node *ptr;
|
|
|
|
rb_dlink_node *next_ptr;
|
2017-08-06 11:05:24 +00:00
|
|
|
struct MsgBuf msgbuf;
|
|
|
|
struct MsgBuf_cache msgbuf_cache;
|
|
|
|
rb_strf_t strings = { .format = text, .format_args = NULL, .next = NULL };
|
2009-03-29 13:48:07 +00:00
|
|
|
|
|
|
|
rb_linebuf_newbuf(&rb_linebuf_old);
|
|
|
|
rb_linebuf_newbuf(&rb_linebuf_new);
|
|
|
|
|
2017-08-06 11:05:24 +00:00
|
|
|
build_msgbuf_tags(&msgbuf, source_p);
|
|
|
|
|
2009-03-29 13:48:07 +00:00
|
|
|
current_serial++;
|
2018-02-27 22:49:13 +00:00
|
|
|
const char *statusmsg_prefix = (ConfigChannel.opmod_send_statusmsg ? "@" : "");
|
2009-03-29 13:48:07 +00:00
|
|
|
|
2017-08-06 11:05:24 +00:00
|
|
|
if(IsServer(source_p)) {
|
|
|
|
msgbuf_cache_initf(&msgbuf_cache, &msgbuf, &strings,
|
2018-02-27 22:49:13 +00:00
|
|
|
":%s %s %s%s :",
|
|
|
|
source_p->name, command, statusmsg_prefix, chptr->chname);
|
2017-08-06 11:05:24 +00:00
|
|
|
} else {
|
|
|
|
msgbuf_cache_initf(&msgbuf_cache, &msgbuf, &strings,
|
2018-02-27 22:49:13 +00:00
|
|
|
":%s!%s@%s %s %s%s :",
|
2014-03-03 04:25:47 +00:00
|
|
|
source_p->name, source_p->username,
|
2018-02-27 22:49:13 +00:00
|
|
|
source_p->host, command, statusmsg_prefix, chptr->chname);
|
2017-08-06 11:05:24 +00:00
|
|
|
}
|
2009-03-29 13:48:07 +00:00
|
|
|
|
2017-08-06 11:05:24 +00:00
|
|
|
if (chptr->mode.mode & MODE_MODERATED) {
|
|
|
|
linebuf_put_msgf(&rb_linebuf_old, &strings,
|
2018-02-27 22:49:13 +00:00
|
|
|
":%s %s %s%s :",
|
|
|
|
use_id(source_p), command, statusmsg_prefix, chptr->chname, text);
|
2017-08-06 11:05:24 +00:00
|
|
|
} else {
|
|
|
|
linebuf_put_msgf(&rb_linebuf_old, &strings,
|
|
|
|
":%s NOTICE @%s :<%s:%s> ",
|
2009-03-29 13:48:07 +00:00
|
|
|
use_id(source_p->servptr), chptr->chname,
|
2017-08-06 11:05:24 +00:00
|
|
|
source_p->name, chptr->chname);
|
|
|
|
}
|
|
|
|
linebuf_put_msgf(&rb_linebuf_new, &strings,
|
|
|
|
":%s %s =%s :",
|
|
|
|
use_id(source_p), command, chptr->chname);
|
2009-03-29 13:48:07 +00:00
|
|
|
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->members.head)
|
|
|
|
{
|
|
|
|
msptr = ptr->data;
|
|
|
|
target_p = msptr->client_p;
|
|
|
|
|
2016-02-27 08:48:37 +00:00
|
|
|
if(!MyClient(source_p) && (IsIOError(target_p->from) || target_p->from == one))
|
|
|
|
continue;
|
|
|
|
|
2016-11-23 21:14:44 +00:00
|
|
|
if(MyClient(source_p) && target_p == one)
|
2009-03-29 13:48:07 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if((msptr->flags & CHFL_CHANOP) == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if(IsDeaf(target_p))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if(!MyClient(target_p))
|
|
|
|
{
|
|
|
|
/* 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;
|
|
|
|
}
|
2017-08-06 11:05:24 +00:00
|
|
|
} else {
|
|
|
|
_send_linebuf(target_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAPS_ONLY(target_p)));
|
2009-03-29 13:48:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-23 21:14:44 +00:00
|
|
|
/* source client may not be on the channel, send echo separately */
|
|
|
|
if(MyClient(source_p) && IsCapable(source_p, CLICAP_ECHO_MESSAGE))
|
|
|
|
{
|
|
|
|
target_p = one;
|
|
|
|
|
2017-08-06 11:05:24 +00:00
|
|
|
_send_linebuf(target_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAPS_ONLY(target_p)));
|
2016-11-23 21:14:44 +00:00
|
|
|
}
|
|
|
|
|
2009-03-29 13:48:07 +00:00
|
|
|
rb_linebuf_donebuf(&rb_linebuf_old);
|
|
|
|
rb_linebuf_donebuf(&rb_linebuf_new);
|
2017-08-06 11:05:24 +00:00
|
|
|
msgbuf_cache_free(&msgbuf_cache);
|
2009-03-29 13:48:07 +00:00
|
|
|
}
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2020-06-07 16:36:31 +00:00
|
|
|
/* _sendto_channel_local
|
2007-01-25 06:40:21 +00:00
|
|
|
*
|
2020-06-07 16:36:31 +00:00
|
|
|
* inputs - source, flags to send to, privs to send to, channel to send to, va_args
|
2007-01-25 06:40:21 +00:00
|
|
|
* outputs - message to local channel members
|
|
|
|
* side effects -
|
|
|
|
*/
|
|
|
|
void
|
2020-06-07 16:36:31 +00:00
|
|
|
_sendto_channel_local(struct Client *source_p, int type, const char *priv, struct Channel *chptr, const char *pattern, va_list *args)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
struct membership *msptr;
|
|
|
|
struct Client *target_p;
|
2008-04-01 20:41:52 +00:00
|
|
|
rb_dlink_node *ptr;
|
2008-04-01 22:47:17 +00:00
|
|
|
rb_dlink_node *next_ptr;
|
2017-08-06 11:05:24 +00:00
|
|
|
struct MsgBuf msgbuf;
|
|
|
|
struct MsgBuf_cache msgbuf_cache;
|
2020-06-07 16:36:31 +00:00
|
|
|
rb_strf_t strings = { .format = pattern, .format_args = args, .next = NULL };
|
2014-03-03 04:25:47 +00:00
|
|
|
|
2017-08-06 11:05:24 +00:00
|
|
|
build_msgbuf_tags(&msgbuf, source_p);
|
2014-03-03 04:25:47 +00:00
|
|
|
|
2017-08-06 11:05:24 +00:00
|
|
|
msgbuf_cache_init(&msgbuf_cache, &msgbuf, &strings);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2008-04-01 22:47:17 +00:00
|
|
|
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->locmembers.head)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
msptr = ptr->data;
|
|
|
|
target_p = msptr->client_p;
|
|
|
|
|
2020-06-07 16:36:31 +00:00
|
|
|
if (IsIOError(target_p))
|
2007-01-25 06:40:21 +00:00
|
|
|
continue;
|
|
|
|
|
2020-06-07 16:36:31 +00:00
|
|
|
if (type && ((msptr->flags & type) == 0))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (priv != NULL && !HasPrivilege(target_p, priv))
|
2007-01-25 06:40:21 +00:00
|
|
|
continue;
|
|
|
|
|
2017-08-06 11:05:24 +00:00
|
|
|
_send_linebuf(target_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAPS_ONLY(target_p)));
|
2010-12-16 06:19:24 +00:00
|
|
|
}
|
|
|
|
|
2017-08-06 11:05:24 +00:00
|
|
|
msgbuf_cache_free(&msgbuf_cache);
|
2010-12-16 06:19:24 +00:00
|
|
|
}
|
|
|
|
|
2020-06-07 16:36:31 +00:00
|
|
|
/* sendto_channel_local_priv()
|
|
|
|
*
|
|
|
|
* inputs - source, flags to send to, privs to send to, channel to send to, va_args
|
|
|
|
* outputs - message to local channel members
|
|
|
|
* side effects -
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
sendto_channel_local_priv(struct Client *source_p, int type, const char *priv, struct Channel *chptr, const char *pattern, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
va_start(args, pattern);
|
|
|
|
_sendto_channel_local(source_p, type, priv, chptr, pattern, &args);
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* sendto_channel_local()
|
|
|
|
*
|
|
|
|
* inputs - source, flags to send to, channel to send to, va_args
|
|
|
|
* outputs - message to local channel members
|
|
|
|
* side effects -
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
sendto_channel_local(struct Client *source_p, int type, struct Channel *chptr, const char *pattern, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
va_start(args, pattern);
|
|
|
|
_sendto_channel_local(source_p, type, NULL, chptr, pattern, &args);
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
2011-11-12 14:41:01 +00:00
|
|
|
/*
|
|
|
|
* _sendto_channel_local_with_capability_butone()
|
2010-12-16 06:19:24 +00:00
|
|
|
*
|
2011-11-12 14:41:01 +00:00
|
|
|
* Shared implementation of sendto_channel_local_with_capability and sendto_channel_local_with_capability_butone
|
2010-12-16 06:19:24 +00:00
|
|
|
*/
|
2011-11-12 14:41:01 +00:00
|
|
|
static void
|
2017-08-06 11:05:24 +00:00
|
|
|
_sendto_channel_local_with_capability_butone(struct Client *source_p, struct Client *one, int type,
|
|
|
|
int caps, int negcaps, struct Channel *chptr, const char *pattern, va_list * args)
|
2010-12-16 06:19:24 +00:00
|
|
|
{
|
|
|
|
struct membership *msptr;
|
|
|
|
struct Client *target_p;
|
|
|
|
rb_dlink_node *ptr;
|
|
|
|
rb_dlink_node *next_ptr;
|
2017-08-06 11:05:24 +00:00
|
|
|
struct MsgBuf msgbuf;
|
|
|
|
struct MsgBuf_cache msgbuf_cache;
|
|
|
|
rb_strf_t strings = { .format = pattern, .format_args = args, .next = NULL };
|
2014-03-03 04:25:47 +00:00
|
|
|
|
2017-08-06 11:05:24 +00:00
|
|
|
build_msgbuf_tags(&msgbuf, source_p);
|
|
|
|
msgbuf_cache_init(&msgbuf_cache, &msgbuf, &strings);
|
2014-03-03 04:25:47 +00:00
|
|
|
|
2010-12-16 06:19:24 +00:00
|
|
|
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->locmembers.head)
|
|
|
|
{
|
|
|
|
msptr = ptr->data;
|
|
|
|
target_p = msptr->client_p;
|
|
|
|
|
2011-11-12 14:41:01 +00:00
|
|
|
if (target_p == one)
|
|
|
|
continue;
|
|
|
|
|
2010-12-16 06:19:24 +00:00
|
|
|
if(IsIOError(target_p) ||
|
|
|
|
!IsCapable(target_p, caps) ||
|
2011-01-10 23:26:05 +00:00
|
|
|
!NotCapable(target_p, negcaps))
|
2010-12-16 06:19:24 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if(type && ((msptr->flags & type) == 0))
|
|
|
|
continue;
|
|
|
|
|
2017-08-06 11:05:24 +00:00
|
|
|
_send_linebuf(target_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAPS_ONLY(target_p)));
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
|
2017-08-06 11:05:24 +00:00
|
|
|
msgbuf_cache_free(&msgbuf_cache);
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
|
2011-11-12 14:41:01 +00:00
|
|
|
/* sendto_channel_local_with_capability()
|
|
|
|
*
|
2017-08-06 11:05:24 +00:00
|
|
|
* inputs - source, flags to send to, caps, negate caps, channel to send to, va_args
|
2011-11-12 14:41:01 +00:00
|
|
|
* outputs - message to local channel members
|
|
|
|
* side effects -
|
|
|
|
*/
|
|
|
|
void
|
2017-08-06 11:05:24 +00:00
|
|
|
sendto_channel_local_with_capability(struct Client *source_p, int type, int caps, int negcaps, struct Channel *chptr, const char *pattern, ...)
|
2011-11-12 14:41:01 +00:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, pattern);
|
2017-08-06 11:05:24 +00:00
|
|
|
_sendto_channel_local_with_capability_butone(source_p, NULL, type, caps, negcaps, chptr, pattern, &args);
|
2011-11-12 14:41:01 +00:00
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* sendto_channel_local_with_capability()
|
|
|
|
*
|
2017-08-06 11:05:24 +00:00
|
|
|
* inputs - source, flags to send to, caps, negate caps, channel to send to, va_args
|
2011-11-12 14:41:01 +00:00
|
|
|
* outputs - message to local channel members
|
|
|
|
* side effects -
|
|
|
|
*/
|
|
|
|
void
|
2017-08-06 11:05:24 +00:00
|
|
|
sendto_channel_local_with_capability_butone(struct Client *one, int type,
|
|
|
|
int caps, int negcaps, struct Channel *chptr, const char *pattern, ...)
|
2011-11-12 14:41:01 +00:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, pattern);
|
2017-08-06 11:05:24 +00:00
|
|
|
_sendto_channel_local_with_capability_butone(one, one, type, caps, negcaps, chptr, pattern, &args);
|
2011-11-12 14:41:01 +00:00
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-25 06:40:21 +00: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
|
|
|
|
sendto_channel_local_butone(struct Client *one, int type, struct Channel *chptr, const char *pattern, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
struct membership *msptr;
|
|
|
|
struct Client *target_p;
|
2016-02-20 22:37:19 +00:00
|
|
|
struct MsgBuf msgbuf;
|
2008-04-01 20:41:52 +00:00
|
|
|
rb_dlink_node *ptr;
|
2008-04-01 22:47:17 +00:00
|
|
|
rb_dlink_node *next_ptr;
|
2017-08-06 11:05:24 +00:00
|
|
|
struct MsgBuf_cache msgbuf_cache;
|
|
|
|
rb_strf_t strings = { .format = pattern, .format_args = &args, .next = NULL };
|
2014-03-03 04:25:47 +00:00
|
|
|
|
2017-08-06 11:05:24 +00:00
|
|
|
build_msgbuf_tags(&msgbuf, one);
|
2016-02-20 22:37:19 +00:00
|
|
|
|
2007-01-25 06:40:21 +00:00
|
|
|
va_start(args, pattern);
|
2017-08-06 11:05:24 +00:00
|
|
|
msgbuf_cache_init(&msgbuf_cache, &msgbuf, &strings);
|
2016-02-21 00:35:35 +00:00
|
|
|
va_end(args);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2008-04-01 22:47:17 +00:00
|
|
|
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->locmembers.head)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
msptr = ptr->data;
|
|
|
|
target_p = msptr->client_p;
|
|
|
|
|
|
|
|
if(target_p == one)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if(IsIOError(target_p))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if(type && ((msptr->flags & type) == 0))
|
|
|
|
continue;
|
|
|
|
|
2016-02-20 22:37:19 +00:00
|
|
|
/* attach the present linebuf to the target */
|
2017-08-06 11:05:24 +00:00
|
|
|
_send_linebuf(target_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAPS_ONLY(target_p)));
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
|
2017-08-06 11:05:24 +00:00
|
|
|
msgbuf_cache_free(&msgbuf_cache);
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* sendto_common_channels_local()
|
|
|
|
*
|
|
|
|
* inputs - pointer to client
|
2017-08-06 11:05:24 +00:00
|
|
|
* - capability mask
|
|
|
|
* - negated capability mask
|
2007-01-25 06:40:21 +00:00
|
|
|
* - pattern to send
|
|
|
|
* output - NONE
|
|
|
|
* side effects - Sends a message to all people on local server who are
|
2014-03-03 04:25:47 +00:00
|
|
|
* in same channel with user.
|
2007-01-25 06:40:21 +00:00
|
|
|
* used by m_nick.c and exit_one_client.
|
|
|
|
*/
|
|
|
|
void
|
2015-11-20 04:43:45 +00:00
|
|
|
sendto_common_channels_local(struct Client *user, int cap, int negcap, const char *pattern, ...)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
va_list args;
|
2008-04-01 20:41:52 +00:00
|
|
|
rb_dlink_node *ptr;
|
2008-04-01 22:47:17 +00:00
|
|
|
rb_dlink_node *next_ptr;
|
2008-04-01 20:41:52 +00:00
|
|
|
rb_dlink_node *uptr;
|
|
|
|
rb_dlink_node *next_uptr;
|
2007-01-25 06:40:21 +00:00
|
|
|
struct Channel *chptr;
|
|
|
|
struct Client *target_p;
|
|
|
|
struct membership *msptr;
|
|
|
|
struct membership *mscptr;
|
2017-08-06 11:05:24 +00:00
|
|
|
struct MsgBuf msgbuf;
|
|
|
|
struct MsgBuf_cache msgbuf_cache;
|
|
|
|
rb_strf_t strings = { .format = pattern, .format_args = &args, .next = NULL };
|
|
|
|
|
|
|
|
build_msgbuf_tags(&msgbuf, user);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
va_start(args, pattern);
|
2017-08-06 11:05:24 +00:00
|
|
|
msgbuf_cache_init(&msgbuf_cache, &msgbuf, &strings);
|
2007-01-25 06:40:21 +00:00
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
++current_serial;
|
|
|
|
|
2008-04-01 22:47:17 +00:00
|
|
|
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, user->user->channel.head)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
mscptr = ptr->data;
|
|
|
|
chptr = mscptr->chptr;
|
|
|
|
|
2008-04-01 20:43:10 +00:00
|
|
|
RB_DLINK_FOREACH_SAFE(uptr, next_uptr, chptr->locmembers.head)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
msptr = uptr->data;
|
|
|
|
target_p = msptr->client_p;
|
|
|
|
|
|
|
|
if(IsIOError(target_p) ||
|
2010-12-16 04:55:05 +00:00
|
|
|
target_p->serial == current_serial ||
|
2015-11-20 04:43:45 +00:00
|
|
|
!IsCapable(target_p, cap) ||
|
|
|
|
!NotCapable(target_p, negcap))
|
2007-01-25 06:40:21 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
target_p->serial = current_serial;
|
2017-08-06 11:05:24 +00:00
|
|
|
send_linebuf(target_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAPS_ONLY(target_p)));
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* this can happen when the user isnt in any channels, but we still
|
|
|
|
* need to send them the data, ie a nick change
|
|
|
|
*/
|
2017-08-05 21:34:17 +00:00
|
|
|
if(MyConnect(user) && (user->serial != current_serial)
|
2017-08-06 11:05:24 +00:00
|
|
|
&& IsCapable(user, cap) && NotCapable(user, negcap)) {
|
|
|
|
send_linebuf(user, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAPS_ONLY(user)));
|
|
|
|
}
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2017-08-06 11:05:24 +00:00
|
|
|
msgbuf_cache_free(&msgbuf_cache);
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* sendto_common_channels_local_butone()
|
|
|
|
*
|
|
|
|
* inputs - pointer to client
|
2017-08-06 11:05:24 +00:00
|
|
|
* - capability mask
|
|
|
|
* - negated capability mask
|
2007-01-25 06:40:21 +00: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
|
2015-11-20 04:43:45 +00:00
|
|
|
sendto_common_channels_local_butone(struct Client *user, int cap, int negcap, const char *pattern, ...)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
va_list args;
|
2008-04-01 20:41:52 +00:00
|
|
|
rb_dlink_node *ptr;
|
2008-04-01 22:47:17 +00:00
|
|
|
rb_dlink_node *next_ptr;
|
2008-04-01 20:41:52 +00:00
|
|
|
rb_dlink_node *uptr;
|
|
|
|
rb_dlink_node *next_uptr;
|
2007-01-25 06:40:21 +00:00
|
|
|
struct Channel *chptr;
|
|
|
|
struct Client *target_p;
|
|
|
|
struct membership *msptr;
|
|
|
|
struct membership *mscptr;
|
2017-08-06 11:05:24 +00:00
|
|
|
struct MsgBuf msgbuf;
|
|
|
|
struct MsgBuf_cache msgbuf_cache;
|
|
|
|
rb_strf_t strings = { .format = pattern, .format_args = &args, .next = NULL };
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2017-08-06 11:05:24 +00:00
|
|
|
build_msgbuf_tags(&msgbuf, user);
|
2016-02-20 22:37:19 +00:00
|
|
|
|
2007-01-25 06:40:21 +00:00
|
|
|
va_start(args, pattern);
|
2017-08-06 11:05:24 +00:00
|
|
|
msgbuf_cache_init(&msgbuf_cache, &msgbuf, &strings);
|
2007-01-25 06:40:21 +00:00
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
++current_serial;
|
|
|
|
/* Skip them -- jilles */
|
|
|
|
user->serial = current_serial;
|
|
|
|
|
2008-04-01 22:47:17 +00:00
|
|
|
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, user->user->channel.head)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
mscptr = ptr->data;
|
|
|
|
chptr = mscptr->chptr;
|
|
|
|
|
2008-04-01 20:43:10 +00:00
|
|
|
RB_DLINK_FOREACH_SAFE(uptr, next_uptr, chptr->locmembers.head)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
msptr = uptr->data;
|
|
|
|
target_p = msptr->client_p;
|
|
|
|
|
|
|
|
if(IsIOError(target_p) ||
|
2010-12-16 04:55:05 +00:00
|
|
|
target_p->serial == current_serial ||
|
2015-11-20 04:43:45 +00:00
|
|
|
!IsCapable(target_p, cap) ||
|
|
|
|
!NotCapable(target_p, negcap))
|
2007-01-25 06:40:21 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
target_p->serial = current_serial;
|
2017-08-06 11:05:24 +00:00
|
|
|
send_linebuf(target_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAPS_ONLY(target_p)));
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-06 11:05:24 +00:00
|
|
|
msgbuf_cache_free(&msgbuf_cache);
|
2007-01-25 06:40:21 +00: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
|
|
|
|
sendto_match_butone(struct Client *one, struct Client *source_p,
|
|
|
|
const char *mask, int what, const char *pattern, ...)
|
|
|
|
{
|
|
|
|
static char buf[BUFSIZE];
|
|
|
|
va_list args;
|
|
|
|
struct Client *target_p;
|
2008-04-01 20:41:52 +00:00
|
|
|
rb_dlink_node *ptr;
|
2008-04-01 22:47:17 +00:00
|
|
|
rb_dlink_node *next_ptr;
|
2017-07-30 12:47:27 +00:00
|
|
|
buf_head_t rb_linebuf_remote;
|
2017-08-06 11:05:24 +00:00
|
|
|
struct MsgBuf msgbuf;
|
|
|
|
struct MsgBuf_cache msgbuf_cache;
|
|
|
|
rb_strf_t strings = { .format = buf, .format_args = NULL, .next = NULL };
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2017-07-30 12:47:27 +00:00
|
|
|
rb_linebuf_newbuf(&rb_linebuf_remote);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2017-08-06 11:05:24 +00:00
|
|
|
build_msgbuf_tags(&msgbuf, source_p);
|
|
|
|
|
2007-01-25 06:40:21 +00:00
|
|
|
va_start(args, pattern);
|
2016-02-10 01:25:32 +00:00
|
|
|
vsnprintf(buf, sizeof(buf), pattern, args);
|
2007-01-25 06:40:21 +00:00
|
|
|
va_end(args);
|
|
|
|
|
2017-08-06 11:05:24 +00:00
|
|
|
msgbuf_cache_initf(&msgbuf_cache, &msgbuf, &strings,
|
|
|
|
IsServer(source_p) ? ":%s " : ":%s!%s@%s ",
|
|
|
|
source_p->name, source_p->username, source_p->host);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2017-08-06 11:05:24 +00:00
|
|
|
linebuf_put_msgf(&rb_linebuf_remote, &strings, ":%s ", use_id(source_p));
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
if(what == MATCH_HOST)
|
|
|
|
{
|
2008-04-01 22:47:17 +00:00
|
|
|
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, lclient_list.head)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
target_p = ptr->data;
|
|
|
|
|
|
|
|
if(match(mask, target_p->host))
|
2017-08-06 11:05:24 +00:00
|
|
|
_send_linebuf(target_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAPS_ONLY(target_p)));
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* what = MATCH_SERVER, if it doesnt match us, just send remote */
|
|
|
|
else if(match(mask, me.name))
|
|
|
|
{
|
2008-04-01 22:47:17 +00:00
|
|
|
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, lclient_list.head)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
target_p = ptr->data;
|
2017-08-06 11:05:24 +00:00
|
|
|
_send_linebuf(target_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAPS_ONLY(target_p)));
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-01 20:43:10 +00:00
|
|
|
RB_DLINK_FOREACH(ptr, serv_list.head)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
target_p = ptr->data;
|
|
|
|
|
|
|
|
if(target_p == one)
|
|
|
|
continue;
|
|
|
|
|
2017-07-30 12:47:27 +00:00
|
|
|
send_linebuf_remote(target_p, source_p, &rb_linebuf_remote);
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
|
2017-08-06 11:05:24 +00:00
|
|
|
msgbuf_cache_free(&msgbuf_cache);
|
2017-07-30 12:47:27 +00:00
|
|
|
rb_linebuf_donebuf(&rb_linebuf_remote);
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* sendto_match_servs()
|
|
|
|
*
|
|
|
|
* inputs - source, mask to send to, caps needed, va_args
|
2014-03-03 04:25:47 +00:00
|
|
|
* outputs -
|
2007-01-25 06:40:21 +00:00
|
|
|
* side effects - message is sent to matching servers with caps.
|
|
|
|
*/
|
|
|
|
void
|
2014-03-03 04:25:47 +00:00
|
|
|
sendto_match_servs(struct Client *source_p, const char *mask, int cap,
|
2007-01-25 06:40:21 +00:00
|
|
|
int nocap, const char *pattern, ...)
|
|
|
|
{
|
|
|
|
static char buf[BUFSIZE];
|
|
|
|
va_list args;
|
2008-04-01 20:41:52 +00:00
|
|
|
rb_dlink_node *ptr;
|
2007-01-25 06:40:21 +00:00
|
|
|
struct Client *target_p;
|
2008-04-01 21:51:34 +00:00
|
|
|
buf_head_t rb_linebuf_id;
|
2017-08-06 11:05:24 +00:00
|
|
|
rb_strf_t strings = { .format = buf, .format_args = NULL, .next = NULL };
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
if(EmptyString(mask))
|
|
|
|
return;
|
|
|
|
|
2008-04-01 21:51:34 +00:00
|
|
|
rb_linebuf_newbuf(&rb_linebuf_id);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
va_start(args, pattern);
|
2016-02-10 01:25:32 +00:00
|
|
|
vsnprintf(buf, sizeof(buf), pattern, args);
|
2007-01-25 06:40:21 +00:00
|
|
|
va_end(args);
|
|
|
|
|
2017-08-06 11:05:24 +00:00
|
|
|
linebuf_put_msgf(&rb_linebuf_id, &strings, ":%s ", use_id(source_p));
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
current_serial++;
|
|
|
|
|
2008-04-01 20:43:10 +00:00
|
|
|
RB_DLINK_FOREACH(ptr, global_serv_list.head)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
target_p = ptr->data;
|
|
|
|
|
|
|
|
/* dont send to ourselves, or back to where it came from.. */
|
|
|
|
if(IsMe(target_p) || target_p->from == source_p->from)
|
|
|
|
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 00:30:30 +00:00
|
|
|
_send_linebuf(target_p->from, &rb_linebuf_id);
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-01 21:51:34 +00:00
|
|
|
rb_linebuf_donebuf(&rb_linebuf_id);
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
|
2015-03-01 06:44:34 +00: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;
|
|
|
|
struct Client *target_p;
|
2017-08-06 11:05:24 +00:00
|
|
|
struct MsgBuf msgbuf;
|
|
|
|
struct MsgBuf_cache msgbuf_cache;
|
|
|
|
rb_strf_t strings = { .format = pattern, .format_args = &args, .next = NULL };
|
2015-03-01 06:44:34 +00:00
|
|
|
|
2017-08-06 11:05:24 +00:00
|
|
|
build_msgbuf_tags(&msgbuf, &me);
|
2015-03-01 06:44:34 +00:00
|
|
|
|
|
|
|
va_start(args, pattern);
|
2017-08-06 11:05:24 +00:00
|
|
|
msgbuf_cache_init(&msgbuf_cache, &msgbuf, &strings);
|
2015-03-01 06:44:34 +00:00
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
RB_DLINK_FOREACH(ptr, lclient_list.head)
|
|
|
|
{
|
|
|
|
target_p = ptr->data;
|
|
|
|
|
2015-03-01 13:53:40 +00:00
|
|
|
if(IsIOError(target_p) || !IsCapable(target_p, cap))
|
2015-03-01 06:44:34 +00:00
|
|
|
continue;
|
|
|
|
|
2017-08-06 11:05:24 +00:00
|
|
|
send_linebuf(target_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAPS_ONLY(target_p)));
|
2015-03-01 06:44:34 +00:00
|
|
|
}
|
|
|
|
|
2017-08-06 11:05:24 +00:00
|
|
|
msgbuf_cache_free(&msgbuf_cache);
|
2015-03-01 06:44:34 +00:00
|
|
|
}
|
|
|
|
|
2007-06-30 22:15:35 +00:00
|
|
|
/* sendto_monitor()
|
|
|
|
*
|
|
|
|
* inputs - monitor nick to send to, format, va_args
|
|
|
|
* outputs - message to local users monitoring the given nick
|
|
|
|
* side effects -
|
|
|
|
*/
|
|
|
|
void
|
2017-08-06 11:05:24 +00:00
|
|
|
sendto_monitor(struct Client *source_p, struct monitor *monptr, const char *pattern, ...)
|
2007-06-30 22:15:35 +00:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
struct Client *target_p;
|
2008-04-01 20:41:52 +00:00
|
|
|
rb_dlink_node *ptr;
|
2008-04-01 22:47:17 +00:00
|
|
|
rb_dlink_node *next_ptr;
|
2017-08-06 11:05:24 +00:00
|
|
|
struct MsgBuf msgbuf;
|
|
|
|
struct MsgBuf_cache msgbuf_cache;
|
|
|
|
rb_strf_t strings = { .format = pattern, .format_args = &args, .next = NULL };
|
2014-03-03 04:25:47 +00:00
|
|
|
|
2017-08-06 11:05:24 +00:00
|
|
|
build_msgbuf_tags(&msgbuf, source_p);
|
2014-03-03 04:25:47 +00:00
|
|
|
|
2007-06-30 22:15:35 +00:00
|
|
|
va_start(args, pattern);
|
2017-08-06 11:05:24 +00:00
|
|
|
msgbuf_cache_init(&msgbuf_cache, &msgbuf, &strings);
|
2007-06-30 22:15:35 +00:00
|
|
|
va_end(args);
|
|
|
|
|
2008-04-01 22:47:17 +00:00
|
|
|
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, monptr->users.head)
|
2007-06-30 22:15:35 +00:00
|
|
|
{
|
|
|
|
target_p = ptr->data;
|
|
|
|
|
|
|
|
if(IsIOError(target_p))
|
|
|
|
continue;
|
|
|
|
|
2017-08-06 11:05:24 +00:00
|
|
|
_send_linebuf(target_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAPS_ONLY(target_p)));
|
2007-06-30 22:15:35 +00:00
|
|
|
}
|
|
|
|
|
2017-08-06 11:05:24 +00:00
|
|
|
msgbuf_cache_free(&msgbuf_cache);
|
2007-06-30 22:15:35 +00:00
|
|
|
}
|
|
|
|
|
2016-11-23 21:43:33 +00:00
|
|
|
/* _sendto_anywhere()
|
2007-01-25 06:40:21 +00:00
|
|
|
*
|
2016-11-23 21:43:33 +00:00
|
|
|
* inputs - real_target, target, source, va_args
|
2007-01-25 06:40:21 +00:00
|
|
|
* outputs -
|
2016-11-23 21:43:33 +00:00
|
|
|
* side effects - client is sent message/own message with correct prefix.
|
2007-01-25 06:40:21 +00:00
|
|
|
*/
|
2016-11-23 21:43:33 +00:00
|
|
|
static void
|
|
|
|
_sendto_anywhere(struct Client *dest_p, struct Client *target_p,
|
|
|
|
struct Client *source_p, const char *command,
|
2016-11-25 16:19:29 +00:00
|
|
|
const char *pattern, va_list *args)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
buf_head_t linebuf;
|
2017-08-06 11:05:24 +00:00
|
|
|
rb_strf_t strings = { .format = pattern, .format_args = args, .next = NULL };
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2016-02-21 00:12:46 +00:00
|
|
|
rb_linebuf_newbuf(&linebuf);
|
|
|
|
|
2017-08-06 11:05:24 +00:00
|
|
|
if (MyClient(dest_p)) {
|
|
|
|
if (IsServer(source_p)) {
|
|
|
|
linebuf_put_msgf(&linebuf, &strings, ":%s %s %s ",
|
2014-03-03 04:25:47 +00:00
|
|
|
source_p->name, command,
|
2007-01-25 06:40:21 +00:00
|
|
|
target_p->name);
|
2017-08-06 11:05:24 +00:00
|
|
|
} else {
|
2016-02-20 22:37:19 +00:00
|
|
|
struct MsgBuf msgbuf;
|
|
|
|
|
2017-08-06 11:05:24 +00:00
|
|
|
build_msgbuf_tags(&msgbuf, source_p);
|
2016-02-20 23:59:38 +00:00
|
|
|
|
2017-08-06 11:05:24 +00:00
|
|
|
linebuf_put_tagsf(&linebuf, &msgbuf, dest_p, &strings,
|
|
|
|
IsPerson(source_p) ? ":%1$s!%4$s@%5$s %2$s %3$s " : ":%1$s %2$s %3$s ",
|
|
|
|
source_p->name, command, target_p->name,
|
|
|
|
source_p->username, source_p->host);
|
2016-02-20 22:37:19 +00:00
|
|
|
}
|
2017-08-06 11:05:24 +00:00
|
|
|
|
|
|
|
_send_linebuf(dest_p, &linebuf);
|
|
|
|
} else {
|
|
|
|
linebuf_put_msgf(&linebuf, &strings, ":%s %s %s ",
|
2007-01-25 06:40:21 +00:00
|
|
|
get_id(source_p, target_p), command,
|
|
|
|
get_id(target_p, target_p));
|
|
|
|
|
2016-11-23 21:43:33 +00:00
|
|
|
send_linebuf_remote(dest_p, source_p, &linebuf);
|
2017-08-06 11:05:24 +00:00
|
|
|
}
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2008-04-01 21:51:34 +00:00
|
|
|
rb_linebuf_donebuf(&linebuf);
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
|
2016-11-23 21:43:33 +00:00
|
|
|
/* sendto_anywhere()
|
|
|
|
*
|
|
|
|
* inputs - target, source, va_args
|
|
|
|
* outputs -
|
|
|
|
* side effects - client is sent message with correct prefix.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
sendto_anywhere(struct Client *target_p, struct Client *source_p,
|
|
|
|
const char *command, const char *pattern, ...)
|
|
|
|
{
|
2016-11-25 16:19:29 +00:00
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, pattern);
|
|
|
|
_sendto_anywhere(target_p, target_p, source_p, command, pattern, &args);
|
|
|
|
va_end(args);
|
2016-11-23 21:43:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* sendto_anywhere_echo()
|
|
|
|
*
|
|
|
|
* inputs - target, source, va_args
|
|
|
|
* outputs -
|
|
|
|
* side effects - client is sent own message with correct prefix.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
sendto_anywhere_echo(struct Client *target_p, struct Client *source_p,
|
|
|
|
const char *command, const char *pattern, ...)
|
|
|
|
{
|
2016-11-25 16:19:29 +00:00
|
|
|
va_list args;
|
|
|
|
|
2016-11-23 21:43:33 +00:00
|
|
|
s_assert(MyClient(source_p));
|
|
|
|
s_assert(!IsServer(source_p));
|
|
|
|
|
2016-11-25 16:19:29 +00:00
|
|
|
va_start(args, pattern);
|
|
|
|
_sendto_anywhere(source_p, target_p, source_p, command, pattern, &args);
|
|
|
|
va_end(args);
|
2016-11-23 21:43:33 +00:00
|
|
|
}
|
|
|
|
|
2007-01-25 06:40:21 +00: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];
|
|
|
|
char *snobuf;
|
|
|
|
struct Client *client_p;
|
2008-04-01 20:41:52 +00:00
|
|
|
rb_dlink_node *ptr;
|
2008-04-01 22:47:17 +00:00
|
|
|
rb_dlink_node *next_ptr;
|
2007-01-25 06:40:21 +00:00
|
|
|
va_list args;
|
2017-08-06 11:05:24 +00:00
|
|
|
struct MsgBuf msgbuf;
|
|
|
|
struct MsgBuf_cache msgbuf_cache;
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2017-08-06 11:05:24 +00:00
|
|
|
build_msgbuf_tags(&msgbuf, &me);
|
|
|
|
|
|
|
|
/* rather a lot of copying around, oh well -- jilles */
|
|
|
|
va_start(args, pattern);
|
|
|
|
vsnprintf(buf, sizeof(buf), pattern, args);
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
msgbuf_cache_initf(&msgbuf_cache, &msgbuf, NULL,
|
|
|
|
":%s NOTICE * :*** Notice -- %s", me.name, buf);
|
2007-01-25 06:40:21 +00: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)
|
|
|
|
{
|
|
|
|
snobuf = construct_snobuf(flags);
|
|
|
|
if (snobuf[1] != '\0')
|
|
|
|
sendto_server(NULL, NULL, CAP_ENCAP|CAP_TS6, NOCAPS,
|
|
|
|
":%s ENCAP * SNOTE %c :%s",
|
|
|
|
me.id, snobuf[1], buf);
|
|
|
|
}
|
2009-03-07 00:27:05 +00:00
|
|
|
else if (remote_rehash_oper_p != NULL)
|
|
|
|
{
|
|
|
|
sendto_one_notice(remote_rehash_oper_p, ":*** Notice -- %s", buf);
|
|
|
|
}
|
2007-01-25 06:40:21 +00:00
|
|
|
level &= ~L_NETWIDE;
|
|
|
|
|
2008-04-01 22:47:17 +00:00
|
|
|
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, local_oper_list.head)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
client_p = ptr->data;
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
2017-08-06 11:05:24 +00:00
|
|
|
if (client_p->snomask & flags) {
|
|
|
|
_send_linebuf(client_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAPS_ONLY(client_p)));
|
|
|
|
}
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
|
2017-08-06 11:05:24 +00:00
|
|
|
msgbuf_cache_free(&msgbuf_cache);
|
2007-01-25 06:40:21 +00: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
|
|
|
|
sendto_realops_snomask_from(int flags, int level, struct Client *source_p,
|
|
|
|
const char *pattern, ...)
|
|
|
|
{
|
|
|
|
struct Client *client_p;
|
2008-04-01 20:41:52 +00:00
|
|
|
rb_dlink_node *ptr;
|
2008-04-01 22:47:17 +00:00
|
|
|
rb_dlink_node *next_ptr;
|
2007-01-25 06:40:21 +00:00
|
|
|
va_list args;
|
2017-08-06 11:05:24 +00:00
|
|
|
struct MsgBuf msgbuf;
|
|
|
|
struct MsgBuf_cache msgbuf_cache;
|
|
|
|
rb_strf_t strings = { .format = pattern, .format_args = &args, .next = NULL };
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2017-08-06 11:05:24 +00:00
|
|
|
build_msgbuf_tags(&msgbuf, &me);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
va_start(args, pattern);
|
2017-08-06 11:05:24 +00:00
|
|
|
msgbuf_cache_initf(&msgbuf_cache, &msgbuf, &strings,
|
2007-01-25 06:40:21 +00:00
|
|
|
":%s NOTICE * :*** Notice -- ", source_p->name);
|
|
|
|
va_end(args);
|
|
|
|
|
2008-04-01 22:47:17 +00:00
|
|
|
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, local_oper_list.head)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
client_p = ptr->data;
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
2017-08-06 11:05:24 +00:00
|
|
|
if (client_p->snomask & flags) {
|
|
|
|
_send_linebuf(client_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAPS_ONLY(client_p)));
|
|
|
|
}
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
|
2017-08-06 11:05:24 +00:00
|
|
|
msgbuf_cache_free(&msgbuf_cache);
|
2007-01-25 06:40:21 +00: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
|
|
|
|
sendto_wallops_flags(int flags, struct Client *source_p, const char *pattern, ...)
|
|
|
|
{
|
|
|
|
struct Client *client_p;
|
2008-04-01 20:41:52 +00:00
|
|
|
rb_dlink_node *ptr;
|
2008-04-01 22:47:17 +00:00
|
|
|
rb_dlink_node *next_ptr;
|
2007-01-25 06:40:21 +00:00
|
|
|
va_list args;
|
2017-08-06 11:05:24 +00:00
|
|
|
struct MsgBuf msgbuf;
|
|
|
|
struct MsgBuf_cache msgbuf_cache;
|
|
|
|
rb_strf_t strings = { .format = pattern, .format_args = &args, .next = NULL };
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2017-08-06 11:05:24 +00:00
|
|
|
build_msgbuf_tags(&msgbuf, source_p);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
va_start(args, pattern);
|
2017-08-06 11:05:24 +00:00
|
|
|
if (IsPerson(source_p)) {
|
|
|
|
msgbuf_cache_initf(&msgbuf_cache, &msgbuf, &strings,
|
2007-01-25 06:40:21 +00:00
|
|
|
":%s!%s@%s WALLOPS :", source_p->name,
|
|
|
|
source_p->username, source_p->host);
|
2017-08-06 11:05:24 +00:00
|
|
|
} else {
|
|
|
|
msgbuf_cache_initf(&msgbuf_cache, &msgbuf, &strings,
|
|
|
|
":%s WALLOPS :", source_p->name);
|
|
|
|
}
|
2007-01-25 06:40:21 +00:00
|
|
|
va_end(args);
|
|
|
|
|
2008-04-01 22:47:17 +00:00
|
|
|
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, IsPerson(source_p) && flags == UMODE_WALLOP ? lclient_list.head : local_oper_list.head)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
client_p = ptr->data;
|
|
|
|
|
2017-08-06 11:05:24 +00:00
|
|
|
if (client_p->umodes & flags) {
|
|
|
|
_send_linebuf(client_p, msgbuf_cache_get(&msgbuf_cache, CLIENT_CAPS_ONLY(client_p)));
|
|
|
|
}
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
|
2017-08-06 11:05:24 +00:00
|
|
|
msgbuf_cache_free(&msgbuf_cache);
|
2007-01-25 06:40:21 +00: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
|
|
|
|
kill_client(struct Client *target_p, struct Client *diedie, const char *pattern, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
buf_head_t linebuf;
|
2017-08-06 11:05:24 +00:00
|
|
|
struct MsgBuf msgbuf;
|
|
|
|
rb_strf_t strings = { .format = pattern, .format_args = &args, .next = NULL };
|
|
|
|
|
|
|
|
build_msgbuf_tags(&msgbuf, &me);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2008-04-01 21:51:34 +00:00
|
|
|
rb_linebuf_newbuf(&linebuf);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
va_start(args, pattern);
|
2017-08-06 11:05:24 +00:00
|
|
|
linebuf_put_tagsf(&linebuf, &msgbuf, target_p, &strings,
|
|
|
|
":%s KILL %s :", get_id(&me, target_p), get_id(diedie, target_p));
|
2007-01-25 06:40:21 +00:00
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
send_linebuf(target_p, &linebuf);
|
2008-04-01 21:51:34 +00:00
|
|
|
rb_linebuf_donebuf(&linebuf);
|
2007-01-25 06:40:21 +00: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
|
|
|
|
kill_client_serv_butone(struct Client *one, struct Client *target_p, const char *pattern, ...)
|
|
|
|
{
|
|
|
|
static char buf[BUFSIZE];
|
|
|
|
va_list args;
|
|
|
|
struct Client *client_p;
|
2008-04-01 20:41:52 +00:00
|
|
|
rb_dlink_node *ptr;
|
2008-04-01 22:47:17 +00:00
|
|
|
rb_dlink_node *next_ptr;
|
2008-04-01 21:51:34 +00:00
|
|
|
buf_head_t rb_linebuf_id;
|
2017-08-06 11:05:24 +00:00
|
|
|
rb_strf_t strings = { .format = pattern, .format_args = &args, .next = NULL };
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2008-04-01 21:51:34 +00:00
|
|
|
rb_linebuf_newbuf(&rb_linebuf_id);
|
2014-03-03 04:25:47 +00:00
|
|
|
|
2007-01-25 06:40:21 +00:00
|
|
|
va_start(args, pattern);
|
2017-08-06 11:05:24 +00:00
|
|
|
linebuf_put_msgf(&rb_linebuf_id, &strings, ":%s KILL %s :%s",
|
2007-01-25 06:40:21 +00:00
|
|
|
use_id(&me), use_id(target_p), buf);
|
2017-08-06 11:05:24 +00:00
|
|
|
va_end(args);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2008-04-01 22:47:17 +00:00
|
|
|
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, serv_list.head)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
client_p = ptr->data;
|
|
|
|
|
|
|
|
/* 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 00:30:30 +00:00
|
|
|
_send_linebuf(client_p, &rb_linebuf_id);
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
|
2008-04-01 21:51:34 +00:00
|
|
|
rb_linebuf_donebuf(&rb_linebuf_id);
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|