Skip to content

Commit

Permalink
Add online mode support
Browse files Browse the repository at this point in the history
  • Loading branch information
Heath123 committed Dec 4, 2020
1 parent 9d3d6fe commit fc85913
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 15 deletions.
7 changes: 7 additions & 0 deletions html/startPage/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ <h1 class='title'>pakkit</h1>
<label for="listen-port">Listen port:</label>
<input type="text" name="listen-port" id="listen-port" value="25566" placeholder="25566">
</p>
<div id="consent-box" style="display: none;">
<br>
<p>
<label for="consent">Consent</label>
<input id="consent" type="checkbox" value="consent"> Allow pakkit to use my auth token from launcher_profiles.json for logging in to online mode servers (can be revoked by pressing F12 and typing <code>localStorage.authConsentGiven = false</code>)
</p>
</div>
<br>
<p>
<label for="start"></label>
Expand Down
8 changes: 8 additions & 0 deletions html/startPage/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ new customTitlebar.Titlebar({
backgroundColor: customTitlebar.Color.fromHex('#FFF')
}); */

if (localStorage.getItem('authConsentGiven') !== 'true') {
document.getElementById('consent-box').style.display = 'contents'
}

var isLoading = false

let connectAddress
Expand Down Expand Up @@ -87,7 +91,11 @@ window.startProxy = function (event) {
connectPort = (connectPort === '') ? '25565' : connectPort
listenPort = (listenPort === '') ? '25566' : listenPort
}
if (document.getElementById('consent').checked) {
localStorage.setItem('authConsentGiven', 'true')
}
ipcRenderer.send('startProxy', JSON.stringify({
consent: localStorage.getItem('authConsentGiven') === 'true',
connectAddress: connectAddress,
connectPort: connectPort,
listenPort: listenPort,
Expand Down
39 changes: 29 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
"escape-html": "^1.0.3",
"md5-file": "^5.0.0",
"minecraft-data": "^2.70.2",
"minecraft-protocol": "^1.19.0",
"minecraft-folder-path": "^1.1.0",
"minecraft-protocol": "github:Heath123/node-minecraft-protocol#ph0t0shop",
"node-eval": "^2.0.0",
"source-map-support": "^0.5.19"
}
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ ipcMain.on('startProxy', (event, arg) => {
proxy = bedrockProxy
}
packetHandler.init(BrowserWindow.getAllWindows()[0], ipcMain, proxy)
proxy.startProxy(ipcMessage.connectAddress, ipcMessage.connectPort, ipcMessage.listenPort, ipcMessage.version, packetHandler.packetHandler, dataFolder)
proxy.startProxy(ipcMessage.connectAddress, ipcMessage.connectPort, ipcMessage.listenPort, ipcMessage.version, ipcMessage.consent, packetHandler.packetHandler, dataFolder)
BrowserWindow.getAllWindows()[0].loadFile('html/mainPage/index.html')
})

Expand Down
2 changes: 1 addition & 1 deletion src/proxy/bedrock/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ exports.capabilities = {
jsonData: false
}

exports.startProxy = function (host, port, listenPort, version, callback, dataFolder) {
exports.startProxy = function (host, port, listenPort, version, authConsent, callback, dataFolder) {
storedCallback = callback
fs.writeFileSync(dataFolder + '/proxypass/config.yml', `
proxy:
Expand Down
11 changes: 9 additions & 2 deletions src/proxy/java/proxy.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Modified from https://github.com/PrismarineJS/node-minecraft-protocol/blob/master/examples/proxy/proxy.js

const mc = require('minecraft-protocol')
const minecraftFolder = require('minecraft-folder-path')

const states = mc.states

Expand All @@ -17,7 +18,7 @@ exports.capabilities = {
serverboundPackets: []
}

exports.startProxy = function (host, port, listenPort, version, callback, dataFolder) {
exports.startProxy = function (host, port, listenPort, version, authConsent, callback, dataFolder) {
storedCallback = callback
const mcdata = require('minecraft-data')(version) // Used to get packets, may remove if I find a better way
toClientMappings = mcdata.protocol.play.toClient.types.packet[1][0].type[1].mappings
Expand Down Expand Up @@ -55,12 +56,18 @@ exports.startProxy = function (host, port, listenPort, version, callback, dataFo
console.log(err.stack)
if (!endedTargetClient) { targetClient.end('Error') }
})
if (authConsent) {
console.log('Will attempt to use launcher_profiles.json for online mode login data')
} else {
console.warn('Consent not given to use launcher_profiles.json - online mode will not work')
}
const targetClient = mc.createClient({
host: host,
port: port,
username: client.username,
keepAlive: false,
version: version
version: version,
profilesFolder: authConsent ? minecraftFolder : undefined
})
realServer = targetClient
client.on('packet', function (data, meta) {
Expand Down

0 comments on commit fc85913

Please sign in to comment.