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'
|
|
|
|
let client = createConnection('192.168.2.5', 25577, username)
|
2020-02-19 10:59:02 +00:00
|
|
|
|
2020-02-23 14:35:05 +00:00
|
|
|
function createConnection(host: string, port: number, username: string) {
|
|
|
|
let client = createClient({
|
|
|
|
version: '1.12.2',
|
|
|
|
host,
|
|
|
|
port,
|
|
|
|
username,
|
|
|
|
skipValidation: true
|
|
|
|
})
|
2020-02-19 10:59:02 +00:00
|
|
|
|
2020-02-23 14:35:05 +00:00
|
|
|
attachForge(client)
|
|
|
|
attachEvents(client)
|
|
|
|
return client;
|
|
|
|
}
|
2020-02-19 10:59:02 +00:00
|
|
|
|
2020-03-02 14:28:27 +00:00
|
|
|
client.on('error', (error) => {
|
|
|
|
console.log("Client Error", error)
|
|
|
|
})
|
|
|
|
|
2020-02-23 14:35:05 +00:00
|
|
|
client.on('end', (resone) => {
|
|
|
|
console.log("Client End Resone:", resone)
|
|
|
|
client = createConnection('192.168.2.5', 25577, username)
|
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 "":
|
|
|
|
break;
|
2020-03-02 14:28:27 +00:00
|
|
|
case "eval":
|
|
|
|
break;
|
2020-03-01 16:32:07 +00:00
|
|
|
case "write":
|
|
|
|
break;
|
2020-02-23 14:35:05 +00:00
|
|
|
case "/respawn":
|
|
|
|
client.write('client_command', { payload: 0 })
|
|
|
|
break;
|
|
|
|
case "//reco":
|
|
|
|
client.end("")
|
|
|
|
client = createConnection('192.168.2.5', 25577, username)
|
|
|
|
break;
|
|
|
|
case "//quit":
|
|
|
|
console.info('Disconnected')
|
|
|
|
client.end("")
|
|
|
|
break;
|
|
|
|
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
|
|
|
})
|