Skip to content

Commit

Permalink
Fix reconnecting on Bedrock
Browse files Browse the repository at this point in the history
  • Loading branch information
Heath123 committed Dec 24, 2020
1 parent fdbf2ce commit b22292c
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 23 deletions.
Binary file modified data/proxypass-pakkit.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion html/mainPage/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,9 @@ function deselectPacket () {
}

window.clearPackets = function () { // window. stops standardjs from complaining
deselectPacket()
sharedVars.allPackets = []
sharedVars.allPacketsHTML = []
deselectPacket()
sharedVars.packetsUpdated = true
// TODO: Doesn't seem to work? When removing line above it doesn't do anything until the next packet
wrappedClusterizeUpdate([])
Expand Down
74 changes: 52 additions & 22 deletions src/proxy/bedrock/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,21 @@ exports.capabilities = {
versionId: 'bedrock-proxypass-json'
}

exports.startProxy = function (host, port, listenPort, version, authConsent, callback, dataFolder) {
let host
let port
let listenPort

function launch() {
proxyPass.startFromArgs('0.0.0.0', Number(listenPort), host, Number(port), 1, true, true, "pakkit", "pakkit proxy powered by ProxyPass", function(err, test) {
console.log(err, test)
})
}

exports.startProxy = function (passedHost, passedPort, passedListenPort, version, authConsent, callback, dataFolder) {
host = passedHost
port = passedPort
listenPort = passedListenPort

java.classpath.push(dataFolder + '/proxypass/proxypass-pakkit.jar')

proxyPass = java.import('com.nukkitx.proxypass.ProxyPass')
Expand All @@ -41,31 +55,39 @@ exports.startProxy = function (host, port, listenPort, version, authConsent, cal

storedCallback = callback

console.log(proxyPass)
proxyPass.startFromArgs('0.0.0.0', Number(listenPort), host, Number(port), 1, true, true, "pakkit", "pakkit proxy powered by ProxyPass", function(err, test) {
console.log(err, test)
})
launch()

// Poll for packets as the java module doesn't seem to support callbacks
setInterval(function () {
const array = proxyPass.packetQueue.toArraySync()
for (const item of array) {
const name = item.packetType.toStringSync().toLowerCase();

const data = JSON.parse(item.jsonData);
const hexIdString = '0x' + item.packetId.toString(16).padStart(2, '0')

// These values are unneeded or are exposed elsewhere in the GUI
delete data.packetId
delete data.packetType
delete data.clientId
delete data.senderId

const raw = Object.values(item.bytes)
// Prepend packet ID for consistency with Java Edition
raw.unshift(item.packetId)

storedCallback(item.direction, { name: name, className: item.className }, data, hexIdString, raw)
if (item.isEvent) {
switch(item.eventType) {
case 'disconnect':
console.log('Disconnect - relaunching proxy')
relaunch()
break;
default:
console.log('Unknown event', item.eventType)
}
} else {
const name = item.packetType.toStringSync().toLowerCase();

const data = JSON.parse(item.jsonData);
const hexIdString = '0x' + item.packetId.toString(16).padStart(2, '0')

// These values are unneeded or are exposed elsewhere in the GUI
delete data.packetId
delete data.packetType
delete data.clientId
delete data.senderId

const raw = Object.values(item.bytes)
// Prepend packet ID for consistency with Java Edition
raw.unshift(item.packetId)

storedCallback(item.direction, { name: name, className: item.className }, data, hexIdString, raw)
}
}

proxyPass.packetQueue.clearSync()
Expand All @@ -77,7 +99,15 @@ exports.startProxy = function (host, port, listenPort, version, authConsent, cal
exports.end = function () {
proxyPass.shutdownStatic(function(err, test) {
console.log(err, test)
});
})
}

// used to relaunch on disconnect
function relaunch () {
proxyPass.shutdownStatic(function(err, test) {
console.log(err, test)
launch()
})
}

exports.writeToClient = function (meta, data) {
Expand Down

0 comments on commit b22292c

Please sign in to comment.