2012-04-19 20:58:29 +02:00
/*
* InspIRCd - - Internet Relay Chat Daemon
2007-07-16 17:30:04 +00:00
*
2012-04-19 20:58:29 +02:00
* Copyright ( C ) 2004 - 2006 , 2008 Craig Edwards < craigedwards @ brainbox . cc >
* Copyright ( C ) 2007 Dennis Friis < peavey @ inspircd . org >
* Copyright ( C ) 2007 Robin Burchell < robin + git @ viroteck . net >
2007-07-16 17:30:04 +00:00
*
2012-04-19 20:58:29 +02:00
* This file is part of InspIRCd . InspIRCd is free software : you can
* redistribute it and / or modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation , version 2.
2007-07-16 17:30:04 +00:00
*
2012-04-19 20:58:29 +02:00
* This program is distributed in the hope that it will be useful , but WITHOUT
* ANY WARRANTY ; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE . See the GNU General Public License for more
* details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < http : //www.gnu.org/licenses/>.
2007-07-16 17:30:04 +00:00
*/
2012-04-19 20:58:29 +02:00
2007-07-16 17:30:04 +00:00
# include "inspircd.h"
/** Handles the /KNOCK command
*/
2007-10-21 21:43:48 +00:00
class CommandKnock : public Command
2007-07-16 17:30:04 +00:00
{
public :
2012-09-13 01:15:44 +02:00
bool sendnotice ;
bool sendnumeric ;
2012-08-25 00:43:50 +02:00
CommandKnock ( Module * Creator ) : Command ( Creator , " KNOCK " , 2 , 2 )
2007-07-16 17:30:04 +00:00
{
syntax = " <channel> <reason> " ;
2010-01-31 19:54:33 +00:00
Penalty = 5 ;
2007-07-16 17:30:04 +00:00
}
2008-06-11 11:35:23 +00:00
2008-05-05 00:21:24 +00:00
CmdResult Handle ( const std : : vector < std : : string > & parameters , User * user )
2007-07-16 17:30:04 +00:00
{
2007-10-15 20:59:05 +00:00
Channel * c = ServerInstance - > FindChan ( parameters [ 0 ] ) ;
2007-07-16 17:30:04 +00:00
if ( ! c )
{
2008-05-19 00:12:47 +00:00
user - > WriteNumeric ( 401 , " %s %s :No such channel " , user - > nick . c_str ( ) , parameters [ 0 ] . c_str ( ) ) ;
2007-07-16 17:30:04 +00:00
return CMD_FAILURE ;
}
2008-01-30 01:07:14 +00:00
if ( c - > HasUser ( user ) )
2007-07-16 17:30:04 +00:00
{
2008-05-19 21:16:42 +00:00
user - > WriteNumeric ( 480 , " %s :Can't KNOCK on %s, you are already on that channel. " , user - > nick . c_str ( ) , c - > name . c_str ( ) ) ;
2007-07-16 17:30:04 +00:00
return CMD_FAILURE ;
}
2008-01-30 01:07:14 +00:00
if ( c - > IsModeSet ( ' K ' ) )
2007-07-16 17:30:04 +00:00
{
2008-05-19 21:16:42 +00:00
user - > WriteNumeric ( 480 , " %s :Can't KNOCK on %s, +K is set. " , user - > nick . c_str ( ) , c - > name . c_str ( ) ) ;
2008-01-30 01:07:14 +00:00
return CMD_FAILURE ;
2007-07-16 17:30:04 +00:00
}
2009-11-15 18:26:25 +00:00
if ( ! c - > IsModeSet ( ' i ' ) )
2007-07-16 17:30:04 +00:00
{
2008-05-19 21:16:42 +00:00
user - > WriteNumeric ( 480 , " %s :Can't KNOCK on %s, channel is not invite only so knocking is pointless! " , user - > nick . c_str ( ) , c - > name . c_str ( ) ) ;
2007-07-16 17:30:04 +00:00
return CMD_FAILURE ;
}
2012-09-13 01:15:44 +02:00
if ( sendnotice )
c - > WriteChannelWithServ ( ServerInstance - > Config - > ServerName , " NOTICE %s :User %s is KNOCKing on %s (%s) " , c - > name . c_str ( ) , user - > nick . c_str ( ) , c - > name . c_str ( ) , parameters [ 1 ] . c_str ( ) ) ;
if ( sendnumeric )
c - > WriteChannelWithServ ( ServerInstance - > Config - > ServerName , " 710 %s %s %s :is KNOCKing: %s " , c - > name . c_str ( ) , c - > name . c_str ( ) , user - > GetFullHost ( ) . c_str ( ) , parameters [ 1 ] . c_str ( ) ) ;
2013-04-28 12:17:53 +01:00
user - > WriteNotice ( " KNOCKing on " + c - > name ) ;
2007-07-16 17:30:04 +00:00
return CMD_SUCCESS ;
}
2009-09-03 15:53:15 +00:00
RouteDescriptor GetRouting ( User * user , const std : : vector < std : : string > & parameters )
{
2010-01-19 15:16:24 +00:00
return ROUTE_OPT_BCAST ;
2009-09-03 15:53:15 +00:00
}
2007-07-16 17:30:04 +00:00
} ;
/** Handles channel mode +K
*/
2008-05-01 16:12:45 +00:00
class Knock : public SimpleChannelModeHandler
2007-07-16 17:30:04 +00:00
{
public :
2009-10-08 23:34:01 +00:00
Knock ( Module * Creator ) : SimpleChannelModeHandler ( Creator , " noknock " , ' K ' ) { }
2007-07-16 17:30:04 +00:00
} ;
class ModuleKnock : public Module
{
2009-09-02 00:43:04 +00:00
CommandKnock cmd ;
Knock kn ;
2007-07-16 17:30:04 +00:00
public :
2009-09-26 14:13:13 +00:00
ModuleKnock ( ) : cmd ( this ) , kn ( this )
2012-10-13 03:12:29 +02:00
{
}
2013-04-30 08:38:33 +01:00
void init ( ) CXX11_OVERRIDE
2007-07-16 17:30:04 +00:00
{
2012-12-02 19:40:17 +01:00
ServerInstance - > Modules - > AddService ( kn ) ;
ServerInstance - > Modules - > AddService ( cmd ) ;
2007-11-04 18:30:43 +00:00
2012-09-13 01:15:44 +02:00
ServerInstance - > Modules - > Attach ( I_OnRehash , this ) ;
OnRehash ( NULL ) ;
2007-07-16 17:30:04 +00:00
}
2013-04-30 08:38:33 +01:00
void OnRehash ( User * user ) CXX11_OVERRIDE
2007-07-16 17:30:04 +00:00
{
2012-09-13 01:15:44 +02:00
std : : string knocknotify = ServerInstance - > Config - > ConfValue ( " knock " ) - > getString ( " notify " ) ;
irc : : string notify ( knocknotify . c_str ( ) ) ;
if ( notify = = " numeric " )
{
cmd . sendnotice = false ;
cmd . sendnumeric = true ;
}
else if ( notify = = " both " )
{
cmd . sendnotice = true ;
cmd . sendnumeric = true ;
}
else
{
cmd . sendnotice = true ;
cmd . sendnumeric = false ;
}
2007-07-16 17:30:04 +00:00
}
2013-04-30 08:38:33 +01:00
Version GetVersion ( ) CXX11_OVERRIDE
2007-07-16 17:30:04 +00:00
{
2012-05-30 03:46:41 +02:00
return Version ( " Provides support for /KNOCK and channel mode +K " , VF_OPTCOMMON | VF_VENDOR ) ;
2007-07-16 17:30:04 +00:00
}
} ;
MODULE_INIT ( ModuleKnock )