ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/channel.c
Revision: 3135
Committed: Mon Mar 10 21:11:25 2014 UTC (12 years, 6 months ago) by michael
Content type: text/x-csrc
File size: 24229 byte(s)
Log Message:
- Server now no longer accepts TS5 links

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

Properties

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