ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/channel_mode.c
Revision: 7006
Committed: Fri Jan 1 00:07:54 2016 UTC (9 years, 7 months ago) by michael
Content type: text/x-csrc
File size: 42795 byte(s)
Log Message:
- Update copyright years

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

Properties

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