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