Skip to content

Commit 1bf6b4b

Browse files
feat: add password validation for joining duels (#171)
* chore: translate server error messages to English * feat: add password validation for joining duels
1 parent 60f3a76 commit 1bf6b4b

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

src/edopro/room/application/JoinHandler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class JoinHandler implements JoinMessageHandler {
3535

3636
if (!room) {
3737
this.socket.send(
38-
ServerErrorClientMessage.create("Sala no encontrada. Intenta recargando la lista")
38+
ServerErrorClientMessage.create("Room not found. Try reloading the list")
3939
);
4040

4141
this.socket.send(ErrorClientMessage.create(ErrorMessages.JOIN_ERROR));
@@ -46,7 +46,7 @@ export class JoinHandler implements JoinMessageHandler {
4646
}
4747

4848
if (room.password !== joinMessage.password) {
49-
this.socket.send(ServerErrorClientMessage.create("Clave incorrecta"));
49+
this.socket.send(ServerErrorClientMessage.create("Wrong password"));
5050
this.socket.send(ErrorClientMessage.create(ErrorMessages.JOIN_ERROR));
5151
this.socket.destroy();
5252

src/edopro/room/domain/RoomState.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export abstract class RoomState {
8888
): void {
8989
socket.send(
9090
ServerErrorClientMessage.create(
91-
`Ya existe un jugador con el nombre :${playerInfoMessage.name}`
91+
`Already exists a player with the name :${playerInfoMessage.name}`
9292
)
9393
);
9494
socket.send(ErrorClientMessage.create(ErrorMessages.JOIN_ERROR));

src/edopro/room/domain/states/dueling/DuelingState.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,12 @@ export class DuelingState extends RoomState {
654654
this.logger.debug("DUELING: JOIN");
655655
const playerInfoMessage = new PlayerInfoMessage(message.previousMessage, message.data.length);
656656
const joinMessage = new JoinGameMessage(message.data);
657+
if (room.password !== joinMessage.password) {
658+
socket.send(ServerErrorClientMessage.create("Wrong password"));
659+
socket.send(ErrorClientMessage.create(ErrorMessages.JOIN_ERROR));
660+
socket.destroy();
661+
return;
662+
}
657663
const reconnectingPlayer = this.playerAlreadyInRoom(playerInfoMessage, room, socket);
658664

659665
if (!(reconnectingPlayer instanceof Client)) {

src/edopro/room/domain/states/waiting/WaitingState.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,15 @@ export class WaitingState extends RoomState {
104104
room.clients.forEach((_client: Client) => {
105105
_client.sendMessage(
106106
ServerErrorClientMessage.create(
107-
`El Jugador:${playerSelect.name} ha sido Baneado de esta Sala, solo podra ingresar como espectador!!`
107+
`The player:${playerSelect.name} has been banned from this room, he can only enter as a spectator!!`
108108
)
109109
);
110110
});
111111

112112
room.spectators.forEach((_client: Client) => {
113113
_client.sendMessage(
114114
ServerErrorClientMessage.create(
115-
`El Jugador:${playerSelect.name} ha sido Baneado de esta Sala, solo podra ingresar como espectador!!`
115+
`The player:${playerSelect.name} has been banned from this room, he can only enter as a spectator!!`
116116
)
117117
);
118118
});

0 commit comments

Comments
 (0)