]> jfr.im git - solanum.git/blob - src/chmode.c
chmode: fix construct_cflags_strings.
[solanum.git] / src / chmode.c
1 chmode_flags[256];
2
3 extern int h_get_channel_access;
4
5 /* OPTIMIZE ME! -- dwr */
6 void
7 construct_cflags_strings(void)
8 {
9 int i;
10 char *ptr = cflagsbuf;
11 char *ptr2 = cflagsmyinfo;
12
13 *ptr = '\0';
14 *ptr2 = '\0';
15
16 for(i = 0; i < 256; i++)
17 {
18 if( !(chmode_table[i].set_func == chm_ban) &&
19 !(chmode_table[i].set_func == chm_forward) &&
20 !(chmode_table[i].set_func == chm_throttle) &&
21 !(chmode_table[i].set_func == chm_key) &&
22 !(chmode_table[i].set_func == chm_limit) &&
23 !(chmode_table[i].set_func == chm_op) &&
24 !(chmode_table[i].set_func == chm_voice))
25 {
26 chmode_flags[i] = chmode_table[i].mode_type;
27 }
28 else
29 {
30 chmode_flags[i] = 0;
31 }
32
33 switch (chmode_flags[i])
34 {
35 case MODE_EXLIMIT:
36 case MODE_DISFORWARD:
37 *ptr++ = (char) i;
38 case MODE_REGONLY:
39 if(rb_dlink_list_length(&service_list))
40 {
41 *ptr++ = (char) i;
42 }
43
44 break;
45 default:
46 if(chmode_flags[i] != 0)
47 {
48 *ptr++ = (char) i;
49 }
50 }
51
52 /* Should we leave orphaned check here? -- dwr */
53 if(!(chmode_table[i].set_func == chm_nosuch) && !(chmode_table[i].set_func == chm_orphaned))
54 {
55 *ptr2++ = (char) i;
56 }
57 }
58
59 *ptr++ = '\0';
60 *ptr2++ = '\0';
61 }
62
63 /*
64 * find_umode_slot
65 *
66 * inputs - NONE
67 * outputs - an available cflag bitmask or
68 * 0 if no cflags are available
69 * side effects - NONE
70 */
71 static unsigned int
72 find_cflag_slot(void)
73 {
74 unsigned int all_cflags = 0, my_cflag = 0, i;
75
76 for (i = 0; i < 256; i++)
77 all_cflags |= chmode_flags[i];
78
79 for (my_cflag = 1; my_cflag && (all_cflags & my_cflag);
80 my_cflag <<= 1);
81
82 return my_cflag;
83 }
84
85 unsigned int
86 cflag_add(char c_, ChannelModeFunc function)
87 {
88 int c = (unsigned char)c_;
89
90 if (chmode_table[c].set_func != chm_nosuch &&
91 chmode_table[c].set_func != chm_orphaned)
92 return 0;
93
94 if (chmode_table[c].set_func == chm_nosuch)
95 chmode_table[c].mode_type = find_cflag_slot();
96 if (chmode_table[c].mode_type == 0)
97 return 0;
98 chmode_table[c].set_func = function;
99 construct_cflags_strings();
100 return chmode_table[c].mode_type;
101 }
102
103 void
104 cflag_orphan(char c_)
105 {
106 int c = (unsigned char)c_;
107
108 s_assert(chmode_flags[c] != 0);
109 chmode_table[c].set_func = chm_orphaned;
110 construct_cflags_strings();
111 }
112
113 int
114 get_channel_access(struct Client *source_p, struct membership *msptr)
115 {
116 hook_data_channel_approval moduledata;
117
118 if(!MyClient(source_p))
119 return CHFL_CHANOP;
120
121 if (msptr == NULL)
122 return CHFL_PEON;
123
124 moduledata.client = source_p;
125 moduledata.chptr = msptr->chptr;
126 moduledata.msptr = msptr;
127 moduledata.target = NULL;
128 moduledata.approved = is_chanop(msptr) ? CHFL_CHANOP : CHFL_PEON;
129
130 call_hook(h_get_channel_access, &moduledata);
131
132 return moduledata.approved;
133 }
134
135 /* add_id()
136 *
137 * inputs - client, channel, id to add, type, forward
138 * outputs - 0 on failure, 1 on success
139 * side effects - given id is added to the appropriate list
140 */
141 int
142 add_id(struct Client *source_p, struct Channel *chptr, const char *banid, const char *forward,
143 rb_dlink_list * list, long mode_type)
144 {
145 struct Ban *actualBan;
146 static char who[USERHOST_REPLYLEN];
147 char *realban = LOCAL_COPY(banid);
148 rb_dlink_node *ptr;
149
150 /* dont let local clients overflow the banlist, or set redundant
151 * bans
152 */
153 if(MyClient(source_p))
154 {
155 if((rb_dlink_list_length(&chptr->banlist) + rb_dlink_list_length(&chptr->exceptlist) + rb_dlink_list_length(&chptr->invexlist) + rb_dlink_list_length(&chptr->quietlist)) >= (chptr->mode.mode & MODE_EXLIMIT ? ConfigChannel.max_bans_large : ConfigChannel.max_bans))
156 {
157 sendto_one(source_p, form_str(ERR_BANLISTFULL),
158 me.name, source_p->name, chptr->chname, realban);
159 return 0;
160 }
161
162 RB_DLINK_FOREACH(ptr, list->head)
163 {
164 actualBan = ptr->data;
165 if(mask_match(actualBan->banstr, realban))
166 return 0;
167 }
168 }
169 /* dont let remotes set duplicates */
170 else
171 {
172 RB_DLINK_FOREACH(ptr, list->head)
173 {
174 actualBan = ptr->data;
175 if(!irccmp(actualBan->banstr, realban))
176 return 0;
177 }
178 }
179
180
181 if(IsPerson(source_p))
182 rb_sprintf(who, "%s!%s@%s", source_p->name, source_p->username, source_p->host);
183 else
184 rb_strlcpy(who, source_p->name, sizeof(who));
185
186 actualBan = allocate_ban(realban, who, forward);
187 actualBan->when = rb_current_time();
188
189 rb_dlinkAdd(actualBan, &actualBan->node, list);
190
191 /* invalidate the can_send() cache */
192 if(mode_type == CHFL_BAN || mode_type == CHFL_QUIET || mode_type == CHFL_EXCEPTION)
193 chptr->bants++;
194
195 return 1;
196 }
197
198 /* del_id()
199 *
200 * inputs - channel, id to remove, type
201 * outputs - pointer to ban that was removed, if any
202 * side effects - given id is removed from the appropriate list and returned
203 */
204 struct Ban *
205 del_id(struct Channel *chptr, const char *banid, rb_dlink_list * list, long mode_type)
206 {
207 rb_dlink_node *ptr;
208 struct Ban *banptr;
209
210 if(EmptyString(banid))
211 return NULL;
212
213 RB_DLINK_FOREACH(ptr, list->head)
214 {
215 banptr = ptr->data;
216
217 if(irccmp(banid, banptr->banstr) == 0)
218 {
219 rb_dlinkDelete(&banptr->node, list);
220 free_ban(banptr);
221
222 /* invalidate the can_send() cache */
223 if(mode_type == CHFL_BAN || mode_type == CHFL_QUIET || mode_type == CHFL_EXCEPTION)
224 chptr->bants++;
225
226 return banptr;
227 }
228 }
229
230 return NULL;
231 }
232
233 /* check_string()
234 *
235 * input - string to check
236 * output - pointer to 'fixed' string, or "*" if empty
237 * side effects - any white space found becomes \0
238 */
239 static char *
240 check_string(char *s)
241 {
242 char *str = s;
243 static char splat[] = "*";
244 if(!(s && *s))
245 return splat;
246
247 for(; *s; ++s)
248 {
249 if(IsSpace(*s))
250 {
251 *s = '\0';
252 break;
253 }
254 }
255 return str;
256 }
257
258 /* pretty_mask()
259 *
260 * inputs - mask to pretty
261 * outputs - better version of the mask
262 * side effects - mask is chopped to limits, and transformed:
263 * x!y@z => x!y@z
264 * y@z => *!y@z
265 * x!y => x!y@*
266 * x => x!*@*
267 * z.d => *!*@z.d
268 */
269 static char *
270 pretty_mask(const char *idmask)
271 {
272 static char mask_buf[BUFSIZE];
273 int old_mask_pos;
274 char *nick, *user, *host, *forward = NULL;
275 char splat[] = "*";
276 char *t, *at, *ex, *ex2;
277 char ne = 0, ue = 0, he = 0, fe = 0; /* save values at nick[NICKLEN], et all */
278 char e2 = 0; /* save value that delimits forward channel */
279 char *mask;
280
281 mask = LOCAL_COPY(idmask);
282 mask = check_string(mask);
283 collapse(mask);
284
285 nick = user = host = splat;
286
287 if((size_t) BUFSIZE - mask_pos < strlen(mask) + 5)
288 return NULL;
289
290 old_mask_pos = mask_pos;
291
292 if (*mask == '$')
293 {
294 mask_pos += rb_sprintf(mask_buf + mask_pos, "%s", mask) + 1;
295 t = mask_buf + old_mask_pos + 1;
296 if (*t == '!')
297 *t = '~';
298 if (*t == '~')
299 t++;
300 *t = ToLower(*t);
301 return mask_buf + old_mask_pos;
302 }
303
304 at = ex = ex2 = NULL;
305 if((t = strchr(mask, '@')) != NULL)
306 {
307 at = t;
308 *t++ = '\0';
309 if(*t != '\0')
310 host = t;
311
312 if((t = strchr(mask, '!')) != NULL)
313 {
314 ex = t;
315 *t++ = '\0';
316 if(*t != '\0')
317 user = t;
318 if(*mask != '\0')
319 nick = mask;
320 }
321 else
322 {
323 if(*mask != '\0')
324 user = mask;
325 }
326
327 if((t = strchr(host, '!')) != NULL || (t = strchr(host, '$')) != NULL)
328 {
329 ex2 = t;
330 e2 = *t;
331 *t++= '\0';
332 if (*t != '\0')
333 forward = t;
334 }
335 }
336 else if((t = strchr(mask, '!')) != NULL)
337 {
338 ex = t;
339 *t++ = '\0';
340 if(*mask != '\0')
341 nick = mask;
342 if(*t != '\0')
343 user = t;
344 }
345 else if(strchr(mask, '.') != NULL || strchr(mask, ':') != NULL)
346 {
347 if(*mask != '\0')
348 host = mask;
349 }
350 else
351 {
352 if(*mask != '\0')
353 nick = mask;
354 }
355
356 /* truncate values to max lengths */
357 if(strlen(nick) > NICKLEN - 1)
358 {
359 ne = nick[NICKLEN - 1];
360 nick[NICKLEN - 1] = '\0';
361 }
362 if(strlen(user) > USERLEN)
363 {
364 ue = user[USERLEN];
365 user[USERLEN] = '\0';
366 }
367 if(strlen(host) > HOSTLEN)
368 {
369 he = host[HOSTLEN];
370 host[HOSTLEN] = '\0';
371 }
372 if(forward && strlen(forward) > CHANNELLEN)
373 {
374 fe = forward[CHANNELLEN];
375 forward[CHANNELLEN] = '\0';
376 }
377
378 if (forward)
379 mask_pos += rb_sprintf(mask_buf + mask_pos, "%s!%s@%s$%s", nick, user, host, forward) + 1;
380 else
381 mask_pos += rb_sprintf(mask_buf + mask_pos, "%s!%s@%s", nick, user, host) + 1;
382
383 /* restore mask, since we may need to use it again later */
384 if(at)
385 *at = '@';
386 if(ex)
387 *ex = '!';
388 if(ex2)
389 *ex2 = e2;
390 if(ne)
391 nick[NICKLEN - 1] = ne;
392 if(ue)
393 user[USERLEN] = ue;
394 if(he)
395 host[HOSTLEN] = he;
396 if(fe)
397 forward[CHANNELLEN] = fe;
398
399 return mask_buf + old_mask_pos;
400 }
401
402 /* fix_key()
403 *
404 * input - key to fix
405 * output - the same key, fixed
406 * side effects - anything below ascii 13 is discarded, ':' discarded,
407 * high ascii is dropped to lower half of ascii table
408 */
409 static char *
410 fix_key(char *arg)
411 {
412 u_char *s, *t, c;
413
414 for(s = t = (u_char *) arg; (c = *s); s++)
415 {
416 c &= 0x7f;
417 if(c != ':' && c != ',' && c > ' ')
418 *t++ = c;
419 }
420
421 *t = '\0';
422 return arg;
423 }
424
425 /* fix_key_remote()
426 *
427 * input - key to fix
428 * ouput - the same key, fixed
429 * side effects - high ascii dropped to lower half of table,
430 * CR/LF/':' are dropped
431 */
432 static char *
433 fix_key_remote(char *arg)
434 {
435 u_char *s, *t, c;
436
437 for(s = t = (u_char *) arg; (c = *s); s++)
438 {
439 c &= 0x7f;
440 if((c != 0x0a) && (c != ':') && (c != ',') && (c != 0x0d) && (c != ' '))
441 *t++ = c;
442 }
443
444 *t = '\0';
445 return arg;
446 }
447
448 /* chm_*()
449 *
450 * The handlers for each specific mode.
451 */
452 void
453 chm_nosuch(struct Client *source_p, struct Channel *chptr,
454 int alevel, int parc, int *parn,
455 const char **parv, int *errors, int dir, char c, long mode_type)
456 {
457 if(*errors & SM_ERR_UNKNOWN)
458 return;
459 *errors |= SM_ERR_UNKNOWN;
460 sendto_one(source_p, form_str(ERR_UNKNOWNMODE), me.name, source_p->name, c);
461 }
462
463 void
464 chm_simple(struct Client *source_p, struct Channel *chptr,
465 int alevel, int parc, int *parn,
466 const char **parv, int *errors, int dir, char c, long mode_type)
467 {
468 if(alevel != CHFL_CHANOP)
469 {
470 if(!(*errors & SM_ERR_NOOPS))
471 sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
472 me.name, source_p->name, chptr->chname);
473 *errors |= SM_ERR_NOOPS;
474 return;
475 }
476
477 if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE))
478 return;
479
480 /* setting + */
481 if((dir == MODE_ADD) && !(chptr->mode.mode & mode_type))
482 {
483 chptr->mode.mode |= mode_type;
484
485 mode_changes[mode_count].letter = c;
486 mode_changes[mode_count].dir = MODE_ADD;
487 mode_changes[mode_count].caps = 0;
488 mode_changes[mode_count].nocaps = 0;
489 mode_changes[mode_count].id = NULL;
490 mode_changes[mode_count].mems = ALL_MEMBERS;
491 mode_changes[mode_count++].arg = NULL;
492 }
493 else if((dir == MODE_DEL) && (chptr->mode.mode & mode_type))
494 {
495 chptr->mode.mode &= ~mode_type;
496
497 mode_changes[mode_count].letter = c;
498 mode_changes[mode_count].dir = MODE_DEL;
499 mode_changes[mode_count].caps = 0;
500 mode_changes[mode_count].nocaps = 0;
501 mode_changes[mode_count].mems = ALL_MEMBERS;
502 mode_changes[mode_count].id = NULL;
503 mode_changes[mode_count++].arg = NULL;
504 }
505 }
506
507 void
508 chm_orphaned(struct Client *source_p, struct Channel *chptr,
509 int alevel, int parc, int *parn,
510 const char **parv, int *errors, int dir, char c, long mode_type)
511 {
512 if(MyClient(source_p))
513 return;
514
515 if((dir == MODE_ADD) && !(chptr->mode.mode & mode_type))
516 {
517 chptr->mode.mode |= mode_type;
518
519 mode_changes[mode_count].letter = c;
520 mode_changes[mode_count].dir = MODE_ADD;
521 mode_changes[mode_count].caps = 0;
522 mode_changes[mode_count].nocaps = 0;
523 mode_changes[mode_count].id = NULL;
524 mode_changes[mode_count].mems = ALL_MEMBERS;
525 mode_changes[mode_count++].arg = NULL;
526 }
527 else if((dir == MODE_DEL) && (chptr->mode.mode & mode_type))
528 {
529 chptr->mode.mode &= ~mode_type;
530
531 mode_changes[mode_count].letter = c;
532 mode_changes[mode_count].dir = MODE_DEL;
533 mode_changes[mode_count].caps = 0;
534 mode_changes[mode_count].nocaps = 0;
535 mode_changes[mode_count].mems = ALL_MEMBERS;
536 mode_changes[mode_count].id = NULL;
537 mode_changes[mode_count++].arg = NULL;
538 }
539 }
540
541 void
542 chm_staff(struct Client *source_p, struct Channel *chptr,
543 int alevel, int parc, int *parn,
544 const char **parv, int *errors, int dir, char c, long mode_type)
545 {
546 if(!IsOper(source_p) && !IsServer(source_p))
547 {
548 if(!(*errors & SM_ERR_NOPRIVS))
549 sendto_one_numeric(source_p, ERR_NOPRIVILEGES, form_str(ERR_NOPRIVILEGES));
550 *errors |= SM_ERR_NOPRIVS;
551 return;
552 }
553 if(MyClient(source_p) && !IsOperResv(source_p))
554 {
555 if(!(*errors & SM_ERR_NOPRIVS))
556 sendto_one(source_p, form_str(ERR_NOPRIVS), me.name,
557 source_p->name, "resv");
558 *errors |= SM_ERR_NOPRIVS;
559 return;
560 }
561
562 if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE))
563 return;
564
565 /* setting + */
566 if((dir == MODE_ADD) && !(chptr->mode.mode & mode_type))
567 {
568 chptr->mode.mode |= mode_type;
569
570 mode_changes[mode_count].letter = c;
571 mode_changes[mode_count].dir = MODE_ADD;
572 mode_changes[mode_count].caps = 0;
573 mode_changes[mode_count].nocaps = 0;
574 mode_changes[mode_count].id = NULL;
575 mode_changes[mode_count].mems = ALL_MEMBERS;
576 mode_changes[mode_count++].arg = NULL;
577 }
578 else if((dir == MODE_DEL) && (chptr->mode.mode & mode_type))
579 {
580 chptr->mode.mode &= ~mode_type;
581
582 mode_changes[mode_count].letter = c;
583 mode_changes[mode_count].dir = MODE_DEL;
584 mode_changes[mode_count].caps = 0;
585 mode_changes[mode_count].nocaps = 0;
586 mode_changes[mode_count].mems = ALL_MEMBERS;
587 mode_changes[mode_count].id = NULL;
588 mode_changes[mode_count++].arg = NULL;
589 }
590 }
591
592 void
593 chm_ban(struct Client *source_p, struct Channel *chptr,
594 int alevel, int parc, int *parn,
595 const char **parv, int *errors, int dir, char c, long mode_type)
596 {
597 char *mask, *raw_mask, *forward;
598 rb_dlink_list *list;
599 rb_dlink_node *ptr;
600 struct Ban *banptr;
601 int errorval;
602 int rpl_list;
603 int rpl_endlist;
604 int caps;
605 int mems;
606
607 switch (mode_type)
608 {
609 case CHFL_BAN:
610 list = &chptr->banlist;
611 errorval = SM_ERR_RPL_B;
612 rpl_list = RPL_BANLIST;
613 rpl_endlist = RPL_ENDOFBANLIST;
614 mems = ALL_MEMBERS;
615 caps = 0;
616 break;
617
618 case CHFL_EXCEPTION:
619 /* if +e is disabled, allow all but +e locally */
620 if(!ConfigChannel.use_except && MyClient(source_p) &&
621 ((dir == MODE_ADD) && (parc > *parn)))
622 return;
623
624 list = &chptr->exceptlist;
625 errorval = SM_ERR_RPL_E;
626 rpl_list = RPL_EXCEPTLIST;
627 rpl_endlist = RPL_ENDOFEXCEPTLIST;
628 caps = CAP_EX;
629
630 if(ConfigChannel.use_except || (dir == MODE_DEL))
631 mems = ONLY_CHANOPS;
632 else
633 mems = ONLY_SERVERS;
634 break;
635
636 case CHFL_INVEX:
637 /* if +I is disabled, allow all but +I locally */
638 if(!ConfigChannel.use_invex && MyClient(source_p) &&
639 (dir == MODE_ADD) && (parc > *parn))
640 return;
641
642 list = &chptr->invexlist;
643 errorval = SM_ERR_RPL_I;
644 rpl_list = RPL_INVITELIST;
645 rpl_endlist = RPL_ENDOFINVITELIST;
646 caps = CAP_IE;
647
648 if(ConfigChannel.use_invex || (dir == MODE_DEL))
649 mems = ONLY_CHANOPS;
650 else
651 mems = ONLY_SERVERS;
652 break;
653
654 case CHFL_QUIET:
655 list = &chptr->quietlist;
656 errorval = SM_ERR_RPL_Q;
657 rpl_list = RPL_QUIETLIST;
658 rpl_endlist = RPL_ENDOFQUIETLIST;
659 mems = ALL_MEMBERS;
660 caps = 0;
661 break;
662
663 default:
664 sendto_realops_snomask(SNO_GENERAL, L_ALL, "chm_ban() called with unknown type!");
665 return;
666 break;
667 }
668
669 if(dir == 0 || parc <= *parn)
670 {
671 if((*errors & errorval) != 0)
672 return;
673 *errors |= errorval;
674
675 /* non-ops cant see +eI lists.. */
676 if(alevel != CHFL_CHANOP && mode_type != CHFL_BAN &&
677 mode_type != CHFL_QUIET)
678 {
679 if(!(*errors & SM_ERR_NOOPS))
680 sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
681 me.name, source_p->name, chptr->chname);
682 *errors |= SM_ERR_NOOPS;
683 return;
684 }
685
686 RB_DLINK_FOREACH(ptr, list->head)
687 {
688 char buf[BANLEN];
689 banptr = ptr->data;
690 if(banptr->forward)
691 rb_snprintf(buf, sizeof(buf), "%s$%s", banptr->banstr, banptr->forward);
692 else
693 rb_strlcpy(buf, banptr->banstr, sizeof(buf));
694
695 sendto_one(source_p, form_str(rpl_list),
696 me.name, source_p->name, chptr->chname,
697 buf, banptr->who, banptr->when);
698 }
699 sendto_one(source_p, form_str(rpl_endlist), me.name, source_p->name, chptr->chname);
700 return;
701 }
702
703 if(alevel != CHFL_CHANOP)
704 {
705 if(!(*errors & SM_ERR_NOOPS))
706 sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
707 me.name, source_p->name, chptr->chname);
708 *errors |= SM_ERR_NOOPS;
709 return;
710 }
711
712 if(MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
713 return;
714
715 raw_mask = parv[(*parn)];
716 (*parn)++;
717
718 /* empty ban, or starts with ':' which messes up s2s, ignore it */
719 if(EmptyString(raw_mask) || *raw_mask == ':')
720 return;
721
722 if(!MyClient(source_p))
723 {
724 if(strchr(raw_mask, ' '))
725 return;
726
727 mask = raw_mask;
728 }
729 else
730 mask = pretty_mask(raw_mask);
731
732 /* Look for a $ after the first character.
733 * As the first character, it marks an extban; afterwards
734 * it delimits a forward channel.
735 */
736 if ((forward = strchr(mask+1, '$')) != NULL)
737 {
738 *forward++ = '\0';
739 if (*forward == '\0')
740 forward = NULL;
741 }
742
743 /* we'd have problems parsing this, hyb6 does it too
744 * also make sure it will always fit on a line with channel
745 * name etc.
746 */
747 if(strlen(mask) > IRCD_MIN(BANLEN, MODEBUFLEN - 5))
748 return;
749
750 /* if we're adding a NEW id */
751 if(dir == MODE_ADD)
752 {
753 if (*mask == '$' && MyClient(source_p))
754 {
755 if (!valid_extban(mask, source_p, chptr, mode_type))
756 /* XXX perhaps return an error message here */
757 return;
758 }
759
760 /* dont allow local clients to overflow the banlist, dont
761 * let remote servers set duplicate bans
762 */
763 if(!add_id(source_p, chptr, mask, forward, list, mode_type))
764 return;
765
766 if(forward)
767 forward[-1]= '$';
768
769 mode_changes[mode_count].letter = c;
770 mode_changes[mode_count].dir = MODE_ADD;
771 mode_changes[mode_count].caps = caps;
772 mode_changes[mode_count].nocaps = 0;
773 mode_changes[mode_count].mems = mems;
774 mode_changes[mode_count].id = NULL;
775 mode_changes[mode_count++].arg = mask;
776 }
777 else if(dir == MODE_DEL)
778 {
779 struct Ban *removed;
780 static char buf[BANLEN * MAXMODEPARAMS];
781 int old_removed_mask_pos = removed_mask_pos;
782 if((removed = del_id(chptr, mask, list, mode_type)) == NULL)
783 {
784 /* mask isn't a valid ban, check raw_mask */
785 if((removed = del_id(chptr, raw_mask, list, mode_type)) != NULL)
786 mask = raw_mask;
787 }
788
789 if(removed && removed->forward)
790 removed_mask_pos += rb_snprintf(buf, sizeof(buf), "%s$%s", removed->banstr, removed->forward);
791 else
792 removed_mask_pos += rb_strlcpy(buf, mask, sizeof(buf));
793 if(removed)
794 {
795 free_ban(removed);
796 removed = NULL;
797 }
798
799 mode_changes[mode_count].letter = c;
800 mode_changes[mode_count].dir = MODE_DEL;
801 mode_changes[mode_count].caps = caps;
802 mode_changes[mode_count].nocaps = 0;
803 mode_changes[mode_count].mems = mems;
804 mode_changes[mode_count].id = NULL;
805 mode_changes[mode_count++].arg = buf + old_removed_mask_pos;
806 }
807 }
808
809 void
810 chm_op(struct Client *source_p, struct Channel *chptr,
811 int alevel, int parc, int *parn,
812 const char **parv, int *errors, int dir, char c, long mode_type)
813 {
814 struct membership *mstptr;
815 const char *opnick;
816 struct Client *targ_p;
817
818 if(alevel != CHFL_CHANOP)
819 {
820 if(!(*errors & SM_ERR_NOOPS))
821 sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
822 me.name, source_p->name, chptr->chname);
823 *errors |= SM_ERR_NOOPS;
824 return;
825 }
826
827 if((dir == MODE_QUERY) || (parc <= *parn))
828 return;
829
830 opnick = parv[(*parn)];
831 (*parn)++;
832
833 /* empty nick */
834 if(EmptyString(opnick))
835 {
836 sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), "*");
837 return;
838 }
839
840 if((targ_p = find_chasing(source_p, opnick, NULL)) == NULL)
841 {
842 return;
843 }
844
845 mstptr = find_channel_membership(chptr, targ_p);
846
847 if(mstptr == NULL)
848 {
849 if(!(*errors & SM_ERR_NOTONCHANNEL) && MyClient(source_p))
850 sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL,
851 form_str(ERR_USERNOTINCHANNEL), opnick, chptr->chname);
852 *errors |= SM_ERR_NOTONCHANNEL;
853 return;
854 }
855
856 if(MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
857 return;
858
859 if(dir == MODE_ADD)
860 {
861 if(targ_p == source_p && mstptr->flags & CHFL_CHANOP)
862 return;
863
864 mode_changes[mode_count].letter = c;
865 mode_changes[mode_count].dir = MODE_ADD;
866 mode_changes[mode_count].caps = 0;
867 mode_changes[mode_count].nocaps = 0;
868 mode_changes[mode_count].mems = ALL_MEMBERS;
869 mode_changes[mode_count].id = targ_p->id;
870 mode_changes[mode_count].arg = targ_p->name;
871 mode_changes[mode_count++].client = targ_p;
872
873 mstptr->flags |= CHFL_CHANOP;
874 }
875 else
876 {
877 if(MyClient(source_p) && IsService(targ_p))
878 {
879 sendto_one(source_p, form_str(ERR_ISCHANSERVICE),
880 me.name, source_p->name, targ_p->name, chptr->chname);
881 return;
882 }
883
884 mode_changes[mode_count].letter = c;
885 mode_changes[mode_count].dir = MODE_DEL;
886 mode_changes[mode_count].caps = 0;
887 mode_changes[mode_count].nocaps = 0;
888 mode_changes[mode_count].mems = ALL_MEMBERS;
889 mode_changes[mode_count].id = targ_p->id;
890 mode_changes[mode_count].arg = targ_p->name;
891 mode_changes[mode_count++].client = targ_p;
892
893 mstptr->flags &= ~CHFL_CHANOP;
894 }
895 }
896
897 void
898 chm_voice(struct Client *source_p, struct Channel *chptr,
899 int alevel, int parc, int *parn,
900 const char **parv, int *errors, int dir, char c, long mode_type)
901 {
902 struct membership *mstptr;
903 const char *opnick;
904 struct Client *targ_p;
905
906 if(alevel != CHFL_CHANOP)
907 {
908 if(!(*errors & SM_ERR_NOOPS))
909 sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
910 me.name, source_p->name, chptr->chname);
911 *errors |= SM_ERR_NOOPS;
912 return;
913 }
914
915 if((dir == MODE_QUERY) || parc <= *parn)
916 return;
917
918 opnick = parv[(*parn)];
919 (*parn)++;
920
921 /* empty nick */
922 if(EmptyString(opnick))
923 {
924 sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), "*");
925 return;
926 }
927
928 if((targ_p = find_chasing(source_p, opnick, NULL)) == NULL)
929 {
930 return;
931 }
932
933 mstptr = find_channel_membership(chptr, targ_p);
934
935 if(mstptr == NULL)
936 {
937 if(!(*errors & SM_ERR_NOTONCHANNEL) && MyClient(source_p))
938 sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL,
939 form_str(ERR_USERNOTINCHANNEL), opnick, chptr->chname);
940 *errors |= SM_ERR_NOTONCHANNEL;
941 return;
942 }
943
944 if(MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
945 return;
946
947 if(dir == MODE_ADD)
948 {
949 mode_changes[mode_count].letter = c;
950 mode_changes[mode_count].dir = MODE_ADD;
951 mode_changes[mode_count].caps = 0;
952 mode_changes[mode_count].nocaps = 0;
953 mode_changes[mode_count].mems = ALL_MEMBERS;
954 mode_changes[mode_count].id = targ_p->id;
955 mode_changes[mode_count].arg = targ_p->name;
956 mode_changes[mode_count++].client = targ_p;
957
958 mstptr->flags |= CHFL_VOICE;
959 }
960 else
961 {
962 mode_changes[mode_count].letter = 'v';
963 mode_changes[mode_count].dir = MODE_DEL;
964 mode_changes[mode_count].caps = 0;
965 mode_changes[mode_count].nocaps = 0;
966 mode_changes[mode_count].mems = ALL_MEMBERS;
967 mode_changes[mode_count].id = targ_p->id;
968 mode_changes[mode_count].arg = targ_p->name;
969 mode_changes[mode_count++].client = targ_p;
970
971 mstptr->flags &= ~CHFL_VOICE;
972 }
973 }
974
975 void
976 chm_limit(struct Client *source_p, struct Channel *chptr,
977 int alevel, int parc, int *parn,
978 const char **parv, int *errors, int dir, char c, long mode_type)
979 {
980 const char *lstr;
981 static char limitstr[30];
982 int limit;
983
984 if(alevel != CHFL_CHANOP)
985 {
986 if(!(*errors & SM_ERR_NOOPS))
987 sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
988 me.name, source_p->name, chptr->chname);
989 *errors |= SM_ERR_NOOPS;
990 return;
991 }
992
993 if(dir == MODE_QUERY)
994 return;
995
996 if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE))
997 return;
998
999 if((dir == MODE_ADD) && parc > *parn)
1000 {
1001 lstr = parv[(*parn)];
1002 (*parn)++;
1003
1004 if(EmptyString(lstr) || (limit = atoi(lstr)) <= 0)
1005 return;
1006
1007 rb_sprintf(limitstr, "%d", limit);
1008
1009 mode_changes[mode_count].letter = c;
1010 mode_changes[mode_count].dir = MODE_ADD;
1011 mode_changes[mode_count].caps = 0;
1012 mode_changes[mode_count].nocaps = 0;
1013 mode_changes[mode_count].mems = ALL_MEMBERS;
1014 mode_changes[mode_count].id = NULL;
1015 mode_changes[mode_count++].arg = limitstr;
1016
1017 chptr->mode.limit = limit;
1018 }
1019 else if(dir == MODE_DEL)
1020 {
1021 if(!chptr->mode.limit)
1022 return;
1023
1024 chptr->mode.limit = 0;
1025
1026 mode_changes[mode_count].letter = c;
1027 mode_changes[mode_count].dir = MODE_DEL;
1028 mode_changes[mode_count].caps = 0;
1029 mode_changes[mode_count].nocaps = 0;
1030 mode_changes[mode_count].mems = ALL_MEMBERS;
1031 mode_changes[mode_count].id = NULL;
1032 mode_changes[mode_count++].arg = NULL;
1033 }
1034 }
1035
1036 void
1037 chm_throttle(struct Client *source_p, struct Channel *chptr,
1038 int alevel, int parc, int *parn,
1039 const char **parv, int *errors, int dir, char c, long mode_type)
1040 {
1041 int joins = 0, timeslice = 0;
1042
1043 if(alevel != CHFL_CHANOP)
1044 {
1045 if(!(*errors & SM_ERR_NOOPS))
1046 sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
1047 me.name, source_p->name, chptr->chname);
1048 *errors |= SM_ERR_NOOPS;
1049 return;
1050 }
1051
1052 if(dir == MODE_QUERY)
1053 return;
1054
1055 if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE))
1056 return;
1057
1058 if((dir == MODE_ADD) && parc > *parn)
1059 {
1060 sscanf(parv[(*parn)], "%d:%d", &joins, &timeslice);
1061
1062 if(!joins || !timeslice)
1063 return;
1064
1065 mode_changes[mode_count].letter = c;
1066 mode_changes[mode_count].dir = MODE_ADD;
1067 mode_changes[mode_count].caps = 0;
1068 mode_changes[mode_count].nocaps = 0;
1069 mode_changes[mode_count].mems = ALL_MEMBERS;
1070 mode_changes[mode_count].id = NULL;
1071 mode_changes[mode_count++].arg = parv[(*parn)];
1072
1073 (*parn)++;
1074
1075 chptr->mode.join_num = joins;
1076 chptr->mode.join_time = timeslice;
1077 }
1078 else if(dir == MODE_DEL)
1079 {
1080 if(!chptr->mode.join_num)
1081 return;
1082
1083 chptr->mode.join_num = 0;
1084 chptr->mode.join_time = 0;
1085 chptr->join_count = 0;
1086 chptr->join_delta = 0;
1087
1088 mode_changes[mode_count].letter = c;
1089 mode_changes[mode_count].dir = MODE_DEL;
1090 mode_changes[mode_count].caps = 0;
1091 mode_changes[mode_count].nocaps = 0;
1092 mode_changes[mode_count].mems = ALL_MEMBERS;
1093 mode_changes[mode_count].id = NULL;
1094 mode_changes[mode_count++].arg = NULL;
1095 }
1096 }
1097
1098 void
1099 chm_forward(struct Client *source_p, struct Channel *chptr,
1100 int alevel, int parc, int *parn,
1101 const char **parv, int *errors, int dir, char c, long mode_type)
1102 {
1103 struct Channel *targptr = NULL;
1104 struct membership *msptr;
1105 const char *forward;
1106
1107 if(dir == MODE_QUERY || (dir == MODE_ADD && parc <= *parn))
1108 {
1109 if (!(*errors & SM_ERR_RPL_F))
1110 {
1111 if (*chptr->mode.forward == '\0')
1112 sendto_one_notice(source_p, ":%s has no forward channel", chptr->chname);
1113 else
1114 sendto_one_notice(source_p, ":%s forward channel is %s", chptr->chname, chptr->mode.forward);
1115 *errors |= SM_ERR_RPL_F;
1116 }
1117 return;
1118 }
1119
1120 #ifndef FORWARD_OPERONLY
1121 if(alevel != CHFL_CHANOP)
1122 {
1123 if(!(*errors & SM_ERR_NOOPS))
1124 sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
1125 me.name, source_p->name, chptr->chname);
1126 *errors |= SM_ERR_NOOPS;
1127 return;
1128 }
1129 #else
1130 if(!IsOper(source_p) && !IsServer(source_p))
1131 {
1132 if(!(*errors & SM_ERR_NOPRIVS))
1133 sendto_one_numeric(source_p, ERR_NOPRIVILEGES, form_str(ERR_NOPRIVILEGES));
1134 *errors |= SM_ERR_NOPRIVS;
1135 return;
1136 }
1137 #endif
1138
1139 if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE))
1140 return;
1141
1142 if(dir == MODE_ADD && parc > *parn)
1143 {
1144 forward = parv[(*parn)];
1145 (*parn)++;
1146
1147 if(EmptyString(forward))
1148 return;
1149 if(!check_channel_name(forward) ||
1150 (MyClient(source_p) && (strlen(forward) > LOC_CHANNELLEN || hash_find_resv(forward))))
1151 {
1152 sendto_one_numeric(source_p, ERR_BADCHANNAME, form_str(ERR_BADCHANNAME), forward);
1153 return;
1154 }
1155 /* don't forward to inconsistent target -- jilles */
1156 if(chptr->chname[0] == '#' && forward[0] == '&')
1157 {
1158 sendto_one_numeric(source_p, ERR_BADCHANNAME,
1159 form_str(ERR_BADCHANNAME), forward);
1160 return;
1161 }
1162 if(MyClient(source_p) && (targptr = find_channel(forward)) == NULL)
1163 {
1164 sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
1165 form_str(ERR_NOSUCHCHANNEL), forward);
1166 return;
1167 }
1168 if(MyClient(source_p) && !(targptr->mode.mode & MODE_FREETARGET))
1169 {
1170 if((msptr = find_channel_membership(targptr, source_p)) == NULL ||
1171 get_channel_access(source_p, msptr) != CHFL_CHANOP)
1172 {
1173 sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
1174 me.name, source_p->name, targptr->chname);
1175 return;
1176 }
1177 }
1178
1179 rb_strlcpy(chptr->mode.forward, forward, sizeof(chptr->mode.forward));
1180
1181 mode_changes[mode_count].letter = c;
1182 mode_changes[mode_count].dir = MODE_ADD;
1183 mode_changes[mode_count].caps = 0;
1184 mode_changes[mode_count].nocaps = 0;
1185 mode_changes[mode_count].mems = ALL_MEMBERS;
1186 mode_changes[mode_count].id = NULL;
1187 mode_changes[mode_count++].arg = forward;
1188 }
1189 else if(dir == MODE_DEL)
1190 {
1191 if(!(*chptr->mode.forward))
1192 return;
1193
1194 *chptr->mode.forward = '\0';
1195
1196 mode_changes[mode_count].letter = c;
1197 mode_changes[mode_count].dir = MODE_DEL;
1198 mode_changes[mode_count].caps = 0;
1199 mode_changes[mode_count].nocaps = 0;
1200 mode_changes[mode_count].mems = ALL_MEMBERS;
1201 mode_changes[mode_count].id = NULL;
1202 mode_changes[mode_count++].arg = NULL;
1203 }
1204 }
1205
1206 void
1207 chm_key(struct Client *source_p, struct Channel *chptr,
1208 int alevel, int parc, int *parn,
1209 const char **parv, int *errors, int dir, char c, long mode_type)
1210 {
1211 char *key;
1212
1213 if(alevel != CHFL_CHANOP)
1214 {
1215 if(!(*errors & SM_ERR_NOOPS))
1216 sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
1217 me.name, source_p->name, chptr->chname);
1218 *errors |= SM_ERR_NOOPS;
1219 return;
1220 }
1221
1222 if(dir == MODE_QUERY)
1223 return;
1224
1225 if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE))
1226 return;
1227
1228 if((dir == MODE_ADD) && parc > *parn)
1229 {
1230 key = LOCAL_COPY(parv[(*parn)]);
1231 (*parn)++;
1232
1233 if(MyClient(source_p))
1234 fix_key(key);
1235 else
1236 fix_key_remote(key);
1237
1238 if(EmptyString(key))
1239 return;
1240
1241 s_assert(key[0] != ' ');
1242 rb_strlcpy(chptr->mode.key, key, sizeof(chptr->mode.key));
1243
1244 mode_changes[mode_count].letter = c;
1245 mode_changes[mode_count].dir = MODE_ADD;
1246 mode_changes[mode_count].caps = 0;
1247 mode_changes[mode_count].nocaps = 0;
1248 mode_changes[mode_count].mems = ALL_MEMBERS;
1249 mode_changes[mode_count].id = NULL;
1250 mode_changes[mode_count++].arg = chptr->mode.key;
1251 }
1252 else if(dir == MODE_DEL)
1253 {
1254 static char splat[] = "*";
1255 int i;
1256
1257 if(parc > *parn)
1258 (*parn)++;
1259
1260 if(!(*chptr->mode.key))
1261 return;
1262
1263 /* hack time. when we get a +k-k mode, the +k arg is
1264 * chptr->mode.key, which the -k sets to \0, so hunt for a
1265 * +k when we get a -k, and set the arg to splat. --anfl
1266 */
1267 for(i = 0; i < mode_count; i++)
1268 {
1269 if(mode_changes[i].letter == 'k' && mode_changes[i].dir == MODE_ADD)
1270 mode_changes[i].arg = splat;
1271 }
1272
1273 *chptr->mode.key = 0;
1274
1275 mode_changes[mode_count].letter = c;
1276 mode_changes[mode_count].dir = MODE_DEL;
1277 mode_changes[mode_count].caps = 0;
1278 mode_changes[mode_count].nocaps = 0;
1279 mode_changes[mode_count].mems = ALL_MEMBERS;
1280 mode_changes[mode_count].id = NULL;
1281 mode_changes[mode_count++].arg = "*";
1282 }
1283 }
1284
1285 /* *INDENT-OFF* */
1286 struct ChannelMode chmode_table[256] =
1287 {
1288 {chm_nosuch, 0 }, /* 0x00 */
1289 {chm_nosuch, 0 }, /* 0x01 */
1290 {chm_nosuch, 0 }, /* 0x02 */
1291 {chm_nosuch, 0 }, /* 0x03 */
1292 {chm_nosuch, 0 }, /* 0x04 */
1293 {chm_nosuch, 0 }, /* 0x05 */
1294 {chm_nosuch, 0 }, /* 0x06 */
1295 {chm_nosuch, 0 }, /* 0x07 */
1296 {chm_nosuch, 0 }, /* 0x08 */
1297 {chm_nosuch, 0 }, /* 0x09 */
1298 {chm_nosuch, 0 }, /* 0x0a */
1299 {chm_nosuch, 0 }, /* 0x0b */
1300 {chm_nosuch, 0 }, /* 0x0c */
1301 {chm_nosuch, 0 }, /* 0x0d */
1302 {chm_nosuch, 0 }, /* 0x0e */
1303 {chm_nosuch, 0 }, /* 0x0f */
1304 {chm_nosuch, 0 }, /* 0x10 */
1305 {chm_nosuch, 0 }, /* 0x11 */
1306 {chm_nosuch, 0 }, /* 0x12 */
1307 {chm_nosuch, 0 }, /* 0x13 */
1308 {chm_nosuch, 0 }, /* 0x14 */
1309 {chm_nosuch, 0 }, /* 0x15 */
1310 {chm_nosuch, 0 }, /* 0x16 */
1311 {chm_nosuch, 0 }, /* 0x17 */
1312 {chm_nosuch, 0 }, /* 0x18 */
1313 {chm_nosuch, 0 }, /* 0x19 */
1314 {chm_nosuch, 0 }, /* 0x1a */
1315 {chm_nosuch, 0 }, /* 0x1b */
1316 {chm_nosuch, 0 }, /* 0x1c */
1317 {chm_nosuch, 0 }, /* 0x1d */
1318 {chm_nosuch, 0 }, /* 0x1e */
1319 {chm_nosuch, 0 }, /* 0x1f */
1320 {chm_nosuch, 0 }, /* 0x20 */
1321 {chm_nosuch, 0 }, /* 0x21 */
1322 {chm_nosuch, 0 }, /* 0x22 */
1323 {chm_nosuch, 0 }, /* 0x23 */
1324 {chm_nosuch, 0 }, /* 0x24 */
1325 {chm_nosuch, 0 }, /* 0x25 */
1326 {chm_nosuch, 0 }, /* 0x26 */
1327 {chm_nosuch, 0 }, /* 0x27 */
1328 {chm_nosuch, 0 }, /* 0x28 */
1329 {chm_nosuch, 0 }, /* 0x29 */
1330 {chm_nosuch, 0 }, /* 0x2a */
1331 {chm_nosuch, 0 }, /* 0x2b */
1332 {chm_nosuch, 0 }, /* 0x2c */
1333 {chm_nosuch, 0 }, /* 0x2d */
1334 {chm_nosuch, 0 }, /* 0x2e */
1335 {chm_nosuch, 0 }, /* 0x2f */
1336 {chm_nosuch, 0 }, /* 0x30 */
1337 {chm_nosuch, 0 }, /* 0x31 */
1338 {chm_nosuch, 0 }, /* 0x32 */
1339 {chm_nosuch, 0 }, /* 0x33 */
1340 {chm_nosuch, 0 }, /* 0x34 */
1341 {chm_nosuch, 0 }, /* 0x35 */
1342 {chm_nosuch, 0 }, /* 0x36 */
1343 {chm_nosuch, 0 }, /* 0x37 */
1344 {chm_nosuch, 0 }, /* 0x38 */
1345 {chm_nosuch, 0 }, /* 0x39 */
1346 {chm_nosuch, 0 }, /* 0x3a */
1347 {chm_nosuch, 0 }, /* 0x3b */
1348 {chm_nosuch, 0 }, /* 0x3c */
1349 {chm_nosuch, 0 }, /* 0x3d */
1350 {chm_nosuch, 0 }, /* 0x3e */
1351 {chm_nosuch, 0 }, /* 0x3f */
1352
1353 {chm_nosuch, 0 }, /* @ */
1354 {chm_nosuch, 0 }, /* A */
1355 {chm_nosuch, 0 }, /* B */
1356 {chm_simple, MODE_NOCTCP }, /* C */
1357 {chm_nosuch, 0 }, /* D */
1358 {chm_nosuch, 0 }, /* E */
1359 {chm_simple, MODE_FREETARGET }, /* F */
1360 {chm_nosuch, 0 }, /* G */
1361 {chm_nosuch, 0 }, /* H */
1362 {chm_ban, CHFL_INVEX }, /* I */
1363 {chm_nosuch, 0 }, /* J */
1364 {chm_nosuch, 0 }, /* K */
1365 {chm_staff, MODE_EXLIMIT }, /* L */
1366 {chm_nosuch, 0 }, /* M */
1367 {chm_nosuch, 0 }, /* N */
1368 {chm_nosuch, 0 }, /* O */
1369 {chm_staff, MODE_PERMANENT }, /* P */
1370 {chm_simple, MODE_DISFORWARD }, /* Q */
1371 {chm_nosuch, 0 }, /* R */
1372 {chm_nosuch, 0 }, /* S */
1373 {chm_nosuch, 0 }, /* T */
1374 {chm_nosuch, 0 }, /* U */
1375 {chm_nosuch, 0 }, /* V */
1376 {chm_nosuch, 0 }, /* W */
1377 {chm_nosuch, 0 }, /* X */
1378 {chm_nosuch, 0 }, /* Y */
1379 {chm_nosuch, 0 }, /* Z */
1380 {chm_nosuch, 0 },
1381 {chm_nosuch, 0 },
1382 {chm_nosuch, 0 },
1383 {chm_nosuch, 0 },
1384 {chm_nosuch, 0 },
1385 {chm_nosuch, 0 },
1386 {chm_nosuch, 0 }, /* a */
1387 {chm_ban, CHFL_BAN }, /* b */
1388 {chm_simple, MODE_NOCOLOR }, /* c */
1389 {chm_nosuch, 0 }, /* d */
1390 {chm_ban, CHFL_EXCEPTION }, /* e */
1391 {chm_forward, 0 }, /* f */
1392 {chm_simple, MODE_FREEINVITE }, /* g */
1393 {chm_nosuch, 0 }, /* h */
1394 {chm_simple, MODE_INVITEONLY }, /* i */
1395 {chm_throttle, 0 }, /* j */
1396 {chm_key, 0 }, /* k */
1397 {chm_limit, 0 }, /* l */
1398 {chm_simple, MODE_MODERATED }, /* m */
1399 {chm_simple, MODE_NOPRIVMSGS }, /* n */
1400 {chm_op, 0 }, /* o */
1401 {chm_simple, MODE_PRIVATE }, /* p */
1402 {chm_ban, CHFL_QUIET }, /* q */
1403 {chm_simple, MODE_REGONLY }, /* r */
1404 {chm_simple, MODE_SECRET }, /* s */
1405 {chm_simple, MODE_TOPICLIMIT }, /* t */
1406 {chm_nosuch, 0 }, /* u */
1407 {chm_voice, 0 }, /* v */
1408 {chm_nosuch, 0 }, /* w */
1409 {chm_nosuch, 0 }, /* x */
1410 {chm_nosuch, 0 }, /* y */
1411 {chm_simple, MODE_OPMODERATE }, /* z */
1412
1413 {chm_nosuch, 0 }, /* 0x7b */
1414 {chm_nosuch, 0 }, /* 0x7c */
1415 {chm_nosuch, 0 }, /* 0x7d */
1416 {chm_nosuch, 0 }, /* 0x7e */
1417 {chm_nosuch, 0 }, /* 0x7f */
1418
1419 {chm_nosuch, 0 }, /* 0x80 */
1420 {chm_nosuch, 0 }, /* 0x81 */
1421 {chm_nosuch, 0 }, /* 0x82 */
1422 {chm_nosuch, 0 }, /* 0x83 */
1423 {chm_nosuch, 0 }, /* 0x84 */
1424 {chm_nosuch, 0 }, /* 0x85 */
1425 {chm_nosuch, 0 }, /* 0x86 */
1426 {chm_nosuch, 0 }, /* 0x87 */
1427 {chm_nosuch, 0 }, /* 0x88 */
1428 {chm_nosuch, 0 }, /* 0x89 */
1429 {chm_nosuch, 0 }, /* 0x8a */
1430 {chm_nosuch, 0 }, /* 0x8b */
1431 {chm_nosuch, 0 }, /* 0x8c */
1432 {chm_nosuch, 0 }, /* 0x8d */
1433 {chm_nosuch, 0 }, /* 0x8e */
1434 {chm_nosuch, 0 }, /* 0x8f */
1435
1436 {chm_nosuch, 0 }, /* 0x90 */
1437 {chm_nosuch, 0 }, /* 0x91 */
1438 {chm_nosuch, 0 }, /* 0x92 */
1439 {chm_nosuch, 0 }, /* 0x93 */
1440 {chm_nosuch, 0 }, /* 0x94 */
1441 {chm_nosuch, 0 }, /* 0x95 */
1442 {chm_nosuch, 0 }, /* 0x96 */
1443 {chm_nosuch, 0 }, /* 0x97 */
1444 {chm_nosuch, 0 }, /* 0x98 */
1445 {chm_nosuch, 0 }, /* 0x99 */
1446 {chm_nosuch, 0 }, /* 0x9a */
1447 {chm_nosuch, 0 }, /* 0x9b */
1448 {chm_nosuch, 0 }, /* 0x9c */
1449 {chm_nosuch, 0 }, /* 0x9d */
1450 {chm_nosuch, 0 }, /* 0x9e */
1451 {chm_nosuch, 0 }, /* 0x9f */
1452
1453 {chm_nosuch, 0 }, /* 0xa0 */
1454 {chm_nosuch, 0 }, /* 0xa1 */
1455 {chm_nosuch, 0 }, /* 0xa2 */
1456 {chm_nosuch, 0 }, /* 0xa3 */
1457 {chm_nosuch, 0 }, /* 0xa4 */
1458 {chm_nosuch, 0 }, /* 0xa5 */
1459 {chm_nosuch, 0 }, /* 0xa6 */
1460 {chm_nosuch, 0 }, /* 0xa7 */
1461 {chm_nosuch, 0 }, /* 0xa8 */
1462 {chm_nosuch, 0 }, /* 0xa9 */
1463 {chm_nosuch, 0 }, /* 0xaa */
1464 {chm_nosuch, 0 }, /* 0xab */
1465 {chm_nosuch, 0 }, /* 0xac */
1466 {chm_nosuch, 0 }, /* 0xad */
1467 {chm_nosuch, 0 }, /* 0xae */
1468 {chm_nosuch, 0 }, /* 0xaf */
1469
1470 {chm_nosuch, 0 }, /* 0xb0 */
1471 {chm_nosuch, 0 }, /* 0xb1 */
1472 {chm_nosuch, 0 }, /* 0xb2 */
1473 {chm_nosuch, 0 }, /* 0xb3 */
1474 {chm_nosuch, 0 }, /* 0xb4 */
1475 {chm_nosuch, 0 }, /* 0xb5 */
1476 {chm_nosuch, 0 }, /* 0xb6 */
1477 {chm_nosuch, 0 }, /* 0xb7 */
1478 {chm_nosuch, 0 }, /* 0xb8 */
1479 {chm_nosuch, 0 }, /* 0xb9 */
1480 {chm_nosuch, 0 }, /* 0xba */
1481 {chm_nosuch, 0 }, /* 0xbb */
1482 {chm_nosuch, 0 }, /* 0xbc */
1483 {chm_nosuch, 0 }, /* 0xbd */
1484 {chm_nosuch, 0 }, /* 0xbe */
1485 {chm_nosuch, 0 }, /* 0xbf */
1486
1487 {chm_nosuch, 0 }, /* 0xc0 */
1488 {chm_nosuch, 0 }, /* 0xc1 */
1489 {chm_nosuch, 0 }, /* 0xc2 */
1490 {chm_nosuch, 0 }, /* 0xc3 */
1491 {chm_nosuch, 0 }, /* 0xc4 */
1492 {chm_nosuch, 0 }, /* 0xc5 */
1493 {chm_nosuch, 0 }, /* 0xc6 */
1494 {chm_nosuch, 0 }, /* 0xc7 */
1495 {chm_nosuch, 0 }, /* 0xc8 */
1496 {chm_nosuch, 0 }, /* 0xc9 */
1497 {chm_nosuch, 0 }, /* 0xca */
1498 {chm_nosuch, 0 }, /* 0xcb */
1499 {chm_nosuch, 0 }, /* 0xcc */
1500 {chm_nosuch, 0 }, /* 0xcd */
1501 {chm_nosuch, 0 }, /* 0xce */
1502 {chm_nosuch, 0 }, /* 0xcf */
1503
1504 {chm_nosuch, 0 }, /* 0xd0 */
1505 {chm_nosuch, 0 }, /* 0xd1 */
1506 {chm_nosuch, 0 }, /* 0xd2 */
1507 {chm_nosuch, 0 }, /* 0xd3 */
1508 {chm_nosuch, 0 }, /* 0xd4 */
1509 {chm_nosuch, 0 }, /* 0xd5 */
1510 {chm_nosuch, 0 }, /* 0xd6 */
1511 {chm_nosuch, 0 }, /* 0xd7 */
1512 {chm_nosuch, 0 }, /* 0xd8 */
1513 {chm_nosuch, 0 }, /* 0xd9 */
1514 {chm_nosuch, 0 }, /* 0xda */
1515 {chm_nosuch, 0 }, /* 0xdb */
1516 {chm_nosuch, 0 }, /* 0xdc */
1517 {chm_nosuch, 0 }, /* 0xdd */
1518 {chm_nosuch, 0 }, /* 0xde */
1519 {chm_nosuch, 0 }, /* 0xdf */
1520
1521 {chm_nosuch, 0 }, /* 0xe0 */
1522 {chm_nosuch, 0 }, /* 0xe1 */
1523 {chm_nosuch, 0 }, /* 0xe2 */
1524 {chm_nosuch, 0 }, /* 0xe3 */
1525 {chm_nosuch, 0 }, /* 0xe4 */
1526 {chm_nosuch, 0 }, /* 0xe5 */
1527 {chm_nosuch, 0 }, /* 0xe6 */
1528 {chm_nosuch, 0 }, /* 0xe7 */
1529 {chm_nosuch, 0 }, /* 0xe8 */
1530 {chm_nosuch, 0 }, /* 0xe9 */
1531 {chm_nosuch, 0 }, /* 0xea */
1532 {chm_nosuch, 0 }, /* 0xeb */
1533 {chm_nosuch, 0 }, /* 0xec */
1534 {chm_nosuch, 0 }, /* 0xed */
1535 {chm_nosuch, 0 }, /* 0xee */
1536 {chm_nosuch, 0 }, /* 0xef */
1537
1538 {chm_nosuch, 0 }, /* 0xf0 */
1539 {chm_nosuch, 0 }, /* 0xf1 */
1540 {chm_nosuch, 0 }, /* 0xf2 */
1541 {chm_nosuch, 0 }, /* 0xf3 */
1542 {chm_nosuch, 0 }, /* 0xf4 */
1543 {chm_nosuch, 0 }, /* 0xf5 */
1544 {chm_nosuch, 0 }, /* 0xf6 */
1545 {chm_nosuch, 0 }, /* 0xf7 */
1546 {chm_nosuch, 0 }, /* 0xf8 */
1547 {chm_nosuch, 0 }, /* 0xf9 */
1548 {chm_nosuch, 0 }, /* 0xfa */
1549 {chm_nosuch, 0 }, /* 0xfb */
1550 {chm_nosuch, 0 }, /* 0xfc */
1551 {chm_nosuch, 0 }, /* 0xfd */
1552 {chm_nosuch, 0 }, /* 0xfe */
1553 {chm_nosuch, 0 }, /* 0xff */
1554 };
1555
1556 /* *INDENT-ON* */
1557
1558 /* set_channel_mode()
1559 *
1560 * inputs - client, source, channel, membership pointer, params
1561 * output -
1562 * side effects - channel modes/memberships are changed, MODE is issued
1563 *
1564 * Extensively modified to be hotpluggable, 03/09/06 -- nenolod
1565 */
1566 void
1567 set_channel_mode(struct Client *client_p, struct Client *source_p,
1568 struct Channel *chptr, struct membership *msptr, int parc, const char *parv[])
1569 {
1570 static char modebuf[BUFSIZE];
1571 static char parabuf[BUFSIZE];
1572 char *mbuf;
1573 char *pbuf;
1574 int cur_len, mlen, paralen, paracount, arglen, len;
1575 int i, j, flags;
1576 int dir = MODE_ADD;
1577 int parn = 1;
1578 int errors = 0;
1579 int alevel;
1580 const char *ml = parv[0];
1581 char c;
1582 struct Client *fakesource_p;
1583
1584 mask_pos = 0;
1585 removed_mask_pos = 0;
1586 mode_count = 0;
1587 mode_limit = 0;
1588 mode_limit_simple = 0;
1589
1590 alevel = get_channel_access(source_p, msptr);
1591
1592 /* Hide connecting server on netburst -- jilles */
1593 if (ConfigServerHide.flatten_links && IsServer(source_p) && !has_id(source_p) && !HasSentEob(source_p))
1594 fakesource_p = &me;
1595 else
1596 fakesource_p = source_p;
1597
1598 for(; (c = *ml) != 0; ml++)
1599 {
1600 switch (c)
1601 {
1602 case '+':
1603 dir = MODE_ADD;
1604 break;
1605 case '-':
1606 dir = MODE_DEL;
1607 break;
1608 case '=':
1609 dir = MODE_QUERY;
1610 break;
1611 default:
1612 /* If this mode char is locked, don't allow local users to change it. */
1613 if (MyClient(source_p) && chptr->mode_lock && strchr(chptr->mode_lock, c))
1614 {
1615 if (!(errors & SM_ERR_MLOCK))
1616 sendto_one_numeric(source_p,
1617 ERR_MLOCKRESTRICTED,
1618 form_str(ERR_MLOCKRESTRICTED),
1619 chptr->chname,
1620 c,
1621 chptr->mode_lock);
1622 errors |= SM_ERR_MLOCK;
1623 continue;
1624 }
1625 chmode_table[(unsigned char) c].set_func(fakesource_p, chptr, alevel,
1626 parc, &parn, parv,
1627 &errors, dir, c,
1628 chmode_table[(unsigned char) c].mode_type);
1629 break;
1630 }
1631 }
1632
1633 /* bail out if we have nothing to do... */
1634 if(!mode_count)
1635 return;
1636
1637 if(IsServer(source_p))
1638 mlen = rb_sprintf(modebuf, ":%s MODE %s ", fakesource_p->name, chptr->chname);
1639 else
1640 mlen = rb_sprintf(modebuf, ":%s!%s@%s MODE %s ",
1641 source_p->name, source_p->username,
1642 source_p->host, chptr->chname);
1643
1644 for(j = 0, flags = ALL_MEMBERS; j < 2; j++, flags = ONLY_CHANOPS)
1645 {
1646 cur_len = mlen;
1647 mbuf = modebuf + mlen;
1648 pbuf = parabuf;
1649 parabuf[0] = '\0';
1650 paracount = paralen = 0;
1651 dir = MODE_QUERY;
1652
1653 for(i = 0; i < mode_count; i++)
1654 {
1655 if(mode_changes[i].letter == 0 || mode_changes[i].mems != flags)
1656 continue;
1657
1658 if(mode_changes[i].arg != NULL)
1659 {
1660 arglen = strlen(mode_changes[i].arg);
1661
1662 if(arglen > MODEBUFLEN - 5)
1663 continue;
1664 }
1665 else
1666 arglen = 0;
1667
1668 /* if we're creeping over MAXMODEPARAMSSERV, or over
1669 * bufsize (4 == +/-,modechar,two spaces) send now.
1670 */
1671 if(mode_changes[i].arg != NULL &&
1672 ((paracount == MAXMODEPARAMSSERV) ||
1673 ((cur_len + paralen + arglen + 4) > (BUFSIZE - 3))))
1674 {
1675 *mbuf = '\0';
1676
1677 if(cur_len > mlen)
1678 sendto_channel_local(flags, chptr, "%s %s", modebuf,
1679 parabuf);
1680 else
1681 continue;
1682
1683 paracount = paralen = 0;
1684 cur_len = mlen;
1685 mbuf = modebuf + mlen;
1686 pbuf = parabuf;
1687 parabuf[0] = '\0';
1688 dir = MODE_QUERY;
1689 }
1690
1691 if(dir != mode_changes[i].dir)
1692 {
1693 *mbuf++ = (mode_changes[i].dir == MODE_ADD) ? '+' : '-';
1694 cur_len++;
1695 dir = mode_changes[i].dir;
1696 }
1697
1698 *mbuf++ = mode_changes[i].letter;
1699 cur_len++;
1700
1701 if(mode_changes[i].arg != NULL)
1702 {
1703 paracount++;
1704 len = rb_sprintf(pbuf, "%s ", mode_changes[i].arg);
1705 pbuf += len;
1706 paralen += len;
1707 }
1708 }
1709
1710 if(paralen && parabuf[paralen - 1] == ' ')
1711 parabuf[paralen - 1] = '\0';
1712
1713 *mbuf = '\0';
1714 if(cur_len > mlen)
1715 sendto_channel_local(flags, chptr, "%s %s", modebuf, parabuf);
1716 }
1717
1718 /* only propagate modes originating locally, or if we're hubbing */
1719 if(MyClient(source_p) || rb_dlink_list_length(&serv_list) > 1)
1720 send_cap_mode_changes(client_p, source_p, chptr, mode_changes, mode_count);
1721 }
1722
1723 /* set_channel_mlock()
1724 *
1725 * inputs - client, source, channel, params
1726 * output -
1727 * side effects - channel mlock is changed / MLOCK is propagated
1728 */
1729 void
1730 set_channel_mlock(struct Client *client_p, struct Client *source_p,
1731 struct Channel *chptr, const char *newmlock, int propagate)
1732 {
1733 rb_free(chptr->mode_lock);
1734 chptr->mode_lock = newmlock ? rb_strdup(newmlock) : NULL;
1735
1736 if (propagate)
1737 {
1738 sendto_server(client_p, NULL, CAP_TS6 | CAP_MLOCK, NOCAPS, ":%s MLOCK %ld %s :%s",
1739 source_p->id, (long) chptr->channelts, chptr->chname,
1740 chptr->mode_lock ? chptr->mode_lock : "");
1741 }
1742 }