Lista de partidas
This commit is contained in:
@@ -28,7 +28,7 @@ export class SalaChatGateway
|
||||
});
|
||||
client.broadcast
|
||||
.to('chat_general')
|
||||
.emit('onUserConnectRoom', userConectado);
|
||||
.emit('onUserChangeStatus', userConectado);
|
||||
} else {
|
||||
client.disconnect();
|
||||
}
|
||||
@@ -40,31 +40,52 @@ export class SalaChatGateway
|
||||
if (userDesconectado) {
|
||||
client.broadcast
|
||||
.to('chat_general')
|
||||
.emit('onUserDisconnectRoom', userDesconectado);
|
||||
.emit('onUserChangeStatus', userDesconectado);
|
||||
}
|
||||
client.leave('chat_general');
|
||||
}
|
||||
|
||||
@SubscribeMessage('chatMsg')
|
||||
@SubscribeMessage('msgChat')
|
||||
handleMsg(client: Socket, msg: string) {
|
||||
const userId = client.handshake.auth.userId;
|
||||
const user = this.salaChatService.getUsuarioUUID(userId);
|
||||
if (user) {
|
||||
client.broadcast.to('chat_general').emit('chatMsg',{ uuid: userId, msg });
|
||||
return { uuid: userId, msg };
|
||||
} else {
|
||||
client.disconnect();
|
||||
}
|
||||
client.broadcast
|
||||
.to('chat_general')
|
||||
.emit('onMsgChat', { uuid: userId, msg });
|
||||
return { uuid: userId, msg };
|
||||
}
|
||||
|
||||
sendBroadcastMsg(msg: string) {
|
||||
this.server.to('chat_general').emit('broadcastMsg', msg);
|
||||
}
|
||||
|
||||
@SubscribeMessage('creaPartida')
|
||||
handleCreaPartida(client: Socket) {
|
||||
@SubscribeMessage('createPartida')
|
||||
handleCreatePartida(client: Socket) {
|
||||
const userId = client.handshake.auth.userId;
|
||||
const partida = this.salaChatService.creaPartida(userId);
|
||||
this.server.to('chat_general').emit('onCrearPartida', partida);
|
||||
client.broadcast.to('chat_general').emit('onCreatePartida', partida);
|
||||
return partida;
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeMessage('cancelPartida')
|
||||
handleCancelPartida(client: Socket, uuidPartida: string) {
|
||||
const userId = client.handshake.auth.userId;
|
||||
const uuidPartidaEliminado = this.salaChatService.eliminarPartida(
|
||||
userId,
|
||||
uuidPartida,
|
||||
);
|
||||
if (uuidPartidaEliminado)
|
||||
client.broadcast
|
||||
.to('chat_general')
|
||||
.emit('onCancelPartida', uuidPartidaEliminado);
|
||||
return uuidPartidaEliminado;
|
||||
}
|
||||
|
||||
@SubscribeMessage('joinPartida')
|
||||
handleJoinPartida(client: Socket, uuidPartida: string) {
|
||||
const userId = client.handshake.auth.userId;
|
||||
const partida = this.salaChatService.unirsePartida(userId, uuidPartida);
|
||||
client.broadcast.to('chat_general').emit('onJoinPartida', partida);
|
||||
return partida;
|
||||
}
|
||||
}
|
||||
@@ -59,4 +59,12 @@ export class SalaChatService {
|
||||
const partida = this.partidasService.creaPartida(uuidJugadorCreador);
|
||||
return partida;
|
||||
}
|
||||
|
||||
unirsePartida(uuidJugadorB:string,uuidPartida:string){
|
||||
return this.partidasService.unirsePartida(uuidJugadorB,uuidPartida);
|
||||
}
|
||||
|
||||
eliminarPartida(uuidJugador:string, uuidPartida:string){
|
||||
return this.partidasService.eliminarPartida(uuidJugador,uuidPartida);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,9 +27,35 @@ export class PartidasService {
|
||||
|
||||
creaPartida(uuidJugadorA: string) {
|
||||
const uuid = uuidv4();
|
||||
const nickJugadorA=this.usuariosService.usuarios.get(uuidJugadorA).nickname;
|
||||
const partida = new Partida(uuid, uuidJugadorA,nickJugadorA);
|
||||
const nickJugadorA =
|
||||
this.usuariosService.usuarios.get(uuidJugadorA).nickname;
|
||||
const partida = new Partida(uuid, uuidJugadorA, nickJugadorA);
|
||||
this._partidas.set(uuid, partida);
|
||||
return partida;
|
||||
}
|
||||
|
||||
unirsePartida(uuidJugadorB: string, uuidPartida: string){
|
||||
const partida = this._partidas.get(uuidPartida);
|
||||
const nickJugadorB = this.usuariosService.usuarios.get(uuidJugadorB)?.nickname;
|
||||
partida.uuidJugadorB = uuidJugadorB;
|
||||
partida.nickJugadorB = nickJugadorB;
|
||||
partida.abierta = false;
|
||||
return partida;
|
||||
}
|
||||
|
||||
|
||||
eliminarPartida(uuidJugador: string, uuidPartida: string) {
|
||||
if (!this._partidas.has(uuidPartida)) {
|
||||
return null;
|
||||
}
|
||||
const partida = this._partidas.get(uuidPartida);
|
||||
if (
|
||||
partida.uuidJugadorA !== uuidJugador &&
|
||||
partida.uuidJugadorB !== uuidJugador
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
this._partidas.delete(uuidPartida);
|
||||
return uuidPartida;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user