Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion bin/mcpd.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

'use strict'

const { config } = require('../lib/config')
const program = require('commander')
program.version(require('../package.json').version)
.option('-p, --port <number>', 'Port to run on. Default: 3000')
Expand All @@ -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)
Expand Down
12 changes: 10 additions & 2 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const fs = require('fs')

// Default configuration
const defaultConfig = {
version: '1.12.2',
ignoredPackets: {
game: {
keep_alive: true,
Expand Down Expand Up @@ -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'
Comment on lines +52 to +54
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't there a way to avoid setting username/email in settings?

Copy link
Contributor Author

@realDragonium realDragonium Aug 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea, its possible. But for that you need to have the username, clientToken and accessToken. So that means that we would need to read the launcher_profiles.json which is located in your .minecraft folder.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading .minecraft is as bad as hell. For example multimc keeps separate .minecraft per instance. I'll look into the client implementation to check if there's a way to skip the credentials. For now leave it be.

Copy link
Contributor Author

@realDragonium realDragonium Aug 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Edit: using the username, clienttoken and accesstoken is the way when you want to skip the credentials. Underneath I used credentials but it should have been validation which makes it not important since you said that you wanted to skip the credentials and not the validation.
--end edit

Not skipping the credentials is the whole point of adding an option to join online mode servers since thats how the server can validate or your account is real or not cracked?

What if we make the path to the launcher_profile.json as config value so you can change it. And make the creation of a client more dynamic so you can set the config after you have started up the proxy.
Or maybe just start the webserver and start the proxy after setting the file path if you want to use online mode servers?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

launcher_profile.json path as config is too much. I mean that this tool should be as simple as we can make it. Let's leave it be right now, I'll make an issue after merging it. It's not a must have to skip the credentials it's just that I don't really like an idea of putting my minecraft credentials to some tool I found on the internet. For a regular user it may (or may not) sound sketchy.

I'm totally aware that those credentials won't leak if you host it locally. But let's be honest there is a chance that someone would use it over the net/on exposed port. In theory, after enabling the online-mode setting, inputting the credentials and saving, we could remove the username and password from the frontend entirely. Next time the settings will be opened, the password field will be filled with some random string, and username with (idk, maybe) [email protected], both inputs disabled and a text with an open padlock icon saying 🔓 Change credentials or something like that.

Second option, the one I'm more convinced to is to make the credentials as a server side settings. No inputs in the frontend, just in the server config file.

},
website: {
open_multiple_packets: true
Expand Down
67 changes: 48 additions & 19 deletions lib/proxy-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,46 @@ module.exports = {
stopping: false,
proxyServer: null,
proxyClient: null,
settings: null,

setSettings(settings){
this.settings = settings
},
Comment on lines +18 to +20
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unneeded


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
}
Comment on lines +42 to +45
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Newlines around this section

this.proxyClient = createClient(playerInfo)

}

console.log('creating a new client!')



Comment on lines +51 to +53
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix multiple newlines

client.on('error', (error) => {
console.log(error)
})

// ===
Expand Down Expand Up @@ -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)
})
Comment on lines +112 to +114
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this block necessary or is it just for debugging


// ===
// Error handlers
// ===
Expand Down
1 change: 1 addition & 0 deletions lib/web-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

proxyInstance.settings = data

return proxyInstance.restart()
}

Expand Down
14 changes: 13 additions & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@
<input v-model='settings.server.host' type="text" placeholder="localhost:25565" class="bg-white border-b-2 focus:border-teal-400 focus:outline-none rounded py-2 px-4 block w-full appearance-none leading-normal placeholder-gray-600 focus:shadow">
<p class="mb-1 mt-3">Proxy port:</p>
<input v-model='settings.server.proxyPort' type="text" placeholder="25565" class="bg-white border-b-2 focus:border-teal-400 focus:outline-none rounded py-2 px-4 block w-full appearance-none leading-normal placeholder-gray-600 focus:shadow">

<p class="text-xs text-gray-700 my-2">Client settings</p>
<div @click='settings.server.target_server_is_online = !settings.server.target_server_is_online' class="text-xs flex items-center pb-3 pt-4 border-b border-gray-300 group cursor-pointer select-none">
<pre class="text-gray-900">Login with a real minecraft account? (necessary for online-mode servers): {{settings.server.target_server_is_online}}</pre>
<CheckSquareIcon class="ml-auto mr-4 text-teal-400" v-if="settings.server.target_server_is_online" size="1.5x"></CheckSquareIcon>
<SquareIcon class="ml-auto mr-4 text-gray-700 group-hover:text-teal-400" v-else size="1.5x"></SquareIcon>
</div>
<p class="mb-1 mt-3">Username (or email if you have a mojang account):</p>
<input v-model='settings.client.username' type="text" placeholder="Username" class="bg-white border-b-2 focus:border-teal-400 focus:outline-none rounded py-2 px-4 block w-full appearance-none leading-normal placeholder-gray-600 focus:shadow">
<p class="mb-1 mt-3">Password: </p>
<input v-model='settings.client.password' type="text" placeholder="Pa$$w0rd123" class="bg-white border-b-2 focus:border-teal-400 focus:outline-none rounded py-2 px-4 block w-full appearance-none leading-normal placeholder-gray-600 focus:shadow">
Comment on lines +29 to +31
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those should be server side, clients be exposed to the web in some rare cases...


</div>
<div>
<div class="text-xl">Ignored packets (custom)</div>
Expand Down Expand Up @@ -73,7 +85,7 @@
</div>
<div v-if="record.state !== 0" class="fixed top-0 left-0 h-screen w-screen z-10 flex items-center justify-center" style="background: rgba(255, 255, 255, .75)">
<div class="absolute bottom-0 left-0 mb-5 ml-5 text-xs text-gray-700">
Recording on {{ host }} at {{ version }}
Recording on {{ settings.server.targetHost }} at {{ settings.version }}
</div>
<div class="absolute top-0 right-0 mt-5 mr-5">
<span v-if="record.state === -1" title="Open settings" class="cursor-pointer mr-5" @click='openSettings'>
Expand Down