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

Comparing:
ircd-hybrid-8/src/client.c (file contents), Revision 1549 by michael, Mon Oct 1 18:11:11 2012 UTC vs.
ircd-hybrid/trunk/src/client.c (file contents), Revision 3502 by michael, Sat May 10 19:42:22 2014 UTC

# Line 1 | Line 1
1   /*
2 < *  ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 < *  client.c: Controls clients.
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-2014 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 18 | Line 17
17   *  along with this program; if not, write to the Free Software
18   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
19   *  USA
20 < *
21 < *  $Id$
20 > */
21 >
22 > /*! \file client.c
23 > * \brief Controls clients.
24 > * \version $Id$
25   */
26  
27   #include "stdinc.h"
28   #include "list.h"
29   #include "client.h"
28 #include "channel_mode.h"
30   #include "event.h"
30 #include "fdlist.h"
31   #include "hash.h"
32   #include "irc_string.h"
33   #include "ircd.h"
34 #include "s_gline.h"
34   #include "numeric.h"
35 < #include "packet.h"
37 < #include "s_auth.h"
35 > #include "auth.h"
36   #include "s_bsd.h"
37   #include "conf.h"
38   #include "log.h"
39 < #include "s_misc.h"
40 < #include "s_serv.h"
39 > #include "misc.h"
40 > #include "server.h"
41   #include "send.h"
42   #include "whowas.h"
43 < #include "s_user.h"
46 < #include "dbuf.h"
43 > #include "user.h"
44   #include "memory.h"
45 + #include "mempool.h"
46   #include "hostmask.h"
49 #include "balloc.h"
47   #include "listener.h"
51 #include "irc_res.h"
48   #include "userhost.h"
49   #include "watch.h"
50 + #include "rng_mt.h"
51 + #include "parse.h"
52  
53   dlink_list listing_client_list = { NULL, NULL, 0 };
54   /* Pointer to beginning of Client list */
# Line 64 | Line 62 | dlink_list oper_list = {NULL, NULL, 0};
62  
63   static EVH check_pings;
64  
65 < static BlockHeap *client_heap  = NULL;
66 < static BlockHeap *lclient_heap = NULL;
65 > static mp_pool_t *client_pool  = NULL;
66 > static mp_pool_t *lclient_pool = NULL;
67  
68   static dlink_list dead_list  = { NULL, NULL, 0};
69   static dlink_list abort_list = { NULL, NULL, 0};
# Line 74 | Line 72 | static dlink_node *eac_next;  /* next ab
72  
73   static void check_pings_list(dlink_list *);
74   static void check_unknowns_list(void);
77 static void ban_them(struct Client *, struct ConfItem *);
75  
76  
77 < /* init_client()
77 > /* client_init()
78   *
79   * inputs       - NONE
80   * output       - NONE
81   * side effects - initialize client free memory
82   */
83   void
84 < init_client(void)
84 > client_init(void)
85   {
86    /* start off the check ping event ..  -- adrian
87     * Every 30 seconds is plenty -- db
88     */
89 <  client_heap = BlockHeapCreate("client", sizeof(struct Client), CLIENT_HEAP_SIZE);
90 <  lclient_heap = BlockHeapCreate("local client", sizeof(struct LocalUser), LCLIENT_HEAP_SIZE);
89 >  client_pool = mp_pool_new(sizeof(struct Client), MP_CHUNK_SIZE_CLIENT);
90 >  lclient_pool = mp_pool_new(sizeof(struct LocalUser), MP_CHUNK_SIZE_LCLIENT);
91    eventAdd("check_pings", check_pings, NULL, 5);
92   }
93  
# Line 112 | Line 109 | init_client(void)
109   struct Client *
110   make_client(struct Client *from)
111   {
112 <  struct Client *client_p = BlockHeapAlloc(client_heap);
112 >  struct Client *client_p = mp_pool_get(client_pool);
113 >
114 >  memset(client_p, 0, sizeof(*client_p));
115  
116 <  if (from == NULL)
116 >  if (!from)
117    {
118      client_p->from                      = client_p; /* 'from' of local client is self! */
119 <    client_p->localClient               = BlockHeapAlloc(lclient_heap);
119 >    client_p->localClient               = mp_pool_get(lclient_pool);
120 >
121 >    memset(client_p->localClient, 0, sizeof(*client_p->localClient));
122 >
123      client_p->localClient->since        = CurrentTime;
124      client_p->localClient->lasttime     = CurrentTime;
125      client_p->localClient->firsttime    = CurrentTime;
# Line 131 | Line 133 | make_client(struct Client *from)
133  
134    client_p->idhnext = client_p;
135    client_p->hnext  = client_p;
136 <  client_p->status = STAT_UNKNOWN;
136 >  SetUnknown(client_p);
137    strcpy(client_p->username, "unknown");
138 +  strcpy(client_p->svid, "0");
139  
140    return client_p;
141   }
# Line 147 | Line 150 | make_client(struct Client *from)
150   static void
151   free_client(struct Client *client_p)
152   {
153 <  assert(client_p != NULL);
153 >  assert(client_p);
154    assert(client_p != &me);
155    assert(client_p->hnext == client_p);
156    assert(client_p->idhnext == client_p);
157    assert(client_p->channel.head == NULL);
158    assert(dlink_list_length(&client_p->channel) == 0);
159    assert(dlink_list_length(&client_p->whowas) == 0);
160 <  assert(!IsServer(client_p) || IsServer(client_p) && client_p->serv);
160 >  assert(!IsServer(client_p) || client_p->serv);
161  
162    MyFree(client_p->serv);
163 +  MyFree(client_p->certfp);
164  
165    if (MyConnect(client_p))
166    {
167      assert(client_p->localClient->invited.head == NULL);
168      assert(dlink_list_length(&client_p->localClient->invited) == 0);
169 <    assert(dlink_list_length(&client_p->localClient->watches) == 0);
169 >    assert(dlink_list_length(&client_p->localClient->watches) == 0);
170      assert(IsClosing(client_p) && IsDead(client_p));
171  
172      MyFree(client_p->localClient->response);
# Line 175 | Line 179 | free_client(struct Client *client_p)
179      {
180        assert(0 < client_p->localClient->listener->ref_count);
181        if (0 == --client_p->localClient->listener->ref_count &&
182 <          !client_p->localClient->listener->active)
182 >          !client_p->localClient->listener->active)
183          free_listener(client_p->localClient->listener);
184      }
185  
186      dbuf_clear(&client_p->localClient->buf_recvq);
187      dbuf_clear(&client_p->localClient->buf_sendq);
188  
189 <    BlockHeapFree(lclient_heap, client_p->localClient);
189 >    mp_pool_release(client_p->localClient);
190    }
191  
192 <  BlockHeapFree(client_heap, client_p);
192 >  mp_pool_release(client_p);
193   }
194  
195   /*
# Line 194 | Line 198 | free_client(struct Client *client_p)
198   *
199   * inputs       - NOT USED (from event)
200   * output       - next time_t when check_pings() should be called again
201 < * side effects -
201 > * side effects -
202   *
203   *
204   * A PING can be sent to clients as necessary.
# Line 216 | Line 220 | free_client(struct Client *client_p)
220  
221   static void
222   check_pings(void *notused)
223 < {              
223 > {
224    check_pings_list(&local_client_list);
225    check_pings_list(&serv_list);
226    check_unknowns_list();
# Line 226 | Line 230 | check_pings(void *notused)
230   *
231   * inputs       - pointer to list to check
232   * output       - NONE
233 < * side effects -
233 > * side effects -
234   */
235   static void
236   check_pings_list(dlink_list *list)
237   {
238 <  char scratch[32];        /* way too generous but... */
239 <  struct Client *client_p; /* current local client_p being examined */
240 <  int ping, pingwarn;      /* ping time value from client */
237 <  dlink_node *ptr, *next_ptr;
238 >  char scratch[IRCD_BUFSIZE];
239 >  int ping = 0;      /* ping time value from client */
240 >  dlink_node *ptr = NULL, *next_ptr = NULL;
241  
242    DLINK_FOREACH_SAFE(ptr, next_ptr, list->head)
243    {
244 <    client_p = ptr->data;
244 >    struct Client *client_p = ptr->data;
245  
246      /*
247      ** Note: No need to notify opers here. It's
# Line 247 | Line 250 | check_pings_list(dlink_list *list)
250      if (IsDead(client_p))
251      {
252        /* Ignore it, its been exited already */
253 <      continue;
253 >      continue;
254      }
255  
256      if (!IsRegistered(client_p))
257 <      ping = CONNECTTIMEOUT, pingwarn = 0;
257 >      ping = CONNECTTIMEOUT;
258      else
259 <      ping = get_client_ping(client_p, &pingwarn);
259 >      ping = get_client_ping(&client_p->localClient->confs);
260  
261      if (ping < CurrentTime - client_p->localClient->lasttime)
262      {
263        if (!IsPingSent(client_p))
264        {
265 <        /*
266 <         * if we havent PINGed the connection and we havent
267 <         * heard from it in a while, PING it to make sure
268 <         * it is still alive.
269 <         */
270 <        SetPingSent(client_p);
271 <        ClearPingWarning(client_p);
272 <        client_p->localClient->lasttime = CurrentTime - ping;
270 <        sendto_one(client_p, "PING :%s", ID_or_name(&me, client_p));
265 >        /*
266 >         * if we havent PINGed the connection and we havent
267 >         * heard from it in a while, PING it to make sure
268 >         * it is still alive.
269 >         */
270 >        SetPingSent(client_p);
271 >        client_p->localClient->lasttime = CurrentTime - ping;
272 >        sendto_one(client_p, "PING :%s", ID_or_name(&me, client_p));
273        }
274        else
275        {
# Line 278 | Line 280 | check_pings_list(dlink_list *list)
280             * and it has a ping time, then close its connection.
281             */
282            if (IsServer(client_p) || IsHandshake(client_p))
283 <          {
284 <            sendto_realops_flags(UMODE_ALL, L_ADMIN,
285 <                                 "No response from %s, closing link",
286 <                                 get_client_name(client_p, HIDE_IP));
287 <            sendto_realops_flags(UMODE_ALL, L_OPER,
288 <                                 "No response from %s, closing link",
289 <                                 get_client_name(client_p, MASK_IP));
290 <            ilog(LOG_TYPE_IRCD, "No response from %s, closing link",
291 <                 get_client_name(client_p, HIDE_IP));
292 <          }
283 >          {
284 >            sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
285 >                                 "No response from %s, closing link",
286 >                                 get_client_name(client_p, HIDE_IP));
287 >            sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
288 >                                 "No response from %s, closing link",
289 >                                 get_client_name(client_p, MASK_IP));
290 >            ilog(LOG_TYPE_IRCD, "No response from %s, closing link",
291 >                 get_client_name(client_p, HIDE_IP));
292 >          }
293  
294            snprintf(scratch, sizeof(scratch), "Ping timeout: %d seconds",
295                     (int)(CurrentTime - client_p->localClient->lasttime));
296 <          exit_client(client_p, &me, scratch);
295 <        }
296 <        else if (!IsPingWarning(client_p) && pingwarn > 0 &&
297 <                 (IsServer(client_p) || IsHandshake(client_p)) &&
298 <                 CurrentTime - client_p->localClient->lasttime >= ping + pingwarn)
299 <        {
300 <          /*
301 <           * If the server hasn't replied in pingwarn seconds after sending
302 <           * the PING, notify the opers so that they are aware of the problem.
303 <           */
304 <          SetPingWarning(client_p);
305 <          sendto_realops_flags(UMODE_ALL, L_ADMIN,
306 <                               "Warning, no response from %s in %d seconds",
307 <                               get_client_name(client_p, HIDE_IP), pingwarn);
308 <          sendto_realops_flags(UMODE_ALL, L_OPER,
309 <                               "Warning, no response from %s in %d seconds",
310 <                               get_client_name(client_p, MASK_IP), pingwarn);
311 <          ilog(LOG_TYPE_IRCD, "No response from %s in %d seconds",
312 <               get_client_name(client_p, HIDE_IP), pingwarn);
296 >          exit_client(client_p, scratch);
297          }
298        }
299      }
# Line 325 | Line 309 | check_pings_list(dlink_list *list)
309   static void
310   check_unknowns_list(void)
311   {
312 <  dlink_node *ptr, *next_ptr;
312 >  dlink_node *ptr = NULL, *ptr_next = NULL;
313  
314 <  DLINK_FOREACH_SAFE(ptr, next_ptr, unknown_list.head)
314 >  DLINK_FOREACH_SAFE(ptr, ptr_next, unknown_list.head)
315    {
316      struct Client *client_p = ptr->data;
317  
# Line 336 | Line 320 | check_unknowns_list(void)
320       * for > 30s, close them.
321       */
322      if (IsAuthFinished(client_p) && (CurrentTime - client_p->localClient->firsttime) > 30)
323 <      exit_client(client_p, &me, "Registration timed out");
323 >      exit_client(client_p, "Registration timed out");
324    }
325   }
326  
# Line 347 | Line 331 | check_unknowns_list(void)
331   * side effects - Check all connections for a pending kline against the
332   *                client, exit the client if a kline matches.
333   */
334 < void
334 > void
335   check_conf_klines(void)
336 < {              
336 > {
337    struct Client *client_p = NULL;       /* current local client_p being examined */
338 <  struct AccessItem *aconf = NULL;
355 <  struct ConfItem *conf = NULL;
338 >  struct MaskItem *conf = NULL;
339    dlink_node *ptr, *next_ptr;
340  
341    DLINK_FOREACH_SAFE(ptr, next_ptr, local_client_list.head)
# Line 364 | Line 347 | check_conf_klines(void)
347      if (IsDead(client_p) || !IsClient(client_p))
348        continue;
349  
350 <    /* if there is a returned struct ConfItem then kill it */
351 <    if ((aconf = find_dline_conf(&client_p->localClient->ip,
369 <                                  client_p->localClient->aftype)) != NULL)
350 >    if ((conf = find_dline_conf(&client_p->localClient->ip,
351 >                                  client_p->localClient->aftype)))
352      {
353 <      if (aconf->status & CONF_EXEMPTDLINE)
354 <        continue;
353 >      if (conf->type == CONF_EXEMPT)
354 >        continue;
355  
356 <      conf = unmap_conf_item(aconf);
375 <      ban_them(client_p, conf);
356 >      conf_try_ban(client_p, conf);
357        continue; /* and go examine next fd/client_p */
358      }
359  
360 <    if (ConfigFileEntry.glines && (aconf = find_gline(client_p)))
360 >    if (ConfigFileEntry.glines)
361      {
362 <      if (IsExemptKline(client_p) ||
363 <          IsExemptGline(client_p))
362 >      if ((conf = find_conf_by_address(client_p->host, &client_p->localClient->ip,
363 >                                       CONF_GLINE, client_p->localClient->aftype,
364 >                                       client_p->username, NULL, 1)))
365        {
366 <        sendto_realops_flags(UMODE_ALL, L_ALL,
367 <                             "GLINE over-ruled for %s, client is %sline_exempt",
386 <                             get_client_name(client_p, HIDE_IP), IsExemptKline(client_p) ? "k" : "g");
366 >        conf_try_ban(client_p, conf);
367 >        /* and go examine next fd/client_p */
368          continue;
369        }
370 +    }
371  
372 <      conf = unmap_conf_item(aconf);
373 <      ban_them(client_p, conf);
374 <      /* and go examine next fd/client_p */    
393 <      continue;
394 <    }
395 <
396 <    if ((aconf = find_kill(client_p)) != NULL)
372 >    if ((conf = find_conf_by_address(client_p->host, &client_p->localClient->ip,
373 >                                     CONF_KLINE, client_p->localClient->aftype,
374 >                                     client_p->username, NULL, 1)))
375      {
376 <
377 <      /* if there is a returned struct AccessItem.. then kill it */
400 <      if (IsExemptKline(client_p))
401 <      {
402 <        sendto_realops_flags(UMODE_ALL, L_ALL,
403 <                             "KLINE over-ruled for %s, client is kline_exempt",
404 <                             get_client_name(client_p, HIDE_IP));
405 <        continue;
406 <      }
407 <
408 <      conf = unmap_conf_item(aconf);
409 <      ban_them(client_p, conf);
410 <      continue;
376 >      conf_try_ban(client_p, conf);
377 >      continue;
378      }
379  
380 <    /* if there is a returned struct MatchItem then kill it */
381 <    if ((conf = find_matching_name_conf(XLINE_TYPE,  client_p->info,
415 <                                        NULL, NULL, 0)) != NULL ||
416 <        (conf = find_matching_name_conf(RXLINE_TYPE, client_p->info,
417 <                                        NULL, NULL, 0)) != NULL)
380 >    if ((conf = find_matching_name_conf(CONF_XLINE,  client_p->info,
381 >                                        NULL, NULL, 0)))
382      {
383 <      ban_them(client_p, conf);
383 >      conf_try_ban(client_p, conf);
384        continue;
385      }
386    }
# Line 426 | Line 390 | check_conf_klines(void)
390    {
391      client_p = ptr->data;
392  
393 <    if ((aconf = find_dline_conf(&client_p->localClient->ip,
394 <                                  client_p->localClient->aftype)))
393 >    if ((conf = find_dline_conf(&client_p->localClient->ip,
394 >                                 client_p->localClient->aftype)))
395      {
396 <      if (aconf->status & CONF_EXEMPTDLINE)
396 >      if (conf->type == CONF_EXEMPT)
397          continue;
398  
399 <      exit_client(client_p, &me, "D-lined");
399 >      exit_client(client_p, "D-lined");
400      }
401    }
402   }
403  
404   /*
405 < * ban_them
405 > * conf_try_ban
406   *
407   * inputs       - pointer to client to ban
408 < *              - pointer to ConfItem
408 > *              - pointer to MaskItem
409   * output       - NONE
410   * side effects - given client_p is banned
411   */
412 < static void
413 < ban_them(struct Client *client_p, struct ConfItem *conf)
412 > void
413 > conf_try_ban(struct Client *client_p, struct MaskItem *conf)
414   {
415 <  const char *user_reason = NULL;       /* What is sent to user */
452 <  struct AccessItem *aconf = NULL;
453 <  struct MatchItem *xconf = NULL;
415 >  const char *user_reason = NULL;  /* What is sent to user */
416    const char *type_string = NULL;
417    const char dline_string[] = "D-line";
418    const char kline_string[] = "K-line";
# Line 459 | Line 421 | ban_them(struct Client *client_p, struct
421  
422    switch (conf->type)
423    {
424 <    case RKLINE_TYPE:
425 <    case KLINE_TYPE:
424 >    case CONF_KLINE:
425 >      if (IsExemptKline(client_p))
426 >      {
427 >        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
428 >                             "KLINE over-ruled for %s, client is kline_exempt",
429 >                             get_client_name(client_p, HIDE_IP));
430 >        return;
431 >      }
432 >
433        type_string = kline_string;
465      aconf = map_to_conf(conf);
434        break;
435 <    case DLINE_TYPE:
435 >    case CONF_DLINE:
436        type_string = dline_string;
469      aconf = map_to_conf(conf);
437        break;
438 <    case GLINE_TYPE:
438 >    case CONF_GLINE:
439 >      if (IsExemptKline(client_p) ||
440 >          IsExemptGline(client_p))
441 >      {
442 >        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
443 >                             "GLINE over-ruled for %s, client is %sline_exempt",
444 >                             get_client_name(client_p, HIDE_IP), IsExemptKline(client_p) ? "k" : "g");
445 >        return;
446 >      }
447 >
448        type_string = gline_string;
473      aconf = map_to_conf(conf);
449        break;
450 <    case RXLINE_TYPE:
476 <    case XLINE_TYPE:
450 >    case CONF_XLINE:
451        type_string = xline_string;
452 <      xconf = map_to_conf(conf);
479 <      ++xconf->count;
452 >      ++conf->count;
453        break;
454      default:
455        assert(0);
456        break;
457    }
458  
459 <  if (aconf != NULL)
487 <    user_reason = aconf->reason ? aconf->reason : type_string;
488 <  if (xconf != NULL)
489 <    user_reason = xconf->reason ? xconf->reason : type_string;
459 >  user_reason = conf->reason ? conf->reason : type_string;
460  
461 <  sendto_realops_flags(UMODE_ALL, L_ALL, "%s active for %s",
461 >  sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, "%s active for %s",
462                         type_string, get_client_name(client_p, HIDE_IP));
463  
464    if (IsClient(client_p))
465 <    sendto_one(client_p, form_str(ERR_YOUREBANNEDCREEP),
496 <               me.name, client_p->name, user_reason);
465 >    sendto_one_numeric(client_p, &me, ERR_YOUREBANNEDCREEP, user_reason);
466  
467 <  exit_client(client_p, &me, user_reason);
467 >  exit_client(client_p, user_reason);
468   }
469  
470   /* update_client_exit_stats()
471   *
472   * input        - pointer to client
473   * output       - NONE
474 < * side effects -
474 > * side effects -
475   */
476   static void
477   update_client_exit_stats(struct Client *client_p)
# Line 517 | Line 486 | update_client_exit_stats(struct Client *
486        --Count.invisi;
487    }
488    else if (IsServer(client_p))
489 <    sendto_realops_flags(UMODE_EXTERNAL, L_ALL, "Server %s split from %s",
489 >    sendto_realops_flags(UMODE_EXTERNAL, L_ALL, SEND_NOTICE,
490 >                         "Server %s split from %s",
491                           client_p->name, client_p->servptr->name);
492  
493    if (splitchecking && !splitmode)
# Line 531 | Line 501 | update_client_exit_stats(struct Client *
501   * side effects - find person by (nick)name
502   */
503   struct Client *
504 < find_person(const struct Client *client_p, const char *name)
504 > find_person(const struct Client *const source_p, const char *name)
505   {
506 <  struct Client *c2ptr;
506 >  struct Client *target_p = NULL;
507  
508    if (IsDigit(*name))
509    {
510 <    if ((c2ptr = hash_find_id(name)) != NULL)
511 <    {
542 <      /* invisible users shall not be found by UID guessing */
543 <      if (HasUMode(c2ptr, UMODE_INVISIBLE) && !IsServer(client_p))
544 <        c2ptr = NULL;
545 <    }
510 >    if (IsServer(source_p->from))
511 >      target_p = hash_find_id(name);
512    }
513    else
514 <    c2ptr = hash_find_client(name);
514 >    target_p = hash_find_client(name);
515  
516 <  return ((c2ptr != NULL && IsClient(c2ptr)) ? c2ptr : NULL);
516 >  return (target_p && IsClient(target_p)) ? target_p : NULL;
517   }
518  
519   /*
520 < * find_chasing - find the client structure for a nick name (user)
521 < *      using history mechanism if necessary. If the client is not found,
522 < *      an error message (NO SUCH NICK) is generated. If the client was found
557 < *      through the history, chasing will be 1 and otherwise 0.
520 > * find_chasing - find the client structure for a nick name (name)
521 > *      using history mechanism if necessary. If the client is not found,
522 > *      an error message (NO SUCH NICK) is generated.
523   */
524   struct Client *
525 < find_chasing(struct Client *client_p, struct Client *source_p, const char *user, int *chasing)
525 > find_chasing(struct Client *source_p, const char *name)
526   {
527 <  struct Client *who = find_person(client_p, user);
563 <
564 <  if (chasing)
565 <    *chasing = 0;
527 >  struct Client *who = find_person(source_p, name);
528  
529    if (who)
530      return who;
531  
532 <  if (IsDigit(*user))
532 >  if (IsDigit(*name))
533      return NULL;
534  
535 <  if ((who = get_history(user,
536 <                        (time_t)ConfigFileEntry.kill_chase_time_limit))
537 <                         == NULL)
535 >  if ((who = whowas_get_history(name,
536 >                         (time_t)ConfigFileEntry.kill_chase_time_limit))
537 >                         == NULL)
538    {
539 <    sendto_one(source_p, form_str(ERR_NOSUCHNICK),
578 <               me.name, source_p->name, user);
539 >    sendto_one_numeric(source_p, &me, ERR_NOSUCHNICK, name);
540      return NULL;
541    }
542  
582  if (chasing)
583    *chasing = 1;
584
543    return who;
544   }
545  
# Line 604 | Line 562 | find_chasing(struct Client *client_p, st
562   *        to modify what it points!!!
563   */
564   const char *
565 < get_client_name(const struct Client *client, enum addr_mask_type type)
565 > get_client_name(const struct Client *client_p, enum addr_mask_type type)
566   {
567    static char nbuf[HOSTLEN * 2 + USERLEN + 5];
568  
569 <  assert(client != NULL);
569 >  assert(client_p);
570  
571 <  if (!MyConnect(client))
572 <    return client->name;
571 >  if (!MyConnect(client_p))
572 >    return client_p->name;
573  
574 <  if (IsServer(client) || IsConnecting(client) || IsHandshake(client))
574 >  if (IsServer(client_p) || IsConnecting(client_p) || IsHandshake(client_p))
575    {
576 <    if (!irccmp(client->name, client->host))
577 <      return client->name;
576 >    if (!irccmp(client_p->name, client_p->host))
577 >      return client_p->name;
578      else if (ConfigServerHide.hide_server_ips)
579        type = MASK_IP;
580    }
581  
582    if (ConfigFileEntry.hide_spoof_ips)
583 <    if (type == SHOW_IP && IsIPSpoof(client))
583 >    if (type == SHOW_IP && IsIPSpoof(client_p))
584        type = MASK_IP;
585  
586    /* And finally, let's get the host information, ip or name */
# Line 630 | Line 588 | get_client_name(const struct Client *cli
588    {
589      case SHOW_IP:
590        snprintf(nbuf, sizeof(nbuf), "%s[%s@%s]",
591 <               client->name,
592 <               client->username, client->sockhost);
591 >               client_p->name,
592 >               client_p->username, client_p->sockhost);
593        break;
594      case MASK_IP:
595 <      if (client->localClient->aftype == AF_INET)
595 >      if (client_p->localClient->aftype == AF_INET)
596          snprintf(nbuf, sizeof(nbuf), "%s[%s@255.255.255.255]",
597 <                 client->name, client->username);
597 >                 client_p->name, client_p->username);
598        else
599          snprintf(nbuf, sizeof(nbuf), "%s[%s@ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff]",
600 <                 client->name, client->username);
600 >                 client_p->name, client_p->username);
601        break;
602      default:
603        snprintf(nbuf, sizeof(nbuf), "%s[%s@%s]",
604 <               client->name,
605 <               client->username, client->host);
604 >               client_p->name,
605 >               client_p->username, client_p->host);
606    }
607  
608    return nbuf;
# Line 654 | Line 612 | void
612   free_exited_clients(void)
613   {
614    dlink_node *ptr = NULL, *next = NULL;
615 <  
615 >
616    DLINK_FOREACH_SAFE(ptr, next, dead_list.head)
617    {
618      free_client(ptr->data);
# Line 672 | Line 630 | free_exited_clients(void)
630   static void
631   exit_one_client(struct Client *source_p, const char *quitmsg)
632   {
633 <  dlink_node *lp = NULL, *next_lp = NULL;
633 >  dlink_node *ptr = NULL, *ptr_next = NULL;
634  
635    assert(!IsMe(source_p));
636  
637    if (IsClient(source_p))
638    {
639 <    if (source_p->servptr->serv != NULL)
682 <      dlinkDelete(&source_p->lnode, &source_p->servptr->serv->client_list);
639 >    dlinkDelete(&source_p->lnode, &source_p->servptr->serv->client_list);
640  
641      /*
642       * If a person is on a channel, send a QUIT notice
# Line 687 | Line 644 | exit_one_client(struct Client *source_p,
644       * that the client can show the "**signoff" message).
645       * (Note: The notice is to the local clients *only*)
646       */
647 <    sendto_common_channels_local(source_p, 0, ":%s!%s@%s QUIT :%s",
647 >    sendto_common_channels_local(source_p, 0, 0, ":%s!%s@%s QUIT :%s",
648                                   source_p->name, source_p->username,
649                                   source_p->host, quitmsg);
650 <    DLINK_FOREACH_SAFE(lp, next_lp, source_p->channel.head)
651 <      remove_user_from_channel(lp->data);
650 >    DLINK_FOREACH_SAFE(ptr, ptr_next, source_p->channel.head)
651 >      remove_user_from_channel(ptr->data);
652  
653 <    add_history(source_p, 0);
654 <    off_history(source_p);
653 >    whowas_add_history(source_p, 0);
654 >    whowas_off_history(source_p);
655  
656      watch_check_hash(source_p, RPL_LOGOFF);
657  
658      if (MyConnect(source_p))
659      {
660        /* Clean up invitefield */
661 <      DLINK_FOREACH_SAFE(lp, next_lp, source_p->localClient->invited.head)
662 <        del_invite(lp->data, source_p);
661 >      DLINK_FOREACH_SAFE(ptr, ptr_next, source_p->localClient->invited.head)
662 >        del_invite(ptr->data, source_p);
663  
664        del_all_accepts(source_p);
665      }
# Line 711 | Line 668 | exit_one_client(struct Client *source_p,
668    {
669      dlinkDelete(&source_p->lnode, &source_p->servptr->serv->server_list);
670  
671 <    if ((lp = dlinkFindDelete(&global_serv_list, source_p)) != NULL)
672 <      free_dlink_node(lp);
671 >    if ((ptr = dlinkFindDelete(&global_serv_list, source_p)))
672 >      free_dlink_node(ptr);
673    }
674  
675    /* Remove source_p from the client lists */
676 <  if (HasID(source_p))
676 >  if (source_p->id[0])
677      hash_del_id(source_p);
678    if (source_p->name[0])
679      hash_del_client(source_p);
# Line 728 | Line 685 | exit_one_client(struct Client *source_p,
685     * NOTE: source_p->node.next cannot be NULL if the client is added
686     *       to global_client_list (there is always &me at its end)
687     */
688 <  if (source_p != NULL && source_p->node.next != NULL)
688 >  if (source_p->node.next) /* XXX: not needed? */
689      dlinkDelete(&source_p->node, &global_client_list);
690  
691    update_client_exit_stats(source_p);
# Line 741 | Line 698 | exit_one_client(struct Client *source_p,
698    dlinkAdd(source_p, make_dlink_node(), &dead_list);
699   }
700  
701 < /* Recursively send QUITs and SQUITs for source_p and all its dependent clients
745 < * and servers to those servers that need them.  A server needs the client
746 < * QUITs if it can't figure them out from the SQUIT (ie pre-TS4) or if it
747 < * isn't getting the SQUIT because of @#(*&@)# hostmasking.  With TS4, once
748 < * a link gets a SQUIT, it doesn't need any QUIT/SQUITs for clients depending
749 < * on that one -orabidoo
750 < *
751 < * This is now called on each local server -adx
752 < */
753 < static void
754 < recurse_send_quits(struct Client *original_source_p, struct Client *source_p,
755 <                   struct Client *from, struct Client *to, const char *comment,
756 <                   const char *splitstr)
757 < {
758 <  dlink_node *ptr, *next;
759 <  struct Client *target_p;
760 <
761 <  assert(to != source_p);  /* should be already removed from serv_list */
762 <
763 <  /* If this server can handle quit storm (QS) removal
764 <   * of dependents, just send the SQUIT
765 <   */
766 <  if (!IsCapable(to, CAP_QS))
767 <    DLINK_FOREACH_SAFE(ptr, next, source_p->serv->client_list.head)
768 <    {
769 <      target_p = ptr->data;
770 <      sendto_one(to, ":%s QUIT :%s", target_p->name, splitstr);
771 <    }
772 <
773 <  DLINK_FOREACH_SAFE(ptr, next, source_p->serv->server_list.head)
774 <    recurse_send_quits(original_source_p, ptr->data, from, to,
775 <                       comment, splitstr);
776 <
777 <  if ((source_p == original_source_p && to != from) ||
778 <                  !IsCapable(to, CAP_QS))
779 <  {
780 <    /* don't use a prefix here - we have to be 100% sure the message
781 <     * will be accepted without Unknown prefix etc.. */
782 <    sendto_one(to, "SQUIT %s :%s", ID_or_name(source_p, to), comment);
783 <  }
784 < }
785 <
786 < /*
701 > /*
702   * Remove all clients that depend on source_p; assumes all (S)QUITs have
703 < * already been sent.  we make sure to exit a server's dependent clients
704 < * and servers before the server itself; exit_one_client takes care of
703 > * already been sent.  we make sure to exit a server's dependent clients
704 > * and servers before the server itself; exit_one_client takes care of
705   * actually removing things off llists.   tweaked from +CSr31  -orabidoo
706   */
707   static void
708   recurse_remove_clients(struct Client *source_p, const char *quitmsg)
709   {
710 <  dlink_node *ptr, *next;
710 >  dlink_node *ptr = NULL, *ptr_next = NULL;
711  
712 <  DLINK_FOREACH_SAFE(ptr, next, source_p->serv->client_list.head)
712 >  DLINK_FOREACH_SAFE(ptr, ptr_next, source_p->serv->client_list.head)
713      exit_one_client(ptr->data, quitmsg);
714  
715 <  DLINK_FOREACH_SAFE(ptr, next, source_p->serv->server_list.head)
715 >  DLINK_FOREACH_SAFE(ptr, ptr_next, source_p->serv->server_list.head)
716    {
717      recurse_remove_clients(ptr->data, quitmsg);
718      exit_one_client(ptr->data, quitmsg);
# Line 805 | Line 720 | recurse_remove_clients(struct Client *so
720   }
721  
722   /*
808 ** Remove *everything* that depends on source_p, from all lists, and sending
809 ** all necessary QUITs and SQUITs.  source_p itself is still on the lists,
810 ** and its SQUITs have been sent except for the upstream one  -orabidoo
811 */
812 static void
813 remove_dependents(struct Client *source_p, struct Client *from,
814                  const char *comment, const char *splitstr)
815 {
816  dlink_node *ptr = NULL;
817
818  DLINK_FOREACH(ptr, serv_list.head)
819    recurse_send_quits(source_p, source_p, from, ptr->data,
820                       comment, splitstr);
821
822  recurse_remove_clients(source_p, splitstr);
823 }
824
825 /*
723   * exit_client - exit a client of any type. Generally, you can use
724   * this on any struct Client, regardless of its state.
725   *
726   * Note, you shouldn't exit remote _users_ without first doing
727   * AddFlag(x, FLAGS_KILLED) and propagating a kill or similar message.
728 + *
729   * However, it is perfectly correct to call exit_client to force a _server_
730   * quit (either local or remote one).
731   *
732 + *
733   * inputs:       - a client pointer that is going to be exited
835 *               - for servers, the second argument is a pointer to who
836 *                 is firing the server. This side won't get any generated
837 *                 messages. NEVER NULL!
734   * output:       none
735   * side effects: the client is delinked from all lists, disconnected,
736   *               and the rest of IRC network is notified of the exit.
737   *               Client memory is scheduled to be freed
738   */
739   void
740 < exit_client(struct Client *source_p, struct Client *from, const char *comment)
740 > exit_client(struct Client *source_p, const char *comment)
741   {
742    dlink_node *m = NULL;
743  
# Line 858 | Line 754 | exit_client(struct Client *source_p, str
754      if (IsIpHash(source_p))
755        remove_one_ip(&source_p->localClient->ip);
756  
757 <    if (source_p->localClient->auth)
862 <    {
863 <      delete_auth(source_p->localClient->auth);
864 <      source_p->localClient->auth = NULL;
865 <    }
757 >    delete_auth(&source_p->localClient->auth);
758  
759 <    /* This source_p could have status of one of STAT_UNKNOWN, STAT_CONNECTING
759 >    /*
760 >     * This source_p could have status of one of STAT_UNKNOWN, STAT_CONNECTING
761       * STAT_HANDSHAKE or STAT_UNKNOWN
762       * all of which are lumped together into unknown_list
763       *
# Line 883 | Line 776 | exit_client(struct Client *source_p, str
776        Count.local--;
777  
778        if (HasUMode(source_p, UMODE_OPER))
779 <      {
887 <        if ((m = dlinkFindDelete(&oper_list, source_p)) != NULL)
779 >        if ((m = dlinkFindDelete(&oper_list, source_p)))
780            free_dlink_node(m);
889      }
781  
782        assert(dlinkFind(&local_client_list, source_p));
783        dlinkDelete(&source_p->localClient->lclient_node, &local_client_list);
784  
785 <      if (source_p->localClient->list_task != NULL)
786 <        free_list_task(source_p->localClient->list_task, source_p);
785 >      if (source_p->localClient->list_task)
786 >        free_list_task(source_p);
787  
788        watch_del_watch_list(source_p);
789 <      sendto_realops_flags(UMODE_CCONN, L_ALL, "Client exiting: %s (%s@%s) [%s] [%s]",
789 >      sendto_realops_flags(UMODE_CCONN, L_ALL, SEND_NOTICE,
790 >                           "Client exiting: %s (%s@%s) [%s] [%s]",
791                             source_p->name, source_p->username, source_p->host, comment,
792                             ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
793                             "255.255.255.255" : source_p->sockhost);
902      sendto_realops_flags(UMODE_CCONN_FULL, L_ALL, "CLIEXIT: %s %s %s %s 0 %s",
903                           source_p->name,
904                           source_p->username,
905                           source_p->host,
906                           ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
907                           "255.255.255.255" : source_p->sockhost,
908                           comment);
794        ilog(LOG_TYPE_USER, "%s (%3u:%02u:%02u): %s!%s@%s %llu/%llu",
795             myctime(source_p->localClient->firsttime), (unsigned int)(on_for / 3600),
796             (unsigned int)((on_for % 3600)/60), (unsigned int)(on_for % 60),
# Line 913 | Line 798 | exit_client(struct Client *source_p, str
798             source_p->localClient->send.bytes>>10,
799             source_p->localClient->recv.bytes>>10);
800      }
801 <
917 <    /* As soon as a client is known to be a server of some sort
918 <     * it has to be put on the serv_list, or SJOIN's to this new server
919 <     * from the connect burst will not be seen.
920 <     * XXX - TBV.  This is not true. The only place where we put a server on
921 <     * serv_list is in server_estab right now after registration process.
922 <     * And only after this, a burst is sent to the remote server, i.e. we never
923 <     * send a burst to STAT_CONNECTING, or STAT_HANDSHAKE. This will need
924 <     * more investigation later on, but for now, it's not a problem after all.
925 <     */
926 <    if (IsServer(source_p) || IsConnecting(source_p) ||
927 <        IsHandshake(source_p))
801 >    else if (IsServer(source_p))
802      {
803 <      if (dlinkFind(&serv_list, source_p))
804 <      {
931 <        dlinkDelete(&source_p->localClient->lclient_node, &serv_list);
932 <        unset_chcap_usage_counts(source_p);
933 <      }
803 >      assert(Count.myserver > 0);
804 >      --Count.myserver;
805  
806 <      if (IsServer(source_p))
807 <        Count.myserver--;
806 >      assert(dlinkFind(&serv_list, source_p));
807 >      dlinkDelete(&source_p->localClient->lclient_node, &serv_list);
808      }
809  
810      if (!IsDead(source_p))
811      {
812        if (IsServer(source_p))
813        {
814 <        /* for them, we are exiting the network */
815 <        sendto_one(source_p, ":%s SQUIT %s :%s",
816 <                   ID_or_name(from, source_p), me.name, comment);
814 >        if (!HasFlag(source_p, FLAGS_SQUIT))
815 >        {
816 >          /* for them, we are exiting the network */
817 >          sendto_one(source_p, ":%s SQUIT %s :%s",
818 >                     me.id, me.id, comment);
819 >        }
820        }
821  
822        sendto_one(source_p, "ERROR :Closing Link: %s (%s)",
823                   source_p->host, comment);
824      }
825  
952    /*
953    ** Currently only server connections can have
954    ** depending remote clients here, but it does no
955    ** harm to check for all local clients. In
956    ** future some other clients than servers might
957    ** have remotes too...
958    **
959    ** Close the Client connection first and mark it
960    ** so that no messages are attempted to send to it.
961    ** Remember it makes source_p->from == NULL.
962    */
826      close_connection(source_p);
827    }
828 +  else if (IsClient(source_p) && HasFlag(source_p->servptr, FLAGS_EOB))
829 +    sendto_realops_flags(UMODE_FARCONNECT, L_ALL, SEND_NOTICE,
830 +                         "Client exiting at %s: %s (%s@%s) [%s]",
831 +                         source_p->servptr->name, source_p->name,
832 +                         source_p->username, source_p->host, comment);
833  
834    if (IsServer(source_p))
835    {
836 <    char splitstr[HOSTLEN + HOSTLEN + 2];
836 >    char splitstr[HOSTLEN + HOSTLEN + 2] = "";
837  
838      /* This shouldn't ever happen */
839 <    assert(source_p->serv != NULL && source_p->servptr != NULL);
839 >    assert(source_p->serv && source_p->servptr);
840  
841      if (ConfigServerHide.hide_servers)
842        /*
843 <       * Set netsplit message to "*.net *.split" to still show
843 >       * Set netsplit message to "*.net *.split" to still show
844         * that its a split, but hide the servers splitting
845         */
846 <      strcpy(splitstr, "*.net *.split");
846 >      strlcpy(splitstr, "*.net *.split", sizeof(splitstr));
847      else
848        snprintf(splitstr, sizeof(splitstr), "%s %s",
849                 source_p->servptr->name, source_p->name);
850  
851 <    remove_dependents(source_p, from->from, comment, splitstr);
851 >    /* Send SQUIT for source_p in every direction. source_p is already off of serv_list here */
852 >    if (!HasFlag(source_p, FLAGS_SQUIT))
853 >      sendto_server(NULL, NOCAPS, NOCAPS, "SQUIT %s :%s", source_p->id, comment);
854 >
855 >    /* Now exit the clients internally */
856 >    recurse_remove_clients(source_p, splitstr);
857  
858 <    if (source_p->servptr == &me)
858 >    if (MyConnect(source_p))
859      {
860 <      sendto_realops_flags(UMODE_ALL, L_ALL,
860 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
861                             "%s was connected for %d seconds.  %llu/%llu sendK/recvK.",
862                             source_p->name, (int)(CurrentTime - source_p->localClient->firsttime),
863                             source_p->localClient->send.bytes >> 10,
864                             source_p->localClient->recv.bytes >> 10);
865        ilog(LOG_TYPE_IRCD, "%s was connected for %d seconds.  %llu/%llu sendK/recvK.",
866 <           source_p->name, (int)(CurrentTime - source_p->localClient->firsttime),
866 >           source_p->name, (int)(CurrentTime - source_p->localClient->firsttime),
867             source_p->localClient->send.bytes >> 10,
868             source_p->localClient->recv.bytes >> 10);
869      }
870    }
871    else if (IsClient(source_p) && !HasFlag(source_p, FLAGS_KILLED))
872 <  {
873 <    sendto_server(from->from, CAP_TS6, NOCAPS,
1001 <                  ":%s QUIT :%s", ID(source_p), comment);
1002 <    sendto_server(from->from, NOCAPS, CAP_TS6,
1003 <                  ":%s QUIT :%s", source_p->name, comment);
1004 <  }
872 >    sendto_server(source_p->from, NOCAPS, NOCAPS, ":%s QUIT :%s",
873 >                  source_p->id, comment);
874  
875    /* The client *better* be off all of the lists */
876    assert(dlinkFind(&unknown_list, source_p) == NULL);
# Line 1045 | Line 914 | dead_link_on_write(struct Client *client
914   void
915   dead_link_on_read(struct Client *client_p, int error)
916   {
917 <  char errmsg[255];
917 >  char errmsg[IRCD_BUFSIZE];
918    int current_error;
919  
920    if (IsDefunct(client_p))
# Line 1059 | Line 928 | dead_link_on_read(struct Client *client_
928    if (IsServer(client_p) || IsHandshake(client_p))
929    {
930      int connected = CurrentTime - client_p->localClient->firsttime;
931 <      
931 >
932      if (error == 0)
933      {
934        /* Admins get the real IP */
935 <      sendto_realops_flags(UMODE_ALL, L_ADMIN,
936 <                           "Server %s closed the connection",
937 <                           get_client_name(client_p, SHOW_IP));
935 >      sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
936 >                           "Server %s closed the connection",
937 >                           get_client_name(client_p, SHOW_IP));
938  
939        /* Opers get a masked IP */
940 <      sendto_realops_flags(UMODE_ALL, L_OPER,
941 <                           "Server %s closed the connection",
942 <                           get_client_name(client_p, MASK_IP));
940 >      sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
941 >                           "Server %s closed the connection",
942 >                           get_client_name(client_p, MASK_IP));
943  
944        ilog(LOG_TYPE_IRCD, "Server %s closed the connection",
945 <           get_client_name(client_p, SHOW_IP));
945 >           get_client_name(client_p, SHOW_IP));
946      }
947      else
948      {
949        report_error(L_ADMIN, "Lost connection to %s: %s",
950 <                   get_client_name(client_p, SHOW_IP), current_error);
950 >                   get_client_name(client_p, SHOW_IP), current_error);
951        report_error(L_OPER, "Lost connection to %s: %s",
952 <                   get_client_name(client_p, MASK_IP), current_error);
952 >                   get_client_name(client_p, MASK_IP), current_error);
953      }
954  
955 <    sendto_realops_flags(UMODE_ALL, L_ALL,
956 <                         "%s had been connected for %d day%s, %2d:%02d:%02d",
957 <                         client_p->name, connected/86400,
958 <                         (connected/86400 == 1) ? "" : "s",
959 <                         (connected % 86400) / 3600, (connected % 3600) / 60,
960 <                         connected % 60);
955 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
956 >                         "%s had been connected for %d day%s, %2d:%02d:%02d",
957 >                         client_p->name, connected/86400,
958 >                         (connected/86400 == 1) ? "" : "s",
959 >                         (connected % 86400) / 3600, (connected % 3600) / 60,
960 >                         connected % 60);
961    }
962  
963    if (error == 0)
# Line 1098 | Line 967 | dead_link_on_read(struct Client *client_
967      snprintf(errmsg, sizeof(errmsg), "Read error: %s",
968               strerror(current_error));
969  
970 <  exit_client(client_p, &me, errmsg);
970 >  exit_client(client_p, errmsg);
971   }
972  
973   void
# Line 1115 | Line 984 | exit_aborted_clients(void)
984  
985      if (target_p == NULL)
986      {
987 <      sendto_realops_flags(UMODE_ALL, L_ALL,
987 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
988                             "Warning: null client on abort_list!");
989        dlinkDelete(ptr, &abort_list);
990        free_dlink_node(ptr);
# Line 1129 | Line 998 | exit_aborted_clients(void)
998      else
999        notice = "Write error: connection closed";
1000  
1001 <    exit_client(target_p, &me, notice);  
1001 >    exit_client(target_p, notice);
1002      free_dlink_node(ptr);
1003    }
1004   }
# Line 1157 | Line 1026 | del_accept(struct split_nuh_item *accept
1026  
1027   struct split_nuh_item *
1028   find_accept(const char *nick, const char *user,
1029 <            const char *host, struct Client *client_p, int do_match)
1029 >            const char *host, struct Client *client_p,
1030 >            int (*cmpfunc)(const char *, const char *))
1031   {
1032    dlink_node *ptr = NULL;
1163  /* XXX We wouldn't need that if match() would return 0 on match */
1164  int (*cmpfunc)(const char *, const char *) = do_match ? match : irccmp;
1033  
1034    DLINK_FOREACH(ptr, client_p->localClient->acceptlist.head)
1035    {
1036      struct split_nuh_item *accept_p = ptr->data;
1037  
1038 <    if (cmpfunc(accept_p->nickptr, nick) == do_match &&
1039 <        cmpfunc(accept_p->userptr, user) == do_match &&
1040 <        cmpfunc(accept_p->hostptr, host) == do_match)
1038 >    if (!cmpfunc(accept_p->nickptr, nick) &&
1039 >        !cmpfunc(accept_p->userptr, user) &&
1040 >        !cmpfunc(accept_p->hostptr, host))
1041        return accept_p;
1042    }
1043  
# Line 1190 | Line 1058 | accept_message(struct Client *source,
1058    dlink_node *ptr = NULL;
1059  
1060    if (source == target || find_accept(source->name, source->username,
1061 <                                      source->host, target, 1))
1061 >                                      source->host, target, match))
1062      return 1;
1063  
1064    if (HasUMode(target, UMODE_SOFTCALLERID))
# Line 1210 | Line 1078 | accept_message(struct Client *source,
1078   void
1079   del_all_accepts(struct Client *client_p)
1080   {
1081 <  dlink_node *ptr = NULL, *next_ptr = NULL;
1081 >  dlink_node *ptr = NULL, *ptr_next = NULL;
1082  
1083 <  DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->localClient->acceptlist.head)
1083 >  DLINK_FOREACH_SAFE(ptr, ptr_next, client_p->localClient->acceptlist.head)
1084      del_accept(ptr->data, client_p);
1085   }
1086 +
1087 + unsigned int
1088 + idle_time_get(const struct Client *source_p, const struct Client *target_p)
1089 + {
1090 +  unsigned int idle = 0;
1091 +  unsigned int min_idle = 0;
1092 +  unsigned int max_idle = 0;
1093 +  const struct ClassItem *class = get_class_ptr(&target_p->localClient->confs);
1094 +
1095 +  if (!(class->flags & CLASS_FLAGS_FAKE_IDLE) || target_p == source_p)
1096 +    return CurrentTime - target_p->localClient->last_privmsg;
1097 +  if (HasUMode(source_p, UMODE_OPER) &&
1098 +      !(class->flags & CLASS_FLAGS_HIDE_IDLE_FROM_OPERS))
1099 +    return CurrentTime - target_p->localClient->last_privmsg;
1100 +
1101 +  min_idle = class->min_idle;
1102 +  max_idle = class->max_idle;
1103 +
1104 +  if (min_idle == max_idle)
1105 +    return min_idle;
1106 +
1107 +  if (class->flags & CLASS_FLAGS_RANDOM_IDLE)
1108 +    idle = genrand_int32();
1109 +  else
1110 +    idle = CurrentTime - target_p->localClient->last_privmsg;
1111 +
1112 +  if (!max_idle)
1113 +    idle = 0;
1114 +  else
1115 +    idle %= max_idle;
1116 +
1117 +  if (idle < min_idle)
1118 +    idle = min_idle + (idle % (max_idle - min_idle));
1119 +
1120 +  return idle;
1121 + }

Diff Legend

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