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