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 1474 by michael, Sun Jul 22 14:44:07 2012 UTC vs.
ircd-hybrid/trunk/src/channel.c (file contents), Revision 3952 by michael, Mon Jun 16 19:53:05 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 + static mp_pool_t *member_pool, *channel_pool;
51   static char buf[IRCD_BUFSIZE];
54 static char modebuf[MODEBUFLEN];
55 static char parabuf[MODEBUFLEN];
52  
53  
54   /*! \brief Initializes the channel blockheap, adds known channel CAPAB
55   */
56   void
57 < init_channels(void)
57 > channel_init(void)
58   {
59    add_capability("EX", CAP_EX, 1);
60    add_capability("IE", CAP_IE, 1);
65  add_capability("CHW", CAP_CHW, 1);
61  
62 <  channel_heap = BlockHeapCreate("channel", sizeof(struct Channel), CHANNEL_HEAP_SIZE);
63 <  ban_heap = BlockHeapCreate("ban", sizeof(struct Ban), BAN_HEAP_SIZE);
64 <  member_heap = BlockHeapCreate("member", sizeof(struct Membership), CHANNEL_HEAP_SIZE*2);
62 >  channel_pool = mp_pool_new(sizeof(struct Channel), MP_CHUNK_SIZE_CHANNEL);
63 >  ban_pool = mp_pool_new(sizeof(struct Ban), MP_CHUNK_SIZE_BAN);
64 >  member_pool = mp_pool_new(sizeof(struct Membership), MP_CHUNK_SIZE_MEMBER);
65   }
66  
67 < /*! \brief adds a user to a channel by adding another link to the
67 > /*! \brief Adds a user to a channel by adding another link to the
68   *         channels member chain.
69 < * \param chptr      pointer to channel to add client to
70 < * \param who        pointer to client (who) to add
71 < * \param flags      flags for chanops etc
72 < * \param flood_ctrl whether to count this join in flood calculations
69 > * \param chptr      Pointer to channel to add client to
70 > * \param who        Pointer to client (who) to add
71 > * \param flags      Flags for chanops etc
72 > * \param flood_ctrl Whether to count this join in flood calculations
73   */
74   void
75   add_user_to_channel(struct Channel *chptr, struct Client *who,
# Line 85 | Line 80 | add_user_to_channel(struct Channel *chpt
80    if (GlobalSetOptions.joinfloodtime > 0)
81    {
82      if (flood_ctrl)
83 <      chptr->number_joined++;
83 >      ++chptr->number_joined;
84  
85      chptr->number_joined -= (CurrentTime - chptr->last_join_time) *
86        (((float)GlobalSetOptions.joinfloodcount) /
# Line 103 | Line 98 | add_user_to_channel(struct Channel *chpt
98        if (!IsSetJoinFloodNoticed(chptr))
99        {
100          SetJoinFloodNoticed(chptr);
101 <        sendto_realops_flags(UMODE_BOTS, L_ALL,
101 >        sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE,
102                               "Possible Join Flooder %s on %s target: %s",
103                               get_client_name(who, HIDE_IP),
104                               who->servptr->name, chptr->chname);
# Line 113 | Line 108 | add_user_to_channel(struct Channel *chpt
108      chptr->last_join_time = CurrentTime;
109    }
110  
111 <  ms = BlockHeapAlloc(member_heap);
111 >  ms = mp_pool_get(member_pool);
112 >  memset(ms, 0, sizeof(*ms));
113 >
114    ms->client_p = who;
115    ms->chptr = chptr;
116    ms->flags = flags;
# Line 122 | Line 119 | add_user_to_channel(struct Channel *chpt
119    dlinkAdd(ms, &ms->usernode, &who->channel);
120   }
121  
122 < /*! \brief deletes an user from a channel by removing a link in the
122 > /*! \brief Deletes an user from a channel by removing a link in the
123   *         channels member chain.
124 < * \param member pointer to Membership struct
124 > * \param member Pointer to Membership struct
125   */
126   void
127   remove_user_from_channel(struct Membership *member)
# Line 135 | Line 132 | remove_user_from_channel(struct Membersh
132    dlinkDelete(&member->channode, &chptr->members);
133    dlinkDelete(&member->usernode, &client_p->channel);
134  
135 <  BlockHeapFree(member_heap, member);
135 >  mp_pool_release(member);
136  
137    if (chptr->members.head == NULL)
138      destroy_channel(chptr);
# Line 149 | Line 146 | remove_user_from_channel(struct Membersh
146   */
147   static void
148   send_members(struct Client *client_p, struct Channel *chptr,
149 <             char *lmodebuf, char *lparabuf)
149 >             char *modebuf, char *parabuf)
150   {
151 <  struct Membership *ms;
155 <  dlink_node *ptr;
151 >  const dlink_node *ptr = NULL;
152    int tlen;              /* length of text to append */
153    char *t, *start;       /* temp char pointer */
154  
155 <  start = t = buf + ircsprintf(buf, ":%s SJOIN %lu %s %s %s:",
156 <                               ID_or_name(&me, client_p),
157 <                               (unsigned long)chptr->channelts,
162 <                               chptr->chname, lmodebuf, lparabuf);
155 >  start = t = buf + snprintf(buf, sizeof(buf), ":%s SJOIN %lu %s %s %s:",
156 >                             me.id, (unsigned long)chptr->channelts,
157 >                             chptr->chname, modebuf, parabuf);
158  
159    DLINK_FOREACH(ptr, chptr->members.head)
160    {
161 <    ms = ptr->data;
161 >    const struct Membership *ms = ptr->data;
162  
163 <    tlen = strlen(IsCapable(client_p, CAP_TS6) ?
169 <      ID(ms->client_p) : ms->client_p->name) + 1;  /* nick + space */
163 >    tlen = strlen(ms->client_p->id) + 1;  /* nick + space */
164  
165      if (ms->flags & CHFL_CHANOP)
166 <      tlen++;
167 < #ifdef HALFOPS
168 <    else if (ms->flags & CHFL_HALFOP)
175 <      tlen++;
176 < #endif
166 >      ++tlen;
167 >    if (ms->flags & CHFL_HALFOP)
168 >      ++tlen;
169      if (ms->flags & CHFL_VOICE)
170 <      tlen++;
170 >      ++tlen;
171  
172 <    /* space will be converted into CR, but we also need space for LF..
173 <     * That's why we use '- 1' here
174 <     * -adx */
172 >    /*
173 >     * Space will be converted into CR, but we also need space for LF..
174 >     * That's why we use '- 1' here -adx
175 >     */
176      if (t + tlen - buf > IRCD_BUFSIZE - 1)
177      {
178 <      *(t - 1) = '\0';  /* kill the space and terminate the string */
178 >      *(t - 1) = '\0';  /* Kill the space and terminate the string */
179        sendto_one(client_p, "%s", buf);
180        t = start;
181      }
182  
183 <    if ((ms->flags & (CHFL_CHANOP | CHFL_HALFOP)))
184 <      *t++ = (!(ms->flags & CHFL_CHANOP) && IsCapable(client_p, CAP_HOPS)) ?
185 <        '%' : '@';
186 <    if ((ms->flags & CHFL_VOICE))
183 >    if (ms->flags & CHFL_CHANOP)
184 >      *t++ = '@';
185 >    if (ms->flags & CHFL_HALFOP)
186 >      *t++ = '%';
187 >    if (ms->flags & CHFL_VOICE)
188        *t++ = '+';
189  
190 <    if (IsCapable(client_p, CAP_TS6))
191 <      strcpy(t, ID(ms->client_p));
198 <    else
199 <      strcpy(t, ms->client_p->name);
190 >    strcpy(t, ms->client_p->id);
191 >
192      t += strlen(t);
193      *t++ = ' ';
194    }
195  
196 <  /* should always be non-NULL unless we have a kind of persistent channels */
197 <  if (chptr->members.head != NULL)
198 <    t--;  /* take the space out */
196 >  /* Should always be non-NULL unless we have a kind of persistent channels */
197 >  if (chptr->members.head)
198 >    t--;  /* Take the space out */
199    *t = '\0';
200    sendto_one(client_p, "%s", buf);
201   }
202  
203 < /*! \brief sends +b/+e/+I
204 < * \param client_p client pointer to server
205 < * \param chptr    pointer to channel
206 < * \param top      pointer to top of mode link list to send
207 < * \param flag     char flag flagging type of mode. Currently this can be 'b', e' or 'I'
203 > /*! \brief Sends +b/+e/+I
204 > * \param client_p Client pointer to server
205 > * \param chptr    Pointer to channel
206 > * \param top      Pointer to top of mode link list to send
207 > * \param flag     Char flag flagging type of mode. Currently this can be 'b', e' or 'I'
208   */
209   static void
210   send_mode_list(struct Client *client_p, struct Channel *chptr,
211 <               dlink_list *top, char flag)
211 >               const dlink_list *top, char flag)
212   {
213 <  int ts5 = !IsCapable(client_p, CAP_TS6);
214 <  dlink_node *lp;
215 <  struct Ban *banptr;
216 <  char pbuf[IRCD_BUFSIZE];
225 <  int tlen, mlen, cur_len, count = 0;
226 <  char *mp = NULL, *pp = pbuf;
213 >  const dlink_node *ptr = NULL;
214 >  char pbuf[IRCD_BUFSIZE] = "";
215 >  int tlen, mlen, cur_len;
216 >  char *pp = pbuf;
217  
218 <  if (top == NULL || top->length == 0)
218 >  if (top->length == 0)
219      return;
220  
221 <  if (ts5)
222 <    mlen = ircsprintf(buf, ":%s MODE %s +", me.name, chptr->chname);
223 <  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;
221 >  mlen = snprintf(buf, sizeof(buf), ":%s BMASK %lu %s %c :", me.id,
222 >                  (unsigned long)chptr->channelts, chptr->chname, flag);
223 >  cur_len = mlen;
224  
225 <  DLINK_FOREACH(lp, top->head)
225 >  DLINK_FOREACH(ptr, top->head)
226    {
227 <    banptr = lp->data;
227 >    const struct Ban *banptr = ptr->data;
228  
229 <    /* must add another b/e/I letter if we use MODE */
246 <    tlen = banptr->len + 3 + ts5;
229 >    tlen = banptr->len + 3;
230  
231      /*
232 <     * send buffer and start over if we cannot fit another ban,
232 >     * Send buffer and start over if we cannot fit another ban,
233       * or if the target is non-ts6 and we have too many modes in
234       * in this line.
235       */
236 <    if (cur_len + (tlen - 1) > IRCD_BUFSIZE - 2 ||
254 <        (!IsCapable(client_p, CAP_TS6) &&
255 <         (count >= MAXMODEPARAMS || pp - pbuf >= MODEBUFLEN)))
236 >    if (cur_len + (tlen - 1) > IRCD_BUFSIZE - 2)
237      {
238 <      *(pp - 1) = '\0';  /* get rid of trailing space on buffer */
239 <      sendto_one(client_p, "%s%s%s", buf, ts5 ? " " : "", pbuf);
238 >      *(pp - 1) = '\0';  /* Get rid of trailing space on buffer */
239 >      sendto_one(client_p, "%s%s", buf, pbuf);
240  
241 <      cur_len = mlen + ts5;
261 <      mp = buf + mlen;
241 >      cur_len = mlen;
242        pp = pbuf;
263      count = 0;
243      }
244  
245 <    count++;
246 <    if (ts5)
268 <    {
269 <      *mp++ = flag;
270 <      *mp = '\0';
271 <    }
272 <
273 <    pp += ircsprintf(pp, "%s!%s@%s ", banptr->name, banptr->username,
274 <                     banptr->host);
245 >    pp += sprintf(pp, "%s!%s@%s ", banptr->name, banptr->user,
246 >                  banptr->host);
247      cur_len += tlen;
248    }
249  
250 <  *(pp - 1) = '\0';  /* get rid of trailing space on buffer */
251 <  sendto_one(client_p, "%s%s%s", buf, ts5 ? " " : "", pbuf);
250 >  *(pp - 1) = '\0';  /* Get rid of trailing space on buffer */
251 >  sendto_one(client_p, "%s%s", buf, pbuf);
252   }
253  
254 < /*! \brief send "client_p" a full list of the modes for channel chptr
255 < * \param client_p pointer to client client_p
256 < * \param chptr    pointer to channel pointer
254 > /*! \brief Send "client_p" a full list of the modes for channel chptr
255 > * \param client_p Pointer to client client_p
256 > * \param chptr    Pointer to channel pointer
257   */
258   void
259   send_channel_modes(struct Client *client_p, struct Channel *chptr)
260   {
261 <  *modebuf = *parabuf = '\0';
261 >  char modebuf[MODEBUFLEN] = "";
262 >  char parabuf[MODEBUFLEN] = "";
263 >
264    channel_modes(chptr, client_p, modebuf, parabuf);
265    send_members(client_p, chptr, modebuf, parabuf);
266  
267    send_mode_list(client_p, chptr, &chptr->banlist, 'b');
268 <
269 <  if (IsCapable(client_p, CAP_EX))
296 <    send_mode_list(client_p, chptr, &chptr->exceptlist, 'e');
297 <  if (IsCapable(client_p, CAP_IE))
298 <    send_mode_list(client_p, chptr, &chptr->invexlist, 'I');
268 >  send_mode_list(client_p, chptr, &chptr->exceptlist, 'e');
269 >  send_mode_list(client_p, chptr, &chptr->invexlist, 'I');
270   }
271  
272 < /*! \brief check channel name for invalid characters
273 < * \param name pointer to channel name string
274 < * \param local indicates whether it's a local or remote creation
272 > /*! \brief Check channel name for invalid characters
273 > * \param name Pointer to channel name string
274 > * \param local Indicates whether it's a local or remote creation
275   * \return 0 if invalid, 1 otherwise
276   */
277   int
278 < check_channel_name(const char *name, int local)
278 > check_channel_name(const char *name, const int local)
279   {
280    const char *p = name;
281 <  const int max_length = local ? LOCAL_CHANNELLEN : CHANNELLEN;
281 >
282    assert(name != NULL);
283  
284    if (!IsChanPrefix(*p))
# Line 326 | Line 297 | check_channel_name(const char *name, int
297          return 0;
298    }
299  
300 <  return p - name <= max_length;
300 >  return p - name <= CHANNELLEN;
301   }
302  
303   void
# Line 335 | Line 306 | remove_ban(struct Ban *bptr, dlink_list
306    dlinkDelete(&bptr->node, list);
307  
308    MyFree(bptr->name);
309 <  MyFree(bptr->username);
309 >  MyFree(bptr->user);
310    MyFree(bptr->host);
311    MyFree(bptr->who);
312  
313 <  BlockHeapFree(ban_heap, bptr);
313 >  mp_pool_release(bptr);
314   }
315  
316   /* free_channel_list()
# Line 351 | Line 322 | remove_ban(struct Ban *bptr, dlink_list
322   void
323   free_channel_list(dlink_list *list)
324   {
325 <  dlink_node *ptr = NULL, *next_ptr = NULL;
325 >  dlink_node *ptr = NULL, *ptr_next = NULL;
326  
327 <  DLINK_FOREACH_SAFE(ptr, next_ptr, list->head)
327 >  DLINK_FOREACH_SAFE(ptr, ptr_next, list->head)
328      remove_ban(ptr->data, list);
329  
330    assert(list->tail == NULL && list->head == NULL);
# Line 361 | Line 332 | free_channel_list(dlink_list *list)
332  
333   /*! \brief Get Channel block for chname (and allocate a new channel
334   *         block, if it didn't exist before)
335 < * \param chname channel name
336 < * \return channel block
335 > * \param chname Channel name
336 > * \return Channel block
337   */
338   struct Channel *
339   make_channel(const char *chname)
# Line 371 | Line 342 | make_channel(const char *chname)
342  
343    assert(!EmptyString(chname));
344  
345 <  chptr = BlockHeapAlloc(channel_heap);
345 >  chptr = mp_pool_get(channel_pool);
346  
347 <  /* doesn't hurt to set it here */
347 >  memset(chptr, 0, sizeof(*chptr));
348 >
349 >  /* Doesn't hurt to set it here */
350    chptr->channelts = CurrentTime;
351    chptr->last_join_time = CurrentTime;
352  
353    strlcpy(chptr->chname, chname, sizeof(chptr->chname));
354 <  dlinkAdd(chptr, &chptr->node, &global_channel_list);
354 >  dlinkAdd(chptr, &chptr->node, &channel_list);
355  
356    hash_add_channel(chptr);
357  
358    return chptr;
359   }
360  
361 < /*! \brief walk through this channel, and destroy it.
362 < * \param chptr channel pointer
361 > /*! \brief Walk through this channel, and destroy it.
362 > * \param chptr Channel pointer
363   */
364   void
365   destroy_channel(struct Channel *chptr)
# Line 396 | Line 369 | destroy_channel(struct Channel *chptr)
369    DLINK_FOREACH_SAFE(ptr, ptr_next, chptr->invites.head)
370      del_invite(chptr, ptr->data);
371  
372 <  /* free ban/exception/invex lists */
372 >  /* Free ban/exception/invex lists */
373    free_channel_list(&chptr->banlist);
374    free_channel_list(&chptr->exceptlist);
375    free_channel_list(&chptr->invexlist);
376  
377 <  dlinkDelete(&chptr->node, &global_channel_list);
377 >  dlinkDelete(&chptr->node, &channel_list);
378    hash_del_channel(chptr);
379  
380 <  BlockHeapFree(channel_heap, chptr);
380 >  mp_pool_release(chptr);
381   }
382  
383   /*!
384 < * \param chptr pointer to channel
385 < * \return string pointer "=" if public, "@" if secret else "*"
384 > * \param chptr Pointer to channel
385 > * \return String pointer "=" if public, "@" if secret else "*"
386   */
387   static const char *
388   channel_pub_or_secret(const struct Channel *chptr)
# Line 422 | Line 395 | channel_pub_or_secret(const struct Chann
395   }
396  
397   /*! \brief lists all names on given channel
398 < * \param source_p pointer to client struct requesting names
399 < * \param chptr    pointer to channel block
400 < * \param show_eon show ENDOFNAMES numeric or not
398 > * \param source_p Pointer to client struct requesting names
399 > * \param chptr    Pointer to channel block
400 > * \param show_eon Show RPL_ENDOFNAMES numeric or not
401   *                 (don't want it with /names with no params)
402   */
403   void
404   channel_member_names(struct Client *source_p, struct Channel *chptr,
405                       int show_eon)
406   {
407 <  struct Client *target_p = NULL;
408 <  struct Membership *ms = NULL;
436 <  dlink_node *ptr = NULL;
437 <  char lbuf[IRCD_BUFSIZE + 1];
407 >  const dlink_node *ptr = NULL;
408 >  char lbuf[IRCD_BUFSIZE + 1] = "";
409    char *t = NULL, *start = NULL;
410    int tlen = 0;
411    int is_member = IsMember(source_p, chptr);
412    int multi_prefix = HasCap(source_p, CAP_MULTI_PREFIX) != 0;
413 +  int uhnames = HasCap(source_p, CAP_UHNAMES) != 0;
414  
415    if (PubChannel(chptr) || is_member)
416    {
417 <    t = lbuf + ircsprintf(lbuf, form_str(RPL_NAMREPLY),
418 <                          me.name, source_p->name,
419 <                          channel_pub_or_secret(chptr),
448 <                          chptr->chname);
417 >    t = lbuf + snprintf(lbuf, sizeof(lbuf), numeric_form(RPL_NAMREPLY),
418 >                        me.name, source_p->name,
419 >                        channel_pub_or_secret(chptr), chptr->chname);
420      start = t;
421  
422      DLINK_FOREACH(ptr, chptr->members.head)
423      {
424 <      ms       = ptr->data;
454 <      target_p = ms->client_p;
424 >      const struct Membership *ms = ptr->data;
425  
426 <      if (HasUMode(target_p, UMODE_INVISIBLE) && !is_member)
426 >      if (HasUMode(ms->client_p, UMODE_INVISIBLE) && !is_member)
427          continue;
428  
429 <      tlen = strlen(target_p->name) + 1;  /* nick + space */
429 >      if (!uhnames)
430 >        tlen = strlen(ms->client_p->name) + 1;  /* nick + space */
431 >      else
432 >        tlen = strlen(ms->client_p->name) + strlen(ms->client_p->username) +
433 >               strlen(ms->client_p->host) + 3;  /* nick + ! + user + @ + host + space */
434  
435        if (!multi_prefix)
436        {
# Line 480 | Line 454 | channel_member_names(struct Client *sour
454          t = start;
455        }
456  
457 <      t += ircsprintf(t, "%s%s ", get_member_status(ms, multi_prefix),
458 <                      target_p->name);
457 >      if (!uhnames)
458 >        t += sprintf(t, "%s%s ", get_member_status(ms, multi_prefix),
459 >                     ms->client_p->name);
460 >      else
461 >        t += sprintf(t, "%s%s!%s@%s ", get_member_status(ms, multi_prefix),
462 >                     ms->client_p->name, ms->client_p->username,
463 >                     ms->client_p->host);
464      }
465  
466 <    if (tlen != 0)
466 >    if (tlen)
467      {
468        *(t - 1) = '\0';
469        sendto_one(source_p, "%s", lbuf);
# Line 492 | Line 471 | channel_member_names(struct Client *sour
471    }
472  
473    if (show_eon)
474 <    sendto_one(source_p, form_str(RPL_ENDOFNAMES),
496 <               me.name, source_p->name, chptr->chname);
474 >    sendto_one_numeric(source_p, &me, RPL_ENDOFNAMES, chptr->chname);
475   }
476  
477 < /*! \brief adds client to invite list
478 < * \param chptr pointer to channel block
479 < * \param who   pointer to client to add invite to
477 > /*! \brief Adds client to invite list
478 > * \param chptr Pointer to channel block
479 > * \param who   Pointer to client to add invite to
480   */
481   void
482   add_invite(struct Channel *chptr, struct Client *who)
# Line 506 | Line 484 | add_invite(struct Channel *chptr, struct
484    del_invite(chptr, who);
485  
486    /*
487 <   * delete last link in chain if the list is max length
487 >   * Delete last link in chain if the list is max length
488     */
489    if (dlink_list_length(&who->localClient->invited) >=
490 <      ConfigChannel.max_chans_per_user)
490 >      ConfigChannel.max_channels)
491      del_invite(who->localClient->invited.tail->data, who);
492  
493 <  /* add client to channel invite list */
493 >  /* Add client to channel invite list */
494    dlinkAdd(who, make_dlink_node(), &chptr->invites);
495  
496 <  /* add channel to the end of the client invite list */
496 >  /* Add channel to the end of the client invite list */
497    dlinkAdd(chptr, make_dlink_node(), &who->localClient->invited);
498   }
499  
500   /*! \brief Delete Invite block from channel invite list
501   *         and client invite list
502 < * \param chptr pointer to Channel struct
503 < * \param who   pointer to client to remove invites from
502 > * \param chptr Pointer to Channel struct
503 > * \param who   Pointer to client to remove invites from
504   */
505   void
506   del_invite(struct Channel *chptr, struct Client *who)
# Line 548 | Line 526 | del_invite(struct Channel *chptr, struct
526   * (like in get_client_name)
527   */
528   const char *
529 < get_member_status(const struct Membership *ms, int combine)
529 > get_member_status(const struct Membership *ms, const int combine)
530   {
531    static char buffer[4];
532 <  char *p = NULL;
555 <
556 <  if (ms == NULL)
557 <    return "";
558 <  p = buffer;
532 >  char *p = buffer;
533  
534    if (ms->flags & CHFL_CHANOP)
535    {
# Line 564 | Line 538 | get_member_status(const struct Membershi
538      *p++ = '@';
539    }
540  
567 #ifdef HALFOPS
541    if (ms->flags & CHFL_HALFOP)
542    {
543      if (!combine)
544        return "%";
545      *p++ = '%';
546    }
574 #endif
547  
548    if (ms->flags & CHFL_VOICE)
549      *p++ = '+';
# Line 581 | Line 553 | get_member_status(const struct Membershi
553   }
554  
555   /*!
556 < * \param who  pointer to Client to check
557 < * \param list pointer to ban list to search
556 > * \param who  Pointer to Client to check
557 > * \param list Pointer to ban list to search
558   * \return 1 if ban found for given n!u\@h mask, 0 otherwise
559   *
560   */
# Line 595 | Line 567 | find_bmask(const struct Client *who, con
567    {
568      const struct Ban *bp = ptr->data;
569  
570 <    if (match(bp->name, who->name) && match(bp->username, who->username))
570 >    if (!match(bp->name, who->name) && !match(bp->user, who->username))
571      {
572        switch (bp->type)
573        {
574          case HM_HOST:
575 <          if (match(bp->host, who->host) || match(bp->host, who->sockhost))
575 >          if (!match(bp->host, who->host) || !match(bp->host, who->sockhost))
576              return 1;
577            break;
578          case HM_IPV4:
# Line 625 | Line 597 | find_bmask(const struct Client *who, con
597   }
598  
599   /*!
600 < * \param chptr pointer to channel block
601 < * \param who   pointer to client to check access fo
600 > * \param chptr Pointer to channel block
601 > * \param who   Pointer to client to check access fo
602   * \return 0 if not banned, 1 otherwise
603   */
604   int
605   is_banned(const struct Channel *chptr, const struct Client *who)
606   {
607    if (find_bmask(who, &chptr->banlist))
608 <    if (!ConfigChannel.use_except || !find_bmask(who, &chptr->exceptlist))
608 >    if (!find_bmask(who, &chptr->exceptlist))
609        return 1;
610  
611    return 0;
612   }
613  
614 < /*!
615 < * \param source_p pointer to client attempting to join
616 < * \param chptr    pointer to channel
617 < * \param key      key sent by client attempting to join if present
614 > /*! Tests if a client can join a certain channel
615 > * \param source_p Pointer to client attempting to join
616 > * \param chptr    Pointer to channel
617 > * \param key      Key sent by client attempting to join if present
618   * \return ERR_BANNEDFROMCHAN, ERR_INVITEONLYCHAN, ERR_CHANNELISFULL
619   *         or 0 if allowed to join.
620   */
621   int
622   can_join(struct Client *source_p, struct Channel *chptr, const char *key)
623   {
624 <  if (is_banned(chptr, source_p))
653 <    return ERR_BANNEDFROMCHAN;
654 <
655 < #ifdef HAVE_LIBCRYPTO
656 <  if ((chptr->mode.mode & MODE_SSLONLY) && !source_p->localClient->fd.ssl)
624 >  if ((chptr->mode.mode & MODE_SSLONLY) && !HasUMode(source_p, UMODE_SSL))
625      return ERR_SSLONLYCHAN;
658 #endif
626  
627    if ((chptr->mode.mode & MODE_REGONLY) && !HasUMode(source_p, UMODE_REGISTERED))
628      return ERR_NEEDREGGEDNICK;
# Line 665 | Line 632 | can_join(struct Client *source_p, struct
632  
633    if (chptr->mode.mode & MODE_INVITEONLY)
634      if (!dlinkFind(&source_p->localClient->invited, chptr))
635 <      if (!ConfigChannel.use_invex || !find_bmask(source_p, &chptr->invexlist))
635 >      if (!find_bmask(source_p, &chptr->invexlist))
636          return ERR_INVITEONLYCHAN;
637  
638    if (chptr->mode.key[0] && (!key || strcmp(chptr->mode.key, key)))
# Line 675 | Line 642 | can_join(struct Client *source_p, struct
642        chptr->mode.limit)
643      return ERR_CHANNELISFULL;
644  
645 +  if (is_banned(chptr, source_p))
646 +    return ERR_BANNEDFROMCHAN;
647 +
648    return 0;
649   }
650  
651   int
652 < has_member_flags(struct Membership *ms, unsigned int flags)
652 > has_member_flags(const struct Membership *ms, const unsigned int flags)
653   {
654 <  if (ms != NULL)
685 <    return ms->flags & flags;
686 <  return 0;
654 >  return ms && (ms->flags & flags);
655   }
656  
657   struct Membership *
# Line 694 | Line 662 | find_channel_link(struct Client *client_
662    if (!IsClient(client_p))
663      return NULL;
664  
665 <  DLINK_FOREACH(ptr, client_p->channel.head)
666 <    if (((struct Membership *)ptr->data)->chptr == chptr)
667 <      return ptr->data;
665 >  if (dlink_list_length(&chptr->members) < dlink_list_length(&client_p->channel))
666 >  {
667 >    DLINK_FOREACH(ptr, chptr->members.head)
668 >      if (((struct Membership *)ptr->data)->client_p == client_p)
669 >        return ptr->data;
670 >  }
671 >  else
672 >  {
673 >    DLINK_FOREACH(ptr, client_p->channel.head)
674 >      if (((struct Membership *)ptr->data)->chptr == chptr)
675 >        return ptr->data;
676 >  }
677  
678    return NULL;
679   }
680  
681 < /*!
682 < * \param chptr    pointer to Channel struct
683 < * \param source_p pointer to Client struct
684 < * \param ms       pointer to Membership struct (can be NULL)
681 > /*! Tests if a client can send to a channel
682 > * \param message The actual message string the client wants to send
683 > * \return 1 if the message does contain any control codes, 0 otherwise
684 > */
685 > static int
686 > msg_has_ctrls(const char *message)
687 > {
688 >  const unsigned char *p = (const unsigned char *)message;
689 >
690 >  for (; *p; ++p)
691 >  {
692 >    if (*p > 31 || *p == 1)
693 >      continue;  /* No control code or CTCP */
694 >
695 >    if (*p == 27)  /* Escape */
696 >    {
697 >      /* ISO 2022 charset shift sequence */
698 >      if (*(p + 1) == '$' ||
699 >          *(p + 1) == '(')
700 >      {
701 >        ++p;
702 >        continue;
703 >      }
704 >    }
705 >
706 >    return 1;  /* Control code */
707 >  }
708 >
709 >  return 0;
710 > }
711 >
712 > /*! Tests if a client can send to a channel
713 > * \param chptr    Pointer to Channel struct
714 > * \param source_p Pointer to Client struct
715 > * \param ms       Pointer to Membership struct (can be NULL)
716 > * \param message  The actual message string the client wants to send
717   * \return CAN_SEND_OPV if op or voiced on channel\n
718   *         CAN_SEND_NONOP if can send to channel but is not an op\n
719   *         ERR_CANNOTSENDTOCHAN or ERR_NEEDREGGEDNICK if they cannot send to channel\n
720   */
721   int
722 < can_send(struct Channel *chptr, struct Client *source_p, struct Membership *ms)
722 > can_send(struct Channel *chptr, struct Client *source_p,
723 >         struct Membership *ms, const char *message)
724   {
725 +  struct MaskItem *conf = NULL;
726 +
727    if (IsServer(source_p) || HasFlag(source_p, FLAGS_SERVICE))
728      return CAN_SEND_OPV;
729  
730    if (MyClient(source_p) && !IsExemptResv(source_p))
731      if (!(HasUMode(source_p, UMODE_OPER) && ConfigFileEntry.oper_pass_resv))
732 <      if (!hash_find_resv(chptr->chname) == ConfigChannel.restrict_channels)
732 >      if ((conf = match_find_resv(chptr->chname)) && !resv_find_exempt(source_p, conf))
733          return ERR_CANNOTSENDTOCHAN;
734  
735 <  if (ms != NULL || (ms = find_channel_link(source_p, chptr)))
736 <  {
735 >  if ((chptr->mode.mode & MODE_NOCTRL) && msg_has_ctrls(message))
736 >    return ERR_NOCTRLSONCHAN;
737 >  if (ms || (ms = find_channel_link(source_p, chptr)))
738      if (ms->flags & (CHFL_CHANOP|CHFL_HALFOP|CHFL_VOICE))
739        return CAN_SEND_OPV;
740 +  if (!ms && (chptr->mode.mode & MODE_NOPRIVMSGS))
741 +    return ERR_CANNOTSENDTOCHAN;
742 +  if (chptr->mode.mode & MODE_MODERATED)
743 +    return ERR_CANNOTSENDTOCHAN;
744 +  if ((chptr->mode.mode & MODE_MODREG) && !HasUMode(source_p, UMODE_REGISTERED))
745 +    return ERR_NEEDREGGEDNICK;
746  
747 <    /* cache can send if quiet_on_ban and banned */
748 <    if (ConfigChannel.quiet_on_ban && MyClient(source_p))
747 >  /* Cache can send if banned */
748 >  if (MyClient(source_p))
749 >  {
750 >    if (ms)
751      {
752        if (ms->flags & CHFL_BAN_SILENCED)
753          return ERR_CANNOTSENDTOCHAN;
# Line 742 | Line 763 | can_send(struct Channel *chptr, struct C
763          ms->flags |= CHFL_BAN_CHECKED;
764        }
765      }
766 +    else if (is_banned(chptr, source_p))
767 +      return ERR_CANNOTSENDTOCHAN;
768    }
746  else if (chptr->mode.mode & MODE_NOPRIVMSGS)
747    return ERR_CANNOTSENDTOCHAN;
748
749  if (chptr->mode.mode & MODE_MODERATED)
750    return ERR_CANNOTSENDTOCHAN;
769  
770    return CAN_SEND_NONOP;
771   }
# Line 755 | Line 773 | can_send(struct Channel *chptr, struct C
773   /*! \brief Updates the client's oper_warn_count_down, warns the
774   *         IRC operators if necessary, and updates
775   *         join_leave_countdown as needed.
776 < * \param source_p pointer to struct Client to check
777 < * \param name     channel name or NULL if this is a part.
776 > * \param source_p Pointer to struct Client to check
777 > * \param name     Channel name or NULL if this is a part.
778   */
779   void
780   check_spambot_warning(struct Client *source_p, const char *name)
# Line 775 | Line 793 | check_spambot_warning(struct Client *sou
793  
794      if (source_p->localClient->oper_warn_count_down == 0)
795      {
796 <      /* Its already known as a possible spambot */
797 <      if (name != NULL)
798 <        sendto_realops_flags(UMODE_BOTS, L_ALL,
796 >      /* It's already known as a possible spambot */
797 >      if (name)
798 >        sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE,
799                               "User %s (%s@%s) trying to join %s is a possible spambot",
800                               source_p->name, source_p->username,
801                               source_p->host, name);
802        else
803 <        sendto_realops_flags(UMODE_BOTS, L_ALL,
803 >        sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE,
804                               "User %s (%s@%s) is a possible spambot",
805                               source_p->name, source_p->username,
806                               source_p->host);
# Line 804 | Line 822 | check_spambot_warning(struct Client *sou
822      {
823        if ((CurrentTime - (source_p->localClient->last_join_time)) <
824            GlobalSetOptions.spam_time)
825 <      {
808 <        /* oh, its a possible spambot */
809 <        source_p->localClient->join_leave_count++;
810 <      }
825 >        source_p->localClient->join_leave_count++;  /* It's a possible spambot */
826      }
827  
828 <    if (name != NULL)
828 >    if (name)
829        source_p->localClient->last_join_time = CurrentTime;
830      else
831        source_p->localClient->last_leave_time = CurrentTime;
832    }
833   }
834  
835 < /*! \brief compares usercount and servercount against their split
835 > /*! \brief Compares usercount and servercount against their split
836   *         values and adjusts splitmode accordingly
837   * \param unused Unused address pointer
838   */
# Line 833 | Line 848 | check_splitmode(void *unused)
848      {
849        splitmode = 1;
850  
851 <      sendto_realops_flags(UMODE_ALL,L_ALL,
851 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
852                             "Network split, activating splitmode");
853        eventAddIsh("check_splitmode", check_splitmode, NULL, 10);
854      }
# Line 841 | Line 856 | check_splitmode(void *unused)
856      {
857        splitmode = 0;
858  
859 <      sendto_realops_flags(UMODE_ALL, L_ALL,
859 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
860                             "Network rejoined, deactivating splitmode");
861        eventDelete(check_splitmode, NULL);
862      }
863    }
864   }
865  
866 < /*! \brief Sets the channel topic for chptr
866 > /*! \brief Sets the channel topic for a certain channel
867   * \param chptr      Pointer to struct Channel
868   * \param topic      The topic string
869   * \param topic_info n!u\@h formatted string of the topic setter
870 < * \param topicts    timestamp on the topic
870 > * \param topicts    Timestamp on the topic
871 > * \param local      Whether the topic is set by a local client
872   */
873   void
874 < set_channel_topic(struct Channel *chptr, const char *topic,
875 <                  const char *topic_info, time_t topicts)
874 > channel_set_topic(struct Channel *chptr, const char *topic,
875 >                  const char *topic_info, time_t topicts, int local)
876   {
877 <  strlcpy(chptr->topic, topic, sizeof(chptr->topic));
877 >  if (local)
878 >    strlcpy(chptr->topic, topic, IRCD_MIN(sizeof(chptr->topic), ServerInfo.max_topic_length + 1));
879 >  else
880 >    strlcpy(chptr->topic, topic, sizeof(chptr->topic));
881 >
882    strlcpy(chptr->topic_info, topic_info, sizeof(chptr->topic_info));
883 <  chptr->topic_time = topicts;
883 >  chptr->topic_time = topicts;
884 > }
885 >
886 > /* do_join_0()
887 > *
888 > * inputs       - pointer to client doing join 0
889 > * output       - NONE
890 > * side effects - Use has decided to join 0. This is legacy
891 > *                from the days when channels were numbers not names. *sigh*
892 > *                There is a bunch of evilness necessary here due to
893 > *                anti spambot code.
894 > */
895 > void
896 > channel_do_join_0(struct Client *source_p)
897 > {
898 >  dlink_node *ptr = NULL, *ptr_next = NULL;
899 >
900 >  if (source_p->channel.head)
901 >    if (MyConnect(source_p) && !HasUMode(source_p, UMODE_OPER))
902 >      check_spambot_warning(source_p, NULL);
903 >
904 >  DLINK_FOREACH_SAFE(ptr, ptr_next, source_p->channel.head)
905 >  {
906 >    struct Channel *chptr = ((struct Membership *)ptr->data)->chptr;
907 >
908 >    sendto_server(source_p, NOCAPS, NOCAPS, ":%s PART %s",
909 >                  source_p->id, chptr->chname);
910 >    sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s!%s@%s PART %s",
911 >                         source_p->name, source_p->username,
912 >                         source_p->host, chptr->chname);
913 >
914 >    remove_user_from_channel(ptr->data);
915 >  }
916 > }
917 >
918 > static char *
919 > channel_find_last0(struct Client *source_p, char *chanlist)
920 > {
921 >  int join0 = 0;
922 >
923 >  for (char *p = chanlist; *p; ++p)  /* Find last "JOIN 0" */
924 >  {
925 >    if (*p == '0' && (*(p + 1) == ',' || *(p + 1) == '\0'))
926 >    {
927 >      if ((*p + 1) == ',')
928 >        ++p;
929 >
930 >      chanlist = p + 1;
931 >      join0 = 1;
932 >    }
933 >    else
934 >    {
935 >      while (*p != ',' && *p != '\0')  /* Skip past channel name */
936 >        ++p;
937 >
938 >      if (*p == '\0')  /* Hit the end */
939 >        break;
940 >    }
941 >  }
942 >
943 >  if (join0)
944 >    channel_do_join_0(source_p);
945 >
946 >  return chanlist;
947 > }
948 >
949 > void
950 > channel_do_join(struct Client *source_p, char *channel, char *key_list)
951 > {
952 >  char *p = NULL;
953 >  char *chan = NULL;
954 >  char *chan_list = NULL;
955 >  struct Channel *chptr = NULL;
956 >  struct MaskItem *conf = NULL;
957 >  const struct ClassItem *class = get_class_ptr(&source_p->localClient->confs);
958 >  int i = 0;
959 >  unsigned int flags = 0;
960 >
961 >  chan_list = channel_find_last0(source_p, channel);
962 >
963 >  for (chan = strtoken(&p, chan_list, ","); chan;
964 >       chan = strtoken(&p,      NULL, ","))
965 >  {
966 >    const char *key = NULL;
967 >
968 >    /* If we have any more keys, take the first for this channel. */
969 >    if (!EmptyString(key_list) && (key_list = strchr(key = key_list, ',')))
970 >      *key_list++ = '\0';
971 >
972 >    /* Empty keys are the same as no keys. */
973 >    if (key && *key == '\0')
974 >      key = NULL;
975 >
976 >    if (!check_channel_name(chan, 1))
977 >    {
978 >      sendto_one_numeric(source_p, &me, ERR_BADCHANNAME, chan);
979 >      continue;
980 >    }
981 >
982 >    if (!IsExemptResv(source_p) &&
983 >        !(HasUMode(source_p, UMODE_OPER) && ConfigFileEntry.oper_pass_resv) &&
984 >        ((conf = match_find_resv(chan)) && !resv_find_exempt(source_p, conf)))
985 >    {
986 >      ++conf->count;
987 >      sendto_one_numeric(source_p, &me, ERR_CHANBANREASON,
988 >                         chan, conf->reason ? conf->reason : "Reserved channel");
989 >      sendto_realops_flags(UMODE_SPY, L_ALL, SEND_NOTICE,
990 >                           "Forbidding reserved channel %s from user %s",
991 >                           chan, get_client_name(source_p, HIDE_IP));
992 >      continue;
993 >    }
994 >
995 >    if (dlink_list_length(&source_p->channel) >=
996 >        ((class->max_channels) ? class->max_channels : ConfigChannel.max_channels))
997 >    {
998 >      sendto_one_numeric(source_p, &me, ERR_TOOMANYCHANNELS, chan);
999 >      break;
1000 >    }
1001 >
1002 >    if ((chptr = hash_find_channel(chan)))
1003 >    {
1004 >      if (IsMember(source_p, chptr))
1005 >        continue;
1006 >
1007 >      if (splitmode && !HasUMode(source_p, UMODE_OPER) &&
1008 >          ConfigChannel.no_join_on_split)
1009 >      {
1010 >        sendto_one_numeric(source_p, &me, ERR_UNAVAILRESOURCE, chptr->chname);
1011 >        continue;
1012 >      }
1013 >
1014 >      /*
1015 >       * can_join checks for +i key, bans.
1016 >       */
1017 >      if ((i = can_join(source_p, chptr, key)))
1018 >      {
1019 >        sendto_one_numeric(source_p, &me, i, chptr->chname);
1020 >        continue;
1021 >      }
1022 >
1023 >      /*
1024 >       * This should never be the case unless there is some sort of
1025 >       * persistant channels.
1026 >       */
1027 >      if (dlink_list_length(&chptr->members) == 0)
1028 >        flags = CHFL_CHANOP;
1029 >      else
1030 >        flags = 0;
1031 >    }
1032 >    else
1033 >    {
1034 >      if (splitmode && !HasUMode(source_p, UMODE_OPER) &&
1035 >          (ConfigChannel.no_create_on_split || ConfigChannel.no_join_on_split))
1036 >      {
1037 >        sendto_one_numeric(source_p, &me, ERR_UNAVAILRESOURCE, chan);
1038 >        continue;
1039 >      }
1040 >
1041 >      flags = CHFL_CHANOP;
1042 >      chptr = make_channel(chan);
1043 >    }
1044 >
1045 >    if (!HasUMode(source_p, UMODE_OPER))
1046 >      check_spambot_warning(source_p, chptr->chname);
1047 >
1048 >    add_user_to_channel(chptr, source_p, flags, 1);
1049 >
1050 >    /*
1051 >     *  Set timestamp if appropriate, and propagate
1052 >     */
1053 >    if (flags == CHFL_CHANOP)
1054 >    {
1055 >      chptr->channelts = CurrentTime;
1056 >      chptr->mode.mode |= MODE_TOPICLIMIT;
1057 >      chptr->mode.mode |= MODE_NOPRIVMSGS;
1058 >
1059 >      sendto_server(source_p, NOCAPS, NOCAPS, ":%s SJOIN %lu %s +nt :@%s",
1060 >                    me.id, (unsigned long)chptr->channelts,
1061 >                    chptr->chname, source_p->id);
1062 >
1063 >      /*
1064 >       * Notify all other users on the new channel
1065 >       */
1066 >      sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s!%s@%s JOIN :%s",
1067 >                           source_p->name, source_p->username,
1068 >                           source_p->host, chptr->chname);
1069 >      sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s MODE %s +nt",
1070 >                           me.name, chptr->chname);
1071 >
1072 >      if (source_p->away[0])
1073 >        sendto_channel_local_butone(source_p, 0, CAP_AWAY_NOTIFY, chptr,
1074 >                                    ":%s!%s@%s AWAY :%s",
1075 >                                    source_p->name, source_p->username,
1076 >                                    source_p->host, source_p->away);
1077 >    }
1078 >    else
1079 >    {
1080 >      sendto_server(source_p, NOCAPS, NOCAPS, ":%s JOIN %lu %s +",
1081 >                    source_p->id, (unsigned long)chptr->channelts,
1082 >                    chptr->chname);
1083 >      sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s!%s@%s JOIN :%s",
1084 >                           source_p->name, source_p->username,
1085 >                           source_p->host, chptr->chname);
1086 >
1087 >      if (source_p->away[0])
1088 >        sendto_channel_local_butone(source_p, 0, CAP_AWAY_NOTIFY, chptr,
1089 >                                    ":%s!%s@%s AWAY :%s",
1090 >                                    source_p->name, source_p->username,
1091 >                                    source_p->host, source_p->away);
1092 >    }
1093 >
1094 >    del_invite(chptr, source_p);
1095 >
1096 >    if (chptr->topic[0])
1097 >    {
1098 >      sendto_one_numeric(source_p, &me, RPL_TOPIC, chptr->chname, chptr->topic);
1099 >      sendto_one_numeric(source_p, &me, RPL_TOPICWHOTIME, chptr->chname,
1100 >                         chptr->topic_info, chptr->topic_time);
1101 >    }
1102 >
1103 >    channel_member_names(source_p, chptr, 1);
1104 >
1105 >    source_p->localClient->last_join_time = CurrentTime;
1106 >  }
1107 > }
1108 >
1109 > /*! \brief Removes a client from a specific channel
1110 > * \param source_p Pointer to source client to remove
1111 > * \param name     Name of channel to remove from
1112 > * \param reason   Part reason to show
1113 > */
1114 > static void
1115 > channel_part_one_client(struct Client *source_p, const char *name, const char *reason)
1116 > {
1117 >  struct Channel *chptr = NULL;
1118 >  struct Membership *ms = NULL;
1119 >
1120 >  if ((chptr = hash_find_channel(name)) == NULL)
1121 >  {
1122 >    sendto_one_numeric(source_p, &me, ERR_NOSUCHCHANNEL, name);
1123 >    return;
1124 >  }
1125 >
1126 >  if ((ms = find_channel_link(source_p, chptr)) == NULL)
1127 >  {
1128 >    sendto_one_numeric(source_p, &me, ERR_NOTONCHANNEL, chptr->chname);
1129 >    return;
1130 >  }
1131 >
1132 >  if (MyConnect(source_p) && !HasUMode(source_p, UMODE_OPER))
1133 >    check_spambot_warning(source_p, NULL);
1134 >
1135 >  /*
1136 >   * Remove user from the old channel (if any)
1137 >   * only allow /part reasons in -m chans
1138 >   */
1139 >  if (*reason && (!MyConnect(source_p) ||
1140 >      ((can_send(chptr, source_p, ms, reason) &&
1141 >       (source_p->localClient->firsttime + ConfigFileEntry.anti_spam_exit_message_time)
1142 >        < CurrentTime))))
1143 >  {
1144 >    sendto_server(source_p, NOCAPS, NOCAPS, ":%s PART %s :%s",
1145 >                  source_p->id, chptr->chname, reason);
1146 >    sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s!%s@%s PART %s :%s",
1147 >                         source_p->name, source_p->username,
1148 >                         source_p->host, chptr->chname, reason);
1149 >  }
1150 >  else
1151 >  {
1152 >    sendto_server(source_p, NOCAPS, NOCAPS, ":%s PART %s",
1153 >                  source_p->id, chptr->chname);
1154 >    sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s!%s@%s PART %s",
1155 >                         source_p->name, source_p->username,
1156 >                         source_p->host, chptr->chname);
1157 >  }
1158 >
1159 >  remove_user_from_channel(ms);
1160 > }
1161 >
1162 > void
1163 > channel_do_part(struct Client *source_p, char *channel, char *reason)
1164 > {
1165 >  char *p = NULL, *name = NULL;
1166 >  char reasonbuf[KICKLEN + 1] = "";
1167 >
1168 >  if (!EmptyString(reason))
1169 >    strlcpy(reasonbuf, reason, sizeof(reasonbuf));
1170 >
1171 >  for (name = strtoken(&p, channel, ","); name;
1172 >       name = strtoken(&p,    NULL, ","))
1173 >    channel_part_one_client(source_p, name, reasonbuf);
1174   }

Diff Legend

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