ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/channel_mode.c
Revision: 1150
Committed: Wed Aug 3 01:09:49 2011 UTC (14 years ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-7.3/src/channel_mode.c
File size: 50310 byte(s)
Log Message:
- add new channel modes O and S

File Contents

# User Rev Content
1 adx 30 /*
2     * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3     * channel_mode.c: Controls modes on channels.
4     *
5     * Copyright (C) 2005 by the past and present ircd coders, and others.
6     *
7     * This program is free software; you can redistribute it and/or modify
8     * it under the terms of the GNU General Public License as published by
9     * the Free Software Foundation; either version 2 of the License, or
10     * (at your option) any later version.
11     *
12     * This program is distributed in the hope that it will be useful,
13     * but WITHOUT ANY WARRANTY; without even the implied warranty of
14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     * GNU General Public License for more details.
16     *
17     * You should have received a copy of the GNU General Public License
18     * along with this program; if not, write to the Free Software
19     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20     * USA
21     *
22 knight 31 * $Id$
23 adx 30 */
24    
25     #include "stdinc.h"
26 michael 1011 #include "list.h"
27 adx 30 #include "channel.h"
28     #include "channel_mode.h"
29     #include "client.h"
30     #include "common.h"
31     #include "hash.h"
32 michael 371 #include "hostmask.h"
33 adx 30 #include "irc_string.h"
34     #include "sprintf_irc.h"
35     #include "ircd.h"
36     #include "numeric.h"
37     #include "s_serv.h" /* captab */
38     #include "s_user.h"
39     #include "send.h"
40     #include "whowas.h"
41     #include "s_conf.h" /* ConfigFileEntry, ConfigChannel */
42     #include "event.h"
43     #include "memory.h"
44     #include "balloc.h"
45     #include "s_log.h"
46 michael 388 #include "msg.h"
47 adx 30
48     /* some small utility functions */
49     static char *check_string(char *);
50     static char *fix_key(char *);
51     static char *fix_key_old(char *);
52     static void chm_nosuch(struct Client *, struct Client *,
53     struct Channel *, int, int *, char **, int *, int,
54     int, char, void *, const char *);
55     static void chm_simple(struct Client *, struct Client *, struct Channel *,
56     int, int *, char **, int *, int, int, char, void *,
57     const char *);
58     static void chm_limit(struct Client *, struct Client *, struct Channel *,
59     int, int *, char **, int *, int, int, char, void *,
60     const char *);
61     static void chm_key(struct Client *, struct Client *, struct Channel *,
62     int, int *, char **, int *, int, int, char, void *,
63     const char *);
64     static void chm_op(struct Client *, struct Client *, struct Channel *, int,
65     int *, char **, int *, int, int, char, void *,
66     const char *);
67     #ifdef HALFOPS
68     static void chm_hop(struct Client *, struct Client *, struct Channel *, int,
69     int *, char **, int *, int, int, char, void *,
70     const char *);
71     #endif
72     static void chm_voice(struct Client *, struct Client *, struct Channel *,
73     int, int *, char **, int *, int, int, char, void *,
74     const char *);
75     static void chm_ban(struct Client *, struct Client *, struct Channel *, int,
76     int *, char **, int *, int, int, char, void *,
77     const char *);
78     static void chm_except(struct Client *, struct Client *, struct Channel *,
79     int, int *, char **, int *, int, int, char, void *,
80     const char *);
81     static void chm_invex(struct Client *, struct Client *, struct Channel *,
82     int, int *, char **, int *, int, int, char, void *,
83     const char *);
84     static void send_cap_mode_changes(struct Client *, struct Client *,
85 michael 1015 struct Channel *, unsigned int, unsigned int);
86 adx 30 static void send_mode_changes(struct Client *, struct Client *,
87     struct Channel *, char *);
88    
89     /* 10 is a magic number in hybrid 6 NFI where it comes from -db */
90     #define BAN_FUDGE 10
91     #define NCHCAPS (sizeof(channel_capabs)/sizeof(int))
92     #define NCHCAP_COMBOS (1 << NCHCAPS)
93    
94 michael 388 static char nuh_mask[MAXPARA][IRCD_BUFSIZE];
95 adx 30 /* some buffers for rebuilding channel/nick lists with ,'s */
96     static char modebuf[IRCD_BUFSIZE];
97     static char parabuf[MODEBUFLEN];
98     static struct ChModeChange mode_changes[IRCD_BUFSIZE];
99     static int mode_count;
100     static int mode_limit; /* number of modes set other than simple */
101     static int simple_modes_mask; /* bit mask of simple modes already set */
102 adx 356 #ifdef HALFOPS
103     static int channel_capabs[] = { CAP_EX, CAP_IE, CAP_TS6, CAP_HOPS };
104     #else
105 adx 30 static int channel_capabs[] = { CAP_EX, CAP_IE, CAP_TS6 };
106 adx 356 #endif
107 adx 30 static struct ChCapCombo chcap_combos[NCHCAP_COMBOS];
108     extern BlockHeap *ban_heap;
109    
110    
111     /* XXX check_string is propably not longer required in add_id and del_id */
112     /* check_string()
113     *
114     * inputs - string to check
115     * output - pointer to modified string
116     * side effects - Fixes a string so that the first white space found
117     * becomes an end of string marker (`\0`).
118     * returns the 'fixed' string or "*" if the string
119     * was NULL length or a NULL pointer.
120     */
121     static char *
122     check_string(char *s)
123     {
124     char *str = s;
125     static char star[] = "*";
126    
127     if (EmptyString(s))
128 michael 593 return star;
129 adx 30
130     for (; *s; ++s)
131     {
132     if (IsSpace(*s))
133     {
134     *s = '\0';
135     break;
136     }
137     }
138    
139 michael 593 return str;
140 adx 30 }
141    
142     /*
143     * Ban functions to work with mode +b/e/d/I
144     */
145     /* add the specified ID to the channel..
146     * -is 8/9/00
147     */
148    
149     int
150     add_id(struct Client *client_p, struct Channel *chptr, char *banid, int type)
151     {
152 michael 593 dlink_list *list = NULL;
153     dlink_node *ban = NULL;
154 adx 30 size_t len = 0;
155 michael 593 struct Ban *ban_p = NULL;
156 adx 30 unsigned int num_mask;
157 michael 593 char name[NICKLEN];
158     char user[USERLEN + 1];
159     char host[HOSTLEN + 1];
160     struct split_nuh_item nuh;
161 adx 30
162     /* dont let local clients overflow the b/e/I lists */
163     if (MyClient(client_p))
164     {
165     num_mask = dlink_list_length(&chptr->banlist) +
166     dlink_list_length(&chptr->exceptlist) +
167     dlink_list_length(&chptr->invexlist);
168    
169     if (num_mask >= ConfigChannel.max_bans)
170     {
171     sendto_one(client_p, form_str(ERR_BANLISTFULL),
172     me.name, client_p->name, chptr->chname, banid);
173     return 0;
174     }
175    
176     collapse(banid);
177     }
178    
179 michael 593 nuh.nuhmask = check_string(banid);
180     nuh.nickptr = name;
181     nuh.userptr = user;
182     nuh.hostptr = host;
183 adx 30
184 michael 593 nuh.nicksize = sizeof(name);
185     nuh.usersize = sizeof(user);
186     nuh.hostsize = sizeof(host);
187    
188     split_nuh(&nuh);
189    
190 adx 30 /*
191 michael 593 * Re-assemble a new n!u@h and print it back to banid for sending
192 adx 30 * the mode to the channel.
193     */
194     len = ircsprintf(banid, "%s!%s@%s", name, user, host);
195    
196     switch (type)
197     {
198     case CHFL_BAN:
199     list = &chptr->banlist;
200     clear_ban_cache(chptr);
201     break;
202     case CHFL_EXCEPTION:
203     list = &chptr->exceptlist;
204     clear_ban_cache(chptr);
205     break;
206     case CHFL_INVEX:
207     list = &chptr->invexlist;
208     break;
209     default:
210     assert(0);
211     return 0;
212     }
213    
214     DLINK_FOREACH(ban, list->head)
215     {
216 michael 593 ban_p = ban->data;
217     if (!irccmp(ban_p->name, name) &&
218     !irccmp(ban_p->username, user) &&
219     !irccmp(ban_p->host, host))
220 adx 30 {
221     return 0;
222     }
223     }
224    
225 michael 593 ban_p = BlockHeapAlloc(ban_heap);
226 adx 30
227 michael 593 DupString(ban_p->name, name);
228     DupString(ban_p->username, user);
229     DupString(ban_p->host, host);
230    
231     ban_p->when = CurrentTime;
232     ban_p->len = len - 2; /* -2 for @ and ! */
233     ban_p->type = parse_netmask(host, &ban_p->addr, &ban_p->bits);
234    
235 adx 30 if (IsClient(client_p))
236     {
237 michael 593 ban_p->who = MyMalloc(strlen(client_p->name) +
238     strlen(client_p->username) +
239     strlen(client_p->host) + 3);
240     ircsprintf(ban_p->who, "%s!%s@%s", client_p->name,
241     client_p->username, client_p->host);
242 adx 30 }
243     else
244 michael 593 DupString(ban_p->who, client_p->name);
245 adx 30
246 michael 593 dlinkAdd(ban_p, &ban_p->node, list);
247 adx 30
248     return 1;
249     }
250    
251     /*
252     * inputs - pointer to channel
253     * - pointer to ban id
254     * - type of ban, i.e. ban, exception, invex
255     * output - 0 for failure, 1 for success
256     * side effects -
257     */
258     static int
259     del_id(struct Channel *chptr, char *banid, int type)
260     {
261     dlink_list *list;
262     dlink_node *ban;
263     struct Ban *banptr;
264 michael 593 char name[NICKLEN];
265     char user[USERLEN + 1];
266     char host[HOSTLEN + 1];
267     struct split_nuh_item nuh;
268 adx 30
269     if (banid == NULL)
270     return 0;
271    
272 michael 593 nuh.nuhmask = check_string(banid);
273     nuh.nickptr = name;
274     nuh.userptr = user;
275     nuh.hostptr = host;
276 adx 30
277 michael 593 nuh.nicksize = sizeof(name);
278     nuh.usersize = sizeof(user);
279     nuh.hostsize = sizeof(host);
280    
281     split_nuh(&nuh);
282    
283 adx 30 /*
284 michael 593 * Re-assemble a new n!u@h and print it back to banid for sending
285 adx 30 * the mode to the channel.
286     */
287     ircsprintf(banid, "%s!%s@%s", name, user, host);
288    
289     switch (type)
290     {
291     case CHFL_BAN:
292     list = &chptr->banlist;
293     clear_ban_cache(chptr);
294     break;
295     case CHFL_EXCEPTION:
296     list = &chptr->exceptlist;
297     clear_ban_cache(chptr);
298     break;
299     case CHFL_INVEX:
300     list = &chptr->invexlist;
301     break;
302     default:
303     sendto_realops_flags(UMODE_ALL, L_ALL,
304     "del_id() called with unknown ban type %d!", type);
305 michael 593 return 0;
306 adx 30 }
307    
308     DLINK_FOREACH(ban, list->head)
309     {
310     banptr = ban->data;
311    
312     if (!irccmp(name, banptr->name) &&
313 michael 593 !irccmp(user, banptr->username) &&
314     !irccmp(host, banptr->host))
315 adx 30 {
316     remove_ban(banptr, list);
317     return 1;
318     }
319     }
320    
321     return 0;
322     }
323    
324     static const struct mode_letter
325     {
326     const unsigned int mode;
327     const unsigned char letter;
328     } flags[] = {
329     { MODE_INVITEONLY, 'i' },
330     { MODE_MODERATED, 'm' },
331     { MODE_NOPRIVMSGS, 'n' },
332     { MODE_PRIVATE, 'p' },
333     { MODE_SECRET, 's' },
334     { MODE_TOPICLIMIT, 't' },
335 michael 1150 { MODE_OPERONLY, 'O' },
336     { MODE_SSLONLY, 'S' },
337 adx 30 { 0, '\0' }
338     };
339    
340     /* channel_modes()
341     *
342     * inputs - pointer to channel
343     * - pointer to client
344     * - pointer to mode buf
345     * - pointer to parameter buf
346     * output - NONE
347     * side effects - write the "simple" list of channel modes for channel
348     * chptr onto buffer mbuf with the parameters in pbuf.
349     */
350     void
351     channel_modes(struct Channel *chptr, struct Client *client_p,
352     char *mbuf, char *pbuf)
353     {
354     int i;
355    
356     *mbuf++ = '+';
357     *pbuf = '\0';
358    
359     for (i = 0; flags[i].mode; ++i)
360     if (chptr->mode.mode & flags[i].mode)
361     *mbuf++ = flags[i].letter;
362    
363     if (chptr->mode.limit)
364     {
365     *mbuf++ = 'l';
366    
367     if (IsMember(client_p, chptr) || IsServer(client_p))
368     pbuf += ircsprintf(pbuf, "%d ", chptr->mode.limit);
369     }
370    
371     if (chptr->mode.key[0])
372     {
373     *mbuf++ = 'k';
374    
375     if (*pbuf || IsMember(client_p, chptr) || IsServer(client_p))
376     ircsprintf(pbuf, "%s ", chptr->mode.key);
377     }
378    
379     *mbuf = '\0';
380     }
381    
382     /* fix_key()
383     *
384     * inputs - pointer to key to clean up
385     * output - pointer to cleaned up key
386     * side effects - input string is modified
387     *
388     * stolen from Undernet's ircd -orabidoo
389     */
390     static char *
391     fix_key(char *arg)
392     {
393     unsigned char *s, *t, c;
394    
395     for (s = t = (unsigned char *)arg; (c = *s); s++)
396     {
397     c &= 0x7f;
398     if (c != ':' && c > ' ' && c != ',')
399     *t++ = c;
400     }
401    
402     *t = '\0';
403     return(arg);
404     }
405    
406     /* fix_key_old()
407     *
408     * inputs - pointer to key to clean up
409     * output - pointer to cleaned up key
410     * side effects - input string is modifed
411     *
412     * Here we attempt to be compatible with older non-hybrid servers.
413     * We can't back down from the ':' issue however. --Rodder
414     */
415     static char *
416     fix_key_old(char *arg)
417     {
418     unsigned char *s, *t, c;
419    
420     for (s = t = (unsigned char *)arg; (c = *s); s++)
421     {
422     c &= 0x7f;
423     if ((c != 0x0a) && (c != ':') && (c != 0x0d) && (c != ','))
424     *t++ = c;
425     }
426    
427     *t = '\0';
428     return(arg);
429     }
430    
431     /* bitmasks for various error returns that set_channel_mode should only return
432     * once per call -orabidoo
433     */
434    
435     #define SM_ERR_NOTS 0x00000001 /* No TS on channel */
436     #define SM_ERR_NOOPS 0x00000002 /* No chan ops */
437     #define SM_ERR_UNKNOWN 0x00000004
438     #define SM_ERR_RPL_B 0x00000008
439     #define SM_ERR_RPL_E 0x00000010
440     #define SM_ERR_NOTONCHANNEL 0x00000020 /* Not on channel */
441     #define SM_ERR_RPL_I 0x00000040
442 michael 1150 #define SM_ERR_NOTOPER 0x00000080
443 adx 30
444     /* Now lets do some stuff to keep track of what combinations of
445     * servers exist...
446     * Note that the number of combinations doubles each time you add
447     * something to this list. Each one is only quick if no servers use that
448     * combination, but if the numbers get too high here MODE will get too
449     * slow. I suggest if you get more than 7 here, you consider getting rid
450     * of some and merging or something. If it wasn't for irc+cs we would
451     * probably not even need to bother about most of these, but unfortunately
452     * we do. -A1kmm
453     */
454    
455     /* void init_chcap_usage_counts(void)
456     *
457     * Inputs - none
458     * Output - none
459     * Side-effects - Initialises the usage counts to zero. Fills in the
460     * chcap_yes and chcap_no combination tables.
461     */
462     void
463     init_chcap_usage_counts(void)
464     {
465     unsigned long m, c, y, n;
466    
467     memset(chcap_combos, 0, sizeof(chcap_combos));
468    
469     /* For every possible combination */
470     for (m = 0; m < NCHCAP_COMBOS; m++)
471     {
472     /* Check each capab */
473     for (c = y = n = 0; c < NCHCAPS; c++)
474     {
475     if ((m & (1 << c)) == 0)
476     n |= channel_capabs[c];
477     else
478     y |= channel_capabs[c];
479     }
480     chcap_combos[m].cap_yes = y;
481     chcap_combos[m].cap_no = n;
482     }
483     }
484    
485     /* void set_chcap_usage_counts(struct Client *serv_p)
486     * Input: serv_p; The client whose capabs to register.
487     * Output: none
488     * Side-effects: Increments the usage counts for the correct capab
489     * combination.
490     */
491     void
492     set_chcap_usage_counts(struct Client *serv_p)
493     {
494     int n;
495    
496     for (n = 0; n < NCHCAP_COMBOS; n++)
497     {
498     if (((serv_p->localClient->caps & chcap_combos[n].cap_yes) ==
499     chcap_combos[n].cap_yes) &&
500     ((serv_p->localClient->caps & chcap_combos[n].cap_no) == 0))
501     {
502     chcap_combos[n].count++;
503     return;
504     }
505     }
506    
507     /* This should be impossible -A1kmm. */
508     assert(0);
509     }
510    
511     /* void set_chcap_usage_counts(struct Client *serv_p)
512     *
513     * Inputs - serv_p; The client whose capabs to register.
514     * Output - none
515     * Side-effects - Decrements the usage counts for the correct capab
516     * combination.
517     */
518     void
519     unset_chcap_usage_counts(struct Client *serv_p)
520     {
521     int n;
522    
523     for (n = 0; n < NCHCAP_COMBOS; n++)
524     {
525     if ((serv_p->localClient->caps & chcap_combos[n].cap_yes) ==
526     chcap_combos[n].cap_yes &&
527     (serv_p->localClient->caps & chcap_combos[n].cap_no) == 0)
528     {
529     /* Hopefully capabs can't change dynamically or anything... */
530     assert(chcap_combos[n].count > 0);
531     chcap_combos[n].count--;
532     return;
533     }
534     }
535    
536     /* This should be impossible -A1kmm. */
537     assert(0);
538     }
539    
540     /* Mode functions handle mode changes for a particular mode... */
541     static void
542     chm_nosuch(struct Client *client_p, struct Client *source_p,
543     struct Channel *chptr, int parc, int *parn,
544     char **parv, int *errors, int alev, int dir, char c, void *d,
545     const char *chname)
546     {
547     if (*errors & SM_ERR_UNKNOWN)
548     return;
549    
550     *errors |= SM_ERR_UNKNOWN;
551     sendto_one(source_p, form_str(ERR_UNKNOWNMODE), me.name,
552     source_p->name, c);
553     }
554    
555     static void
556     chm_simple(struct Client *client_p, struct Client *source_p, struct Channel *chptr,
557     int parc, int *parn, char **parv, int *errors, int alev, int dir,
558     char c, void *d, const char *chname)
559     {
560     long mode_type;
561    
562     mode_type = (long)d;
563    
564     if ((alev < CHACCESS_HALFOP) ||
565     ((mode_type == MODE_PRIVATE) && (alev < CHACCESS_CHANOP)))
566     {
567     if (!(*errors & SM_ERR_NOOPS))
568     sendto_one(source_p, form_str(alev == CHACCESS_NOTONCHAN ?
569     ERR_NOTONCHANNEL : ERR_CHANOPRIVSNEEDED),
570     me.name, source_p->name, chname);
571     *errors |= SM_ERR_NOOPS;
572     return;
573     }
574    
575     /* If have already dealt with this simple mode, ignore it */
576     if (simple_modes_mask & mode_type)
577     return;
578    
579     simple_modes_mask |= mode_type;
580    
581     /* setting + */
582     /* Apparently, (though no one has ever told the hybrid group directly)
583     * admins don't like redundant mode checking. ok. It would have been nice
584     * if you had have told us directly. I've left the original code snippets
585     * in place.
586     *
587     * -Dianora
588     */
589     if ((dir == MODE_ADD)) /* && !(chptr->mode.mode & mode_type)) */
590     {
591     chptr->mode.mode |= mode_type;
592    
593     mode_changes[mode_count].letter = c;
594     mode_changes[mode_count].dir = MODE_ADD;
595     mode_changes[mode_count].caps = 0;
596     mode_changes[mode_count].nocaps = 0;
597     mode_changes[mode_count].id = NULL;
598     mode_changes[mode_count].mems = ALL_MEMBERS;
599     mode_changes[mode_count++].arg = NULL;
600     }
601     else if ((dir == MODE_DEL)) /* && (chptr->mode.mode & mode_type)) */
602     {
603     /* setting - */
604    
605     chptr->mode.mode &= ~mode_type;
606    
607     mode_changes[mode_count].letter = c;
608     mode_changes[mode_count].dir = MODE_DEL;
609     mode_changes[mode_count].caps = 0;
610     mode_changes[mode_count].nocaps = 0;
611     mode_changes[mode_count].mems = ALL_MEMBERS;
612     mode_changes[mode_count].id = NULL;
613     mode_changes[mode_count++].arg = NULL;
614     }
615     }
616    
617     static void
618 michael 1150 chm_operonly(struct Client *client_p, struct Client *source_p, struct Channel *chptr,
619     int parc, int *parn, char **parv, int *errors, int alev, int dir,
620     char c, void *d, const char *chname)
621     {
622     long mode_type;
623    
624     mode_type = (long)d;
625    
626     if ((alev < CHACCESS_HALFOP) ||
627     ((mode_type == MODE_PRIVATE) && (alev < CHACCESS_CHANOP)))
628     {
629     if (!(*errors & SM_ERR_NOOPS))
630     sendto_one(source_p, form_str(alev == CHACCESS_NOTONCHAN ?
631     ERR_NOTONCHANNEL : ERR_CHANOPRIVSNEEDED),
632     me.name, source_p->name, chname);
633     *errors |= SM_ERR_NOOPS;
634     return;
635     }
636     else if (MyClient(source_p) && !IsOper(source_p))
637     {
638     if (!(*errors & SM_ERR_NOTOPER))
639     {
640     if (alev == CHACCESS_NOTONCHAN)
641     sendto_one(source_p, form_str(ERR_NOTONCHANNEL),
642     me.name, source_p->name, chname);
643     else
644     sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
645     me.name, source_p->name);
646     }
647    
648     *errors |= SM_ERR_NOTOPER;
649     return;
650     }
651    
652     /* If have already dealt with this simple mode, ignore it */
653     if (simple_modes_mask & mode_type)
654     return;
655    
656     simple_modes_mask |= mode_type;
657    
658     if ((dir == MODE_ADD)) /* && !(chptr->mode.mode & mode_type)) */
659     {
660     chptr->mode.mode |= mode_type;
661    
662     mode_changes[mode_count].letter = c;
663     mode_changes[mode_count].dir = MODE_ADD;
664     mode_changes[mode_count].caps = 0;
665     mode_changes[mode_count].nocaps = 0;
666     mode_changes[mode_count].id = NULL;
667     mode_changes[mode_count].mems = ALL_MEMBERS;
668     mode_changes[mode_count].mems = ALL_MEMBERS;
669     mode_changes[mode_count++].arg = NULL;
670     }
671     else if ((dir == MODE_DEL)) /* && (chptr->mode.mode & mode_type)) */
672     {
673     /* setting - */
674    
675     chptr->mode.mode &= ~mode_type;
676    
677     mode_changes[mode_count].letter = c;
678     mode_changes[mode_count].dir = MODE_DEL;
679     mode_changes[mode_count].caps = 0;
680     mode_changes[mode_count].nocaps = 0;
681     mode_changes[mode_count].mems = ALL_MEMBERS;
682     mode_changes[mode_count].id = NULL;
683     mode_changes[mode_count++].arg = NULL;
684     }
685     }
686    
687     static void
688 adx 30 chm_ban(struct Client *client_p, struct Client *source_p,
689     struct Channel *chptr, int parc, int *parn,
690     char **parv, int *errors, int alev, int dir, char c, void *d,
691     const char *chname)
692     {
693     char *mask = NULL;
694    
695     if (dir == MODE_QUERY || parc <= *parn)
696     {
697     dlink_node *ptr = NULL;
698    
699     if (*errors & SM_ERR_RPL_B)
700     return;
701    
702     *errors |= SM_ERR_RPL_B;
703    
704     DLINK_FOREACH(ptr, chptr->banlist.head)
705     {
706     const struct Ban *banptr = ptr->data;
707     sendto_one(client_p, form_str(RPL_BANLIST),
708     me.name, client_p->name, chname,
709     banptr->name, banptr->username, banptr->host,
710     banptr->who, banptr->when);
711     }
712    
713     sendto_one(source_p, form_str(RPL_ENDOFBANLIST), me.name,
714     source_p->name, chname);
715     return;
716     }
717    
718     if (alev < CHACCESS_HALFOP)
719     {
720     if (!(*errors & SM_ERR_NOOPS))
721     sendto_one(source_p, form_str(alev == CHACCESS_NOTONCHAN ?
722     ERR_NOTONCHANNEL : ERR_CHANOPRIVSNEEDED),
723     me.name, source_p->name, chname);
724     *errors |= SM_ERR_NOOPS;
725     return;
726     }
727    
728     if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
729     return;
730    
731 michael 388 mask = nuh_mask[*parn];
732     memcpy(mask, parv[*parn], sizeof(nuh_mask[*parn]));
733     ++*parn;
734    
735 adx 30 if (IsServer(client_p))
736     if (strchr(mask, ' '))
737     return;
738    
739     switch (dir)
740     {
741     case MODE_ADD:
742     if (!add_id(source_p, chptr, mask, CHFL_BAN))
743     return;
744     break;
745     case MODE_DEL:
746     if (!del_id(chptr, mask, CHFL_BAN))
747     return;
748     break;
749     default:
750     assert(0);
751     }
752    
753     mode_changes[mode_count].letter = c;
754     mode_changes[mode_count].dir = dir;
755     mode_changes[mode_count].caps = 0;
756     mode_changes[mode_count].nocaps = 0;
757     mode_changes[mode_count].mems = ALL_MEMBERS;
758     mode_changes[mode_count].id = NULL;
759     mode_changes[mode_count++].arg = mask;
760     }
761    
762     static void
763     chm_except(struct Client *client_p, struct Client *source_p,
764     struct Channel *chptr, int parc, int *parn,
765     char **parv, int *errors, int alev, int dir, char c, void *d,
766     const char *chname)
767     {
768     char *mask = NULL;
769    
770     /* if we have +e disabled, allow local clients to do anything but
771     * set the mode. This prevents the abuse of +e when just a few
772     * servers support it. --fl
773     */
774     if (!ConfigChannel.use_except && MyClient(source_p) &&
775     ((dir == MODE_ADD) && (parc > *parn)))
776     {
777     if (*errors & SM_ERR_RPL_E)
778     return;
779    
780     *errors |= SM_ERR_RPL_E;
781     return;
782     }
783    
784     if (alev < CHACCESS_HALFOP)
785     {
786     if (!(*errors & SM_ERR_NOOPS))
787     sendto_one(source_p, form_str(alev == CHACCESS_NOTONCHAN ?
788     ERR_NOTONCHANNEL : ERR_CHANOPRIVSNEEDED),
789     me.name, source_p->name, chname);
790     *errors |= SM_ERR_NOOPS;
791     return;
792     }
793    
794     if (dir == MODE_QUERY || parc <= *parn)
795     {
796     dlink_node *ptr = NULL;
797    
798     if (*errors & SM_ERR_RPL_E)
799     return;
800    
801     *errors |= SM_ERR_RPL_E;
802    
803     DLINK_FOREACH(ptr, chptr->exceptlist.head)
804     {
805     const struct Ban *banptr = ptr->data;
806     sendto_one(client_p, form_str(RPL_EXCEPTLIST),
807     me.name, client_p->name, chname,
808     banptr->name, banptr->username, banptr->host,
809     banptr->who, banptr->when);
810     }
811    
812     sendto_one(source_p, form_str(RPL_ENDOFEXCEPTLIST), me.name,
813     source_p->name, chname);
814     return;
815     }
816    
817     if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
818     return;
819    
820 michael 388 mask = nuh_mask[*parn];
821     memcpy(mask, parv[*parn], sizeof(nuh_mask[*parn]));
822     ++*parn;
823 adx 30
824     if (IsServer(client_p))
825     if (strchr(mask, ' '))
826     return;
827    
828     switch (dir)
829     {
830     case MODE_ADD:
831     if (!add_id(source_p, chptr, mask, CHFL_EXCEPTION))
832     return;
833     break;
834     case MODE_DEL:
835     if (!del_id(chptr, mask, CHFL_EXCEPTION))
836     return;
837     break;
838     default:
839     assert(0);
840     }
841    
842     mode_changes[mode_count].letter = c;
843     mode_changes[mode_count].dir = dir;
844     mode_changes[mode_count].caps = CAP_EX;
845     mode_changes[mode_count].nocaps = 0;
846    
847     if (ConfigChannel.use_except)
848     mode_changes[mode_count].mems = ONLY_CHANOPS;
849     else
850     mode_changes[mode_count].mems = ONLY_SERVERS;
851    
852     mode_changes[mode_count].id = NULL;
853     mode_changes[mode_count++].arg = mask;
854     }
855    
856     static void
857     chm_invex(struct Client *client_p, struct Client *source_p,
858     struct Channel *chptr, int parc, int *parn,
859     char **parv, int *errors, int alev, int dir, char c, void *d,
860     const char *chname)
861     {
862     char *mask = NULL;
863    
864     /* if we have +I disabled, allow local clients to do anything but
865     * set the mode. This prevents the abuse of +I when just a few
866     * servers support it --fl
867     */
868     if (!ConfigChannel.use_invex && MyClient(source_p) &&
869     (dir == MODE_ADD) && (parc > *parn))
870     {
871     if (*errors & SM_ERR_RPL_I)
872     return;
873    
874     *errors |= SM_ERR_RPL_I;
875     return;
876     }
877    
878     if (alev < CHACCESS_HALFOP)
879     {
880     if (!(*errors & SM_ERR_NOOPS))
881     sendto_one(source_p, form_str(alev == CHACCESS_NOTONCHAN ?
882     ERR_NOTONCHANNEL : ERR_CHANOPRIVSNEEDED),
883     me.name, source_p->name, chname);
884     *errors |= SM_ERR_NOOPS;
885     return;
886     }
887    
888     if (dir == MODE_QUERY || parc <= *parn)
889     {
890     dlink_node *ptr = NULL;
891    
892     if (*errors & SM_ERR_RPL_I)
893     return;
894    
895     *errors |= SM_ERR_RPL_I;
896    
897     DLINK_FOREACH(ptr, chptr->invexlist.head)
898     {
899     const struct Ban *banptr = ptr->data;
900     sendto_one(client_p, form_str(RPL_INVITELIST), me.name,
901     client_p->name, chname,
902     banptr->name, banptr->username, banptr->host,
903     banptr->who, banptr->when);
904     }
905    
906     sendto_one(source_p, form_str(RPL_ENDOFINVITELIST), me.name,
907     source_p->name, chname);
908     return;
909     }
910    
911     if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
912     return;
913    
914 michael 388 mask = nuh_mask[*parn];
915     memcpy(mask, parv[*parn], sizeof(nuh_mask[*parn]));
916     ++*parn;
917 adx 30
918     if (IsServer(client_p))
919     if (strchr(mask, ' '))
920     return;
921    
922     switch (dir)
923     {
924     case MODE_ADD:
925     if (!add_id(source_p, chptr, mask, CHFL_INVEX))
926     return;
927     break;
928     case MODE_DEL:
929     if (!del_id(chptr, mask, CHFL_INVEX))
930     return;
931     break;
932     default:
933     assert(0);
934     }
935    
936     mode_changes[mode_count].letter = c;
937     mode_changes[mode_count].dir = dir;
938     mode_changes[mode_count].caps = CAP_IE;
939     mode_changes[mode_count].nocaps = 0;
940    
941     if (ConfigChannel.use_invex)
942     mode_changes[mode_count].mems = ONLY_CHANOPS;
943     else
944     mode_changes[mode_count].mems = ONLY_SERVERS;
945    
946     mode_changes[mode_count].id = NULL;
947     mode_changes[mode_count++].arg = mask;
948     }
949    
950     /*
951     * inputs - pointer to channel
952     * output - none
953     * side effects - clear ban cache
954     */
955     void
956     clear_ban_cache(struct Channel *chptr)
957     {
958     dlink_node *ptr = NULL;
959    
960 michael 572 DLINK_FOREACH(ptr, chptr->members.head)
961 adx 30 {
962     struct Membership *ms = ptr->data;
963 michael 572
964     if (MyConnect(ms->client_p))
965     ms->flags &= ~(CHFL_BAN_SILENCED|CHFL_BAN_CHECKED);
966 adx 30 }
967     }
968    
969 michael 759 void
970     clear_ban_cache_client(struct Client *client_p)
971     {
972     dlink_node *ptr = NULL;
973    
974 michael 760 DLINK_FOREACH(ptr, client_p->channel.head)
975 michael 759 {
976     struct Membership *ms = ptr->data;
977     ms->flags &= ~(CHFL_BAN_SILENCED|CHFL_BAN_CHECKED);
978     }
979     }
980    
981 adx 30 static void
982     chm_op(struct Client *client_p, struct Client *source_p,
983     struct Channel *chptr, int parc, int *parn,
984     char **parv, int *errors, int alev, int dir, char c, void *d,
985     const char *chname)
986     {
987     char *opnick;
988     struct Client *targ_p;
989     struct Membership *member;
990 adx 356 int caps = 0;
991 adx 30
992     if (alev < CHACCESS_CHANOP)
993     {
994     if (!(*errors & SM_ERR_NOOPS))
995     sendto_one(source_p, form_str(alev == CHACCESS_NOTONCHAN ?
996     ERR_NOTONCHANNEL : ERR_CHANOPRIVSNEEDED),
997     me.name, source_p->name, chname);
998     *errors |= SM_ERR_NOOPS;
999     return;
1000     }
1001    
1002     if ((dir == MODE_QUERY) || (parc <= *parn))
1003     return;
1004    
1005     opnick = parv[(*parn)++];
1006    
1007     if ((targ_p = find_chasing(client_p, source_p, opnick, NULL)) == NULL)
1008     return;
1009     if (!IsClient(targ_p))
1010     return;
1011    
1012     if ((member = find_channel_link(targ_p, chptr)) == NULL)
1013     {
1014     if (!(*errors & SM_ERR_NOTONCHANNEL))
1015     sendto_one(source_p, form_str(ERR_USERNOTINCHANNEL),
1016     me.name, source_p->name, opnick, chname);
1017     *errors |= SM_ERR_NOTONCHANNEL;
1018     return;
1019     }
1020    
1021     if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
1022     return;
1023    
1024     /* no redundant mode changes */
1025     if (dir == MODE_ADD && has_member_flags(member, CHFL_CHANOP))
1026     return;
1027     if (dir == MODE_DEL && !has_member_flags(member, CHFL_CHANOP))
1028 adx 356 {
1029     #ifdef HALFOPS
1030     if (has_member_flags(member, CHFL_HALFOP))
1031 db 931 {
1032     --*parn;
1033 adx 356 chm_hop(client_p, source_p, chptr, parc, parn, parv, errors, alev,
1034     dir, c, d, chname);
1035 db 931 }
1036 adx 356 #endif
1037 adx 30 return;
1038 adx 356 }
1039 adx 30
1040 adx 356 #ifdef HALFOPS
1041     if (dir == MODE_ADD && has_member_flags(member, CHFL_HALFOP))
1042     {
1043     /* promoting from % to @ is visible only to CAP_HOPS servers */
1044     mode_changes[mode_count].letter = 'h';
1045     mode_changes[mode_count].dir = MODE_DEL;
1046     mode_changes[mode_count].caps = caps = CAP_HOPS;
1047     mode_changes[mode_count].nocaps = 0;
1048     mode_changes[mode_count].mems = ALL_MEMBERS;
1049     mode_changes[mode_count].id = NULL;
1050     mode_changes[mode_count].arg = targ_p->name;
1051     mode_changes[mode_count++].client = targ_p;
1052     }
1053     #endif
1054    
1055 adx 30 mode_changes[mode_count].letter = 'o';
1056     mode_changes[mode_count].dir = dir;
1057 adx 356 mode_changes[mode_count].caps = caps;
1058 adx 30 mode_changes[mode_count].nocaps = 0;
1059     mode_changes[mode_count].mems = ALL_MEMBERS;
1060     mode_changes[mode_count].id = targ_p->id;
1061     mode_changes[mode_count].arg = targ_p->name;
1062     mode_changes[mode_count++].client = targ_p;
1063    
1064     if (dir == MODE_ADD)
1065     {
1066     AddMemberFlag(member, CHFL_CHANOP);
1067 adx 356 DelMemberFlag(member, CHFL_DEOPPED | CHFL_HALFOP);
1068 adx 30 }
1069     else
1070     DelMemberFlag(member, CHFL_CHANOP);
1071     }
1072    
1073     #ifdef HALFOPS
1074     static void
1075     chm_hop(struct Client *client_p, struct Client *source_p,
1076     struct Channel *chptr, int parc, int *parn,
1077     char **parv, int *errors, int alev, int dir, char c, void *d,
1078     const char *chname)
1079     {
1080     char *opnick;
1081     struct Client *targ_p;
1082     struct Membership *member;
1083    
1084     /* *sigh* - dont allow halfops to set +/-h, they could fully control a
1085     * channel if there were no ops - it doesnt solve anything.. MODE_PRIVATE
1086     * when used with MODE_SECRET is paranoid - cant use +p
1087     *
1088     * it needs to be optional per channel - but not via +p, that or remove
1089     * paranoid.. -- fl_
1090     *
1091     * +p means paranoid, it is useless for anything else on modern IRC, as
1092     * list isn't really usable. If you want to have a private channel these
1093     * days, you set it +s. Halfops can no longer remove simple modes when
1094     * +p is set (although they can set +p) so it is safe to use this to
1095     * control whether they can (de)halfop...
1096     */
1097     if (alev <
1098     ((chptr->mode.mode & MODE_PRIVATE) ? CHACCESS_CHANOP : CHACCESS_HALFOP))
1099     {
1100     if (!(*errors & SM_ERR_NOOPS))
1101     sendto_one(source_p, form_str(alev == CHACCESS_NOTONCHAN ?
1102     ERR_NOTONCHANNEL : ERR_CHANOPRIVSNEEDED),
1103     me.name, source_p->name, chname);
1104     *errors |= SM_ERR_NOOPS;
1105     return;
1106     }
1107    
1108     if ((dir == MODE_QUERY) || (parc <= *parn))
1109     return;
1110    
1111     opnick = parv[(*parn)++];
1112    
1113     if ((targ_p = find_chasing(client_p, source_p, opnick, NULL)) == NULL)
1114     return;
1115     if (!IsClient(targ_p))
1116     return;
1117    
1118     if ((member = find_channel_link(targ_p, chptr)) == NULL)
1119     {
1120     if (!(*errors & SM_ERR_NOTONCHANNEL))
1121     sendto_one(source_p, form_str(ERR_USERNOTINCHANNEL),
1122     me.name, source_p->name, opnick, chname);
1123     *errors |= SM_ERR_NOTONCHANNEL;
1124     return;
1125     }
1126    
1127     if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
1128     return;
1129    
1130     /* no redundant mode changes */
1131 adx 356 if (dir == MODE_ADD && has_member_flags(member, CHFL_HALFOP | CHFL_CHANOP))
1132 adx 30 return;
1133     if (dir == MODE_DEL && !has_member_flags(member, CHFL_HALFOP))
1134     return;
1135    
1136     mode_changes[mode_count].letter = 'h';
1137     mode_changes[mode_count].dir = dir;
1138 adx 356 mode_changes[mode_count].caps = CAP_HOPS;
1139 adx 30 mode_changes[mode_count].nocaps = 0;
1140     mode_changes[mode_count].mems = ALL_MEMBERS;
1141     mode_changes[mode_count].id = targ_p->id;
1142     mode_changes[mode_count].arg = targ_p->name;
1143     mode_changes[mode_count++].client = targ_p;
1144    
1145 adx 356 mode_changes[mode_count].letter = 'o';
1146     mode_changes[mode_count].dir = dir;
1147     mode_changes[mode_count].caps = 0;
1148     mode_changes[mode_count].nocaps = CAP_HOPS;
1149     mode_changes[mode_count].mems = ONLY_SERVERS;
1150     mode_changes[mode_count].id = targ_p->id;
1151     mode_changes[mode_count].arg = targ_p->name;
1152     mode_changes[mode_count++].client = targ_p;
1153    
1154 adx 30 if (dir == MODE_ADD)
1155     {
1156     AddMemberFlag(member, CHFL_HALFOP);
1157     DelMemberFlag(member, CHFL_DEOPPED);
1158     }
1159     else
1160     DelMemberFlag(member, CHFL_HALFOP);
1161     }
1162     #endif
1163    
1164     static void
1165     chm_voice(struct Client *client_p, struct Client *source_p,
1166     struct Channel *chptr, int parc, int *parn,
1167     char **parv, int *errors, int alev, int dir, char c, void *d,
1168     const char *chname)
1169     {
1170     char *opnick;
1171     struct Client *targ_p;
1172     struct Membership *member;
1173    
1174     if (alev < CHACCESS_HALFOP)
1175     {
1176     if (!(*errors & SM_ERR_NOOPS))
1177     sendto_one(source_p, form_str(alev == CHACCESS_NOTONCHAN ?
1178     ERR_NOTONCHANNEL : ERR_CHANOPRIVSNEEDED),
1179     me.name, source_p->name, chname);
1180     *errors |= SM_ERR_NOOPS;
1181     return;
1182     }
1183    
1184     if ((dir == MODE_QUERY) || parc <= *parn)
1185     return;
1186    
1187     opnick = parv[(*parn)++];
1188    
1189     if ((targ_p = find_chasing(client_p, source_p, opnick, NULL)) == NULL)
1190     return;
1191     if (!IsClient(targ_p))
1192     return;
1193    
1194     if ((member = find_channel_link(targ_p, chptr)) == NULL)
1195     {
1196     if (!(*errors & SM_ERR_NOTONCHANNEL))
1197     sendto_one(source_p, form_str(ERR_USERNOTINCHANNEL),
1198     me.name, source_p->name, opnick, chname);
1199     *errors |= SM_ERR_NOTONCHANNEL;
1200     return;
1201     }
1202    
1203     if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
1204     return;
1205    
1206     /* no redundant mode changes */
1207     if (dir == MODE_ADD && has_member_flags(member, CHFL_VOICE))
1208     return;
1209     if (dir == MODE_DEL && !has_member_flags(member, CHFL_VOICE))
1210     return;
1211    
1212     mode_changes[mode_count].letter = 'v';
1213     mode_changes[mode_count].dir = dir;
1214     mode_changes[mode_count].caps = 0;
1215     mode_changes[mode_count].nocaps = 0;
1216     mode_changes[mode_count].mems = ALL_MEMBERS;
1217     mode_changes[mode_count].id = targ_p->id;
1218     mode_changes[mode_count].arg = targ_p->name;
1219     mode_changes[mode_count++].client = targ_p;
1220    
1221     if (dir == MODE_ADD)
1222     AddMemberFlag(member, CHFL_VOICE);
1223     else
1224     DelMemberFlag(member, CHFL_VOICE);
1225     }
1226    
1227     static void
1228     chm_limit(struct Client *client_p, struct Client *source_p,
1229     struct Channel *chptr, int parc, int *parn,
1230     char **parv, int *errors, int alev, int dir, char c, void *d,
1231     const char *chname)
1232     {
1233     int i, limit;
1234     char *lstr;
1235    
1236     if (alev < CHACCESS_HALFOP)
1237     {
1238     if (!(*errors & SM_ERR_NOOPS))
1239     sendto_one(source_p, form_str(alev == CHACCESS_NOTONCHAN ?
1240     ERR_NOTONCHANNEL : ERR_CHANOPRIVSNEEDED),
1241     me.name, source_p->name, chname);
1242     *errors |= SM_ERR_NOOPS;
1243     return;
1244     }
1245    
1246     if (dir == MODE_QUERY)
1247     return;
1248    
1249     if ((dir == MODE_ADD) && parc > *parn)
1250     {
1251     lstr = parv[(*parn)++];
1252    
1253     if ((limit = atoi(lstr)) <= 0)
1254     return;
1255    
1256     ircsprintf(lstr, "%d", limit);
1257    
1258     /* if somebody sets MODE #channel +ll 1 2, accept latter --fl */
1259     for (i = 0; i < mode_count; i++)
1260     {
1261     if (mode_changes[i].letter == c && mode_changes[i].dir == MODE_ADD)
1262     mode_changes[i].letter = 0;
1263     }
1264    
1265     mode_changes[mode_count].letter = c;
1266     mode_changes[mode_count].dir = MODE_ADD;
1267     mode_changes[mode_count].caps = 0;
1268     mode_changes[mode_count].nocaps = 0;
1269     mode_changes[mode_count].mems = ALL_MEMBERS;
1270     mode_changes[mode_count].id = NULL;
1271     mode_changes[mode_count++].arg = lstr;
1272    
1273     chptr->mode.limit = limit;
1274     }
1275     else if (dir == MODE_DEL)
1276     {
1277     if (!chptr->mode.limit)
1278     return;
1279    
1280     chptr->mode.limit = 0;
1281    
1282     mode_changes[mode_count].letter = c;
1283     mode_changes[mode_count].dir = MODE_DEL;
1284     mode_changes[mode_count].caps = 0;
1285     mode_changes[mode_count].nocaps = 0;
1286     mode_changes[mode_count].mems = ALL_MEMBERS;
1287     mode_changes[mode_count].id = NULL;
1288     mode_changes[mode_count++].arg = NULL;
1289     }
1290     }
1291    
1292     static void
1293     chm_key(struct Client *client_p, struct Client *source_p,
1294     struct Channel *chptr, int parc, int *parn,
1295     char **parv, int *errors, int alev, int dir, char c, void *d,
1296     const char *chname)
1297     {
1298     int i;
1299     char *key;
1300    
1301     if (alev < CHACCESS_HALFOP)
1302     {
1303     if (!(*errors & SM_ERR_NOOPS))
1304     sendto_one(source_p, form_str(alev == CHACCESS_NOTONCHAN ?
1305     ERR_NOTONCHANNEL : ERR_CHANOPRIVSNEEDED),
1306     me.name, source_p->name, chname);
1307     *errors |= SM_ERR_NOOPS;
1308     return;
1309     }
1310    
1311     if (dir == MODE_QUERY)
1312     return;
1313    
1314     if ((dir == MODE_ADD) && parc > *parn)
1315     {
1316     key = parv[(*parn)++];
1317    
1318     if (MyClient(source_p))
1319     fix_key(key);
1320     else
1321     fix_key_old(key);
1322    
1323     if (*key == '\0')
1324     return;
1325    
1326     assert(key[0] != ' ');
1327     strlcpy(chptr->mode.key, key, sizeof(chptr->mode.key));
1328    
1329     /* if somebody does MODE #channel +kk a b, accept latter --fl */
1330     for (i = 0; i < mode_count; i++)
1331     {
1332     if (mode_changes[i].letter == c && mode_changes[i].dir == MODE_ADD)
1333     mode_changes[i].letter = 0;
1334     }
1335    
1336     mode_changes[mode_count].letter = c;
1337     mode_changes[mode_count].dir = MODE_ADD;
1338     mode_changes[mode_count].caps = 0;
1339     mode_changes[mode_count].nocaps = 0;
1340     mode_changes[mode_count].mems = ALL_MEMBERS;
1341     mode_changes[mode_count].id = NULL;
1342     mode_changes[mode_count++].arg = chptr->mode.key;
1343     }
1344     else if (dir == MODE_DEL)
1345     {
1346     if (parc > *parn)
1347     (*parn)++;
1348    
1349     if (chptr->mode.key[0] == '\0')
1350     return;
1351    
1352     chptr->mode.key[0] = '\0';
1353    
1354     mode_changes[mode_count].letter = c;
1355     mode_changes[mode_count].dir = MODE_DEL;
1356     mode_changes[mode_count].caps = 0;
1357     mode_changes[mode_count].nocaps = 0;
1358     mode_changes[mode_count].mems = ALL_MEMBERS;
1359     mode_changes[mode_count].id = NULL;
1360     mode_changes[mode_count++].arg = "*";
1361     }
1362     }
1363    
1364     struct ChannelMode
1365     {
1366     void (*func) (struct Client *client_p, struct Client *source_p,
1367     struct Channel *chptr, int parc, int *parn, char **parv,
1368     int *errors, int alev, int dir, char c, void *d,
1369     const char *chname);
1370     void *d;
1371     };
1372    
1373     static struct ChannelMode ModeTable[255] =
1374     {
1375     {chm_nosuch, NULL},
1376     {chm_nosuch, NULL}, /* A */
1377     {chm_nosuch, NULL}, /* B */
1378     {chm_nosuch, NULL}, /* C */
1379     {chm_nosuch, NULL}, /* D */
1380     {chm_nosuch, NULL}, /* E */
1381     {chm_nosuch, NULL}, /* F */
1382     {chm_nosuch, NULL}, /* G */
1383     {chm_nosuch, NULL}, /* H */
1384     {chm_invex, NULL}, /* I */
1385     {chm_nosuch, NULL}, /* J */
1386     {chm_nosuch, NULL}, /* K */
1387     {chm_nosuch, NULL}, /* L */
1388     {chm_nosuch, NULL}, /* M */
1389     {chm_nosuch, NULL}, /* N */
1390 michael 1150 {chm_operonly, (void *) MODE_OPERONLY}, /* O */
1391 adx 30 {chm_nosuch, NULL}, /* P */
1392     {chm_nosuch, NULL}, /* Q */
1393     {chm_nosuch, NULL}, /* R */
1394 michael 1150 {chm_simple, (void *) MODE_SSLONLY}, /* S */
1395 adx 30 {chm_nosuch, NULL}, /* T */
1396     {chm_nosuch, NULL}, /* U */
1397     {chm_nosuch, NULL}, /* V */
1398     {chm_nosuch, NULL}, /* W */
1399     {chm_nosuch, NULL}, /* X */
1400     {chm_nosuch, NULL}, /* Y */
1401     {chm_nosuch, NULL}, /* Z */
1402     {chm_nosuch, NULL},
1403     {chm_nosuch, NULL},
1404     {chm_nosuch, NULL},
1405     {chm_nosuch, NULL},
1406     {chm_nosuch, NULL},
1407     {chm_nosuch, NULL},
1408     {chm_nosuch, NULL}, /* a */
1409     {chm_ban, NULL}, /* b */
1410     {chm_nosuch, NULL}, /* c */
1411     {chm_nosuch, NULL}, /* d */
1412     {chm_except, NULL}, /* e */
1413     {chm_nosuch, NULL}, /* f */
1414     {chm_nosuch, NULL}, /* g */
1415     #ifdef HALFOPS
1416     {chm_hop, NULL}, /* h */
1417     #else
1418     {chm_nosuch, NULL}, /* h */
1419     #endif
1420     {chm_simple, (void *) MODE_INVITEONLY}, /* i */
1421     {chm_nosuch, NULL}, /* j */
1422     {chm_key, NULL}, /* k */
1423     {chm_limit, NULL}, /* l */
1424     {chm_simple, (void *) MODE_MODERATED}, /* m */
1425     {chm_simple, (void *) MODE_NOPRIVMSGS}, /* n */
1426     {chm_op, NULL}, /* o */
1427     {chm_simple, (void *) MODE_PRIVATE}, /* p */
1428     {chm_nosuch, NULL}, /* q */
1429     {chm_nosuch, NULL}, /* r */
1430     {chm_simple, (void *) MODE_SECRET}, /* s */
1431     {chm_simple, (void *) MODE_TOPICLIMIT}, /* t */
1432     {chm_nosuch, NULL}, /* u */
1433     {chm_voice, NULL}, /* v */
1434     {chm_nosuch, NULL}, /* w */
1435     {chm_nosuch, NULL}, /* x */
1436     {chm_nosuch, NULL}, /* y */
1437     {chm_nosuch, NULL}, /* z */
1438     };
1439    
1440     /* get_channel_access()
1441     *
1442     * inputs - pointer to Client struct
1443     * - pointer to Membership struct
1444     * output - CHACCESS_CHANOP if we should let them have
1445     * chanop level access, 0 for peon level access.
1446     * side effects - NONE
1447     */
1448     static int
1449     get_channel_access(struct Client *source_p, struct Membership *member)
1450     {
1451     /* Let hacked servers in for now... */
1452     if (!MyClient(source_p))
1453     return CHACCESS_CHANOP;
1454    
1455     if (member == NULL)
1456     return CHACCESS_NOTONCHAN;
1457    
1458     /* just to be sure.. */
1459     assert(source_p == member->client_p);
1460    
1461     if (has_member_flags(member, CHFL_CHANOP))
1462     return CHACCESS_CHANOP;
1463    
1464     #ifdef HALFOPS
1465     if (has_member_flags(member, CHFL_HALFOP))
1466     return CHACCESS_HALFOP;
1467     #endif
1468    
1469     return CHACCESS_PEON;
1470     }
1471    
1472     /* void send_cap_mode_changes(struct Client *client_p,
1473     * struct Client *source_p,
1474     * struct Channel *chptr, int cap, int nocap)
1475     * Input: The client sending(client_p), the source client(source_p),
1476     * the channel to send mode changes for(chptr)
1477     * Output: None.
1478     * Side-effects: Sends the appropriate mode changes to capable servers.
1479     *
1480     * send_cap_mode_changes() will loop the server list itself, because
1481     * at this point in time we have 4 capabs for channels, CAP_IE, CAP_EX,
1482     * and a server could support any number of these..
1483     * so we make the modebufs per server, tailoring them to each servers
1484     * specific demand. Its not very pretty, but its one of the few realistic
1485     * ways to handle having this many capabs for channel modes.. --fl_
1486     *
1487     * Reverted back to my original design, except that we now keep a count
1488     * of the number of servers which each combination as an optimisation, so
1489     * the capabs combinations which are not needed are not worked out. -A1kmm
1490     */
1491     /* rewritten to ensure parabuf < MODEBUFLEN -db */
1492    
1493     static void
1494     send_cap_mode_changes(struct Client *client_p, struct Client *source_p,
1495 michael 1015 struct Channel *chptr, unsigned int cap, unsigned int nocap)
1496 adx 30 {
1497     int i, mbl, pbl, arglen, nc, mc;
1498     int len;
1499     const char *arg = NULL;
1500     char *parptr;
1501     int dir = MODE_QUERY;
1502    
1503     mc = 0;
1504     nc = 0;
1505     pbl = 0;
1506    
1507     parabuf[0] = '\0';
1508     parptr = parabuf;
1509    
1510     if ((cap & CAP_TS6) && source_p->id[0] != '\0')
1511     mbl = ircsprintf(modebuf, ":%s TMODE %lu %s ", source_p->id,
1512     (unsigned long)chptr->channelts, chptr->chname);
1513     else
1514     mbl = ircsprintf(modebuf, ":%s MODE %s ", source_p->name,
1515     chptr->chname);
1516    
1517     /* loop the list of - modes we have */
1518     for (i = 0; i < mode_count; i++)
1519     {
1520     /* if they dont support the cap we need, or they do support a cap they
1521     * cant have, then dont add it to the modebuf.. that way they wont see
1522     * the mode
1523     */
1524     if ((mode_changes[i].letter == 0) ||
1525     ((cap & mode_changes[i].caps) != mode_changes[i].caps)
1526     || ((nocap & mode_changes[i].nocaps) != mode_changes[i].nocaps))
1527     continue;
1528    
1529     arg = "";
1530    
1531     if ((cap & CAP_TS6) && mode_changes[i].id)
1532     arg = mode_changes[i].id;
1533     if (*arg == '\0')
1534     arg = mode_changes[i].arg;
1535    
1536     /* if we're creeping past the buf size, we need to send it and make
1537     * another line for the other modes
1538     * XXX - this could give away server topology with uids being
1539     * different lengths, but not much we can do, except possibly break
1540     * them as if they were the longest of the nick or uid at all times,
1541     * which even then won't work as we don't always know the uid -A1kmm.
1542     */
1543     if (arg != NULL)
1544     arglen = strlen(arg);
1545     else
1546     arglen = 0;
1547    
1548     if ((mc == MAXMODEPARAMS) ||
1549     ((arglen + mbl + pbl + 2) > IRCD_BUFSIZE) ||
1550     (pbl + arglen + BAN_FUDGE) >= MODEBUFLEN)
1551     {
1552     if (nc != 0)
1553 michael 885 sendto_server(client_p, chptr, cap, nocap,
1554     "%s %s",
1555 adx 30 modebuf, parabuf);
1556     nc = 0;
1557     mc = 0;
1558    
1559     if ((cap & CAP_TS6) && source_p->id[0] != '\0')
1560     mbl = ircsprintf(modebuf, ":%s MODE %s ", source_p->id,
1561     chptr->chname);
1562     else
1563     mbl = ircsprintf(modebuf, ":%s MODE %s ", source_p->name,
1564     chptr->chname);
1565    
1566     pbl = 0;
1567     parabuf[0] = '\0';
1568     parptr = parabuf;
1569     dir = MODE_QUERY;
1570     }
1571    
1572     if (dir != mode_changes[i].dir)
1573     {
1574     modebuf[mbl++] = (mode_changes[i].dir == MODE_ADD) ? '+' : '-';
1575     dir = mode_changes[i].dir;
1576     }
1577    
1578     modebuf[mbl++] = mode_changes[i].letter;
1579     modebuf[mbl] = '\0';
1580     nc++;
1581    
1582     if (arg != NULL)
1583     {
1584     len = ircsprintf(parptr, "%s ", arg);
1585     pbl += len;
1586     parptr += len;
1587     mc++;
1588     }
1589     }
1590    
1591     if (pbl && parabuf[pbl - 1] == ' ')
1592     parabuf[pbl - 1] = 0;
1593    
1594     if (nc != 0)
1595 michael 885 sendto_server(client_p, chptr, cap, nocap,
1596     "%s %s", modebuf, parabuf);
1597 adx 30 }
1598    
1599     /* void send_mode_changes(struct Client *client_p,
1600     * struct Client *source_p,
1601     * struct Channel *chptr)
1602     * Input: The client sending(client_p), the source client(source_p),
1603     * the channel to send mode changes for(chptr),
1604     * mode change globals.
1605     * Output: None.
1606     * Side-effects: Sends the appropriate mode changes to other clients
1607     * and propagates to servers.
1608     */
1609     /* ensure parabuf < MODEBUFLEN -db */
1610     static void
1611     send_mode_changes(struct Client *client_p, struct Client *source_p,
1612     struct Channel *chptr, char *chname)
1613     {
1614     int i, mbl, pbl, arglen, nc, mc;
1615     int len;
1616     const char *arg = NULL;
1617     char *parptr;
1618     int dir = MODE_QUERY;
1619    
1620     /* bail out if we have nothing to do... */
1621     if (!mode_count)
1622     return;
1623    
1624     if (IsServer(source_p))
1625     mbl = ircsprintf(modebuf, ":%s MODE %s ", (IsHidden(source_p) ||
1626     ConfigServerHide.hide_servers) ?
1627     me.name : source_p->name, chname);
1628     else
1629     mbl = ircsprintf(modebuf, ":%s!%s@%s MODE %s ", source_p->name,
1630     source_p->username, source_p->host, chname);
1631    
1632     mc = 0;
1633     nc = 0;
1634     pbl = 0;
1635    
1636     parabuf[0] = '\0';
1637     parptr = parabuf;
1638    
1639     for (i = 0; i < mode_count; i++)
1640     {
1641     if (mode_changes[i].letter == 0 ||
1642     mode_changes[i].mems == NON_CHANOPS ||
1643     mode_changes[i].mems == ONLY_SERVERS)
1644     continue;
1645    
1646     arg = mode_changes[i].arg;
1647     if (arg != NULL)
1648     arglen = strlen(arg);
1649     else
1650     arglen = 0;
1651    
1652     if ((mc == MAXMODEPARAMS) ||
1653     ((arglen + mbl + pbl + 2) > IRCD_BUFSIZE) ||
1654     ((arglen + pbl + BAN_FUDGE) >= MODEBUFLEN))
1655     {
1656     if (mbl && modebuf[mbl - 1] == '-')
1657     modebuf[mbl - 1] = '\0';
1658    
1659     if (nc != 0)
1660     sendto_channel_local(ALL_MEMBERS, NO, chptr, "%s %s", modebuf, parabuf);
1661    
1662     nc = 0;
1663     mc = 0;
1664    
1665     if (IsServer(source_p))
1666     mbl = ircsprintf(modebuf, ":%s MODE %s ", me.name, chname);
1667     else
1668     mbl = ircsprintf(modebuf, ":%s!%s@%s MODE %s ", source_p->name,
1669     source_p->username, source_p->host, chname);
1670    
1671     pbl = 0;
1672     parabuf[0] = '\0';
1673     parptr = parabuf;
1674     dir = MODE_QUERY;
1675     }
1676    
1677     if (dir != mode_changes[i].dir)
1678     {
1679     modebuf[mbl++] = (mode_changes[i].dir == MODE_ADD) ? '+' : '-';
1680     dir = mode_changes[i].dir;
1681     }
1682    
1683     modebuf[mbl++] = mode_changes[i].letter;
1684     modebuf[mbl] = '\0';
1685     nc++;
1686    
1687     if (arg != NULL)
1688     {
1689     len = ircsprintf(parptr, "%s ", arg);
1690     pbl += len;
1691     parptr += len;
1692     mc++;
1693     }
1694     }
1695    
1696     if (pbl && parabuf[pbl - 1] == ' ')
1697     parabuf[pbl - 1] = 0;
1698    
1699     if (nc != 0)
1700     sendto_channel_local(ALL_MEMBERS, NO, chptr, "%s %s", modebuf, parabuf);
1701    
1702     nc = 0;
1703     mc = 0;
1704    
1705     /* Now send to servers... */
1706     for (i = 0; i < NCHCAP_COMBOS; i++)
1707     if (chcap_combos[i].count != 0)
1708     send_cap_mode_changes(client_p, source_p, chptr,
1709     chcap_combos[i].cap_yes,
1710     chcap_combos[i].cap_no);
1711     }
1712    
1713     /* void set_channel_mode(struct Client *client_p, struct Client *source_p,
1714     * struct Channel *chptr, int parc, char **parv,
1715     * char *chname)
1716     * Input: The client we received this from, the client this originated
1717     * from, the channel, the parameter count starting at the modes,
1718     * the parameters, the channel name.
1719     * Output: None.
1720     * Side-effects: Changes the channel membership and modes appropriately,
1721     * sends the appropriate MODE messages to the appropriate
1722     * clients.
1723     */
1724     void
1725     set_channel_mode(struct Client *client_p, struct Client *source_p, struct Channel *chptr,
1726     struct Membership *member, int parc, char *parv[], char *chname)
1727     {
1728     int dir = MODE_ADD;
1729     int parn = 1;
1730     int alevel, errors = 0;
1731     char *ml = parv[0], c;
1732     int table_position;
1733    
1734     mode_count = 0;
1735     mode_limit = 0;
1736     simple_modes_mask = 0;
1737    
1738     alevel = get_channel_access(source_p, member);
1739    
1740     for (; (c = *ml) != '\0'; ml++)
1741     {
1742     #if 0
1743     if(mode_count > 20)
1744     break;
1745     #endif
1746     switch (c)
1747     {
1748     case '+':
1749     dir = MODE_ADD;
1750     break;
1751     case '-':
1752     dir = MODE_DEL;
1753     break;
1754     case '=':
1755     dir = MODE_QUERY;
1756     break;
1757     default:
1758     if (c < 'A' || c > 'z')
1759     table_position = 0;
1760     else
1761     table_position = c - 'A' + 1;
1762     ModeTable[table_position].func(client_p, source_p, chptr,
1763     parc, &parn,
1764     parv, &errors, alevel, dir, c,
1765     ModeTable[table_position].d,
1766     chname);
1767     break;
1768     }
1769     }
1770    
1771     send_mode_changes(client_p, source_p, chptr, chname);
1772     }

Properties

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