Server error handling

This commit is contained in:
Sam 2018-07-21 02:46:54 +10:00
parent aa325dad50
commit 841d03cdec
1 changed files with 27 additions and 19 deletions

View File

@ -220,6 +220,11 @@ ptserver_io.on('connection', (socket) => {
socket.disconnect(disconnect) socket.disconnect(disconnect)
} }
function updateUserData (username, userData, room) { function updateUserData (username, userData, room) {
if (!room === undefined || room === undefined || room === null) {
console.log('Tried to update a user who isnt in a room', username, userData, room)
return false
}
try {
for (var i in ptserver_io.sockets.adapter.rooms[room].users) { for (var i in ptserver_io.sockets.adapter.rooms[room].users) {
var user = ptserver_io.sockets.adapter.rooms[room].users[i] var user = ptserver_io.sockets.adapter.rooms[room].users[i]
if (user.username === username) { if (user.username === username) {
@ -241,6 +246,9 @@ ptserver_io.on('connection', (socket) => {
return return
} }
} }
} catch (e) {
console.log('Failed to update a user', username, userData, room)
}
} }
function transferHost (user, newHostPredicate) { function transferHost (user, newHostPredicate) {
if (user.role !== 'host') { if (user.role !== 'host') {