ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.0.x/src/channel.c
Revision: 1156
Committed: Tue Aug 9 20:29:20 2011 UTC (12 years, 7 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-8/src/channel.c
File size: 24762 byte(s)
Log Message:
- create ircd-hybrid-8 "branch"

File Contents

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

Properties

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