Пример #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,
            }));
        }
Пример #2
0
        public async Task <IActionResult> JoinLobby([FromBody] JoinLobbyRequest request)
        {
            Guid lobbyId = _registry.JoinLobby(request.HostId, request.JoineeId);

            ServerSidePlayer joinee = _registry.GetPlayerById(request.JoineeId);

            List <ServerSidePlayer> members = _registry.GetLobbyMembers(request.HostId);

            await _hubContext.Clients.Group(lobbyId.ToString()).NewPlayerInLobby(new ServerSidePlayerOverview {
                Id        = joinee.Id,
                AvatarUrl = joinee.AvatarUrl,
                Name      = joinee.Name,
            });

            return(base.Ok(new JoinLobbyResponse {
                LobbyId = lobbyId,
                Members = GetOverviewFromPlayer(members)
            }));
        }