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-7.2/src/channel.c (file contents), Revision 356 by adx, Mon Jan 2 22:05:15 2006 UTC vs.
ircd-hybrid/trunk/src/channel.c (file contents), Revision 3215 by michael, Tue Mar 25 19:23:15 2014 UTC

# Line 1 | Line 1
1   /*
2 < *  ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
2 > *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Copyright (C) 2002 by the past and present ircd coders, and others.
4 > *  Copyright (c) 1997-2014 ircd-hybrid development team
5   *
6   *  This program is free software; you can redistribute it and/or modify
7   *  it under the terms of the GNU General Public License as published by
# Line 25 | Line 25
25   */
26  
27   #include "stdinc.h"
28 < #include "tools.h"
28 > #include "list.h"
29   #include "channel.h"
30   #include "channel_mode.h"
31   #include "client.h"
32 #include "common.h"
32   #include "hash.h"
33 + #include "conf.h"
34 + #include "hostmask.h"
35   #include "irc_string.h"
35 #include "sprintf_irc.h"
36   #include "ircd.h"
37 #include "list.h"
37   #include "numeric.h"
38 < #include "s_serv.h"             /* captab */
40 < #include "s_user.h"
38 > #include "s_serv.h"
39   #include "send.h"
42 #include "s_conf.h"             /* ConfigFileEntry, ConfigChannel */
40   #include "event.h"
41   #include "memory.h"
42 < #include "balloc.h"
42 > #include "mempool.h"
43 > #include "s_misc.h"
44 > #include "resv.h"
45  
47 struct config_channel_entry ConfigChannel;
46   dlink_list global_channel_list = { NULL, NULL, 0 };
47 < dlink_list lazylink_channels = { NULL, NULL, 0 };
50 < BlockHeap *ban_heap;    /*! \todo ban_heap shouldn't be a global var */
47 > mp_pool_t *ban_pool;    /*! \todo ban_pool shouldn't be a global var */
48  
49 < static BlockHeap *topic_heap = NULL;
50 < static BlockHeap *member_heap = NULL;
54 < static BlockHeap *channel_heap = NULL;
49 > static mp_pool_t *member_pool = NULL;
50 > static mp_pool_t *channel_pool = NULL;
51  
52   static char buf[IRCD_BUFSIZE];
57 static char modebuf[MODEBUFLEN];
58 static char parabuf[MODEBUFLEN];
53  
54  
55   /*! \brief Initializes the channel blockheap, adds known channel CAPAB
56   */
57   void
58 < init_channels(void)
58 > channel_init(void)
59   {
66  /*
67   * XXX - These should get moved to somwhere else once we have
68   * a modular channelmode system
69   */
60    add_capability("EX", CAP_EX, 1);
61    add_capability("IE", CAP_IE, 1);
72  add_capability("CHW", CAP_CHW, 1);
62  
63 <  channel_heap = BlockHeapCreate("channel", sizeof(struct Channel), CHANNEL_HEAP_SIZE);
64 <  ban_heap = BlockHeapCreate("ban", sizeof(struct Ban), BAN_HEAP_SIZE);
65 <  topic_heap = BlockHeapCreate("topic", TOPICLEN+1 + USERHOST_REPLYLEN, TOPIC_HEAP_SIZE);
77 <  member_heap = BlockHeapCreate("member", sizeof(struct Membership), CHANNEL_HEAP_SIZE*2);
63 >  channel_pool = mp_pool_new(sizeof(struct Channel), MP_CHUNK_SIZE_CHANNEL);
64 >  ban_pool = mp_pool_new(sizeof(struct Ban), MP_CHUNK_SIZE_BAN);
65 >  member_pool = mp_pool_new(sizeof(struct Membership), MP_CHUNK_SIZE_MEMBER);
66   }
67  
68   /*! \brief adds a user to a channel by adding another link to the
# Line 111 | Line 99 | add_user_to_channel(struct Channel *chpt
99        if (!IsSetJoinFloodNoticed(chptr))
100        {
101          SetJoinFloodNoticed(chptr);
102 <        sendto_realops_flags(UMODE_BOTS, L_ALL,
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);
# Line 121 | Line 109 | add_user_to_channel(struct Channel *chpt
109      chptr->last_join_time = CurrentTime;
110    }
111  
112 <  ms = BlockHeapAlloc(member_heap);
112 >  ms = mp_pool_get(member_pool);
113 >  memset(ms, 0, sizeof(*ms));
114 >
115    ms->client_p = who;
116    ms->chptr = chptr;
117    ms->flags = flags;
118  
119    dlinkAdd(ms, &ms->channode, &chptr->members);
130
131  if (MyConnect(who))
132    dlinkAdd(ms, &ms->locchannode, &chptr->locmembers);
133
120    dlinkAdd(ms, &ms->usernode, &who->channel);
121   }
122  
# Line 145 | Line 131 | remove_user_from_channel(struct Membersh
131    struct Channel *chptr = member->chptr;
132  
133    dlinkDelete(&member->channode, &chptr->members);
148
149  if (MyConnect(client_p))
150    dlinkDelete(&member->locchannode, &chptr->locmembers);
151
134    dlinkDelete(&member->usernode, &client_p->channel);
135  
136 <  BlockHeapFree(member_heap, member);
136 >  mp_pool_release(member);
137  
138 <  if (dlink_list_length(&chptr->members) == 0)
157 <  {
158 <    assert(dlink_list_length(&chptr->locmembers) == 0);
138 >  if (chptr->members.head == NULL)
139      destroy_channel(chptr);
160  }
140   }
141  
142   /* send_members()
# Line 168 | Line 147 | remove_user_from_channel(struct Membersh
147   */
148   static void
149   send_members(struct Client *client_p, struct Channel *chptr,
150 <             char *lmodebuf, char *lparabuf)
150 >             char *modebuf, char *parabuf)
151   {
152 <  struct Membership *ms;
174 <  dlink_node *ptr;
152 >  const dlink_node *ptr = NULL;
153    int tlen;              /* length of text to append */
154    char *t, *start;       /* temp char pointer */
155  
156 <  start = t = buf + ircsprintf(buf, ":%s SJOIN %lu %s %s %s:",
157 <                               ID_or_name(&me, client_p),
158 <                               (unsigned long)chptr->channelts,
181 <                               chptr->chname, lmodebuf, lparabuf);
156 >  start = t = buf + snprintf(buf, sizeof(buf), ":%s SJOIN %lu %s %s %s:",
157 >                             me.id, (unsigned long)chptr->channelts,
158 >                             chptr->chname, modebuf, parabuf);
159  
160    DLINK_FOREACH(ptr, chptr->members.head)
161    {
162 <    ms = ptr->data;
162 >    const struct Membership *ms = ptr->data;
163  
164 <    tlen = strlen(IsCapable(client_p, CAP_TS6) ?
188 <      ID(ms->client_p) : ms->client_p->name) + 1;  /* nick + space */
164 >    tlen = strlen(ms->client_p->id) + 1;  /* nick + space */
165  
166      if (ms->flags & CHFL_CHANOP)
167        tlen++;
168   #ifdef HALFOPS
169 <    else if (ms->flags & CHFL_HALFOP)
169 >    if (ms->flags & CHFL_HALFOP)
170        tlen++;
171   #endif
172      if (ms->flags & CHFL_VOICE)
# Line 199 | Line 175 | send_members(struct Client *client_p, st
175      /* space will be converted into CR, but we also need space for LF..
176       * That's why we use '- 1' here
177       * -adx */
178 <    if (t + tlen - buf > sizeof(buf) - 1)
178 >    if (t + tlen - buf > IRCD_BUFSIZE - 1)
179      {
180        *(t - 1) = '\0';  /* kill the space and terminate the string */
181        sendto_one(client_p, "%s", buf);
182        t = start;
183      }
184  
185 <    if ((ms->flags & (CHFL_CHANOP | CHFL_HALFOP)))
186 <      *t++ = (!(ms->flags & CHFL_CHANOP) && IsCapable(client_p, CAP_HOPS)) ?
187 <        '%' : '@';
188 <    if ((ms->flags & CHFL_VOICE))
185 >    if (ms->flags & CHFL_CHANOP)
186 >      *t++ = '@';
187 >    if (ms->flags & CHFL_HALFOP)
188 >      *t++ = '%';
189 >    if (ms->flags & CHFL_VOICE)
190        *t++ = '+';
191  
192 <    if (IsCapable(client_p, CAP_TS6))
193 <      strcpy(t, ID(ms->client_p));
217 <    else
218 <      strcpy(t, ms->client_p->name);
192 >    strcpy(t, ms->client_p->id);
193 >
194      t += strlen(t);
195      *t++ = ' ';
196    }
# Line 235 | Line 210 | send_members(struct Client *client_p, st
210   */
211   static void
212   send_mode_list(struct Client *client_p, struct Channel *chptr,
213 <               dlink_list *top, char flag)
213 >               const dlink_list *top, char flag)
214   {
215 <  int ts5 = !IsCapable(client_p, CAP_TS6);
216 <  dlink_node *lp;
242 <  struct Ban *banptr;
243 <  char pbuf[IRCD_BUFSIZE];
215 >  const dlink_node *lp = NULL;
216 >  char pbuf[IRCD_BUFSIZE] = "";
217    int tlen, mlen, cur_len, count = 0;
218 <  char *mp = NULL, *pp = pbuf;
218 >  char *pp = pbuf;
219  
220 <  if (top == NULL || top->length == 0)
220 >  if (top->length == 0)
221      return;
222  
223 <  if (ts5)
224 <    mlen = ircsprintf(buf, ":%s MODE %s +", me.name, chptr->chname);
225 <  else
253 <    mlen = ircsprintf(buf, ":%s BMASK %lu %s %c :", me.id,
254 <                      (unsigned long)chptr->channelts, chptr->chname, flag);
255 <
256 <  /* MODE needs additional one byte for space between buf and pbuf */
257 <  cur_len = mlen + ts5;
258 <  mp = buf + mlen;
223 >  mlen = snprintf(buf, sizeof(buf), ":%s BMASK %lu %s %c :", me.id,
224 >                  (unsigned long)chptr->channelts, chptr->chname, flag);
225 >  cur_len = mlen;
226  
227    DLINK_FOREACH(lp, top->head)
228    {
229 <    banptr = lp->data;
229 >    const struct Ban *banptr = lp->data;
230  
231 <    /* must add another b/e/I letter if we use MODE */
265 <    tlen = banptr->len + 3 + ts5;
231 >    tlen = banptr->len + 3;
232  
233      /*
234       * send buffer and start over if we cannot fit another ban,
235       * or if the target is non-ts6 and we have too many modes in
236       * in this line.
237       */
238 <    if (cur_len + (tlen - 1) > IRCD_BUFSIZE - 2 ||
273 <        (!IsCapable(client_p, CAP_TS6) &&
274 <         (count >= MAXMODEPARAMS || pp - pbuf >= MODEBUFLEN)))
238 >    if (cur_len + (tlen - 1) > IRCD_BUFSIZE - 2)
239      {
240        *(pp - 1) = '\0';  /* get rid of trailing space on buffer */
241 <      sendto_one(client_p, "%s%s%s", buf, ts5 ? " " : "", pbuf);
241 >      sendto_one(client_p, "%s%s", buf, pbuf);
242  
243 <      cur_len = mlen + ts5;
280 <      mp = buf + mlen;
243 >      cur_len = mlen;
244        pp = pbuf;
245        count = 0;
246      }
247  
248      count++;
249 <    if (ts5)
250 <    {
288 <      *mp++ = flag;
289 <      *mp = '\0';
290 <    }
291 <
292 <    pp += ircsprintf(pp, "%s!%s@%s ", banptr->name, banptr->username,
293 <                     banptr->host);
249 >    pp += sprintf(pp, "%s!%s@%s ", banptr->name, banptr->user,
250 >                  banptr->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%s", buf, ts5 ? " " : "", pbuf);
255 >  sendto_one(client_p, "%s%s", buf, pbuf);
256   }
257  
258   /*! \brief send "client_p" a full list of the modes for channel chptr
# Line 305 | Line 262 | send_mode_list(struct Client *client_p,
262   void
263   send_channel_modes(struct Client *client_p, struct Channel *chptr)
264   {
265 <  if (chptr->chname[0] != '#')
266 <    return;
265 >  char modebuf[MODEBUFLEN] = "";
266 >  char parabuf[MODEBUFLEN] = "";
267  
311  *modebuf = *parabuf = '\0';
268    channel_modes(chptr, client_p, modebuf, parabuf);
269    send_members(client_p, chptr, modebuf, parabuf);
270  
271    send_mode_list(client_p, chptr, &chptr->banlist, 'b');
272 <
273 <  if (IsCapable(client_p, CAP_EX))
318 <    send_mode_list(client_p, chptr, &chptr->exceptlist, 'e');
319 <  if (IsCapable(client_p, CAP_IE))
320 <    send_mode_list(client_p, chptr, &chptr->invexlist, 'I');
272 >  send_mode_list(client_p, chptr, &chptr->exceptlist, 'e');
273 >  send_mode_list(client_p, chptr, &chptr->invexlist, 'I');
274   }
275  
276   /*! \brief check channel name for invalid characters
277   * \param name pointer to channel name string
278 < * \return TRUE (1) if name ok, FALSE (0) otherwise
278 > * \param local indicates whether it's a local or remote creation
279 > * \return 0 if invalid, 1 otherwise
280   */
281   int
282 < check_channel_name(const char *name)
282 > check_channel_name(const char *name, const int local)
283   {
284 <  const unsigned char *p = (const unsigned char *)name;
284 >  const char *p = name;
285 >  const int max_length = local ? LOCAL_CHANNELLEN : CHANNELLEN;
286    assert(name != NULL);
287  
288 <  for (; *p; ++p)
289 <    if (!IsChanChar(*p))
335 <      return 0;
288 >  if (!IsChanPrefix(*p))
289 >    return 0;
290  
291 <  return 1;
291 >  if (!local || !ConfigChannel.disable_fake_channels)
292 >  {
293 >    while (*++p)
294 >      if (!IsChanChar(*p))
295 >        return 0;
296 >  }
297 >  else
298 >  {
299 >    while (*++p)
300 >      if (!IsVisibleChanChar(*p))
301 >        return 0;
302 >  }
303 >
304 >  return p - name <= max_length;
305   }
306  
307   void
# Line 343 | Line 310 | remove_ban(struct Ban *bptr, dlink_list
310    dlinkDelete(&bptr->node, list);
311  
312    MyFree(bptr->name);
313 <  MyFree(bptr->username);
313 >  MyFree(bptr->user);
314    MyFree(bptr->host);
315    MyFree(bptr->who);
316  
317 <  BlockHeapFree(ban_heap, bptr);
317 >  mp_pool_release(bptr);
318   }
319  
320   /* free_channel_list()
# Line 369 | Line 336 | free_channel_list(dlink_list *list)
336  
337   /*! \brief Get Channel block for chname (and allocate a new channel
338   *         block, if it didn't exist before)
339 < * \param client_p client pointer
340 < * \param chname   channel name
374 < * \param isnew    pointer to int flag whether channel was newly created or not
375 < * \return channel block or NULL if illegal name
339 > * \param chname channel name
340 > * \return channel block
341   */
342   struct Channel *
343 < get_or_create_channel(struct Client *client_p, const char *chname, int *isnew)
343 > make_channel(const char *chname)
344   {
345    struct Channel *chptr = NULL;
381  int len;
346  
347 <  if (EmptyString(chname))
384 <    return NULL;
347 >  assert(!EmptyString(chname));
348  
349 <  if ((len = strlen(chname)) > CHANNELLEN)
387 <  {
388 <    if (IsServer(client_p))
389 <      sendto_realops_flags(UMODE_DEBUG, L_ALL,
390 <                           "*** Long channel name from %s (%d > %d): %s",
391 <                           client_p->name, len, CHANNELLEN, chname);
392 <    return NULL;
393 <  }
349 >  chptr = mp_pool_get(channel_pool);
350  
351 <  if ((chptr = hash_find_channel(chname)) != NULL)
396 <  {
397 <    if (isnew != NULL)
398 <      *isnew = 0;
351 >  memset(chptr, 0, sizeof(*chptr));
352  
400    return chptr;
401  }
402
403  if (isnew != NULL)
404    *isnew = 1;
405
406  chptr = BlockHeapAlloc(channel_heap);
353    /* doesn't hurt to set it here */
354 <  chptr->channelts = chptr->last_join_time = CurrentTime;
354 >  chptr->channelts = CurrentTime;
355 >  chptr->last_join_time = CurrentTime;
356  
357    strlcpy(chptr->chname, chname, sizeof(chptr->chname));
358    dlinkAdd(chptr, &chptr->node, &global_channel_list);
# Line 431 | Line 378 | destroy_channel(struct Channel *chptr)
378    free_channel_list(&chptr->exceptlist);
379    free_channel_list(&chptr->invexlist);
380  
434  /* Free the topic */
435  free_topic(chptr);
436
381    dlinkDelete(&chptr->node, &global_channel_list);
382    hash_del_channel(chptr);
383  
384 <  if (ServerInfo.hub)
441 <    if ((ptr = dlinkFindDelete(&lazylink_channels, chptr)))
442 <      free_dlink_node(ptr);
443 <
444 <  BlockHeapFree(channel_heap, chptr);
384 >  mp_pool_release(chptr);
385   }
386  
387   /*!
# Line 449 | Line 389 | destroy_channel(struct Channel *chptr)
389   * \return string pointer "=" if public, "@" if secret else "*"
390   */
391   static const char *
392 < channel_pub_or_secret(struct Channel *chptr)
392 > channel_pub_or_secret(const struct Channel *chptr)
393   {
394    if (SecretChannel(chptr))
395      return "@";
# Line 468 | Line 408 | void
408   channel_member_names(struct Client *source_p, struct Channel *chptr,
409                       int show_eon)
410   {
411 <  struct Client *target_p = NULL;
412 <  struct Membership *ms = NULL;
473 <  dlink_node *ptr = NULL;
474 <  char lbuf[IRCD_BUFSIZE + 1];
411 >  const dlink_node *ptr = NULL;
412 >  char lbuf[IRCD_BUFSIZE + 1] = "";
413    char *t = NULL, *start = NULL;
414    int tlen = 0;
415    int is_member = IsMember(source_p, chptr);
416 +  int multi_prefix = HasCap(source_p, CAP_MULTI_PREFIX) != 0;
417 +  int uhnames = HasCap(source_p, CAP_UHNAMES) != 0;
418  
419    if (PubChannel(chptr) || is_member)
420    {
421 <    t = lbuf + ircsprintf(lbuf, form_str(RPL_NAMREPLY),
422 <                          me.name, source_p->name,
423 <                          channel_pub_or_secret(chptr),
484 <                          chptr->chname);
421 >    t = lbuf + snprintf(lbuf, sizeof(lbuf), numeric_form(RPL_NAMREPLY),
422 >                        me.name, source_p->name,
423 >                        channel_pub_or_secret(chptr), chptr->chname);
424      start = t;
425  
426      DLINK_FOREACH(ptr, chptr->members.head)
427      {
428 <      ms       = ptr->data;
490 <      target_p = ms->client_p;
428 >      const struct Membership *ms = ptr->data;
429  
430 <      if (IsInvisible(target_p) && !is_member)
430 >      if (HasUMode(ms->client_p, UMODE_INVISIBLE) && !is_member)
431          continue;
432  
433 <      tlen = strlen(target_p->name) + 1;  /* nick + space */
433 >      if (!uhnames)
434 >        tlen = strlen(ms->client_p->name) + 1;  /* nick + space */
435 >      else
436 >        tlen = strlen(ms->client_p->name) + strlen(ms->client_p->username) +
437 >               strlen(ms->client_p->host) + 3;
438  
439 <      if (ms->flags & (CHFL_CHANOP | CHFL_HALFOP | CHFL_VOICE))
440 <        ++tlen;
441 <      if (t + tlen - lbuf > IRCD_BUFSIZE)
439 >      if (!multi_prefix)
440 >      {
441 >        if (ms->flags & (CHFL_CHANOP | CHFL_HALFOP | CHFL_VOICE))
442 >          ++tlen;
443 >      }
444 >      else
445 >      {
446 >        if (ms->flags & CHFL_CHANOP)
447 >          ++tlen;
448 >        if (ms->flags & CHFL_HALFOP)
449 >          ++tlen;
450 >        if (ms->flags & CHFL_VOICE)
451 >          ++tlen;
452 >      }
453 >
454 >      if (t + tlen - lbuf > IRCD_BUFSIZE - 2)
455        {
456          *(t - 1) = '\0';
457          sendto_one(source_p, "%s", lbuf);
458          t = start;
459        }
460  
461 <      t += ircsprintf(t, "%s%s ", get_member_status(ms, NO),
462 <                      target_p->name);
461 >      if (!uhnames)
462 >        t += sprintf(t, "%s%s ", get_member_status(ms, multi_prefix),
463 >                     ms->client_p->name);
464 >      else
465 >        t += sprintf(t, "%s%s!%s@%s ", get_member_status(ms, multi_prefix),
466 >                     ms->client_p->name, ms->client_p->username,
467 >                     ms->client_p->host);
468      }
469  
470 <    if (tlen != 0)
470 >    if (tlen)
471      {
472        *(t - 1) = '\0';
473        sendto_one(source_p, "%s", lbuf);
# Line 515 | Line 475 | channel_member_names(struct Client *sour
475    }
476  
477    if (show_eon)
478 <    sendto_one(source_p, form_str(RPL_ENDOFNAMES),
519 <               me.name, source_p->name, chptr->chname);
478 >    sendto_one_numeric(source_p, &me, RPL_ENDOFNAMES, chptr->chname);
479   }
480  
481   /*! \brief adds client to invite list
# Line 571 | Line 530 | del_invite(struct Channel *chptr, struct
530   * (like in get_client_name)
531   */
532   const char *
533 < get_member_status(const struct Membership *ms, int combine)
533 > get_member_status(const struct Membership *ms, const int combine)
534   {
535    static char buffer[4];
536 <  char *p = NULL;
578 <
579 <  if (ms == NULL)
580 <    return "";
581 <  p = buffer;
536 >  char *p = buffer;
537  
538    if (ms->flags & CHFL_CHANOP)
539    {
# Line 618 | Line 573 | find_bmask(const struct Client *who, con
573    {
574      const struct Ban *bp = ptr->data;
575  
576 <    if (match(bp->name, who->name) &&
577 <        match(bp->username, who->username) &&
578 <        (match(bp->host, who->host) ||
579 <         match(bp->host, who->sockhost) ||
580 <         match_cidr(bp->host, who->sockhost)))
581 <      return 1;
576 >    if (!match(bp->name, who->name) && !match(bp->user, who->username))
577 >    {
578 >      switch (bp->type)
579 >      {
580 >        case HM_HOST:
581 >          if (!match(bp->host, who->host) || !match(bp->host, who->sockhost))
582 >            return 1;
583 >          break;
584 >        case HM_IPV4:
585 >          if (who->localClient->aftype == AF_INET)
586 >            if (match_ipv4(&who->localClient->ip, &bp->addr, bp->bits))
587 >              return 1;
588 >          break;
589 > #ifdef IPV6
590 >        case HM_IPV6:
591 >          if (who->localClient->aftype == AF_INET6)
592 >            if (match_ipv6(&who->localClient->ip, &bp->addr, bp->bits))
593 >              return 1;
594 >          break;
595 > #endif
596 >        default:
597 >          assert(0);
598 >      }
599 >    }
600    }
601  
602    return 0;
# Line 635 | Line 608 | find_bmask(const struct Client *who, con
608   * \return 0 if not banned, 1 otherwise
609   */
610   int
611 < is_banned(struct Channel *chptr, struct Client *who)
611 > is_banned(const struct Channel *chptr, const struct Client *who)
612   {
613 <  assert(IsClient(who));
613 >  if (find_bmask(who, &chptr->banlist))
614 >    if (!find_bmask(who, &chptr->exceptlist))
615 >      return 1;
616  
617 <  return find_bmask(who, &chptr->banlist) && (!ConfigChannel.use_except ||
643 <         !find_bmask(who, &chptr->exceptlist));
617 >  return 0;
618   }
619  
620   /*!
621   * \param source_p pointer to client attempting to join
622 < * \param chptr    pointer to channel
622 > * \param chptr    pointer to channel
623   * \param key      key sent by client attempting to join if present
624   * \return ERR_BANNEDFROMCHAN, ERR_INVITEONLYCHAN, ERR_CHANNELISFULL
625   *         or 0 if allowed to join.
# Line 653 | Line 627 | is_banned(struct Channel *chptr, struct
627   int
628   can_join(struct Client *source_p, struct Channel *chptr, const char *key)
629   {
630 <  if (find_bmask(source_p, &chptr->banlist))
631 <    if (!ConfigChannel.use_except || !find_bmask(source_p, &chptr->exceptlist))
632 <      return ERR_BANNEDFROMCHAN;
630 >  if ((chptr->mode.mode & MODE_SSLONLY) && !HasUMode(source_p, UMODE_SSL))
631 >    return ERR_SSLONLYCHAN;
632 >
633 >  if ((chptr->mode.mode & MODE_REGONLY) && !HasUMode(source_p, UMODE_REGISTERED))
634 >    return ERR_NEEDREGGEDNICK;
635 >
636 >  if ((chptr->mode.mode & MODE_OPERONLY) && !HasUMode(source_p, UMODE_OPER))
637 >    return ERR_OPERONLYCHAN;
638  
639    if (chptr->mode.mode & MODE_INVITEONLY)
640      if (!dlinkFind(&source_p->localClient->invited, chptr))
641 <      if (!ConfigChannel.use_invex || !find_bmask(source_p, &chptr->invexlist))
641 >      if (!find_bmask(source_p, &chptr->invexlist))
642          return ERR_INVITEONLYCHAN;
643  
644 <  if (chptr->mode.key[0] && (EmptyString(key) || irccmp(chptr->mode.key, key)))
644 >  if (chptr->mode.key[0] && (!key || strcmp(chptr->mode.key, key)))
645      return ERR_BADCHANNELKEY;
646  
647    if (chptr->mode.limit && dlink_list_length(&chptr->members) >=
648        chptr->mode.limit)
649      return ERR_CHANNELISFULL;
650  
651 +  if (is_banned(chptr, source_p))
652 +    return ERR_BANNEDFROMCHAN;
653 +
654    return 0;
655   }
656  
657   int
658 < has_member_flags(struct Membership *ms, unsigned int flags)
658 > has_member_flags(const struct Membership *ms, const unsigned int flags)
659   {
660 <  if (ms != NULL)
679 <    return ms->flags & flags;
680 <  return 0;
660 >  return ms && (ms->flags & flags);
661   }
662  
663   struct Membership *
# Line 688 | Line 668 | find_channel_link(struct Client *client_
668    if (!IsClient(client_p))
669      return NULL;
670  
671 <  DLINK_FOREACH(ptr, client_p->channel.head)
672 <    if (((struct Membership *)ptr->data)->chptr == chptr)
673 <      return (struct Membership *)ptr->data;
671 >  if (dlink_list_length(&chptr->members) < dlink_list_length(&client_p->channel))
672 >  {
673 >    DLINK_FOREACH(ptr, chptr->members.head)
674 >      if (((struct Membership *)ptr->data)->client_p == client_p)
675 >        return ptr->data;
676 >  }
677 >  else
678 >  {
679 >    DLINK_FOREACH(ptr, client_p->channel.head)
680 >      if (((struct Membership *)ptr->data)->chptr == chptr)
681 >        return ptr->data;
682 >  }
683  
684    return NULL;
685   }
686  
687 + /*
688 + * Basically the same functionality as in bahamut
689 + */
690 + static int
691 + msg_has_ctrls(const char *message)
692 + {
693 +  const unsigned char *p = (const unsigned char *)message;
694 +
695 +  for (; *p; ++p)
696 +  {
697 +    if (*p > 31 || *p == 1)
698 +      continue;
699 +
700 +    if (*p == 27)
701 +    {
702 +      if (*(p + 1) == '$' ||
703 +          *(p + 1) == '(')
704 +      {
705 +        ++p;
706 +        continue;
707 +      }
708 +    }
709 +
710 +    return 1;
711 +  }
712 +
713 +  return 0;
714 + }
715 +
716   /*!
717   * \param chptr    pointer to Channel struct
718   * \param source_p pointer to Client struct
719 + * \param ms       pointer to Membership struct (can be NULL)
720   * \return CAN_SEND_OPV if op or voiced on channel\n
721   *         CAN_SEND_NONOP if can send to channel but is not an op\n
722 < *         CAN_SEND_NO if they cannot send to channel\n
722 > *         ERR_CANNOTSENDTOCHAN or ERR_NEEDREGGEDNICK if they cannot send to channel\n
723   */
724   int
725 < can_send(struct Channel *chptr, struct Client *source_p)
725 > can_send(struct Channel *chptr, struct Client *source_p,
726 >         struct Membership *ms, const char *message)
727   {
728 <  struct Membership *ms = NULL;
728 >  struct MaskItem *conf = NULL;
729  
730 <  if (IsServer(source_p))
730 >  if (IsServer(source_p) || HasFlag(source_p, FLAGS_SERVICE))
731      return CAN_SEND_OPV;
732  
733 <  if (MyClient(source_p) && !IsExemptResv(source_p) &&
734 <      !(IsOper(source_p) && ConfigFileEntry.oper_pass_resv) &&
735 <      (!hash_find_resv(chptr->chname) == ConfigChannel.restrict_channels))
736 <    return CAN_SEND_NO;
737 <
738 <  if ((ms = find_channel_link(source_p, chptr)) == NULL)
739 <  {
740 <    if (chptr->mode.mode & MODE_NOPRIVMSGS)
721 <      return CAN_SEND_NO;
722 <  }
723 <  else
724 <  {
733 >  if (MyClient(source_p) && !IsExemptResv(source_p))
734 >    if (!(HasUMode(source_p, UMODE_OPER) && ConfigFileEntry.oper_pass_resv))
735 >      if ((conf = match_find_resv(chptr->chname)) && !resv_find_exempt(source_p, conf))
736 >        return ERR_CANNOTSENDTOCHAN;
737 >
738 >  if ((chptr->mode.mode & MODE_NOCTRL) && msg_has_ctrls(message))
739 >    return ERR_NOCTRLSONCHAN;
740 >  if (ms || (ms = find_channel_link(source_p, chptr)))
741      if (ms->flags & (CHFL_CHANOP|CHFL_HALFOP|CHFL_VOICE))
742        return CAN_SEND_OPV;
743 +  if (!ms && (chptr->mode.mode & MODE_NOPRIVMSGS))
744 +    return ERR_CANNOTSENDTOCHAN;
745 +  if (chptr->mode.mode & MODE_MODERATED)
746 +    return ERR_CANNOTSENDTOCHAN;
747 +  if ((chptr->mode.mode & MODE_MODREG) && !HasUMode(source_p, UMODE_REGISTERED))
748 +    return ERR_NEEDREGGEDNICK;
749  
750 <    /* cache can send if quiet_on_ban and banned */
751 <    if (ConfigChannel.quiet_on_ban && MyClient(source_p))
750 >  /* cache can send if banned */
751 >  if (MyClient(source_p))
752 >  {
753 >    if (ms)
754      {
755        if (ms->flags & CHFL_BAN_SILENCED)
756 <        return CAN_SEND_NO;
756 >        return ERR_CANNOTSENDTOCHAN;
757  
758        if (!(ms->flags & CHFL_BAN_CHECKED))
759        {
760          if (is_banned(chptr, source_p))
761          {
762            ms->flags |= (CHFL_BAN_CHECKED|CHFL_BAN_SILENCED);
763 <          return CAN_SEND_NO;
763 >          return ERR_CANNOTSENDTOCHAN;
764          }
765  
766          ms->flags |= CHFL_BAN_CHECKED;
767        }
768      }
769 +    else if (is_banned(chptr, source_p))
770 +      return ERR_CANNOTSENDTOCHAN;
771    }
772  
747  if (chptr->mode.mode & MODE_MODERATED)
748    return CAN_SEND_NO;
749
750  return CAN_SEND_NONOP;
751 }
752
753 /*! \brief Checks to see if given client can send a part message
754 * \param member     pointer to channel membership
755 * \param chptr      pointer to channel struct
756 * \param source_p   pointer to struct Client to check
757 */
758 int
759 can_send_part(struct Membership *member, struct Channel *chptr,
760              struct Client *source_p)
761 {
762  if (has_member_flags(member, CHFL_CHANOP|CHFL_HALFOP))
763    return CAN_SEND_OPV;
764
765  if (chptr->mode.mode & MODE_MODERATED)
766    return CAN_SEND_NO;
767
768  if (ConfigChannel.quiet_on_ban && MyClient(source_p) &&
769      is_banned(chptr, source_p))
770    return CAN_SEND_NO;
771
773    return CAN_SEND_NONOP;
774   }
775  
# Line 797 | Line 798 | check_spambot_warning(struct Client *sou
798      {
799        /* Its already known as a possible spambot */
800        if (name != NULL)
801 <        sendto_realops_flags(UMODE_BOTS, L_ALL,
801 >        sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE,
802                               "User %s (%s@%s) trying to join %s is a possible spambot",
803                               source_p->name, source_p->username,
804                               source_p->host, name);
805        else
806 <        sendto_realops_flags(UMODE_BOTS, L_ALL,
806 >        sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE,
807                               "User %s (%s@%s) is a possible spambot",
808                               source_p->name, source_p->username,
809                               source_p->host);
# Line 830 | Line 831 | check_spambot_warning(struct Client *sou
831        }
832      }
833  
834 <    if (name != NULL)
834 >    if (name)
835        source_p->localClient->last_join_time = CurrentTime;
836      else
837        source_p->localClient->last_leave_time = CurrentTime;
# Line 853 | Line 854 | check_splitmode(void *unused)
854      {
855        splitmode = 1;
856  
857 <      sendto_realops_flags(UMODE_ALL,L_ALL,
857 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
858                             "Network split, activating splitmode");
859        eventAddIsh("check_splitmode", check_splitmode, NULL, 10);
860      }
# Line 861 | Line 862 | check_splitmode(void *unused)
862      {
863        splitmode = 0;
864  
865 <      sendto_realops_flags(UMODE_ALL, L_ALL,
865 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
866                             "Network rejoined, deactivating splitmode");
867        eventDelete(check_splitmode, NULL);
868      }
869    }
870   }
871  
871 /*! \brief Allocates a new topic
872 * \param chptr Channel to allocate a new topic for
873 */
874 static void
875 allocate_topic(struct Channel *chptr)
876 {
877  void *ptr = NULL;
878
879  if (chptr == NULL)
880    return;
881
882  ptr = BlockHeapAlloc(topic_heap);  
883
884  /* Basically we allocate one large block for the topic and
885   * the topic info.  We then split it up into two and shove it
886   * in the chptr
887   */
888  chptr->topic       = ptr;
889  chptr->topic_info  = (char *)ptr + TOPICLEN+1;
890  *chptr->topic      = '\0';
891  *chptr->topic_info = '\0';
892 }
893
894 void
895 free_topic(struct Channel *chptr)
896 {
897  void *ptr = NULL;
898  assert(chptr);
899  if (chptr->topic == NULL)
900    return;
901
902  /*
903   * If you change allocate_topic you MUST change this as well
904   */
905  ptr = chptr->topic;
906  BlockHeapFree(topic_heap, ptr);    
907  chptr->topic      = NULL;
908  chptr->topic_info = NULL;
909 }
910
872   /*! \brief Sets the channel topic for chptr
873   * \param chptr      Pointer to struct Channel
874   * \param topic      The topic string
# Line 916 | Line 877 | free_topic(struct Channel *chptr)
877   */
878   void
879   set_channel_topic(struct Channel *chptr, const char *topic,
880 <                  const char *topic_info, time_t topicts)
880 >                  const char *topic_info, time_t topicts, int local)
881   {
882 <  if (!EmptyString(topic))
883 <  {
923 <    if (chptr->topic == NULL)
924 <      allocate_topic(chptr);
925 <
926 <    strlcpy(chptr->topic, topic, TOPICLEN+1);
927 <    strlcpy(chptr->topic_info, topic_info, USERHOST_REPLYLEN);
928 <    chptr->topic_time = topicts;
929 <  }
882 >  if (local)
883 >    strlcpy(chptr->topic, topic, IRCD_MIN(sizeof(chptr->topic), ServerInfo.max_topic_length + 1));
884    else
885 <  {
886 <    /*
887 <     * Do not reset chptr->topic_time here, it's required for
888 <     * bursting topics properly.
935 <     */
936 <    if (chptr->topic != NULL)
937 <      free_topic(chptr);
938 <  }
885 >    strlcpy(chptr->topic, topic, sizeof(chptr->topic));
886 >
887 >  strlcpy(chptr->topic_info, topic_info, sizeof(chptr->topic_info));
888 >  chptr->topic_time = topicts;
889   }

Diff Legend

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