ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/channel_mode.c
Revision: 3144
Committed: Wed Mar 12 20:02:20 2014 UTC (11 years, 5 months ago) by michael
Content type: text/x-csrc
File size: 48008 byte(s)
Log Message:
- removed unused variables

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

Properties

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