ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/channel.c
Revision: 3183
Committed: Thu Mar 20 16:49:21 2014 UTC (11 years, 5 months ago) by michael
Content type: text/x-csrc
File size: 24040 byte(s)
Log Message:
- Cleanup some places where we no longer need to use ID_or_name()

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

Properties

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