ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/channel.c
Revision: 3471
Committed: Sun May 4 15:11:32 2014 UTC (11 years, 3 months ago) by michael
Content type: text/x-csrc
File size: 24107 byte(s)
Log Message:
- channel.c:send_members(): added missing #ifdef HALFOPS

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

Properties

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