ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/channel_mode.c
Revision: 8020
Committed: Thu Mar 16 18:45:15 2017 UTC (9 years, 6 months ago) by michael
Content type: text/x-csrc
File size: 42347 byte(s)
Log Message:
- channel_mode.c:send_mode_changes_client(): remove senseless code

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

Properties

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