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

Comparing ircd-hybrid/trunk/src/channel.c (file contents):
Revision 5983 by michael, Mon May 25 15:24:48 2015 UTC vs.
Revision 7012 by michael, Fri Jan 1 13:52:27 2016 UTC

# Line 1 | Line 1
1   /*
2   *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Copyright (c) 1997-2015 ircd-hybrid development team
4 > *  Copyright (c) 1997-2016 ircd-hybrid development team
5   *
6   *  This program is free software; you can redistribute it and/or modify
7   *  it under the terms of the GNU General Public License as published by
# Line 47 | Line 47
47   dlink_list channel_list;
48   mp_pool_t *ban_pool;    /*! \todo ban_pool shouldn't be a global var */
49  
50 struct event splitmode_event =
51 {
52  .name = "check_splitmode",
53  .handler = check_splitmode,
54  .when = 5
55 };
56
50   static mp_pool_t *member_pool, *channel_pool;
51  
52  
# Line 62 | Line 55 | static mp_pool_t *member_pool, *channel_
55   void
56   channel_init(void)
57   {
58 <  add_capability("EX", CAP_EX);
59 <  add_capability("IE", CAP_IE);
58 >  add_capability("EX", CAPAB_EX);
59 >  add_capability("IE", CAPAB_IE);
60  
61    channel_pool = mp_pool_new(sizeof(struct Channel), MP_CHUNK_SIZE_CHANNEL);
62    ban_pool = mp_pool_new(sizeof(struct Ban), MP_CHUNK_SIZE_BAN);
# Line 73 | Line 66 | channel_init(void)
66   /*! \brief Adds a user to a channel by adding another link to the
67   *         channels member chain.
68   * \param chptr      Pointer to channel to add client to
69 < * \param who        Pointer to client (who) to add
69 > * \param client_p   Pointer to client (who) to add
70   * \param flags      Flags for chanops etc
71   * \param flood_ctrl Whether to count this join in flood calculations
72   */
73   void
74 < add_user_to_channel(struct Channel *chptr, struct Client *who,
74 > add_user_to_channel(struct Channel *chptr, struct Client *client_p,
75                      unsigned int flags, int flood_ctrl)
76   {
77    struct Membership *member = NULL;
78  
79 <  assert(IsClient(who));
79 >  assert(IsClient(client_p));
80  
81    if (GlobalSetOptions.joinfloodtime > 0)
82    {
# Line 108 | Line 101 | add_user_to_channel(struct Channel *chpt
101          SetJoinFloodNoticed(chptr);
102          sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE,
103                               "Possible Join Flooder %s on %s target: %s",
104 <                             get_client_name(who, HIDE_IP),
105 <                             who->servptr->name, chptr->name);
104 >                             get_client_name(client_p, HIDE_IP),
105 >                             client_p->servptr->name, chptr->name);
106        }
107      }
108  
# Line 117 | Line 110 | add_user_to_channel(struct Channel *chpt
110    }
111  
112    member = mp_pool_get(member_pool);
113 <  member->client_p = who;
113 >  member->client_p = client_p;
114    member->chptr = chptr;
115    member->flags = flags;
116  
117    dlinkAdd(member, &member->channode, &chptr->members);
118  
119 <  if (MyConnect(who))
119 >  if (MyConnect(client_p))
120      dlinkAdd(member, &member->locchannode, &chptr->locmembers);
121  
122 <  dlinkAdd(member, &member->usernode, &who->channel);
122 >  dlinkAdd(member, &member->usernode, &client_p->channel);
123   }
124  
125   /*! \brief Deletes an user from a channel by removing a link in the
# Line 149 | Line 142 | remove_user_from_channel(struct Membersh
142    mp_pool_release(member);
143  
144    if (chptr->members.head == NULL)
145 <    destroy_channel(chptr);
145 >    channel_free(chptr);
146   }
147  
148 < /* send_members()
148 > /* channel_send_members()
149   *
150   * inputs       -
151   * output       - NONE
152   * side effects -
153   */
154   static void
155 < send_members(struct Client *client_p, const struct Channel *chptr,
156 <             char *modebuf, char *parabuf)
155 > channel_send_members(struct Client *client_p, const struct Channel *chptr,
156 >                     char *modebuf, char *parabuf)
157   {
158    char buf[IRCD_BUFSIZE] = "";
159    const dlink_node *node = NULL;
160    int tlen;              /* length of text to append */
161    char *t, *start;       /* temp char pointer */
162  
163 <  start = t = buf + snprintf(buf, sizeof(buf), ":%s SJOIN %lu %s %s %s:",
164 <                             me.id, (unsigned long)chptr->creationtime,
163 >  start = t = buf + snprintf(buf, sizeof(buf), ":%s SJOIN %ju %s %s %s:",
164 >                             me.id, chptr->creationtime,
165                               chptr->name, modebuf, parabuf);
166  
167    DLINK_FOREACH(node, chptr->members.head)
# Line 222 | Line 215 | send_members(struct Client *client_p, co
215   * \param flag     Char flag flagging type of mode. Currently this can be 'b', e' or 'I'
216   */
217   static void
218 < send_mode_list(struct Client *client_p, const struct Channel *chptr,
219 <               const dlink_list *list, const char flag)
218 > channel_send_mask_list(struct Client *client_p, const struct Channel *chptr,
219 >                       const dlink_list *list, const char flag)
220   {
221    const dlink_node *node = NULL;
222    char mbuf[IRCD_BUFSIZE] = "";
# Line 231 | Line 224 | send_mode_list(struct Client *client_p,
224    int tlen, mlen, cur_len;
225    char *pp = pbuf;
226  
227 <  if (!list->length)
227 >  if (!dlink_list_length(list))
228      return;
229  
230 <  mlen = snprintf(mbuf, sizeof(mbuf), ":%s BMASK %lu %s %c :", me.id,
231 <                  (unsigned long)chptr->creationtime, chptr->name, flag);
230 >  mlen = snprintf(mbuf, sizeof(mbuf), ":%s BMASK %ju %s %c :", me.id,
231 >                  chptr->creationtime, chptr->name, flag);
232    cur_len = mlen;
233  
234    DLINK_FOREACH(node, list->head)
# Line 269 | Line 262 | send_mode_list(struct Client *client_p,
262   * \param chptr    Pointer to channel pointer
263   */
264   void
265 < send_channel_modes(struct Client *client_p, struct Channel *chptr)
265 > channel_send_modes(struct Client *client_p, struct Channel *chptr)
266   {
267    char modebuf[MODEBUFLEN] = "";
268    char parabuf[MODEBUFLEN] = "";
269  
270    channel_modes(chptr, client_p, modebuf, parabuf);
271 <  send_members(client_p, chptr, modebuf, parabuf);
271 >  channel_send_members(client_p, chptr, modebuf, parabuf);
272  
273 <  send_mode_list(client_p, chptr, &chptr->banlist, 'b');
274 <  send_mode_list(client_p, chptr, &chptr->exceptlist, 'e');
275 <  send_mode_list(client_p, chptr, &chptr->invexlist, 'I');
273 >  channel_send_mask_list(client_p, chptr, &chptr->banlist, 'b');
274 >  channel_send_mask_list(client_p, chptr, &chptr->exceptlist, 'e');
275 >  channel_send_mask_list(client_p, chptr, &chptr->invexlist, 'I');
276   }
277  
278   /*! \brief Check channel name for invalid characters
# Line 288 | Line 281 | send_channel_modes(struct Client *client
281   * \return 0 if invalid, 1 otherwise
282   */
283   int
284 < check_channel_name(const char *name, const int local)
284 > channel_check_name(const char *name, const int local)
285   {
286    const char *p = name;
287  
# Line 320 | Line 313 | remove_ban(struct Ban *ban, dlink_list *
313    mp_pool_release(ban);
314   }
315  
316 < /* free_channel_list()
316 > /* channel_free_mask_list()
317   *
318   * inputs       - pointer to dlink_list
319   * output       - NONE
320   * side effects -
321   */
322 < void
323 < free_channel_list(dlink_list *list)
322 > static void
323 > channel_free_mask_list(dlink_list *list)
324   {
325    dlink_node *node = NULL, *node_next = NULL;
326  
# Line 341 | Line 334 | free_channel_list(dlink_list *list)
334   * \return Channel block
335   */
336   struct Channel *
337 < make_channel(const char *name)
337 > channel_make(const char *name)
338   {
339    struct Channel *chptr = NULL;
340  
# Line 353 | Line 346 | make_channel(const char *name)
346    chptr->creationtime = CurrentTime;
347    chptr->last_join_time = CurrentTime;
348  
349 <  strlcpy(chptr->name, name, sizeof(chptr->name));
350 <  dlinkAdd(chptr, &chptr->node, &channel_list);
349 >  chptr->name_len = strlcpy(chptr->name, name, sizeof(chptr->name));
350 >  if (chptr->name_len >= sizeof(chptr->name))
351 >    chptr->name_len = sizeof(chptr->name) - 1;
352  
353 +  dlinkAdd(chptr, &chptr->node, &channel_list);
354    hash_add_channel(chptr);
355  
356    return chptr;
# Line 365 | Line 360 | make_channel(const char *name)
360   * \param chptr Channel pointer
361   */
362   void
363 < destroy_channel(struct Channel *chptr)
363 > channel_free(struct Channel *chptr)
364   {
365    clear_invites_channel(chptr);
366  
367    /* Free ban/exception/invex lists */
368 <  free_channel_list(&chptr->banlist);
369 <  free_channel_list(&chptr->exceptlist);
370 <  free_channel_list(&chptr->invexlist);
368 >  channel_free_mask_list(&chptr->banlist);
369 >  channel_free_mask_list(&chptr->exceptlist);
370 >  channel_free_mask_list(&chptr->invexlist);
371  
372    dlinkDelete(&chptr->node, &channel_list);
373    hash_del_channel(chptr);
# Line 395 | Line 390 | channel_pub_or_secret(const struct Chann
390   }
391  
392   /*! \brief lists all names on given channel
393 < * \param source_p Pointer to client struct requesting names
393 > * \param client_p Pointer to client struct requesting names
394   * \param chptr    Pointer to channel block
395   * \param show_eon Show RPL_ENDOFNAMES numeric or not
396   *                 (don't want it with /names with no params)
397   */
398   void
399 < channel_member_names(struct Client *source_p, struct Channel *chptr,
399 > channel_member_names(struct Client *client_p, struct Channel *chptr,
400                       int show_eon)
401   {
402    const dlink_node *node = NULL;
403    char buf[IRCD_BUFSIZE + 1] = "";
404    char *t = NULL, *start = NULL;
405    int tlen = 0;
406 <  const int is_member = IsMember(source_p, chptr);
407 <  const int multi_prefix = HasCap(source_p, CAP_MULTI_PREFIX) != 0;
408 <  const int uhnames = HasCap(source_p, CAP_UHNAMES) != 0;
406 >  const int is_member = IsMember(client_p, chptr);
407 >  const int multi_prefix = HasCap(client_p, CAP_MULTI_PREFIX) != 0;
408 >  const int uhnames = HasCap(client_p, CAP_UHNAMES) != 0;
409  
410 <  assert(IsClient(source_p));
410 >  assert(IsClient(client_p));
411  
412    if (PubChannel(chptr) || is_member)
413    {
414      t = buf + snprintf(buf, sizeof(buf), numeric_form(RPL_NAMREPLY),
415 <                       me.name, source_p->name,
415 >                       me.name, client_p->name,
416                         channel_pub_or_secret(chptr), chptr->name);
417      start = t;
418  
# Line 452 | Line 447 | channel_member_names(struct Client *sour
447        if (t + tlen - buf > IRCD_BUFSIZE - 2)
448        {
449          *(t - 1) = '\0';
450 <        sendto_one(source_p, "%s", buf);
450 >        sendto_one(client_p, "%s", buf);
451          t = start;
452        }
453  
# Line 468 | Line 463 | channel_member_names(struct Client *sour
463      if (tlen)
464      {
465        *(t - 1) = '\0';
466 <      sendto_one(source_p, "%s", buf);
466 >      sendto_one(client_p, "%s", buf);
467      }
468    }
469  
470    if (show_eon)
471 <    sendto_one_numeric(source_p, &me, RPL_ENDOFNAMES, chptr->name);
471 >    sendto_one_numeric(client_p, &me, RPL_ENDOFNAMES, chptr->name);
472   }
473  
474   /*! \brief Adds client to invite list
475 < * \param chptr Pointer to channel block
476 < * \param who   Pointer to client to add invite to
475 > * \param chptr    Pointer to channel block
476 > * \param client_p Pointer to client to add invite to
477   */
478   void
479 < add_invite(struct Channel *chptr, struct Client *who)
479 > add_invite(struct Channel *chptr, struct Client *client_p)
480   {
481 <  assert(IsClient(who));
481 >  assert(IsClient(client_p));
482  
483 <  del_invite(chptr, who);
483 >  del_invite(chptr, client_p);
484  
485    /*
486     * Delete last link in chain if the list is max length
487     */
488 <  if (dlink_list_length(&who->connection->invited) >=
488 >  if (dlink_list_length(&client_p->connection->invited) >=
489        ConfigChannel.max_channels)
490 <    del_invite(who->connection->invited.tail->data, who);
490 >    del_invite(client_p->connection->invited.tail->data, client_p);
491  
492    /* Add client to channel invite list */
493 <  dlinkAdd(who, make_dlink_node(), &chptr->invites);
493 >  dlinkAdd(client_p, make_dlink_node(), &chptr->invites);
494  
495    /* Add channel to the end of the client invite list */
496 <  dlinkAdd(chptr, make_dlink_node(), &who->connection->invited);
496 >  dlinkAdd(chptr, make_dlink_node(), &client_p->connection->invited);
497   }
498  
499   /*! \brief Delete Invite block from channel invite list
500   *         and client invite list
501 < * \param chptr Pointer to Channel struct
502 < * \param who   Pointer to client to remove invites from
501 > * \param chptr    Pointer to Channel struct
502 > * \param client_p Pointer to client to remove invites from
503   */
504   void
505 < del_invite(struct Channel *chptr, struct Client *who)
505 > del_invite(struct Channel *chptr, struct Client *client_p)
506   {
507    dlink_node *node = NULL;
508  
509 <  if ((node = dlinkFindDelete(&who->connection->invited, chptr)))
509 >  if ((node = dlinkFindDelete(&client_p->connection->invited, chptr)))
510      free_dlink_node(node);
511  
512 <  if ((node = dlinkFindDelete(&chptr->invites, who)))
512 >  if ((node = dlinkFindDelete(&chptr->invites, client_p)))
513      free_dlink_node(node);
514   }
515  
# Line 531 | Line 526 | clear_invites_channel(struct Channel *ch
526   }
527  
528   /*! \brief Removes all invites of a specific client
529 < * \param source_p Pointer to Client struct
529 > * \param client_p Pointer to Client struct
530   */
531   void
532 < clear_invites_client(struct Client *source_p)
532 > clear_invites_client(struct Client *client_p)
533   {
534    dlink_node *node = NULL, *node_next = NULL;
535  
536 <  DLINK_FOREACH_SAFE(node, node_next, source_p->connection->invited.head)
537 <    del_invite(node->data, source_p);
536 >  DLINK_FOREACH_SAFE(node, node_next, client_p->connection->invited.head)
537 >    del_invite(node->data, client_p);
538   }
539  
540   /* get_member_status()
# Line 556 | Line 551 | clear_invites_client(struct Client *sour
551   const char *
552   get_member_status(const struct Membership *member, const int combine)
553   {
554 <  static char buffer[4];  /* 4 for @%+\0 */
554 >  static char buffer[CMEMBER_STATUS_FLAGS_LEN + 1];  /* +1 for \0 */
555    char *p = buffer;
556  
557    if (member->flags & CHFL_CHANOP)
# Line 581 | Line 576 | get_member_status(const struct Membershi
576   }
577  
578   /*!
579 < * \param who  Pointer to Client to check
580 < * \param list Pointer to ban list to search
579 > * \param client_p Pointer to Client to check
580 > * \param list     Pointer to ban list to search
581   * \return 1 if ban found for given n!u\@h mask, 0 otherwise
582   */
583   static int
584 < find_bmask(const struct Client *who, const dlink_list *const list)
584 > find_bmask(const struct Client *client_p, const dlink_list *const list)
585   {
586    const dlink_node *node = NULL;
587  
# Line 594 | Line 589 | find_bmask(const struct Client *who, con
589    {
590      const struct Ban *ban = node->data;
591  
592 <    if (!match(ban->name, who->name) && !match(ban->user, who->username))
592 >    if (!match(ban->name, client_p->name) && !match(ban->user, client_p->username))
593      {
594        switch (ban->type)
595        {
596          case HM_HOST:
597 <          if (!match(ban->host, who->host) || !match(ban->host, who->sockhost))
597 >          if (!match(ban->host, client_p->host) || !match(ban->host, client_p->sockhost))
598              return 1;
599            break;
600          case HM_IPV4:
601 <          if (who->connection->aftype == AF_INET)
602 <            if (match_ipv4(&who->connection->ip, &ban->addr, ban->bits))
601 >          if (client_p->connection->aftype == AF_INET)
602 >            if (match_ipv4(&client_p->connection->ip, &ban->addr, ban->bits))
603                return 1;
604            break;
605          case HM_IPV6:
606 <          if (who->connection->aftype == AF_INET6)
607 <            if (match_ipv6(&who->connection->ip, &ban->addr, ban->bits))
606 >          if (client_p->connection->aftype == AF_INET6)
607 >            if (match_ipv6(&client_p->connection->ip, &ban->addr, ban->bits))
608                return 1;
609            break;
610          default:
# Line 622 | Line 617 | find_bmask(const struct Client *who, con
617   }
618  
619   /*!
620 < * \param chptr Pointer to channel block
621 < * \param who   Pointer to client to check access fo
620 > * \param chptr    Pointer to channel block
621 > * \param client_p Pointer to client to check access fo
622   * \return 0 if not banned, 1 otherwise
623   */
624   int
625 < is_banned(const struct Channel *chptr, const struct Client *who)
625 > is_banned(const struct Channel *chptr, const struct Client *client_p)
626   {
627 <  if (find_bmask(who, &chptr->banlist))
628 <    if (!find_bmask(who, &chptr->exceptlist))
627 >  if (find_bmask(client_p, &chptr->banlist))
628 >    if (!find_bmask(client_p, &chptr->exceptlist))
629        return 1;
630  
631    return 0;
632   }
633  
634   /*! Tests if a client can join a certain channel
635 < * \param source_p Pointer to client attempting to join
635 > * \param client_p Pointer to client attempting to join
636   * \param chptr    Pointer to channel
637   * \param key      Key sent by client attempting to join if present
638   * \return ERR_BANNEDFROMCHAN, ERR_INVITEONLYCHAN, ERR_CHANNELISFULL
639   *         or 0 if allowed to join.
640   */
641 < int
642 < can_join(struct Client *source_p, const struct Channel *chptr, const char *key)
641 > static int
642 > can_join(struct Client *client_p, const struct Channel *chptr, const char *key)
643   {
644 <  if ((chptr->mode.mode & MODE_SSLONLY) && !HasUMode(source_p, UMODE_SSL))
644 >  if ((chptr->mode.mode & MODE_SSLONLY) && !HasUMode(client_p, UMODE_SSL))
645      return ERR_SSLONLYCHAN;
646  
647 <  if ((chptr->mode.mode & MODE_REGONLY) && !HasUMode(source_p, UMODE_REGISTERED))
647 >  if ((chptr->mode.mode & MODE_REGONLY) && !HasUMode(client_p, UMODE_REGISTERED))
648      return ERR_NEEDREGGEDNICK;
649  
650 <  if ((chptr->mode.mode & MODE_OPERONLY) && !HasUMode(source_p, UMODE_OPER))
650 >  if ((chptr->mode.mode & MODE_OPERONLY) && !HasUMode(client_p, UMODE_OPER))
651      return ERR_OPERONLYCHAN;
652  
653    if (chptr->mode.mode & MODE_INVITEONLY)
654 <    if (!dlinkFind(&source_p->connection->invited, chptr))
655 <      if (!find_bmask(source_p, &chptr->invexlist))
654 >    if (!dlinkFind(&client_p->connection->invited, chptr))
655 >      if (!find_bmask(client_p, &chptr->invexlist))
656          return ERR_INVITEONLYCHAN;
657  
658    if (chptr->mode.key[0] && (!key || strcmp(chptr->mode.key, key)))
# Line 667 | Line 662 | can_join(struct Client *source_p, const
662        chptr->mode.limit)
663      return ERR_CHANNELISFULL;
664  
665 <  if (is_banned(chptr, source_p))
665 >  if (is_banned(chptr, client_p))
666      return ERR_BANNEDFROMCHAN;
667  
668    return 0;
# Line 736 | Line 731 | msg_has_ctrls(const char *message)
731  
732   /*! Tests if a client can send to a channel
733   * \param chptr    Pointer to Channel struct
734 < * \param source_p Pointer to Client struct
734 > * \param client_p Pointer to Client struct
735   * \param member   Pointer to Membership struct (can be NULL)
736   * \param message  The actual message string the client wants to send
737   * \return CAN_SEND_OPV if op or voiced on channel\n
# Line 744 | Line 739 | msg_has_ctrls(const char *message)
739   *         ERR_CANNOTSENDTOCHAN or ERR_NEEDREGGEDNICK if they cannot send to channel\n
740   */
741   int
742 < can_send(struct Channel *chptr, struct Client *source_p,
743 <         struct Membership *member, const char *message)
742 > can_send(struct Channel *chptr, struct Client *client_p,
743 >         struct Membership *member, const char *message, int notice)
744   {
745    const struct MaskItem *conf = NULL;
746  
747 <  if (IsServer(source_p) || HasFlag(source_p, FLAGS_SERVICE))
747 >  if (IsServer(client_p) || HasFlag(client_p, FLAGS_SERVICE))
748      return CAN_SEND_OPV;
749  
750 <  if (MyClient(source_p) && !IsExemptResv(source_p))
751 <    if (!(HasUMode(source_p, UMODE_OPER) && ConfigGeneral.oper_pass_resv))
752 <      if ((conf = match_find_resv(chptr->name)) && !resv_find_exempt(source_p, conf))
750 >  if (MyClient(client_p) && !HasFlag(client_p, FLAGS_EXEMPTRESV))
751 >    if (!(HasUMode(client_p, UMODE_OPER) && HasOFlag(client_p, OPER_FLAG_JOIN_RESV)))
752 >      if ((conf = match_find_resv(chptr->name)) && !resv_find_exempt(client_p, conf))
753          return ERR_CANNOTSENDTOCHAN;
754  
755    if ((chptr->mode.mode & MODE_NOCTRL) && msg_has_ctrls(message))
# Line 764 | Line 759 | can_send(struct Channel *chptr, struct C
759      if (*message == '\001' && strncmp(message + 1, "ACTION ", 7))
760        return ERR_NOCTCP;
761  
762 <  if (member || (member = find_channel_link(source_p, chptr)))
762 >  if (member || (member = find_channel_link(client_p, chptr)))
763      if (member->flags & (CHFL_CHANOP | CHFL_HALFOP | CHFL_VOICE))
764        return CAN_SEND_OPV;
765  
# Line 774 | Line 769 | can_send(struct Channel *chptr, struct C
769    if (chptr->mode.mode & MODE_MODERATED)
770      return ERR_CANNOTSENDTOCHAN;
771  
772 <  if ((chptr->mode.mode & MODE_MODREG) && !HasUMode(source_p, UMODE_REGISTERED))
772 >  if ((chptr->mode.mode & MODE_MODREG) && !HasUMode(client_p, UMODE_REGISTERED))
773      return ERR_NEEDREGGEDNICK;
774  
775 +  if ((chptr->mode.mode & MODE_NONOTICE) && notice)
776 +    return ERR_CANNOTSENDTOCHAN;
777 +
778    /* Cache can send if banned */
779 <  if (MyClient(source_p))
779 >  if (MyClient(client_p))
780    {
781      if (member)
782      {
# Line 787 | Line 785 | can_send(struct Channel *chptr, struct C
785  
786        if (!(member->flags & CHFL_BAN_CHECKED))
787        {
788 <        if (is_banned(chptr, source_p))
788 >        if (is_banned(chptr, client_p))
789          {
790            member->flags |= (CHFL_BAN_CHECKED | CHFL_BAN_SILENCED);
791            return ERR_CANNOTSENDTOCHAN;
# Line 796 | Line 794 | can_send(struct Channel *chptr, struct C
794          member->flags |= CHFL_BAN_CHECKED;
795        }
796      }
797 <    else if (is_banned(chptr, source_p))
797 >    else if (is_banned(chptr, client_p))
798        return ERR_CANNOTSENDTOCHAN;
799    }
800  
# Line 806 | Line 804 | can_send(struct Channel *chptr, struct C
804   /*! \brief Updates the client's oper_warn_count_down, warns the
805   *         IRC operators if necessary, and updates
806   *         join_leave_countdown as needed.
807 < * \param source_p Pointer to struct Client to check
807 > * \param client_p Pointer to struct Client to check
808   * \param name     Channel name or NULL if this is a part.
809   */
810   void
811 < check_spambot_warning(struct Client *source_p, const char *name)
811 > check_spambot_warning(struct Client *client_p, const char *name)
812   {
813    int t_delta = 0;
814    int decrement_count = 0;
815  
816    if ((GlobalSetOptions.spam_num &&
817 <       (source_p->connection->join_leave_count >=
817 >       (client_p->connection->join_leave_count >=
818          GlobalSetOptions.spam_num)))
819    {
820 <    if (source_p->connection->oper_warn_count_down > 0)
821 <      source_p->connection->oper_warn_count_down--;
820 >    if (client_p->connection->oper_warn_count_down > 0)
821 >      client_p->connection->oper_warn_count_down--;
822      else
823 <      source_p->connection->oper_warn_count_down = 0;
823 >      client_p->connection->oper_warn_count_down = 0;
824  
825 <    if (source_p->connection->oper_warn_count_down == 0)
825 >    if (client_p->connection->oper_warn_count_down == 0)
826      {
827        /* It's already known as a possible spambot */
828        if (name)
829          sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE,
830                               "User %s (%s@%s) trying to join %s is a possible spambot",
831 <                             source_p->name, source_p->username,
832 <                             source_p->host, name);
831 >                             client_p->name, client_p->username,
832 >                             client_p->host, name);
833        else
834          sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE,
835                               "User %s (%s@%s) is a possible spambot",
836 <                             source_p->name, source_p->username,
837 <                             source_p->host);
838 <      source_p->connection->oper_warn_count_down = OPER_SPAM_COUNTDOWN;
836 >                             client_p->name, client_p->username,
837 >                             client_p->host);
838 >      client_p->connection->oper_warn_count_down = OPER_SPAM_COUNTDOWN;
839      }
840    }
841    else
842    {
843 <    if ((t_delta = (CurrentTime - source_p->connection->last_leave_time)) >
843 >    if ((t_delta = (CurrentTime - client_p->connection->last_leave_time)) >
844           JOIN_LEAVE_COUNT_EXPIRE_TIME)
845      {
846        decrement_count = (t_delta / JOIN_LEAVE_COUNT_EXPIRE_TIME);
847  
848 <      if (decrement_count > source_p->connection->join_leave_count)
849 <        source_p->connection->join_leave_count = 0;
848 >      if (decrement_count > client_p->connection->join_leave_count)
849 >        client_p->connection->join_leave_count = 0;
850        else
851 <        source_p->connection->join_leave_count -= decrement_count;
851 >        client_p->connection->join_leave_count -= decrement_count;
852      }
853      else
854      {
855 <      if ((CurrentTime - (source_p->connection->last_join_time)) <
855 >      if ((CurrentTime - (client_p->connection->last_join_time)) <
856            GlobalSetOptions.spam_time)
857 <        source_p->connection->join_leave_count++;  /* It's a possible spambot */
857 >        client_p->connection->join_leave_count++;  /* It's a possible spambot */
858      }
859  
860      if (name)
861 <      source_p->connection->last_join_time = CurrentTime;
861 >      client_p->connection->last_join_time = CurrentTime;
862      else
863 <      source_p->connection->last_leave_time = CurrentTime;
866 <  }
867 < }
868 <
869 < /*! \brief Compares usercount and servercount against their split
870 < *         values and adjusts splitmode accordingly
871 < * \param unused Unused address pointer
872 < */
873 < void
874 < check_splitmode(void *unused)
875 < {
876 <  if (splitchecking && (ConfigChannel.no_join_on_split ||
877 <                        ConfigChannel.no_create_on_split))
878 <  {
879 <    const unsigned int server = dlink_list_length(&global_server_list);
880 <
881 <    if (!splitmode && ((server < split_servers) || (Count.total < split_users)))
882 <    {
883 <      splitmode = 1;
884 <
885 <      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
886 <                           "Network split, activating splitmode");
887 <      event_add(&splitmode_event, NULL);
888 <    }
889 <    else if (splitmode && (server >= split_servers) && (Count.total >= split_users))
890 <    {
891 <      splitmode = 0;
892 <
893 <      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
894 <                           "Network rejoined, deactivating splitmode");
895 <      event_delete(&splitmode_event);
896 <    }
863 >      client_p->connection->last_leave_time = CurrentTime;
864    }
865   }
866  
# Line 927 | Line 894 | channel_set_topic(struct Channel *chptr,
894   *                anti spambot code.
895   */
896   void
897 < channel_do_join_0(struct Client *source_p)
897 > channel_do_join_0(struct Client *client_p)
898   {
899    dlink_node *node = NULL, *node_next = NULL;
900  
901 <  if (source_p->channel.head)
902 <    if (MyConnect(source_p) && !HasUMode(source_p, UMODE_OPER))
903 <      check_spambot_warning(source_p, NULL);
901 >  if (client_p->channel.head)
902 >    if (MyConnect(client_p) && !HasUMode(client_p, UMODE_OPER))
903 >      check_spambot_warning(client_p, NULL);
904  
905 <  DLINK_FOREACH_SAFE(node, node_next, source_p->channel.head)
905 >  DLINK_FOREACH_SAFE(node, node_next, client_p->channel.head)
906    {
907      struct Channel *chptr = ((struct Membership *)node->data)->chptr;
908  
909 <    sendto_server(source_p, 0, 0, ":%s PART %s",
910 <                  source_p->id, chptr->name);
911 <    sendto_channel_local(0, chptr, ":%s!%s@%s PART %s",
912 <                         source_p->name, source_p->username,
913 <                         source_p->host, chptr->name);
909 >    sendto_server(client_p, 0, 0, ":%s PART %s",
910 >                  client_p->id, chptr->name);
911 >    sendto_channel_local(NULL, chptr, 0, 0, 0, ":%s!%s@%s PART %s",
912 >                         client_p->name, client_p->username,
913 >                         client_p->host, chptr->name);
914  
915      remove_user_from_channel(node->data);
916    }
917   }
918  
919   static char *
920 < channel_find_last0(struct Client *source_p, char *chanlist)
920 > channel_find_last0(struct Client *client_p, char *chanlist)
921   {
922    int join0 = 0;
923  
# Line 975 | Line 942 | channel_find_last0(struct Client *source
942    }
943  
944    if (join0)
945 <    channel_do_join_0(source_p);
945 >    channel_do_join_0(client_p);
946  
947    return chanlist;
948   }
949  
950   void
951 < channel_do_join(struct Client *source_p, char *channel, char *key_list)
951 > channel_do_join(struct Client *client_p, char *channel, char *key_list)
952   {
953    char *p = NULL;
954    char *chan = NULL;
955    char *chan_list = NULL;
956    struct Channel *chptr = NULL;
957    struct MaskItem *conf = NULL;
958 <  const struct ClassItem *const class = get_class_ptr(&source_p->connection->confs);
958 >  const struct ClassItem *const class = get_class_ptr(&client_p->connection->confs);
959    int i = 0;
960    unsigned int flags = 0;
961  
962 <  assert(IsClient(source_p));
962 >  assert(IsClient(client_p));
963  
964 <  chan_list = channel_find_last0(source_p, channel);
964 >  chan_list = channel_find_last0(client_p, channel);
965  
966 <  for (chan = strtoken(&p, chan_list, ","); chan;
967 <       chan = strtoken(&p,      NULL, ","))
966 >  for (chan = strtok_r(chan_list, ",", &p); chan;
967 >       chan = strtok_r(NULL,      ",", &p))
968    {
969      const char *key = NULL;
970  
# Line 1009 | Line 976 | channel_do_join(struct Client *source_p,
976      if (key && *key == '\0')
977        key = NULL;
978  
979 <    if (!check_channel_name(chan, 1))
979 >    if (!channel_check_name(chan, 1))
980      {
981 <      sendto_one_numeric(source_p, &me, ERR_BADCHANNAME, chan);
981 >      sendto_one_numeric(client_p, &me, ERR_BADCHANNAME, chan);
982        continue;
983      }
984  
985 <    if (!IsExemptResv(source_p) &&
986 <        !(HasUMode(source_p, UMODE_OPER) && ConfigGeneral.oper_pass_resv) &&
987 <        ((conf = match_find_resv(chan)) && !resv_find_exempt(source_p, conf)))
985 >    if (!HasFlag(client_p, FLAGS_EXEMPTRESV) &&
986 >        !(HasUMode(client_p, UMODE_OPER) && HasOFlag(client_p, OPER_FLAG_JOIN_RESV)) &&
987 >        ((conf = match_find_resv(chan)) && !resv_find_exempt(client_p, conf)))
988      {
989        ++conf->count;
990 <      sendto_one_numeric(source_p, &me, ERR_CHANBANREASON, chan, conf->reason);
990 >      sendto_one_numeric(client_p, &me, ERR_CHANBANREASON, chan, conf->reason);
991        sendto_realops_flags(UMODE_REJ, L_ALL, SEND_NOTICE,
992                             "Forbidding reserved channel %s from user %s",
993 <                           chan, get_client_name(source_p, HIDE_IP));
993 >                           chan, get_client_name(client_p, HIDE_IP));
994        continue;
995      }
996  
997 <    if (dlink_list_length(&source_p->channel) >=
997 >    if (dlink_list_length(&client_p->channel) >=
998          ((class->max_channels) ? class->max_channels : ConfigChannel.max_channels))
999      {
1000 <      sendto_one_numeric(source_p, &me, ERR_TOOMANYCHANNELS, chan);
1000 >      sendto_one_numeric(client_p, &me, ERR_TOOMANYCHANNELS, chan);
1001        break;
1002      }
1003  
1004      if ((chptr = hash_find_channel(chan)))
1005      {
1006 <      if (IsMember(source_p, chptr))
1006 >      if (IsMember(client_p, chptr))
1007          continue;
1008  
1042      if (splitmode && !HasUMode(source_p, UMODE_OPER) &&
1043          ConfigChannel.no_join_on_split)
1044      {
1045        sendto_one_numeric(source_p, &me, ERR_UNAVAILRESOURCE, chptr->name);
1046        continue;
1047      }
1048
1009        /*
1010         * can_join checks for +i key, bans.
1011         */
1012 <      if ((i = can_join(source_p, chptr, key)))
1012 >      if ((i = can_join(client_p, chptr, key)))
1013        {
1014 <        sendto_one_numeric(source_p, &me, i, chptr->name);
1014 >        sendto_one_numeric(client_p, &me, i, chptr->name);
1015          continue;
1016        }
1017  
# Line 1066 | Line 1026 | channel_do_join(struct Client *source_p,
1026      }
1027      else
1028      {
1069      if (splitmode && !HasUMode(source_p, UMODE_OPER) &&
1070          (ConfigChannel.no_create_on_split || ConfigChannel.no_join_on_split))
1071      {
1072        sendto_one_numeric(source_p, &me, ERR_UNAVAILRESOURCE, chan);
1073        continue;
1074      }
1075
1029        flags = CHFL_CHANOP;
1030 <      chptr = make_channel(chan);
1030 >      chptr = channel_make(chan);
1031      }
1032  
1033 <    if (!HasUMode(source_p, UMODE_OPER))
1034 <      check_spambot_warning(source_p, chptr->name);
1033 >    if (!HasUMode(client_p, UMODE_OPER))
1034 >      check_spambot_warning(client_p, chptr->name);
1035  
1036 <    add_user_to_channel(chptr, source_p, flags, 1);
1036 >    add_user_to_channel(chptr, client_p, flags, 1);
1037  
1038      /*
1039       * Set timestamp if appropriate, and propagate
# Line 1091 | Line 1044 | channel_do_join(struct Client *source_p,
1044        chptr->mode.mode |= MODE_TOPICLIMIT;
1045        chptr->mode.mode |= MODE_NOPRIVMSGS;
1046  
1047 <      sendto_server(source_p, 0, 0, ":%s SJOIN %lu %s +nt :@%s",
1048 <                    me.id, (unsigned long)chptr->creationtime,
1049 <                    chptr->name, source_p->id);
1047 >      sendto_server(client_p, 0, 0, ":%s SJOIN %ju %s +nt :@%s",
1048 >                    me.id, chptr->creationtime,
1049 >                    chptr->name, client_p->id);
1050  
1051        /*
1052         * Notify all other users on the new channel
1053         */
1054 <      sendto_channel_local_butone(NULL, CAP_EXTENDED_JOIN, 0, chptr, ":%s!%s@%s JOIN %s %s :%s",
1055 <                                  source_p->name, source_p->username,
1056 <                                  source_p->host, chptr->name,
1057 <                                  (!IsDigit(source_p->account[0]) && source_p->account[0] != '*') ? source_p->account : "*",
1058 <                                  source_p->info);
1059 <      sendto_channel_local_butone(NULL, 0, CAP_EXTENDED_JOIN, chptr, ":%s!%s@%s JOIN :%s",
1060 <                                  source_p->name, source_p->username,
1108 <                                  source_p->host, chptr->name);
1109 <      sendto_channel_local(0, chptr, ":%s MODE %s +nt",
1054 >      sendto_channel_local(NULL, chptr, 0, CAP_EXTENDED_JOIN, 0, ":%s!%s@%s JOIN %s %s :%s",
1055 >                           client_p->name, client_p->username,
1056 >                           client_p->host, chptr->name, client_p->account, client_p->info);
1057 >      sendto_channel_local(NULL, chptr, 0, 0, CAP_EXTENDED_JOIN, ":%s!%s@%s JOIN :%s",
1058 >                           client_p->name, client_p->username,
1059 >                           client_p->host, chptr->name);
1060 >      sendto_channel_local(NULL, chptr, 0, 0, 0, ":%s MODE %s +nt",
1061                             me.name, chptr->name);
1062  
1063 <      if (source_p->away[0])
1064 <        sendto_channel_local_butone(source_p, CAP_AWAY_NOTIFY, 0, chptr,
1065 <                                    ":%s!%s@%s AWAY :%s",
1066 <                                    source_p->name, source_p->username,
1067 <                                    source_p->host, source_p->away);
1063 >      if (client_p->away[0])
1064 >        sendto_channel_local(client_p, chptr, 0, CAP_AWAY_NOTIFY, 0,
1065 >                             ":%s!%s@%s AWAY :%s",
1066 >                             client_p->name, client_p->username,
1067 >                             client_p->host, client_p->away);
1068      }
1069      else
1070      {
1071 <      sendto_server(source_p, 0, 0, ":%s JOIN %lu %s +",
1072 <                    source_p->id, (unsigned long)chptr->creationtime,
1071 >      sendto_server(client_p, 0, 0, ":%s JOIN %ju %s +",
1072 >                    client_p->id, chptr->creationtime,
1073                      chptr->name);
1074  
1075 <      sendto_channel_local_butone(NULL, CAP_EXTENDED_JOIN, 0, chptr, ":%s!%s@%s JOIN %s %s :%s",
1076 <                                  source_p->name, source_p->username,
1077 <                                  source_p->host, chptr->name,
1078 <                                  (!IsDigit(source_p->account[0]) && source_p->account[0] != '*') ? source_p->account : "*",
1079 <                                  source_p->info);
1080 <      sendto_channel_local_butone(NULL, 0, CAP_EXTENDED_JOIN, chptr, ":%s!%s@%s JOIN :%s",
1081 <                                  source_p->name, source_p->username,
1082 <                                  source_p->host, chptr->name);
1083 <
1084 <      if (source_p->away[0])
1085 <        sendto_channel_local_butone(source_p, CAP_AWAY_NOTIFY, 0, chptr,
1086 <                                    ":%s!%s@%s AWAY :%s",
1136 <                                    source_p->name, source_p->username,
1137 <                                    source_p->host, source_p->away);
1075 >      sendto_channel_local(NULL, chptr, 0, CAP_EXTENDED_JOIN, 0, ":%s!%s@%s JOIN %s %s :%s",
1076 >                           client_p->name, client_p->username,
1077 >                           client_p->host, chptr->name, client_p->account, client_p->info);
1078 >      sendto_channel_local(NULL, chptr, 0, 0, CAP_EXTENDED_JOIN, ":%s!%s@%s JOIN :%s",
1079 >                           client_p->name, client_p->username,
1080 >                           client_p->host, chptr->name);
1081 >
1082 >      if (client_p->away[0])
1083 >        sendto_channel_local(client_p, chptr, 0, CAP_AWAY_NOTIFY, 0,
1084 >                             ":%s!%s@%s AWAY :%s",
1085 >                             client_p->name, client_p->username,
1086 >                             client_p->host, client_p->away);
1087      }
1088  
1089 <    del_invite(chptr, source_p);
1089 >    del_invite(chptr, client_p);
1090  
1091      if (chptr->topic[0])
1092      {
1093 <      sendto_one_numeric(source_p, &me, RPL_TOPIC, chptr->name, chptr->topic);
1094 <      sendto_one_numeric(source_p, &me, RPL_TOPICWHOTIME, chptr->name,
1093 >      sendto_one_numeric(client_p, &me, RPL_TOPIC, chptr->name, chptr->topic);
1094 >      sendto_one_numeric(client_p, &me, RPL_TOPICWHOTIME, chptr->name,
1095                           chptr->topic_info, chptr->topic_time);
1096      }
1097  
1098 <    channel_member_names(source_p, chptr, 1);
1098 >    channel_member_names(client_p, chptr, 1);
1099  
1100 <    source_p->connection->last_join_time = CurrentTime;
1100 >    client_p->connection->last_join_time = CurrentTime;
1101    }
1102   }
1103  
1104   /*! \brief Removes a client from a specific channel
1105 < * \param source_p Pointer to source client to remove
1105 > * \param client_p Pointer to source client to remove
1106   * \param name     Name of channel to remove from
1107   * \param reason   Part reason to show
1108   */
1109   static void
1110 < channel_part_one_client(struct Client *source_p, const char *name, const char *reason)
1110 > channel_part_one_client(struct Client *client_p, const char *name, const char *reason)
1111   {
1112    struct Channel *chptr = NULL;
1113    struct Membership *member = NULL;
1114  
1115    if ((chptr = hash_find_channel(name)) == NULL)
1116    {
1117 <    sendto_one_numeric(source_p, &me, ERR_NOSUCHCHANNEL, name);
1117 >    sendto_one_numeric(client_p, &me, ERR_NOSUCHCHANNEL, name);
1118      return;
1119    }
1120  
1121 <  if ((member = find_channel_link(source_p, chptr)) == NULL)
1121 >  if ((member = find_channel_link(client_p, chptr)) == NULL)
1122    {
1123 <    sendto_one_numeric(source_p, &me, ERR_NOTONCHANNEL, chptr->name);
1123 >    sendto_one_numeric(client_p, &me, ERR_NOTONCHANNEL, chptr->name);
1124      return;
1125    }
1126  
1127 <  if (MyConnect(source_p) && !HasUMode(source_p, UMODE_OPER))
1128 <    check_spambot_warning(source_p, NULL);
1127 >  if (MyConnect(client_p) && !HasUMode(client_p, UMODE_OPER))
1128 >    check_spambot_warning(client_p, NULL);
1129  
1130    /*
1131     * Remove user from the old channel (if any)
1132     * only allow /part reasons in -m chans
1133     */
1134 <  if (*reason && (!MyConnect(source_p) ||
1135 <      ((can_send(chptr, source_p, member, reason) &&
1136 <       (source_p->connection->firsttime + ConfigGeneral.anti_spam_exit_message_time)
1137 <        < CurrentTime))))
1138 <  {
1139 <    sendto_server(source_p, 0, 0, ":%s PART %s :%s",
1140 <                  source_p->id, chptr->name, reason);
1141 <    sendto_channel_local(0, chptr, ":%s!%s@%s PART %s :%s",
1142 <                         source_p->name, source_p->username,
1143 <                         source_p->host, chptr->name, reason);
1134 >  if (*reason && (!MyConnect(client_p) ||
1135 >      ((client_p->connection->firsttime +
1136 >        ConfigGeneral.anti_spam_exit_message_time) < CurrentTime &&
1137 >       can_send(chptr, client_p, member, reason, 0) < 0)))
1138 >  {
1139 >    sendto_server(client_p, 0, 0, ":%s PART %s :%s",
1140 >                  client_p->id, chptr->name, reason);
1141 >    sendto_channel_local(NULL, chptr, 0, 0, 0, ":%s!%s@%s PART %s :%s",
1142 >                         client_p->name, client_p->username,
1143 >                         client_p->host, chptr->name, reason);
1144    }
1145    else
1146    {
1147 <    sendto_server(source_p, 0, 0, ":%s PART %s",
1148 <                  source_p->id, chptr->name);
1149 <    sendto_channel_local(0, chptr, ":%s!%s@%s PART %s",
1150 <                         source_p->name, source_p->username,
1151 <                         source_p->host, chptr->name);
1147 >    sendto_server(client_p, 0, 0, ":%s PART %s",
1148 >                  client_p->id, chptr->name);
1149 >    sendto_channel_local(NULL, chptr, 0, 0, 0, ":%s!%s@%s PART %s",
1150 >                         client_p->name, client_p->username,
1151 >                         client_p->host, chptr->name);
1152    }
1153  
1154    remove_user_from_channel(member);
1155   }
1156  
1157   void
1158 < channel_do_part(struct Client *source_p, char *channel, const char *reason)
1158 > channel_do_part(struct Client *client_p, char *channel, const char *reason)
1159   {
1160    char *p = NULL, *name = NULL;
1161    char buf[KICKLEN + 1] = "";
1162  
1163 <  assert(IsClient(source_p));
1163 >  assert(IsClient(client_p));
1164  
1165    if (!EmptyString(reason))
1166      strlcpy(buf, reason, sizeof(buf));
1167  
1168 <  for (name = strtoken(&p, channel, ","); name;
1169 <       name = strtoken(&p,    NULL, ","))
1170 <    channel_part_one_client(source_p, name, buf);
1168 >  for (name = strtok_r(channel, ",", &p); name;
1169 >       name = strtok_r(NULL,    ",", &p))
1170 >    channel_part_one_client(client_p, name, buf);
1171   }

Diff Legend

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