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

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 6982 by michael, Wed Dec 23 19:49:38 2015 UTC

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

Diff Legend

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