ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/channel_mode.c
Revision: 3634
Committed: Fri May 23 18:55:33 2014 UTC (12 years, 4 months ago) by michael
Content type: text/x-csrc
File size: 45905 byte(s)
Log Message:
- channel_mode.c: removed unused SM_ERR_NOTS; made errorcodes use an enum

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

Properties

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