Skip to content

Commit

Permalink
Merge pull request #213 from Noita-Together/feature/disconnected_prompt
Browse files Browse the repository at this point in the history
User disconnect message
  • Loading branch information
SkyeOfBreeze authored Nov 21, 2024
2 parents c9941a9 + 6f9771c commit 95eaa2c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
6 changes: 6 additions & 0 deletions noita_mod/core/files/ws/events.lua
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ wsEvents = {
DespawnPlayerGhost(data.userId)
PlayerList[data.userId] = nil
PlayerCount = PlayerCount - 1
GamePrint(data.userId.. " left the lobby (" .. data.reason .. ")")
end,
PlayerPickup = function(data)
if (data.heart ~= nil) then
Expand Down Expand Up @@ -259,5 +260,10 @@ wsEvents = {
GameAddFlagRun(entry.flag)
end
end
end,
ClientDisconnected = function(data)
print("received a disconnect message from NT client")
GamePrint("Disconnected from lobby. Check NT client for information")
GamePrintImportant("Disconnected from lobby", "check client for information", "")
end
}
3 changes: 0 additions & 3 deletions nt-app/src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,9 @@ ipcMain.on("TRY_LOGIN", async (event, account) => {
responseType: "json"
}
)
console.log(body)
const { token } = body
console.log(token)
appEvent("USER_EXTRA", undefined)
let decoded = jwt.decode(token)
console.log(decoded)
let { sub, preferred_username } = decoded
wsClient({
display_name: preferred_username,
Expand Down
8 changes: 7 additions & 1 deletion nt-app/src/noita.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ class NoitaGame extends EventEmitter {
)
}

clientDisconnected(){
console.log('client disconnected')
this.sendEvt('ClientDisconnected')
}

gameListen() {
if (!this.server) {
this.server = new ws.Server({ port: this.port })
Expand Down Expand Up @@ -247,8 +252,9 @@ class NoitaGame extends EventEmitter {
this.sendEvt("AddPlayer", data)
}

removePlayer(data) {
removePlayer(data, reason) {
delete this.players[data.userId]
data['reason'] = reason
this.sendEvt("RemovePlayer", data)
}

Expand Down
11 changes: 8 additions & 3 deletions nt-app/src/ws.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,22 @@ module.exports = (data) => {
if (payload.userId == user.userId) {
noita.reset()
} else {
noita.removePlayer(payload)
noita.removePlayer(payload, 'banned')
}
},
sUserKicked: (payload) => {
if (payload.userId == user.userId) {
noita.reset()
} else {
noita.removePlayer(payload)
noita.removePlayer(payload, 'kicked')
}
},
sUserLeftRoom: (payload) => {
if (payload.userId == user.userId) {
noita.sendEvt('clientLeftRoom')
noita.reset()
} else {
noita.removePlayer(payload)
noita.removePlayer(payload, 'left/disconnected')
}
},
sUserJoinedRoom: (payload) => {
Expand Down Expand Up @@ -114,6 +115,7 @@ module.exports = (data) => {
})

client.on("close", () => {
noita.clientDisconnected()
appEvent("CONNECTION_LOST")
client.terminate()
client = null
Expand Down Expand Up @@ -221,6 +223,9 @@ module.exports = (data) => {
lobby.sUserLeftRoom(payload)
appEvent('sUserLeftRoom', payload)
return
case '/fakedc':
noita.clientDisconnected()
return;
}
}
}
Expand Down

0 comments on commit 95eaa2c

Please sign in to comment.