ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/channel_mode.c
Revision: 7797
Committed: Tue Oct 18 17:27:10 2016 UTC (8 years, 10 months ago) by michael
Content type: text/x-csrc
File size: 42468 byte(s)
Log Message:
- Minor style corrections and constifications

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

Properties

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