Skip to content

Commit

Permalink
Merge pull request #217 from Noita-Together/next
Browse files Browse the repository at this point in the history
Disconnect tracking
  • Loading branch information
SkyeOfBreeze authored Nov 23, 2024
2 parents 69e4df7 + a758ed4 commit 8091cff
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
2 changes: 1 addition & 1 deletion nt-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nt-app",
"version": "0.11.4",
"version": "0.11.5",
"author": "Noita-Together",
"description": "Allows you to play noita with friends...",
"repository": "https://github.com/Noita-Together/noita-together",
Expand Down
4 changes: 2 additions & 2 deletions nt-app/src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,10 @@ const ipcPlugin = (ipc) => {
})
})

ipc.on("CONNECTION_LOST", () => {
ipc.on("CONNECTION_LOST", (event, data) => {
store.dispatch("errDialog", {
title: "Disconnected from server",
body: "",
body: `Received status code of ${data} when disconnected`,
canClose: false
})
})
Expand Down
37 changes: 28 additions & 9 deletions nt-app/src/ws.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { v4: uuidv4 } = require("uuid")
const { ipcMain } = require("electron")
const { ipcMain, net } = require("electron")
const ws = require("ws")
const {
encodeLobbyMsg,
Expand Down Expand Up @@ -29,7 +29,7 @@ module.exports = (data) => {
let isHost = false

console.log(`Connect to lobby server ${host}`)
/** @type {ws} */
/** @type {WebSocket} */
let client = new ws(`${host}${data.token}`, {
servername: sni
})
Expand All @@ -44,10 +44,6 @@ module.exports = (data) => {
client.send(heartbeat)
}
}, 10000)
client.on("close", () => {
clearInterval(timer)
timer = undefined
})

const lobby = {
sHostStart: (payload) => {
Expand Down Expand Up @@ -114,9 +110,29 @@ module.exports = (data) => {
appEvent("CONNECTED", data)
})

client.on("close", () => {
client.on("close", (code) => {
clearInterval(timer)
timer = undefined
//codes https://github.com/Luka967/websocket-close-codes
console.log(`CONNECTION_LOST with a code of ${code}. Send a message to https://stat.moistmob.com/disconnected/${code}`)
const req = net.request({
url: `https://stat.moistmob.com/disconnected/${code}`,
method: 'GET'
})
req.on('response', (response)=> {
console.log(`STATUS: ${response.statusCode}`);
console.log(`HEADERS: ${JSON.stringify(response.headers)}`);

response.on('data', (chunk) => {
console.log(`BODY: ${chunk}`)
});
})
req.on('error', (error) => {
console.log(error)
})
req.end()
noita.clientDisconnected()
appEvent("CONNECTION_LOST")
appEvent("CONNECTION_LOST", code)
client.terminate()
client = null
})
Expand Down Expand Up @@ -225,7 +241,10 @@ module.exports = (data) => {
return
case '/fakedc':
noita.clientDisconnected()
return;
return
case '/dcthesocket':
client.close()
return
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "noita-together",
"private": true,
"version": "0.11.4",
"version": "0.11.5",
"packageManager": "yarn@3.5.1",
"workspaces": [
"nt-app/",
Expand Down

0 comments on commit 8091cff

Please sign in to comment.