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

Properties

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