ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/channel_mode.c
Revision: 3687
Committed: Thu May 29 16:12:37 2014 UTC (11 years, 3 months ago) by michael
Content type: text/x-csrc
File size: 45650 byte(s)
Log Message:
- channel_mode.c:channel_modes(): replaced sprintf with strcat;
  use %u conversion specifier for unsigned ints

File Contents

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

Properties

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