ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/channel_mode.c
Revision: 2939
Committed: Sun Jan 26 12:51:50 2014 UTC (11 years, 7 months ago) by michael
Content type: text/x-csrc
File size: 54685 byte(s)
Log Message:
- channel_mode.c: minor optimizations to set_channel_mode()

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

Properties

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