ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/channel.c
(Generate patch)

Comparing:
ircd-hybrid-7.2/src/channel.c (file contents), Revision 632 by michael, Thu Jun 1 10:53:00 2006 UTC vs.
ircd-hybrid/trunk/src/channel.c (file contents), Revision 8439 by michael, Thu Mar 29 13:07:32 2018 UTC

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

Comparing:
ircd-hybrid-7.2/src/channel.c (property svn:keywords), Revision 632 by michael, Thu Jun 1 10:53:00 2006 UTC vs.
ircd-hybrid/trunk/src/channel.c (property svn:keywords), Revision 8439 by michael, Thu Mar 29 13:07:32 2018 UTC

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

Diff Legend

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