2 * ircd-ratbox: A slightly useful ircd.
3 * m_knock.c: Requests to be invited to a channel.
5 * Copyright (C) 1996-2002 Hybrid Development Team
6 * Copyright (C) 2002-2005 ircd-ratbox development team
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 * $Id: m_knock.c 3570 2007-09-09 19:19:23Z jilles $
27 #include "sprintf_irc.h"
31 #include "irc_string.h"
41 static int m_knock(struct Client
*, struct Client
*, int, const char **);
43 struct Message knock_msgtab
= {
44 "KNOCK", 0, 0, 0, MFLG_SLOW
,
45 {mg_unreg
, {m_knock
, 2}, {m_knock
, 2}, mg_ignore
, mg_ignore
, {m_knock
, 2}}
48 mapi_clist_av1 knock_clist
[] = { &knock_msgtab
, NULL
};
49 DECLARE_MODULE_AV1(knock
, NULL
, NULL
, knock_clist
, NULL
, NULL
, "$Revision: 3570 $");
52 * parv[0] = sender prefix
55 * The KNOCK command has the following syntax:
56 * :<sender> KNOCK <channel>
58 * If a user is not banned from the channel they can use the KNOCK
59 * command to have the server NOTICE the channel operators notifying
60 * they would like to join. Helpful if the channel is invite-only, the
61 * key is forgotten, or the channel is full (INVITE can bypass each one
62 * of these conditions. Concept by Dianora <db@db.net> and written by
66 m_knock(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
68 struct Channel
*chptr
;
71 if(MyClient(source_p
) && ConfigChannel
.use_knock
== 0)
73 sendto_one(source_p
, form_str(ERR_KNOCKDISABLED
),
74 me
.name
, source_p
->name
);
78 name
= LOCAL_COPY(parv
[1]);
80 /* dont allow one knock to multiple chans */
81 if((p
= strchr(name
, ',')))
84 if(!IsChannelName(name
))
86 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
87 form_str(ERR_NOSUCHCHANNEL
), name
);
91 if((chptr
= find_channel(name
)) == NULL
)
93 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
94 form_str(ERR_NOSUCHCHANNEL
), name
);
98 if(IsMember(source_p
, chptr
))
100 if(MyClient(source_p
))
101 sendto_one(source_p
, form_str(ERR_KNOCKONCHAN
),
102 me
.name
, source_p
->name
, name
);
106 if(!((chptr
->mode
.mode
& MODE_INVITEONLY
) || (*chptr
->mode
.key
) ||
107 (chptr
->mode
.limit
&&
108 rb_dlink_list_length(&chptr
->members
) >= (unsigned long)chptr
->mode
.limit
)))
110 sendto_one_numeric(source_p
, ERR_CHANOPEN
,
111 form_str(ERR_CHANOPEN
), name
);
115 /* cant knock to a +p channel */
116 if(HiddenChannel(chptr
))
118 sendto_one_numeric(source_p
, ERR_CANNOTSENDTOCHAN
,
119 form_str(ERR_CANNOTSENDTOCHAN
), name
);
124 if(MyClient(source_p
))
126 /* don't allow a knock if the user is banned */
127 if(is_banned(chptr
, source_p
, NULL
, NULL
, NULL
) == CHFL_BAN
||
128 is_quieted(chptr
, source_p
, NULL
, NULL
, NULL
) == CHFL_BAN
)
130 sendto_one_numeric(source_p
, ERR_CANNOTSENDTOCHAN
,
131 form_str(ERR_CANNOTSENDTOCHAN
), name
);
135 /* local flood protection:
136 * allow one knock per user per knock_delay
137 * allow one knock per channel per knock_delay_channel
139 if(!IsOper(source_p
) &&
140 (source_p
->localClient
->last_knock
+ ConfigChannel
.knock_delay
) > rb_current_time())
142 sendto_one(source_p
, form_str(ERR_TOOMANYKNOCK
),
143 me
.name
, source_p
->name
, name
, "user");
146 else if((chptr
->last_knock
+ ConfigChannel
.knock_delay_channel
) > rb_current_time())
148 sendto_one(source_p
, form_str(ERR_TOOMANYKNOCK
),
149 me
.name
, source_p
->name
, name
, "channel");
153 /* ok, we actually can send the knock, tell client */
154 source_p
->localClient
->last_knock
= rb_current_time();
156 sendto_one(source_p
, form_str(RPL_KNOCKDLVR
),
157 me
.name
, source_p
->name
, name
);
160 chptr
->last_knock
= rb_current_time();
162 if(ConfigChannel
.use_knock
)
163 sendto_channel_local(chptr
->mode
.mode
& MODE_FREEINVITE
? ALL_MEMBERS
: ONLY_CHANOPS
,
164 chptr
, form_str(RPL_KNOCK
),
165 me
.name
, name
, name
, source_p
->name
,
166 source_p
->username
, source_p
->host
);
168 sendto_server(client_p
, chptr
, CAP_KNOCK
|CAP_TS6
, NOCAPS
,
169 ":%s KNOCK %s", use_id(source_p
), name
);
170 sendto_server(client_p
, chptr
, CAP_KNOCK
, CAP_TS6
,
171 ":%s KNOCK %s", source_p
->name
, name
);