2020-02-19 10:59:02 +00:00
|
|
|
import { createInterface } from 'readline'
|
|
|
|
import { createClient } from 'minecraft-protocol'
|
|
|
|
|
|
|
|
import { attachForge } from './forge'
|
2020-02-23 14:35:05 +00:00
|
|
|
import { attachEvents } from './event'
|
2020-02-19 10:59:02 +00:00
|
|
|
|
2020-02-23 14:35:05 +00:00
|
|
|
let username = process.argv[2] || 'Mr_jtb'
|
2020-09-24 02:33:38 +00:00
|
|
|
let password = process.argv[3] || ''
|
|
|
|
let version = process.argv[4] || '1.12.2'
|
|
|
|
let readAddress = process.argv[5] || '192.168.2.5:25577'
|
|
|
|
let realAddress = readAddress.split(":")
|
|
|
|
let address = realAddress[0]
|
|
|
|
let port = parseInt(realAddress[1] || "25565")
|
|
|
|
let client = commandLineCreateClient()
|
2020-02-19 10:59:02 +00:00
|
|
|
|
2020-09-24 02:33:38 +00:00
|
|
|
function commandLineCreateClient() {
|
|
|
|
return createConnection(address, port, username, password)
|
|
|
|
}
|
|
|
|
|
|
|
|
function createConnection(host: string, port: number, username: string, password: string) {
|
2020-02-23 14:35:05 +00:00
|
|
|
let client = createClient({
|
2020-04-07 05:31:20 +00:00
|
|
|
version,
|
2020-02-23 14:35:05 +00:00
|
|
|
host,
|
|
|
|
port,
|
|
|
|
username,
|
2020-09-24 02:33:38 +00:00
|
|
|
password,
|
|
|
|
clientToken: 'd02c7f39-2376-45da-a5a5-50e24fa8b185',
|
|
|
|
//@ts-ignore
|
|
|
|
authServer: 'https://mcsso.yumc.pw/api/yggdrasil/authserver',
|
|
|
|
sessionServer: 'https://mcsso.yumc.pw/api/yggdrasil/sessionserver'
|
2020-02-23 14:35:05 +00:00
|
|
|
})
|
2020-02-19 10:59:02 +00:00
|
|
|
|
2020-09-24 02:33:38 +00:00
|
|
|
attachCommon(client)
|
2020-02-23 14:35:05 +00:00
|
|
|
attachForge(client)
|
|
|
|
attachEvents(client)
|
2020-09-24 02:33:38 +00:00
|
|
|
return client
|
2020-02-23 14:35:05 +00:00
|
|
|
}
|
2020-02-19 10:59:02 +00:00
|
|
|
|
2020-09-24 02:33:38 +00:00
|
|
|
function attachCommon(client) {
|
|
|
|
client.on('error', (error) => {
|
|
|
|
console.log("Client Error", error)
|
|
|
|
})
|
|
|
|
client.on('end', (resone) => {
|
|
|
|
console.log("Client End Resone:", resone)
|
|
|
|
if (`${resone}` != "SocketClosed") {
|
|
|
|
setTimeout(() => {
|
|
|
|
client = commandLineCreateClient()
|
|
|
|
}, 500)
|
|
|
|
} else {
|
|
|
|
process.exit(0)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2020-02-19 10:59:02 +00:00
|
|
|
|
|
|
|
const rl = createInterface({
|
|
|
|
input: process.stdin,
|
|
|
|
output: process.stdout,
|
2020-03-01 16:32:07 +00:00
|
|
|
completer: (line, func) => {
|
|
|
|
let args = line.split(' ')
|
|
|
|
let comp = args[args.length - 1]
|
|
|
|
client.once('tab_complete', (msg) => {
|
|
|
|
let mcts = msg.matches.filter(s => s)
|
|
|
|
func(null, [mcts, comp])
|
|
|
|
})
|
|
|
|
client.write('tab_complete', {
|
|
|
|
text: line
|
|
|
|
})
|
|
|
|
},
|
2020-02-23 14:35:05 +00:00
|
|
|
terminal: true,
|
|
|
|
prompt: ''
|
2020-02-19 10:59:02 +00:00
|
|
|
})
|
|
|
|
|
2020-03-01 16:32:07 +00:00
|
|
|
rl.on('line', function (line) {
|
2020-02-23 14:35:05 +00:00
|
|
|
switch (line) {
|
|
|
|
case "":
|
2020-09-24 02:33:38 +00:00
|
|
|
break
|
2020-03-02 14:28:27 +00:00
|
|
|
case "eval":
|
2020-09-24 02:33:38 +00:00
|
|
|
break
|
2020-03-01 16:32:07 +00:00
|
|
|
case "write":
|
2020-09-24 02:33:38 +00:00
|
|
|
break
|
2020-02-23 14:35:05 +00:00
|
|
|
case "/respawn":
|
|
|
|
client.write('client_command', { payload: 0 })
|
2020-09-24 02:33:38 +00:00
|
|
|
break
|
2020-02-23 14:35:05 +00:00
|
|
|
case "//reco":
|
|
|
|
client.end("")
|
2020-09-24 02:33:38 +00:00
|
|
|
client = commandLineCreateClient()
|
|
|
|
break
|
2020-02-23 14:35:05 +00:00
|
|
|
case "//quit":
|
|
|
|
console.info('Disconnected')
|
|
|
|
client.end("")
|
2020-09-24 02:33:38 +00:00
|
|
|
break
|
2020-02-23 14:35:05 +00:00
|
|
|
case "//end":
|
|
|
|
console.info('Forcibly ended client')
|
|
|
|
process.exit(0)
|
|
|
|
default:
|
|
|
|
client.write('chat', { message: line })
|
2020-02-19 10:59:02 +00:00
|
|
|
}
|
2020-02-23 14:35:05 +00:00
|
|
|
rl.prompt()
|
2020-02-19 10:59:02 +00:00
|
|
|
})
|