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-7.2/src/client.c (file contents), Revision 992 by michael, Mon Aug 17 19:19:16 2009 UTC vs.
ircd-hybrid-8/src/client.c (file contents), Revision 1514 by michael, Sun Aug 26 09:11:17 2012 UTC

# Line 23 | Line 23
23   */
24  
25   #include "stdinc.h"
26 < #include "tools.h"
26 > #include "list.h"
27   #include "client.h"
28   #include "channel_mode.h"
29 #include "common.h"
29   #include "event.h"
30   #include "fdlist.h"
31   #include "hash.h"
32   #include "irc_string.h"
34 #include "sprintf_irc.h"
33   #include "ircd.h"
36 #include "list.h"
34   #include "s_gline.h"
35   #include "numeric.h"
36   #include "packet.h"
37   #include "s_auth.h"
38   #include "s_bsd.h"
39 < #include "s_conf.h"
40 < #include "s_log.h"
39 > #include "conf.h"
40 > #include "log.h"
41   #include "s_misc.h"
42   #include "s_serv.h"
43   #include "send.h"
# Line 77 | Line 74 | static dlink_node *eac_next;  /* next ab
74  
75   static void check_pings_list(dlink_list *);
76   static void check_unknowns_list(void);
77 < static void ban_them(struct Client *client_p, struct ConfItem *conf);
77 > static void ban_them(struct Client *, struct ConfItem *);
78  
79  
80   /* init_client()
# Line 119 | Line 116 | make_client(struct Client *from)
116  
117    if (from == NULL)
118    {
119 <    client_p->from  = client_p; /* 'from' of local client is self! */
120 <    client_p->since = client_p->lasttime = client_p->firsttime = CurrentTime;
121 <
122 <    client_p->localClient = BlockHeapAlloc(lclient_heap);
119 >    client_p->from                      = client_p; /* 'from' of local client is self! */
120 >    client_p->localClient               = BlockHeapAlloc(lclient_heap);
121 >    client_p->localClient->since        = CurrentTime;
122 >    client_p->localClient->lasttime     = CurrentTime;
123 >    client_p->localClient->firsttime    = CurrentTime;
124      client_p->localClient->registration = REG_INIT;
125 +
126      /* as good a place as any... */
127 <    dlinkAdd(client_p, make_dlink_node(), &unknown_list);
127 >    dlinkAdd(client_p, &client_p->localClient->lclient_node, &unknown_list);
128    }
129    else
130      client_p->from = from; /* 'from' of local client is self! */
131  
132 +  client_p->idhnext = client_p;
133    client_p->hnext  = client_p;
134    client_p->status = STAT_UNKNOWN;
135    strcpy(client_p->username, "unknown");
# Line 150 | Line 150 | free_client(struct Client *client_p)
150    assert(client_p != NULL);
151    assert(client_p != &me);
152    assert(client_p->hnext == client_p);
153 +  assert(client_p->idhnext == client_p);
154    assert(client_p->channel.head == NULL);
155    assert(dlink_list_length(&client_p->channel) == 0);
156 +  assert(dlink_list_length(&client_p->whowas) == 0);
157 +  assert(!IsServer(client_p) || IsServer(client_p) && client_p->serv);
158  
156  MyFree(client_p->away);
159    MyFree(client_p->serv);
160  
161    if (MyConnect(client_p))
162    {
163      assert(client_p->localClient->invited.head == NULL);
164      assert(dlink_list_length(&client_p->localClient->invited) == 0);
165 +    assert(dlink_list_length(&client_p->localClient->watches) == 0);
166      assert(IsClosing(client_p) && IsDead(client_p));
167  
168      MyFree(client_p->localClient->response);
# Line 254 | Line 257 | check_pings_list(dlink_list *list)
257        continue;
258      }
259  
257    if (GlobalSetOptions.idletime && IsClient(client_p))
258    {
259      if (!IsExemptKline(client_p) && !IsOper(client_p) &&
260          !IsIdlelined(client_p) &&
261          ((CurrentTime - client_p->localClient->last) > GlobalSetOptions.idletime))
262      {
263        struct ConfItem *conf;
264        struct AccessItem *aconf;
265
266        conf = make_conf_item(KLINE_TYPE);
267        aconf = (struct AccessItem *)map_to_conf(conf);
268
269        DupString(aconf->host, client_p->host);
270        DupString(aconf->reason, "idle exceeder");
271        DupString(aconf->user, client_p->username);
272        aconf->hold = CurrentTime + 60;
273        add_temp_line(conf);
274
275        sendto_realops_flags(UMODE_ALL, L_ALL,
276                             "Idle time limit exceeded for %s - temp k-lining",
277                             get_client_name(client_p, HIDE_IP));
278        exit_client(client_p, &me, aconf->reason);
279        continue;
280      }
281    }
282
260      if (!IsRegistered(client_p))
261        ping = CONNECTTIMEOUT, pingwarn = 0;
262      else
263        ping = get_client_ping(client_p, &pingwarn);
264  
265 <    if (ping < CurrentTime - client_p->lasttime)
265 >    if (ping < CurrentTime - client_p->localClient->lasttime)
266      {
267        if (!IsPingSent(client_p))
268        {
# Line 296 | Line 273 | check_pings_list(dlink_list *list)
273           */
274          SetPingSent(client_p);
275          ClearPingWarning(client_p);
276 <        client_p->lasttime = CurrentTime - ping;
276 >        client_p->localClient->lasttime = CurrentTime - ping;
277          sendto_one(client_p, "PING :%s", ID_or_name(&me, client_p));
278        }
279        else
280        {
281 <        if (CurrentTime - client_p->lasttime >= 2 * ping)
281 >        if (CurrentTime - client_p->localClient->lasttime >= 2 * ping)
282          {
283            /*
284             * If the client/server hasn't talked to us in 2*ping seconds
# Line 315 | Line 292 | check_pings_list(dlink_list *list)
292              sendto_realops_flags(UMODE_ALL, L_OPER,
293                                   "No response from %s, closing link",
294                                   get_client_name(client_p, MASK_IP));
295 <            ilog(L_NOTICE, "No response from %s, closing link",
295 >            ilog(LOG_TYPE_IRCD, "No response from %s, closing link",
296                   get_client_name(client_p, HIDE_IP));
297            }
298  
299 <          ircsprintf(scratch, "Ping timeout: %d seconds",
300 <                     (int)(CurrentTime - client_p->lasttime));
299 >          snprintf(scratch, sizeof(scratch), "Ping timeout: %d seconds",
300 >                   (int)(CurrentTime - client_p->localClient->lasttime));
301            exit_client(client_p, &me, scratch);
302          }
303          else if (!IsPingWarning(client_p) && pingwarn > 0 &&
304                   (IsServer(client_p) || IsHandshake(client_p)) &&
305 <                 CurrentTime - client_p->lasttime >= ping + pingwarn)
305 >                 CurrentTime - client_p->localClient->lasttime >= ping + pingwarn)
306          {
307            /*
308             * If the server hasn't replied in pingwarn seconds after sending
# Line 338 | Line 315 | check_pings_list(dlink_list *list)
315            sendto_realops_flags(UMODE_ALL, L_OPER,
316                                 "Warning, no response from %s in %d seconds",
317                                 get_client_name(client_p, MASK_IP), pingwarn);
318 <          ilog(L_NOTICE, "No response from %s in %d seconds",
318 >          ilog(LOG_TYPE_IRCD, "No response from %s in %d seconds",
319                 get_client_name(client_p, HIDE_IP), pingwarn);
320          }
321        }
# Line 372 | Line 349 | check_unknowns_list(void)
349       * Check UNKNOWN connections - if they have been in this state
350       * for > 30s, close them.
351       */
352 <    if (IsAuthFinished(client_p) && (CurrentTime - client_p->firsttime) > 30)
352 >    if (IsAuthFinished(client_p) && (CurrentTime - client_p->localClient->firsttime) > 30)
353        exit_client(client_p, &me, "Registration timed out");
354    }
355   }
# Line 555 | Line 532 | ban_them(struct Client *client_p, struct
532   static void
533   update_client_exit_stats(struct Client *client_p)
534   {
535 <  if (IsServer(client_p))
559 <  {
560 <    sendto_realops_flags(UMODE_EXTERNAL, L_ALL,
561 <                         "Server %s split from %s",
562 <                         client_p->name, client_p->servptr->name);
563 <  }
564 <  else if (IsClient(client_p))
535 >  if (IsClient(client_p))
536    {
537 +    assert(Count.total > 0);
538      --Count.total;
539 <    if (IsOper(client_p))
539 >    if (HasUMode(client_p, UMODE_OPER))
540        --Count.oper;
541 <    if (IsInvisible(client_p))
541 >    if (HasUMode(client_p, UMODE_INVISIBLE))
542        --Count.invisi;
543    }
544 +  else if (IsServer(client_p))
545 +    sendto_realops_flags(UMODE_EXTERNAL, L_ALL, "Server %s split from %s",
546 +                         client_p->name, client_p->servptr->name);
547  
548    if (splitchecking && !splitmode)
549      check_splitmode(NULL);
# Line 580 | Line 555 | update_client_exit_stats(struct Client *
555   * output       - return client pointer
556   * side effects - find person by (nick)name
557   */
583 /* XXX - ugly wrapper */
558   struct Client *
559   find_person(const struct Client *client_p, const char *name)
560   {
# Line 591 | Line 565 | find_person(const struct Client *client_
565      if ((c2ptr = hash_find_id(name)) != NULL)
566      {
567        /* invisible users shall not be found by UID guessing */
568 <      if (IsInvisible(c2ptr) && !IsServer(client_p))
568 >      if (HasUMode(c2ptr, UMODE_INVISIBLE) && !IsServer(client_p))
569          c2ptr = NULL;
570      }
571    }
572    else
573 <    c2ptr = find_client(name);
573 >    c2ptr = hash_find_client(name);
574  
575    return ((c2ptr != NULL && IsClient(c2ptr)) ? c2ptr : NULL);
576   }
# Line 616 | Line 590 | find_chasing(struct Client *client_p, st
590      *chasing = 0;
591  
592    if (who)
593 <    return(who);
593 >    return who;
594  
595    if (IsDigit(*user))
596 <    return(NULL);
596 >    return NULL;
597  
598    if ((who = get_history(user,
599                          (time_t)ConfigFileEntry.kill_chase_time_limit))
# Line 627 | Line 601 | find_chasing(struct Client *client_p, st
601    {
602      sendto_one(source_p, form_str(ERR_NOSUCHNICK),
603                 me.name, source_p->name, user);
604 <    return(NULL);
604 >    return NULL;
605    }
606  
607    if (chasing)
608      *chasing = 1;
609  
610 <  return(who);
610 >  return who;
611   }
612  
613   /*
# Line 655 | Line 629 | find_chasing(struct Client *client_p, st
629   *        to modify what it points!!!
630   */
631   const char *
632 < get_client_name(struct Client *client, int showip)
632 > get_client_name(const struct Client *client, enum addr_mask_type type)
633   {
634    static char nbuf[HOSTLEN * 2 + USERLEN + 5];
635  
636    assert(client != NULL);
637  
638 <  if (irccmp(client->name, client->host) == 0)
639 <    return(client->name);
638 >  if (!MyConnect(client))
639 >    return client->name;
640  
641 <  if (ConfigServerHide.hide_server_ips)
642 <    if (IsServer(client) || IsConnecting(client) || IsHandshake(client))
643 <      showip = MASK_IP;
641 >  if (IsServer(client) || IsConnecting(client) || IsHandshake(client))
642 >  {
643 >    if (!irccmp(client->name, client->host))
644 >      return client->name;
645 >    else if (ConfigServerHide.hide_server_ips)
646 >      type = MASK_IP;
647 >  }
648  
649    if (ConfigFileEntry.hide_spoof_ips)
650 <    if (showip == SHOW_IP && IsIPSpoof(client))
651 <      showip = MASK_IP;
650 >    if (type == SHOW_IP && IsIPSpoof(client))
651 >      type = MASK_IP;
652  
653    /* And finally, let's get the host information, ip or name */
654 <  switch (showip)
654 >  switch (type)
655    {
656      case SHOW_IP:
657 <      if (MyConnect(client))
658 <      {
659 <        ircsprintf(nbuf, "%s[%s@%s]", client->name, client->username,
660 <                   client->sockhost);
683 <        break;
684 <      }
657 >      snprintf(nbuf, sizeof(nbuf), "%s[%s@%s]",
658 >               client->name,
659 >               client->username, client->sockhost);
660 >      break;
661      case MASK_IP:
662 <      ircsprintf(nbuf, "%s[%s@255.255.255.255]", client->name,
663 <                 client->username);
662 >      if (client->localClient->aftype == AF_INET)
663 >        snprintf(nbuf, sizeof(nbuf), "%s[%s@255.255.255.255]",
664 >                 client->name, client->username);
665 >      else
666 >        snprintf(nbuf, sizeof(nbuf), "%s[%s@ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff]",
667 >                 client->name, client->username);
668        break;
669      default:
670 <      ircsprintf(nbuf, "%s[%s@%s]", client->name, client->username,
671 <                 client->host);
670 >      snprintf(nbuf, sizeof(nbuf), "%s[%s@%s]",
671 >               client->name,
672 >               client->username, client->host);
673    }
674  
675 <  return(nbuf);
675 >  return nbuf;
676   }
677  
678   void
# Line 720 | Line 701 | exit_one_client(struct Client *source_p,
701  
702    assert(!IsMe(source_p));
703  
704 <  if (IsServer(source_p))
724 <  {
725 <    dlinkDelete(&source_p->lnode, &source_p->servptr->serv->server_list);
726 <
727 <    if ((lp = dlinkFindDelete(&global_serv_list, source_p)) != NULL)
728 <      free_dlink_node(lp);
729 <  }
730 <  else if (IsClient(source_p))
704 >  if (IsClient(source_p))
705    {
706      if (source_p->servptr->serv != NULL)
707        dlinkDelete(&source_p->lnode, &source_p->servptr->serv->client_list);
708  
709 <    /* If a person is on a channel, send a QUIT notice
710 <    ** to every client (person) on the same channel (so
711 <    ** that the client can show the "**signoff" message).
712 <    ** (Note: The notice is to the local clients *only*)
713 <    */
709 >    /*
710 >     * If a person is on a channel, send a QUIT notice
711 >     * to every client (person) on the same channel (so
712 >     * that the client can show the "**signoff" message).
713 >     * (Note: The notice is to the local clients *only*)
714 >     */
715      sendto_common_channels_local(source_p, 0, ":%s!%s@%s QUIT :%s",
716                                   source_p->name, source_p->username,
717                                   source_p->host, quitmsg);
# Line 757 | Line 732 | exit_one_client(struct Client *source_p,
732        del_all_accepts(source_p);
733      }
734    }
735 +  else if (IsServer(source_p))
736 +  {
737 +    dlinkDelete(&source_p->lnode, &source_p->servptr->serv->server_list);
738 +
739 +    if ((lp = dlinkFindDelete(&global_serv_list, source_p)) != NULL)
740 +      free_dlink_node(lp);
741 +  }
742  
743    /* Remove source_p from the client lists */
744    if (HasID(source_p))
# Line 796 | Line 778 | exit_one_client(struct Client *source_p,
778   static void
779   recurse_send_quits(struct Client *original_source_p, struct Client *source_p,
780                     struct Client *from, struct Client *to, const char *comment,
781 <                   const char *splitstr, const char *myname)
781 >                   const char *splitstr)
782   {
783    dlink_node *ptr, *next;
784    struct Client *target_p;
785 <  int hidden = match(myname, source_p->name);
785 >  int hidden = match(me.name, source_p->name); /* XXX */
786  
787    assert(to != source_p);  /* should be already removed from serv_list */
788  
# Line 819 | Line 801 | recurse_send_quits(struct Client *origin
801  
802    DLINK_FOREACH_SAFE(ptr, next, source_p->serv->server_list.head)
803      recurse_send_quits(original_source_p, ptr->data, from, to,
804 <                       comment, splitstr, myname);
804 >                       comment, splitstr);
805  
806    if (!hidden && ((source_p == original_source_p && to != from) ||
807                    !IsCapable(to, CAP_QS)))
# Line 860 | Line 842 | static void
842   remove_dependents(struct Client *source_p, struct Client *from,
843                    const char *comment, const char *splitstr)
844   {
845 <  struct Client *to;
864 <  struct ConfItem *conf;
865 <  static char myname[HOSTLEN+1];
866 <  dlink_node *ptr;
845 >  dlink_node *ptr = NULL;
846  
847    DLINK_FOREACH(ptr, serv_list.head)
848 <  {
849 <    to = ptr->data;
871 <
872 <    if ((conf = to->serv->sconf) != NULL)
873 <      strlcpy(myname, my_name_for_link(conf), sizeof(myname));
874 <    else
875 <      strlcpy(myname, me.name, sizeof(myname));
876 <    recurse_send_quits(source_p, source_p, from, to,
877 <                       comment, splitstr, myname);
878 <  }
848 >    recurse_send_quits(source_p, source_p, from, ptr->data,
849 >                       comment, splitstr);
850  
851    recurse_remove_clients(source_p, splitstr);
852   }
# Line 885 | Line 856 | remove_dependents(struct Client *source_
856   * this on any struct Client, regardless of its state.
857   *
858   * Note, you shouldn't exit remote _users_ without first doing
859 < * SetKilled and propagating a kill or similar message. However,
860 < * it is perfectly correct to call exit_client to force a _server_
859 > * AddFlag(x, FLAGS_KILLED) and propagating a kill or similar message.
860 > * However, it is perfectly correct to call exit_client to force a _server_
861   * quit (either local or remote one).
862   *
863   * inputs:       - a client pointer that is going to be exited
# Line 901 | Line 872 | remove_dependents(struct Client *source_
872   void
873   exit_client(struct Client *source_p, struct Client *from, const char *comment)
874   {
875 <  dlink_node *m;
875 >  dlink_node *m = NULL;
876  
877    if (MyConnect(source_p))
878    {
# Line 930 | Line 901 | exit_client(struct Client *source_p, str
901       */
902      if (!IsRegistered(source_p))
903      {
904 <      if ((m = dlinkFindDelete(&unknown_list, source_p)) != NULL)
905 <        free_dlink_node(m);
904 >      assert(dlinkFind(&unknown_list, source_p));
905 >
906 >      dlinkDelete(&source_p->localClient->lclient_node, &unknown_list);
907      }
908      else if (IsClient(source_p))
909      {
910 +      time_t on_for = CurrentTime - source_p->localClient->firsttime;
911 +      assert(Count.local > 0);
912        Count.local--;
913  
914 <      if (IsOper(source_p))
914 >      if (HasUMode(source_p, UMODE_OPER))
915        {
916          if ((m = dlinkFindDelete(&oper_list, source_p)) != NULL)
917            free_dlink_node(m);
918        }
919  
920 +      assert(dlinkFind(&local_client_list, source_p));
921        dlinkDelete(&source_p->localClient->lclient_node, &local_client_list);
922 +
923        if (source_p->localClient->list_task != NULL)
924          free_list_task(source_p->localClient->list_task, source_p);
925  
# Line 956 | Line 932 | exit_client(struct Client *source_p, str
932                             source_p->name,
933                             source_p->username,
934                             source_p->host,
959
935                             ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
936                             "255.255.255.255" : source_p->sockhost,
937                             comment);
938 +      ilog(LOG_TYPE_USER, "%s (%3u:%02u:%02u): %s!%s@%s %llu/%llu",
939 +           myctime(source_p->localClient->firsttime), (unsigned int)(on_for / 3600),
940 +           (unsigned int)((on_for % 3600)/60), (unsigned int)(on_for % 60),
941 +           source_p->name, source_p->username, source_p->host,
942 +           source_p->localClient->send.bytes>>10,
943 +           source_p->localClient->recv.bytes>>10);
944      }
945  
946      /* As soon as a client is known to be a server of some sort
947       * it has to be put on the serv_list, or SJOIN's to this new server
948       * from the connect burst will not be seen.
949 +     * XXX - TBV.  This is not true. The only place where we put a server on
950 +     * serv_list is in server_estab right now after registration process.
951 +     * And only after this, a burst is sent to the remote server, i.e. we never
952 +     * send a burst to STAT_CONNECTING, or STAT_HANDSHAKE. This will need
953 +     * more investigation later on, but for now, it's not a problem after all.
954       */
955      if (IsServer(source_p) || IsConnecting(source_p) ||
956          IsHandshake(source_p))
957      {
958 <      if ((m = dlinkFindDelete(&serv_list, source_p)) != NULL)
958 >      if (dlinkFind(&serv_list, source_p))
959        {
960 <        free_dlink_node(m);
960 >        dlinkDelete(&source_p->localClient->lclient_node, &serv_list);
961          unset_chcap_usage_counts(source_p);
962        }
963  
# Line 979 | Line 965 | exit_client(struct Client *source_p, str
965          Count.myserver--;
966      }
967  
982    log_user_exit(source_p);
983
968      if (!IsDead(source_p))
969      {
970        if (IsServer(source_p))
# Line 1031 | Line 1015 | exit_client(struct Client *source_p, str
1015      {
1016        sendto_realops_flags(UMODE_ALL, L_ALL,
1017                             "%s was connected for %d seconds.  %llu/%llu sendK/recvK.",
1018 <                           source_p->name, (int)(CurrentTime - source_p->firsttime),
1018 >                           source_p->name, (int)(CurrentTime - source_p->localClient->firsttime),
1019                             source_p->localClient->send.bytes >> 10,
1020                             source_p->localClient->recv.bytes >> 10);
1021 <      ilog(L_NOTICE, "%s was connected for %d seconds.  %llu/%llu sendK/recvK.",
1022 <           source_p->name, (int)(CurrentTime - source_p->firsttime),
1021 >      ilog(LOG_TYPE_IRCD, "%s was connected for %d seconds.  %llu/%llu sendK/recvK.",
1022 >           source_p->name, (int)(CurrentTime - source_p->localClient->firsttime),
1023             source_p->localClient->send.bytes >> 10,
1024             source_p->localClient->recv.bytes >> 10);
1025      }
1026    }
1027 <  else if (IsClient(source_p) && !IsKilled(source_p))
1027 >  else if (IsClient(source_p) && !HasFlag(source_p, FLAGS_KILLED))
1028    {
1029 <    sendto_server(from->from, NULL, CAP_TS6, NOCAPS,
1029 >    sendto_server(from->from, CAP_TS6, NOCAPS,
1030                    ":%s QUIT :%s", ID(source_p), comment);
1031 <    sendto_server(from->from, NULL, NOCAPS, CAP_TS6,
1031 >    sendto_server(from->from, NOCAPS, CAP_TS6,
1032                    ":%s QUIT :%s", source_p->name, comment);
1033    }
1034  
# Line 1103 | Line 1087 | dead_link_on_read(struct Client *client_
1087  
1088    if (IsServer(client_p) || IsHandshake(client_p))
1089    {
1090 <    int connected = CurrentTime - client_p->firsttime;
1090 >    int connected = CurrentTime - client_p->localClient->firsttime;
1091        
1092      if (error == 0)
1093      {
# Line 1117 | Line 1101 | dead_link_on_read(struct Client *client_
1101                             "Server %s closed the connection",
1102                             get_client_name(client_p, MASK_IP));
1103  
1104 <      ilog(L_NOTICE, "Server %s closed the connection",
1104 >      ilog(LOG_TYPE_IRCD, "Server %s closed the connection",
1105             get_client_name(client_p, SHOW_IP));
1106      }
1107      else
# Line 1140 | Line 1124 | dead_link_on_read(struct Client *client_
1124      strlcpy(errmsg, "Remote host closed the connection",
1125              sizeof(errmsg));
1126    else
1127 <    ircsprintf(errmsg, "Read error: %s",
1128 <               strerror(current_error));
1127 >    snprintf(errmsg, sizeof(errmsg), "Read error: %s",
1128 >             strerror(current_error));
1129  
1130    exit_client(client_p, &me, errmsg);
1131   }
# Line 1238 | Line 1222 | accept_message(struct Client *source,
1222                                        source->host, target, 1))
1223      return 1;
1224  
1225 <  if (IsSoftCallerId(target))
1225 >  if (HasUMode(target, UMODE_SOFTCALLERID))
1226      DLINK_FOREACH(ptr, target->channel.head)
1227        if (IsMember(source, ((struct Membership *)ptr->data)->chptr))
1228          return 1;
# Line 1260 | Line 1244 | del_all_accepts(struct Client *client_p)
1244    DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->localClient->acceptlist.head)
1245      del_accept(ptr->data, client_p);
1246   }
1263
1264 /* set_initial_nick()
1265 *
1266 * inputs
1267 * output
1268 * side effects -
1269 *
1270 * This function is only called to set up an initially registering
1271 * client.
1272 */
1273 void
1274 set_initial_nick(struct Client *client_p, struct Client *source_p,
1275                 const char *nick)
1276 {
1277 char buf[USERLEN + 1];
1278
1279  /* Client setting NICK the first time */
1280  
1281  /* This had to be copied here to avoid problems.. */
1282  source_p->tsinfo = CurrentTime;
1283  source_p->localClient->registration &= ~REG_NEED_NICK;
1284
1285  if (source_p->name[0])
1286    hash_del_client(source_p);
1287
1288  strlcpy(source_p->name, nick, sizeof(source_p->name));
1289  hash_add_client(source_p);
1290
1291  /* fd_desc is long enough */
1292  fd_note(&client_p->localClient->fd, "Nick: %s", nick);
1293  
1294  if (!source_p->localClient->registration)
1295  {
1296    strlcpy(buf, source_p->username, sizeof(buf));
1297
1298    /*
1299     * USER already received, now we have NICK.
1300     * *NOTE* For servers "NICK" *must* precede the
1301     * user message (giving USER before NICK is possible
1302     * only for local client connection!). register_user
1303     * may reject the client and call exit_client for it
1304     * --must test this and exit m_nick too!!!
1305     */
1306    register_local_user(client_p, source_p, nick, buf);
1307  }
1308 }
1309
1310 /* change_local_nick()
1311 *
1312 * inputs       - pointer to server
1313 *              - pointer to client
1314 *              - nick
1315 * output       -
1316 * side effects - changes nick of a LOCAL user
1317 */
1318 void
1319 change_local_nick(struct Client *client_p, struct Client *source_p, const char *nick)
1320 {
1321  int samenick = 0;
1322
1323  assert(source_p->name[0] && !EmptyString(nick));
1324
1325  /*
1326   * Client just changing his/her nick. If he/she is
1327   * on a channel, send note of change to all clients
1328   * on that channel. Propagate notice to other servers.
1329   */
1330  if ((source_p->localClient->last_nick_change +
1331       ConfigFileEntry.max_nick_time) < CurrentTime)
1332    source_p->localClient->number_of_nick_changes = 0;
1333  source_p->localClient->last_nick_change = CurrentTime;
1334  source_p->localClient->number_of_nick_changes++;
1335
1336  if ((ConfigFileEntry.anti_nick_flood &&
1337      (source_p->localClient->number_of_nick_changes
1338       <= ConfigFileEntry.max_nick_changes)) ||
1339     !ConfigFileEntry.anti_nick_flood ||
1340     (IsOper(source_p) && ConfigFileEntry.no_oper_flood))
1341  {
1342    samenick = !irccmp(source_p->name, nick);
1343
1344    if (!samenick)
1345    {
1346      source_p->tsinfo = CurrentTime;
1347      clear_ban_cache_client(source_p);
1348      watch_check_hash(source_p, RPL_LOGOFF);
1349    }
1350
1351    /* XXX - the format of this notice should eventually be changed
1352     * to either %s[%s@%s], or even better would be get_client_name() -bill
1353     */
1354    sendto_realops_flags(UMODE_NCHANGE, L_ALL, "Nick change: From %s to %s [%s@%s]",
1355                         source_p->name, nick, source_p->username, source_p->host);
1356    sendto_common_channels_local(source_p, 1, ":%s!%s@%s NICK :%s",
1357                                 source_p->name, source_p->username,
1358                                 source_p->host, nick);
1359    add_history(source_p, 1);
1360
1361    sendto_server(client_p, NULL, CAP_TS6, NOCAPS,
1362                  ":%s NICK %s :%lu",
1363                  ID(source_p), nick, (unsigned long)source_p->tsinfo);
1364    sendto_server(client_p, NULL, NOCAPS, CAP_TS6,
1365                  ":%s NICK %s :%lu",
1366                  source_p->name, nick, (unsigned long)source_p->tsinfo);
1367
1368    hash_del_client(source_p);
1369    strcpy(source_p->name, nick);
1370    hash_add_client(source_p);
1371
1372    if (!samenick)
1373      watch_check_hash(source_p, RPL_LOGON);
1374
1375    /* fd_desc is long enough */
1376    fd_note(&client_p->localClient->fd, "Nick: %s", nick);
1377  }
1378  else
1379    sendto_one(source_p, form_str(ERR_NICKTOOFAST),
1380               me.name, source_p->name, source_p->name,
1381               nick, ConfigFileEntry.max_nick_time);
1382 }

Diff Legend

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