ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/channel_mode.c
Revision: 4833
Committed: Sun Nov 2 11:45:04 2014 UTC (10 years, 9 months ago) by michael
Content type: text/x-csrc
File size: 42599 byte(s)
Log Message:
- Constification

File Contents

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

Properties

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