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/src/channel.c (file contents), Revision 32 by knight, Sun Oct 2 20:41:23 2005 UTC vs.
ircd-hybrid/trunk/src/channel.c (file contents), Revision 8003 by michael, Tue Mar 14 14:21:14 2017 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-2017 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 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 "conf_resv.h"
35 + #include "hostmask.h"
36   #include "irc_string.h"
35 #include "sprintf_irc.h"
37   #include "ircd.h"
37 #include "list.h"
38   #include "numeric.h"
39 < #include "s_serv.h"             /* captab */
40 < #include "s_user.h"
39 > #include "server.h"
40   #include "send.h"
42 #include "s_conf.h"             /* ConfigFileEntry, ConfigChannel */
41   #include "event.h"
42   #include "memory.h"
43 < #include "balloc.h"
43 > #include "mempool.h"
44 > #include "misc.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 config_channel_entry ConfigChannel;
48 < dlink_list global_channel_list = { NULL, NULL, 0 };
49 < dlink_list lazylink_channels = { NULL, NULL, 0 };
50 < BlockHeap *ban_heap;    /*! \todo ban_heap shouldn't be a global var */
51 <
52 < static BlockHeap *topic_heap = NULL;
53 < static BlockHeap *member_heap = NULL;
54 < static BlockHeap *channel_heap = NULL;
55 <
56 < static char buf[IRCD_BUFSIZE];
57 < static char modebuf[MODEBUFLEN];
58 < static char parabuf[MODEBUFLEN];
50 > static mp_pool_t *member_pool, *channel_pool, *invite_pool;
51  
52  
53   /*! \brief Initializes the channel blockheap, adds known channel CAPAB
54   */
55   void
56 < init_channels(void)
56 > channel_init(void)
57   {
58 <  /*
59 <   * XXX - These should get moved to somwhere else once we have
60 <   * a modular channelmode system
61 <   */
70 <  add_capability("EX", CAP_EX, 1);
71 <  add_capability("IE", CAP_IE, 1);
72 <  add_capability("CHW", CAP_CHW, 1);
73 <
74 <  channel_heap = BlockHeapCreate("channel", sizeof(struct Channel), CHANNEL_HEAP_SIZE);
75 <  ban_heap = BlockHeapCreate("ban", sizeof(struct Ban), BAN_HEAP_SIZE);
76 <  topic_heap = BlockHeapCreate("topic", TOPICLEN+1 + USERHOST_REPLYLEN, TOPIC_HEAP_SIZE);
77 <  member_heap = BlockHeapCreate("member", sizeof(struct Membership), CHANNEL_HEAP_SIZE*2);
58 >  invite_pool = mp_pool_new(sizeof(struct Invite), MP_CHUNK_SIZE_INVITE);
59 >  channel_pool = mp_pool_new(sizeof(struct Channel), MP_CHUNK_SIZE_CHANNEL);
60 >  ban_pool = mp_pool_new(sizeof(struct Ban), MP_CHUNK_SIZE_BAN);
61 >  member_pool = mp_pool_new(sizeof(struct Membership), MP_CHUNK_SIZE_MEMBER);
62   }
63  
64 < /*! \brief adds a user to a channel by adding another link to the
64 > /*! \brief Adds a user to a channel by adding another link to the
65   *         channels member chain.
66 < * \param chptr      pointer to channel to add client to
67 < * \param who        pointer to client (who) to add
68 < * \param flags      flags for chanops etc
69 < * \param flood_ctrl whether to count this join in flood calculations
66 > * \param chptr      Pointer to channel to add client to
67 > * \param client_p   Pointer to client (who) to add
68 > * \param flags      Flags for chanops etc
69 > * \param flood_ctrl Whether to count this join in flood calculations
70   */
71   void
72 < add_user_to_channel(struct Channel *chptr, struct Client *who,
72 > add_user_to_channel(struct Channel *chptr, struct Client *client_p,
73                      unsigned int flags, int flood_ctrl)
74   {
75 <  struct Membership *ms = NULL;
75 >  assert(IsClient(client_p));
76  
77 <  if (GlobalSetOptions.joinfloodtime > 0)
77 >  if (GlobalSetOptions.joinfloodtime)
78    {
79      if (flood_ctrl)
80 <      chptr->number_joined++;
80 >      ++chptr->number_joined;
81  
82      chptr->number_joined -= (CurrentTime - chptr->last_join_time) *
83        (((float)GlobalSetOptions.joinfloodcount) /
# Line 111 | Line 95 | add_user_to_channel(struct Channel *chpt
95        if (!IsSetJoinFloodNoticed(chptr))
96        {
97          SetJoinFloodNoticed(chptr);
98 <        sendto_realops_flags(UMODE_BOTS, L_ALL,
98 >        sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE,
99                               "Possible Join Flooder %s on %s target: %s",
100 <                             get_client_name(who, HIDE_IP),
101 <                             who->servptr->name, chptr->chname);
100 >                             client_get_name(client_p, HIDE_IP),
101 >                             client_p->servptr->name, chptr->name);
102        }
103      }
104  
105      chptr->last_join_time = CurrentTime;
106    }
107  
108 <  ms = BlockHeapAlloc(member_heap);
109 <  ms->client_p = who;
110 <  ms->chptr = chptr;
111 <  ms->flags = flags;
108 >  struct Membership *member = mp_pool_get(member_pool);
109 >  member->client_p = client_p;
110 >  member->chptr = chptr;
111 >  member->flags = flags;
112  
113 <  dlinkAdd(ms, &ms->channode, &chptr->members);
113 >  dlinkAdd(member, &member->channode, &chptr->members);
114  
115 <  if (MyConnect(who))
116 <    dlinkAdd(ms, &ms->locchannode, &chptr->locmembers);
115 >  if (MyConnect(client_p))
116 >    dlinkAdd(member, &member->locchannode, &chptr->locmembers);
117  
118 <  dlinkAdd(ms, &ms->usernode, &who->channel);
118 >  dlinkAdd(member, &member->usernode, &client_p->channel);
119   }
120  
121 < /*! \brief deletes an user from a channel by removing a link in the
121 > /*! \brief Deletes an user from a channel by removing a link in the
122   *         channels member chain.
123 < * \param member pointer to Membership struct
123 > * \param member Pointer to Membership struct
124   */
125   void
126   remove_user_from_channel(struct Membership *member)
127   {
128 <  struct Client *client_p = member->client_p;
129 <  struct Channel *chptr = member->chptr;
128 >  struct Client *const client_p = member->client_p;
129 >  struct Channel *const chptr = member->chptr;
130  
131    dlinkDelete(&member->channode, &chptr->members);
132  
# Line 151 | Line 135 | remove_user_from_channel(struct Membersh
135  
136    dlinkDelete(&member->usernode, &client_p->channel);
137  
138 <  BlockHeapFree(member_heap, member);
138 >  mp_pool_release(member);
139  
140 <  if (dlink_list_length(&chptr->members) == 0)
141 <  {
158 <    assert(dlink_list_length(&chptr->locmembers) == 0);
159 <    destroy_channel(chptr);
160 <  }
140 >  if (chptr->members.head == NULL)
141 >    channel_free(chptr);
142   }
143  
144 < /* send_members()
144 > /* channel_send_members()
145   *
146   * inputs       -
147   * output       - NONE
148   * side effects -
149   */
150   static void
151 < send_members(struct Client *client_p, struct Channel *chptr,
152 <             char *lmodebuf, char *lparabuf)
151 > channel_send_members(struct Client *client_p, const struct Channel *chptr,
152 >                     const char *modebuf, const char *parabuf)
153   {
154 <  struct Membership *ms;
155 <  dlink_node *ptr;
154 >  char buf[IRCD_BUFSIZE] = "";
155 >  dlink_node *node;
156    int tlen;              /* length of text to append */
157    char *t, *start;       /* temp char pointer */
158  
159 <  start = t = buf + ircsprintf(buf, ":%s SJOIN %lu %s %s %s:",
160 <                               ID_or_name(&me, client_p),
161 <                               (unsigned long)chptr->channelts,
162 <                               chptr->chname, lmodebuf, lparabuf);
163 <
164 <  DLINK_FOREACH(ptr, chptr->members.head)
165 <  {
166 <    ms = ptr->data;
167 <
168 <    tlen = strlen(IsCapable(client_p, CAP_TS6) ?
169 <      ID(ms->client_p) : ms->client_p->name) + 1;  /* nick + space */
170 <
171 <    if (ms->flags & CHFL_CHANOP)
172 <      tlen++;
173 < #ifdef HALFOPS
174 <    if (ms->flags & CHFL_HALFOP)
175 <      tlen++;
176 < #endif
177 <    if (ms->flags & CHFL_VOICE)
178 <      tlen++;
179 <
180 <    /* space will be converted into CR, but we also need space for LF..
200 <     * That's why we use '- 1' here
201 <     * -adx */
202 <    if (t + tlen - buf > sizeof(buf) - 1)
159 >  start = t = buf + snprintf(buf, sizeof(buf), ":%s SJOIN %ju %s %s %s:",
160 >                             me.id, chptr->creationtime,
161 >                             chptr->name, modebuf, parabuf);
162 >
163 >  DLINK_FOREACH(node, chptr->members.head)
164 >  {
165 >    const struct Membership *member = node->data;
166 >
167 >    tlen = strlen(member->client_p->id) + 1;  /* +1 for space */
168 >
169 >    if (member->flags & CHFL_CHANOP)
170 >      ++tlen;
171 >    if (member->flags & CHFL_HALFOP)
172 >      ++tlen;
173 >    if (member->flags & CHFL_VOICE)
174 >      ++tlen;
175 >
176 >    /*
177 >     * Space will be converted into CR, but we also need space for LF..
178 >     * That's why we use '- 1' here -adx
179 >     */
180 >    if (t + tlen - buf > IRCD_BUFSIZE - 1)
181      {
182 <      *(t - 1) = '\0';  /* kill the space and terminate the string */
182 >      *(t - 1) = '\0';  /* Kill the space and terminate the string */
183        sendto_one(client_p, "%s", buf);
184        t = start;
185      }
186  
187 <    strcpy(t, get_member_status(ms, YES));
188 <    t += strlen(t);
187 >    if (member->flags & CHFL_CHANOP)
188 >      *t++ = '@';
189 >    if (member->flags & CHFL_HALFOP)
190 >      *t++ = '%';
191 >    if (member->flags & CHFL_VOICE)
192 >      *t++ = '+';
193 >
194 >    strcpy(t, member->client_p->id);
195  
212    if (IsCapable(client_p, CAP_TS6))
213      strcpy(t, ID(ms->client_p));
214    else
215      strcpy(t, ms->client_p->name);
196      t += strlen(t);
197      *t++ = ' ';
198    }
199  
200 <  /* should always be non-NULL unless we have a kind of persistent channels */
201 <  if (chptr->members.head != NULL)
202 <    t--;  /* take the space out */
200 >  /* Should always be non-NULL unless we have a kind of persistent channels */
201 >  if (chptr->members.head)
202 >    t--;  /* Take the space out */
203    *t = '\0';
204    sendto_one(client_p, "%s", buf);
205   }
206  
207 < /*! \brief sends +b/+e/+I
208 < * \param client_p client pointer to server
209 < * \param chptr    pointer to channel
210 < * \param top      pointer to top of mode link list to send
211 < * \param flag     char flag flagging type of mode. Currently this can be 'b', e' or 'I'
207 > /*! \brief Sends +b/+e/+I
208 > * \param client_p Client pointer to server
209 > * \param chptr    Pointer to channel
210 > * \param list     Pointer to list of modes to send
211 > * \param flag     Char flag flagging type of mode. Currently this can be 'b', e' or 'I'
212   */
213   static void
214 < send_mode_list(struct Client *client_p, struct Channel *chptr,
215 <               dlink_list *top, char flag)
214 > channel_send_mask_list(struct Client *client_p, const struct Channel *chptr,
215 >                       const dlink_list *list, const char flag)
216   {
217 <  int ts5 = !IsCapable(client_p, CAP_TS6);
218 <  dlink_node *lp;
219 <  struct Ban *banptr;
220 <  char pbuf[IRCD_BUFSIZE];
221 <  int tlen, mlen, cur_len, count = 0;
242 <  char *mp = NULL, *pp = pbuf;
217 >  dlink_node *node;
218 >  char mbuf[IRCD_BUFSIZE] = "";
219 >  char pbuf[IRCD_BUFSIZE] = "";
220 >  int tlen, mlen, cur_len;
221 >  char *pp = pbuf;
222  
223 <  if (top == NULL || top->length == 0)
223 >  if (!dlink_list_length(list))
224      return;
225  
226 <  if (ts5)
227 <    mlen = ircsprintf(buf, ":%s MODE %s +", me.name, chptr->chname);
228 <  else
250 <    mlen = ircsprintf(buf, ":%s BMASK %lu %s %c :", me.id,
251 <                      (unsigned long)chptr->channelts, chptr->chname, flag);
252 <
253 <  /* MODE needs additional one byte for space between buf and pbuf */
254 <  cur_len = mlen + ts5;
255 <  mp = buf + mlen;
226 >  mlen = snprintf(mbuf, sizeof(mbuf), ":%s BMASK %ju %s %c :", me.id,
227 >                  chptr->creationtime, chptr->name, flag);
228 >  cur_len = mlen;
229  
230 <  DLINK_FOREACH(lp, top->head)
230 >  DLINK_FOREACH(node, list->head)
231    {
232 <    banptr = lp->data;
232 >    const struct Ban *ban = node->data;
233  
234 <    /* must add another b/e/I letter if we use MODE */
262 <    tlen = banptr->len + 3 + ts5;
234 >    tlen = ban->len + 3;  /* +3 for ! + @ + space */
235  
236      /*
237 <     * send buffer and start over if we cannot fit another ban,
266 <     * or if the target is non-ts6 and we have too many modes in
267 <     * in this line.
237 >     * Send buffer and start over if we cannot fit another ban
238       */
239 <    if (cur_len + (tlen - 1) > IRCD_BUFSIZE - 2 ||
270 <        (!IsCapable(client_p, CAP_TS6) &&
271 <         (count >= MAXMODEPARAMS || pp - pbuf >= MODEBUFLEN)))
239 >    if (cur_len + (tlen - 1) > IRCD_BUFSIZE - 2)
240      {
241 <      *(pp - 1) = '\0';  /* get rid of trailing space on buffer */
242 <      sendto_one(client_p, "%s%s%s", buf, ts5 ? " " : "", pbuf);
241 >      *(pp - 1) = '\0';  /* Get rid of trailing space on buffer */
242 >      sendto_one(client_p, "%s%s", mbuf, pbuf);
243  
244 <      cur_len = mlen + ts5;
277 <      mp = buf + mlen;
244 >      cur_len = mlen;
245        pp = pbuf;
279      count = 0;
280    }
281
282    count++;
283    if (ts5)
284    {
285      *mp++ = flag;
286      *mp = '\0';
246      }
247  
248 <    pp += ircsprintf(pp, "%s!%s@%s ", banptr->name, banptr->username,
290 <                     banptr->host);
248 >    pp += sprintf(pp, "%s!%s@%s ", ban->name, ban->user, ban->host);
249      cur_len += tlen;
250    }
251  
252 <  *(pp - 1) = '\0';  /* get rid of trailing space on buffer */
253 <  sendto_one(client_p, "%s%s%s", buf, ts5 ? " " : "", pbuf);
252 >  *(pp - 1) = '\0';  /* Get rid of trailing space on buffer */
253 >  sendto_one(client_p, "%s%s", mbuf, pbuf);
254   }
255  
256 < /*! \brief send "client_p" a full list of the modes for channel chptr
257 < * \param client_p pointer to client client_p
258 < * \param chptr    pointer to channel pointer
256 > /*! \brief Send "client_p" a full list of the modes for channel chptr
257 > * \param client_p Pointer to client client_p
258 > * \param chptr    Pointer to channel pointer
259   */
260   void
261 < send_channel_modes(struct Client *client_p, struct Channel *chptr)
261 > channel_send_modes(struct Client *client_p, struct Channel *chptr)
262   {
263 <  if (chptr->chname[0] != '#')
264 <    return;
263 >  char modebuf[MODEBUFLEN] = "";
264 >  char parabuf[MODEBUFLEN] = "";
265  
308  *modebuf = *parabuf = '\0';
266    channel_modes(chptr, client_p, modebuf, parabuf);
267 <  send_members(client_p, chptr, modebuf, parabuf);
267 >  channel_send_members(client_p, chptr, modebuf, parabuf);
268  
269 <  send_mode_list(client_p, chptr, &chptr->banlist, 'b');
270 <
271 <  if (IsCapable(client_p, CAP_EX))
315 <    send_mode_list(client_p, chptr, &chptr->exceptlist, 'e');
316 <  if (IsCapable(client_p, CAP_IE))
317 <    send_mode_list(client_p, chptr, &chptr->invexlist, 'I');
269 >  channel_send_mask_list(client_p, chptr, &chptr->banlist, 'b');
270 >  channel_send_mask_list(client_p, chptr, &chptr->exceptlist, 'e');
271 >  channel_send_mask_list(client_p, chptr, &chptr->invexlist, 'I');
272   }
273  
274 < /*! \brief check channel name for invalid characters
275 < * \param name pointer to channel name string
276 < * \return TRUE (1) if name ok, FALSE (0) otherwise
274 > /*! \brief Check channel name for invalid characters
275 > * \param name Pointer to channel name string
276 > * \param local Indicates whether it's a local or remote creation
277 > * \return 0 if invalid, 1 otherwise
278   */
279   int
280 < check_channel_name(const char *name)
280 > channel_check_name(const char *name, const int local)
281   {
282 <  const unsigned char *p = (const unsigned char *)name;
328 <  assert(name != NULL);
282 >  const char *p = name;
283  
284 <  for (; *p; ++p)
285 <    if (!IsChanChar(*p))
286 <      return 0;
284 >  assert(!EmptyString(p));
285 >
286 >  if (!IsChanPrefix(*p))
287 >    return 0;
288 >
289 >  if (!local || !ConfigChannel.disable_fake_channels)
290 >  {
291 >    while (*++p)
292 >      if (!IsChanChar(*p))
293 >        return 0;
294 >  }
295 >  else
296 >  {
297 >    while (*++p)
298 >      if (!IsVisibleChanChar(*p))
299 >        return 0;
300 >  }
301  
302 <  return 1;
302 >  return p - name <= CHANNELLEN;
303   }
304  
305   void
306 < remove_ban(struct Ban *bptr, dlink_list *list)
306 > remove_ban(struct Ban *ban, dlink_list *list)
307   {
308 <  dlinkDelete(&bptr->node, list);
309 <
342 <  MyFree(bptr->name);
343 <  MyFree(bptr->username);
344 <  MyFree(bptr->host);
345 <  MyFree(bptr->who);
346 <
347 <  BlockHeapFree(ban_heap, bptr);
308 >  dlinkDelete(&ban->node, list);
309 >  mp_pool_release(ban);
310   }
311  
312 < /* free_channel_list()
312 > /* channel_free_mask_list()
313   *
314   * inputs       - pointer to dlink_list
315   * output       - NONE
316   * side effects -
317   */
318 < void
319 < free_channel_list(dlink_list *list)
318 > static void
319 > channel_free_mask_list(dlink_list *list)
320   {
321 <  dlink_node *ptr = NULL, *next_ptr = NULL;
322 <
323 <  DLINK_FOREACH_SAFE(ptr, next_ptr, list->head)
324 <    remove_ban(ptr->data, list);
325 <
364 <  assert(list->tail == NULL && list->head == NULL);
321 >  while (list->head)
322 >  {
323 >    struct Ban *ban = list->head->data;
324 >    remove_ban(ban, list);
325 >  }
326   }
327  
328 < /*! \brief Get Channel block for chname (and allocate a new channel
328 > /*! \brief Get Channel block for name (and allocate a new channel
329   *         block, if it didn't exist before)
330 < * \param client_p client pointer
331 < * \param chname   channel name
371 < * \param isnew    pointer to int flag whether channel was newly created or not
372 < * \return channel block or NULL if illegal name
330 > * \param name Channel name
331 > * \return Channel block
332   */
333   struct Channel *
334 < get_or_create_channel(struct Client *client_p, const char *chname, int *isnew)
334 > channel_make(const char *name)
335   {
336 <  struct Channel *chptr = NULL;
378 <  int len;
379 <
380 <  if (EmptyString(chname))
381 <    return NULL;
382 <
383 <  if ((len = strlen(chname)) > CHANNELLEN)
384 <  {
385 <    if (IsServer(client_p))
386 <      sendto_realops_flags(UMODE_DEBUG, L_ALL,
387 <                           "*** Long channel name from %s (%d > %d): %s",
388 <                           client_p->name, len, CHANNELLEN, chname);
389 <    return NULL;
390 <  }
391 <
392 <  if ((chptr = hash_find_channel(chname)) != NULL)
393 <  {
394 <    if (isnew != NULL)
395 <      *isnew = 0;
336 >  assert(!EmptyString(name));
337  
338 <    return chptr;
339 <  }
340 <
341 <  if (isnew != NULL)
401 <    *isnew = 1;
338 >  struct Channel *chptr = mp_pool_get(channel_pool);
339 >  /* Doesn't hurt to set it here */
340 >  chptr->creationtime = CurrentTime;
341 >  chptr->last_join_time = CurrentTime;
342  
343 <  chptr = BlockHeapAlloc(channel_heap);
344 <  /* doesn't hurt to set it here */
345 <  chptr->channelts = chptr->last_join_time = CurrentTime;
406 <
407 <  strlcpy(chptr->chname, chname, sizeof(chptr->chname));
408 <  dlinkAdd(chptr, &chptr->node, &global_channel_list);
343 >  chptr->name_len = strlcpy(chptr->name, name, sizeof(chptr->name));
344 >  if (chptr->name_len >= sizeof(chptr->name))
345 >    chptr->name_len = sizeof(chptr->name) - 1;
346  
347 +  dlinkAdd(chptr, &chptr->node, &channel_list);
348    hash_add_channel(chptr);
349  
350    return chptr;
351   }
352  
353 < /*! \brief walk through this channel, and destroy it.
354 < * \param chptr channel pointer
353 > /*! \brief Walk through this channel, and destroy it.
354 > * \param chptr Channel pointer
355   */
356   void
357 < destroy_channel(struct Channel *chptr)
357 > channel_free(struct Channel *chptr)
358   {
359 <  dlink_node *ptr = NULL, *ptr_next = NULL;
422 <
423 <  DLINK_FOREACH_SAFE(ptr, ptr_next, chptr->invites.head)
424 <    del_invite(chptr, ptr->data);
359 >  clear_invite_list(&chptr->invites);
360  
361 <  /* free ban/exception/invex lists */
362 <  free_channel_list(&chptr->banlist);
363 <  free_channel_list(&chptr->exceptlist);
364 <  free_channel_list(&chptr->invexlist);
361 >  /* Free ban/exception/invex lists */
362 >  channel_free_mask_list(&chptr->banlist);
363 >  channel_free_mask_list(&chptr->exceptlist);
364 >  channel_free_mask_list(&chptr->invexlist);
365  
366 <  /* Free the topic */
432 <  free_topic(chptr);
433 <
434 <  dlinkDelete(&chptr->node, &global_channel_list);
366 >  dlinkDelete(&chptr->node, &channel_list);
367    hash_del_channel(chptr);
368  
369 <  if (ServerInfo.hub)
438 <    if ((ptr = dlinkFindDelete(&lazylink_channels, chptr)))
439 <      free_dlink_node(ptr);
440 <
441 <  BlockHeapFree(channel_heap, chptr);
369 >  mp_pool_release(chptr);
370   }
371  
372   /*!
373 < * \param chptr pointer to channel
374 < * \return string pointer "=" if public, "@" if secret else "*"
373 > * \param chptr Pointer to channel
374 > * \return String pointer "=" if public, "@" if secret else "*"
375   */
376   static const char *
377 < channel_pub_or_secret(struct Channel *chptr)
377 > channel_pub_or_secret(const struct Channel *chptr)
378   {
379    if (SecretChannel(chptr))
380      return "@";
# Line 456 | Line 384 | channel_pub_or_secret(struct Channel *ch
384   }
385  
386   /*! \brief lists all names on given channel
387 < * \param source_p pointer to client struct requesting names
388 < * \param chptr    pointer to channel block
389 < * \param show_eon show ENDOFNAMES numeric or not
387 > * \param client_p Pointer to client struct requesting names
388 > * \param chptr    Pointer to channel block
389 > * \param show_eon Show RPL_ENDOFNAMES numeric or not
390   *                 (don't want it with /names with no params)
391   */
392   void
393 < channel_member_names(struct Client *source_p, struct Channel *chptr,
393 > channel_member_names(struct Client *client_p, struct Channel *chptr,
394                       int show_eon)
395   {
396 <  struct Client *target_p = NULL;
397 <  struct Membership *ms = NULL;
470 <  dlink_node *ptr = NULL;
471 <  char lbuf[IRCD_BUFSIZE + 1];
396 >  dlink_node *node;
397 >  char buf[IRCD_BUFSIZE + 1] = "";
398    char *t = NULL, *start = NULL;
399    int tlen = 0;
400 <  int is_member = IsMember(source_p, chptr);
400 >  const int is_member = IsMember(client_p, chptr);
401 >  const int multi_prefix = HasCap(client_p, CAP_MULTI_PREFIX) != 0;
402 >  const int uhnames = HasCap(client_p, CAP_UHNAMES) != 0;
403 >
404 >  assert(IsClient(client_p));
405  
406    if (PubChannel(chptr) || is_member)
407    {
408 <    t = lbuf + ircsprintf(lbuf, form_str(RPL_NAMREPLY),
409 <                          me.name, source_p->name,
410 <                          channel_pub_or_secret(chptr),
481 <                          chptr->chname);
408 >    t = buf + snprintf(buf, sizeof(buf), numeric_form(RPL_NAMREPLY),
409 >                       me.name, client_p->name,
410 >                       channel_pub_or_secret(chptr), chptr->name);
411      start = t;
412  
413 <    DLINK_FOREACH(ptr, chptr->members.head)
413 >    DLINK_FOREACH(node, chptr->members.head)
414      {
415 <      ms       = ptr->data;
487 <      target_p = ms->client_p;
415 >      const struct Membership *member = node->data;
416  
417 <      if (IsInvisible(target_p) && !is_member)
417 >      if (HasUMode(member->client_p, UMODE_INVISIBLE) && !is_member)
418          continue;
419  
420 <      tlen = strlen(target_p->name) + 1;  /* nick + space */
420 >      if (!uhnames)
421 >        tlen = strlen(member->client_p->name) + 1;  /* +1 for space */
422 >      else
423 >        tlen = strlen(member->client_p->name) + strlen(member->client_p->username) +
424 >               strlen(member->client_p->host) + 3;  /* +3 for ! + @ + space */
425  
426 <      if (ms->flags & (CHFL_CHANOP | CHFL_HALFOP | CHFL_VOICE))
427 <        ++tlen;
428 <      if (t + tlen - lbuf > IRCD_BUFSIZE)
426 >      if (!multi_prefix)
427 >      {
428 >        if (member->flags & (CHFL_CHANOP | CHFL_HALFOP | CHFL_VOICE))
429 >          ++tlen;
430 >      }
431 >      else
432 >      {
433 >        if (member->flags & CHFL_CHANOP)
434 >          ++tlen;
435 >        if (member->flags & CHFL_HALFOP)
436 >          ++tlen;
437 >        if (member->flags & CHFL_VOICE)
438 >          ++tlen;
439 >      }
440 >
441 >      if (t + tlen - buf > IRCD_BUFSIZE - 2)
442        {
443          *(t - 1) = '\0';
444 <        sendto_one(source_p, "%s", lbuf);
444 >        sendto_one(client_p, "%s", buf);
445          t = start;
446        }
447  
448 <      t += ircsprintf(t, "%s%s ", get_member_status(ms, NO),
449 <                      target_p->name);
448 >      if (!uhnames)
449 >        t += sprintf(t, "%s%s ", get_member_status(member, multi_prefix),
450 >                     member->client_p->name);
451 >      else
452 >        t += sprintf(t, "%s%s!%s@%s ", get_member_status(member, multi_prefix),
453 >                     member->client_p->name, member->client_p->username,
454 >                     member->client_p->host);
455      }
456  
457 <    if (tlen != 0)
457 >    if (tlen)
458      {
459        *(t - 1) = '\0';
460 <      sendto_one(source_p, "%s", lbuf);
460 >      sendto_one(client_p, "%s", buf);
461      }
462    }
463  
464    if (show_eon)
465 <    sendto_one(source_p, form_str(RPL_ENDOFNAMES),
466 <               me.name, source_p->name, chptr->chname);
465 >    sendto_one_numeric(client_p, &me, RPL_ENDOFNAMES, chptr->name);
466 > }
467 >
468 > static struct Invite *
469 > find_invite(struct Channel *chptr, struct Client *client_p)
470 > {
471 >  dlink_node *node, *node_next;
472 >  dlink_list *list;
473 >
474 >  /* Take the shortest of the two lists */
475 >  if (dlink_list_length(&client_p->connection->invited) < dlink_list_length(&chptr->invites))
476 >    list = &client_p->connection->invited;
477 >  else
478 >    list = &chptr->invites;
479 >
480 >  DLINK_FOREACH_SAFE(node, node_next, list->head)
481 >  {
482 >    struct Invite *invite = node->data;
483 >
484 >    if (ConfigChannel.invite_expire_time &&
485 >        ConfigChannel.invite_expire_time + invite->when < CurrentTime)
486 >      del_invite(invite);
487 >    else if (invite->chptr == chptr && invite->client_p == client_p)
488 >      return invite;
489 >  }
490 >
491 >  return NULL;
492   }
493  
494 < /*! \brief adds client to invite list
495 < * \param chptr pointer to channel block
496 < * \param who   pointer to client to add invite to
494 > /*! \brief Adds client to invite list
495 > * \param chptr    Pointer to channel block
496 > * \param client_p Pointer to client to add invite to
497   */
498   void
499 < add_invite(struct Channel *chptr, struct Client *who)
499 > add_invite(struct Channel *chptr, struct Client *client_p)
500   {
501 <  del_invite(chptr, who);
501 >  struct Invite *invite;
502  
503 <  /*
504 <   * delete last link in chain if the list is max length
505 <   */
506 <  if (dlink_list_length(&who->invited) >=
507 <      ConfigChannel.max_chans_per_user)
508 <    del_invite(who->invited.tail->data, who);
503 >  if ((invite = find_invite(chptr, client_p)))
504 >    del_invite(invite);
505 >
506 >  invite = mp_pool_get(invite_pool);
507 >  invite->client_p = client_p;
508 >  invite->chptr = chptr;
509 >  invite->when = CurrentTime;
510  
511 <  /* add client to channel invite list */
512 <  dlinkAdd(who, make_dlink_node(), &chptr->invites);
511 >  /* Delete last link in chain if the list is max length */
512 >  while (dlink_list_length(&client_p->connection->invited) &&
513 >         dlink_list_length(&client_p->connection->invited) >= ConfigChannel.max_invites)
514 >    del_invite(client_p->connection->invited.tail->data);
515  
516 <  /* add channel to the end of the client invite list */
517 <  dlinkAdd(chptr, make_dlink_node(), &who->invited);
516 >  /* Add client to channel invite list */
517 >  dlinkAdd(invite, &invite->chan_node, &chptr->invites);
518 >
519 >  /* Add channel to the end of the client invite list */
520 >  dlinkAdd(invite, &invite->user_node, &client_p->connection->invited);
521   }
522  
523   /*! \brief Delete Invite block from channel invite list
524   *         and client invite list
525 < * \param chptr pointer to Channel struct
545 < * \param who   pointer to client to remove invites from
525 > * \param invite Pointer to Invite struct
526   */
527   void
528 < del_invite(struct Channel *chptr, struct Client *who)
528 > del_invite(struct Invite *invite)
529   {
530 <  dlink_node *ptr = NULL;
530 >  dlinkDelete(&invite->user_node, &invite->client_p->connection->invited);
531 >  dlinkDelete(&invite->chan_node, &invite->chptr->invites);
532  
533 <  if ((ptr = dlinkFindDelete(&who->invited, chptr)))
534 <    free_dlink_node(ptr);
533 >  /* Release memory pointed to by 'invite' */
534 >  mp_pool_release(invite);
535 > }
536  
537 <  if ((ptr = dlinkFindDelete(&chptr->invites, who)))
538 <    free_dlink_node(ptr);
537 > /*! \brief Removes and frees all Invite blocks from a list
538 > * \param list Pointer to a dlink_list
539 > */
540 > void
541 > clear_invite_list(dlink_list *list)
542 > {
543 >  while (list->head)
544 >    del_invite(list->head->data);
545   }
546  
547   /* get_member_status()
# Line 565 | Line 553 | del_invite(struct Channel *chptr, struct
553   * side effects -
554   *
555   * NOTE: Returned string is usually a static buffer
556 < * (like in get_client_name)
556 > * (like in client_get_name)
557   */
558   const char *
559 < get_member_status(const struct Membership *ms, int combine)
559 > get_member_status(const struct Membership *member, const int combine)
560   {
561 <  static char buffer[4];
562 <  char *p = NULL;
561 >  static char buffer[CMEMBER_STATUS_FLAGS_LEN + 1];  /* +1 for \0 */
562 >  char *p = buffer;
563  
564 <  if (ms == NULL)
577 <    return "";
578 <  p = buffer;
579 <
580 <  if (ms->flags & CHFL_CHANOP)
564 >  if (member->flags & CHFL_CHANOP)
565    {
566      if (!combine)
567        return "@";
568      *p++ = '@';
569    }
570  
571 < #ifdef HALFOPS
588 <  if (ms->flags & CHFL_HALFOP)
571 >  if (member->flags & CHFL_HALFOP)
572    {
573      if (!combine)
574        return "%";
575      *p++ = '%';
576    }
594 #endif
577  
578 <  if (ms->flags & CHFL_VOICE)
578 >  if (member->flags & CHFL_VOICE)
579      *p++ = '+';
580    *p = '\0';
581  
# Line 601 | Line 583 | get_member_status(const struct Membershi
583   }
584  
585   /*!
586 < * \param who  pointer to Client to check
587 < * \param list pointer to ban list to search
586 > * \param client_p Pointer to Client to check
587 > * \param list     Pointer to ban list to search
588   * \return 1 if ban found for given n!u\@h mask, 0 otherwise
607 *
589   */
590   static int
591 < find_bmask(const struct Client *who, const dlink_list *const list)
591 > find_bmask(const struct Client *client_p, const dlink_list *list)
592   {
593 <  const dlink_node *ptr = NULL;
593 >  dlink_node *node;
594  
595 <  DLINK_FOREACH(ptr, list->head)
595 >  DLINK_FOREACH(node, list->head)
596    {
597 <    const struct Ban *bp = ptr->data;
597 >    const struct Ban *ban = node->data;
598  
599 <    if (match(bp->name, who->name) &&
600 <        match(bp->username, who->username) &&
601 <        (match(bp->host, who->host) ||
602 <         match(bp->host, who->sockhost) ||
603 <         match_cidr(bp->host, who->sockhost)))
604 <      return 1;
599 >    if (!match(ban->name, client_p->name) && !match(ban->user, client_p->username))
600 >    {
601 >      switch (ban->type)
602 >      {
603 >        case HM_HOST:
604 >          if (!match(ban->host, client_p->host) || !match(ban->host, client_p->sockhost))
605 >            return 1;
606 >          break;
607 >        case HM_IPV4:
608 >          if (client_p->connection->aftype == AF_INET)
609 >            if (match_ipv4(&client_p->connection->ip, &ban->addr, ban->bits))
610 >              return 1;
611 >          break;
612 >        case HM_IPV6:
613 >          if (client_p->connection->aftype == AF_INET6)
614 >            if (match_ipv6(&client_p->connection->ip, &ban->addr, ban->bits))
615 >              return 1;
616 >          break;
617 >        default:
618 >          assert(0);
619 >      }
620 >    }
621    }
622  
623    return 0;
624   }
625  
626   /*!
627 < * \param chptr pointer to channel block
628 < * \param who   pointer to client to check access fo
627 > * \param chptr    Pointer to channel block
628 > * \param client_p Pointer to client to check access fo
629   * \return 0 if not banned, 1 otherwise
630   */
631   int
632 < is_banned(struct Channel *chptr, struct Client *who)
632 > is_banned(const struct Channel *chptr, const struct Client *client_p)
633   {
634 <  assert(IsClient(who));
634 >  if (find_bmask(client_p, &chptr->banlist))
635 >    if (!find_bmask(client_p, &chptr->exceptlist))
636 >      return 1;
637  
638 <  return find_bmask(who, &chptr->banlist) && (!ConfigChannel.use_except ||
640 <         !find_bmask(who, &chptr->exceptlist));
638 >  return 0;
639   }
640  
641 < /*!
642 < * \param source_p pointer to client attempting to join
643 < * \param chptr    pointer to channel
644 < * \param key      key sent by client attempting to join if present
641 > /*! Tests if a client can join a certain channel
642 > * \param client_p Pointer to client attempting to join
643 > * \param chptr    Pointer to channel
644 > * \param key      Key sent by client attempting to join if present
645   * \return ERR_BANNEDFROMCHAN, ERR_INVITEONLYCHAN, ERR_CHANNELISFULL
646   *         or 0 if allowed to join.
647   */
648 < int
649 < can_join(struct Client *source_p, struct Channel *chptr, const char *key)
648 > static int
649 > can_join(struct Client *client_p, struct Channel *chptr, const char *key)
650   {
651 <  if (find_bmask(source_p, &chptr->banlist))
652 <    if (!ConfigChannel.use_except || !find_bmask(source_p, &chptr->exceptlist))
653 <      return ERR_BANNEDFROMCHAN;
651 >  if ((chptr->mode.mode & MODE_SSLONLY) && !HasUMode(client_p, UMODE_SSL))
652 >    return ERR_SSLONLYCHAN;
653 >
654 >  if ((chptr->mode.mode & MODE_REGONLY) && !HasUMode(client_p, UMODE_REGISTERED))
655 >    return ERR_NEEDREGGEDNICK;
656 >
657 >  if ((chptr->mode.mode & MODE_OPERONLY) && !HasUMode(client_p, UMODE_OPER))
658 >    return ERR_OPERONLYCHAN;
659  
660    if (chptr->mode.mode & MODE_INVITEONLY)
661 <    if (!dlinkFind(&source_p->invited, chptr))
662 <      if (!ConfigChannel.use_invex || !find_bmask(source_p, &chptr->invexlist))
661 >    if (!find_invite(chptr, client_p))
662 >      if (!find_bmask(client_p, &chptr->invexlist))
663          return ERR_INVITEONLYCHAN;
664  
665 <  if (chptr->mode.key[0] && (EmptyString(key) || irccmp(chptr->mode.key, key)))
665 >  if (chptr->mode.key[0] && (!key || strcmp(chptr->mode.key, key)))
666      return ERR_BADCHANNELKEY;
667  
668    if (chptr->mode.limit && dlink_list_length(&chptr->members) >=
669        chptr->mode.limit)
670      return ERR_CHANNELISFULL;
671  
672 +  if (is_banned(chptr, client_p))
673 +    return ERR_BANNEDFROMCHAN;
674 +
675    return 0;
676   }
677  
678   int
679 < has_member_flags(struct Membership *ms, unsigned int flags)
679 > has_member_flags(const struct Membership *member, const unsigned int flags)
680   {
681 <  if (ms != NULL)
676 <    return ms->flags & flags;
677 <  return 0;
681 >  return member && (member->flags & flags);
682   }
683  
684   struct Membership *
685   find_channel_link(struct Client *client_p, struct Channel *chptr)
686   {
687 <  dlink_node *ptr = NULL;
687 >  dlink_node *node;
688  
689    if (!IsClient(client_p))
690      return NULL;
691  
692 <  DLINK_FOREACH(ptr, client_p->channel.head)
693 <    if (((struct Membership *)ptr->data)->chptr == chptr)
694 <      return (struct Membership *)ptr->data;
692 >  if (dlink_list_length(&chptr->members) < dlink_list_length(&client_p->channel))
693 >  {
694 >    DLINK_FOREACH(node, chptr->members.head)
695 >      if (((struct Membership *)node->data)->client_p == client_p)
696 >        return node->data;
697 >  }
698 >  else
699 >  {
700 >    DLINK_FOREACH(node, client_p->channel.head)
701 >      if (((struct Membership *)node->data)->chptr == chptr)
702 >        return node->data;
703 >  }
704  
705    return NULL;
706   }
707  
708 < /*!
709 < * \param chptr    pointer to Channel struct
710 < * \param source_p pointer to Client struct
698 < * \return CAN_SEND_OPV if op or voiced on channel\n
699 < *         CAN_SEND_NONOP if can send to channel but is not an op\n
700 < *         CAN_SEND_NO if they cannot send to channel\n
708 > /*! Checks if a message contains control codes
709 > * \param message The actual message string the client wants to send
710 > * \return 1 if the message does contain any control codes, 0 otherwise
711   */
712 < int
713 < can_send(struct Channel *chptr, struct Client *source_p)
712 > static int
713 > msg_has_ctrls(const char *message)
714   {
715 <  struct Membership *ms = NULL;
706 <
707 <  if (IsServer(source_p))
708 <    return CAN_SEND_OPV;
715 >  const unsigned char *p = (const unsigned char *)message;
716  
717 <  if (MyClient(source_p) && !IsExemptResv(source_p) &&
711 <      !(IsOper(source_p) && ConfigFileEntry.oper_pass_resv) &&
712 <      (!hash_find_resv(chptr->chname) == ConfigChannel.restrict_channels))
713 <    return CAN_SEND_NO;
714 <
715 <  if ((ms = find_channel_link(source_p, chptr)) == NULL)
716 <  {
717 <    if (chptr->mode.mode & MODE_NOPRIVMSGS)
718 <      return CAN_SEND_NO;
719 <  }
720 <  else
717 >  for (; *p; ++p)
718    {
719 <    if (ms->flags & (CHFL_CHANOP|CHFL_HALFOP|CHFL_VOICE))
720 <      return CAN_SEND_OPV;
719 >    if (*p > 31 || *p == 1)
720 >      continue;  /* No control code or CTCP */
721  
722 <    /* cache can send if quiet_on_ban and banned */
726 <    if (ConfigChannel.quiet_on_ban && MyClient(source_p))
722 >    if (*p == 27)  /* Escape */
723      {
724 <      if (ms->flags & CHFL_BAN_SILENCED)
725 <        return CAN_SEND_NO;
726 <
731 <      if (!(ms->flags & CHFL_BAN_CHECKED))
724 >      /* ISO 2022 charset shift sequence */
725 >      if (*(p + 1) == '$' ||
726 >          *(p + 1) == '(')
727        {
728 <        if (is_banned(chptr, source_p))
729 <        {
735 <          ms->flags |= (CHFL_BAN_CHECKED|CHFL_BAN_SILENCED);
736 <          return CAN_SEND_NO;
737 <        }
738 <
739 <        ms->flags |= CHFL_BAN_CHECKED;
728 >        ++p;
729 >        continue;
730        }
731      }
742  }
732  
733 <  if (chptr->mode.mode & MODE_MODERATED)
734 <    return CAN_SEND_NO;
733 >    return 1;  /* Control code */
734 >  }
735  
736 <  return CAN_SEND_NONOP;
736 >  return 0;  /* No control code found */
737   }
738  
739 < /*! \brief Checks to see if given client can send a part message
740 < * \param member     pointer to channel membership
741 < * \param chptr      pointer to channel struct
742 < * \param source_p   pointer to struct Client to check
739 > /*! Tests if a client can send to a channel
740 > * \param chptr    Pointer to Channel struct
741 > * \param client_p Pointer to Client struct
742 > * \param member   Pointer to Membership struct (can be NULL)
743 > * \param message  The actual message string the client wants to send
744 > * \return CAN_SEND_OPV if op or voiced on channel\n
745 > *         CAN_SEND_NONOP if can send to channel but is not an op\n
746 > *         ERR_CANNOTSENDTOCHAN or ERR_NEEDREGGEDNICK if they cannot send to channel\n
747   */
748   int
749 < can_send_part(struct Membership *member, struct Channel *chptr,
750 <              struct Client *source_p)
749 > can_send(struct Channel *chptr, struct Client *client_p,
750 >         struct Membership *member, const char *message, int notice)
751   {
752 <  if (has_member_flags(member, CHFL_CHANOP|CHFL_HALFOP))
752 >  const struct ResvItem *resv = NULL;
753 >
754 >  if (IsServer(client_p) || HasFlag(client_p, FLAGS_SERVICE))
755      return CAN_SEND_OPV;
756  
757 +  if (MyConnect(client_p) && !HasFlag(client_p, FLAGS_EXEMPTRESV))
758 +    if (!(HasUMode(client_p, UMODE_OPER) && HasOFlag(client_p, OPER_FLAG_JOIN_RESV)))
759 +      if ((resv = resv_find(chptr->name, match)) && !resv_exempt_find(client_p, resv))
760 +        return ERR_CANNOTSENDTOCHAN;
761 +
762 +  if ((chptr->mode.mode & MODE_NOCTRL) && msg_has_ctrls(message))
763 +    return ERR_NOCTRLSONCHAN;
764 +
765 +  if (chptr->mode.mode & MODE_NOCTCP)
766 +    if (*message == '\001' && strncmp(message + 1, "ACTION ", 7))
767 +      return ERR_NOCTCP;
768 +
769 +  if (member || (member = find_channel_link(client_p, chptr)))
770 +    if (member->flags & (CHFL_CHANOP | CHFL_HALFOP | CHFL_VOICE))
771 +      return CAN_SEND_OPV;
772 +
773 +  if (!member && (chptr->mode.mode & MODE_NOPRIVMSGS))
774 +    return ERR_CANNOTSENDTOCHAN;
775 +
776    if (chptr->mode.mode & MODE_MODERATED)
777 <    return CAN_SEND_NO;
777 >    return ERR_CANNOTSENDTOCHAN;
778 >
779 >  if ((chptr->mode.mode & MODE_MODREG) && !HasUMode(client_p, UMODE_REGISTERED))
780 >    return ERR_NEEDREGGEDNICK;
781 >
782 >  if ((chptr->mode.mode & MODE_NONOTICE) && notice)
783 >    return ERR_CANNOTSENDTOCHAN;
784 >
785 >  /* Cache can send if banned */
786 >  if (MyConnect(client_p))
787 >  {
788 >    if (member)
789 >    {
790 >      if (member->flags & CHFL_BAN_SILENCED)
791 >        return ERR_CANNOTSENDTOCHAN;
792 >
793 >      if (!(member->flags & CHFL_BAN_CHECKED))
794 >      {
795 >        if (is_banned(chptr, client_p))
796 >        {
797 >          member->flags |= (CHFL_BAN_CHECKED | CHFL_BAN_SILENCED);
798 >          return ERR_CANNOTSENDTOCHAN;
799 >        }
800  
801 <  if (ConfigChannel.quiet_on_ban && MyClient(source_p) &&
802 <      is_banned(chptr, source_p))
803 <    return CAN_SEND_NO;
801 >        member->flags |= CHFL_BAN_CHECKED;
802 >      }
803 >    }
804 >    else if (is_banned(chptr, client_p))
805 >      return ERR_CANNOTSENDTOCHAN;
806 >  }
807  
808    return CAN_SEND_NONOP;
809   }
# Line 772 | Line 811 | can_send_part(struct Membership *member,
811   /*! \brief Updates the client's oper_warn_count_down, warns the
812   *         IRC operators if necessary, and updates
813   *         join_leave_countdown as needed.
814 < * \param source_p pointer to struct Client to check
815 < * \param name     channel name or NULL if this is a part.
814 > * \param client_p Pointer to struct Client to check
815 > * \param name     Channel name or NULL if this is a part.
816   */
817   void
818 < check_spambot_warning(struct Client *source_p, const char *name)
818 > check_spambot_warning(struct Client *client_p, const char *name)
819   {
820    int t_delta = 0;
821    int decrement_count = 0;
822  
823    if ((GlobalSetOptions.spam_num &&
824 <       (source_p->localClient->join_leave_count >=
824 >       (client_p->connection->join_leave_count >=
825          GlobalSetOptions.spam_num)))
826    {
827 <    if (source_p->localClient->oper_warn_count_down > 0)
828 <      source_p->localClient->oper_warn_count_down--;
827 >    if (client_p->connection->oper_warn_count_down > 0)
828 >      client_p->connection->oper_warn_count_down--;
829      else
830 <      source_p->localClient->oper_warn_count_down = 0;
830 >      client_p->connection->oper_warn_count_down = 0;
831  
832 <    if (source_p->localClient->oper_warn_count_down == 0)
832 >    if (client_p->connection->oper_warn_count_down == 0)
833      {
834 <      /* Its already known as a possible spambot */
835 <      if (name != NULL)
836 <        sendto_realops_flags(UMODE_BOTS, L_ALL,
834 >      /* It's already known as a possible spambot */
835 >      if (name)
836 >        sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE,
837                               "User %s (%s@%s) trying to join %s is a possible spambot",
838 <                             source_p->name, source_p->username,
839 <                             source_p->host, name);
838 >                             client_p->name, client_p->username,
839 >                             client_p->host, name);
840        else
841 <        sendto_realops_flags(UMODE_BOTS, L_ALL,
841 >        sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE,
842                               "User %s (%s@%s) is a possible spambot",
843 <                             source_p->name, source_p->username,
844 <                             source_p->host);
845 <      source_p->localClient->oper_warn_count_down = OPER_SPAM_COUNTDOWN;
843 >                             client_p->name, client_p->username,
844 >                             client_p->host);
845 >      client_p->connection->oper_warn_count_down = OPER_SPAM_COUNTDOWN;
846      }
847    }
848    else
849    {
850 <    if ((t_delta = (CurrentTime - source_p->localClient->last_leave_time)) >
850 >    if ((t_delta = (CurrentTime - client_p->connection->last_leave_time)) >
851           JOIN_LEAVE_COUNT_EXPIRE_TIME)
852      {
853        decrement_count = (t_delta / JOIN_LEAVE_COUNT_EXPIRE_TIME);
854 <      if (decrement_count > source_p->localClient->join_leave_count)
855 <        source_p->localClient->join_leave_count = 0;
854 >
855 >      if (decrement_count > client_p->connection->join_leave_count)
856 >        client_p->connection->join_leave_count = 0;
857        else
858 <        source_p->localClient->join_leave_count -= decrement_count;
858 >        client_p->connection->join_leave_count -= decrement_count;
859      }
860      else
861      {
862 <      if ((CurrentTime - (source_p->localClient->last_join_time)) <
862 >      if ((CurrentTime - (client_p->connection->last_join_time)) <
863            GlobalSetOptions.spam_time)
864 <      {
825 <        /* oh, its a possible spambot */
826 <        source_p->localClient->join_leave_count++;
827 <      }
864 >        client_p->connection->join_leave_count++;  /* It's a possible spambot */
865      }
866  
867 <    if (name != NULL)
868 <      source_p->localClient->last_join_time = CurrentTime;
867 >    if (name)
868 >      client_p->connection->last_join_time = CurrentTime;
869      else
870 <      source_p->localClient->last_leave_time = CurrentTime;
870 >      client_p->connection->last_leave_time = CurrentTime;
871    }
872   }
873  
874 < /*! \brief compares usercount and servercount against their split
875 < *         values and adjusts splitmode accordingly
876 < * \param unused Unused address pointer
874 > /*! \brief Sets the channel topic for a certain channel
875 > * \param chptr      Pointer to struct Channel
876 > * \param topic      The topic string
877 > * \param topic_info n!u\@h formatted string of the topic setter
878 > * \param topicts    Timestamp on the topic
879 > * \param local      Whether the topic is set by a local client
880 > */
881 > void
882 > channel_set_topic(struct Channel *chptr, const char *topic,
883 >                  const char *topic_info, uintmax_t topicts, int local)
884 > {
885 >  if (local)
886 >    strlcpy(chptr->topic, topic, IRCD_MIN(sizeof(chptr->topic), ConfigServerInfo.max_topic_length + 1));
887 >  else
888 >    strlcpy(chptr->topic, topic, sizeof(chptr->topic));
889 >
890 >  strlcpy(chptr->topic_info, topic_info, sizeof(chptr->topic_info));
891 >  chptr->topic_time = topicts;
892 > }
893 >
894 > /* do_join_0()
895 > *
896 > * inputs       - pointer to client doing join 0
897 > * output       - NONE
898 > * side effects - Use has decided to join 0. This is legacy
899 > *                from the days when channels were numbers not names. *sigh*
900 > *                There is a bunch of evilness necessary here due to
901 > *                anti spambot code.
902   */
903   void
904 < check_splitmode(void *unused)
904 > channel_do_join_0(struct Client *client_p)
905   {
906 <  if (splitchecking && (ConfigChannel.no_join_on_split ||
907 <                        ConfigChannel.no_create_on_split))
906 >  if (client_p->channel.head)
907 >    if (MyConnect(client_p) && !HasUMode(client_p, UMODE_OPER))
908 >      check_spambot_warning(client_p, NULL);
909 >
910 >  while (client_p->channel.head)
911    {
912 <    const unsigned int server = dlink_list_length(&global_serv_list);
912 >    struct Membership *member = client_p->channel.head->data;
913 >
914 >    sendto_server(client_p, 0, 0, ":%s PART %s",
915 >                  client_p->id, member->chptr->name);
916 >    sendto_channel_local(NULL, member->chptr, 0, 0, 0, ":%s!%s@%s PART %s",
917 >                         client_p->name, client_p->username,
918 >                         client_p->host, member->chptr->name);
919  
920 <    if (!splitmode && ((server < split_servers) || (Count.total < split_users)))
920 >    remove_user_from_channel(member);
921 >  }
922 > }
923 >
924 > static char *
925 > channel_find_last0(struct Client *client_p, char *chanlist)
926 > {
927 >  int join0 = 0;
928 >
929 >  for (char *p = chanlist; *p; ++p)  /* Find last "JOIN 0" */
930 >  {
931 >    if (*p == '0' && (*(p + 1) == ',' || *(p + 1) == '\0'))
932      {
933 <      splitmode = 1;
933 >      if (*(p + 1) == ',')
934 >        ++p;
935  
936 <      sendto_realops_flags(UMODE_ALL,L_ALL,
937 <                           "Network split, activating splitmode");
855 <      eventAddIsh("check_splitmode", check_splitmode, NULL, 10);
936 >      chanlist = p + 1;
937 >      join0 = 1;
938      }
939 <    else if (splitmode && (server > split_servers) && (Count.total > split_users))
939 >    else
940      {
941 <      splitmode = 0;
941 >      while (*p != ',' && *p != '\0')  /* Skip past channel name */
942 >        ++p;
943  
944 <      sendto_realops_flags(UMODE_ALL, L_ALL,
945 <                           "Network rejoined, deactivating splitmode");
863 <      eventDelete(check_splitmode, NULL);
944 >      if (*p == '\0')  /* Hit the end */
945 >        break;
946      }
947    }
948 +
949 +  if (join0)
950 +    channel_do_join_0(client_p);
951 +
952 +  return chanlist;
953   }
954  
955 < /*! \brief Allocates a new topic
956 < * \param chptr Channel to allocate a new topic for
870 < */
871 < static void
872 < allocate_topic(struct Channel *chptr)
955 > void
956 > channel_do_join(struct Client *client_p, char *channel, char *key_list)
957   {
958 <  void *ptr = NULL;
958 >  char *p = NULL;
959 >  char *chan_list = NULL;
960 >  const struct ResvItem *resv = NULL;
961 >  const struct ClassItem *const class = get_class_ptr(&client_p->connection->confs);
962 >  unsigned int flags = 0;
963  
964 <  if (chptr == NULL)
877 <    return;
964 >  assert(IsClient(client_p));
965  
966 <  ptr = BlockHeapAlloc(topic_heap);  
966 >  chan_list = channel_find_last0(client_p, channel);
967  
968 <  /* Basically we allocate one large block for the topic and
969 <   * the topic info.  We then split it up into two and shove it
970 <   * in the chptr
971 <   */
885 <  chptr->topic       = ptr;
886 <  chptr->topic_info  = (char *)ptr + TOPICLEN+1;
887 <  *chptr->topic      = '\0';
888 <  *chptr->topic_info = '\0';
889 < }
968 >  for (const char *name = strtok_r(chan_list, ",", &p); name;
969 >                   name = strtok_r(NULL,      ",", &p))
970 >  {
971 >    const char *key = NULL;
972  
973 < void
974 < free_topic(struct Channel *chptr)
975 < {
894 <  void *ptr = NULL;
895 <  assert(chptr);
896 <  if (chptr->topic == NULL)
897 <    return;
973 >    /* If we have any more keys, take the first for this channel. */
974 >    if (!EmptyString(key_list) && (key_list = strchr(key = key_list, ',')))
975 >      *key_list++ = '\0';
976  
977 <  /*
978 <   * If you change allocate_topic you MUST change this as well
979 <   */
980 <  ptr = chptr->topic;
981 <  BlockHeapFree(topic_heap, ptr);    
982 <  chptr->topic      = NULL;
983 <  chptr->topic_info = NULL;
977 >    /* Empty keys are the same as no keys. */
978 >    if (key && *key == '\0')
979 >      key = NULL;
980 >
981 >    if (!channel_check_name(name, 1))
982 >    {
983 >      sendto_one_numeric(client_p, &me, ERR_BADCHANNAME, name);
984 >      continue;
985 >    }
986 >
987 >    if (!HasFlag(client_p, FLAGS_EXEMPTRESV) &&
988 >        !(HasUMode(client_p, UMODE_OPER) && HasOFlag(client_p, OPER_FLAG_JOIN_RESV)) &&
989 >        ((resv = resv_find(name, match)) && !resv_exempt_find(client_p, resv)))
990 >    {
991 >      sendto_one_numeric(client_p, &me, ERR_CHANBANREASON, name, resv->reason);
992 >      sendto_realops_flags(UMODE_REJ, L_ALL, SEND_NOTICE,
993 >                           "Forbidding reserved channel %s from user %s",
994 >                           name, client_get_name(client_p, HIDE_IP));
995 >      continue;
996 >    }
997 >
998 >    if (dlink_list_length(&client_p->channel) >=
999 >        ((class->max_channels) ? class->max_channels : ConfigChannel.max_channels))
1000 >    {
1001 >      sendto_one_numeric(client_p, &me, ERR_TOOMANYCHANNELS, name);
1002 >      break;
1003 >    }
1004 >
1005 >    struct Channel *chptr;
1006 >    if ((chptr = hash_find_channel(name)))
1007 >    {
1008 >      if (IsMember(client_p, chptr))
1009 >        continue;
1010 >
1011 >      /* can_join() checks for +i, +l, key, bans, etc. */
1012 >      int ret = can_join(client_p, chptr, key);
1013 >      if (ret)
1014 >      {
1015 >        sendto_one_numeric(client_p, &me, ret, chptr->name);
1016 >        continue;
1017 >      }
1018 >
1019 >      /*
1020 >       * This should never be the case unless there is some sort of
1021 >       * persistant channels.
1022 >       */
1023 >      if (!dlink_list_length(&chptr->members))
1024 >        flags = CHFL_CHANOP;
1025 >      else
1026 >        flags = 0;
1027 >    }
1028 >    else
1029 >    {
1030 >      flags = CHFL_CHANOP;
1031 >      chptr = channel_make(name);
1032 >    }
1033 >
1034 >    if (!HasUMode(client_p, UMODE_OPER))
1035 >      check_spambot_warning(client_p, chptr->name);
1036 >
1037 >    add_user_to_channel(chptr, client_p, flags, 1);
1038 >
1039 >    /*
1040 >     * Set timestamp if appropriate, and propagate
1041 >     */
1042 >    if (flags == CHFL_CHANOP)
1043 >    {
1044 >      chptr->creationtime = CurrentTime;
1045 >      chptr->mode.mode |= MODE_TOPICLIMIT;
1046 >      chptr->mode.mode |= MODE_NOPRIVMSGS;
1047 >
1048 >      sendto_server(client_p, 0, 0, ":%s SJOIN %ju %s +nt :@%s",
1049 >                    me.id, chptr->creationtime,
1050 >                    chptr->name, client_p->id);
1051 >
1052 >      /*
1053 >       * Notify all other users on the new channel
1054 >       */
1055 >      sendto_channel_local(NULL, chptr, 0, CAP_EXTENDED_JOIN, 0, ":%s!%s@%s JOIN %s %s :%s",
1056 >                           client_p->name, client_p->username,
1057 >                           client_p->host, chptr->name, client_p->account, client_p->info);
1058 >      sendto_channel_local(NULL, chptr, 0, 0, CAP_EXTENDED_JOIN, ":%s!%s@%s JOIN :%s",
1059 >                           client_p->name, client_p->username,
1060 >                           client_p->host, chptr->name);
1061 >      sendto_channel_local(NULL, chptr, 0, 0, 0, ":%s MODE %s +nt",
1062 >                           me.name, chptr->name);
1063 >
1064 >      if (client_p->away[0])
1065 >        sendto_channel_local(client_p, chptr, 0, CAP_AWAY_NOTIFY, 0,
1066 >                             ":%s!%s@%s AWAY :%s",
1067 >                             client_p->name, client_p->username,
1068 >                             client_p->host, client_p->away);
1069 >    }
1070 >    else
1071 >    {
1072 >      sendto_server(client_p, 0, 0, ":%s JOIN %ju %s +",
1073 >                    client_p->id, chptr->creationtime,
1074 >                    chptr->name);
1075 >
1076 >      sendto_channel_local(NULL, chptr, 0, CAP_EXTENDED_JOIN, 0, ":%s!%s@%s JOIN %s %s :%s",
1077 >                           client_p->name, client_p->username,
1078 >                           client_p->host, chptr->name, client_p->account, client_p->info);
1079 >      sendto_channel_local(NULL, chptr, 0, 0, CAP_EXTENDED_JOIN, ":%s!%s@%s JOIN :%s",
1080 >                           client_p->name, client_p->username,
1081 >                           client_p->host, chptr->name);
1082 >
1083 >      if (client_p->away[0])
1084 >        sendto_channel_local(client_p, chptr, 0, CAP_AWAY_NOTIFY, 0,
1085 >                             ":%s!%s@%s AWAY :%s",
1086 >                             client_p->name, client_p->username,
1087 >                             client_p->host, client_p->away);
1088 >    }
1089 >
1090 >    struct Invite *invite = find_invite(chptr, client_p);
1091 >    if (invite)
1092 >      del_invite(invite);
1093 >
1094 >    if (chptr->topic[0])
1095 >    {
1096 >      sendto_one_numeric(client_p, &me, RPL_TOPIC, chptr->name, chptr->topic);
1097 >      sendto_one_numeric(client_p, &me, RPL_TOPICWHOTIME, chptr->name,
1098 >                         chptr->topic_info, chptr->topic_time);
1099 >    }
1100 >
1101 >    channel_member_names(client_p, chptr, 1);
1102 >
1103 >    client_p->connection->last_join_time = CurrentTime;
1104 >  }
1105   }
1106  
1107 < /*! \brief Sets the channel topic for chptr
1108 < * \param chptr      Pointer to struct Channel
1109 < * \param topic      The topic string
1110 < * \param topic_info n!u\@h formatted string of the topic setter
912 < * \param topicts    timestamp on the topic
1107 > /*! \brief Removes a client from a specific channel
1108 > * \param client_p Pointer to client to remove
1109 > * \param name     Name of channel to remove from
1110 > * \param reason   Part reason to show
1111   */
1112 < void
1113 < set_channel_topic(struct Channel *chptr, const char *topic,
916 <                  const char *topic_info, time_t topicts)
1112 > static void
1113 > channel_part_one_client(struct Client *client_p, const char *name, const char *reason)
1114   {
1115 <  if (!EmptyString(topic))
1115 >  struct Channel *chptr = NULL;
1116 >  struct Membership *member = NULL;
1117 >
1118 >  if ((chptr = hash_find_channel(name)) == NULL)
1119    {
1120 <    if (chptr->topic == NULL)
1121 <      allocate_topic(chptr);
1120 >    sendto_one_numeric(client_p, &me, ERR_NOSUCHCHANNEL, name);
1121 >    return;
1122 >  }
1123  
1124 <    strlcpy(chptr->topic, topic, TOPICLEN+1);
1125 <    strlcpy(chptr->topic_info, topic_info, USERHOST_REPLYLEN);
1126 <    chptr->topic_time = topicts;
1124 >  if ((member = find_channel_link(client_p, chptr)) == NULL)
1125 >  {
1126 >    sendto_one_numeric(client_p, &me, ERR_NOTONCHANNEL, chptr->name);
1127 >    return;
1128 >  }
1129 >
1130 >  if (MyConnect(client_p) && !HasUMode(client_p, UMODE_OPER))
1131 >    check_spambot_warning(client_p, NULL);
1132 >
1133 >  /*
1134 >   * Remove user from the old channel (if any)
1135 >   * only allow /part reasons in -m chans
1136 >   */
1137 >  if (*reason && (!MyConnect(client_p) ||
1138 >      ((client_p->connection->firsttime +
1139 >        ConfigGeneral.anti_spam_exit_message_time) < CurrentTime &&
1140 >       can_send(chptr, client_p, member, reason, 0) < 0)))
1141 >  {
1142 >    sendto_server(client_p, 0, 0, ":%s PART %s :%s",
1143 >                  client_p->id, chptr->name, reason);
1144 >    sendto_channel_local(NULL, chptr, 0, 0, 0, ":%s!%s@%s PART %s :%s",
1145 >                         client_p->name, client_p->username,
1146 >                         client_p->host, chptr->name, reason);
1147    }
1148    else
1149    {
1150 <    if (chptr->topic != NULL)
1151 <      free_topic(chptr);
1152 <
1153 <    chptr->topic_time = 0;
1150 >    sendto_server(client_p, 0, 0, ":%s PART %s",
1151 >                  client_p->id, chptr->name);
1152 >    sendto_channel_local(NULL, chptr, 0, 0, 0, ":%s!%s@%s PART %s",
1153 >                         client_p->name, client_p->username,
1154 >                         client_p->host, chptr->name);
1155    }
1156 +
1157 +  remove_user_from_channel(member);
1158   }
1159  
1160 + void
1161 + channel_do_part(struct Client *client_p, char *channel, const char *reason)
1162 + {
1163 +  char *p = NULL;
1164 +  char buf[KICKLEN + 1] = "";
1165 +
1166 +  assert(IsClient(client_p));
1167 +
1168 +  if (!EmptyString(reason))
1169 +    strlcpy(buf, reason, sizeof(buf));
1170 +
1171 +  for (const char *name = strtok_r(channel, ",", &p); name;
1172 +                   name = strtok_r(NULL,    ",", &p))
1173 +    channel_part_one_client(client_p, name, buf);
1174 + }

Comparing:
ircd-hybrid/src/channel.c (property svn:keywords), Revision 32 by knight, Sun Oct 2 20:41:23 2005 UTC vs.
ircd-hybrid/trunk/src/channel.c (property svn:keywords), Revision 8003 by michael, Tue Mar 14 14:21:14 2017 UTC

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

Diff Legend

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