2020-11-03 02:08:57 +00:00
const osu = require ( "osu-packet" ) ,
2022-01-04 03:39:53 +00:00
maths = require ( "./util/Maths.js" ) ,
2022-08-26 12:52:00 +01:00
Streams = require ( "./Streams.js" ) ,
2022-01-04 03:39:53 +00:00
OsuBattleRoyale = require ( "./MultiplayerExtras/OsuBattleRoyale.js" ) ;
2020-11-03 02:08:57 +00:00
module . exports = function ( User , Message , Stream , IsCalledFromMultiplayer = false ) {
2022-01-04 03:39:53 +00:00
if ( Message [ 0 ] != "!" ) return ;
2022-02-23 05:35:10 +00:00
2022-01-04 03:39:53 +00:00
const command = Message . split ( " " ) [ 0 ] ;
const args = Message . split ( " " ) ;
let responseMessage = "" ;
let commandBanchoPacketWriter = null ;
switch ( command ) {
case "!help" :
// This is terrible
if ( args . length == 1 ) {
responseMessage = "Commands with an * next to them have a sub help section" +
"\n!help - Shows this message" +
"\n!roll - Rolls a random number or a number between 0 and a given number" +
"\n!ranking* - Sets your perfered ranking type" +
"\n!mp* - Shows information about all multiplayer commands" +
"\n!admin* - Shows information about all admin commands" ;
} else {
switch ( args [ 1 ] ) {
case "ranking" :
responseMessage = "Ranking Commands:" +
"\n!ranking pp - Sets your ranking type to pp" +
"\n!ranking score - Sets your ranking type to score" +
"\n!ranking acc - Sets your ranking type to accuracy" ;
break ;
case "mp" :
responseMessage = "Multiplayer Commands:" +
"\n!mp start - Starts a multiplayer match with a delay" +
"\n!mp abort - Aborts the currently running multiplayer match" +
"\n!mp obr - Enables Battle Royale mode" ;
break ;
case "admin" :
responseMessage = "Admin Commands:" +
"\n!lock - Locks/Unlocks a channel and limits conversation to mods and above only" ;
break ;
default :
break ;
}
}
break ;
case "!ranking" :
if ( args . length == 1 ) {
responseMessage = "You need to select a ranking mode! use \"!help ranking\" to see the options." ;
} else {
switch ( args [ 1 ] ) {
case "pp" :
responseMessage = "Set ranking mode to pp" ;
User . rankingMode = 0 ;
2022-04-20 07:25:15 +01:00
User . updateUserInfo ( true ) ;
2022-01-04 03:39:53 +00:00
break ;
case "score" :
responseMessage = "Set ranking mode to score" ;
User . rankingMode = 1 ;
2022-04-20 07:25:15 +01:00
User . updateUserInfo ( true ) ;
2022-01-04 03:39:53 +00:00
break ;
case "acc" :
responseMessage = "Set ranking mode to accuracy" ;
User . rankingMode = 2 ;
2022-04-20 07:25:15 +01:00
User . updateUserInfo ( true ) ;
2022-01-04 03:39:53 +00:00
break ;
}
}
break ;
case "!roll" :
if ( args . length == 1 ) {
responseMessage = User . username + " rolled " + maths . randInt ( 0 , 65535 ) ;
} else {
if ( ` ${ parseInt ( args [ 1 ] ) } ` == "NaN" ) responseMessage = User . username + " rolled " + maths . randInt ( 0 , 65535 ) ;
else responseMessage = User . username + " rolled " + maths . randInt ( 0 , parseInt ( args [ 1 ] ) ) ;
}
break ;
case "!lock" :
if ( ! Stream . includes ( "#" ) ) responseMessage = "Multiplayer channels and private channels cannot be locked!" ;
else {
for ( let i = 0 ; i < global . channels . length ; i ++ ) {
// Find the channel that pertains to this stream
if ( global . channels [ i ] . channelName == Stream ) {
if ( global . channels [ i ] . locked ) {
global . channels [ i ] . locked = false ;
responseMessage = "Channel is now unlocked." ;
} else {
global . channels [ i ] . locked = true ;
responseMessage = "Channel is now locked, chat restricted to mods and above." ;
}
break ;
}
}
}
break ;
case "!mp" :
if ( ! IsCalledFromMultiplayer ) return ;
if ( User . currentMatch . matchStartCountdownActive ) return ;
if ( args . length == 1 ) return ;
switch ( args [ 1 ] ) {
case "start" :
if ( args . length > 3 ) return ;
2022-02-23 05:33:03 +00:00
if ( ! isNaN ( args [ 2 ] ) ) {
2022-01-04 03:39:53 +00:00
User . currentMatch . matchStartCountdownActive = true ;
let countdown = parseInt ( args [ 2 ] ) ;
let intervalRef = setInterval ( ( ) => {
let local _osuPacketWriter = new osu . Bancho . Writer ;
if ( countdown != 0 && countdown > 0 ) countdown -- ;
if ( countdown <= 10 && countdown > 0 ) {
local _osuPacketWriter . SendMessage ( {
2022-02-23 05:35:10 +00:00
sendingClient : global . botUser . username ,
2022-01-04 03:39:53 +00:00
message : "Starting in " + countdown ,
target : "#multiplayer" ,
2022-02-23 05:35:10 +00:00
senderId : global . botUser . id
2022-01-04 03:39:53 +00:00
} ) ;
2022-08-26 12:52:00 +01:00
Streams . sendToStream ( Stream , local _osuPacketWriter . toBuffer , null ) ;
2022-01-04 03:39:53 +00:00
} else if ( countdown == 0 ) {
local _osuPacketWriter . SendMessage ( {
2022-02-23 05:35:10 +00:00
sendingClient : global . botUser . username ,
2022-01-04 03:39:53 +00:00
message : "Good luck, have fun!" ,
target : "#multiplayer" ,
2022-02-23 05:35:10 +00:00
senderId : global . botUser . id
2022-01-04 03:39:53 +00:00
} ) ;
2022-08-26 12:52:00 +01:00
Streams . sendToStream ( Stream , local _osuPacketWriter . toBuffer , null ) ;
2022-01-04 03:39:53 +00:00
User . currentMatch . matchStartCountdownActive = false ;
setTimeout ( ( ) => User . currentMatch . startMatch ( ) , 1000 ) ;
clearInterval ( intervalRef ) ;
}
} , 1000 ) ;
} else {
responseMessage = "Good luck, have fun!" ;
setTimeout ( ( ) => User . currentMatch . startMatch ( ) , 1000 ) ;
}
break ;
case "abort" :
//if (args.length > 2) return;
User . currentMatch . finishMatch ( ) ;
break ;
case "obr" :
if ( User . currentMatch . multiplayerExtras != null ) {
if ( User . currentMatch . multiplayerExtras . name == "osu! Battle Royale" ) {
commandBanchoPacketWriter = new osu . Bancho . Writer ;
commandBanchoPacketWriter . SendMessage ( {
2022-02-23 05:35:10 +00:00
sendingClient : global . botUser . username ,
2022-01-04 03:39:53 +00:00
message : "osu! Battle Royale has been disabled!" ,
target : "#multiplayer" ,
2022-02-23 05:35:10 +00:00
senderId : global . botUser . id
2022-01-04 03:39:53 +00:00
} ) ;
User . currentMatch . multiplayerExtras = null ;
2022-08-26 12:52:00 +01:00
Streams . sendToStream ( Stream , commandBanchoPacketWriter . toBuffer , null ) ;
2022-01-04 03:39:53 +00:00
}
else enableOBR ( User , Stream , commandBanchoPacketWriter ) ;
}
else enableOBR ( User , Stream , commandBanchoPacketWriter ) ;
break ;
default :
break ;
}
break ;
}
const osuPacketWriter = new osu . Bancho . Writer ;
if ( responseMessage != "" ) {
if ( Stream . includes ( "#" ) ) {
osuPacketWriter . SendMessage ( {
2022-02-23 05:35:10 +00:00
sendingClient : global . botUser . username ,
2022-01-04 03:39:53 +00:00
message : responseMessage ,
target : Stream ,
2022-02-23 05:35:10 +00:00
senderId : global . botUser . id
2022-01-04 03:39:53 +00:00
} ) ;
} else {
osuPacketWriter . SendMessage ( {
2022-02-23 05:35:10 +00:00
sendingClient : global . botUser . username ,
2022-01-04 03:39:53 +00:00
message : responseMessage ,
target : "#multiplayer" ,
2022-02-23 05:35:10 +00:00
senderId : global . botUser . id
2022-01-04 03:39:53 +00:00
} ) ;
}
}
2022-08-26 12:52:00 +01:00
Streams . sendToStream ( Stream , osuPacketWriter . toBuffer , null ) ;
2021-01-26 12:24:13 +00:00
}
function enableOBR ( User , Stream , commandBanchoPacketWriter ) {
2022-01-04 03:39:53 +00:00
User . currentMatch . multiplayerExtras = new OsuBattleRoyale ( User . currentMatch ) ;
commandBanchoPacketWriter = new osu . Bancho . Writer ;
commandBanchoPacketWriter . SendMessage ( {
2022-02-23 05:35:10 +00:00
sendingClient : global . botUser . username ,
2022-01-04 03:39:53 +00:00
message : "osu! Battle Royale has been enabled!" ,
target : "#multiplayer" ,
2022-02-23 05:35:10 +00:00
senderId : global . botUser . id
2022-01-04 03:39:53 +00:00
} ) ;
commandBanchoPacketWriter . SendMessage ( {
2022-02-23 05:35:10 +00:00
sendingClient : global . botUser . username ,
2022-01-04 03:39:53 +00:00
message : "New Multiplayer Rules Added:\n - Players that are in a failed state by the end of the map get eliminated\n - The player(s) with the lowest score get eliminated" ,
target : "#multiplayer" ,
2022-02-23 05:35:10 +00:00
senderId : global . botUser . id
2022-01-04 03:39:53 +00:00
} ) ;
2022-08-26 12:52:00 +01:00
Streams . sendToStream ( Stream , commandBanchoPacketWriter . toBuffer , null ) ;
2020-08-27 13:09:35 +01:00
}