diff --git a/bin/mcpd.js b/bin/mcpd.js index 5384c6f..039f413 100755 --- a/bin/mcpd.js +++ b/bin/mcpd.js @@ -2,6 +2,7 @@ 'use strict' +const { config } = require('../lib/config') const program = require('commander') program.version(require('../package.json').version) .option('-p, --port ', 'Port to run on. Default: 3000') @@ -16,7 +17,8 @@ const proxy = require('../lib/proxy-server') const web = require('../lib/web-server') ;(async function () { - proxy.start('1.12.2') + proxy.setSettings(config) + proxy.start() const webPort = await web.listen(program.port || 3000) web.bindProxyInstance(proxy) diff --git a/lib/config.js b/lib/config.js index 43b44d9..26a9112 100644 --- a/lib/config.js +++ b/lib/config.js @@ -7,6 +7,7 @@ const fs = require('fs') // Default configuration const defaultConfig = { + version: '1.12.2', ignoredPackets: { game: { keep_alive: true, @@ -42,8 +43,15 @@ const defaultConfig = { } }, server: { - host: 'localhost', - proxyPort: 25566 + targetHost: 'localhost', + targetPort: 25565, + target_server_is_online: false, + proxyPort: 25566, + online_mode: false + }, + client: { + username: 'username/email', + password: 'password123' }, website: { open_multiple_packets: true diff --git a/lib/proxy-server.js b/lib/proxy-server.js index d7597af..6263ecd 100644 --- a/lib/proxy-server.js +++ b/lib/proxy-server.js @@ -13,23 +13,46 @@ module.exports = { stopping: false, proxyServer: null, proxyClient: null, + settings: null, + + setSettings(settings){ + this.settings = settings + }, + + async start () { - async start (version, proxyPort = 25566, targetHost = 'localhost', targetPort = 25565) { this.proxyServer = createServer({ - 'online-mode': false, + 'online-mode': this.settings.server.online_mode, keepAlive: false, - version, - port: proxyPort + version: this.settings.version, + port: this.settings.server.proxyPort }) return new Promise((resolve, reject) => { this.proxyServer.on('login', (client) => { - this.proxyClient = createClient({ - host: targetHost, - port: targetPort, - username: client.username, - keepAlive: false, - version + // console.log(client) + console.log('client is logging in!') + if (this.proxyClient == null) { + const playerInfo = { + host: this.settings.server.targetHost, + port: this.settings.server.targetPort, + keepAlive: false, + version: this.settings.version + } + if(this.settings.server.target_server_is_online){ + playerInfo.username = this.settings.client.username + playerInfo.password = this.settings.client.password + } + this.proxyClient = createClient(playerInfo) + + } + + console.log('creating a new client!') + + + + client.on('error', (error) => { + console.log(error) }) // === @@ -64,26 +87,32 @@ module.exports = { // End handlers // === - this.proxyClient.on('end', () => { - this.proxyClientEnded = true + //This will call the proxyClient + client.on('end', () => { + this.clientEnded = true + console.log('ending client!') - if (!this.clientEnded) { - client.end() + if (!this.proxyClientEnded) { + this.proxyClient.end() emitter.emit(this.stopping ? 'stop' : 'end') this.stopping = false } }) - client.on('end', () => { - this.clientEnded = true - - if (!this.proxyClientEnded) { - this.proxyClient.end() + this.proxyClient.on('end', () => { + this.proxyClientEnded = true + console.log('ending proxy client!') + if (!this.clientEnded) { + client.end() emitter.emit(this.stopping ? 'stop' : 'end') this.stopping = false } }) + this.proxyClient.on('session', (session) => { + // console.log(session) + }) + // === // Error handlers // === diff --git a/lib/web-server.js b/lib/web-server.js index 1498749..06e6a5f 100644 --- a/lib/web-server.js +++ b/lib/web-server.js @@ -50,6 +50,7 @@ fastify.post('/settings', async (request, reply) => { } if (data.server.host !== config.server.host || data.server.proxyPort !== config.server.proxyPort) { + proxyInstance.setSettings(data) return proxyInstance.restart() } diff --git a/src/App.vue b/src/App.vue index 181a41b..835c798 100644 --- a/src/App.vue +++ b/src/App.vue @@ -18,6 +18,18 @@

Proxy port:

+ +

Client settings

+
+
Login with a real minecraft account? (necessary for online-mode servers): {{settings.server.target_server_is_online}}
+ + +
+

Username (or email if you have a mojang account):

+ +

Password:

+ +
Ignored packets (custom)
@@ -73,7 +85,7 @@
- Recording on {{ host }} at {{ version }} + Recording on {{ settings.server.targetHost }} at {{ settings.version }}