Ejemplo n.º 1
0
#pragma warning restore 4014

        private async Task <QosResult> GetResultAsync(int timeoutMs)
        {
            var result = new QosResult();

            if (!PlayFabSettings.staticPlayer.IsClientLoggedIn())
            {
                result.ErrorCode    = (int)QosErrorCode.NotLoggedIn;
                result.ErrorMessage = "Client is not logged in";
                return(result);
            }

            // get datacenter map (call thunderhead)
            await InitializeQoSServerList();

            int serverCount = _dataCenterMap.Count;

            if (serverCount <= 0)
            {
                result.ErrorCode    = (int)QosErrorCode.FailedToRetrieveServerList;
                result.ErrorMessage = "Failed to get server list from PlayFab multiplayer servers";
                return(result);
            }

            // ping servers
            result.RegionResults = await GetSortedRegionLatencies(timeoutMs);

            result.ErrorCode = (int)QosErrorCode.Success;
            return(result);
        }
Ejemplo n.º 2
0
        public async Task<QosResult> GetQosResultAsync(int timeoutMs = DefaultTimeoutMs)
        {
            QosResult result = await GetResultAsync(timeoutMs);
            if (result.ErrorCode != (int)QosErrorCode.Success)
            {
                return result;
            }

            Task.Factory.StartNew(() => SendResultsToPlayFab(result));
            return result;
        }
Ejemplo n.º 3
0
#pragma warning disable 4014
        public async Task <QosResult> GetQosResultAsync(int timeoutMs = DefaultTimeoutMs)
        {
            await new PlayFabUtil.SynchronizationContextRemover();

            QosResult result = await GetResultAsync(timeoutMs);

            if (result.ErrorCode != (int)QosErrorCode.Success)
            {
                return(result);
            }

            Task.Factory.StartNew(() => SendResultsToPlayFab(result));
            return(result);
        }
Ejemplo n.º 4
0
        public static QosResultFacade CreateFrom(QosResult result)
        {
            var regionResults = new List <QosRegionResultFacade>(result.RegionResults.Count);

            foreach (QosRegionResult regionResult in result.RegionResults)
            {
                regionResults.Add(QosRegionResultFacade.CreateFrom(regionResult));
            }

            return(new QosResultFacade
            {
                RegionResults = regionResults,
                ErrorCode = result.ErrorCode
            });
        }
Ejemplo n.º 5
0
        private async Task SendResultsToPlayFab(QosResult result)
        {
            var eventContents = new EventContents
            {
                Name = "qos_result",
                EventNamespace = "playfab.servers",
                Payload = QosResultFacade.CreateFrom(result)
            };

            var writeEventsRequest = new WriteEventsRequest
            {
                Events = new List<EventContents> {eventContents}
            };

            await WriteTelemetryAsync(writeEventsRequest);
        }
Ejemplo n.º 6
0
        public static QosResultPlayFabEvent CreateFrom(QosResult result)
        {
#if (NETSTANDARD && !NETSTANDARD1_1) || NETFRAMEWORK || NETCOREAPP
            return(new QosResultPlayFabEvent
            {
                RegionResults = result.RegionResults.ConvertAll(x => new QosRegionResultSummary()
                {
                    Region = x.Region,
                    ErrorCode = x.ErrorCode,
                    LatencyMs = x.LatencyMs
                }),
                ErrorCode = result.ErrorCode
            });
#else
            throw new NotSupportedException("QoS ping library is only supported on .net standard 2.0 and newer, .net core or full .net framework");
#endif
        }
Ejemplo n.º 7
0
#pragma warning disable 4014
        public async Task <QosResult> GetQosResultAsync(
            int timeoutMs           = DefaultTimeoutMs,
            int pingsPerRegion      = DefaultPingsPerRegion,
            int degreeOfParallelism = DefaultDegreeOfParallelism)
        {
            await new PlayFabUtil.SynchronizationContextRemover();

            QosResult result = await GetResultAsync(timeoutMs, pingsPerRegion, degreeOfParallelism);

            if (result.ErrorCode != (int)QosErrorCode.Success)
            {
                return(result);
            }

            if (_reportResults)
            {
                Task.Factory.StartNew(qosResultsReporter, result).Unwrap();
            }

            return(result);
        }