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
;
471 * output - the same key, fixed
472 * side effects - anything below ascii 13 is discarded, ':' discarded,
473 * high ascii is dropped to lower half of ascii table
480 for(s
= t
= (u_char
*) arg
; (c
= *s
); s
++)
483 if(c
!= ':' && c
!= ',' && c
> ' ')
494 * ouput - the same key, fixed
495 * side effects - high ascii dropped to lower half of table,
496 * CR/LF/':' are dropped
499 fix_key_remote(char *arg
)
503 for(s
= t
= (u_char
*) arg
; (c
= *s
); s
++)
506 if((c
!= 0x0a) && (c
!= ':') && (c
!= ',') && (c
!= 0x0d) && (c
!= ' '))
516 * The handlers for each specific mode.
519 chm_nosuch(struct Client
*source_p
, struct Channel
*chptr
,
520 int alevel
, int parc
, int *parn
,
521 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
523 if(*errors
& SM_ERR_UNKNOWN
)
525 *errors
|= SM_ERR_UNKNOWN
;
526 sendto_one(source_p
, form_str(ERR_UNKNOWNMODE
), me
.name
, source_p
->name
, c
);
530 chm_simple(struct Client
*source_p
, struct Channel
*chptr
,
531 int alevel
, int parc
, int *parn
,
532 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
534 if(alevel
!= CHFL_CHANOP
)
536 if(!(*errors
& SM_ERR_NOOPS
))
537 sendto_one(source_p
, form_str(ERR_CHANOPRIVSNEEDED
),
538 me
.name
, source_p
->name
, chptr
->chname
);
539 *errors
|= SM_ERR_NOOPS
;
543 if(MyClient(source_p
) && (++mode_limit_simple
> MAXMODES_SIMPLE
))
547 if((dir
== MODE_ADD
) && !(chptr
->mode
.mode
& mode_type
))
549 /* if +f is disabled, ignore an attempt to set +QF locally */
550 if(!ConfigChannel
.use_forward
&& MyClient(source_p
) &&
551 (c
== 'Q' || c
== 'F'))
554 chptr
->mode
.mode
|= mode_type
;
556 mode_changes
[mode_count
].letter
= c
;
557 mode_changes
[mode_count
].dir
= MODE_ADD
;
558 mode_changes
[mode_count
].caps
= 0;
559 mode_changes
[mode_count
].nocaps
= 0;
560 mode_changes
[mode_count
].id
= NULL
;
561 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
562 mode_changes
[mode_count
++].arg
= NULL
;
564 else if((dir
== MODE_DEL
) && (chptr
->mode
.mode
& mode_type
))
566 chptr
->mode
.mode
&= ~mode_type
;
568 mode_changes
[mode_count
].letter
= c
;
569 mode_changes
[mode_count
].dir
= MODE_DEL
;
570 mode_changes
[mode_count
].caps
= 0;
571 mode_changes
[mode_count
].nocaps
= 0;
572 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
573 mode_changes
[mode_count
].id
= NULL
;
574 mode_changes
[mode_count
++].arg
= NULL
;
579 chm_orphaned(struct Client
*source_p
, struct Channel
*chptr
,
580 int alevel
, int parc
, int *parn
,
581 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
583 if(MyClient(source_p
))
586 if((dir
== MODE_ADD
) && !(chptr
->mode
.mode
& mode_type
))
588 chptr
->mode
.mode
|= mode_type
;
590 mode_changes
[mode_count
].letter
= c
;
591 mode_changes
[mode_count
].dir
= MODE_ADD
;
592 mode_changes
[mode_count
].caps
= 0;
593 mode_changes
[mode_count
].nocaps
= 0;
594 mode_changes
[mode_count
].id
= NULL
;
595 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
596 mode_changes
[mode_count
++].arg
= NULL
;
598 else if((dir
== MODE_DEL
) && (chptr
->mode
.mode
& mode_type
))
600 chptr
->mode
.mode
&= ~mode_type
;
602 mode_changes
[mode_count
].letter
= c
;
603 mode_changes
[mode_count
].dir
= MODE_DEL
;
604 mode_changes
[mode_count
].caps
= 0;
605 mode_changes
[mode_count
].nocaps
= 0;
606 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
607 mode_changes
[mode_count
].id
= NULL
;
608 mode_changes
[mode_count
++].arg
= NULL
;
613 chm_staff(struct Client
*source_p
, struct Channel
*chptr
,
614 int alevel
, int parc
, int *parn
,
615 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
617 if(!IsOper(source_p
) && !IsServer(source_p
))
619 if(!(*errors
& SM_ERR_NOPRIVS
))
620 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
, form_str(ERR_NOPRIVILEGES
));
621 *errors
|= SM_ERR_NOPRIVS
;
624 if(MyClient(source_p
) && !IsOperResv(source_p
))
626 if(!(*errors
& SM_ERR_NOPRIVS
))
627 sendto_one(source_p
, form_str(ERR_NOPRIVS
), me
.name
,
628 source_p
->name
, "resv");
629 *errors
|= SM_ERR_NOPRIVS
;
633 if(MyClient(source_p
) && (++mode_limit_simple
> MAXMODES_SIMPLE
))
637 if((dir
== MODE_ADD
) && !(chptr
->mode
.mode
& mode_type
))
639 chptr
->mode
.mode
|= mode_type
;
641 mode_changes
[mode_count
].letter
= c
;
642 mode_changes
[mode_count
].dir
= MODE_ADD
;
643 mode_changes
[mode_count
].caps
= 0;
644 mode_changes
[mode_count
].nocaps
= 0;
645 mode_changes
[mode_count
].id
= NULL
;
646 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
647 mode_changes
[mode_count
++].arg
= NULL
;
649 else if((dir
== MODE_DEL
) && (chptr
->mode
.mode
& mode_type
))
651 chptr
->mode
.mode
&= ~mode_type
;
653 mode_changes
[mode_count
].letter
= c
;
654 mode_changes
[mode_count
].dir
= MODE_DEL
;
655 mode_changes
[mode_count
].caps
= 0;
656 mode_changes
[mode_count
].nocaps
= 0;
657 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
658 mode_changes
[mode_count
].id
= NULL
;
659 mode_changes
[mode_count
++].arg
= NULL
;
664 chm_ban(struct Client
*source_p
, struct Channel
*chptr
,
665 int alevel
, int parc
, int *parn
,
666 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
668 char *mask
, *raw_mask
, *forward
;
681 list
= &chptr
->banlist
;
682 errorval
= SM_ERR_RPL_B
;
683 rpl_list
= RPL_BANLIST
;
684 rpl_endlist
= RPL_ENDOFBANLIST
;
690 /* if +e is disabled, allow all but +e locally */
691 if(!ConfigChannel
.use_except
&& MyClient(source_p
) &&
692 ((dir
== MODE_ADD
) && (parc
> *parn
)))
695 list
= &chptr
->exceptlist
;
696 errorval
= SM_ERR_RPL_E
;
697 rpl_list
= RPL_EXCEPTLIST
;
698 rpl_endlist
= RPL_ENDOFEXCEPTLIST
;
701 if(ConfigChannel
.use_except
|| (dir
== MODE_DEL
))
708 /* if +I is disabled, allow all but +I locally */
709 if(!ConfigChannel
.use_invex
&& MyClient(source_p
) &&
710 (dir
== MODE_ADD
) && (parc
> *parn
))
713 list
= &chptr
->invexlist
;
714 errorval
= SM_ERR_RPL_I
;
715 rpl_list
= RPL_INVITELIST
;
716 rpl_endlist
= RPL_ENDOFINVITELIST
;
719 if(ConfigChannel
.use_invex
|| (dir
== MODE_DEL
))
726 list
= &chptr
->quietlist
;
727 errorval
= SM_ERR_RPL_Q
;
728 rpl_list
= RPL_QUIETLIST
;
729 rpl_endlist
= RPL_ENDOFQUIETLIST
;
735 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "chm_ban() called with unknown type!");
740 if(dir
== 0 || parc
<= *parn
)
742 if((*errors
& errorval
) != 0)
746 /* non-ops cant see +eI lists.. */
747 if(alevel
!= CHFL_CHANOP
&& mode_type
!= CHFL_BAN
&&
748 mode_type
!= CHFL_QUIET
)
750 if(!(*errors
& SM_ERR_NOOPS
))
751 sendto_one(source_p
, form_str(ERR_CHANOPRIVSNEEDED
),
752 me
.name
, source_p
->name
, chptr
->chname
);
753 *errors
|= SM_ERR_NOOPS
;
757 RB_DLINK_FOREACH(ptr
, list
->head
)
762 rb_snprintf(buf
, sizeof(buf
), "%s$%s", banptr
->banstr
, banptr
->forward
);
764 rb_strlcpy(buf
, banptr
->banstr
, sizeof(buf
));
766 sendto_one(source_p
, form_str(rpl_list
),
767 me
.name
, source_p
->name
, chptr
->chname
,
768 buf
, banptr
->who
, banptr
->when
);
770 sendto_one(source_p
, form_str(rpl_endlist
), me
.name
, source_p
->name
, chptr
->chname
);
774 if(alevel
!= CHFL_CHANOP
)
776 if(!(*errors
& SM_ERR_NOOPS
))
777 sendto_one(source_p
, form_str(ERR_CHANOPRIVSNEEDED
),
778 me
.name
, source_p
->name
, chptr
->chname
);
779 *errors
|= SM_ERR_NOOPS
;
783 if(MyClient(source_p
) && (++mode_limit
> MAXMODEPARAMS
))
786 raw_mask
= parv
[(*parn
)];
789 /* empty ban, or starts with ':' which messes up s2s, ignore it */
790 if(EmptyString(raw_mask
) || *raw_mask
== ':')
793 if(!MyClient(source_p
))
795 if(strchr(raw_mask
, ' '))
801 mask
= pretty_mask(raw_mask
);
803 /* we'd have problems parsing this, hyb6 does it too
804 * also make sure it will always fit on a line with channel
807 if(strlen(mask
) > IRCD_MIN(BANLEN
, MODEBUFLEN
- 5))
810 /* Look for a $ after the first character.
811 * As the first character, it marks an extban; afterwards
812 * it delimits a forward channel.
814 if ((forward
= strchr(mask
+1, '$')) != NULL
)
817 if (*forward
== '\0')
821 /* if we're adding a NEW id */
824 if (*mask
== '$' && MyClient(source_p
))
826 if (!valid_extban(mask
, source_p
, chptr
, mode_type
))
827 /* XXX perhaps return an error message here */
831 if(forward
!= NULL
&& !ConfigChannel
.use_forward
&&
835 /* dont allow local clients to overflow the banlist, dont
836 * let remote servers set duplicate bans
838 if(!add_id(source_p
, chptr
, mask
, forward
, list
, mode_type
))
844 mode_changes
[mode_count
].letter
= c
;
845 mode_changes
[mode_count
].dir
= MODE_ADD
;
846 mode_changes
[mode_count
].caps
= caps
;
847 mode_changes
[mode_count
].nocaps
= 0;
848 mode_changes
[mode_count
].mems
= mems
;
849 mode_changes
[mode_count
].id
= NULL
;
850 mode_changes
[mode_count
++].arg
= mask
;
852 else if(dir
== MODE_DEL
)
855 static char buf
[BANLEN
* MAXMODEPARAMS
];
856 int old_removed_mask_pos
= removed_mask_pos
;
857 if((removed
= del_id(chptr
, mask
, list
, mode_type
)) == NULL
)
859 /* mask isn't a valid ban, check raw_mask */
860 if((removed
= del_id(chptr
, raw_mask
, list
, mode_type
)) != NULL
)
864 if(removed
&& removed
->forward
)
865 removed_mask_pos
+= rb_snprintf(buf
, sizeof(buf
), "%s$%s", removed
->banstr
, removed
->forward
);
867 removed_mask_pos
+= rb_strlcpy(buf
, mask
, sizeof(buf
));
874 mode_changes
[mode_count
].letter
= c
;
875 mode_changes
[mode_count
].dir
= MODE_DEL
;
876 mode_changes
[mode_count
].caps
= caps
;
877 mode_changes
[mode_count
].nocaps
= 0;
878 mode_changes
[mode_count
].mems
= mems
;
879 mode_changes
[mode_count
].id
= NULL
;
880 mode_changes
[mode_count
++].arg
= buf
+ old_removed_mask_pos
;
885 chm_op(struct Client
*source_p
, struct Channel
*chptr
,
886 int alevel
, int parc
, int *parn
,
887 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
889 struct membership
*mstptr
;
891 struct Client
*targ_p
;
893 if(alevel
!= CHFL_CHANOP
)
895 if(!(*errors
& SM_ERR_NOOPS
))
896 sendto_one(source_p
, form_str(ERR_CHANOPRIVSNEEDED
),
897 me
.name
, source_p
->name
, chptr
->chname
);
898 *errors
|= SM_ERR_NOOPS
;
902 if((dir
== MODE_QUERY
) || (parc
<= *parn
))
905 opnick
= parv
[(*parn
)];
909 if(EmptyString(opnick
))
911 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
, form_str(ERR_NOSUCHNICK
), "*");
915 if((targ_p
= find_chasing(source_p
, opnick
, NULL
)) == NULL
)
920 mstptr
= find_channel_membership(chptr
, targ_p
);
924 if(!(*errors
& SM_ERR_NOTONCHANNEL
) && MyClient(source_p
))
925 sendto_one_numeric(source_p
, ERR_USERNOTINCHANNEL
,
926 form_str(ERR_USERNOTINCHANNEL
), opnick
, chptr
->chname
);
927 *errors
|= SM_ERR_NOTONCHANNEL
;
931 if(MyClient(source_p
) && (++mode_limit
> MAXMODEPARAMS
))
936 if(targ_p
== source_p
&& mstptr
->flags
& CHFL_CHANOP
)
939 mode_changes
[mode_count
].letter
= c
;
940 mode_changes
[mode_count
].dir
= MODE_ADD
;
941 mode_changes
[mode_count
].caps
= 0;
942 mode_changes
[mode_count
].nocaps
= 0;
943 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
944 mode_changes
[mode_count
].id
= targ_p
->id
;
945 mode_changes
[mode_count
].arg
= targ_p
->name
;
946 mode_changes
[mode_count
++].client
= targ_p
;
948 mstptr
->flags
|= CHFL_CHANOP
;
952 if(MyClient(source_p
) && IsService(targ_p
))
954 sendto_one(source_p
, form_str(ERR_ISCHANSERVICE
),
955 me
.name
, source_p
->name
, targ_p
->name
, chptr
->chname
);
959 mode_changes
[mode_count
].letter
= c
;
960 mode_changes
[mode_count
].dir
= MODE_DEL
;
961 mode_changes
[mode_count
].caps
= 0;
962 mode_changes
[mode_count
].nocaps
= 0;
963 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
964 mode_changes
[mode_count
].id
= targ_p
->id
;
965 mode_changes
[mode_count
].arg
= targ_p
->name
;
966 mode_changes
[mode_count
++].client
= targ_p
;
968 mstptr
->flags
&= ~CHFL_CHANOP
;
973 chm_voice(struct Client
*source_p
, struct Channel
*chptr
,
974 int alevel
, int parc
, int *parn
,
975 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
977 struct membership
*mstptr
;
979 struct Client
*targ_p
;
981 if(alevel
!= CHFL_CHANOP
)
983 if(!(*errors
& SM_ERR_NOOPS
))
984 sendto_one(source_p
, form_str(ERR_CHANOPRIVSNEEDED
),
985 me
.name
, source_p
->name
, chptr
->chname
);
986 *errors
|= SM_ERR_NOOPS
;
990 if((dir
== MODE_QUERY
) || parc
<= *parn
)
993 opnick
= parv
[(*parn
)];
997 if(EmptyString(opnick
))
999 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
, form_str(ERR_NOSUCHNICK
), "*");
1003 if((targ_p
= find_chasing(source_p
, opnick
, NULL
)) == NULL
)
1008 mstptr
= find_channel_membership(chptr
, targ_p
);
1012 if(!(*errors
& SM_ERR_NOTONCHANNEL
) && MyClient(source_p
))
1013 sendto_one_numeric(source_p
, ERR_USERNOTINCHANNEL
,
1014 form_str(ERR_USERNOTINCHANNEL
), opnick
, chptr
->chname
);
1015 *errors
|= SM_ERR_NOTONCHANNEL
;
1019 if(MyClient(source_p
) && (++mode_limit
> MAXMODEPARAMS
))
1024 mode_changes
[mode_count
].letter
= c
;
1025 mode_changes
[mode_count
].dir
= MODE_ADD
;
1026 mode_changes
[mode_count
].caps
= 0;
1027 mode_changes
[mode_count
].nocaps
= 0;
1028 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
1029 mode_changes
[mode_count
].id
= targ_p
->id
;
1030 mode_changes
[mode_count
].arg
= targ_p
->name
;
1031 mode_changes
[mode_count
++].client
= targ_p
;
1033 mstptr
->flags
|= CHFL_VOICE
;
1037 mode_changes
[mode_count
].letter
= 'v';
1038 mode_changes
[mode_count
].dir
= MODE_DEL
;
1039 mode_changes
[mode_count
].caps
= 0;
1040 mode_changes
[mode_count
].nocaps
= 0;
1041 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
1042 mode_changes
[mode_count
].id
= targ_p
->id
;
1043 mode_changes
[mode_count
].arg
= targ_p
->name
;
1044 mode_changes
[mode_count
++].client
= targ_p
;
1046 mstptr
->flags
&= ~CHFL_VOICE
;
1051 chm_limit(struct Client
*source_p
, struct Channel
*chptr
,
1052 int alevel
, int parc
, int *parn
,
1053 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
1056 static char limitstr
[30];
1059 if(alevel
!= CHFL_CHANOP
)
1061 if(!(*errors
& SM_ERR_NOOPS
))
1062 sendto_one(source_p
, form_str(ERR_CHANOPRIVSNEEDED
),
1063 me
.name
, source_p
->name
, chptr
->chname
);
1064 *errors
|= SM_ERR_NOOPS
;
1068 if(dir
== MODE_QUERY
)
1071 if(MyClient(source_p
) && (++mode_limit_simple
> MAXMODES_SIMPLE
))
1074 if((dir
== MODE_ADD
) && parc
> *parn
)
1076 lstr
= parv
[(*parn
)];
1079 if(EmptyString(lstr
) || (limit
= atoi(lstr
)) <= 0)
1082 rb_sprintf(limitstr
, "%d", limit
);
1084 mode_changes
[mode_count
].letter
= c
;
1085 mode_changes
[mode_count
].dir
= MODE_ADD
;
1086 mode_changes
[mode_count
].caps
= 0;
1087 mode_changes
[mode_count
].nocaps
= 0;
1088 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
1089 mode_changes
[mode_count
].id
= NULL
;
1090 mode_changes
[mode_count
++].arg
= limitstr
;
1092 chptr
->mode
.limit
= limit
;
1094 else if(dir
== MODE_DEL
)
1096 if(!chptr
->mode
.limit
)
1099 chptr
->mode
.limit
= 0;
1101 mode_changes
[mode_count
].letter
= c
;
1102 mode_changes
[mode_count
].dir
= MODE_DEL
;
1103 mode_changes
[mode_count
].caps
= 0;
1104 mode_changes
[mode_count
].nocaps
= 0;
1105 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
1106 mode_changes
[mode_count
].id
= NULL
;
1107 mode_changes
[mode_count
++].arg
= NULL
;
1112 chm_throttle(struct Client
*source_p
, struct Channel
*chptr
,
1113 int alevel
, int parc
, int *parn
,
1114 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
1116 int joins
= 0, timeslice
= 0;
1118 if(alevel
!= CHFL_CHANOP
)
1120 if(!(*errors
& SM_ERR_NOOPS
))
1121 sendto_one(source_p
, form_str(ERR_CHANOPRIVSNEEDED
),
1122 me
.name
, source_p
->name
, chptr
->chname
);
1123 *errors
|= SM_ERR_NOOPS
;
1127 if(dir
== MODE_QUERY
)
1130 if(MyClient(source_p
) && (++mode_limit_simple
> MAXMODES_SIMPLE
))
1133 if((dir
== MODE_ADD
) && parc
> *parn
)
1135 sscanf(parv
[(*parn
)], "%d:%d", &joins
, ×lice
);
1137 if(!joins
|| !timeslice
)
1140 mode_changes
[mode_count
].letter
= c
;
1141 mode_changes
[mode_count
].dir
= MODE_ADD
;
1142 mode_changes
[mode_count
].caps
= 0;
1143 mode_changes
[mode_count
].nocaps
= 0;
1144 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
1145 mode_changes
[mode_count
].id
= NULL
;
1146 mode_changes
[mode_count
++].arg
= parv
[(*parn
)];
1150 chptr
->mode
.join_num
= joins
;
1151 chptr
->mode
.join_time
= timeslice
;
1153 else if(dir
== MODE_DEL
)
1155 if(!chptr
->mode
.join_num
)
1158 chptr
->mode
.join_num
= 0;
1159 chptr
->mode
.join_time
= 0;
1160 chptr
->join_count
= 0;
1161 chptr
->join_delta
= 0;
1163 mode_changes
[mode_count
].letter
= c
;
1164 mode_changes
[mode_count
].dir
= MODE_DEL
;
1165 mode_changes
[mode_count
].caps
= 0;
1166 mode_changes
[mode_count
].nocaps
= 0;
1167 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
1168 mode_changes
[mode_count
].id
= NULL
;
1169 mode_changes
[mode_count
++].arg
= NULL
;
1174 chm_forward(struct Client
*source_p
, struct Channel
*chptr
,
1175 int alevel
, int parc
, int *parn
,
1176 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
1178 struct Channel
*targptr
= NULL
;
1179 struct membership
*msptr
;
1180 const char *forward
;
1182 /* if +f is disabled, ignore local attempts to set it */
1183 if(!ConfigChannel
.use_forward
&& MyClient(source_p
) &&
1184 (dir
== MODE_ADD
) && (parc
> *parn
))
1187 if(dir
== MODE_QUERY
|| (dir
== MODE_ADD
&& parc
<= *parn
))
1189 if (!(*errors
& SM_ERR_RPL_F
))
1191 if (*chptr
->mode
.forward
== '\0')
1192 sendto_one_notice(source_p
, ":%s has no forward channel", chptr
->chname
);
1194 sendto_one_notice(source_p
, ":%s forward channel is %s", chptr
->chname
, chptr
->mode
.forward
);
1195 *errors
|= SM_ERR_RPL_F
;
1200 #ifndef FORWARD_OPERONLY
1201 if(alevel
!= CHFL_CHANOP
)
1203 if(!(*errors
& SM_ERR_NOOPS
))
1204 sendto_one(source_p
, form_str(ERR_CHANOPRIVSNEEDED
),
1205 me
.name
, source_p
->name
, chptr
->chname
);
1206 *errors
|= SM_ERR_NOOPS
;
1210 if(!IsOper(source_p
) && !IsServer(source_p
))
1212 if(!(*errors
& SM_ERR_NOPRIVS
))
1213 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
, form_str(ERR_NOPRIVILEGES
));
1214 *errors
|= SM_ERR_NOPRIVS
;
1219 if(MyClient(source_p
) && (++mode_limit_simple
> MAXMODES_SIMPLE
))
1222 if(dir
== MODE_ADD
&& parc
> *parn
)
1224 forward
= parv
[(*parn
)];
1227 if(EmptyString(forward
))
1229 if(!check_channel_name(forward
) ||
1230 (MyClient(source_p
) && (strlen(forward
) > LOC_CHANNELLEN
|| hash_find_resv(forward
))))
1232 sendto_one_numeric(source_p
, ERR_BADCHANNAME
, form_str(ERR_BADCHANNAME
), forward
);
1235 /* don't forward to inconsistent target -- jilles */
1236 if(chptr
->chname
[0] == '#' && forward
[0] == '&')
1238 sendto_one_numeric(source_p
, ERR_BADCHANNAME
,
1239 form_str(ERR_BADCHANNAME
), forward
);
1242 if(MyClient(source_p
) && (targptr
= find_channel(forward
)) == NULL
)
1244 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
1245 form_str(ERR_NOSUCHCHANNEL
), forward
);
1248 if(MyClient(source_p
) && !(targptr
->mode
.mode
& MODE_FREETARGET
))
1250 if((msptr
= find_channel_membership(targptr
, source_p
)) == NULL
||
1251 get_channel_access(source_p
, msptr
) != CHFL_CHANOP
)
1253 sendto_one(source_p
, form_str(ERR_CHANOPRIVSNEEDED
),
1254 me
.name
, source_p
->name
, targptr
->chname
);
1259 rb_strlcpy(chptr
->mode
.forward
, forward
, sizeof(chptr
->mode
.forward
));
1261 mode_changes
[mode_count
].letter
= c
;
1262 mode_changes
[mode_count
].dir
= MODE_ADD
;
1263 mode_changes
[mode_count
].caps
= 0;
1264 mode_changes
[mode_count
].nocaps
= 0;
1265 mode_changes
[mode_count
].mems
=
1266 ConfigChannel
.use_forward
? ALL_MEMBERS
: ONLY_SERVERS
;
1267 mode_changes
[mode_count
].id
= NULL
;
1268 mode_changes
[mode_count
++].arg
= forward
;
1270 else if(dir
== MODE_DEL
)
1272 if(!(*chptr
->mode
.forward
))
1275 *chptr
->mode
.forward
= '\0';
1277 mode_changes
[mode_count
].letter
= c
;
1278 mode_changes
[mode_count
].dir
= MODE_DEL
;
1279 mode_changes
[mode_count
].caps
= 0;
1280 mode_changes
[mode_count
].nocaps
= 0;
1281 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
1282 mode_changes
[mode_count
].id
= NULL
;
1283 mode_changes
[mode_count
++].arg
= NULL
;
1288 chm_key(struct Client
*source_p
, struct Channel
*chptr
,
1289 int alevel
, int parc
, int *parn
,
1290 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
1294 if(alevel
!= CHFL_CHANOP
)
1296 if(!(*errors
& SM_ERR_NOOPS
))
1297 sendto_one(source_p
, form_str(ERR_CHANOPRIVSNEEDED
),
1298 me
.name
, source_p
->name
, chptr
->chname
);
1299 *errors
|= SM_ERR_NOOPS
;
1303 if(dir
== MODE_QUERY
)
1306 if(MyClient(source_p
) && (++mode_limit_simple
> MAXMODES_SIMPLE
))
1309 if((dir
== MODE_ADD
) && parc
> *parn
)
1311 key
= LOCAL_COPY(parv
[(*parn
)]);
1314 if(MyClient(source_p
))
1317 fix_key_remote(key
);
1319 if(EmptyString(key
))
1322 s_assert(key
[0] != ' ');
1323 rb_strlcpy(chptr
->mode
.key
, key
, sizeof(chptr
->mode
.key
));
1325 mode_changes
[mode_count
].letter
= c
;
1326 mode_changes
[mode_count
].dir
= MODE_ADD
;
1327 mode_changes
[mode_count
].caps
= 0;
1328 mode_changes
[mode_count
].nocaps
= 0;
1329 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
1330 mode_changes
[mode_count
].id
= NULL
;
1331 mode_changes
[mode_count
++].arg
= chptr
->mode
.key
;
1333 else if(dir
== MODE_DEL
)
1335 static char splat
[] = "*";
1341 if(!(*chptr
->mode
.key
))
1344 /* hack time. when we get a +k-k mode, the +k arg is
1345 * chptr->mode.key, which the -k sets to \0, so hunt for a
1346 * +k when we get a -k, and set the arg to splat. --anfl
1348 for(i
= 0; i
< mode_count
; i
++)
1350 if(mode_changes
[i
].letter
== 'k' && mode_changes
[i
].dir
== MODE_ADD
)
1351 mode_changes
[i
].arg
= splat
;
1354 *chptr
->mode
.key
= 0;
1356 mode_changes
[mode_count
].letter
= c
;
1357 mode_changes
[mode_count
].dir
= MODE_DEL
;
1358 mode_changes
[mode_count
].caps
= 0;
1359 mode_changes
[mode_count
].nocaps
= 0;
1360 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
1361 mode_changes
[mode_count
].id
= NULL
;
1362 mode_changes
[mode_count
++].arg
= "*";
1367 struct ChannelMode chmode_table
[256] =
1369 {chm_nosuch
, 0 }, /* 0x00 */
1370 {chm_nosuch
, 0 }, /* 0x01 */
1371 {chm_nosuch
, 0 }, /* 0x02 */
1372 {chm_nosuch
, 0 }, /* 0x03 */
1373 {chm_nosuch
, 0 }, /* 0x04 */
1374 {chm_nosuch
, 0 }, /* 0x05 */
1375 {chm_nosuch
, 0 }, /* 0x06 */
1376 {chm_nosuch
, 0 }, /* 0x07 */
1377 {chm_nosuch
, 0 }, /* 0x08 */
1378 {chm_nosuch
, 0 }, /* 0x09 */
1379 {chm_nosuch
, 0 }, /* 0x0a */
1380 {chm_nosuch
, 0 }, /* 0x0b */
1381 {chm_nosuch
, 0 }, /* 0x0c */
1382 {chm_nosuch
, 0 }, /* 0x0d */
1383 {chm_nosuch
, 0 }, /* 0x0e */
1384 {chm_nosuch
, 0 }, /* 0x0f */
1385 {chm_nosuch
, 0 }, /* 0x10 */
1386 {chm_nosuch
, 0 }, /* 0x11 */
1387 {chm_nosuch
, 0 }, /* 0x12 */
1388 {chm_nosuch
, 0 }, /* 0x13 */
1389 {chm_nosuch
, 0 }, /* 0x14 */
1390 {chm_nosuch
, 0 }, /* 0x15 */
1391 {chm_nosuch
, 0 }, /* 0x16 */
1392 {chm_nosuch
, 0 }, /* 0x17 */
1393 {chm_nosuch
, 0 }, /* 0x18 */
1394 {chm_nosuch
, 0 }, /* 0x19 */
1395 {chm_nosuch
, 0 }, /* 0x1a */
1396 {chm_nosuch
, 0 }, /* 0x1b */
1397 {chm_nosuch
, 0 }, /* 0x1c */
1398 {chm_nosuch
, 0 }, /* 0x1d */
1399 {chm_nosuch
, 0 }, /* 0x1e */
1400 {chm_nosuch
, 0 }, /* 0x1f */
1401 {chm_nosuch
, 0 }, /* 0x20 */
1402 {chm_nosuch
, 0 }, /* 0x21 */
1403 {chm_nosuch
, 0 }, /* 0x22 */
1404 {chm_nosuch
, 0 }, /* 0x23 */
1405 {chm_nosuch
, 0 }, /* 0x24 */
1406 {chm_nosuch
, 0 }, /* 0x25 */
1407 {chm_nosuch
, 0 }, /* 0x26 */
1408 {chm_nosuch
, 0 }, /* 0x27 */
1409 {chm_nosuch
, 0 }, /* 0x28 */
1410 {chm_nosuch
, 0 }, /* 0x29 */
1411 {chm_nosuch
, 0 }, /* 0x2a */
1412 {chm_nosuch
, 0 }, /* 0x2b */
1413 {chm_nosuch
, 0 }, /* 0x2c */
1414 {chm_nosuch
, 0 }, /* 0x2d */
1415 {chm_nosuch
, 0 }, /* 0x2e */
1416 {chm_nosuch
, 0 }, /* 0x2f */
1417 {chm_nosuch
, 0 }, /* 0x30 */
1418 {chm_nosuch
, 0 }, /* 0x31 */
1419 {chm_nosuch
, 0 }, /* 0x32 */
1420 {chm_nosuch
, 0 }, /* 0x33 */
1421 {chm_nosuch
, 0 }, /* 0x34 */
1422 {chm_nosuch
, 0 }, /* 0x35 */
1423 {chm_nosuch
, 0 }, /* 0x36 */
1424 {chm_nosuch
, 0 }, /* 0x37 */
1425 {chm_nosuch
, 0 }, /* 0x38 */
1426 {chm_nosuch
, 0 }, /* 0x39 */
1427 {chm_nosuch
, 0 }, /* 0x3a */
1428 {chm_nosuch
, 0 }, /* 0x3b */
1429 {chm_nosuch
, 0 }, /* 0x3c */
1430 {chm_nosuch
, 0 }, /* 0x3d */
1431 {chm_nosuch
, 0 }, /* 0x3e */
1432 {chm_nosuch
, 0 }, /* 0x3f */
1434 {chm_nosuch
, 0 }, /* @ */
1435 {chm_nosuch
, 0 }, /* A */
1436 {chm_nosuch
, 0 }, /* B */
1437 {chm_simple
, MODE_NOCTCP
}, /* C */
1438 {chm_nosuch
, 0 }, /* D */
1439 {chm_nosuch
, 0 }, /* E */
1440 {chm_simple
, MODE_FREETARGET
}, /* F */
1441 {chm_nosuch
, 0 }, /* G */
1442 {chm_nosuch
, 0 }, /* H */
1443 {chm_ban
, CHFL_INVEX
}, /* I */
1444 {chm_nosuch
, 0 }, /* J */
1445 {chm_nosuch
, 0 }, /* K */
1446 {chm_staff
, MODE_EXLIMIT
}, /* L */
1447 {chm_nosuch
, 0 }, /* M */
1448 {chm_nosuch
, 0 }, /* N */
1449 {chm_nosuch
, 0 }, /* O */
1450 {chm_staff
, MODE_PERMANENT
}, /* P */
1451 {chm_simple
, MODE_DISFORWARD
}, /* Q */
1452 {chm_nosuch
, 0 }, /* R */
1453 {chm_nosuch
, 0 }, /* S */
1454 {chm_nosuch
, 0 }, /* T */
1455 {chm_nosuch
, 0 }, /* U */
1456 {chm_nosuch
, 0 }, /* V */
1457 {chm_nosuch
, 0 }, /* W */
1458 {chm_nosuch
, 0 }, /* X */
1459 {chm_nosuch
, 0 }, /* Y */
1460 {chm_nosuch
, 0 }, /* Z */
1467 {chm_nosuch
, 0 }, /* a */
1468 {chm_ban
, CHFL_BAN
}, /* b */
1469 {chm_simple
, MODE_NOCOLOR
}, /* c */
1470 {chm_nosuch
, 0 }, /* d */
1471 {chm_ban
, CHFL_EXCEPTION
}, /* e */
1472 {chm_forward
, 0 }, /* f */
1473 {chm_simple
, MODE_FREEINVITE
}, /* g */
1474 {chm_nosuch
, 0 }, /* h */
1475 {chm_simple
, MODE_INVITEONLY
}, /* i */
1476 {chm_throttle
, 0 }, /* j */
1477 {chm_key
, 0 }, /* k */
1478 {chm_limit
, 0 }, /* l */
1479 {chm_simple
, MODE_MODERATED
}, /* m */
1480 {chm_simple
, MODE_NOPRIVMSGS
}, /* n */
1481 {chm_op
, 0 }, /* o */
1482 {chm_simple
, MODE_PRIVATE
}, /* p */
1483 {chm_ban
, CHFL_QUIET
}, /* q */
1484 {chm_simple
, MODE_REGONLY
}, /* r */
1485 {chm_simple
, MODE_SECRET
}, /* s */
1486 {chm_simple
, MODE_TOPICLIMIT
}, /* t */
1487 {chm_nosuch
, 0 }, /* u */
1488 {chm_voice
, 0 }, /* v */
1489 {chm_nosuch
, 0 }, /* w */
1490 {chm_nosuch
, 0 }, /* x */
1491 {chm_nosuch
, 0 }, /* y */
1492 {chm_simple
, MODE_OPMODERATE
}, /* z */
1494 {chm_nosuch
, 0 }, /* 0x7b */
1495 {chm_nosuch
, 0 }, /* 0x7c */
1496 {chm_nosuch
, 0 }, /* 0x7d */
1497 {chm_nosuch
, 0 }, /* 0x7e */
1498 {chm_nosuch
, 0 }, /* 0x7f */
1500 {chm_nosuch
, 0 }, /* 0x80 */
1501 {chm_nosuch
, 0 }, /* 0x81 */
1502 {chm_nosuch
, 0 }, /* 0x82 */
1503 {chm_nosuch
, 0 }, /* 0x83 */
1504 {chm_nosuch
, 0 }, /* 0x84 */
1505 {chm_nosuch
, 0 }, /* 0x85 */
1506 {chm_nosuch
, 0 }, /* 0x86 */
1507 {chm_nosuch
, 0 }, /* 0x87 */
1508 {chm_nosuch
, 0 }, /* 0x88 */
1509 {chm_nosuch
, 0 }, /* 0x89 */
1510 {chm_nosuch
, 0 }, /* 0x8a */
1511 {chm_nosuch
, 0 }, /* 0x8b */
1512 {chm_nosuch
, 0 }, /* 0x8c */
1513 {chm_nosuch
, 0 }, /* 0x8d */
1514 {chm_nosuch
, 0 }, /* 0x8e */
1515 {chm_nosuch
, 0 }, /* 0x8f */
1517 {chm_nosuch
, 0 }, /* 0x90 */
1518 {chm_nosuch
, 0 }, /* 0x91 */
1519 {chm_nosuch
, 0 }, /* 0x92 */
1520 {chm_nosuch
, 0 }, /* 0x93 */
1521 {chm_nosuch
, 0 }, /* 0x94 */
1522 {chm_nosuch
, 0 }, /* 0x95 */
1523 {chm_nosuch
, 0 }, /* 0x96 */
1524 {chm_nosuch
, 0 }, /* 0x97 */
1525 {chm_nosuch
, 0 }, /* 0x98 */
1526 {chm_nosuch
, 0 }, /* 0x99 */
1527 {chm_nosuch
, 0 }, /* 0x9a */
1528 {chm_nosuch
, 0 }, /* 0x9b */
1529 {chm_nosuch
, 0 }, /* 0x9c */
1530 {chm_nosuch
, 0 }, /* 0x9d */
1531 {chm_nosuch
, 0 }, /* 0x9e */
1532 {chm_nosuch
, 0 }, /* 0x9f */
1534 {chm_nosuch
, 0 }, /* 0xa0 */
1535 {chm_nosuch
, 0 }, /* 0xa1 */
1536 {chm_nosuch
, 0 }, /* 0xa2 */
1537 {chm_nosuch
, 0 }, /* 0xa3 */
1538 {chm_nosuch
, 0 }, /* 0xa4 */
1539 {chm_nosuch
, 0 }, /* 0xa5 */
1540 {chm_nosuch
, 0 }, /* 0xa6 */
1541 {chm_nosuch
, 0 }, /* 0xa7 */
1542 {chm_nosuch
, 0 }, /* 0xa8 */
1543 {chm_nosuch
, 0 }, /* 0xa9 */
1544 {chm_nosuch
, 0 }, /* 0xaa */
1545 {chm_nosuch
, 0 }, /* 0xab */
1546 {chm_nosuch
, 0 }, /* 0xac */
1547 {chm_nosuch
, 0 }, /* 0xad */
1548 {chm_nosuch
, 0 }, /* 0xae */
1549 {chm_nosuch
, 0 }, /* 0xaf */
1551 {chm_nosuch
, 0 }, /* 0xb0 */
1552 {chm_nosuch
, 0 }, /* 0xb1 */
1553 {chm_nosuch
, 0 }, /* 0xb2 */
1554 {chm_nosuch
, 0 }, /* 0xb3 */
1555 {chm_nosuch
, 0 }, /* 0xb4 */
1556 {chm_nosuch
, 0 }, /* 0xb5 */
1557 {chm_nosuch
, 0 }, /* 0xb6 */
1558 {chm_nosuch
, 0 }, /* 0xb7 */
1559 {chm_nosuch
, 0 }, /* 0xb8 */
1560 {chm_nosuch
, 0 }, /* 0xb9 */
1561 {chm_nosuch
, 0 }, /* 0xba */
1562 {chm_nosuch
, 0 }, /* 0xbb */
1563 {chm_nosuch
, 0 }, /* 0xbc */
1564 {chm_nosuch
, 0 }, /* 0xbd */
1565 {chm_nosuch
, 0 }, /* 0xbe */
1566 {chm_nosuch
, 0 }, /* 0xbf */
1568 {chm_nosuch
, 0 }, /* 0xc0 */
1569 {chm_nosuch
, 0 }, /* 0xc1 */
1570 {chm_nosuch
, 0 }, /* 0xc2 */
1571 {chm_nosuch
, 0 }, /* 0xc3 */
1572 {chm_nosuch
, 0 }, /* 0xc4 */
1573 {chm_nosuch
, 0 }, /* 0xc5 */
1574 {chm_nosuch
, 0 }, /* 0xc6 */
1575 {chm_nosuch
, 0 }, /* 0xc7 */
1576 {chm_nosuch
, 0 }, /* 0xc8 */
1577 {chm_nosuch
, 0 }, /* 0xc9 */
1578 {chm_nosuch
, 0 }, /* 0xca */
1579 {chm_nosuch
, 0 }, /* 0xcb */
1580 {chm_nosuch
, 0 }, /* 0xcc */
1581 {chm_nosuch
, 0 }, /* 0xcd */
1582 {chm_nosuch
, 0 }, /* 0xce */
1583 {chm_nosuch
, 0 }, /* 0xcf */
1585 {chm_nosuch
, 0 }, /* 0xd0 */
1586 {chm_nosuch
, 0 }, /* 0xd1 */
1587 {chm_nosuch
, 0 }, /* 0xd2 */
1588 {chm_nosuch
, 0 }, /* 0xd3 */
1589 {chm_nosuch
, 0 }, /* 0xd4 */
1590 {chm_nosuch
, 0 }, /* 0xd5 */
1591 {chm_nosuch
, 0 }, /* 0xd6 */
1592 {chm_nosuch
, 0 }, /* 0xd7 */
1593 {chm_nosuch
, 0 }, /* 0xd8 */
1594 {chm_nosuch
, 0 }, /* 0xd9 */
1595 {chm_nosuch
, 0 }, /* 0xda */
1596 {chm_nosuch
, 0 }, /* 0xdb */
1597 {chm_nosuch
, 0 }, /* 0xdc */
1598 {chm_nosuch
, 0 }, /* 0xdd */
1599 {chm_nosuch
, 0 }, /* 0xde */
1600 {chm_nosuch
, 0 }, /* 0xdf */
1602 {chm_nosuch
, 0 }, /* 0xe0 */
1603 {chm_nosuch
, 0 }, /* 0xe1 */
1604 {chm_nosuch
, 0 }, /* 0xe2 */
1605 {chm_nosuch
, 0 }, /* 0xe3 */
1606 {chm_nosuch
, 0 }, /* 0xe4 */
1607 {chm_nosuch
, 0 }, /* 0xe5 */
1608 {chm_nosuch
, 0 }, /* 0xe6 */
1609 {chm_nosuch
, 0 }, /* 0xe7 */
1610 {chm_nosuch
, 0 }, /* 0xe8 */
1611 {chm_nosuch
, 0 }, /* 0xe9 */
1612 {chm_nosuch
, 0 }, /* 0xea */
1613 {chm_nosuch
, 0 }, /* 0xeb */
1614 {chm_nosuch
, 0 }, /* 0xec */
1615 {chm_nosuch
, 0 }, /* 0xed */
1616 {chm_nosuch
, 0 }, /* 0xee */
1617 {chm_nosuch
, 0 }, /* 0xef */
1619 {chm_nosuch
, 0 }, /* 0xf0 */
1620 {chm_nosuch
, 0 }, /* 0xf1 */
1621 {chm_nosuch
, 0 }, /* 0xf2 */
1622 {chm_nosuch
, 0 }, /* 0xf3 */
1623 {chm_nosuch
, 0 }, /* 0xf4 */
1624 {chm_nosuch
, 0 }, /* 0xf5 */
1625 {chm_nosuch
, 0 }, /* 0xf6 */
1626 {chm_nosuch
, 0 }, /* 0xf7 */
1627 {chm_nosuch
, 0 }, /* 0xf8 */
1628 {chm_nosuch
, 0 }, /* 0xf9 */
1629 {chm_nosuch
, 0 }, /* 0xfa */
1630 {chm_nosuch
, 0 }, /* 0xfb */
1631 {chm_nosuch
, 0 }, /* 0xfc */
1632 {chm_nosuch
, 0 }, /* 0xfd */
1633 {chm_nosuch
, 0 }, /* 0xfe */
1634 {chm_nosuch
, 0 }, /* 0xff */
1639 /* set_channel_mode()
1641 * inputs - client, source, channel, membership pointer, params
1643 * side effects - channel modes/memberships are changed, MODE is issued
1645 * Extensively modified to be hotpluggable, 03/09/06 -- nenolod
1648 set_channel_mode(struct Client
*client_p
, struct Client
*source_p
,
1649 struct Channel
*chptr
, struct membership
*msptr
, int parc
, const char *parv
[])
1651 static char modebuf
[BUFSIZE
];
1652 static char parabuf
[BUFSIZE
];
1655 int cur_len
, mlen
, paralen
, paracount
, arglen
, len
;
1661 const char *ml
= parv
[0];
1663 struct Client
*fakesource_p
;
1666 removed_mask_pos
= 0;
1669 mode_limit_simple
= 0;
1671 alevel
= get_channel_access(source_p
, msptr
);
1673 /* Hide connecting server on netburst -- jilles */
1674 if (ConfigServerHide
.flatten_links
&& IsServer(source_p
) && !has_id(source_p
) && !HasSentEob(source_p
))
1677 fakesource_p
= source_p
;
1679 for(; (c
= *ml
) != 0; ml
++)
1693 /* If this mode char is locked, don't allow local users to change it. */
1694 if (MyClient(source_p
) && chptr
->mode_lock
&& strchr(chptr
->mode_lock
, c
))
1696 if (!(errors
& SM_ERR_MLOCK
))
1697 sendto_one_numeric(source_p
,
1698 ERR_MLOCKRESTRICTED
,
1699 form_str(ERR_MLOCKRESTRICTED
),
1703 errors
|= SM_ERR_MLOCK
;
1706 chmode_table
[(unsigned char) c
].set_func(fakesource_p
, chptr
, alevel
,
1709 chmode_table
[(unsigned char) c
].mode_type
);
1714 /* bail out if we have nothing to do... */
1718 if(IsServer(source_p
))
1719 mlen
= rb_sprintf(modebuf
, ":%s MODE %s ", fakesource_p
->name
, chptr
->chname
);
1721 mlen
= rb_sprintf(modebuf
, ":%s!%s@%s MODE %s ",
1722 source_p
->name
, source_p
->username
,
1723 source_p
->host
, chptr
->chname
);
1725 for(j
= 0, flags
= ALL_MEMBERS
; j
< 2; j
++, flags
= ONLY_CHANOPS
)
1728 mbuf
= modebuf
+ mlen
;
1731 paracount
= paralen
= 0;
1734 for(i
= 0; i
< mode_count
; i
++)
1736 if(mode_changes
[i
].letter
== 0 || mode_changes
[i
].mems
!= flags
)
1739 if(mode_changes
[i
].arg
!= NULL
)
1741 arglen
= strlen(mode_changes
[i
].arg
);
1743 if(arglen
> MODEBUFLEN
- 5)
1749 /* if we're creeping over MAXMODEPARAMSSERV, or over
1750 * bufsize (4 == +/-,modechar,two spaces) send now.
1752 if(mode_changes
[i
].arg
!= NULL
&&
1753 ((paracount
== MAXMODEPARAMSSERV
) ||
1754 ((cur_len
+ paralen
+ arglen
+ 4) > (BUFSIZE
- 3))))
1759 sendto_channel_local(flags
, chptr
, "%s %s", modebuf
,
1764 paracount
= paralen
= 0;
1766 mbuf
= modebuf
+ mlen
;
1772 if(dir
!= mode_changes
[i
].dir
)
1774 *mbuf
++ = (mode_changes
[i
].dir
== MODE_ADD
) ? '+' : '-';
1776 dir
= mode_changes
[i
].dir
;
1779 *mbuf
++ = mode_changes
[i
].letter
;
1782 if(mode_changes
[i
].arg
!= NULL
)
1785 len
= rb_sprintf(pbuf
, "%s ", mode_changes
[i
].arg
);
1791 if(paralen
&& parabuf
[paralen
- 1] == ' ')
1792 parabuf
[paralen
- 1] = '\0';
1796 sendto_channel_local(flags
, chptr
, "%s %s", modebuf
, parabuf
);
1799 /* only propagate modes originating locally, or if we're hubbing */
1800 if(MyClient(source_p
) || rb_dlink_list_length(&serv_list
) > 1)
1801 send_cap_mode_changes(client_p
, source_p
, chptr
, mode_changes
, mode_count
);
1804 /* set_channel_mlock()
1806 * inputs - client, source, channel, params
1808 * side effects - channel mlock is changed / MLOCK is propagated
1811 set_channel_mlock(struct Client
*client_p
, struct Client
*source_p
,
1812 struct Channel
*chptr
, const char *newmlock
, int propagate
)
1814 rb_free(chptr
->mode_lock
);
1815 chptr
->mode_lock
= newmlock
? rb_strdup(newmlock
) : NULL
;
1819 sendto_server(client_p
, NULL
, CAP_TS6
| CAP_MLOCK
, NOCAPS
, ":%s MLOCK %ld %s :%s",
1820 source_p
->id
, (long) chptr
->channelts
, chptr
->chname
,
1821 chptr
->mode_lock
? chptr
->mode_lock
: "");