ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/channel_mode.c
Revision: 6759
Committed: Fri Nov 13 18:23:37 2015 UTC (9 years, 9 months ago) by michael
Content type: text/x-csrc
File size: 42586 byte(s)
Log Message:
- Merge sendto_channel_local_butone() functionality into sendto_channel_local() and get rid of sendto_channel_local_butone()

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

Properties

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