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/trunk/src/channel.c (file contents):
Revision 3144 by michael, Wed Mar 12 20:02:20 2014 UTC vs.
Revision 7766 by michael, Fri Oct 7 16:27:37 2016 UTC

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

Comparing ircd-hybrid/trunk/src/channel.c (property svn:keywords):
Revision 3144 by michael, Wed Mar 12 20:02:20 2014 UTC vs.
Revision 7766 by michael, Fri Oct 7 16:27:37 2016 UTC

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

Diff Legend

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