ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/src/channel_mode.c
Revision: 8050
Committed: Sun Mar 19 11:25:27 2017 UTC (9 years, 4 months ago) by michael
Content type: text/x-csrc
File size: 43629 byte(s)
Log Message:
- channel_mode.c: constification; remove useless comments

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

Properties

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