ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/src/channel.c
Revision: 3140
Committed: Wed Mar 12 19:23:20 2014 UTC (11 years, 5 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid/trunk/src/channel.c
File size: 24177 byte(s)
Log Message:
- Get rid of halfop -> op rewriting for servers that don't support halfops

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

Properties

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