ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/channel_mode.c
Revision: 3141
Committed: Wed Mar 12 19:35:27 2014 UTC (11 years, 5 months ago) by michael
Content type: text/x-csrc
File size: 48083 byte(s)
Log Message:
- channel_mode.c: fixed buglet in send_mode_changes_server()

File Contents

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

Properties

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