ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/channel.c
Revision: 9234
Committed: Fri Jan 31 17:38:34 2020 UTC (6 years, 8 months ago) by michael
Content type: text/x-csrc
File size: 34276 byte(s)
Log Message:
- Extbans have been implemented. Main implementation done by Adam for p4.
  Currently supported extbans:

  Matching:

   $a:<account>   Matches users logged into a matching account.
   $c:<channel>   Matches users that are on the given channel. An additional
                  prefix of either @, %, or + can be specified to test for
                  certain channel privileges.
   $o:<class>     Matches IRC operators that have joined a class
                  matching the mask.
   $r:<realname>  Matches users with a matching realname.
   $s:<server>    Matches users that are connected to a server matching the mask.
   $u:<modes>     Matches users having the specified user modes set or not set.
   $z:<certfp>    Matches users having the given TLS certificate fingerprint.

  Acting:

   $j:<banmask>   Prevents matching users from joining the channel.
   $m:<banmask>   Blocks messages from matching users. Users with voice
                  or above are not affected.

File Contents

# User Rev Content
1 adx 30 /*
2 michael 2916 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 adx 30 *
4 michael 9101 * Copyright (c) 1997-2020 ircd-hybrid development team
5 adx 30 *
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
8     * the Free Software Foundation; either version 2 of the License, or
9     * (at your option) any later version.
10     *
11     * This program is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
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 michael 4565 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 adx 30 * USA
20     */
21    
22     /*! \file channel.c
23     * \brief Responsible for managing channels, members, bans and topics
24 knight 31 * \version $Id$
25 adx 30 */
26    
27     #include "stdinc.h"
28 michael 1011 #include "list.h"
29 adx 30 #include "channel.h"
30     #include "channel_mode.h"
31     #include "client.h"
32     #include "hash.h"
33 michael 1632 #include "conf.h"
34 michael 7234 #include "conf_resv.h"
35 michael 371 #include "hostmask.h"
36 adx 30 #include "irc_string.h"
37     #include "ircd.h"
38     #include "numeric.h"
39 michael 3347 #include "server.h"
40 adx 30 #include "send.h"
41     #include "event.h"
42     #include "memory.h"
43 michael 3347 #include "misc.h"
44 michael 9234 #include "extban.h"
45 adx 30
46 michael 3235
47 michael 8439 /** Doubly linked list containing a list of all channels. */
48     static dlink_list channel_list;
49 adx 30
50    
51 michael 8439 /*! \brief Returns the channel_list as constant
52     * \return channel_list
53     */
54     const dlink_list *
55     channel_get_list(void)
56     {
57     return &channel_list;
58     }
59    
60 michael 3308 /*! \brief Adds a user to a channel by adding another link to the
61 adx 30 * channels member chain.
62 michael 9081 * \param channel Pointer to channel to add client to
63 michael 6681 * \param client_p Pointer to client (who) to add
64 michael 3308 * \param flags Flags for chanops etc
65     * \param flood_ctrl Whether to count this join in flood calculations
66 adx 30 */
67     void
68 michael 9081 add_user_to_channel(struct Channel *channel, struct Client *client_p,
69 michael 8664 unsigned int flags, bool flood_ctrl)
70 adx 30 {
71 michael 6681 assert(IsClient(client_p));
72 michael 5590
73 michael 7779 if (GlobalSetOptions.joinfloodtime)
74 adx 30 {
75 michael 8664 if (flood_ctrl == true)
76 michael 9081 ++channel->number_joined;
77 adx 30
78 michael 9081 channel->number_joined -= (event_base->time.sec_monotonic - channel->last_join_time) *
79 adx 30 (((float)GlobalSetOptions.joinfloodcount) /
80     (float)GlobalSetOptions.joinfloodtime);
81    
82 michael 9081 if (channel->number_joined <= 0)
83 adx 30 {
84 michael 9081 channel->number_joined = 0;
85     ClearJoinFloodNoticed(channel);
86 adx 30 }
87 michael 9081 else if (channel->number_joined >= GlobalSetOptions.joinfloodcount)
88 adx 30 {
89 michael 9081 channel->number_joined = GlobalSetOptions.joinfloodcount;
90 adx 30
91 michael 9081 if (!IsSetJoinFloodNoticed(channel))
92 adx 30 {
93 michael 9081 SetJoinFloodNoticed(channel);
94 michael 1618 sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE,
95 adx 30 "Possible Join Flooder %s on %s target: %s",
96 michael 7997 client_get_name(client_p, HIDE_IP),
97 michael 9081 client_p->servptr->name, channel->name);
98 adx 30 }
99     }
100    
101 michael 9081 channel->last_join_time = event_base->time.sec_monotonic;
102 adx 30 }
103    
104 michael 9081 struct ChannelMember *member = xcalloc(sizeof(*member));
105     member->client = client_p;
106     member->channel = channel;
107 michael 4815 member->flags = flags;
108 adx 30
109 michael 9081 dlinkAdd(member, &member->channode, &channel->members);
110 michael 4170
111 michael 6681 if (MyConnect(client_p))
112 michael 9081 dlinkAdd(member, &member->locchannode, &channel->members_local);
113 michael 4170
114 michael 6681 dlinkAdd(member, &member->usernode, &client_p->channel);
115 adx 30 }
116    
117 michael 3308 /*! \brief Deletes an user from a channel by removing a link in the
118 adx 30 * channels member chain.
119 michael 3308 * \param member Pointer to Membership struct
120 adx 30 */
121     void
122 michael 9081 remove_user_from_channel(struct ChannelMember *member)
123 adx 30 {
124 michael 9081 struct Client *const client_p = member->client;
125     struct Channel *const channel = member->channel;
126 adx 30
127 michael 9081 dlinkDelete(&member->channode, &channel->members);
128 michael 4170
129     if (MyConnect(client_p))
130 michael 9081 dlinkDelete(&member->locchannode, &channel->members_local);
131 michael 4170
132 adx 30 dlinkDelete(&member->usernode, &client_p->channel);
133    
134 michael 8385 xfree(member);
135 adx 30
136 michael 9081 if (channel->members.head == NULL)
137     channel_free(channel);
138 adx 30 }
139    
140 michael 6373 /* channel_send_members()
141 adx 30 *
142     * inputs -
143     * output - NONE
144     * side effects -
145     */
146     static void
147 michael 9081 channel_send_members(struct Client *client_p, const struct Channel *channel,
148 michael 7797 const char *modebuf, const char *parabuf)
149 adx 30 {
150 michael 8059 dlink_node *node;
151 michael 9086 char buf[IRCD_BUFSIZE];
152 adx 30 int tlen; /* length of text to append */
153     char *t, *start; /* temp char pointer */
154    
155 michael 6782 start = t = buf + snprintf(buf, sizeof(buf), ":%s SJOIN %ju %s %s %s:",
156 michael 9081 me.id, channel->creation_time,
157     channel->name, modebuf, parabuf);
158 adx 30
159 michael 9081 DLINK_FOREACH(node, channel->members.head)
160 adx 30 {
161 michael 9081 const struct ChannelMember *member = node->data;
162 adx 30
163 michael 9081 tlen = strlen(member->client->id) + 1; /* +1 for space */
164 adx 30
165 michael 4815 if (member->flags & CHFL_CHANOP)
166 michael 3250 ++tlen;
167 michael 4815 if (member->flags & CHFL_HALFOP)
168 michael 3250 ++tlen;
169 michael 4815 if (member->flags & CHFL_VOICE)
170 michael 3250 ++tlen;
171 adx 30
172 michael 3250 /*
173     * Space will be converted into CR, but we also need space for LF..
174 michael 3782 * That's why we use '- 1' here -adx
175 michael 3250 */
176 michael 1330 if (t + tlen - buf > IRCD_BUFSIZE - 1)
177 adx 30 {
178 michael 3250 *(t - 1) = '\0'; /* Kill the space and terminate the string */
179 adx 30 sendto_one(client_p, "%s", buf);
180     t = start;
181     }
182    
183 michael 4815 if (member->flags & CHFL_CHANOP)
184 michael 3140 *t++ = '@';
185 michael 4815 if (member->flags & CHFL_HALFOP)
186 michael 3140 *t++ = '%';
187 michael 4815 if (member->flags & CHFL_VOICE)
188 adx 356 *t++ = '+';
189 adx 30
190 michael 9081 strcpy(t, member->client->id);
191 michael 3135
192 adx 30 t += strlen(t);
193     *t++ = ' ';
194     }
195    
196 michael 3250 /* Should always be non-NULL unless we have a kind of persistent channels */
197 michael 9081 if (channel->members.head)
198 michael 8431 --t; /* Take the space out */
199 adx 30 *t = '\0';
200     sendto_one(client_p, "%s", buf);
201     }
202    
203 michael 3308 /*! \brief Sends +b/+e/+I
204     * \param client_p Client pointer to server
205 michael 9081 * \param channel Pointer to channel
206 michael 3997 * \param list Pointer to list of modes to send
207 michael 3308 * \param flag Char flag flagging type of mode. Currently this can be 'b', e' or 'I'
208 adx 30 */
209     static void
210 michael 9081 channel_send_mask_list(struct Client *client_p, const struct Channel *channel,
211 michael 6373 const dlink_list *list, const char flag)
212 adx 30 {
213 michael 7687 dlink_node *node;
214 michael 9086 char mbuf[IRCD_BUFSIZE];
215     char pbuf[IRCD_BUFSIZE];
216 michael 3523 int tlen, mlen, cur_len;
217 michael 3144 char *pp = pbuf;
218 adx 30
219 michael 8447 if (dlink_list_length(list) == 0)
220 adx 30 return;
221    
222 michael 6782 mlen = snprintf(mbuf, sizeof(mbuf), ":%s BMASK %ju %s %c :", me.id,
223 michael 9081 channel->creation_time, channel->name, flag);
224 michael 3135 cur_len = mlen;
225 adx 30
226 michael 4800 DLINK_FOREACH(node, list->head)
227 adx 30 {
228 michael 4815 const struct Ban *ban = node->data;
229 adx 30
230 michael 9234 tlen = ban->banstr_len + 1; /* +1 for space */
231 adx 30
232     /*
233 michael 3996 * Send buffer and start over if we cannot fit another ban
234 adx 30 */
235 michael 3135 if (cur_len + (tlen - 1) > IRCD_BUFSIZE - 2)
236 adx 30 {
237 michael 3250 *(pp - 1) = '\0'; /* Get rid of trailing space on buffer */
238 michael 4388 sendto_one(client_p, "%s%s", mbuf, pbuf);
239 adx 30
240 michael 3135 cur_len = mlen;
241 adx 30 pp = pbuf;
242     }
243    
244 michael 9234 pp += sprintf(pp, "%s ", ban->banstr);
245 adx 30 cur_len += tlen;
246     }
247    
248 michael 3250 *(pp - 1) = '\0'; /* Get rid of trailing space on buffer */
249 michael 4388 sendto_one(client_p, "%s%s", mbuf, pbuf);
250 adx 30 }
251    
252 michael 9081 /*! \brief Send "client_p" a full list of the modes for channel channel
253 michael 3308 * \param client_p Pointer to client client_p
254 michael 9081 * \param channel Pointer to channel pointer
255 adx 30 */
256     void
257 michael 9081 channel_send_modes(struct Client *client_p, const struct Channel *channel)
258 adx 30 {
259 michael 3145 char modebuf[MODEBUFLEN] = "";
260     char parabuf[MODEBUFLEN] = "";
261    
262 michael 9081 channel_modes(channel, client_p, modebuf, parabuf);
263     channel_send_members(client_p, channel, modebuf, parabuf);
264 adx 30
265 michael 9081 channel_send_mask_list(client_p, channel, &channel->banlist, 'b');
266     channel_send_mask_list(client_p, channel, &channel->exceptlist, 'e');
267     channel_send_mask_list(client_p, channel, &channel->invexlist, 'I');
268 adx 30 }
269    
270 michael 3308 /*! \brief Check channel name for invalid characters
271     * \param name Pointer to channel name string
272     * \param local Indicates whether it's a local or remote creation
273 michael 632 * \return 0 if invalid, 1 otherwise
274 adx 30 */
275 michael 8660 bool
276     channel_check_name(const char *name, bool local)
277 adx 30 {
278 michael 632 const char *p = name;
279 michael 3421
280 michael 5590 assert(!EmptyString(p));
281 adx 30
282 michael 632 if (!IsChanPrefix(*p))
283 michael 8660 return false;
284 adx 30
285 michael 8660 if (local == false || ConfigChannel.disable_fake_channels == 0)
286 michael 632 {
287     while (*++p)
288 db 634 if (!IsChanChar(*p))
289 michael 8660 return false;
290 michael 632 }
291     else
292     {
293     while (*++p)
294 db 634 if (!IsVisibleChanChar(*p))
295 michael 8660 return false;
296 michael 632 }
297    
298 michael 3421 return p - name <= CHANNELLEN;
299 adx 30 }
300    
301     void
302 michael 4815 remove_ban(struct Ban *ban, dlink_list *list)
303 adx 30 {
304 michael 4815 dlinkDelete(&ban->node, list);
305 michael 8385 xfree(ban);
306 adx 30 }
307    
308 michael 6373 /* channel_free_mask_list()
309 adx 30 *
310     * inputs - pointer to dlink_list
311     * output - NONE
312     * side effects -
313     */
314 michael 6373 static void
315     channel_free_mask_list(dlink_list *list)
316 adx 30 {
317 michael 7266 while (list->head)
318     {
319     struct Ban *ban = list->head->data;
320     remove_ban(ban, list);
321     }
322 adx 30 }
323    
324 michael 4618 /*! \brief Get Channel block for name (and allocate a new channel
325 adx 30 * block, if it didn't exist before)
326 michael 4618 * \param name Channel name
327 michael 3308 * \return Channel block
328 adx 30 */
329     struct Channel *
330 michael 6373 channel_make(const char *name)
331 adx 30 {
332 michael 4618 assert(!EmptyString(name));
333 adx 30
334 michael 9081 struct Channel *channel = xcalloc(sizeof(*channel));
335     channel->hnextch = channel;
336 michael 3308 /* Doesn't hurt to set it here */
337 michael 9081 channel->creation_time = event_base->time.sec_real;
338     channel->last_join_time = event_base->time.sec_monotonic;
339 adx 30
340 michael 8027 /* Cache channel name length to avoid repetitive strlen() calls. */
341 michael 9081 channel->name_len = strlcpy(channel->name, name, sizeof(channel->name));
342     if (channel->name_len >= sizeof(channel->name))
343     channel->name_len = sizeof(channel->name) - 1;
344 michael 6990
345 michael 9081 dlinkAdd(channel, &channel->node, &channel_list);
346     hash_add_channel(channel);
347 adx 30
348 michael 9081 return channel;
349 adx 30 }
350    
351 michael 3308 /*! \brief Walk through this channel, and destroy it.
352 michael 9081 * \param channel Channel pointer
353 adx 30 */
354     void
355 michael 9081 channel_free(struct Channel *channel)
356 adx 30 {
357 michael 9081 clear_invite_list(&channel->invites);
358 adx 30
359 michael 3308 /* Free ban/exception/invex lists */
360 michael 9081 channel_free_mask_list(&channel->banlist);
361     channel_free_mask_list(&channel->exceptlist);
362     channel_free_mask_list(&channel->invexlist);
363 adx 30
364 michael 9081 dlinkDelete(&channel->node, &channel_list);
365     hash_del_channel(channel);
366 adx 30
367 michael 9081 assert(channel->hnextch == channel);
368 michael 8588
369 michael 9081 assert(channel->node.prev == NULL);
370     assert(channel->node.next == NULL);
371 michael 8588
372 michael 9081 assert(dlink_list_length(&channel->members_local) == 0);
373     assert(channel->members_local.head == NULL);
374     assert(channel->members_local.tail == NULL);
375 michael 8588
376 michael 9081 assert(dlink_list_length(&channel->members) == 0);
377     assert(channel->members.head == NULL);
378     assert(channel->members.tail == NULL);
379 michael 8588
380 michael 9081 assert(dlink_list_length(&channel->invites) == 0);
381     assert(channel->invites.head == NULL);
382     assert(channel->invites.tail == NULL);
383 michael 8588
384 michael 9081 assert(dlink_list_length(&channel->banlist) == 0);
385     assert(channel->banlist.head == NULL);
386     assert(channel->banlist.tail == NULL);
387 michael 8588
388 michael 9081 assert(dlink_list_length(&channel->exceptlist) == 0);
389     assert(channel->exceptlist.head == NULL);
390     assert(channel->exceptlist.tail == NULL);
391 michael 8588
392 michael 9081 assert(dlink_list_length(&channel->invexlist) == 0);
393     assert(channel->invexlist.head == NULL);
394     assert(channel->invexlist.tail == NULL);
395 michael 8588
396 michael 9081 xfree(channel);
397 adx 30 }
398    
399     /*!
400 michael 9081 * \param channel Pointer to channel
401 michael 3308 * \return String pointer "=" if public, "@" if secret else "*"
402 adx 30 */
403     static const char *
404 michael 9081 channel_pub_or_secret(const struct Channel *channel)
405 adx 30 {
406 michael 9081 if (SecretChannel(channel))
407 adx 30 return "@";
408 michael 9081 if (PrivateChannel(channel))
409 adx 30 return "*";
410     return "=";
411     }
412    
413     /*! \brief lists all names on given channel
414 michael 6681 * \param client_p Pointer to client struct requesting names
415 michael 9081 * \param channel Pointer to channel block
416 michael 3308 * \param show_eon Show RPL_ENDOFNAMES numeric or not
417 adx 30 * (don't want it with /names with no params)
418     */
419     void
420 michael 9081 channel_member_names(struct Client *client_p, struct Channel *channel, bool show_eon)
421 adx 30 {
422 michael 7687 dlink_node *node;
423 michael 9086 char buf[IRCD_BUFSIZE + 1];
424 adx 30 int tlen = 0;
425 michael 9081 bool is_member = IsMember(client_p, channel);
426 michael 8656 bool multi_prefix = HasCap(client_p, CAP_MULTI_PREFIX) != 0;
427     bool uhnames = HasCap(client_p, CAP_UHNAMES) != 0;
428 adx 30
429 michael 6681 assert(IsClient(client_p));
430 michael 5590
431 michael 9081 if (PubChannel(channel) || is_member == true)
432 adx 30 {
433 michael 9086 char *t = buf + snprintf(buf, sizeof(buf), numeric_form(RPL_NAMREPLY), me.name, client_p->name,
434     channel_pub_or_secret(channel), channel->name);
435     char *start = t;
436 adx 30
437 michael 9081 DLINK_FOREACH(node, channel->members.head)
438 adx 30 {
439 michael 9081 const struct ChannelMember *member = node->data;
440 adx 30
441 michael 9081 if (HasUMode(member->client, UMODE_INVISIBLE) && is_member == false)
442 adx 30 continue;
443    
444 michael 8656 if (uhnames == true)
445 michael 9081 tlen = strlen(member->client->name) + strlen(member->client->username) +
446     strlen(member->client->host) + 3; /* +3 for ! + @ + space */
447 michael 8431 else
448 michael 9081 tlen = strlen(member->client->name) + 1; /* +1 for space */
449 adx 30
450 michael 8656 if (multi_prefix == true)
451 michael 506 {
452 michael 4815 if (member->flags & CHFL_CHANOP)
453 michael 506 ++tlen;
454 michael 4815 if (member->flags & CHFL_HALFOP)
455 michael 506 ++tlen;
456 michael 4815 if (member->flags & CHFL_VOICE)
457 michael 506 ++tlen;
458     }
459 michael 8431 else
460     {
461     if (member->flags & (CHFL_CHANOP | CHFL_HALFOP | CHFL_VOICE))
462     ++tlen;
463     }
464 michael 506
465 michael 4388 if (t + tlen - buf > IRCD_BUFSIZE - 2)
466 adx 30 {
467     *(t - 1) = '\0';
468 michael 6681 sendto_one(client_p, "%s", buf);
469 adx 30 t = start;
470     }
471    
472 michael 8656 if (uhnames == true)
473 michael 4815 t += sprintf(t, "%s%s!%s@%s ", get_member_status(member, multi_prefix),
474 michael 9081 member->client->name, member->client->username,
475     member->client->host);
476 michael 8431 else
477     t += sprintf(t, "%s%s ", get_member_status(member, multi_prefix),
478 michael 9081 member->client->name);
479 adx 30 }
480    
481 michael 3215 if (tlen)
482 adx 30 {
483     *(t - 1) = '\0';
484 michael 6681 sendto_one(client_p, "%s", buf);
485 adx 30 }
486     }
487    
488 michael 8656 if (show_eon == true)
489 michael 9081 sendto_one_numeric(client_p, &me, RPL_ENDOFNAMES, channel->name);
490 adx 30 }
491    
492 michael 7549 static struct Invite *
493 michael 9081 find_invite(struct Channel *channel, struct Client *client_p)
494 michael 7549 {
495     dlink_node *node, *node_next;
496     dlink_list *list;
497    
498 michael 7793 /* Take the shortest of the two lists */
499 michael 9081 if (dlink_list_length(&client_p->connection->invited) < dlink_list_length(&channel->invites))
500 michael 7549 list = &client_p->connection->invited;
501     else
502 michael 9081 list = &channel->invites;
503 michael 7549
504     DLINK_FOREACH_SAFE(node, node_next, list->head)
505     {
506     struct Invite *invite = node->data;
507    
508 michael 7793 if (ConfigChannel.invite_expire_time &&
509 michael 8903 ConfigChannel.invite_expire_time + invite->when < event_base->time.sec_monotonic)
510 michael 7793 del_invite(invite);
511 michael 9081 else if (invite->channel == channel && invite->client == client_p)
512 michael 7549 return invite;
513     }
514    
515     return NULL;
516     }
517    
518 michael 3308 /*! \brief Adds client to invite list
519 michael 9081 * \param channel Pointer to channel block
520 michael 6681 * \param client_p Pointer to client to add invite to
521 adx 30 */
522     void
523 michael 9081 add_invite(struct Channel *channel, struct Client *client_p)
524 adx 30 {
525 michael 9200 struct Invite *invite = find_invite(channel, client_p);
526     if (invite)
527 michael 7549 del_invite(invite);
528 adx 30
529 michael 8385 invite = xcalloc(sizeof(*invite));
530 michael 9081 invite->client = client_p;
531     invite->channel = channel;
532 michael 8903 invite->when = event_base->time.sec_monotonic;
533 michael 7549
534 michael 7542 /* Delete last link in chain if the list is max length */
535     while (dlink_list_length(&client_p->connection->invited) &&
536 michael 7766 dlink_list_length(&client_p->connection->invited) >= ConfigChannel.max_invites)
537 michael 7549 del_invite(client_p->connection->invited.tail->data);
538 adx 30
539 michael 3308 /* Add client to channel invite list */
540 michael 9081 dlinkAdd(invite, &invite->chan_node, &channel->invites);
541 adx 30
542 michael 3308 /* Add channel to the end of the client invite list */
543 michael 7549 dlinkAdd(invite, &invite->user_node, &client_p->connection->invited);
544 adx 30 }
545    
546     /*! \brief Delete Invite block from channel invite list
547     * and client invite list
548 michael 7549 * \param invite Pointer to Invite struct
549 adx 30 */
550     void
551 michael 7549 del_invite(struct Invite *invite)
552 adx 30 {
553 michael 9081 dlinkDelete(&invite->user_node, &invite->client->connection->invited);
554     dlinkDelete(&invite->chan_node, &invite->channel->invites);
555 adx 30
556 michael 7549 /* Release memory pointed to by 'invite' */
557 michael 8385 xfree(invite);
558 adx 30 }
559    
560 michael 7762 /*! \brief Removes and frees all Invite blocks from a list
561     * \param list Pointer to a dlink_list
562 michael 4811 */
563     void
564 michael 7762 clear_invite_list(dlink_list *list)
565 michael 4811 {
566 michael 7762 while (list->head)
567     del_invite(list->head->data);
568 michael 4811 }
569    
570 adx 30 /* get_member_status()
571     *
572 michael 9081 * inputs - pointer to struct ChannelMember
573 adx 30 * - YES if we can combine different flags
574     * output - string either @, +, % or "" depending on whether
575     * chanop, voiced or user
576     * side effects -
577     *
578     * NOTE: Returned string is usually a static buffer
579 michael 7997 * (like in client_get_name)
580 adx 30 */
581     const char *
582 michael 9081 get_member_status(const struct ChannelMember *member, bool combine)
583 adx 30 {
584 michael 6904 static char buffer[CMEMBER_STATUS_FLAGS_LEN + 1]; /* +1 for \0 */
585 michael 1902 char *p = buffer;
586 adx 30
587 michael 4815 if (member->flags & CHFL_CHANOP)
588 adx 30 {
589 michael 8656 if (combine == false)
590 adx 30 return "@";
591     *p++ = '@';
592     }
593    
594 michael 4815 if (member->flags & CHFL_HALFOP)
595 adx 30 {
596 michael 8656 if (combine == false)
597 adx 30 return "%";
598     *p++ = '%';
599     }
600    
601 michael 4815 if (member->flags & CHFL_VOICE)
602 adx 30 *p++ = '+';
603     *p = '\0';
604    
605     return buffer;
606     }
607    
608     /*!
609 michael 6681 * \param client_p Pointer to Client to check
610     * \param list Pointer to ban list to search
611 adx 30 * \return 1 if ban found for given n!u\@h mask, 0 otherwise
612     */
613 michael 8664 static bool
614 michael 9234 ban_matches(struct Client *client_p, struct Channel *channel, struct Ban *ban)
615 adx 30 {
616 michael 9234 /* Is a matching extban, call custom match handler */
617     if (ban->extban & extban_matching_mask())
618     {
619     struct Extban *extban = extban_find_flag(ban->extban & extban_matching_mask());
620     if (extban == NULL)
621     return false;
622    
623     if (extban->matches == NULL || extban->matches(client_p, channel, ban) == EXTBAN_NO_MATCH)
624     return false;
625    
626     return true;
627     }
628    
629     if (match(ban->name, client_p->name) == 0 && match(ban->user, client_p->username) == 0)
630     {
631     switch (ban->type)
632     {
633     case HM_HOST:
634     if (match(ban->host, client_p->realhost) == 0 ||
635     match(ban->host, client_p->sockhost) == 0 || match(ban->host, client_p->host) == 0)
636     return true;
637     break;
638     case HM_IPV4:
639     if (client_p->ip.ss.ss_family == AF_INET)
640     if (match_ipv4(&client_p->ip, &ban->addr, ban->bits))
641     return true;
642     break;
643     case HM_IPV6:
644     if (client_p->ip.ss.ss_family == AF_INET6)
645     if (match_ipv6(&client_p->ip, &ban->addr, ban->bits))
646     return true;
647     break;
648     default:
649     assert(0);
650     }
651     }
652    
653     return false;
654     }
655    
656     bool
657     find_bmask(struct Client *client_p, struct Channel *channel, const dlink_list *list, struct Extban *extban)
658     {
659 michael 7687 dlink_node *node;
660 adx 30
661 michael 4800 DLINK_FOREACH(node, list->head)
662 adx 30 {
663 michael 9234 struct Ban *ban = node->data;
664 adx 30
665 michael 9234 /* Looking for a specific type of extban? */
666     if (extban)
667 michael 371 {
668 michael 9234 if (!(ban->extban & extban->flag))
669     continue;
670 michael 371 }
671 michael 9234 else
672     {
673     /*
674     * Acting extbans have their own time they act and are not general purpose bans,
675     * so skip them unless we are hunting them.
676     */
677     if (ban->extban & extban_acting_mask())
678     continue;
679     }
680    
681     bool matches = ban_matches(client_p, channel, ban);
682     if (matches == false)
683     continue;
684    
685     return true;
686 adx 30 }
687    
688 michael 8664 return false;
689 adx 30 }
690    
691     /*!
692 michael 9081 * \param channel Pointer to channel block
693 michael 6681 * \param client_p Pointer to client to check access fo
694 adx 30 * \return 0 if not banned, 1 otherwise
695     */
696 michael 8664 bool
697 michael 9234 is_banned(struct Channel *channel, struct Client *client_p)
698 adx 30 {
699 michael 9234 if (find_bmask(client_p, channel, &channel->banlist, NULL) == true)
700     return find_bmask(client_p, channel, &channel->exceptlist, NULL) == false;
701 michael 8664 return false;
702 adx 30 }
703    
704 michael 3308 /*! Tests if a client can join a certain channel
705 michael 6681 * \param client_p Pointer to client attempting to join
706 michael 9081 * \param channel Pointer to channel
707 michael 3308 * \param key Key sent by client attempting to join if present
708 adx 30 * \return ERR_BANNEDFROMCHAN, ERR_INVITEONLYCHAN, ERR_CHANNELISFULL
709     * or 0 if allowed to join.
710     */
711 michael 6881 static int
712 michael 9081 can_join(struct Client *client_p, struct Channel *channel, const char *key)
713 adx 30 {
714 michael 9157 if (HasCMode(channel, MODE_SECUREONLY) && !HasUMode(client_p, UMODE_SECURE))
715     return ERR_SECUREONLYCHAN;
716 michael 1150
717 michael 9081 if (HasCMode(channel, MODE_REGONLY) && !HasUMode(client_p, UMODE_REGISTERED))
718 michael 1173 return ERR_NEEDREGGEDNICK;
719    
720 michael 9081 if (HasCMode(channel, MODE_OPERONLY) && !HasUMode(client_p, UMODE_OPER))
721 michael 1150 return ERR_OPERONLYCHAN;
722    
723 michael 9081 if (HasCMode(channel, MODE_INVITEONLY))
724     if (find_invite(channel, client_p) == NULL)
725 michael 9234 if (find_bmask(client_p, channel, &channel->invexlist, NULL) == false)
726 adx 30 return ERR_INVITEONLYCHAN;
727    
728 michael 9081 if (channel->mode.key[0] && (key == NULL || strcmp(channel->mode.key, key)))
729 adx 30 return ERR_BADCHANNELKEY;
730    
731 michael 9081 if (channel->mode.limit && dlink_list_length(&channel->members) >=
732     channel->mode.limit)
733 adx 30 return ERR_CHANNELISFULL;
734    
735 michael 9081 if (is_banned(channel, client_p) == true)
736 michael 2208 return ERR_BANNEDFROMCHAN;
737    
738 michael 9234 return extban_join_can_join(channel, client_p, NULL);
739 adx 30 }
740    
741     int
742 michael 9081 has_member_flags(const struct ChannelMember *member, const unsigned int flags)
743 adx 30 {
744 michael 4815 return member && (member->flags & flags);
745 adx 30 }
746    
747 michael 9081 struct ChannelMember *
748     find_channel_link(const struct Client *client_p, const struct Channel *channel)
749 adx 30 {
750 michael 7914 dlink_node *node;
751 adx 30
752     if (!IsClient(client_p))
753     return NULL;
754    
755 michael 8439 /* Take the shortest of the two lists */
756 michael 9081 if (dlink_list_length(&channel->members) < dlink_list_length(&client_p->channel))
757 michael 2567 {
758 michael 9081 DLINK_FOREACH(node, channel->members.head)
759     if (((struct ChannelMember *)node->data)->client == client_p)
760 michael 4800 return node->data;
761 michael 2567 }
762     else
763     {
764 michael 4800 DLINK_FOREACH(node, client_p->channel.head)
765 michael 9081 if (((struct ChannelMember *)node->data)->channel == channel)
766 michael 4800 return node->data;
767 michael 2567 }
768 adx 30
769     return NULL;
770     }
771    
772 michael 4783 /*! Checks if a message contains control codes
773 michael 3888 * \param message The actual message string the client wants to send
774     * \return 1 if the message does contain any control codes, 0 otherwise
775 michael 1937 */
776 michael 8658 static bool
777 michael 1937 msg_has_ctrls(const char *message)
778     {
779 michael 8805 for (const char *p = message; *p; ++p)
780 michael 1937 {
781     if (*p > 31 || *p == 1)
782 michael 3952 continue; /* No control code or CTCP */
783 michael 1937
784 michael 3888 if (*p == 27) /* Escape */
785 michael 1937 {
786 michael 3888 /* ISO 2022 charset shift sequence */
787 michael 1937 if (*(p + 1) == '$' ||
788     *(p + 1) == '(')
789     {
790     ++p;
791     continue;
792     }
793     }
794    
795 michael 8658 return true; /* Control code */
796 michael 1937 }
797    
798 michael 8658 return false; /* No control code found */
799 michael 1937 }
800    
801 michael 3308 /*! Tests if a client can send to a channel
802 michael 9081 * \param channel Pointer to Channel struct
803 michael 6681 * \param client_p Pointer to Client struct
804 michael 4815 * \param member Pointer to Membership struct (can be NULL)
805 michael 3308 * \param message The actual message string the client wants to send
806 adx 30 * \return CAN_SEND_OPV if op or voiced on channel\n
807     * CAN_SEND_NONOP if can send to channel but is not an op\n
808 michael 1173 * ERR_CANNOTSENDTOCHAN or ERR_NEEDREGGEDNICK if they cannot send to channel\n
809 adx 30 */
810     int
811 michael 9081 can_send(struct Channel *channel, struct Client *client_p,
812     struct ChannelMember *member, const char *message, bool notice)
813 adx 30 {
814 michael 9086 const struct ResvItem *resv;
815 michael 1858
816 michael 6681 if (IsServer(client_p) || HasFlag(client_p, FLAGS_SERVICE))
817 adx 30 return CAN_SEND_OPV;
818    
819 michael 7054 if (MyConnect(client_p) && !HasFlag(client_p, FLAGS_EXEMPTRESV))
820 michael 6681 if (!(HasUMode(client_p, UMODE_OPER) && HasOFlag(client_p, OPER_FLAG_JOIN_RESV)))
821 michael 9081 if ((resv = resv_find(channel->name, match)) && resv_exempt_find(client_p, resv) == false)
822 michael 1834 return ERR_CANNOTSENDTOCHAN;
823 adx 30
824 michael 9081 if (HasCMode(channel, MODE_NOCTRL) && msg_has_ctrls(message) == true)
825 michael 1944 return ERR_NOCTRLSONCHAN;
826 michael 4884
827 michael 9081 if (HasCMode(channel, MODE_NOCTCP))
828 michael 5465 if (*message == '\001' && strncmp(message + 1, "ACTION ", 7))
829 michael 5464 return ERR_NOCTCP;
830    
831 michael 9081 if (member || (member = find_channel_link(client_p, channel)))
832 michael 5583 if (member->flags & (CHFL_CHANOP | CHFL_HALFOP | CHFL_VOICE))
833 adx 30 return CAN_SEND_OPV;
834 michael 4884
835 michael 9081 if (member == NULL && HasCMode(channel, MODE_NOPRIVMSGS))
836 michael 2441 return ERR_CANNOTSENDTOCHAN;
837 michael 4884
838 michael 9081 if (HasCMode(channel, MODE_MODERATED))
839 michael 1944 return ERR_CANNOTSENDTOCHAN;
840 michael 4884
841 michael 9081 if (HasCMode(channel, MODE_MODREG) && !HasUMode(client_p, UMODE_REGISTERED))
842 michael 1944 return ERR_NEEDREGGEDNICK;
843 adx 30
844 michael 9081 if (HasCMode(channel, MODE_NONOTICE) && notice == true)
845 michael 6858 return ERR_CANNOTSENDTOCHAN;
846    
847 michael 3308 /* Cache can send if banned */
848 michael 7054 if (MyConnect(client_p))
849 michael 1944 {
850 michael 4815 if (member)
851 adx 30 {
852 michael 4815 if (member->flags & CHFL_BAN_SILENCED)
853 michael 1834 return ERR_CANNOTSENDTOCHAN;
854 adx 30
855 michael 4815 if (!(member->flags & CHFL_BAN_CHECKED))
856 adx 30 {
857 michael 9081 if (is_banned(channel, client_p) == true)
858 adx 30 {
859 michael 5583 member->flags |= (CHFL_BAN_CHECKED | CHFL_BAN_SILENCED);
860 michael 1834 return ERR_CANNOTSENDTOCHAN;
861 adx 30 }
862    
863 michael 4815 member->flags |= CHFL_BAN_CHECKED;
864 adx 30 }
865     }
866 michael 9081 else if (is_banned(channel, client_p) == true)
867 michael 1941 return ERR_CANNOTSENDTOCHAN;
868     }
869 adx 30
870 michael 9234 return extban_mute_can_send(channel, client_p, member);
871 adx 30 }
872    
873     /*! \brief Updates the client's oper_warn_count_down, warns the
874     * IRC operators if necessary, and updates
875     * join_leave_countdown as needed.
876 michael 6682 * \param client_p Pointer to struct Client to check
877 michael 3308 * \param name Channel name or NULL if this is a part.
878 adx 30 */
879     void
880 michael 6682 check_spambot_warning(struct Client *client_p, const char *name)
881 adx 30 {
882 michael 8274 if (GlobalSetOptions.spam_num &&
883     (client_p->connection->join_leave_count >= GlobalSetOptions.spam_num))
884 adx 30 {
885 michael 8797 if (client_p->connection->oper_warn_count_down)
886     --client_p->connection->oper_warn_count_down;
887 adx 30
888 michael 6682 if (client_p->connection->oper_warn_count_down == 0)
889 adx 30 {
890 michael 3308 /* It's already known as a possible spambot */
891 michael 3235 if (name)
892 michael 1618 sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE,
893 adx 30 "User %s (%s@%s) trying to join %s is a possible spambot",
894 michael 6682 client_p->name, client_p->username,
895     client_p->host, name);
896 adx 30 else
897 michael 1618 sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE,
898 adx 30 "User %s (%s@%s) is a possible spambot",
899 michael 6682 client_p->name, client_p->username,
900     client_p->host);
901     client_p->connection->oper_warn_count_down = OPER_SPAM_COUNTDOWN;
902 adx 30 }
903     }
904     else
905     {
906 michael 8903 unsigned int t_delta = event_base->time.sec_monotonic - client_p->connection->last_leave_time;
907 michael 8276 if (t_delta > JOIN_LEAVE_COUNT_EXPIRE_TIME)
908 adx 30 {
909 michael 8796 unsigned int decrement_count = (t_delta / JOIN_LEAVE_COUNT_EXPIRE_TIME);
910 michael 6682 if (decrement_count > client_p->connection->join_leave_count)
911     client_p->connection->join_leave_count = 0;
912 adx 30 else
913 michael 6682 client_p->connection->join_leave_count -= decrement_count;
914 adx 30 }
915     else
916     {
917 michael 8904 if ((event_base->time.sec_monotonic - client_p->connection->last_join_time) < GlobalSetOptions.spam_time)
918 michael 8805 ++client_p->connection->join_leave_count; /* It's a possible spambot */
919 adx 30 }
920    
921 michael 3215 if (name)
922 michael 8903 client_p->connection->last_join_time = event_base->time.sec_monotonic;
923 adx 30 else
924 michael 8903 client_p->connection->last_leave_time = event_base->time.sec_monotonic;
925 adx 30 }
926     }
927    
928 michael 3308 /*! \brief Sets the channel topic for a certain channel
929 michael 9081 * \param channel Pointer to struct Channel
930 adx 30 * \param topic The topic string
931     * \param topic_info n!u\@h formatted string of the topic setter
932 michael 3308 * \param topicts Timestamp on the topic
933     * \param local Whether the topic is set by a local client
934 adx 30 */
935     void
936 michael 9081 channel_set_topic(struct Channel *channel, const char *topic,
937 michael 8660 const char *topic_info, uintmax_t topicts, bool local)
938 adx 30 {
939 michael 8660 if (local == true)
940 michael 9081 strlcpy(channel->topic, topic, IRCD_MIN(sizeof(channel->topic), ConfigServerInfo.max_topic_length + 1));
941 michael 1751 else
942 michael 9081 strlcpy(channel->topic, topic, sizeof(channel->topic));
943 michael 1751
944 michael 9081 strlcpy(channel->topic_info, topic_info, sizeof(channel->topic_info));
945     channel->topic_time = topicts;
946 adx 30 }
947 michael 3912
948     void
949 michael 8367 channel_do_join(struct Client *client_p, char *chan_list, char *key_list)
950 michael 3912 {
951     char *p = NULL;
952 michael 7282 const struct ResvItem *resv = NULL;
953 michael 8437 const struct ClassItem *const class = class_get_ptr(&client_p->connection->confs);
954 michael 3912 unsigned int flags = 0;
955    
956 michael 8513 assert(MyClient(client_p));
957 michael 5590
958 michael 7908 for (const char *name = strtok_r(chan_list, ",", &p); name;
959     name = strtok_r(NULL, ",", &p))
960 michael 3912 {
961     const char *key = NULL;
962    
963     /* If we have any more keys, take the first for this channel. */
964     if (!EmptyString(key_list) && (key_list = strchr(key = key_list, ',')))
965     *key_list++ = '\0';
966    
967     /* Empty keys are the same as no keys. */
968     if (key && *key == '\0')
969     key = NULL;
970    
971 michael 8660 if (channel_check_name(name, true) == false)
972 michael 3912 {
973 michael 7908 sendto_one_numeric(client_p, &me, ERR_BADCHANNAME, name);
974 michael 3912 continue;
975     }
976    
977 michael 6682 if (!HasFlag(client_p, FLAGS_EXEMPTRESV) &&
978     !(HasUMode(client_p, UMODE_OPER) && HasOFlag(client_p, OPER_FLAG_JOIN_RESV)) &&
979 michael 8658 ((resv = resv_find(name, match)) && resv_exempt_find(client_p, resv) == false))
980 michael 3912 {
981 michael 7908 sendto_one_numeric(client_p, &me, ERR_CHANBANREASON, name, resv->reason);
982 michael 4151 sendto_realops_flags(UMODE_REJ, L_ALL, SEND_NOTICE,
983 michael 3912 "Forbidding reserved channel %s from user %s",
984 michael 7997 name, client_get_name(client_p, HIDE_IP));
985 michael 3912 continue;
986     }
987    
988 michael 6682 if (dlink_list_length(&client_p->channel) >=
989 michael 3933 ((class->max_channels) ? class->max_channels : ConfigChannel.max_channels))
990 michael 3912 {
991 michael 7908 sendto_one_numeric(client_p, &me, ERR_TOOMANYCHANNELS, name);
992 michael 3912 break;
993     }
994    
995 michael 9200 struct Channel *channel = hash_find_channel(name);
996     if (channel)
997 michael 3912 {
998 michael 9081 if (IsMember(client_p, channel))
999 michael 3912 continue;
1000    
1001 michael 7557 /* can_join() checks for +i, +l, key, bans, etc. */
1002 michael 9081 int ret = can_join(client_p, channel, key);
1003 michael 7557 if (ret)
1004 michael 3912 {
1005 michael 9081 sendto_one_numeric(client_p, &me, ret, channel->name);
1006 michael 3912 continue;
1007     }
1008    
1009     /*
1010     * This should never be the case unless there is some sort of
1011     * persistant channels.
1012     */
1013 michael 9081 if (dlink_list_length(&channel->members) == 0)
1014 michael 3912 flags = CHFL_CHANOP;
1015     else
1016     flags = 0;
1017     }
1018     else
1019     {
1020     flags = CHFL_CHANOP;
1021 michael 9081 channel = channel_make(name);
1022 michael 3912 }
1023    
1024 michael 6682 if (!HasUMode(client_p, UMODE_OPER))
1025 michael 9081 check_spambot_warning(client_p, channel->name);
1026 michael 3912
1027 michael 9081 add_user_to_channel(channel, client_p, flags, true);
1028 michael 3912
1029     /*
1030 michael 5545 * Set timestamp if appropriate, and propagate
1031 michael 3912 */
1032     if (flags == CHFL_CHANOP)
1033     {
1034 michael 9081 channel->creation_time = event_base->time.sec_real;
1035     AddCMode(channel, MODE_TOPICLIMIT);
1036     AddCMode(channel, MODE_NOPRIVMSGS);
1037 michael 3912
1038 michael 8513 sendto_server(NULL, 0, 0, ":%s SJOIN %ju %s +nt :@%s",
1039 michael 9081 me.id, channel->creation_time,
1040     channel->name, client_p->id);
1041 michael 3912
1042     /*
1043     * Notify all other users on the new channel
1044     */
1045 michael 9081 sendto_channel_local(NULL, channel, 0, CAP_EXTENDED_JOIN, 0, ":%s!%s@%s JOIN %s %s :%s",
1046 michael 6759 client_p->name, client_p->username,
1047 michael 9081 client_p->host, channel->name, client_p->account, client_p->info);
1048     sendto_channel_local(NULL, channel, 0, 0, CAP_EXTENDED_JOIN, ":%s!%s@%s JOIN :%s",
1049 michael 6759 client_p->name, client_p->username,
1050 michael 9081 client_p->host, channel->name);
1051     sendto_channel_local(NULL, channel, 0, 0, 0, ":%s MODE %s +nt",
1052     me.name, channel->name);
1053 michael 3912 }
1054     else
1055     {
1056 michael 8513 sendto_server(NULL, 0, 0, ":%s JOIN %ju %s +",
1057 michael 9081 client_p->id, channel->creation_time,
1058     channel->name);
1059 michael 3912
1060 michael 9081 sendto_channel_local(NULL, channel, 0, CAP_EXTENDED_JOIN, 0, ":%s!%s@%s JOIN %s %s :%s",
1061 michael 6759 client_p->name, client_p->username,
1062 michael 9081 client_p->host, channel->name, client_p->account, client_p->info);
1063     sendto_channel_local(NULL, channel, 0, 0, CAP_EXTENDED_JOIN, ":%s!%s@%s JOIN :%s",
1064 michael 6759 client_p->name, client_p->username,
1065 michael 9081 client_p->host, channel->name);
1066 michael 3912 }
1067    
1068 michael 8542 if (client_p->away[0])
1069 michael 9081 sendto_channel_local(client_p, channel, 0, CAP_AWAY_NOTIFY, 0,
1070 michael 8542 ":%s!%s@%s AWAY :%s",
1071     client_p->name, client_p->username,
1072     client_p->host, client_p->away);
1073    
1074 michael 9200 struct Invite *invite = find_invite(channel, client_p);
1075     if (invite)
1076 michael 7549 del_invite(invite);
1077 michael 3912
1078 michael 9081 if (channel->topic[0])
1079 michael 3912 {
1080 michael 9081 sendto_one_numeric(client_p, &me, RPL_TOPIC, channel->name, channel->topic);
1081     sendto_one_numeric(client_p, &me, RPL_TOPICWHOTIME, channel->name,
1082     channel->topic_info, channel->topic_time);
1083 michael 3912 }
1084    
1085 michael 9081 channel_member_names(client_p, channel, true);
1086 michael 3912
1087 michael 8903 client_p->connection->last_join_time = event_base->time.sec_monotonic;
1088 michael 3912 }
1089     }
1090    
1091     /*! \brief Removes a client from a specific channel
1092 michael 7612 * \param client_p Pointer to client to remove
1093 michael 3912 * \param name Name of channel to remove from
1094     * \param reason Part reason to show
1095     */
1096     static void
1097 michael 6682 channel_part_one_client(struct Client *client_p, const char *name, const char *reason)
1098 michael 3912 {
1099 michael 9081 struct Channel *channel = NULL;
1100     struct ChannelMember *member = NULL;
1101 michael 3912
1102 michael 9081 if ((channel = hash_find_channel(name)) == NULL)
1103 michael 3912 {
1104 michael 6682 sendto_one_numeric(client_p, &me, ERR_NOSUCHCHANNEL, name);
1105 michael 3912 return;
1106     }
1107    
1108 michael 9081 if ((member = find_channel_link(client_p, channel)) == NULL)
1109 michael 3912 {
1110 michael 9081 sendto_one_numeric(client_p, &me, ERR_NOTONCHANNEL, channel->name);
1111 michael 3912 return;
1112     }
1113    
1114 michael 6682 if (MyConnect(client_p) && !HasUMode(client_p, UMODE_OPER))
1115     check_spambot_warning(client_p, NULL);
1116 michael 3912
1117     /*
1118     * Remove user from the old channel (if any)
1119     * only allow /part reasons in -m chans
1120     */
1121 michael 6682 if (*reason && (!MyConnect(client_p) ||
1122 michael 8919 ((client_p->connection->created_monotonic +
1123     ConfigGeneral.anti_spam_exit_message_time) < event_base->time.sec_monotonic &&
1124 michael 9081 can_send(channel, client_p, member, reason, false) < 0)))
1125 michael 3912 {
1126 michael 6682 sendto_server(client_p, 0, 0, ":%s PART %s :%s",
1127 michael 9081 client_p->id, channel->name, reason);
1128     sendto_channel_local(NULL, channel, 0, 0, 0, ":%s!%s@%s PART %s :%s",
1129 michael 6682 client_p->name, client_p->username,
1130 michael 9081 client_p->host, channel->name, reason);
1131 michael 3912 }
1132     else
1133     {
1134 michael 6682 sendto_server(client_p, 0, 0, ":%s PART %s",
1135 michael 9081 client_p->id, channel->name);
1136     sendto_channel_local(NULL, channel, 0, 0, 0, ":%s!%s@%s PART %s",
1137 michael 6682 client_p->name, client_p->username,
1138 michael 9081 client_p->host, channel->name);
1139 michael 3912 }
1140    
1141 michael 4815 remove_user_from_channel(member);
1142 michael 3912 }
1143    
1144     void
1145 michael 6682 channel_do_part(struct Client *client_p, char *channel, const char *reason)
1146 michael 3912 {
1147 michael 7797 char *p = NULL;
1148 michael 4785 char buf[KICKLEN + 1] = "";
1149 michael 3912
1150 michael 6682 assert(IsClient(client_p));
1151 michael 5590
1152 michael 3937 if (!EmptyString(reason))
1153 michael 4785 strlcpy(buf, reason, sizeof(buf));
1154 michael 3912
1155 michael 7797 for (const char *name = strtok_r(channel, ",", &p); name;
1156     name = strtok_r(NULL, ",", &p))
1157 michael 6682 channel_part_one_client(client_p, name, buf);
1158 michael 3912 }

Properties

Name Value
svn:eol-style native
svn:keywords Id