Ejemplo n.º 1
0
        private async Task <IActionResult> GetJoinLobbyResponse(Boolean result, Guid playerId, Boolean sendMessageIntoLobby)
        {
            if (result == false)
            {
                return(BadRequest());
            }


            PlayerServerSide player  = playerRegistry.GetPlayerById(playerId);
            Guid             lobbyId = playerRegistry.GetLobbyIdByPlayerId(playerId);

            if (sendMessageIntoLobby == true)
            {
                await lobbyHubContext.Clients.Group(lobbyId.ToString()).PlayerJoinedLobby(GetPlayerOverview(player));
            }

            List <ServerSidePlayerOverview> playerInLobby = new();

            foreach (var item in player.Lobby.Players)
            {
                playerInLobby.Add(GetPlayerOverview(item));
            }

            return(base.Ok(new JoinLobbyResponse
            {
                LobbyId = lobbyId,
                PlayersInLobby = playerInLobby,
            }));
        }
Ejemplo n.º 2
0
 private static ServerSidePlayerOverview GetPlayerOverview(PlayerServerSide player)
 {
     return(new ServerSidePlayerOverview
     {
         AvatarUrl = player.AvatarUrl,
         Id = player.Id,
         Name = player.Name,
     });
 }
Ejemplo n.º 3
0
        public async Task <IActionResult> AddPlayer([FromBody] CreatePlayerRequest request)
        {
            PlayerServerSide player = new PlayerServerSide(request.Name, request.AvatarUrl, request.Id);

            playerRegistry.AddPlayer(request.Id, player);

            await lobbyHubContext.Clients.All.NewPlayer(new ServerSidePlayerOverview
            {
                AvatarUrl = request.AvatarUrl,
                Id        = request.Id,
                Name      = request.Name,
            });

            Guid lobbyId = playerRegistry.GetLobbyIdByPlayerId(request.Id);

            return(base.Ok(new AddPlayerResponse {
                LobbyId = lobbyId
            }));
        }