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 1176 by michael, Sun Aug 14 11:24:24 2011 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"
29 #include "common.h"
30   #include "event.h"
31 #include "fdlist.h"
31   #include "hash.h"
32   #include "irc_string.h"
33   #include "ircd.h"
35 #include "s_gline.h"
34   #include "numeric.h"
35 < #include "packet.h"
38 < #include "s_auth.h"
35 > #include "auth.h"
36   #include "s_bsd.h"
37 < #include "s_conf.h"
38 < #include "s_log.h"
39 < #include "s_misc.h"
40 < #include "s_serv.h"
37 > #include "conf.h"
38 > #include "log.h"
39 > #include "misc.h"
40 > #include "server.h"
41   #include "send.h"
42   #include "whowas.h"
43 < #include "s_user.h"
47 < #include "dbuf.h"
43 > #include "user.h"
44   #include "memory.h"
45 + #include "mempool.h"
46   #include "hostmask.h"
50 #include "balloc.h"
47   #include "listener.h"
52 #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 65 | 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 75 | 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);
78 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 113 | 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 <  if (from == NULL)
114 >  memset(client_p, 0, sizeof(*client_p));
115 >
116 >  if (!from)
117    {
118 <    client_p->from  = client_p; /* 'from' of local client is self! */
119 <    client_p->since = client_p->lasttime = client_p->firsttime = CurrentTime;
118 >    client_p->from                      = client_p; /* 'from' of local client is self! */
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 = BlockHeapAlloc(lclient_heap);
123 >    client_p->localClient->since        = CurrentTime;
124 >    client_p->localClient->lasttime     = CurrentTime;
125 >    client_p->localClient->firsttime    = CurrentTime;
126      client_p->localClient->registration = REG_INIT;
127 +
128      /* as good a place as any... */
129      dlinkAdd(client_p, &client_p->localClient->lclient_node, &unknown_list);
130    }
131    else
132      client_p->from = from; /* 'from' of local client is self! */
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 145 | 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) || client_p->serv);
161  
154  MyFree(client_p->away);
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);
170      assert(IsClosing(client_p) && IsDead(client_p));
171  
172      MyFree(client_p->localClient->response);
# Line 170 | 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 189 | 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 211 | 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 221 | 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 */
232 <  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 242 | Line 250 | check_pings_list(dlink_list *list)
250      if (IsDead(client_p))
251      {
252        /* Ignore it, its been exited already */
245      continue;
246    }
247
248    if (client_p->localClient->reject_delay > 0)
249    {
250      if (client_p->localClient->reject_delay <= CurrentTime)
251        exit_client(client_p, &me, "Rejected");
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->lasttime)
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->lasttime = CurrentTime - ping;
272 <        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        {
276 <        if (CurrentTime - client_p->lasttime >= 2 * ping)
276 >        if (CurrentTime - client_p->localClient->lasttime >= 2 * ping)
277          {
278            /*
279             * If the client/server hasn't talked to us in 2*ping seconds
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(L_NOTICE, "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->lasttime));
296 <          exit_client(client_p, &me, scratch);
297 <        }
298 <        else if (!IsPingWarning(client_p) && pingwarn > 0 &&
299 <                 (IsServer(client_p) || IsHandshake(client_p)) &&
300 <                 CurrentTime - client_p->lasttime >= ping + pingwarn)
301 <        {
302 <          /*
303 <           * If the server hasn't replied in pingwarn seconds after sending
304 <           * the PING, notify the opers so that they are aware of the problem.
305 <           */
306 <          SetPingWarning(client_p);
307 <          sendto_realops_flags(UMODE_ALL, L_ADMIN,
308 <                               "Warning, no response from %s in %d seconds",
309 <                               get_client_name(client_p, HIDE_IP), pingwarn);
310 <          sendto_realops_flags(UMODE_ALL, L_OPER,
311 <                               "Warning, no response from %s in %d seconds",
312 <                               get_client_name(client_p, MASK_IP), pingwarn);
313 <          ilog(L_NOTICE, "No response from %s in %d seconds",
314 <               get_client_name(client_p, HIDE_IP), pingwarn);
295 >                   (int)(CurrentTime - client_p->localClient->lasttime));
296 >          exit_client(client_p, scratch);
297          }
298        }
299      }
# Line 327 | 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  
336    if (client_p->localClient->reject_delay > 0)
337    {
338      if (client_p->localClient->reject_delay <= CurrentTime)
339        exit_client(client_p, &me, "Rejected");
340      continue;
341    }
342
318      /*
319       * Check UNKNOWN connections - if they have been in this state
320       * for > 30s, close them.
321       */
322 <    if (IsAuthFinished(client_p) && (CurrentTime - client_p->firsttime) > 30)
323 <      exit_client(client_p, &me, "Registration timed out");
322 >    if (IsAuthFinished(client_p) && (CurrentTime - client_p->localClient->firsttime) > 30)
323 >      exit_client(client_p, "Registration timed out");
324    }
325   }
326  
# Line 356 | 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;
364 <  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 373 | 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,
378 <                                  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);
384 <      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",
395 <                             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 */    
402 <      continue;
403 <    }
404 <
405 <    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 */
409 <      if (IsExemptKline(client_p))
410 <      {
411 <        sendto_realops_flags(UMODE_ALL, L_ALL,
412 <                             "KLINE over-ruled for %s, client is kline_exempt",
413 <                             get_client_name(client_p, HIDE_IP));
414 <        continue;
415 <      }
416 <
417 <      conf = unmap_conf_item(aconf);
418 <      ban_them(client_p, conf);
419 <      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,
424 <                                        NULL, NULL, 0)) != NULL ||
425 <        (conf = find_matching_name_conf(RXLINE_TYPE, client_p->info,
426 <                                        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 435 | 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 */
461 <  const char *channel_reason = NULL;    /* What is sent to channel */
462 <  struct AccessItem *aconf = NULL;
463 <  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 469 | 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;
475      aconf = map_to_conf(conf);
434        break;
435 <    case DLINE_TYPE:
435 >    case CONF_DLINE:
436        type_string = dline_string;
479      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;
483      aconf = map_to_conf(conf);
449        break;
450 <    case RXLINE_TYPE:
486 <    case XLINE_TYPE:
450 >    case CONF_XLINE:
451        type_string = xline_string;
452 <      xconf = map_to_conf(conf);
489 <      ++xconf->count;
452 >      ++conf->count;
453        break;
454      default:
455        assert(0);
456        break;
457    }
458  
459 <  if (ConfigFileEntry.kline_with_reason)
497 <  {
498 <    if (aconf != NULL)
499 <      user_reason = aconf->reason ? aconf->reason : type_string;
500 <    if (xconf != NULL)
501 <      user_reason = xconf->reason ? xconf->reason : type_string;
502 <  }
503 <  else
504 <    user_reason = type_string;
505 <
506 <  if (ConfigFileEntry.kline_reason != NULL)
507 <    channel_reason = ConfigFileEntry.kline_reason;
508 <  else
509 <    channel_reason = user_reason;
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),
516 <               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, channel_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 531 | Line 480 | update_client_exit_stats(struct Client *
480    {
481      assert(Count.total > 0);
482      --Count.total;
483 <    if (IsOper(client_p))
483 >    if (HasUMode(client_p, UMODE_OPER))
484        --Count.oper;
485 <    if (IsInvisible(client_p))
485 >    if (HasUMode(client_p, UMODE_INVISIBLE))
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 550 | Line 500 | update_client_exit_stats(struct Client *
500   * output       - return client pointer
501   * side effects - find person by (nick)name
502   */
553 /* XXX - ugly wrapper */
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 <    {
563 <      /* invisible users shall not be found by UID guessing */
564 <      if (IsInvisible(c2ptr) && !IsServer(client_p))
565 <        c2ptr = NULL;
566 <    }
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
578 < *      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);
584 <
585 <  if (chasing)
586 <    *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),
599 <               me.name, source_p->name, user);
539 >    sendto_one_numeric(source_p, &me, ERR_NOSUCHNICK, name);
540      return NULL;
541    }
542  
603  if (chasing)
604    *chasing = 1;
605
543    return who;
544   }
545  
# Line 625 | 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, int showip)
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 (irccmp(client->name, client->host) == 0)
572 <    return client->name;
571 >  if (!MyConnect(client_p))
572 >    return client_p->name;
573  
574 <  if (ConfigServerHide.hide_server_ips)
575 <    if (IsServer(client) || IsConnecting(client) || IsHandshake(client))
576 <      showip = MASK_IP;
574 >  if (IsServer(client_p) || IsConnecting(client_p) || IsHandshake(client_p))
575 >  {
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 (showip == SHOW_IP && IsIPSpoof(client))
584 <      showip = MASK_IP;
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 */
587 <  switch (showip)
587 >  switch (type)
588    {
589      case SHOW_IP:
590 <      if (MyConnect(client))
591 <      {
592 <        snprintf(nbuf, sizeof(nbuf), "%s[%s@%s]",
593 <                 client->name,
653 <                 client->username, client->sockhost);
654 <        break;
655 <      }
590 >      snprintf(nbuf, sizeof(nbuf), "%s[%s@%s]",
591 >               client_p->name,
592 >               client_p->username, client_p->sockhost);
593 >      break;
594      case MASK_IP:
595 <      snprintf(nbuf, sizeof(nbuf), "%s[%s@255.255.255.255]",
596 <               client->name, client->username);
595 >      if (client_p->localClient->aftype == AF_INET)
596 >        snprintf(nbuf, sizeof(nbuf), "%s[%s@255.255.255.255]",
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_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 670 | 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 688 | 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)
698 <      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 703 | 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 727 | 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 744 | 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 757 | 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
761 < * and servers to those servers that need them.  A server needs the client
762 < * QUITs if it can't figure them out from the SQUIT (ie pre-TS4) or if it
763 < * isn't getting the SQUIT because of @#(*&@)# hostmasking.  With TS4, once
764 < * a link gets a SQUIT, it doesn't need any QUIT/SQUITs for clients depending
765 < * on that one -orabidoo
766 < *
767 < * This is now called on each local server -adx
768 < */
769 < static void
770 < recurse_send_quits(struct Client *original_source_p, struct Client *source_p,
771 <                   struct Client *from, struct Client *to, const char *comment,
772 <                   const char *splitstr)
773 < {
774 <  dlink_node *ptr, *next;
775 <  struct Client *target_p;
776 <  int hidden = match(me.name, source_p->name); /* XXX */
777 <
778 <  assert(to != source_p);  /* should be already removed from serv_list */
779 <
780 <  /* If this server can handle quit storm (QS) removal
781 <   * of dependents, just send the SQUIT
782 <   *
783 <   * Always check *all* dependent servers if some of them are
784 <   * hidden behind fakename. If so, send out the QUITs -adx
785 <   */
786 <  if (hidden || !IsCapable(to, CAP_QS))
787 <    DLINK_FOREACH_SAFE(ptr, next, source_p->serv->client_list.head)
788 <    {
789 <      target_p = ptr->data;
790 <      sendto_one(to, ":%s QUIT :%s", target_p->name, splitstr);
791 <    }
792 <
793 <  DLINK_FOREACH_SAFE(ptr, next, source_p->serv->server_list.head)
794 <    recurse_send_quits(original_source_p, ptr->data, from, to,
795 <                       comment, splitstr);
796 <
797 <  if (!hidden && ((source_p == original_source_p && to != from) ||
798 <                  !IsCapable(to, CAP_QS)))
799 <  {
800 <    /* don't use a prefix here - we have to be 100% sure the message
801 <     * will be accepted without Unknown prefix etc.. */
802 <    sendto_one(to, "SQUIT %s :%s", ID_or_name(source_p, to), comment);
803 <  }
804 < }
805 <
806 < /*
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 825 | Line 720 | recurse_remove_clients(struct Client *so
720   }
721  
722   /*
828 ** Remove *everything* that depends on source_p, from all lists, and sending
829 ** all necessary QUITs and SQUITs.  source_p itself is still on the lists,
830 ** and its SQUITs have been sent except for the upstream one  -orabidoo
831 */
832 static void
833 remove_dependents(struct Client *source_p, struct Client *from,
834                  const char *comment, const char *splitstr)
835 {
836  dlink_node *ptr = NULL;
837
838  DLINK_FOREACH(ptr, serv_list.head)
839    recurse_send_quits(source_p, source_p, from, ptr->data,
840                       comment, splitstr);
841
842  recurse_remove_clients(source_p, splitstr);
843 }
844
845 /*
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 < * SetKilled and propagating a kill or similar message. However,
728 < * it is perfectly correct to call exit_client to force a _server_
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
855 *               - for servers, the second argument is a pointer to who
856 *                 is firing the server. This side won't get any generated
857 *                 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 878 | 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)
882 <    {
883 <      delete_auth(source_p->localClient->auth);
884 <      source_p->localClient->auth = NULL;
885 <    }
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 898 | Line 771 | exit_client(struct Client *source_p, str
771      }
772      else if (IsClient(source_p))
773      {
774 +      time_t on_for = CurrentTime - source_p->localClient->firsttime;
775        assert(Count.local > 0);
776        Count.local--;
777  
778 <      if (IsOper(source_p))
779 <      {
906 <        if ((m = dlinkFindDelete(&oper_list, source_p)) != NULL)
778 >      if (HasUMode(source_p, UMODE_OPER))
779 >        if ((m = dlinkFindDelete(&oper_list, source_p)))
780            free_dlink_node(m);
908      }
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);
794 <      sendto_realops_flags(UMODE_CCONN_FULL, L_ALL, "CLIEXIT: %s %s %s %s 0 %s",
795 <                           source_p->name,
796 <                           source_p->username,
797 <                           source_p->host,
798 <
799 <                           ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
927 <                           "255.255.255.255" : source_p->sockhost,
928 <                           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),
797 >           source_p->name, source_p->username, source_p->host,
798 >           source_p->localClient->send.bytes>>10,
799 >           source_p->localClient->recv.bytes>>10);
800      }
801 <
931 <    /* As soon as a client is known to be a server of some sort
932 <     * it has to be put on the serv_list, or SJOIN's to this new server
933 <     * from the connect burst will not be seen.
934 <     */
935 <    if (IsServer(source_p) || IsConnecting(source_p) ||
936 <        IsHandshake(source_p))
801 >    else if (IsServer(source_p))
802      {
803 <      if ((m = dlinkFindDelete(&serv_list, source_p)) != NULL)
804 <      {
940 <        free_dlink_node(m);
941 <        unset_chcap_usage_counts(source_p);
942 <      }
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  
948    log_user_exit(source_p);
949
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  
963    /*
964    ** Currently only server connections can have
965    ** depending remote clients here, but it does no
966    ** harm to check for all local clients. In
967    ** future some other clients than servers might
968    ** have remotes too...
969    **
970    ** Close the Client connection first and mark it
971    ** so that no messages are attempted to send to it.
972    ** Remember it makes source_p->from == NULL.
973    */
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->firsttime),
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(L_NOTICE, "%s was connected for %d seconds.  %llu/%llu sendK/recvK.",
866 <           source_p->name, (int)(CurrentTime - source_p->firsttime),
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),
867             source_p->localClient->send.bytes >> 10,
868             source_p->localClient->recv.bytes >> 10);
869      }
870    }
871 <  else if (IsClient(source_p) && !IsKilled(source_p))
872 <  {
873 <    sendto_server(from->from, NULL, CAP_TS6, NOCAPS,
1012 <                  ":%s QUIT :%s", ID(source_p), comment);
1013 <    sendto_server(from->from, NULL, NOCAPS, CAP_TS6,
1014 <                  ":%s QUIT :%s", source_p->name, comment);
1015 <  }
871 >  else if (IsClient(source_p) && !HasFlag(source_p, FLAGS_KILLED))
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 1056 | 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 1069 | Line 927 | dead_link_on_read(struct Client *client_
927  
928    if (IsServer(client_p) || IsHandshake(client_p))
929    {
930 <    int connected = CurrentTime - client_p->firsttime;
931 <      
930 >    int connected = CurrentTime - client_p->localClient->firsttime;
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(L_NOTICE, "Server %s closed the connection",
945 <           get_client_name(client_p, SHOW_IP));
944 >      ilog(LOG_TYPE_IRCD, "Server %s closed the connection",
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 1109 | 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 1126 | 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 1140 | 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 1168 | 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;
1174  /* XXX We wouldn't need that if match() would return 0 on match */
1175  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 1201 | 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 (IsSoftCallerId(target))
1064 >  if (HasUMode(target, UMODE_SOFTCALLERID))
1065      DLINK_FOREACH(ptr, target->channel.head)
1066        if (IsMember(source, ((struct Membership *)ptr->data)->chptr))
1067          return 1;
# Line 1221 | 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 < /* change_local_nick()
1088 < *
1232 < * inputs       - pointer to server
1233 < *              - pointer to client
1234 < *              - nick
1235 < * output       -
1236 < * side effects - changes nick of a LOCAL user
1237 < */
1238 < void
1239 < change_local_nick(struct Client *client_p, struct Client *source_p, const char *nick)
1087 > unsigned int
1088 > idle_time_get(const struct Client *source_p, const struct Client *target_p)
1089   {
1090 <  int samenick = 0;
1091 <
1092 <  assert(source_p->name[0] && !EmptyString(nick));
1093 <
1094 <  /*
1095 <   * Client just changing his/her nick. If he/she is
1096 <   * on a channel, send note of change to all clients
1097 <   * on that channel. Propagate notice to other servers.
1098 <   */
1099 <  if ((source_p->localClient->last_nick_change +
1251 <       ConfigFileEntry.max_nick_time) < CurrentTime)
1252 <    source_p->localClient->number_of_nick_changes = 0;
1253 <  source_p->localClient->last_nick_change = CurrentTime;
1254 <  source_p->localClient->number_of_nick_changes++;
1255 <
1256 <  if ((ConfigFileEntry.anti_nick_flood &&
1257 <      (source_p->localClient->number_of_nick_changes
1258 <       <= ConfigFileEntry.max_nick_changes)) ||
1259 <     !ConfigFileEntry.anti_nick_flood ||
1260 <     (IsOper(source_p) && ConfigFileEntry.no_oper_flood))
1261 <  {
1262 <    samenick = !irccmp(source_p->name, nick);
1263 <
1264 <    if (!samenick)
1265 <    {
1266 <      source_p->tsinfo = CurrentTime;
1267 <      clear_ban_cache_client(source_p);
1268 <      watch_check_hash(source_p, RPL_LOGOFF);
1269 <
1270 <      if (HasUMode(source_p, UMODE_REGISTERED))
1271 <      {
1272 <        unsigned int oldmodes = source_p->umodes;
1273 <        char modebuf[IRCD_BUFSIZE] = { '\0' };
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 <        DelUMode(source_p, UMODE_REGISTERED);
1102 <        send_umode(source_p, source_p, oldmodes, 0xffffffff, modebuf);
1277 <      }
1278 <    }
1101 >  min_idle = class->min_idle;
1102 >  max_idle = class->max_idle;
1103  
1104 <    /* XXX - the format of this notice should eventually be changed
1105 <     * to either %s[%s@%s], or even better would be get_client_name() -bill
1282 <     */
1283 <    sendto_realops_flags(UMODE_NCHANGE, L_ALL, "Nick change: From %s to %s [%s@%s]",
1284 <                         source_p->name, nick, source_p->username, source_p->host);
1285 <    sendto_common_channels_local(source_p, 1, ":%s!%s@%s NICK :%s",
1286 <                                 source_p->name, source_p->username,
1287 <                                 source_p->host, nick);
1288 <    add_history(source_p, 1);
1104 >  if (min_idle == max_idle)
1105 >    return min_idle;
1106  
1107 <    sendto_server(client_p, NULL, CAP_TS6, NOCAPS,
1108 <                  ":%s NICK %s :%lu",
1109 <                  ID(source_p), nick, (unsigned long)source_p->tsinfo);
1110 <    sendto_server(client_p, NULL, NOCAPS, CAP_TS6,
1294 <                  ":%s NICK %s :%lu",
1295 <                  source_p->name, nick, (unsigned long)source_p->tsinfo);
1107 >  if (class->flags & CLASS_FLAGS_RANDOM_IDLE)
1108 >    idle = genrand_int32();
1109 >  else
1110 >    idle = CurrentTime - target_p->localClient->last_privmsg;
1111  
1112 <    hash_del_client(source_p);
1113 <    strcpy(source_p->name, nick);
1114 <    hash_add_client(source_p);
1112 >  if (!max_idle)
1113 >    idle = 0;
1114 >  else
1115 >    idle %= max_idle;
1116  
1117 <    if (!samenick)
1118 <      watch_check_hash(source_p, RPL_LOGON);
1117 >  if (idle < min_idle)
1118 >    idle = min_idle + (idle % (max_idle - min_idle));
1119  
1120 <    /* fd_desc is long enough */
1305 <    fd_note(&client_p->localClient->fd, "Nick: %s", nick);
1306 <  }
1307 <  else
1308 <    sendto_one(source_p, form_str(ERR_NICKTOOFAST),
1309 <               me.name, source_p->name, source_p->name,
1310 <               nick, ConfigFileEntry.max_nick_time);
1120 >  return idle;
1121   }

Diff Legend

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