2020-11-03 02:08:57 +00:00
const osu = require ( "osu-packet" ) ,
maths = require ( "./util/Maths.js" ) ,
2021-01-26 12:24:13 +00:00
OsuBattleRoyale = require ( "./MultiplayerExtras/OsuBattleRoyale.js" ) ;
2020-11-03 02:08:57 +00:00
module . exports = function ( User , Message , Stream , IsCalledFromMultiplayer = false ) {
if ( Message [ 0 ] != "!" ) return ;
2020-08-27 13:09:35 +01:00
const command = Message . split ( " " ) [ 0 ] ;
2020-11-03 02:08:57 +00:00
const args = Message . split ( " " ) ;
let responseMessage = "" ;
2021-01-26 12:24:13 +00:00
let commandBanchoPacketWriter = null ;
2020-08-27 13:09:35 +01:00
switch ( command ) {
case "!help" :
2020-11-03 02:08:57 +00:00
// This is terrible
if ( args . length == 1 ) {
2021-09-03 23:47:46 +01:00
responseMessage = "Commands with an * next to them have a sub help section" +
2020-11-03 02:08:57 +00:00
"\n!help - Shows this message" +
"\n!roll - Rolls a random number or a number between 0 and a given number" +
2021-09-03 23:47:46 +01:00
"\n!ranking* - Sets your perfered ranking type" +
"\n!mp* - Shows information about all multiplayer commands" +
"\n!admin* - Shows information about all admin commands" ;
2020-11-03 02:08:57 +00:00
} else {
switch ( args [ 1 ] ) {
2021-09-03 23:47:46 +01:00
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 ;
2020-11-03 02:08:57 +00:00
case "mp" :
responseMessage = "Multiplayer Commands:" +
"\n!mp start - Starts a multiplayer match with a delay" +
2021-01-26 12:24:13 +00:00
"\n!mp abort - Aborts the currently running multiplayer match" +
2021-09-03 23:47:46 +01:00
"\n!mp obr - Enables Battle Royale mode" ;
2020-11-03 02:08:57 +00:00
break ;
case "admin" :
responseMessage = "Admin Commands:" +
"\n!lock - Locks/Unlocks a channel and limits conversation to mods and above only" ;
break ;
default :
break ;
}
}
break ;
2020-08-27 13:09:35 +01:00
2021-09-03 23:47:46 +01:00
case "!ranking" :
if ( args . length == 1 ) {
2021-09-24 00:23:24 +01:00
responseMessage = "You need to select a ranking mode! use \"!help ranking\" to see the options." ;
2021-09-03 23:47:46 +01:00
} else {
switch ( args [ 1 ] ) {
case "pp" :
responseMessage = "Set ranking mode to pp" ;
User . rankingMode = 0 ;
User . getNewUserInformationFromDatabase ( ) ;
break ;
case "score" :
responseMessage = "Set ranking mode to score" ;
User . rankingMode = 1 ;
User . getNewUserInformationFromDatabase ( ) ;
break ;
case "acc" :
responseMessage = "Set ranking mode to accuracy" ;
User . rankingMode = 2 ;
User . getNewUserInformationFromDatabase ( ) ;
break ;
}
}
break ;
2020-11-03 02:08:57 +00:00
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 ] ) ) ;
}
2020-08-27 13:09:35 +01:00
break ;
case "!lock" :
2020-11-03 02:08:57 +00:00
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 ;
2021-01-26 12:24:13 +00:00
if ( User . currentMatch . matchStartCountdownActive ) return ;
2020-11-03 02:08:57 +00:00
if ( args . length == 1 ) return ;
switch ( args [ 1 ] ) {
case "start" :
if ( args . length > 3 ) return ;
if ( ` ${ parseInt ( args [ 2 ] ) } ` != "NaN" ) {
2021-01-26 12:24:13 +00:00
User . currentMatch . matchStartCountdownActive = true ;
2020-11-03 02:08:57 +00:00
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 ( {
2021-05-15 00:24:39 +01:00
sendingClient : global . users [ "bot" ] . username ,
2020-11-03 02:08:57 +00:00
message : "Starting in " + countdown ,
target : "#multiplayer" ,
2021-05-15 00:24:39 +01:00
senderId : global . users [ "bot" ] . id
2020-11-03 02:08:57 +00:00
} ) ;
global . StreamsHandler . sendToStream ( Stream , local _osuPacketWriter . toBuffer , null ) ;
} else if ( countdown == 0 ) {
local _osuPacketWriter . SendMessage ( {
2021-05-15 00:24:39 +01:00
sendingClient : global . users [ "bot" ] . username ,
2020-11-03 02:08:57 +00:00
message : "Good luck, have fun!" ,
target : "#multiplayer" ,
2021-05-15 00:24:39 +01:00
senderId : global . users [ "bot" ] . id
2020-11-03 02:08:57 +00:00
} ) ;
global . StreamsHandler . sendToStream ( Stream , local _osuPacketWriter . toBuffer , null ) ;
2021-01-26 12:24:13 +00:00
User . currentMatch . matchStartCountdownActive = false ;
setTimeout ( ( ) => User . currentMatch . startMatch ( ) , 1000 ) ;
2020-11-03 02:08:57 +00:00
clearInterval ( intervalRef ) ;
}
} , 1000 ) ;
} else {
responseMessage = "Good luck, have fun!" ;
2021-01-26 12:24:13 +00:00
setTimeout ( ( ) => User . currentMatch . startMatch ( ) , 1000 ) ;
2020-11-03 02:08:57 +00:00
}
break ;
case "abort" :
2021-01-26 12:24:13 +00:00
//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 ( {
2021-05-15 00:24:39 +01:00
sendingClient : global . users [ "bot" ] . username ,
2021-01-26 12:24:13 +00:00
message : "osu! Battle Royale has been disabled!" ,
target : "#multiplayer" ,
2021-05-15 00:24:39 +01:00
senderId : global . users [ "bot" ] . id
2021-01-26 12:24:13 +00:00
} ) ;
User . currentMatch . multiplayerExtras = null ;
global . StreamsHandler . sendToStream ( Stream , commandBanchoPacketWriter . toBuffer , null ) ;
}
else enableOBR ( User , Stream , commandBanchoPacketWriter ) ;
}
else enableOBR ( User , Stream , commandBanchoPacketWriter ) ;
2020-11-03 02:08:57 +00:00
break ;
default :
break ;
}
break ;
}
const osuPacketWriter = new osu . Bancho . Writer ;
if ( responseMessage != "" ) {
if ( Stream . includes ( "#" ) ) {
osuPacketWriter . SendMessage ( {
2021-05-15 00:24:39 +01:00
sendingClient : global . users [ "bot" ] . username ,
2020-11-03 02:08:57 +00:00
message : responseMessage ,
target : Stream ,
2021-05-15 00:24:39 +01:00
senderId : global . users [ "bot" ] . id
2020-11-03 02:08:57 +00:00
} ) ;
} else {
osuPacketWriter . SendMessage ( {
2021-05-15 00:24:39 +01:00
sendingClient : global . users [ "bot" ] . username ,
2020-11-03 02:08:57 +00:00
message : responseMessage ,
target : "#multiplayer" ,
2021-05-15 00:24:39 +01:00
senderId : global . users [ "bot" ] . id
2020-11-03 02:08:57 +00:00
} ) ;
}
2020-08-27 13:09:35 +01:00
}
2020-11-03 02:08:57 +00:00
global . StreamsHandler . sendToStream ( Stream , osuPacketWriter . toBuffer , null ) ;
2021-01-26 12:24:13 +00:00
}
function enableOBR ( User , Stream , commandBanchoPacketWriter ) {
User . currentMatch . multiplayerExtras = new OsuBattleRoyale ( User . currentMatch ) ;
commandBanchoPacketWriter = new osu . Bancho . Writer ;
commandBanchoPacketWriter . SendMessage ( {
2021-05-15 00:24:39 +01:00
sendingClient : global . users [ "bot" ] . username ,
2021-01-26 12:24:13 +00:00
message : "osu! Battle Royale has been enabled!" ,
target : "#multiplayer" ,
2021-05-15 00:24:39 +01:00
senderId : global . users [ "bot" ] . id
2021-01-26 12:24:13 +00:00
} ) ;
commandBanchoPacketWriter . SendMessage ( {
2021-05-15 00:24:39 +01:00
sendingClient : global . users [ "bot" ] . username ,
2021-01-26 12:24:13 +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" ,
2021-05-15 00:24:39 +01:00
senderId : global . users [ "bot" ] . id
2021-01-26 12:24:13 +00:00
} ) ;
global . StreamsHandler . sendToStream ( Stream , commandBanchoPacketWriter . toBuffer , null ) ;
2020-08-27 13:09:35 +01:00
}