Spaces:
Runtime error
Runtime error
Fixed bug where you could join the room multiple times
Browse files
server/src/socket/routes/join_room.ts
CHANGED
|
@@ -21,14 +21,25 @@ export function JoinRoomHandler(ctx: Context<JoinRoomPayload>) {
|
|
| 21 |
let room: Room;
|
| 22 |
|
| 23 |
if (ctx.payload.roomId && !ctx.server.rooms[ctx.payload.roomId]) {
|
|
|
|
| 24 |
room = new Room(ctx.payload.roomId);
|
| 25 |
ctx.server.rooms[room.id] = room;
|
|
|
|
| 26 |
} else if (!ctx.payload.roomId) {
|
|
|
|
| 27 |
ctx.payload.roomId = generateSessionToken(12);
|
| 28 |
room = new Room(ctx.payload.roomId);
|
| 29 |
ctx.server.rooms[room.id] = room;
|
|
|
|
| 30 |
} else {
|
|
|
|
| 31 |
room = ctx.server.rooms[ctx.payload.roomId]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
}
|
| 33 |
|
| 34 |
ctx.user.currentRoom = room;
|
|
|
|
| 21 |
let room: Room;
|
| 22 |
|
| 23 |
if (ctx.payload.roomId && !ctx.server.rooms[ctx.payload.roomId]) {
|
| 24 |
+
// User sent roomId, but room doesn't exist
|
| 25 |
room = new Room(ctx.payload.roomId);
|
| 26 |
ctx.server.rooms[room.id] = room;
|
| 27 |
+
|
| 28 |
} else if (!ctx.payload.roomId) {
|
| 29 |
+
// Didn't include RoomID, creating new one
|
| 30 |
ctx.payload.roomId = generateSessionToken(12);
|
| 31 |
room = new Room(ctx.payload.roomId);
|
| 32 |
ctx.server.rooms[room.id] = room;
|
| 33 |
+
|
| 34 |
} else {
|
| 35 |
+
// RoomId included and room exists, joining...
|
| 36 |
room = ctx.server.rooms[ctx.payload.roomId]
|
| 37 |
+
if (room.hasUser(ctx.user.id)) {
|
| 38 |
+
return ctx.ws.send(JSON.stringify({
|
| 39 |
+
"message": "join_room_response",
|
| 40 |
+
"status": "failed, you are already part of this room",
|
| 41 |
+
}))
|
| 42 |
+
}
|
| 43 |
}
|
| 44 |
|
| 45 |
ctx.user.currentRoom = room;
|