ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/channel_mode.c
Revision: 8089
Committed: Wed Mar 29 12:22:47 2017 UTC (9 years, 6 months ago) by michael
Content type: text/x-csrc
File size: 34729 byte(s)
Log Message:
- Cleanup channel mode table handling

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 7924 * Copyright (c) 1997-2017 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 michael 4565 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 adx 30 * USA
20     */
21    
22 michael 2916 /*! \file channel_mode.c
23     * \brief Controls modes on channels.
24     * \version $Id$
25     */
26    
27 adx 30 #include "stdinc.h"
28 michael 1011 #include "list.h"
29 adx 30 #include "channel.h"
30     #include "channel_mode.h"
31     #include "client.h"
32 michael 1632 #include "conf.h"
33 michael 371 #include "hostmask.h"
34 adx 30 #include "irc_string.h"
35     #include "ircd.h"
36     #include "numeric.h"
37 michael 3347 #include "server.h"
38 adx 30 #include "send.h"
39     #include "memory.h"
40 michael 1654 #include "mempool.h"
41 michael 1243 #include "parse.h"
42 adx 30
43    
44 michael 388 static char nuh_mask[MAXPARA][IRCD_BUFSIZE];
45 adx 30 static struct ChModeChange mode_changes[IRCD_BUFSIZE];
46 michael 3057 static unsigned int mode_count;
47     static unsigned int mode_limit; /* number of modes set other than simple */
48     static unsigned int simple_modes_mask; /* bit mask of simple modes already set */
49 michael 1654 extern mp_pool_t *ban_pool;
50 adx 30
51    
52     /* check_string()
53     *
54     * inputs - string to check
55     * output - pointer to modified string
56     * side effects - Fixes a string so that the first white space found
57     * becomes an end of string marker (`\0`).
58     * returns the 'fixed' string or "*" if the string
59     * was NULL length or a NULL pointer.
60     */
61     static char *
62     check_string(char *s)
63     {
64 michael 4833 char *const str = s;
65 adx 30 static char star[] = "*";
66    
67 michael 1772 if (EmptyString(str))
68 michael 593 return star;
69 adx 30
70     for (; *s; ++s)
71     {
72     if (IsSpace(*s))
73     {
74     *s = '\0';
75     break;
76     }
77     }
78    
79 michael 1772 return EmptyString(str) ? star : str;
80 adx 30 }
81    
82     /*
83 michael 5583 * Ban functions to work with mode +b/e/I
84 adx 30 */
85 michael 2892 /* add the specified ID to the channel.
86     * -is 8/9/00
87 adx 30 */
88    
89     int
90 michael 3044 add_id(struct Client *client_p, struct Channel *chptr, char *banid, unsigned int type)
91 adx 30 {
92 michael 7797 dlink_list *list;
93     dlink_node *node;
94 michael 3215 char name[NICKLEN + 1] = "";
95     char user[USERLEN + 1] = "";
96     char host[HOSTLEN + 1] = "";
97 michael 593 struct split_nuh_item nuh;
98 adx 30
99     if (MyClient(client_p))
100     {
101 michael 3700 unsigned int num_mask = dlink_list_length(&chptr->banlist) +
102     dlink_list_length(&chptr->exceptlist) +
103     dlink_list_length(&chptr->invexlist);
104 adx 30
105 michael 8046 /* Don't let local clients overflow the b/e/I lists */
106     if (num_mask >= ((HasCMode(chptr, MODE_EXTLIMIT)) ? ConfigChannel.max_bans_large :
107     ConfigChannel.max_bans))
108 adx 30 {
109 michael 4618 sendto_one_numeric(client_p, &me, ERR_BANLISTFULL, chptr->name, banid);
110 adx 30 return 0;
111     }
112    
113     collapse(banid);
114     }
115    
116 michael 593 nuh.nuhmask = check_string(banid);
117     nuh.nickptr = name;
118     nuh.userptr = user;
119     nuh.hostptr = host;
120 adx 30
121 michael 593 nuh.nicksize = sizeof(name);
122     nuh.usersize = sizeof(user);
123     nuh.hostsize = sizeof(host);
124    
125     split_nuh(&nuh);
126    
127 adx 30 /*
128 michael 593 * Re-assemble a new n!u@h and print it back to banid for sending
129 adx 30 * the mode to the channel.
130     */
131 michael 7797 size_t len = snprintf(banid, IRCD_BUFSIZE, "%s!%s@%s", name, user, host);
132 adx 30
133     switch (type)
134     {
135     case CHFL_BAN:
136     list = &chptr->banlist;
137 michael 7764 clear_ban_cache_list(&chptr->locmembers);
138 adx 30 break;
139     case CHFL_EXCEPTION:
140     list = &chptr->exceptlist;
141 michael 7764 clear_ban_cache_list(&chptr->locmembers);
142 adx 30 break;
143     case CHFL_INVEX:
144     list = &chptr->invexlist;
145     break;
146     default:
147 michael 7797 list = NULL; /* Let it crash */
148 adx 30 }
149    
150 michael 4800 DLINK_FOREACH(node, list->head)
151 adx 30 {
152 michael 7797 const struct Ban *ban = node->data;
153 michael 2892
154 michael 4815 if (!irccmp(ban->name, name) &&
155     !irccmp(ban->user, user) &&
156     !irccmp(ban->host, host))
157 adx 30 return 0;
158     }
159    
160 michael 7797 struct Ban *ban = mp_pool_get(ban_pool);
161 michael 4815 ban->when = CurrentTime;
162     ban->len = len - 2; /* -2 for ! + @ */
163     ban->type = parse_netmask(host, &ban->addr, &ban->bits);
164 michael 5757 strlcpy(ban->name, name, sizeof(ban->name));
165     strlcpy(ban->user, user, sizeof(ban->user));
166     strlcpy(ban->host, host, sizeof(ban->host));
167 michael 3700
168 adx 30 if (IsClient(client_p))
169 michael 5757 snprintf(ban->who, sizeof(ban->who), "%s!%s@%s", client_p->name,
170     client_p->username, client_p->host);
171 michael 5753 else if (IsHidden(client_p) || ConfigServerHide.hide_servers)
172 michael 5757 strlcpy(ban->who, me.name, sizeof(ban->who));
173 adx 30 else
174 michael 5757 strlcpy(ban->who, client_p->name, sizeof(ban->who));
175 adx 30
176 michael 4815 dlinkAdd(ban, &ban->node, list);
177 adx 30
178     return 1;
179     }
180    
181     /*
182     * inputs - pointer to channel
183     * - pointer to ban id
184     * - type of ban, i.e. ban, exception, invex
185     * output - 0 for failure, 1 for success
186     * side effects -
187     */
188     static int
189 michael 3044 del_id(struct Channel *chptr, char *banid, unsigned int type)
190 adx 30 {
191 michael 7797 dlink_list *list;
192     dlink_node *node;
193 michael 3215 char name[NICKLEN + 1] = "";
194     char user[USERLEN + 1] = "";
195     char host[HOSTLEN + 1] = "";
196 michael 593 struct split_nuh_item nuh;
197 adx 30
198 michael 2892 assert(banid);
199 adx 30
200 michael 593 nuh.nuhmask = check_string(banid);
201     nuh.nickptr = name;
202     nuh.userptr = user;
203     nuh.hostptr = host;
204 adx 30
205 michael 593 nuh.nicksize = sizeof(name);
206     nuh.usersize = sizeof(user);
207     nuh.hostsize = sizeof(host);
208    
209     split_nuh(&nuh);
210    
211 adx 30 /*
212 michael 593 * Re-assemble a new n!u@h and print it back to banid for sending
213 adx 30 * the mode to the channel.
214     */
215 michael 4826 snprintf(banid, IRCD_BUFSIZE, "%s!%s@%s", name, user, host);
216 adx 30
217     switch (type)
218     {
219     case CHFL_BAN:
220     list = &chptr->banlist;
221 michael 7764 clear_ban_cache_list(&chptr->locmembers);
222 adx 30 break;
223     case CHFL_EXCEPTION:
224     list = &chptr->exceptlist;
225 michael 7764 clear_ban_cache_list(&chptr->locmembers);
226 adx 30 break;
227     case CHFL_INVEX:
228     list = &chptr->invexlist;
229     break;
230     default:
231 michael 7797 list = NULL; /* Let it crash */
232 adx 30 }
233    
234 michael 4800 DLINK_FOREACH(node, list->head)
235 adx 30 {
236 michael 4815 struct Ban *ban = node->data;
237 adx 30
238 michael 4815 if (!irccmp(name, ban->name) &&
239     !irccmp(user, ban->user) &&
240     !irccmp(host, ban->host))
241 adx 30 {
242 michael 4815 remove_ban(ban, list);
243 adx 30 return 1;
244     }
245     }
246    
247     return 0;
248     }
249    
250     /* channel_modes()
251     *
252     * inputs - pointer to channel
253     * - pointer to client
254     * - pointer to mode buf
255     * - pointer to parameter buf
256     * output - NONE
257     * side effects - write the "simple" list of channel modes for channel
258     * chptr onto buffer mbuf with the parameters in pbuf.
259     */
260     void
261 michael 3687 channel_modes(struct Channel *chptr, struct Client *client_p, char *mbuf, char *pbuf)
262 adx 30 {
263     *mbuf++ = '+';
264     *pbuf = '\0';
265    
266 michael 8089 for (const struct mode_letter *tab = cmode_tab; tab->mode; ++tab)
267     if (tab->mode && HasCMode(chptr, tab->mode))
268 michael 1175 *mbuf++ = tab->letter;
269 adx 30
270     if (chptr->mode.limit)
271     {
272     *mbuf++ = 'l';
273    
274 michael 6359 if (IsServer(client_p) || IsMember(client_p, chptr))
275 michael 7355 pbuf += sprintf(pbuf, "%u ", chptr->mode.limit);
276 adx 30 }
277    
278     if (chptr->mode.key[0])
279     {
280     *mbuf++ = 'k';
281    
282 michael 6359 if (IsServer(client_p) || IsMember(client_p, chptr))
283 michael 3692 sprintf(pbuf, "%s ", chptr->mode.key);
284 adx 30 }
285    
286     *mbuf = '\0';
287     }
288    
289     /* fix_key()
290 michael 2892 *
291 adx 30 * inputs - pointer to key to clean up
292     * output - pointer to cleaned up key
293     * side effects - input string is modified
294     *
295     * stolen from Undernet's ircd -orabidoo
296     */
297     static char *
298     fix_key(char *arg)
299     {
300     unsigned char *s, *t, c;
301    
302 michael 8022 for (s = t = (unsigned char *)arg; (c = *s) && s - (unsigned char *)arg < KEYLEN; ++s)
303 adx 30 {
304     c &= 0x7f;
305 michael 2892
306 adx 30 if (c != ':' && c > ' ' && c != ',')
307     *t++ = c;
308     }
309    
310     *t = '\0';
311 michael 2892 return arg;
312 adx 30 }
313    
314 michael 3149 /*
315     * inputs - pointer to channel
316     * output - none
317     * side effects - clear ban cache
318     */
319     void
320 michael 7764 clear_ban_cache_list(dlink_list *list)
321 michael 3149 {
322 michael 7764 dlink_node *node;
323 michael 3149
324 michael 7764 DLINK_FOREACH(node, list->head)
325 michael 3149 {
326 michael 4815 struct Membership *member = node->data;
327 michael 5752 member->flags &= ~(CHFL_BAN_SILENCED | CHFL_BAN_CHECKED);
328 michael 3149 }
329     }
330    
331 michael 3634 /*
332     * Bitmasks for various error returns that set_channel_mode should only return
333 adx 30 * once per call -orabidoo
334     */
335 michael 3634 enum
336     {
337     SM_ERR_NOOPS = 1 << 0, /* No chan ops */
338     SM_ERR_UNKNOWN = 1 << 1,
339     SM_ERR_RPL_B = 1 << 2,
340     SM_ERR_RPL_E = 1 << 3,
341     SM_ERR_RPL_I = 1 << 4,
342     SM_ERR_NOTONCHANNEL = 1 << 5, /* Client is not on channel */
343 michael 8051 SM_ERR_NOTOPER = 1 << 6, /* Only irc-operators can change that mode */
344     SM_ERR_ONLYSERVER = 1 << 7 /* Only servers or services can change that mode */
345 michael 3634 };
346 adx 30
347     /* Mode functions handle mode changes for a particular mode... */
348     static void
349 michael 3374 chm_nosuch(struct Client *source_p, struct Channel *chptr, int parc, int *parn,
350 michael 2937 char **parv, int *errors, int alev, int dir, char c, unsigned int d)
351 adx 30 {
352     if (*errors & SM_ERR_UNKNOWN)
353     return;
354    
355     *errors |= SM_ERR_UNKNOWN;
356 michael 3109 sendto_one_numeric(source_p, &me, ERR_UNKNOWNMODE, c);
357 adx 30 }
358    
359     static void
360 michael 3374 chm_simple(struct Client *source_p, struct Channel *chptr, int parc, int *parn,
361     char **parv, int *errors, int alev, int dir, char c, unsigned int d)
362 adx 30 {
363 michael 3719 if (alev < CHACCESS_HALFOP)
364 adx 30 {
365     if (!(*errors & SM_ERR_NOOPS))
366 michael 3109 sendto_one_numeric(source_p, &me,
367     alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
368 michael 4618 ERR_CHANOPRIVSNEEDED, chptr->name);
369 michael 4884
370 adx 30 *errors |= SM_ERR_NOOPS;
371     return;
372     }
373    
374     /* If have already dealt with this simple mode, ignore it */
375 michael 2937 if (simple_modes_mask & d)
376 adx 30 return;
377    
378 michael 2937 simple_modes_mask |= d;
379 adx 30
380     /* setting + */
381 michael 2937 if (dir == MODE_ADD) /* && !(chptr->mode.mode & d)) */
382 adx 30 {
383 michael 8044 AddCMode(chptr, d);
384 adx 30
385     mode_changes[mode_count].letter = c;
386 michael 3734 mode_changes[mode_count].arg = NULL;
387 adx 30 mode_changes[mode_count].id = NULL;
388 michael 8040 mode_changes[mode_count].flags = 0;
389 michael 4799 mode_changes[mode_count++].dir = dir;
390 adx 30 }
391 michael 2937 else if (dir == MODE_DEL) /* && (chptr->mode.mode & d)) */
392 adx 30 {
393     /* setting - */
394 michael 8044 DelCMode(chptr, d);
395 adx 30
396     mode_changes[mode_count].letter = c;
397 michael 3734 mode_changes[mode_count].arg = NULL;
398 adx 30 mode_changes[mode_count].id = NULL;
399 michael 8040 mode_changes[mode_count].flags = 0;
400 michael 4799 mode_changes[mode_count++].dir = dir;
401 adx 30 }
402     }
403    
404     static void
405 michael 3374 chm_registered(struct Client *source_p, struct Channel *chptr, int parc, int *parn,
406     char **parv, int *errors, int alev, int dir, char c, unsigned int d)
407 michael 1167 {
408 michael 1219 if (!IsServer(source_p) && !HasFlag(source_p, FLAGS_SERVICE))
409 michael 1167 {
410     if (!(*errors & SM_ERR_ONLYSERVER))
411 michael 3109 sendto_one_numeric(source_p, &me,
412     alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
413 michael 4618 ERR_ONLYSERVERSCANCHANGE, chptr->name);
414 michael 4884
415 michael 1167 *errors |= SM_ERR_ONLYSERVER;
416     return;
417     }
418    
419     /* If have already dealt with this simple mode, ignore it */
420 michael 2937 if (simple_modes_mask & d)
421 michael 1167 return;
422    
423 michael 2937 simple_modes_mask |= d;
424 michael 1167
425     /* setting + */
426 michael 2937 if (dir == MODE_ADD) /* && !(chptr->mode.mode & d)) */
427 michael 1167 {
428 michael 8044 AddCMode(chptr, d);
429 michael 1167
430     mode_changes[mode_count].letter = c;
431 michael 3734 mode_changes[mode_count].arg = NULL;
432 michael 1167 mode_changes[mode_count].id = NULL;
433 michael 8040 mode_changes[mode_count].flags = 0;
434 michael 4799 mode_changes[mode_count++].dir = dir;
435 michael 1167 }
436 michael 2937 else if (dir == MODE_DEL) /* && (chptr->mode.mode & d)) */
437 michael 1167 {
438     /* setting - */
439 michael 8044 DelCMode(chptr, d);
440 michael 1167
441     mode_changes[mode_count].letter = c;
442 michael 3734 mode_changes[mode_count].arg = NULL;
443 michael 1167 mode_changes[mode_count].id = NULL;
444 michael 8040 mode_changes[mode_count].flags = 0;
445 michael 4799 mode_changes[mode_count++].dir = dir;
446 michael 1167 }
447     }
448    
449     static void
450 michael 8046 chm_simple_oper(struct Client *source_p, struct Channel *chptr, int parc, int *parn,
451     char **parv, int *errors, int alev, int dir, char c, unsigned int d)
452 michael 1150 {
453 michael 5580 if (alev < CHACCESS_HALFOP)
454 michael 1150 {
455     if (!(*errors & SM_ERR_NOOPS))
456 michael 3109 sendto_one_numeric(source_p, &me,
457     alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
458 michael 4618 ERR_CHANOPRIVSNEEDED, chptr->name);
459 michael 3648
460 michael 1150 *errors |= SM_ERR_NOOPS;
461     return;
462     }
463 michael 3648
464     if (MyClient(source_p) && !HasUMode(source_p, UMODE_OPER))
465 michael 1150 {
466     if (!(*errors & SM_ERR_NOTOPER))
467 michael 3648 sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES);
468 michael 1150
469     *errors |= SM_ERR_NOTOPER;
470     return;
471     }
472    
473     /* If have already dealt with this simple mode, ignore it */
474 michael 2937 if (simple_modes_mask & d)
475 michael 1150 return;
476    
477 michael 2937 simple_modes_mask |= d;
478 michael 1150
479 michael 2937 if (dir == MODE_ADD) /* && !(chptr->mode.mode & d)) */
480 michael 1150 {
481 michael 8044 AddCMode(chptr, d);
482 michael 1150
483     mode_changes[mode_count].letter = c;
484 michael 3734 mode_changes[mode_count].arg = NULL;
485 michael 1150 mode_changes[mode_count].id = NULL;
486 michael 8040 mode_changes[mode_count].flags = 0;
487 michael 4799 mode_changes[mode_count++].dir = dir;
488 michael 1150 }
489 michael 2937 else if (dir == MODE_DEL) /* && (chptr->mode.mode & d)) */
490 michael 1150 {
491     /* setting - */
492 michael 8044 DelCMode(chptr, d);
493 michael 1150
494     mode_changes[mode_count].letter = c;
495 michael 3734 mode_changes[mode_count].arg = NULL;
496 michael 1150 mode_changes[mode_count].id = NULL;
497 michael 8040 mode_changes[mode_count].flags = 0;
498 michael 4799 mode_changes[mode_count++].dir = dir;
499 michael 1150 }
500     }
501    
502     static void
503 michael 3374 chm_ban(struct Client *source_p, struct Channel *chptr, int parc, int *parn,
504 michael 2937 char **parv, int *errors, int alev, int dir, char c, unsigned int d)
505 adx 30 {
506     if (dir == MODE_QUERY || parc <= *parn)
507     {
508 michael 7797 dlink_node *node;
509 adx 30
510     if (*errors & SM_ERR_RPL_B)
511     return;
512    
513     *errors |= SM_ERR_RPL_B;
514    
515 michael 4800 DLINK_FOREACH(node, chptr->banlist.head)
516 adx 30 {
517 michael 4815 const struct Ban *ban = node->data;
518 michael 8040
519 michael 8044 if (!HasCMode(chptr, MODE_HIDEBMASKS) || alev >= CHACCESS_HALFOP)
520 michael 8040 sendto_one_numeric(source_p, &me, RPL_BANLIST, chptr->name,
521     ban->name, ban->user, ban->host,
522     ban->who, ban->when);
523 adx 30 }
524    
525 michael 4618 sendto_one_numeric(source_p, &me, RPL_ENDOFBANLIST, chptr->name);
526 adx 30 return;
527     }
528    
529     if (alev < CHACCESS_HALFOP)
530     {
531     if (!(*errors & SM_ERR_NOOPS))
532 michael 3109 sendto_one_numeric(source_p, &me,
533     alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
534 michael 4618 ERR_CHANOPRIVSNEEDED, chptr->name);
535 michael 4884
536 adx 30 *errors |= SM_ERR_NOOPS;
537     return;
538     }
539    
540     if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
541     return;
542    
543 michael 8051 char *const mask = nuh_mask[*parn];
544 michael 5745 strlcpy(mask, parv[*parn], sizeof(nuh_mask[*parn]));
545 michael 4791 ++(*parn);
546 michael 388
547 michael 5031 if (*mask == ':' || (!MyConnect(source_p) && strchr(mask, ' ')))
548     return;
549 adx 30
550     switch (dir)
551     {
552     case MODE_ADD:
553     if (!add_id(source_p, chptr, mask, CHFL_BAN))
554     return;
555     break;
556     case MODE_DEL:
557     if (!del_id(chptr, mask, CHFL_BAN))
558     return;
559     break;
560     default:
561     assert(0);
562     }
563    
564     mode_changes[mode_count].letter = c;
565 michael 8018 mode_changes[mode_count].arg = mask; /* At this point 'mask' is no longer than NICKLEN + USERLEN + HOSTLEN + 3 */
566 michael 3734 mode_changes[mode_count].id = NULL;
567 michael 8044 if (HasCMode(chptr, MODE_HIDEBMASKS))
568 michael 8040 mode_changes[mode_count].flags = CHFL_CHANOP | CHFL_HALFOP;
569     else
570     mode_changes[mode_count].flags = 0;
571 michael 4799 mode_changes[mode_count++].dir = dir;
572 adx 30 }
573    
574     static void
575 michael 3374 chm_except(struct Client *source_p, struct Channel *chptr, int parc, int *parn,
576 michael 2937 char **parv, int *errors, int alev, int dir, char c, unsigned int d)
577 adx 30 {
578     if (dir == MODE_QUERY || parc <= *parn)
579     {
580 michael 7797 dlink_node *node;
581 adx 30
582     if (*errors & SM_ERR_RPL_E)
583     return;
584    
585     *errors |= SM_ERR_RPL_E;
586    
587 michael 4800 DLINK_FOREACH(node, chptr->exceptlist.head)
588 adx 30 {
589 michael 4815 const struct Ban *ban = node->data;
590 michael 8040
591 michael 8044 if (!HasCMode(chptr, MODE_HIDEBMASKS) || alev >= CHACCESS_HALFOP)
592 michael 8040 sendto_one_numeric(source_p, &me, RPL_EXCEPTLIST, chptr->name,
593     ban->name, ban->user, ban->host,
594     ban->who, ban->when);
595 adx 30 }
596    
597 michael 4618 sendto_one_numeric(source_p, &me, RPL_ENDOFEXCEPTLIST, chptr->name);
598 adx 30 return;
599     }
600    
601 michael 3841 if (alev < CHACCESS_HALFOP)
602     {
603     if (!(*errors & SM_ERR_NOOPS))
604     sendto_one_numeric(source_p, &me,
605     alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
606 michael 4618 ERR_CHANOPRIVSNEEDED, chptr->name);
607 michael 4884
608 michael 3841 *errors |= SM_ERR_NOOPS;
609     return;
610     }
611    
612 adx 30 if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
613     return;
614    
615 michael 8051 char *const mask = nuh_mask[*parn];
616 michael 5745 strlcpy(mask, parv[*parn], sizeof(nuh_mask[*parn]));
617 michael 4791 ++(*parn);
618 adx 30
619 michael 5031 if (*mask == ':' || (!MyConnect(source_p) && strchr(mask, ' ')))
620     return;
621 adx 30
622     switch (dir)
623     {
624     case MODE_ADD:
625     if (!add_id(source_p, chptr, mask, CHFL_EXCEPTION))
626     return;
627     break;
628     case MODE_DEL:
629     if (!del_id(chptr, mask, CHFL_EXCEPTION))
630     return;
631     break;
632     default:
633     assert(0);
634     }
635    
636     mode_changes[mode_count].letter = c;
637 michael 8018 mode_changes[mode_count].arg = mask; /* At this point 'mask' is no longer than NICKLEN + USERLEN + HOSTLEN + 3 */
638 michael 3734 mode_changes[mode_count].id = NULL;
639 michael 8044 if (HasCMode(chptr, MODE_HIDEBMASKS))
640 michael 8040 mode_changes[mode_count].flags = CHFL_CHANOP | CHFL_HALFOP;
641     else
642     mode_changes[mode_count].flags = 0;
643 michael 4799 mode_changes[mode_count++].dir = dir;
644 adx 30 }
645    
646     static void
647 michael 3374 chm_invex(struct Client *source_p, struct Channel *chptr, int parc, int *parn,
648 michael 2937 char **parv, int *errors, int alev, int dir, char c, unsigned int d)
649 adx 30 {
650     if (dir == MODE_QUERY || parc <= *parn)
651     {
652 michael 7797 dlink_node *node;
653 adx 30
654     if (*errors & SM_ERR_RPL_I)
655     return;
656    
657     *errors |= SM_ERR_RPL_I;
658    
659 michael 4800 DLINK_FOREACH(node, chptr->invexlist.head)
660 adx 30 {
661 michael 4815 const struct Ban *ban = node->data;
662 michael 8040
663 michael 8044 if (!HasCMode(chptr, MODE_HIDEBMASKS) || alev >= CHACCESS_HALFOP)
664 michael 8040 sendto_one_numeric(source_p, &me, RPL_INVEXLIST, chptr->name,
665     ban->name, ban->user, ban->host,
666     ban->who, ban->when);
667 adx 30 }
668    
669 michael 4618 sendto_one_numeric(source_p, &me, RPL_ENDOFINVEXLIST, chptr->name);
670 adx 30 return;
671     }
672    
673 michael 3841 if (alev < CHACCESS_HALFOP)
674     {
675     if (!(*errors & SM_ERR_NOOPS))
676     sendto_one_numeric(source_p, &me,
677     alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
678 michael 4618 ERR_CHANOPRIVSNEEDED, chptr->name);
679 michael 4884
680 michael 3841 *errors |= SM_ERR_NOOPS;
681     return;
682     }
683    
684 adx 30 if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
685     return;
686    
687 michael 8051 char *const mask = nuh_mask[*parn];
688 michael 5745 strlcpy(mask, parv[*parn], sizeof(nuh_mask[*parn]));
689 michael 4791 ++(*parn);
690 adx 30
691 michael 5031 if (*mask == ':' || (!MyConnect(source_p) && strchr(mask, ' ')))
692     return;
693 adx 30
694     switch (dir)
695     {
696     case MODE_ADD:
697     if (!add_id(source_p, chptr, mask, CHFL_INVEX))
698     return;
699     break;
700     case MODE_DEL:
701     if (!del_id(chptr, mask, CHFL_INVEX))
702     return;
703     break;
704     default:
705     assert(0);
706     }
707    
708     mode_changes[mode_count].letter = c;
709 michael 8018 mode_changes[mode_count].arg = mask; /* At this point 'mask' is no longer than NICKLEN + USERLEN + HOSTLEN + 3 */
710 michael 3734 mode_changes[mode_count].id = NULL;
711 michael 8044 if (HasCMode(chptr, MODE_HIDEBMASKS))
712 michael 8040 mode_changes[mode_count].flags = CHFL_CHANOP | CHFL_HALFOP;
713     else
714     mode_changes[mode_count].flags = 0;
715 michael 4799 mode_changes[mode_count++].dir = dir;
716 adx 30 }
717    
718     static void
719 michael 3374 chm_voice(struct Client *source_p, struct Channel *chptr, int parc, int *parn,
720 michael 2951 char **parv, int *errors, int alev, int dir, char c, unsigned int d)
721 adx 30 {
722 michael 3143 struct Client *target_p;
723 adx 30 struct Membership *member;
724    
725 michael 2951 if (alev < CHACCESS_HALFOP)
726 adx 30 {
727     if (!(*errors & SM_ERR_NOOPS))
728 michael 3109 sendto_one_numeric(source_p, &me,
729     alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
730 michael 4618 ERR_CHANOPRIVSNEEDED, chptr->name);
731 michael 4884
732 adx 30 *errors |= SM_ERR_NOOPS;
733     return;
734     }
735    
736 michael 3671 if (dir == MODE_QUERY || parc <= *parn)
737 adx 30 return;
738    
739 michael 3672 if ((target_p = find_chasing(source_p, parv[(*parn)++])) == NULL)
740 michael 3737 return; /* find_chasing sends ERR_NOSUCHNICK */
741 adx 30
742 michael 3143 if ((member = find_channel_link(target_p, chptr)) == NULL)
743 adx 30 {
744     if (!(*errors & SM_ERR_NOTONCHANNEL))
745 michael 4618 sendto_one_numeric(source_p, &me, ERR_USERNOTINCHANNEL, target_p->name, chptr->name);
746 michael 4884
747 adx 30 *errors |= SM_ERR_NOTONCHANNEL;
748     return;
749     }
750    
751     if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
752     return;
753    
754 michael 6930 switch (dir)
755     {
756     case MODE_ADD:
757     if (has_member_flags(member, CHFL_VOICE))
758     return; /* No redundant mode changes */
759 michael 4884
760 michael 6930 AddMemberFlag(member, CHFL_VOICE);
761     break;
762     case MODE_DEL:
763     if (!has_member_flags(member, CHFL_VOICE))
764     return; /* No redundant mode changes */
765 adx 30
766 michael 6930 DelMemberFlag(member, CHFL_VOICE);
767     break;
768     }
769    
770 michael 3734 mode_changes[mode_count].letter = c;
771     mode_changes[mode_count].arg = target_p->name;
772     mode_changes[mode_count].id = target_p->id;
773 michael 8040 mode_changes[mode_count].flags = 0;
774 michael 4799 mode_changes[mode_count++].dir = dir;
775 adx 30 }
776    
777     static void
778 michael 3374 chm_hop(struct Client *source_p, struct Channel *chptr, int parc, int *parn,
779 michael 3150 char **parv, int *errors, int alev, int dir, char c, unsigned int d)
780 adx 30 {
781 michael 3143 struct Client *target_p;
782 adx 30 struct Membership *member;
783    
784 michael 3713 if (alev < CHACCESS_CHANOP)
785 adx 30 {
786     if (!(*errors & SM_ERR_NOOPS))
787 michael 3109 sendto_one_numeric(source_p, &me,
788     alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
789 michael 4618 ERR_CHANOPRIVSNEEDED, chptr->name);
790 michael 4884
791 adx 30 *errors |= SM_ERR_NOOPS;
792     return;
793     }
794    
795 michael 3671 if (dir == MODE_QUERY || parc <= *parn)
796 adx 30 return;
797    
798 michael 3672 if ((target_p = find_chasing(source_p, parv[(*parn)++])) == NULL)
799 michael 3737 return; /* find_chasing sends ERR_NOSUCHNICK */
800 adx 30
801 michael 3143 if ((member = find_channel_link(target_p, chptr)) == NULL)
802 adx 30 {
803     if (!(*errors & SM_ERR_NOTONCHANNEL))
804 michael 4618 sendto_one_numeric(source_p, &me, ERR_USERNOTINCHANNEL, target_p->name, chptr->name);
805 michael 4884
806 adx 30 *errors |= SM_ERR_NOTONCHANNEL;
807     return;
808     }
809    
810     if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
811     return;
812    
813 michael 6930 switch (dir)
814     {
815     case MODE_ADD:
816     if (has_member_flags(member, CHFL_HALFOP))
817     return; /* No redundant mode changes */
818 michael 4884
819 michael 6930 AddMemberFlag(member, CHFL_HALFOP);
820     break;
821     case MODE_DEL:
822     if (!has_member_flags(member, CHFL_HALFOP))
823     return; /* No redundant mode changes */
824 adx 30
825 michael 6930 DelMemberFlag(member, CHFL_HALFOP);
826     break;
827     }
828    
829 michael 3734 mode_changes[mode_count].letter = c;
830     mode_changes[mode_count].arg = target_p->name;
831     mode_changes[mode_count].id = target_p->id;
832 michael 8040 mode_changes[mode_count].flags = 0;
833 michael 4799 mode_changes[mode_count++].dir = dir;
834 adx 30 }
835    
836     static void
837 michael 3374 chm_op(struct Client *source_p, struct Channel *chptr, int parc, int *parn,
838 michael 2951 char **parv, int *errors, int alev, int dir, char c, unsigned int d)
839 adx 30 {
840 michael 3143 struct Client *target_p;
841 adx 30 struct Membership *member;
842    
843 michael 2951 if (alev < CHACCESS_CHANOP)
844 adx 30 {
845     if (!(*errors & SM_ERR_NOOPS))
846 michael 3109 sendto_one_numeric(source_p, &me,
847     alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
848 michael 4618 ERR_CHANOPRIVSNEEDED, chptr->name);
849 michael 4884
850 adx 30 *errors |= SM_ERR_NOOPS;
851     return;
852     }
853    
854 michael 3671 if (dir == MODE_QUERY || parc <= *parn)
855 adx 30 return;
856    
857 michael 3672 if ((target_p = find_chasing(source_p, parv[(*parn)++])) == NULL)
858 michael 3737 return; /* find_chasing sends ERR_NOSUCHNICK */
859 adx 30
860 michael 3143 if ((member = find_channel_link(target_p, chptr)) == NULL)
861 adx 30 {
862     if (!(*errors & SM_ERR_NOTONCHANNEL))
863 michael 4618 sendto_one_numeric(source_p, &me, ERR_USERNOTINCHANNEL, target_p->name, chptr->name);
864 michael 4884
865 adx 30 *errors |= SM_ERR_NOTONCHANNEL;
866     return;
867     }
868    
869     if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
870     return;
871    
872 michael 6930 switch (dir)
873     {
874     case MODE_ADD:
875     if (has_member_flags(member, CHFL_CHANOP))
876     return; /* No redundant mode changes */
877 michael 4884
878 michael 6930 AddMemberFlag(member, CHFL_CHANOP);
879     break;
880     case MODE_DEL:
881     if (!has_member_flags(member, CHFL_CHANOP))
882     return; /* No redundant mode changes */
883 adx 30
884 michael 6930 DelMemberFlag(member, CHFL_CHANOP);
885     break;
886     }
887    
888 michael 3734 mode_changes[mode_count].letter = c;
889     mode_changes[mode_count].arg = target_p->name;
890     mode_changes[mode_count].id = target_p->id;
891 michael 8040 mode_changes[mode_count].flags = 0;
892 michael 4799 mode_changes[mode_count++].dir = dir;
893 adx 30 }
894    
895     static void
896 michael 3374 chm_limit(struct Client *source_p, struct Channel *chptr, int parc, int *parn,
897 michael 2937 char **parv, int *errors, int alev, int dir, char c, unsigned int d)
898 adx 30 {
899     if (alev < CHACCESS_HALFOP)
900     {
901     if (!(*errors & SM_ERR_NOOPS))
902 michael 3109 sendto_one_numeric(source_p, &me,
903     alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
904 michael 4618 ERR_CHANOPRIVSNEEDED, chptr->name);
905 adx 30 *errors |= SM_ERR_NOOPS;
906     return;
907     }
908    
909     if (dir == MODE_QUERY)
910     return;
911    
912 michael 3671 if (dir == MODE_ADD && parc > *parn)
913 adx 30 {
914 michael 4833 char *const lstr = parv[(*parn)++];
915 michael 6947 int limit = 0;
916 adx 30
917 michael 3153 if (EmptyString(lstr) || (limit = atoi(lstr)) <= 0)
918 adx 30 return;
919    
920 michael 1793 sprintf(lstr, "%d", limit);
921 adx 30
922 michael 3151 /* If somebody sets MODE #channel +ll 1 2, accept latter --fl */
923 michael 3671 for (unsigned int i = 0; i < mode_count; ++i)
924 adx 30 if (mode_changes[i].letter == c && mode_changes[i].dir == MODE_ADD)
925     mode_changes[i].letter = 0;
926    
927     mode_changes[mode_count].letter = c;
928 michael 3734 mode_changes[mode_count].arg = lstr;
929 adx 30 mode_changes[mode_count].id = NULL;
930 michael 8040 mode_changes[mode_count].flags = 0;
931 michael 4799 mode_changes[mode_count++].dir = dir;
932 adx 30
933     chptr->mode.limit = limit;
934     }
935     else if (dir == MODE_DEL)
936     {
937     if (!chptr->mode.limit)
938     return;
939    
940     chptr->mode.limit = 0;
941    
942     mode_changes[mode_count].letter = c;
943 michael 3734 mode_changes[mode_count].arg = NULL;
944 adx 30 mode_changes[mode_count].id = NULL;
945 michael 8040 mode_changes[mode_count].flags = 0;
946 michael 4799 mode_changes[mode_count++].dir = dir;
947 adx 30 }
948     }
949    
950     static void
951 michael 3374 chm_key(struct Client *source_p, struct Channel *chptr, int parc, int *parn,
952 michael 2937 char **parv, int *errors, int alev, int dir, char c, unsigned int d)
953 adx 30 {
954     if (alev < CHACCESS_HALFOP)
955     {
956     if (!(*errors & SM_ERR_NOOPS))
957 michael 3109 sendto_one_numeric(source_p, &me,
958     alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
959 michael 4618 ERR_CHANOPRIVSNEEDED, chptr->name);
960 adx 30 *errors |= SM_ERR_NOOPS;
961     return;
962     }
963    
964     if (dir == MODE_QUERY)
965     return;
966    
967 michael 3671 if (dir == MODE_ADD && parc > *parn)
968 adx 30 {
969 michael 4833 char *const key = fix_key(parv[(*parn)++]);
970 adx 30
971 michael 3153 if (EmptyString(key))
972 adx 30 return;
973    
974     assert(key[0] != ' ');
975     strlcpy(chptr->mode.key, key, sizeof(chptr->mode.key));
976    
977 michael 3151 /* If somebody does MODE #channel +kk a b, accept latter --fl */
978 michael 3671 for (unsigned int i = 0; i < mode_count; ++i)
979 adx 30 if (mode_changes[i].letter == c && mode_changes[i].dir == MODE_ADD)
980     mode_changes[i].letter = 0;
981    
982     mode_changes[mode_count].letter = c;
983 michael 8022 mode_changes[mode_count].arg = key;
984 adx 30 mode_changes[mode_count].id = NULL;
985 michael 8040 mode_changes[mode_count].flags = 0;
986 michael 4799 mode_changes[mode_count++].dir = dir;
987 adx 30 }
988     else if (dir == MODE_DEL)
989     {
990     if (parc > *parn)
991 michael 4791 ++(*parn);
992 adx 30
993     if (chptr->mode.key[0] == '\0')
994     return;
995    
996     chptr->mode.key[0] = '\0';
997    
998     mode_changes[mode_count].letter = c;
999 michael 3734 mode_changes[mode_count].arg = "*";
1000 adx 30 mode_changes[mode_count].id = NULL;
1001 michael 8040 mode_changes[mode_count].flags = 0;
1002 michael 4799 mode_changes[mode_count++].dir = dir;
1003 adx 30 }
1004     }
1005    
1006     /* get_channel_access()
1007     *
1008     * inputs - pointer to Client struct
1009     * - pointer to Membership struct
1010     * output - CHACCESS_CHANOP if we should let them have
1011     * chanop level access, 0 for peon level access.
1012     * side effects - NONE
1013     */
1014     static int
1015 michael 2941 get_channel_access(const struct Client *source_p,
1016     const struct Membership *member)
1017 adx 30 {
1018     /* Let hacked servers in for now... */
1019     if (!MyClient(source_p))
1020 michael 4102 return CHACCESS_REMOTE;
1021 adx 30
1022 michael 3235 if (!member)
1023 adx 30 return CHACCESS_NOTONCHAN;
1024    
1025 michael 3374 /* Just to be sure.. */
1026 adx 30 assert(source_p == member->client_p);
1027    
1028     if (has_member_flags(member, CHFL_CHANOP))
1029     return CHACCESS_CHANOP;
1030    
1031     if (has_member_flags(member, CHFL_HALFOP))
1032     return CHACCESS_HALFOP;
1033    
1034     return CHACCESS_PEON;
1035     }
1036    
1037 michael 3151 /* send_mode_changes_server()
1038 michael 3159 * Input: the source client(source_p),
1039 adx 30 * the channel to send mode changes for(chptr)
1040     * Output: None.
1041 michael 3151 * Side-effects: Sends the appropriate mode changes to servers.
1042 adx 30 *
1043     */
1044     static void
1045 michael 3150 send_mode_changes_server(struct Client *source_p, struct Channel *chptr)
1046 adx 30 {
1047 michael 8016 char modebuf[IRCD_BUFSIZE] = "";
1048     char parabuf[IRCD_BUFSIZE] = "";
1049     char *parptr = parabuf;
1050 michael 8042 unsigned int mbl = 0, pbl = 0, arglen = 0, modecount = 0, paracount = 0;
1051     unsigned int dir = MODE_QUERY;
1052 adx 30
1053 michael 8016 mbl = snprintf(modebuf, sizeof(modebuf), ":%s TMODE %ju %s ",
1054     source_p->id, chptr->creationtime, chptr->name);
1055 adx 30
1056 michael 3374 /* Loop the list of modes we have */
1057 michael 5545 for (unsigned int i = 0; i < mode_count; ++i)
1058 adx 30 {
1059 michael 3668 if (mode_changes[i].letter == 0)
1060 adx 30 continue;
1061    
1062 michael 8016 const char *arg;
1063 michael 3141 if (mode_changes[i].id)
1064     arg = mode_changes[i].id;
1065     else
1066     arg = mode_changes[i].arg;
1067 adx 30
1068 michael 3215 if (arg)
1069 michael 3141 arglen = strlen(arg);
1070     else
1071     arglen = 0;
1072    
1073 michael 3136 /*
1074     * If we're creeping past the buf size, we need to send it and make
1075 adx 30 * another line for the other modes
1076     */
1077 michael 8014 if ((paracount == MAXMODEPARAMS) ||
1078 michael 8016 ((arglen + mbl + pbl + 2 /* +2 for /r/n */ ) > IRCD_BUFSIZE))
1079 adx 30 {
1080 michael 8014 if (modecount)
1081 michael 4962 sendto_server(source_p, 0, 0, "%s %s", modebuf, parabuf);
1082 michael 3215
1083 michael 8014 modecount = 0;
1084     paracount = 0;
1085 adx 30
1086 michael 8016 mbl = snprintf(modebuf, sizeof(modebuf), ":%s TMODE %ju %s ",
1087     source_p->id, chptr->creationtime, chptr->name);
1088 adx 30
1089     pbl = 0;
1090     parabuf[0] = '\0';
1091     parptr = parabuf;
1092     dir = MODE_QUERY;
1093     }
1094    
1095     if (dir != mode_changes[i].dir)
1096     {
1097     modebuf[mbl++] = (mode_changes[i].dir == MODE_ADD) ? '+' : '-';
1098     dir = mode_changes[i].dir;
1099     }
1100    
1101     modebuf[mbl++] = mode_changes[i].letter;
1102     modebuf[mbl] = '\0';
1103 michael 8014 ++modecount;
1104 adx 30
1105 michael 3215 if (arg)
1106 adx 30 {
1107 michael 8016 int len = sprintf(parptr, (pbl == 0) ? "%s" : " %s", arg);
1108 adx 30 pbl += len;
1109     parptr += len;
1110 michael 8014 ++paracount;
1111 adx 30 }
1112     }
1113    
1114 michael 8014 if (modecount)
1115 michael 4962 sendto_server(source_p, 0, 0, "%s %s", modebuf, parabuf);
1116 adx 30 }
1117    
1118     /* void send_mode_changes(struct Client *client_p,
1119     * struct Client *source_p,
1120     * struct Channel *chptr)
1121     * Input: The client sending(client_p), the source client(source_p),
1122     * the channel to send mode changes for(chptr),
1123     * mode change globals.
1124     * Output: None.
1125     * Side-effects: Sends the appropriate mode changes to other clients
1126     * and propagates to servers.
1127     */
1128     static void
1129 michael 5748 send_mode_changes_client(struct Client *source_p, struct Channel *chptr)
1130 adx 30 {
1131 michael 8040 unsigned int flags = 0;
1132 adx 30
1133 michael 8040 for (unsigned int pass = 2; pass--; flags = CHFL_CHANOP | CHFL_HALFOP)
1134 adx 30 {
1135 michael 8040 char modebuf[IRCD_BUFSIZE] = "";
1136     char parabuf[IRCD_BUFSIZE] = "";
1137     char *parptr = parabuf;
1138 michael 8042 unsigned int mbl = 0, pbl = 0, arglen = 0, modecount = 0, paracount = 0;
1139     unsigned int dir = MODE_QUERY;
1140 adx 30
1141 michael 8040 if (IsServer(source_p))
1142     mbl = snprintf(modebuf, sizeof(modebuf), ":%s MODE %s ", (IsHidden(source_p) ||
1143     ConfigServerHide.hide_servers) ?
1144     me.name : source_p->name, chptr->name);
1145 adx 30 else
1146 michael 8040 mbl = snprintf(modebuf, sizeof(modebuf), ":%s!%s@%s MODE %s ", source_p->name,
1147     source_p->username, source_p->host, chptr->name);
1148 adx 30
1149 michael 8040 for (unsigned int i = 0; i < mode_count; ++i)
1150 adx 30 {
1151 michael 8040 if (mode_changes[i].letter == 0 || mode_changes[i].flags != flags)
1152     continue;
1153 adx 30
1154 michael 8040 const char *arg = mode_changes[i].arg;
1155     if (arg)
1156     arglen = strlen(arg);
1157 adx 30 else
1158 michael 8040 arglen = 0;
1159 adx 30
1160 michael 8040 if ((paracount == MAXMODEPARAMS) ||
1161     ((arglen + mbl + pbl + 2 /* +2 for /r/n */ ) > IRCD_BUFSIZE))
1162     {
1163     if (modecount)
1164     sendto_channel_local(NULL, chptr, flags, 0, 0, "%s %s", modebuf, parabuf);
1165 adx 30
1166 michael 8040 modecount = 0;
1167     paracount = 0;
1168 adx 30
1169 michael 8040 if (IsServer(source_p))
1170     mbl = snprintf(modebuf, sizeof(modebuf), ":%s MODE %s ", (IsHidden(source_p) ||
1171     ConfigServerHide.hide_servers) ?
1172     me.name : source_p->name, chptr->name);
1173     else
1174     mbl = snprintf(modebuf, sizeof(modebuf), ":%s!%s@%s MODE %s ", source_p->name,
1175     source_p->username, source_p->host, chptr->name);
1176 adx 30
1177 michael 8040 pbl = 0;
1178     parabuf[0] = '\0';
1179     parptr = parabuf;
1180     dir = MODE_QUERY;
1181     }
1182    
1183     if (dir != mode_changes[i].dir)
1184     {
1185     modebuf[mbl++] = (mode_changes[i].dir == MODE_ADD) ? '+' : '-';
1186     dir = mode_changes[i].dir;
1187     }
1188    
1189     modebuf[mbl++] = mode_changes[i].letter;
1190     modebuf[mbl] = '\0';
1191     ++modecount;
1192    
1193     if (arg)
1194     {
1195     int len = sprintf(parptr, (pbl == 0) ? "%s" : " %s", arg);
1196     pbl += len;
1197     parptr += len;
1198     ++paracount;
1199     }
1200 adx 30 }
1201 michael 8040
1202     if (modecount)
1203     sendto_channel_local(NULL, chptr, flags, 0, 0, "%s %s", modebuf, parabuf);
1204 adx 30 }
1205     }
1206    
1207 michael 8089 const struct mode_letter *cmode_map[256];
1208     const struct mode_letter cmode_tab[] =
1209     {
1210     { 'b', 0, chm_ban },
1211     { 'c', MODE_NOCTRL, chm_simple },
1212     { 'e', 0, chm_except },
1213     { 'h', 0, chm_hop },
1214     { 'i', MODE_INVITEONLY, chm_simple },
1215     { 'k', 0, chm_key },
1216     { 'l', 0, chm_limit },
1217     { 'm', MODE_MODERATED, chm_simple },
1218     { 'n', MODE_NOPRIVMSGS, chm_simple },
1219     { 'o', 0, chm_op },
1220     { 'p', MODE_PRIVATE, chm_simple },
1221     { 'r', MODE_REGISTERED, chm_registered },
1222     { 's', MODE_SECRET, chm_simple },
1223     { 't', MODE_TOPICLIMIT, chm_simple },
1224     { 'u', MODE_HIDEBMASKS, chm_simple },
1225     { 'v', 0, chm_voice },
1226     { 'C', MODE_NOCTCP, chm_simple },
1227     { 'I', 0, chm_invex },
1228     { 'L', MODE_EXTLIMIT, chm_simple_oper },
1229     { 'M', MODE_MODREG, chm_simple },
1230     { 'O', MODE_OPERONLY, chm_simple_oper },
1231     { 'R', MODE_REGONLY, chm_simple },
1232     { 'S', MODE_SSLONLY, chm_simple },
1233     { 'T', MODE_NONOTICE, chm_simple },
1234     { '\0', 0, NULL }
1235     };
1236    
1237     void
1238     channel_mode_init(void)
1239     {
1240     for (const struct mode_letter *tab = cmode_tab; tab->letter; ++tab)
1241     cmode_map[tab->letter] = tab;
1242     }
1243    
1244 michael 3671 /*
1245 michael 3159 * Input: The the client this originated
1246 adx 30 * from, the channel, the parameter count starting at the modes,
1247     * the parameters, the channel name.
1248     * Output: None.
1249     * Side-effects: Changes the channel membership and modes appropriately,
1250     * sends the appropriate MODE messages to the appropriate
1251     * clients.
1252     */
1253     void
1254 michael 3150 set_channel_mode(struct Client *source_p, struct Channel *chptr,
1255 michael 2937 struct Membership *member, int parc, char *parv[])
1256 adx 30 {
1257     int dir = MODE_ADD;
1258     int parn = 1;
1259 michael 3671 int alevel = 0, errors = 0;
1260 adx 30
1261     mode_count = 0;
1262     mode_limit = 0;
1263     simple_modes_mask = 0;
1264    
1265     alevel = get_channel_access(source_p, member);
1266    
1267 michael 3283 for (const char *ml = parv[0]; *ml; ++ml)
1268 adx 30 {
1269 michael 3250 switch (*ml)
1270 adx 30 {
1271     case '+':
1272     dir = MODE_ADD;
1273     break;
1274     case '-':
1275     dir = MODE_DEL;
1276     break;
1277     case '=':
1278     dir = MODE_QUERY;
1279     break;
1280     default:
1281 michael 2939 {
1282 michael 8089 const struct mode_letter *mode = cmode_map[(unsigned char)*ml];
1283 michael 2939
1284 michael 8089 if (mode)
1285     mode->func(source_p, chptr, parc, &parn, parv,
1286     &errors, alevel, dir, *ml, mode->mode);
1287     else
1288     chm_nosuch(source_p, chptr, parc, &parn, parv,
1289     &errors, alevel, dir, *ml, mode->mode);
1290 adx 30 break;
1291 michael 2939 }
1292 adx 30 }
1293     }
1294    
1295 michael 5749 /* Bail out if we have nothing to do... */
1296     if (!mode_count)
1297     return;
1298    
1299 michael 5748 send_mode_changes_client(source_p, chptr);
1300     send_mode_changes_server(source_p, chptr);
1301 adx 30 }

Properties

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