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 1858 by michael, Thu Apr 25 15:00:52 2013 UTC vs.
Revision 7997 by michael, Tue Mar 14 13:17:52 2017 UTC

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

Comparing ircd-hybrid/trunk/src/channel.c (property svn:keywords):
Revision 1858 by michael, Thu Apr 25 15:00:52 2013 UTC vs.
Revision 7997 by michael, Tue Mar 14 13:17:52 2017 UTC

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

Diff Legend

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