ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/src/channel.c
Revision: 3186
Committed: Thu Mar 20 18:09:34 2014 UTC (10 years ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid/trunk/src/channel.c
File size: 24040 byte(s)
Log Message:
- Get rid of the ID() macro

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 1997-2014 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
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 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19 * USA
20 */
21
22 /*! \file channel.c
23 * \brief Responsible for managing channels, members, bans and topics
24 * \version $Id$
25 */
26
27 #include "stdinc.h"
28 #include "list.h"
29 #include "channel.h"
30 #include "channel_mode.h"
31 #include "client.h"
32 #include "hash.h"
33 #include "conf.h"
34 #include "hostmask.h"
35 #include "irc_string.h"
36 #include "ircd.h"
37 #include "numeric.h"
38 #include "s_serv.h"
39 #include "send.h"
40 #include "event.h"
41 #include "memory.h"
42 #include "mempool.h"
43 #include "s_misc.h"
44 #include "resv.h"
45
46 dlink_list global_channel_list = { NULL, NULL, 0 };
47 mp_pool_t *ban_pool; /*! \todo ban_pool shouldn't be a global var */
48
49 static mp_pool_t *member_pool = NULL;
50 static mp_pool_t *channel_pool = NULL;
51
52 static char buf[IRCD_BUFSIZE];
53
54
55 /*! \brief Initializes the channel blockheap, adds known channel CAPAB
56 */
57 void
58 channel_init(void)
59 {
60 add_capability("EX", CAP_EX, 1);
61 add_capability("IE", CAP_IE, 1);
62
63 channel_pool = mp_pool_new(sizeof(struct Channel), MP_CHUNK_SIZE_CHANNEL);
64 ban_pool = mp_pool_new(sizeof(struct Ban), MP_CHUNK_SIZE_BAN);
65 member_pool = mp_pool_new(sizeof(struct Membership), MP_CHUNK_SIZE_MEMBER);
66 }
67
68 /*! \brief adds a user to a channel by adding another link to the
69 * channels member chain.
70 * \param chptr pointer to channel to add client to
71 * \param who pointer to client (who) to add
72 * \param flags flags for chanops etc
73 * \param flood_ctrl whether to count this join in flood calculations
74 */
75 void
76 add_user_to_channel(struct Channel *chptr, struct Client *who,
77 unsigned int flags, int flood_ctrl)
78 {
79 struct Membership *ms = NULL;
80
81 if (GlobalSetOptions.joinfloodtime > 0)
82 {
83 if (flood_ctrl)
84 chptr->number_joined++;
85
86 chptr->number_joined -= (CurrentTime - chptr->last_join_time) *
87 (((float)GlobalSetOptions.joinfloodcount) /
88 (float)GlobalSetOptions.joinfloodtime);
89
90 if (chptr->number_joined <= 0)
91 {
92 chptr->number_joined = 0;
93 ClearJoinFloodNoticed(chptr);
94 }
95 else if (chptr->number_joined >= GlobalSetOptions.joinfloodcount)
96 {
97 chptr->number_joined = GlobalSetOptions.joinfloodcount;
98
99 if (!IsSetJoinFloodNoticed(chptr))
100 {
101 SetJoinFloodNoticed(chptr);
102 sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE,
103 "Possible Join Flooder %s on %s target: %s",
104 get_client_name(who, HIDE_IP),
105 who->servptr->name, chptr->chname);
106 }
107 }
108
109 chptr->last_join_time = CurrentTime;
110 }
111
112 ms = mp_pool_get(member_pool);
113 memset(ms, 0, sizeof(*ms));
114
115 ms->client_p = who;
116 ms->chptr = chptr;
117 ms->flags = flags;
118
119 dlinkAdd(ms, &ms->channode, &chptr->members);
120 dlinkAdd(ms, &ms->usernode, &who->channel);
121 }
122
123 /*! \brief deletes an user from a channel by removing a link in the
124 * channels member chain.
125 * \param member pointer to Membership struct
126 */
127 void
128 remove_user_from_channel(struct Membership *member)
129 {
130 struct Client *client_p = member->client_p;
131 struct Channel *chptr = member->chptr;
132
133 dlinkDelete(&member->channode, &chptr->members);
134 dlinkDelete(&member->usernode, &client_p->channel);
135
136 mp_pool_release(member);
137
138 if (chptr->members.head == NULL)
139 destroy_channel(chptr);
140 }
141
142 /* send_members()
143 *
144 * inputs -
145 * output - NONE
146 * side effects -
147 */
148 static void
149 send_members(struct Client *client_p, struct Channel *chptr,
150 char *modebuf, char *parabuf)
151 {
152 const dlink_node *ptr = NULL;
153 int tlen; /* length of text to append */
154 char *t, *start; /* temp char pointer */
155
156 start = t = buf + snprintf(buf, sizeof(buf), ":%s SJOIN %lu %s %s %s:",
157 me.id, (unsigned long)chptr->channelts,
158 chptr->chname, modebuf, parabuf);
159
160 DLINK_FOREACH(ptr, chptr->members.head)
161 {
162 const struct Membership *ms = ptr->data;
163
164 tlen = strlen(ms->client_p->id) + 1; /* nick + space */
165
166 if (ms->flags & CHFL_CHANOP)
167 tlen++;
168 #ifdef HALFOPS
169 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..
176 * That's why we use '- 1' here
177 * -adx */
178 if (t + tlen - buf > IRCD_BUFSIZE - 1)
179 {
180 *(t - 1) = '\0'; /* kill the space and terminate the string */
181 sendto_one(client_p, "%s", buf);
182 t = start;
183 }
184
185 if (ms->flags & CHFL_CHANOP)
186 *t++ = '@';
187 if (ms->flags & CHFL_HALFOP)
188 *t++ = '%';
189 if (ms->flags & CHFL_VOICE)
190 *t++ = '+';
191
192 strcpy(t, ms->client_p->id);
193
194 t += strlen(t);
195 *t++ = ' ';
196 }
197
198 /* should always be non-NULL unless we have a kind of persistent channels */
199 if (chptr->members.head != NULL)
200 t--; /* take the space out */
201 *t = '\0';
202 sendto_one(client_p, "%s", buf);
203 }
204
205 /*! \brief sends +b/+e/+I
206 * \param client_p client pointer to server
207 * \param chptr pointer to channel
208 * \param top pointer to top of mode link list to send
209 * \param flag char flag flagging type of mode. Currently this can be 'b', e' or 'I'
210 */
211 static void
212 send_mode_list(struct Client *client_p, struct Channel *chptr,
213 const dlink_list *top, char flag)
214 {
215 const dlink_node *lp = NULL;
216 char pbuf[IRCD_BUFSIZE];
217 int tlen, mlen, cur_len, count = 0;
218 char *pp = pbuf;
219
220 if (top == NULL || top->length == 0)
221 return;
222
223 mlen = snprintf(buf, sizeof(buf), ":%s BMASK %lu %s %c :", me.id,
224 (unsigned long)chptr->channelts, chptr->chname, flag);
225 cur_len = mlen;
226
227 DLINK_FOREACH(lp, top->head)
228 {
229 const struct Ban *banptr = lp->data;
230
231 tlen = banptr->len + 3;
232
233 /*
234 * send buffer and start over if we cannot fit another ban,
235 * or if the target is non-ts6 and we have too many modes in
236 * in this line.
237 */
238 if (cur_len + (tlen - 1) > IRCD_BUFSIZE - 2)
239 {
240 *(pp - 1) = '\0'; /* get rid of trailing space on buffer */
241 sendto_one(client_p, "%s%s", buf, pbuf);
242
243 cur_len = mlen;
244 pp = pbuf;
245 count = 0;
246 }
247
248 count++;
249 pp += sprintf(pp, "%s!%s@%s ", banptr->name, banptr->user,
250 banptr->host);
251 cur_len += tlen;
252 }
253
254 *(pp - 1) = '\0'; /* get rid of trailing space on buffer */
255 sendto_one(client_p, "%s%s", buf, pbuf);
256 }
257
258 /*! \brief send "client_p" a full list of the modes for channel chptr
259 * \param client_p pointer to client client_p
260 * \param chptr pointer to channel pointer
261 */
262 void
263 send_channel_modes(struct Client *client_p, struct Channel *chptr)
264 {
265 char modebuf[MODEBUFLEN] = "";
266 char parabuf[MODEBUFLEN] = "";
267
268 channel_modes(chptr, client_p, modebuf, parabuf);
269 send_members(client_p, chptr, modebuf, parabuf);
270
271 send_mode_list(client_p, chptr, &chptr->banlist, 'b');
272 send_mode_list(client_p, chptr, &chptr->exceptlist, 'e');
273 send_mode_list(client_p, chptr, &chptr->invexlist, 'I');
274 }
275
276 /*! \brief check channel name for invalid characters
277 * \param name pointer to channel name string
278 * \param local indicates whether it's a local or remote creation
279 * \return 0 if invalid, 1 otherwise
280 */
281 int
282 check_channel_name(const char *name, const int local)
283 {
284 const char *p = name;
285 const int max_length = local ? LOCAL_CHANNELLEN : CHANNELLEN;
286 assert(name != NULL);
287
288 if (!IsChanPrefix(*p))
289 return 0;
290
291 if (!local || !ConfigChannel.disable_fake_channels)
292 {
293 while (*++p)
294 if (!IsChanChar(*p))
295 return 0;
296 }
297 else
298 {
299 while (*++p)
300 if (!IsVisibleChanChar(*p))
301 return 0;
302 }
303
304 return p - name <= max_length;
305 }
306
307 void
308 remove_ban(struct Ban *bptr, dlink_list *list)
309 {
310 dlinkDelete(&bptr->node, list);
311
312 MyFree(bptr->name);
313 MyFree(bptr->user);
314 MyFree(bptr->host);
315 MyFree(bptr->who);
316
317 mp_pool_release(bptr);
318 }
319
320 /* free_channel_list()
321 *
322 * inputs - pointer to dlink_list
323 * output - NONE
324 * side effects -
325 */
326 void
327 free_channel_list(dlink_list *list)
328 {
329 dlink_node *ptr = NULL, *next_ptr = NULL;
330
331 DLINK_FOREACH_SAFE(ptr, next_ptr, list->head)
332 remove_ban(ptr->data, list);
333
334 assert(list->tail == NULL && list->head == NULL);
335 }
336
337 /*! \brief Get Channel block for chname (and allocate a new channel
338 * block, if it didn't exist before)
339 * \param chname channel name
340 * \return channel block
341 */
342 struct Channel *
343 make_channel(const char *chname)
344 {
345 struct Channel *chptr = NULL;
346
347 assert(!EmptyString(chname));
348
349 chptr = mp_pool_get(channel_pool);
350
351 memset(chptr, 0, sizeof(*chptr));
352
353 /* doesn't hurt to set it here */
354 chptr->channelts = CurrentTime;
355 chptr->last_join_time = CurrentTime;
356
357 strlcpy(chptr->chname, chname, sizeof(chptr->chname));
358 dlinkAdd(chptr, &chptr->node, &global_channel_list);
359
360 hash_add_channel(chptr);
361
362 return chptr;
363 }
364
365 /*! \brief walk through this channel, and destroy it.
366 * \param chptr channel pointer
367 */
368 void
369 destroy_channel(struct Channel *chptr)
370 {
371 dlink_node *ptr = NULL, *ptr_next = NULL;
372
373 DLINK_FOREACH_SAFE(ptr, ptr_next, chptr->invites.head)
374 del_invite(chptr, ptr->data);
375
376 /* free ban/exception/invex lists */
377 free_channel_list(&chptr->banlist);
378 free_channel_list(&chptr->exceptlist);
379 free_channel_list(&chptr->invexlist);
380
381 dlinkDelete(&chptr->node, &global_channel_list);
382 hash_del_channel(chptr);
383
384 mp_pool_release(chptr);
385 }
386
387 /*!
388 * \param chptr pointer to channel
389 * \return string pointer "=" if public, "@" if secret else "*"
390 */
391 static const char *
392 channel_pub_or_secret(const struct Channel *chptr)
393 {
394 if (SecretChannel(chptr))
395 return "@";
396 if (PrivateChannel(chptr))
397 return "*";
398 return "=";
399 }
400
401 /*! \brief lists all names on given channel
402 * \param source_p pointer to client struct requesting names
403 * \param chptr pointer to channel block
404 * \param show_eon show ENDOFNAMES numeric or not
405 * (don't want it with /names with no params)
406 */
407 void
408 channel_member_names(struct Client *source_p, struct Channel *chptr,
409 int show_eon)
410 {
411 const dlink_node *ptr = NULL;
412 char lbuf[IRCD_BUFSIZE + 1];
413 char *t = NULL, *start = NULL;
414 int tlen = 0;
415 int is_member = IsMember(source_p, chptr);
416 int multi_prefix = HasCap(source_p, CAP_MULTI_PREFIX) != 0;
417 int uhnames = HasCap(source_p, CAP_UHNAMES) != 0;
418
419 if (PubChannel(chptr) || is_member)
420 {
421 t = lbuf + snprintf(lbuf, sizeof(lbuf), numeric_form(RPL_NAMREPLY),
422 me.name, source_p->name,
423 channel_pub_or_secret(chptr), chptr->chname);
424 start = t;
425
426 DLINK_FOREACH(ptr, chptr->members.head)
427 {
428 const struct Membership *ms = ptr->data;
429
430 if (HasUMode(ms->client_p, UMODE_INVISIBLE) && !is_member)
431 continue;
432
433 if (!uhnames)
434 tlen = strlen(ms->client_p->name) + 1; /* nick + space */
435 else
436 tlen = strlen(ms->client_p->name) + strlen(ms->client_p->username) +
437 strlen(ms->client_p->host) + 3;
438
439 if (!multi_prefix)
440 {
441 if (ms->flags & (CHFL_CHANOP | CHFL_HALFOP | CHFL_VOICE))
442 ++tlen;
443 }
444 else
445 {
446 if (ms->flags & CHFL_CHANOP)
447 ++tlen;
448 if (ms->flags & CHFL_HALFOP)
449 ++tlen;
450 if (ms->flags & CHFL_VOICE)
451 ++tlen;
452 }
453
454 if (t + tlen - lbuf > IRCD_BUFSIZE - 2)
455 {
456 *(t - 1) = '\0';
457 sendto_one(source_p, "%s", lbuf);
458 t = start;
459 }
460
461 if (!uhnames)
462 t += sprintf(t, "%s%s ", get_member_status(ms, multi_prefix),
463 ms->client_p->name);
464 else
465 t += sprintf(t, "%s%s!%s@%s ", get_member_status(ms, multi_prefix),
466 ms->client_p->name, ms->client_p->username,
467 ms->client_p->host);
468 }
469
470 if (tlen != 0)
471 {
472 *(t - 1) = '\0';
473 sendto_one(source_p, "%s", lbuf);
474 }
475 }
476
477 if (show_eon)
478 sendto_one_numeric(source_p, &me, RPL_ENDOFNAMES, chptr->chname);
479 }
480
481 /*! \brief adds client to invite list
482 * \param chptr pointer to channel block
483 * \param who pointer to client to add invite to
484 */
485 void
486 add_invite(struct Channel *chptr, struct Client *who)
487 {
488 del_invite(chptr, who);
489
490 /*
491 * delete last link in chain if the list is max length
492 */
493 if (dlink_list_length(&who->localClient->invited) >=
494 ConfigChannel.max_chans_per_user)
495 del_invite(who->localClient->invited.tail->data, who);
496
497 /* add client to channel invite list */
498 dlinkAdd(who, make_dlink_node(), &chptr->invites);
499
500 /* add channel to the end of the client invite list */
501 dlinkAdd(chptr, make_dlink_node(), &who->localClient->invited);
502 }
503
504 /*! \brief Delete Invite block from channel invite list
505 * and client invite list
506 * \param chptr pointer to Channel struct
507 * \param who pointer to client to remove invites from
508 */
509 void
510 del_invite(struct Channel *chptr, struct Client *who)
511 {
512 dlink_node *ptr = NULL;
513
514 if ((ptr = dlinkFindDelete(&who->localClient->invited, chptr)))
515 free_dlink_node(ptr);
516
517 if ((ptr = dlinkFindDelete(&chptr->invites, who)))
518 free_dlink_node(ptr);
519 }
520
521 /* get_member_status()
522 *
523 * inputs - pointer to struct Membership
524 * - YES if we can combine different flags
525 * output - string either @, +, % or "" depending on whether
526 * chanop, voiced or user
527 * side effects -
528 *
529 * NOTE: Returned string is usually a static buffer
530 * (like in get_client_name)
531 */
532 const char *
533 get_member_status(const struct Membership *ms, const int combine)
534 {
535 static char buffer[4];
536 char *p = buffer;
537
538 if (ms->flags & CHFL_CHANOP)
539 {
540 if (!combine)
541 return "@";
542 *p++ = '@';
543 }
544
545 #ifdef HALFOPS
546 if (ms->flags & CHFL_HALFOP)
547 {
548 if (!combine)
549 return "%";
550 *p++ = '%';
551 }
552 #endif
553
554 if (ms->flags & CHFL_VOICE)
555 *p++ = '+';
556 *p = '\0';
557
558 return buffer;
559 }
560
561 /*!
562 * \param who pointer to Client to check
563 * \param list pointer to ban list to search
564 * \return 1 if ban found for given n!u\@h mask, 0 otherwise
565 *
566 */
567 static int
568 find_bmask(const struct Client *who, const dlink_list *const list)
569 {
570 const dlink_node *ptr = NULL;
571
572 DLINK_FOREACH(ptr, list->head)
573 {
574 const struct Ban *bp = ptr->data;
575
576 if (!match(bp->name, who->name) && !match(bp->user, who->username))
577 {
578 switch (bp->type)
579 {
580 case HM_HOST:
581 if (!match(bp->host, who->host) || !match(bp->host, who->sockhost))
582 return 1;
583 break;
584 case HM_IPV4:
585 if (who->localClient->aftype == AF_INET)
586 if (match_ipv4(&who->localClient->ip, &bp->addr, bp->bits))
587 return 1;
588 break;
589 #ifdef IPV6
590 case HM_IPV6:
591 if (who->localClient->aftype == AF_INET6)
592 if (match_ipv6(&who->localClient->ip, &bp->addr, bp->bits))
593 return 1;
594 break;
595 #endif
596 default:
597 assert(0);
598 }
599 }
600 }
601
602 return 0;
603 }
604
605 /*!
606 * \param chptr pointer to channel block
607 * \param who pointer to client to check access fo
608 * \return 0 if not banned, 1 otherwise
609 */
610 int
611 is_banned(const struct Channel *chptr, const struct Client *who)
612 {
613 if (find_bmask(who, &chptr->banlist))
614 if (!find_bmask(who, &chptr->exceptlist))
615 return 1;
616
617 return 0;
618 }
619
620 /*!
621 * \param source_p pointer to client attempting to join
622 * \param chptr pointer to channel
623 * \param key key sent by client attempting to join if present
624 * \return ERR_BANNEDFROMCHAN, ERR_INVITEONLYCHAN, ERR_CHANNELISFULL
625 * or 0 if allowed to join.
626 */
627 int
628 can_join(struct Client *source_p, struct Channel *chptr, const char *key)
629 {
630 if ((chptr->mode.mode & MODE_SSLONLY) && !HasUMode(source_p, UMODE_SSL))
631 return ERR_SSLONLYCHAN;
632
633 if ((chptr->mode.mode & MODE_REGONLY) && !HasUMode(source_p, UMODE_REGISTERED))
634 return ERR_NEEDREGGEDNICK;
635
636 if ((chptr->mode.mode & MODE_OPERONLY) && !HasUMode(source_p, UMODE_OPER))
637 return ERR_OPERONLYCHAN;
638
639 if (chptr->mode.mode & MODE_INVITEONLY)
640 if (!dlinkFind(&source_p->localClient->invited, chptr))
641 if (!find_bmask(source_p, &chptr->invexlist))
642 return ERR_INVITEONLYCHAN;
643
644 if (chptr->mode.key[0] && (!key || strcmp(chptr->mode.key, key)))
645 return ERR_BADCHANNELKEY;
646
647 if (chptr->mode.limit && dlink_list_length(&chptr->members) >=
648 chptr->mode.limit)
649 return ERR_CHANNELISFULL;
650
651 if (is_banned(chptr, source_p))
652 return ERR_BANNEDFROMCHAN;
653
654 return 0;
655 }
656
657 int
658 has_member_flags(const struct Membership *ms, const unsigned int flags)
659 {
660 if (ms != NULL)
661 return ms->flags & flags;
662 return 0;
663 }
664
665 struct Membership *
666 find_channel_link(struct Client *client_p, struct Channel *chptr)
667 {
668 dlink_node *ptr = NULL;
669
670 if (!IsClient(client_p))
671 return NULL;
672
673 if (dlink_list_length(&chptr->members) < dlink_list_length(&client_p->channel))
674 {
675 DLINK_FOREACH(ptr, chptr->members.head)
676 if (((struct Membership *)ptr->data)->client_p == client_p)
677 return ptr->data;
678 }
679 else
680 {
681 DLINK_FOREACH(ptr, client_p->channel.head)
682 if (((struct Membership *)ptr->data)->chptr == chptr)
683 return ptr->data;
684 }
685
686 return NULL;
687 }
688
689 /*
690 * Basically the same functionality as in bahamut
691 */
692 static int
693 msg_has_ctrls(const char *message)
694 {
695 const unsigned char *p = (const unsigned char *)message;
696
697 for (; *p; ++p)
698 {
699 if (*p > 31 || *p == 1)
700 continue;
701
702 if (*p == 27)
703 {
704 if (*(p + 1) == '$' ||
705 *(p + 1) == '(')
706 {
707 ++p;
708 continue;
709 }
710 }
711
712 return 1;
713 }
714
715 return 0;
716 }
717
718 /*!
719 * \param chptr pointer to Channel struct
720 * \param source_p pointer to Client struct
721 * \param ms pointer to Membership struct (can be NULL)
722 * \return CAN_SEND_OPV if op or voiced on channel\n
723 * CAN_SEND_NONOP if can send to channel but is not an op\n
724 * ERR_CANNOTSENDTOCHAN or ERR_NEEDREGGEDNICK if they cannot send to channel\n
725 */
726 int
727 can_send(struct Channel *chptr, struct Client *source_p,
728 struct Membership *ms, const char *message)
729 {
730 struct MaskItem *conf = NULL;
731
732 if (IsServer(source_p) || HasFlag(source_p, FLAGS_SERVICE))
733 return CAN_SEND_OPV;
734
735 if (MyClient(source_p) && !IsExemptResv(source_p))
736 if (!(HasUMode(source_p, UMODE_OPER) && ConfigFileEntry.oper_pass_resv))
737 if ((conf = match_find_resv(chptr->chname)) && !resv_find_exempt(source_p, conf))
738 return ERR_CANNOTSENDTOCHAN;
739
740 if ((chptr->mode.mode & MODE_NOCTRL) && msg_has_ctrls(message))
741 return ERR_NOCTRLSONCHAN;
742 if (ms || (ms = find_channel_link(source_p, chptr)))
743 if (ms->flags & (CHFL_CHANOP|CHFL_HALFOP|CHFL_VOICE))
744 return CAN_SEND_OPV;
745 if (!ms && (chptr->mode.mode & MODE_NOPRIVMSGS))
746 return ERR_CANNOTSENDTOCHAN;
747 if (chptr->mode.mode & MODE_MODERATED)
748 return ERR_CANNOTSENDTOCHAN;
749 if ((chptr->mode.mode & MODE_MODREG) && !HasUMode(source_p, UMODE_REGISTERED))
750 return ERR_NEEDREGGEDNICK;
751
752 /* cache can send if banned */
753 if (MyClient(source_p))
754 {
755 if (ms)
756 {
757 if (ms->flags & CHFL_BAN_SILENCED)
758 return ERR_CANNOTSENDTOCHAN;
759
760 if (!(ms->flags & CHFL_BAN_CHECKED))
761 {
762 if (is_banned(chptr, source_p))
763 {
764 ms->flags |= (CHFL_BAN_CHECKED|CHFL_BAN_SILENCED);
765 return ERR_CANNOTSENDTOCHAN;
766 }
767
768 ms->flags |= CHFL_BAN_CHECKED;
769 }
770 }
771 else if (is_banned(chptr, source_p))
772 return ERR_CANNOTSENDTOCHAN;
773 }
774
775 return CAN_SEND_NONOP;
776 }
777
778 /*! \brief Updates the client's oper_warn_count_down, warns the
779 * IRC operators if necessary, and updates
780 * join_leave_countdown as needed.
781 * \param source_p pointer to struct Client to check
782 * \param name channel name or NULL if this is a part.
783 */
784 void
785 check_spambot_warning(struct Client *source_p, const char *name)
786 {
787 int t_delta = 0;
788 int decrement_count = 0;
789
790 if ((GlobalSetOptions.spam_num &&
791 (source_p->localClient->join_leave_count >=
792 GlobalSetOptions.spam_num)))
793 {
794 if (source_p->localClient->oper_warn_count_down > 0)
795 source_p->localClient->oper_warn_count_down--;
796 else
797 source_p->localClient->oper_warn_count_down = 0;
798
799 if (source_p->localClient->oper_warn_count_down == 0)
800 {
801 /* Its already known as a possible spambot */
802 if (name != NULL)
803 sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE,
804 "User %s (%s@%s) trying to join %s is a possible spambot",
805 source_p->name, source_p->username,
806 source_p->host, name);
807 else
808 sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE,
809 "User %s (%s@%s) is a possible spambot",
810 source_p->name, source_p->username,
811 source_p->host);
812 source_p->localClient->oper_warn_count_down = OPER_SPAM_COUNTDOWN;
813 }
814 }
815 else
816 {
817 if ((t_delta = (CurrentTime - source_p->localClient->last_leave_time)) >
818 JOIN_LEAVE_COUNT_EXPIRE_TIME)
819 {
820 decrement_count = (t_delta / JOIN_LEAVE_COUNT_EXPIRE_TIME);
821 if (decrement_count > source_p->localClient->join_leave_count)
822 source_p->localClient->join_leave_count = 0;
823 else
824 source_p->localClient->join_leave_count -= decrement_count;
825 }
826 else
827 {
828 if ((CurrentTime - (source_p->localClient->last_join_time)) <
829 GlobalSetOptions.spam_time)
830 {
831 /* oh, its a possible spambot */
832 source_p->localClient->join_leave_count++;
833 }
834 }
835
836 if (name != NULL)
837 source_p->localClient->last_join_time = CurrentTime;
838 else
839 source_p->localClient->last_leave_time = CurrentTime;
840 }
841 }
842
843 /*! \brief compares usercount and servercount against their split
844 * values and adjusts splitmode accordingly
845 * \param unused Unused address pointer
846 */
847 void
848 check_splitmode(void *unused)
849 {
850 if (splitchecking && (ConfigChannel.no_join_on_split ||
851 ConfigChannel.no_create_on_split))
852 {
853 const unsigned int server = dlink_list_length(&global_serv_list);
854
855 if (!splitmode && ((server < split_servers) || (Count.total < split_users)))
856 {
857 splitmode = 1;
858
859 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
860 "Network split, activating splitmode");
861 eventAddIsh("check_splitmode", check_splitmode, NULL, 10);
862 }
863 else if (splitmode && (server > split_servers) && (Count.total > split_users))
864 {
865 splitmode = 0;
866
867 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
868 "Network rejoined, deactivating splitmode");
869 eventDelete(check_splitmode, NULL);
870 }
871 }
872 }
873
874 /*! \brief Sets the channel topic for chptr
875 * \param chptr Pointer to struct Channel
876 * \param topic The topic string
877 * \param topic_info n!u\@h formatted string of the topic setter
878 * \param topicts timestamp on the topic
879 */
880 void
881 set_channel_topic(struct Channel *chptr, const char *topic,
882 const char *topic_info, time_t topicts, int local)
883 {
884 if (local)
885 strlcpy(chptr->topic, topic, IRCD_MIN(sizeof(chptr->topic), ServerInfo.max_topic_length + 1));
886 else
887 strlcpy(chptr->topic, topic, sizeof(chptr->topic));
888
889 strlcpy(chptr->topic_info, topic_info, sizeof(chptr->topic_info));
890 chptr->topic_time = topicts;
891 }

Properties

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