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

Diff Legend

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