ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/channel.c
Revision: 356
Committed: Mon Jan 2 22:05:15 2006 UTC (18 years, 2 months ago) by adx
Content type: text/x-csrc
Original Path: ircd-hybrid-7.2/src/channel.c
File size: 25307 byte(s)
Log Message:
+ MFC support for halfop->op rewriting.

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

Properties

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