ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/channel_mode.c
Revision: 3151
Committed: Fri Mar 14 14:24:09 2014 UTC (11 years, 5 months ago) by michael
Content type: text/x-csrc
File size: 46527 byte(s)
Log Message:
- channel_mode.c: style corrections

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

Properties

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