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

Diff Legend

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