ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/src/channel.c
Revision: 315
Committed: Fri Dec 23 11:56:34 2005 UTC (20 years, 7 months ago) by michael
Content type: text/x-csrc
File size: 24758 byte(s)
Log Message:
- Moved 'invited' dlink_list to LocalUser struct which will save
  some 1.3mb of ram on a typical efnet server.

File Contents

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

Properties

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