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 3235 by michael, Sat Mar 29 19:34:16 2014 UTC vs.
Revision 4151 by michael, Wed Jul 2 17:44:54 2014 UTC

# Line 35 | Line 35
35   #include "irc_string.h"
36   #include "ircd.h"
37   #include "numeric.h"
38 < #include "s_serv.h"
38 > #include "server.h"
39   #include "send.h"
40   #include "event.h"
41   #include "memory.h"
42   #include "mempool.h"
43 < #include "s_misc.h"
43 > #include "misc.h"
44   #include "resv.h"
45  
46  
47 < dlink_list global_channel_list;
47 > dlink_list channel_list;
48   mp_pool_t *ban_pool;    /*! \todo ban_pool shouldn't be a global var */
49  
50 < static mp_pool_t *member_pool = NULL;
51 < static mp_pool_t *channel_pool = NULL;
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;
58   static char buf[IRCD_BUFSIZE];
59  
60  
# Line 66 | Line 71 | channel_init(void)
71    member_pool = mp_pool_new(sizeof(struct Membership), MP_CHUNK_SIZE_MEMBER);
72   }
73  
74 < /*! \brief adds a user to a channel by adding another link to the
74 > /*! \brief Adds a user to a channel by adding another link to the
75   *         channels member chain.
76 < * \param chptr      pointer to channel to add client to
77 < * \param who        pointer to client (who) to add
78 < * \param flags      flags for chanops etc
79 < * \param flood_ctrl whether to count this join in flood calculations
76 > * \param chptr      Pointer to channel to add client to
77 > * \param who        Pointer to client (who) to add
78 > * \param flags      Flags for chanops etc
79 > * \param flood_ctrl Whether to count this join in flood calculations
80   */
81   void
82   add_user_to_channel(struct Channel *chptr, struct Client *who,
# Line 82 | Line 87 | add_user_to_channel(struct Channel *chpt
87    if (GlobalSetOptions.joinfloodtime > 0)
88    {
89      if (flood_ctrl)
90 <      chptr->number_joined++;
90 >      ++chptr->number_joined;
91  
92      chptr->number_joined -= (CurrentTime - chptr->last_join_time) *
93        (((float)GlobalSetOptions.joinfloodcount) /
# Line 111 | Line 116 | add_user_to_channel(struct Channel *chpt
116    }
117  
118    ms = mp_pool_get(member_pool);
114  memset(ms, 0, sizeof(*ms));
115
119    ms->client_p = who;
120    ms->chptr = chptr;
121    ms->flags = flags;
# Line 121 | Line 124 | add_user_to_channel(struct Channel *chpt
124    dlinkAdd(ms, &ms->usernode, &who->channel);
125   }
126  
127 < /*! \brief deletes an user from a channel by removing a link in the
127 > /*! \brief Deletes an user from a channel by removing a link in the
128   *         channels member chain.
129 < * \param member pointer to Membership struct
129 > * \param member Pointer to Membership struct
130   */
131   void
132   remove_user_from_channel(struct Membership *member)
# Line 162 | Line 165 | send_members(struct Client *client_p, st
165    {
166      const struct Membership *ms = ptr->data;
167  
168 <    tlen = strlen(ms->client_p->id) + 1;  /* nick + space */
168 >    tlen = strlen(ms->client_p->id) + 1;  /* +1 for space */
169  
170      if (ms->flags & CHFL_CHANOP)
171 <      tlen++;
169 < #ifdef HALFOPS
171 >      ++tlen;
172      if (ms->flags & CHFL_HALFOP)
173 <      tlen++;
172 < #endif
173 >      ++tlen;
174      if (ms->flags & CHFL_VOICE)
175 <      tlen++;
175 >      ++tlen;
176  
177 <    /* space will be converted into CR, but we also need space for LF..
178 <     * That's why we use '- 1' here
179 <     * -adx */
177 >    /*
178 >     * Space will be converted into CR, but we also need space for LF..
179 >     * That's why we use '- 1' here -adx
180 >     */
181      if (t + tlen - buf > IRCD_BUFSIZE - 1)
182      {
183 <      *(t - 1) = '\0';  /* kill the space and terminate the string */
183 >      *(t - 1) = '\0';  /* Kill the space and terminate the string */
184        sendto_one(client_p, "%s", buf);
185        t = start;
186      }
# Line 196 | Line 198 | send_members(struct Client *client_p, st
198      *t++ = ' ';
199    }
200  
201 <  /* should always be non-NULL unless we have a kind of persistent channels */
201 >  /* Should always be non-NULL unless we have a kind of persistent channels */
202    if (chptr->members.head)
203 <    t--;  /* take the space out */
203 >    t--;  /* Take the space out */
204    *t = '\0';
205    sendto_one(client_p, "%s", buf);
206   }
207  
208 < /*! \brief sends +b/+e/+I
209 < * \param client_p client pointer to server
210 < * \param chptr    pointer to channel
211 < * \param top      pointer to top of mode link list to send
212 < * \param flag     char flag flagging type of mode. Currently this can be 'b', e' or 'I'
208 > /*! \brief Sends +b/+e/+I
209 > * \param client_p Client pointer to server
210 > * \param chptr    Pointer to channel
211 > * \param list     Pointer to list of modes to send
212 > * \param flag     Char flag flagging type of mode. Currently this can be 'b', e' or 'I'
213   */
214   static void
215   send_mode_list(struct Client *client_p, struct Channel *chptr,
216 <               const dlink_list *top, char flag)
216 >               const dlink_list *list, char flag)
217   {
218 <  const dlink_node *lp = NULL;
218 >  const dlink_node *ptr = NULL;
219    char pbuf[IRCD_BUFSIZE] = "";
220 <  int tlen, mlen, cur_len, count = 0;
220 >  int tlen, mlen, cur_len;
221    char *pp = pbuf;
222  
223 <  if (top->length == 0)
223 >  if (list->length == 0)
224      return;
225  
226    mlen = snprintf(buf, sizeof(buf), ":%s BMASK %lu %s %c :", me.id,
227                    (unsigned long)chptr->channelts, chptr->chname, flag);
228    cur_len = mlen;
229  
230 <  DLINK_FOREACH(lp, top->head)
230 >  DLINK_FOREACH(ptr, list->head)
231    {
232 <    const struct Ban *banptr = lp->data;
232 >    const struct Ban *banptr = ptr->data;
233  
234 <    tlen = banptr->len + 3;
234 >    tlen = banptr->len + 3;  /* +3 for ! + @ + space */
235  
236      /*
237 <     * send buffer and start over if we cannot fit another ban,
236 <     * or if the target is non-ts6 and we have too many modes in
237 <     * in this line.
237 >     * Send buffer and start over if we cannot fit another ban
238       */
239      if (cur_len + (tlen - 1) > IRCD_BUFSIZE - 2)
240      {
241 <      *(pp - 1) = '\0';  /* get rid of trailing space on buffer */
241 >      *(pp - 1) = '\0';  /* Get rid of trailing space on buffer */
242        sendto_one(client_p, "%s%s", buf, pbuf);
243  
244        cur_len = mlen;
245        pp = pbuf;
246      count = 0;
246      }
247  
249    count++;
248      pp += sprintf(pp, "%s!%s@%s ", banptr->name, banptr->user,
249                    banptr->host);
250      cur_len += tlen;
251    }
252  
253 <  *(pp - 1) = '\0';  /* get rid of trailing space on buffer */
253 >  *(pp - 1) = '\0';  /* Get rid of trailing space on buffer */
254    sendto_one(client_p, "%s%s", buf, pbuf);
255   }
256  
257 < /*! \brief send "client_p" a full list of the modes for channel chptr
258 < * \param client_p pointer to client client_p
259 < * \param chptr    pointer to channel pointer
257 > /*! \brief Send "client_p" a full list of the modes for channel chptr
258 > * \param client_p Pointer to client client_p
259 > * \param chptr    Pointer to channel pointer
260   */
261   void
262   send_channel_modes(struct Client *client_p, struct Channel *chptr)
# Line 274 | Line 272 | send_channel_modes(struct Client *client
272    send_mode_list(client_p, chptr, &chptr->invexlist, 'I');
273   }
274  
275 < /*! \brief check channel name for invalid characters
276 < * \param name pointer to channel name string
277 < * \param local indicates whether it's a local or remote creation
275 > /*! \brief Check channel name for invalid characters
276 > * \param name Pointer to channel name string
277 > * \param local Indicates whether it's a local or remote creation
278   * \return 0 if invalid, 1 otherwise
279   */
280   int
281   check_channel_name(const char *name, const int local)
282   {
283    const char *p = name;
284 <  const int max_length = local ? LOCAL_CHANNELLEN : CHANNELLEN;
284 >
285    assert(name != NULL);
286  
287    if (!IsChanPrefix(*p))
# Line 302 | Line 300 | check_channel_name(const char *name, con
300          return 0;
301    }
302  
303 <  return p - name <= max_length;
303 >  return p - name <= CHANNELLEN;
304   }
305  
306   void
# Line 327 | Line 325 | remove_ban(struct Ban *bptr, dlink_list
325   void
326   free_channel_list(dlink_list *list)
327   {
328 <  dlink_node *ptr = NULL, *next_ptr = NULL;
328 >  dlink_node *ptr = NULL, *ptr_next = NULL;
329  
330 <  DLINK_FOREACH_SAFE(ptr, next_ptr, list->head)
330 >  DLINK_FOREACH_SAFE(ptr, ptr_next, list->head)
331      remove_ban(ptr->data, list);
332  
333    assert(list->tail == NULL && list->head == NULL);
# Line 337 | Line 335 | free_channel_list(dlink_list *list)
335  
336   /*! \brief Get Channel block for chname (and allocate a new channel
337   *         block, if it didn't exist before)
338 < * \param chname channel name
339 < * \return channel block
338 > * \param chname Channel name
339 > * \return Channel block
340   */
341   struct Channel *
342   make_channel(const char *chname)
# Line 349 | Line 347 | make_channel(const char *chname)
347  
348    chptr = mp_pool_get(channel_pool);
349  
350 <  memset(chptr, 0, sizeof(*chptr));
353 <
354 <  /* doesn't hurt to set it here */
350 >  /* Doesn't hurt to set it here */
351    chptr->channelts = CurrentTime;
352    chptr->last_join_time = CurrentTime;
353  
354    strlcpy(chptr->chname, chname, sizeof(chptr->chname));
355 <  dlinkAdd(chptr, &chptr->node, &global_channel_list);
355 >  dlinkAdd(chptr, &chptr->node, &channel_list);
356  
357    hash_add_channel(chptr);
358  
359    return chptr;
360   }
361  
362 < /*! \brief walk through this channel, and destroy it.
363 < * \param chptr channel pointer
362 > /*! \brief Walk through this channel, and destroy it.
363 > * \param chptr Channel pointer
364   */
365   void
366   destroy_channel(struct Channel *chptr)
# Line 374 | Line 370 | destroy_channel(struct Channel *chptr)
370    DLINK_FOREACH_SAFE(ptr, ptr_next, chptr->invites.head)
371      del_invite(chptr, ptr->data);
372  
373 <  /* free ban/exception/invex lists */
373 >  /* Free ban/exception/invex lists */
374    free_channel_list(&chptr->banlist);
375    free_channel_list(&chptr->exceptlist);
376    free_channel_list(&chptr->invexlist);
377  
378 <  dlinkDelete(&chptr->node, &global_channel_list);
378 >  dlinkDelete(&chptr->node, &channel_list);
379    hash_del_channel(chptr);
380  
381    mp_pool_release(chptr);
382   }
383  
384   /*!
385 < * \param chptr pointer to channel
386 < * \return string pointer "=" if public, "@" if secret else "*"
385 > * \param chptr Pointer to channel
386 > * \return String pointer "=" if public, "@" if secret else "*"
387   */
388   static const char *
389   channel_pub_or_secret(const struct Channel *chptr)
# Line 400 | Line 396 | channel_pub_or_secret(const struct Chann
396   }
397  
398   /*! \brief lists all names on given channel
399 < * \param source_p pointer to client struct requesting names
400 < * \param chptr    pointer to channel block
401 < * \param show_eon show ENDOFNAMES numeric or not
399 > * \param source_p Pointer to client struct requesting names
400 > * \param chptr    Pointer to channel block
401 > * \param show_eon Show RPL_ENDOFNAMES numeric or not
402   *                 (don't want it with /names with no params)
403   */
404   void
# Line 432 | Line 428 | channel_member_names(struct Client *sour
428          continue;
429  
430        if (!uhnames)
431 <        tlen = strlen(ms->client_p->name) + 1;  /* nick + space */
431 >        tlen = strlen(ms->client_p->name) + 1;  /* +1 for space */
432        else
433          tlen = strlen(ms->client_p->name) + strlen(ms->client_p->username) +
434 <               strlen(ms->client_p->host) + 3;
434 >               strlen(ms->client_p->host) + 3;  /* +3 for ! + @ + space */
435  
436        if (!multi_prefix)
437        {
# Line 479 | Line 475 | channel_member_names(struct Client *sour
475      sendto_one_numeric(source_p, &me, RPL_ENDOFNAMES, chptr->chname);
476   }
477  
478 < /*! \brief adds client to invite list
479 < * \param chptr pointer to channel block
480 < * \param who   pointer to client to add invite to
478 > /*! \brief Adds client to invite list
479 > * \param chptr Pointer to channel block
480 > * \param who   Pointer to client to add invite to
481   */
482   void
483   add_invite(struct Channel *chptr, struct Client *who)
# Line 489 | Line 485 | add_invite(struct Channel *chptr, struct
485    del_invite(chptr, who);
486  
487    /*
488 <   * delete last link in chain if the list is max length
488 >   * Delete last link in chain if the list is max length
489     */
490    if (dlink_list_length(&who->localClient->invited) >=
491 <      ConfigChannel.max_chans_per_user)
491 >      ConfigChannel.max_channels)
492      del_invite(who->localClient->invited.tail->data, who);
493  
494 <  /* add client to channel invite list */
494 >  /* Add client to channel invite list */
495    dlinkAdd(who, make_dlink_node(), &chptr->invites);
496  
497 <  /* add channel to the end of the client invite list */
497 >  /* Add channel to the end of the client invite list */
498    dlinkAdd(chptr, make_dlink_node(), &who->localClient->invited);
499   }
500  
501   /*! \brief Delete Invite block from channel invite list
502   *         and client invite list
503 < * \param chptr pointer to Channel struct
504 < * \param who   pointer to client to remove invites from
503 > * \param chptr Pointer to Channel struct
504 > * \param who   Pointer to client to remove invites from
505   */
506   void
507   del_invite(struct Channel *chptr, struct Client *who)
# Line 533 | Line 529 | del_invite(struct Channel *chptr, struct
529   const char *
530   get_member_status(const struct Membership *ms, const int combine)
531   {
532 <  static char buffer[4];
532 >  static char buffer[4];  /* 4 for @%+\0 */
533    char *p = buffer;
534  
535    if (ms->flags & CHFL_CHANOP)
# Line 543 | Line 539 | get_member_status(const struct Membershi
539      *p++ = '@';
540    }
541  
546 #ifdef HALFOPS
542    if (ms->flags & CHFL_HALFOP)
543    {
544      if (!combine)
545        return "%";
546      *p++ = '%';
547    }
553 #endif
548  
549    if (ms->flags & CHFL_VOICE)
550      *p++ = '+';
# Line 560 | Line 554 | get_member_status(const struct Membershi
554   }
555  
556   /*!
557 < * \param who  pointer to Client to check
558 < * \param list pointer to ban list to search
557 > * \param who  Pointer to Client to check
558 > * \param list Pointer to ban list to search
559   * \return 1 if ban found for given n!u\@h mask, 0 otherwise
560   *
561   */
# Line 604 | Line 598 | find_bmask(const struct Client *who, con
598   }
599  
600   /*!
601 < * \param chptr pointer to channel block
602 < * \param who   pointer to client to check access fo
601 > * \param chptr Pointer to channel block
602 > * \param who   Pointer to client to check access fo
603   * \return 0 if not banned, 1 otherwise
604   */
605   int
# Line 618 | Line 612 | is_banned(const struct Channel *chptr, c
612    return 0;
613   }
614  
615 < /*!
616 < * \param source_p pointer to client attempting to join
617 < * \param chptr    pointer to channel
618 < * \param key      key sent by client attempting to join if present
615 > /*! Tests if a client can join a certain channel
616 > * \param source_p Pointer to client attempting to join
617 > * \param chptr    Pointer to channel
618 > * \param key      Key sent by client attempting to join if present
619   * \return ERR_BANNEDFROMCHAN, ERR_INVITEONLYCHAN, ERR_CHANNELISFULL
620   *         or 0 if allowed to join.
621   */
# Line 685 | Line 679 | find_channel_link(struct Client *client_
679    return NULL;
680   }
681  
682 < /*
683 < * Basically the same functionality as in bahamut
682 > /*! Tests if a client can send to a channel
683 > * \param message The actual message string the client wants to send
684 > * \return 1 if the message does contain any control codes, 0 otherwise
685   */
686   static int
687   msg_has_ctrls(const char *message)
# Line 696 | Line 691 | msg_has_ctrls(const char *message)
691    for (; *p; ++p)
692    {
693      if (*p > 31 || *p == 1)
694 <      continue;
694 >      continue;  /* No control code or CTCP */
695  
696 <    if (*p == 27)
696 >    if (*p == 27)  /* Escape */
697      {
698 +      /* ISO 2022 charset shift sequence */
699        if (*(p + 1) == '$' ||
700            *(p + 1) == '(')
701        {
# Line 708 | Line 704 | msg_has_ctrls(const char *message)
704        }
705      }
706  
707 <    return 1;
707 >    return 1;  /* Control code */
708    }
709  
710    return 0;
711   }
712  
713 < /*!
714 < * \param chptr    pointer to Channel struct
715 < * \param source_p pointer to Client struct
716 < * \param ms       pointer to Membership struct (can be NULL)
713 > /*! Tests if a client can send to a channel
714 > * \param chptr    Pointer to Channel struct
715 > * \param source_p Pointer to Client struct
716 > * \param ms       Pointer to Membership struct (can be NULL)
717 > * \param message  The actual message string the client wants to send
718   * \return CAN_SEND_OPV if op or voiced on channel\n
719   *         CAN_SEND_NONOP if can send to channel but is not an op\n
720   *         ERR_CANNOTSENDTOCHAN or ERR_NEEDREGGEDNICK if they cannot send to channel\n
# Line 748 | Line 745 | can_send(struct Channel *chptr, struct C
745    if ((chptr->mode.mode & MODE_MODREG) && !HasUMode(source_p, UMODE_REGISTERED))
746      return ERR_NEEDREGGEDNICK;
747  
748 <  /* cache can send if banned */
748 >  /* Cache can send if banned */
749    if (MyClient(source_p))
750    {
751      if (ms)
# Line 777 | Line 774 | can_send(struct Channel *chptr, struct C
774   /*! \brief Updates the client's oper_warn_count_down, warns the
775   *         IRC operators if necessary, and updates
776   *         join_leave_countdown as needed.
777 < * \param source_p pointer to struct Client to check
778 < * \param name     channel name or NULL if this is a part.
777 > * \param source_p Pointer to struct Client to check
778 > * \param name     Channel name or NULL if this is a part.
779   */
780   void
781   check_spambot_warning(struct Client *source_p, const char *name)
# Line 797 | Line 794 | check_spambot_warning(struct Client *sou
794  
795      if (source_p->localClient->oper_warn_count_down == 0)
796      {
797 <      /* Its already known as a possible spambot */
797 >      /* It's already known as a possible spambot */
798        if (name)
799          sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE,
800                               "User %s (%s@%s) trying to join %s is a possible spambot",
# Line 826 | Line 823 | check_spambot_warning(struct Client *sou
823      {
824        if ((CurrentTime - (source_p->localClient->last_join_time)) <
825            GlobalSetOptions.spam_time)
826 <      {
830 <        /* oh, its a possible spambot */
831 <        source_p->localClient->join_leave_count++;
832 <      }
826 >        source_p->localClient->join_leave_count++;  /* It's a possible spambot */
827      }
828  
829      if (name)
# Line 839 | Line 833 | check_spambot_warning(struct Client *sou
833    }
834   }
835  
836 < /*! \brief compares usercount and servercount against their split
836 > /*! \brief Compares usercount and servercount against their split
837   *         values and adjusts splitmode accordingly
838   * \param unused Unused address pointer
839   */
# Line 857 | Line 851 | check_splitmode(void *unused)
851  
852        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
853                             "Network split, activating splitmode");
854 <      eventAddIsh("check_splitmode", check_splitmode, NULL, 10);
854 >      event_add(&splitmode_event, NULL);
855      }
856 <    else if (splitmode && (server > split_servers) && (Count.total > split_users))
856 >    else if (splitmode && (server >= split_servers) && (Count.total >= split_users))
857      {
858        splitmode = 0;
859  
860        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
861                             "Network rejoined, deactivating splitmode");
862 <      eventDelete(check_splitmode, NULL);
862 >      event_delete(&splitmode_event);
863      }
864    }
865   }
866  
867 < /*! \brief Sets the channel topic for chptr
867 > /*! \brief Sets the channel topic for a certain channel
868   * \param chptr      Pointer to struct Channel
869   * \param topic      The topic string
870   * \param topic_info n!u\@h formatted string of the topic setter
871 < * \param topicts    timestamp on the topic
871 > * \param topicts    Timestamp on the topic
872 > * \param local      Whether the topic is set by a local client
873   */
874   void
875 < set_channel_topic(struct Channel *chptr, const char *topic,
875 > channel_set_topic(struct Channel *chptr, const char *topic,
876                    const char *topic_info, time_t topicts, int local)
877   {
878    if (local)
# Line 888 | Line 883 | set_channel_topic(struct Channel *chptr,
883    strlcpy(chptr->topic_info, topic_info, sizeof(chptr->topic_info));
884    chptr->topic_time = topicts;
885   }
886 +
887 + /* do_join_0()
888 + *
889 + * inputs       - pointer to client doing join 0
890 + * output       - NONE
891 + * side effects - Use has decided to join 0. This is legacy
892 + *                from the days when channels were numbers not names. *sigh*
893 + *                There is a bunch of evilness necessary here due to
894 + *                anti spambot code.
895 + */
896 + void
897 + channel_do_join_0(struct Client *source_p)
898 + {
899 +  dlink_node *ptr = NULL, *ptr_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);
904 +
905 +  DLINK_FOREACH_SAFE(ptr, ptr_next, source_p->channel.head)
906 +  {
907 +    struct Channel *chptr = ((struct Membership *)ptr->data)->chptr;
908 +
909 +    sendto_server(source_p, NOCAPS, NOCAPS, ":%s PART %s",
910 +                  source_p->id, chptr->chname);
911 +    sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s!%s@%s PART %s",
912 +                         source_p->name, source_p->username,
913 +                         source_p->host, chptr->chname);
914 +
915 +    remove_user_from_channel(ptr->data);
916 +  }
917 + }
918 +
919 + static char *
920 + channel_find_last0(struct Client *source_p, char *chanlist)
921 + {
922 +  int join0 = 0;
923 +
924 +  for (char *p = chanlist; *p; ++p)  /* Find last "JOIN 0" */
925 +  {
926 +    if (*p == '0' && (*(p + 1) == ',' || *(p + 1) == '\0'))
927 +    {
928 +      if ((*p + 1) == ',')
929 +        ++p;
930 +
931 +      chanlist = p + 1;
932 +      join0 = 1;
933 +    }
934 +    else
935 +    {
936 +      while (*p != ',' && *p != '\0')  /* Skip past channel name */
937 +        ++p;
938 +
939 +      if (*p == '\0')  /* Hit the end */
940 +        break;
941 +    }
942 +  }
943 +
944 +  if (join0)
945 +    channel_do_join_0(source_p);
946 +
947 +  return chanlist;
948 + }
949 +
950 + void
951 + channel_do_join(struct Client *source_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 *class = get_class_ptr(&source_p->localClient->confs);
959 +  int i = 0;
960 +  unsigned int flags = 0;
961 +
962 +  chan_list = channel_find_last0(source_p, channel);
963 +
964 +  for (chan = strtoken(&p, chan_list, ","); chan;
965 +       chan = strtoken(&p,      NULL, ","))
966 +  {
967 +    const char *key = NULL;
968 +
969 +    /* If we have any more keys, take the first for this channel. */
970 +    if (!EmptyString(key_list) && (key_list = strchr(key = key_list, ',')))
971 +      *key_list++ = '\0';
972 +
973 +    /* Empty keys are the same as no keys. */
974 +    if (key && *key == '\0')
975 +      key = NULL;
976 +
977 +    if (!check_channel_name(chan, 1))
978 +    {
979 +      sendto_one_numeric(source_p, &me, ERR_BADCHANNAME, chan);
980 +      continue;
981 +    }
982 +
983 +    if (!IsExemptResv(source_p) &&
984 +        !(HasUMode(source_p, UMODE_OPER) && ConfigFileEntry.oper_pass_resv) &&
985 +        ((conf = match_find_resv(chan)) && !resv_find_exempt(source_p, conf)))
986 +    {
987 +      ++conf->count;
988 +      sendto_one_numeric(source_p, &me, ERR_CHANBANREASON,
989 +                         chan, conf->reason ? conf->reason : "Reserved channel");
990 +      sendto_realops_flags(UMODE_REJ, L_ALL, SEND_NOTICE,
991 +                           "Forbidding reserved channel %s from user %s",
992 +                           chan, get_client_name(source_p, HIDE_IP));
993 +      continue;
994 +    }
995 +
996 +    if (dlink_list_length(&source_p->channel) >=
997 +        ((class->max_channels) ? class->max_channels : ConfigChannel.max_channels))
998 +    {
999 +      sendto_one_numeric(source_p, &me, ERR_TOOMANYCHANNELS, chan);
1000 +      break;
1001 +    }
1002 +
1003 +    if ((chptr = hash_find_channel(chan)))
1004 +    {
1005 +      if (IsMember(source_p, chptr))
1006 +        continue;
1007 +
1008 +      if (splitmode && !HasUMode(source_p, UMODE_OPER) &&
1009 +          ConfigChannel.no_join_on_split)
1010 +      {
1011 +        sendto_one_numeric(source_p, &me, ERR_UNAVAILRESOURCE, chptr->chname);
1012 +        continue;
1013 +      }
1014 +
1015 +      /*
1016 +       * can_join checks for +i key, bans.
1017 +       */
1018 +      if ((i = can_join(source_p, chptr, key)))
1019 +      {
1020 +        sendto_one_numeric(source_p, &me, i, chptr->chname);
1021 +        continue;
1022 +      }
1023 +
1024 +      /*
1025 +       * This should never be the case unless there is some sort of
1026 +       * persistant channels.
1027 +       */
1028 +      if (dlink_list_length(&chptr->members) == 0)
1029 +        flags = CHFL_CHANOP;
1030 +      else
1031 +        flags = 0;
1032 +    }
1033 +    else
1034 +    {
1035 +      if (splitmode && !HasUMode(source_p, UMODE_OPER) &&
1036 +          (ConfigChannel.no_create_on_split || ConfigChannel.no_join_on_split))
1037 +      {
1038 +        sendto_one_numeric(source_p, &me, ERR_UNAVAILRESOURCE, chan);
1039 +        continue;
1040 +      }
1041 +
1042 +      flags = CHFL_CHANOP;
1043 +      chptr = make_channel(chan);
1044 +    }
1045 +
1046 +    if (!HasUMode(source_p, UMODE_OPER))
1047 +      check_spambot_warning(source_p, chptr->chname);
1048 +
1049 +    add_user_to_channel(chptr, source_p, flags, 1);
1050 +
1051 +    /*
1052 +     *  Set timestamp if appropriate, and propagate
1053 +     */
1054 +    if (flags == CHFL_CHANOP)
1055 +    {
1056 +      chptr->channelts = CurrentTime;
1057 +      chptr->mode.mode |= MODE_TOPICLIMIT;
1058 +      chptr->mode.mode |= MODE_NOPRIVMSGS;
1059 +
1060 +      sendto_server(source_p, NOCAPS, NOCAPS, ":%s SJOIN %lu %s +nt :@%s",
1061 +                    me.id, (unsigned long)chptr->channelts,
1062 +                    chptr->chname, source_p->id);
1063 +
1064 +      /*
1065 +       * Notify all other users on the new channel
1066 +       */
1067 +      sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s!%s@%s JOIN :%s",
1068 +                           source_p->name, source_p->username,
1069 +                           source_p->host, chptr->chname);
1070 +      sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s MODE %s +nt",
1071 +                           me.name, chptr->chname);
1072 +
1073 +      if (source_p->away[0])
1074 +        sendto_channel_local_butone(source_p, 0, CAP_AWAY_NOTIFY, chptr,
1075 +                                    ":%s!%s@%s AWAY :%s",
1076 +                                    source_p->name, source_p->username,
1077 +                                    source_p->host, source_p->away);
1078 +    }
1079 +    else
1080 +    {
1081 +      sendto_server(source_p, NOCAPS, NOCAPS, ":%s JOIN %lu %s +",
1082 +                    source_p->id, (unsigned long)chptr->channelts,
1083 +                    chptr->chname);
1084 +      sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s!%s@%s JOIN :%s",
1085 +                           source_p->name, source_p->username,
1086 +                           source_p->host, chptr->chname);
1087 +
1088 +      if (source_p->away[0])
1089 +        sendto_channel_local_butone(source_p, 0, CAP_AWAY_NOTIFY, chptr,
1090 +                                    ":%s!%s@%s AWAY :%s",
1091 +                                    source_p->name, source_p->username,
1092 +                                    source_p->host, source_p->away);
1093 +    }
1094 +
1095 +    del_invite(chptr, source_p);
1096 +
1097 +    if (chptr->topic[0])
1098 +    {
1099 +      sendto_one_numeric(source_p, &me, RPL_TOPIC, chptr->chname, chptr->topic);
1100 +      sendto_one_numeric(source_p, &me, RPL_TOPICWHOTIME, chptr->chname,
1101 +                         chptr->topic_info, chptr->topic_time);
1102 +    }
1103 +
1104 +    channel_member_names(source_p, chptr, 1);
1105 +
1106 +    source_p->localClient->last_join_time = CurrentTime;
1107 +  }
1108 + }
1109 +
1110 + /*! \brief Removes a client from a specific channel
1111 + * \param source_p Pointer to source client to remove
1112 + * \param name     Name of channel to remove from
1113 + * \param reason   Part reason to show
1114 + */
1115 + static void
1116 + channel_part_one_client(struct Client *source_p, const char *name, const char *reason)
1117 + {
1118 +  struct Channel *chptr = NULL;
1119 +  struct Membership *ms = NULL;
1120 +
1121 +  if ((chptr = hash_find_channel(name)) == NULL)
1122 +  {
1123 +    sendto_one_numeric(source_p, &me, ERR_NOSUCHCHANNEL, name);
1124 +    return;
1125 +  }
1126 +
1127 +  if ((ms = find_channel_link(source_p, chptr)) == NULL)
1128 +  {
1129 +    sendto_one_numeric(source_p, &me, ERR_NOTONCHANNEL, chptr->chname);
1130 +    return;
1131 +  }
1132 +
1133 +  if (MyConnect(source_p) && !HasUMode(source_p, UMODE_OPER))
1134 +    check_spambot_warning(source_p, NULL);
1135 +
1136 +  /*
1137 +   * Remove user from the old channel (if any)
1138 +   * only allow /part reasons in -m chans
1139 +   */
1140 +  if (*reason && (!MyConnect(source_p) ||
1141 +      ((can_send(chptr, source_p, ms, reason) &&
1142 +       (source_p->localClient->firsttime + ConfigFileEntry.anti_spam_exit_message_time)
1143 +        < CurrentTime))))
1144 +  {
1145 +    sendto_server(source_p, NOCAPS, NOCAPS, ":%s PART %s :%s",
1146 +                  source_p->id, chptr->chname, reason);
1147 +    sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s!%s@%s PART %s :%s",
1148 +                         source_p->name, source_p->username,
1149 +                         source_p->host, chptr->chname, reason);
1150 +  }
1151 +  else
1152 +  {
1153 +    sendto_server(source_p, NOCAPS, NOCAPS, ":%s PART %s",
1154 +                  source_p->id, chptr->chname);
1155 +    sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s!%s@%s PART %s",
1156 +                         source_p->name, source_p->username,
1157 +                         source_p->host, chptr->chname);
1158 +  }
1159 +
1160 +  remove_user_from_channel(ms);
1161 + }
1162 +
1163 + void
1164 + channel_do_part(struct Client *source_p, char *channel, char *reason)
1165 + {
1166 +  char *p = NULL, *name = NULL;
1167 +  char reasonbuf[KICKLEN + 1] = "";
1168 +
1169 +  if (!EmptyString(reason))
1170 +    strlcpy(reasonbuf, reason, sizeof(reasonbuf));
1171 +
1172 +  for (name = strtoken(&p, channel, ","); name;
1173 +       name = strtoken(&p,    NULL, ","))
1174 +    channel_part_one_client(source_p, name, reasonbuf);
1175 + }

Diff Legend

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