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
])
107 case MODE_FREETARGET
:
108 case MODE_DISFORWARD
:
109 if(ConfigChannel
.use_forward
)
113 if(chmode_flags
[i
] != 0)
119 /* Should we leave orphaned check here? -- dwr */
120 if(!(chmode_table
[i
].set_func
== chm_nosuch
) && !(chmode_table
[i
].set_func
== chm_orphaned
))
134 * outputs - an available cflag bitmask or
135 * 0 if no cflags are available
136 * side effects - NONE
139 find_cflag_slot(void)
141 unsigned int all_cflags
= 0, my_cflag
= 0, i
;
143 for (i
= 0; i
< 256; i
++)
144 all_cflags
|= chmode_flags
[i
];
146 for (my_cflag
= 1; my_cflag
&& (all_cflags
& my_cflag
);
153 cflag_add(char c_
, ChannelModeFunc function
)
155 int c
= (unsigned char)c_
;
157 if (chmode_table
[c
].set_func
!= chm_nosuch
&&
158 chmode_table
[c
].set_func
!= chm_orphaned
)
161 if (chmode_table
[c
].set_func
== chm_nosuch
)
162 chmode_table
[c
].mode_type
= find_cflag_slot();
163 if (chmode_table
[c
].mode_type
== 0)
165 chmode_table
[c
].set_func
= function
;
166 construct_cflags_strings();
167 return chmode_table
[c
].mode_type
;
171 cflag_orphan(char c_
)
173 int c
= (unsigned char)c_
;
175 s_assert(chmode_flags
[c
] != 0);
176 chmode_table
[c
].set_func
= chm_orphaned
;
177 construct_cflags_strings();
181 get_channel_access(struct Client
*source_p
, struct membership
*msptr
)
183 hook_data_channel_approval moduledata
;
185 if(!MyClient(source_p
))
191 moduledata
.client
= source_p
;
192 moduledata
.chptr
= msptr
->chptr
;
193 moduledata
.msptr
= msptr
;
194 moduledata
.target
= NULL
;
195 moduledata
.approved
= is_chanop(msptr
) ? CHFL_CHANOP
: CHFL_PEON
;
197 call_hook(h_get_channel_access
, &moduledata
);
199 return moduledata
.approved
;
204 * inputs - client, channel, id to add, type, forward
205 * outputs - 0 on failure, 1 on success
206 * side effects - given id is added to the appropriate list
209 add_id(struct Client
*source_p
, struct Channel
*chptr
, const char *banid
, const char *forward
,
210 rb_dlink_list
* list
, long mode_type
)
212 struct Ban
*actualBan
;
213 static char who
[USERHOST_REPLYLEN
];
214 char *realban
= LOCAL_COPY(banid
);
217 /* dont let local clients overflow the banlist, or set redundant
220 if(MyClient(source_p
))
222 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
))
224 sendto_one(source_p
, form_str(ERR_BANLISTFULL
),
225 me
.name
, source_p
->name
, chptr
->chname
, realban
);
229 RB_DLINK_FOREACH(ptr
, list
->head
)
231 actualBan
= ptr
->data
;
232 if(mask_match(actualBan
->banstr
, realban
))
236 /* dont let remotes set duplicates */
239 RB_DLINK_FOREACH(ptr
, list
->head
)
241 actualBan
= ptr
->data
;
242 if(!irccmp(actualBan
->banstr
, realban
))
248 if(IsPerson(source_p
))
249 rb_sprintf(who
, "%s!%s@%s", source_p
->name
, source_p
->username
, source_p
->host
);
251 rb_strlcpy(who
, source_p
->name
, sizeof(who
));
253 actualBan
= allocate_ban(realban
, who
, forward
);
254 actualBan
->when
= rb_current_time();
256 rb_dlinkAdd(actualBan
, &actualBan
->node
, list
);
258 /* invalidate the can_send() cache */
259 if(mode_type
== CHFL_BAN
|| mode_type
== CHFL_QUIET
|| mode_type
== CHFL_EXCEPTION
)
267 * inputs - channel, id to remove, type
268 * outputs - pointer to ban that was removed, if any
269 * side effects - given id is removed from the appropriate list and returned
272 del_id(struct Channel
*chptr
, const char *banid
, rb_dlink_list
* list
, long mode_type
)
277 if(EmptyString(banid
))
280 RB_DLINK_FOREACH(ptr
, list
->head
)
284 if(irccmp(banid
, banptr
->banstr
) == 0)
286 rb_dlinkDelete(&banptr
->node
, list
);
288 /* invalidate the can_send() cache */
289 if(mode_type
== CHFL_BAN
|| mode_type
== CHFL_QUIET
|| mode_type
== CHFL_EXCEPTION
)
301 * input - string to check
302 * output - pointer to 'fixed' string, or "*" if empty
303 * side effects - any white space found becomes \0
306 check_string(char *s
)
309 static char splat
[] = "*";
326 * inputs - mask to pretty
327 * outputs - better version of the mask
328 * side effects - mask is chopped to limits, and transformed:
336 pretty_mask(const char *idmask
)
338 static char mask_buf
[BUFSIZE
];
340 char *nick
, *user
, *host
, *forward
= NULL
;
342 char *t
, *at
, *ex
, *ex2
;
343 char ne
= 0, ue
= 0, he
= 0, fe
= 0; /* save values at nick[NICKLEN], et all */
344 char e2
= 0; /* save value that delimits forward channel */
347 mask
= LOCAL_COPY(idmask
);
348 mask
= check_string(mask
);
351 nick
= user
= host
= splat
;
353 if((size_t) BUFSIZE
- mask_pos
< strlen(mask
) + 5)
356 old_mask_pos
= mask_pos
;
360 mask_pos
+= rb_sprintf(mask_buf
+ mask_pos
, "%s", mask
) + 1;
361 t
= mask_buf
+ old_mask_pos
+ 1;
367 return mask_buf
+ old_mask_pos
;
370 at
= ex
= ex2
= NULL
;
371 if((t
= strchr(mask
, '@')) != NULL
)
378 if((t
= strchr(mask
, '!')) != NULL
)
393 if((t
= strchr(host
, '!')) != NULL
|| (t
= strchr(host
, '$')) != NULL
)
402 else if((t
= strchr(mask
, '!')) != NULL
)
411 else if(strchr(mask
, '.') != NULL
|| strchr(mask
, ':') != NULL
)
422 /* truncate values to max lengths */
423 if(strlen(nick
) > NICKLEN
- 1)
425 ne
= nick
[NICKLEN
- 1];
426 nick
[NICKLEN
- 1] = '\0';
428 if(strlen(user
) > USERLEN
)
431 user
[USERLEN
] = '\0';
433 if(strlen(host
) > HOSTLEN
)
436 host
[HOSTLEN
] = '\0';
438 if(forward
&& strlen(forward
) > CHANNELLEN
)
440 fe
= forward
[CHANNELLEN
];
441 forward
[CHANNELLEN
] = '\0';
445 mask_pos
+= rb_sprintf(mask_buf
+ mask_pos
, "%s!%s@%s$%s", nick
, user
, host
, forward
) + 1;
447 mask_pos
+= rb_sprintf(mask_buf
+ mask_pos
, "%s!%s@%s", nick
, user
, host
) + 1;
449 /* restore mask, since we may need to use it again later */
457 nick
[NICKLEN
- 1] = ne
;
463 forward
[CHANNELLEN
] = fe
;
465 return mask_buf
+ old_mask_pos
;
470 * input - client, channel to set mode on, target channel name
471 * output - true if forwarding should be allowed
472 * side effects - numeric sent if not allowed
475 check_forward(struct Client
*source_p
, struct Channel
*chptr
,
478 struct Channel
*targptr
;
479 struct membership
*msptr
;
481 if(!check_channel_name(forward
) ||
482 (MyClient(source_p
) && (strlen(forward
) > LOC_CHANNELLEN
|| hash_find_resv(forward
))))
484 sendto_one_numeric(source_p
, ERR_BADCHANNAME
, form_str(ERR_BADCHANNAME
), forward
);
487 /* don't forward to inconsistent target -- jilles */
488 if(chptr
->chname
[0] == '#' && forward
[0] == '&')
490 sendto_one_numeric(source_p
, ERR_BADCHANNAME
,
491 form_str(ERR_BADCHANNAME
), forward
);
494 if(MyClient(source_p
) && (targptr
= find_channel(forward
)) == NULL
)
496 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
497 form_str(ERR_NOSUCHCHANNEL
), forward
);
500 if(MyClient(source_p
) && !(targptr
->mode
.mode
& MODE_FREETARGET
))
502 if((msptr
= find_channel_membership(targptr
, source_p
)) == NULL
||
503 get_channel_access(source_p
, msptr
) != CHFL_CHANOP
)
505 sendto_one(source_p
, form_str(ERR_CHANOPRIVSNEEDED
),
506 me
.name
, source_p
->name
, targptr
->chname
);
516 * output - the same key, fixed
517 * side effects - anything below ascii 13 is discarded, ':' discarded,
518 * high ascii is dropped to lower half of ascii table
525 for(s
= t
= (u_char
*) arg
; (c
= *s
); s
++)
528 if(c
!= ':' && c
!= ',' && c
> ' ')
539 * ouput - the same key, fixed
540 * side effects - high ascii dropped to lower half of table,
541 * CR/LF/':' are dropped
544 fix_key_remote(char *arg
)
548 for(s
= t
= (u_char
*) arg
; (c
= *s
); s
++)
551 if((c
!= 0x0a) && (c
!= ':') && (c
!= ',') && (c
!= 0x0d) && (c
!= ' '))
561 * The handlers for each specific mode.
564 chm_nosuch(struct Client
*source_p
, struct Channel
*chptr
,
565 int alevel
, int parc
, int *parn
,
566 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
568 if(*errors
& SM_ERR_UNKNOWN
)
570 *errors
|= SM_ERR_UNKNOWN
;
571 sendto_one(source_p
, form_str(ERR_UNKNOWNMODE
), me
.name
, source_p
->name
, c
);
575 chm_simple(struct Client
*source_p
, struct Channel
*chptr
,
576 int alevel
, int parc
, int *parn
,
577 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
579 if(alevel
!= CHFL_CHANOP
)
581 if(!(*errors
& SM_ERR_NOOPS
))
582 sendto_one(source_p
, form_str(ERR_CHANOPRIVSNEEDED
),
583 me
.name
, source_p
->name
, chptr
->chname
);
584 *errors
|= SM_ERR_NOOPS
;
588 if(MyClient(source_p
) && (++mode_limit_simple
> MAXMODES_SIMPLE
))
592 if((dir
== MODE_ADD
) && !(chptr
->mode
.mode
& mode_type
))
594 /* if +f is disabled, ignore an attempt to set +QF locally */
595 if(!ConfigChannel
.use_forward
&& MyClient(source_p
) &&
596 (c
== 'Q' || c
== 'F'))
599 chptr
->mode
.mode
|= mode_type
;
601 mode_changes
[mode_count
].letter
= c
;
602 mode_changes
[mode_count
].dir
= MODE_ADD
;
603 mode_changes
[mode_count
].caps
= 0;
604 mode_changes
[mode_count
].nocaps
= 0;
605 mode_changes
[mode_count
].id
= NULL
;
606 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
607 mode_changes
[mode_count
++].arg
= NULL
;
609 else if((dir
== MODE_DEL
) && (chptr
->mode
.mode
& mode_type
))
611 chptr
->mode
.mode
&= ~mode_type
;
613 mode_changes
[mode_count
].letter
= c
;
614 mode_changes
[mode_count
].dir
= MODE_DEL
;
615 mode_changes
[mode_count
].caps
= 0;
616 mode_changes
[mode_count
].nocaps
= 0;
617 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
618 mode_changes
[mode_count
].id
= NULL
;
619 mode_changes
[mode_count
++].arg
= NULL
;
624 chm_orphaned(struct Client
*source_p
, struct Channel
*chptr
,
625 int alevel
, int parc
, int *parn
,
626 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
628 if(MyClient(source_p
))
631 if((dir
== MODE_ADD
) && !(chptr
->mode
.mode
& mode_type
))
633 chptr
->mode
.mode
|= mode_type
;
635 mode_changes
[mode_count
].letter
= c
;
636 mode_changes
[mode_count
].dir
= MODE_ADD
;
637 mode_changes
[mode_count
].caps
= 0;
638 mode_changes
[mode_count
].nocaps
= 0;
639 mode_changes
[mode_count
].id
= NULL
;
640 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
641 mode_changes
[mode_count
++].arg
= NULL
;
643 else if((dir
== MODE_DEL
) && (chptr
->mode
.mode
& mode_type
))
645 chptr
->mode
.mode
&= ~mode_type
;
647 mode_changes
[mode_count
].letter
= c
;
648 mode_changes
[mode_count
].dir
= MODE_DEL
;
649 mode_changes
[mode_count
].caps
= 0;
650 mode_changes
[mode_count
].nocaps
= 0;
651 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
652 mode_changes
[mode_count
].id
= NULL
;
653 mode_changes
[mode_count
++].arg
= NULL
;
658 chm_staff(struct Client
*source_p
, struct Channel
*chptr
,
659 int alevel
, int parc
, int *parn
,
660 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
662 if(!IsOper(source_p
) && !IsServer(source_p
))
664 if(!(*errors
& SM_ERR_NOPRIVS
))
665 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
, form_str(ERR_NOPRIVILEGES
));
666 *errors
|= SM_ERR_NOPRIVS
;
669 if(MyClient(source_p
) && !IsOperResv(source_p
))
671 if(!(*errors
& SM_ERR_NOPRIVS
))
672 sendto_one(source_p
, form_str(ERR_NOPRIVS
), me
.name
,
673 source_p
->name
, "resv");
674 *errors
|= SM_ERR_NOPRIVS
;
678 if(MyClient(source_p
) && (++mode_limit_simple
> MAXMODES_SIMPLE
))
682 if((dir
== MODE_ADD
) && !(chptr
->mode
.mode
& mode_type
))
684 chptr
->mode
.mode
|= mode_type
;
686 mode_changes
[mode_count
].letter
= c
;
687 mode_changes
[mode_count
].dir
= MODE_ADD
;
688 mode_changes
[mode_count
].caps
= 0;
689 mode_changes
[mode_count
].nocaps
= 0;
690 mode_changes
[mode_count
].id
= NULL
;
691 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
692 mode_changes
[mode_count
++].arg
= NULL
;
694 else if((dir
== MODE_DEL
) && (chptr
->mode
.mode
& mode_type
))
696 chptr
->mode
.mode
&= ~mode_type
;
698 mode_changes
[mode_count
].letter
= c
;
699 mode_changes
[mode_count
].dir
= MODE_DEL
;
700 mode_changes
[mode_count
].caps
= 0;
701 mode_changes
[mode_count
].nocaps
= 0;
702 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
703 mode_changes
[mode_count
].id
= NULL
;
704 mode_changes
[mode_count
++].arg
= NULL
;
709 chm_ban(struct Client
*source_p
, struct Channel
*chptr
,
710 int alevel
, int parc
, int *parn
,
711 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
713 char *mask
, *raw_mask
, *forward
;
726 list
= &chptr
->banlist
;
727 errorval
= SM_ERR_RPL_B
;
728 rpl_list
= RPL_BANLIST
;
729 rpl_endlist
= RPL_ENDOFBANLIST
;
735 /* if +e is disabled, allow all but +e locally */
736 if(!ConfigChannel
.use_except
&& MyClient(source_p
) &&
737 ((dir
== MODE_ADD
) && (parc
> *parn
)))
740 list
= &chptr
->exceptlist
;
741 errorval
= SM_ERR_RPL_E
;
742 rpl_list
= RPL_EXCEPTLIST
;
743 rpl_endlist
= RPL_ENDOFEXCEPTLIST
;
746 if(ConfigChannel
.use_except
|| (dir
== MODE_DEL
))
753 /* if +I is disabled, allow all but +I locally */
754 if(!ConfigChannel
.use_invex
&& MyClient(source_p
) &&
755 (dir
== MODE_ADD
) && (parc
> *parn
))
758 list
= &chptr
->invexlist
;
759 errorval
= SM_ERR_RPL_I
;
760 rpl_list
= RPL_INVITELIST
;
761 rpl_endlist
= RPL_ENDOFINVITELIST
;
764 if(ConfigChannel
.use_invex
|| (dir
== MODE_DEL
))
771 list
= &chptr
->quietlist
;
772 errorval
= SM_ERR_RPL_Q
;
773 rpl_list
= RPL_QUIETLIST
;
774 rpl_endlist
= RPL_ENDOFQUIETLIST
;
780 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "chm_ban() called with unknown type!");
785 if(dir
== 0 || parc
<= *parn
)
787 if((*errors
& errorval
) != 0)
791 /* non-ops cant see +eI lists.. */
792 if(alevel
!= CHFL_CHANOP
&& mode_type
!= CHFL_BAN
&&
793 mode_type
!= CHFL_QUIET
)
795 if(!(*errors
& SM_ERR_NOOPS
))
796 sendto_one(source_p
, form_str(ERR_CHANOPRIVSNEEDED
),
797 me
.name
, source_p
->name
, chptr
->chname
);
798 *errors
|= SM_ERR_NOOPS
;
802 RB_DLINK_FOREACH(ptr
, list
->head
)
807 rb_snprintf(buf
, sizeof(buf
), "%s$%s", banptr
->banstr
, banptr
->forward
);
809 rb_strlcpy(buf
, banptr
->banstr
, sizeof(buf
));
811 sendto_one(source_p
, form_str(rpl_list
),
812 me
.name
, source_p
->name
, chptr
->chname
,
813 buf
, banptr
->who
, banptr
->when
);
815 sendto_one(source_p
, form_str(rpl_endlist
), me
.name
, source_p
->name
, chptr
->chname
);
819 if(alevel
!= CHFL_CHANOP
)
821 if(!(*errors
& SM_ERR_NOOPS
))
822 sendto_one(source_p
, form_str(ERR_CHANOPRIVSNEEDED
),
823 me
.name
, source_p
->name
, chptr
->chname
);
824 *errors
|= SM_ERR_NOOPS
;
828 if(MyClient(source_p
) && (++mode_limit
> MAXMODEPARAMS
))
831 raw_mask
= parv
[(*parn
)];
834 /* empty ban, or starts with ':' which messes up s2s, ignore it */
835 if(EmptyString(raw_mask
) || *raw_mask
== ':')
838 if(!MyClient(source_p
))
840 if(strchr(raw_mask
, ' '))
846 mask
= pretty_mask(raw_mask
);
848 /* we'd have problems parsing this, hyb6 does it too
849 * also make sure it will always fit on a line with channel
852 if(strlen(mask
) > IRCD_MIN(BANLEN
, MODEBUFLEN
- 5))
855 /* Look for a $ after the first character.
856 * As the first character, it marks an extban; afterwards
857 * it delimits a forward channel.
859 if ((forward
= strchr(mask
+1, '$')) != NULL
)
862 if (*forward
== '\0')
866 /* if we're adding a NEW id */
869 if (*mask
== '$' && MyClient(source_p
))
871 if (!valid_extban(mask
, source_p
, chptr
, mode_type
))
872 /* XXX perhaps return an error message here */
876 /* For compatibility, only check the forward channel from
877 * local clients. Accept any forward channel from servers.
879 if(forward
!= NULL
&& MyClient(source_p
))
881 if(!ConfigChannel
.use_forward
)
883 if(!check_forward(source_p
, chptr
, forward
))
885 /* Forwards only make sense for bans. */
886 if(mode_type
!= CHFL_BAN
)
890 /* dont allow local clients to overflow the banlist, dont
891 * let remote servers set duplicate bans
893 if(!add_id(source_p
, chptr
, mask
, forward
, list
, mode_type
))
899 mode_changes
[mode_count
].letter
= c
;
900 mode_changes
[mode_count
].dir
= MODE_ADD
;
901 mode_changes
[mode_count
].caps
= caps
;
902 mode_changes
[mode_count
].nocaps
= 0;
903 mode_changes
[mode_count
].mems
= mems
;
904 mode_changes
[mode_count
].id
= NULL
;
905 mode_changes
[mode_count
++].arg
= mask
;
907 else if(dir
== MODE_DEL
)
910 static char buf
[BANLEN
* MAXMODEPARAMS
];
911 int old_removed_mask_pos
= removed_mask_pos
;
912 if((removed
= del_id(chptr
, mask
, list
, mode_type
)) == NULL
)
914 /* mask isn't a valid ban, check raw_mask */
915 if((removed
= del_id(chptr
, raw_mask
, list
, mode_type
)) != NULL
)
919 if(removed
&& removed
->forward
)
920 removed_mask_pos
+= rb_snprintf(buf
, sizeof(buf
), "%s$%s", removed
->banstr
, removed
->forward
);
922 removed_mask_pos
+= rb_strlcpy(buf
, mask
, sizeof(buf
));
929 mode_changes
[mode_count
].letter
= c
;
930 mode_changes
[mode_count
].dir
= MODE_DEL
;
931 mode_changes
[mode_count
].caps
= caps
;
932 mode_changes
[mode_count
].nocaps
= 0;
933 mode_changes
[mode_count
].mems
= mems
;
934 mode_changes
[mode_count
].id
= NULL
;
935 mode_changes
[mode_count
++].arg
= buf
+ old_removed_mask_pos
;
940 chm_op(struct Client
*source_p
, struct Channel
*chptr
,
941 int alevel
, int parc
, int *parn
,
942 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
944 struct membership
*mstptr
;
946 struct Client
*targ_p
;
948 if(alevel
!= CHFL_CHANOP
)
950 if(!(*errors
& SM_ERR_NOOPS
))
951 sendto_one(source_p
, form_str(ERR_CHANOPRIVSNEEDED
),
952 me
.name
, source_p
->name
, chptr
->chname
);
953 *errors
|= SM_ERR_NOOPS
;
957 if((dir
== MODE_QUERY
) || (parc
<= *parn
))
960 opnick
= parv
[(*parn
)];
964 if(EmptyString(opnick
))
966 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
, form_str(ERR_NOSUCHNICK
), "*");
970 if((targ_p
= find_chasing(source_p
, opnick
, NULL
)) == NULL
)
975 mstptr
= find_channel_membership(chptr
, targ_p
);
979 if(!(*errors
& SM_ERR_NOTONCHANNEL
) && MyClient(source_p
))
980 sendto_one_numeric(source_p
, ERR_USERNOTINCHANNEL
,
981 form_str(ERR_USERNOTINCHANNEL
), opnick
, chptr
->chname
);
982 *errors
|= SM_ERR_NOTONCHANNEL
;
986 if(MyClient(source_p
) && (++mode_limit
> MAXMODEPARAMS
))
991 if(targ_p
== source_p
&& mstptr
->flags
& CHFL_CHANOP
)
994 mode_changes
[mode_count
].letter
= c
;
995 mode_changes
[mode_count
].dir
= MODE_ADD
;
996 mode_changes
[mode_count
].caps
= 0;
997 mode_changes
[mode_count
].nocaps
= 0;
998 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
999 mode_changes
[mode_count
].id
= targ_p
->id
;
1000 mode_changes
[mode_count
].arg
= targ_p
->name
;
1001 mode_changes
[mode_count
++].client
= targ_p
;
1003 mstptr
->flags
|= CHFL_CHANOP
;
1007 if(MyClient(source_p
) && IsService(targ_p
))
1009 sendto_one(source_p
, form_str(ERR_ISCHANSERVICE
),
1010 me
.name
, source_p
->name
, targ_p
->name
, chptr
->chname
);
1014 mode_changes
[mode_count
].letter
= c
;
1015 mode_changes
[mode_count
].dir
= MODE_DEL
;
1016 mode_changes
[mode_count
].caps
= 0;
1017 mode_changes
[mode_count
].nocaps
= 0;
1018 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
1019 mode_changes
[mode_count
].id
= targ_p
->id
;
1020 mode_changes
[mode_count
].arg
= targ_p
->name
;
1021 mode_changes
[mode_count
++].client
= targ_p
;
1023 mstptr
->flags
&= ~CHFL_CHANOP
;
1028 chm_voice(struct Client
*source_p
, struct Channel
*chptr
,
1029 int alevel
, int parc
, int *parn
,
1030 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
1032 struct membership
*mstptr
;
1034 struct Client
*targ_p
;
1036 if(alevel
!= CHFL_CHANOP
)
1038 if(!(*errors
& SM_ERR_NOOPS
))
1039 sendto_one(source_p
, form_str(ERR_CHANOPRIVSNEEDED
),
1040 me
.name
, source_p
->name
, chptr
->chname
);
1041 *errors
|= SM_ERR_NOOPS
;
1045 if((dir
== MODE_QUERY
) || parc
<= *parn
)
1048 opnick
= parv
[(*parn
)];
1052 if(EmptyString(opnick
))
1054 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
, form_str(ERR_NOSUCHNICK
), "*");
1058 if((targ_p
= find_chasing(source_p
, opnick
, NULL
)) == NULL
)
1063 mstptr
= find_channel_membership(chptr
, targ_p
);
1067 if(!(*errors
& SM_ERR_NOTONCHANNEL
) && MyClient(source_p
))
1068 sendto_one_numeric(source_p
, ERR_USERNOTINCHANNEL
,
1069 form_str(ERR_USERNOTINCHANNEL
), opnick
, chptr
->chname
);
1070 *errors
|= SM_ERR_NOTONCHANNEL
;
1074 if(MyClient(source_p
) && (++mode_limit
> MAXMODEPARAMS
))
1079 mode_changes
[mode_count
].letter
= c
;
1080 mode_changes
[mode_count
].dir
= MODE_ADD
;
1081 mode_changes
[mode_count
].caps
= 0;
1082 mode_changes
[mode_count
].nocaps
= 0;
1083 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
1084 mode_changes
[mode_count
].id
= targ_p
->id
;
1085 mode_changes
[mode_count
].arg
= targ_p
->name
;
1086 mode_changes
[mode_count
++].client
= targ_p
;
1088 mstptr
->flags
|= CHFL_VOICE
;
1092 mode_changes
[mode_count
].letter
= 'v';
1093 mode_changes
[mode_count
].dir
= MODE_DEL
;
1094 mode_changes
[mode_count
].caps
= 0;
1095 mode_changes
[mode_count
].nocaps
= 0;
1096 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
1097 mode_changes
[mode_count
].id
= targ_p
->id
;
1098 mode_changes
[mode_count
].arg
= targ_p
->name
;
1099 mode_changes
[mode_count
++].client
= targ_p
;
1101 mstptr
->flags
&= ~CHFL_VOICE
;
1106 chm_limit(struct Client
*source_p
, struct Channel
*chptr
,
1107 int alevel
, int parc
, int *parn
,
1108 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
1111 static char limitstr
[30];
1114 if(alevel
!= CHFL_CHANOP
)
1116 if(!(*errors
& SM_ERR_NOOPS
))
1117 sendto_one(source_p
, form_str(ERR_CHANOPRIVSNEEDED
),
1118 me
.name
, source_p
->name
, chptr
->chname
);
1119 *errors
|= SM_ERR_NOOPS
;
1123 if(dir
== MODE_QUERY
)
1126 if(MyClient(source_p
) && (++mode_limit_simple
> MAXMODES_SIMPLE
))
1129 if((dir
== MODE_ADD
) && parc
> *parn
)
1131 lstr
= parv
[(*parn
)];
1134 if(EmptyString(lstr
) || (limit
= atoi(lstr
)) <= 0)
1137 rb_sprintf(limitstr
, "%d", limit
);
1139 mode_changes
[mode_count
].letter
= c
;
1140 mode_changes
[mode_count
].dir
= MODE_ADD
;
1141 mode_changes
[mode_count
].caps
= 0;
1142 mode_changes
[mode_count
].nocaps
= 0;
1143 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
1144 mode_changes
[mode_count
].id
= NULL
;
1145 mode_changes
[mode_count
++].arg
= limitstr
;
1147 chptr
->mode
.limit
= limit
;
1149 else if(dir
== MODE_DEL
)
1151 if(!chptr
->mode
.limit
)
1154 chptr
->mode
.limit
= 0;
1156 mode_changes
[mode_count
].letter
= c
;
1157 mode_changes
[mode_count
].dir
= MODE_DEL
;
1158 mode_changes
[mode_count
].caps
= 0;
1159 mode_changes
[mode_count
].nocaps
= 0;
1160 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
1161 mode_changes
[mode_count
].id
= NULL
;
1162 mode_changes
[mode_count
++].arg
= NULL
;
1167 chm_throttle(struct Client
*source_p
, struct Channel
*chptr
,
1168 int alevel
, int parc
, int *parn
,
1169 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
1171 int joins
= 0, timeslice
= 0;
1173 if(alevel
!= CHFL_CHANOP
)
1175 if(!(*errors
& SM_ERR_NOOPS
))
1176 sendto_one(source_p
, form_str(ERR_CHANOPRIVSNEEDED
),
1177 me
.name
, source_p
->name
, chptr
->chname
);
1178 *errors
|= SM_ERR_NOOPS
;
1182 if(dir
== MODE_QUERY
)
1185 if(MyClient(source_p
) && (++mode_limit_simple
> MAXMODES_SIMPLE
))
1188 if((dir
== MODE_ADD
) && parc
> *parn
)
1190 sscanf(parv
[(*parn
)], "%d:%d", &joins
, ×lice
);
1192 if(!joins
|| !timeslice
)
1195 mode_changes
[mode_count
].letter
= c
;
1196 mode_changes
[mode_count
].dir
= MODE_ADD
;
1197 mode_changes
[mode_count
].caps
= 0;
1198 mode_changes
[mode_count
].nocaps
= 0;
1199 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
1200 mode_changes
[mode_count
].id
= NULL
;
1201 mode_changes
[mode_count
++].arg
= parv
[(*parn
)];
1205 chptr
->mode
.join_num
= joins
;
1206 chptr
->mode
.join_time
= timeslice
;
1208 else if(dir
== MODE_DEL
)
1210 if(!chptr
->mode
.join_num
)
1213 chptr
->mode
.join_num
= 0;
1214 chptr
->mode
.join_time
= 0;
1215 chptr
->join_count
= 0;
1216 chptr
->join_delta
= 0;
1218 mode_changes
[mode_count
].letter
= c
;
1219 mode_changes
[mode_count
].dir
= MODE_DEL
;
1220 mode_changes
[mode_count
].caps
= 0;
1221 mode_changes
[mode_count
].nocaps
= 0;
1222 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
1223 mode_changes
[mode_count
].id
= NULL
;
1224 mode_changes
[mode_count
++].arg
= NULL
;
1229 chm_forward(struct Client
*source_p
, struct Channel
*chptr
,
1230 int alevel
, int parc
, int *parn
,
1231 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
1233 const char *forward
;
1235 /* if +f is disabled, ignore local attempts to set it */
1236 if(!ConfigChannel
.use_forward
&& MyClient(source_p
) &&
1237 (dir
== MODE_ADD
) && (parc
> *parn
))
1240 if(dir
== MODE_QUERY
|| (dir
== MODE_ADD
&& parc
<= *parn
))
1242 if (!(*errors
& SM_ERR_RPL_F
))
1244 if (*chptr
->mode
.forward
== '\0')
1245 sendto_one_notice(source_p
, ":%s has no forward channel", chptr
->chname
);
1247 sendto_one_notice(source_p
, ":%s forward channel is %s", chptr
->chname
, chptr
->mode
.forward
);
1248 *errors
|= SM_ERR_RPL_F
;
1253 #ifndef FORWARD_OPERONLY
1254 if(alevel
!= CHFL_CHANOP
)
1256 if(!(*errors
& SM_ERR_NOOPS
))
1257 sendto_one(source_p
, form_str(ERR_CHANOPRIVSNEEDED
),
1258 me
.name
, source_p
->name
, chptr
->chname
);
1259 *errors
|= SM_ERR_NOOPS
;
1263 if(!IsOper(source_p
) && !IsServer(source_p
))
1265 if(!(*errors
& SM_ERR_NOPRIVS
))
1266 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
, form_str(ERR_NOPRIVILEGES
));
1267 *errors
|= SM_ERR_NOPRIVS
;
1272 if(MyClient(source_p
) && (++mode_limit_simple
> MAXMODES_SIMPLE
))
1275 if(dir
== MODE_ADD
&& parc
> *parn
)
1277 forward
= parv
[(*parn
)];
1280 if(EmptyString(forward
))
1283 if(!check_forward(source_p
, chptr
, forward
))
1286 rb_strlcpy(chptr
->mode
.forward
, forward
, sizeof(chptr
->mode
.forward
));
1288 mode_changes
[mode_count
].letter
= c
;
1289 mode_changes
[mode_count
].dir
= MODE_ADD
;
1290 mode_changes
[mode_count
].caps
= 0;
1291 mode_changes
[mode_count
].nocaps
= 0;
1292 mode_changes
[mode_count
].mems
=
1293 ConfigChannel
.use_forward
? ALL_MEMBERS
: ONLY_SERVERS
;
1294 mode_changes
[mode_count
].id
= NULL
;
1295 mode_changes
[mode_count
++].arg
= forward
;
1297 else if(dir
== MODE_DEL
)
1299 if(!(*chptr
->mode
.forward
))
1302 *chptr
->mode
.forward
= '\0';
1304 mode_changes
[mode_count
].letter
= c
;
1305 mode_changes
[mode_count
].dir
= MODE_DEL
;
1306 mode_changes
[mode_count
].caps
= 0;
1307 mode_changes
[mode_count
].nocaps
= 0;
1308 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
1309 mode_changes
[mode_count
].id
= NULL
;
1310 mode_changes
[mode_count
++].arg
= NULL
;
1315 chm_key(struct Client
*source_p
, struct Channel
*chptr
,
1316 int alevel
, int parc
, int *parn
,
1317 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
1321 if(alevel
!= CHFL_CHANOP
)
1323 if(!(*errors
& SM_ERR_NOOPS
))
1324 sendto_one(source_p
, form_str(ERR_CHANOPRIVSNEEDED
),
1325 me
.name
, source_p
->name
, chptr
->chname
);
1326 *errors
|= SM_ERR_NOOPS
;
1330 if(dir
== MODE_QUERY
)
1333 if(MyClient(source_p
) && (++mode_limit_simple
> MAXMODES_SIMPLE
))
1336 if((dir
== MODE_ADD
) && parc
> *parn
)
1338 key
= LOCAL_COPY(parv
[(*parn
)]);
1341 if(MyClient(source_p
))
1344 fix_key_remote(key
);
1346 if(EmptyString(key
))
1349 s_assert(key
[0] != ' ');
1350 rb_strlcpy(chptr
->mode
.key
, key
, sizeof(chptr
->mode
.key
));
1352 mode_changes
[mode_count
].letter
= c
;
1353 mode_changes
[mode_count
].dir
= MODE_ADD
;
1354 mode_changes
[mode_count
].caps
= 0;
1355 mode_changes
[mode_count
].nocaps
= 0;
1356 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
1357 mode_changes
[mode_count
].id
= NULL
;
1358 mode_changes
[mode_count
++].arg
= chptr
->mode
.key
;
1360 else if(dir
== MODE_DEL
)
1362 static char splat
[] = "*";
1368 if(!(*chptr
->mode
.key
))
1371 /* hack time. when we get a +k-k mode, the +k arg is
1372 * chptr->mode.key, which the -k sets to \0, so hunt for a
1373 * +k when we get a -k, and set the arg to splat. --anfl
1375 for(i
= 0; i
< mode_count
; i
++)
1377 if(mode_changes
[i
].letter
== 'k' && mode_changes
[i
].dir
== MODE_ADD
)
1378 mode_changes
[i
].arg
= splat
;
1381 *chptr
->mode
.key
= 0;
1383 mode_changes
[mode_count
].letter
= c
;
1384 mode_changes
[mode_count
].dir
= MODE_DEL
;
1385 mode_changes
[mode_count
].caps
= 0;
1386 mode_changes
[mode_count
].nocaps
= 0;
1387 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
1388 mode_changes
[mode_count
].id
= NULL
;
1389 mode_changes
[mode_count
++].arg
= "*";
1394 struct ChannelMode chmode_table
[256] =
1396 {chm_nosuch
, 0 }, /* 0x00 */
1397 {chm_nosuch
, 0 }, /* 0x01 */
1398 {chm_nosuch
, 0 }, /* 0x02 */
1399 {chm_nosuch
, 0 }, /* 0x03 */
1400 {chm_nosuch
, 0 }, /* 0x04 */
1401 {chm_nosuch
, 0 }, /* 0x05 */
1402 {chm_nosuch
, 0 }, /* 0x06 */
1403 {chm_nosuch
, 0 }, /* 0x07 */
1404 {chm_nosuch
, 0 }, /* 0x08 */
1405 {chm_nosuch
, 0 }, /* 0x09 */
1406 {chm_nosuch
, 0 }, /* 0x0a */
1407 {chm_nosuch
, 0 }, /* 0x0b */
1408 {chm_nosuch
, 0 }, /* 0x0c */
1409 {chm_nosuch
, 0 }, /* 0x0d */
1410 {chm_nosuch
, 0 }, /* 0x0e */
1411 {chm_nosuch
, 0 }, /* 0x0f */
1412 {chm_nosuch
, 0 }, /* 0x10 */
1413 {chm_nosuch
, 0 }, /* 0x11 */
1414 {chm_nosuch
, 0 }, /* 0x12 */
1415 {chm_nosuch
, 0 }, /* 0x13 */
1416 {chm_nosuch
, 0 }, /* 0x14 */
1417 {chm_nosuch
, 0 }, /* 0x15 */
1418 {chm_nosuch
, 0 }, /* 0x16 */
1419 {chm_nosuch
, 0 }, /* 0x17 */
1420 {chm_nosuch
, 0 }, /* 0x18 */
1421 {chm_nosuch
, 0 }, /* 0x19 */
1422 {chm_nosuch
, 0 }, /* 0x1a */
1423 {chm_nosuch
, 0 }, /* 0x1b */
1424 {chm_nosuch
, 0 }, /* 0x1c */
1425 {chm_nosuch
, 0 }, /* 0x1d */
1426 {chm_nosuch
, 0 }, /* 0x1e */
1427 {chm_nosuch
, 0 }, /* 0x1f */
1428 {chm_nosuch
, 0 }, /* 0x20 */
1429 {chm_nosuch
, 0 }, /* 0x21 */
1430 {chm_nosuch
, 0 }, /* 0x22 */
1431 {chm_nosuch
, 0 }, /* 0x23 */
1432 {chm_nosuch
, 0 }, /* 0x24 */
1433 {chm_nosuch
, 0 }, /* 0x25 */
1434 {chm_nosuch
, 0 }, /* 0x26 */
1435 {chm_nosuch
, 0 }, /* 0x27 */
1436 {chm_nosuch
, 0 }, /* 0x28 */
1437 {chm_nosuch
, 0 }, /* 0x29 */
1438 {chm_nosuch
, 0 }, /* 0x2a */
1439 {chm_nosuch
, 0 }, /* 0x2b */
1440 {chm_nosuch
, 0 }, /* 0x2c */
1441 {chm_nosuch
, 0 }, /* 0x2d */
1442 {chm_nosuch
, 0 }, /* 0x2e */
1443 {chm_nosuch
, 0 }, /* 0x2f */
1444 {chm_nosuch
, 0 }, /* 0x30 */
1445 {chm_nosuch
, 0 }, /* 0x31 */
1446 {chm_nosuch
, 0 }, /* 0x32 */
1447 {chm_nosuch
, 0 }, /* 0x33 */
1448 {chm_nosuch
, 0 }, /* 0x34 */
1449 {chm_nosuch
, 0 }, /* 0x35 */
1450 {chm_nosuch
, 0 }, /* 0x36 */
1451 {chm_nosuch
, 0 }, /* 0x37 */
1452 {chm_nosuch
, 0 }, /* 0x38 */
1453 {chm_nosuch
, 0 }, /* 0x39 */
1454 {chm_nosuch
, 0 }, /* 0x3a */
1455 {chm_nosuch
, 0 }, /* 0x3b */
1456 {chm_nosuch
, 0 }, /* 0x3c */
1457 {chm_nosuch
, 0 }, /* 0x3d */
1458 {chm_nosuch
, 0 }, /* 0x3e */
1459 {chm_nosuch
, 0 }, /* 0x3f */
1461 {chm_nosuch
, 0 }, /* @ */
1462 {chm_nosuch
, 0 }, /* A */
1463 {chm_nosuch
, 0 }, /* B */
1464 {chm_simple
, MODE_NOCTCP
}, /* C */
1465 {chm_nosuch
, 0 }, /* D */
1466 {chm_nosuch
, 0 }, /* E */
1467 {chm_simple
, MODE_FREETARGET
}, /* F */
1468 {chm_nosuch
, 0 }, /* G */
1469 {chm_nosuch
, 0 }, /* H */
1470 {chm_ban
, CHFL_INVEX
}, /* I */
1471 {chm_nosuch
, 0 }, /* J */
1472 {chm_nosuch
, 0 }, /* K */
1473 {chm_staff
, MODE_EXLIMIT
}, /* L */
1474 {chm_nosuch
, 0 }, /* M */
1475 {chm_nosuch
, 0 }, /* N */
1476 {chm_nosuch
, 0 }, /* O */
1477 {chm_staff
, MODE_PERMANENT
}, /* P */
1478 {chm_simple
, MODE_DISFORWARD
}, /* Q */
1479 {chm_nosuch
, 0 }, /* R */
1480 {chm_nosuch
, 0 }, /* S */
1481 {chm_nosuch
, 0 }, /* T */
1482 {chm_nosuch
, 0 }, /* U */
1483 {chm_nosuch
, 0 }, /* V */
1484 {chm_nosuch
, 0 }, /* W */
1485 {chm_nosuch
, 0 }, /* X */
1486 {chm_nosuch
, 0 }, /* Y */
1487 {chm_nosuch
, 0 }, /* Z */
1494 {chm_nosuch
, 0 }, /* a */
1495 {chm_ban
, CHFL_BAN
}, /* b */
1496 {chm_simple
, MODE_NOCOLOR
}, /* c */
1497 {chm_nosuch
, 0 }, /* d */
1498 {chm_ban
, CHFL_EXCEPTION
}, /* e */
1499 {chm_forward
, 0 }, /* f */
1500 {chm_simple
, MODE_FREEINVITE
}, /* g */
1501 {chm_nosuch
, 0 }, /* h */
1502 {chm_simple
, MODE_INVITEONLY
}, /* i */
1503 {chm_throttle
, 0 }, /* j */
1504 {chm_key
, 0 }, /* k */
1505 {chm_limit
, 0 }, /* l */
1506 {chm_simple
, MODE_MODERATED
}, /* m */
1507 {chm_simple
, MODE_NOPRIVMSGS
}, /* n */
1508 {chm_op
, 0 }, /* o */
1509 {chm_simple
, MODE_PRIVATE
}, /* p */
1510 {chm_ban
, CHFL_QUIET
}, /* q */
1511 {chm_simple
, MODE_REGONLY
}, /* r */
1512 {chm_simple
, MODE_SECRET
}, /* s */
1513 {chm_simple
, MODE_TOPICLIMIT
}, /* t */
1514 {chm_nosuch
, 0 }, /* u */
1515 {chm_voice
, 0 }, /* v */
1516 {chm_nosuch
, 0 }, /* w */
1517 {chm_nosuch
, 0 }, /* x */
1518 {chm_nosuch
, 0 }, /* y */
1519 {chm_simple
, MODE_OPMODERATE
}, /* z */
1521 {chm_nosuch
, 0 }, /* 0x7b */
1522 {chm_nosuch
, 0 }, /* 0x7c */
1523 {chm_nosuch
, 0 }, /* 0x7d */
1524 {chm_nosuch
, 0 }, /* 0x7e */
1525 {chm_nosuch
, 0 }, /* 0x7f */
1527 {chm_nosuch
, 0 }, /* 0x80 */
1528 {chm_nosuch
, 0 }, /* 0x81 */
1529 {chm_nosuch
, 0 }, /* 0x82 */
1530 {chm_nosuch
, 0 }, /* 0x83 */
1531 {chm_nosuch
, 0 }, /* 0x84 */
1532 {chm_nosuch
, 0 }, /* 0x85 */
1533 {chm_nosuch
, 0 }, /* 0x86 */
1534 {chm_nosuch
, 0 }, /* 0x87 */
1535 {chm_nosuch
, 0 }, /* 0x88 */
1536 {chm_nosuch
, 0 }, /* 0x89 */
1537 {chm_nosuch
, 0 }, /* 0x8a */
1538 {chm_nosuch
, 0 }, /* 0x8b */
1539 {chm_nosuch
, 0 }, /* 0x8c */
1540 {chm_nosuch
, 0 }, /* 0x8d */
1541 {chm_nosuch
, 0 }, /* 0x8e */
1542 {chm_nosuch
, 0 }, /* 0x8f */
1544 {chm_nosuch
, 0 }, /* 0x90 */
1545 {chm_nosuch
, 0 }, /* 0x91 */
1546 {chm_nosuch
, 0 }, /* 0x92 */
1547 {chm_nosuch
, 0 }, /* 0x93 */
1548 {chm_nosuch
, 0 }, /* 0x94 */
1549 {chm_nosuch
, 0 }, /* 0x95 */
1550 {chm_nosuch
, 0 }, /* 0x96 */
1551 {chm_nosuch
, 0 }, /* 0x97 */
1552 {chm_nosuch
, 0 }, /* 0x98 */
1553 {chm_nosuch
, 0 }, /* 0x99 */
1554 {chm_nosuch
, 0 }, /* 0x9a */
1555 {chm_nosuch
, 0 }, /* 0x9b */
1556 {chm_nosuch
, 0 }, /* 0x9c */
1557 {chm_nosuch
, 0 }, /* 0x9d */
1558 {chm_nosuch
, 0 }, /* 0x9e */
1559 {chm_nosuch
, 0 }, /* 0x9f */
1561 {chm_nosuch
, 0 }, /* 0xa0 */
1562 {chm_nosuch
, 0 }, /* 0xa1 */
1563 {chm_nosuch
, 0 }, /* 0xa2 */
1564 {chm_nosuch
, 0 }, /* 0xa3 */
1565 {chm_nosuch
, 0 }, /* 0xa4 */
1566 {chm_nosuch
, 0 }, /* 0xa5 */
1567 {chm_nosuch
, 0 }, /* 0xa6 */
1568 {chm_nosuch
, 0 }, /* 0xa7 */
1569 {chm_nosuch
, 0 }, /* 0xa8 */
1570 {chm_nosuch
, 0 }, /* 0xa9 */
1571 {chm_nosuch
, 0 }, /* 0xaa */
1572 {chm_nosuch
, 0 }, /* 0xab */
1573 {chm_nosuch
, 0 }, /* 0xac */
1574 {chm_nosuch
, 0 }, /* 0xad */
1575 {chm_nosuch
, 0 }, /* 0xae */
1576 {chm_nosuch
, 0 }, /* 0xaf */
1578 {chm_nosuch
, 0 }, /* 0xb0 */
1579 {chm_nosuch
, 0 }, /* 0xb1 */
1580 {chm_nosuch
, 0 }, /* 0xb2 */
1581 {chm_nosuch
, 0 }, /* 0xb3 */
1582 {chm_nosuch
, 0 }, /* 0xb4 */
1583 {chm_nosuch
, 0 }, /* 0xb5 */
1584 {chm_nosuch
, 0 }, /* 0xb6 */
1585 {chm_nosuch
, 0 }, /* 0xb7 */
1586 {chm_nosuch
, 0 }, /* 0xb8 */
1587 {chm_nosuch
, 0 }, /* 0xb9 */
1588 {chm_nosuch
, 0 }, /* 0xba */
1589 {chm_nosuch
, 0 }, /* 0xbb */
1590 {chm_nosuch
, 0 }, /* 0xbc */
1591 {chm_nosuch
, 0 }, /* 0xbd */
1592 {chm_nosuch
, 0 }, /* 0xbe */
1593 {chm_nosuch
, 0 }, /* 0xbf */
1595 {chm_nosuch
, 0 }, /* 0xc0 */
1596 {chm_nosuch
, 0 }, /* 0xc1 */
1597 {chm_nosuch
, 0 }, /* 0xc2 */
1598 {chm_nosuch
, 0 }, /* 0xc3 */
1599 {chm_nosuch
, 0 }, /* 0xc4 */
1600 {chm_nosuch
, 0 }, /* 0xc5 */
1601 {chm_nosuch
, 0 }, /* 0xc6 */
1602 {chm_nosuch
, 0 }, /* 0xc7 */
1603 {chm_nosuch
, 0 }, /* 0xc8 */
1604 {chm_nosuch
, 0 }, /* 0xc9 */
1605 {chm_nosuch
, 0 }, /* 0xca */
1606 {chm_nosuch
, 0 }, /* 0xcb */
1607 {chm_nosuch
, 0 }, /* 0xcc */
1608 {chm_nosuch
, 0 }, /* 0xcd */
1609 {chm_nosuch
, 0 }, /* 0xce */
1610 {chm_nosuch
, 0 }, /* 0xcf */
1612 {chm_nosuch
, 0 }, /* 0xd0 */
1613 {chm_nosuch
, 0 }, /* 0xd1 */
1614 {chm_nosuch
, 0 }, /* 0xd2 */
1615 {chm_nosuch
, 0 }, /* 0xd3 */
1616 {chm_nosuch
, 0 }, /* 0xd4 */
1617 {chm_nosuch
, 0 }, /* 0xd5 */
1618 {chm_nosuch
, 0 }, /* 0xd6 */
1619 {chm_nosuch
, 0 }, /* 0xd7 */
1620 {chm_nosuch
, 0 }, /* 0xd8 */
1621 {chm_nosuch
, 0 }, /* 0xd9 */
1622 {chm_nosuch
, 0 }, /* 0xda */
1623 {chm_nosuch
, 0 }, /* 0xdb */
1624 {chm_nosuch
, 0 }, /* 0xdc */
1625 {chm_nosuch
, 0 }, /* 0xdd */
1626 {chm_nosuch
, 0 }, /* 0xde */
1627 {chm_nosuch
, 0 }, /* 0xdf */
1629 {chm_nosuch
, 0 }, /* 0xe0 */
1630 {chm_nosuch
, 0 }, /* 0xe1 */
1631 {chm_nosuch
, 0 }, /* 0xe2 */
1632 {chm_nosuch
, 0 }, /* 0xe3 */
1633 {chm_nosuch
, 0 }, /* 0xe4 */
1634 {chm_nosuch
, 0 }, /* 0xe5 */
1635 {chm_nosuch
, 0 }, /* 0xe6 */
1636 {chm_nosuch
, 0 }, /* 0xe7 */
1637 {chm_nosuch
, 0 }, /* 0xe8 */
1638 {chm_nosuch
, 0 }, /* 0xe9 */
1639 {chm_nosuch
, 0 }, /* 0xea */
1640 {chm_nosuch
, 0 }, /* 0xeb */
1641 {chm_nosuch
, 0 }, /* 0xec */
1642 {chm_nosuch
, 0 }, /* 0xed */
1643 {chm_nosuch
, 0 }, /* 0xee */
1644 {chm_nosuch
, 0 }, /* 0xef */
1646 {chm_nosuch
, 0 }, /* 0xf0 */
1647 {chm_nosuch
, 0 }, /* 0xf1 */
1648 {chm_nosuch
, 0 }, /* 0xf2 */
1649 {chm_nosuch
, 0 }, /* 0xf3 */
1650 {chm_nosuch
, 0 }, /* 0xf4 */
1651 {chm_nosuch
, 0 }, /* 0xf5 */
1652 {chm_nosuch
, 0 }, /* 0xf6 */
1653 {chm_nosuch
, 0 }, /* 0xf7 */
1654 {chm_nosuch
, 0 }, /* 0xf8 */
1655 {chm_nosuch
, 0 }, /* 0xf9 */
1656 {chm_nosuch
, 0 }, /* 0xfa */
1657 {chm_nosuch
, 0 }, /* 0xfb */
1658 {chm_nosuch
, 0 }, /* 0xfc */
1659 {chm_nosuch
, 0 }, /* 0xfd */
1660 {chm_nosuch
, 0 }, /* 0xfe */
1661 {chm_nosuch
, 0 }, /* 0xff */
1666 /* set_channel_mode()
1668 * inputs - client, source, channel, membership pointer, params
1670 * side effects - channel modes/memberships are changed, MODE is issued
1672 * Extensively modified to be hotpluggable, 03/09/06 -- nenolod
1675 set_channel_mode(struct Client
*client_p
, struct Client
*source_p
,
1676 struct Channel
*chptr
, struct membership
*msptr
, int parc
, const char *parv
[])
1678 static char modebuf
[BUFSIZE
];
1679 static char parabuf
[BUFSIZE
];
1682 int cur_len
, mlen
, paralen
, paracount
, arglen
, len
;
1688 const char *ml
= parv
[0];
1690 struct Client
*fakesource_p
;
1693 removed_mask_pos
= 0;
1696 mode_limit_simple
= 0;
1698 alevel
= get_channel_access(source_p
, msptr
);
1700 /* Hide connecting server on netburst -- jilles */
1701 if (ConfigServerHide
.flatten_links
&& IsServer(source_p
) && !has_id(source_p
) && !HasSentEob(source_p
))
1704 fakesource_p
= source_p
;
1706 for(; (c
= *ml
) != 0; ml
++)
1720 /* If this mode char is locked, don't allow local users to change it. */
1721 if (MyClient(source_p
) && chptr
->mode_lock
&& strchr(chptr
->mode_lock
, c
))
1723 if (!(errors
& SM_ERR_MLOCK
))
1724 sendto_one_numeric(source_p
,
1725 ERR_MLOCKRESTRICTED
,
1726 form_str(ERR_MLOCKRESTRICTED
),
1730 errors
|= SM_ERR_MLOCK
;
1733 chmode_table
[(unsigned char) c
].set_func(fakesource_p
, chptr
, alevel
,
1736 chmode_table
[(unsigned char) c
].mode_type
);
1741 /* bail out if we have nothing to do... */
1745 if(IsServer(source_p
))
1746 mlen
= rb_sprintf(modebuf
, ":%s MODE %s ", fakesource_p
->name
, chptr
->chname
);
1748 mlen
= rb_sprintf(modebuf
, ":%s!%s@%s MODE %s ",
1749 source_p
->name
, source_p
->username
,
1750 source_p
->host
, chptr
->chname
);
1752 for(j
= 0, flags
= ALL_MEMBERS
; j
< 2; j
++, flags
= ONLY_CHANOPS
)
1755 mbuf
= modebuf
+ mlen
;
1758 paracount
= paralen
= 0;
1761 for(i
= 0; i
< mode_count
; i
++)
1763 if(mode_changes
[i
].letter
== 0 || mode_changes
[i
].mems
!= flags
)
1766 if(mode_changes
[i
].arg
!= NULL
)
1768 arglen
= strlen(mode_changes
[i
].arg
);
1770 if(arglen
> MODEBUFLEN
- 5)
1776 /* if we're creeping over MAXMODEPARAMSSERV, or over
1777 * bufsize (4 == +/-,modechar,two spaces) send now.
1779 if(mode_changes
[i
].arg
!= NULL
&&
1780 ((paracount
== MAXMODEPARAMSSERV
) ||
1781 ((cur_len
+ paralen
+ arglen
+ 4) > (BUFSIZE
- 3))))
1786 sendto_channel_local(flags
, chptr
, "%s %s", modebuf
,
1791 paracount
= paralen
= 0;
1793 mbuf
= modebuf
+ mlen
;
1799 if(dir
!= mode_changes
[i
].dir
)
1801 *mbuf
++ = (mode_changes
[i
].dir
== MODE_ADD
) ? '+' : '-';
1803 dir
= mode_changes
[i
].dir
;
1806 *mbuf
++ = mode_changes
[i
].letter
;
1809 if(mode_changes
[i
].arg
!= NULL
)
1812 len
= rb_sprintf(pbuf
, "%s ", mode_changes
[i
].arg
);
1818 if(paralen
&& parabuf
[paralen
- 1] == ' ')
1819 parabuf
[paralen
- 1] = '\0';
1823 sendto_channel_local(flags
, chptr
, "%s %s", modebuf
, parabuf
);
1826 /* only propagate modes originating locally, or if we're hubbing */
1827 if(MyClient(source_p
) || rb_dlink_list_length(&serv_list
) > 1)
1828 send_cap_mode_changes(client_p
, source_p
, chptr
, mode_changes
, mode_count
);
1831 /* set_channel_mlock()
1833 * inputs - client, source, channel, params
1835 * side effects - channel mlock is changed / MLOCK is propagated
1838 set_channel_mlock(struct Client
*client_p
, struct Client
*source_p
,
1839 struct Channel
*chptr
, const char *newmlock
, int propagate
)
1841 rb_free(chptr
->mode_lock
);
1842 chptr
->mode_lock
= newmlock
? rb_strdup(newmlock
) : NULL
;
1846 sendto_server(client_p
, NULL
, CAP_TS6
| CAP_MLOCK
, NOCAPS
, ":%s MLOCK %ld %s :%s",
1847 source_p
->id
, (long) chptr
->channelts
, chptr
->chname
,
1848 chptr
->mode_lock
? chptr
->mode_lock
: "");