fix game message on frontend + started endgame message to chat (need to print username instead of ids)
This commit is contained in:
parent
6894c30f92
commit
0a9c727e92
1 changed files with 4 additions and 1 deletions
|
|
@ -182,15 +182,18 @@ class StateI {
|
||||||
}
|
}
|
||||||
|
|
||||||
private async cleanupGame(gameId: GameId, game: Pong): Promise<void> {
|
private async cleanupGame(gameId: GameId, game: Pong): Promise<void> {
|
||||||
|
let chat_text = 'A game ended between ';
|
||||||
clearInterval(game.gameUpdate ?? undefined);
|
clearInterval(game.gameUpdate ?? undefined);
|
||||||
this.games.delete(gameId);
|
this.games.delete(gameId);
|
||||||
const winner = game.checkWinner() ?? 'left';
|
const winner = game.checkWinner() ?? 'left';
|
||||||
let player: PUser | undefined = undefined;
|
let player: PUser | undefined = undefined;
|
||||||
if ((player = this.users.get(game.userLeft)) !== undefined) {
|
if ((player = this.users.get(game.userLeft)) !== undefined) {
|
||||||
|
chat_text += player.id + ' and ';
|
||||||
player.currentGame = null;
|
player.currentGame = null;
|
||||||
player.socket.emit('gameEnd', winner);
|
player.socket.emit('gameEnd', winner);
|
||||||
}
|
}
|
||||||
if ((player = this.users.get(game.userRight)) !== undefined) {
|
if ((player = this.users.get(game.userRight)) !== undefined) {
|
||||||
|
chat_text += player.id ;
|
||||||
player.currentGame = null;
|
player.currentGame = null;
|
||||||
player.socket.emit('gameEnd', winner);
|
player.socket.emit('gameEnd', winner);
|
||||||
}
|
}
|
||||||
|
|
@ -201,7 +204,7 @@ class StateI {
|
||||||
this.fastify.db.setPongGameOutcome(gameId, { id: game.userLeft, score: game.score[0] }, { id: game.userRight, score: game.score[1] }, outcome, game.local);
|
this.fastify.db.setPongGameOutcome(gameId, { id: game.userLeft, score: game.score[0] }, { id: game.userRight, score: game.score[1] }, outcome, game.local);
|
||||||
this.fastify.log.info('SetGameOutcome !');
|
this.fastify.log.info('SetGameOutcome !');
|
||||||
if (!game.local) {
|
if (!game.local) {
|
||||||
let payload = {'nextGame':'game finished'}; // TODO: add names of ppl
|
let payload = {'nextGame':chat_text}; // TODO: add names of ppl
|
||||||
try {
|
try {
|
||||||
const resp = await fetch("http://app-chat/api/chat/broadcast", {
|
const resp = await fetch("http://app-chat/api/chat/broadcast", {
|
||||||
method:'POST',
|
method:'POST',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue