2 * charybdis: A slightly useful ircd.
3 * chmode.c: channel mode management
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
8 * Copyright (C) 2005-2006 charybdis development team
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
25 * $Id: chmode.c 3580 2007-11-07 23:45:14Z jilles $
37 #include "s_serv.h" /* captab */
41 #include "s_conf.h" /* ConfigFileEntry, ConfigChannel */
42 #include "s_newconf.h"
46 /* bitmasks for error returns, so we send once per call */
47 #define SM_ERR_NOTS 0x00000001 /* No TS on channel */
48 #define SM_ERR_NOOPS 0x00000002 /* No chan ops */
49 #define SM_ERR_UNKNOWN 0x00000004
50 #define SM_ERR_RPL_C 0x00000008
51 #define SM_ERR_RPL_B 0x00000010
52 #define SM_ERR_RPL_E 0x00000020
53 #define SM_ERR_NOTONCHANNEL 0x00000040 /* Not on channel */
54 #define SM_ERR_RPL_I 0x00000100
55 #define SM_ERR_RPL_D 0x00000200
56 #define SM_ERR_NOPRIVS 0x00000400
57 #define SM_ERR_RPL_Q 0x00000800
58 #define SM_ERR_RPL_F 0x00001000
59 #define SM_ERR_MLOCK 0x00002000
61 #define MAXMODES_SIMPLE 46 /* a-zA-Z except bqeIov */
63 static struct ChModeChange mode_changes
[BUFSIZE
];
64 static int mode_count
;
65 static int mode_limit
;
66 static int mode_limit_simple
;
68 static int removed_mask_pos
;
71 char cflagsmyinfo
[256];
73 int chmode_flags
[256];
75 extern int h_get_channel_access
;
77 /* OPTIMIZE ME! -- dwr */
79 construct_cflags_strings(void)
82 char *ptr
= cflagsbuf
;
83 char *ptr2
= cflagsmyinfo
;
88 for(i
= 0; i
< 256; i
++)
90 if( !(chmode_table
[i
].set_func
== chm_ban
) &&
91 !(chmode_table
[i
].set_func
== chm_forward
) &&
92 !(chmode_table
[i
].set_func
== chm_throttle
) &&
93 !(chmode_table
[i
].set_func
== chm_key
) &&
94 !(chmode_table
[i
].set_func
== chm_limit
) &&
95 !(chmode_table
[i
].set_func
== chm_op
) &&
96 !(chmode_table
[i
].set_func
== chm_voice
))
98 chmode_flags
[i
] = chmode_table
[i
].mode_type
;
105 switch (chmode_flags
[i
])
108 case MODE_DISFORWARD
:
109 /* TODO FIXME: make use_forward work again */
112 if(rb_dlink_list_length(&service_list
))
119 if(chmode_flags
[i
] != 0)
125 /* Should we leave orphaned check here? -- dwr */
126 if(!(chmode_table
[i
].set_func
== chm_nosuch
) && !(chmode_table
[i
].set_func
== chm_orphaned
))
140 * outputs - an available cflag bitmask or
141 * 0 if no cflags are available
142 * side effects - NONE
145 find_cflag_slot(void)
147 unsigned int all_cflags
= 0, my_cflag
= 0, i
;
149 for (i
= 0; i
< 256; i
++)
150 all_cflags
|= chmode_flags
[i
];
152 for (my_cflag
= 1; my_cflag
&& (all_cflags
& my_cflag
);
159 cflag_add(char c_
, ChannelModeFunc function
)
161 int c
= (unsigned char)c_
;
163 if (chmode_table
[c
].set_func
!= chm_nosuch
&&
164 chmode_table
[c
].set_func
!= chm_orphaned
)
167 if (chmode_table
[c
].set_func
== chm_nosuch
)
168 chmode_table
[c
].mode_type
= find_cflag_slot();
169 if (chmode_table
[c
].mode_type
== 0)
171 chmode_table
[c
].set_func
= function
;
172 construct_cflags_strings();
173 return chmode_table
[c
].mode_type
;
177 cflag_orphan(char c_
)
179 int c
= (unsigned char)c_
;
181 s_assert(chmode_flags
[c
] != 0);
182 chmode_table
[c
].set_func
= chm_orphaned
;
183 construct_cflags_strings();
187 get_channel_access(struct Client
*source_p
, struct membership
*msptr
)
189 hook_data_channel_approval moduledata
;
191 if(!MyClient(source_p
))
197 moduledata
.client
= source_p
;
198 moduledata
.chptr
= msptr
->chptr
;
199 moduledata
.msptr
= msptr
;
200 moduledata
.target
= NULL
;
201 moduledata
.approved
= is_chanop(msptr
) ? CHFL_CHANOP
: CHFL_PEON
;
203 call_hook(h_get_channel_access
, &moduledata
);
205 return moduledata
.approved
;
210 * inputs - client, channel, id to add, type, forward
211 * outputs - 0 on failure, 1 on success
212 * side effects - given id is added to the appropriate list
215 add_id(struct Client
*source_p
, struct Channel
*chptr
, const char *banid
, const char *forward
,
216 rb_dlink_list
* list
, long mode_type
)
218 struct Ban
*actualBan
;
219 static char who
[USERHOST_REPLYLEN
];
220 char *realban
= LOCAL_COPY(banid
);
223 /* dont let local clients overflow the banlist, or set redundant
226 if(MyClient(source_p
))
228 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
))
230 sendto_one(source_p
, form_str(ERR_BANLISTFULL
),
231 me
.name
, source_p
->name
, chptr
->chname
, realban
);
235 RB_DLINK_FOREACH(ptr
, list
->head
)
237 actualBan
= ptr
->data
;
238 if(mask_match(actualBan
->banstr
, realban
))
242 /* dont let remotes set duplicates */
245 RB_DLINK_FOREACH(ptr
, list
->head
)
247 actualBan
= ptr
->data
;
248 if(!irccmp(actualBan
->banstr
, realban
))
254 if(IsPerson(source_p
))
255 rb_sprintf(who
, "%s!%s@%s", source_p
->name
, source_p
->username
, source_p
->host
);
257 rb_strlcpy(who
, source_p
->name
, sizeof(who
));
259 actualBan
= allocate_ban(realban
, who
, forward
);
260 actualBan
->when
= rb_current_time();
262 rb_dlinkAdd(actualBan
, &actualBan
->node
, list
);
264 /* invalidate the can_send() cache */
265 if(mode_type
== CHFL_BAN
|| mode_type
== CHFL_QUIET
|| mode_type
== CHFL_EXCEPTION
)
273 * inputs - channel, id to remove, type
274 * outputs - pointer to ban that was removed, if any
275 * side effects - given id is removed from the appropriate list and returned
278 del_id(struct Channel
*chptr
, const char *banid
, rb_dlink_list
* list
, long mode_type
)
283 if(EmptyString(banid
))
286 RB_DLINK_FOREACH(ptr
, list
->head
)
290 if(irccmp(banid
, banptr
->banstr
) == 0)
292 rb_dlinkDelete(&banptr
->node
, list
);
295 /* invalidate the can_send() cache */
296 if(mode_type
== CHFL_BAN
|| mode_type
== CHFL_QUIET
|| mode_type
== CHFL_EXCEPTION
)
308 * input - string to check
309 * output - pointer to 'fixed' string, or "*" if empty
310 * side effects - any white space found becomes \0
313 check_string(char *s
)
316 static char splat
[] = "*";
333 * inputs - mask to pretty
334 * outputs - better version of the mask
335 * side effects - mask is chopped to limits, and transformed:
343 pretty_mask(const char *idmask
)
345 static char mask_buf
[BUFSIZE
];
347 char *nick
, *user
, *host
, *forward
= NULL
;
349 char *t
, *at
, *ex
, *ex2
;
350 char ne
= 0, ue
= 0, he
= 0, fe
= 0; /* save values at nick[NICKLEN], et all */
351 char e2
= 0; /* save value that delimits forward channel */
354 mask
= LOCAL_COPY(idmask
);
355 mask
= check_string(mask
);
358 nick
= user
= host
= splat
;
360 if((size_t) BUFSIZE
- mask_pos
< strlen(mask
) + 5)
363 old_mask_pos
= mask_pos
;
367 mask_pos
+= rb_sprintf(mask_buf
+ mask_pos
, "%s", mask
) + 1;
368 t
= mask_buf
+ old_mask_pos
+ 1;
374 return mask_buf
+ old_mask_pos
;
377 at
= ex
= ex2
= NULL
;
378 if((t
= strchr(mask
, '@')) != NULL
)
385 if((t
= strchr(mask
, '!')) != NULL
)
400 if((t
= strchr(host
, '!')) != NULL
|| (t
= strchr(host
, '$')) != NULL
)
409 else if((t
= strchr(mask
, '!')) != NULL
)
418 else if(strchr(mask
, '.') != NULL
|| strchr(mask
, ':') != NULL
)
429 /* truncate values to max lengths */
430 if(strlen(nick
) > NICKLEN
- 1)
432 ne
= nick
[NICKLEN
- 1];
433 nick
[NICKLEN
- 1] = '\0';
435 if(strlen(user
) > USERLEN
)
438 user
[USERLEN
] = '\0';
440 if(strlen(host
) > HOSTLEN
)
443 host
[HOSTLEN
] = '\0';
445 if(forward
&& strlen(forward
) > CHANNELLEN
)
447 fe
= forward
[CHANNELLEN
];
448 forward
[CHANNELLEN
] = '\0';
452 mask_pos
+= rb_sprintf(mask_buf
+ mask_pos
, "%s!%s@%s$%s", nick
, user
, host
, forward
) + 1;
454 mask_pos
+= rb_sprintf(mask_buf
+ mask_pos
, "%s!%s@%s", nick
, user
, host
) + 1;
456 /* restore mask, since we may need to use it again later */
464 nick
[NICKLEN
- 1] = ne
;
470 forward
[CHANNELLEN
] = fe
;
472 return mask_buf
+ old_mask_pos
;
478 * output - the same key, fixed
479 * side effects - anything below ascii 13 is discarded, ':' discarded,
480 * high ascii is dropped to lower half of ascii table
487 for(s
= t
= (u_char
*) arg
; (c
= *s
); s
++)
490 if(c
!= ':' && c
!= ',' && c
> ' ')
501 * ouput - the same key, fixed
502 * side effects - high ascii dropped to lower half of table,
503 * CR/LF/':' are dropped
506 fix_key_remote(char *arg
)
510 for(s
= t
= (u_char
*) arg
; (c
= *s
); s
++)
513 if((c
!= 0x0a) && (c
!= ':') && (c
!= ',') && (c
!= 0x0d) && (c
!= ' '))
523 * The handlers for each specific mode.
526 chm_nosuch(struct Client
*source_p
, struct Channel
*chptr
,
527 int alevel
, int parc
, int *parn
,
528 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
530 if(*errors
& SM_ERR_UNKNOWN
)
532 *errors
|= SM_ERR_UNKNOWN
;
533 sendto_one(source_p
, form_str(ERR_UNKNOWNMODE
), me
.name
, source_p
->name
, c
);
537 chm_simple(struct Client
*source_p
, struct Channel
*chptr
,
538 int alevel
, int parc
, int *parn
,
539 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
541 if(alevel
!= CHFL_CHANOP
)
543 if(!(*errors
& SM_ERR_NOOPS
))
544 sendto_one(source_p
, form_str(ERR_CHANOPRIVSNEEDED
),
545 me
.name
, source_p
->name
, chptr
->chname
);
546 *errors
|= SM_ERR_NOOPS
;
550 if(MyClient(source_p
) && (++mode_limit_simple
> MAXMODES_SIMPLE
))
554 if((dir
== MODE_ADD
) && !(chptr
->mode
.mode
& mode_type
))
556 chptr
->mode
.mode
|= mode_type
;
558 mode_changes
[mode_count
].letter
= c
;
559 mode_changes
[mode_count
].dir
= MODE_ADD
;
560 mode_changes
[mode_count
].caps
= 0;
561 mode_changes
[mode_count
].nocaps
= 0;
562 mode_changes
[mode_count
].id
= NULL
;
563 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
564 mode_changes
[mode_count
++].arg
= NULL
;
566 else if((dir
== MODE_DEL
) && (chptr
->mode
.mode
& mode_type
))
568 chptr
->mode
.mode
&= ~mode_type
;
570 mode_changes
[mode_count
].letter
= c
;
571 mode_changes
[mode_count
].dir
= MODE_DEL
;
572 mode_changes
[mode_count
].caps
= 0;
573 mode_changes
[mode_count
].nocaps
= 0;
574 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
575 mode_changes
[mode_count
].id
= NULL
;
576 mode_changes
[mode_count
++].arg
= NULL
;
581 chm_orphaned(struct Client
*source_p
, struct Channel
*chptr
,
582 int alevel
, int parc
, int *parn
,
583 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
585 if(MyClient(source_p
))
588 if((dir
== MODE_ADD
) && !(chptr
->mode
.mode
& mode_type
))
590 chptr
->mode
.mode
|= mode_type
;
592 mode_changes
[mode_count
].letter
= c
;
593 mode_changes
[mode_count
].dir
= MODE_ADD
;
594 mode_changes
[mode_count
].caps
= 0;
595 mode_changes
[mode_count
].nocaps
= 0;
596 mode_changes
[mode_count
].id
= NULL
;
597 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
598 mode_changes
[mode_count
++].arg
= NULL
;
600 else if((dir
== MODE_DEL
) && (chptr
->mode
.mode
& mode_type
))
602 chptr
->mode
.mode
&= ~mode_type
;
604 mode_changes
[mode_count
].letter
= c
;
605 mode_changes
[mode_count
].dir
= MODE_DEL
;
606 mode_changes
[mode_count
].caps
= 0;
607 mode_changes
[mode_count
].nocaps
= 0;
608 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
609 mode_changes
[mode_count
].id
= NULL
;
610 mode_changes
[mode_count
++].arg
= NULL
;
615 chm_staff(struct Client
*source_p
, struct Channel
*chptr
,
616 int alevel
, int parc
, int *parn
,
617 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
619 if(!IsOper(source_p
) && !IsServer(source_p
))
621 if(!(*errors
& SM_ERR_NOPRIVS
))
622 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
, form_str(ERR_NOPRIVILEGES
));
623 *errors
|= SM_ERR_NOPRIVS
;
626 if(MyClient(source_p
) && !IsOperResv(source_p
))
628 if(!(*errors
& SM_ERR_NOPRIVS
))
629 sendto_one(source_p
, form_str(ERR_NOPRIVS
), me
.name
,
630 source_p
->name
, "resv");
631 *errors
|= SM_ERR_NOPRIVS
;
635 if(MyClient(source_p
) && (++mode_limit_simple
> MAXMODES_SIMPLE
))
639 if((dir
== MODE_ADD
) && !(chptr
->mode
.mode
& mode_type
))
641 chptr
->mode
.mode
|= mode_type
;
643 mode_changes
[mode_count
].letter
= c
;
644 mode_changes
[mode_count
].dir
= MODE_ADD
;
645 mode_changes
[mode_count
].caps
= 0;
646 mode_changes
[mode_count
].nocaps
= 0;
647 mode_changes
[mode_count
].id
= NULL
;
648 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
649 mode_changes
[mode_count
++].arg
= NULL
;
651 else if((dir
== MODE_DEL
) && (chptr
->mode
.mode
& mode_type
))
653 chptr
->mode
.mode
&= ~mode_type
;
655 mode_changes
[mode_count
].letter
= c
;
656 mode_changes
[mode_count
].dir
= MODE_DEL
;
657 mode_changes
[mode_count
].caps
= 0;
658 mode_changes
[mode_count
].nocaps
= 0;
659 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
660 mode_changes
[mode_count
].id
= NULL
;
661 mode_changes
[mode_count
++].arg
= NULL
;
666 chm_ban(struct Client
*source_p
, struct Channel
*chptr
,
667 int alevel
, int parc
, int *parn
,
668 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
670 char *mask
, *raw_mask
, *forward
;
683 list
= &chptr
->banlist
;
684 errorval
= SM_ERR_RPL_B
;
685 rpl_list
= RPL_BANLIST
;
686 rpl_endlist
= RPL_ENDOFBANLIST
;
692 /* if +e is disabled, allow all but +e locally */
693 if(!ConfigChannel
.use_except
&& MyClient(source_p
) &&
694 ((dir
== MODE_ADD
) && (parc
> *parn
)))
697 list
= &chptr
->exceptlist
;
698 errorval
= SM_ERR_RPL_E
;
699 rpl_list
= RPL_EXCEPTLIST
;
700 rpl_endlist
= RPL_ENDOFEXCEPTLIST
;
703 if(ConfigChannel
.use_except
|| (dir
== MODE_DEL
))
710 /* if +I is disabled, allow all but +I locally */
711 if(!ConfigChannel
.use_invex
&& MyClient(source_p
) &&
712 (dir
== MODE_ADD
) && (parc
> *parn
))
715 list
= &chptr
->invexlist
;
716 errorval
= SM_ERR_RPL_I
;
717 rpl_list
= RPL_INVITELIST
;
718 rpl_endlist
= RPL_ENDOFINVITELIST
;
721 if(ConfigChannel
.use_invex
|| (dir
== MODE_DEL
))
728 list
= &chptr
->quietlist
;
729 errorval
= SM_ERR_RPL_Q
;
730 rpl_list
= RPL_QUIETLIST
;
731 rpl_endlist
= RPL_ENDOFQUIETLIST
;
737 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "chm_ban() called with unknown type!");
742 if(dir
== 0 || parc
<= *parn
)
744 if((*errors
& errorval
) != 0)
748 /* non-ops cant see +eI lists.. */
749 if(alevel
!= CHFL_CHANOP
&& mode_type
!= CHFL_BAN
&&
750 mode_type
!= CHFL_QUIET
)
752 if(!(*errors
& SM_ERR_NOOPS
))
753 sendto_one(source_p
, form_str(ERR_CHANOPRIVSNEEDED
),
754 me
.name
, source_p
->name
, chptr
->chname
);
755 *errors
|= SM_ERR_NOOPS
;
759 RB_DLINK_FOREACH(ptr
, list
->head
)
764 rb_snprintf(buf
, sizeof(buf
), "%s$%s", banptr
->banstr
, banptr
->forward
);
766 rb_strlcpy(buf
, banptr
->banstr
, sizeof(buf
));
768 sendto_one(source_p
, form_str(rpl_list
),
769 me
.name
, source_p
->name
, chptr
->chname
,
770 buf
, banptr
->who
, banptr
->when
);
772 sendto_one(source_p
, form_str(rpl_endlist
), me
.name
, source_p
->name
, chptr
->chname
);
776 if(alevel
!= CHFL_CHANOP
)
778 if(!(*errors
& SM_ERR_NOOPS
))
779 sendto_one(source_p
, form_str(ERR_CHANOPRIVSNEEDED
),
780 me
.name
, source_p
->name
, chptr
->chname
);
781 *errors
|= SM_ERR_NOOPS
;
785 if(MyClient(source_p
) && (++mode_limit
> MAXMODEPARAMS
))
788 raw_mask
= parv
[(*parn
)];
791 /* empty ban, or starts with ':' which messes up s2s, ignore it */
792 if(EmptyString(raw_mask
) || *raw_mask
== ':')
795 if(!MyClient(source_p
))
797 if(strchr(raw_mask
, ' '))
803 mask
= pretty_mask(raw_mask
);
805 /* Look for a $ after the first character.
806 * As the first character, it marks an extban; afterwards
807 * it delimits a forward channel.
809 if ((forward
= strchr(mask
+1, '$')) != NULL
)
812 if (*forward
== '\0')
816 /* we'd have problems parsing this, hyb6 does it too
817 * also make sure it will always fit on a line with channel
820 if(strlen(mask
) > IRCD_MIN(BANLEN
, MODEBUFLEN
- 5))
823 /* if we're adding a NEW id */
826 if (*mask
== '$' && MyClient(source_p
))
828 if (!valid_extban(mask
, source_p
, chptr
, mode_type
))
829 /* XXX perhaps return an error message here */
833 /* dont allow local clients to overflow the banlist, dont
834 * let remote servers set duplicate bans
836 if(!add_id(source_p
, chptr
, mask
, forward
, list
, mode_type
))
842 mode_changes
[mode_count
].letter
= c
;
843 mode_changes
[mode_count
].dir
= MODE_ADD
;
844 mode_changes
[mode_count
].caps
= caps
;
845 mode_changes
[mode_count
].nocaps
= 0;
846 mode_changes
[mode_count
].mems
= mems
;
847 mode_changes
[mode_count
].id
= NULL
;
848 mode_changes
[mode_count
++].arg
= mask
;
850 else if(dir
== MODE_DEL
)
853 static char buf
[BANLEN
* MAXMODEPARAMS
];
854 int old_removed_mask_pos
= removed_mask_pos
;
855 if((removed
= del_id(chptr
, mask
, list
, mode_type
)) == NULL
)
857 /* mask isn't a valid ban, check raw_mask */
858 if((removed
= del_id(chptr
, raw_mask
, list
, mode_type
)) != NULL
)
862 if(removed
&& removed
->forward
)
863 removed_mask_pos
+= rb_snprintf(buf
, sizeof(buf
), "%s$%s", removed
->banstr
, removed
->forward
);
865 removed_mask_pos
+= rb_strlcpy(buf
, mask
, sizeof(buf
));
872 mode_changes
[mode_count
].letter
= c
;
873 mode_changes
[mode_count
].dir
= MODE_DEL
;
874 mode_changes
[mode_count
].caps
= caps
;
875 mode_changes
[mode_count
].nocaps
= 0;
876 mode_changes
[mode_count
].mems
= mems
;
877 mode_changes
[mode_count
].id
= NULL
;
878 mode_changes
[mode_count
++].arg
= buf
+ old_removed_mask_pos
;
883 chm_op(struct Client
*source_p
, struct Channel
*chptr
,
884 int alevel
, int parc
, int *parn
,
885 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
887 struct membership
*mstptr
;
889 struct Client
*targ_p
;
891 if(alevel
!= CHFL_CHANOP
)
893 if(!(*errors
& SM_ERR_NOOPS
))
894 sendto_one(source_p
, form_str(ERR_CHANOPRIVSNEEDED
),
895 me
.name
, source_p
->name
, chptr
->chname
);
896 *errors
|= SM_ERR_NOOPS
;
900 if((dir
== MODE_QUERY
) || (parc
<= *parn
))
903 opnick
= parv
[(*parn
)];
907 if(EmptyString(opnick
))
909 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
, form_str(ERR_NOSUCHNICK
), "*");
913 if((targ_p
= find_chasing(source_p
, opnick
, NULL
)) == NULL
)
918 mstptr
= find_channel_membership(chptr
, targ_p
);
922 if(!(*errors
& SM_ERR_NOTONCHANNEL
) && MyClient(source_p
))
923 sendto_one_numeric(source_p
, ERR_USERNOTINCHANNEL
,
924 form_str(ERR_USERNOTINCHANNEL
), opnick
, chptr
->chname
);
925 *errors
|= SM_ERR_NOTONCHANNEL
;
929 if(MyClient(source_p
) && (++mode_limit
> MAXMODEPARAMS
))
934 if(targ_p
== source_p
&& mstptr
->flags
& CHFL_CHANOP
)
937 mode_changes
[mode_count
].letter
= c
;
938 mode_changes
[mode_count
].dir
= MODE_ADD
;
939 mode_changes
[mode_count
].caps
= 0;
940 mode_changes
[mode_count
].nocaps
= 0;
941 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
942 mode_changes
[mode_count
].id
= targ_p
->id
;
943 mode_changes
[mode_count
].arg
= targ_p
->name
;
944 mode_changes
[mode_count
++].client
= targ_p
;
946 mstptr
->flags
|= CHFL_CHANOP
;
950 if(MyClient(source_p
) && IsService(targ_p
))
952 sendto_one(source_p
, form_str(ERR_ISCHANSERVICE
),
953 me
.name
, source_p
->name
, targ_p
->name
, chptr
->chname
);
957 mode_changes
[mode_count
].letter
= c
;
958 mode_changes
[mode_count
].dir
= MODE_DEL
;
959 mode_changes
[mode_count
].caps
= 0;
960 mode_changes
[mode_count
].nocaps
= 0;
961 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
962 mode_changes
[mode_count
].id
= targ_p
->id
;
963 mode_changes
[mode_count
].arg
= targ_p
->name
;
964 mode_changes
[mode_count
++].client
= targ_p
;
966 mstptr
->flags
&= ~CHFL_CHANOP
;
971 chm_voice(struct Client
*source_p
, struct Channel
*chptr
,
972 int alevel
, int parc
, int *parn
,
973 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
975 struct membership
*mstptr
;
977 struct Client
*targ_p
;
979 if(alevel
!= CHFL_CHANOP
)
981 if(!(*errors
& SM_ERR_NOOPS
))
982 sendto_one(source_p
, form_str(ERR_CHANOPRIVSNEEDED
),
983 me
.name
, source_p
->name
, chptr
->chname
);
984 *errors
|= SM_ERR_NOOPS
;
988 if((dir
== MODE_QUERY
) || parc
<= *parn
)
991 opnick
= parv
[(*parn
)];
995 if(EmptyString(opnick
))
997 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
, form_str(ERR_NOSUCHNICK
), "*");
1001 if((targ_p
= find_chasing(source_p
, opnick
, NULL
)) == NULL
)
1006 mstptr
= find_channel_membership(chptr
, targ_p
);
1010 if(!(*errors
& SM_ERR_NOTONCHANNEL
) && MyClient(source_p
))
1011 sendto_one_numeric(source_p
, ERR_USERNOTINCHANNEL
,
1012 form_str(ERR_USERNOTINCHANNEL
), opnick
, chptr
->chname
);
1013 *errors
|= SM_ERR_NOTONCHANNEL
;
1017 if(MyClient(source_p
) && (++mode_limit
> MAXMODEPARAMS
))
1022 mode_changes
[mode_count
].letter
= c
;
1023 mode_changes
[mode_count
].dir
= MODE_ADD
;
1024 mode_changes
[mode_count
].caps
= 0;
1025 mode_changes
[mode_count
].nocaps
= 0;
1026 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
1027 mode_changes
[mode_count
].id
= targ_p
->id
;
1028 mode_changes
[mode_count
].arg
= targ_p
->name
;
1029 mode_changes
[mode_count
++].client
= targ_p
;
1031 mstptr
->flags
|= CHFL_VOICE
;
1035 mode_changes
[mode_count
].letter
= 'v';
1036 mode_changes
[mode_count
].dir
= MODE_DEL
;
1037 mode_changes
[mode_count
].caps
= 0;
1038 mode_changes
[mode_count
].nocaps
= 0;
1039 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
1040 mode_changes
[mode_count
].id
= targ_p
->id
;
1041 mode_changes
[mode_count
].arg
= targ_p
->name
;
1042 mode_changes
[mode_count
++].client
= targ_p
;
1044 mstptr
->flags
&= ~CHFL_VOICE
;
1049 chm_limit(struct Client
*source_p
, struct Channel
*chptr
,
1050 int alevel
, int parc
, int *parn
,
1051 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
1054 static char limitstr
[30];
1057 if(alevel
!= CHFL_CHANOP
)
1059 if(!(*errors
& SM_ERR_NOOPS
))
1060 sendto_one(source_p
, form_str(ERR_CHANOPRIVSNEEDED
),
1061 me
.name
, source_p
->name
, chptr
->chname
);
1062 *errors
|= SM_ERR_NOOPS
;
1066 if(dir
== MODE_QUERY
)
1069 if(MyClient(source_p
) && (++mode_limit_simple
> MAXMODES_SIMPLE
))
1072 if((dir
== MODE_ADD
) && parc
> *parn
)
1074 lstr
= parv
[(*parn
)];
1077 if(EmptyString(lstr
) || (limit
= atoi(lstr
)) <= 0)
1080 rb_sprintf(limitstr
, "%d", limit
);
1082 mode_changes
[mode_count
].letter
= c
;
1083 mode_changes
[mode_count
].dir
= MODE_ADD
;
1084 mode_changes
[mode_count
].caps
= 0;
1085 mode_changes
[mode_count
].nocaps
= 0;
1086 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
1087 mode_changes
[mode_count
].id
= NULL
;
1088 mode_changes
[mode_count
++].arg
= limitstr
;
1090 chptr
->mode
.limit
= limit
;
1092 else if(dir
== MODE_DEL
)
1094 if(!chptr
->mode
.limit
)
1097 chptr
->mode
.limit
= 0;
1099 mode_changes
[mode_count
].letter
= c
;
1100 mode_changes
[mode_count
].dir
= MODE_DEL
;
1101 mode_changes
[mode_count
].caps
= 0;
1102 mode_changes
[mode_count
].nocaps
= 0;
1103 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
1104 mode_changes
[mode_count
].id
= NULL
;
1105 mode_changes
[mode_count
++].arg
= NULL
;
1110 chm_throttle(struct Client
*source_p
, struct Channel
*chptr
,
1111 int alevel
, int parc
, int *parn
,
1112 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
1114 int joins
= 0, timeslice
= 0;
1116 if(alevel
!= CHFL_CHANOP
)
1118 if(!(*errors
& SM_ERR_NOOPS
))
1119 sendto_one(source_p
, form_str(ERR_CHANOPRIVSNEEDED
),
1120 me
.name
, source_p
->name
, chptr
->chname
);
1121 *errors
|= SM_ERR_NOOPS
;
1125 if(dir
== MODE_QUERY
)
1128 if(MyClient(source_p
) && (++mode_limit_simple
> MAXMODES_SIMPLE
))
1131 if((dir
== MODE_ADD
) && parc
> *parn
)
1133 sscanf(parv
[(*parn
)], "%d:%d", &joins
, ×lice
);
1135 if(!joins
|| !timeslice
)
1138 mode_changes
[mode_count
].letter
= c
;
1139 mode_changes
[mode_count
].dir
= MODE_ADD
;
1140 mode_changes
[mode_count
].caps
= 0;
1141 mode_changes
[mode_count
].nocaps
= 0;
1142 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
1143 mode_changes
[mode_count
].id
= NULL
;
1144 mode_changes
[mode_count
++].arg
= parv
[(*parn
)];
1148 chptr
->mode
.join_num
= joins
;
1149 chptr
->mode
.join_time
= timeslice
;
1151 else if(dir
== MODE_DEL
)
1153 if(!chptr
->mode
.join_num
)
1156 chptr
->mode
.join_num
= 0;
1157 chptr
->mode
.join_time
= 0;
1158 chptr
->join_count
= 0;
1159 chptr
->join_delta
= 0;
1161 mode_changes
[mode_count
].letter
= c
;
1162 mode_changes
[mode_count
].dir
= MODE_DEL
;
1163 mode_changes
[mode_count
].caps
= 0;
1164 mode_changes
[mode_count
].nocaps
= 0;
1165 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
1166 mode_changes
[mode_count
].id
= NULL
;
1167 mode_changes
[mode_count
++].arg
= NULL
;
1172 chm_forward(struct Client
*source_p
, struct Channel
*chptr
,
1173 int alevel
, int parc
, int *parn
,
1174 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
1176 struct Channel
*targptr
= NULL
;
1177 struct membership
*msptr
;
1178 const char *forward
;
1180 if(dir
== MODE_QUERY
|| (dir
== MODE_ADD
&& parc
<= *parn
))
1182 if (!(*errors
& SM_ERR_RPL_F
))
1184 if (*chptr
->mode
.forward
== '\0')
1185 sendto_one_notice(source_p
, ":%s has no forward channel", chptr
->chname
);
1187 sendto_one_notice(source_p
, ":%s forward channel is %s", chptr
->chname
, chptr
->mode
.forward
);
1188 *errors
|= SM_ERR_RPL_F
;
1193 #ifndef FORWARD_OPERONLY
1194 if(alevel
!= CHFL_CHANOP
)
1196 if(!(*errors
& SM_ERR_NOOPS
))
1197 sendto_one(source_p
, form_str(ERR_CHANOPRIVSNEEDED
),
1198 me
.name
, source_p
->name
, chptr
->chname
);
1199 *errors
|= SM_ERR_NOOPS
;
1203 if(!IsOper(source_p
) && !IsServer(source_p
))
1205 if(!(*errors
& SM_ERR_NOPRIVS
))
1206 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
, form_str(ERR_NOPRIVILEGES
));
1207 *errors
|= SM_ERR_NOPRIVS
;
1212 if(MyClient(source_p
) && (++mode_limit_simple
> MAXMODES_SIMPLE
))
1215 if(dir
== MODE_ADD
&& parc
> *parn
)
1217 forward
= parv
[(*parn
)];
1220 if(EmptyString(forward
))
1222 if(!check_channel_name(forward
) ||
1223 (MyClient(source_p
) && (strlen(forward
) > LOC_CHANNELLEN
|| hash_find_resv(forward
))))
1225 sendto_one_numeric(source_p
, ERR_BADCHANNAME
, form_str(ERR_BADCHANNAME
), forward
);
1228 /* don't forward to inconsistent target -- jilles */
1229 if(chptr
->chname
[0] == '#' && forward
[0] == '&')
1231 sendto_one_numeric(source_p
, ERR_BADCHANNAME
,
1232 form_str(ERR_BADCHANNAME
), forward
);
1235 if(MyClient(source_p
) && (targptr
= find_channel(forward
)) == NULL
)
1237 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
1238 form_str(ERR_NOSUCHCHANNEL
), forward
);
1241 if(MyClient(source_p
) && !(targptr
->mode
.mode
& MODE_FREETARGET
))
1243 if((msptr
= find_channel_membership(targptr
, source_p
)) == NULL
||
1244 get_channel_access(source_p
, msptr
) != CHFL_CHANOP
)
1246 sendto_one(source_p
, form_str(ERR_CHANOPRIVSNEEDED
),
1247 me
.name
, source_p
->name
, targptr
->chname
);
1252 rb_strlcpy(chptr
->mode
.forward
, forward
, sizeof(chptr
->mode
.forward
));
1254 mode_changes
[mode_count
].letter
= c
;
1255 mode_changes
[mode_count
].dir
= MODE_ADD
;
1256 mode_changes
[mode_count
].caps
= 0;
1257 mode_changes
[mode_count
].nocaps
= 0;
1258 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
1259 mode_changes
[mode_count
].id
= NULL
;
1260 mode_changes
[mode_count
++].arg
= forward
;
1262 else if(dir
== MODE_DEL
)
1264 if(!(*chptr
->mode
.forward
))
1267 *chptr
->mode
.forward
= '\0';
1269 mode_changes
[mode_count
].letter
= c
;
1270 mode_changes
[mode_count
].dir
= MODE_DEL
;
1271 mode_changes
[mode_count
].caps
= 0;
1272 mode_changes
[mode_count
].nocaps
= 0;
1273 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
1274 mode_changes
[mode_count
].id
= NULL
;
1275 mode_changes
[mode_count
++].arg
= NULL
;
1280 chm_key(struct Client
*source_p
, struct Channel
*chptr
,
1281 int alevel
, int parc
, int *parn
,
1282 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
1286 if(alevel
!= CHFL_CHANOP
)
1288 if(!(*errors
& SM_ERR_NOOPS
))
1289 sendto_one(source_p
, form_str(ERR_CHANOPRIVSNEEDED
),
1290 me
.name
, source_p
->name
, chptr
->chname
);
1291 *errors
|= SM_ERR_NOOPS
;
1295 if(dir
== MODE_QUERY
)
1298 if(MyClient(source_p
) && (++mode_limit_simple
> MAXMODES_SIMPLE
))
1301 if((dir
== MODE_ADD
) && parc
> *parn
)
1303 key
= LOCAL_COPY(parv
[(*parn
)]);
1306 if(MyClient(source_p
))
1309 fix_key_remote(key
);
1311 if(EmptyString(key
))
1314 s_assert(key
[0] != ' ');
1315 rb_strlcpy(chptr
->mode
.key
, key
, sizeof(chptr
->mode
.key
));
1317 mode_changes
[mode_count
].letter
= c
;
1318 mode_changes
[mode_count
].dir
= MODE_ADD
;
1319 mode_changes
[mode_count
].caps
= 0;
1320 mode_changes
[mode_count
].nocaps
= 0;
1321 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
1322 mode_changes
[mode_count
].id
= NULL
;
1323 mode_changes
[mode_count
++].arg
= chptr
->mode
.key
;
1325 else if(dir
== MODE_DEL
)
1327 static char splat
[] = "*";
1333 if(!(*chptr
->mode
.key
))
1336 /* hack time. when we get a +k-k mode, the +k arg is
1337 * chptr->mode.key, which the -k sets to \0, so hunt for a
1338 * +k when we get a -k, and set the arg to splat. --anfl
1340 for(i
= 0; i
< mode_count
; i
++)
1342 if(mode_changes
[i
].letter
== 'k' && mode_changes
[i
].dir
== MODE_ADD
)
1343 mode_changes
[i
].arg
= splat
;
1346 *chptr
->mode
.key
= 0;
1348 mode_changes
[mode_count
].letter
= c
;
1349 mode_changes
[mode_count
].dir
= MODE_DEL
;
1350 mode_changes
[mode_count
].caps
= 0;
1351 mode_changes
[mode_count
].nocaps
= 0;
1352 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
1353 mode_changes
[mode_count
].id
= NULL
;
1354 mode_changes
[mode_count
++].arg
= "*";
1359 struct ChannelMode chmode_table
[256] =
1361 {chm_nosuch
, 0 }, /* 0x00 */
1362 {chm_nosuch
, 0 }, /* 0x01 */
1363 {chm_nosuch
, 0 }, /* 0x02 */
1364 {chm_nosuch
, 0 }, /* 0x03 */
1365 {chm_nosuch
, 0 }, /* 0x04 */
1366 {chm_nosuch
, 0 }, /* 0x05 */
1367 {chm_nosuch
, 0 }, /* 0x06 */
1368 {chm_nosuch
, 0 }, /* 0x07 */
1369 {chm_nosuch
, 0 }, /* 0x08 */
1370 {chm_nosuch
, 0 }, /* 0x09 */
1371 {chm_nosuch
, 0 }, /* 0x0a */
1372 {chm_nosuch
, 0 }, /* 0x0b */
1373 {chm_nosuch
, 0 }, /* 0x0c */
1374 {chm_nosuch
, 0 }, /* 0x0d */
1375 {chm_nosuch
, 0 }, /* 0x0e */
1376 {chm_nosuch
, 0 }, /* 0x0f */
1377 {chm_nosuch
, 0 }, /* 0x10 */
1378 {chm_nosuch
, 0 }, /* 0x11 */
1379 {chm_nosuch
, 0 }, /* 0x12 */
1380 {chm_nosuch
, 0 }, /* 0x13 */
1381 {chm_nosuch
, 0 }, /* 0x14 */
1382 {chm_nosuch
, 0 }, /* 0x15 */
1383 {chm_nosuch
, 0 }, /* 0x16 */
1384 {chm_nosuch
, 0 }, /* 0x17 */
1385 {chm_nosuch
, 0 }, /* 0x18 */
1386 {chm_nosuch
, 0 }, /* 0x19 */
1387 {chm_nosuch
, 0 }, /* 0x1a */
1388 {chm_nosuch
, 0 }, /* 0x1b */
1389 {chm_nosuch
, 0 }, /* 0x1c */
1390 {chm_nosuch
, 0 }, /* 0x1d */
1391 {chm_nosuch
, 0 }, /* 0x1e */
1392 {chm_nosuch
, 0 }, /* 0x1f */
1393 {chm_nosuch
, 0 }, /* 0x20 */
1394 {chm_nosuch
, 0 }, /* 0x21 */
1395 {chm_nosuch
, 0 }, /* 0x22 */
1396 {chm_nosuch
, 0 }, /* 0x23 */
1397 {chm_nosuch
, 0 }, /* 0x24 */
1398 {chm_nosuch
, 0 }, /* 0x25 */
1399 {chm_nosuch
, 0 }, /* 0x26 */
1400 {chm_nosuch
, 0 }, /* 0x27 */
1401 {chm_nosuch
, 0 }, /* 0x28 */
1402 {chm_nosuch
, 0 }, /* 0x29 */
1403 {chm_nosuch
, 0 }, /* 0x2a */
1404 {chm_nosuch
, 0 }, /* 0x2b */
1405 {chm_nosuch
, 0 }, /* 0x2c */
1406 {chm_nosuch
, 0 }, /* 0x2d */
1407 {chm_nosuch
, 0 }, /* 0x2e */
1408 {chm_nosuch
, 0 }, /* 0x2f */
1409 {chm_nosuch
, 0 }, /* 0x30 */
1410 {chm_nosuch
, 0 }, /* 0x31 */
1411 {chm_nosuch
, 0 }, /* 0x32 */
1412 {chm_nosuch
, 0 }, /* 0x33 */
1413 {chm_nosuch
, 0 }, /* 0x34 */
1414 {chm_nosuch
, 0 }, /* 0x35 */
1415 {chm_nosuch
, 0 }, /* 0x36 */
1416 {chm_nosuch
, 0 }, /* 0x37 */
1417 {chm_nosuch
, 0 }, /* 0x38 */
1418 {chm_nosuch
, 0 }, /* 0x39 */
1419 {chm_nosuch
, 0 }, /* 0x3a */
1420 {chm_nosuch
, 0 }, /* 0x3b */
1421 {chm_nosuch
, 0 }, /* 0x3c */
1422 {chm_nosuch
, 0 }, /* 0x3d */
1423 {chm_nosuch
, 0 }, /* 0x3e */
1424 {chm_nosuch
, 0 }, /* 0x3f */
1426 {chm_nosuch
, 0 }, /* @ */
1427 {chm_nosuch
, 0 }, /* A */
1428 {chm_nosuch
, 0 }, /* B */
1429 {chm_simple
, MODE_NOCTCP
}, /* C */
1430 {chm_nosuch
, 0 }, /* D */
1431 {chm_nosuch
, 0 }, /* E */
1432 {chm_simple
, MODE_FREETARGET
}, /* F */
1433 {chm_nosuch
, 0 }, /* G */
1434 {chm_nosuch
, 0 }, /* H */
1435 {chm_ban
, CHFL_INVEX
}, /* I */
1436 {chm_nosuch
, 0 }, /* J */
1437 {chm_nosuch
, 0 }, /* K */
1438 {chm_staff
, MODE_EXLIMIT
}, /* L */
1439 {chm_nosuch
, 0 }, /* M */
1440 {chm_nosuch
, 0 }, /* N */
1441 {chm_nosuch
, 0 }, /* O */
1442 {chm_staff
, MODE_PERMANENT
}, /* P */
1443 {chm_simple
, MODE_DISFORWARD
}, /* Q */
1444 {chm_nosuch
, 0 }, /* R */
1445 {chm_nosuch
, 0 }, /* S */
1446 {chm_nosuch
, 0 }, /* T */
1447 {chm_nosuch
, 0 }, /* U */
1448 {chm_nosuch
, 0 }, /* V */
1449 {chm_nosuch
, 0 }, /* W */
1450 {chm_nosuch
, 0 }, /* X */
1451 {chm_nosuch
, 0 }, /* Y */
1452 {chm_nosuch
, 0 }, /* Z */
1459 {chm_nosuch
, 0 }, /* a */
1460 {chm_ban
, CHFL_BAN
}, /* b */
1461 {chm_simple
, MODE_NOCOLOR
}, /* c */
1462 {chm_nosuch
, 0 }, /* d */
1463 {chm_ban
, CHFL_EXCEPTION
}, /* e */
1464 {chm_forward
, 0 }, /* f */
1465 {chm_simple
, MODE_FREEINVITE
}, /* g */
1466 {chm_nosuch
, 0 }, /* h */
1467 {chm_simple
, MODE_INVITEONLY
}, /* i */
1468 {chm_throttle
, 0 }, /* j */
1469 {chm_key
, 0 }, /* k */
1470 {chm_limit
, 0 }, /* l */
1471 {chm_simple
, MODE_MODERATED
}, /* m */
1472 {chm_simple
, MODE_NOPRIVMSGS
}, /* n */
1473 {chm_op
, 0 }, /* o */
1474 {chm_simple
, MODE_PRIVATE
}, /* p */
1475 {chm_ban
, CHFL_QUIET
}, /* q */
1476 {chm_simple
, MODE_REGONLY
}, /* r */
1477 {chm_simple
, MODE_SECRET
}, /* s */
1478 {chm_simple
, MODE_TOPICLIMIT
}, /* t */
1479 {chm_nosuch
, 0 }, /* u */
1480 {chm_voice
, 0 }, /* v */
1481 {chm_nosuch
, 0 }, /* w */
1482 {chm_nosuch
, 0 }, /* x */
1483 {chm_nosuch
, 0 }, /* y */
1484 {chm_simple
, MODE_OPMODERATE
}, /* z */
1486 {chm_nosuch
, 0 }, /* 0x7b */
1487 {chm_nosuch
, 0 }, /* 0x7c */
1488 {chm_nosuch
, 0 }, /* 0x7d */
1489 {chm_nosuch
, 0 }, /* 0x7e */
1490 {chm_nosuch
, 0 }, /* 0x7f */
1492 {chm_nosuch
, 0 }, /* 0x80 */
1493 {chm_nosuch
, 0 }, /* 0x81 */
1494 {chm_nosuch
, 0 }, /* 0x82 */
1495 {chm_nosuch
, 0 }, /* 0x83 */
1496 {chm_nosuch
, 0 }, /* 0x84 */
1497 {chm_nosuch
, 0 }, /* 0x85 */
1498 {chm_nosuch
, 0 }, /* 0x86 */
1499 {chm_nosuch
, 0 }, /* 0x87 */
1500 {chm_nosuch
, 0 }, /* 0x88 */
1501 {chm_nosuch
, 0 }, /* 0x89 */
1502 {chm_nosuch
, 0 }, /* 0x8a */
1503 {chm_nosuch
, 0 }, /* 0x8b */
1504 {chm_nosuch
, 0 }, /* 0x8c */
1505 {chm_nosuch
, 0 }, /* 0x8d */
1506 {chm_nosuch
, 0 }, /* 0x8e */
1507 {chm_nosuch
, 0 }, /* 0x8f */
1509 {chm_nosuch
, 0 }, /* 0x90 */
1510 {chm_nosuch
, 0 }, /* 0x91 */
1511 {chm_nosuch
, 0 }, /* 0x92 */
1512 {chm_nosuch
, 0 }, /* 0x93 */
1513 {chm_nosuch
, 0 }, /* 0x94 */
1514 {chm_nosuch
, 0 }, /* 0x95 */
1515 {chm_nosuch
, 0 }, /* 0x96 */
1516 {chm_nosuch
, 0 }, /* 0x97 */
1517 {chm_nosuch
, 0 }, /* 0x98 */
1518 {chm_nosuch
, 0 }, /* 0x99 */
1519 {chm_nosuch
, 0 }, /* 0x9a */
1520 {chm_nosuch
, 0 }, /* 0x9b */
1521 {chm_nosuch
, 0 }, /* 0x9c */
1522 {chm_nosuch
, 0 }, /* 0x9d */
1523 {chm_nosuch
, 0 }, /* 0x9e */
1524 {chm_nosuch
, 0 }, /* 0x9f */
1526 {chm_nosuch
, 0 }, /* 0xa0 */
1527 {chm_nosuch
, 0 }, /* 0xa1 */
1528 {chm_nosuch
, 0 }, /* 0xa2 */
1529 {chm_nosuch
, 0 }, /* 0xa3 */
1530 {chm_nosuch
, 0 }, /* 0xa4 */
1531 {chm_nosuch
, 0 }, /* 0xa5 */
1532 {chm_nosuch
, 0 }, /* 0xa6 */
1533 {chm_nosuch
, 0 }, /* 0xa7 */
1534 {chm_nosuch
, 0 }, /* 0xa8 */
1535 {chm_nosuch
, 0 }, /* 0xa9 */
1536 {chm_nosuch
, 0 }, /* 0xaa */
1537 {chm_nosuch
, 0 }, /* 0xab */
1538 {chm_nosuch
, 0 }, /* 0xac */
1539 {chm_nosuch
, 0 }, /* 0xad */
1540 {chm_nosuch
, 0 }, /* 0xae */
1541 {chm_nosuch
, 0 }, /* 0xaf */
1543 {chm_nosuch
, 0 }, /* 0xb0 */
1544 {chm_nosuch
, 0 }, /* 0xb1 */
1545 {chm_nosuch
, 0 }, /* 0xb2 */
1546 {chm_nosuch
, 0 }, /* 0xb3 */
1547 {chm_nosuch
, 0 }, /* 0xb4 */
1548 {chm_nosuch
, 0 }, /* 0xb5 */
1549 {chm_nosuch
, 0 }, /* 0xb6 */
1550 {chm_nosuch
, 0 }, /* 0xb7 */
1551 {chm_nosuch
, 0 }, /* 0xb8 */
1552 {chm_nosuch
, 0 }, /* 0xb9 */
1553 {chm_nosuch
, 0 }, /* 0xba */
1554 {chm_nosuch
, 0 }, /* 0xbb */
1555 {chm_nosuch
, 0 }, /* 0xbc */
1556 {chm_nosuch
, 0 }, /* 0xbd */
1557 {chm_nosuch
, 0 }, /* 0xbe */
1558 {chm_nosuch
, 0 }, /* 0xbf */
1560 {chm_nosuch
, 0 }, /* 0xc0 */
1561 {chm_nosuch
, 0 }, /* 0xc1 */
1562 {chm_nosuch
, 0 }, /* 0xc2 */
1563 {chm_nosuch
, 0 }, /* 0xc3 */
1564 {chm_nosuch
, 0 }, /* 0xc4 */
1565 {chm_nosuch
, 0 }, /* 0xc5 */
1566 {chm_nosuch
, 0 }, /* 0xc6 */
1567 {chm_nosuch
, 0 }, /* 0xc7 */
1568 {chm_nosuch
, 0 }, /* 0xc8 */
1569 {chm_nosuch
, 0 }, /* 0xc9 */
1570 {chm_nosuch
, 0 }, /* 0xca */
1571 {chm_nosuch
, 0 }, /* 0xcb */
1572 {chm_nosuch
, 0 }, /* 0xcc */
1573 {chm_nosuch
, 0 }, /* 0xcd */
1574 {chm_nosuch
, 0 }, /* 0xce */
1575 {chm_nosuch
, 0 }, /* 0xcf */
1577 {chm_nosuch
, 0 }, /* 0xd0 */
1578 {chm_nosuch
, 0 }, /* 0xd1 */
1579 {chm_nosuch
, 0 }, /* 0xd2 */
1580 {chm_nosuch
, 0 }, /* 0xd3 */
1581 {chm_nosuch
, 0 }, /* 0xd4 */
1582 {chm_nosuch
, 0 }, /* 0xd5 */
1583 {chm_nosuch
, 0 }, /* 0xd6 */
1584 {chm_nosuch
, 0 }, /* 0xd7 */
1585 {chm_nosuch
, 0 }, /* 0xd8 */
1586 {chm_nosuch
, 0 }, /* 0xd9 */
1587 {chm_nosuch
, 0 }, /* 0xda */
1588 {chm_nosuch
, 0 }, /* 0xdb */
1589 {chm_nosuch
, 0 }, /* 0xdc */
1590 {chm_nosuch
, 0 }, /* 0xdd */
1591 {chm_nosuch
, 0 }, /* 0xde */
1592 {chm_nosuch
, 0 }, /* 0xdf */
1594 {chm_nosuch
, 0 }, /* 0xe0 */
1595 {chm_nosuch
, 0 }, /* 0xe1 */
1596 {chm_nosuch
, 0 }, /* 0xe2 */
1597 {chm_nosuch
, 0 }, /* 0xe3 */
1598 {chm_nosuch
, 0 }, /* 0xe4 */
1599 {chm_nosuch
, 0 }, /* 0xe5 */
1600 {chm_nosuch
, 0 }, /* 0xe6 */
1601 {chm_nosuch
, 0 }, /* 0xe7 */
1602 {chm_nosuch
, 0 }, /* 0xe8 */
1603 {chm_nosuch
, 0 }, /* 0xe9 */
1604 {chm_nosuch
, 0 }, /* 0xea */
1605 {chm_nosuch
, 0 }, /* 0xeb */
1606 {chm_nosuch
, 0 }, /* 0xec */
1607 {chm_nosuch
, 0 }, /* 0xed */
1608 {chm_nosuch
, 0 }, /* 0xee */
1609 {chm_nosuch
, 0 }, /* 0xef */
1611 {chm_nosuch
, 0 }, /* 0xf0 */
1612 {chm_nosuch
, 0 }, /* 0xf1 */
1613 {chm_nosuch
, 0 }, /* 0xf2 */
1614 {chm_nosuch
, 0 }, /* 0xf3 */
1615 {chm_nosuch
, 0 }, /* 0xf4 */
1616 {chm_nosuch
, 0 }, /* 0xf5 */
1617 {chm_nosuch
, 0 }, /* 0xf6 */
1618 {chm_nosuch
, 0 }, /* 0xf7 */
1619 {chm_nosuch
, 0 }, /* 0xf8 */
1620 {chm_nosuch
, 0 }, /* 0xf9 */
1621 {chm_nosuch
, 0 }, /* 0xfa */
1622 {chm_nosuch
, 0 }, /* 0xfb */
1623 {chm_nosuch
, 0 }, /* 0xfc */
1624 {chm_nosuch
, 0 }, /* 0xfd */
1625 {chm_nosuch
, 0 }, /* 0xfe */
1626 {chm_nosuch
, 0 }, /* 0xff */
1631 /* set_channel_mode()
1633 * inputs - client, source, channel, membership pointer, params
1635 * side effects - channel modes/memberships are changed, MODE is issued
1637 * Extensively modified to be hotpluggable, 03/09/06 -- nenolod
1640 set_channel_mode(struct Client
*client_p
, struct Client
*source_p
,
1641 struct Channel
*chptr
, struct membership
*msptr
, int parc
, const char *parv
[])
1643 static char modebuf
[BUFSIZE
];
1644 static char parabuf
[BUFSIZE
];
1647 int cur_len
, mlen
, paralen
, paracount
, arglen
, len
;
1653 const char *ml
= parv
[0];
1655 struct Client
*fakesource_p
;
1658 removed_mask_pos
= 0;
1661 mode_limit_simple
= 0;
1663 alevel
= get_channel_access(source_p
, msptr
);
1665 /* Hide connecting server on netburst -- jilles */
1666 if (ConfigServerHide
.flatten_links
&& IsServer(source_p
) && !has_id(source_p
) && !HasSentEob(source_p
))
1669 fakesource_p
= source_p
;
1671 for(; (c
= *ml
) != 0; ml
++)
1685 /* If this mode char is locked, don't allow local users to change it. */
1686 if (MyClient(source_p
) && chptr
->mode_lock
&& strchr(chptr
->mode_lock
, c
))
1688 if (!(errors
& SM_ERR_MLOCK
))
1689 sendto_one_numeric(source_p
,
1690 ERR_MLOCKRESTRICTED
,
1691 form_str(ERR_MLOCKRESTRICTED
),
1695 errors
|= SM_ERR_MLOCK
;
1698 chmode_table
[(unsigned char) c
].set_func(fakesource_p
, chptr
, alevel
,
1701 chmode_table
[(unsigned char) c
].mode_type
);
1706 /* bail out if we have nothing to do... */
1710 if(IsServer(source_p
))
1711 mlen
= rb_sprintf(modebuf
, ":%s MODE %s ", fakesource_p
->name
, chptr
->chname
);
1713 mlen
= rb_sprintf(modebuf
, ":%s!%s@%s MODE %s ",
1714 source_p
->name
, source_p
->username
,
1715 source_p
->host
, chptr
->chname
);
1717 for(j
= 0, flags
= ALL_MEMBERS
; j
< 2; j
++, flags
= ONLY_CHANOPS
)
1720 mbuf
= modebuf
+ mlen
;
1723 paracount
= paralen
= 0;
1726 for(i
= 0; i
< mode_count
; i
++)
1728 if(mode_changes
[i
].letter
== 0 || mode_changes
[i
].mems
!= flags
)
1731 if(mode_changes
[i
].arg
!= NULL
)
1733 arglen
= strlen(mode_changes
[i
].arg
);
1735 if(arglen
> MODEBUFLEN
- 5)
1741 /* if we're creeping over MAXMODEPARAMSSERV, or over
1742 * bufsize (4 == +/-,modechar,two spaces) send now.
1744 if(mode_changes
[i
].arg
!= NULL
&&
1745 ((paracount
== MAXMODEPARAMSSERV
) ||
1746 ((cur_len
+ paralen
+ arglen
+ 4) > (BUFSIZE
- 3))))
1751 sendto_channel_local(flags
, chptr
, "%s %s", modebuf
,
1756 paracount
= paralen
= 0;
1758 mbuf
= modebuf
+ mlen
;
1764 if(dir
!= mode_changes
[i
].dir
)
1766 *mbuf
++ = (mode_changes
[i
].dir
== MODE_ADD
) ? '+' : '-';
1768 dir
= mode_changes
[i
].dir
;
1771 *mbuf
++ = mode_changes
[i
].letter
;
1774 if(mode_changes
[i
].arg
!= NULL
)
1777 len
= rb_sprintf(pbuf
, "%s ", mode_changes
[i
].arg
);
1783 if(paralen
&& parabuf
[paralen
- 1] == ' ')
1784 parabuf
[paralen
- 1] = '\0';
1788 sendto_channel_local(flags
, chptr
, "%s %s", modebuf
, parabuf
);
1791 /* only propagate modes originating locally, or if we're hubbing */
1792 if(MyClient(source_p
) || rb_dlink_list_length(&serv_list
) > 1)
1793 send_cap_mode_changes(client_p
, source_p
, chptr
, mode_changes
, mode_count
);
1796 /* set_channel_mlock()
1798 * inputs - client, source, channel, params
1800 * side effects - channel mlock is changed / MLOCK is propagated
1803 set_channel_mlock(struct Client
*client_p
, struct Client
*source_p
,
1804 struct Channel
*chptr
, const char *newmlock
, int propagate
)
1806 rb_free(chptr
->mode_lock
);
1807 chptr
->mode_lock
= newmlock
? rb_strdup(newmlock
) : NULL
;
1811 sendto_server(client_p
, NULL
, CAP_TS6
| CAP_MLOCK
, NOCAPS
, ":%s MLOCK %ld %s :%s",
1812 source_p
->id
, (long) chptr
->channelts
, chptr
->chname
,
1813 chptr
->mode_lock
? chptr
->mode_lock
: "");