ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/channel_mode.c
Revision: 3192
Committed: Sun Mar 23 19:46:39 2014 UTC (11 years, 5 months ago) by michael
Content type: text/x-csrc
File size: 46192 byte(s)
Log Message:
- Fixed compile error in ms_sid()
- Cleaned up find_chasing(). Removed useless third 'chasing' argument.

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 3192 if ((target_p = find_chasing(source_p, opnick)) == NULL)
839 adx 30 return;
840    
841 michael 3143 if ((member = find_channel_link(target_p, chptr)) == NULL)
842 adx 30 {
843     if (!(*errors & SM_ERR_NOTONCHANNEL))
844 michael 3109 sendto_one_numeric(source_p, &me, ERR_USERNOTINCHANNEL, opnick, chptr->chname);
845 adx 30 *errors |= SM_ERR_NOTONCHANNEL;
846     return;
847     }
848    
849     if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
850     return;
851    
852     /* no redundant mode changes */
853 michael 2951 if (dir == MODE_ADD && has_member_flags(member, CHFL_VOICE))
854 adx 30 return;
855 michael 2951 if (dir == MODE_DEL && !has_member_flags(member, CHFL_VOICE))
856 adx 30 return;
857    
858 michael 2951 mode_changes[mode_count].letter = 'v';
859 adx 30 mode_changes[mode_count].dir = dir;
860     mode_changes[mode_count].mems = ALL_MEMBERS;
861 michael 3143 mode_changes[mode_count].id = target_p->id;
862     mode_changes[mode_count].arg = target_p->name;
863     mode_changes[mode_count++].client = target_p;
864 adx 30
865     if (dir == MODE_ADD)
866 michael 2951 AddMemberFlag(member, CHFL_VOICE);
867 adx 30 else
868 michael 2951 DelMemberFlag(member, CHFL_VOICE);
869 adx 30 }
870    
871     #ifdef HALFOPS
872     static void
873 michael 3150 chm_hop(struct Client *source_p,
874     struct Channel *chptr, int parc, int *parn,
875     char **parv, int *errors, int alev, int dir, char c, unsigned int d)
876 adx 30 {
877 michael 2892 const char *opnick = NULL;
878 michael 3143 struct Client *target_p;
879 adx 30 struct Membership *member;
880    
881     /* *sigh* - dont allow halfops to set +/-h, they could fully control a
882     * channel if there were no ops - it doesnt solve anything.. MODE_PRIVATE
883     * when used with MODE_SECRET is paranoid - cant use +p
884     *
885     * it needs to be optional per channel - but not via +p, that or remove
886     * paranoid.. -- fl_
887     *
888     * +p means paranoid, it is useless for anything else on modern IRC, as
889     * list isn't really usable. If you want to have a private channel these
890     * days, you set it +s. Halfops can no longer remove simple modes when
891     * +p is set (although they can set +p) so it is safe to use this to
892     * control whether they can (de)halfop...
893     */
894     if (alev <
895     ((chptr->mode.mode & MODE_PRIVATE) ? CHACCESS_CHANOP : CHACCESS_HALFOP))
896     {
897     if (!(*errors & SM_ERR_NOOPS))
898 michael 3109 sendto_one_numeric(source_p, &me,
899     alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
900     ERR_CHANOPRIVSNEEDED, chptr->chname);
901 adx 30 *errors |= SM_ERR_NOOPS;
902     return;
903     }
904    
905     if ((dir == MODE_QUERY) || (parc <= *parn))
906     return;
907    
908     opnick = parv[(*parn)++];
909    
910 michael 3192 if ((target_p = find_chasing(source_p, opnick)) == NULL)
911 adx 30 return;
912    
913 michael 3143 if ((member = find_channel_link(target_p, chptr)) == NULL)
914 adx 30 {
915     if (!(*errors & SM_ERR_NOTONCHANNEL))
916 michael 3109 sendto_one_numeric(source_p, &me, ERR_USERNOTINCHANNEL, opnick, chptr->chname);
917 adx 30 *errors |= SM_ERR_NOTONCHANNEL;
918     return;
919     }
920    
921     if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
922     return;
923    
924     /* no redundant mode changes */
925 michael 3140 if (dir == MODE_ADD && has_member_flags(member, CHFL_HALFOP))
926 adx 30 return;
927     if (dir == MODE_DEL && !has_member_flags(member, CHFL_HALFOP))
928     return;
929    
930     mode_changes[mode_count].letter = 'h';
931     mode_changes[mode_count].dir = dir;
932     mode_changes[mode_count].mems = ALL_MEMBERS;
933 michael 3143 mode_changes[mode_count].id = target_p->id;
934     mode_changes[mode_count].arg = target_p->name;
935     mode_changes[mode_count++].client = target_p;
936 adx 30
937     if (dir == MODE_ADD)
938     {
939     AddMemberFlag(member, CHFL_HALFOP);
940     DelMemberFlag(member, CHFL_DEOPPED);
941     }
942     else
943     DelMemberFlag(member, CHFL_HALFOP);
944     }
945     #endif
946    
947     static void
948 michael 3150 chm_op(struct Client *source_p,
949 michael 2951 struct Channel *chptr, int parc, int *parn,
950     char **parv, int *errors, int alev, int dir, char c, unsigned int d)
951 adx 30 {
952 michael 2892 const char *opnick = NULL;
953 michael 3143 struct Client *target_p;
954 adx 30 struct Membership *member;
955    
956 michael 2951 if (alev < CHACCESS_CHANOP)
957 adx 30 {
958     if (!(*errors & SM_ERR_NOOPS))
959 michael 3109 sendto_one_numeric(source_p, &me,
960     alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
961     ERR_CHANOPRIVSNEEDED, chptr->chname);
962 adx 30 *errors |= SM_ERR_NOOPS;
963     return;
964     }
965    
966 michael 2951 if ((dir == MODE_QUERY) || (parc <= *parn))
967 adx 30 return;
968    
969     opnick = parv[(*parn)++];
970    
971 michael 3192 if ((target_p = find_chasing(source_p, opnick)) == NULL)
972 adx 30 return;
973    
974 michael 3143 if ((member = find_channel_link(target_p, chptr)) == NULL)
975 adx 30 {
976     if (!(*errors & SM_ERR_NOTONCHANNEL))
977 michael 3109 sendto_one_numeric(source_p, &me, ERR_USERNOTINCHANNEL, opnick, chptr->chname);
978 adx 30 *errors |= SM_ERR_NOTONCHANNEL;
979     return;
980     }
981    
982     if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
983     return;
984    
985     /* no redundant mode changes */
986 michael 2951 if (dir == MODE_ADD && has_member_flags(member, CHFL_CHANOP))
987 adx 30 return;
988 michael 2951 if (dir == MODE_DEL && !has_member_flags(member, CHFL_CHANOP))
989 adx 30 return;
990    
991 michael 2951 mode_changes[mode_count].letter = 'o';
992 adx 30 mode_changes[mode_count].dir = dir;
993     mode_changes[mode_count].mems = ALL_MEMBERS;
994 michael 3143 mode_changes[mode_count].id = target_p->id;
995     mode_changes[mode_count].arg = target_p->name;
996     mode_changes[mode_count++].client = target_p;
997 adx 30
998     if (dir == MODE_ADD)
999 michael 2951 {
1000     AddMemberFlag(member, CHFL_CHANOP);
1001 michael 3140 DelMemberFlag(member, CHFL_DEOPPED);
1002 michael 2951 }
1003 adx 30 else
1004 michael 2951 DelMemberFlag(member, CHFL_CHANOP);
1005 adx 30 }
1006    
1007     static void
1008 michael 3150 chm_limit(struct Client *source_p,
1009 adx 30 struct Channel *chptr, int parc, int *parn,
1010 michael 2937 char **parv, int *errors, int alev, int dir, char c, unsigned int d)
1011 adx 30 {
1012 michael 3151 unsigned int i = 0;
1013     int limit = 0;
1014 adx 30
1015     if (alev < CHACCESS_HALFOP)
1016     {
1017     if (!(*errors & SM_ERR_NOOPS))
1018 michael 3109 sendto_one_numeric(source_p, &me,
1019     alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
1020     ERR_CHANOPRIVSNEEDED, chptr->chname);
1021 adx 30 *errors |= SM_ERR_NOOPS;
1022     return;
1023     }
1024    
1025     if (dir == MODE_QUERY)
1026     return;
1027    
1028     if ((dir == MODE_ADD) && parc > *parn)
1029     {
1030 michael 3151 char *lstr = parv[(*parn)++];
1031 adx 30
1032 michael 3153 if (EmptyString(lstr) || (limit = atoi(lstr)) <= 0)
1033 adx 30 return;
1034    
1035 michael 1793 sprintf(lstr, "%d", limit);
1036 adx 30
1037 michael 3151 /* If somebody sets MODE #channel +ll 1 2, accept latter --fl */
1038     for (i = 0; i < mode_count; ++i)
1039 adx 30 if (mode_changes[i].letter == c && mode_changes[i].dir == MODE_ADD)
1040     mode_changes[i].letter = 0;
1041    
1042     mode_changes[mode_count].letter = c;
1043     mode_changes[mode_count].dir = MODE_ADD;
1044     mode_changes[mode_count].mems = ALL_MEMBERS;
1045     mode_changes[mode_count].id = NULL;
1046     mode_changes[mode_count++].arg = lstr;
1047    
1048     chptr->mode.limit = limit;
1049     }
1050     else if (dir == MODE_DEL)
1051     {
1052     if (!chptr->mode.limit)
1053     return;
1054    
1055     chptr->mode.limit = 0;
1056    
1057     mode_changes[mode_count].letter = c;
1058     mode_changes[mode_count].dir = MODE_DEL;
1059     mode_changes[mode_count].mems = ALL_MEMBERS;
1060     mode_changes[mode_count].id = NULL;
1061     mode_changes[mode_count++].arg = NULL;
1062     }
1063     }
1064    
1065     static void
1066 michael 3150 chm_key(struct Client *source_p,
1067 adx 30 struct Channel *chptr, int parc, int *parn,
1068 michael 2937 char **parv, int *errors, int alev, int dir, char c, unsigned int d)
1069 adx 30 {
1070 michael 3151 unsigned int i = 0;
1071 adx 30
1072     if (alev < CHACCESS_HALFOP)
1073     {
1074     if (!(*errors & SM_ERR_NOOPS))
1075 michael 3109 sendto_one_numeric(source_p, &me,
1076     alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
1077     ERR_CHANOPRIVSNEEDED, chptr->chname);
1078 adx 30 *errors |= SM_ERR_NOOPS;
1079     return;
1080     }
1081    
1082     if (dir == MODE_QUERY)
1083     return;
1084    
1085     if ((dir == MODE_ADD) && parc > *parn)
1086     {
1087 michael 3151 char *key = parv[(*parn)++];
1088 adx 30
1089     if (MyClient(source_p))
1090     fix_key(key);
1091     else
1092     fix_key_old(key);
1093    
1094 michael 3153 if (EmptyString(key))
1095 adx 30 return;
1096    
1097     assert(key[0] != ' ');
1098     strlcpy(chptr->mode.key, key, sizeof(chptr->mode.key));
1099    
1100 michael 3151 /* If somebody does MODE #channel +kk a b, accept latter --fl */
1101     for (i = 0; i < mode_count; ++i)
1102 adx 30 if (mode_changes[i].letter == c && mode_changes[i].dir == MODE_ADD)
1103     mode_changes[i].letter = 0;
1104    
1105     mode_changes[mode_count].letter = c;
1106     mode_changes[mode_count].dir = MODE_ADD;
1107     mode_changes[mode_count].mems = ALL_MEMBERS;
1108     mode_changes[mode_count].id = NULL;
1109     mode_changes[mode_count++].arg = chptr->mode.key;
1110     }
1111     else if (dir == MODE_DEL)
1112     {
1113     if (parc > *parn)
1114     (*parn)++;
1115    
1116     if (chptr->mode.key[0] == '\0')
1117     return;
1118    
1119     chptr->mode.key[0] = '\0';
1120    
1121     mode_changes[mode_count].letter = c;
1122     mode_changes[mode_count].dir = MODE_DEL;
1123     mode_changes[mode_count].mems = ALL_MEMBERS;
1124     mode_changes[mode_count].id = NULL;
1125     mode_changes[mode_count++].arg = "*";
1126     }
1127     }
1128    
1129     struct ChannelMode
1130     {
1131 michael 3150 void (*func)(struct Client *,
1132 michael 2937 struct Channel *, int, int *, char **,
1133     int *, int, int, char, unsigned int);
1134     unsigned int d;
1135 adx 30 };
1136    
1137 michael 2939 static struct ChannelMode ModeTable[256] =
1138 adx 30 {
1139 michael 2939 { chm_nosuch, 0 }, /* 0x00 */
1140     { chm_nosuch, 0 }, /* 0x01 */
1141     { chm_nosuch, 0 }, /* 0x02 */
1142     { chm_nosuch, 0 }, /* 0x03 */
1143     { chm_nosuch, 0 }, /* 0x04 */
1144     { chm_nosuch, 0 }, /* 0x05 */
1145     { chm_nosuch, 0 }, /* 0x06 */
1146     { chm_nosuch, 0 }, /* 0x07 */
1147     { chm_nosuch, 0 }, /* 0x08 */
1148     { chm_nosuch, 0 }, /* 0x09 */
1149     { chm_nosuch, 0 }, /* 0x0a */
1150     { chm_nosuch, 0 }, /* 0x0b */
1151     { chm_nosuch, 0 }, /* 0x0c */
1152     { chm_nosuch, 0 }, /* 0x0d */
1153     { chm_nosuch, 0 }, /* 0x0e */
1154     { chm_nosuch, 0 }, /* 0x0f */
1155     { chm_nosuch, 0 }, /* 0x10 */
1156     { chm_nosuch, 0 }, /* 0x11 */
1157     { chm_nosuch, 0 }, /* 0x12 */
1158     { chm_nosuch, 0 }, /* 0x13 */
1159     { chm_nosuch, 0 }, /* 0x14 */
1160     { chm_nosuch, 0 }, /* 0x15 */
1161     { chm_nosuch, 0 }, /* 0x16 */
1162     { chm_nosuch, 0 }, /* 0x17 */
1163     { chm_nosuch, 0 }, /* 0x18 */
1164     { chm_nosuch, 0 }, /* 0x19 */
1165     { chm_nosuch, 0 }, /* 0x1a */
1166     { chm_nosuch, 0 }, /* 0x1b */
1167     { chm_nosuch, 0 }, /* 0x1c */
1168     { chm_nosuch, 0 }, /* 0x1d */
1169     { chm_nosuch, 0 }, /* 0x1e */
1170     { chm_nosuch, 0 }, /* 0x1f */
1171     { chm_nosuch, 0 }, /* 0x20 */
1172     { chm_nosuch, 0 }, /* 0x21 */
1173     { chm_nosuch, 0 }, /* 0x22 */
1174     { chm_nosuch, 0 }, /* 0x23 */
1175     { chm_nosuch, 0 }, /* 0x24 */
1176     { chm_nosuch, 0 }, /* 0x25 */
1177     { chm_nosuch, 0 }, /* 0x26 */
1178     { chm_nosuch, 0 }, /* 0x27 */
1179     { chm_nosuch, 0 }, /* 0x28 */
1180     { chm_nosuch, 0 }, /* 0x29 */
1181     { chm_nosuch, 0 }, /* 0x2a */
1182     { chm_nosuch, 0 }, /* 0x2b */
1183     { chm_nosuch, 0 }, /* 0x2c */
1184     { chm_nosuch, 0 }, /* 0x2d */
1185     { chm_nosuch, 0 }, /* 0x2e */
1186     { chm_nosuch, 0 }, /* 0x2f */
1187     { chm_nosuch, 0 }, /* 0x30 */
1188     { chm_nosuch, 0 }, /* 0x31 */
1189     { chm_nosuch, 0 }, /* 0x32 */
1190     { chm_nosuch, 0 }, /* 0x33 */
1191     { chm_nosuch, 0 }, /* 0x34 */
1192     { chm_nosuch, 0 }, /* 0x35 */
1193     { chm_nosuch, 0 }, /* 0x36 */
1194     { chm_nosuch, 0 }, /* 0x37 */
1195     { chm_nosuch, 0 }, /* 0x38 */
1196     { chm_nosuch, 0 }, /* 0x39 */
1197     { chm_nosuch, 0 }, /* 0x3a */
1198     { chm_nosuch, 0 }, /* 0x3b */
1199     { chm_nosuch, 0 }, /* 0x3c */
1200     { chm_nosuch, 0 }, /* 0x3d */
1201     { chm_nosuch, 0 }, /* 0x3e */
1202     { chm_nosuch, 0 }, /* 0x3f */
1203     { chm_nosuch, 0 }, /* @ */
1204     { chm_nosuch, 0 }, /* A */
1205     { chm_nosuch, 0 }, /* B */
1206     { chm_nosuch, 0 }, /* C */
1207     { chm_nosuch, 0 }, /* D */
1208     { chm_nosuch, 0 }, /* E */
1209     { chm_nosuch, 0 }, /* F */
1210     { chm_nosuch, 0 }, /* G */
1211     { chm_nosuch, 0 }, /* H */
1212     { chm_invex, 0 }, /* I */
1213     { chm_nosuch, 0 }, /* J */
1214     { chm_nosuch, 0 }, /* K */
1215     { chm_nosuch, 0 }, /* L */
1216     { chm_simple, MODE_MODREG}, /* M */
1217     { chm_nosuch, 0 }, /* N */
1218     { chm_operonly, MODE_OPERONLY}, /* O */
1219     { chm_nosuch, 0 }, /* P */
1220     { chm_nosuch, 0 }, /* Q */
1221     { chm_simple, MODE_REGONLY}, /* R */
1222     { chm_simple, MODE_SSLONLY}, /* S */
1223     { chm_nosuch, 0 }, /* T */
1224     { chm_nosuch, 0 }, /* U */
1225     { chm_nosuch, 0 }, /* V */
1226     { chm_nosuch, 0 }, /* W */
1227     { chm_nosuch, 0 }, /* X */
1228     { chm_nosuch, 0 }, /* Y */
1229     { chm_nosuch, 0 }, /* Z */
1230     { chm_nosuch, 0 },
1231     { chm_nosuch, 0 },
1232     { chm_nosuch, 0 },
1233     { chm_nosuch, 0 },
1234     { chm_nosuch, 0 },
1235     { chm_nosuch, 0 },
1236     { chm_nosuch, 0 }, /* a */
1237     { chm_ban, 0 }, /* b */
1238     { chm_simple, MODE_NOCTRL}, /* c */
1239     { chm_nosuch, 0 }, /* d */
1240     { chm_except, 0 }, /* e */
1241     { chm_nosuch, 0 }, /* f */
1242     { chm_nosuch, 0 }, /* g */
1243 adx 30 #ifdef HALFOPS
1244 michael 2939 { chm_hop, 0 }, /* h */
1245 adx 30 #else
1246 michael 2939 { chm_nosuch, 0 }, /* h */
1247 adx 30 #endif
1248 michael 2939 { chm_simple, MODE_INVITEONLY }, /* i */
1249     { chm_nosuch, 0 }, /* j */
1250     { chm_key, 0 }, /* k */
1251     { chm_limit, 0 }, /* l */
1252     { chm_simple, MODE_MODERATED }, /* m */
1253     { chm_simple, MODE_NOPRIVMSGS }, /* n */
1254     { chm_op, 0 }, /* o */
1255     { chm_simple, MODE_PRIVATE }, /* p */
1256     { chm_nosuch, 0 }, /* q */
1257     { chm_registered, MODE_REGISTERED }, /* r */
1258     { chm_simple, MODE_SECRET }, /* s */
1259     { chm_simple, MODE_TOPICLIMIT }, /* t */
1260     { chm_nosuch, 0 }, /* u */
1261     { chm_voice, 0 }, /* v */
1262     { chm_nosuch, 0 }, /* w */
1263     { chm_nosuch, 0 }, /* x */
1264     { chm_nosuch, 0 }, /* y */
1265     { chm_nosuch, 0 }, /* z */
1266     { chm_nosuch, 0 }, /* 0x7b */
1267     { chm_nosuch, 0 }, /* 0x7c */
1268     { chm_nosuch, 0 }, /* 0x7d */
1269     { chm_nosuch, 0 }, /* 0x7e */
1270     { chm_nosuch, 0 }, /* 0x7f */
1271     { chm_nosuch, 0 }, /* 0x80 */
1272     { chm_nosuch, 0 }, /* 0x81 */
1273     { chm_nosuch, 0 }, /* 0x82 */
1274     { chm_nosuch, 0 }, /* 0x83 */
1275     { chm_nosuch, 0 }, /* 0x84 */
1276     { chm_nosuch, 0 }, /* 0x85 */
1277     { chm_nosuch, 0 }, /* 0x86 */
1278     { chm_nosuch, 0 }, /* 0x87 */
1279     { chm_nosuch, 0 }, /* 0x88 */
1280     { chm_nosuch, 0 }, /* 0x89 */
1281     { chm_nosuch, 0 }, /* 0x8a */
1282     { chm_nosuch, 0 }, /* 0x8b */
1283     { chm_nosuch, 0 }, /* 0x8c */
1284     { chm_nosuch, 0 }, /* 0x8d */
1285     { chm_nosuch, 0 }, /* 0x8e */
1286     { chm_nosuch, 0 }, /* 0x8f */
1287     { chm_nosuch, 0 }, /* 0x90 */
1288     { chm_nosuch, 0 }, /* 0x91 */
1289     { chm_nosuch, 0 }, /* 0x92 */
1290     { chm_nosuch, 0 }, /* 0x93 */
1291     { chm_nosuch, 0 }, /* 0x94 */
1292     { chm_nosuch, 0 }, /* 0x95 */
1293     { chm_nosuch, 0 }, /* 0x96 */
1294     { chm_nosuch, 0 }, /* 0x97 */
1295     { chm_nosuch, 0 }, /* 0x98 */
1296     { chm_nosuch, 0 }, /* 0x99 */
1297     { chm_nosuch, 0 }, /* 0x9a */
1298     { chm_nosuch, 0 }, /* 0x9b */
1299     { chm_nosuch, 0 }, /* 0x9c */
1300     { chm_nosuch, 0 }, /* 0x9d */
1301     { chm_nosuch, 0 }, /* 0x9e */
1302     { chm_nosuch, 0 }, /* 0x9f */
1303     { chm_nosuch, 0 }, /* 0xa0 */
1304     { chm_nosuch, 0 }, /* 0xa1 */
1305     { chm_nosuch, 0 }, /* 0xa2 */
1306     { chm_nosuch, 0 }, /* 0xa3 */
1307     { chm_nosuch, 0 }, /* 0xa4 */
1308     { chm_nosuch, 0 }, /* 0xa5 */
1309     { chm_nosuch, 0 }, /* 0xa6 */
1310     { chm_nosuch, 0 }, /* 0xa7 */
1311     { chm_nosuch, 0 }, /* 0xa8 */
1312     { chm_nosuch, 0 }, /* 0xa9 */
1313     { chm_nosuch, 0 }, /* 0xaa */
1314     { chm_nosuch, 0 }, /* 0xab */
1315     { chm_nosuch, 0 }, /* 0xac */
1316     { chm_nosuch, 0 }, /* 0xad */
1317     { chm_nosuch, 0 }, /* 0xae */
1318     { chm_nosuch, 0 }, /* 0xaf */
1319     { chm_nosuch, 0 }, /* 0xb0 */
1320     { chm_nosuch, 0 }, /* 0xb1 */
1321     { chm_nosuch, 0 }, /* 0xb2 */
1322     { chm_nosuch, 0 }, /* 0xb3 */
1323     { chm_nosuch, 0 }, /* 0xb4 */
1324     { chm_nosuch, 0 }, /* 0xb5 */
1325     { chm_nosuch, 0 }, /* 0xb6 */
1326     { chm_nosuch, 0 }, /* 0xb7 */
1327     { chm_nosuch, 0 }, /* 0xb8 */
1328     { chm_nosuch, 0 }, /* 0xb9 */
1329     { chm_nosuch, 0 }, /* 0xba */
1330     { chm_nosuch, 0 }, /* 0xbb */
1331     { chm_nosuch, 0 }, /* 0xbc */
1332     { chm_nosuch, 0 }, /* 0xbd */
1333     { chm_nosuch, 0 }, /* 0xbe */
1334     { chm_nosuch, 0 }, /* 0xbf */
1335     { chm_nosuch, 0 }, /* 0xc0 */
1336     { chm_nosuch, 0 }, /* 0xc1 */
1337     { chm_nosuch, 0 }, /* 0xc2 */
1338     { chm_nosuch, 0 }, /* 0xc3 */
1339     { chm_nosuch, 0 }, /* 0xc4 */
1340     { chm_nosuch, 0 }, /* 0xc5 */
1341     { chm_nosuch, 0 }, /* 0xc6 */
1342     { chm_nosuch, 0 }, /* 0xc7 */
1343     { chm_nosuch, 0 }, /* 0xc8 */
1344     { chm_nosuch, 0 }, /* 0xc9 */
1345     { chm_nosuch, 0 }, /* 0xca */
1346     { chm_nosuch, 0 }, /* 0xcb */
1347     { chm_nosuch, 0 }, /* 0xcc */
1348     { chm_nosuch, 0 }, /* 0xcd */
1349     { chm_nosuch, 0 }, /* 0xce */
1350     { chm_nosuch, 0 }, /* 0xcf */
1351     { chm_nosuch, 0 }, /* 0xd0 */
1352     { chm_nosuch, 0 }, /* 0xd1 */
1353     { chm_nosuch, 0 }, /* 0xd2 */
1354     { chm_nosuch, 0 }, /* 0xd3 */
1355     { chm_nosuch, 0 }, /* 0xd4 */
1356     { chm_nosuch, 0 }, /* 0xd5 */
1357     { chm_nosuch, 0 }, /* 0xd6 */
1358     { chm_nosuch, 0 }, /* 0xd7 */
1359     { chm_nosuch, 0 }, /* 0xd8 */
1360     { chm_nosuch, 0 }, /* 0xd9 */
1361     { chm_nosuch, 0 }, /* 0xda */
1362     { chm_nosuch, 0 }, /* 0xdb */
1363     { chm_nosuch, 0 }, /* 0xdc */
1364     { chm_nosuch, 0 }, /* 0xdd */
1365     { chm_nosuch, 0 }, /* 0xde */
1366     { chm_nosuch, 0 }, /* 0xdf */
1367     { chm_nosuch, 0 }, /* 0xe0 */
1368     { chm_nosuch, 0 }, /* 0xe1 */
1369     { chm_nosuch, 0 }, /* 0xe2 */
1370     { chm_nosuch, 0 }, /* 0xe3 */
1371     { chm_nosuch, 0 }, /* 0xe4 */
1372     { chm_nosuch, 0 }, /* 0xe5 */
1373     { chm_nosuch, 0 }, /* 0xe6 */
1374     { chm_nosuch, 0 }, /* 0xe7 */
1375     { chm_nosuch, 0 }, /* 0xe8 */
1376     { chm_nosuch, 0 }, /* 0xe9 */
1377     { chm_nosuch, 0 }, /* 0xea */
1378     { chm_nosuch, 0 }, /* 0xeb */
1379     { chm_nosuch, 0 }, /* 0xec */
1380     { chm_nosuch, 0 }, /* 0xed */
1381     { chm_nosuch, 0 }, /* 0xee */
1382     { chm_nosuch, 0 }, /* 0xef */
1383     { chm_nosuch, 0 }, /* 0xf0 */
1384     { chm_nosuch, 0 }, /* 0xf1 */
1385     { chm_nosuch, 0 }, /* 0xf2 */
1386     { chm_nosuch, 0 }, /* 0xf3 */
1387     { chm_nosuch, 0 }, /* 0xf4 */
1388     { chm_nosuch, 0 }, /* 0xf5 */
1389     { chm_nosuch, 0 }, /* 0xf6 */
1390     { chm_nosuch, 0 }, /* 0xf7 */
1391     { chm_nosuch, 0 }, /* 0xf8 */
1392     { chm_nosuch, 0 }, /* 0xf9 */
1393     { chm_nosuch, 0 }, /* 0xfa */
1394     { chm_nosuch, 0 }, /* 0xfb */
1395     { chm_nosuch, 0 }, /* 0xfc */
1396     { chm_nosuch, 0 }, /* 0xfd */
1397     { chm_nosuch, 0 }, /* 0xfe */
1398     { chm_nosuch, 0 }, /* 0xff */
1399 adx 30 };
1400    
1401     /* get_channel_access()
1402     *
1403     * inputs - pointer to Client struct
1404     * - pointer to Membership struct
1405     * output - CHACCESS_CHANOP if we should let them have
1406     * chanop level access, 0 for peon level access.
1407     * side effects - NONE
1408     */
1409     static int
1410 michael 2941 get_channel_access(const struct Client *source_p,
1411     const struct Membership *member)
1412 adx 30 {
1413     /* Let hacked servers in for now... */
1414     if (!MyClient(source_p))
1415     return CHACCESS_CHANOP;
1416    
1417     if (member == NULL)
1418     return CHACCESS_NOTONCHAN;
1419    
1420     /* just to be sure.. */
1421     assert(source_p == member->client_p);
1422    
1423     if (has_member_flags(member, CHFL_CHANOP))
1424     return CHACCESS_CHANOP;
1425    
1426     #ifdef HALFOPS
1427     if (has_member_flags(member, CHFL_HALFOP))
1428     return CHACCESS_HALFOP;
1429     #endif
1430    
1431     return CHACCESS_PEON;
1432     }
1433    
1434 michael 3151 /* send_mode_changes_server()
1435 michael 3159 * Input: the source client(source_p),
1436 adx 30 * the channel to send mode changes for(chptr)
1437     * Output: None.
1438 michael 3151 * Side-effects: Sends the appropriate mode changes to servers.
1439 adx 30 *
1440     */
1441     static void
1442 michael 3150 send_mode_changes_server(struct Client *source_p, struct Channel *chptr)
1443 adx 30 {
1444 michael 3057 unsigned int i;
1445 michael 3151 int mbl = 0, pbl = 0, arglen = 0, nc = 0, mc = 0;
1446     int len = 0;
1447 adx 30 const char *arg = NULL;
1448     char *parptr;
1449     int dir = MODE_QUERY;
1450    
1451     parabuf[0] = '\0';
1452     parptr = parabuf;
1453    
1454 michael 3135 mbl = snprintf(modebuf, sizeof(modebuf), ":%s TMODE %lu %s ", source_p->id,
1455     (unsigned long)chptr->channelts, chptr->chname);
1456 adx 30
1457 michael 3151 /* loop the list of modes we have */
1458 michael 3140 for (i = 0; i < mode_count; ++i)
1459 adx 30 {
1460 michael 3140 if (mode_changes[i].letter == 0) /* XXX: can it ever happen? */
1461 adx 30 continue;
1462    
1463 michael 3141 if (mode_changes[i].id)
1464     arg = mode_changes[i].id;
1465     else
1466     arg = mode_changes[i].arg;
1467 adx 30
1468 michael 3141 if (arg != NULL)
1469     arglen = strlen(arg);
1470     else
1471     arglen = 0;
1472    
1473 michael 3136 /*
1474     * If we're creeping past the buf size, we need to send it and make
1475 adx 30 * another line for the other modes
1476     */
1477     if ((mc == MAXMODEPARAMS) ||
1478     ((arglen + mbl + pbl + 2) > IRCD_BUFSIZE) ||
1479     (pbl + arglen + BAN_FUDGE) >= MODEBUFLEN)
1480     {
1481     if (nc != 0)
1482 michael 3150 sendto_server(source_p, NOCAPS, NOCAPS, "%s %s", modebuf, parabuf);
1483 adx 30 nc = 0;
1484     mc = 0;
1485    
1486 michael 3135 mbl = snprintf(modebuf, sizeof(modebuf), ":%s TMODE %lu %s ", source_p->id,
1487     (unsigned long)chptr->channelts, chptr->chname);
1488 adx 30
1489     pbl = 0;
1490     parabuf[0] = '\0';
1491     parptr = parabuf;
1492     dir = MODE_QUERY;
1493     }
1494    
1495     if (dir != mode_changes[i].dir)
1496     {
1497     modebuf[mbl++] = (mode_changes[i].dir == MODE_ADD) ? '+' : '-';
1498     dir = mode_changes[i].dir;
1499     }
1500    
1501     modebuf[mbl++] = mode_changes[i].letter;
1502     modebuf[mbl] = '\0';
1503     nc++;
1504    
1505     if (arg != NULL)
1506     {
1507 michael 1793 len = sprintf(parptr, "%s ", arg);
1508 adx 30 pbl += len;
1509     parptr += len;
1510     mc++;
1511     }
1512     }
1513    
1514     if (pbl && parabuf[pbl - 1] == ' ')
1515 michael 3149 parabuf[pbl - 1] = '\0';
1516 adx 30
1517     if (nc != 0)
1518 michael 3150 sendto_server(source_p, NOCAPS, NOCAPS, "%s %s", modebuf, parabuf);
1519 adx 30 }
1520    
1521     /* void send_mode_changes(struct Client *client_p,
1522     * struct Client *source_p,
1523     * struct Channel *chptr)
1524     * Input: The client sending(client_p), the source client(source_p),
1525     * the channel to send mode changes for(chptr),
1526     * mode change globals.
1527     * Output: None.
1528     * Side-effects: Sends the appropriate mode changes to other clients
1529     * and propagates to servers.
1530     */
1531     /* ensure parabuf < MODEBUFLEN -db */
1532     static void
1533 michael 3150 send_mode_changes(struct Client *source_p, struct Channel *chptr)
1534 adx 30 {
1535 michael 3057 unsigned int i;
1536 michael 3151 int mbl = 0, pbl = 0, arglen = 0, nc = 0, mc = 0;
1537     int len = 0;
1538 adx 30 const char *arg = NULL;
1539     char *parptr;
1540     int dir = MODE_QUERY;
1541    
1542 michael 3151 /* Bail out if we have nothing to do... */
1543 adx 30 if (!mode_count)
1544     return;
1545    
1546     if (IsServer(source_p))
1547 michael 3029 mbl = snprintf(modebuf, sizeof(modebuf), ":%s MODE %s ", (IsHidden(source_p) ||
1548     ConfigServerHide.hide_servers) ?
1549     me.name : source_p->name, chptr->chname);
1550 adx 30 else
1551 michael 3029 mbl = snprintf(modebuf, sizeof(modebuf), ":%s!%s@%s MODE %s ", source_p->name,
1552     source_p->username, source_p->host, chptr->chname);
1553 adx 30
1554     parabuf[0] = '\0';
1555     parptr = parabuf;
1556    
1557 michael 3140 for (i = 0; i < mode_count; ++i)
1558 adx 30 {
1559     if (mode_changes[i].letter == 0 ||
1560     mode_changes[i].mems == NON_CHANOPS ||
1561     mode_changes[i].mems == ONLY_SERVERS)
1562     continue;
1563    
1564     arg = mode_changes[i].arg;
1565     if (arg != NULL)
1566     arglen = strlen(arg);
1567     else
1568     arglen = 0;
1569    
1570 michael 2892 if ((mc == MAXMODEPARAMS) ||
1571 adx 30 ((arglen + mbl + pbl + 2) > IRCD_BUFSIZE) ||
1572 michael 2892 ((arglen + pbl + BAN_FUDGE) >= MODEBUFLEN))
1573 adx 30 {
1574     if (mbl && modebuf[mbl - 1] == '-')
1575     modebuf[mbl - 1] = '\0';
1576    
1577     if (nc != 0)
1578 michael 1243 sendto_channel_local(ALL_MEMBERS, 0, chptr, "%s %s", modebuf, parabuf);
1579 adx 30
1580     nc = 0;
1581     mc = 0;
1582    
1583     if (IsServer(source_p))
1584 michael 3029 mbl = snprintf(modebuf, sizeof(modebuf), ":%s MODE %s ", (IsHidden(source_p) ||
1585     ConfigServerHide.hide_servers) ?
1586     me.name : source_p->name, chptr->chname);
1587 adx 30 else
1588 michael 3029 mbl = snprintf(modebuf, sizeof(modebuf), ":%s!%s@%s MODE %s ", source_p->name,
1589     source_p->username, source_p->host, chptr->chname);
1590 adx 30
1591     pbl = 0;
1592     parabuf[0] = '\0';
1593     parptr = parabuf;
1594     dir = MODE_QUERY;
1595     }
1596    
1597     if (dir != mode_changes[i].dir)
1598     {
1599     modebuf[mbl++] = (mode_changes[i].dir == MODE_ADD) ? '+' : '-';
1600     dir = mode_changes[i].dir;
1601     }
1602    
1603     modebuf[mbl++] = mode_changes[i].letter;
1604     modebuf[mbl] = '\0';
1605     nc++;
1606    
1607     if (arg != NULL)
1608     {
1609 michael 1793 len = sprintf(parptr, "%s ", arg);
1610 adx 30 pbl += len;
1611     parptr += len;
1612     mc++;
1613     }
1614     }
1615    
1616     if (pbl && parabuf[pbl - 1] == ' ')
1617 michael 3149 parabuf[pbl - 1] = '\0';
1618 adx 30
1619     if (nc != 0)
1620 michael 1243 sendto_channel_local(ALL_MEMBERS, 0, chptr, "%s %s", modebuf, parabuf);
1621 adx 30
1622 michael 3150 send_mode_changes_server(source_p, chptr);
1623 adx 30 }
1624    
1625 michael 3159 /*
1626     * Input: The the client this originated
1627 adx 30 * from, the channel, the parameter count starting at the modes,
1628     * the parameters, the channel name.
1629     * Output: None.
1630     * Side-effects: Changes the channel membership and modes appropriately,
1631     * sends the appropriate MODE messages to the appropriate
1632     * clients.
1633     */
1634     void
1635 michael 3150 set_channel_mode(struct Client *source_p, struct Channel *chptr,
1636 michael 2937 struct Membership *member, int parc, char *parv[])
1637 adx 30 {
1638     int dir = MODE_ADD;
1639     int parn = 1;
1640     int alevel, errors = 0;
1641     char *ml = parv[0], c;
1642    
1643     mode_count = 0;
1644     mode_limit = 0;
1645     simple_modes_mask = 0;
1646    
1647     alevel = get_channel_access(source_p, member);
1648    
1649 michael 2939 for (; (c = *ml); ++ml)
1650 adx 30 {
1651     switch (c)
1652     {
1653     case '+':
1654     dir = MODE_ADD;
1655     break;
1656     case '-':
1657     dir = MODE_DEL;
1658     break;
1659     case '=':
1660     dir = MODE_QUERY;
1661     break;
1662     default:
1663 michael 2939 {
1664     struct ChannelMode *tptr = &ModeTable[(unsigned char)c];
1665    
1666 michael 3150 tptr->func(source_p, chptr, parc, &parn, parv,
1667     &errors, alevel, dir, c, tptr->d);
1668 adx 30 break;
1669 michael 2939 }
1670 adx 30 }
1671     }
1672    
1673 michael 3150 send_mode_changes(source_p, chptr);
1674 adx 30 }

Properties

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