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