diff --git a/services/decks-service/src/decks-service.ts b/services/decks-service/src/decks-service.ts index f27ae5e8..9e70e677 100644 --- a/services/decks-service/src/decks-service.ts +++ b/services/decks-service/src/decks-service.ts @@ -70,7 +70,7 @@ export default class DecksService extends Service { } await this.broker.broadcast('cache.clean.decks'); await this.broker.cacher?.clean(); - }, 1000); + }, 5000); } }, ); diff --git a/services/games-service/src/game.ts b/services/games-service/src/game.ts index 7189f83a..2dc81385 100644 --- a/services/games-service/src/game.ts +++ b/services/games-service/src/game.ts @@ -54,6 +54,7 @@ export default class Game extends TurnHandler { private nextTurnTimeout: NodeJS.Timer = null; private players: { [id: string]: GamePlayer } = this.initalizePlayers(this._room); private gameState = GameState.TURN_SETUP; + protected lastGameState = null; constructor(private _room: Room, broker: ServiceBroker, logger: LoggerInstance) { super(broker, logger); @@ -80,6 +81,7 @@ export default class Game extends TurnHandler { return this.fetchCards(this._room.options.decks) .then(() => { this.logger.info('Game started, sending data', initialData); + this.lastGameState = initialData; this.broker.emit('games.updated', initialData); this.handleNextTurn(); }); @@ -120,12 +122,13 @@ export default class Game extends TurnHandler { state: GameState.ENEDED, }; + this.lastGameState = initialData; this.broker.emit('games.updated', initialData); } private handleNextTurn() { if (this.nextTurnTimeout) { - clearTimeout(this.nextTurnTimeout) + clearTimeout(this.nextTurnTimeout); } // Target should actually be based on the first user score to get to that. @@ -150,6 +153,7 @@ export default class Game extends TurnHandler { }; this.logger.info('Starting turn', withState); + this.lastGameState = withState; await this.broker.emit('games.updated', withState); this.setGameTimer(); }) @@ -183,6 +187,8 @@ export default class Game extends TurnHandler { winningCards: [], state: GameState.SELECTING_WINNER, }; + + this.lastGameState = initialData; await this.broker.emit('games.updated', initialData); } @@ -220,6 +226,7 @@ export default class Game extends TurnHandler { state: GameState.TURN_SETUP, }; + this.lastGameState = initialData; this.broker.emit('games.updated', initialData); this.nextTurnTimeout = setTimeout(() => { @@ -256,6 +263,7 @@ export default class Game extends TurnHandler { // Store the end state of each round in a collection. this.turns.push(initialData); + this.lastGameState = initialData; // Emit the winning card, and winning player, for front-end display await this.broker.emit('games.updated', initialData); @@ -286,6 +294,11 @@ export default class Game extends TurnHandler { // Ensure the new player is including in the match. this.players[playerId] = { _id: playerId, cards: [], isCzar: false, score: 0 }; await this.dealWhiteCards(this.players[playerId]); + + // Implement this. + // if (this.lastGameState) { + // emit update to only the player that joined. + // } } public destroy() { diff --git a/services/games-service/src/turn.ts b/services/games-service/src/turn.ts index dc4ea13e..6f3ee148 100644 --- a/services/games-service/src/turn.ts +++ b/services/games-service/src/turn.ts @@ -105,7 +105,7 @@ export default class TurnHandler { } private pickBlackCard(): Promise { - const index = this.getRandomIndex(this.blackCards.length); + const index = this.getRandomIndex(this.blackCards.length - 1); // Remove the card so it cannot be chosen again. this.blackCards.splice(index, 1); const id = this.blackCards[index]; @@ -113,29 +113,30 @@ export default class TurnHandler { } private pickWhiteCard(): string { - const index = this.getRandomIndex(this.whiteCards.length); + const index = this.getRandomIndex(this.whiteCards.length - 1); // Remove the card so it cannot be chosen again. this.whiteCards.splice(index, 1); return this.whiteCards[index]; } + private emitCardsToPlayer(player: GamePlayer) { + // Get all the cards and deal them to the player. + return this.broker.call('cards.get', { id: player.cards }) + .then(cards => this.broker.emit('games.deal', { clientId: player._id, cards })); + } + // Given a player, deal all the white cards to it. protected dealWhiteCards(player: GamePlayer): Promise { const cardsNeeded = 10 - player.cards.length; if (!cardsNeeded) { - return; + return this.emitCardsToPlayer(player); } - // for (let i = 0; i < cardsNeeded; i++) { - // player.cards.push(this.pickWhiteCard()); - // } while (player.cards?.length !== 10) { player.cards.push(this.pickWhiteCard()); } - // Get all the cards and deal them to the player. - return this.broker.call('cards.get', { id: player.cards }) - .then(cards => this.broker.emit('games.deal', { clientId: player._id, cards })); + return this.emitCardsToPlayer(player); } private async ensurePlayersHaveCards(players: { [id: string]: GamePlayer }) { diff --git a/services/rooms-service/src/rooms-service.ts b/services/rooms-service/src/rooms-service.ts index b73398e3..1099c50a 100644 --- a/services/rooms-service/src/rooms-service.ts +++ b/services/rooms-service/src/rooms-service.ts @@ -231,7 +231,7 @@ export default class RoomsService extends Service { */ private async afterAddPlayer(ctx: Context<{ clientId: string; roomId: string }>, res: Room) { const { clientId, roomId } = ctx.params; - const prop = ctx.action.name === 'join-players' ? 'player' : 'spectator'; + const prop = ctx.action.name === 'rooms.join-players' ? 'player' : 'spectator'; await ctx.emit(`${this.name}.${prop}.joined`, { clientId, roomId }); return ctx.call(`${this.name}.get`, { id: roomId, populate: ['players', 'spectators'] }); } diff --git a/skaffold.yaml b/skaffold.yaml index 80256e9d..b1788891 100644 --- a/skaffold.yaml +++ b/skaffold.yaml @@ -75,9 +75,6 @@ deploy: profiles: - name: gcb patches: - - op: replace - path: /deploy/kubectl/manifests/0 - value: services/nginx/k8s-svc.yaml - op: replace path: /build/artifacts/1/docker/dockerfile value: Dockerfile @@ -108,3 +105,19 @@ profiles: - config/managed-cert.yaml - config/load-balancer-backend-config.yaml - config/ingress.yaml + + - services/nginx/k8s-svc.yaml + - services/nginx/k8s-pod.yaml + - config/secret.yaml + - config/base-config.yaml + - services/admin-gateway-service/k8s-pod.yaml + - services/admin-gateway-service/k8s-svc.yaml + - services/web-gateway-service/k8s-pod.yaml + - services/web-gateway-service/k8s-svc.yaml + - services/websocket-gateway-service/k8s-pod.yaml + - services/websocket-gateway-service/k8s-svc.yaml + - services/cards-service/k8s-pod.yaml + - services/decks-service/k8s-pod.yaml + - services/clients-service/k8s-pod.yaml + - services/rooms-service/k8s-pod.yaml + - services/games-service/k8s-pod.yaml \ No newline at end of file