ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/channel_mode.c
Revision: 3753
Committed: Sun Jun 1 18:11:35 2014 UTC (11 years, 2 months ago) by michael
Content type: text/x-csrc
File size: 43600 byte(s)
Log Message:
- More ms_sjoin() cleanups

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

Properties

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