Skip to content

Commit

Permalink
Add error message when unable to connect (Bedrock)
Browse files Browse the repository at this point in the history
  • Loading branch information
Heath123 committed Dec 24, 2020
1 parent 46ab9c5 commit 3d7a778
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 7 deletions.
Binary file modified data/proxypass-pakkit.jar
Binary file not shown.
5 changes: 5 additions & 0 deletions html/mainPage/js/ipcHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,9 @@ exports.setup = function (passedSharedVars) {
const ipcMessage = JSON.parse(arg)
handleError(ipcMessage.msg, ipcMessage.stack)
})

sharedVars.ipcRenderer.on('message', (event, arg) => {
const ipcMessage = JSON.parse(arg)
errorDialog(ipcMessage.header, ipcMessage.info)
})
}
21 changes: 17 additions & 4 deletions html/mainPage/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,12 +280,13 @@ function editAndResend (id) {

// dialogOpen = true
document.getElementById('dialog-overlay').className = 'dialog-overlay active'
document.getElementById('dialog').className='dialog'
document.getElementById('dialog').innerHTML =

`<h2>Edit and resend packet</h2>
<textarea id="packetEditor"></textarea>
<button style="margin-top: 16px;" onclick="resendEdited(${id}, packetEditor.getValue())">Send</button>
<button style="margin-top: 16px;" onclick="closeDialog()">Close</button>`
`<h2>Edit and resend packet</h2>
<textarea id="packetEditor"></textarea>
<button style="margin-top: 16px;" onclick="resendEdited(${id}, packetEditor.getValue())">Send</button>
<button style="margin-top: 16px;" class="bottom-button" onclick="closeDialog()">Close</button>`

document.getElementById('packetEditor').value = JSON.stringify(sharedVars.allPackets[id].data, null, 2)

Expand All @@ -296,6 +297,18 @@ function editAndResend (id) {
})
}

function errorDialog(header, info) {
// dialogOpen = true
document.getElementById('dialog-overlay').className = 'dialog-overlay active'
document.getElementById('dialog').className='dialog dialog-small'
document.getElementById('dialog').innerHTML =

`<h2>${header}</h2>
${info}
<br>
<button style="margin-top: 16px;" class="bottom-button" onclick="closeDialog()">Close</button>`
}

sharedVars.ipcRenderer.on('editAndResend', (event, arg) => { // Context menu
const ipcMessage = JSON.parse(arg)
editAndResend(ipcMessage.id)
Expand Down
12 changes: 12 additions & 0 deletions html/mainPage/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ div.dialog {
box-sizing: border-box;
}

div.dialog-small {
top: calc(50% - 100px);
left: calc(50% - 250px);
height: 200px;
width: 500px;
}

.CodeMirror.CodeMirror {
height: calc(100% - 120px);
}
Expand Down Expand Up @@ -252,4 +259,9 @@ div.error {

#mainPresets, #extendedPresets {
display: contents;
}

.bottom-button {
position: absolute;
bottom: 16px;
}
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ if (continueProgram) {
proxy = bedrockProxy
}
packetHandler.init(BrowserWindow.getAllWindows()[0], ipcMain, proxy)
proxy.startProxy(ipcMessage.connectAddress, ipcMessage.connectPort, ipcMessage.listenPort, ipcMessage.version, ipcMessage.consent, packetHandler.packetHandler, dataFolder)
proxy.startProxy(ipcMessage.connectAddress, ipcMessage.connectPort, ipcMessage.listenPort, ipcMessage.version, ipcMessage.consent, packetHandler.packetHandler, packetHandler.messageHandler , dataFolder)
BrowserWindow.getAllWindows()[0].loadFile('html/mainPage/index.html')
})

Expand Down
4 changes: 4 additions & 0 deletions src/packetHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,7 @@ exports.packetHandler = function (direction, meta, data, id, raw) {
console.error(err)
}
}

exports.messageHandler = function (header, info) {
mainWindow.send('message', JSON.stringify({ header: header, info: info }))
}
8 changes: 7 additions & 1 deletion src/proxy/bedrock/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function launch() {
})
}

exports.startProxy = function (passedHost, passedPort, passedListenPort, version, authConsent, callback, dataFolder) {
exports.startProxy = function (passedHost, passedPort, passedListenPort, version, authConsent, callback, messageCallback, dataFolder) {
host = passedHost
port = passedPort
listenPort = passedListenPort
Expand Down Expand Up @@ -63,6 +63,12 @@ exports.startProxy = function (passedHost, passedPort, passedListenPort, version
for (const item of array) {
if (item.isEvent) {
switch(item.eventType) {
case 'unableToConnect':
messageCallback('Ubale to connect to server', 'Unable to connect to the Bedrock server at ' +
item.eventData.replace(/^\//, '') + // Remove slash at start
'. Make sure the server is online.')
relaunch()
break;
case 'disconnect':
console.log('Disconnect - relaunching proxy')
relaunch()
Expand Down
2 changes: 1 addition & 1 deletion src/proxy/java/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ exports.capabilities = {
versionId: undefined
}

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

// . cannot be in a JSON property name with electron-store
Expand Down

0 comments on commit 3d7a778

Please sign in to comment.