From 33194d74bf83581b82bfe3ff43bb419cbe43e430 Mon Sep 17 00:00:00 2001 From: realDragonium Date: Wed, 29 Jul 2020 23:32:58 +0200 Subject: [PATCH 1/2] first setup which works with online servers! added login credentials for creating a client. --- lib/config.js | 5 ++++ lib/proxy-server.js | 58 +++++++++++++++++++++++++++++++++------------ 2 files changed, 48 insertions(+), 15 deletions(-) diff --git a/lib/config.js b/lib/config.js index 245cbdc..9da8062 100644 --- a/lib/config.js +++ b/lib/config.js @@ -44,6 +44,11 @@ const defaultConfig = { server: { host: 'localhost', proxyPort: 25566 + }, + client: { + username: 'username', + email: 'email@email.email', + password: 'password123' } } diff --git a/lib/proxy-server.js b/lib/proxy-server.js index d7597af..21b0fbb 100644 --- a/lib/proxy-server.js +++ b/lib/proxy-server.js @@ -13,8 +13,12 @@ module.exports = { stopping: false, proxyServer: null, proxyClient: null, + settings: null, async start (version, proxyPort = 25566, targetHost = 'localhost', targetPort = 25565) { + // const response = await fetch(`http://${HOST}/settings`) + // this.settings = await response.json() + this.proxyServer = createServer({ 'online-mode': false, keepAlive: false, @@ -24,12 +28,30 @@ module.exports = { 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) { + this.proxyClient = createClient({ + host: 'play.nlkingdom.nl', + // host: targetHost, + // port: targetPort, + // username: client.username, + username: '', + keepAlive: false, + version, + uuid: client.uuid, + password: '' + }) + } else { + + } + + console.log('creating a new client!') + + + + client.on('error', (error) => { + console.log(error) }) // === @@ -64,9 +86,21 @@ module.exports = { // End handlers // === + //This will call the proxyClient + client.on('end', () => { + this.clientEnded = true + console.log('ending client!') + + // if (!this.proxyClientEnded) { + // this.proxyClient.end() + // emitter.emit(this.stopping ? 'stop' : 'end') + // this.stopping = false + // } + }) + this.proxyClient.on('end', () => { this.proxyClientEnded = true - + console.log('ending proxy client!') if (!this.clientEnded) { client.end() emitter.emit(this.stopping ? 'stop' : 'end') @@ -74,14 +108,8 @@ module.exports = { } }) - client.on('end', () => { - this.clientEnded = true - - if (!this.proxyClientEnded) { - this.proxyClient.end() - emitter.emit(this.stopping ? 'stop' : 'end') - this.stopping = false - } + this.proxyClient.on('session', (session) => { + // console.log(session) }) // === From 0b408cd9c9e27788d729d547532164b30d120912 Mon Sep 17 00:00:00 2001 From: realDragonium Date: Thu, 30 Jul 2020 12:09:28 +0200 Subject: [PATCH 2/2] Most settings for the proxy are now loaded from the config. You can change your version now and WIP for: - making the server restart if you change targetHost - passing the settings correctly from web to proxy - trying to make it so that you dont have to relog if you want to join another server if you login with a online account in minecraft self. --- bin/mcpd.js | 4 +++- lib/config.js | 11 +++++++---- lib/proxy-server.js | 45 +++++++++++++++++++++++---------------------- lib/web-server.js | 1 + src/App.vue | 14 +++++++++++++- 5 files changed, 47 insertions(+), 28 deletions(-) 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 e48359f..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,12 +43,14 @@ 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: 'email@email.email', + username: 'username/email', password: 'password123' }, website: { diff --git a/lib/proxy-server.js b/lib/proxy-server.js index 21b0fbb..6263ecd 100644 --- a/lib/proxy-server.js +++ b/lib/proxy-server.js @@ -15,15 +15,17 @@ module.exports = { proxyClient: null, settings: null, - async start (version, proxyPort = 25566, targetHost = 'localhost', targetPort = 25565) { - // const response = await fetch(`http://${HOST}/settings`) - // this.settings = await response.json() + setSettings(settings){ + this.settings = settings + }, + + async start () { 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) => { @@ -31,18 +33,17 @@ module.exports = { // console.log(client) console.log('client is logging in!') if (this.proxyClient == null) { - this.proxyClient = createClient({ - host: 'play.nlkingdom.nl', - // host: targetHost, - // port: targetPort, - // username: client.username, - username: '', + const playerInfo = { + host: this.settings.server.targetHost, + port: this.settings.server.targetPort, keepAlive: false, - version, - uuid: client.uuid, - password: '' - }) - } else { + 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) } @@ -91,11 +92,11 @@ module.exports = { this.clientEnded = true console.log('ending client!') - // if (!this.proxyClientEnded) { - // this.proxyClient.end() - // emitter.emit(this.stopping ? 'stop' : 'end') - // this.stopping = false - // } + if (!this.proxyClientEnded) { + this.proxyClient.end() + emitter.emit(this.stopping ? 'stop' : 'end') + this.stopping = false + } }) this.proxyClient.on('end', () => { 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 }}