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, MAXPARA, MFLG_SLOW, 0, |
48 |
{ m_unregistered, m_knock, m_knock, m_ignore, m_knock, m_ignore } |
49 |
}; |
50 |
|
51 |
void |
52 |
_modinit(void) |
53 |
{ |
54 |
mod_add_cmd(&knock_msgtab); |
55 |
add_capability("KNOCK", CAP_KNOCK, 1); |
56 |
add_isupport("KNOCK", NULL, -1); |
57 |
} |
58 |
|
59 |
void |
60 |
_moddeinit(void) |
61 |
{ |
62 |
mod_del_cmd(&knock_msgtab); |
63 |
delete_capability("KNOCK"); |
64 |
delete_isupport("KNOCK"); |
65 |
} |
66 |
|
67 |
const char *_version = "$Revision$"; |
68 |
|
69 |
/* m_knock |
70 |
* parv[0] = sender prefix |
71 |
* parv[1] = channel |
72 |
* |
73 |
* The KNOCK command has the following syntax: |
74 |
* :<sender> KNOCK <channel> |
75 |
* |
76 |
* If a user is not banned from the channel they can use the KNOCK |
77 |
* command to have the server NOTICE the channel operators notifying |
78 |
* they would like to join. Helpful if the channel is invite-only, the |
79 |
* key is forgotten, or the channel is full (INVITE can bypass each one |
80 |
* of these conditions. Concept by Dianora <db@db.net> and written by |
81 |
* <anonymous> |
82 |
*/ |
83 |
static void |
84 |
m_knock(struct Client *client_p, struct Client *source_p, |
85 |
int parc, char *parv[]) |
86 |
{ |
87 |
struct Channel *chptr = NULL; |
88 |
|
89 |
if (EmptyString(parv[1])) |
90 |
{ |
91 |
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), |
92 |
me.name, source_p->name, "KNOCK"); |
93 |
return; |
94 |
} |
95 |
|
96 |
if (!ConfigChannel.use_knock && MyClient(source_p)) |
97 |
{ |
98 |
sendto_one(source_p, form_str(ERR_KNOCKDISABLED), |
99 |
me.name, source_p->name); |
100 |
return; |
101 |
} |
102 |
|
103 |
if ((chptr = hash_find_channel(parv[1])) == NULL) |
104 |
{ |
105 |
sendto_one(source_p, form_str(ERR_NOSUCHCHANNEL), |
106 |
me.name, source_p->name, parv[1]); |
107 |
return; |
108 |
} |
109 |
|
110 |
/* Normal channel, just be sure they aren't on it */ |
111 |
if (IsMember(source_p, chptr)) |
112 |
{ |
113 |
sendto_one(source_p, form_str(ERR_KNOCKONCHAN), me.name, |
114 |
source_p->name, chptr->chname); |
115 |
return; |
116 |
} |
117 |
|
118 |
if (!((chptr->mode.mode & MODE_INVITEONLY) || (*chptr->mode.key) || |
119 |
(chptr->mode.limit && dlink_list_length(&chptr->members) >= |
120 |
chptr->mode.limit))) |
121 |
{ |
122 |
sendto_one(source_p, form_str(ERR_CHANOPEN), me.name, |
123 |
source_p->name, chptr->chname); |
124 |
return; |
125 |
} |
126 |
|
127 |
if (MyClient(source_p)) |
128 |
{ |
129 |
/* |
130 |
* Don't allow a knock if the user is banned, or the channel is private |
131 |
*/ |
132 |
if (PrivateChannel(chptr) || is_banned(chptr, source_p)) |
133 |
{ |
134 |
sendto_one(source_p, form_str(ERR_CANNOTSENDTOCHAN), |
135 |
me.name, source_p->name, chptr->chname); |
136 |
return; |
137 |
} |
138 |
|
139 |
/* |
140 |
* flood protection: |
141 |
* allow one knock per user per knock_delay |
142 |
* allow one knock per channel per knock_delay_channel |
143 |
* |
144 |
* we only limit local requests.. |
145 |
*/ |
146 |
if ((source_p->localClient->last_knock + ConfigChannel.knock_delay) > |
147 |
CurrentTime) |
148 |
{ |
149 |
sendto_one(source_p, form_str(ERR_TOOMANYKNOCK), me.name, |
150 |
source_p->name, chptr->chname, "user"); |
151 |
return; |
152 |
} |
153 |
|
154 |
if ((chptr->last_knock + ConfigChannel.knock_delay_channel) > CurrentTime) |
155 |
{ |
156 |
sendto_one(source_p, form_str(ERR_TOOMANYKNOCK), me.name, |
157 |
source_p->name, chptr->chname, "channel"); |
158 |
return; |
159 |
} |
160 |
|
161 |
source_p->localClient->last_knock = CurrentTime; |
162 |
|
163 |
sendto_one(source_p, form_str(RPL_KNOCKDLVR), me.name, |
164 |
source_p->name, chptr->chname); |
165 |
} |
166 |
|
167 |
chptr->last_knock = CurrentTime; |
168 |
|
169 |
if (ConfigChannel.use_knock) |
170 |
sendto_channel_local(CHFL_CHANOP, 0, chptr, form_str(RPL_KNOCK), |
171 |
me.name, chptr->chname, chptr->chname, |
172 |
source_p->name, source_p->username, |
173 |
source_p->host); |
174 |
|
175 |
sendto_server(client_p, chptr, CAP_KNOCK|CAP_TS6, NOCAPS, |
176 |
":%s KNOCK %s", ID(source_p), chptr->chname); |
177 |
sendto_server(client_p, chptr, CAP_KNOCK, CAP_TS6, |
178 |
":%s KNOCK %s", source_p->name, chptr->chname); |
179 |
} |