ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/channel.c
Revision: 3022
Committed: Mon Feb 24 20:41:16 2014 UTC (11 years, 6 months ago) by michael
Content type: text/x-csrc
File size: 24936 byte(s)
Log Message:
- Moved "struct config_channel_entry ConfigChannel" from channel.c to conf.c

File Contents

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

Properties

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