ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/channel.c
(Generate patch)

Comparing ircd-hybrid/trunk/src/channel.c (file contents):
Revision 4209 by michael, Sat Jul 12 18:15:19 2014 UTC vs.
Revision 7766 by michael, Fri Oct 7 16:27:37 2016 UTC

# Line 1 | Line 1
1   /*
2   *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Copyright (c) 1997-2014 ircd-hybrid development team
4 > *  Copyright (c) 1997-2016 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 31 | Line 31
31   #include "client.h"
32   #include "hash.h"
33   #include "conf.h"
34 + #include "conf_resv.h"
35   #include "hostmask.h"
36   #include "irc_string.h"
37   #include "ircd.h"
# Line 41 | Line 42
42   #include "memory.h"
43   #include "mempool.h"
44   #include "misc.h"
44 #include "resv.h"
45  
46  
47   dlink_list channel_list;
48   mp_pool_t *ban_pool;    /*! \todo ban_pool shouldn't be a global var */
49  
50 < struct event splitmode_event =
51 < {
52 <  .name = "check_splitmode",
53 <  .handler = check_splitmode,
54 <  .when = 5
55 < };
56 <
57 < static mp_pool_t *member_pool, *channel_pool;
58 < static char buf[IRCD_BUFSIZE];
50 > static mp_pool_t *member_pool, *channel_pool, *invite_pool;
51  
52  
53   /*! \brief Initializes the channel blockheap, adds known channel CAPAB
# Line 63 | Line 55 | static char buf[IRCD_BUFSIZE];
55   void
56   channel_init(void)
57   {
58 <  add_capability("EX", CAP_EX, 1);
59 <  add_capability("IE", CAP_IE, 1);
58 >  add_capability("EX", CAPAB_EX);
59 >  add_capability("IE", CAPAB_IE);
60  
61 +  invite_pool = mp_pool_new(sizeof(struct Invite), MP_CHUNK_SIZE_INVITE);
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);
# Line 74 | Line 67 | channel_init(void)
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
70 > * \param client_p   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,
75 > add_user_to_channel(struct Channel *chptr, struct Client *client_p,
76                      unsigned int flags, int flood_ctrl)
77   {
78 <  struct Membership *ms = NULL;
78 >  assert(IsClient(client_p));
79  
80    if (GlobalSetOptions.joinfloodtime > 0)
81    {
# Line 107 | Line 100 | add_user_to_channel(struct Channel *chpt
100          SetJoinFloodNoticed(chptr);
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);
103 >                             get_client_name(client_p, HIDE_IP),
104 >                             client_p->servptr->name, chptr->name);
105        }
106      }
107  
108      chptr->last_join_time = CurrentTime;
109    }
110  
111 <  ms = mp_pool_get(member_pool);
112 <  ms->client_p = who;
113 <  ms->chptr = chptr;
114 <  ms->flags = flags;
111 >  struct Membership *member = mp_pool_get(member_pool);
112 >  member->client_p = client_p;
113 >  member->chptr = chptr;
114 >  member->flags = flags;
115  
116 <  dlinkAdd(ms, &ms->channode, &chptr->members);
116 >  dlinkAdd(member, &member->channode, &chptr->members);
117  
118 <  if (MyConnect(who))
119 <    dlinkAdd(ms, &ms->locchannode, &chptr->locmembers);
118 >  if (MyConnect(client_p))
119 >    dlinkAdd(member, &member->locchannode, &chptr->locmembers);
120  
121 <  dlinkAdd(ms, &ms->usernode, &who->channel);
121 >  dlinkAdd(member, &member->usernode, &client_p->channel);
122   }
123  
124   /*! \brief Deletes an user from a channel by removing a link in the
# Line 135 | Line 128 | add_user_to_channel(struct Channel *chpt
128   void
129   remove_user_from_channel(struct Membership *member)
130   {
131 <  struct Client *client_p = member->client_p;
132 <  struct Channel *chptr = member->chptr;
131 >  struct Client *const client_p = member->client_p;
132 >  struct Channel *const chptr = member->chptr;
133  
134    dlinkDelete(&member->channode, &chptr->members);
135  
# Line 148 | Line 141 | remove_user_from_channel(struct Membersh
141    mp_pool_release(member);
142  
143    if (chptr->members.head == NULL)
144 <    destroy_channel(chptr);
144 >    channel_free(chptr);
145   }
146  
147 < /* send_members()
147 > /* channel_send_members()
148   *
149   * inputs       -
150   * output       - NONE
151   * side effects -
152   */
153   static void
154 < send_members(struct Client *client_p, struct Channel *chptr,
155 <             char *modebuf, char *parabuf)
154 > channel_send_members(struct Client *client_p, const struct Channel *chptr,
155 >                     char *modebuf, char *parabuf)
156   {
157 <  const dlink_node *ptr = NULL;
157 >  char buf[IRCD_BUFSIZE] = "";
158 >  dlink_node *node;
159    int tlen;              /* length of text to append */
160    char *t, *start;       /* temp char pointer */
161  
162 <  start = t = buf + snprintf(buf, sizeof(buf), ":%s SJOIN %lu %s %s %s:",
163 <                             me.id, (unsigned long)chptr->channelts,
164 <                             chptr->chname, modebuf, parabuf);
162 >  start = t = buf + snprintf(buf, sizeof(buf), ":%s SJOIN %ju %s %s %s:",
163 >                             me.id, chptr->creationtime,
164 >                             chptr->name, modebuf, parabuf);
165  
166 <  DLINK_FOREACH(ptr, chptr->members.head)
166 >  DLINK_FOREACH(node, chptr->members.head)
167    {
168 <    const struct Membership *ms = ptr->data;
168 >    const struct Membership *member = node->data;
169  
170 <    tlen = strlen(ms->client_p->id) + 1;  /* +1 for space */
170 >    tlen = strlen(member->client_p->id) + 1;  /* +1 for space */
171  
172 <    if (ms->flags & CHFL_CHANOP)
172 >    if (member->flags & CHFL_CHANOP)
173        ++tlen;
174 <    if (ms->flags & CHFL_HALFOP)
174 >    if (member->flags & CHFL_HALFOP)
175        ++tlen;
176 <    if (ms->flags & CHFL_VOICE)
176 >    if (member->flags & CHFL_VOICE)
177        ++tlen;
178  
179      /*
# Line 193 | Line 187 | send_members(struct Client *client_p, st
187        t = start;
188      }
189  
190 <    if (ms->flags & CHFL_CHANOP)
190 >    if (member->flags & CHFL_CHANOP)
191        *t++ = '@';
192 <    if (ms->flags & CHFL_HALFOP)
192 >    if (member->flags & CHFL_HALFOP)
193        *t++ = '%';
194 <    if (ms->flags & CHFL_VOICE)
194 >    if (member->flags & CHFL_VOICE)
195        *t++ = '+';
196  
197 <    strcpy(t, ms->client_p->id);
197 >    strcpy(t, member->client_p->id);
198  
199      t += strlen(t);
200      *t++ = ' ';
# Line 220 | Line 214 | send_members(struct Client *client_p, st
214   * \param flag     Char flag flagging type of mode. Currently this can be 'b', e' or 'I'
215   */
216   static void
217 < send_mode_list(struct Client *client_p, struct Channel *chptr,
218 <               const dlink_list *list, char flag)
217 > channel_send_mask_list(struct Client *client_p, const struct Channel *chptr,
218 >                       const dlink_list *list, const char flag)
219   {
220 <  const dlink_node *ptr = NULL;
220 >  dlink_node *node;
221 >  char mbuf[IRCD_BUFSIZE] = "";
222    char pbuf[IRCD_BUFSIZE] = "";
223    int tlen, mlen, cur_len;
224    char *pp = pbuf;
225  
226 <  if (list->length == 0)
226 >  if (!dlink_list_length(list))
227      return;
228  
229 <  mlen = snprintf(buf, sizeof(buf), ":%s BMASK %lu %s %c :", me.id,
230 <                  (unsigned long)chptr->channelts, chptr->chname, flag);
229 >  mlen = snprintf(mbuf, sizeof(mbuf), ":%s BMASK %ju %s %c :", me.id,
230 >                  chptr->creationtime, chptr->name, flag);
231    cur_len = mlen;
232  
233 <  DLINK_FOREACH(ptr, list->head)
233 >  DLINK_FOREACH(node, list->head)
234    {
235 <    const struct Ban *banptr = ptr->data;
235 >    const struct Ban *ban = node->data;
236  
237 <    tlen = banptr->len + 3;  /* +3 for ! + @ + space */
237 >    tlen = ban->len + 3;  /* +3 for ! + @ + space */
238  
239      /*
240       * Send buffer and start over if we cannot fit another ban
# Line 247 | Line 242 | send_mode_list(struct Client *client_p,
242      if (cur_len + (tlen - 1) > IRCD_BUFSIZE - 2)
243      {
244        *(pp - 1) = '\0';  /* Get rid of trailing space on buffer */
245 <      sendto_one(client_p, "%s%s", buf, pbuf);
245 >      sendto_one(client_p, "%s%s", mbuf, pbuf);
246  
247        cur_len = mlen;
248        pp = pbuf;
249      }
250  
251 <    pp += sprintf(pp, "%s!%s@%s ", banptr->name, banptr->user,
257 <                  banptr->host);
251 >    pp += sprintf(pp, "%s!%s@%s ", ban->name, ban->user, ban->host);
252      cur_len += tlen;
253    }
254  
255    *(pp - 1) = '\0';  /* Get rid of trailing space on buffer */
256 <  sendto_one(client_p, "%s%s", buf, pbuf);
256 >  sendto_one(client_p, "%s%s", mbuf, pbuf);
257   }
258  
259   /*! \brief Send "client_p" a full list of the modes for channel chptr
# Line 267 | Line 261 | send_mode_list(struct Client *client_p,
261   * \param chptr    Pointer to channel pointer
262   */
263   void
264 < send_channel_modes(struct Client *client_p, struct Channel *chptr)
264 > channel_send_modes(struct Client *client_p, struct Channel *chptr)
265   {
266    char modebuf[MODEBUFLEN] = "";
267    char parabuf[MODEBUFLEN] = "";
268  
269    channel_modes(chptr, client_p, modebuf, parabuf);
270 <  send_members(client_p, chptr, modebuf, parabuf);
270 >  channel_send_members(client_p, chptr, modebuf, parabuf);
271  
272 <  send_mode_list(client_p, chptr, &chptr->banlist, 'b');
273 <  send_mode_list(client_p, chptr, &chptr->exceptlist, 'e');
274 <  send_mode_list(client_p, chptr, &chptr->invexlist, 'I');
272 >  channel_send_mask_list(client_p, chptr, &chptr->banlist, 'b');
273 >  channel_send_mask_list(client_p, chptr, &chptr->exceptlist, 'e');
274 >  channel_send_mask_list(client_p, chptr, &chptr->invexlist, 'I');
275   }
276  
277   /*! \brief Check channel name for invalid characters
# Line 286 | Line 280 | send_channel_modes(struct Client *client
280   * \return 0 if invalid, 1 otherwise
281   */
282   int
283 < check_channel_name(const char *name, const int local)
283 > channel_check_name(const char *name, const int local)
284   {
285    const char *p = name;
286  
287 <  assert(name != NULL);
287 >  assert(!EmptyString(p));
288  
289    if (!IsChanPrefix(*p))
290      return 0;
# Line 312 | Line 306 | check_channel_name(const char *name, con
306   }
307  
308   void
309 < remove_ban(struct Ban *bptr, dlink_list *list)
309 > remove_ban(struct Ban *ban, dlink_list *list)
310   {
311 <  dlinkDelete(&bptr->node, list);
312 <
319 <  MyFree(bptr->name);
320 <  MyFree(bptr->user);
321 <  MyFree(bptr->host);
322 <  MyFree(bptr->who);
323 <
324 <  mp_pool_release(bptr);
311 >  dlinkDelete(&ban->node, list);
312 >  mp_pool_release(ban);
313   }
314  
315 < /* free_channel_list()
315 > /* channel_free_mask_list()
316   *
317   * inputs       - pointer to dlink_list
318   * output       - NONE
319   * side effects -
320   */
321 < void
322 < free_channel_list(dlink_list *list)
321 > static void
322 > channel_free_mask_list(dlink_list *list)
323   {
324 <  dlink_node *ptr = NULL, *ptr_next = NULL;
325 <
326 <  DLINK_FOREACH_SAFE(ptr, ptr_next, list->head)
327 <    remove_ban(ptr->data, list);
328 <
341 <  assert(list->tail == NULL && list->head == NULL);
324 >  while (list->head)
325 >  {
326 >    struct Ban *ban = list->head->data;
327 >    remove_ban(ban, list);
328 >  }
329   }
330  
331 < /*! \brief Get Channel block for chname (and allocate a new channel
331 > /*! \brief Get Channel block for name (and allocate a new channel
332   *         block, if it didn't exist before)
333 < * \param chname Channel name
333 > * \param name Channel name
334   * \return Channel block
335   */
336   struct Channel *
337 < make_channel(const char *chname)
337 > channel_make(const char *name)
338   {
339    struct Channel *chptr = NULL;
340  
341 <  assert(!EmptyString(chname));
341 >  assert(!EmptyString(name));
342  
343    chptr = mp_pool_get(channel_pool);
344  
345    /* Doesn't hurt to set it here */
346 <  chptr->channelts = CurrentTime;
346 >  chptr->creationtime = CurrentTime;
347    chptr->last_join_time = CurrentTime;
348  
349 <  strlcpy(chptr->chname, chname, sizeof(chptr->chname));
350 <  dlinkAdd(chptr, &chptr->node, &channel_list);
349 >  chptr->name_len = strlcpy(chptr->name, name, sizeof(chptr->name));
350 >  if (chptr->name_len >= sizeof(chptr->name))
351 >    chptr->name_len = sizeof(chptr->name) - 1;
352  
353 +  dlinkAdd(chptr, &chptr->node, &channel_list);
354    hash_add_channel(chptr);
355  
356    return chptr;
# Line 371 | Line 360 | make_channel(const char *chname)
360   * \param chptr Channel pointer
361   */
362   void
363 < destroy_channel(struct Channel *chptr)
363 > channel_free(struct Channel *chptr)
364   {
365 <  dlink_node *ptr = NULL, *ptr_next = NULL;
377 <
378 <  DLINK_FOREACH_SAFE(ptr, ptr_next, chptr->invites.head)
379 <    del_invite(chptr, ptr->data);
365 >  clear_invite_list(&chptr->invites);
366  
367    /* Free ban/exception/invex lists */
368 <  free_channel_list(&chptr->banlist);
369 <  free_channel_list(&chptr->exceptlist);
370 <  free_channel_list(&chptr->invexlist);
368 >  channel_free_mask_list(&chptr->banlist);
369 >  channel_free_mask_list(&chptr->exceptlist);
370 >  channel_free_mask_list(&chptr->invexlist);
371  
372    dlinkDelete(&chptr->node, &channel_list);
373    hash_del_channel(chptr);
# Line 404 | Line 390 | channel_pub_or_secret(const struct Chann
390   }
391  
392   /*! \brief lists all names on given channel
393 < * \param source_p Pointer to client struct requesting names
393 > * \param client_p Pointer to client struct requesting names
394   * \param chptr    Pointer to channel block
395   * \param show_eon Show RPL_ENDOFNAMES numeric or not
396   *                 (don't want it with /names with no params)
397   */
398   void
399 < channel_member_names(struct Client *source_p, struct Channel *chptr,
399 > channel_member_names(struct Client *client_p, struct Channel *chptr,
400                       int show_eon)
401   {
402 <  const dlink_node *ptr = NULL;
403 <  char lbuf[IRCD_BUFSIZE + 1] = "";
402 >  dlink_node *node;
403 >  char buf[IRCD_BUFSIZE + 1] = "";
404    char *t = NULL, *start = NULL;
405    int tlen = 0;
406 <  int is_member = IsMember(source_p, chptr);
407 <  int multi_prefix = HasCap(source_p, CAP_MULTI_PREFIX) != 0;
408 <  int uhnames = HasCap(source_p, CAP_UHNAMES) != 0;
406 >  const int is_member = IsMember(client_p, chptr);
407 >  const int multi_prefix = HasCap(client_p, CAP_MULTI_PREFIX) != 0;
408 >  const int uhnames = HasCap(client_p, CAP_UHNAMES) != 0;
409 >
410 >  assert(IsClient(client_p));
411  
412    if (PubChannel(chptr) || is_member)
413    {
414 <    t = lbuf + snprintf(lbuf, sizeof(lbuf), numeric_form(RPL_NAMREPLY),
415 <                        me.name, source_p->name,
416 <                        channel_pub_or_secret(chptr), chptr->chname);
414 >    t = buf + snprintf(buf, sizeof(buf), numeric_form(RPL_NAMREPLY),
415 >                       me.name, client_p->name,
416 >                       channel_pub_or_secret(chptr), chptr->name);
417      start = t;
418  
419 <    DLINK_FOREACH(ptr, chptr->members.head)
419 >    DLINK_FOREACH(node, chptr->members.head)
420      {
421 <      const struct Membership *ms = ptr->data;
421 >      const struct Membership *member = node->data;
422  
423 <      if (HasUMode(ms->client_p, UMODE_INVISIBLE) && !is_member)
423 >      if (HasUMode(member->client_p, UMODE_INVISIBLE) && !is_member)
424          continue;
425  
426        if (!uhnames)
427 <        tlen = strlen(ms->client_p->name) + 1;  /* +1 for space */
427 >        tlen = strlen(member->client_p->name) + 1;  /* +1 for space */
428        else
429 <        tlen = strlen(ms->client_p->name) + strlen(ms->client_p->username) +
430 <               strlen(ms->client_p->host) + 3;  /* +3 for ! + @ + space */
429 >        tlen = strlen(member->client_p->name) + strlen(member->client_p->username) +
430 >               strlen(member->client_p->host) + 3;  /* +3 for ! + @ + space */
431  
432        if (!multi_prefix)
433        {
434 <        if (ms->flags & (CHFL_CHANOP | CHFL_HALFOP | CHFL_VOICE))
434 >        if (member->flags & (CHFL_CHANOP | CHFL_HALFOP | CHFL_VOICE))
435            ++tlen;
436        }
437        else
438        {
439 <        if (ms->flags & CHFL_CHANOP)
439 >        if (member->flags & CHFL_CHANOP)
440            ++tlen;
441 <        if (ms->flags & CHFL_HALFOP)
441 >        if (member->flags & CHFL_HALFOP)
442            ++tlen;
443 <        if (ms->flags & CHFL_VOICE)
443 >        if (member->flags & CHFL_VOICE)
444            ++tlen;
445        }
446  
447 <      if (t + tlen - lbuf > IRCD_BUFSIZE - 2)
447 >      if (t + tlen - buf > IRCD_BUFSIZE - 2)
448        {
449          *(t - 1) = '\0';
450 <        sendto_one(source_p, "%s", lbuf);
450 >        sendto_one(client_p, "%s", buf);
451          t = start;
452        }
453  
454        if (!uhnames)
455 <        t += sprintf(t, "%s%s ", get_member_status(ms, multi_prefix),
456 <                     ms->client_p->name);
455 >        t += sprintf(t, "%s%s ", get_member_status(member, multi_prefix),
456 >                     member->client_p->name);
457        else
458 <        t += sprintf(t, "%s%s!%s@%s ", get_member_status(ms, multi_prefix),
459 <                     ms->client_p->name, ms->client_p->username,
460 <                     ms->client_p->host);
458 >        t += sprintf(t, "%s%s!%s@%s ", get_member_status(member, multi_prefix),
459 >                     member->client_p->name, member->client_p->username,
460 >                     member->client_p->host);
461      }
462  
463      if (tlen)
464      {
465        *(t - 1) = '\0';
466 <      sendto_one(source_p, "%s", lbuf);
466 >      sendto_one(client_p, "%s", buf);
467      }
468    }
469  
470    if (show_eon)
471 <    sendto_one_numeric(source_p, &me, RPL_ENDOFNAMES, chptr->chname);
471 >    sendto_one_numeric(client_p, &me, RPL_ENDOFNAMES, chptr->name);
472 > }
473 >
474 > static struct Invite *
475 > find_invite(struct Channel *chptr, struct Client *client_p)
476 > {
477 >  dlink_node *node, *node_next;
478 >  dlink_list *list;
479 >
480 >  if (dlink_list_length(&client_p->connection->invited) < dlink_list_length(&chptr->invites))
481 >    list = &client_p->connection->invited;
482 >  else
483 >    list = &chptr->invites;
484 >
485 >  DLINK_FOREACH_SAFE(node, node_next, list->head)
486 >  {
487 >    struct Invite *invite = node->data;
488 >
489 >    if (invite->chptr == chptr && invite->client_p == client_p)
490 >      return invite;
491 >  }
492 >
493 >  return NULL;
494   }
495  
496   /*! \brief Adds client to invite list
497 < * \param chptr Pointer to channel block
498 < * \param who   Pointer to client to add invite to
497 > * \param chptr    Pointer to channel block
498 > * \param client_p Pointer to client to add invite to
499   */
500   void
501 < add_invite(struct Channel *chptr, struct Client *who)
501 > add_invite(struct Channel *chptr, struct Client *client_p)
502   {
503 <  del_invite(chptr, who);
503 >  struct Invite *invite;
504  
505 <  /*
506 <   * Delete last link in chain if the list is max length
507 <   */
508 <  if (dlink_list_length(&who->localClient->invited) >=
509 <      ConfigChannel.max_channels)
510 <    del_invite(who->localClient->invited.tail->data, who);
505 >  if ((invite = find_invite(chptr, client_p)))
506 >    del_invite(invite);
507 >
508 >  invite = mp_pool_get(invite_pool);
509 >  invite->client_p = client_p;
510 >  invite->chptr = chptr;
511 >  invite->when = CurrentTime;
512 >
513 >  /* Delete last link in chain if the list is max length */
514 >  while (dlink_list_length(&client_p->connection->invited) &&
515 >         dlink_list_length(&client_p->connection->invited) >= ConfigChannel.max_invites)
516 >    del_invite(client_p->connection->invited.tail->data);
517  
518    /* Add client to channel invite list */
519 <  dlinkAdd(who, make_dlink_node(), &chptr->invites);
519 >  dlinkAdd(invite, &invite->chan_node, &chptr->invites);
520  
521    /* Add channel to the end of the client invite list */
522 <  dlinkAdd(chptr, make_dlink_node(), &who->localClient->invited);
522 >  dlinkAdd(invite, &invite->user_node, &client_p->connection->invited);
523   }
524  
525   /*! \brief Delete Invite block from channel invite list
526   *         and client invite list
527 < * \param chptr Pointer to Channel struct
512 < * \param who   Pointer to client to remove invites from
527 > * \param invite Pointer to Invite struct
528   */
529   void
530 < del_invite(struct Channel *chptr, struct Client *who)
530 > del_invite(struct Invite *invite)
531   {
532 <  dlink_node *ptr = NULL;
532 >  dlinkDelete(&invite->user_node, &invite->client_p->connection->invited);
533 >  dlinkDelete(&invite->chan_node, &invite->chptr->invites);
534  
535 <  if ((ptr = dlinkFindDelete(&who->localClient->invited, chptr)))
536 <    free_dlink_node(ptr);
535 >  /* Release memory pointed to by 'invite' */
536 >  mp_pool_release(invite);
537 > }
538  
539 <  if ((ptr = dlinkFindDelete(&chptr->invites, who)))
540 <    free_dlink_node(ptr);
539 > /*! \brief Removes and frees all Invite blocks from a list
540 > * \param list Pointer to a dlink_list
541 > */
542 > void
543 > clear_invite_list(dlink_list *list)
544 > {
545 >  while (list->head)
546 >    del_invite(list->head->data);
547   }
548  
549   /* get_member_status()
# Line 535 | Line 558 | del_invite(struct Channel *chptr, struct
558   * (like in get_client_name)
559   */
560   const char *
561 < get_member_status(const struct Membership *ms, const int combine)
561 > get_member_status(const struct Membership *member, const int combine)
562   {
563 <  static char buffer[4];  /* 4 for @%+\0 */
563 >  static char buffer[CMEMBER_STATUS_FLAGS_LEN + 1];  /* +1 for \0 */
564    char *p = buffer;
565  
566 <  if (ms->flags & CHFL_CHANOP)
566 >  if (member->flags & CHFL_CHANOP)
567    {
568      if (!combine)
569        return "@";
570      *p++ = '@';
571    }
572  
573 <  if (ms->flags & CHFL_HALFOP)
573 >  if (member->flags & CHFL_HALFOP)
574    {
575      if (!combine)
576        return "%";
577      *p++ = '%';
578    }
579  
580 <  if (ms->flags & CHFL_VOICE)
580 >  if (member->flags & CHFL_VOICE)
581      *p++ = '+';
582    *p = '\0';
583  
# Line 562 | Line 585 | get_member_status(const struct Membershi
585   }
586  
587   /*!
588 < * \param who  Pointer to Client to check
589 < * \param list Pointer to ban list to search
588 > * \param client_p Pointer to Client to check
589 > * \param list     Pointer to ban list to search
590   * \return 1 if ban found for given n!u\@h mask, 0 otherwise
568 *
591   */
592   static int
593 < find_bmask(const struct Client *who, const dlink_list *const list)
593 > find_bmask(const struct Client *client_p, const dlink_list *list)
594   {
595 <  const dlink_node *ptr = NULL;
595 >  dlink_node *node;
596  
597 <  DLINK_FOREACH(ptr, list->head)
597 >  DLINK_FOREACH(node, list->head)
598    {
599 <    const struct Ban *bp = ptr->data;
599 >    const struct Ban *ban = node->data;
600  
601 <    if (!match(bp->name, who->name) && !match(bp->user, who->username))
601 >    if (!match(ban->name, client_p->name) && !match(ban->user, client_p->username))
602      {
603 <      switch (bp->type)
603 >      switch (ban->type)
604        {
605          case HM_HOST:
606 <          if (!match(bp->host, who->host) || !match(bp->host, who->sockhost))
606 >          if (!match(ban->host, client_p->host) || !match(ban->host, client_p->sockhost))
607              return 1;
608            break;
609          case HM_IPV4:
610 <          if (who->localClient->aftype == AF_INET)
611 <            if (match_ipv4(&who->localClient->ip, &bp->addr, bp->bits))
610 >          if (client_p->connection->aftype == AF_INET)
611 >            if (match_ipv4(&client_p->connection->ip, &ban->addr, ban->bits))
612                return 1;
613            break;
592 #ifdef IPV6
614          case HM_IPV6:
615 <          if (who->localClient->aftype == AF_INET6)
616 <            if (match_ipv6(&who->localClient->ip, &bp->addr, bp->bits))
615 >          if (client_p->connection->aftype == AF_INET6)
616 >            if (match_ipv6(&client_p->connection->ip, &ban->addr, ban->bits))
617                return 1;
618            break;
598 #endif
619          default:
620            assert(0);
621        }
# Line 606 | Line 626 | find_bmask(const struct Client *who, con
626   }
627  
628   /*!
629 < * \param chptr Pointer to channel block
630 < * \param who   Pointer to client to check access fo
629 > * \param chptr    Pointer to channel block
630 > * \param client_p Pointer to client to check access fo
631   * \return 0 if not banned, 1 otherwise
632   */
633   int
634 < is_banned(const struct Channel *chptr, const struct Client *who)
634 > is_banned(const struct Channel *chptr, const struct Client *client_p)
635   {
636 <  if (find_bmask(who, &chptr->banlist))
637 <    if (!find_bmask(who, &chptr->exceptlist))
636 >  if (find_bmask(client_p, &chptr->banlist))
637 >    if (!find_bmask(client_p, &chptr->exceptlist))
638        return 1;
639  
640    return 0;
641   }
642  
643   /*! Tests if a client can join a certain channel
644 < * \param source_p Pointer to client attempting to join
644 > * \param client_p Pointer to client attempting to join
645   * \param chptr    Pointer to channel
646   * \param key      Key sent by client attempting to join if present
647   * \return ERR_BANNEDFROMCHAN, ERR_INVITEONLYCHAN, ERR_CHANNELISFULL
648   *         or 0 if allowed to join.
649   */
650 < int
651 < can_join(struct Client *source_p, struct Channel *chptr, const char *key)
650 > static int
651 > can_join(struct Client *client_p, struct Channel *chptr, const char *key)
652   {
653 <  if ((chptr->mode.mode & MODE_SSLONLY) && !HasUMode(source_p, UMODE_SSL))
653 >  if ((chptr->mode.mode & MODE_SSLONLY) && !HasUMode(client_p, UMODE_SSL))
654      return ERR_SSLONLYCHAN;
655  
656 <  if ((chptr->mode.mode & MODE_REGONLY) && !HasUMode(source_p, UMODE_REGISTERED))
656 >  if ((chptr->mode.mode & MODE_REGONLY) && !HasUMode(client_p, UMODE_REGISTERED))
657      return ERR_NEEDREGGEDNICK;
658  
659 <  if ((chptr->mode.mode & MODE_OPERONLY) && !HasUMode(source_p, UMODE_OPER))
659 >  if ((chptr->mode.mode & MODE_OPERONLY) && !HasUMode(client_p, UMODE_OPER))
660      return ERR_OPERONLYCHAN;
661  
662    if (chptr->mode.mode & MODE_INVITEONLY)
663 <    if (!dlinkFind(&source_p->localClient->invited, chptr))
664 <      if (!find_bmask(source_p, &chptr->invexlist))
663 >    if (!find_invite(chptr, client_p))
664 >      if (!find_bmask(client_p, &chptr->invexlist))
665          return ERR_INVITEONLYCHAN;
666  
667    if (chptr->mode.key[0] && (!key || strcmp(chptr->mode.key, key)))
# Line 651 | Line 671 | can_join(struct Client *source_p, struct
671        chptr->mode.limit)
672      return ERR_CHANNELISFULL;
673  
674 <  if (is_banned(chptr, source_p))
674 >  if (is_banned(chptr, client_p))
675      return ERR_BANNEDFROMCHAN;
676  
677    return 0;
678   }
679  
680   int
681 < has_member_flags(const struct Membership *ms, const unsigned int flags)
681 > has_member_flags(const struct Membership *member, const unsigned int flags)
682   {
683 <  return ms && (ms->flags & flags);
683 >  return member && (member->flags & flags);
684   }
685  
686   struct Membership *
687   find_channel_link(struct Client *client_p, struct Channel *chptr)
688   {
689 <  dlink_node *ptr = NULL;
689 >  dlink_node *node = NULL;
690  
691    if (!IsClient(client_p))
692      return NULL;
693  
694    if (dlink_list_length(&chptr->members) < dlink_list_length(&client_p->channel))
695    {
696 <    DLINK_FOREACH(ptr, chptr->members.head)
697 <      if (((struct Membership *)ptr->data)->client_p == client_p)
698 <        return ptr->data;
696 >    DLINK_FOREACH(node, chptr->members.head)
697 >      if (((struct Membership *)node->data)->client_p == client_p)
698 >        return node->data;
699    }
700    else
701    {
702 <    DLINK_FOREACH(ptr, client_p->channel.head)
703 <      if (((struct Membership *)ptr->data)->chptr == chptr)
704 <        return ptr->data;
702 >    DLINK_FOREACH(node, client_p->channel.head)
703 >      if (((struct Membership *)node->data)->chptr == chptr)
704 >        return node->data;
705    }
706  
707    return NULL;
708   }
709  
710 < /*! Tests if a client can send to a channel
710 > /*! Checks if a message contains control codes
711   * \param message The actual message string the client wants to send
712   * \return 1 if the message does contain any control codes, 0 otherwise
713   */
# Line 715 | Line 735 | msg_has_ctrls(const char *message)
735      return 1;  /* Control code */
736    }
737  
738 <  return 0;
738 >  return 0;  /* No control code found */
739   }
740  
741   /*! Tests if a client can send to a channel
742   * \param chptr    Pointer to Channel struct
743 < * \param source_p Pointer to Client struct
744 < * \param ms       Pointer to Membership struct (can be NULL)
743 > * \param client_p Pointer to Client struct
744 > * \param member   Pointer to Membership struct (can be NULL)
745   * \param message  The actual message string the client wants to send
746   * \return CAN_SEND_OPV if op or voiced on channel\n
747   *         CAN_SEND_NONOP if can send to channel but is not an op\n
748   *         ERR_CANNOTSENDTOCHAN or ERR_NEEDREGGEDNICK if they cannot send to channel\n
749   */
750   int
751 < can_send(struct Channel *chptr, struct Client *source_p,
752 <         struct Membership *ms, const char *message)
751 > can_send(struct Channel *chptr, struct Client *client_p,
752 >         struct Membership *member, const char *message, int notice)
753   {
754 <  struct MaskItem *conf = NULL;
754 >  const struct ResvItem *resv = NULL;
755  
756 <  if (IsServer(source_p) || HasFlag(source_p, FLAGS_SERVICE))
756 >  if (IsServer(client_p) || HasFlag(client_p, FLAGS_SERVICE))
757      return CAN_SEND_OPV;
758  
759 <  if (MyClient(source_p) && !IsExemptResv(source_p))
760 <    if (!(HasUMode(source_p, UMODE_OPER) && ConfigFileEntry.oper_pass_resv))
761 <      if ((conf = match_find_resv(chptr->chname)) && !resv_find_exempt(source_p, conf))
759 >  if (MyConnect(client_p) && !HasFlag(client_p, FLAGS_EXEMPTRESV))
760 >    if (!(HasUMode(client_p, UMODE_OPER) && HasOFlag(client_p, OPER_FLAG_JOIN_RESV)))
761 >      if ((resv = resv_find(chptr->name, match)) && !resv_exempt_find(client_p, resv))
762          return ERR_CANNOTSENDTOCHAN;
763  
764    if ((chptr->mode.mode & MODE_NOCTRL) && msg_has_ctrls(message))
765      return ERR_NOCTRLSONCHAN;
766 <  if (ms || (ms = find_channel_link(source_p, chptr)))
767 <    if (ms->flags & (CHFL_CHANOP|CHFL_HALFOP|CHFL_VOICE))
766 >
767 >  if (chptr->mode.mode & MODE_NOCTCP)
768 >    if (*message == '\001' && strncmp(message + 1, "ACTION ", 7))
769 >      return ERR_NOCTCP;
770 >
771 >  if (member || (member = find_channel_link(client_p, chptr)))
772 >    if (member->flags & (CHFL_CHANOP | CHFL_HALFOP | CHFL_VOICE))
773        return CAN_SEND_OPV;
774 <  if (!ms && (chptr->mode.mode & MODE_NOPRIVMSGS))
774 >
775 >  if (!member && (chptr->mode.mode & MODE_NOPRIVMSGS))
776      return ERR_CANNOTSENDTOCHAN;
777 +
778    if (chptr->mode.mode & MODE_MODERATED)
779      return ERR_CANNOTSENDTOCHAN;
780 <  if ((chptr->mode.mode & MODE_MODREG) && !HasUMode(source_p, UMODE_REGISTERED))
780 >
781 >  if ((chptr->mode.mode & MODE_MODREG) && !HasUMode(client_p, UMODE_REGISTERED))
782      return ERR_NEEDREGGEDNICK;
783  
784 +  if ((chptr->mode.mode & MODE_NONOTICE) && notice)
785 +    return ERR_CANNOTSENDTOCHAN;
786 +
787    /* Cache can send if banned */
788 <  if (MyClient(source_p))
788 >  if (MyConnect(client_p))
789    {
790 <    if (ms)
790 >    if (member)
791      {
792 <      if (ms->flags & CHFL_BAN_SILENCED)
792 >      if (member->flags & CHFL_BAN_SILENCED)
793          return ERR_CANNOTSENDTOCHAN;
794  
795 <      if (!(ms->flags & CHFL_BAN_CHECKED))
795 >      if (!(member->flags & CHFL_BAN_CHECKED))
796        {
797 <        if (is_banned(chptr, source_p))
797 >        if (is_banned(chptr, client_p))
798          {
799 <          ms->flags |= (CHFL_BAN_CHECKED|CHFL_BAN_SILENCED);
799 >          member->flags |= (CHFL_BAN_CHECKED | CHFL_BAN_SILENCED);
800            return ERR_CANNOTSENDTOCHAN;
801          }
802  
803 <        ms->flags |= CHFL_BAN_CHECKED;
803 >        member->flags |= CHFL_BAN_CHECKED;
804        }
805      }
806 <    else if (is_banned(chptr, source_p))
806 >    else if (is_banned(chptr, client_p))
807        return ERR_CANNOTSENDTOCHAN;
808    }
809  
# Line 782 | Line 813 | can_send(struct Channel *chptr, struct C
813   /*! \brief Updates the client's oper_warn_count_down, warns the
814   *         IRC operators if necessary, and updates
815   *         join_leave_countdown as needed.
816 < * \param source_p Pointer to struct Client to check
816 > * \param client_p Pointer to struct Client to check
817   * \param name     Channel name or NULL if this is a part.
818   */
819   void
820 < check_spambot_warning(struct Client *source_p, const char *name)
820 > check_spambot_warning(struct Client *client_p, const char *name)
821   {
822    int t_delta = 0;
823    int decrement_count = 0;
824  
825    if ((GlobalSetOptions.spam_num &&
826 <       (source_p->localClient->join_leave_count >=
826 >       (client_p->connection->join_leave_count >=
827          GlobalSetOptions.spam_num)))
828    {
829 <    if (source_p->localClient->oper_warn_count_down > 0)
830 <      source_p->localClient->oper_warn_count_down--;
829 >    if (client_p->connection->oper_warn_count_down > 0)
830 >      client_p->connection->oper_warn_count_down--;
831      else
832 <      source_p->localClient->oper_warn_count_down = 0;
832 >      client_p->connection->oper_warn_count_down = 0;
833  
834 <    if (source_p->localClient->oper_warn_count_down == 0)
834 >    if (client_p->connection->oper_warn_count_down == 0)
835      {
836        /* It's already known as a possible spambot */
837        if (name)
838          sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE,
839                               "User %s (%s@%s) trying to join %s is a possible spambot",
840 <                             source_p->name, source_p->username,
841 <                             source_p->host, name);
840 >                             client_p->name, client_p->username,
841 >                             client_p->host, name);
842        else
843          sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE,
844                               "User %s (%s@%s) is a possible spambot",
845 <                             source_p->name, source_p->username,
846 <                             source_p->host);
847 <      source_p->localClient->oper_warn_count_down = OPER_SPAM_COUNTDOWN;
845 >                             client_p->name, client_p->username,
846 >                             client_p->host);
847 >      client_p->connection->oper_warn_count_down = OPER_SPAM_COUNTDOWN;
848      }
849    }
850    else
851    {
852 <    if ((t_delta = (CurrentTime - source_p->localClient->last_leave_time)) >
852 >    if ((t_delta = (CurrentTime - client_p->connection->last_leave_time)) >
853           JOIN_LEAVE_COUNT_EXPIRE_TIME)
854      {
855        decrement_count = (t_delta / JOIN_LEAVE_COUNT_EXPIRE_TIME);
856 <      if (decrement_count > source_p->localClient->join_leave_count)
857 <        source_p->localClient->join_leave_count = 0;
856 >
857 >      if (decrement_count > client_p->connection->join_leave_count)
858 >        client_p->connection->join_leave_count = 0;
859        else
860 <        source_p->localClient->join_leave_count -= decrement_count;
860 >        client_p->connection->join_leave_count -= decrement_count;
861      }
862      else
863      {
864 <      if ((CurrentTime - (source_p->localClient->last_join_time)) <
864 >      if ((CurrentTime - (client_p->connection->last_join_time)) <
865            GlobalSetOptions.spam_time)
866 <        source_p->localClient->join_leave_count++;  /* It's a possible spambot */
866 >        client_p->connection->join_leave_count++;  /* It's a possible spambot */
867      }
868  
869      if (name)
870 <      source_p->localClient->last_join_time = CurrentTime;
870 >      client_p->connection->last_join_time = CurrentTime;
871      else
872 <      source_p->localClient->last_leave_time = CurrentTime;
841 <  }
842 < }
843 <
844 < /*! \brief Compares usercount and servercount against their split
845 < *         values and adjusts splitmode accordingly
846 < * \param unused Unused address pointer
847 < */
848 < void
849 < check_splitmode(void *unused)
850 < {
851 <  if (splitchecking && (ConfigChannel.no_join_on_split ||
852 <                        ConfigChannel.no_create_on_split))
853 <  {
854 <    const unsigned int server = dlink_list_length(&global_server_list);
855 <
856 <    if (!splitmode && ((server < split_servers) || (Count.total < split_users)))
857 <    {
858 <      splitmode = 1;
859 <
860 <      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
861 <                           "Network split, activating splitmode");
862 <      event_add(&splitmode_event, NULL);
863 <    }
864 <    else if (splitmode && (server >= split_servers) && (Count.total >= split_users))
865 <    {
866 <      splitmode = 0;
867 <
868 <      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
869 <                           "Network rejoined, deactivating splitmode");
870 <      event_delete(&splitmode_event);
871 <    }
872 >      client_p->connection->last_leave_time = CurrentTime;
873    }
874   }
875  
# Line 881 | Line 882 | check_splitmode(void *unused)
882   */
883   void
884   channel_set_topic(struct Channel *chptr, const char *topic,
885 <                  const char *topic_info, time_t topicts, int local)
885 >                  const char *topic_info, uintmax_t topicts, int local)
886   {
887    if (local)
888 <    strlcpy(chptr->topic, topic, IRCD_MIN(sizeof(chptr->topic), ServerInfo.max_topic_length + 1));
888 >    strlcpy(chptr->topic, topic, IRCD_MIN(sizeof(chptr->topic), ConfigServerInfo.max_topic_length + 1));
889    else
890      strlcpy(chptr->topic, topic, sizeof(chptr->topic));
891  
# Line 902 | Line 903 | channel_set_topic(struct Channel *chptr,
903   *                anti spambot code.
904   */
905   void
906 < channel_do_join_0(struct Client *source_p)
906 > channel_do_join_0(struct Client *client_p)
907   {
908 <  dlink_node *ptr = NULL, *ptr_next = NULL;
909 <
910 <  if (source_p->channel.head)
910 <    if (MyConnect(source_p) && !HasUMode(source_p, UMODE_OPER))
911 <      check_spambot_warning(source_p, NULL);
908 >  if (client_p->channel.head)
909 >    if (MyConnect(client_p) && !HasUMode(client_p, UMODE_OPER))
910 >      check_spambot_warning(client_p, NULL);
911  
912 <  DLINK_FOREACH_SAFE(ptr, ptr_next, source_p->channel.head)
912 >  while (client_p->channel.head)
913    {
914 <    struct Channel *chptr = ((struct Membership *)ptr->data)->chptr;
914 >    struct Membership *member = client_p->channel.head->data;
915  
916 <    sendto_server(source_p, NOCAPS, NOCAPS, ":%s PART %s",
917 <                  source_p->id, chptr->chname);
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->chname);
916 >    sendto_server(client_p, 0, 0, ":%s PART %s",
917 >                  client_p->id, member->chptr->name);
918 >    sendto_channel_local(NULL, member->chptr, 0, 0, 0, ":%s!%s@%s PART %s",
919 >                         client_p->name, client_p->username,
920 >                         client_p->host, member->chptr->name);
921  
922 <    remove_user_from_channel(ptr->data);
922 >    remove_user_from_channel(member);
923    }
924   }
925  
926   static char *
927 < channel_find_last0(struct Client *source_p, char *chanlist)
927 > channel_find_last0(struct Client *client_p, char *chanlist)
928   {
929    int join0 = 0;
930  
# Line 933 | Line 932 | channel_find_last0(struct Client *source
932    {
933      if (*p == '0' && (*(p + 1) == ',' || *(p + 1) == '\0'))
934      {
935 <      if ((*p + 1) == ',')
935 >      if (*(p + 1) == ',')
936          ++p;
937  
938        chanlist = p + 1;
# Line 950 | Line 949 | channel_find_last0(struct Client *source
949    }
950  
951    if (join0)
952 <    channel_do_join_0(source_p);
952 >    channel_do_join_0(client_p);
953  
954    return chanlist;
955   }
956  
957   void
958 < channel_do_join(struct Client *source_p, char *channel, char *key_list)
958 > channel_do_join(struct Client *client_p, char *channel, char *key_list)
959   {
960    char *p = NULL;
962  char *chan = NULL;
961    char *chan_list = NULL;
962    struct Channel *chptr = NULL;
963 <  struct MaskItem *conf = NULL;
964 <  const struct ClassItem *class = get_class_ptr(&source_p->localClient->confs);
967 <  int i = 0;
963 >  const struct ResvItem *resv = NULL;
964 >  const struct ClassItem *const class = get_class_ptr(&client_p->connection->confs);
965    unsigned int flags = 0;
966  
967 <  chan_list = channel_find_last0(source_p, channel);
967 >  assert(IsClient(client_p));
968  
969 <  for (chan = strtoken(&p, chan_list, ","); chan;
970 <       chan = strtoken(&p,      NULL, ","))
969 >  chan_list = channel_find_last0(client_p, channel);
970 >
971 >  for (const char *chan = strtok_r(chan_list, ",", &p); chan;
972 >                   chan = strtok_r(NULL,      ",", &p))
973    {
974      const char *key = NULL;
975  
# Line 982 | Line 981 | channel_do_join(struct Client *source_p,
981      if (key && *key == '\0')
982        key = NULL;
983  
984 <    if (!check_channel_name(chan, 1))
984 >    if (!channel_check_name(chan, 1))
985      {
986 <      sendto_one_numeric(source_p, &me, ERR_BADCHANNAME, chan);
986 >      sendto_one_numeric(client_p, &me, ERR_BADCHANNAME, chan);
987        continue;
988      }
989  
990 <    if (!IsExemptResv(source_p) &&
991 <        !(HasUMode(source_p, UMODE_OPER) && ConfigFileEntry.oper_pass_resv) &&
992 <        ((conf = match_find_resv(chan)) && !resv_find_exempt(source_p, conf)))
993 <    {
994 <      ++conf->count;
996 <      sendto_one_numeric(source_p, &me, ERR_CHANBANREASON,
997 <                         chan, conf->reason ? conf->reason : "Reserved channel");
990 >    if (!HasFlag(client_p, FLAGS_EXEMPTRESV) &&
991 >        !(HasUMode(client_p, UMODE_OPER) && HasOFlag(client_p, OPER_FLAG_JOIN_RESV)) &&
992 >        ((resv = resv_find(chan, match)) && !resv_exempt_find(client_p, resv)))
993 >    {
994 >      sendto_one_numeric(client_p, &me, ERR_CHANBANREASON, chan, resv->reason);
995        sendto_realops_flags(UMODE_REJ, L_ALL, SEND_NOTICE,
996                             "Forbidding reserved channel %s from user %s",
997 <                           chan, get_client_name(source_p, HIDE_IP));
997 >                           chan, get_client_name(client_p, HIDE_IP));
998        continue;
999      }
1000  
1001 <    if (dlink_list_length(&source_p->channel) >=
1001 >    if (dlink_list_length(&client_p->channel) >=
1002          ((class->max_channels) ? class->max_channels : ConfigChannel.max_channels))
1003      {
1004 <      sendto_one_numeric(source_p, &me, ERR_TOOMANYCHANNELS, chan);
1004 >      sendto_one_numeric(client_p, &me, ERR_TOOMANYCHANNELS, chan);
1005        break;
1006      }
1007  
1008      if ((chptr = hash_find_channel(chan)))
1009      {
1010 <      if (IsMember(source_p, chptr))
1014 <        continue;
1015 <
1016 <      if (splitmode && !HasUMode(source_p, UMODE_OPER) &&
1017 <          ConfigChannel.no_join_on_split)
1018 <      {
1019 <        sendto_one_numeric(source_p, &me, ERR_UNAVAILRESOURCE, chptr->chname);
1010 >      if (IsMember(client_p, chptr))
1011          continue;
1021      }
1012  
1013 <      /*
1014 <       * can_join checks for +i key, bans.
1015 <       */
1026 <      if ((i = can_join(source_p, chptr, key)))
1013 >      /* can_join() checks for +i, +l, key, bans, etc. */
1014 >      int ret = can_join(client_p, chptr, key);
1015 >      if (ret)
1016        {
1017 <        sendto_one_numeric(source_p, &me, i, chptr->chname);
1017 >        sendto_one_numeric(client_p, &me, ret, chptr->name);
1018          continue;
1019        }
1020  
# Line 1033 | Line 1022 | channel_do_join(struct Client *source_p,
1022         * This should never be the case unless there is some sort of
1023         * persistant channels.
1024         */
1025 <      if (dlink_list_length(&chptr->members) == 0)
1025 >      if (!dlink_list_length(&chptr->members))
1026          flags = CHFL_CHANOP;
1027        else
1028          flags = 0;
1029      }
1030      else
1031      {
1043      if (splitmode && !HasUMode(source_p, UMODE_OPER) &&
1044          (ConfigChannel.no_create_on_split || ConfigChannel.no_join_on_split))
1045      {
1046        sendto_one_numeric(source_p, &me, ERR_UNAVAILRESOURCE, chan);
1047        continue;
1048      }
1049
1032        flags = CHFL_CHANOP;
1033 <      chptr = make_channel(chan);
1033 >      chptr = channel_make(chan);
1034      }
1035  
1036 <    if (!HasUMode(source_p, UMODE_OPER))
1037 <      check_spambot_warning(source_p, chptr->chname);
1036 >    if (!HasUMode(client_p, UMODE_OPER))
1037 >      check_spambot_warning(client_p, chptr->name);
1038  
1039 <    add_user_to_channel(chptr, source_p, flags, 1);
1039 >    add_user_to_channel(chptr, client_p, flags, 1);
1040  
1041      /*
1042 <     *  Set timestamp if appropriate, and propagate
1042 >     * Set timestamp if appropriate, and propagate
1043       */
1044      if (flags == CHFL_CHANOP)
1045      {
1046 <      chptr->channelts = CurrentTime;
1046 >      chptr->creationtime = CurrentTime;
1047        chptr->mode.mode |= MODE_TOPICLIMIT;
1048        chptr->mode.mode |= MODE_NOPRIVMSGS;
1049  
1050 <      sendto_server(source_p, NOCAPS, NOCAPS, ":%s SJOIN %lu %s +nt :@%s",
1051 <                    me.id, (unsigned long)chptr->channelts,
1052 <                    chptr->chname, source_p->id);
1050 >      sendto_server(client_p, 0, 0, ":%s SJOIN %ju %s +nt :@%s",
1051 >                    me.id, chptr->creationtime,
1052 >                    chptr->name, client_p->id);
1053  
1054        /*
1055         * Notify all other users on the new channel
1056         */
1057 <      sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s!%s@%s JOIN :%s",
1058 <                           source_p->name, source_p->username,
1059 <                           source_p->host, chptr->chname);
1060 <      sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s MODE %s +nt",
1061 <                           me.name, chptr->chname);
1062 <
1063 <      if (source_p->away[0])
1064 <        sendto_channel_local_butone(source_p, 0, CAP_AWAY_NOTIFY, chptr,
1065 <                                    ":%s!%s@%s AWAY :%s",
1066 <                                    source_p->name, source_p->username,
1067 <                                    source_p->host, source_p->away);
1057 >      sendto_channel_local(NULL, chptr, 0, CAP_EXTENDED_JOIN, 0, ":%s!%s@%s JOIN %s %s :%s",
1058 >                           client_p->name, client_p->username,
1059 >                           client_p->host, chptr->name, client_p->account, client_p->info);
1060 >      sendto_channel_local(NULL, chptr, 0, 0, CAP_EXTENDED_JOIN, ":%s!%s@%s JOIN :%s",
1061 >                           client_p->name, client_p->username,
1062 >                           client_p->host, chptr->name);
1063 >      sendto_channel_local(NULL, chptr, 0, 0, 0, ":%s MODE %s +nt",
1064 >                           me.name, chptr->name);
1065 >
1066 >      if (client_p->away[0])
1067 >        sendto_channel_local(client_p, chptr, 0, CAP_AWAY_NOTIFY, 0,
1068 >                             ":%s!%s@%s AWAY :%s",
1069 >                             client_p->name, client_p->username,
1070 >                             client_p->host, client_p->away);
1071      }
1072      else
1073      {
1074 <      sendto_server(source_p, NOCAPS, NOCAPS, ":%s JOIN %lu %s +",
1075 <                    source_p->id, (unsigned long)chptr->channelts,
1076 <                    chptr->chname);
1077 <      sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s!%s@%s JOIN :%s",
1078 <                           source_p->name, source_p->username,
1079 <                           source_p->host, chptr->chname);
1080 <
1081 <      if (source_p->away[0])
1082 <        sendto_channel_local_butone(source_p, 0, CAP_AWAY_NOTIFY, chptr,
1083 <                                    ":%s!%s@%s AWAY :%s",
1084 <                                    source_p->name, source_p->username,
1085 <                                    source_p->host, source_p->away);
1086 <    }
1087 <
1088 <    del_invite(chptr, source_p);
1074 >      sendto_server(client_p, 0, 0, ":%s JOIN %ju %s +",
1075 >                    client_p->id, chptr->creationtime,
1076 >                    chptr->name);
1077 >
1078 >      sendto_channel_local(NULL, chptr, 0, CAP_EXTENDED_JOIN, 0, ":%s!%s@%s JOIN %s %s :%s",
1079 >                           client_p->name, client_p->username,
1080 >                           client_p->host, chptr->name, client_p->account, client_p->info);
1081 >      sendto_channel_local(NULL, chptr, 0, 0, CAP_EXTENDED_JOIN, ":%s!%s@%s JOIN :%s",
1082 >                           client_p->name, client_p->username,
1083 >                           client_p->host, chptr->name);
1084 >
1085 >      if (client_p->away[0])
1086 >        sendto_channel_local(client_p, chptr, 0, CAP_AWAY_NOTIFY, 0,
1087 >                             ":%s!%s@%s AWAY :%s",
1088 >                             client_p->name, client_p->username,
1089 >                             client_p->host, client_p->away);
1090 >    }
1091 >
1092 >    struct Invite *invite = find_invite(chptr, client_p);
1093 >    if (invite)
1094 >      del_invite(invite);
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,
1098 >      sendto_one_numeric(client_p, &me, RPL_TOPIC, chptr->name, chptr->topic);
1099 >      sendto_one_numeric(client_p, &me, RPL_TOPICWHOTIME, chptr->name,
1100                           chptr->topic_info, chptr->topic_time);
1101      }
1102  
1103 <    channel_member_names(source_p, chptr, 1);
1103 >    channel_member_names(client_p, chptr, 1);
1104  
1105 <    source_p->localClient->last_join_time = CurrentTime;
1105 >    client_p->connection->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
1110 > * \param client_p Pointer to 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)
1115 > channel_part_one_client(struct Client *client_p, const char *name, const char *reason)
1116   {
1117    struct Channel *chptr = NULL;
1118 <  struct Membership *ms = NULL;
1118 >  struct Membership *member = NULL;
1119  
1120    if ((chptr = hash_find_channel(name)) == NULL)
1121    {
1122 <    sendto_one_numeric(source_p, &me, ERR_NOSUCHCHANNEL, name);
1122 >    sendto_one_numeric(client_p, &me, ERR_NOSUCHCHANNEL, name);
1123      return;
1124    }
1125  
1126 <  if ((ms = find_channel_link(source_p, chptr)) == NULL)
1126 >  if ((member = find_channel_link(client_p, chptr)) == NULL)
1127    {
1128 <    sendto_one_numeric(source_p, &me, ERR_NOTONCHANNEL, chptr->chname);
1128 >    sendto_one_numeric(client_p, &me, ERR_NOTONCHANNEL, chptr->name);
1129      return;
1130    }
1131  
1132 <  if (MyConnect(source_p) && !HasUMode(source_p, UMODE_OPER))
1133 <    check_spambot_warning(source_p, NULL);
1132 >  if (MyConnect(client_p) && !HasUMode(client_p, UMODE_OPER))
1133 >    check_spambot_warning(client_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);
1139 >  if (*reason && (!MyConnect(client_p) ||
1140 >      ((client_p->connection->firsttime +
1141 >        ConfigGeneral.anti_spam_exit_message_time) < CurrentTime &&
1142 >       can_send(chptr, client_p, member, reason, 0) < 0)))
1143 >  {
1144 >    sendto_server(client_p, 0, 0, ":%s PART %s :%s",
1145 >                  client_p->id, chptr->name, reason);
1146 >    sendto_channel_local(NULL, chptr, 0, 0, 0, ":%s!%s@%s PART %s :%s",
1147 >                         client_p->name, client_p->username,
1148 >                         client_p->host, chptr->name, 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);
1152 >    sendto_server(client_p, 0, 0, ":%s PART %s",
1153 >                  client_p->id, chptr->name);
1154 >    sendto_channel_local(NULL, chptr, 0, 0, 0, ":%s!%s@%s PART %s",
1155 >                         client_p->name, client_p->username,
1156 >                         client_p->host, chptr->name);
1157    }
1158  
1159 <  remove_user_from_channel(ms);
1159 >  remove_user_from_channel(member);
1160   }
1161  
1162   void
1163 < channel_do_part(struct Client *source_p, char *channel, char *reason)
1163 > channel_do_part(struct Client *client_p, char *channel, const char *reason)
1164   {
1165    char *p = NULL, *name = NULL;
1166 <  char reasonbuf[KICKLEN + 1] = "";
1166 >  char buf[KICKLEN + 1] = "";
1167 >
1168 >  assert(IsClient(client_p));
1169  
1170    if (!EmptyString(reason))
1171 <    strlcpy(reasonbuf, reason, sizeof(reasonbuf));
1171 >    strlcpy(buf, reason, sizeof(buf));
1172  
1173 <  for (name = strtoken(&p, channel, ","); name;
1174 <       name = strtoken(&p,    NULL, ","))
1175 <    channel_part_one_client(source_p, name, reasonbuf);
1173 >  for (name = strtok_r(channel, ",", &p); name;
1174 >       name = strtok_r(NULL,    ",", &p))
1175 >    channel_part_one_client(client_p, name, buf);
1176   }

Comparing ircd-hybrid/trunk/src/channel.c (property svn:keywords):
Revision 4209 by michael, Sat Jul 12 18:15:19 2014 UTC vs.
Revision 7766 by michael, Fri Oct 7 16:27:37 2016 UTC

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

Diff Legend

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