1 |
/* |
2 |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
* m_knock.c: Requests to be invited to a channel. |
4 |
* |
5 |
* Copyright (C) 2002 by the past and present ircd coders, and others. |
6 |
* |
7 |
* This program is free software; you can redistribute it and/or modify |
8 |
* it under the terms of the GNU General Public License as published by |
9 |
* the Free Software Foundation; either version 2 of the License, or |
10 |
* (at your option) any later version. |
11 |
* |
12 |
* This program is distributed in the hope that it will be useful, |
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
* GNU General Public License for more details. |
16 |
* |
17 |
* You should have received a copy of the GNU General Public License |
18 |
* along with this program; if not, write to the Free Software |
19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
20 |
* USA |
21 |
* |
22 |
* $Id$ |
23 |
*/ |
24 |
|
25 |
#include "stdinc.h" |
26 |
#include "list.h" |
27 |
#include "handlers.h" |
28 |
#include "channel.h" |
29 |
#include "channel_mode.h" |
30 |
#include "client.h" |
31 |
#include "hash.h" |
32 |
#include "irc_string.h" |
33 |
#include "sprintf_irc.h" |
34 |
#include "ircd.h" |
35 |
#include "numeric.h" |
36 |
#include "send.h" |
37 |
#include "s_conf.h" |
38 |
#include "msg.h" |
39 |
#include "parse.h" |
40 |
#include "modules.h" |
41 |
#include "s_serv.h" |
42 |
#include "s_user.h" |
43 |
|
44 |
static void m_knock(struct Client *, struct Client *, int, char *[]); |
45 |
|
46 |
struct Message knock_msgtab = { |
47 |
"KNOCK", 0, 0, 2, 0, MFLG_SLOW, 0, |
48 |
{ m_unregistered, m_knock, m_knock, m_ignore, m_knock, m_ignore } |
49 |
}; |
50 |
|
51 |
#ifndef STATIC_MODULES |
52 |
void |
53 |
_modinit(void) |
54 |
{ |
55 |
mod_add_cmd(&knock_msgtab); |
56 |
add_capability("KNOCK", CAP_KNOCK, 1); |
57 |
add_isupport("KNOCK", NULL, -1); |
58 |
} |
59 |
|
60 |
void |
61 |
_moddeinit(void) |
62 |
{ |
63 |
mod_del_cmd(&knock_msgtab); |
64 |
delete_capability("KNOCK"); |
65 |
delete_isupport("KNOCK"); |
66 |
} |
67 |
|
68 |
const char *_version = "$Revision$"; |
69 |
#endif |
70 |
|
71 |
/* m_knock |
72 |
* parv[0] = sender prefix |
73 |
* parv[1] = channel |
74 |
* |
75 |
* The KNOCK command has the following syntax: |
76 |
* :<sender> KNOCK <channel> |
77 |
* |
78 |
* If a user is not banned from the channel they can use the KNOCK |
79 |
* command to have the server NOTICE the channel operators notifying |
80 |
* they would like to join. Helpful if the channel is invite-only, the |
81 |
* key is forgotten, or the channel is full (INVITE can bypass each one |
82 |
* of these conditions. Concept by Dianora <db@db.net> and written by |
83 |
* <anonymous> |
84 |
*/ |
85 |
static void |
86 |
m_knock(struct Client *client_p, struct Client *source_p, |
87 |
int parc, char *parv[]) |
88 |
{ |
89 |
struct Channel *chptr = NULL; |
90 |
|
91 |
if (EmptyString(parv[1])) |
92 |
{ |
93 |
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), |
94 |
me.name, source_p->name, "KNOCK"); |
95 |
return; |
96 |
} |
97 |
|
98 |
if (!ConfigChannel.use_knock && MyClient(source_p)) |
99 |
{ |
100 |
sendto_one(source_p, form_str(ERR_KNOCKDISABLED), |
101 |
me.name, source_p->name); |
102 |
return; |
103 |
} |
104 |
|
105 |
if ((chptr = hash_find_channel(parv[1])) == NULL) |
106 |
{ |
107 |
sendto_one(source_p, form_str(ERR_NOSUCHCHANNEL), |
108 |
me.name, source_p->name, parv[1]); |
109 |
return; |
110 |
} |
111 |
|
112 |
/* Normal channel, just be sure they aren't on it */ |
113 |
if (IsMember(source_p, chptr)) |
114 |
{ |
115 |
sendto_one(source_p, form_str(ERR_KNOCKONCHAN), me.name, |
116 |
source_p->name, chptr->chname); |
117 |
return; |
118 |
} |
119 |
|
120 |
if (!((chptr->mode.mode & MODE_INVITEONLY) || (*chptr->mode.key) || |
121 |
(chptr->mode.limit && dlink_list_length(&chptr->members) >= |
122 |
chptr->mode.limit))) |
123 |
{ |
124 |
sendto_one(source_p, form_str(ERR_CHANOPEN), me.name, |
125 |
source_p->name, chptr->chname); |
126 |
return; |
127 |
} |
128 |
|
129 |
if (MyClient(source_p)) |
130 |
{ |
131 |
/* |
132 |
* Don't allow a knock if the user is banned, or the channel is private |
133 |
*/ |
134 |
if (PrivateChannel(chptr) || is_banned(chptr, source_p)) |
135 |
{ |
136 |
sendto_one(source_p, form_str(ERR_CANNOTSENDTOCHAN), |
137 |
me.name, source_p->name, chptr->chname); |
138 |
return; |
139 |
} |
140 |
|
141 |
/* |
142 |
* flood protection: |
143 |
* allow one knock per user per knock_delay |
144 |
* allow one knock per channel per knock_delay_channel |
145 |
* |
146 |
* we only limit local requests.. |
147 |
*/ |
148 |
if ((source_p->localClient->last_knock + ConfigChannel.knock_delay) > |
149 |
CurrentTime) |
150 |
{ |
151 |
sendto_one(source_p, form_str(ERR_TOOMANYKNOCK), me.name, |
152 |
source_p->name, chptr->chname, "user"); |
153 |
return; |
154 |
} |
155 |
|
156 |
if ((chptr->last_knock + ConfigChannel.knock_delay_channel) > CurrentTime) |
157 |
{ |
158 |
sendto_one(source_p, form_str(ERR_TOOMANYKNOCK), me.name, |
159 |
source_p->name, chptr->chname, "channel"); |
160 |
return; |
161 |
} |
162 |
|
163 |
source_p->localClient->last_knock = CurrentTime; |
164 |
|
165 |
sendto_one(source_p, form_str(RPL_KNOCKDLVR), me.name, |
166 |
source_p->name, chptr->chname); |
167 |
} |
168 |
|
169 |
chptr->last_knock = CurrentTime; |
170 |
|
171 |
if (ConfigChannel.use_knock) |
172 |
sendto_channel_local(CHFL_CHANOP, 0, chptr, form_str(RPL_KNOCK), |
173 |
me.name, chptr->chname, chptr->chname, |
174 |
source_p->name, source_p->username, |
175 |
source_p->host); |
176 |
|
177 |
sendto_server(client_p, chptr, CAP_KNOCK|CAP_TS6, NOCAPS, |
178 |
":%s KNOCK %s", ID(source_p), chptr->chname); |
179 |
sendto_server(client_p, chptr, CAP_KNOCK, CAP_TS6, |
180 |
":%s KNOCK %s", source_p->name, chptr->chname); |
181 |
} |