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

Comparing:
ircd-hybrid-7.2/src/channel.c (property svn:keywords), Revision 456 by michael, Sun Feb 12 20:17:29 2006 UTC vs.
ircd-hybrid/trunk/src/channel.c (property svn:keywords), Revision 8367 by michael, Mon Mar 5 19:51:42 2018 UTC

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

Diff Legend

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