ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/branches/ircd-hybrid-newconf/src/channel.c
Revision: 398
Committed: Tue Feb 7 12:00:21 2006 UTC (20 years, 6 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid/src/channel.c
File size: 25218 byte(s)
Log Message:
- Ripped out lazylinks as discussed on irc. the main concept wasn't very well
  designed and will be done in a better way some day.  Anyways, they propably
  never worked and were considered bloat by most people.  Good bye!

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

Properties

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