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
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
;
69 char cflagsmyinfo
[256];
71 int chmode_flags
[256];
73 /* OPTIMIZE ME! -- dwr */
75 construct_noparam_modes(void)
78 char *ptr
= cflagsbuf
;
79 char *ptr2
= cflagsmyinfo
;
80 static int prev_chmode_flags
[256];
85 for(i
= 0; i
< 256; i
++)
87 if( !(chmode_table
[i
].set_func
== chm_ban
) &&
88 !(chmode_table
[i
].set_func
== chm_forward
) &&
89 !(chmode_table
[i
].set_func
== chm_throttle
) &&
90 !(chmode_table
[i
].set_func
== chm_key
) &&
91 !(chmode_table
[i
].set_func
== chm_limit
) &&
92 !(chmode_table
[i
].set_func
== chm_owner
) &&
93 !(chmode_table
[i
].set_func
== chm_op
) &&
94 !(chmode_table
[i
].set_func
== chm_halfop
) &&
95 !(chmode_table
[i
].set_func
== chm_voice
))
97 chmode_flags
[i
] = chmode_table
[i
].mode_type
;
104 if (prev_chmode_flags
[i
] != 0 && prev_chmode_flags
[i
] != chmode_flags
[i
])
106 if (chmode_flags
[i
] == 0)
108 chmode_table
[i
].set_func
= chm_orphaned
;
109 sendto_realops_snomask(SNO_DEBUG
, L_ALL
, "Cmode +%c is now orphaned", i
);
113 sendto_realops_snomask(SNO_DEBUG
, L_ALL
, "Orphaned cmode +%c is picked up by module", i
);
115 chmode_flags
[i
] = prev_chmode_flags
[i
];
118 prev_chmode_flags
[i
] = chmode_flags
[i
];
120 switch (chmode_flags
[i
])
123 case MODE_DISFORWARD
:
124 if(ConfigChannel
.use_forward
)
131 if(rb_dlink_list_length(&service_list
))
138 if(chmode_flags
[i
] != 0)
144 /* Should we leave orphaned check here? -- dwr */
145 if(!(chmode_table
[i
].set_func
== chm_nosuch
) && !(chmode_table
[i
].set_func
== chm_orphaned
))
159 * outputs - an available cflag bitmask or
160 * 0 if no cflags are available
161 * side effects - NONE
164 find_cflag_slot(void)
166 unsigned int all_cflags
= 0, my_cflag
= 0, i
;
168 for (i
= 0; i
< 256; i
++)
169 all_cflags
|= chmode_flags
[i
];
171 for (my_cflag
= 1; my_cflag
&& (all_cflags
& my_cflag
);
178 get_channel_access(struct Client
*source_p
, struct membership
*msptr
)
180 if(!MyClient(source_p
) || is_owner(msptr
))
182 else if(is_chanop(msptr
))
184 else if(is_halfop(msptr
))
192 * inputs - client, channel, id to add, type
193 * outputs - 0 on failure, 1 on success
194 * side effects - given id is added to the appropriate list
197 add_id(struct Client
*source_p
, struct Channel
*chptr
, const char *banid
,
198 rb_dlink_list
* list
, long mode_type
)
200 struct Ban
*actualBan
;
201 static char who
[USERHOST_REPLYLEN
];
202 char *realban
= LOCAL_COPY(banid
);
205 /* dont let local clients overflow the banlist, or set redundant
208 if(MyClient(source_p
))
210 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
))
212 sendto_one(source_p
, form_str(ERR_BANLISTFULL
),
213 me
.name
, source_p
->name
, chptr
->chname
, realban
);
217 RB_DLINK_FOREACH(ptr
, list
->head
)
219 actualBan
= ptr
->data
;
220 if(mask_match(actualBan
->banstr
, realban
))
224 /* dont let remotes set duplicates */
227 RB_DLINK_FOREACH(ptr
, list
->head
)
229 actualBan
= ptr
->data
;
230 if(!irccmp(actualBan
->banstr
, realban
))
236 if(IsPerson(source_p
))
237 rb_sprintf(who
, "%s!%s@%s", source_p
->name
, source_p
->username
, source_p
->host
);
239 rb_strlcpy(who
, source_p
->name
, sizeof(who
));
241 actualBan
= allocate_ban(realban
, who
);
242 actualBan
->when
= rb_current_time();
244 rb_dlinkAdd(actualBan
, &actualBan
->node
, list
);
246 /* invalidate the can_send() cache */
247 if(mode_type
== CHFL_BAN
|| mode_type
== CHFL_QUIET
|| mode_type
== CHFL_EXCEPTION
)
255 * inputs - channel, id to remove, type
256 * outputs - 0 on failure, 1 on success
257 * side effects - given id is removed from the appropriate list
260 del_id(struct Channel
*chptr
, const char *banid
, rb_dlink_list
* list
, long mode_type
)
265 if(EmptyString(banid
))
268 RB_DLINK_FOREACH(ptr
, list
->head
)
272 if(irccmp(banid
, banptr
->banstr
) == 0)
274 rb_dlinkDelete(&banptr
->node
, list
);
277 /* invalidate the can_send() cache */
278 if(mode_type
== CHFL_BAN
|| mode_type
== CHFL_QUIET
|| mode_type
== CHFL_EXCEPTION
)
290 * input - string to check
291 * output - pointer to 'fixed' string, or "*" if empty
292 * side effects - any white space found becomes \0
295 check_string(char *s
)
298 static char splat
[] = "*";
315 * inputs - mask to pretty
316 * outputs - better version of the mask
317 * side effects - mask is chopped to limits, and transformed:
325 pretty_mask(const char *idmask
)
327 static char mask_buf
[BUFSIZE
];
329 char *nick
, *user
, *host
;
332 char ne
= 0, ue
= 0, he
= 0; /* save values at nick[NICKLEN], et all */
335 mask
= LOCAL_COPY(idmask
);
336 mask
= check_string(mask
);
339 nick
= user
= host
= splat
;
341 if((size_t) BUFSIZE
- mask_pos
< strlen(mask
) + 5)
344 old_mask_pos
= mask_pos
;
348 mask_pos
+= rb_sprintf(mask_buf
+ mask_pos
, "%s", mask
) + 1;
349 t
= mask_buf
+ old_mask_pos
+ 1;
355 return mask_buf
+ old_mask_pos
;
359 if((t
= strchr(mask
, '@')) != NULL
)
366 if((t
= strchr(mask
, '!')) != NULL
)
381 else if((t
= strchr(mask
, '!')) != NULL
)
390 else if(strchr(mask
, '.') != NULL
|| strchr(mask
, ':') != NULL
|| strchr(mask
, '/') != NULL
)
401 /* truncate values to max lengths */
402 if(strlen(nick
) > NICKLEN
- 1)
404 ne
= nick
[NICKLEN
- 1];
405 nick
[NICKLEN
- 1] = '\0';
407 if(strlen(user
) > USERLEN
)
410 user
[USERLEN
] = '\0';
412 if(strlen(host
) > HOSTLEN
)
415 host
[HOSTLEN
] = '\0';
418 mask_pos
+= rb_sprintf(mask_buf
+ mask_pos
, "%s!%s@%s", nick
, user
, host
) + 1;
420 /* restore mask, since we may need to use it again later */
426 nick
[NICKLEN
- 1] = ne
;
432 return mask_buf
+ old_mask_pos
;
438 * output - the same key, fixed
439 * side effects - anything below ascii 13 is discarded, ':' discarded,
440 * high ascii is dropped to lower half of ascii table
447 for(s
= t
= (u_char
*) arg
; (c
= *s
); s
++)
450 if(c
!= ':' && c
!= ',' && c
> ' ')
461 * ouput - the same key, fixed
462 * side effects - high ascii dropped to lower half of table,
463 * CR/LF/':' are dropped
466 fix_key_remote(char *arg
)
470 for(s
= t
= (u_char
*) arg
; (c
= *s
); s
++)
473 if((c
!= 0x0a) && (c
!= ':') && (c
!= ',') && (c
!= 0x0d) && (c
!= ' '))
483 * The handlers for each specific mode.
486 chm_nosuch(struct Client
*source_p
, struct Channel
*chptr
,
487 int alevel
, int parc
, int *parn
,
488 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
490 if(*errors
& SM_ERR_UNKNOWN
)
492 *errors
|= SM_ERR_UNKNOWN
;
493 sendto_one(source_p
, form_str(ERR_UNKNOWNMODE
), me
.name
, source_p
->name
, c
);
497 chm_simple(struct Client
*source_p
, struct Channel
*chptr
,
498 int alevel
, int parc
, int *parn
,
499 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
504 if(alevel
!= CHFL_CHANOP
&& alevel
!= CHFL_OWNER
&& alevel
!= CHFL_HALFOP
)
506 if (IsOverride(source_p
))
510 if(!(*errors
& SM_ERR_NOOPS
))
511 sendto_one(source_p
, form_str(ERR_CHANOPRIVSNEEDED
),
512 me
.name
, source_p
->name
, chptr
->chname
);
513 *errors
|= SM_ERR_NOOPS
;
518 if(MyClient(source_p
) && (++mode_limit_simple
> MAXMODES_SIMPLE
))
522 if((dir
== MODE_ADD
) && !(chptr
->mode
.mode
& mode_type
))
524 /* if +f is disabled, ignore an attempt to set +QF locally */
525 if(!ConfigChannel
.use_forward
&& MyClient(source_p
) &&
526 (c
== 'Q' || c
== 'F'))
529 chptr
->mode
.mode
|= mode_type
;
531 mode_changes
[mode_count
].letter
= c
;
532 mode_changes
[mode_count
].dir
= MODE_ADD
;
533 mode_changes
[mode_count
].caps
= 0;
534 mode_changes
[mode_count
].nocaps
= 0;
535 mode_changes
[mode_count
].id
= NULL
;
536 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
537 mode_changes
[mode_count
].override
= override
;
538 mode_changes
[mode_count
++].arg
= NULL
;
540 else if((dir
== MODE_DEL
) && (chptr
->mode
.mode
& mode_type
))
542 chptr
->mode
.mode
&= ~mode_type
;
544 mode_changes
[mode_count
].letter
= c
;
545 mode_changes
[mode_count
].dir
= MODE_DEL
;
546 mode_changes
[mode_count
].caps
= 0;
547 mode_changes
[mode_count
].nocaps
= 0;
548 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
549 mode_changes
[mode_count
].id
= NULL
;
550 mode_changes
[mode_count
].override
= override
;
551 mode_changes
[mode_count
++].arg
= NULL
;
556 chm_orphaned(struct Client
*source_p
, struct Channel
*chptr
,
557 int alevel
, int parc
, int *parn
,
558 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
560 if(MyClient(source_p
))
563 if((dir
== MODE_ADD
) && !(chptr
->mode
.mode
& mode_type
))
565 chptr
->mode
.mode
|= mode_type
;
567 mode_changes
[mode_count
].letter
= c
;
568 mode_changes
[mode_count
].dir
= MODE_ADD
;
569 mode_changes
[mode_count
].caps
= 0;
570 mode_changes
[mode_count
].nocaps
= 0;
571 mode_changes
[mode_count
].id
= NULL
;
572 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
573 mode_changes
[mode_count
++].arg
= NULL
;
575 else if((dir
== MODE_DEL
) && (chptr
->mode
.mode
& mode_type
))
577 chptr
->mode
.mode
&= ~mode_type
;
579 mode_changes
[mode_count
].letter
= c
;
580 mode_changes
[mode_count
].dir
= MODE_DEL
;
581 mode_changes
[mode_count
].caps
= 0;
582 mode_changes
[mode_count
].nocaps
= 0;
583 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
584 mode_changes
[mode_count
].id
= NULL
;
585 mode_changes
[mode_count
++].arg
= NULL
;
590 chm_staff(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(!IsOper(source_p
) && !IsServer(source_p
))
596 if(!(*errors
& SM_ERR_NOPRIVS
))
597 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
, form_str(ERR_NOPRIVILEGES
));
598 *errors
|= SM_ERR_NOPRIVS
;
601 if(MyClient(source_p
) && !IsOperResv(source_p
))
603 if(!(*errors
& SM_ERR_NOPRIVS
))
604 sendto_one(source_p
, form_str(ERR_NOPRIVS
), me
.name
,
605 source_p
->name
, "resv");
606 *errors
|= SM_ERR_NOPRIVS
;
610 if(MyClient(source_p
) && (++mode_limit_simple
> MAXMODES_SIMPLE
))
614 if((dir
== MODE_ADD
) && !(chptr
->mode
.mode
& mode_type
))
616 chptr
->mode
.mode
|= mode_type
;
618 mode_changes
[mode_count
].letter
= c
;
619 mode_changes
[mode_count
].dir
= MODE_ADD
;
620 mode_changes
[mode_count
].caps
= 0;
621 mode_changes
[mode_count
].nocaps
= 0;
622 mode_changes
[mode_count
].id
= NULL
;
623 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
624 mode_changes
[mode_count
++].arg
= NULL
;
626 else if((dir
== MODE_DEL
) && (chptr
->mode
.mode
& mode_type
))
628 chptr
->mode
.mode
&= ~mode_type
;
630 mode_changes
[mode_count
].letter
= c
;
631 mode_changes
[mode_count
].dir
= MODE_DEL
;
632 mode_changes
[mode_count
].caps
= 0;
633 mode_changes
[mode_count
].nocaps
= 0;
634 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
635 mode_changes
[mode_count
].id
= NULL
;
636 mode_changes
[mode_count
++].arg
= NULL
;
641 chm_ban(struct Client
*source_p
, struct Channel
*chptr
,
642 int alevel
, int parc
, int *parn
,
643 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
646 const char *raw_mask
;
659 list
= &chptr
->banlist
;
660 errorval
= SM_ERR_RPL_B
;
661 rpl_list
= RPL_BANLIST
;
662 rpl_endlist
= RPL_ENDOFBANLIST
;
668 /* if +e is disabled, allow all but +e locally */
669 if(!ConfigChannel
.use_except
&& MyClient(source_p
) &&
670 ((dir
== MODE_ADD
) && (parc
> *parn
)))
673 list
= &chptr
->exceptlist
;
674 errorval
= SM_ERR_RPL_E
;
675 rpl_list
= RPL_EXCEPTLIST
;
676 rpl_endlist
= RPL_ENDOFEXCEPTLIST
;
679 if(ConfigChannel
.use_except
|| (dir
== MODE_DEL
))
686 /* if +I is disabled, allow all but +I locally */
687 if(!ConfigChannel
.use_invex
&& MyClient(source_p
) &&
688 (dir
== MODE_ADD
) && (parc
> *parn
))
691 list
= &chptr
->invexlist
;
692 errorval
= SM_ERR_RPL_I
;
693 rpl_list
= RPL_INVITELIST
;
694 rpl_endlist
= RPL_ENDOFINVITELIST
;
697 if(ConfigChannel
.use_invex
|| (dir
== MODE_DEL
))
704 list
= &chptr
->quietlist
;
705 errorval
= SM_ERR_RPL_Q
;
706 rpl_list
= RPL_BANLIST
;
707 rpl_endlist
= RPL_ENDOFBANLIST
;
713 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "chm_ban() called with unknown type!");
718 if(dir
== 0 || parc
<= *parn
)
720 if((*errors
& errorval
) != 0)
724 /* non-ops cant see +eI lists.. */
725 if(alevel
!= CHFL_CHANOP
&& alevel
!= CHFL_OWNER
&& alevel
!= CHFL_HALFOP
&& mode_type
!= CHFL_BAN
&&
726 mode_type
!= CHFL_QUIET
)
728 if(!(*errors
& SM_ERR_NOOPS
))
729 sendto_one(source_p
, form_str(ERR_CHANOPRIVSNEEDED
),
730 me
.name
, source_p
->name
, chptr
->chname
);
731 *errors
|= SM_ERR_NOOPS
;
735 RB_DLINK_FOREACH(ptr
, list
->head
)
738 sendto_one(source_p
, form_str(rpl_list
),
739 me
.name
, source_p
->name
, chptr
->chname
,
740 banptr
->banstr
, banptr
->who
, banptr
->when
);
742 if (mode_type
== CHFL_QUIET
)
743 sendto_one(source_p
, ":%s %d %s %s :End of Channel Quiet List", me
.name
, rpl_endlist
, source_p
->name
, chptr
->chname
);
745 sendto_one(source_p
, form_str(rpl_endlist
), me
.name
, source_p
->name
, chptr
->chname
);
749 if(alevel
!= CHFL_CHANOP
&& alevel
!= CHFL_OWNER
&& alevel
!= CHFL_HALFOP
)
751 if(!(*errors
& SM_ERR_NOOPS
))
752 sendto_one(source_p
, form_str(ERR_CHANOPRIVSNEEDED
),
753 me
.name
, source_p
->name
, chptr
->chname
);
754 *errors
|= SM_ERR_NOOPS
;
758 if(MyClient(source_p
) && (++mode_limit
> MAXMODEPARAMS
))
761 raw_mask
= parv
[(*parn
)];
764 /* empty ban, or starts with ':' which messes up s2s, ignore it */
765 if(EmptyString(raw_mask
) || *raw_mask
== ':')
768 if(!MyClient(source_p
))
770 if(strchr(raw_mask
, ' '))
776 mask
= pretty_mask(raw_mask
);
778 /* we'd have problems parsing this, hyb6 does it too
779 * also make sure it will always fit on a line with channel
782 if(strlen(mask
) > IRCD_MIN(BANLEN
, MODEBUFLEN
- 5))
785 /* if we're adding a NEW id */
788 if (*mask
== '$' && MyClient(source_p
))
790 if (!valid_extban(mask
, source_p
, chptr
, mode_type
))
791 /* XXX perhaps return an error message here */
795 /* dont allow local clients to overflow the banlist, dont
796 * let remote servers set duplicate bans
798 if(!add_id(source_p
, chptr
, mask
, list
, mode_type
))
801 mode_changes
[mode_count
].letter
= c
;
802 mode_changes
[mode_count
].dir
= MODE_ADD
;
803 mode_changes
[mode_count
].caps
= caps
;
804 mode_changes
[mode_count
].nocaps
= 0;
805 mode_changes
[mode_count
].mems
= mems
;
806 mode_changes
[mode_count
].id
= NULL
;
807 mode_changes
[mode_count
++].arg
= mask
;
809 else if(dir
== MODE_DEL
)
811 if(del_id(chptr
, mask
, list
, mode_type
) == 0)
813 /* mask isn't a valid ban, check raw_mask */
814 if(del_id(chptr
, raw_mask
, list
, mode_type
))
818 mode_changes
[mode_count
].letter
= c
;
819 mode_changes
[mode_count
].dir
= MODE_DEL
;
820 mode_changes
[mode_count
].caps
= caps
;
821 mode_changes
[mode_count
].nocaps
= 0;
822 mode_changes
[mode_count
].mems
= mems
;
823 mode_changes
[mode_count
].id
= NULL
;
824 mode_changes
[mode_count
++].arg
= mask
;
829 chm_owner(struct Client
*source_p
, struct Channel
*chptr
,
830 int alevel
, int parc
, int *parn
,
831 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
833 struct membership
*mstptr
;
834 const char *ownernick
;
835 struct Client
*targ_p
;
837 if(!ConfigChannel
.use_owner
)
839 if(*errors
& SM_ERR_UNKNOWN
)
841 *errors
|= SM_ERR_UNKNOWN
;
842 sendto_one(source_p
, form_str(ERR_UNKNOWNMODE
), me
.name
, source_p
->name
, c
);
846 if(alevel
!= CHFL_OWNER
)
848 if(!(*errors
& SM_ERR_NOOPS
))
849 sendto_one(source_p
, form_str(ERR_CHANOPRIVSNEEDED
),
850 me
.name
, source_p
->name
, chptr
->chname
);
851 *errors
|= SM_ERR_NOOPS
;
855 if((dir
== MODE_QUERY
) || (parc
<= *parn
))
858 ownernick
= parv
[(*parn
)];
862 if(EmptyString(ownernick
))
864 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
, form_str(ERR_NOSUCHNICK
), "*");
868 if((targ_p
= find_chasing(source_p
, ownernick
, NULL
)) == NULL
)
873 mstptr
= find_channel_membership(chptr
, targ_p
);
877 if(!(*errors
& SM_ERR_NOTONCHANNEL
) && MyClient(source_p
))
878 sendto_one_numeric(source_p
, ERR_USERNOTINCHANNEL
,
879 form_str(ERR_USERNOTINCHANNEL
), ownernick
, chptr
->chname
);
880 *errors
|= SM_ERR_NOTONCHANNEL
;
884 if(MyClient(source_p
) && (++mode_limit
> MAXMODEPARAMS
))
889 if(targ_p
== source_p
)
892 mode_changes
[mode_count
].letter
= c
;
893 mode_changes
[mode_count
].dir
= MODE_ADD
;
894 mode_changes
[mode_count
].caps
= 0;
895 mode_changes
[mode_count
].nocaps
= 0;
896 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
897 mode_changes
[mode_count
].id
= targ_p
->id
;
898 mode_changes
[mode_count
].arg
= targ_p
->name
;
899 mode_changes
[mode_count
++].client
= targ_p
;
901 mstptr
->flags
|= CHFL_OWNER
;
905 if(MyClient(source_p
) && IsService(targ_p
))
907 sendto_one(source_p
, form_str(ERR_ISCHANSERVICE
),
908 me
.name
, source_p
->name
, targ_p
->name
, chptr
->chname
);
912 mode_changes
[mode_count
].letter
= c
;
913 mode_changes
[mode_count
].dir
= MODE_DEL
;
914 mode_changes
[mode_count
].caps
= 0;
915 mode_changes
[mode_count
].nocaps
= 0;
916 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
917 mode_changes
[mode_count
].id
= targ_p
->id
;
918 mode_changes
[mode_count
].arg
= targ_p
->name
;
919 mode_changes
[mode_count
++].client
= targ_p
;
921 mstptr
->flags
&= ~CHFL_OWNER
;
926 chm_op(struct Client
*source_p
, struct Channel
*chptr
,
927 int alevel
, int parc
, int *parn
,
928 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
930 struct membership
*mstptr
;
932 struct Client
*targ_p
;
934 if(alevel
!= CHFL_CHANOP
&& alevel
!= CHFL_OWNER
)
936 if(!(*errors
& SM_ERR_NOOPS
))
937 sendto_one(source_p
, form_str(ERR_CHANOPRIVSNEEDED
),
938 me
.name
, source_p
->name
, chptr
->chname
);
939 *errors
|= SM_ERR_NOOPS
;
943 if((dir
== MODE_QUERY
) || (parc
<= *parn
))
946 opnick
= parv
[(*parn
)];
950 if(EmptyString(opnick
))
952 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
, form_str(ERR_NOSUCHNICK
), "*");
956 if((targ_p
= find_chasing(source_p
, opnick
, NULL
)) == NULL
)
961 mstptr
= find_channel_membership(chptr
, targ_p
);
965 if(!(*errors
& SM_ERR_NOTONCHANNEL
) && MyClient(source_p
))
966 sendto_one_numeric(source_p
, ERR_USERNOTINCHANNEL
,
967 form_str(ERR_USERNOTINCHANNEL
), opnick
, chptr
->chname
);
968 *errors
|= SM_ERR_NOTONCHANNEL
;
972 if(MyClient(source_p
) && (++mode_limit
> MAXMODEPARAMS
))
977 if(targ_p
== source_p
)
980 mode_changes
[mode_count
].letter
= c
;
981 mode_changes
[mode_count
].dir
= MODE_ADD
;
982 mode_changes
[mode_count
].caps
= 0;
983 mode_changes
[mode_count
].nocaps
= 0;
984 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
985 mode_changes
[mode_count
].id
= targ_p
->id
;
986 mode_changes
[mode_count
].arg
= targ_p
->name
;
987 mode_changes
[mode_count
++].client
= targ_p
;
989 mstptr
->flags
|= CHFL_CHANOP
;
993 if(MyClient(source_p
) && IsService(targ_p
))
995 sendto_one(source_p
, form_str(ERR_ISCHANSERVICE
),
996 me
.name
, source_p
->name
, targ_p
->name
, chptr
->chname
);
1000 mode_changes
[mode_count
].letter
= c
;
1001 mode_changes
[mode_count
].dir
= MODE_DEL
;
1002 mode_changes
[mode_count
].caps
= 0;
1003 mode_changes
[mode_count
].nocaps
= 0;
1004 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
1005 mode_changes
[mode_count
].id
= targ_p
->id
;
1006 mode_changes
[mode_count
].arg
= targ_p
->name
;
1007 mode_changes
[mode_count
++].client
= targ_p
;
1009 mstptr
->flags
&= ~CHFL_CHANOP
;
1014 chm_halfop(struct Client
*source_p
, struct Channel
*chptr
,
1015 int alevel
, int parc
, int *parn
,
1016 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
1018 struct membership
*mstptr
;
1019 const char *halfopnick
;
1020 struct Client
*targ_p
;
1022 if(!ConfigChannel
.use_halfop
)
1024 if(*errors
& SM_ERR_UNKNOWN
)
1026 *errors
|= SM_ERR_UNKNOWN
;
1027 sendto_one(source_p
, form_str(ERR_UNKNOWNMODE
), me
.name
, source_p
->name
, c
);
1031 if(alevel
!= CHFL_CHANOP
&& alevel
!= CHFL_OWNER
)
1033 if(!(*errors
& SM_ERR_NOOPS
))
1034 sendto_one(source_p
, form_str(ERR_CHANOPRIVSNEEDED
),
1035 me
.name
, source_p
->name
, chptr
->chname
);
1036 *errors
|= SM_ERR_NOOPS
;
1040 if((dir
== MODE_QUERY
) || (parc
<= *parn
))
1043 halfopnick
= parv
[(*parn
)];
1047 if(EmptyString(halfopnick
))
1049 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
, form_str(ERR_NOSUCHNICK
), "*");
1053 if((targ_p
= find_chasing(source_p
, halfopnick
, NULL
)) == NULL
)
1058 mstptr
= find_channel_membership(chptr
, targ_p
);
1062 if(!(*errors
& SM_ERR_NOTONCHANNEL
) && MyClient(source_p
))
1063 sendto_one_numeric(source_p
, ERR_USERNOTINCHANNEL
,
1064 form_str(ERR_USERNOTINCHANNEL
), halfopnick
, chptr
->chname
);
1065 *errors
|= SM_ERR_NOTONCHANNEL
;
1069 if(MyClient(source_p
) && (++mode_limit
> MAXMODEPARAMS
))
1074 if(targ_p
== source_p
)
1077 mode_changes
[mode_count
].letter
= c
;
1078 mode_changes
[mode_count
].dir
= MODE_ADD
;
1079 mode_changes
[mode_count
].caps
= 0;
1080 mode_changes
[mode_count
].nocaps
= 0;
1081 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
1082 mode_changes
[mode_count
].id
= targ_p
->id
;
1083 mode_changes
[mode_count
].arg
= targ_p
->name
;
1084 mode_changes
[mode_count
++].client
= targ_p
;
1086 mstptr
->flags
|= CHFL_HALFOP
;
1090 if(MyClient(source_p
) && IsService(targ_p
))
1092 sendto_one(source_p
, form_str(ERR_ISCHANSERVICE
),
1093 me
.name
, source_p
->name
, targ_p
->name
, chptr
->chname
);
1097 mode_changes
[mode_count
].letter
= c
;
1098 mode_changes
[mode_count
].dir
= MODE_DEL
;
1099 mode_changes
[mode_count
].caps
= 0;
1100 mode_changes
[mode_count
].nocaps
= 0;
1101 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
1102 mode_changes
[mode_count
].id
= targ_p
->id
;
1103 mode_changes
[mode_count
].arg
= targ_p
->name
;
1104 mode_changes
[mode_count
++].client
= targ_p
;
1106 mstptr
->flags
&= ~CHFL_HALFOP
;
1111 chm_voice(struct Client
*source_p
, struct Channel
*chptr
,
1112 int alevel
, int parc
, int *parn
,
1113 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
1115 struct membership
*mstptr
;
1117 struct Client
*targ_p
;
1119 if(alevel
!= CHFL_CHANOP
&& alevel
!= CHFL_OWNER
&& alevel
!= CHFL_HALFOP
)
1121 if(!(*errors
& SM_ERR_NOOPS
))
1122 sendto_one(source_p
, form_str(ERR_CHANOPRIVSNEEDED
),
1123 me
.name
, source_p
->name
, chptr
->chname
);
1124 *errors
|= SM_ERR_NOOPS
;
1128 if((dir
== MODE_QUERY
) || parc
<= *parn
)
1131 opnick
= parv
[(*parn
)];
1135 if(EmptyString(opnick
))
1137 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
, form_str(ERR_NOSUCHNICK
), "*");
1141 if((targ_p
= find_chasing(source_p
, opnick
, NULL
)) == NULL
)
1146 mstptr
= find_channel_membership(chptr
, targ_p
);
1150 if(!(*errors
& SM_ERR_NOTONCHANNEL
) && MyClient(source_p
))
1151 sendto_one_numeric(source_p
, ERR_USERNOTINCHANNEL
,
1152 form_str(ERR_USERNOTINCHANNEL
), opnick
, chptr
->chname
);
1153 *errors
|= SM_ERR_NOTONCHANNEL
;
1157 if(MyClient(source_p
) && (++mode_limit
> MAXMODEPARAMS
))
1162 mode_changes
[mode_count
].letter
= c
;
1163 mode_changes
[mode_count
].dir
= MODE_ADD
;
1164 mode_changes
[mode_count
].caps
= 0;
1165 mode_changes
[mode_count
].nocaps
= 0;
1166 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
1167 mode_changes
[mode_count
].id
= targ_p
->id
;
1168 mode_changes
[mode_count
].arg
= targ_p
->name
;
1169 mode_changes
[mode_count
++].client
= targ_p
;
1171 mstptr
->flags
|= CHFL_VOICE
;
1175 mode_changes
[mode_count
].letter
= 'v';
1176 mode_changes
[mode_count
].dir
= MODE_DEL
;
1177 mode_changes
[mode_count
].caps
= 0;
1178 mode_changes
[mode_count
].nocaps
= 0;
1179 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
1180 mode_changes
[mode_count
].id
= targ_p
->id
;
1181 mode_changes
[mode_count
].arg
= targ_p
->name
;
1182 mode_changes
[mode_count
++].client
= targ_p
;
1184 mstptr
->flags
&= ~CHFL_VOICE
;
1189 chm_limit(struct Client
*source_p
, struct Channel
*chptr
,
1190 int alevel
, int parc
, int *parn
,
1191 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
1194 static char limitstr
[30];
1197 if(alevel
!= CHFL_CHANOP
&& alevel
!= CHFL_OWNER
&& alevel
!= CHFL_HALFOP
)
1199 if(!(*errors
& SM_ERR_NOOPS
))
1200 sendto_one(source_p
, form_str(ERR_CHANOPRIVSNEEDED
),
1201 me
.name
, source_p
->name
, chptr
->chname
);
1202 *errors
|= SM_ERR_NOOPS
;
1206 if(dir
== MODE_QUERY
)
1209 if(MyClient(source_p
) && (++mode_limit_simple
> MAXMODES_SIMPLE
))
1212 if((dir
== MODE_ADD
) && parc
> *parn
)
1214 lstr
= parv
[(*parn
)];
1217 if(EmptyString(lstr
) || (limit
= atoi(lstr
)) <= 0)
1220 rb_sprintf(limitstr
, "%d", limit
);
1222 mode_changes
[mode_count
].letter
= c
;
1223 mode_changes
[mode_count
].dir
= MODE_ADD
;
1224 mode_changes
[mode_count
].caps
= 0;
1225 mode_changes
[mode_count
].nocaps
= 0;
1226 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
1227 mode_changes
[mode_count
].id
= NULL
;
1228 mode_changes
[mode_count
++].arg
= limitstr
;
1230 chptr
->mode
.limit
= limit
;
1232 else if(dir
== MODE_DEL
)
1234 if(!chptr
->mode
.limit
)
1237 chptr
->mode
.limit
= 0;
1239 mode_changes
[mode_count
].letter
= c
;
1240 mode_changes
[mode_count
].dir
= MODE_DEL
;
1241 mode_changes
[mode_count
].caps
= 0;
1242 mode_changes
[mode_count
].nocaps
= 0;
1243 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
1244 mode_changes
[mode_count
].id
= NULL
;
1245 mode_changes
[mode_count
++].arg
= NULL
;
1250 chm_throttle(struct Client
*source_p
, struct Channel
*chptr
,
1251 int alevel
, int parc
, int *parn
,
1252 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
1254 int joins
= 0, timeslice
= 0;
1256 if(alevel
!= CHFL_CHANOP
&& alevel
!= CHFL_OWNER
&& alevel
!= CHFL_HALFOP
)
1258 if(!(*errors
& SM_ERR_NOOPS
))
1259 sendto_one(source_p
, form_str(ERR_CHANOPRIVSNEEDED
),
1260 me
.name
, source_p
->name
, chptr
->chname
);
1261 *errors
|= SM_ERR_NOOPS
;
1265 if(dir
== MODE_QUERY
)
1268 if(MyClient(source_p
) && (++mode_limit_simple
> MAXMODES_SIMPLE
))
1271 if((dir
== MODE_ADD
) && parc
> *parn
)
1273 sscanf(parv
[(*parn
)], "%d:%d", &joins
, ×lice
);
1275 if(!joins
|| !timeslice
)
1278 mode_changes
[mode_count
].letter
= c
;
1279 mode_changes
[mode_count
].dir
= MODE_ADD
;
1280 mode_changes
[mode_count
].caps
= 0;
1281 mode_changes
[mode_count
].nocaps
= 0;
1282 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
1283 mode_changes
[mode_count
].id
= NULL
;
1284 mode_changes
[mode_count
++].arg
= parv
[(*parn
)];
1288 chptr
->mode
.join_num
= joins
;
1289 chptr
->mode
.join_time
= timeslice
;
1291 else if(dir
== MODE_DEL
)
1293 if(!chptr
->mode
.join_num
)
1296 chptr
->mode
.join_num
= 0;
1297 chptr
->mode
.join_time
= 0;
1298 chptr
->join_count
= 0;
1299 chptr
->join_delta
= 0;
1301 mode_changes
[mode_count
].letter
= c
;
1302 mode_changes
[mode_count
].dir
= MODE_DEL
;
1303 mode_changes
[mode_count
].caps
= 0;
1304 mode_changes
[mode_count
].nocaps
= 0;
1305 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
1306 mode_changes
[mode_count
].id
= NULL
;
1307 mode_changes
[mode_count
++].arg
= NULL
;
1312 chm_forward(struct Client
*source_p
, struct Channel
*chptr
,
1313 int alevel
, int parc
, int *parn
,
1314 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
1316 struct Channel
*targptr
= NULL
;
1317 struct membership
*msptr
;
1318 const char *forward
;
1320 /* if +f is disabled, ignore local attempts to set it */
1321 if(!ConfigChannel
.use_forward
&& MyClient(source_p
) &&
1322 (dir
== MODE_ADD
) && (parc
> *parn
))
1325 if(dir
== MODE_QUERY
|| (dir
== MODE_ADD
&& parc
<= *parn
))
1327 if (!(*errors
& SM_ERR_RPL_F
))
1329 if (*chptr
->mode
.forward
== '\0')
1330 sendto_one_notice(source_p
, ":%s has no forward channel", chptr
->chname
);
1332 sendto_one_notice(source_p
, ":%s forward channel is %s", chptr
->chname
, chptr
->mode
.forward
);
1333 *errors
|= SM_ERR_RPL_F
;
1338 #ifndef FORWARD_OPERONLY
1339 if(alevel
!= CHFL_CHANOP
&& alevel
!= CHFL_OWNER
&& alevel
!= CHFL_HALFOP
)
1341 if(!(*errors
& SM_ERR_NOOPS
))
1342 sendto_one(source_p
, form_str(ERR_CHANOPRIVSNEEDED
),
1343 me
.name
, source_p
->name
, chptr
->chname
);
1344 *errors
|= SM_ERR_NOOPS
;
1348 if(!IsOper(source_p
) && !IsServer(source_p
))
1350 if(!(*errors
& SM_ERR_NOPRIVS
))
1351 sendto_one_numeric(source_p
, ERR_NOPRIVILEGES
, form_str(ERR_NOPRIVILEGES
));
1352 *errors
|= SM_ERR_NOPRIVS
;
1357 if(MyClient(source_p
) && (++mode_limit_simple
> MAXMODES_SIMPLE
))
1360 if(dir
== MODE_ADD
&& parc
> *parn
)
1362 forward
= parv
[(*parn
)];
1365 if(EmptyString(forward
))
1367 if(!check_channel_name(forward
) ||
1368 (MyClient(source_p
) && (strlen(forward
) > LOC_CHANNELLEN
|| hash_find_resv(forward
))))
1370 sendto_one_numeric(source_p
, ERR_BADCHANNAME
, form_str(ERR_BADCHANNAME
), forward
);
1373 /* don't forward to inconsistent target -- jilles */
1374 if(chptr
->chname
[0] == '#' && forward
[0] == '&')
1376 sendto_one_numeric(source_p
, ERR_BADCHANNAME
,
1377 form_str(ERR_BADCHANNAME
), forward
);
1380 if(MyClient(source_p
) && (targptr
= find_channel(forward
)) == NULL
)
1382 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
1383 form_str(ERR_NOSUCHCHANNEL
), forward
);
1386 if(MyClient(source_p
) && !(targptr
->mode
.mode
& MODE_FREETARGET
))
1388 if((msptr
= find_channel_membership(targptr
, source_p
)) == NULL
||
1391 sendto_one(source_p
, form_str(ERR_CHANOPRIVSNEEDED
),
1392 me
.name
, source_p
->name
, targptr
->chname
);
1397 rb_strlcpy(chptr
->mode
.forward
, forward
, sizeof(chptr
->mode
.forward
));
1399 mode_changes
[mode_count
].letter
= c
;
1400 mode_changes
[mode_count
].dir
= MODE_ADD
;
1401 mode_changes
[mode_count
].caps
= 0;
1402 mode_changes
[mode_count
].nocaps
= 0;
1403 mode_changes
[mode_count
].mems
= ConfigChannel
.use_forward
? ALL_MEMBERS
: ONLY_SERVERS
;
1404 mode_changes
[mode_count
].id
= NULL
;
1405 mode_changes
[mode_count
++].arg
= forward
;
1407 else if(dir
== MODE_DEL
)
1409 if(!(*chptr
->mode
.forward
))
1412 *chptr
->mode
.forward
= '\0';
1414 mode_changes
[mode_count
].letter
= c
;
1415 mode_changes
[mode_count
].dir
= MODE_DEL
;
1416 mode_changes
[mode_count
].caps
= 0;
1417 mode_changes
[mode_count
].nocaps
= 0;
1418 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
1419 mode_changes
[mode_count
].id
= NULL
;
1420 mode_changes
[mode_count
++].arg
= NULL
;
1425 chm_key(struct Client
*source_p
, struct Channel
*chptr
,
1426 int alevel
, int parc
, int *parn
,
1427 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
1431 if(alevel
!= CHFL_CHANOP
&& alevel
!= CHFL_OWNER
&& alevel
!= CHFL_HALFOP
)
1433 if(!(*errors
& SM_ERR_NOOPS
))
1434 sendto_one(source_p
, form_str(ERR_CHANOPRIVSNEEDED
),
1435 me
.name
, source_p
->name
, chptr
->chname
);
1436 *errors
|= SM_ERR_NOOPS
;
1440 if(dir
== MODE_QUERY
)
1443 if(MyClient(source_p
) && (++mode_limit_simple
> MAXMODES_SIMPLE
))
1446 if((dir
== MODE_ADD
) && parc
> *parn
)
1448 key
= LOCAL_COPY(parv
[(*parn
)]);
1451 if(MyClient(source_p
))
1454 fix_key_remote(key
);
1456 if(EmptyString(key
))
1459 s_assert(key
[0] != ' ');
1460 rb_strlcpy(chptr
->mode
.key
, key
, sizeof(chptr
->mode
.key
));
1462 mode_changes
[mode_count
].letter
= c
;
1463 mode_changes
[mode_count
].dir
= MODE_ADD
;
1464 mode_changes
[mode_count
].caps
= 0;
1465 mode_changes
[mode_count
].nocaps
= 0;
1466 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
1467 mode_changes
[mode_count
].id
= NULL
;
1468 mode_changes
[mode_count
++].arg
= chptr
->mode
.key
;
1470 else if(dir
== MODE_DEL
)
1472 static char splat
[] = "*";
1478 if(!(*chptr
->mode
.key
))
1481 /* hack time. when we get a +k-k mode, the +k arg is
1482 * chptr->mode.key, which the -k sets to \0, so hunt for a
1483 * +k when we get a -k, and set the arg to splat. --anfl
1485 for(i
= 0; i
< mode_count
; i
++)
1487 if(mode_changes
[i
].letter
== 'k' && mode_changes
[i
].dir
== MODE_ADD
)
1488 mode_changes
[i
].arg
= splat
;
1491 *chptr
->mode
.key
= 0;
1493 mode_changes
[mode_count
].letter
= c
;
1494 mode_changes
[mode_count
].dir
= MODE_DEL
;
1495 mode_changes
[mode_count
].caps
= 0;
1496 mode_changes
[mode_count
].nocaps
= 0;
1497 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
1498 mode_changes
[mode_count
].id
= NULL
;
1499 mode_changes
[mode_count
++].arg
= "*";
1504 chm_regonly(struct Client
*source_p
, struct Channel
*chptr
,
1505 int alevel
, int parc
, int *parn
,
1506 const char **parv
, int *errors
, int dir
, char c
, long mode_type
)
1508 if(alevel
!= CHFL_CHANOP
&& alevel
!= CHFL_OWNER
&& alevel
!= CHFL_HALFOP
)
1510 if(!(*errors
& SM_ERR_NOOPS
))
1511 sendto_one(source_p
, form_str(ERR_CHANOPRIVSNEEDED
),
1512 me
.name
, source_p
->name
, chptr
->chname
);
1513 *errors
|= SM_ERR_NOOPS
;
1517 if(dir
== MODE_QUERY
)
1520 if(((dir
== MODE_ADD
) && (chptr
->mode
.mode
& mode_type
)) ||
1521 ((dir
== MODE_DEL
) && !(chptr
->mode
.mode
& mode_type
)))
1524 if(MyClient(source_p
) && (++mode_limit_simple
> MAXMODES_SIMPLE
))
1528 chptr
->mode
.mode
|= mode_type
;
1530 chptr
->mode
.mode
&= ~mode_type
;
1532 mode_changes
[mode_count
].letter
= c
;
1533 mode_changes
[mode_count
].dir
= dir
;
1534 mode_changes
[mode_count
].caps
= CAP_SERVICE
;
1535 mode_changes
[mode_count
].nocaps
= 0;
1536 mode_changes
[mode_count
].mems
= ALL_MEMBERS
;
1537 mode_changes
[mode_count
].id
= NULL
;
1538 mode_changes
[mode_count
++].arg
= NULL
;
1542 struct ChannelMode chmode_table
[256] =
1544 {chm_nosuch
, 0 }, /* 0x00 */
1545 {chm_nosuch
, 0 }, /* 0x01 */
1546 {chm_nosuch
, 0 }, /* 0x02 */
1547 {chm_nosuch
, 0 }, /* 0x03 */
1548 {chm_nosuch
, 0 }, /* 0x04 */
1549 {chm_nosuch
, 0 }, /* 0x05 */
1550 {chm_nosuch
, 0 }, /* 0x06 */
1551 {chm_nosuch
, 0 }, /* 0x07 */
1552 {chm_nosuch
, 0 }, /* 0x08 */
1553 {chm_nosuch
, 0 }, /* 0x09 */
1554 {chm_nosuch
, 0 }, /* 0x0a */
1555 {chm_nosuch
, 0 }, /* 0x0b */
1556 {chm_nosuch
, 0 }, /* 0x0c */
1557 {chm_nosuch
, 0 }, /* 0x0d */
1558 {chm_nosuch
, 0 }, /* 0x0e */
1559 {chm_nosuch
, 0 }, /* 0x0f */
1560 {chm_nosuch
, 0 }, /* 0x10 */
1561 {chm_nosuch
, 0 }, /* 0x11 */
1562 {chm_nosuch
, 0 }, /* 0x12 */
1563 {chm_nosuch
, 0 }, /* 0x13 */
1564 {chm_nosuch
, 0 }, /* 0x14 */
1565 {chm_nosuch
, 0 }, /* 0x15 */
1566 {chm_nosuch
, 0 }, /* 0x16 */
1567 {chm_nosuch
, 0 }, /* 0x17 */
1568 {chm_nosuch
, 0 }, /* 0x18 */
1569 {chm_nosuch
, 0 }, /* 0x19 */
1570 {chm_nosuch
, 0 }, /* 0x1a */
1571 {chm_nosuch
, 0 }, /* 0x1b */
1572 {chm_nosuch
, 0 }, /* 0x1c */
1573 {chm_nosuch
, 0 }, /* 0x1d */
1574 {chm_nosuch
, 0 }, /* 0x1e */
1575 {chm_nosuch
, 0 }, /* 0x1f */
1576 {chm_nosuch
, 0 }, /* 0x20 */
1577 {chm_nosuch
, 0 }, /* 0x21 */
1578 {chm_nosuch
, 0 }, /* 0x22 */
1579 {chm_nosuch
, 0 }, /* 0x23 */
1580 {chm_nosuch
, 0 }, /* 0x24 */
1581 {chm_nosuch
, 0 }, /* 0x25 */
1582 {chm_nosuch
, 0 }, /* 0x26 */
1583 {chm_nosuch
, 0 }, /* 0x27 */
1584 {chm_nosuch
, 0 }, /* 0x28 */
1585 {chm_nosuch
, 0 }, /* 0x29 */
1586 {chm_nosuch
, 0 }, /* 0x2a */
1587 {chm_nosuch
, 0 }, /* 0x2b */
1588 {chm_nosuch
, 0 }, /* 0x2c */
1589 {chm_nosuch
, 0 }, /* 0x2d */
1590 {chm_nosuch
, 0 }, /* 0x2e */
1591 {chm_nosuch
, 0 }, /* 0x2f */
1592 {chm_nosuch
, 0 }, /* 0x30 */
1593 {chm_nosuch
, 0 }, /* 0x31 */
1594 {chm_nosuch
, 0 }, /* 0x32 */
1595 {chm_nosuch
, 0 }, /* 0x33 */
1596 {chm_nosuch
, 0 }, /* 0x34 */
1597 {chm_nosuch
, 0 }, /* 0x35 */
1598 {chm_nosuch
, 0 }, /* 0x36 */
1599 {chm_nosuch
, 0 }, /* 0x37 */
1600 {chm_nosuch
, 0 }, /* 0x38 */
1601 {chm_nosuch
, 0 }, /* 0x39 */
1602 {chm_nosuch
, 0 }, /* 0x3a */
1603 {chm_nosuch
, 0 }, /* 0x3b */
1604 {chm_nosuch
, 0 }, /* 0x3c */
1605 {chm_nosuch
, 0 }, /* 0x3d */
1606 {chm_nosuch
, 0 }, /* 0x3e */
1607 {chm_nosuch
, 0 }, /* 0x3f */
1609 {chm_nosuch
, 0 }, /* @ */
1610 {chm_nosuch
, 0 }, /* A */
1611 {chm_nosuch
, 0 }, /* B */
1612 {chm_simple
, MODE_NOCTCP
}, /* C */
1613 {chm_simple
, MODE_NOACTION
}, /* D */
1614 {chm_simple
, MODE_NOKICK
}, /* E */
1615 {chm_simple
, MODE_FREETARGET
}, /* F */
1616 {chm_simple
, MODE_NOCAPS
}, /* G */
1617 {chm_nosuch
, 0 }, /* H */
1618 {chm_ban
, CHFL_INVEX
}, /* I */
1619 {chm_simple
, MODE_NOREJOIN
}, /* J */
1620 {chm_simple
, MODE_NOREPEAT
}, /* K */
1621 {chm_staff
, MODE_EXLIMIT
}, /* L */
1622 {chm_nosuch
, 0 }, /* M */
1623 {chm_simple
, MODE_NONICK
}, /* N */
1624 {chm_nosuch
, 0 }, /* O */
1625 {chm_staff
, MODE_PERMANENT
}, /* P */
1626 {chm_simple
, MODE_DISFORWARD
}, /* Q */
1627 {chm_nosuch
, 0 }, /* R */
1628 {chm_nosuch
, 0 }, /* S */
1629 {chm_simple
, MODE_NONOTICE
}, /* T */
1630 {chm_nosuch
, 0 }, /* U */
1631 {chm_nosuch
, 0 }, /* V */
1632 {chm_nosuch
, 0 }, /* W */
1633 {chm_nosuch
, 0 }, /* X */
1634 {chm_nosuch
, 0 }, /* Y */
1635 {chm_nosuch
, 0 }, /* Z */
1642 {chm_owner
, 0 }, /* a */
1643 {chm_ban
, CHFL_BAN
}, /* b */
1644 {chm_simple
, MODE_NOCOLOR
}, /* c */
1645 {chm_nosuch
, 0 }, /* d */
1646 {chm_ban
, CHFL_EXCEPTION
}, /* e */
1647 {chm_forward
, 0 }, /* f */
1648 {chm_simple
, MODE_FREEINVITE
}, /* g */
1649 {chm_halfop
, 0 }, /* h */
1650 {chm_simple
, MODE_INVITEONLY
}, /* i */
1651 {chm_throttle
, 0 }, /* j */
1652 {chm_key
, 0 }, /* k */
1653 {chm_limit
, 0 }, /* l */
1654 {chm_simple
, MODE_MODERATED
}, /* m */
1655 {chm_simple
, MODE_NOPRIVMSGS
}, /* n */
1656 {chm_op
, 0 }, /* o */
1657 {chm_simple
, MODE_PRIVATE
}, /* p */
1658 {chm_ban
, CHFL_QUIET
}, /* q */
1659 {chm_regonly
, MODE_REGONLY
}, /* r */
1660 {chm_simple
, MODE_SECRET
}, /* s */
1661 {chm_simple
, MODE_TOPICLIMIT
}, /* t */
1662 {chm_nosuch
, 0 }, /* u */
1663 {chm_voice
, 0 }, /* v */
1664 {chm_nosuch
, 0 }, /* w */
1665 {chm_nosuch
, 0 }, /* x */
1666 {chm_nosuch
, 0 }, /* y */
1667 {chm_simple
, MODE_OPMODERATE
}, /* z */
1669 {chm_nosuch
, 0 }, /* 0x7b */
1670 {chm_nosuch
, 0 }, /* 0x7c */
1671 {chm_nosuch
, 0 }, /* 0x7d */
1672 {chm_nosuch
, 0 }, /* 0x7e */
1673 {chm_nosuch
, 0 }, /* 0x7f */
1675 {chm_nosuch
, 0 }, /* 0x80 */
1676 {chm_nosuch
, 0 }, /* 0x81 */
1677 {chm_nosuch
, 0 }, /* 0x82 */
1678 {chm_nosuch
, 0 }, /* 0x83 */
1679 {chm_nosuch
, 0 }, /* 0x84 */
1680 {chm_nosuch
, 0 }, /* 0x85 */
1681 {chm_nosuch
, 0 }, /* 0x86 */
1682 {chm_nosuch
, 0 }, /* 0x87 */
1683 {chm_nosuch
, 0 }, /* 0x88 */
1684 {chm_nosuch
, 0 }, /* 0x89 */
1685 {chm_nosuch
, 0 }, /* 0x8a */
1686 {chm_nosuch
, 0 }, /* 0x8b */
1687 {chm_nosuch
, 0 }, /* 0x8c */
1688 {chm_nosuch
, 0 }, /* 0x8d */
1689 {chm_nosuch
, 0 }, /* 0x8e */
1690 {chm_nosuch
, 0 }, /* 0x8f */
1692 {chm_nosuch
, 0 }, /* 0x90 */
1693 {chm_nosuch
, 0 }, /* 0x91 */
1694 {chm_nosuch
, 0 }, /* 0x92 */
1695 {chm_nosuch
, 0 }, /* 0x93 */
1696 {chm_nosuch
, 0 }, /* 0x94 */
1697 {chm_nosuch
, 0 }, /* 0x95 */
1698 {chm_nosuch
, 0 }, /* 0x96 */
1699 {chm_nosuch
, 0 }, /* 0x97 */
1700 {chm_nosuch
, 0 }, /* 0x98 */
1701 {chm_nosuch
, 0 }, /* 0x99 */
1702 {chm_nosuch
, 0 }, /* 0x9a */
1703 {chm_nosuch
, 0 }, /* 0x9b */
1704 {chm_nosuch
, 0 }, /* 0x9c */
1705 {chm_nosuch
, 0 }, /* 0x9d */
1706 {chm_nosuch
, 0 }, /* 0x9e */
1707 {chm_nosuch
, 0 }, /* 0x9f */
1709 {chm_nosuch
, 0 }, /* 0xa0 */
1710 {chm_nosuch
, 0 }, /* 0xa1 */
1711 {chm_nosuch
, 0 }, /* 0xa2 */
1712 {chm_nosuch
, 0 }, /* 0xa3 */
1713 {chm_nosuch
, 0 }, /* 0xa4 */
1714 {chm_nosuch
, 0 }, /* 0xa5 */
1715 {chm_nosuch
, 0 }, /* 0xa6 */
1716 {chm_nosuch
, 0 }, /* 0xa7 */
1717 {chm_nosuch
, 0 }, /* 0xa8 */
1718 {chm_nosuch
, 0 }, /* 0xa9 */
1719 {chm_nosuch
, 0 }, /* 0xaa */
1720 {chm_nosuch
, 0 }, /* 0xab */
1721 {chm_nosuch
, 0 }, /* 0xac */
1722 {chm_nosuch
, 0 }, /* 0xad */
1723 {chm_nosuch
, 0 }, /* 0xae */
1724 {chm_nosuch
, 0 }, /* 0xaf */
1726 {chm_nosuch
, 0 }, /* 0xb0 */
1727 {chm_nosuch
, 0 }, /* 0xb1 */
1728 {chm_nosuch
, 0 }, /* 0xb2 */
1729 {chm_nosuch
, 0 }, /* 0xb3 */
1730 {chm_nosuch
, 0 }, /* 0xb4 */
1731 {chm_nosuch
, 0 }, /* 0xb5 */
1732 {chm_nosuch
, 0 }, /* 0xb6 */
1733 {chm_nosuch
, 0 }, /* 0xb7 */
1734 {chm_nosuch
, 0 }, /* 0xb8 */
1735 {chm_nosuch
, 0 }, /* 0xb9 */
1736 {chm_nosuch
, 0 }, /* 0xba */
1737 {chm_nosuch
, 0 }, /* 0xbb */
1738 {chm_nosuch
, 0 }, /* 0xbc */
1739 {chm_nosuch
, 0 }, /* 0xbd */
1740 {chm_nosuch
, 0 }, /* 0xbe */
1741 {chm_nosuch
, 0 }, /* 0xbf */
1743 {chm_nosuch
, 0 }, /* 0xc0 */
1744 {chm_nosuch
, 0 }, /* 0xc1 */
1745 {chm_nosuch
, 0 }, /* 0xc2 */
1746 {chm_nosuch
, 0 }, /* 0xc3 */
1747 {chm_nosuch
, 0 }, /* 0xc4 */
1748 {chm_nosuch
, 0 }, /* 0xc5 */
1749 {chm_nosuch
, 0 }, /* 0xc6 */
1750 {chm_nosuch
, 0 }, /* 0xc7 */
1751 {chm_nosuch
, 0 }, /* 0xc8 */
1752 {chm_nosuch
, 0 }, /* 0xc9 */
1753 {chm_nosuch
, 0 }, /* 0xca */
1754 {chm_nosuch
, 0 }, /* 0xcb */
1755 {chm_nosuch
, 0 }, /* 0xcc */
1756 {chm_nosuch
, 0 }, /* 0xcd */
1757 {chm_nosuch
, 0 }, /* 0xce */
1758 {chm_nosuch
, 0 }, /* 0xcf */
1760 {chm_nosuch
, 0 }, /* 0xd0 */
1761 {chm_nosuch
, 0 }, /* 0xd1 */
1762 {chm_nosuch
, 0 }, /* 0xd2 */
1763 {chm_nosuch
, 0 }, /* 0xd3 */
1764 {chm_nosuch
, 0 }, /* 0xd4 */
1765 {chm_nosuch
, 0 }, /* 0xd5 */
1766 {chm_nosuch
, 0 }, /* 0xd6 */
1767 {chm_nosuch
, 0 }, /* 0xd7 */
1768 {chm_nosuch
, 0 }, /* 0xd8 */
1769 {chm_nosuch
, 0 }, /* 0xd9 */
1770 {chm_nosuch
, 0 }, /* 0xda */
1771 {chm_nosuch
, 0 }, /* 0xdb */
1772 {chm_nosuch
, 0 }, /* 0xdc */
1773 {chm_nosuch
, 0 }, /* 0xdd */
1774 {chm_nosuch
, 0 }, /* 0xde */
1775 {chm_nosuch
, 0 }, /* 0xdf */
1777 {chm_nosuch
, 0 }, /* 0xe0 */
1778 {chm_nosuch
, 0 }, /* 0xe1 */
1779 {chm_nosuch
, 0 }, /* 0xe2 */
1780 {chm_nosuch
, 0 }, /* 0xe3 */
1781 {chm_nosuch
, 0 }, /* 0xe4 */
1782 {chm_nosuch
, 0 }, /* 0xe5 */
1783 {chm_nosuch
, 0 }, /* 0xe6 */
1784 {chm_nosuch
, 0 }, /* 0xe7 */
1785 {chm_nosuch
, 0 }, /* 0xe8 */
1786 {chm_nosuch
, 0 }, /* 0xe9 */
1787 {chm_nosuch
, 0 }, /* 0xea */
1788 {chm_nosuch
, 0 }, /* 0xeb */
1789 {chm_nosuch
, 0 }, /* 0xec */
1790 {chm_nosuch
, 0 }, /* 0xed */
1791 {chm_nosuch
, 0 }, /* 0xee */
1792 {chm_nosuch
, 0 }, /* 0xef */
1794 {chm_nosuch
, 0 }, /* 0xf0 */
1795 {chm_nosuch
, 0 }, /* 0xf1 */
1796 {chm_nosuch
, 0 }, /* 0xf2 */
1797 {chm_nosuch
, 0 }, /* 0xf3 */
1798 {chm_nosuch
, 0 }, /* 0xf4 */
1799 {chm_nosuch
, 0 }, /* 0xf5 */
1800 {chm_nosuch
, 0 }, /* 0xf6 */
1801 {chm_nosuch
, 0 }, /* 0xf7 */
1802 {chm_nosuch
, 0 }, /* 0xf8 */
1803 {chm_nosuch
, 0 }, /* 0xf9 */
1804 {chm_nosuch
, 0 }, /* 0xfa */
1805 {chm_nosuch
, 0 }, /* 0xfb */
1806 {chm_nosuch
, 0 }, /* 0xfc */
1807 {chm_nosuch
, 0 }, /* 0xfd */
1808 {chm_nosuch
, 0 }, /* 0xfe */
1809 {chm_nosuch
, 0 }, /* 0xff */
1814 /* set_channel_mode()
1816 * inputs - client, source, channel, membership pointer, params
1818 * side effects - channel modes/memberships are changed, MODE is issued
1820 * Extensively modified to be hotpluggable, 03/09/06 -- nenolod
1823 set_channel_mode(struct Client
*client_p
, struct Client
*source_p
,
1824 struct Channel
*chptr
, struct membership
*msptr
, int parc
, const char *parv
[])
1826 static char cmdbuf
[BUFSIZE
];
1827 static char modebuf
[BUFSIZE
];
1828 static char parabuf
[BUFSIZE
];
1831 int cur_len
, mlen
, paralen
, paracount
, arglen
, len
;
1832 int i
, j
, flags
, override
;
1837 const char *ml
= parv
[0];
1839 struct Client
*fakesource_p
;
1844 mode_limit_simple
= 0;
1846 alevel
= get_channel_access(source_p
, msptr
);
1848 /* Hide connecting server on netburst -- jilles */
1849 if (ConfigServerHide
.flatten_links
&& IsServer(source_p
) && !has_id(source_p
) && !HasSentEob(source_p
))
1852 fakesource_p
= source_p
;
1854 for(; (c
= *ml
) != 0; ml
++)
1868 chmode_table
[(unsigned char) c
].set_func(fakesource_p
, chptr
, alevel
,
1871 chmode_table
[(unsigned char) c
].mode_type
);
1876 /* bail out if we have nothing to do... */
1880 if(IsServer(source_p
))
1881 rb_sprintf(cmdbuf
, ":%s MODE %s ", fakesource_p
->name
, chptr
->chname
);
1883 rb_sprintf(cmdbuf
, ":%s!%s@%s MODE %s ",
1884 source_p
->name
, source_p
->username
,
1885 source_p
->host
, chptr
->chname
);
1887 for (override
= 0; override
< (IsOverride(source_p
) ? 2 : 1); ++override
)
1889 int was_on_chan
= 0;
1895 add_user_to_channel(chptr
, source_p
, 0);
1898 for(j
= 0, flags
= ALL_MEMBERS
; j
< 2; j
++, flags
= ONLY_CHANOPS
)
1901 mbuf
= modebuf
+ mlen
;
1904 paracount
= paralen
= 0;
1907 for(i
= 0; i
< mode_count
; i
++)
1909 if(mode_changes
[i
].letter
== 0 || mode_changes
[i
].mems
!= flags
)
1911 if(mode_changes
[i
].override
!= override
)
1914 if(mode_changes
[i
].arg
!= NULL
)
1916 arglen
= strlen(mode_changes
[i
].arg
);
1918 if(arglen
> MODEBUFLEN
- 5)
1924 /* if we're creeping over MAXMODEPARAMSSERV, or over
1925 * bufsize (4 == +/-,modechar,two spaces) send now.
1927 if(mode_changes
[i
].arg
!= NULL
&&
1928 ((paracount
== MAXMODEPARAMSSERV
) ||
1929 ((cur_len
+ paralen
+ arglen
+ 4) > (BUFSIZE
- 3))))
1935 sendto_channel_local(flags
, chptr
, "%s%s %s",
1936 cmdbuf
, modebuf
, parabuf
);
1938 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
,
1939 "%s is overriding modes on %s: %s %s",
1940 get_oper_name(source_p
), chptr
->chname
,
1946 paracount
= paralen
= 0;
1948 mbuf
= modebuf
+ mlen
;
1954 if(dir
!= mode_changes
[i
].dir
)
1956 *mbuf
++ = (mode_changes
[i
].dir
== MODE_ADD
) ? '+' : '-';
1958 dir
= mode_changes
[i
].dir
;
1961 *mbuf
++ = mode_changes
[i
].letter
;
1964 if(mode_changes
[i
].arg
!= NULL
)
1967 len
= rb_sprintf(pbuf
, "%s ", mode_changes
[i
].arg
);
1973 if(override
&& !was_on_chan
)
1974 remove_user_from_channel(find_channel_membership(chptr
, source_p
));
1976 /* only propagate modes originating locally, or if we're hubbing */
1977 if(MyClient(source_p
) || rb_dlink_list_length(&serv_list
) > 1)
1978 send_cap_mode_changes(client_p
, source_p
, chptr
, mode_changes
, mode_count
);