ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/channel.c
Revision: 2943
Committed: Sun Jan 26 15:42:53 2014 UTC (11 years, 7 months ago) by michael
Content type: text/x-csrc
File size: 24979 byte(s)
Log Message:
- channel_mode.c, channel.c: removed unused header include

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

Properties

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