ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/send.c
(Generate patch)

Comparing:
ircd-hybrid-7.2/src/send.c (file contents), Revision 939 by db, Sat May 2 01:41:47 2009 UTC vs.
ircd-hybrid/trunk/src/send.c (file contents), Revision 7105 by michael, Sat Jan 23 20:11:27 2016 UTC

# Line 1 | Line 1
1   /*
2 < *  ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 < *  send.c: Functions for sending messages.
2 > *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Copyright (C) 2002 by the past and present ircd coders, and others.
4 > *  Copyright (c) 1997-2016 ircd-hybrid development team
5   *
6   *  This program is free software; you can redistribute it and/or modify
7   *  it under the terms of the GNU General Public License as published by
# Line 16 | Line 15
15   *
16   *  You should have received a copy of the GNU General Public License
17   *  along with this program; if not, write to the Free Software
18 < *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
18 > *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19   *  USA
20 < *
21 < *  $Id$
20 > */
21 >
22 > /*! \file send.c
23 > * \brief Functions for sending messages.
24 > * \version $Id$
25   */
26  
27   #include "stdinc.h"
28 < #include "tools.h"
28 > #include "list.h"
29   #include "send.h"
30   #include "channel.h"
31   #include "client.h"
30 #include "common.h"
32   #include "dbuf.h"
33   #include "irc_string.h"
34   #include "ircd.h"
34 #include "handlers.h"
35 #include "numeric.h"
36 #include "fdlist.h"
35   #include "s_bsd.h"
36 < #include "s_serv.h"
37 < #include "sprintf_irc.h"
38 < #include "s_conf.h"
41 < #include "list.h"
42 < #include "s_log.h"
43 < #include "memory.h"
44 < #include "hook.h"
45 < #include "irc_getnameinfo.h"
46 < #include "packet.h"
36 > #include "server.h"
37 > #include "conf_class.h"
38 > #include "log.h"
39  
48 #define LOG_BUFSIZE 2048
40  
41 < struct Callback *iosend_cb = NULL;
51 < struct Callback *iosendctrl_cb = NULL;
41 > static uintmax_t current_serial;
42  
53 static void send_message(struct Client *, char *, int);
54 static void send_message_remote(struct Client *, struct Client *, char *, int);
55
56 static unsigned long current_serial = 0L;
43  
44   /* send_format()
45   *
46 < * inputs       - buffer to format into
47 < *              - size of the buffer
46 > * inputs
47 > *              - buffer
48   *              - format pattern to use
49   *              - var args
50   * output       - number of bytes formatted output
51   * side effects - modifies sendbuf
52   */
53 < static inline int
54 < send_format(char *lsendbuf, int bufsize, const char *pattern, va_list args)
53 > static void
54 > send_format(struct dbuf_block *buffer, const char *pattern, va_list args)
55   {
70  int len;
71
56    /*
57     * from rfc1459
58     *
59     * IRC messages are always lines of characters terminated with a CR-LF
60     * (Carriage Return - Line Feed) pair, and these messages shall not
61 <   * exceed 512 characters in length,  counting all characters
61 >   * exceed 512 characters in length,  counting all characters
62     * including the trailing CR-LF.
63     * Thus, there are 510 characters maximum allowed
64     * for the command and its parameters.  There is no provision for
65     * continuation message lines.  See section 7 for more details about
66     * current implementations.
67     */
68 <  len = vsnprintf(lsendbuf, bufsize - 1, pattern, args);
85 <  if (len > bufsize - 2)
86 <    len = bufsize - 2;  /* required by some versions of vsnprintf */
87 <
88 <  lsendbuf[len++] = '\r';
89 <  lsendbuf[len++] = '\n';
90 <  return (len);
91 < }
68 >  dbuf_put_args(buffer, pattern, args);
69  
70 < /*
71 < * iosend_default - append a packet to the client's sendq.
95 < */
96 < void *
97 < iosend_default(va_list args)
98 < {
99 <  struct Client *to = va_arg(args, struct Client *);
100 <  int length = va_arg(args, int);
101 <  char *buf = va_arg(args, char *);
70 >  if (buffer->size > IRCD_BUFSIZE - 2)
71 >    buffer->size = IRCD_BUFSIZE - 2;
72  
73 <  dbuf_put(&to->localClient->buf_sendq, buf, length);
74 <  return NULL;
73 >  buffer->data[buffer->size++] = '\r';
74 >  buffer->data[buffer->size++] = '\n';
75   }
76  
77   /*
# Line 110 | Line 80 | iosend_default(va_list args)
80   **      sendq.
81   */
82   static void
83 < send_message(struct Client *to, char *buf, int len)
83 > send_message(struct Client *to, struct dbuf_block *buf)
84   {
85    assert(!IsMe(to));
86    assert(to != &me);
87 +  assert(MyConnect(to));
88  
89 <  if (dbuf_length(&to->localClient->buf_sendq) + len > get_sendq(to))
89 >  if (dbuf_length(&to->connection->buf_sendq) + buf->size > get_sendq(&to->connection->confs))
90    {
91      if (IsServer(to))
92 <      sendto_realops_flags(UMODE_ALL, L_ALL,
93 <                           "Max SendQ limit exceeded for %s: %lu > %lu",
92 >      sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
93 >                           "Max SendQ limit exceeded for %s: %zu > %u",
94                             get_client_name(to, HIDE_IP),
95 <                           (unsigned long)(dbuf_length(&to->localClient->buf_sendq) + len),
96 <                           get_sendq(to));
95 >                           (dbuf_length(&to->connection->buf_sendq) + buf->size),
96 >                           get_sendq(&to->connection->confs));
97 >
98      if (IsClient(to))
99 <      SetSendQExceeded(to);
99 >      AddFlag(to, FLAGS_SENDQEX);
100 >
101      dead_link_on_write(to, 0);
102      return;
103    }
104  
105 <  execute_callback(iosend_cb, to, len, buf);
105 >  dbuf_add(&to->connection->buf_sendq, buf);
106  
107    /*
108 <   ** Update statistics. The following is slightly incorrect
109 <   ** because it counts messages even if queued, but bytes
110 <   ** only really sent. Queued bytes get updated in SendQueued.
108 >   * Update statistics. The following is slightly incorrect because
109 >   * it counts messages even if queued, but bytes only really sent.
110 >   * Queued bytes get updated in send_queued_write().
111     */
112 <  ++to->localClient->send.messages;
113 <  ++me.localClient->send.messages;
112 >  ++to->connection->send.messages;
113 >  ++me.connection->send.messages;
114  
115 <  if (dbuf_length(&to->localClient->buf_sendq) >
143 <      (IsServer(to) ? (unsigned int) 1024 : (unsigned int) 4096))
144 <    send_queued_write(to);
115 >  send_queued_write(to);
116   }
117  
118   /* send_message_remote()
119   *
120   * inputs       - pointer to client from message is being sent
121   *              - pointer to client to send to
122 < *              - pointer to preformatted buffer
152 < *              - length of input buffer
122 > *              - pointer to buffer
123   * output       - none
124   * side effects - Despite the function name, this only sends to directly
125   *                connected clients.
126 < *
126 > *
127   */
128   static void
129 < send_message_remote(struct Client *to, struct Client *from,
160 <                    char *buf, int len)
129 > send_message_remote(struct Client *to, struct Client *from, struct dbuf_block *buf)
130   {
131 <  if (!MyConnect(to))
132 <  {
133 <    sendto_realops_flags(UMODE_ALL, L_ALL,
134 <                         "server send message to %s [%s] dropped from %s(Not local server)",
166 <                         to->name, to->from->name, from->name);
167 <    return;
168 <  }
169 <
170 <  /* Optimize by checking if (from && to) before everything */
171 <  /* we set to->from up there.. */
131 >  assert(MyConnect(to));
132 >  assert(IsServer(to));
133 >  assert(!IsMe(to));
134 >  assert(to->from == to);
135  
136 <  if (!MyClient(from) && IsClient(to) && (to == from->from))
136 >  if (to == from->from)
137    {
138 <    if (IsServer(from))
139 <    {
140 <      sendto_realops_flags(UMODE_ALL, L_ALL,
178 <                           "Send message to %s [%s] dropped from %s(Fake Dir)",
179 <                           to->name, to->from->name, from->name);
180 <      return;
181 <    }
182 <
183 <    sendto_realops_flags(UMODE_ALL, L_ALL,
184 <                         "Ghosted: %s[%s@%s] from %s[%s@%s] (%s)",
185 <                         to->name, to->username, to->host,
186 <                         from->name, from->username, from->host,
187 <                         to->from->name);
188 <
189 <    sendto_server(NULL, NULL, CAP_TS6, NOCAPS,
190 <                  ":%s KILL %s :%s (%s[%s@%s] Ghosted %s)",
191 <                  me.id, to->name, me.name, to->name,
192 <                  to->username, to->host, to->from->name);
193 <    sendto_server(NULL, NULL, NOCAPS, CAP_TS6,
194 <                  ":%s KILL %s :%s (%s[%s@%s] Ghosted %s)",
195 <                  me.name, to->name, me.name, to->name,
196 <                  to->username, to->host, to->from->name);
197 <
198 <    SetKilled(to);
199 <
200 <    if (IsClient(from))
201 <      sendto_one(from, form_str(ERR_GHOSTEDCLIENT),
202 <                 me.name, from->name, to->name, to->username,
203 <                 to->host, to->from);
204 <
205 <    exit_client(to, &me, "Ghosted client");
206 <
138 >    sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
139 >                         "Send message to %s dropped from %s (Fake Dir)",
140 >                         to->name, from->name);
141      return;
142 <  }
142 >  }
143  
144 <  send_message(to, buf, len);
144 >  send_message(to, buf);
145   }
146  
147   /*
# Line 215 | Line 149 | send_message_remote(struct Client *to, s
149   **      Called when a socket is ready for writing.
150   */
151   void
152 < sendq_unblocked(fde_t *fd, struct Client *client_p)
152 > sendq_unblocked(fde_t *fd, void *data)
153   {
154 <  ClearSendqBlocked(client_p);
155 <  /* let send_queued_write be executed by send_queued_all */
154 >  struct Client *const client_p = data;
155 >  assert(fd == &client_p->connection->fd);
156  
157 < #ifdef HAVE_LIBCRYPTO
158 <  if (fd->flags.pending_read)
225 <  {
226 <    fd->flags.pending_read = 0;
227 <    read_packet(fd, client_p);
228 <  }
229 < #endif
230 < }
231 <
232 < /*
233 < ** slinkq_unblocked
234 < **      Called when a server control socket is ready for writing.
235 < */
236 < static void
237 < slinkq_unblocked(fde_t *fd, struct Client *client_p)
238 < {
239 <  ClearSlinkqBlocked(client_p);
240 <  send_queued_slink_write(client_p);
157 >  DelFlag(client_p, FLAGS_BLOCKED);
158 >  send_queued_write(client_p);
159   }
160  
161   /*
# Line 249 | Line 167 | slinkq_unblocked(fde_t *fd, struct Clien
167   void
168   send_queued_write(struct Client *to)
169   {
170 <  int retlen;
171 <  struct dbuf_block *first;
170 >  int retlen = 0;
171 > #ifdef HAVE_TLS
172 >  int want_read = 0;
173 > #endif
174  
175    /*
176     ** Once socket is marked dead, we cannot start writing to it,
177     ** even if the error is removed...
178     */
179 <  if (IsDead(to) || IsSendqBlocked(to))
179 >  if (IsDead(to) || HasFlag(to, FLAGS_BLOCKED))
180      return;  /* no use calling send() now */
181  
182    /* Next, lets try to write some data */
183 <
264 <  if (dbuf_length(&to->localClient->buf_sendq))
183 >  if (dbuf_length(&to->connection->buf_sendq))
184    {
185 <    do {
186 <      first = to->localClient->buf_sendq.blocks.head->data;
185 >    do
186 >    {
187 >      const struct dbuf_block *first = to->connection->buf_sendq.blocks.head->data;
188  
189 < #ifdef HAVE_LIBCRYPTO
190 <      if (to->localClient->fd.ssl)
189 > #ifdef HAVE_TLS
190 >      if (tls_isusing(&to->connection->fd.ssl))
191        {
192 <        retlen = SSL_write(to->localClient->fd.ssl, first->data, first->size);
192 >        retlen = tls_write(&to->connection->fd.ssl, first->data + to->connection->buf_sendq.pos, first->size - to->connection->buf_sendq.pos, &want_read);
193  
194 <        /* translate openssl error codes, sigh */
195 <        if (retlen < 0)
276 <          switch (SSL_get_error(to->localClient->fd.ssl, retlen))
277 <          {
278 <            case SSL_ERROR_WANT_READ:
279 <              return;  /* retry later, don't register for write events */
280 <
281 <            case SSL_ERROR_WANT_WRITE:
282 <              errno = EWOULDBLOCK;
283 <            case SSL_ERROR_SYSCALL:
284 <              break;
285 <            case SSL_ERROR_SSL:
286 <              if (errno == EAGAIN)
287 <                break;
288 <            default:
289 <              retlen = errno = 0;  /* either an SSL-specific error or EOF */
290 <          }
194 >        if (want_read)
195 >          return;  /* Retry later, don't register for write events */
196        }
197        else
198   #endif
199 <        retlen = send(to->localClient->fd.fd, first->data, first->size, 0);
199 >        retlen = send(to->connection->fd.fd, first->data + to->connection->buf_sendq.pos, first->size - to->connection->buf_sendq.pos, 0);
200  
201        if (retlen <= 0)
297      {
298 #ifdef _WIN32
299        errno = WSAGetLastError();
300 #endif
202          break;
302      }
203  
204 <      dbuf_delete(&to->localClient->buf_sendq, retlen);
204 >      dbuf_delete(&to->connection->buf_sendq, retlen);
205  
206        /* We have some data written .. update counters */
207 <      to->localClient->send.bytes += retlen;
208 <      me.localClient->send.bytes += retlen;
209 <    } while (dbuf_length(&to->localClient->buf_sendq));
207 >      to->connection->send.bytes += retlen;
208 >      me.connection->send.bytes += retlen;
209 >    } while (dbuf_length(&to->connection->buf_sendq));
210  
211 <    if ((retlen < 0) && (ignoreErrno(errno)))
211 >    if (retlen < 0 && ignoreErrno(errno))
212      {
213 +      AddFlag(to, FLAGS_BLOCKED);
214 +
215        /* we have a non-fatal error, reschedule a write */
216 <      SetSendqBlocked(to);
217 <      comm_setselect(&to->localClient->fd, COMM_SELECT_WRITE,
316 <                     (PF *)sendq_unblocked, (void *)to, 0);
216 >      comm_setselect(&to->connection->fd, COMM_SELECT_WRITE,
217 >                     sendq_unblocked, to, 0);
218      }
219      else if (retlen <= 0)
220      {
# Line 323 | Line 224 | send_queued_write(struct Client *to)
224    }
225   }
226  
326 /*
327 ** send_queued_slink_write
328 **      This is called when there is a chance the some output would
329 **      be possible. This attempts to empty the send queue as far as
330 **      possible, and then if any data is left, a write is rescheduled.
331 */
332 void
333 send_queued_slink_write(struct Client *to)
334 {
335  int retlen;
336
337  /*
338   ** Once socket is marked dead, we cannot start writing to it,
339   ** even if the error is removed...
340   */
341  if (IsDead(to) || IsSlinkqBlocked(to))
342    return;  /* no use calling send() now */
343
344  /* Next, lets try to write some data */
345  if (to->localClient->slinkq != NULL)
346  {
347    retlen = send(to->localClient->ctrlfd.fd,
348                   to->localClient->slinkq + to->localClient->slinkq_ofs,
349                   to->localClient->slinkq_len, 0);
350    if (retlen < 0)
351    {
352      /* If we have a fatal error */
353      if (!ignoreErrno(errno))
354      {
355        dead_link_on_write(to, errno);
356        return;
357      }
358    }
359    else if (retlen == 0)
360    {
361      /* 0 bytes is an EOF .. */
362      dead_link_on_write(to, 0);
363      return;
364    }
365    else
366    {
367      execute_callback(iosendctrl_cb, to, retlen,
368        to->localClient->slinkq + to->localClient->slinkq_ofs);
369      to->localClient->slinkq_len -= retlen;
370
371      assert(to->localClient->slinkq_len >= 0);
372      if (to->localClient->slinkq_len)
373        to->localClient->slinkq_ofs += retlen;
374      else
375      {
376        to->localClient->slinkq_ofs = 0;
377        MyFree(to->localClient->slinkq);
378        to->localClient->slinkq = NULL;
379      }
380    }
381
382    /* Finally, if we have any more data, reschedule a write */
383    if (to->localClient->slinkq_len)
384    {
385      SetSlinkqBlocked(to);
386      comm_setselect(&to->localClient->ctrlfd, COMM_SELECT_WRITE,
387                     (PF *)slinkq_unblocked, (void *)to, 0);
388    }
389  }
390 }
391
227   /* send_queued_all()
228   *
229   * input        - NONE
# Line 398 | Line 233 | send_queued_slink_write(struct Client *t
233   void
234   send_queued_all(void)
235   {
236 <  dlink_node *ptr;
236 >  dlink_node *node = NULL;
237  
238    /* Servers are processed first, mainly because this can generate
239     * a notice to opers, which is to be delivered by this function.
240     */
241 <  DLINK_FOREACH(ptr, serv_list.head)
242 <    send_queued_write((struct Client *) ptr->data);
241 >  DLINK_FOREACH(node, local_server_list.head)
242 >    send_queued_write(node->data);
243  
244 <  DLINK_FOREACH(ptr, unknown_list.head)
245 <    send_queued_write((struct Client *) ptr->data);
244 >  DLINK_FOREACH(node, unknown_list.head)
245 >    send_queued_write(node->data);
246  
247 <  DLINK_FOREACH(ptr, local_client_list.head)
248 <    send_queued_write((struct Client *) ptr->data);
247 >  DLINK_FOREACH(node, local_client_list.head)
248 >    send_queued_write(node->data);
249  
250    /* NOTE: This can still put clients on aborted_list; unfortunately,
251     * exit_aborted_clients takes precedence over send_queued_all,
# Line 431 | Line 266 | void
266   sendto_one(struct Client *to, const char *pattern, ...)
267   {
268    va_list args;
269 <  char buffer[IRCD_BUFSIZE];
270 <  int len;
269 >  struct dbuf_block *buffer = NULL;
270 >
271 >  if (IsDead(to->from))
272 >    return;  /* This socket has already been marked as dead */
273  
274 <  if (to->from != NULL)
438 <    to = to->from;
439 <  if (IsDead(to))
440 <    return; /* This socket has already been marked as dead */
274 >  buffer = dbuf_alloc();
275  
276    va_start(args, pattern);
277 <  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
277 >  send_format(buffer, pattern, args);
278 >  va_end(args);
279 >
280 >  send_message(to->from, buffer);
281 >
282 >  dbuf_ref_free(buffer);
283 > }
284 >
285 > void
286 > sendto_one_numeric(struct Client *to, struct Client *from, enum irc_numerics numeric, ...)
287 > {
288 >  struct dbuf_block *buffer = NULL;
289 >  const char *dest = NULL, *numstr = NULL;
290 >  va_list args;
291 >
292 >  if (IsDead(to->from))
293 >    return;
294 >
295 >  dest = ID_or_name(to, to);
296 >
297 >  if (EmptyString(dest))
298 >    dest = "*";
299 >
300 >  buffer = dbuf_alloc();
301 >
302 >  dbuf_put_fmt(buffer, ":%s %03d %s ", ID_or_name(from, to), numeric & ~SND_EXPLICIT, dest);
303 >
304 >  va_start(args, numeric);
305 >
306 >  if (numeric & SND_EXPLICIT)
307 >    numstr = va_arg(args, const char *);
308 >  else
309 >    numstr = numeric_form(numeric);
310 >
311 >  send_format(buffer, numstr, args);
312    va_end(args);
313  
314 <  send_message(to, buffer, len);
314 >  send_message(to->from, buffer);
315 >
316 >  dbuf_ref_free(buffer);
317 > }
318 >
319 > void
320 > sendto_one_notice(struct Client *to, struct Client *from, const char *pattern, ...)
321 > {
322 >  struct dbuf_block *buffer = NULL;
323 >  const char *dest = NULL;
324 >  va_list args;
325 >
326 >  if (IsDead(to->from))
327 >    return;
328 >
329 >  dest = ID_or_name(to, to);
330 >
331 >  if (EmptyString(dest))
332 >    dest = "*";
333 >
334 >  buffer = dbuf_alloc();
335 >
336 >  dbuf_put_fmt(buffer, ":%s NOTICE %s ", ID_or_name(from, to), dest);
337 >
338 >  va_start(args, pattern);
339 >  send_format(buffer, pattern, args);
340 >  va_end(args);
341 >
342 >  send_message(to->from, buffer);
343 >
344 >  dbuf_ref_free(buffer);
345   }
346  
347   /* sendto_channel_butone()
# Line 459 | Line 357 | sendto_one(struct Client *to, const char
357   */
358   void
359   sendto_channel_butone(struct Client *one, struct Client *from,
360 <                      struct Channel *chptr, const char *command,
360 >                      struct Channel *chptr, unsigned int type,
361                        const char *pattern, ...)
362   {
363 <  va_list alocal, aremote, auid;
364 <  char local_buf[IRCD_BUFSIZE];
365 <  char remote_buf[IRCD_BUFSIZE];
366 <  char uid_buf[IRCD_BUFSIZE];
367 <  int local_len, remote_len, uid_len;
470 <  dlink_node *ptr;
471 <  dlink_node *ptr_next;
472 <  struct Client *target_p;
363 >  va_list alocal, aremote;
364 >  struct dbuf_block *local_buf, *remote_buf;
365 >  dlink_node *node = NULL;
366 >
367 >  local_buf = dbuf_alloc(), remote_buf = dbuf_alloc();
368  
369 <  if (IsServer(from))
370 <    local_len = ircsprintf(local_buf, ":%s %s %s ",
476 <                           from->name, command, chptr->chname);
369 >  if (IsClient(from))
370 >    dbuf_put_fmt(local_buf, ":%s!%s@%s ", from->name, from->username, from->host);
371    else
372 <    local_len = ircsprintf(local_buf, ":%s!%s@%s %s %s ",
373 <                           from->name, from->username, from->host,
374 <                           command, chptr->chname);
481 <  remote_len = ircsprintf(remote_buf, ":%s %s %s ",
482 <                          from->name, command, chptr->chname);
483 <  uid_len = ircsprintf(uid_buf, ":%s %s %s ",
484 <                       ID(from), command, chptr->chname);
372 >    dbuf_put_fmt(local_buf, ":%s ", from->name);
373 >
374 >  dbuf_put_fmt(remote_buf, ":%s ", from->id);
375  
376    va_start(alocal, pattern);
377    va_start(aremote, pattern);
378 <  va_start(auid, pattern);
379 <  local_len += send_format(&local_buf[local_len], IRCD_BUFSIZE - local_len,
380 <                           pattern, alocal);
491 <  remote_len += send_format(&remote_buf[remote_len], IRCD_BUFSIZE - remote_len,
492 <                            pattern, aremote);
493 <  uid_len += send_format(&uid_buf[uid_len], IRCD_BUFSIZE - uid_len, pattern,
494 <                         auid);
495 <  va_end(auid);
378 >  send_format(local_buf, pattern, alocal);
379 >  send_format(remote_buf, pattern, aremote);
380 >
381    va_end(aremote);
382    va_end(alocal);
383  
384    ++current_serial;
385  
386 <  DLINK_FOREACH_SAFE(ptr, ptr_next, chptr->members.head)
386 >  DLINK_FOREACH(node, chptr->members.head)
387    {
388 <    target_p = ((struct Membership *)ptr->data)->client_p;
389 <    assert(target_p != NULL);
388 >    struct Membership *member = node->data;
389 >    struct Client *target_p = member->client_p;
390  
391 <    if (IsDefunct(target_p) || IsDeaf(target_p) || target_p->from == one)
391 >    assert(IsClient(target_p));
392 >
393 >    if (IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF) ||
394 >        (one && target_p->from == one->from))
395        continue;
396  
397 <    if (MyClient(target_p))
398 <    {
399 <      if (target_p->serial != current_serial)
400 <      {
401 <        send_message(target_p, local_buf, local_len);
402 <        target_p->serial = current_serial;
403 <      }
404 <    }
405 <    else
518 <    {
519 <      /* Now check whether a message has been sent to this
520 <       * remote link already
521 <       */
522 <      if (target_p->from->serial != current_serial)
523 <      {
524 <        if (IsCapable(target_p->from, CAP_TS6))
525 <          send_message_remote(target_p->from, from, uid_buf, uid_len);
526 <        else
527 <          send_message_remote(target_p->from, from, remote_buf, remote_len);
528 <        target_p->from->serial = current_serial;
529 <      }
530 <    }
397 >    if (type && (member->flags & type) == 0)
398 >      continue;
399 >
400 >    if (MyConnect(target_p))
401 >      send_message(target_p, local_buf);
402 >    else if (target_p->from->connection->serial != current_serial)
403 >      send_message_remote(target_p->from, from, remote_buf);
404 >
405 >    target_p->from->connection->serial = current_serial;
406    }
407 +
408 +  dbuf_ref_free(local_buf);
409 +  dbuf_ref_free(remote_buf);
410   }
411  
412   /* sendto_server()
413 < *
413 > *
414   * inputs       - pointer to client to NOT send to
415   *              - pointer to channel
416   *              - caps or'd together which must ALL be present
# Line 543 | Line 421 | sendto_channel_butone(struct Client *one
421   * side effects - Send a message to all connected servers, except the
422   *                client 'one' (if non-NULL), as long as the servers
423   *                support ALL capabs in 'caps', and NO capabs in 'nocaps'.
424 < *            
424 > *
425   * This function was written in an attempt to merge together the other
426   * billion sendto_*serv*() functions, which sprung up with capabs,
427   * lazylinks, uids, etc.
428   * -davidt
429   */
430 < void
430 > void
431   sendto_server(struct Client *one,
432 <              struct Channel *chptr, unsigned long caps,
433 <              unsigned long nocaps,
432 >              const unsigned int caps,
433 >              const unsigned int nocaps,
434                const char *format, ...)
435   {
436    va_list args;
437 <  dlink_node *ptr = NULL;
438 <  char buffer[IRCD_BUFSIZE];
561 <  int len = 0;
562 <
563 <  if (chptr && chptr->chname[0] != '#')
564 <    return;
437 >  dlink_node *node = NULL;
438 >  struct dbuf_block *buffer = dbuf_alloc();
439  
440    va_start(args, format);
441 <  len = send_format(buffer, IRCD_BUFSIZE, format, args);
441 >  send_format(buffer, format, args);
442    va_end(args);
443  
444 <  DLINK_FOREACH(ptr, serv_list.head)
444 >  DLINK_FOREACH(node, local_server_list.head)
445    {
446 <    struct Client *client_p = ptr->data;
446 >    struct Client *client_p = node->data;
447  
448      /* If dead already skip */
449      if (IsDead(client_p))
450        continue;
451 +
452      /* check against 'one' */
453 <    if (one != NULL && (client_p == one->from))
453 >    if (one && (client_p == one->from))
454        continue;
455 +
456      /* check we have required capabs */
457 <    if ((client_p->localClient->caps & caps) != caps)
457 >    if ((client_p->connection->caps & caps) != caps)
458        continue;
459 +
460      /* check we don't have any forbidden capabs */
461 <    if ((client_p->localClient->caps & nocaps) != 0)
461 >    if ((client_p->connection->caps & nocaps))
462        continue;
463  
464 <    send_message(client_p, buffer, len);
464 >    send_message(client_p, buffer);
465    }
466 +
467 +  dbuf_ref_free(buffer);
468   }
469  
470   /* sendto_common_channels_local()
# Line 594 | Line 473 | sendto_server(struct Client *one,
473   *              - pattern to send
474   * output       - NONE
475   * side effects - Sends a message to all people on local server who are
476 < *                in same channel with user.
476 > *                in same channel with user.
477   *                used by m_nick.c and exit_one_client.
478   */
479   void
480 < sendto_common_channels_local(struct Client *user, int touser,
481 <                             const char *pattern, ...)
480 > sendto_common_channels_local(struct Client *user, int touser, unsigned int poscap,
481 >                             unsigned int negcap, const char *pattern, ...)
482   {
483    va_list args;
484    dlink_node *uptr;
485    dlink_node *cptr;
486    struct Channel *chptr;
487 <  struct Membership *ms;
487 >  struct Membership *member;
488    struct Client *target_p;
489 <  char buffer[IRCD_BUFSIZE];
611 <  int len;
489 >  struct dbuf_block *buffer = dbuf_alloc();
490  
491    va_start(args, pattern);
492 <  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
492 >  send_format(buffer, pattern, args);
493    va_end(args);
494  
495    ++current_serial;
496  
497    DLINK_FOREACH(cptr, user->channel.head)
498    {
499 <    chptr = ((struct Membership *) cptr->data)->chptr;
622 <    assert(chptr != NULL);
499 >    chptr = ((struct Membership *)cptr->data)->chptr;
500  
501 <    DLINK_FOREACH(uptr, chptr->members.head)
501 >    DLINK_FOREACH(uptr, chptr->locmembers.head)
502      {
503 <      ms = uptr->data;
504 <      target_p = ms->client_p;
505 <      assert(target_p != NULL);
503 >      member = uptr->data;
504 >      target_p = member->client_p;
505 >
506 >      if (target_p == user || IsDefunct(target_p) ||
507 >          target_p->connection->serial == current_serial)
508 >        continue;
509 >
510 >      if (poscap && HasCap(target_p, poscap) != poscap)
511 >        continue;
512  
513 <      if (!MyConnect(target_p) || target_p == user || IsDefunct(target_p) ||
631 <          target_p->serial == current_serial)
513 >      if (negcap && HasCap(target_p, negcap))
514          continue;
515  
516 <      target_p->serial = current_serial;
517 <      send_message(target_p, buffer, len);
516 >      target_p->connection->serial = current_serial;
517 >      send_message(target_p, buffer);
518      }
519    }
520  
521    if (touser && MyConnect(user) && !IsDead(user) &&
522 <      user->serial != current_serial)
523 <    send_message(user, buffer, len);
522 >      user->connection->serial != current_serial)
523 >    if (HasCap(user, poscap) == poscap)
524 >      send_message(user, buffer);
525 >
526 >  dbuf_ref_free(buffer);
527   }
528  
529 < /* sendto_channel_local()
530 < *
531 < * inputs       - member status mask, e.g. CHFL_CHANOP | CHFL_VOICE
532 < *              - whether to ignore +D clients (YES/NO)
533 < *              - pointer to channel to send to
534 < *              - var args pattern
535 < * output       - NONE
651 < * side effects - Send a message to all members of a channel that are
652 < *                locally connected to this server.
529 > /*! \brief Send a message to members of a channel that are locally connected to this server.
530 > * \param one      Client to skip; can be NULL
531 > * \param chptr    Destination channel
532 > * \param status   Channel member status flags clients must have
533 > * \param poscap   Positive client capabilities flags (CAP)
534 > * \param negcap   Negative client capabilities flags (CAP)
535 > * \param pattern  Format string for command arguments
536   */
537   void
538 < sendto_channel_local(int type, int nodeaf, struct Channel *chptr,
539 <                     const char *pattern, ...)
538 > sendto_channel_local(const struct Client *one, struct Channel *chptr, unsigned int status,
539 >                     unsigned int poscap, unsigned int negcap, const char *pattern, ...)
540   {
541    va_list args;
542 <  char buffer[IRCD_BUFSIZE];
543 <  int len;
661 <  dlink_node *ptr;
662 <  struct Membership *ms;
663 <  struct Client *target_p;
542 >  dlink_node *node = NULL;
543 >  struct dbuf_block *buffer = dbuf_alloc();
544  
545    va_start(args, pattern);
546 <  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
546 >  send_format(buffer, pattern, args);
547    va_end(args);
548  
549 <  DLINK_FOREACH(ptr, chptr->members.head)
549 >  DLINK_FOREACH(node, chptr->locmembers.head)
550    {
551 <    ms = ptr->data;
552 <    target_p = ms->client_p;
551 >    struct Membership *member = node->data;
552 >    struct Client *target_p = member->client_p;
553  
554 <    if (type != 0 && (ms->flags & type) == 0)
554 >    if (IsDefunct(target_p))
555        continue;
556  
557 <    if (!MyConnect(target_p) || IsDefunct(target_p) ||
678 <        (nodeaf && IsDeaf(target_p)))
557 >    if (one && target_p == one->from)
558        continue;
559  
560 <    send_message(target_p, buffer, len);
682 <  }
683 < }
684 <
685 < /* sendto_channel_local_butone()
686 < *
687 < * inputs       - pointer to client to NOT send message to
688 < *              - member status mask, e.g. CHFL_CHANOP | CHFL_VOICE
689 < *              - pointer to channel to send to
690 < *              - var args pattern
691 < * output       - NONE
692 < * side effects - Send a message to all members of a channel that are
693 < *                locally connected to this server except one.
694 < *
695 < * WARNING - +D clients are omitted
696 < */
697 < void      
698 < sendto_channel_local_butone(struct Client *one, int type,
699 <                            struct Channel *chptr, const char *pattern, ...)
700 < {
701 <  va_list args;
702 <  char buffer[IRCD_BUFSIZE];
703 <  int len;
704 <  struct Client *target_p;
705 <  struct Membership *ms;
706 <  dlink_node *ptr;
707 <
708 <  va_start(args, pattern);
709 <  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
710 <  va_end(args);
711 <
712 <  DLINK_FOREACH(ptr, chptr->members.head)      
713 <  {  
714 <    ms = ptr->data;
715 <    target_p = ms->client_p;
716 <
717 <    if (type != 0 && (ms->flags & type) == 0)
560 >    if (status && (member->flags & status) == 0)
561        continue;
562  
563 <    if (!MyConnect(target_p) || target_p == one ||
721 <        IsDefunct(target_p) || IsDeaf(target_p))
563 >    if (poscap && HasCap(target_p, poscap) != poscap)
564        continue;
723    send_message(target_p, buffer, len);
724  }
725 }
726
727
728 /* sendto_channel_remote()
729 *
730 * inputs       - Client not to send towards
731 *              - Client from whom message is from
732 *              - member status mask, e.g. CHFL_CHANOP | CHFL_VOICE
733 *              - pointer to channel to send to
734 *              - var args pattern
735 * output       - NONE
736 * side effects - Send a message to all members of a channel that are
737 *                remote to this server.
738 */
739 void
740 sendto_channel_remote(struct Client *one, struct Client *from, int type, int caps,
741                      int nocaps, struct Channel *chptr, const char *pattern, ...)
742 {
743  va_list args;
744  char buffer[IRCD_BUFSIZE];
745  int len;
746  dlink_node *ptr;
747  struct Client *target_p;
748  struct Membership *ms;
749
750  va_start(args, pattern);
751  len = send_format(buffer, IRCD_BUFSIZE, pattern, args);
752  va_end(args);
753
754  ++current_serial;
565  
566 <  DLINK_FOREACH(ptr, chptr->members.head)
757 <  {
758 <    ms = ptr->data;
759 <    target_p = ms->client_p;
760 <
761 <    if (type != 0 && (ms->flags & type) == 0)
566 >    if (negcap && HasCap(target_p, negcap))
567        continue;
568  
569 <    if (MyConnect(target_p))
570 <      continue;
766 <    target_p = target_p->from;
569 >    send_message(target_p, buffer);
570 >  }
571  
572 <    if (target_p == one->from ||
769 <        ((target_p->from->localClient->caps & caps) != caps) ||
770 <        ((target_p->from->localClient->caps & nocaps) != 0))
771 <      continue;
772 <    if (target_p->from->serial != current_serial)
773 <    {
774 <      send_message(target_p, buffer, len);
775 <      target_p->from->serial = current_serial;
776 <    }
777 <  }
572 >  dbuf_ref_free(buffer);
573   }
574  
575   /*
# Line 795 | Line 590 | sendto_channel_remote(struct Client *one
590   * side effects - NONE
591   */
592   static int
593 < match_it(const struct Client *one, const char *mask, int what)
593 > match_it(const struct Client *one, const char *mask, unsigned int what)
594   {
595    if (what == MATCH_HOST)
596 <    return(match(mask, one->host));
596 >    return !match(mask, one->host);
597  
598 <  return(match(mask, one->servptr->name));
598 >  return !match(mask, one->servptr->name);
599   }
600  
601   /* sendto_match_butone()
# Line 811 | Line 606 | match_it(const struct Client *one, const
606   * ugh. ONLY used by m_message.c to send an "oper magic" message. ugh.
607   */
608   void
609 < sendto_match_butone(struct Client *one, struct Client *from, char *mask,
609 > sendto_match_butone(struct Client *one, struct Client *from, const char *mask,
610                      int what, const char *pattern, ...)
611   {
612    va_list alocal, aremote;
613 <  struct Client *client_p;
614 <  dlink_node *ptr, *ptr_next;
615 <  char local_buf[IRCD_BUFSIZE], remote_buf[IRCD_BUFSIZE];
616 <  int local_len = ircsprintf(local_buf, ":%s!%s@%s ", from->name,
617 <                             from->username, from->host);
618 <  int remote_len = ircsprintf(remote_buf, ":%s ", from->name);
613 >  dlink_node *node = NULL;
614 >  struct dbuf_block *local_buf, *remote_buf;
615 >
616 >  local_buf = dbuf_alloc(), remote_buf = dbuf_alloc();
617 >
618 >  dbuf_put_fmt(local_buf, ":%s!%s@%s ", from->name, from->username, from->host);
619 >  dbuf_put_fmt(remote_buf, ":%s ", from->id);
620  
621    va_start(alocal, pattern);
622    va_start(aremote, pattern);
623 <  local_len += send_format(&local_buf[local_len], IRCD_BUFSIZE - local_len,
624 <                           pattern, alocal);
829 <  remote_len += send_format(&remote_buf[remote_len], IRCD_BUFSIZE - remote_len,
830 <                            pattern, aremote);
623 >  send_format(local_buf, pattern, alocal);
624 >  send_format(remote_buf, pattern, aremote);
625    va_end(aremote);
626    va_end(alocal);
627  
628    /* scan the local clients */
629 <  DLINK_FOREACH(ptr, local_client_list.head)
629 >  DLINK_FOREACH(node, local_client_list.head)
630    {
631 <    client_p = ptr->data;
631 >    struct Client *client_p = node->data;
632  
633 <    if (client_p != one && !IsDefunct(client_p) &&
633 >    if ((!one || client_p != one->from) && !IsDefunct(client_p) &&
634          match_it(client_p, mask, what))
635 <      send_message(client_p, local_buf, local_len);
635 >      send_message(client_p, local_buf);
636    }
637  
638    /* Now scan servers */
639 <  DLINK_FOREACH_SAFE(ptr, ptr_next, serv_list.head)
639 >  DLINK_FOREACH(node, local_server_list.head)
640    {
641 <    client_p = ptr->data;
641 >    struct Client *client_p = node->data;
642  
643      /*
644       * The old code looped through every client on the
# Line 870 | Line 664 | sendto_match_butone(struct Client *one,
664       * server deal with it.
665       * -wnder
666       */
667 <    if (client_p != one && !IsDefunct(client_p))
668 <      send_message_remote(client_p, from, remote_buf, remote_len);
667 >    if ((!one || client_p != one->from) && !IsDefunct(client_p))
668 >      send_message_remote(client_p, from, remote_buf);
669    }
670 +
671 +  dbuf_ref_free(local_buf);
672 +  dbuf_ref_free(remote_buf);
673   }
674  
675   /* sendto_match_servs()
# Line 885 | Line 682 | sendto_match_butone(struct Client *one,
682   * side effects - data sent to servers matching with capab
683   */
684   void
685 < sendto_match_servs(struct Client *source_p, const char *mask, int cap,
685 > sendto_match_servs(struct Client *source_p, const char *mask, unsigned int cap,
686                     const char *pattern, ...)
687   {
688    va_list args;
689 <  struct Client *target_p;
690 <  dlink_node *ptr;
894 <  char buffer[IRCD_BUFSIZE];
895 <  int found = 0;
689 >  dlink_node *node = NULL;
690 >  struct dbuf_block *buffer = dbuf_alloc();
691  
692 +  dbuf_put_fmt(buffer, ":%s ", source_p->id);
693    va_start(args, pattern);
694 <  vsnprintf(buffer, sizeof(buffer), pattern, args);
694 >  send_format(buffer, pattern, args);
695    va_end(args);
696  
697 <  current_serial++;
697 >  ++current_serial;
698  
699 <  DLINK_FOREACH(ptr, global_serv_list.head)
699 >  DLINK_FOREACH(node, global_server_list.head)
700    {
701 <    target_p = ptr->data;
701 >    struct Client *target_p = node->data;
702  
703      /* Do not attempt to send to ourselves, or the source */
704      if (IsMe(target_p) || target_p->from == source_p->from)
705        continue;
706  
707 <    if (target_p->from->serial == current_serial)
707 >    if (target_p->from->connection->serial == current_serial)
708        continue;
709  
710      if (match(mask, target_p->name))
711 <    {
916 <      /*
917 <       * if we set the serial here, then we'll never do a
918 <       * match() again, if !IsCapable()
919 <       */
920 <      target_p->from->serial = current_serial;
921 <      found++;
711 >      continue;
712  
713 <      if (!IsCapable(target_p->from, cap))
714 <        continue;
713 >    /*
714 >     * If we set the serial here, then we'll never do a
715 >     * match() again, if !IsCapable()
716 >     */
717 >    target_p->from->connection->serial = current_serial;
718  
719 <      sendto_anywhere(target_p, source_p, "%s", buffer);
720 <    }
719 >    if (!IsCapable(target_p->from, cap))
720 >      continue;
721 >
722 >    send_message_remote(target_p->from, source_p, buffer);
723    }
724 +
725 +  dbuf_ref_free(buffer);
726   }
727  
728   /* sendto_anywhere()
# Line 939 | Line 736 | sendto_match_servs(struct Client *source
736   */
737   void
738   sendto_anywhere(struct Client *to, struct Client *from,
739 +                const char *command,
740                  const char *pattern, ...)
741   {
742    va_list args;
743 <  char buffer[IRCD_BUFSIZE];
946 <  int len;
947 <  struct Client *send_to = (to->from != NULL ? to->from : to);
743 >  struct dbuf_block *buffer = NULL;
744  
745 <  if (IsDead(send_to))
745 >  if (IsDead(to->from))
746      return;
747  
748 <  if (MyClient(to))
749 <  {
750 <    if (IsServer(from))
751 <    {
752 <      if (IsCapable(to, CAP_TS6) && HasID(from))
753 <        len = ircsprintf(buffer, ":%s ", from->id);
754 <      else
755 <        len = ircsprintf(buffer, ":%s ", from->name);
960 <    }
961 <    else
962 <      len = ircsprintf(buffer, ":%s!%s@%s ",
963 <                       from->name, from->username, from->host);
964 <  }
965 <  else len = ircsprintf(buffer, ":%s ", ID_or_name(from, send_to));
748 >  buffer = dbuf_alloc();
749 >
750 >  if (MyClient(to) && IsClient(from))
751 >    dbuf_put_fmt(buffer, ":%s!%s@%s %s %s ", from->name, from->username,
752 >                 from->host, command, to->name);
753 >  else
754 >    dbuf_put_fmt(buffer, ":%s %s %s ", ID_or_name(from, to),
755 >                 command, ID_or_name(to, to));
756  
757    va_start(args, pattern);
758 <  len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args);
758 >  send_format(buffer, pattern, args);
759    va_end(args);
760  
761 <  if(MyClient(to))
762 <    send_message(send_to, buffer, len);
761 >  if (MyConnect(to))
762 >    send_message(to, buffer);
763    else
764 <    send_message_remote(send_to, from, buffer, len);
764 >    send_message_remote(to->from, from, buffer);
765 >
766 >  dbuf_ref_free(buffer);
767   }
768  
769   /* sendto_realops_flags()
# Line 983 | Line 775 | sendto_anywhere(struct Client *to, struc
775   * side effects - Send to *local* ops only but NOT +s nonopers.
776   */
777   void
778 < sendto_realops_flags(unsigned int flags, int level, const char *pattern, ...)
778 > sendto_realops_flags(unsigned int flags, int level, int type, const char *pattern, ...)
779   {
780 <  struct Client *client_p;
781 <  char nbuf[IRCD_BUFSIZE];
782 <  dlink_node *ptr;
780 >  const char *ntype = NULL;
781 >  dlink_node *node = NULL;
782 >  char nbuf[IRCD_BUFSIZE] = "";
783    va_list args;
784  
785    va_start(args, pattern);
786 <  vsnprintf(nbuf, IRCD_BUFSIZE, pattern, args);
786 >  vsnprintf(nbuf, sizeof(nbuf), pattern, args);
787    va_end(args);
788  
789 <  DLINK_FOREACH(ptr, oper_list.head)
789 >  switch (type)
790    {
791 <    client_p = ptr->data;
792 <    assert(client_p->umodes & UMODE_OPER);
793 <
794 <    /* If we're sending it to opers and theyre an admin, skip.
795 <     * If we're sending it to admins, and theyre not, skip.
796 <     */
797 <    if (((level == L_ADMIN) && !IsAdmin(client_p)) ||
798 <        ((level == L_OPER) && IsAdmin(client_p)))
799 <      continue;
800 <
801 <    if (client_p->umodes & flags)
1010 <      sendto_one(client_p, ":%s NOTICE %s :*** Notice -- %s",
1011 <                 me.name, client_p->name, nbuf);
791 >    case SEND_NOTICE:
792 >      ntype = "Notice";
793 >      break;
794 >    case SEND_GLOBAL:
795 >      ntype = "Global";
796 >      break;
797 >    case SEND_LOCOPS:
798 >      ntype = "LocOps";
799 >      break;
800 >    default:
801 >      assert(0);
802    }
1013 }
1014
1015 /* sendto_wallops_flags()
1016 *
1017 * inputs       - flag types of messages to show to real opers
1018 *              - client sending request
1019 *              - var args input message
1020 * output       - NONE
1021 * side effects - Send a wallops to local opers
1022 */
1023 void
1024 sendto_wallops_flags(unsigned int flags, struct Client *source_p,
1025                     const char *pattern, ...)
1026 {
1027  struct Client *client_p;
1028  dlink_node *ptr;
1029  va_list args;
1030  char buffer[IRCD_BUFSIZE];
1031  int len;
1032
1033  if (IsClient(source_p))
1034    len = ircsprintf(buffer, ":%s!%s@%s WALLOPS :",
1035                     source_p->name, source_p->username, source_p->host);
1036  else
1037    len = ircsprintf(buffer, ":%s WALLOPS :", source_p->name);
803  
804 <  va_start(args, pattern);
1040 <  len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args);
1041 <  va_end(args);
1042 <
1043 <  DLINK_FOREACH(ptr, oper_list.head)
804 >  DLINK_FOREACH(node, oper_list.head)
805    {
806 <    client_p = ptr->data;
807 <    assert(client_p->umodes & UMODE_OPER);
1047 <
1048 <    if ((client_p->umodes & flags) && !IsDefunct(client_p))
1049 <      send_message(client_p, buffer, len);
1050 <  }
1051 < }
1052 <
1053 < /* ts_warn()
1054 < *
1055 < * inputs       - var args message
1056 < * output       - NONE
1057 < * side effects - Call sendto_realops_flags, with some flood checking
1058 < *                (at most 5 warnings every 5 seconds)
1059 < */
1060 < void
1061 < ts_warn(const char *pattern, ...)
1062 < {
1063 <  va_list args;
1064 <  char buffer[LOG_BUFSIZE];
1065 <  static time_t last = 0;
1066 <  static int warnings = 0;
806 >    struct Client *client_p = node->data;
807 >    assert(HasUMode(client_p, UMODE_OPER));
808  
809 <  /*
810 <   ** if we're running with TS_WARNINGS enabled and someone does
811 <   ** something silly like (remotely) connecting a nonTS server,
812 <   ** we'll get a ton of warnings, so we make sure we don't send
813 <   ** more than 5 every 5 seconds.  -orabidoo
814 <   */
809 >    /*
810 >     * If we're sending it to opers and they're an admin, skip.
811 >     * If we're sending it to admins, and they're not, skip.
812 >     */
813 >    if (((level == L_ADMIN) && !HasUMode(client_p, UMODE_ADMIN)) ||
814 >        ((level == L_OPER) && HasUMode(client_p, UMODE_ADMIN)))
815 >      continue;
816  
817 <  if (CurrentTime - last < 5)
818 <  {
819 <    if (++warnings > 5)
1078 <      return;
817 >    if (HasUMode(client_p, flags))
818 >      sendto_one(client_p, ":%s NOTICE %s :*** %s -- %s",
819 >                 me.name, client_p->name, ntype, nbuf);
820    }
1080  else
1081  {
1082    last = CurrentTime;
1083    warnings = 0;
1084  }
1085
1086  va_start(args, pattern);
1087  vsprintf_irc(buffer, pattern, args);
1088  va_end(args);
1089
1090  sendto_realops_flags(UMODE_ALL, L_ALL, "%s", buffer);
1091  ilog(L_CRIT, "%s", buffer);
821   }
822  
823 < /* kill_client()
823 > /* ts_warn()
824   *
825 < * inputs       - client to send kill towards
826 < *              - pointer to client to kill
827 < *              - reason for kill
828 < * output       - NONE
1100 < * side effects - NONE
825 > * inputs       - var args message
826 > * output       - NONE
827 > * side effects - Call sendto_realops_flags, with some flood checking
828 > *                (at most 5 warnings every 5 seconds)
829   */
830   void
831 < kill_client(struct Client *client_p, struct Client *diedie,
1104 <            const char *pattern, ...)
831 > sendto_realops_flags_ratelimited(time_t *rate, const char *pattern, ...)
832   {
833    va_list args;
834 <  char buffer[IRCD_BUFSIZE];
1108 <  int len;
834 >  char buffer[IRCD_BUFSIZE] = "";
835  
836 <  if (client_p->from != NULL)
1111 <    client_p = client_p->from;
1112 <  if (IsDead(client_p))
836 >  if ((CurrentTime - *rate) < 20)
837      return;
838  
839 <  len = ircsprintf(buffer, ":%s KILL %s :", ID_or_name(&me, client_p->from),
1116 <                   ID_or_name(diedie, client_p));
839 >  *rate = CurrentTime;
840  
841    va_start(args, pattern);
842 <  len += send_format(&buffer[len], IRCD_BUFSIZE - len, pattern, args);
842 >  vsnprintf(buffer, sizeof(buffer), pattern, args);
843    va_end(args);
844  
845 <  send_message(client_p, buffer, len);
845 >  sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, "%s", buffer);
846 >  ilog(LOG_TYPE_IRCD, "%s", buffer);
847   }
848  
849 < /* kill_client_ll_serv_butone()
849 > /* sendto_wallops_flags()
850   *
851 < * inputs       - pointer to client to not send to
852 < *              - pointer to client to kill
853 < * output       - NONE
854 < * side effects - Send a KILL for the given client
855 < *                message to all connected servers
1132 < *                except the client 'one'. Also deal with
1133 < *                client being unknown to leaf, as in lazylink...
851 > * inputs       - flag types of messages to show to real opers
852 > *              - client sending request
853 > *              - var args input message
854 > * output       - NONE
855 > * side effects - Send a wallops to local opers
856   */
857   void
858 < kill_client_ll_serv_butone(struct Client *one, struct Client *source_p,
859 <                           const char *pattern, ...)
858 > sendto_wallops_flags(unsigned int flags, struct Client *source_p,
859 >                     const char *pattern, ...)
860   {
861 +  dlink_node *node = NULL;
862    va_list args;
863 <  int have_uid = 0;
1141 <  dlink_node *ptr = NULL;
1142 <  char buf_uid[IRCD_BUFSIZE], buf_nick[IRCD_BUFSIZE];
1143 <  int len_uid = 0, len_nick = 0;
863 >  struct dbuf_block *buffer = dbuf_alloc();
864  
865 <  if (HasID(source_p) && (me.id[0] != '\0'))
866 <  {
867 <    have_uid = 1;
868 <    va_start(args, pattern);
1149 <    len_uid = ircsprintf(buf_uid, ":%s KILL %s :", me.id, ID(source_p));
1150 <    len_uid += send_format(&buf_uid[len_uid], IRCD_BUFSIZE - len_uid, pattern,
1151 <                           args);
1152 <    va_end(args);
1153 <  }
865 >  if (IsClient(source_p))
866 >    dbuf_put_fmt(buffer, ":%s!%s@%s WALLOPS :", source_p->name, source_p->username, source_p->host);
867 >  else
868 >    dbuf_put_fmt(buffer, ":%s WALLOPS :", source_p->name);
869  
870    va_start(args, pattern);
871 <  len_nick = ircsprintf(buf_nick, ":%s KILL %s :", me.name, source_p->name);
1157 <  len_nick += send_format(&buf_nick[len_nick], IRCD_BUFSIZE - len_nick, pattern,
1158 <                          args);
871 >  send_format(buffer, pattern, args);
872    va_end(args);
873  
874 <  DLINK_FOREACH(ptr, serv_list.head)
874 >  DLINK_FOREACH(node, oper_list.head)
875    {
876 <    struct Client *client_p = ptr->data;
877 <
1165 <    if (one != NULL && (client_p == one->from))
1166 <      continue;
1167 <    if (IsDefunct(client_p))
1168 <      continue;
876 >    struct Client *client_p = node->data;
877 >    assert(client_p->umodes & UMODE_OPER);
878  
879 <    if (have_uid && IsCapable(client_p, CAP_TS6))
880 <      send_message(client_p, buf_uid, len_uid);
1172 <    else
1173 <      send_message(client_p, buf_nick, len_nick);
879 >    if (HasUMode(client_p, flags) && !IsDefunct(client_p))
880 >      send_message(client_p, buffer);
881    }
882 < }
882 >
883 >  dbuf_ref_free(buffer);
884 > }

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)