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

Comparing:
ircd-hybrid-7.2/src/channel.c (property svn:keywords), Revision 572 by michael, Sun Apr 30 16:57:48 2006 UTC vs.
ircd-hybrid/trunk/src/channel.c (property svn:keywords), Revision 7766 by michael, Fri Oct 7 16:27:37 2016 UTC

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

Diff Legend

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