2012-04-19 20:58:29 +02:00
/*
* InspIRCd - - Internet Relay Chat Daemon
*
2025-01-04 12:08:33 +00:00
* Copyright ( C ) 2019 - 2024 Sadie Powell < sadie @ witchery . services >
2024-06-07 10:37:56 +01:00
* Copyright ( C ) 2013 - 2014 , 2016 Attila Molnar < attilamolnar @ hush . com >
2020-01-11 22:02:47 +00:00
* Copyright ( C ) 2010 Craig Edwards < brain @ inspircd . org >
2012-04-19 20:58:29 +02:00
* Copyright ( C ) 2009 - 2010 Daniel De Graaf < danieldg @ inspircd . org >
2009-09-03 02:30:45 +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.
2009-09-03 02:30:45 +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 .
2009-09-03 02:30:45 +00:00
*
2012-04-19 20:58:29 +02:00
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < http : //www.gnu.org/licenses/>.
2009-09-03 02:30:45 +00:00
*/
# include "inspircd.h"
# define NETWORK_VALUE 9000000
2021-10-01 05:15:29 +01:00
class CommandOjoin final
: public SplitCommand
2009-09-03 02:30:45 +00:00
{
2022-01-25 13:59:42 +00:00
public :
2009-09-03 02:30:45 +00:00
bool active ;
2013-06-18 19:40:55 +02:00
bool notice ;
bool op ;
ModeHandler * npmh ;
2020-05-26 16:29:13 +01:00
ChanModeReference opmode ;
2014-08-06 13:44:02 +02:00
CommandOjoin ( Module * parent , ModeHandler & mode )
: SplitCommand ( parent , " OJOIN " , 1 )
, npmh ( & mode )
2020-05-26 16:29:13 +01:00
, opmode ( parent , " op " )
2009-09-03 02:30:45 +00:00
{
2020-04-14 21:30:50 +01:00
access_needed = CmdAccess : : OPERATOR ;
2020-04-14 16:41:31 +01:00
syntax = { " <channel> " } ;
2009-09-03 02:30:45 +00:00
active = false ;
}
2019-01-25 02:52:11 +00:00
CmdResult HandleLocal ( LocalUser * user , const Params & parameters ) override
2009-09-03 02:30:45 +00:00
{
// Make sure the channel name is allowable.
2020-06-21 04:25:45 +01:00
if ( ! ServerInstance - > Channels . IsChannel ( parameters [ 0 ] ) )
2009-09-03 02:30:45 +00:00
{
2021-05-08 17:17:29 +01:00
user - > WriteNumeric ( ERR_BADCHANMASK , parameters [ 0 ] , " Invalid channel name " ) ;
2020-10-26 23:40:24 +00:00
return CmdResult : : FAILURE ;
2009-09-03 02:30:45 +00:00
}
active = true ;
2013-04-12 16:00:17 +02:00
// override is false because we want OnUserPreJoin to run
2023-06-22 16:40:05 +01:00
Membership * memb = Channel : : JoinUser ( user , parameters [ 0 ] , false ) ;
2009-09-03 02:30:45 +00:00
active = false ;
2023-06-22 16:40:05 +01:00
if ( memb )
2009-09-03 02:30:45 +00:00
{
2023-06-22 16:40:05 +01:00
ServerInstance - > SNO . WriteGlobalSno ( ' a ' , user - > nick + " used OJOIN to join " + memb - > chan - > name ) ;
2009-09-03 02:30:45 +00:00
if ( notice )
2023-06-22 16:40:05 +01:00
memb - > chan - > WriteRemoteNotice ( user - > nick + " joined on official network business. " ) ;
2009-09-03 02:30:45 +00:00
}
else
{
2023-06-22 16:40:05 +01:00
Channel * channel = ServerInstance - > Channels . Find ( parameters [ 0 ] ) ;
2014-09-03 15:32:02 +02:00
if ( ! channel )
2020-10-26 23:40:24 +00:00
return CmdResult : : FAILURE ;
2014-09-03 15:32:02 +02:00
2019-02-07 12:17:09 +00:00
ServerInstance - > SNO . WriteGlobalSno ( ' a ' , user - > nick + " used OJOIN in " + parameters [ 0 ] ) ;
2009-09-09 19:28:34 +00:00
// they're already in the channel
2014-09-03 15:32:02 +02:00
Modes : : ChangeList changelist ;
changelist . push_add ( npmh , user - > nick ) ;
2020-05-26 16:29:13 +01:00
if ( op & & opmode )
changelist . push_add ( * opmode , user - > nick ) ;
2022-07-22 18:33:38 +01:00
ServerInstance - > Modes . Process ( ServerInstance - > FakeClient , channel , nullptr , changelist ) ;
2009-09-03 02:30:45 +00:00
}
2020-10-26 23:40:24 +00:00
return CmdResult : : SUCCESS ;
2009-09-03 15:53:15 +00:00
}
2009-09-03 02:30:45 +00:00
} ;
2009-09-09 19:28:34 +00:00
/** channel mode +Y
2009-09-03 02:30:45 +00:00
*/
2021-10-01 05:39:12 +01:00
class NetworkPrefix final
: public PrefixMode
2009-09-03 02:30:45 +00:00
{
2022-01-25 13:59:42 +00:00
public :
2013-06-18 19:40:55 +02:00
NetworkPrefix ( Module * parent , char NPrefix )
2014-08-06 13:35:40 +02:00
: PrefixMode ( parent , " official-join " , ' Y ' , NETWORK_VALUE , NPrefix )
2009-09-03 02:30:45 +00:00
{
2022-05-17 13:41:40 +01:00
ranktoset = ranktounset = std : : numeric_limits < ModeHandler : : Rank > : : max ( ) ;
2009-09-03 02:30:45 +00:00
}
2021-03-30 17:52:02 +01:00
ModResult AccessCheck ( User * source , Channel * channel , Modes : : Change & change ) override
2009-09-03 02:30:45 +00:00
{
2023-01-10 23:02:45 +00:00
auto * theuser = ServerInstance - > Users . Find ( change . param ) ;
2010-02-05 15:58:58 +00:00
// remove own privs?
2021-03-30 17:52:02 +01:00
if ( source = = theuser & & ! change . adding )
2010-02-05 15:58:58 +00:00
return MOD_RES_ALLOW ;
2009-09-03 02:30:45 +00:00
2010-02-05 15:58:58 +00:00
return MOD_RES_PASSTHRU ;
2009-09-03 02:30:45 +00:00
}
} ;
2021-10-01 04:37:03 +01:00
class ModuleOjoin final
: public Module
2009-09-03 02:30:45 +00:00
{
2022-01-25 13:59:42 +00:00
private :
2014-08-06 13:44:02 +02:00
NetworkPrefix np ;
2009-09-03 02:30:45 +00:00
CommandOjoin mycommand ;
2022-01-25 13:59:42 +00:00
public :
2009-09-03 02:30:45 +00:00
2009-09-26 14:13:13 +00:00
ModuleOjoin ( )
2020-04-11 14:00:48 +01:00
: Module ( VF_VENDOR , " Adds the /OJOIN command which allows server operators to join a channel and receive the server operator-only Y (official-join) channel prefix mode. " )
2024-12-10 14:04:16 +00:00
, np ( this , ServerInstance - > Config - > ConfValue ( " ojoin " ) - > getCharacter ( " prefix " , ' \0 ' , true ) )
2014-08-06 13:44:02 +02:00
, mycommand ( this , np )
2010-01-17 17:10:45 +00:00
{
}
2021-05-23 01:53:34 +01:00
ModResult OnUserPreJoin ( LocalUser * user , Channel * chan , const std : : string & cname , std : : string & privs , const std : : string & keygiven , bool override ) override
2009-09-03 02:30:45 +00:00
{
if ( mycommand . active )
{
2014-08-06 13:44:02 +02:00
privs + = np . GetModeChar ( ) ;
2020-05-26 16:29:13 +01:00
if ( mycommand . op & & mycommand . opmode )
privs + = mycommand . opmode - > IsPrefixMode ( ) - > GetPrefix ( ) ;
2009-09-03 02:30:45 +00:00
return MOD_RES_ALLOW ;
}
return MOD_RES_PASSTHRU ;
}
2019-01-25 02:52:11 +00:00
void ReadConfig ( ConfigStatus & status ) override
2009-09-03 02:30:45 +00:00
{
2023-01-10 20:57:56 +00:00
const auto & Conf = ServerInstance - > Config - > ConfValue ( " ojoin " ) ;
2013-06-18 19:40:55 +02:00
mycommand . notice = Conf - > getBool ( " notice " , true ) ;
mycommand . op = Conf - > getBool ( " op " , true ) ;
2009-09-03 02:30:45 +00:00
}
2022-09-29 12:01:29 +01:00
ModResult OnUserPreKick ( User * source , Membership * memb , const std : : string & reason ) override
2009-09-03 02:30:45 +00:00
{
// Don't do anything if they're not +Y
2016-08-30 16:19:31 +02:00
if ( ! memb - > HasMode ( & np ) )
2009-09-03 02:30:45 +00:00
return MOD_RES_PASSTHRU ;
// Let them do whatever they want to themselves.
2009-09-13 20:31:23 +00:00
if ( source = = memb - > user )
2009-09-03 02:30:45 +00:00
return MOD_RES_PASSTHRU ;
2016-02-25 16:12:09 +01:00
source - > WriteNumeric ( ERR_RESTRICTED , memb - > chan - > name , " Can't kick " + memb - > user - > nick + " as they're on official network business. " ) ;
2009-09-13 20:31:23 +00:00
return MOD_RES_DENY ;
2009-09-03 02:30:45 +00:00
}
2019-01-25 02:52:11 +00:00
void Prioritize ( ) override
2009-09-03 02:30:45 +00:00
{
2019-02-07 12:16:33 +00:00
ServerInstance - > Modules . SetPriority ( this , I_OnUserPreJoin , PRIORITY_FIRST ) ;
2009-09-03 02:30:45 +00:00
}
} ;
MODULE_INIT ( ModuleOjoin )