ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/channel.c
Revision: 456
Committed: Sun Feb 12 20:17:29 2006 UTC (18 years, 2 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-7.2/src/channel.c
File size: 25206 byte(s)
Log Message:
- Unbreak can_send

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

Properties

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