ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/channel_mode.c
Revision: 4102
Committed: Sun Jun 29 19:35:28 2014 UTC (11 years, 2 months ago) by michael
Content type: text/x-csrc
File size: 43567 byte(s)
Log Message:
- Add CHACCESS_REMOTE for servers remote Clients

File Contents

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

Properties

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