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
34 #include "s_serv.h" /* captab */
38 #include "s_conf.h" /* ConfigFileEntry, ConfigChannel */
39 #include "s_newconf.h"
45 /* bitmasks for error returns, so we send once per call */
46 #define SM_ERR_NOTS 0x00000001 /* No TS on channel */
47 #define SM_ERR_NOOPS 0x00000002 /* No chan ops */
48 #define SM_ERR_UNKNOWN 0x00000004
49 #define SM_ERR_RPL_C 0x00000008
50 #define SM_ERR_RPL_B 0x00000010
51 #define SM_ERR_RPL_E 0x00000020
52 #define SM_ERR_NOTONCHANNEL 0x00000040 /* Not on channel */
53 #define SM_ERR_RPL_I 0x00000100
54 #define SM_ERR_RPL_D 0x00000200
55 #define SM_ERR_NOPRIVS 0x00000400
56 #define SM_ERR_RPL_Q 0x00000800
57 #define SM_ERR_RPL_F 0x00001000
58 #define SM_ERR_MLOCK 0x00002000
60 #define MAXMODES_SIMPLE 46 /* a-zA-Z except bqeIov */
62 static struct ChModeChange mode_changes
[BUFSIZE
];
63 static int mode_count
;
64 static int mode_limit
;
65 static int mode_limit_simple
;
67 static int removed_mask_pos
;
70 char cflagsmyinfo
[256];
72 int chmode_flags
[256];
74 extern int h_get_channel_access
;
76 /* OPTIMIZE ME! -- dwr */
78 construct_cflags_strings(void)
81 char *ptr
= cflagsbuf
;
82 char *ptr2
= cflagsmyinfo
;
87 for(i
= 0; i
< 256; i
++)
89 if( !(chmode_table
[i
].set_func
== chm_ban
) &&
90 !(chmode_table
[i
].set_func
== chm_forward
) &&
91 !(chmode_table
[i
].set_func
== chm_throttle
) &&
92 !(chmode_table
[i
].set_func
== chm_key
) &&
93 !(chmode_table
[i
].set_func
== chm_limit
) &&
94 !(chmode_table
[i
].set_func
== chm_op
) &&
95 !(chmode_table
[i
].set_func
== chm_voice
))
97 chmode_flags
[i
] = chmode_table
[i
].mode_type
;
104 switch (chmode_flags
[i
])
106 case MODE_FREETARGET
:
107 case MODE_DISFORWARD
:
108 if(ConfigChannel
.use_forward
)
112 if(chmode_flags
[i
] != 0)
118 /* Should we leave orphaned check here? -- dwr */
119 if(!(chmode_table
[i
].set_func
== chm_nosuch
) && !(chmode_table
[i
].set_func
== chm_orphaned
))
133 * outputs - an available cflag bitmask or
134 * 0 if no cflags are available
135 * side effects - NONE
138 find_cflag_slot(void)
140 unsigned int all_cflags
= 0, my_cflag
= 0, i
;
142 for (i
= 0; i
< 256; i
++)
143 all_cflags
|= chmode_flags
[i
];
145 for (my_cflag
= 1; my_cflag
&& (all_cflags
& my_cflag
);
152 cflag_add(char c_
, ChannelModeFunc function
)
154 int c
= (unsigned char)c_
;
156 if (chmode_table
[c
].set_func
!= chm_nosuch
&&
157 chmode_table
[c
].set_func
!= chm_orphaned
)
160 if (chmode_table
[c
].set_func
== chm_nosuch
)
161 chmode_table
[c
].mode_type
= find_cflag_slot();
162 if (chmode_table
[c
].mode_type
== 0)
164 chmode_table
[c
].set_func
= function
;
165 construct_cflags_strings();
166 return chmode_table
[c
].mode_type
;
170 cflag_orphan(char c_
)
172 int c
= (unsigned char)c_
;
174 s_assert(chmode_flags
[c
] != 0);
175 chmode_table
[c
].set_func
= chm_orphaned
;
176 construct_cflags_strings();
180 get_channel_access(struct Client
*source_p
, struct Channel
*chptr
, struct membership
*msptr
, int dir
, const char *modestr
)
182 hook_data_channel_approval moduledata
;
184 if(!MyClient(source_p
))
187 moduledata
.client
= source_p
;
188 moduledata
.chptr
= chptr
;
189 moduledata
.msptr
= msptr
;
190 moduledata
.target
= NULL
;
191 moduledata
.approved
= (msptr
!= NULL
&& is_chanop(msptr
)) ? CHFL_CHANOP
: CHFL_PEON
;
192 moduledata
.dir
= dir
;
193 moduledata
.modestr
= modestr
;
195 call_hook(h_get_channel_access
, &moduledata
);
197 return moduledata
.approved
;
200 /* allow_mode_change()
202 * Checks if mlock and chanops permit a mode change.
204 * inputs - client, channel, access level, errors pointer, mode char
205 * outputs - false on failure, true on success
206 * side effects - error message sent on failure
209 allow_mode_change(struct Client
*source_p
, struct Channel
*chptr
, int alevel
,
212 /* If this mode char is locked, don't allow local users to change it. */
213 if (MyClient(source_p
) && chptr
->mode_lock
&& strchr(chptr
->mode_lock
, c
))
215 if (!(*errors
& SM_ERR_MLOCK
))
216 sendto_one_numeric(source_p
,
218 form_str(ERR_MLOCKRESTRICTED
),
222 *errors
|= SM_ERR_MLOCK
;
225 if(alevel
< CHFL_CHANOP
)
227 if(!(*errors
& SM_ERR_NOOPS
))
228 sendto_one(source_p
, form_str(ERR_CHANOPRIVSNEEDED
),
229 me
.name
, source_p
->name
, chptr
->chname
);
230 *errors
|= SM_ERR_NOOPS
;
238 * inputs - client, channel, id to add, type, forward
239 * outputs - false on failure, true on success
240 * side effects - given id is added to the appropriate list
243 add_id(struct Client
*source_p
, struct Channel
*chptr
, const char *banid
, const char *forward
,
244 rb_dlink_list
* list
, long mode_type
)
246 struct Ban
*actualBan
;
247 static char who
[USERHOST_REPLYLEN
];
248 char *realban
= LOCAL_COPY(banid
);
251 /* dont let local clients overflow the banlist, or set redundant
254 if(MyClient(source_p
))
256 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
)) >= (unsigned long)(chptr
->mode
.mode
& MODE_EXLIMIT
? ConfigChannel
.max_bans_large
: ConfigChannel
.max_bans
))
258 sendto_one(source_p
, form_str(ERR_BANLISTFULL
),
259 me
.name
, source_p
->name
, chptr
->chname
, realban
);
263 RB_DLINK_FOREACH(ptr
, list
->head
)
265 actualBan
= ptr
->data
;
266 if(mask_match(actualBan
->banstr
, realban
))
270 /* dont let remotes set duplicates */
273 RB_DLINK_FOREACH(ptr
, list
->head
)
275 actualBan
= ptr
->data
;
276 if(!irccmp(actualBan
->banstr
, realban
))
282 if(IsPerson(source_p
))
283 sprintf(who
, "%s!%s@%s", source_p
->name
, source_p
->username
, source_p
->host
);
285 rb_strlcpy(who
, source_p
->name
, sizeof(who
));
287 actualBan
= allocate_ban(realban
, who
, forward
);
288 actualBan
->when
= rb_current_time();
290 rb_dlinkAdd(actualBan
, &actualBan
->node
, list
);
292 /* invalidate the can_send() cache */
293 if(mode_type
== CHFL_BAN
|| mode_type
== CHFL_QUIET
|| mode_type
== CHFL_EXCEPTION
)
294 chptr
->bants
= rb_current_time();
301 * inputs - channel, id to remove, type
302 * outputs - pointer to ban that was removed, if any
303 * side effects - given id is removed from the appropriate list and returned
306 del_id(struct Channel
*chptr
, const char *banid
, rb_dlink_list
* list
, long mode_type
)
311 if(EmptyString(banid
))
314 RB_DLINK_FOREACH(ptr
, list
->head
)
318 if(irccmp(banid
, banptr
->banstr
) == 0)
320 rb_dlinkDelete(&banptr
->node
, list
);
322 /* invalidate the can_send() cache */
323 if(mode_type
== CHFL_BAN
|| mode_type
== CHFL_QUIET
|| mode_type
== CHFL_EXCEPTION
)
324 chptr
->bants
= rb_current_time();
335 * input - string to check
336 * output - pointer to 'fixed' string, or "*" if empty
337 * side effects - any white space found becomes \0
340 check_string(char *s
)
343 static char splat
[] = "*";
360 * inputs - mask to pretty
361 * outputs - better version of the mask
362 * side effects - mask is chopped to limits, and transformed:
370 pretty_mask(const char *idmask
)
372 static char mask_buf
[BUFSIZE
];
374 const char *nick
, *user
, *host
, *forward
= NULL
;
380 mask
= LOCAL_COPY(idmask
);
381 mask
= check_string(mask
);
383 masklen
= strlen(mask
);
385 nick
= user
= host
= "*";
389 if((size_t) BUFSIZE
- mask_pos
< masklen
+ 5)
392 old_mask_pos
= mask_pos
;
396 memcpy(mask_buf
+ mask_pos
, mask
, masklen
+ 1);
397 mask_pos
+= masklen
+ 1;
398 t
= mask_buf
+ old_mask_pos
+ 1;
404 return mask_buf
+ old_mask_pos
;
408 if((t
= memchr(mask
, '@', masklen
)) != NULL
)
413 host
= t
, hl
= strlen(t
);
415 if((t
= memchr(mask
, '!', at
- mask
)) != NULL
)
420 user
= t
, ul
= at
- t
;
422 nick
= mask
, nl
= ex
- mask
;
427 user
= mask
, ul
= at
- mask
;
430 if((t
= memchr(host
, '!', hl
)) != NULL
||
431 (t
= memchr(host
, '$', hl
)) != NULL
)
435 forward
= t
, fl
= host
+ hl
- t
;
439 else if((t
= memchr(mask
, '!', masklen
)) != NULL
)
444 nick
= mask
, nl
= ex
- mask
;
446 user
= t
, ul
= strlen(t
);
448 else if(memchr(mask
, '.', masklen
) != NULL
||
449 memchr(mask
, ':', masklen
) != NULL
)
451 host
= mask
, hl
= masklen
;
456 nick
= mask
, nl
= masklen
;
459 /* truncate values to max lengths */
469 memcpy(mask_buf
+ mask_pos
, nick
, nl
), mask_pos
+= nl
;
470 mask_buf
[mask_pos
++] = '!';
471 memcpy(mask_buf
+ mask_pos
, user
, ul
), mask_pos
+= ul
;
472 mask_buf
[mask_pos
++] = '@';
473 memcpy(mask_buf
+ mask_pos
, host
, hl
), mask_pos
+= hl
;
475 mask_buf
[mask_pos
++] = '$';
476 memcpy(mask_buf
+ mask_pos
, forward
, fl
), mask_pos
+= fl
;
478 mask_buf
[mask_pos
++] = '\0';
480 return mask_buf
+ old_mask_pos
;
485 * input - client, channel to set mode on, target channel name
486 * output - true if forwarding should be allowed
487 * side effects - numeric sent if not allowed
490 check_forward(struct Client
*source_p
, struct Channel
*chptr
,
493 struct Channel
*targptr
= NULL
;
494 struct membership
*msptr
;
496 if(!check_channel_name(forward
) ||
497 (MyClient(source_p
) && (strlen(forward
) > LOC_CHANNELLEN
|| hash_find_resv(forward
))))
499 sendto_one_numeric(source_p
, ERR_BADCHANNAME
, form_str(ERR_BADCHANNAME
), forward
);
502 /* don't forward to inconsistent target -- jilles */
503 if(chptr
->chname
[0] == '#' && forward
[0] == '&')
505 sendto_one_numeric(source_p
, ERR_BADCHANNAME
,
506 form_str(ERR_BADCHANNAME
), forward
);
509 if(MyClient(source_p
) && (targptr
= find_channel(forward
)) == NULL
)
511 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
512 form_str(ERR_NOSUCHCHANNEL
), forward
);
515 if(MyClient(source_p
) && !(targptr
->mode
.mode
& MODE_FREETARGET
))
517 if((msptr
= find_channel_membership(targptr
, source_p
)) == NULL
||
518 get_channel_access(source_p
, targptr
, msptr
, MODE_QUERY
, NULL
) < CHFL_CHANOP
)
520 sendto_one(source_p
, form_str(ERR_CHANOPRIVSNEEDED
),
521 me
.name
, source_p
->name
, targptr
->chname
);
531 * output - the same key, fixed
532 * side effects - anything below ascii 13 is discarded, ':' discarded,
533 * high ascii is dropped to lower half of ascii table
538 unsigned char *s
, *t
, c
;
540 for(s
= t
= (unsigned char *) arg
; (c
= *s
); s
++)
543 if(c
!= ':' && c
!= ',' && c
> ' ')
554 * ouput - the same key, fixed
555 * side effects - high ascii dropped to lower half of table,
556 * CR/LF/':' are dropped
559 fix_key_remote(char *arg
)
561 unsigned char *s
, *t
, c
;
563 for(s
= t
= (unsigned char *) arg
; (c
= *s
); s
++)
566 if((c
!= 0x0a) && (c
!= ':') && (c
!= ',') && (c
!= 0x0d) && (c
!= ' '))
576 * The handlers for each specific mode.
579 chm_nosuch(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(*errors
& SM_ERR_UNKNOWN
)
585 *errors
|= SM_ERR_UNKNOWN
;
586 sendto_one(source_p
, form_str(ERR_UNKNOWNMODE
), me
.name
, source_p
->name
, c
);
590 chm_simple(struct Client
*source_p
, struct Channel
*chptr
,
591 int alevel
, int parc
, int *parn
,
592 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
594 if(!allow_mode_change(source_p
, chptr
, alevel
, errors
, c
))
597 if(MyClient(source_p
) && (++mode_limit_simple
> MAXMODES_SIMPLE
))
601 if((dir
== MODE_ADD
) && !(chptr
->mode
.mode
& mode_type
))
603 /* if +f is disabled, ignore an attempt to set +QF locally */
604 if(!ConfigChannel
.use_forward
&& MyClient(source_p
) &&
605 (c
== 'Q' || c
== 'F'))
608 chptr
->mode
.mode
|= mode_type
;
610 mode_changes
[mode_count
].letter
= c
;
611 mode_changes
[mode_count
].dir
= MODE_ADD
;
612 mode_changes
[mode_count
].id
= NULL
;
613 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
614 mode_changes
[mode_count
++].arg
= NULL
;
616 else if((dir
== MODE_DEL
) && (chptr
->mode
.mode
& mode_type
))
618 chptr
->mode
.mode
&= ~mode_type
;
620 mode_changes
[mode_count
].letter
= c
;
621 mode_changes
[mode_count
].dir
= MODE_DEL
;
622 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
623 mode_changes
[mode_count
].id
= NULL
;
624 mode_changes
[mode_count
++].arg
= NULL
;
629 chm_orphaned(struct Client
*source_p
, struct Channel
*chptr
,
630 int alevel
, int parc
, int *parn
,
631 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
633 if(MyClient(source_p
))
636 if((dir
== MODE_ADD
) && !(chptr
->mode
.mode
& mode_type
))
638 chptr
->mode
.mode
|= mode_type
;
640 mode_changes
[mode_count
].letter
= c
;
641 mode_changes
[mode_count
].dir
= MODE_ADD
;
642 mode_changes
[mode_count
].id
= NULL
;
643 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
644 mode_changes
[mode_count
++].arg
= NULL
;
646 else if((dir
== MODE_DEL
) && (chptr
->mode
.mode
& mode_type
))
648 chptr
->mode
.mode
&= ~mode_type
;
650 mode_changes
[mode_count
].letter
= c
;
651 mode_changes
[mode_count
].dir
= MODE_DEL
;
652 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
653 mode_changes
[mode_count
].id
= NULL
;
654 mode_changes
[mode_count
++].arg
= NULL
;
659 chm_hidden(struct Client
*source_p
, struct Channel
*chptr
,
660 int alevel
, int parc
, int *parn
,
661 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
663 if(!IsOper(source_p
) && !IsServer(source_p
))
665 if(!(*errors
& SM_ERR_NOPRIVS
))
666 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
, form_str(ERR_NOPRIVILEGES
));
667 *errors
|= SM_ERR_NOPRIVS
;
670 if(MyClient(source_p
) && !IsOperAdmin(source_p
))
672 if(!(*errors
& SM_ERR_NOPRIVS
))
673 sendto_one(source_p
, form_str(ERR_NOPRIVS
), me
.name
,
674 source_p
->name
, "admin");
675 *errors
|= SM_ERR_NOPRIVS
;
679 if(MyClient(source_p
) && (++mode_limit_simple
> MAXMODES_SIMPLE
))
683 if((dir
== MODE_ADD
) && !(chptr
->mode
.mode
& mode_type
))
685 chptr
->mode
.mode
|= mode_type
;
687 mode_changes
[mode_count
].letter
= c
;
688 mode_changes
[mode_count
].dir
= MODE_ADD
;
689 mode_changes
[mode_count
].id
= NULL
;
690 mode_changes
[mode_count
].mems
= ONLY_OPERS
;
691 mode_changes
[mode_count
++].arg
= NULL
;
693 else if((dir
== MODE_DEL
) && (chptr
->mode
.mode
& mode_type
))
695 chptr
->mode
.mode
&= ~mode_type
;
697 mode_changes
[mode_count
].letter
= c
;
698 mode_changes
[mode_count
].dir
= MODE_DEL
;
699 mode_changes
[mode_count
].mems
= ONLY_OPERS
;
700 mode_changes
[mode_count
].id
= NULL
;
701 mode_changes
[mode_count
++].arg
= NULL
;
706 chm_staff(struct Client
*source_p
, struct Channel
*chptr
,
707 int alevel
, int parc
, int *parn
,
708 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
710 if(!IsOper(source_p
) && !IsServer(source_p
))
712 if(!(*errors
& SM_ERR_NOPRIVS
))
713 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
, form_str(ERR_NOPRIVILEGES
));
714 *errors
|= SM_ERR_NOPRIVS
;
717 if(MyClient(source_p
) && !IsOperResv(source_p
))
719 if(!(*errors
& SM_ERR_NOPRIVS
))
720 sendto_one(source_p
, form_str(ERR_NOPRIVS
), me
.name
,
721 source_p
->name
, "resv");
722 *errors
|= SM_ERR_NOPRIVS
;
726 if(!allow_mode_change(source_p
, chptr
, CHFL_CHANOP
, errors
, c
))
729 if(MyClient(source_p
) && (++mode_limit_simple
> MAXMODES_SIMPLE
))
733 if((dir
== MODE_ADD
) && !(chptr
->mode
.mode
& mode_type
))
735 chptr
->mode
.mode
|= mode_type
;
737 mode_changes
[mode_count
].letter
= c
;
738 mode_changes
[mode_count
].dir
= MODE_ADD
;
739 mode_changes
[mode_count
].id
= NULL
;
740 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
741 mode_changes
[mode_count
++].arg
= NULL
;
743 else if((dir
== MODE_DEL
) && (chptr
->mode
.mode
& mode_type
))
745 chptr
->mode
.mode
&= ~mode_type
;
747 mode_changes
[mode_count
].letter
= c
;
748 mode_changes
[mode_count
].dir
= MODE_DEL
;
749 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
750 mode_changes
[mode_count
].id
= NULL
;
751 mode_changes
[mode_count
++].arg
= NULL
;
756 chm_ban(struct Client
*source_p
, struct Channel
*chptr
,
757 int alevel
, int parc
, int *parn
,
758 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
760 const char *mask
, *raw_mask
;
766 const char *rpl_list_p
;
767 const char *rpl_endlist_p
;
773 list
= &chptr
->banlist
;
774 errorval
= SM_ERR_RPL_B
;
775 rpl_list_p
= form_str(RPL_BANLIST
);
776 rpl_endlist_p
= form_str(RPL_ENDOFBANLIST
);
781 /* if +e is disabled, allow all but +e locally */
782 if(!ConfigChannel
.use_except
&& MyClient(source_p
) &&
783 ((dir
== MODE_ADD
) && (parc
> *parn
)))
786 list
= &chptr
->exceptlist
;
787 errorval
= SM_ERR_RPL_E
;
788 rpl_list_p
= form_str(RPL_EXCEPTLIST
);
789 rpl_endlist_p
= form_str(RPL_ENDOFEXCEPTLIST
);
791 if(ConfigChannel
.use_except
|| (dir
== MODE_DEL
))
798 /* if +I is disabled, allow all but +I locally */
799 if(!ConfigChannel
.use_invex
&& MyClient(source_p
) &&
800 (dir
== MODE_ADD
) && (parc
> *parn
))
803 list
= &chptr
->invexlist
;
804 errorval
= SM_ERR_RPL_I
;
805 rpl_list_p
= form_str(RPL_INVITELIST
);
806 rpl_endlist_p
= form_str(RPL_ENDOFINVITELIST
);
808 if(ConfigChannel
.use_invex
|| (dir
== MODE_DEL
))
815 list
= &chptr
->quietlist
;
816 errorval
= SM_ERR_RPL_Q
;
817 rpl_list_p
= form_str(RPL_QUIETLIST
);
818 rpl_endlist_p
= form_str(RPL_ENDOFQUIETLIST
);
823 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "chm_ban() called with unknown type!");
827 if(dir
== 0 || parc
<= *parn
)
829 if((*errors
& errorval
) != 0)
833 /* non-ops cant see +eI lists.. */
834 /* note that this is still permitted if +e/+I are mlocked. */
835 if(alevel
< CHFL_CHANOP
&& mode_type
!= CHFL_BAN
&&
836 mode_type
!= CHFL_QUIET
)
838 if(!(*errors
& SM_ERR_NOOPS
))
839 sendto_one(source_p
, form_str(ERR_CHANOPRIVSNEEDED
),
840 me
.name
, source_p
->name
, chptr
->chname
);
841 *errors
|= SM_ERR_NOOPS
;
845 RB_DLINK_FOREACH(ptr
, list
->head
)
850 snprintf(buf
, sizeof(buf
), "%s$%s", banptr
->banstr
, banptr
->forward
);
852 rb_strlcpy(buf
, banptr
->banstr
, sizeof(buf
));
854 sendto_one(source_p
, rpl_list_p
,
855 me
.name
, source_p
->name
, chptr
->chname
,
856 buf
, banptr
->who
, banptr
->when
);
858 sendto_one(source_p
, rpl_endlist_p
, me
.name
, source_p
->name
, chptr
->chname
);
862 if(!allow_mode_change(source_p
, chptr
, alevel
, errors
, c
))
866 if(MyClient(source_p
) && (++mode_limit
> MAXMODEPARAMS
))
869 raw_mask
= parv
[(*parn
)];
872 /* empty ban, or starts with ':' which messes up s2s, ignore it */
873 if(EmptyString(raw_mask
) || *raw_mask
== ':')
876 if(!MyClient(source_p
))
878 if(strchr(raw_mask
, ' '))
884 mask
= pretty_mask(raw_mask
);
886 /* we'd have problems parsing this, hyb6 does it too
887 * also make sure it will always fit on a line with channel
890 if(strlen(mask
) > MIN(BANLEN
, MODEBUFLEN
- 5))
892 sendto_one_numeric(source_p
, ERR_INVALIDBAN
,
893 form_str(ERR_INVALIDBAN
),
894 chptr
->chname
, c
, raw_mask
);
898 /* Look for a $ after the first character.
899 * As the first character, it marks an extban; afterwards
900 * it delimits a forward channel.
902 if ((forward
= strchr(mask
+1, '$')) != NULL
)
905 if (*forward
== '\0')
909 /* if we're adding a NEW id */
912 if (*mask
== '$' && MyClient(source_p
))
914 if (!valid_extban(mask
, source_p
, chptr
, mode_type
))
916 sendto_one_numeric(source_p
, ERR_INVALIDBAN
,
917 form_str(ERR_INVALIDBAN
),
918 chptr
->chname
, c
, raw_mask
);
923 /* For compatibility, only check the forward channel from
924 * local clients. Accept any forward channel from servers.
926 if(forward
!= NULL
&& MyClient(source_p
))
928 /* For simplicity and future flexibility, do not
929 * allow '$' in forwarding targets.
931 if(!ConfigChannel
.use_forward
||
932 strchr(forward
, '$') != NULL
)
934 sendto_one_numeric(source_p
, ERR_INVALIDBAN
,
935 form_str(ERR_INVALIDBAN
),
936 chptr
->chname
, c
, raw_mask
);
939 /* check_forward() sends its own error message */
940 if(!check_forward(source_p
, chptr
, forward
))
942 /* Forwards only make sense for bans. */
943 if(mode_type
!= CHFL_BAN
)
945 sendto_one_numeric(source_p
, ERR_INVALIDBAN
,
946 form_str(ERR_INVALIDBAN
),
947 chptr
->chname
, c
, raw_mask
);
952 /* dont allow local clients to overflow the banlist, dont
953 * let remote servers set duplicate bans
955 if(!add_id(source_p
, chptr
, mask
, forward
, list
, mode_type
))
961 mode_changes
[mode_count
].letter
= c
;
962 mode_changes
[mode_count
].dir
= MODE_ADD
;
963 mode_changes
[mode_count
].mems
= mems
;
964 mode_changes
[mode_count
].id
= NULL
;
965 mode_changes
[mode_count
++].arg
= mask
;
967 else if(dir
== MODE_DEL
)
970 static char buf
[BANLEN
* MAXMODEPARAMS
];
971 int old_removed_mask_pos
= removed_mask_pos
;
972 if((removed
= del_id(chptr
, mask
, list
, mode_type
)) == NULL
)
974 /* mask isn't a valid ban, check raw_mask */
975 if((removed
= del_id(chptr
, raw_mask
, list
, mode_type
)) != NULL
)
979 if(removed
&& removed
->forward
)
980 removed_mask_pos
+= snprintf(buf
+ old_removed_mask_pos
, sizeof(buf
), "%s$%s", removed
->banstr
, removed
->forward
) + 1;
982 removed_mask_pos
+= rb_strlcpy(buf
+ old_removed_mask_pos
, mask
, sizeof(buf
)) + 1;
989 mode_changes
[mode_count
].letter
= c
;
990 mode_changes
[mode_count
].dir
= MODE_DEL
;
991 mode_changes
[mode_count
].mems
= mems
;
992 mode_changes
[mode_count
].id
= NULL
;
993 mode_changes
[mode_count
++].arg
= buf
+ old_removed_mask_pos
;
998 chm_op(struct Client
*source_p
, struct Channel
*chptr
,
999 int alevel
, int parc
, int *parn
,
1000 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
1002 struct membership
*mstptr
;
1004 struct Client
*targ_p
;
1006 if(!allow_mode_change(source_p
, chptr
, alevel
, errors
, c
))
1009 if((dir
== MODE_QUERY
) || (parc
<= *parn
))
1012 opnick
= parv
[(*parn
)];
1016 if(EmptyString(opnick
))
1018 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
, form_str(ERR_NOSUCHNICK
), "*");
1022 if((targ_p
= find_chasing(source_p
, opnick
, NULL
)) == NULL
)
1027 mstptr
= find_channel_membership(chptr
, targ_p
);
1031 if(!(*errors
& SM_ERR_NOTONCHANNEL
) && MyClient(source_p
))
1032 sendto_one_numeric(source_p
, ERR_USERNOTINCHANNEL
,
1033 form_str(ERR_USERNOTINCHANNEL
), opnick
, chptr
->chname
);
1034 *errors
|= SM_ERR_NOTONCHANNEL
;
1038 if(MyClient(source_p
) && (++mode_limit
> MAXMODEPARAMS
))
1043 if(targ_p
== source_p
&& mstptr
->flags
& CHFL_CHANOP
)
1046 mode_changes
[mode_count
].letter
= c
;
1047 mode_changes
[mode_count
].dir
= MODE_ADD
;
1048 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
1049 mode_changes
[mode_count
].id
= targ_p
->id
;
1050 mode_changes
[mode_count
++].arg
= targ_p
->name
;
1052 mstptr
->flags
|= CHFL_CHANOP
;
1056 if(MyClient(source_p
) && IsService(targ_p
))
1058 sendto_one(source_p
, form_str(ERR_ISCHANSERVICE
),
1059 me
.name
, source_p
->name
, targ_p
->name
, chptr
->chname
);
1063 mode_changes
[mode_count
].letter
= c
;
1064 mode_changes
[mode_count
].dir
= MODE_DEL
;
1065 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
1066 mode_changes
[mode_count
].id
= targ_p
->id
;
1067 mode_changes
[mode_count
++].arg
= targ_p
->name
;
1069 mstptr
->flags
&= ~CHFL_CHANOP
;
1074 chm_voice(struct Client
*source_p
, struct Channel
*chptr
,
1075 int alevel
, int parc
, int *parn
,
1076 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
1078 struct membership
*mstptr
;
1080 struct Client
*targ_p
;
1082 if(!allow_mode_change(source_p
, chptr
, alevel
, errors
, c
))
1085 if((dir
== MODE_QUERY
) || parc
<= *parn
)
1088 opnick
= parv
[(*parn
)];
1092 if(EmptyString(opnick
))
1094 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
, form_str(ERR_NOSUCHNICK
), "*");
1098 if((targ_p
= find_chasing(source_p
, opnick
, NULL
)) == NULL
)
1103 mstptr
= find_channel_membership(chptr
, targ_p
);
1107 if(!(*errors
& SM_ERR_NOTONCHANNEL
) && MyClient(source_p
))
1108 sendto_one_numeric(source_p
, ERR_USERNOTINCHANNEL
,
1109 form_str(ERR_USERNOTINCHANNEL
), opnick
, chptr
->chname
);
1110 *errors
|= SM_ERR_NOTONCHANNEL
;
1114 if(MyClient(source_p
) && (++mode_limit
> MAXMODEPARAMS
))
1119 mode_changes
[mode_count
].letter
= c
;
1120 mode_changes
[mode_count
].dir
= MODE_ADD
;
1121 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
1122 mode_changes
[mode_count
].id
= targ_p
->id
;
1123 mode_changes
[mode_count
++].arg
= targ_p
->name
;
1125 mstptr
->flags
|= CHFL_VOICE
;
1129 mode_changes
[mode_count
].letter
= 'v';
1130 mode_changes
[mode_count
].dir
= MODE_DEL
;
1131 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
1132 mode_changes
[mode_count
].id
= targ_p
->id
;
1133 mode_changes
[mode_count
++].arg
= targ_p
->name
;
1135 mstptr
->flags
&= ~CHFL_VOICE
;
1140 chm_limit(struct Client
*source_p
, struct Channel
*chptr
,
1141 int alevel
, int parc
, int *parn
,
1142 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
1145 static char limitstr
[30];
1148 if(!allow_mode_change(source_p
, chptr
, alevel
, errors
, c
))
1151 if(dir
== MODE_QUERY
)
1154 if(MyClient(source_p
) && (++mode_limit_simple
> MAXMODES_SIMPLE
))
1157 if((dir
== MODE_ADD
) && parc
> *parn
)
1159 lstr
= parv
[(*parn
)];
1162 if(EmptyString(lstr
) || (limit
= atoi(lstr
)) <= 0)
1165 sprintf(limitstr
, "%d", limit
);
1167 mode_changes
[mode_count
].letter
= c
;
1168 mode_changes
[mode_count
].dir
= MODE_ADD
;
1169 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
1170 mode_changes
[mode_count
].id
= NULL
;
1171 mode_changes
[mode_count
++].arg
= limitstr
;
1173 chptr
->mode
.limit
= limit
;
1175 else if(dir
== MODE_DEL
)
1177 if(!chptr
->mode
.limit
)
1180 chptr
->mode
.limit
= 0;
1182 mode_changes
[mode_count
].letter
= c
;
1183 mode_changes
[mode_count
].dir
= MODE_DEL
;
1184 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
1185 mode_changes
[mode_count
].id
= NULL
;
1186 mode_changes
[mode_count
++].arg
= NULL
;
1191 chm_throttle(struct Client
*source_p
, struct Channel
*chptr
,
1192 int alevel
, int parc
, int *parn
,
1193 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
1195 int joins
= 0, timeslice
= 0;
1197 if(!allow_mode_change(source_p
, chptr
, alevel
, errors
, c
))
1200 if(dir
== MODE_QUERY
)
1203 if(MyClient(source_p
) && (++mode_limit_simple
> MAXMODES_SIMPLE
))
1206 if((dir
== MODE_ADD
) && parc
> *parn
)
1208 if (sscanf(parv
[(*parn
)], "%d:%d", &joins
, ×lice
) < 2)
1211 if(joins
<= 0 || timeslice
<= 0)
1214 mode_changes
[mode_count
].letter
= c
;
1215 mode_changes
[mode_count
].dir
= MODE_ADD
;
1216 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
1217 mode_changes
[mode_count
].id
= NULL
;
1218 mode_changes
[mode_count
++].arg
= parv
[(*parn
)];
1222 chptr
->mode
.join_num
= joins
;
1223 chptr
->mode
.join_time
= timeslice
;
1225 else if(dir
== MODE_DEL
)
1227 if(!chptr
->mode
.join_num
)
1230 chptr
->mode
.join_num
= 0;
1231 chptr
->mode
.join_time
= 0;
1232 chptr
->join_count
= 0;
1233 chptr
->join_delta
= 0;
1235 mode_changes
[mode_count
].letter
= c
;
1236 mode_changes
[mode_count
].dir
= MODE_DEL
;
1237 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
1238 mode_changes
[mode_count
].id
= NULL
;
1239 mode_changes
[mode_count
++].arg
= NULL
;
1244 chm_forward(struct Client
*source_p
, struct Channel
*chptr
,
1245 int alevel
, int parc
, int *parn
,
1246 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
1248 const char *forward
;
1250 /* if +f is disabled, ignore local attempts to set it */
1251 if(!ConfigChannel
.use_forward
&& MyClient(source_p
) &&
1252 (dir
== MODE_ADD
) && (parc
> *parn
))
1255 if(dir
== MODE_QUERY
|| (dir
== MODE_ADD
&& parc
<= *parn
))
1257 if (!(*errors
& SM_ERR_RPL_F
))
1259 if (*chptr
->mode
.forward
== '\0')
1260 sendto_one_notice(source_p
, ":%s has no forward channel", chptr
->chname
);
1262 sendto_one_notice(source_p
, ":%s forward channel is %s", chptr
->chname
, chptr
->mode
.forward
);
1263 *errors
|= SM_ERR_RPL_F
;
1268 #ifndef FORWARD_OPERONLY
1269 if(!allow_mode_change(source_p
, chptr
, alevel
, errors
, c
))
1272 if(!IsOper(source_p
) && !IsServer(source_p
))
1274 if(!(*errors
& SM_ERR_NOPRIVS
))
1275 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
, form_str(ERR_NOPRIVILEGES
));
1276 *errors
|= SM_ERR_NOPRIVS
;
1281 if(MyClient(source_p
) && (++mode_limit_simple
> MAXMODES_SIMPLE
))
1284 if(dir
== MODE_ADD
&& parc
> *parn
)
1286 forward
= parv
[(*parn
)];
1289 if(EmptyString(forward
))
1292 if(!check_forward(source_p
, chptr
, forward
))
1295 rb_strlcpy(chptr
->mode
.forward
, forward
, sizeof(chptr
->mode
.forward
));
1297 mode_changes
[mode_count
].letter
= c
;
1298 mode_changes
[mode_count
].dir
= MODE_ADD
;
1299 mode_changes
[mode_count
].mems
=
1300 ConfigChannel
.use_forward
? ALL_MEMBERS
: ONLY_SERVERS
;
1301 mode_changes
[mode_count
].id
= NULL
;
1302 mode_changes
[mode_count
++].arg
= forward
;
1304 else if(dir
== MODE_DEL
)
1306 if(!(*chptr
->mode
.forward
))
1309 *chptr
->mode
.forward
= '\0';
1311 mode_changes
[mode_count
].letter
= c
;
1312 mode_changes
[mode_count
].dir
= MODE_DEL
;
1313 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
1314 mode_changes
[mode_count
].id
= NULL
;
1315 mode_changes
[mode_count
++].arg
= NULL
;
1320 chm_key(struct Client
*source_p
, struct Channel
*chptr
,
1321 int alevel
, int parc
, int *parn
,
1322 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
1326 if(!allow_mode_change(source_p
, chptr
, alevel
, errors
, c
))
1329 if(dir
== MODE_QUERY
)
1332 if(MyClient(source_p
) && (++mode_limit_simple
> MAXMODES_SIMPLE
))
1335 if((dir
== MODE_ADD
) && parc
> *parn
)
1337 key
= LOCAL_COPY(parv
[(*parn
)]);
1340 if(MyClient(source_p
))
1343 fix_key_remote(key
);
1345 if(EmptyString(key
))
1348 s_assert(key
[0] != ' ');
1349 rb_strlcpy(chptr
->mode
.key
, key
, sizeof(chptr
->mode
.key
));
1351 mode_changes
[mode_count
].letter
= c
;
1352 mode_changes
[mode_count
].dir
= MODE_ADD
;
1353 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
1354 mode_changes
[mode_count
].id
= NULL
;
1355 mode_changes
[mode_count
++].arg
= chptr
->mode
.key
;
1357 else if(dir
== MODE_DEL
)
1359 static char splat
[] = "*";
1365 if(!(*chptr
->mode
.key
))
1368 /* hack time. when we get a +k-k mode, the +k arg is
1369 * chptr->mode.key, which the -k sets to \0, so hunt for a
1370 * +k when we get a -k, and set the arg to splat. --anfl
1372 for(i
= 0; i
< mode_count
; i
++)
1374 if(mode_changes
[i
].letter
== 'k' && mode_changes
[i
].dir
== MODE_ADD
)
1375 mode_changes
[i
].arg
= splat
;
1378 *chptr
->mode
.key
= 0;
1380 mode_changes
[mode_count
].letter
= c
;
1381 mode_changes
[mode_count
].dir
= MODE_DEL
;
1382 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
1383 mode_changes
[mode_count
].id
= NULL
;
1384 mode_changes
[mode_count
++].arg
= "*";
1389 struct ChannelMode chmode_table
[256] =
1391 {chm_nosuch
, 0 }, /* 0x00 */
1392 {chm_nosuch
, 0 }, /* 0x01 */
1393 {chm_nosuch
, 0 }, /* 0x02 */
1394 {chm_nosuch
, 0 }, /* 0x03 */
1395 {chm_nosuch
, 0 }, /* 0x04 */
1396 {chm_nosuch
, 0 }, /* 0x05 */
1397 {chm_nosuch
, 0 }, /* 0x06 */
1398 {chm_nosuch
, 0 }, /* 0x07 */
1399 {chm_nosuch
, 0 }, /* 0x08 */
1400 {chm_nosuch
, 0 }, /* 0x09 */
1401 {chm_nosuch
, 0 }, /* 0x0a */
1402 {chm_nosuch
, 0 }, /* 0x0b */
1403 {chm_nosuch
, 0 }, /* 0x0c */
1404 {chm_nosuch
, 0 }, /* 0x0d */
1405 {chm_nosuch
, 0 }, /* 0x0e */
1406 {chm_nosuch
, 0 }, /* 0x0f */
1407 {chm_nosuch
, 0 }, /* 0x10 */
1408 {chm_nosuch
, 0 }, /* 0x11 */
1409 {chm_nosuch
, 0 }, /* 0x12 */
1410 {chm_nosuch
, 0 }, /* 0x13 */
1411 {chm_nosuch
, 0 }, /* 0x14 */
1412 {chm_nosuch
, 0 }, /* 0x15 */
1413 {chm_nosuch
, 0 }, /* 0x16 */
1414 {chm_nosuch
, 0 }, /* 0x17 */
1415 {chm_nosuch
, 0 }, /* 0x18 */
1416 {chm_nosuch
, 0 }, /* 0x19 */
1417 {chm_nosuch
, 0 }, /* 0x1a */
1418 {chm_nosuch
, 0 }, /* 0x1b */
1419 {chm_nosuch
, 0 }, /* 0x1c */
1420 {chm_nosuch
, 0 }, /* 0x1d */
1421 {chm_nosuch
, 0 }, /* 0x1e */
1422 {chm_nosuch
, 0 }, /* 0x1f */
1423 {chm_nosuch
, 0 }, /* 0x20 */
1424 {chm_nosuch
, 0 }, /* 0x21 */
1425 {chm_nosuch
, 0 }, /* 0x22 */
1426 {chm_nosuch
, 0 }, /* 0x23 */
1427 {chm_nosuch
, 0 }, /* 0x24 */
1428 {chm_nosuch
, 0 }, /* 0x25 */
1429 {chm_nosuch
, 0 }, /* 0x26 */
1430 {chm_nosuch
, 0 }, /* 0x27 */
1431 {chm_nosuch
, 0 }, /* 0x28 */
1432 {chm_nosuch
, 0 }, /* 0x29 */
1433 {chm_nosuch
, 0 }, /* 0x2a */
1434 {chm_nosuch
, 0 }, /* 0x2b */
1435 {chm_nosuch
, 0 }, /* 0x2c */
1436 {chm_nosuch
, 0 }, /* 0x2d */
1437 {chm_nosuch
, 0 }, /* 0x2e */
1438 {chm_nosuch
, 0 }, /* 0x2f */
1439 {chm_nosuch
, 0 }, /* 0x30 */
1440 {chm_nosuch
, 0 }, /* 0x31 */
1441 {chm_nosuch
, 0 }, /* 0x32 */
1442 {chm_nosuch
, 0 }, /* 0x33 */
1443 {chm_nosuch
, 0 }, /* 0x34 */
1444 {chm_nosuch
, 0 }, /* 0x35 */
1445 {chm_nosuch
, 0 }, /* 0x36 */
1446 {chm_nosuch
, 0 }, /* 0x37 */
1447 {chm_nosuch
, 0 }, /* 0x38 */
1448 {chm_nosuch
, 0 }, /* 0x39 */
1449 {chm_nosuch
, 0 }, /* 0x3a */
1450 {chm_nosuch
, 0 }, /* 0x3b */
1451 {chm_nosuch
, 0 }, /* 0x3c */
1452 {chm_nosuch
, 0 }, /* 0x3d */
1453 {chm_nosuch
, 0 }, /* 0x3e */
1454 {chm_nosuch
, 0 }, /* 0x3f */
1456 {chm_nosuch
, 0 }, /* @ */
1457 {chm_nosuch
, 0 }, /* A */
1458 {chm_nosuch
, 0 }, /* B */
1459 {chm_nosuch
, 0 }, /* C */
1460 {chm_nosuch
, 0 }, /* D */
1461 {chm_nosuch
, 0 }, /* E */
1462 {chm_simple
, MODE_FREETARGET
}, /* F */
1463 {chm_nosuch
, 0 }, /* G */
1464 {chm_nosuch
, 0 }, /* H */
1465 {chm_ban
, CHFL_INVEX
}, /* I */
1466 {chm_nosuch
, 0 }, /* J */
1467 {chm_nosuch
, 0 }, /* K */
1468 {chm_staff
, MODE_EXLIMIT
}, /* L */
1469 {chm_nosuch
, 0 }, /* M */
1470 {chm_nosuch
, 0 }, /* N */
1471 {chm_nosuch
, 0 }, /* O */
1472 {chm_staff
, MODE_PERMANENT
}, /* P */
1473 {chm_simple
, MODE_DISFORWARD
}, /* Q */
1474 {chm_nosuch
, 0 }, /* R */
1475 {chm_nosuch
, 0 }, /* S */
1476 {chm_nosuch
, 0 }, /* T */
1477 {chm_nosuch
, 0 }, /* U */
1478 {chm_nosuch
, 0 }, /* V */
1479 {chm_nosuch
, 0 }, /* W */
1480 {chm_nosuch
, 0 }, /* X */
1481 {chm_nosuch
, 0 }, /* Y */
1482 {chm_nosuch
, 0 }, /* Z */
1489 {chm_nosuch
, 0 }, /* a */
1490 {chm_ban
, CHFL_BAN
}, /* b */
1491 {chm_nosuch
, 0 }, /* c */
1492 {chm_nosuch
, 0 }, /* d */
1493 {chm_ban
, CHFL_EXCEPTION
}, /* e */
1494 {chm_forward
, 0 }, /* f */
1495 {chm_simple
, MODE_FREEINVITE
}, /* g */
1496 {chm_nosuch
, 0 }, /* h */
1497 {chm_simple
, MODE_INVITEONLY
}, /* i */
1498 {chm_throttle
, 0 }, /* j */
1499 {chm_key
, 0 }, /* k */
1500 {chm_limit
, 0 }, /* l */
1501 {chm_simple
, MODE_MODERATED
}, /* m */
1502 {chm_simple
, MODE_NOPRIVMSGS
}, /* n */
1503 {chm_op
, 0 }, /* o */
1504 {chm_simple
, MODE_PRIVATE
}, /* p */
1505 {chm_ban
, CHFL_QUIET
}, /* q */
1506 {chm_simple
, MODE_REGONLY
}, /* r */
1507 {chm_simple
, MODE_SECRET
}, /* s */
1508 {chm_simple
, MODE_TOPICLIMIT
}, /* t */
1509 {chm_nosuch
, 0 }, /* u */
1510 {chm_voice
, 0 }, /* v */
1511 {chm_nosuch
, 0 }, /* w */
1512 {chm_nosuch
, 0 }, /* x */
1513 {chm_nosuch
, 0 }, /* y */
1514 {chm_simple
, MODE_OPMODERATE
}, /* z */
1516 {chm_nosuch
, 0 }, /* 0x7b */
1517 {chm_nosuch
, 0 }, /* 0x7c */
1518 {chm_nosuch
, 0 }, /* 0x7d */
1519 {chm_nosuch
, 0 }, /* 0x7e */
1520 {chm_nosuch
, 0 }, /* 0x7f */
1522 {chm_nosuch
, 0 }, /* 0x80 */
1523 {chm_nosuch
, 0 }, /* 0x81 */
1524 {chm_nosuch
, 0 }, /* 0x82 */
1525 {chm_nosuch
, 0 }, /* 0x83 */
1526 {chm_nosuch
, 0 }, /* 0x84 */
1527 {chm_nosuch
, 0 }, /* 0x85 */
1528 {chm_nosuch
, 0 }, /* 0x86 */
1529 {chm_nosuch
, 0 }, /* 0x87 */
1530 {chm_nosuch
, 0 }, /* 0x88 */
1531 {chm_nosuch
, 0 }, /* 0x89 */
1532 {chm_nosuch
, 0 }, /* 0x8a */
1533 {chm_nosuch
, 0 }, /* 0x8b */
1534 {chm_nosuch
, 0 }, /* 0x8c */
1535 {chm_nosuch
, 0 }, /* 0x8d */
1536 {chm_nosuch
, 0 }, /* 0x8e */
1537 {chm_nosuch
, 0 }, /* 0x8f */
1539 {chm_nosuch
, 0 }, /* 0x90 */
1540 {chm_nosuch
, 0 }, /* 0x91 */
1541 {chm_nosuch
, 0 }, /* 0x92 */
1542 {chm_nosuch
, 0 }, /* 0x93 */
1543 {chm_nosuch
, 0 }, /* 0x94 */
1544 {chm_nosuch
, 0 }, /* 0x95 */
1545 {chm_nosuch
, 0 }, /* 0x96 */
1546 {chm_nosuch
, 0 }, /* 0x97 */
1547 {chm_nosuch
, 0 }, /* 0x98 */
1548 {chm_nosuch
, 0 }, /* 0x99 */
1549 {chm_nosuch
, 0 }, /* 0x9a */
1550 {chm_nosuch
, 0 }, /* 0x9b */
1551 {chm_nosuch
, 0 }, /* 0x9c */
1552 {chm_nosuch
, 0 }, /* 0x9d */
1553 {chm_nosuch
, 0 }, /* 0x9e */
1554 {chm_nosuch
, 0 }, /* 0x9f */
1556 {chm_nosuch
, 0 }, /* 0xa0 */
1557 {chm_nosuch
, 0 }, /* 0xa1 */
1558 {chm_nosuch
, 0 }, /* 0xa2 */
1559 {chm_nosuch
, 0 }, /* 0xa3 */
1560 {chm_nosuch
, 0 }, /* 0xa4 */
1561 {chm_nosuch
, 0 }, /* 0xa5 */
1562 {chm_nosuch
, 0 }, /* 0xa6 */
1563 {chm_nosuch
, 0 }, /* 0xa7 */
1564 {chm_nosuch
, 0 }, /* 0xa8 */
1565 {chm_nosuch
, 0 }, /* 0xa9 */
1566 {chm_nosuch
, 0 }, /* 0xaa */
1567 {chm_nosuch
, 0 }, /* 0xab */
1568 {chm_nosuch
, 0 }, /* 0xac */
1569 {chm_nosuch
, 0 }, /* 0xad */
1570 {chm_nosuch
, 0 }, /* 0xae */
1571 {chm_nosuch
, 0 }, /* 0xaf */
1573 {chm_nosuch
, 0 }, /* 0xb0 */
1574 {chm_nosuch
, 0 }, /* 0xb1 */
1575 {chm_nosuch
, 0 }, /* 0xb2 */
1576 {chm_nosuch
, 0 }, /* 0xb3 */
1577 {chm_nosuch
, 0 }, /* 0xb4 */
1578 {chm_nosuch
, 0 }, /* 0xb5 */
1579 {chm_nosuch
, 0 }, /* 0xb6 */
1580 {chm_nosuch
, 0 }, /* 0xb7 */
1581 {chm_nosuch
, 0 }, /* 0xb8 */
1582 {chm_nosuch
, 0 }, /* 0xb9 */
1583 {chm_nosuch
, 0 }, /* 0xba */
1584 {chm_nosuch
, 0 }, /* 0xbb */
1585 {chm_nosuch
, 0 }, /* 0xbc */
1586 {chm_nosuch
, 0 }, /* 0xbd */
1587 {chm_nosuch
, 0 }, /* 0xbe */
1588 {chm_nosuch
, 0 }, /* 0xbf */
1590 {chm_nosuch
, 0 }, /* 0xc0 */
1591 {chm_nosuch
, 0 }, /* 0xc1 */
1592 {chm_nosuch
, 0 }, /* 0xc2 */
1593 {chm_nosuch
, 0 }, /* 0xc3 */
1594 {chm_nosuch
, 0 }, /* 0xc4 */
1595 {chm_nosuch
, 0 }, /* 0xc5 */
1596 {chm_nosuch
, 0 }, /* 0xc6 */
1597 {chm_nosuch
, 0 }, /* 0xc7 */
1598 {chm_nosuch
, 0 }, /* 0xc8 */
1599 {chm_nosuch
, 0 }, /* 0xc9 */
1600 {chm_nosuch
, 0 }, /* 0xca */
1601 {chm_nosuch
, 0 }, /* 0xcb */
1602 {chm_nosuch
, 0 }, /* 0xcc */
1603 {chm_nosuch
, 0 }, /* 0xcd */
1604 {chm_nosuch
, 0 }, /* 0xce */
1605 {chm_nosuch
, 0 }, /* 0xcf */
1607 {chm_nosuch
, 0 }, /* 0xd0 */
1608 {chm_nosuch
, 0 }, /* 0xd1 */
1609 {chm_nosuch
, 0 }, /* 0xd2 */
1610 {chm_nosuch
, 0 }, /* 0xd3 */
1611 {chm_nosuch
, 0 }, /* 0xd4 */
1612 {chm_nosuch
, 0 }, /* 0xd5 */
1613 {chm_nosuch
, 0 }, /* 0xd6 */
1614 {chm_nosuch
, 0 }, /* 0xd7 */
1615 {chm_nosuch
, 0 }, /* 0xd8 */
1616 {chm_nosuch
, 0 }, /* 0xd9 */
1617 {chm_nosuch
, 0 }, /* 0xda */
1618 {chm_nosuch
, 0 }, /* 0xdb */
1619 {chm_nosuch
, 0 }, /* 0xdc */
1620 {chm_nosuch
, 0 }, /* 0xdd */
1621 {chm_nosuch
, 0 }, /* 0xde */
1622 {chm_nosuch
, 0 }, /* 0xdf */
1624 {chm_nosuch
, 0 }, /* 0xe0 */
1625 {chm_nosuch
, 0 }, /* 0xe1 */
1626 {chm_nosuch
, 0 }, /* 0xe2 */
1627 {chm_nosuch
, 0 }, /* 0xe3 */
1628 {chm_nosuch
, 0 }, /* 0xe4 */
1629 {chm_nosuch
, 0 }, /* 0xe5 */
1630 {chm_nosuch
, 0 }, /* 0xe6 */
1631 {chm_nosuch
, 0 }, /* 0xe7 */
1632 {chm_nosuch
, 0 }, /* 0xe8 */
1633 {chm_nosuch
, 0 }, /* 0xe9 */
1634 {chm_nosuch
, 0 }, /* 0xea */
1635 {chm_nosuch
, 0 }, /* 0xeb */
1636 {chm_nosuch
, 0 }, /* 0xec */
1637 {chm_nosuch
, 0 }, /* 0xed */
1638 {chm_nosuch
, 0 }, /* 0xee */
1639 {chm_nosuch
, 0 }, /* 0xef */
1641 {chm_nosuch
, 0 }, /* 0xf0 */
1642 {chm_nosuch
, 0 }, /* 0xf1 */
1643 {chm_nosuch
, 0 }, /* 0xf2 */
1644 {chm_nosuch
, 0 }, /* 0xf3 */
1645 {chm_nosuch
, 0 }, /* 0xf4 */
1646 {chm_nosuch
, 0 }, /* 0xf5 */
1647 {chm_nosuch
, 0 }, /* 0xf6 */
1648 {chm_nosuch
, 0 }, /* 0xf7 */
1649 {chm_nosuch
, 0 }, /* 0xf8 */
1650 {chm_nosuch
, 0 }, /* 0xf9 */
1651 {chm_nosuch
, 0 }, /* 0xfa */
1652 {chm_nosuch
, 0 }, /* 0xfb */
1653 {chm_nosuch
, 0 }, /* 0xfc */
1654 {chm_nosuch
, 0 }, /* 0xfd */
1655 {chm_nosuch
, 0 }, /* 0xfe */
1656 {chm_nosuch
, 0 }, /* 0xff */
1661 /* set_channel_mode()
1663 * inputs - client, source, channel, membership pointer, params
1665 * side effects - channel modes/memberships are changed, MODE is issued
1667 * Extensively modified to be hotpluggable, 03/09/06 -- nenolod
1670 set_channel_mode(struct Client
*client_p
, struct Client
*source_p
,
1671 struct Channel
*chptr
, struct membership
*msptr
, int parc
, const char *parv
[])
1673 static char modebuf
[BUFSIZE
];
1674 static char parabuf
[BUFSIZE
];
1677 int cur_len
, mlen
, paralen
, paracount
, arglen
, len
;
1679 int dir
= MODE_QUERY
;
1683 const char *ml
= parv
[0];
1685 struct Client
*fakesource_p
;
1686 int reauthorized
= 0; /* if we change from MODE_QUERY to MODE_ADD/MODE_DEL, then reauth once, ugly but it works */
1687 int flags_list
[3] = { ALL_MEMBERS
, ONLY_CHANOPS
, ONLY_OPERS
};
1690 removed_mask_pos
= 0;
1693 mode_limit_simple
= 0;
1695 /* Hide connecting server on netburst -- jilles */
1696 if (ConfigServerHide
.flatten_links
&& IsServer(source_p
) && !has_id(source_p
) && !HasSentEob(source_p
))
1699 fakesource_p
= source_p
;
1701 alevel
= get_channel_access(source_p
, chptr
, msptr
, dir
, reconstruct_parv(parc
, parv
));
1703 for(; (c
= *ml
) != 0; ml
++)
1711 alevel
= get_channel_access(source_p
, chptr
, msptr
, dir
, reconstruct_parv(parc
, parv
));
1719 alevel
= get_channel_access(source_p
, chptr
, msptr
, dir
, reconstruct_parv(parc
, parv
));
1727 chmode_table
[(unsigned char) c
].set_func(fakesource_p
, chptr
, alevel
,
1730 chmode_table
[(unsigned char) c
].mode_type
);
1735 /* bail out if we have nothing to do... */
1739 if(IsServer(source_p
))
1740 mlen
= sprintf(modebuf
, ":%s MODE %s ", fakesource_p
->name
, chptr
->chname
);
1742 mlen
= sprintf(modebuf
, ":%s!%s@%s MODE %s ",
1743 source_p
->name
, source_p
->username
,
1744 source_p
->host
, chptr
->chname
);
1746 for(j
= 0; j
< 3; j
++)
1748 flags
= flags_list
[j
];
1750 mbuf
= modebuf
+ mlen
;
1753 paracount
= paralen
= 0;
1756 for(i
= 0; i
< mode_count
; i
++)
1758 if(mode_changes
[i
].letter
== 0 || mode_changes
[i
].mems
!= flags
)
1761 if(mode_changes
[i
].arg
!= NULL
)
1763 arglen
= strlen(mode_changes
[i
].arg
);
1765 if(arglen
> MODEBUFLEN
- 5)
1771 /* if we're creeping over MAXMODEPARAMSSERV, or over
1772 * bufsize (4 == +/-,modechar,two spaces) send now.
1774 if(mode_changes
[i
].arg
!= NULL
&&
1775 ((paracount
== MAXMODEPARAMSSERV
) ||
1776 ((cur_len
+ paralen
+ arglen
+ 4) > (BUFSIZE
- 3))))
1781 sendto_channel_local(flags
, chptr
, "%s %s", modebuf
,
1786 paracount
= paralen
= 0;
1788 mbuf
= modebuf
+ mlen
;
1794 if(dir
!= mode_changes
[i
].dir
)
1796 *mbuf
++ = (mode_changes
[i
].dir
== MODE_ADD
) ? '+' : '-';
1798 dir
= mode_changes
[i
].dir
;
1801 *mbuf
++ = mode_changes
[i
].letter
;
1804 if(mode_changes
[i
].arg
!= NULL
)
1807 len
= sprintf(pbuf
, "%s ", mode_changes
[i
].arg
);
1813 if(paralen
&& parabuf
[paralen
- 1] == ' ')
1814 parabuf
[paralen
- 1] = '\0';
1818 sendto_channel_local(flags
, chptr
, "%s %s", modebuf
, parabuf
);
1821 /* only propagate modes originating locally, or if we're hubbing */
1822 if(MyClient(source_p
) || rb_dlink_list_length(&serv_list
) > 1)
1823 send_cap_mode_changes(client_p
, source_p
, chptr
, mode_changes
, mode_count
);
1826 /* set_channel_mlock()
1828 * inputs - client, source, channel, params
1830 * side effects - channel mlock is changed / MLOCK is propagated
1833 set_channel_mlock(struct Client
*client_p
, struct Client
*source_p
,
1834 struct Channel
*chptr
, const char *newmlock
, bool propagate
)
1836 rb_free(chptr
->mode_lock
);
1837 chptr
->mode_lock
= newmlock
? rb_strdup(newmlock
) : NULL
;
1841 sendto_server(client_p
, NULL
, CAP_TS6
| CAP_MLOCK
, NOCAPS
, ":%s MLOCK %ld %s :%s",
1842 source_p
->id
, (long) chptr
->channelts
, chptr
->chname
,
1843 chptr
->mode_lock
? chptr
->mode_lock
: "");