Ejemplo n.º 1
0
        public static ServerSeasonPass GetSeasonPass()
        {
            AccelByteServerPlugin.CheckPlugin();

            return(AccelByteServerPlugin.seasonPass ?? (AccelByteServerPlugin.seasonPass = new ServerSeasonPass(
                                                            new ServerSeasonPassApi(
                                                                AccelByteServerPlugin.config.BaseUrl,
                                                                AccelByteServerPlugin.httpClient),
                                                            AccelByteServerPlugin.session,
                                                            AccelByteServerPlugin.config.Namespace,
                                                            AccelByteServerPlugin.coroutineRunner)));
        }
Ejemplo n.º 2
0
        public static ServerMatchmaking GetMatchmaking()
        {
            AccelByteServerPlugin.CheckPlugin();

            return(AccelByteServerPlugin.matchmaking ?? (AccelByteServerPlugin.matchmaking = new ServerMatchmaking(
                                                             new ServerMatchmakingApi(
                                                                 AccelByteServerPlugin.config.MatchmakingServerUrl,
                                                                 AccelByteServerPlugin.httpClient),
                                                             AccelByteServerPlugin.session,
                                                             AccelByteServerPlugin.config.Namespace,
                                                             AccelByteServerPlugin.coroutineRunner)));
        }
