Skip to content

Commit

Permalink
Fixed an issue that prevented activation of the external sync start g…
Browse files Browse the repository at this point in the history
…uard.
  • Loading branch information
sei-bstein committed Nov 22, 2023
1 parent 3ff3d02 commit 40e40be
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions projects/gameboard-ui/src/app/api/player-models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ export interface TeamMember {
id: string;
approvedName: string;
role: PlayerRole;
userId: string;
}

export interface TeamPlayer {
Expand Down
18 changes: 12 additions & 6 deletions projects/gameboard-ui/src/app/guards/external-sync-game.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import { GameService } from '@/api/game.service';
import { PlayerService } from '@/api/player.service';
import { LogService } from '@/services/log.service';
import { Injectable } from '@angular/core';
import { UserService as LocalUserService } from '@/utility/user.service';
import { ActivatedRouteSnapshot, CanActivate, CanActivateChild, RouterStateSnapshot, UrlTree } from '@angular/router';
import { Observable, firstValueFrom } from 'rxjs';

@Injectable({ providedIn: 'root' })
export class ExternalSyncGameGuard implements CanActivate, CanActivateChild {
constructor(
private gameService: GameService,
private localUserService: LocalUserService,
private logService: LogService,
private playerService: PlayerService) { }

Expand All @@ -26,10 +28,11 @@ export class ExternalSyncGameGuard implements CanActivate, CanActivateChild {

private async _canActivate(route: ActivatedRouteSnapshot) {
const gameId = route.paramMap.get('gameId') || '';
const playerId = route.paramMap.get('playerId') || "";
const teamId = route.paramMap.get('teamId') || "";
const userId = this.localUserService.user$.value?.id;

if (!gameId || !playerId) {
this.logService.logWarning("Can't activate ExternalSyncGameGuard for gameId + playerId", gameId, playerId);
if (!gameId || !teamId || !userId) {
this.logService.logWarning("Can't activate ExternalSyncGameGuard for gameId, teamId, userId", gameId, teamId, userId);
return false;
}

Expand All @@ -38,9 +41,12 @@ export class ExternalSyncGameGuard implements CanActivate, CanActivateChild {
if (!game.requireSynchronizedStart || game.mode !== GameEngineMode.External)
return false;

const player = await firstValueFrom(this.playerService.retrieve(playerId));
const playState = await firstValueFrom(this.gameService.getGamePlayState(gameId, player.teamId));
const team = await firstValueFrom(this.playerService.getTeam(teamId));
if (!team.members.some(m => m.userId == userId)) {
return false;
}

return (playState == GamePlayState.Started);
const playState = await firstValueFrom(this.gameService.getGamePlayState(gameId, teamId));
return playState == GamePlayState.Started;
}
}

0 comments on commit 40e40be

Please sign in to comment.