public async Task <IActionResult> Get(int gameID) { var game = await dbContext.Games .Include(g => g.Characters).AsNoTracking() .Include(g => g.Stages).AsNoTracking() .FirstOrDefaultAsync(g => g.ID == gameID); if (game == null) { return(CodeResultAndLog(HttpStatusCode.NotFound, $"Could not find Game with ID '{gameID}'.")); } var dto = GameDto.Create(game, cdnService); return(CodeResult(HttpStatusCode.OK, dto)); }
public async Task SelectRole(GameCommand <SelectRole> cmd) { var game = _inProgressGameStore.FindById(cmd.GameId); try { await _gameService.ExecuteSelectRole(game, GetUserId(), cmd.Action); } catch (Exception e) { await Clients.Caller.Error(new GameErrorEvent { ErrorMessage = e.Message }); } var changedEvent = new GameChangedEvent { Game = GameDto.Create(game) }; await Clients.Group(cmd.GameId).GameChanged(changedEvent); await BroadcastAvailableActionTypes(game); }
public override async Task OnConnectedAsync() { if (Context.GetHttpContext().Request.Query.TryGetValue("gameId", out var gameId)) { var game = _inProgressGameStore.FindById(gameId); await Groups.AddToGroupAsync(Context.ConnectionId, gameId); var changedEvent = new GameChangedEvent { Game = GameDto.Create(game) }; await Clients.Caller.GameChanged(changedEvent); await SendAvailableActionTypes(game, GetUserId()); } else { await Clients.Caller.Error(new GameErrorEvent { ErrorMessage = "Not found gameId query param" }); } }
private async Task ExecuteRoleAction(string gameId, IAction build) { var game = _inProgressGameStore.FindById(gameId); try { await _gameService.ExecuteRoleAction(game, GetUserId(), build); } catch (Exception e) { await Clients.Caller.Error(new GameErrorEvent { ErrorMessage = e.Message }); } await Clients.Groups(gameId).GameChanged(new GameChangedEvent { Game = GameDto.Create(game) }); await BroadcastAvailableActionTypes(game); if (game.Status == GameStatus.ENDED) { await AfterGameEnded(game); } }