public ResolveServiceEndpointResponse(ResolvedEndpoint endpoint)
        {
            if (endpoint == null)
            {
                throw new ArgumentNullException(nameof(endpoint));
            }

            //We allow null on the endpoint but not if they pass this DTO one
            Endpoint = endpoint;

            //We can assume success since they provided an endpoint
            ResultCode = ResolveServiceEndpointResponseCode.Success;
        }
Exemplo n.º 2
0
        //TODO: Expand this with more information if needed by clients.

        /// <inheritdoc />
        public GameServerEntry(ResolvedEndpoint serverAddress, GameServerStatusFlags flags, string serverMoniker)
        {
            if (serverAddress == null)
            {
                throw new ArgumentNullException(nameof(serverAddress));
            }
            if (string.IsNullOrWhiteSpace(serverMoniker))
            {
                throw new ArgumentException("Value cannot be null or whitespace.", nameof(serverMoniker));
            }

            ServerAddress = serverAddress;
            Flags         = flags;
            ServerMoniker = serverMoniker;
        }
        public async Task <ResolveServiceEndpointResponse> Discover([FromBody] ResolveServiceEndpointRequest requestModel)
        {
            if (LoggingService.IsEnabled(LogLevel.Debug))
            {
                LoggingService.LogDebug($"Service Discover request for: {requestModel.Region}:{requestModel.ServiceType}");
            }

            if (!ModelState.IsValid)
            {
                if (LoggingService.IsEnabled(LogLevel.Debug))
                {
                    LoggingService.LogDebug($"Resolution request was sent with an invalid model ModelState.");
                }

                return(new ResolveServiceEndpointResponse(ResolveServiceEndpointResponseCode.GeneralRequestError));
            }

            //We need to check if we know about the locale
            //If we don't we should indicate it is unlisted
            //We also need to check if the keypair region and servicetype exist
            if (!await EndpointRepository.HasEntryAsync(requestModel.Region, requestModel.ServiceType))
            {
                if (LoggingService.IsEnabled(LogLevel.Debug))
                {
                    LoggingService.LogDebug($"Client requested unlisted service Region: {requestModel.Region} Service: {requestModel.ServiceType}.");
                }

                return(new ResolveServiceEndpointResponse(ResolveServiceEndpointResponseCode.ServiceUnlisted));
            }

            ResolvedEndpoint endpoint = await EndpointRepository.RetrieveAsync(requestModel.Region, requestModel.ServiceType);

            if (endpoint == null)
            {
                //Log the error. It shouldn't be null if the checks passed
                if (LoggingService.IsEnabled(LogLevel.Error))
                {
                    LoggingService.LogError($"Resolution request {requestModel.ServiceType} for region {requestModel.Region} failed even through it was a known pair.");
                }

                return(new ResolveServiceEndpointResponse(ResolveServiceEndpointResponseCode.GeneralRequestError));
            }

            //Just return the JSON model response to the client
            return(new ResolveServiceEndpointResponse(endpoint));
        }
        //TODO: We might want to provide details about the type of instance.

        /// <inheritdoc />
        public ZoneServerRegisterationRequest([NotNull] ResolvedEndpoint zoneServerEndpoint)
        {
            ZoneServerEndpoint = zoneServerEndpoint ?? throw new ArgumentNullException(nameof(zoneServerEndpoint));
        }