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 8367 by michael, Mon Mar 5 19:51:42 2018 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-2018 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 31 | Line 31
31   #include "client.h"
32   #include "hash.h"
33   #include "conf.h"
34 + #include "conf_resv.h"
35   #include "hostmask.h"
36   #include "irc_string.h"
37   #include "ircd.h"
# Line 41 | Line 42
42   #include "memory.h"
43   #include "mempool.h"
44   #include "misc.h"
44 #include "resv.h"
45  
46  
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 <
57 < static mp_pool_t *member_pool, *channel_pool;
50 > static mp_pool_t *member_pool, *channel_pool, *invite_pool;
51  
52  
53   /*! \brief Initializes the channel blockheap, adds known channel CAPAB
# Line 62 | Line 55 | static mp_pool_t *member_pool, *channel_
55   void
56   channel_init(void)
57   {
58 <  add_capability("EX", CAP_EX);
66 <  add_capability("IE", CAP_IE);
67 <
58 >  invite_pool = mp_pool_new(sizeof(struct Invite), MP_CHUNK_SIZE_INVITE);
59    channel_pool = mp_pool_new(sizeof(struct Channel), MP_CHUNK_SIZE_CHANNEL);
60    ban_pool = mp_pool_new(sizeof(struct Ban), MP_CHUNK_SIZE_BAN);
61    member_pool = mp_pool_new(sizeof(struct Membership), MP_CHUNK_SIZE_MEMBER);
# Line 73 | Line 64 | channel_init(void)
64   /*! \brief Adds a user to a channel by adding another link to the
65   *         channels member chain.
66   * \param chptr      Pointer to channel to add client to
67 < * \param who        Pointer to client (who) to add
67 > * \param client_p   Pointer to client (who) to add
68   * \param flags      Flags for chanops etc
69   * \param flood_ctrl Whether to count this join in flood calculations
70   */
71   void
72 < add_user_to_channel(struct Channel *chptr, struct Client *who,
72 > add_user_to_channel(struct Channel *chptr, struct Client *client_p,
73                      unsigned int flags, int flood_ctrl)
74   {
75 <  struct Membership *member = NULL;
75 >  assert(IsClient(client_p));
76  
77 <  assert(IsClient(who));
87 <
88 <  if (GlobalSetOptions.joinfloodtime > 0)
77 >  if (GlobalSetOptions.joinfloodtime)
78    {
79      if (flood_ctrl)
80        ++chptr->number_joined;
# Line 108 | Line 97 | add_user_to_channel(struct Channel *chpt
97          SetJoinFloodNoticed(chptr);
98          sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE,
99                               "Possible Join Flooder %s on %s target: %s",
100 <                             get_client_name(who, HIDE_IP),
101 <                             who->servptr->name, chptr->name);
100 >                             client_get_name(client_p, HIDE_IP),
101 >                             client_p->servptr->name, chptr->name);
102        }
103      }
104  
105      chptr->last_join_time = CurrentTime;
106    }
107  
108 <  member = mp_pool_get(member_pool);
109 <  member->client_p = who;
108 >  struct Membership *member = mp_pool_get(member_pool);
109 >  member->client_p = client_p;
110    member->chptr = chptr;
111    member->flags = flags;
112  
113    dlinkAdd(member, &member->channode, &chptr->members);
114  
115 <  if (MyConnect(who))
115 >  if (MyConnect(client_p))
116      dlinkAdd(member, &member->locchannode, &chptr->locmembers);
117  
118 <  dlinkAdd(member, &member->usernode, &who->channel);
118 >  dlinkAdd(member, &member->usernode, &client_p->channel);
119   }
120  
121   /*! \brief Deletes an user from a channel by removing a link in the
# Line 149 | Line 138 | remove_user_from_channel(struct Membersh
138    mp_pool_release(member);
139  
140    if (chptr->members.head == NULL)
141 <    destroy_channel(chptr);
141 >    channel_free(chptr);
142   }
143  
144 < /* send_members()
144 > /* channel_send_members()
145   *
146   * inputs       -
147   * output       - NONE
148   * side effects -
149   */
150   static void
151 < send_members(struct Client *client_p, const struct Channel *chptr,
152 <             char *modebuf, char *parabuf)
151 > channel_send_members(struct Client *client_p, const struct Channel *chptr,
152 >                     const char *modebuf, const char *parabuf)
153   {
154 +  dlink_node *node;
155    char buf[IRCD_BUFSIZE] = "";
166  const dlink_node *node = NULL;
156    int tlen;              /* length of text to append */
157    char *t, *start;       /* temp char pointer */
158  
159 <  start = t = buf + snprintf(buf, sizeof(buf), ":%s SJOIN %lu %s %s %s:",
160 <                             me.id, (unsigned long)chptr->creationtime,
159 >  start = t = buf + snprintf(buf, sizeof(buf), ":%s SJOIN %ju %s %s %s:",
160 >                             me.id, chptr->creationtime,
161                               chptr->name, modebuf, parabuf);
162  
163    DLINK_FOREACH(node, chptr->members.head)
# Line 222 | Line 211 | send_members(struct Client *client_p, co
211   * \param flag     Char flag flagging type of mode. Currently this can be 'b', e' or 'I'
212   */
213   static void
214 < send_mode_list(struct Client *client_p, const struct Channel *chptr,
215 <               const dlink_list *list, const char flag)
214 > channel_send_mask_list(struct Client *client_p, const struct Channel *chptr,
215 >                       const dlink_list *list, const char flag)
216   {
217 <  const dlink_node *node = NULL;
217 >  dlink_node *node;
218    char mbuf[IRCD_BUFSIZE] = "";
219    char pbuf[IRCD_BUFSIZE] = "";
220    int tlen, mlen, cur_len;
221    char *pp = pbuf;
222  
223 <  if (!list->length)
223 >  if (!dlink_list_length(list))
224      return;
225  
226 <  mlen = snprintf(mbuf, sizeof(mbuf), ":%s BMASK %lu %s %c :", me.id,
227 <                  (unsigned long)chptr->creationtime, chptr->name, flag);
226 >  mlen = snprintf(mbuf, sizeof(mbuf), ":%s BMASK %ju %s %c :", me.id,
227 >                  chptr->creationtime, chptr->name, flag);
228    cur_len = mlen;
229  
230    DLINK_FOREACH(node, list->head)
# Line 269 | Line 258 | send_mode_list(struct Client *client_p,
258   * \param chptr    Pointer to channel pointer
259   */
260   void
261 < send_channel_modes(struct Client *client_p, struct Channel *chptr)
261 > channel_send_modes(struct Client *client_p, struct Channel *chptr)
262   {
263    char modebuf[MODEBUFLEN] = "";
264    char parabuf[MODEBUFLEN] = "";
265  
266    channel_modes(chptr, client_p, modebuf, parabuf);
267 <  send_members(client_p, chptr, modebuf, parabuf);
267 >  channel_send_members(client_p, chptr, modebuf, parabuf);
268  
269 <  send_mode_list(client_p, chptr, &chptr->banlist, 'b');
270 <  send_mode_list(client_p, chptr, &chptr->exceptlist, 'e');
271 <  send_mode_list(client_p, chptr, &chptr->invexlist, 'I');
269 >  channel_send_mask_list(client_p, chptr, &chptr->banlist, 'b');
270 >  channel_send_mask_list(client_p, chptr, &chptr->exceptlist, 'e');
271 >  channel_send_mask_list(client_p, chptr, &chptr->invexlist, 'I');
272   }
273  
274   /*! \brief Check channel name for invalid characters
# Line 288 | Line 277 | send_channel_modes(struct Client *client
277   * \return 0 if invalid, 1 otherwise
278   */
279   int
280 < check_channel_name(const char *name, const int local)
280 > channel_check_name(const char *name, const int local)
281   {
282    const char *p = name;
283  
# Line 320 | Line 309 | remove_ban(struct Ban *ban, dlink_list *
309    mp_pool_release(ban);
310   }
311  
312 < /* free_channel_list()
312 > /* channel_free_mask_list()
313   *
314   * inputs       - pointer to dlink_list
315   * output       - NONE
316   * side effects -
317   */
318 < void
319 < free_channel_list(dlink_list *list)
318 > static void
319 > channel_free_mask_list(dlink_list *list)
320   {
321 <  dlink_node *node = NULL, *node_next = NULL;
322 <
323 <  DLINK_FOREACH_SAFE(node, node_next, list->head)
324 <    remove_ban(node->data, list);
321 >  while (list->head)
322 >  {
323 >    struct Ban *ban = list->head->data;
324 >    remove_ban(ban, list);
325 >  }
326   }
327  
328   /*! \brief Get Channel block for name (and allocate a new channel
# Line 341 | Line 331 | free_channel_list(dlink_list *list)
331   * \return Channel block
332   */
333   struct Channel *
334 < make_channel(const char *name)
334 > channel_make(const char *name)
335   {
346  struct Channel *chptr = NULL;
347
336    assert(!EmptyString(name));
337  
338 <  chptr = mp_pool_get(channel_pool);
351 <
338 >  struct Channel *chptr = mp_pool_get(channel_pool);
339    /* Doesn't hurt to set it here */
340    chptr->creationtime = CurrentTime;
341    chptr->last_join_time = CurrentTime;
342  
343 <  strlcpy(chptr->name, name, sizeof(chptr->name));
344 <  dlinkAdd(chptr, &chptr->node, &channel_list);
343 >  /* Cache channel name length to avoid repetitive strlen() calls. */
344 >  chptr->name_len = strlcpy(chptr->name, name, sizeof(chptr->name));
345 >  if (chptr->name_len >= sizeof(chptr->name))
346 >    chptr->name_len = sizeof(chptr->name) - 1;
347  
348 +  dlinkAdd(chptr, &chptr->node, &channel_list);
349    hash_add_channel(chptr);
350  
351    return chptr;
# Line 365 | Line 355 | make_channel(const char *name)
355   * \param chptr Channel pointer
356   */
357   void
358 < destroy_channel(struct Channel *chptr)
358 > channel_free(struct Channel *chptr)
359   {
360 <  clear_invites_channel(chptr);
360 >  clear_invite_list(&chptr->invites);
361  
362    /* Free ban/exception/invex lists */
363 <  free_channel_list(&chptr->banlist);
364 <  free_channel_list(&chptr->exceptlist);
365 <  free_channel_list(&chptr->invexlist);
363 >  channel_free_mask_list(&chptr->banlist);
364 >  channel_free_mask_list(&chptr->exceptlist);
365 >  channel_free_mask_list(&chptr->invexlist);
366  
367    dlinkDelete(&chptr->node, &channel_list);
368    hash_del_channel(chptr);
# Line 395 | Line 385 | channel_pub_or_secret(const struct Chann
385   }
386  
387   /*! \brief lists all names on given channel
388 < * \param source_p Pointer to client struct requesting names
388 > * \param client_p Pointer to client struct requesting names
389   * \param chptr    Pointer to channel block
390   * \param show_eon Show RPL_ENDOFNAMES numeric or not
391   *                 (don't want it with /names with no params)
392   */
393   void
394 < channel_member_names(struct Client *source_p, struct Channel *chptr,
394 > channel_member_names(struct Client *client_p, struct Channel *chptr,
395                       int show_eon)
396   {
397 <  const dlink_node *node = NULL;
397 >  dlink_node *node;
398    char buf[IRCD_BUFSIZE + 1] = "";
399    char *t = NULL, *start = NULL;
400    int tlen = 0;
401 <  const int is_member = IsMember(source_p, chptr);
402 <  const int multi_prefix = HasCap(source_p, CAP_MULTI_PREFIX) != 0;
403 <  const int uhnames = HasCap(source_p, CAP_UHNAMES) != 0;
401 >  const int is_member = IsMember(client_p, chptr);
402 >  const int multi_prefix = HasCap(client_p, CAP_MULTI_PREFIX) != 0;
403 >  const int uhnames = HasCap(client_p, CAP_UHNAMES) != 0;
404  
405 <  assert(IsClient(source_p));
405 >  assert(IsClient(client_p));
406  
407    if (PubChannel(chptr) || is_member)
408    {
409      t = buf + snprintf(buf, sizeof(buf), numeric_form(RPL_NAMREPLY),
410 <                       me.name, source_p->name,
410 >                       me.name, client_p->name,
411                         channel_pub_or_secret(chptr), chptr->name);
412      start = t;
413  
# Line 452 | Line 442 | channel_member_names(struct Client *sour
442        if (t + tlen - buf > IRCD_BUFSIZE - 2)
443        {
444          *(t - 1) = '\0';
445 <        sendto_one(source_p, "%s", buf);
445 >        sendto_one(client_p, "%s", buf);
446          t = start;
447        }
448  
# Line 468 | Line 458 | channel_member_names(struct Client *sour
458      if (tlen)
459      {
460        *(t - 1) = '\0';
461 <      sendto_one(source_p, "%s", buf);
461 >      sendto_one(client_p, "%s", buf);
462      }
463    }
464  
465    if (show_eon)
466 <    sendto_one_numeric(source_p, &me, RPL_ENDOFNAMES, chptr->name);
466 >    sendto_one_numeric(client_p, &me, RPL_ENDOFNAMES, chptr->name);
467   }
468  
469 < /*! \brief Adds client to invite list
470 < * \param chptr Pointer to channel block
481 < * \param who   Pointer to client to add invite to
482 < */
483 < void
484 < add_invite(struct Channel *chptr, struct Client *who)
469 > static struct Invite *
470 > find_invite(struct Channel *chptr, struct Client *client_p)
471   {
472 <  assert(IsClient(who));
472 >  dlink_node *node, *node_next;
473 >  dlink_list *list;
474  
475 <  del_invite(chptr, who);
475 >  /* Take the shortest of the two lists */
476 >  if (dlink_list_length(&client_p->connection->invited) < dlink_list_length(&chptr->invites))
477 >    list = &client_p->connection->invited;
478 >  else
479 >    list = &chptr->invites;
480  
481 <  /*
482 <   * Delete last link in chain if the list is max length
483 <   */
493 <  if (dlink_list_length(&who->connection->invited) >=
494 <      ConfigChannel.max_channels)
495 <    del_invite(who->connection->invited.tail->data, who);
481 >  DLINK_FOREACH_SAFE(node, node_next, list->head)
482 >  {
483 >    struct Invite *invite = node->data;
484  
485 <  /* Add client to channel invite list */
486 <  dlinkAdd(who, make_dlink_node(), &chptr->invites);
485 >    if (ConfigChannel.invite_expire_time &&
486 >        ConfigChannel.invite_expire_time + invite->when < CurrentTime)
487 >      del_invite(invite);
488 >    else if (invite->chptr == chptr && invite->client_p == client_p)
489 >      return invite;
490 >  }
491  
492 <  /* Add channel to the end of the client invite list */
501 <  dlinkAdd(chptr, make_dlink_node(), &who->connection->invited);
492 >  return NULL;
493   }
494  
495 < /*! \brief Delete Invite block from channel invite list
496 < *         and client invite list
497 < * \param chptr Pointer to Channel struct
507 < * \param who   Pointer to client to remove invites from
495 > /*! \brief Adds client to invite list
496 > * \param chptr    Pointer to channel block
497 > * \param client_p Pointer to client to add invite to
498   */
499   void
500 < del_invite(struct Channel *chptr, struct Client *who)
500 > add_invite(struct Channel *chptr, struct Client *client_p)
501   {
502 <  dlink_node *node = NULL;
502 >  struct Invite *invite = find_invite(chptr, client_p);
503 >  if (invite)
504 >    del_invite(invite);
505 >
506 >  invite = mp_pool_get(invite_pool);
507 >  invite->client_p = client_p;
508 >  invite->chptr = chptr;
509 >  invite->when = CurrentTime;
510 >
511 >  /* Delete last link in chain if the list is max length */
512 >  while (dlink_list_length(&client_p->connection->invited) &&
513 >         dlink_list_length(&client_p->connection->invited) >= ConfigChannel.max_invites)
514 >    del_invite(client_p->connection->invited.tail->data);
515  
516 <  if ((node = dlinkFindDelete(&who->connection->invited, chptr)))
517 <    free_dlink_node(node);
516 >  /* Add client to channel invite list */
517 >  dlinkAdd(invite, &invite->chan_node, &chptr->invites);
518  
519 <  if ((node = dlinkFindDelete(&chptr->invites, who)))
520 <    free_dlink_node(node);
519 >  /* Add channel to the end of the client invite list */
520 >  dlinkAdd(invite, &invite->user_node, &client_p->connection->invited);
521   }
522  
523 < /*! \brief Removes all invites of a specific channel
524 < * \param chptr Pointer to Channel struct
523 > /*! \brief Delete Invite block from channel invite list
524 > *         and client invite list
525 > * \param invite Pointer to Invite struct
526   */
527   void
528 < clear_invites_channel(struct Channel *chptr)
528 > del_invite(struct Invite *invite)
529   {
530 <  dlink_node *node = NULL, *node_next = NULL;
530 >  dlinkDelete(&invite->user_node, &invite->client_p->connection->invited);
531 >  dlinkDelete(&invite->chan_node, &invite->chptr->invites);
532  
533 <  DLINK_FOREACH_SAFE(node, node_next, chptr->invites.head)
534 <    del_invite(chptr, node->data);
533 >  /* Release memory pointed to by 'invite' */
534 >  mp_pool_release(invite);
535   }
536  
537 < /*! \brief Removes all invites of a specific client
538 < * \param source_p Pointer to Client struct
537 > /*! \brief Removes and frees all Invite blocks from a list
538 > * \param list Pointer to a dlink_list
539   */
540   void
541 < clear_invites_client(struct Client *source_p)
541 > clear_invite_list(dlink_list *list)
542   {
543 <  dlink_node *node = NULL, *node_next = NULL;
544 <
541 <  DLINK_FOREACH_SAFE(node, node_next, source_p->connection->invited.head)
542 <    del_invite(node->data, source_p);
543 >  while (list->head)
544 >    del_invite(list->head->data);
545   }
546  
547   /* get_member_status()
# Line 551 | Line 553 | clear_invites_client(struct Client *sour
553   * side effects -
554   *
555   * NOTE: Returned string is usually a static buffer
556 < * (like in get_client_name)
556 > * (like in client_get_name)
557   */
558   const char *
559   get_member_status(const struct Membership *member, const int combine)
560   {
561 <  static char buffer[4];  /* 4 for @%+\0 */
561 >  static char buffer[CMEMBER_STATUS_FLAGS_LEN + 1];  /* +1 for \0 */
562    char *p = buffer;
563  
564    if (member->flags & CHFL_CHANOP)
# Line 581 | Line 583 | get_member_status(const struct Membershi
583   }
584  
585   /*!
586 < * \param who  Pointer to Client to check
587 < * \param list Pointer to ban list to search
586 > * \param client_p Pointer to Client to check
587 > * \param list     Pointer to ban list to search
588   * \return 1 if ban found for given n!u\@h mask, 0 otherwise
589   */
590   static int
591 < find_bmask(const struct Client *who, const dlink_list *const list)
591 > find_bmask(const struct Client *client_p, const dlink_list *list)
592   {
593 <  const dlink_node *node = NULL;
593 >  dlink_node *node;
594  
595    DLINK_FOREACH(node, list->head)
596    {
597      const struct Ban *ban = node->data;
598  
599 <    if (!match(ban->name, who->name) && !match(ban->user, who->username))
599 >    if (!match(ban->name, client_p->name) && !match(ban->user, client_p->username))
600      {
601        switch (ban->type)
602        {
603          case HM_HOST:
604 <          if (!match(ban->host, who->host) || !match(ban->host, who->sockhost))
604 >          if (!match(ban->host, client_p->host) || !match(ban->host, client_p->sockhost))
605              return 1;
606            break;
607          case HM_IPV4:
608 <          if (who->connection->aftype == AF_INET)
609 <            if (match_ipv4(&who->connection->ip, &ban->addr, ban->bits))
608 >          if (client_p->connection->aftype == AF_INET)
609 >            if (match_ipv4(&client_p->connection->ip, &ban->addr, ban->bits))
610                return 1;
611            break;
612          case HM_IPV6:
613 <          if (who->connection->aftype == AF_INET6)
614 <            if (match_ipv6(&who->connection->ip, &ban->addr, ban->bits))
613 >          if (client_p->connection->aftype == AF_INET6)
614 >            if (match_ipv6(&client_p->connection->ip, &ban->addr, ban->bits))
615                return 1;
616            break;
617          default:
# Line 622 | Line 624 | find_bmask(const struct Client *who, con
624   }
625  
626   /*!
627 < * \param chptr Pointer to channel block
628 < * \param who   Pointer to client to check access fo
627 > * \param chptr    Pointer to channel block
628 > * \param client_p Pointer to client to check access fo
629   * \return 0 if not banned, 1 otherwise
630   */
631   int
632 < is_banned(const struct Channel *chptr, const struct Client *who)
632 > is_banned(const struct Channel *chptr, const struct Client *client_p)
633   {
634 <  if (find_bmask(who, &chptr->banlist))
635 <    if (!find_bmask(who, &chptr->exceptlist))
634 >  if (find_bmask(client_p, &chptr->banlist))
635 >    if (!find_bmask(client_p, &chptr->exceptlist))
636        return 1;
637  
638    return 0;
639   }
640  
641   /*! Tests if a client can join a certain channel
642 < * \param source_p Pointer to client attempting to join
642 > * \param client_p Pointer to client attempting to join
643   * \param chptr    Pointer to channel
644   * \param key      Key sent by client attempting to join if present
645   * \return ERR_BANNEDFROMCHAN, ERR_INVITEONLYCHAN, ERR_CHANNELISFULL
646   *         or 0 if allowed to join.
647   */
648 < int
649 < can_join(struct Client *source_p, const struct Channel *chptr, const char *key)
648 > static int
649 > can_join(struct Client *client_p, struct Channel *chptr, const char *key)
650   {
651 <  if ((chptr->mode.mode & MODE_SSLONLY) && !HasUMode(source_p, UMODE_SSL))
651 >  if (HasCMode(chptr, MODE_SSLONLY) && !HasUMode(client_p, UMODE_SSL))
652      return ERR_SSLONLYCHAN;
653  
654 <  if ((chptr->mode.mode & MODE_REGONLY) && !HasUMode(source_p, UMODE_REGISTERED))
654 >  if (HasCMode(chptr, MODE_REGONLY) && !HasUMode(client_p, UMODE_REGISTERED))
655      return ERR_NEEDREGGEDNICK;
656  
657 <  if ((chptr->mode.mode & MODE_OPERONLY) && !HasUMode(source_p, UMODE_OPER))
657 >  if (HasCMode(chptr, MODE_OPERONLY) && !HasUMode(client_p, UMODE_OPER))
658      return ERR_OPERONLYCHAN;
659  
660 <  if (chptr->mode.mode & MODE_INVITEONLY)
661 <    if (!dlinkFind(&source_p->connection->invited, chptr))
662 <      if (!find_bmask(source_p, &chptr->invexlist))
660 >  if (HasCMode(chptr, MODE_INVITEONLY))
661 >    if (!find_invite(chptr, client_p))
662 >      if (!find_bmask(client_p, &chptr->invexlist))
663          return ERR_INVITEONLYCHAN;
664  
665    if (chptr->mode.key[0] && (!key || strcmp(chptr->mode.key, key)))
# Line 667 | Line 669 | can_join(struct Client *source_p, const
669        chptr->mode.limit)
670      return ERR_CHANNELISFULL;
671  
672 <  if (is_banned(chptr, source_p))
672 >  if (is_banned(chptr, client_p))
673      return ERR_BANNEDFROMCHAN;
674  
675    return 0;
# Line 682 | Line 684 | has_member_flags(const struct Membership
684   struct Membership *
685   find_channel_link(struct Client *client_p, struct Channel *chptr)
686   {
687 <  dlink_node *node = NULL;
687 >  dlink_node *node;
688  
689    if (!IsClient(client_p))
690      return NULL;
# Line 736 | Line 738 | msg_has_ctrls(const char *message)
738  
739   /*! Tests if a client can send to a channel
740   * \param chptr    Pointer to Channel struct
741 < * \param source_p Pointer to Client struct
741 > * \param client_p Pointer to Client struct
742   * \param member   Pointer to Membership struct (can be NULL)
743   * \param message  The actual message string the client wants to send
744   * \return CAN_SEND_OPV if op or voiced on channel\n
# Line 744 | Line 746 | msg_has_ctrls(const char *message)
746   *         ERR_CANNOTSENDTOCHAN or ERR_NEEDREGGEDNICK if they cannot send to channel\n
747   */
748   int
749 < can_send(struct Channel *chptr, struct Client *source_p,
750 <         struct Membership *member, const char *message)
749 > can_send(struct Channel *chptr, struct Client *client_p,
750 >         struct Membership *member, const char *message, int notice)
751   {
752 <  const struct MaskItem *conf = NULL;
752 >  const struct ResvItem *resv = NULL;
753  
754 <  if (IsServer(source_p) || HasFlag(source_p, FLAGS_SERVICE))
754 >  if (IsServer(client_p) || HasFlag(client_p, FLAGS_SERVICE))
755      return CAN_SEND_OPV;
756  
757 <  if (MyClient(source_p) && !IsExemptResv(source_p))
758 <    if (!(HasUMode(source_p, UMODE_OPER) && ConfigGeneral.oper_pass_resv))
759 <      if ((conf = match_find_resv(chptr->name)) && !resv_find_exempt(source_p, conf))
757 >  if (MyConnect(client_p) && !HasFlag(client_p, FLAGS_EXEMPTRESV))
758 >    if (!(HasUMode(client_p, UMODE_OPER) && HasOFlag(client_p, OPER_FLAG_JOIN_RESV)))
759 >      if ((resv = resv_find(chptr->name, match)) && !resv_exempt_find(client_p, resv))
760          return ERR_CANNOTSENDTOCHAN;
761  
762 <  if ((chptr->mode.mode & MODE_NOCTRL) && msg_has_ctrls(message))
762 >  if (HasCMode(chptr, MODE_NOCTRL) && msg_has_ctrls(message))
763      return ERR_NOCTRLSONCHAN;
764  
765 <  if (chptr->mode.mode & MODE_NOCTCP)
765 >  if (HasCMode(chptr, MODE_NOCTCP))
766      if (*message == '\001' && strncmp(message + 1, "ACTION ", 7))
767        return ERR_NOCTCP;
768  
769 <  if (member || (member = find_channel_link(source_p, chptr)))
769 >  if (member || (member = find_channel_link(client_p, chptr)))
770      if (member->flags & (CHFL_CHANOP | CHFL_HALFOP | CHFL_VOICE))
771        return CAN_SEND_OPV;
772  
773 <  if (!member && (chptr->mode.mode & MODE_NOPRIVMSGS))
773 >  if (!member && HasCMode(chptr, MODE_NOPRIVMSGS))
774      return ERR_CANNOTSENDTOCHAN;
775  
776 <  if (chptr->mode.mode & MODE_MODERATED)
776 >  if (HasCMode(chptr, MODE_MODERATED))
777      return ERR_CANNOTSENDTOCHAN;
778  
779 <  if ((chptr->mode.mode & MODE_MODREG) && !HasUMode(source_p, UMODE_REGISTERED))
779 >  if (HasCMode(chptr, MODE_MODREG) && !HasUMode(client_p, UMODE_REGISTERED))
780      return ERR_NEEDREGGEDNICK;
781  
782 +  if (HasCMode(chptr, MODE_NONOTICE) && notice)
783 +    return ERR_CANNOTSENDTOCHAN;
784 +
785    /* Cache can send if banned */
786 <  if (MyClient(source_p))
786 >  if (MyConnect(client_p))
787    {
788      if (member)
789      {
# Line 787 | Line 792 | can_send(struct Channel *chptr, struct C
792  
793        if (!(member->flags & CHFL_BAN_CHECKED))
794        {
795 <        if (is_banned(chptr, source_p))
795 >        if (is_banned(chptr, client_p))
796          {
797            member->flags |= (CHFL_BAN_CHECKED | CHFL_BAN_SILENCED);
798            return ERR_CANNOTSENDTOCHAN;
# Line 796 | Line 801 | can_send(struct Channel *chptr, struct C
801          member->flags |= CHFL_BAN_CHECKED;
802        }
803      }
804 <    else if (is_banned(chptr, source_p))
804 >    else if (is_banned(chptr, client_p))
805        return ERR_CANNOTSENDTOCHAN;
806    }
807  
# Line 806 | Line 811 | can_send(struct Channel *chptr, struct C
811   /*! \brief Updates the client's oper_warn_count_down, warns the
812   *         IRC operators if necessary, and updates
813   *         join_leave_countdown as needed.
814 < * \param source_p Pointer to struct Client to check
814 > * \param client_p Pointer to struct Client to check
815   * \param name     Channel name or NULL if this is a part.
816   */
817   void
818 < check_spambot_warning(struct Client *source_p, const char *name)
818 > check_spambot_warning(struct Client *client_p, const char *name)
819   {
820 <  int t_delta = 0;
821 <  int decrement_count = 0;
817 <
818 <  if ((GlobalSetOptions.spam_num &&
819 <       (source_p->connection->join_leave_count >=
820 <        GlobalSetOptions.spam_num)))
820 >  if (GlobalSetOptions.spam_num &&
821 >      (client_p->connection->join_leave_count >= GlobalSetOptions.spam_num))
822    {
823 <    if (source_p->connection->oper_warn_count_down > 0)
824 <      source_p->connection->oper_warn_count_down--;
823 >    if (client_p->connection->oper_warn_count_down > 0)
824 >      client_p->connection->oper_warn_count_down--;
825      else
826 <      source_p->connection->oper_warn_count_down = 0;
826 >      client_p->connection->oper_warn_count_down = 0;
827  
828 <    if (source_p->connection->oper_warn_count_down == 0)
828 >    if (client_p->connection->oper_warn_count_down == 0)
829      {
830        /* It's already known as a possible spambot */
831        if (name)
832          sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE,
833                               "User %s (%s@%s) trying to join %s is a possible spambot",
834 <                             source_p->name, source_p->username,
835 <                             source_p->host, name);
834 >                             client_p->name, client_p->username,
835 >                             client_p->host, name);
836        else
837          sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE,
838                               "User %s (%s@%s) is a possible spambot",
839 <                             source_p->name, source_p->username,
840 <                             source_p->host);
841 <      source_p->connection->oper_warn_count_down = OPER_SPAM_COUNTDOWN;
839 >                             client_p->name, client_p->username,
840 >                             client_p->host);
841 >      client_p->connection->oper_warn_count_down = OPER_SPAM_COUNTDOWN;
842      }
843    }
844    else
845    {
846 <    if ((t_delta = (CurrentTime - source_p->connection->last_leave_time)) >
847 <         JOIN_LEAVE_COUNT_EXPIRE_TIME)
846 >    int t_delta = CurrentTime - client_p->connection->last_leave_time;
847 >    if (t_delta > JOIN_LEAVE_COUNT_EXPIRE_TIME)
848      {
849 <      decrement_count = (t_delta / JOIN_LEAVE_COUNT_EXPIRE_TIME);
850 <
851 <      if (decrement_count > source_p->connection->join_leave_count)
851 <        source_p->connection->join_leave_count = 0;
849 >      int decrement_count = (t_delta / JOIN_LEAVE_COUNT_EXPIRE_TIME);
850 >      if (decrement_count > client_p->connection->join_leave_count)
851 >        client_p->connection->join_leave_count = 0;
852        else
853 <        source_p->connection->join_leave_count -= decrement_count;
853 >        client_p->connection->join_leave_count -= decrement_count;
854      }
855      else
856      {
857 <      if ((CurrentTime - (source_p->connection->last_join_time)) <
857 >      if ((CurrentTime - (client_p->connection->last_join_time)) <
858            GlobalSetOptions.spam_time)
859 <        source_p->connection->join_leave_count++;  /* It's a possible spambot */
859 >        client_p->connection->join_leave_count++;  /* It's a possible spambot */
860      }
861  
862      if (name)
863 <      source_p->connection->last_join_time = CurrentTime;
863 >      client_p->connection->last_join_time = CurrentTime;
864      else
865 <      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 <    }
865 >      client_p->connection->last_leave_time = CurrentTime;
866    }
867   }
868  
# Line 906 | Line 875 | check_splitmode(void *unused)
875   */
876   void
877   channel_set_topic(struct Channel *chptr, const char *topic,
878 <                  const char *topic_info, time_t topicts, int local)
878 >                  const char *topic_info, uintmax_t topicts, int local)
879   {
880    if (local)
881      strlcpy(chptr->topic, topic, IRCD_MIN(sizeof(chptr->topic), ConfigServerInfo.max_topic_length + 1));
# Line 917 | Line 886 | channel_set_topic(struct Channel *chptr,
886    chptr->topic_time = topicts;
887   }
888  
920 /* do_join_0()
921 *
922 * inputs       - pointer to client doing join 0
923 * output       - NONE
924 * side effects - Use has decided to join 0. This is legacy
925 *                from the days when channels were numbers not names. *sigh*
926 *                There is a bunch of evilness necessary here due to
927 *                anti spambot code.
928 */
929 void
930 channel_do_join_0(struct Client *source_p)
931 {
932  dlink_node *node = NULL, *node_next = NULL;
933
934  if (source_p->channel.head)
935    if (MyConnect(source_p) && !HasUMode(source_p, UMODE_OPER))
936      check_spambot_warning(source_p, NULL);
937
938  DLINK_FOREACH_SAFE(node, node_next, source_p->channel.head)
939  {
940    struct Channel *chptr = ((struct Membership *)node->data)->chptr;
941
942    sendto_server(source_p, 0, 0, ":%s PART %s",
943                  source_p->id, chptr->name);
944    sendto_channel_local(0, chptr, ":%s!%s@%s PART %s",
945                         source_p->name, source_p->username,
946                         source_p->host, chptr->name);
947
948    remove_user_from_channel(node->data);
949  }
950 }
951
952 static char *
953 channel_find_last0(struct Client *source_p, char *chanlist)
954 {
955  int join0 = 0;
956
957  for (char *p = chanlist; *p; ++p)  /* Find last "JOIN 0" */
958  {
959    if (*p == '0' && (*(p + 1) == ',' || *(p + 1) == '\0'))
960    {
961      if (*(p + 1) == ',')
962        ++p;
963
964      chanlist = p + 1;
965      join0 = 1;
966    }
967    else
968    {
969      while (*p != ',' && *p != '\0')  /* Skip past channel name */
970        ++p;
971
972      if (*p == '\0')  /* Hit the end */
973        break;
974    }
975  }
976
977  if (join0)
978    channel_do_join_0(source_p);
979
980  return chanlist;
981 }
982
889   void
890 < channel_do_join(struct Client *source_p, char *channel, char *key_list)
890 > channel_do_join(struct Client *client_p, char *chan_list, char *key_list)
891   {
892    char *p = NULL;
893 <  char *chan = NULL;
894 <  char *chan_list = NULL;
989 <  struct Channel *chptr = NULL;
990 <  struct MaskItem *conf = NULL;
991 <  const struct ClassItem *const class = get_class_ptr(&source_p->connection->confs);
992 <  int i = 0;
893 >  const struct ResvItem *resv = NULL;
894 >  const struct ClassItem *const class = get_class_ptr(&client_p->connection->confs);
895    unsigned int flags = 0;
896  
897 <  assert(IsClient(source_p));
996 <
997 <  chan_list = channel_find_last0(source_p, channel);
897 >  assert(IsClient(client_p));
898  
899 <  for (chan = strtoken(&p, chan_list, ","); chan;
900 <       chan = strtoken(&p,      NULL, ","))
899 >  for (const char *name = strtok_r(chan_list, ",", &p); name;
900 >                   name = strtok_r(NULL,      ",", &p))
901    {
902      const char *key = NULL;
903  
# Line 1009 | Line 909 | channel_do_join(struct Client *source_p,
909      if (key && *key == '\0')
910        key = NULL;
911  
912 <    if (!check_channel_name(chan, 1))
912 >    if (!channel_check_name(name, 1))
913      {
914 <      sendto_one_numeric(source_p, &me, ERR_BADCHANNAME, chan);
914 >      sendto_one_numeric(client_p, &me, ERR_BADCHANNAME, name);
915        continue;
916      }
917  
918 <    if (!IsExemptResv(source_p) &&
919 <        !(HasUMode(source_p, UMODE_OPER) && ConfigGeneral.oper_pass_resv) &&
920 <        ((conf = match_find_resv(chan)) && !resv_find_exempt(source_p, conf)))
918 >    if (!HasFlag(client_p, FLAGS_EXEMPTRESV) &&
919 >        !(HasUMode(client_p, UMODE_OPER) && HasOFlag(client_p, OPER_FLAG_JOIN_RESV)) &&
920 >        ((resv = resv_find(name, match)) && !resv_exempt_find(client_p, resv)))
921      {
922 <      ++conf->count;
1023 <      sendto_one_numeric(source_p, &me, ERR_CHANBANREASON, chan, conf->reason);
922 >      sendto_one_numeric(client_p, &me, ERR_CHANBANREASON, name, resv->reason);
923        sendto_realops_flags(UMODE_REJ, L_ALL, SEND_NOTICE,
924                             "Forbidding reserved channel %s from user %s",
925 <                           chan, get_client_name(source_p, HIDE_IP));
925 >                           name, client_get_name(client_p, HIDE_IP));
926        continue;
927      }
928  
929 <    if (dlink_list_length(&source_p->channel) >=
929 >    if (dlink_list_length(&client_p->channel) >=
930          ((class->max_channels) ? class->max_channels : ConfigChannel.max_channels))
931      {
932 <      sendto_one_numeric(source_p, &me, ERR_TOOMANYCHANNELS, chan);
932 >      sendto_one_numeric(client_p, &me, ERR_TOOMANYCHANNELS, name);
933        break;
934      }
935  
936 <    if ((chptr = hash_find_channel(chan)))
936 >    struct Channel *chptr = hash_find_channel(name);
937 >    if (chptr)
938      {
939 <      if (IsMember(source_p, chptr))
939 >      if (IsMember(client_p, chptr))
940          continue;
941  
942 <      if (splitmode && !HasUMode(source_p, UMODE_OPER) &&
943 <          ConfigChannel.no_join_on_split)
942 >      /* can_join() checks for +i, +l, key, bans, etc. */
943 >      int ret = can_join(client_p, chptr, key);
944 >      if (ret)
945        {
946 <        sendto_one_numeric(source_p, &me, ERR_UNAVAILRESOURCE, chptr->name);
1046 <        continue;
1047 <      }
1048 <
1049 <      /*
1050 <       * can_join checks for +i key, bans.
1051 <       */
1052 <      if ((i = can_join(source_p, chptr, key)))
1053 <      {
1054 <        sendto_one_numeric(source_p, &me, i, chptr->name);
946 >        sendto_one_numeric(client_p, &me, ret, chptr->name);
947          continue;
948        }
949  
# Line 1066 | Line 958 | channel_do_join(struct Client *source_p,
958      }
959      else
960      {
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
961        flags = CHFL_CHANOP;
962 <      chptr = make_channel(chan);
962 >      chptr = channel_make(name);
963      }
964  
965 <    if (!HasUMode(source_p, UMODE_OPER))
966 <      check_spambot_warning(source_p, chptr->name);
965 >    if (!HasUMode(client_p, UMODE_OPER))
966 >      check_spambot_warning(client_p, chptr->name);
967  
968 <    add_user_to_channel(chptr, source_p, flags, 1);
968 >    add_user_to_channel(chptr, client_p, flags, 1);
969  
970      /*
971       * Set timestamp if appropriate, and propagate
# Line 1088 | Line 973 | channel_do_join(struct Client *source_p,
973      if (flags == CHFL_CHANOP)
974      {
975        chptr->creationtime = CurrentTime;
976 <      chptr->mode.mode |= MODE_TOPICLIMIT;
977 <      chptr->mode.mode |= MODE_NOPRIVMSGS;
976 >      AddCMode(chptr, MODE_TOPICLIMIT);
977 >      AddCMode(chptr, MODE_NOPRIVMSGS);
978  
979 <      sendto_server(source_p, 0, 0, ":%s SJOIN %lu %s +nt :@%s",
980 <                    me.id, (unsigned long)chptr->creationtime,
981 <                    chptr->name, source_p->id);
979 >      sendto_server(client_p, 0, 0, ":%s SJOIN %ju %s +nt :@%s",
980 >                    me.id, chptr->creationtime,
981 >                    chptr->name, client_p->id);
982  
983        /*
984         * Notify all other users on the new channel
985         */
986 <      sendto_channel_local_butone(NULL, CAP_EXTENDED_JOIN, 0, chptr, ":%s!%s@%s JOIN %s %s :%s",
987 <                                  source_p->name, source_p->username,
988 <                                  source_p->host, chptr->name,
989 <                                  (!IsDigit(source_p->account[0]) && source_p->account[0] != '*') ? source_p->account : "*",
990 <                                  source_p->info);
991 <      sendto_channel_local_butone(NULL, 0, CAP_EXTENDED_JOIN, chptr, ":%s!%s@%s JOIN :%s",
992 <                                  source_p->name, source_p->username,
1108 <                                  source_p->host, chptr->name);
1109 <      sendto_channel_local(0, chptr, ":%s MODE %s +nt",
986 >      sendto_channel_local(NULL, chptr, 0, CAP_EXTENDED_JOIN, 0, ":%s!%s@%s JOIN %s %s :%s",
987 >                           client_p->name, client_p->username,
988 >                           client_p->host, chptr->name, client_p->account, client_p->info);
989 >      sendto_channel_local(NULL, chptr, 0, 0, CAP_EXTENDED_JOIN, ":%s!%s@%s JOIN :%s",
990 >                           client_p->name, client_p->username,
991 >                           client_p->host, chptr->name);
992 >      sendto_channel_local(NULL, chptr, 0, 0, 0, ":%s MODE %s +nt",
993                             me.name, chptr->name);
994  
995 <      if (source_p->away[0])
996 <        sendto_channel_local_butone(source_p, CAP_AWAY_NOTIFY, 0, chptr,
997 <                                    ":%s!%s@%s AWAY :%s",
998 <                                    source_p->name, source_p->username,
999 <                                    source_p->host, source_p->away);
995 >      if (client_p->away[0])
996 >        sendto_channel_local(client_p, chptr, 0, CAP_AWAY_NOTIFY, 0,
997 >                             ":%s!%s@%s AWAY :%s",
998 >                             client_p->name, client_p->username,
999 >                             client_p->host, client_p->away);
1000      }
1001      else
1002      {
1003 <      sendto_server(source_p, 0, 0, ":%s JOIN %lu %s +",
1004 <                    source_p->id, (unsigned long)chptr->creationtime,
1003 >      sendto_server(client_p, 0, 0, ":%s JOIN %ju %s +",
1004 >                    client_p->id, chptr->creationtime,
1005                      chptr->name);
1006  
1007 <      sendto_channel_local_butone(NULL, CAP_EXTENDED_JOIN, 0, chptr, ":%s!%s@%s JOIN %s %s :%s",
1008 <                                  source_p->name, source_p->username,
1009 <                                  source_p->host, chptr->name,
1010 <                                  (!IsDigit(source_p->account[0]) && source_p->account[0] != '*') ? source_p->account : "*",
1011 <                                  source_p->info);
1012 <      sendto_channel_local_butone(NULL, 0, CAP_EXTENDED_JOIN, chptr, ":%s!%s@%s JOIN :%s",
1013 <                                  source_p->name, source_p->username,
1014 <                                  source_p->host, chptr->name);
1015 <
1016 <      if (source_p->away[0])
1017 <        sendto_channel_local_butone(source_p, CAP_AWAY_NOTIFY, 0, chptr,
1018 <                                    ":%s!%s@%s AWAY :%s",
1019 <                                    source_p->name, source_p->username,
1020 <                                    source_p->host, source_p->away);
1021 <    }
1022 <
1023 <    del_invite(chptr, source_p);
1007 >      sendto_channel_local(NULL, chptr, 0, CAP_EXTENDED_JOIN, 0, ":%s!%s@%s JOIN %s %s :%s",
1008 >                           client_p->name, client_p->username,
1009 >                           client_p->host, chptr->name, client_p->account, client_p->info);
1010 >      sendto_channel_local(NULL, chptr, 0, 0, CAP_EXTENDED_JOIN, ":%s!%s@%s JOIN :%s",
1011 >                           client_p->name, client_p->username,
1012 >                           client_p->host, chptr->name);
1013 >
1014 >      if (client_p->away[0])
1015 >        sendto_channel_local(client_p, chptr, 0, CAP_AWAY_NOTIFY, 0,
1016 >                             ":%s!%s@%s AWAY :%s",
1017 >                             client_p->name, client_p->username,
1018 >                             client_p->host, client_p->away);
1019 >    }
1020 >
1021 >    struct Invite *invite = find_invite(chptr, client_p);
1022 >    if (invite)
1023 >      del_invite(invite);
1024  
1025      if (chptr->topic[0])
1026      {
1027 <      sendto_one_numeric(source_p, &me, RPL_TOPIC, chptr->name, chptr->topic);
1028 <      sendto_one_numeric(source_p, &me, RPL_TOPICWHOTIME, chptr->name,
1027 >      sendto_one_numeric(client_p, &me, RPL_TOPIC, chptr->name, chptr->topic);
1028 >      sendto_one_numeric(client_p, &me, RPL_TOPICWHOTIME, chptr->name,
1029                           chptr->topic_info, chptr->topic_time);
1030      }
1031  
1032 <    channel_member_names(source_p, chptr, 1);
1032 >    channel_member_names(client_p, chptr, 1);
1033  
1034 <    source_p->connection->last_join_time = CurrentTime;
1034 >    client_p->connection->last_join_time = CurrentTime;
1035    }
1036   }
1037  
1038   /*! \brief Removes a client from a specific channel
1039 < * \param source_p Pointer to source client to remove
1039 > * \param client_p Pointer to client to remove
1040   * \param name     Name of channel to remove from
1041   * \param reason   Part reason to show
1042   */
1043   static void
1044 < channel_part_one_client(struct Client *source_p, const char *name, const char *reason)
1044 > channel_part_one_client(struct Client *client_p, const char *name, const char *reason)
1045   {
1046    struct Channel *chptr = NULL;
1047    struct Membership *member = NULL;
1048  
1049    if ((chptr = hash_find_channel(name)) == NULL)
1050    {
1051 <    sendto_one_numeric(source_p, &me, ERR_NOSUCHCHANNEL, name);
1051 >    sendto_one_numeric(client_p, &me, ERR_NOSUCHCHANNEL, name);
1052      return;
1053    }
1054  
1055 <  if ((member = find_channel_link(source_p, chptr)) == NULL)
1055 >  if ((member = find_channel_link(client_p, chptr)) == NULL)
1056    {
1057 <    sendto_one_numeric(source_p, &me, ERR_NOTONCHANNEL, chptr->name);
1057 >    sendto_one_numeric(client_p, &me, ERR_NOTONCHANNEL, chptr->name);
1058      return;
1059    }
1060  
1061 <  if (MyConnect(source_p) && !HasUMode(source_p, UMODE_OPER))
1062 <    check_spambot_warning(source_p, NULL);
1061 >  if (MyConnect(client_p) && !HasUMode(client_p, UMODE_OPER))
1062 >    check_spambot_warning(client_p, NULL);
1063  
1064    /*
1065     * Remove user from the old channel (if any)
1066     * only allow /part reasons in -m chans
1067     */
1068 <  if (*reason && (!MyConnect(source_p) ||
1069 <      ((can_send(chptr, source_p, member, reason) &&
1070 <       (source_p->connection->firsttime + ConfigGeneral.anti_spam_exit_message_time)
1071 <        < CurrentTime))))
1072 <  {
1073 <    sendto_server(source_p, 0, 0, ":%s PART %s :%s",
1074 <                  source_p->id, chptr->name, reason);
1075 <    sendto_channel_local(0, chptr, ":%s!%s@%s PART %s :%s",
1076 <                         source_p->name, source_p->username,
1077 <                         source_p->host, chptr->name, reason);
1068 >  if (*reason && (!MyConnect(client_p) ||
1069 >      ((client_p->connection->firsttime +
1070 >        ConfigGeneral.anti_spam_exit_message_time) < CurrentTime &&
1071 >       can_send(chptr, client_p, member, reason, 0) < 0)))
1072 >  {
1073 >    sendto_server(client_p, 0, 0, ":%s PART %s :%s",
1074 >                  client_p->id, chptr->name, reason);
1075 >    sendto_channel_local(NULL, chptr, 0, 0, 0, ":%s!%s@%s PART %s :%s",
1076 >                         client_p->name, client_p->username,
1077 >                         client_p->host, chptr->name, reason);
1078    }
1079    else
1080    {
1081 <    sendto_server(source_p, 0, 0, ":%s PART %s",
1082 <                  source_p->id, chptr->name);
1083 <    sendto_channel_local(0, chptr, ":%s!%s@%s PART %s",
1084 <                         source_p->name, source_p->username,
1085 <                         source_p->host, chptr->name);
1081 >    sendto_server(client_p, 0, 0, ":%s PART %s",
1082 >                  client_p->id, chptr->name);
1083 >    sendto_channel_local(NULL, chptr, 0, 0, 0, ":%s!%s@%s PART %s",
1084 >                         client_p->name, client_p->username,
1085 >                         client_p->host, chptr->name);
1086    }
1087  
1088    remove_user_from_channel(member);
1089   }
1090  
1091   void
1092 < channel_do_part(struct Client *source_p, char *channel, const char *reason)
1092 > channel_do_part(struct Client *client_p, char *channel, const char *reason)
1093   {
1094 <  char *p = NULL, *name = NULL;
1094 >  char *p = NULL;
1095    char buf[KICKLEN + 1] = "";
1096  
1097 <  assert(IsClient(source_p));
1097 >  assert(IsClient(client_p));
1098  
1099    if (!EmptyString(reason))
1100      strlcpy(buf, reason, sizeof(buf));
1101  
1102 <  for (name = strtoken(&p, channel, ","); name;
1103 <       name = strtoken(&p,    NULL, ","))
1104 <    channel_part_one_client(source_p, name, buf);
1102 >  for (const char *name = strtok_r(channel, ",", &p); name;
1103 >                   name = strtok_r(NULL,    ",", &p))
1104 >    channel_part_one_client(client_p, name, buf);
1105   }

Comparing ircd-hybrid/trunk/src/channel.c (property svn:keywords):
Revision 5983 by michael, Mon May 25 15:24:48 2015 UTC vs.
Revision 8367 by michael, Mon Mar 5 19:51:42 2018 UTC

# Line 1 | Line 1
1 < Id Revision
1 > Id

Diff Legend

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