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-8/src/channel.c (file contents), Revision 1330 by michael, Sun Apr 1 12:12:00 2012 UTC vs.
ircd-hybrid/trunk/src/channel.c (file contents), Revision 4151 by michael, Wed Jul 2 17:44:54 2014 UTC

# Line 1 | Line 1
1   /*
2 < *  ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
2 > *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Copyright (C) 2002 by the past and present ircd coders, and others.
4 > *  Copyright (c) 1997-2014 ircd-hybrid development team
5   *
6   *  This program is free software; you can redistribute it and/or modify
7   *  it under the terms of the GNU General Public License as published by
# Line 30 | Line 30
30   #include "channel_mode.h"
31   #include "client.h"
32   #include "hash.h"
33 + #include "conf.h"
34   #include "hostmask.h"
35   #include "irc_string.h"
35 #include "sprintf_irc.h"
36   #include "ircd.h"
37   #include "numeric.h"
38 < #include "s_serv.h"             /* captab */
39 < #include "s_user.h"
38 > #include "server.h"
39   #include "send.h"
41 #include "conf.h"             /* ConfigFileEntry, ConfigChannel */
40   #include "event.h"
41   #include "memory.h"
42 < #include "balloc.h"
42 > #include "mempool.h"
43 > #include "misc.h"
44 > #include "resv.h"
45  
46 struct config_channel_entry ConfigChannel;
47 dlink_list global_channel_list = { NULL, NULL, 0 };
48 BlockHeap *ban_heap;    /*! \todo ban_heap shouldn't be a global var */
46  
47 < static BlockHeap *member_heap = NULL;
48 < static BlockHeap *channel_heap = NULL;
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;
58   static char buf[IRCD_BUFSIZE];
54 static char modebuf[MODEBUFLEN];
55 static char parabuf[MODEBUFLEN];
59  
60  
61   /*! \brief Initializes the channel blockheap, adds known channel CAPAB
62   */
63   void
64 < init_channels(void)
64 > channel_init(void)
65   {
66    add_capability("EX", CAP_EX, 1);
67    add_capability("IE", CAP_IE, 1);
65  add_capability("CHW", CAP_CHW, 1);
68  
69 <  channel_heap = BlockHeapCreate("channel", sizeof(struct Channel), CHANNEL_HEAP_SIZE);
70 <  ban_heap = BlockHeapCreate("ban", sizeof(struct Ban), BAN_HEAP_SIZE);
71 <  member_heap = BlockHeapCreate("member", sizeof(struct Membership), CHANNEL_HEAP_SIZE*2);
69 >  channel_pool = mp_pool_new(sizeof(struct Channel), MP_CHUNK_SIZE_CHANNEL);
70 >  ban_pool = mp_pool_new(sizeof(struct Ban), MP_CHUNK_SIZE_BAN);
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 85 | 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 103 | Line 105 | add_user_to_channel(struct Channel *chpt
105        if (!IsSetJoinFloodNoticed(chptr))
106        {
107          SetJoinFloodNoticed(chptr);
108 <        sendto_realops_flags(UMODE_BOTS, L_ALL,
108 >        sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE,
109                               "Possible Join Flooder %s on %s target: %s",
110                               get_client_name(who, HIDE_IP),
111                               who->servptr->name, chptr->chname);
# Line 113 | Line 115 | add_user_to_channel(struct Channel *chpt
115      chptr->last_join_time = CurrentTime;
116    }
117  
118 <  ms = BlockHeapAlloc(member_heap);
118 >  ms = mp_pool_get(member_pool);
119    ms->client_p = who;
120    ms->chptr = chptr;
121    ms->flags = flags;
# Line 122 | 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 135 | Line 137 | remove_user_from_channel(struct Membersh
137    dlinkDelete(&member->channode, &chptr->members);
138    dlinkDelete(&member->usernode, &client_p->channel);
139  
140 <  BlockHeapFree(member_heap, member);
140 >  mp_pool_release(member);
141  
142    if (chptr->members.head == NULL)
143      destroy_channel(chptr);
# Line 149 | Line 151 | remove_user_from_channel(struct Membersh
151   */
152   static void
153   send_members(struct Client *client_p, struct Channel *chptr,
154 <             char *lmodebuf, char *lparabuf)
154 >             char *modebuf, char *parabuf)
155   {
156 <  struct Membership *ms;
155 <  dlink_node *ptr;
156 >  const dlink_node *ptr = NULL;
157    int tlen;              /* length of text to append */
158    char *t, *start;       /* temp char pointer */
159  
160 <  start = t = buf + ircsprintf(buf, ":%s SJOIN %lu %s %s %s:",
161 <                               ID_or_name(&me, client_p),
162 <                               (unsigned long)chptr->channelts,
162 <                               chptr->chname, lmodebuf, lparabuf);
160 >  start = t = buf + snprintf(buf, sizeof(buf), ":%s SJOIN %lu %s %s %s:",
161 >                             me.id, (unsigned long)chptr->channelts,
162 >                             chptr->chname, modebuf, parabuf);
163  
164    DLINK_FOREACH(ptr, chptr->members.head)
165    {
166 <    ms = ptr->data;
166 >    const struct Membership *ms = ptr->data;
167  
168 <    tlen = strlen(IsCapable(client_p, CAP_TS6) ?
169 <      ID(ms->client_p) : ms->client_p->name) + 1;  /* nick + space */
168 >    tlen = strlen(ms->client_p->id) + 1;  /* +1 for space */
169  
170      if (ms->flags & CHFL_CHANOP)
171 <      tlen++;
172 < #ifdef HALFOPS
173 <    else if (ms->flags & CHFL_HALFOP)
175 <      tlen++;
176 < #endif
171 >      ++tlen;
172 >    if (ms->flags & CHFL_HALFOP)
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      }
187  
188 <    if ((ms->flags & (CHFL_CHANOP | CHFL_HALFOP)))
189 <      *t++ = (!(ms->flags & CHFL_CHANOP) && IsCapable(client_p, CAP_HOPS)) ?
190 <        '%' : '@';
191 <    if ((ms->flags & CHFL_VOICE))
188 >    if (ms->flags & CHFL_CHANOP)
189 >      *t++ = '@';
190 >    if (ms->flags & CHFL_HALFOP)
191 >      *t++ = '%';
192 >    if (ms->flags & CHFL_VOICE)
193        *t++ = '+';
194  
195 <    if (IsCapable(client_p, CAP_TS6))
196 <      strcpy(t, ID(ms->client_p));
198 <    else
199 <      strcpy(t, ms->client_p->name);
195 >    strcpy(t, ms->client_p->id);
196 >
197      t += strlen(t);
198      *t++ = ' ';
199    }
200  
201 <  /* should always be non-NULL unless we have a kind of persistent channels */
202 <  if (chptr->members.head != NULL)
203 <    t--;  /* take the space out */
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 */
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 <               dlink_list *top, char flag)
216 >               const dlink_list *list, char flag)
217   {
218 <  int ts5 = !IsCapable(client_p, CAP_TS6);
219 <  dlink_node *lp;
220 <  struct Ban *banptr;
221 <  char pbuf[IRCD_BUFSIZE];
225 <  int tlen, mlen, cur_len, count = 0;
226 <  char *mp = NULL, *pp = pbuf;
218 >  const dlink_node *ptr = NULL;
219 >  char pbuf[IRCD_BUFSIZE] = "";
220 >  int tlen, mlen, cur_len;
221 >  char *pp = pbuf;
222  
223 <  if (top == NULL || top->length == 0)
223 >  if (list->length == 0)
224      return;
225  
226 <  if (ts5)
227 <    mlen = ircsprintf(buf, ":%s MODE %s +", me.name, chptr->chname);
228 <  else
234 <    mlen = ircsprintf(buf, ":%s BMASK %lu %s %c :", me.id,
235 <                      (unsigned long)chptr->channelts, chptr->chname, flag);
236 <
237 <  /* MODE needs additional one byte for space between buf and pbuf */
238 <  cur_len = mlen + ts5;
239 <  mp = buf + mlen;
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 <    banptr = lp->data;
232 >    const struct Ban *banptr = ptr->data;
233  
234 <    /* must add another b/e/I letter if we use MODE */
246 <    tlen = banptr->len + 3 + ts5;
234 >    tlen = banptr->len + 3;  /* +3 for ! + @ + space */
235  
236      /*
237 <     * send buffer and start over if we cannot fit another ban,
250 <     * or if the target is non-ts6 and we have too many modes in
251 <     * 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 ||
254 <        (!IsCapable(client_p, CAP_TS6) &&
255 <         (count >= MAXMODEPARAMS || pp - pbuf >= MODEBUFLEN)))
239 >    if (cur_len + (tlen - 1) > IRCD_BUFSIZE - 2)
240      {
241 <      *(pp - 1) = '\0';  /* get rid of trailing space on buffer */
242 <      sendto_one(client_p, "%s%s%s", buf, ts5 ? " " : "", pbuf);
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 + ts5;
261 <      mp = buf + mlen;
244 >      cur_len = mlen;
245        pp = pbuf;
263      count = 0;
264    }
265
266    count++;
267    if (ts5)
268    {
269      *mp++ = flag;
270      *mp = '\0';
246      }
247  
248 <    pp += ircsprintf(pp, "%s!%s@%s ", banptr->name, banptr->username,
249 <                     banptr->host);
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 */
254 <  sendto_one(client_p, "%s%s%s", buf, ts5 ? " " : "", pbuf);
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)
263   {
264 <  if (chptr->chname[0] != '#')
265 <    return;
264 >  char modebuf[MODEBUFLEN] = "";
265 >  char parabuf[MODEBUFLEN] = "";
266  
292  *modebuf = *parabuf = '\0';
267    channel_modes(chptr, client_p, modebuf, parabuf);
268    send_members(client_p, chptr, modebuf, parabuf);
269  
270    send_mode_list(client_p, chptr, &chptr->banlist, 'b');
271 <
272 <  if (IsCapable(client_p, CAP_EX))
299 <    send_mode_list(client_p, chptr, &chptr->exceptlist, 'e');
300 <  if (IsCapable(client_p, CAP_IE))
301 <    send_mode_list(client_p, chptr, &chptr->invexlist, 'I');
271 >  send_mode_list(client_p, chptr, &chptr->exceptlist, 'e');
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, int local)
281 > check_channel_name(const char *name, const int local)
282   {
283    const char *p = name;
284 <  int max_length = local ? LOCAL_CHANNELLEN : CHANNELLEN;
284 >
285    assert(name != NULL);
286  
287    if (!IsChanPrefix(*p))
# Line 329 | Line 300 | check_channel_name(const char *name, int
300          return 0;
301    }
302  
303 <  return p - name <= max_length;
303 >  return p - name <= CHANNELLEN;
304   }
305  
306   void
# Line 338 | Line 309 | remove_ban(struct Ban *bptr, dlink_list
309    dlinkDelete(&bptr->node, list);
310  
311    MyFree(bptr->name);
312 <  MyFree(bptr->username);
312 >  MyFree(bptr->user);
313    MyFree(bptr->host);
314    MyFree(bptr->who);
315  
316 <  BlockHeapFree(ban_heap, bptr);
316 >  mp_pool_release(bptr);
317   }
318  
319   /* free_channel_list()
# Line 354 | 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 364 | 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 374 | Line 345 | make_channel(const char *chname)
345  
346    assert(!EmptyString(chname));
347  
348 <  chptr = BlockHeapAlloc(channel_heap);
348 >  chptr = mp_pool_get(channel_pool);
349  
350 <  /* 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 399 | 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 <  BlockHeapFree(channel_heap, chptr);
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 425 | 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
405   channel_member_names(struct Client *source_p, struct Channel *chptr,
406                       int show_eon)
407   {
408 <  struct Client *target_p = NULL;
409 <  struct Membership *ms = NULL;
439 <  dlink_node *ptr = NULL;
440 <  char lbuf[IRCD_BUFSIZE + 1];
408 >  const dlink_node *ptr = NULL;
409 >  char lbuf[IRCD_BUFSIZE + 1] = "";
410    char *t = NULL, *start = NULL;
411    int tlen = 0;
412    int is_member = IsMember(source_p, chptr);
413    int multi_prefix = HasCap(source_p, CAP_MULTI_PREFIX) != 0;
414 +  int uhnames = HasCap(source_p, CAP_UHNAMES) != 0;
415  
416    if (PubChannel(chptr) || is_member)
417    {
418 <    t = lbuf + ircsprintf(lbuf, form_str(RPL_NAMREPLY),
419 <                          me.name, source_p->name,
420 <                          channel_pub_or_secret(chptr),
451 <                          chptr->chname);
418 >    t = lbuf + snprintf(lbuf, sizeof(lbuf), numeric_form(RPL_NAMREPLY),
419 >                        me.name, source_p->name,
420 >                        channel_pub_or_secret(chptr), chptr->chname);
421      start = t;
422  
423      DLINK_FOREACH(ptr, chptr->members.head)
424      {
425 <      ms       = ptr->data;
457 <      target_p = ms->client_p;
425 >      const struct Membership *ms = ptr->data;
426  
427 <      if (HasUMode(target_p, UMODE_INVISIBLE) && !is_member)
427 >      if (HasUMode(ms->client_p, UMODE_INVISIBLE) && !is_member)
428          continue;
429  
430 <      tlen = strlen(target_p->name) + 1;  /* nick + space */
430 >      if (!uhnames)
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;  /* +3 for ! + @ + space */
435  
436        if (!multi_prefix)
437        {
# Line 483 | Line 455 | channel_member_names(struct Client *sour
455          t = start;
456        }
457  
458 <      t += ircsprintf(t, "%s%s ", get_member_status(ms, multi_prefix),
459 <                      target_p->name);
458 >      if (!uhnames)
459 >        t += sprintf(t, "%s%s ", get_member_status(ms, multi_prefix),
460 >                     ms->client_p->name);
461 >      else
462 >        t += sprintf(t, "%s%s!%s@%s ", get_member_status(ms, multi_prefix),
463 >                     ms->client_p->name, ms->client_p->username,
464 >                     ms->client_p->host);
465      }
466  
467 <    if (tlen != 0)
467 >    if (tlen)
468      {
469        *(t - 1) = '\0';
470        sendto_one(source_p, "%s", lbuf);
# Line 495 | Line 472 | channel_member_names(struct Client *sour
472    }
473  
474    if (show_eon)
475 <    sendto_one(source_p, form_str(RPL_ENDOFNAMES),
499 <               me.name, source_p->name, chptr->chname);
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 509 | 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 551 | Line 527 | del_invite(struct Channel *chptr, struct
527   * (like in get_client_name)
528   */
529   const char *
530 < get_member_status(const struct Membership *ms, int combine)
530 > get_member_status(const struct Membership *ms, const int combine)
531   {
532 <  static char buffer[4];
533 <  char *p = NULL;
558 <
559 <  if (ms == NULL)
560 <    return "";
561 <  p = buffer;
532 >  static char buffer[4];  /* 4 for @%+\0 */
533 >  char *p = buffer;
534  
535    if (ms->flags & CHFL_CHANOP)
536    {
# Line 567 | Line 539 | get_member_status(const struct Membershi
539      *p++ = '@';
540    }
541  
570 #ifdef HALFOPS
542    if (ms->flags & CHFL_HALFOP)
543    {
544      if (!combine)
545        return "%";
546      *p++ = '%';
547    }
577 #endif
548  
549    if (ms->flags & CHFL_VOICE)
550      *p++ = '+';
# Line 584 | 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 596 | Line 566 | find_bmask(const struct Client *who, con
566  
567    DLINK_FOREACH(ptr, list->head)
568    {
569 <    struct Ban *bp = ptr->data;
569 >    const struct Ban *bp = ptr->data;
570  
571 <    if (match(bp->name, who->name) && match(bp->username, who->username))
571 >    if (!match(bp->name, who->name) && !match(bp->user, who->username))
572      {
573        switch (bp->type)
574        {
575          case HM_HOST:
576 <          if (match(bp->host, who->host) || match(bp->host, who->sockhost))
576 >          if (!match(bp->host, who->host) || !match(bp->host, who->sockhost))
577              return 1;
578            break;
579          case HM_IPV4:
# Line 628 | 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
606   is_banned(const struct Channel *chptr, const struct Client *who)
607   {
608    if (find_bmask(who, &chptr->banlist))
609 <    if (!ConfigChannel.use_except || !find_bmask(who, &chptr->exceptlist))
609 >    if (!find_bmask(who, &chptr->exceptlist))
610        return 1;
611  
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   */
622   int
623   can_join(struct Client *source_p, struct Channel *chptr, const char *key)
624   {
625 <  if (is_banned(chptr, source_p))
656 <    return ERR_BANNEDFROMCHAN;
657 <
658 < #ifdef HAVE_LIBCRYPTO
659 <  if ((chptr->mode.mode & MODE_SSLONLY) && !source_p->localClient->fd.ssl)
625 >  if ((chptr->mode.mode & MODE_SSLONLY) && !HasUMode(source_p, UMODE_SSL))
626      return ERR_SSLONLYCHAN;
661 #endif
627  
628    if ((chptr->mode.mode & MODE_REGONLY) && !HasUMode(source_p, UMODE_REGISTERED))
629      return ERR_NEEDREGGEDNICK;
# Line 668 | Line 633 | can_join(struct Client *source_p, struct
633  
634    if (chptr->mode.mode & MODE_INVITEONLY)
635      if (!dlinkFind(&source_p->localClient->invited, chptr))
636 <      if (!ConfigChannel.use_invex || !find_bmask(source_p, &chptr->invexlist))
636 >      if (!find_bmask(source_p, &chptr->invexlist))
637          return ERR_INVITEONLYCHAN;
638  
639 <  if (chptr->mode.key[0] && (!key || irccmp(chptr->mode.key, key)))
639 >  if (chptr->mode.key[0] && (!key || strcmp(chptr->mode.key, key)))
640      return ERR_BADCHANNELKEY;
641  
642    if (chptr->mode.limit && dlink_list_length(&chptr->members) >=
643        chptr->mode.limit)
644      return ERR_CHANNELISFULL;
645  
646 +  if (is_banned(chptr, source_p))
647 +    return ERR_BANNEDFROMCHAN;
648 +
649    return 0;
650   }
651  
652   int
653 < has_member_flags(struct Membership *ms, unsigned int flags)
653 > has_member_flags(const struct Membership *ms, const unsigned int flags)
654   {
655 <  if (ms != NULL)
688 <    return ms->flags & flags;
689 <  return 0;
655 >  return ms && (ms->flags & flags);
656   }
657  
658   struct Membership *
# Line 697 | Line 663 | find_channel_link(struct Client *client_
663    if (!IsClient(client_p))
664      return NULL;
665  
666 <  DLINK_FOREACH(ptr, client_p->channel.head)
667 <    if (((struct Membership *)ptr->data)->chptr == chptr)
668 <      return ptr->data;
666 >  if (dlink_list_length(&chptr->members) < dlink_list_length(&client_p->channel))
667 >  {
668 >    DLINK_FOREACH(ptr, chptr->members.head)
669 >      if (((struct Membership *)ptr->data)->client_p == client_p)
670 >        return ptr->data;
671 >  }
672 >  else
673 >  {
674 >    DLINK_FOREACH(ptr, client_p->channel.head)
675 >      if (((struct Membership *)ptr->data)->chptr == chptr)
676 >        return ptr->data;
677 >  }
678  
679    return NULL;
680   }
681  
682 < /*!
683 < * \param chptr    pointer to Channel struct
684 < * \param source_p pointer to Client struct
685 < * \param ms       pointer to Membership struct (can be NULL)
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)
688 > {
689 >  const unsigned char *p = (const unsigned char *)message;
690 >
691 >  for (; *p; ++p)
692 >  {
693 >    if (*p > 31 || *p == 1)
694 >      continue;  /* No control code or CTCP */
695 >
696 >    if (*p == 27)  /* Escape */
697 >    {
698 >      /* ISO 2022 charset shift sequence */
699 >      if (*(p + 1) == '$' ||
700 >          *(p + 1) == '(')
701 >      {
702 >        ++p;
703 >        continue;
704 >      }
705 >    }
706 >
707 >    return 1;  /* Control code */
708 >  }
709 >
710 >  return 0;
711 > }
712 >
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
721   */
722   int
723 < can_send(struct Channel *chptr, struct Client *source_p, struct Membership *ms)
723 > can_send(struct Channel *chptr, struct Client *source_p,
724 >         struct Membership *ms, const char *message)
725   {
726 +  struct MaskItem *conf = NULL;
727 +
728    if (IsServer(source_p) || HasFlag(source_p, FLAGS_SERVICE))
729      return CAN_SEND_OPV;
730  
731    if (MyClient(source_p) && !IsExemptResv(source_p))
732      if (!(HasUMode(source_p, UMODE_OPER) && ConfigFileEntry.oper_pass_resv))
733 <      if (!hash_find_resv(chptr->chname) == ConfigChannel.restrict_channels)
733 >      if ((conf = match_find_resv(chptr->chname)) && !resv_find_exempt(source_p, conf))
734          return ERR_CANNOTSENDTOCHAN;
735  
736 <  if (ms != NULL || (ms = find_channel_link(source_p, chptr)))
737 <  {
736 >  if ((chptr->mode.mode & MODE_NOCTRL) && msg_has_ctrls(message))
737 >    return ERR_NOCTRLSONCHAN;
738 >  if (ms || (ms = find_channel_link(source_p, chptr)))
739      if (ms->flags & (CHFL_CHANOP|CHFL_HALFOP|CHFL_VOICE))
740        return CAN_SEND_OPV;
741 +  if (!ms && (chptr->mode.mode & MODE_NOPRIVMSGS))
742 +    return ERR_CANNOTSENDTOCHAN;
743 +  if (chptr->mode.mode & MODE_MODERATED)
744 +    return ERR_CANNOTSENDTOCHAN;
745 +  if ((chptr->mode.mode & MODE_MODREG) && !HasUMode(source_p, UMODE_REGISTERED))
746 +    return ERR_NEEDREGGEDNICK;
747  
748 <    /* cache can send if quiet_on_ban and banned */
749 <    if (ConfigChannel.quiet_on_ban && MyClient(source_p))
748 >  /* Cache can send if banned */
749 >  if (MyClient(source_p))
750 >  {
751 >    if (ms)
752      {
753        if (ms->flags & CHFL_BAN_SILENCED)
754          return ERR_CANNOTSENDTOCHAN;
# Line 745 | Line 764 | can_send(struct Channel *chptr, struct C
764          ms->flags |= CHFL_BAN_CHECKED;
765        }
766      }
767 +    else if (is_banned(chptr, source_p))
768 +      return ERR_CANNOTSENDTOCHAN;
769    }
749  else if (chptr->mode.mode & MODE_NOPRIVMSGS)
750    return ERR_CANNOTSENDTOCHAN;
751
752  if (chptr->mode.mode & MODE_MODERATED)
753    return ERR_CANNOTSENDTOCHAN;
770  
771    return CAN_SEND_NONOP;
772   }
# Line 758 | 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 778 | 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 */
798 <      if (name != NULL)
799 <        sendto_realops_flags(UMODE_BOTS, L_ALL,
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",
801                               source_p->name, source_p->username,
802                               source_p->host, name);
803        else
804 <        sendto_realops_flags(UMODE_BOTS, L_ALL,
804 >        sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE,
805                               "User %s (%s@%s) is a possible spambot",
806                               source_p->name, source_p->username,
807                               source_p->host);
# Line 807 | Line 823 | check_spambot_warning(struct Client *sou
823      {
824        if ((CurrentTime - (source_p->localClient->last_join_time)) <
825            GlobalSetOptions.spam_time)
826 <      {
811 <        /* oh, its a possible spambot */
812 <        source_p->localClient->join_leave_count++;
813 <      }
826 >        source_p->localClient->join_leave_count++;  /* It's a possible spambot */
827      }
828  
829 <    if (name != NULL)
829 >    if (name)
830        source_p->localClient->last_join_time = CurrentTime;
831      else
832        source_p->localClient->last_leave_time = CurrentTime;
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 836 | Line 849 | check_splitmode(void *unused)
849      {
850        splitmode = 1;
851  
852 <      sendto_realops_flags(UMODE_ALL,L_ALL,
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,
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,
876 <                  const char *topic_info, time_t topicts)
875 > channel_set_topic(struct Channel *chptr, const char *topic,
876 >                  const char *topic_info, time_t topicts, int local)
877   {
878 <  strlcpy(chptr->topic, topic, sizeof(chptr->topic));
878 >  if (local)
879 >    strlcpy(chptr->topic, topic, IRCD_MIN(sizeof(chptr->topic), ServerInfo.max_topic_length + 1));
880 >  else
881 >    strlcpy(chptr->topic, topic, sizeof(chptr->topic));
882 >
883    strlcpy(chptr->topic_info, topic_info, sizeof(chptr->topic_info));
884 <  chptr->topic_time = topicts;
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)