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 4170 by michael, Sat Jul 5 15:32:59 2014 UTC vs.
Revision 7234 by michael, Wed Feb 3 16:30:10 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
50   static mp_pool_t *member_pool, *channel_pool;
58 static char buf[IRCD_BUFSIZE];
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    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 74 | 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 107 | 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 <  ms->client_p = who;
112 <  ms->chptr = chptr;
113 <  ms->flags = flags;
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 <  dlinkAdd(ms, &ms->channode, &chptr->members);
115 >  dlinkAdd(member, &member->channode, &chptr->members);
116  
117 <  if (MyConnect(who))
118 <    dlinkAdd(ms, &ms->locchannode, &chptr->locmembers);
117 >  if (MyConnect(client_p))
118 >    dlinkAdd(member, &member->locchannode, &chptr->locmembers);
119  
120 <  dlinkAdd(ms, &ms->usernode, &who->channel);
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 135 | 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  
# Line 148 | Line 140 | remove_user_from_channel(struct Membersh
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 193 | 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 220 | 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 247 | 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,
257 <                  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 267 | 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 286 | 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 312 | 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 <
319 <  MyFree(bptr->name);
320 <  MyFree(bptr->user);
321 <  MyFree(bptr->host);
322 <  MyFree(bptr->who);
323 <
324 <  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;
323 >  dlink_node *node = NULL, *node_next = NULL;
324  
325 <  DLINK_FOREACH_SAFE(ptr, ptr_next, list->head)
326 <    remove_ban(ptr->data, list);
340 <
341 <  assert(list->tail == NULL && list->head == NULL);
325 >  DLINK_FOREACH_SAFE(node, node_next, list->head)
326 >    remove_ban(node->data, list);
327   }
328  
329 < /*! \brief Get Channel block for chname (and allocate a new channel
329 > /*! \brief Get Channel block for name (and allocate a new channel
330   *         block, if it didn't exist before)
331 < * \param chname Channel name
331 > * \param name Channel name
332   * \return Channel block
333   */
334   struct Channel *
335 < make_channel(const char *chname)
335 > channel_make(const char *name)
336   {
337    struct Channel *chptr = NULL;
338  
339 <  assert(!EmptyString(chname));
339 >  assert(!EmptyString(name));
340  
341    chptr = mp_pool_get(channel_pool);
342  
343    /* Doesn't hurt to set it here */
344 <  chptr->channelts = CurrentTime;
344 >  chptr->creationtime = CurrentTime;
345    chptr->last_join_time = CurrentTime;
346  
347 <  strlcpy(chptr->chname, chname, sizeof(chptr->chname));
348 <  dlinkAdd(chptr, &chptr->node, &channel_list);
347 >  chptr->name_len = strlcpy(chptr->name, name, sizeof(chptr->name));
348 >  if (chptr->name_len >= sizeof(chptr->name))
349 >    chptr->name_len = sizeof(chptr->name) - 1;
350  
351 +  dlinkAdd(chptr, &chptr->node, &channel_list);
352    hash_add_channel(chptr);
353  
354    return chptr;
# Line 371 | Line 358 | make_channel(const char *chname)
358   * \param chptr Channel pointer
359   */
360   void
361 < destroy_channel(struct Channel *chptr)
361 > channel_free(struct Channel *chptr)
362   {
363 <  dlink_node *ptr = NULL, *ptr_next = NULL;
377 <
378 <  DLINK_FOREACH_SAFE(ptr, ptr_next, chptr->invites.head)
379 <    del_invite(chptr, ptr->data);
363 >  clear_invites_channel(chptr);
364  
365    /* Free ban/exception/invex lists */
366 <  free_channel_list(&chptr->banlist);
367 <  free_channel_list(&chptr->exceptlist);
368 <  free_channel_list(&chptr->invexlist);
366 >  channel_free_mask_list(&chptr->banlist);
367 >  channel_free_mask_list(&chptr->exceptlist);
368 >  channel_free_mask_list(&chptr->invexlist);
369  
370    dlinkDelete(&chptr->node, &channel_list);
371    hash_del_channel(chptr);
# Line 404 | Line 388 | channel_pub_or_secret(const struct Chann
388   }
389  
390   /*! \brief lists all names on given channel
391 < * \param source_p Pointer to client struct requesting names
391 > * \param client_p Pointer to client struct requesting names
392   * \param chptr    Pointer to channel block
393   * \param show_eon Show RPL_ENDOFNAMES numeric or not
394   *                 (don't want it with /names with no params)
395   */
396   void
397 < channel_member_names(struct Client *source_p, struct Channel *chptr,
397 > channel_member_names(struct Client *client_p, struct Channel *chptr,
398                       int show_eon)
399   {
400 <  const dlink_node *ptr = NULL;
401 <  char lbuf[IRCD_BUFSIZE + 1] = "";
400 >  const dlink_node *node = NULL;
401 >  char buf[IRCD_BUFSIZE + 1] = "";
402    char *t = NULL, *start = NULL;
403    int tlen = 0;
404 <  int is_member = IsMember(source_p, chptr);
405 <  int multi_prefix = HasCap(source_p, CAP_MULTI_PREFIX) != 0;
406 <  int uhnames = HasCap(source_p, CAP_UHNAMES) != 0;
404 >  const int is_member = IsMember(client_p, chptr);
405 >  const int multi_prefix = HasCap(client_p, CAP_MULTI_PREFIX) != 0;
406 >  const int uhnames = HasCap(client_p, CAP_UHNAMES) != 0;
407 >
408 >  assert(IsClient(client_p));
409  
410    if (PubChannel(chptr) || is_member)
411    {
412 <    t = lbuf + snprintf(lbuf, sizeof(lbuf), numeric_form(RPL_NAMREPLY),
413 <                        me.name, source_p->name,
414 <                        channel_pub_or_secret(chptr), chptr->chname);
412 >    t = buf + snprintf(buf, sizeof(buf), numeric_form(RPL_NAMREPLY),
413 >                       me.name, client_p->name,
414 >                       channel_pub_or_secret(chptr), chptr->name);
415      start = t;
416  
417 <    DLINK_FOREACH(ptr, chptr->members.head)
417 >    DLINK_FOREACH(node, chptr->members.head)
418      {
419 <      const struct Membership *ms = ptr->data;
419 >      const struct Membership *member = node->data;
420  
421 <      if (HasUMode(ms->client_p, UMODE_INVISIBLE) && !is_member)
421 >      if (HasUMode(member->client_p, UMODE_INVISIBLE) && !is_member)
422          continue;
423  
424        if (!uhnames)
425 <        tlen = strlen(ms->client_p->name) + 1;  /* +1 for space */
425 >        tlen = strlen(member->client_p->name) + 1;  /* +1 for space */
426        else
427 <        tlen = strlen(ms->client_p->name) + strlen(ms->client_p->username) +
428 <               strlen(ms->client_p->host) + 3;  /* +3 for ! + @ + space */
427 >        tlen = strlen(member->client_p->name) + strlen(member->client_p->username) +
428 >               strlen(member->client_p->host) + 3;  /* +3 for ! + @ + space */
429  
430        if (!multi_prefix)
431        {
432 <        if (ms->flags & (CHFL_CHANOP | CHFL_HALFOP | CHFL_VOICE))
432 >        if (member->flags & (CHFL_CHANOP | CHFL_HALFOP | CHFL_VOICE))
433            ++tlen;
434        }
435        else
436        {
437 <        if (ms->flags & CHFL_CHANOP)
437 >        if (member->flags & CHFL_CHANOP)
438            ++tlen;
439 <        if (ms->flags & CHFL_HALFOP)
439 >        if (member->flags & CHFL_HALFOP)
440            ++tlen;
441 <        if (ms->flags & CHFL_VOICE)
441 >        if (member->flags & CHFL_VOICE)
442            ++tlen;
443        }
444  
445 <      if (t + tlen - lbuf > IRCD_BUFSIZE - 2)
445 >      if (t + tlen - buf > IRCD_BUFSIZE - 2)
446        {
447          *(t - 1) = '\0';
448 <        sendto_one(source_p, "%s", lbuf);
448 >        sendto_one(client_p, "%s", buf);
449          t = start;
450        }
451  
452        if (!uhnames)
453 <        t += sprintf(t, "%s%s ", get_member_status(ms, multi_prefix),
454 <                     ms->client_p->name);
453 >        t += sprintf(t, "%s%s ", get_member_status(member, multi_prefix),
454 >                     member->client_p->name);
455        else
456 <        t += sprintf(t, "%s%s!%s@%s ", get_member_status(ms, multi_prefix),
457 <                     ms->client_p->name, ms->client_p->username,
458 <                     ms->client_p->host);
456 >        t += sprintf(t, "%s%s!%s@%s ", get_member_status(member, multi_prefix),
457 >                     member->client_p->name, member->client_p->username,
458 >                     member->client_p->host);
459      }
460  
461      if (tlen)
462      {
463        *(t - 1) = '\0';
464 <      sendto_one(source_p, "%s", lbuf);
464 >      sendto_one(client_p, "%s", buf);
465      }
466    }
467  
468    if (show_eon)
469 <    sendto_one_numeric(source_p, &me, RPL_ENDOFNAMES, chptr->chname);
469 >    sendto_one_numeric(client_p, &me, RPL_ENDOFNAMES, chptr->name);
470   }
471  
472   /*! \brief Adds client to invite list
473 < * \param chptr Pointer to channel block
474 < * \param who   Pointer to client to add invite to
473 > * \param chptr    Pointer to channel block
474 > * \param client_p Pointer to client to add invite to
475   */
476   void
477 < add_invite(struct Channel *chptr, struct Client *who)
477 > add_invite(struct Channel *chptr, struct Client *client_p)
478   {
479 <  del_invite(chptr, who);
479 >  assert(IsClient(client_p));
480 >
481 >  del_invite(chptr, client_p);
482  
483    /*
484     * Delete last link in chain if the list is max length
485     */
486 <  if (dlink_list_length(&who->localClient->invited) >=
486 >  if (dlink_list_length(&client_p->connection->invited) >=
487        ConfigChannel.max_channels)
488 <    del_invite(who->localClient->invited.tail->data, who);
488 >    del_invite(client_p->connection->invited.tail->data, client_p);
489  
490    /* Add client to channel invite list */
491 <  dlinkAdd(who, make_dlink_node(), &chptr->invites);
491 >  dlinkAdd(client_p, make_dlink_node(), &chptr->invites);
492  
493    /* Add channel to the end of the client invite list */
494 <  dlinkAdd(chptr, make_dlink_node(), &who->localClient->invited);
494 >  dlinkAdd(chptr, make_dlink_node(), &client_p->connection->invited);
495   }
496  
497   /*! \brief Delete Invite block from channel invite list
498   *         and client invite list
499 + * \param chptr    Pointer to Channel struct
500 + * \param client_p Pointer to client to remove invites from
501 + */
502 + void
503 + del_invite(struct Channel *chptr, struct Client *client_p)
504 + {
505 +  dlink_node *node = NULL;
506 +
507 +  if ((node = dlinkFindDelete(&client_p->connection->invited, chptr)))
508 +    free_dlink_node(node);
509 +
510 +  if ((node = dlinkFindDelete(&chptr->invites, client_p)))
511 +    free_dlink_node(node);
512 + }
513 +
514 + /*! \brief Removes all invites of a specific channel
515   * \param chptr Pointer to Channel struct
512 * \param who   Pointer to client to remove invites from
516   */
517   void
518 < del_invite(struct Channel *chptr, struct Client *who)
518 > clear_invites_channel(struct Channel *chptr)
519   {
520 <  dlink_node *ptr = NULL;
520 >  dlink_node *node = NULL, *node_next = NULL;
521  
522 <  if ((ptr = dlinkFindDelete(&who->localClient->invited, chptr)))
523 <    free_dlink_node(ptr);
522 >  DLINK_FOREACH_SAFE(node, node_next, chptr->invites.head)
523 >    del_invite(chptr, node->data);
524 > }
525  
526 <  if ((ptr = dlinkFindDelete(&chptr->invites, who)))
527 <    free_dlink_node(ptr);
526 > /*! \brief Removes all invites of a specific client
527 > * \param client_p Pointer to Client struct
528 > */
529 > void
530 > clear_invites_client(struct Client *client_p)
531 > {
532 >  dlink_node *node = NULL, *node_next = NULL;
533 >
534 >  DLINK_FOREACH_SAFE(node, node_next, client_p->connection->invited.head)
535 >    del_invite(node->data, client_p);
536   }
537  
538   /* get_member_status()
# Line 535 | Line 547 | del_invite(struct Channel *chptr, struct
547   * (like in get_client_name)
548   */
549   const char *
550 < get_member_status(const struct Membership *ms, const int combine)
550 > get_member_status(const struct Membership *member, const int combine)
551   {
552 <  static char buffer[4];  /* 4 for @%+\0 */
552 >  static char buffer[CMEMBER_STATUS_FLAGS_LEN + 1];  /* +1 for \0 */
553    char *p = buffer;
554  
555 <  if (ms->flags & CHFL_CHANOP)
555 >  if (member->flags & CHFL_CHANOP)
556    {
557      if (!combine)
558        return "@";
559      *p++ = '@';
560    }
561  
562 <  if (ms->flags & CHFL_HALFOP)
562 >  if (member->flags & CHFL_HALFOP)
563    {
564      if (!combine)
565        return "%";
566      *p++ = '%';
567    }
568  
569 <  if (ms->flags & CHFL_VOICE)
569 >  if (member->flags & CHFL_VOICE)
570      *p++ = '+';
571    *p = '\0';
572  
# Line 562 | Line 574 | get_member_status(const struct Membershi
574   }
575  
576   /*!
577 < * \param who  Pointer to Client to check
578 < * \param list Pointer to ban list to search
577 > * \param client_p Pointer to Client to check
578 > * \param list     Pointer to ban list to search
579   * \return 1 if ban found for given n!u\@h mask, 0 otherwise
568 *
580   */
581   static int
582 < find_bmask(const struct Client *who, const dlink_list *const list)
582 > find_bmask(const struct Client *client_p, const dlink_list *const list)
583   {
584 <  const dlink_node *ptr = NULL;
584 >  const dlink_node *node = NULL;
585  
586 <  DLINK_FOREACH(ptr, list->head)
586 >  DLINK_FOREACH(node, list->head)
587    {
588 <    const struct Ban *bp = ptr->data;
588 >    const struct Ban *ban = node->data;
589  
590 <    if (!match(bp->name, who->name) && !match(bp->user, who->username))
590 >    if (!match(ban->name, client_p->name) && !match(ban->user, client_p->username))
591      {
592 <      switch (bp->type)
592 >      switch (ban->type)
593        {
594          case HM_HOST:
595 <          if (!match(bp->host, who->host) || !match(bp->host, who->sockhost))
595 >          if (!match(ban->host, client_p->host) || !match(ban->host, client_p->sockhost))
596              return 1;
597            break;
598          case HM_IPV4:
599 <          if (who->localClient->aftype == AF_INET)
600 <            if (match_ipv4(&who->localClient->ip, &bp->addr, bp->bits))
599 >          if (client_p->connection->aftype == AF_INET)
600 >            if (match_ipv4(&client_p->connection->ip, &ban->addr, ban->bits))
601                return 1;
602            break;
592 #ifdef IPV6
603          case HM_IPV6:
604 <          if (who->localClient->aftype == AF_INET6)
605 <            if (match_ipv6(&who->localClient->ip, &bp->addr, bp->bits))
604 >          if (client_p->connection->aftype == AF_INET6)
605 >            if (match_ipv6(&client_p->connection->ip, &ban->addr, ban->bits))
606                return 1;
607            break;
598 #endif
608          default:
609            assert(0);
610        }
# Line 606 | Line 615 | find_bmask(const struct Client *who, con
615   }
616  
617   /*!
618 < * \param chptr Pointer to channel block
619 < * \param who   Pointer to client to check access fo
618 > * \param chptr    Pointer to channel block
619 > * \param client_p Pointer to client to check access fo
620   * \return 0 if not banned, 1 otherwise
621   */
622   int
623 < is_banned(const struct Channel *chptr, const struct Client *who)
623 > is_banned(const struct Channel *chptr, const struct Client *client_p)
624   {
625 <  if (find_bmask(who, &chptr->banlist))
626 <    if (!find_bmask(who, &chptr->exceptlist))
625 >  if (find_bmask(client_p, &chptr->banlist))
626 >    if (!find_bmask(client_p, &chptr->exceptlist))
627        return 1;
628  
629    return 0;
630   }
631  
632   /*! Tests if a client can join a certain channel
633 < * \param source_p Pointer to client attempting to join
633 > * \param client_p Pointer to client attempting to join
634   * \param chptr    Pointer to channel
635   * \param key      Key sent by client attempting to join if present
636   * \return ERR_BANNEDFROMCHAN, ERR_INVITEONLYCHAN, ERR_CHANNELISFULL
637   *         or 0 if allowed to join.
638   */
639 < int
640 < can_join(struct Client *source_p, struct Channel *chptr, const char *key)
639 > static int
640 > can_join(struct Client *client_p, const struct Channel *chptr, const char *key)
641   {
642 <  if ((chptr->mode.mode & MODE_SSLONLY) && !HasUMode(source_p, UMODE_SSL))
642 >  if ((chptr->mode.mode & MODE_SSLONLY) && !HasUMode(client_p, UMODE_SSL))
643      return ERR_SSLONLYCHAN;
644  
645 <  if ((chptr->mode.mode & MODE_REGONLY) && !HasUMode(source_p, UMODE_REGISTERED))
645 >  if ((chptr->mode.mode & MODE_REGONLY) && !HasUMode(client_p, UMODE_REGISTERED))
646      return ERR_NEEDREGGEDNICK;
647  
648 <  if ((chptr->mode.mode & MODE_OPERONLY) && !HasUMode(source_p, UMODE_OPER))
648 >  if ((chptr->mode.mode & MODE_OPERONLY) && !HasUMode(client_p, UMODE_OPER))
649      return ERR_OPERONLYCHAN;
650  
651    if (chptr->mode.mode & MODE_INVITEONLY)
652 <    if (!dlinkFind(&source_p->localClient->invited, chptr))
653 <      if (!find_bmask(source_p, &chptr->invexlist))
652 >    if (!dlinkFind(&client_p->connection->invited, chptr))
653 >      if (!find_bmask(client_p, &chptr->invexlist))
654          return ERR_INVITEONLYCHAN;
655  
656    if (chptr->mode.key[0] && (!key || strcmp(chptr->mode.key, key)))
# Line 651 | Line 660 | can_join(struct Client *source_p, struct
660        chptr->mode.limit)
661      return ERR_CHANNELISFULL;
662  
663 <  if (is_banned(chptr, source_p))
663 >  if (is_banned(chptr, client_p))
664      return ERR_BANNEDFROMCHAN;
665  
666    return 0;
667   }
668  
669   int
670 < has_member_flags(const struct Membership *ms, const unsigned int flags)
670 > has_member_flags(const struct Membership *member, const unsigned int flags)
671   {
672 <  return ms && (ms->flags & flags);
672 >  return member && (member->flags & flags);
673   }
674  
675   struct Membership *
676   find_channel_link(struct Client *client_p, struct Channel *chptr)
677   {
678 <  dlink_node *ptr = NULL;
678 >  dlink_node *node = NULL;
679  
680    if (!IsClient(client_p))
681      return NULL;
682  
683    if (dlink_list_length(&chptr->members) < dlink_list_length(&client_p->channel))
684    {
685 <    DLINK_FOREACH(ptr, chptr->members.head)
686 <      if (((struct Membership *)ptr->data)->client_p == client_p)
687 <        return ptr->data;
685 >    DLINK_FOREACH(node, chptr->members.head)
686 >      if (((struct Membership *)node->data)->client_p == client_p)
687 >        return node->data;
688    }
689    else
690    {
691 <    DLINK_FOREACH(ptr, client_p->channel.head)
692 <      if (((struct Membership *)ptr->data)->chptr == chptr)
693 <        return ptr->data;
691 >    DLINK_FOREACH(node, client_p->channel.head)
692 >      if (((struct Membership *)node->data)->chptr == chptr)
693 >        return node->data;
694    }
695  
696    return NULL;
697   }
698  
699 < /*! Tests if a client can send to a channel
699 > /*! Checks if a message contains control codes
700   * \param message The actual message string the client wants to send
701   * \return 1 if the message does contain any control codes, 0 otherwise
702   */
# Line 715 | Line 724 | msg_has_ctrls(const char *message)
724      return 1;  /* Control code */
725    }
726  
727 <  return 0;
727 >  return 0;  /* No control code found */
728   }
729  
730   /*! Tests if a client can send to a channel
731   * \param chptr    Pointer to Channel struct
732 < * \param source_p Pointer to Client struct
733 < * \param ms       Pointer to Membership struct (can be NULL)
732 > * \param client_p Pointer to Client struct
733 > * \param member   Pointer to Membership struct (can be NULL)
734   * \param message  The actual message string the client wants to send
735   * \return CAN_SEND_OPV if op or voiced on channel\n
736   *         CAN_SEND_NONOP if can send to channel but is not an op\n
737   *         ERR_CANNOTSENDTOCHAN or ERR_NEEDREGGEDNICK if they cannot send to channel\n
738   */
739   int
740 < can_send(struct Channel *chptr, struct Client *source_p,
741 <         struct Membership *ms, const char *message)
740 > can_send(struct Channel *chptr, struct Client *client_p,
741 >         struct Membership *member, const char *message, int notice)
742   {
743 <  struct MaskItem *conf = NULL;
743 >  const struct MaskItem *conf = NULL;
744  
745 <  if (IsServer(source_p) || HasFlag(source_p, FLAGS_SERVICE))
745 >  if (IsServer(client_p) || HasFlag(client_p, FLAGS_SERVICE))
746      return CAN_SEND_OPV;
747  
748 <  if (MyClient(source_p) && !IsExemptResv(source_p))
749 <    if (!(HasUMode(source_p, UMODE_OPER) && ConfigFileEntry.oper_pass_resv))
750 <      if ((conf = match_find_resv(chptr->chname)) && !resv_find_exempt(source_p, conf))
748 >  if (MyConnect(client_p) && !HasFlag(client_p, FLAGS_EXEMPTRESV))
749 >    if (!(HasUMode(client_p, UMODE_OPER) && HasOFlag(client_p, OPER_FLAG_JOIN_RESV)))
750 >      if ((conf = match_find_resv(chptr->name)) && !resv_find_exempt(client_p, conf))
751          return ERR_CANNOTSENDTOCHAN;
752  
753    if ((chptr->mode.mode & MODE_NOCTRL) && msg_has_ctrls(message))
754      return ERR_NOCTRLSONCHAN;
755 <  if (ms || (ms = find_channel_link(source_p, chptr)))
756 <    if (ms->flags & (CHFL_CHANOP|CHFL_HALFOP|CHFL_VOICE))
755 >
756 >  if (chptr->mode.mode & MODE_NOCTCP)
757 >    if (*message == '\001' && strncmp(message + 1, "ACTION ", 7))
758 >      return ERR_NOCTCP;
759 >
760 >  if (member || (member = find_channel_link(client_p, chptr)))
761 >    if (member->flags & (CHFL_CHANOP | CHFL_HALFOP | CHFL_VOICE))
762        return CAN_SEND_OPV;
763 <  if (!ms && (chptr->mode.mode & MODE_NOPRIVMSGS))
763 >
764 >  if (!member && (chptr->mode.mode & MODE_NOPRIVMSGS))
765      return ERR_CANNOTSENDTOCHAN;
766 +
767    if (chptr->mode.mode & MODE_MODERATED)
768      return ERR_CANNOTSENDTOCHAN;
769 <  if ((chptr->mode.mode & MODE_MODREG) && !HasUMode(source_p, UMODE_REGISTERED))
769 >
770 >  if ((chptr->mode.mode & MODE_MODREG) && !HasUMode(client_p, UMODE_REGISTERED))
771      return ERR_NEEDREGGEDNICK;
772  
773 +  if ((chptr->mode.mode & MODE_NONOTICE) && notice)
774 +    return ERR_CANNOTSENDTOCHAN;
775 +
776    /* Cache can send if banned */
777 <  if (MyClient(source_p))
777 >  if (MyConnect(client_p))
778    {
779 <    if (ms)
779 >    if (member)
780      {
781 <      if (ms->flags & CHFL_BAN_SILENCED)
781 >      if (member->flags & CHFL_BAN_SILENCED)
782          return ERR_CANNOTSENDTOCHAN;
783  
784 <      if (!(ms->flags & CHFL_BAN_CHECKED))
784 >      if (!(member->flags & CHFL_BAN_CHECKED))
785        {
786 <        if (is_banned(chptr, source_p))
786 >        if (is_banned(chptr, client_p))
787          {
788 <          ms->flags |= (CHFL_BAN_CHECKED|CHFL_BAN_SILENCED);
788 >          member->flags |= (CHFL_BAN_CHECKED | CHFL_BAN_SILENCED);
789            return ERR_CANNOTSENDTOCHAN;
790          }
791  
792 <        ms->flags |= CHFL_BAN_CHECKED;
792 >        member->flags |= CHFL_BAN_CHECKED;
793        }
794      }
795 <    else if (is_banned(chptr, source_p))
795 >    else if (is_banned(chptr, client_p))
796        return ERR_CANNOTSENDTOCHAN;
797    }
798  
# Line 782 | Line 802 | can_send(struct Channel *chptr, struct C
802   /*! \brief Updates the client's oper_warn_count_down, warns the
803   *         IRC operators if necessary, and updates
804   *         join_leave_countdown as needed.
805 < * \param source_p Pointer to struct Client to check
805 > * \param client_p Pointer to struct Client to check
806   * \param name     Channel name or NULL if this is a part.
807   */
808   void
809 < check_spambot_warning(struct Client *source_p, const char *name)
809 > check_spambot_warning(struct Client *client_p, const char *name)
810   {
811    int t_delta = 0;
812    int decrement_count = 0;
813  
814    if ((GlobalSetOptions.spam_num &&
815 <       (source_p->localClient->join_leave_count >=
815 >       (client_p->connection->join_leave_count >=
816          GlobalSetOptions.spam_num)))
817    {
818 <    if (source_p->localClient->oper_warn_count_down > 0)
819 <      source_p->localClient->oper_warn_count_down--;
818 >    if (client_p->connection->oper_warn_count_down > 0)
819 >      client_p->connection->oper_warn_count_down--;
820      else
821 <      source_p->localClient->oper_warn_count_down = 0;
821 >      client_p->connection->oper_warn_count_down = 0;
822  
823 <    if (source_p->localClient->oper_warn_count_down == 0)
823 >    if (client_p->connection->oper_warn_count_down == 0)
824      {
825        /* It's already known as a possible spambot */
826        if (name)
827          sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE,
828                               "User %s (%s@%s) trying to join %s is a possible spambot",
829 <                             source_p->name, source_p->username,
830 <                             source_p->host, name);
829 >                             client_p->name, client_p->username,
830 >                             client_p->host, name);
831        else
832          sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE,
833                               "User %s (%s@%s) is a possible spambot",
834 <                             source_p->name, source_p->username,
835 <                             source_p->host);
836 <      source_p->localClient->oper_warn_count_down = OPER_SPAM_COUNTDOWN;
834 >                             client_p->name, client_p->username,
835 >                             client_p->host);
836 >      client_p->connection->oper_warn_count_down = OPER_SPAM_COUNTDOWN;
837      }
838    }
839    else
840    {
841 <    if ((t_delta = (CurrentTime - source_p->localClient->last_leave_time)) >
841 >    if ((t_delta = (CurrentTime - client_p->connection->last_leave_time)) >
842           JOIN_LEAVE_COUNT_EXPIRE_TIME)
843      {
844        decrement_count = (t_delta / JOIN_LEAVE_COUNT_EXPIRE_TIME);
845 <      if (decrement_count > source_p->localClient->join_leave_count)
846 <        source_p->localClient->join_leave_count = 0;
845 >
846 >      if (decrement_count > client_p->connection->join_leave_count)
847 >        client_p->connection->join_leave_count = 0;
848        else
849 <        source_p->localClient->join_leave_count -= decrement_count;
849 >        client_p->connection->join_leave_count -= decrement_count;
850      }
851      else
852      {
853 <      if ((CurrentTime - (source_p->localClient->last_join_time)) <
853 >      if ((CurrentTime - (client_p->connection->last_join_time)) <
854            GlobalSetOptions.spam_time)
855 <        source_p->localClient->join_leave_count++;  /* It's a possible spambot */
855 >        client_p->connection->join_leave_count++;  /* It's a possible spambot */
856      }
857  
858      if (name)
859 <      source_p->localClient->last_join_time = CurrentTime;
859 >      client_p->connection->last_join_time = CurrentTime;
860      else
861 <      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_serv_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 <    }
861 >      client_p->connection->last_leave_time = CurrentTime;
862    }
863   }
864  
# Line 884 | Line 874 | channel_set_topic(struct Channel *chptr,
874                    const char *topic_info, time_t topicts, int local)
875   {
876    if (local)
877 <    strlcpy(chptr->topic, topic, IRCD_MIN(sizeof(chptr->topic), ServerInfo.max_topic_length + 1));
877 >    strlcpy(chptr->topic, topic, IRCD_MIN(sizeof(chptr->topic), ConfigServerInfo.max_topic_length + 1));
878    else
879      strlcpy(chptr->topic, topic, sizeof(chptr->topic));
880  
# Line 902 | Line 892 | channel_set_topic(struct Channel *chptr,
892   *                anti spambot code.
893   */
894   void
895 < channel_do_join_0(struct Client *source_p)
895 > channel_do_join_0(struct Client *client_p)
896   {
897 <  dlink_node *ptr = NULL, *ptr_next = NULL;
897 >  dlink_node *node = NULL, *node_next = NULL;
898  
899 <  if (source_p->channel.head)
900 <    if (MyConnect(source_p) && !HasUMode(source_p, UMODE_OPER))
901 <      check_spambot_warning(source_p, NULL);
899 >  if (client_p->channel.head)
900 >    if (MyConnect(client_p) && !HasUMode(client_p, UMODE_OPER))
901 >      check_spambot_warning(client_p, NULL);
902  
903 <  DLINK_FOREACH_SAFE(ptr, ptr_next, source_p->channel.head)
903 >  DLINK_FOREACH_SAFE(node, node_next, client_p->channel.head)
904    {
905 <    struct Channel *chptr = ((struct Membership *)ptr->data)->chptr;
905 >    struct Channel *chptr = ((struct Membership *)node->data)->chptr;
906  
907 <    sendto_server(source_p, NOCAPS, NOCAPS, ":%s PART %s",
908 <                  source_p->id, chptr->chname);
909 <    sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s!%s@%s PART %s",
910 <                         source_p->name, source_p->username,
911 <                         source_p->host, chptr->chname);
907 >    sendto_server(client_p, 0, 0, ":%s PART %s",
908 >                  client_p->id, chptr->name);
909 >    sendto_channel_local(NULL, chptr, 0, 0, 0, ":%s!%s@%s PART %s",
910 >                         client_p->name, client_p->username,
911 >                         client_p->host, chptr->name);
912  
913 <    remove_user_from_channel(ptr->data);
913 >    remove_user_from_channel(node->data);
914    }
915   }
916  
917   static char *
918 < channel_find_last0(struct Client *source_p, char *chanlist)
918 > channel_find_last0(struct Client *client_p, char *chanlist)
919   {
920    int join0 = 0;
921  
# Line 933 | Line 923 | channel_find_last0(struct Client *source
923    {
924      if (*p == '0' && (*(p + 1) == ',' || *(p + 1) == '\0'))
925      {
926 <      if ((*p + 1) == ',')
926 >      if (*(p + 1) == ',')
927          ++p;
928  
929        chanlist = p + 1;
# Line 950 | Line 940 | channel_find_last0(struct Client *source
940    }
941  
942    if (join0)
943 <    channel_do_join_0(source_p);
943 >    channel_do_join_0(client_p);
944  
945    return chanlist;
946   }
947  
948   void
949 < channel_do_join(struct Client *source_p, char *channel, char *key_list)
949 > channel_do_join(struct Client *client_p, char *channel, char *key_list)
950   {
951    char *p = NULL;
952    char *chan = NULL;
953    char *chan_list = NULL;
954    struct Channel *chptr = NULL;
955    struct MaskItem *conf = NULL;
956 <  const struct ClassItem *class = get_class_ptr(&source_p->localClient->confs);
956 >  const struct ClassItem *const class = get_class_ptr(&client_p->connection->confs);
957    int i = 0;
958    unsigned int flags = 0;
959  
960 <  chan_list = channel_find_last0(source_p, channel);
960 >  assert(IsClient(client_p));
961  
962 <  for (chan = strtoken(&p, chan_list, ","); chan;
963 <       chan = strtoken(&p,      NULL, ","))
962 >  chan_list = channel_find_last0(client_p, channel);
963 >
964 >  for (chan = strtok_r(chan_list, ",", &p); chan;
965 >       chan = strtok_r(NULL,      ",", &p))
966    {
967      const char *key = NULL;
968  
# Line 982 | Line 974 | channel_do_join(struct Client *source_p,
974      if (key && *key == '\0')
975        key = NULL;
976  
977 <    if (!check_channel_name(chan, 1))
977 >    if (!channel_check_name(chan, 1))
978      {
979 <      sendto_one_numeric(source_p, &me, ERR_BADCHANNAME, chan);
979 >      sendto_one_numeric(client_p, &me, ERR_BADCHANNAME, chan);
980        continue;
981      }
982  
983 <    if (!IsExemptResv(source_p) &&
984 <        !(HasUMode(source_p, UMODE_OPER) && ConfigFileEntry.oper_pass_resv) &&
985 <        ((conf = match_find_resv(chan)) && !resv_find_exempt(source_p, conf)))
983 >    if (!HasFlag(client_p, FLAGS_EXEMPTRESV) &&
984 >        !(HasUMode(client_p, UMODE_OPER) && HasOFlag(client_p, OPER_FLAG_JOIN_RESV)) &&
985 >        ((conf = match_find_resv(chan)) && !resv_find_exempt(client_p, conf)))
986      {
987        ++conf->count;
988 <      sendto_one_numeric(source_p, &me, ERR_CHANBANREASON,
997 <                         chan, conf->reason ? conf->reason : "Reserved channel");
988 >      sendto_one_numeric(client_p, &me, ERR_CHANBANREASON, chan, conf->reason);
989        sendto_realops_flags(UMODE_REJ, L_ALL, SEND_NOTICE,
990                             "Forbidding reserved channel %s from user %s",
991 <                           chan, get_client_name(source_p, HIDE_IP));
991 >                           chan, get_client_name(client_p, HIDE_IP));
992        continue;
993      }
994  
995 <    if (dlink_list_length(&source_p->channel) >=
995 >    if (dlink_list_length(&client_p->channel) >=
996          ((class->max_channels) ? class->max_channels : ConfigChannel.max_channels))
997      {
998 <      sendto_one_numeric(source_p, &me, ERR_TOOMANYCHANNELS, chan);
998 >      sendto_one_numeric(client_p, &me, ERR_TOOMANYCHANNELS, chan);
999        break;
1000      }
1001  
1002      if ((chptr = hash_find_channel(chan)))
1003      {
1004 <      if (IsMember(source_p, chptr))
1004 >      if (IsMember(client_p, chptr))
1005          continue;
1006  
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);
1020        continue;
1021      }
1022
1007        /*
1008         * can_join checks for +i key, bans.
1009         */
1010 <      if ((i = can_join(source_p, chptr, key)))
1010 >      if ((i = can_join(client_p, chptr, key)))
1011        {
1012 <        sendto_one_numeric(source_p, &me, i, chptr->chname);
1012 >        sendto_one_numeric(client_p, &me, i, chptr->name);
1013          continue;
1014        }
1015  
# Line 1033 | Line 1017 | channel_do_join(struct Client *source_p,
1017         * This should never be the case unless there is some sort of
1018         * persistant channels.
1019         */
1020 <      if (dlink_list_length(&chptr->members) == 0)
1020 >      if (!dlink_list_length(&chptr->members))
1021          flags = CHFL_CHANOP;
1022        else
1023          flags = 0;
1024      }
1025      else
1026      {
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
1027        flags = CHFL_CHANOP;
1028 <      chptr = make_channel(chan);
1028 >      chptr = channel_make(chan);
1029      }
1030  
1031 <    if (!HasUMode(source_p, UMODE_OPER))
1032 <      check_spambot_warning(source_p, chptr->chname);
1031 >    if (!HasUMode(client_p, UMODE_OPER))
1032 >      check_spambot_warning(client_p, chptr->name);
1033  
1034 <    add_user_to_channel(chptr, source_p, flags, 1);
1034 >    add_user_to_channel(chptr, client_p, flags, 1);
1035  
1036      /*
1037 <     *  Set timestamp if appropriate, and propagate
1037 >     * Set timestamp if appropriate, and propagate
1038       */
1039      if (flags == CHFL_CHANOP)
1040      {
1041 <      chptr->channelts = CurrentTime;
1041 >      chptr->creationtime = CurrentTime;
1042        chptr->mode.mode |= MODE_TOPICLIMIT;
1043        chptr->mode.mode |= MODE_NOPRIVMSGS;
1044  
1045 <      sendto_server(source_p, NOCAPS, NOCAPS, ":%s SJOIN %lu %s +nt :@%s",
1046 <                    me.id, (unsigned long)chptr->channelts,
1047 <                    chptr->chname, source_p->id);
1045 >      sendto_server(client_p, 0, 0, ":%s SJOIN %ju %s +nt :@%s",
1046 >                    me.id, chptr->creationtime,
1047 >                    chptr->name, client_p->id);
1048  
1049        /*
1050         * Notify all other users on the new channel
1051         */
1052 <      sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s!%s@%s JOIN :%s",
1053 <                           source_p->name, source_p->username,
1054 <                           source_p->host, chptr->chname);
1055 <      sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s MODE %s +nt",
1056 <                           me.name, chptr->chname);
1057 <
1058 <      if (source_p->away[0])
1059 <        sendto_channel_local_butone(source_p, 0, CAP_AWAY_NOTIFY, chptr,
1060 <                                    ":%s!%s@%s AWAY :%s",
1061 <                                    source_p->name, source_p->username,
1062 <                                    source_p->host, source_p->away);
1052 >      sendto_channel_local(NULL, chptr, 0, CAP_EXTENDED_JOIN, 0, ":%s!%s@%s JOIN %s %s :%s",
1053 >                           client_p->name, client_p->username,
1054 >                           client_p->host, chptr->name, client_p->account, client_p->info);
1055 >      sendto_channel_local(NULL, chptr, 0, 0, CAP_EXTENDED_JOIN, ":%s!%s@%s JOIN :%s",
1056 >                           client_p->name, client_p->username,
1057 >                           client_p->host, chptr->name);
1058 >      sendto_channel_local(NULL, chptr, 0, 0, 0, ":%s MODE %s +nt",
1059 >                           me.name, chptr->name);
1060 >
1061 >      if (client_p->away[0])
1062 >        sendto_channel_local(client_p, chptr, 0, CAP_AWAY_NOTIFY, 0,
1063 >                             ":%s!%s@%s AWAY :%s",
1064 >                             client_p->name, client_p->username,
1065 >                             client_p->host, client_p->away);
1066      }
1067      else
1068      {
1069 <      sendto_server(source_p, NOCAPS, NOCAPS, ":%s JOIN %lu %s +",
1070 <                    source_p->id, (unsigned long)chptr->channelts,
1071 <                    chptr->chname);
1072 <      sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s!%s@%s JOIN :%s",
1073 <                           source_p->name, source_p->username,
1074 <                           source_p->host, chptr->chname);
1075 <
1076 <      if (source_p->away[0])
1077 <        sendto_channel_local_butone(source_p, 0, CAP_AWAY_NOTIFY, chptr,
1078 <                                    ":%s!%s@%s AWAY :%s",
1079 <                                    source_p->name, source_p->username,
1080 <                                    source_p->host, source_p->away);
1069 >      sendto_server(client_p, 0, 0, ":%s JOIN %ju %s +",
1070 >                    client_p->id, chptr->creationtime,
1071 >                    chptr->name);
1072 >
1073 >      sendto_channel_local(NULL, chptr, 0, CAP_EXTENDED_JOIN, 0, ":%s!%s@%s JOIN %s %s :%s",
1074 >                           client_p->name, client_p->username,
1075 >                           client_p->host, chptr->name, client_p->account, client_p->info);
1076 >      sendto_channel_local(NULL, chptr, 0, 0, CAP_EXTENDED_JOIN, ":%s!%s@%s JOIN :%s",
1077 >                           client_p->name, client_p->username,
1078 >                           client_p->host, chptr->name);
1079 >
1080 >      if (client_p->away[0])
1081 >        sendto_channel_local(client_p, chptr, 0, CAP_AWAY_NOTIFY, 0,
1082 >                             ":%s!%s@%s AWAY :%s",
1083 >                             client_p->name, client_p->username,
1084 >                             client_p->host, client_p->away);
1085      }
1086  
1087 <    del_invite(chptr, source_p);
1087 >    del_invite(chptr, client_p);
1088  
1089      if (chptr->topic[0])
1090      {
1091 <      sendto_one_numeric(source_p, &me, RPL_TOPIC, chptr->chname, chptr->topic);
1092 <      sendto_one_numeric(source_p, &me, RPL_TOPICWHOTIME, chptr->chname,
1091 >      sendto_one_numeric(client_p, &me, RPL_TOPIC, chptr->name, chptr->topic);
1092 >      sendto_one_numeric(client_p, &me, RPL_TOPICWHOTIME, chptr->name,
1093                           chptr->topic_info, chptr->topic_time);
1094      }
1095  
1096 <    channel_member_names(source_p, chptr, 1);
1096 >    channel_member_names(client_p, chptr, 1);
1097  
1098 <    source_p->localClient->last_join_time = CurrentTime;
1098 >    client_p->connection->last_join_time = CurrentTime;
1099    }
1100   }
1101  
1102   /*! \brief Removes a client from a specific channel
1103 < * \param source_p Pointer to source client to remove
1103 > * \param client_p Pointer to source client to remove
1104   * \param name     Name of channel to remove from
1105   * \param reason   Part reason to show
1106   */
1107   static void
1108 < channel_part_one_client(struct Client *source_p, const char *name, const char *reason)
1108 > channel_part_one_client(struct Client *client_p, const char *name, const char *reason)
1109   {
1110    struct Channel *chptr = NULL;
1111 <  struct Membership *ms = NULL;
1111 >  struct Membership *member = NULL;
1112  
1113    if ((chptr = hash_find_channel(name)) == NULL)
1114    {
1115 <    sendto_one_numeric(source_p, &me, ERR_NOSUCHCHANNEL, name);
1115 >    sendto_one_numeric(client_p, &me, ERR_NOSUCHCHANNEL, name);
1116      return;
1117    }
1118  
1119 <  if ((ms = find_channel_link(source_p, chptr)) == NULL)
1119 >  if ((member = find_channel_link(client_p, chptr)) == NULL)
1120    {
1121 <    sendto_one_numeric(source_p, &me, ERR_NOTONCHANNEL, chptr->chname);
1121 >    sendto_one_numeric(client_p, &me, ERR_NOTONCHANNEL, chptr->name);
1122      return;
1123    }
1124  
1125 <  if (MyConnect(source_p) && !HasUMode(source_p, UMODE_OPER))
1126 <    check_spambot_warning(source_p, NULL);
1125 >  if (MyConnect(client_p) && !HasUMode(client_p, UMODE_OPER))
1126 >    check_spambot_warning(client_p, NULL);
1127  
1128    /*
1129     * Remove user from the old channel (if any)
1130     * only allow /part reasons in -m chans
1131     */
1132 <  if (*reason && (!MyConnect(source_p) ||
1133 <      ((can_send(chptr, source_p, ms, reason) &&
1134 <       (source_p->localClient->firsttime + ConfigFileEntry.anti_spam_exit_message_time)
1135 <        < CurrentTime))))
1136 <  {
1137 <    sendto_server(source_p, NOCAPS, NOCAPS, ":%s PART %s :%s",
1138 <                  source_p->id, chptr->chname, reason);
1139 <    sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s!%s@%s PART %s :%s",
1140 <                         source_p->name, source_p->username,
1141 <                         source_p->host, chptr->chname, reason);
1132 >  if (*reason && (!MyConnect(client_p) ||
1133 >      ((client_p->connection->firsttime +
1134 >        ConfigGeneral.anti_spam_exit_message_time) < CurrentTime &&
1135 >       can_send(chptr, client_p, member, reason, 0) < 0)))
1136 >  {
1137 >    sendto_server(client_p, 0, 0, ":%s PART %s :%s",
1138 >                  client_p->id, chptr->name, reason);
1139 >    sendto_channel_local(NULL, chptr, 0, 0, 0, ":%s!%s@%s PART %s :%s",
1140 >                         client_p->name, client_p->username,
1141 >                         client_p->host, chptr->name, reason);
1142    }
1143    else
1144    {
1145 <    sendto_server(source_p, NOCAPS, NOCAPS, ":%s PART %s",
1146 <                  source_p->id, chptr->chname);
1147 <    sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s!%s@%s PART %s",
1148 <                         source_p->name, source_p->username,
1149 <                         source_p->host, chptr->chname);
1145 >    sendto_server(client_p, 0, 0, ":%s PART %s",
1146 >                  client_p->id, chptr->name);
1147 >    sendto_channel_local(NULL, chptr, 0, 0, 0, ":%s!%s@%s PART %s",
1148 >                         client_p->name, client_p->username,
1149 >                         client_p->host, chptr->name);
1150    }
1151  
1152 <  remove_user_from_channel(ms);
1152 >  remove_user_from_channel(member);
1153   }
1154  
1155   void
1156 < channel_do_part(struct Client *source_p, char *channel, char *reason)
1156 > channel_do_part(struct Client *client_p, char *channel, const char *reason)
1157   {
1158    char *p = NULL, *name = NULL;
1159 <  char reasonbuf[KICKLEN + 1] = "";
1159 >  char buf[KICKLEN + 1] = "";
1160 >
1161 >  assert(IsClient(client_p));
1162  
1163    if (!EmptyString(reason))
1164 <    strlcpy(reasonbuf, reason, sizeof(reasonbuf));
1164 >    strlcpy(buf, reason, sizeof(buf));
1165  
1166 <  for (name = strtoken(&p, channel, ","); name;
1167 <       name = strtoken(&p,    NULL, ","))
1168 <    channel_part_one_client(source_p, name, reasonbuf);
1166 >  for (name = strtok_r(channel, ",", &p); name;
1167 >       name = strtok_r(NULL,    ",", &p))
1168 >    channel_part_one_client(client_p, name, buf);
1169   }

Diff Legend

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