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

Diff Legend

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