ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/src/channel_mode.c
Revision: 3725
Committed: Sat May 31 16:29:38 2014 UTC (12 years, 1 month ago) by michael
Content type: text/x-csrc
File size: 44342 byte(s)
Log Message:
- Halfops are now part of the ircd core and enabled by default

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

Properties

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