Skip to content

Commit 21b7a2f

Browse files
committed
Don't return early for the client + normalize lobby code
1 parent f2a439e commit 21b7a2f

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

src/clients/client.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class ClientService {
3838
sendLobby(response: EventMessage, code: LobbyCode) {
3939
for (const [socketId, socket] of Object.entries(this.clients)) {
4040
// skip clients not in the lobby
41-
if (!ROOMMAN.isJoined(socketId, code)) return;
41+
if (!ROOMMAN.isJoined(socketId, code)) continue;
4242

4343
if (socket.readyState === WebSocket.OPEN) {
4444
socket.send(JSON.stringify(response));

src/events/events.gateway.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,9 @@ export class EventsGateway implements OnGatewayConnection, OnGatewayDisconnect {
190190
socketId: SocketId,
191191
{ machine, code, password }: JoinLobbyPayload,
192192
): Promise<EventMessage<ResponseStatusPayload> | undefined> {
193-
if (!canJoinLobby(code, password)) {
193+
const normalizedCode = code.toUpperCase();
194+
195+
if (!canJoinLobby(normalizedCode, password)) {
194196
return {
195197
event: 'responseStatus',
196198
data: {
@@ -211,7 +213,7 @@ export class EventsGateway implements OnGatewayConnection, OnGatewayDisconnect {
211213
this.disconnectMachine(socketId);
212214
}
213215

214-
const lobby = LOBBYMAN.lobbies[code];
216+
const lobby = LOBBYMAN.lobbies[normalizedCode];
215217
if (lobby === undefined) {
216218
return responseStatusFailure('joinLobby', 'Lobby not found');
217219
}
@@ -230,10 +232,10 @@ export class EventsGateway implements OnGatewayConnection, OnGatewayDisconnect {
230232
...machine,
231233
socketId,
232234
};
233-
ROOMMAN.join(socketId, code);
234-
LOBBYMAN.machineConnections[socketId] = code;
235+
ROOMMAN.join(socketId, normalizedCode);
236+
LOBBYMAN.machineConnections[socketId] = normalizedCode;
235237

236-
this.broadcastLobbyState(code);
238+
this.broadcastLobbyState(normalizedCode);
237239

238240
return undefined;
239241
}

0 commit comments

Comments
 (0)