ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/src/channel_mode.c
Revision: 1592
Committed: Sat Oct 27 21:02:32 2012 UTC (11 years, 5 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid/trunk/src/channel_mode.c
File size: 51590 byte(s)
Log Message:
- Second time's the charm? Moving svnroot/ircd-hybrid-8 to
  svnroot/ircd-hybrid/trunk

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

Properties

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