ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/channel_mode.c
Revision: 3057
Committed: Wed Feb 26 19:33:54 2014 UTC (11 years, 6 months ago) by michael
Content type: text/x-csrc
File size: 54955 byte(s)
Log Message:
- channel_mode.c: made mode_count, mode_limit, simple_modes_mask unsigned int types

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 #define NCHCAPS (sizeof(channel_capabs)/sizeof(int))
46     #define NCHCAP_COMBOS (1 << NCHCAPS)
47    
48 michael 2892
49 michael 388 static char nuh_mask[MAXPARA][IRCD_BUFSIZE];
50 adx 30 /* some buffers for rebuilding channel/nick lists with ,'s */
51     static char modebuf[IRCD_BUFSIZE];
52     static char parabuf[MODEBUFLEN];
53     static struct ChModeChange mode_changes[IRCD_BUFSIZE];
54 michael 3057 static unsigned int mode_count;
55     static unsigned int mode_limit; /* number of modes set other than simple */
56     static unsigned int simple_modes_mask; /* bit mask of simple modes already set */
57 adx 356 #ifdef HALFOPS
58 michael 3049 static int channel_capabs[] = { CAP_TS6, CAP_HOPS };
59 adx 356 #else
60 michael 3049 static int channel_capabs[] = { CAP_TS6 };
61 adx 356 #endif
62 adx 30 static struct ChCapCombo chcap_combos[NCHCAP_COMBOS];
63 michael 1654 extern mp_pool_t *ban_pool;
64 adx 30
65    
66     /* check_string()
67     *
68     * inputs - string to check
69     * output - pointer to modified string
70     * side effects - Fixes a string so that the first white space found
71     * becomes an end of string marker (`\0`).
72     * returns the 'fixed' string or "*" if the string
73     * was NULL length or a NULL pointer.
74     */
75     static char *
76     check_string(char *s)
77     {
78     char *str = s;
79     static char star[] = "*";
80    
81 michael 1772 if (EmptyString(str))
82 michael 593 return star;
83 adx 30
84     for (; *s; ++s)
85     {
86     if (IsSpace(*s))
87     {
88     *s = '\0';
89     break;
90     }
91     }
92    
93 michael 1772 return EmptyString(str) ? star : str;
94 adx 30 }
95    
96     /*
97     * Ban functions to work with mode +b/e/d/I
98     */
99 michael 2892 /* add the specified ID to the channel.
100     * -is 8/9/00
101 adx 30 */
102    
103     int
104 michael 3044 add_id(struct Client *client_p, struct Channel *chptr, char *banid, unsigned int type)
105 adx 30 {
106 michael 593 dlink_list *list = NULL;
107     dlink_node *ban = NULL;
108 adx 30 size_t len = 0;
109 michael 593 struct Ban *ban_p = NULL;
110 adx 30 unsigned int num_mask;
111 michael 1431 char name[NICKLEN + 1];
112 michael 593 char user[USERLEN + 1];
113     char host[HOSTLEN + 1];
114     struct split_nuh_item nuh;
115 adx 30
116     /* dont let local clients overflow the b/e/I lists */
117     if (MyClient(client_p))
118     {
119     num_mask = dlink_list_length(&chptr->banlist) +
120     dlink_list_length(&chptr->exceptlist) +
121     dlink_list_length(&chptr->invexlist);
122    
123     if (num_mask >= ConfigChannel.max_bans)
124     {
125 michael 1834 sendto_one(client_p, form_str(ERR_BANLISTFULL),
126 adx 30 me.name, client_p->name, chptr->chname, banid);
127     return 0;
128     }
129    
130     collapse(banid);
131     }
132    
133 michael 593 nuh.nuhmask = check_string(banid);
134     nuh.nickptr = name;
135     nuh.userptr = user;
136     nuh.hostptr = host;
137 adx 30
138 michael 593 nuh.nicksize = sizeof(name);
139     nuh.usersize = sizeof(user);
140     nuh.hostsize = sizeof(host);
141    
142     split_nuh(&nuh);
143    
144 adx 30 /*
145 michael 593 * Re-assemble a new n!u@h and print it back to banid for sending
146 adx 30 * the mode to the channel.
147     */
148 michael 1793 len = sprintf(banid, "%s!%s@%s", name, user, host);
149 adx 30
150     switch (type)
151     {
152     case CHFL_BAN:
153     list = &chptr->banlist;
154     clear_ban_cache(chptr);
155     break;
156     case CHFL_EXCEPTION:
157     list = &chptr->exceptlist;
158     clear_ban_cache(chptr);
159     break;
160     case CHFL_INVEX:
161     list = &chptr->invexlist;
162     break;
163     default:
164     assert(0);
165     return 0;
166     }
167    
168     DLINK_FOREACH(ban, list->head)
169     {
170 michael 593 ban_p = ban->data;
171 michael 2892
172 michael 593 if (!irccmp(ban_p->name, name) &&
173 michael 2296 !irccmp(ban_p->user, user) &&
174 michael 593 !irccmp(ban_p->host, host))
175 adx 30 return 0;
176     }
177    
178 michael 1654 ban_p = mp_pool_get(ban_pool);
179     memset(ban_p, 0, sizeof(*ban_p));
180 michael 1646 ban_p->name = xstrdup(name);
181 michael 2296 ban_p->user = xstrdup(user);
182 michael 1646 ban_p->host = xstrdup(host);
183 michael 593 ban_p->when = CurrentTime;
184 michael 2892 ban_p->len = len - 2; /* -2 for @ and ! */
185 michael 593 ban_p->type = parse_netmask(host, &ban_p->addr, &ban_p->bits);
186    
187 adx 30 if (IsClient(client_p))
188     {
189 michael 593 ban_p->who = MyMalloc(strlen(client_p->name) +
190     strlen(client_p->username) +
191     strlen(client_p->host) + 3);
192 michael 1793 sprintf(ban_p->who, "%s!%s@%s", client_p->name,
193 michael 2296 client_p->username, client_p->host);
194 adx 30 }
195 michael 2242 else if (IsHidden(client_p) || (IsServer(client_p) && ConfigServerHide.hide_servers))
196     ban_p->who = xstrdup(me.name);
197 adx 30 else
198 michael 1646 ban_p->who = xstrdup(client_p->name);
199 adx 30
200 michael 593 dlinkAdd(ban_p, &ban_p->node, list);
201 adx 30
202     return 1;
203     }
204    
205     /*
206     * inputs - pointer to channel
207     * - pointer to ban id
208     * - type of ban, i.e. ban, exception, invex
209     * output - 0 for failure, 1 for success
210     * side effects -
211     */
212     static int
213 michael 3044 del_id(struct Channel *chptr, char *banid, unsigned int type)
214 adx 30 {
215     dlink_list *list;
216     dlink_node *ban;
217     struct Ban *banptr;
218 michael 1431 char name[NICKLEN + 1];
219 michael 593 char user[USERLEN + 1];
220     char host[HOSTLEN + 1];
221     struct split_nuh_item nuh;
222 adx 30
223 michael 2892 assert(banid);
224 adx 30
225 michael 593 nuh.nuhmask = check_string(banid);
226     nuh.nickptr = name;
227     nuh.userptr = user;
228     nuh.hostptr = host;
229 adx 30
230 michael 593 nuh.nicksize = sizeof(name);
231     nuh.usersize = sizeof(user);
232     nuh.hostsize = sizeof(host);
233    
234     split_nuh(&nuh);
235    
236 adx 30 /*
237 michael 593 * Re-assemble a new n!u@h and print it back to banid for sending
238 adx 30 * the mode to the channel.
239     */
240 michael 1793 sprintf(banid, "%s!%s@%s", name, user, host);
241 adx 30
242     switch (type)
243     {
244     case CHFL_BAN:
245     list = &chptr->banlist;
246     clear_ban_cache(chptr);
247     break;
248     case CHFL_EXCEPTION:
249     list = &chptr->exceptlist;
250     clear_ban_cache(chptr);
251     break;
252     case CHFL_INVEX:
253     list = &chptr->invexlist;
254     break;
255     default:
256 michael 2892 assert(0);
257 michael 593 return 0;
258 adx 30 }
259    
260     DLINK_FOREACH(ban, list->head)
261     {
262     banptr = ban->data;
263    
264     if (!irccmp(name, banptr->name) &&
265 michael 2296 !irccmp(user, banptr->user) &&
266 michael 593 !irccmp(host, banptr->host))
267 adx 30 {
268     remove_ban(banptr, list);
269     return 1;
270     }
271     }
272    
273     return 0;
274     }
275    
276 michael 2892 const struct mode_letter chan_modes[] =
277     {
278 michael 1937 { MODE_NOCTRL, 'c' },
279 adx 30 { MODE_INVITEONLY, 'i' },
280     { MODE_MODERATED, 'm' },
281     { MODE_NOPRIVMSGS, 'n' },
282     { MODE_PRIVATE, 'p' },
283 michael 1167 { MODE_REGISTERED, 'r' },
284 adx 30 { MODE_SECRET, 's' },
285     { MODE_TOPICLIMIT, 't' },
286 michael 1954 { MODE_MODREG, 'M' },
287 michael 1150 { MODE_OPERONLY, 'O' },
288 michael 1175 { MODE_REGONLY, 'R' },
289 michael 1150 { MODE_SSLONLY, 'S' },
290 adx 30 { 0, '\0' }
291     };
292    
293     /* channel_modes()
294     *
295     * inputs - pointer to channel
296     * - pointer to client
297     * - pointer to mode buf
298     * - pointer to parameter buf
299     * output - NONE
300     * side effects - write the "simple" list of channel modes for channel
301     * chptr onto buffer mbuf with the parameters in pbuf.
302     */
303     void
304     channel_modes(struct Channel *chptr, struct Client *client_p,
305     char *mbuf, char *pbuf)
306     {
307 michael 1175 const struct mode_letter *tab = chan_modes;
308 adx 30
309     *mbuf++ = '+';
310     *pbuf = '\0';
311    
312 michael 1175 for (; tab->mode; ++tab)
313     if (chptr->mode.mode & tab->mode)
314     *mbuf++ = tab->letter;
315 adx 30
316     if (chptr->mode.limit)
317     {
318     *mbuf++ = 'l';
319    
320 michael 1219 if (IsServer(client_p) || HasFlag(client_p, FLAGS_SERVICE) || IsMember(client_p, chptr))
321 michael 1793 pbuf += sprintf(pbuf, "%d ", chptr->mode.limit);
322 adx 30 }
323    
324     if (chptr->mode.key[0])
325     {
326     *mbuf++ = 'k';
327    
328 michael 1219 if (IsServer(client_p) || HasFlag(client_p, FLAGS_SERVICE) || IsMember(client_p, chptr))
329 michael 1793 sprintf(pbuf, "%s ", chptr->mode.key);
330 adx 30 }
331    
332     *mbuf = '\0';
333     }
334    
335     /* fix_key()
336 michael 2892 *
337 adx 30 * inputs - pointer to key to clean up
338     * output - pointer to cleaned up key
339     * side effects - input string is modified
340     *
341     * stolen from Undernet's ircd -orabidoo
342     */
343     static char *
344     fix_key(char *arg)
345     {
346     unsigned char *s, *t, c;
347    
348     for (s = t = (unsigned char *)arg; (c = *s); s++)
349     {
350     c &= 0x7f;
351 michael 2892
352 adx 30 if (c != ':' && c > ' ' && c != ',')
353     *t++ = c;
354     }
355    
356     *t = '\0';
357 michael 2892 return arg;
358 adx 30 }
359    
360     /* fix_key_old()
361 michael 2892 *
362 adx 30 * inputs - pointer to key to clean up
363     * output - pointer to cleaned up key
364 michael 2892 * side effects - input string is modifed
365 adx 30 *
366     * Here we attempt to be compatible with older non-hybrid servers.
367     * We can't back down from the ':' issue however. --Rodder
368     */
369     static char *
370     fix_key_old(char *arg)
371     {
372     unsigned char *s, *t, c;
373    
374     for (s = t = (unsigned char *)arg; (c = *s); s++)
375     {
376     c &= 0x7f;
377 michael 2892
378     if ((c != 0x0a) && (c != ':') &&
379     (c != 0x0d) && (c != ','))
380 adx 30 *t++ = c;
381     }
382    
383     *t = '\0';
384 michael 2892 return arg;
385 adx 30 }
386    
387     /* bitmasks for various error returns that set_channel_mode should only return
388     * once per call -orabidoo
389     */
390    
391     #define SM_ERR_NOTS 0x00000001 /* No TS on channel */
392     #define SM_ERR_NOOPS 0x00000002 /* No chan ops */
393     #define SM_ERR_UNKNOWN 0x00000004
394     #define SM_ERR_RPL_B 0x00000008
395     #define SM_ERR_RPL_E 0x00000010
396     #define SM_ERR_NOTONCHANNEL 0x00000020 /* Not on channel */
397     #define SM_ERR_RPL_I 0x00000040
398 michael 1150 #define SM_ERR_NOTOPER 0x00000080
399 michael 1167 #define SM_ERR_ONLYSERVER 0x00000100
400 adx 30
401     /* Now lets do some stuff to keep track of what combinations of
402     * servers exist...
403     * Note that the number of combinations doubles each time you add
404     * something to this list. Each one is only quick if no servers use that
405     * combination, but if the numbers get too high here MODE will get too
406     * slow. I suggest if you get more than 7 here, you consider getting rid
407     * of some and merging or something. If it wasn't for irc+cs we would
408     * probably not even need to bother about most of these, but unfortunately
409     * we do. -A1kmm
410     */
411    
412     /* void init_chcap_usage_counts(void)
413     *
414     * Inputs - none
415     * Output - none
416     * Side-effects - Initialises the usage counts to zero. Fills in the
417     * chcap_yes and chcap_no combination tables.
418     */
419     void
420     init_chcap_usage_counts(void)
421     {
422     unsigned long m, c, y, n;
423    
424     memset(chcap_combos, 0, sizeof(chcap_combos));
425    
426     /* For every possible combination */
427     for (m = 0; m < NCHCAP_COMBOS; m++)
428     {
429     /* Check each capab */
430     for (c = y = n = 0; c < NCHCAPS; c++)
431     {
432     if ((m & (1 << c)) == 0)
433     n |= channel_capabs[c];
434     else
435     y |= channel_capabs[c];
436     }
437 michael 2892
438 adx 30 chcap_combos[m].cap_yes = y;
439     chcap_combos[m].cap_no = n;
440     }
441     }
442    
443     /* void set_chcap_usage_counts(struct Client *serv_p)
444     * Input: serv_p; The client whose capabs to register.
445     * Output: none
446     * Side-effects: Increments the usage counts for the correct capab
447     * combination.
448     */
449     void
450     set_chcap_usage_counts(struct Client *serv_p)
451     {
452     int n;
453    
454     for (n = 0; n < NCHCAP_COMBOS; n++)
455     {
456     if (((serv_p->localClient->caps & chcap_combos[n].cap_yes) ==
457     chcap_combos[n].cap_yes) &&
458     ((serv_p->localClient->caps & chcap_combos[n].cap_no) == 0))
459     {
460     chcap_combos[n].count++;
461     return;
462     }
463     }
464    
465     /* This should be impossible -A1kmm. */
466     assert(0);
467     }
468    
469     /* void set_chcap_usage_counts(struct Client *serv_p)
470     *
471     * Inputs - serv_p; The client whose capabs to register.
472     * Output - none
473     * Side-effects - Decrements the usage counts for the correct capab
474     * combination.
475     */
476     void
477     unset_chcap_usage_counts(struct Client *serv_p)
478     {
479     int n;
480    
481     for (n = 0; n < NCHCAP_COMBOS; n++)
482     {
483     if ((serv_p->localClient->caps & chcap_combos[n].cap_yes) ==
484     chcap_combos[n].cap_yes &&
485     (serv_p->localClient->caps & chcap_combos[n].cap_no) == 0)
486     {
487     /* Hopefully capabs can't change dynamically or anything... */
488     assert(chcap_combos[n].count > 0);
489     chcap_combos[n].count--;
490     return;
491     }
492     }
493    
494     /* This should be impossible -A1kmm. */
495     assert(0);
496     }
497    
498     /* Mode functions handle mode changes for a particular mode... */
499     static void
500     chm_nosuch(struct Client *client_p, struct Client *source_p,
501     struct Channel *chptr, int parc, int *parn,
502 michael 2937 char **parv, int *errors, int alev, int dir, char c, unsigned int d)
503 adx 30 {
504     if (*errors & SM_ERR_UNKNOWN)
505     return;
506    
507     *errors |= SM_ERR_UNKNOWN;
508 michael 1834 sendto_one(source_p, form_str(ERR_UNKNOWNMODE), me.name,
509 adx 30 source_p->name, c);
510     }
511    
512     static void
513     chm_simple(struct Client *client_p, struct Client *source_p, struct Channel *chptr,
514     int parc, int *parn, char **parv, int *errors, int alev, int dir,
515 michael 2937 char c, unsigned int d)
516 adx 30 {
517     if ((alev < CHACCESS_HALFOP) ||
518 michael 2937 ((d == MODE_PRIVATE) && (alev < CHACCESS_CHANOP)))
519 adx 30 {
520     if (!(*errors & SM_ERR_NOOPS))
521 michael 1834 sendto_one(source_p, form_str(alev == CHACCESS_NOTONCHAN ?
522     ERR_NOTONCHANNEL : ERR_CHANOPRIVSNEEDED),
523 michael 2937 me.name, source_p->name, chptr->chname);
524 adx 30 *errors |= SM_ERR_NOOPS;
525     return;
526     }
527    
528     /* If have already dealt with this simple mode, ignore it */
529 michael 2937 if (simple_modes_mask & d)
530 adx 30 return;
531    
532 michael 2937 simple_modes_mask |= d;
533 adx 30
534     /* setting + */
535 michael 2892 /* Apparently, (though no one has ever told the hybrid group directly)
536     * admins don't like redundant mode checking. ok. It would have been nice
537     * if you had have told us directly. I've left the original code snippets
538     * in place.
539     *
540     * -Dianora
541     */
542 michael 2937 if (dir == MODE_ADD) /* && !(chptr->mode.mode & d)) */
543 adx 30 {
544 michael 2937 chptr->mode.mode |= d;
545 adx 30
546     mode_changes[mode_count].letter = c;
547     mode_changes[mode_count].dir = MODE_ADD;
548     mode_changes[mode_count].caps = 0;
549     mode_changes[mode_count].nocaps = 0;
550     mode_changes[mode_count].id = NULL;
551     mode_changes[mode_count].mems = ALL_MEMBERS;
552     mode_changes[mode_count++].arg = NULL;
553     }
554 michael 2937 else if (dir == MODE_DEL) /* && (chptr->mode.mode & d)) */
555 adx 30 {
556     /* setting - */
557    
558 michael 2937 chptr->mode.mode &= ~d;
559 adx 30
560     mode_changes[mode_count].letter = c;
561     mode_changes[mode_count].dir = MODE_DEL;
562     mode_changes[mode_count].caps = 0;
563     mode_changes[mode_count].nocaps = 0;
564     mode_changes[mode_count].mems = ALL_MEMBERS;
565     mode_changes[mode_count].id = NULL;
566     mode_changes[mode_count++].arg = NULL;
567     }
568     }
569    
570     static void
571 michael 1167 chm_registered(struct Client *client_p, struct Client *source_p, struct Channel *chptr,
572     int parc, int *parn, char **parv, int *errors, int alev, int dir,
573 michael 2937 char c, unsigned int d)
574 michael 1167 {
575 michael 1219 if (!IsServer(source_p) && !HasFlag(source_p, FLAGS_SERVICE))
576 michael 1167 {
577     if (!(*errors & SM_ERR_ONLYSERVER))
578 michael 1834 sendto_one(source_p, form_str(alev == CHACCESS_NOTONCHAN ?
579     ERR_NOTONCHANNEL : ERR_ONLYSERVERSCANCHANGE),
580 michael 2937 me.name, source_p->name, chptr->chname);
581 michael 1167 *errors |= SM_ERR_ONLYSERVER;
582     return;
583     }
584    
585     /* If have already dealt with this simple mode, ignore it */
586 michael 2937 if (simple_modes_mask & d)
587 michael 1167 return;
588    
589 michael 2937 simple_modes_mask |= d;
590 michael 1167
591     /* setting + */
592 michael 2892 /* Apparently, (though no one has ever told the hybrid group directly)
593     * admins don't like redundant mode checking. ok. It would have been nice
594     * if you had have told us directly. I've left the original code snippets
595     * in place.
596     *
597     * -Dianora
598 michael 1167 */
599 michael 2937 if (dir == MODE_ADD) /* && !(chptr->mode.mode & d)) */
600 michael 1167 {
601 michael 2937 chptr->mode.mode |= d;
602 michael 1167
603     mode_changes[mode_count].letter = c;
604     mode_changes[mode_count].dir = MODE_ADD;
605     mode_changes[mode_count].caps = 0;
606     mode_changes[mode_count].nocaps = 0;
607     mode_changes[mode_count].id = NULL;
608     mode_changes[mode_count].mems = ALL_MEMBERS;
609     mode_changes[mode_count++].arg = NULL;
610     }
611 michael 2937 else if (dir == MODE_DEL) /* && (chptr->mode.mode & d)) */
612 michael 1167 {
613     /* setting - */
614    
615 michael 2937 chptr->mode.mode &= ~d;
616 michael 1167
617     mode_changes[mode_count].letter = c;
618     mode_changes[mode_count].dir = MODE_DEL;
619     mode_changes[mode_count].caps = 0;
620     mode_changes[mode_count].nocaps = 0;
621     mode_changes[mode_count].mems = ALL_MEMBERS;
622     mode_changes[mode_count].id = NULL;
623     mode_changes[mode_count++].arg = NULL;
624     }
625     }
626    
627     static void
628 michael 1150 chm_operonly(struct Client *client_p, struct Client *source_p, struct Channel *chptr,
629     int parc, int *parn, char **parv, int *errors, int alev, int dir,
630 michael 2937 char c, unsigned int d)
631 michael 1150 {
632     if ((alev < CHACCESS_HALFOP) ||
633 michael 2937 ((d == MODE_PRIVATE) && (alev < CHACCESS_CHANOP)))
634 michael 1150 {
635     if (!(*errors & SM_ERR_NOOPS))
636 michael 1834 sendto_one(source_p, form_str(alev == CHACCESS_NOTONCHAN ?
637     ERR_NOTONCHANNEL : ERR_CHANOPRIVSNEEDED),
638 michael 2937 me.name, source_p->name, chptr->chname);
639 michael 1150 *errors |= SM_ERR_NOOPS;
640     return;
641     }
642 michael 1219 else if (MyClient(source_p) && !HasUMode(source_p, UMODE_OPER))
643 michael 1150 {
644     if (!(*errors & SM_ERR_NOTOPER))
645     {
646     if (alev == CHACCESS_NOTONCHAN)
647 michael 1834 sendto_one(source_p, form_str(ERR_NOTONCHANNEL),
648 michael 2937 me.name, source_p->name, chptr->chname);
649 michael 1150 else
650 michael 1834 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
651 michael 1150 me.name, source_p->name);
652     }
653    
654     *errors |= SM_ERR_NOTOPER;
655     return;
656     }
657    
658     /* If have already dealt with this simple mode, ignore it */
659 michael 2937 if (simple_modes_mask & d)
660 michael 1150 return;
661    
662 michael 2937 simple_modes_mask |= d;
663 michael 1150
664 michael 2937 if (dir == MODE_ADD) /* && !(chptr->mode.mode & d)) */
665 michael 1150 {
666 michael 2937 chptr->mode.mode |= d;
667 michael 1150
668     mode_changes[mode_count].letter = c;
669     mode_changes[mode_count].dir = MODE_ADD;
670     mode_changes[mode_count].caps = 0;
671     mode_changes[mode_count].nocaps = 0;
672     mode_changes[mode_count].id = NULL;
673     mode_changes[mode_count].mems = ALL_MEMBERS;
674     mode_changes[mode_count].mems = ALL_MEMBERS;
675     mode_changes[mode_count++].arg = NULL;
676     }
677 michael 2937 else if (dir == MODE_DEL) /* && (chptr->mode.mode & d)) */
678 michael 1150 {
679     /* setting - */
680    
681 michael 2937 chptr->mode.mode &= ~d;
682 michael 1150
683     mode_changes[mode_count].letter = c;
684     mode_changes[mode_count].dir = MODE_DEL;
685     mode_changes[mode_count].caps = 0;
686     mode_changes[mode_count].nocaps = 0;
687     mode_changes[mode_count].mems = ALL_MEMBERS;
688     mode_changes[mode_count].id = NULL;
689     mode_changes[mode_count++].arg = NULL;
690     }
691     }
692    
693     static void
694 adx 30 chm_ban(struct Client *client_p, struct Client *source_p,
695     struct Channel *chptr, int parc, int *parn,
696 michael 2937 char **parv, int *errors, int alev, int dir, char c, unsigned int d)
697 adx 30 {
698     char *mask = NULL;
699    
700     if (dir == MODE_QUERY || parc <= *parn)
701     {
702     dlink_node *ptr = NULL;
703    
704     if (*errors & SM_ERR_RPL_B)
705     return;
706    
707     *errors |= SM_ERR_RPL_B;
708    
709     DLINK_FOREACH(ptr, chptr->banlist.head)
710     {
711     const struct Ban *banptr = ptr->data;
712 michael 1834 sendto_one(client_p, form_str(RPL_BANLIST),
713 michael 2937 me.name, client_p->name, chptr->chname,
714 michael 2296 banptr->name, banptr->user, banptr->host,
715 michael 2892 banptr->who, banptr->when);
716 adx 30 }
717    
718 michael 1834 sendto_one(source_p, form_str(RPL_ENDOFBANLIST), me.name,
719 michael 2937 source_p->name, chptr->chname);
720 adx 30 return;
721     }
722    
723     if (alev < CHACCESS_HALFOP)
724     {
725     if (!(*errors & SM_ERR_NOOPS))
726 michael 1834 sendto_one(source_p, form_str(alev == CHACCESS_NOTONCHAN ?
727     ERR_NOTONCHANNEL : ERR_CHANOPRIVSNEEDED),
728 michael 2937 me.name, source_p->name, chptr->chname);
729 adx 30 *errors |= SM_ERR_NOOPS;
730     return;
731     }
732    
733     if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
734     return;
735    
736 michael 388 mask = nuh_mask[*parn];
737     memcpy(mask, parv[*parn], sizeof(nuh_mask[*parn]));
738     ++*parn;
739    
740 adx 30 if (IsServer(client_p))
741     if (strchr(mask, ' '))
742     return;
743    
744     switch (dir)
745     {
746     case MODE_ADD:
747     if (!add_id(source_p, chptr, mask, CHFL_BAN))
748     return;
749     break;
750     case MODE_DEL:
751     if (!del_id(chptr, mask, CHFL_BAN))
752     return;
753     break;
754     default:
755     assert(0);
756     }
757    
758     mode_changes[mode_count].letter = c;
759     mode_changes[mode_count].dir = dir;
760     mode_changes[mode_count].caps = 0;
761     mode_changes[mode_count].nocaps = 0;
762     mode_changes[mode_count].mems = ALL_MEMBERS;
763     mode_changes[mode_count].id = NULL;
764     mode_changes[mode_count++].arg = mask;
765     }
766    
767     static void
768     chm_except(struct Client *client_p, struct Client *source_p,
769     struct Channel *chptr, int parc, int *parn,
770 michael 2937 char **parv, int *errors, int alev, int dir, char c, unsigned int d)
771 adx 30 {
772     char *mask = NULL;
773    
774     if (alev < CHACCESS_HALFOP)
775     {
776     if (!(*errors & SM_ERR_NOOPS))
777 michael 1834 sendto_one(source_p, form_str(alev == CHACCESS_NOTONCHAN ?
778     ERR_NOTONCHANNEL : ERR_CHANOPRIVSNEEDED),
779 michael 2937 me.name, source_p->name, chptr->chname);
780 adx 30 *errors |= SM_ERR_NOOPS;
781     return;
782     }
783    
784     if (dir == MODE_QUERY || parc <= *parn)
785     {
786     dlink_node *ptr = NULL;
787    
788     if (*errors & SM_ERR_RPL_E)
789     return;
790    
791     *errors |= SM_ERR_RPL_E;
792    
793     DLINK_FOREACH(ptr, chptr->exceptlist.head)
794     {
795     const struct Ban *banptr = ptr->data;
796 michael 1834 sendto_one(client_p, form_str(RPL_EXCEPTLIST),
797 michael 2937 me.name, client_p->name, chptr->chname,
798 michael 2296 banptr->name, banptr->user, banptr->host,
799 michael 2892 banptr->who, banptr->when);
800 adx 30 }
801    
802 michael 1834 sendto_one(source_p, form_str(RPL_ENDOFEXCEPTLIST), me.name,
803 michael 2937 source_p->name, chptr->chname);
804 adx 30 return;
805     }
806    
807     if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
808     return;
809    
810 michael 388 mask = nuh_mask[*parn];
811     memcpy(mask, parv[*parn], sizeof(nuh_mask[*parn]));
812     ++*parn;
813 adx 30
814     if (IsServer(client_p))
815     if (strchr(mask, ' '))
816     return;
817    
818     switch (dir)
819     {
820     case MODE_ADD:
821     if (!add_id(source_p, chptr, mask, CHFL_EXCEPTION))
822     return;
823     break;
824     case MODE_DEL:
825     if (!del_id(chptr, mask, CHFL_EXCEPTION))
826     return;
827     break;
828     default:
829     assert(0);
830     }
831    
832     mode_changes[mode_count].letter = c;
833     mode_changes[mode_count].dir = dir;
834 michael 1684 mode_changes[mode_count].caps = 0;
835 adx 30 mode_changes[mode_count].nocaps = 0;
836 michael 1495 mode_changes[mode_count].mems = ONLY_CHANOPS;
837 adx 30 mode_changes[mode_count].id = NULL;
838     mode_changes[mode_count++].arg = mask;
839     }
840    
841     static void
842     chm_invex(struct Client *client_p, struct Client *source_p,
843     struct Channel *chptr, int parc, int *parn,
844 michael 2937 char **parv, int *errors, int alev, int dir, char c, unsigned int d)
845 adx 30 {
846     char *mask = NULL;
847    
848     if (alev < CHACCESS_HALFOP)
849     {
850     if (!(*errors & SM_ERR_NOOPS))
851 michael 1834 sendto_one(source_p, form_str(alev == CHACCESS_NOTONCHAN ?
852     ERR_NOTONCHANNEL : ERR_CHANOPRIVSNEEDED),
853 michael 2937 me.name, source_p->name, chptr->chname);
854 adx 30 *errors |= SM_ERR_NOOPS;
855     return;
856     }
857    
858     if (dir == MODE_QUERY || parc <= *parn)
859     {
860     dlink_node *ptr = NULL;
861    
862     if (*errors & SM_ERR_RPL_I)
863     return;
864    
865     *errors |= SM_ERR_RPL_I;
866    
867     DLINK_FOREACH(ptr, chptr->invexlist.head)
868     {
869     const struct Ban *banptr = ptr->data;
870 michael 1834 sendto_one(client_p, form_str(RPL_INVITELIST), me.name,
871 michael 2937 client_p->name, chptr->chname,
872 michael 2892 banptr->name, banptr->user, banptr->host,
873 adx 30 banptr->who, banptr->when);
874     }
875    
876 michael 1834 sendto_one(source_p, form_str(RPL_ENDOFINVITELIST), me.name,
877 michael 2937 source_p->name, chptr->chname);
878 adx 30 return;
879     }
880    
881     if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
882     return;
883    
884 michael 388 mask = nuh_mask[*parn];
885     memcpy(mask, parv[*parn], sizeof(nuh_mask[*parn]));
886     ++*parn;
887 adx 30
888     if (IsServer(client_p))
889     if (strchr(mask, ' '))
890     return;
891    
892     switch (dir)
893     {
894     case MODE_ADD:
895     if (!add_id(source_p, chptr, mask, CHFL_INVEX))
896     return;
897     break;
898     case MODE_DEL:
899     if (!del_id(chptr, mask, CHFL_INVEX))
900     return;
901     break;
902     default:
903     assert(0);
904     }
905    
906     mode_changes[mode_count].letter = c;
907     mode_changes[mode_count].dir = dir;
908 michael 1684 mode_changes[mode_count].caps = 0;
909 adx 30 mode_changes[mode_count].nocaps = 0;
910 michael 1495 mode_changes[mode_count].mems = ONLY_CHANOPS;
911 adx 30 mode_changes[mode_count].id = NULL;
912     mode_changes[mode_count++].arg = mask;
913     }
914    
915     /*
916     * inputs - pointer to channel
917     * output - none
918     * side effects - clear ban cache
919     */
920     void
921     clear_ban_cache(struct Channel *chptr)
922     {
923     dlink_node *ptr = NULL;
924    
925 michael 572 DLINK_FOREACH(ptr, chptr->members.head)
926 adx 30 {
927     struct Membership *ms = ptr->data;
928 michael 572
929     if (MyConnect(ms->client_p))
930     ms->flags &= ~(CHFL_BAN_SILENCED|CHFL_BAN_CHECKED);
931 adx 30 }
932     }
933    
934 michael 759 void
935     clear_ban_cache_client(struct Client *client_p)
936     {
937     dlink_node *ptr = NULL;
938    
939 michael 760 DLINK_FOREACH(ptr, client_p->channel.head)
940 michael 759 {
941     struct Membership *ms = ptr->data;
942     ms->flags &= ~(CHFL_BAN_SILENCED|CHFL_BAN_CHECKED);
943     }
944     }
945    
946 adx 30 static void
947 michael 2951 chm_voice(struct Client *client_p, struct Client *source_p,
948     struct Channel *chptr, int parc, int *parn,
949     char **parv, int *errors, int alev, int dir, char c, unsigned int d)
950 adx 30 {
951 michael 2892 const char *opnick = NULL;
952 adx 30 struct Client *targ_p;
953     struct Membership *member;
954    
955 michael 2951 if (alev < CHACCESS_HALFOP)
956 adx 30 {
957     if (!(*errors & SM_ERR_NOOPS))
958 michael 1834 sendto_one(source_p, form_str(alev == CHACCESS_NOTONCHAN ?
959     ERR_NOTONCHANNEL : ERR_CHANOPRIVSNEEDED),
960 michael 2937 me.name, source_p->name, chptr->chname);
961 adx 30 *errors |= SM_ERR_NOOPS;
962     return;
963     }
964    
965 michael 2951 if ((dir == MODE_QUERY) || parc <= *parn)
966 adx 30 return;
967    
968     opnick = parv[(*parn)++];
969    
970 michael 2475 if ((targ_p = find_chasing(source_p, opnick, NULL)) == NULL)
971 adx 30 return;
972     if (!IsClient(targ_p))
973     return;
974    
975     if ((member = find_channel_link(targ_p, chptr)) == NULL)
976     {
977     if (!(*errors & SM_ERR_NOTONCHANNEL))
978 michael 2951 sendto_one(source_p, form_str(ERR_USERNOTINCHANNEL),
979     me.name, source_p->name, opnick, chptr->chname);
980 adx 30 *errors |= SM_ERR_NOTONCHANNEL;
981     return;
982     }
983    
984     if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
985     return;
986    
987     /* no redundant mode changes */
988 michael 2951 if (dir == MODE_ADD && has_member_flags(member, CHFL_VOICE))
989 adx 30 return;
990 michael 2951 if (dir == MODE_DEL && !has_member_flags(member, CHFL_VOICE))
991 adx 30 return;
992    
993 michael 2951 mode_changes[mode_count].letter = 'v';
994 adx 30 mode_changes[mode_count].dir = dir;
995 michael 2951 mode_changes[mode_count].caps = 0;
996 adx 30 mode_changes[mode_count].nocaps = 0;
997     mode_changes[mode_count].mems = ALL_MEMBERS;
998     mode_changes[mode_count].id = targ_p->id;
999     mode_changes[mode_count].arg = targ_p->name;
1000     mode_changes[mode_count++].client = targ_p;
1001    
1002     if (dir == MODE_ADD)
1003 michael 2951 AddMemberFlag(member, CHFL_VOICE);
1004 adx 30 else
1005 michael 2951 DelMemberFlag(member, CHFL_VOICE);
1006 adx 30 }
1007    
1008     #ifdef HALFOPS
1009     static void
1010     chm_hop(struct Client *client_p, struct Client *source_p,
1011     struct Channel *chptr, int parc, int *parn,
1012 michael 2937 char **parv, int *errors, int alev, int dir, char c, unsigned int d)
1013 adx 30 {
1014 michael 2892 const char *opnick = NULL;
1015 adx 30 struct Client *targ_p;
1016     struct Membership *member;
1017    
1018     /* *sigh* - dont allow halfops to set +/-h, they could fully control a
1019     * channel if there were no ops - it doesnt solve anything.. MODE_PRIVATE
1020     * when used with MODE_SECRET is paranoid - cant use +p
1021     *
1022     * it needs to be optional per channel - but not via +p, that or remove
1023     * paranoid.. -- fl_
1024     *
1025     * +p means paranoid, it is useless for anything else on modern IRC, as
1026     * list isn't really usable. If you want to have a private channel these
1027     * days, you set it +s. Halfops can no longer remove simple modes when
1028     * +p is set (although they can set +p) so it is safe to use this to
1029     * control whether they can (de)halfop...
1030     */
1031     if (alev <
1032     ((chptr->mode.mode & MODE_PRIVATE) ? CHACCESS_CHANOP : CHACCESS_HALFOP))
1033     {
1034     if (!(*errors & SM_ERR_NOOPS))
1035 michael 1834 sendto_one(source_p, form_str(alev == CHACCESS_NOTONCHAN ?
1036     ERR_NOTONCHANNEL : ERR_CHANOPRIVSNEEDED),
1037 michael 2937 me.name, source_p->name, chptr->chname);
1038 adx 30 *errors |= SM_ERR_NOOPS;
1039     return;
1040     }
1041    
1042     if ((dir == MODE_QUERY) || (parc <= *parn))
1043     return;
1044    
1045     opnick = parv[(*parn)++];
1046    
1047 michael 2475 if ((targ_p = find_chasing(source_p, opnick, NULL)) == NULL)
1048 adx 30 return;
1049     if (!IsClient(targ_p))
1050     return;
1051    
1052     if ((member = find_channel_link(targ_p, chptr)) == NULL)
1053     {
1054     if (!(*errors & SM_ERR_NOTONCHANNEL))
1055 michael 1834 sendto_one(source_p, form_str(ERR_USERNOTINCHANNEL),
1056 michael 2937 me.name, source_p->name, opnick, chptr->chname);
1057 adx 30 *errors |= SM_ERR_NOTONCHANNEL;
1058     return;
1059     }
1060    
1061     if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
1062     return;
1063    
1064     /* no redundant mode changes */
1065 adx 356 if (dir == MODE_ADD && has_member_flags(member, CHFL_HALFOP | CHFL_CHANOP))
1066 adx 30 return;
1067     if (dir == MODE_DEL && !has_member_flags(member, CHFL_HALFOP))
1068     return;
1069    
1070     mode_changes[mode_count].letter = 'h';
1071     mode_changes[mode_count].dir = dir;
1072 adx 356 mode_changes[mode_count].caps = CAP_HOPS;
1073 adx 30 mode_changes[mode_count].nocaps = 0;
1074     mode_changes[mode_count].mems = ALL_MEMBERS;
1075     mode_changes[mode_count].id = targ_p->id;
1076     mode_changes[mode_count].arg = targ_p->name;
1077     mode_changes[mode_count++].client = targ_p;
1078    
1079 adx 356 mode_changes[mode_count].letter = 'o';
1080     mode_changes[mode_count].dir = dir;
1081     mode_changes[mode_count].caps = 0;
1082     mode_changes[mode_count].nocaps = CAP_HOPS;
1083     mode_changes[mode_count].mems = ONLY_SERVERS;
1084     mode_changes[mode_count].id = targ_p->id;
1085     mode_changes[mode_count].arg = targ_p->name;
1086     mode_changes[mode_count++].client = targ_p;
1087    
1088 adx 30 if (dir == MODE_ADD)
1089     {
1090     AddMemberFlag(member, CHFL_HALFOP);
1091     DelMemberFlag(member, CHFL_DEOPPED);
1092     }
1093     else
1094     DelMemberFlag(member, CHFL_HALFOP);
1095     }
1096     #endif
1097    
1098     static void
1099 michael 2951 chm_op(struct Client *client_p, struct Client *source_p,
1100     struct Channel *chptr, int parc, int *parn,
1101     char **parv, int *errors, int alev, int dir, char c, unsigned int d)
1102 adx 30 {
1103 michael 2892 const char *opnick = NULL;
1104 adx 30 struct Client *targ_p;
1105     struct Membership *member;
1106 michael 2951 int caps = 0;
1107 adx 30
1108 michael 2951 if (alev < CHACCESS_CHANOP)
1109 adx 30 {
1110     if (!(*errors & SM_ERR_NOOPS))
1111 michael 1834 sendto_one(source_p, form_str(alev == CHACCESS_NOTONCHAN ?
1112     ERR_NOTONCHANNEL : ERR_CHANOPRIVSNEEDED),
1113 michael 2937 me.name, source_p->name, chptr->chname);
1114 adx 30 *errors |= SM_ERR_NOOPS;
1115     return;
1116     }
1117    
1118 michael 2951 if ((dir == MODE_QUERY) || (parc <= *parn))
1119 adx 30 return;
1120    
1121     opnick = parv[(*parn)++];
1122    
1123 michael 2475 if ((targ_p = find_chasing(source_p, opnick, NULL)) == NULL)
1124 adx 30 return;
1125     if (!IsClient(targ_p))
1126     return;
1127    
1128     if ((member = find_channel_link(targ_p, chptr)) == NULL)
1129     {
1130     if (!(*errors & SM_ERR_NOTONCHANNEL))
1131 michael 2951 sendto_one(source_p, form_str(ERR_USERNOTINCHANNEL), me.name,
1132     source_p->name, opnick, chptr->chname);
1133 adx 30 *errors |= SM_ERR_NOTONCHANNEL;
1134     return;
1135     }
1136    
1137     if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
1138     return;
1139    
1140     /* no redundant mode changes */
1141 michael 2951 if (dir == MODE_ADD && has_member_flags(member, CHFL_CHANOP))
1142 adx 30 return;
1143 michael 2951 if (dir == MODE_DEL && !has_member_flags(member, CHFL_CHANOP))
1144     {
1145     #ifdef HALFOPS
1146     if (has_member_flags(member, CHFL_HALFOP))
1147     {
1148     --*parn;
1149     chm_hop(client_p, source_p, chptr, parc, parn, parv, errors, alev,
1150     dir, c, d);
1151     }
1152     #endif
1153 adx 30 return;
1154 michael 2951 }
1155 adx 30
1156 michael 2951 #ifdef HALFOPS
1157     if (dir == MODE_ADD && has_member_flags(member, CHFL_HALFOP))
1158     {
1159     /* promoting from % to @ is visible only to CAP_HOPS servers */
1160     mode_changes[mode_count].letter = 'h';
1161     mode_changes[mode_count].dir = MODE_DEL;
1162     mode_changes[mode_count].caps = caps = CAP_HOPS;
1163     mode_changes[mode_count].nocaps = 0;
1164     mode_changes[mode_count].mems = ALL_MEMBERS;
1165     mode_changes[mode_count].id = NULL;
1166     mode_changes[mode_count].arg = targ_p->name;
1167     mode_changes[mode_count++].client = targ_p;
1168     }
1169     #endif
1170    
1171     mode_changes[mode_count].letter = 'o';
1172 adx 30 mode_changes[mode_count].dir = dir;
1173 michael 2951 mode_changes[mode_count].caps = caps;
1174 adx 30 mode_changes[mode_count].nocaps = 0;
1175     mode_changes[mode_count].mems = ALL_MEMBERS;
1176     mode_changes[mode_count].id = targ_p->id;
1177     mode_changes[mode_count].arg = targ_p->name;
1178     mode_changes[mode_count++].client = targ_p;
1179    
1180     if (dir == MODE_ADD)
1181 michael 2951 {
1182     AddMemberFlag(member, CHFL_CHANOP);
1183     DelMemberFlag(member, CHFL_DEOPPED | CHFL_HALFOP);
1184     }
1185 adx 30 else
1186 michael 2951 DelMemberFlag(member, CHFL_CHANOP);
1187 adx 30 }
1188    
1189     static void
1190     chm_limit(struct Client *client_p, struct Client *source_p,
1191     struct Channel *chptr, int parc, int *parn,
1192 michael 2937 char **parv, int *errors, int alev, int dir, char c, unsigned int d)
1193 adx 30 {
1194 michael 3057 unsigned int i;
1195     int limit;
1196 adx 30 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 michael 3057 unsigned int i;
1258 adx 30 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 michael 2941 get_channel_access(const struct Client *source_p,
1603     const struct Membership *member)
1604 adx 30 {
1605     /* Let hacked servers in for now... */
1606     if (!MyClient(source_p))
1607     return CHACCESS_CHANOP;
1608    
1609     if (member == NULL)
1610     return CHACCESS_NOTONCHAN;
1611    
1612     /* just to be sure.. */
1613     assert(source_p == member->client_p);
1614    
1615     if (has_member_flags(member, CHFL_CHANOP))
1616     return CHACCESS_CHANOP;
1617    
1618     #ifdef HALFOPS
1619     if (has_member_flags(member, CHFL_HALFOP))
1620     return CHACCESS_HALFOP;
1621     #endif
1622    
1623     return CHACCESS_PEON;
1624     }
1625    
1626     /* void send_cap_mode_changes(struct Client *client_p,
1627     * struct Client *source_p,
1628     * struct Channel *chptr, int cap, int nocap)
1629     * Input: The client sending(client_p), the source client(source_p),
1630     * the channel to send mode changes for(chptr)
1631     * Output: None.
1632     * Side-effects: Sends the appropriate mode changes to capable servers.
1633     *
1634     * send_cap_mode_changes() will loop the server list itself, because
1635     * at this point in time we have 4 capabs for channels, CAP_IE, CAP_EX,
1636     * and a server could support any number of these..
1637     * so we make the modebufs per server, tailoring them to each servers
1638     * specific demand. Its not very pretty, but its one of the few realistic
1639     * ways to handle having this many capabs for channel modes.. --fl_
1640     *
1641     * Reverted back to my original design, except that we now keep a count
1642     * of the number of servers which each combination as an optimisation, so
1643     * the capabs combinations which are not needed are not worked out. -A1kmm
1644     */
1645     /* rewritten to ensure parabuf < MODEBUFLEN -db */
1646    
1647     static void
1648     send_cap_mode_changes(struct Client *client_p, struct Client *source_p,
1649 michael 1015 struct Channel *chptr, unsigned int cap, unsigned int nocap)
1650 adx 30 {
1651 michael 3057 unsigned int i;
1652     int mbl, pbl, arglen, nc, mc;
1653 adx 30 int len;
1654     const char *arg = NULL;
1655     char *parptr;
1656     int dir = MODE_QUERY;
1657    
1658     mc = 0;
1659     nc = 0;
1660     pbl = 0;
1661    
1662     parabuf[0] = '\0';
1663     parptr = parabuf;
1664    
1665     if ((cap & CAP_TS6) && source_p->id[0] != '\0')
1666 michael 3029 mbl = snprintf(modebuf, sizeof(modebuf), ":%s TMODE %lu %s ", source_p->id,
1667     (unsigned long)chptr->channelts, chptr->chname);
1668 adx 30 else
1669 michael 3029 mbl = snprintf(modebuf, sizeof(modebuf), ":%s MODE %s ", source_p->name,
1670     chptr->chname);
1671 adx 30
1672     /* loop the list of - modes we have */
1673     for (i = 0; i < mode_count; i++)
1674     {
1675     /* if they dont support the cap we need, or they do support a cap they
1676     * cant have, then dont add it to the modebuf.. that way they wont see
1677     * the mode
1678     */
1679     if ((mode_changes[i].letter == 0) ||
1680 michael 2892 ((cap & mode_changes[i].caps) != mode_changes[i].caps) ||
1681     ((nocap & mode_changes[i].nocaps) != mode_changes[i].nocaps))
1682 adx 30 continue;
1683    
1684     arg = "";
1685    
1686     if ((cap & CAP_TS6) && mode_changes[i].id)
1687     arg = mode_changes[i].id;
1688     if (*arg == '\0')
1689     arg = mode_changes[i].arg;
1690    
1691     /* if we're creeping past the buf size, we need to send it and make
1692     * another line for the other modes
1693     * XXX - this could give away server topology with uids being
1694     * different lengths, but not much we can do, except possibly break
1695     * them as if they were the longest of the nick or uid at all times,
1696     * which even then won't work as we don't always know the uid -A1kmm.
1697     */
1698     if (arg != NULL)
1699     arglen = strlen(arg);
1700     else
1701     arglen = 0;
1702    
1703     if ((mc == MAXMODEPARAMS) ||
1704     ((arglen + mbl + pbl + 2) > IRCD_BUFSIZE) ||
1705     (pbl + arglen + BAN_FUDGE) >= MODEBUFLEN)
1706     {
1707     if (nc != 0)
1708 michael 2892 sendto_server(client_p, cap, nocap, "%s %s", modebuf, parabuf);
1709 adx 30 nc = 0;
1710     mc = 0;
1711    
1712     if ((cap & CAP_TS6) && source_p->id[0] != '\0')
1713 michael 3051 mbl = snprintf(modebuf, sizeof(modebuf), ":%s TMODE %lu %s ", source_p->id,
1714     (unsigned long)chptr->channelts, chptr->chname);
1715 adx 30 else
1716 michael 3029 mbl = snprintf(modebuf, sizeof(modebuf), ":%s MODE %s ", source_p->name,
1717     chptr->chname);
1718 adx 30
1719     pbl = 0;
1720     parabuf[0] = '\0';
1721     parptr = parabuf;
1722     dir = MODE_QUERY;
1723     }
1724    
1725     if (dir != mode_changes[i].dir)
1726     {
1727     modebuf[mbl++] = (mode_changes[i].dir == MODE_ADD) ? '+' : '-';
1728     dir = mode_changes[i].dir;
1729     }
1730    
1731     modebuf[mbl++] = mode_changes[i].letter;
1732     modebuf[mbl] = '\0';
1733     nc++;
1734    
1735     if (arg != NULL)
1736     {
1737 michael 1793 len = sprintf(parptr, "%s ", arg);
1738 adx 30 pbl += len;
1739     parptr += len;
1740     mc++;
1741     }
1742     }
1743    
1744     if (pbl && parabuf[pbl - 1] == ' ')
1745     parabuf[pbl - 1] = 0;
1746    
1747     if (nc != 0)
1748 michael 2892 sendto_server(client_p, cap, nocap, "%s %s", modebuf, parabuf);
1749 adx 30 }
1750    
1751     /* void send_mode_changes(struct Client *client_p,
1752     * struct Client *source_p,
1753     * struct Channel *chptr)
1754     * Input: The client sending(client_p), the source client(source_p),
1755     * the channel to send mode changes for(chptr),
1756     * mode change globals.
1757     * Output: None.
1758     * Side-effects: Sends the appropriate mode changes to other clients
1759     * and propagates to servers.
1760     */
1761     /* ensure parabuf < MODEBUFLEN -db */
1762     static void
1763     send_mode_changes(struct Client *client_p, struct Client *source_p,
1764 michael 2937 struct Channel *chptr)
1765 adx 30 {
1766 michael 3057 unsigned int i;
1767     int mbl, pbl, arglen, nc, mc;
1768 adx 30 int len;
1769     const char *arg = NULL;
1770     char *parptr;
1771     int dir = MODE_QUERY;
1772    
1773     /* bail out if we have nothing to do... */
1774     if (!mode_count)
1775     return;
1776    
1777     if (IsServer(source_p))
1778 michael 3029 mbl = snprintf(modebuf, sizeof(modebuf), ":%s MODE %s ", (IsHidden(source_p) ||
1779     ConfigServerHide.hide_servers) ?
1780     me.name : source_p->name, chptr->chname);
1781 adx 30 else
1782 michael 3029 mbl = snprintf(modebuf, sizeof(modebuf), ":%s!%s@%s MODE %s ", source_p->name,
1783     source_p->username, source_p->host, chptr->chname);
1784 adx 30
1785     mc = 0;
1786     nc = 0;
1787     pbl = 0;
1788    
1789     parabuf[0] = '\0';
1790     parptr = parabuf;
1791    
1792     for (i = 0; i < mode_count; i++)
1793     {
1794     if (mode_changes[i].letter == 0 ||
1795     mode_changes[i].mems == NON_CHANOPS ||
1796     mode_changes[i].mems == ONLY_SERVERS)
1797     continue;
1798    
1799     arg = mode_changes[i].arg;
1800     if (arg != NULL)
1801     arglen = strlen(arg);
1802     else
1803     arglen = 0;
1804    
1805 michael 2892 if ((mc == MAXMODEPARAMS) ||
1806 adx 30 ((arglen + mbl + pbl + 2) > IRCD_BUFSIZE) ||
1807 michael 2892 ((arglen + pbl + BAN_FUDGE) >= MODEBUFLEN))
1808 adx 30 {
1809     if (mbl && modebuf[mbl - 1] == '-')
1810     modebuf[mbl - 1] = '\0';
1811    
1812     if (nc != 0)
1813 michael 1243 sendto_channel_local(ALL_MEMBERS, 0, chptr, "%s %s", modebuf, parabuf);
1814 adx 30
1815     nc = 0;
1816     mc = 0;
1817    
1818     if (IsServer(source_p))
1819 michael 3029 mbl = snprintf(modebuf, sizeof(modebuf), ":%s MODE %s ", (IsHidden(source_p) ||
1820     ConfigServerHide.hide_servers) ?
1821     me.name : source_p->name, chptr->chname);
1822 adx 30 else
1823 michael 3029 mbl = snprintf(modebuf, sizeof(modebuf), ":%s!%s@%s MODE %s ", source_p->name,
1824     source_p->username, source_p->host, chptr->chname);
1825 adx 30
1826     pbl = 0;
1827     parabuf[0] = '\0';
1828     parptr = parabuf;
1829     dir = MODE_QUERY;
1830     }
1831    
1832     if (dir != mode_changes[i].dir)
1833     {
1834     modebuf[mbl++] = (mode_changes[i].dir == MODE_ADD) ? '+' : '-';
1835     dir = mode_changes[i].dir;
1836     }
1837    
1838     modebuf[mbl++] = mode_changes[i].letter;
1839     modebuf[mbl] = '\0';
1840     nc++;
1841    
1842     if (arg != NULL)
1843     {
1844 michael 1793 len = sprintf(parptr, "%s ", arg);
1845 adx 30 pbl += len;
1846     parptr += len;
1847     mc++;
1848     }
1849     }
1850    
1851     if (pbl && parabuf[pbl - 1] == ' ')
1852     parabuf[pbl - 1] = 0;
1853    
1854     if (nc != 0)
1855 michael 1243 sendto_channel_local(ALL_MEMBERS, 0, chptr, "%s %s", modebuf, parabuf);
1856 adx 30
1857     nc = 0;
1858     mc = 0;
1859    
1860     /* Now send to servers... */
1861     for (i = 0; i < NCHCAP_COMBOS; i++)
1862     if (chcap_combos[i].count != 0)
1863     send_cap_mode_changes(client_p, source_p, chptr,
1864     chcap_combos[i].cap_yes,
1865     chcap_combos[i].cap_no);
1866     }
1867    
1868     /* void set_channel_mode(struct Client *client_p, struct Client *source_p,
1869     * struct Channel *chptr, int parc, char **parv,
1870     * char *chname)
1871     * Input: The client we received this from, the client this originated
1872     * from, the channel, the parameter count starting at the modes,
1873     * the parameters, the channel name.
1874     * Output: None.
1875     * Side-effects: Changes the channel membership and modes appropriately,
1876     * sends the appropriate MODE messages to the appropriate
1877     * clients.
1878     */
1879     void
1880     set_channel_mode(struct Client *client_p, struct Client *source_p, struct Channel *chptr,
1881 michael 2937 struct Membership *member, int parc, char *parv[])
1882 adx 30 {
1883     int dir = MODE_ADD;
1884     int parn = 1;
1885     int alevel, errors = 0;
1886     char *ml = parv[0], c;
1887    
1888     mode_count = 0;
1889     mode_limit = 0;
1890     simple_modes_mask = 0;
1891    
1892     alevel = get_channel_access(source_p, member);
1893    
1894 michael 2939 for (; (c = *ml); ++ml)
1895 adx 30 {
1896     switch (c)
1897     {
1898     case '+':
1899     dir = MODE_ADD;
1900     break;
1901     case '-':
1902     dir = MODE_DEL;
1903     break;
1904     case '=':
1905     dir = MODE_QUERY;
1906     break;
1907     default:
1908 michael 2939 {
1909     struct ChannelMode *tptr = &ModeTable[(unsigned char)c];
1910    
1911     tptr->func(client_p, source_p, chptr, parc, &parn,
1912     parv, &errors, alevel, dir, c, tptr->d);
1913 adx 30 break;
1914 michael 2939 }
1915 adx 30 }
1916     }
1917    
1918 michael 2937 send_mode_changes(client_p, source_p, chptr);
1919 adx 30 }

Properties

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