Ejemplo n.º 3
0
        public static ServerUserAccount GetUserAccount()
        {
            AccelByteServerPlugin.CheckPlugin();

            return(AccelByteServerPlugin.userAccount ?? (AccelByteServerPlugin.userAccount = new ServerUserAccount(
                                                             new ServerUserAccountApi(
                                                                 AccelByteServerPlugin.config.BaseUrl,
                                                                 AccelByteServerPlugin.httpClient),
                                                             AccelByteServerPlugin.session,
                                                             AccelByteServerPlugin.config.Namespace,
                                                             AccelByteServerPlugin.coroutineRunner)));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Check whether if this static class is need to be refreshed/re-init
        /// </summary>
        private static void CheckPlugin()
        {
#if UNITY_EDITOR
            if (AccelByteServerPlugin.hasBeenInitialized)
            {
                return;
            }

            AccelByteServerPlugin.hasBeenInitialized = true;
            AccelByteServerPlugin.Init();
#endif
        }
Ejemplo n.º 5
0
        public static ServerQos GetQos()
        {
            if (AccelByteServerPlugin.qos != null)
            {
                return(AccelByteServerPlugin.qos);
            }

            AccelByteServerPlugin.CheckPlugin();
            AccelByteServerPlugin.qos = new ServerQos(
                new ServerQosManagerApi(
                    AccelByteServerPlugin.config.QosManagerServerUrl,
                    AccelByteServerPlugin.httpClient),
                AccelByteServerPlugin.coroutineRunner);

            return(AccelByteServerPlugin.qos);
        }
Ejemplo n.º 6
0
        public static ServerGameTelemetry GetGameTelemetry()
        {
            if (AccelByteServerPlugin.gameTelemetry != null)
            {
                return(AccelByteServerPlugin.gameTelemetry);
            }

            AccelByteServerPlugin.CheckPlugin();
            AccelByteServerPlugin.gameTelemetry = new ServerGameTelemetry(
                new ServerGameTelemetryApi(
                    AccelByteServerPlugin.config.GameTelemetryServerUrl,
                    AccelByteServerPlugin.httpClient),
                AccelByteServerPlugin.session,
                AccelByteServerPlugin.coroutineRunner);

            return(AccelByteServerPlugin.gameTelemetry);
        }
Ejemplo n.º 7
0
        public static ServerCloudSave GetCloudSave()
        {
            if (AccelByteServerPlugin.cloudSave != null)
            {
                return(AccelByteServerPlugin.cloudSave);
            }

            AccelByteServerPlugin.CheckPlugin();
            AccelByteServerPlugin.cloudSave = new ServerCloudSave(
                new ServerCloudSaveApi(
                    AccelByteServerPlugin.config.CloudSaveServerUrl,
                    AccelByteServerPlugin.httpClient),
                AccelByteServerPlugin.session,
                AccelByteServerPlugin.config.Namespace,
                AccelByteServerPlugin.coroutineRunner);

            return(AccelByteServerPlugin.cloudSave);
        }
Ejemplo n.º 8
0
        public static ServerLobby GetLobby()
        {
            if (AccelByteServerPlugin.lobby != null)
            {
                return(AccelByteServerPlugin.lobby);
            }

            AccelByteServerPlugin.CheckPlugin();
            AccelByteServerPlugin.lobby = new ServerLobby(
                new ServerLobbyApi(
                    AccelByteServerPlugin.config.LobbyServerUrl,
                    AccelByteServerPlugin.httpClient),
                AccelByteServerPlugin.session,
                AccelByteServerPlugin.config.Namespace,
                AccelByteServerPlugin.coroutineRunner);

            return(AccelByteServerPlugin.lobby);
        }
Ejemplo n.º 9
0
        public static ServerAchievement GetAchievement()
        {
            if (AccelByteServerPlugin.achievement != null)
            {
                return(AccelByteServerPlugin.achievement);
            }

            AccelByteServerPlugin.CheckPlugin();
            AccelByteServerPlugin.achievement = new ServerAchievement(
                new ServerAchievementApi(
                    AccelByteServerPlugin.config.AchievementServerUrl,
                    AccelByteServerPlugin.httpClient),
                AccelByteServerPlugin.session,
                AccelByteServerPlugin.config.Namespace,
                AccelByteServerPlugin.coroutineRunner);

            return(AccelByteServerPlugin.achievement);
        }
Ejemplo n.º 10
0
        public static ServerStatistic GetStatistic()
        {
            if (AccelByteServerPlugin.statistic != null)
            {
                return(AccelByteServerPlugin.statistic);
            }

            AccelByteServerPlugin.CheckPlugin();
            AccelByteServerPlugin.statistic = new ServerStatistic(
                new ServerStatisticApi(
                    AccelByteServerPlugin.config.StatisticServerUrl,
                    AccelByteServerPlugin.httpClient),
                AccelByteServerPlugin.session,
                AccelByteServerPlugin.config.Namespace,
                AccelByteServerPlugin.coroutineRunner);

            return(AccelByteServerPlugin.statistic);
        }
Ejemplo n.º 11
0
        public static ServerEcommerce GetEcommerce()
        {
            if (AccelByteServerPlugin.ecommerce != null)
            {
                return(AccelByteServerPlugin.ecommerce);
            }

            AccelByteServerPlugin.CheckPlugin();
            AccelByteServerPlugin.ecommerce = new ServerEcommerce(
                new ServerEcommerceApi(
                    AccelByteServerPlugin.config.PlatformServerUrl,
                    AccelByteServerPlugin.httpClient),
                AccelByteServerPlugin.session,
                AccelByteServerPlugin.config.Namespace,
                AccelByteServerPlugin.coroutineRunner);

            return(AccelByteServerPlugin.ecommerce);
        }
Ejemplo n.º 12
0
        public static DedicatedServerManager GetDedicatedServerManager()
        {
            if (AccelByteServerPlugin.dedicatedServerManager != null)
            {
                return(AccelByteServerPlugin.dedicatedServerManager);
            }

            AccelByteServerPlugin.CheckPlugin();
            AccelByteServerPlugin.dedicatedServerManager = new DedicatedServerManager(
                new DedicatedServerManagerApi(
                    AccelByteServerPlugin.config.DSMControllerServerUrl,
                    AccelByteServerPlugin.config.Namespace,
                    AccelByteServerPlugin.httpClient),
                AccelByteServerPlugin.session,
                AccelByteServerPlugin.coroutineRunner);

            return(AccelByteServerPlugin.dedicatedServerManager);
        }
Ejemplo n.º 13
0
 public static DedicatedServer GetDedicatedServer()
 {
     AccelByteServerPlugin.CheckPlugin();
     return(AccelByteServerPlugin.server);
 }
Ejemplo n.º 14
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());
            }
        }