]>
Commit | Line | Data |
---|---|---|
212380e3 AC |
1 | /* |
2 | * ircd-ratbox: A slightly useful ircd. | |
3 | * m_knock.c: Requests to be invited to a channel. | |
4 | * | |
5 | * Copyright (C) 1996-2002 Hybrid Development Team | |
6 | * Copyright (C) 2002-2005 ircd-ratbox development team | |
7 | * | |
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. | |
12 | * | |
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. | |
17 | * | |
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 | |
21 | * USA | |
212380e3 AC |
22 | */ |
23 | ||
24 | #include "stdinc.h" | |
212380e3 AC |
25 | #include "channel.h" |
26 | #include "client.h" | |
27 | #include "hash.h" | |
4562c604 | 28 | #include "match.h" |
212380e3 AC |
29 | #include "ircd.h" |
30 | #include "numeric.h" | |
31 | #include "send.h" | |
32 | #include "s_conf.h" | |
33 | #include "msg.h" | |
34 | #include "parse.h" | |
35 | #include "modules.h" | |
36 | #include "s_serv.h" | |
0b904d91 | 37 | #include "supported.h" |
212380e3 | 38 | |
428ca87b | 39 | static int m_knock(struct MsgBuf *, struct Client *, struct Client *, int, const char **); |
212380e3 AC |
40 | |
41 | struct Message knock_msgtab = { | |
7baa37a9 | 42 | "KNOCK", 0, 0, 0, 0, |
212380e3 AC |
43 | {mg_unreg, {m_knock, 2}, {m_knock, 2}, mg_ignore, mg_ignore, {m_knock, 2}} |
44 | }; | |
45 | ||
0b904d91 AC |
46 | static int |
47 | _modinit(void) | |
48 | { | |
49 | add_isupport("KNOCK", isupport_boolean, &ConfigChannel.use_knock); | |
50 | return 0; | |
51 | } | |
52 | ||
53 | static void | |
54 | _moddeinit(void) | |
55 | { | |
56 | delete_isupport("KNOCK"); | |
57 | } | |
58 | ||
212380e3 | 59 | mapi_clist_av1 knock_clist[] = { &knock_msgtab, NULL }; |
0b904d91 | 60 | DECLARE_MODULE_AV1(knock, _modinit, _moddeinit, knock_clist, NULL, NULL, "$Revision: 3570 $"); |
212380e3 AC |
61 | |
62 | /* m_knock | |
212380e3 AC |
63 | * parv[1] = channel |
64 | * | |
65 | * The KNOCK command has the following syntax: | |
66 | * :<sender> KNOCK <channel> | |
67 | * | |
68 | * If a user is not banned from the channel they can use the KNOCK | |
69 | * command to have the server NOTICE the channel operators notifying | |
70 | * they would like to join. Helpful if the channel is invite-only, the | |
71 | * key is forgotten, or the channel is full (INVITE can bypass each one | |
72 | * of these conditions. Concept by Dianora <db@db.net> and written by | |
73 | * <anonymous> | |
74 | */ | |
75 | static int | |
428ca87b | 76 | m_knock(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 AC |
77 | { |
78 | struct Channel *chptr; | |
79 | char *p, *name; | |
80 | ||
81 | if(MyClient(source_p) && ConfigChannel.use_knock == 0) | |
82 | { | |
83 | sendto_one(source_p, form_str(ERR_KNOCKDISABLED), | |
84 | me.name, source_p->name); | |
85 | return 0; | |
86 | } | |
87 | ||
88 | name = LOCAL_COPY(parv[1]); | |
89 | ||
90 | /* dont allow one knock to multiple chans */ | |
91 | if((p = strchr(name, ','))) | |
92 | *p = '\0'; | |
93 | ||
212380e3 AC |
94 | if((chptr = find_channel(name)) == NULL) |
95 | { | |
96 | sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, | |
97 | form_str(ERR_NOSUCHCHANNEL), name); | |
98 | return 0; | |
99 | } | |
100 | ||
101 | if(IsMember(source_p, chptr)) | |
102 | { | |
103 | if(MyClient(source_p)) | |
104 | sendto_one(source_p, form_str(ERR_KNOCKONCHAN), | |
105 | me.name, source_p->name, name); | |
106 | return 0; | |
107 | } | |
108 | ||
55abcbb2 KB |
109 | if(!((chptr->mode.mode & MODE_INVITEONLY) || (*chptr->mode.key) || |
110 | (chptr->mode.limit && | |
5b96d9a6 | 111 | rb_dlink_list_length(&chptr->members) >= (unsigned long)chptr->mode.limit))) |
212380e3 AC |
112 | { |
113 | sendto_one_numeric(source_p, ERR_CHANOPEN, | |
114 | form_str(ERR_CHANOPEN), name); | |
115 | return 0; | |
116 | } | |
117 | ||
118 | /* cant knock to a +p channel */ | |
119 | if(HiddenChannel(chptr)) | |
120 | { | |
121 | sendto_one_numeric(source_p, ERR_CANNOTSENDTOCHAN, | |
122 | form_str(ERR_CANNOTSENDTOCHAN), name); | |
123 | return 0; | |
124 | } | |
125 | ||
55abcbb2 | 126 | |
212380e3 AC |
127 | if(MyClient(source_p)) |
128 | { | |
129 | /* don't allow a knock if the user is banned */ | |
765d839d EM |
130 | if(is_banned(chptr, source_p, NULL, NULL, NULL, NULL) == CHFL_BAN || |
131 | is_quieted(chptr, source_p, NULL, NULL, NULL) == CHFL_BAN) | |
212380e3 AC |
132 | { |
133 | sendto_one_numeric(source_p, ERR_CANNOTSENDTOCHAN, | |
134 | form_str(ERR_CANNOTSENDTOCHAN), name); | |
135 | return 0; | |
136 | } | |
137 | ||
138 | /* local flood protection: | |
139 | * allow one knock per user per knock_delay | |
140 | * allow one knock per channel per knock_delay_channel | |
141 | */ | |
55abcbb2 | 142 | if(!IsOper(source_p) && |
e3354945 | 143 | (source_p->localClient->last_knock + ConfigChannel.knock_delay) > rb_current_time()) |
212380e3 AC |
144 | { |
145 | sendto_one(source_p, form_str(ERR_TOOMANYKNOCK), | |
146 | me.name, source_p->name, name, "user"); | |
147 | return 0; | |
148 | } | |
e3354945 | 149 | else if((chptr->last_knock + ConfigChannel.knock_delay_channel) > rb_current_time()) |
212380e3 AC |
150 | { |
151 | sendto_one(source_p, form_str(ERR_TOOMANYKNOCK), | |
152 | me.name, source_p->name, name, "channel"); | |
153 | return 0; | |
154 | } | |
155 | ||
156 | /* ok, we actually can send the knock, tell client */ | |
e3354945 | 157 | source_p->localClient->last_knock = rb_current_time(); |
212380e3 AC |
158 | |
159 | sendto_one(source_p, form_str(RPL_KNOCKDLVR), | |
160 | me.name, source_p->name, name); | |
161 | } | |
162 | ||
e3354945 | 163 | chptr->last_knock = rb_current_time(); |
212380e3 AC |
164 | |
165 | if(ConfigChannel.use_knock) | |
732a8c53 JT |
166 | sendto_channel_local(chptr->mode.mode & MODE_FREEINVITE ? ALL_MEMBERS : ONLY_CHANOPS, |
167 | chptr, form_str(RPL_KNOCK), | |
212380e3 AC |
168 | me.name, name, name, source_p->name, |
169 | source_p->username, source_p->host); | |
170 | ||
171 | sendto_server(client_p, chptr, CAP_KNOCK|CAP_TS6, NOCAPS, | |
172 | ":%s KNOCK %s", use_id(source_p), name); | |
173 | sendto_server(client_p, chptr, CAP_KNOCK, CAP_TS6, | |
174 | ":%s KNOCK %s", source_p->name, name); | |
175 | return 0; | |
176 | } | |
177 |