Fixed issue where unknown user could send certain messages and crash
server
This commit is contained in:
parent
ee348bf7f3
commit
cbe7433b0f
19
server.js
19
server.js
|
@ -307,7 +307,6 @@ socketServer.on('connection', (socket) => {
|
||||||
if (socket.ourRoom == null) {
|
if (socket.ourRoom == null) {
|
||||||
// console.log('This user should join a room first')
|
// console.log('This user should join a room first')
|
||||||
socket.emit('flowerror', 'You aren\' connected to a room! Use join');
|
socket.emit('flowerror', 'You aren\' connected to a room! Use join');
|
||||||
socket.emit('rejoin');
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -356,7 +355,6 @@ socketServer.on('connection', (socket) => {
|
||||||
if (socket.ourRoom == null) {
|
if (socket.ourRoom == null) {
|
||||||
// console.log('This user should join a room first')
|
// console.log('This user should join a room first')
|
||||||
socket.emit('flowerror', 'You aren\' connected to a room! Use join');
|
socket.emit('flowerror', 'You aren\' connected to a room! Use join');
|
||||||
socket.emit('rejoin');
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// console.log('New message in channel ' + socket.selfUser.room + ' from ' + socket.selfUser.username + ' saying ' + msg)
|
// console.log('New message in channel ' + socket.selfUser.room + ' from ' + socket.selfUser.username + ' saying ' + msg)
|
||||||
|
@ -372,8 +370,16 @@ socketServer.on('connection', (socket) => {
|
||||||
|
|
||||||
socket.on('party_pausing_change', (value) => {
|
socket.on('party_pausing_change', (value) => {
|
||||||
const user = socket.selfUser;
|
const user = socket.selfUser;
|
||||||
|
|
||||||
|
if (!user) {
|
||||||
|
return 'Invalid status';
|
||||||
|
}
|
||||||
|
|
||||||
const room = socketServer.sockets.adapter.rooms[user.room];
|
const room = socketServer.sockets.adapter.rooms[user.room];
|
||||||
if (!user || !room) return 'Invalid status';
|
if (!room) {
|
||||||
|
return 'Invalid status';
|
||||||
|
}
|
||||||
|
|
||||||
if (user.role !== 'host') return 'You are not the host';
|
if (user.role !== 'host') return 'You are not the host';
|
||||||
room.partyPausing = value;
|
room.partyPausing = value;
|
||||||
socket.broadcast.to(socket.selfUser.room).emit('party-pausing-changed', { value, user });
|
socket.broadcast.to(socket.selfUser.room).emit('party-pausing-changed', { value, user });
|
||||||
|
@ -383,10 +389,16 @@ socketServer.on('connection', (socket) => {
|
||||||
|
|
||||||
socket.on('party_pausing_send', (isPause) => {
|
socket.on('party_pausing_send', (isPause) => {
|
||||||
const user = socket.selfUser;
|
const user = socket.selfUser;
|
||||||
|
if (!user) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
const room = socketServer.sockets.adapter.rooms[user.room];
|
const room = socketServer.sockets.adapter.rooms[user.room];
|
||||||
|
|
||||||
if (!room || !room.partyPausing) {
|
if (!room || !room.partyPausing) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
socket.broadcast.to(socket.selfUser.room).emit('party-pausing-pause', { isPause, user });
|
socket.broadcast.to(socket.selfUser.room).emit('party-pausing-pause', { isPause, user });
|
||||||
socket.emit('party-pausing-pause', { isPause, user });
|
socket.emit('party-pausing-pause', { isPause, user });
|
||||||
return true;
|
return true;
|
||||||
|
@ -395,7 +407,6 @@ socketServer.on('connection', (socket) => {
|
||||||
socket.on('transfer_host', (data) => {
|
socket.on('transfer_host', (data) => {
|
||||||
if (socket.ourRoom == null) {
|
if (socket.ourRoom == null) {
|
||||||
socket.emit('flowerror', 'You aren\'t connected to a room! Use join');
|
socket.emit('flowerror', 'You aren\'t connected to a room! Use join');
|
||||||
socket.emit('rejoin');
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
transferHost(socket.selfUser, (user) => user.username === data.username);
|
transferHost(socket.selfUser, (user) => user.username === data.username);
|
||||||
|
|
Loading…
Reference in New Issue