public async Task GetGameConnection()

in Runtime/Core/ApiGatewayManagement/AnywhereGameServerAdapter.cs [30:77]


        public async Task<GetGameConnectionResponse> GetGameConnection(GetGameConnectionRequest request)
        {
            try
            {
                var describeGameSessionsResponse = await _amazonGameLiftWrapper.DescribeGameSessions(new DescribeGameSessionsRequest
                {
                    FleetId = _fleetId,
                    StatusFilter = GameSessionStatus.ACTIVE
                });
                
                if (describeGameSessionsResponse.GameSessions.Any())
                {
                    var oldestGameSession = describeGameSessionsResponse.GameSessions.First();
                    var createPlayerSessionResponse = await _amazonGameLiftWrapper.CreatePlayerSession(new CreatePlayerSessionRequest
                    {
                        GameSessionId = oldestGameSession.GameSessionId,
                        PlayerId = _playerIdPrefix + Guid.NewGuid().ToString()
                    });
                    var playerSession = createPlayerSessionResponse.PlayerSession;

                    var response = new GetGameConnectionResponse
                    {
                        IpAddress = playerSession.IpAddress,
                        DnsName = playerSession.DnsName,
                        Port = playerSession.Port.ToString(),
                        PlayerSessionId = playerSession.PlayerSessionId,
                        Ready = true
                    };

                    return Response.Ok(response);
                }

                return Response.Fail(new GetGameConnectionResponse
                {
                    ErrorCode = ErrorCode.NoGameSessionWasFound
                });
            }
            catch (Exception ex)
            {
                Logger.LogError(ex, ex.Message);

                return Response.Fail(new GetGameConnectionResponse
                {
                    ErrorCode = ErrorCode.UnknownError,
                    ErrorMessage = ex.Message
                });
            }
        }