public static ServerQos GetQos()
        {
            if (AccelByteServerPlugin.qos == null)
            {
                CheckPlugin();
                AccelByteServerPlugin.qos = new ServerQos(
                    new ServerQosManagerApi(
                        AccelByteServerPlugin.config.QosManagerServerUrl,
                        AccelByteServerPlugin.httpWorker),
                    AccelByteServerPlugin.coroutineRunner);
            }

            return(AccelByteServerPlugin.qos);
        }
        static AccelByteServerPlugin()
        {
#if UNITY_EDITOR // Handle an unexpected behaviour if Domain Reload (experimental) is disabled
            EditorApplication.playModeStateChanged += state =>
            {
                if (state == PlayModeStateChange.ExitingEditMode)
                {
                    hasBeenInitialized = false;

                    accessToken            = null;
                    server                 = null;
                    dedicatedServerManager = null;
                    ecommerce              = null;
                    statistic              = null;
                    qos           = null;
                    gameTelemetry = null;
                    achievement   = null;
                    lobby         = null;
                    cloudSave     = null;
                }
            };
        }
Пример #3
0
        static AccelByteServerPlugin()
        {
#if UNITY_EDITOR // Handle an unexpected behaviour if Domain Reload (experimental) is disabled
            EditorApplication.playModeStateChanged += state =>
            {
                if (state != PlayModeStateChange.ExitingEditMode)
                {
                    return;
                }

                AccelByteServerPlugin.hasBeenInitialized     = false;
                AccelByteServerPlugin.accessToken            = null;
                AccelByteServerPlugin.server                 = null;
                AccelByteServerPlugin.dedicatedServerManager = null;
                AccelByteServerPlugin.ecommerce              = null;
                AccelByteServerPlugin.statistic              = null;
                AccelByteServerPlugin.qos           = null;
                AccelByteServerPlugin.gameTelemetry = null;
                AccelByteServerPlugin.achievement   = null;
                AccelByteServerPlugin.lobby         = null;
                AccelByteServerPlugin.cloudSave     = null;
                AccelByteServerPlugin.seasonPass    = null;
            };
        }
Пример #4
0
        public IEnumerator RegisterServer(RegisterServerRequest registerRequest, string accessToken,
                                          ResultCallback callback)
        {
            Assert.IsNotNull(registerRequest, "Register failed. registerserverRequest is null!");
            Assert.IsNotNull(accessToken, "Can't update a slot! accessToken parameter is null!");
            if (this.serverType != ServerType.NONE)
            {
                callback.TryError(ErrorCode.Conflict, "Server is already registered.");

                yield break;
            }
            if (dsmServerUrl.Length == 0)
            {
                ServerQos qos = AccelByteServerPlugin.GetQos();
                Result <Dictionary <string, int> > latenciesResult = null;
                qos.GetServerLatencies(reqResult => latenciesResult = reqResult);
                yield return(new WaitUntil(() => latenciesResult != null));

                foreach (KeyValuePair <string, int> latency in latenciesResult.Value.OrderBy(item => item.Value))
                {
                    var getUrlRequest = HttpRequestBuilder.CreateGet(this.baseUrl + "/public/dsm?region=" + latency.Key)
                                        .WithBearerAuth(accessToken)
                                        .WithContentType(MediaType.ApplicationJson)
                                        .Accepts(MediaType.ApplicationJson)
                                        .GetResult();

                    IHttpResponse getUrlResponse = null;

                    yield return(this.httpWorker.SendRequest(getUrlRequest, rsp => getUrlResponse = rsp));

                    var getUrlResult = getUrlResponse.TryParseJson <DSMClient>();
                    if (getUrlResult.Value.status == "HEALTHY")
                    {
                        dsmServerUrl = getUrlResult.Value.host_address;
                        break;
                    }
                }
            }
            if (serverSetup.ip.Length == 0)
            {
                var getPubIpRequest = HttpRequestBuilder.CreateGet("https://api.ipify.org?format=json")
                                      .WithContentType(MediaType.ApplicationJson)
                                      .Accepts(MediaType.ApplicationJson)
                                      .GetResult();

                IHttpResponse getPubIpResponse = null;

                yield return(this.httpWorker.SendRequest(getPubIpRequest, rsp => getPubIpResponse = rsp));

                var getPubIpResult = getPubIpResponse.TryParseJson <PubIp>();
                serverSetup.ip = getPubIpResult.Value.ip;
            }

            if (IsCurrentProvider(Provider.AGONES))
            {
#if ENABLE_AGONES_PLUGIN
                InitiateAgones(callback);
#else
                callback.TryError(ErrorCode.NotFound,
                                  "Can't request register server. Agones provider arguments is passed but Agones plugin is not found.");
#endif
            }
            else
            {
                registerRequest.ip           = serverSetup.ip;
                registerRequest.provider     = serverSetup.provider;
                registerRequest.game_version = serverSetup.game_version;

                var request = HttpRequestBuilder.CreatePost(this.dsmServerUrl + "/dsm/namespaces/{namespace}/servers/register")
                              .WithPathParam("namespace", this.namespace_)
                              .WithBearerAuth(accessToken)
                              .WithContentType(MediaType.ApplicationJson)
                              .Accepts(MediaType.ApplicationJson)
                              .WithBody(registerRequest.ToUtf8Json())
                              .GetResult();

                IHttpResponse response = null;

                yield return(this.httpWorker.SendRequest(request, rsp => response = rsp));

                var result = response.TryParseJson <ServerInfo>();
                if (!result.IsError)
                {
                    serverSetup.pod_name = result.Value.pod_name;
                    serverType           = ServerType.CLOUDSERVER;
                }
                callback.Try(response.TryParse());
            }
        }