Beispiel #1
0
        /// <summary>
        /// Check if user has purchased the subscription and eligible to play
        /// </summary>
        /// <param name="callback"> Returns the boolean result whether the user is subscribed and eligible to play the game via callback when the operation is completed</param>
        public void GetUserEligibleToPlay(ResultCallback <bool> callback)
        {
            Report.GetFunctionLog(this.GetType().Name);

            ResultCallback <ItemInfo> onGotItemInfo = (itemInfoResult) =>
            {
                if (itemInfoResult.IsError)
                {
                    callback.TryError(itemInfoResult.Error.Code);
                    return;
                }

                string[] skus   = itemInfoResult.Value.features;
                string[] appIds = { AccelBytePlugin.Config.AppId };

                AccelBytePlugin.GetEntitlement().GetUserEntitlementOwnershipAny(null, appIds, skus, (ownershipResult) =>
                {
                    if (ownershipResult.IsError)
                    {
                        callback.TryError(ownershipResult.Error.Code);
                        return;
                    }

                    callback.TryOk(ownershipResult.Value.owned);
                });
            };

            AccelBytePlugin.GetItems().GetItemByAppId(AccelBytePlugin.Config.AppId, onGotItemInfo);
        }
Beispiel #2
0
        private void ReplaceUserRecordRecursive(int remainingAttempt, string key, Dictionary <string, object> recordRequest, ResultCallback callback, Func <Dictionary <string, object>, Dictionary <string, object> > payloadModifier)
        {
            if (remainingAttempt <= 0)
            {
                callback.TryError(new Error(ErrorCode.PreconditionFailed, "Exhaust all retry attempt to modify game record. Please try again."));
                return;
            }

            GetUserRecord(key, getUserRecordResult =>
            {
                var updateRequest = new ConcurrentReplaceRequest();
                if (getUserRecordResult.IsError)
                {
                    if (getUserRecordResult.Error.Code == ErrorCode.PlayerRecordNotFound)
                    {
                        updateRequest.value     = recordRequest;
                        updateRequest.updatedAt = DateTime.Now;

                        this.coroutineRunner.Run(
                            this.api.ReplaceUserRecord(
                                this.@namespace,
                                this.session.UserId,
                                this.session.AuthorizationToken,
                                key,
                                updateRequest,
                                callback,
                                () =>
                        {
                            ReplaceUserRecordRecursive(remainingAttempt - 1, key, recordRequest, callback, payloadModifier);
                        }));
                    }
                    else
                    {
                        callback.TryError(getUserRecordResult.Error);
                    }
                }
                else
                {
                    getUserRecordResult.Value.value = payloadModifier(getUserRecordResult.Value.value);

                    updateRequest.value     = getUserRecordResult.Value.value;
                    updateRequest.updatedAt = getUserRecordResult.Value.updated_at;

                    this.coroutineRunner.Run(
                        this.api.ReplaceUserRecord(
                            this.@namespace,
                            this.session.UserId,
                            this.session.AuthorizationToken,
                            key,
                            updateRequest,
                            callback,
                            () =>
                    {
                        ReplaceUserRecordRecursive(remainingAttempt - 1, key, recordRequest, callback, payloadModifier);
                    }));
                }
            });
        }
Beispiel #3
0
        public IEnumerator GetSessionId(string accessToken, ResultCallback <ServerSessionResponse> callback)
        {
            Assert.IsNotNull(accessToken, "Can't check session ID! accessToken parameter is null!");

            if (this.serverType == ServerType.NONE)
            {
                callback.TryError(new Error(ErrorCode.NotFound, "Server not registered yet"));
                yield break;
            }

            var request = HttpRequestBuilder.CreateGet(this.baseUrl + "/namespaces/{namespace}/servers/{server}/session")
                          .WithPathParam("namespace", this.namespace_)
                          .WithPathParam("server", serverSetup.pod_name)
                          .WithBearerAuth(accessToken)
                          .WithContentType(MediaType.ApplicationJson)
                          .Accepts(MediaType.ApplicationJson)
                          .GetResult();

            IHttpResponse response = null;

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

            var result = response.TryParseJson <ServerSessionResponse>();

            callback.Try(result);
        }
Beispiel #4
0
        public IEnumerator RegisterLocalServer(RegisterLocalServerRequest registerRequest, string accessToken,
                                               ResultCallback callback)
        {
            Assert.IsNotNull(registerRequest, "Register failed. registerRequest 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;
            }

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

            IHttpResponse response = null;

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

            var result = response.TryParse();

            if (!result.IsError)
            {
                serverType           = ServerType.LOCALSERVER;
                serverSetup.pod_name = registerRequest.name;
            }

            callback.Try(result);
        }
Beispiel #5
0
        /// <summary>
        /// Ban a Single User.
        /// Only Moderator that can ban other user.
        /// </summary>
        /// <param name="userId">Ban user's user ID</param>
        /// <param name="banType">The type of Ban</param>
        /// <param name="reason">The reason of Banning</param>
        /// <param name="endDate">The date when the ban is lifted</param>
        /// <param name="comment">The detail or comment about the banning</param>
        /// <param name="notifyUser">Notify user via email or not</param>
        /// <param name="callback">Returns a result via callback when completed</param>
        public void BanUser(string userId, BanType banType, BanReason reason, DateTime endDate, string comment, bool notifyUser,
                            ResultCallback <UserBanResponseV3> callback)
        {
            Report.GetFunctionLog(this.GetType().Name);

            if (!this.loginSession.IsValid())
            {
                callback.TryError(ErrorCode.IsNotLoggedIn);

                return;
            }

            var banRequest = new BanCreateRequest
            {
                ban       = banType.ToString(),
                comment   = comment,
                endDate   = endDate.ToString("o"),
                reason    = reason.ToString(),
                skipNotif = !notifyUser
            };

            this.coroutineRunner.Run(
                this.userAccount.BanUser(
                    AccelBytePlugin.Config.Namespace,
                    this.loginSession.AuthorizationToken,
                    userId,
                    banRequest,
                    callback));
        }
Beispiel #6
0
        public IEnumerator ShutdownServer(ShutdownServerRequest shutdownServerRequest, string accessToken,
                                          ResultCallback callback)
        {
            Assert.IsNotNull(shutdownServerRequest, "Register failed. shutdownServerNotif is null!");
            Assert.IsNotNull(accessToken, "Can't update a slot! accessToken parameter is null!");
            if (this.serverType != ServerType.CLOUDSERVER)
            {
                callback.TryError(ErrorCode.Conflict, "Server not registered as Cloud Server.");

                yield break;
            }

            shutdownServerRequest.pod_name = serverSetup.pod_name;
            var request = HttpRequestBuilder.CreatePost(this.baseUrl + "/namespaces/{namespace}/servers/shutdown")
                          .WithPathParam("namespace", this.namespace_)
                          .WithBearerAuth(accessToken)
                          .WithContentType(MediaType.ApplicationJson)
                          .Accepts(MediaType.ApplicationJson)
                          .WithBody(shutdownServerRequest.ToUtf8Json())
                          .GetResult();

            IHttpResponse response = null;

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

            var result = response.TryParse();

            serverType = ServerType.NONE;
            callback.Try(result);
        }
        /// <summary>
        /// Register server to DSM and mark this machine as ready
        /// </summary>
        /// <param name="podName">Should be taken from "POD_NAME" environment variable</param>
        /// <param name="port">Exposed port number to connect to</param>
        /// <param name="callback">Returns a Result via callback when completed</param>
        public void RegisterServer(string podName, int portNumber, ResultCallback callback)
        {
            Report.GetFunctionLog(this.GetType().Name);

            Assert.IsNotNull(podName, "Can't Register server; podName is null!");

            if (!this.serverSession.IsValid())
            {
                Debug.Log("Server RegisterServer session is not valid");
                callback.TryError(ErrorCode.IsNotLoggedIn);

                return;
            }

            this.name = podName;
            var request = new RegisterServerRequest {
                pod_name = this.name, port = portNumber
            };

            this.coroutineRunner.Run(this.api.RegisterServer(request, this.serverSession.AuthorizationToken, callback));

            if (this.isHeartBeatAutomatic)
            {
                this.heartBeatCoroutine = this.coroutineRunner.Run(RunPeriodicHeartBeat());
            }
        }
Beispiel #8
0
        public IEnumerator Update(UpdateUserRequest updateUserRequest, ResultCallback <UserData> callback)
        {
            Report.GetFunctionLog(this.GetType().Name);
            Assert.IsNotNull(updateUserRequest, "Update failed. updateUserRequest is null!");
            if (!string.IsNullOrEmpty(updateUserRequest.emailAddress))
            {
                Error error = new Error(ErrorCode.BadRequest, "Cannot update user email using this function. Use UpdateEmail instead.");
                callback.TryError(error);
            }

            var request = HttpRequestBuilder.CreatePatch(this.baseUrl + "/v4/public/namespaces/{namespace}/users/me")
                          .WithPathParam("namespace", this.@namespace)
                          .WithBearerAuth(this.session.AuthorizationToken)
                          .WithContentType(MediaType.ApplicationJson)
                          .WithBody(updateUserRequest.ToUtf8Json())
                          .Accepts(MediaType.ApplicationJson)
                          .GetResult();

            IHttpResponse response = null;

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

            var result = response.TryParseJson <UserData>();

            callback.Try(result);
        }
        /// <summary>
        /// Redeem Campaign Code to Receive In Game Item.
        /// </summary>
        /// <param name="code">The campaign code to redeem.</param>
        /// <param name="region">Region of the item. If not set, the region from the access token will be used.</param>
        /// <param name="language">Display language.null If not set, the language from the access token will be used.</param>
        /// <param name="callback">Returns a Result that contains EntitlementInfo via callback when completed</param>
        public void RedeemCode(string code, string region, string language, ResultCallback <FulfillmentResult> callback)
        {
            Report.GetFunctionLog(this.GetType().Name);
            Assert.IsNotNull(code, "Can't redeem code! code parameter is null!");

            if (!this.session.IsValid())
            {
                callback.TryError(ErrorCode.IsNotLoggedIn);

                return;
            }

            FulFillCodeRequest fulFillCodeRequest = new FulFillCodeRequest {
                code     = code,
                region   = region,
                language = language
            };

            this.coroutineRunner.Run(
                this.api.RedeemCode(
                    this.@namespace,
                    this.session.UserId,
                    this.session.AuthorizationToken,
                    fulFillCodeRequest,
                    callback));
        }
        private IEnumerator <ITask> LoginWithOtherPlatformAsync(PlatformType platformType, string platformToken,
                                                                ResultCallback callback)
        {
            if (this.IsLoggedIn)
            {
                this.Logout();
            }

            Result <TokenData> loginResult = null;

            yield return(Task.Await(this.authApi.GetUserTokenWithOtherPlatform(this.@namespace,
                                                                               this.clientId, this.clientSecret, platformType, platformToken,
                                                                               result => { loginResult = result; })));

            if (loginResult.IsError)
            {
                callback.TryError(ErrorCode.GenerateTokenFailed,
                                  "cannot generate platform token for " + platformType, loginResult.Error);

                yield break;
            }

            this.tokenData       = loginResult.Value;
            this.nextRefreshTime = User.ScheduleNormalRefresh(this.tokenData.expires_in);

            callback.TryOk();
        }
Beispiel #11
0
        /// <summary>
        /// Query user entitlements.
        /// </summary>
        /// <param name="entitlementName">The name of the entitlement (optional)</param>
        /// <param name="itemId">Item's id (optional)</param>
        /// <param name="offset">Offset of the list that has been sliced based on Limit parameter (optional, default = 0)</param>
        /// <param name="limit">The limit of item on page (optional)</param>
        /// <param name="callback">Returns a Result that contains EntitlementPagingSlicedResult via callback when completed</param>
        /// <param name="entitlementClazz">Class of the entitlement (optional)</param>
        /// <param name="entitlementAppType">This is the type of application that entitled (optional)</param>
        public void QueryUserEntitlements(string entitlementName, string itemId, int offset, int limit, ResultCallback <EntitlementPagingSlicedResult> callback,
                                          EntitlementClazz entitlementClazz = EntitlementClazz.NONE, EntitlementAppType entitlementAppType = EntitlementAppType.NONE)
        {
            Report.GetFunctionLog(this.GetType().Name);
            Assert.IsNotNull(entitlementName, "Can't query user entitlements! EntitlementName parameter is null!");
            Assert.IsNotNull(itemId, "Can't query user entitlements! ItemId parameter is null!");

            if (!this.session.IsValid())
            {
                callback.TryError(ErrorCode.IsNotLoggedIn);

                return;
            }

            this.coroutineRunner.Run(
                this.api.QueryUserEntitlements(
                    this.@namespace,
                    this.session.UserId,
                    this.session.AuthorizationToken,
                    entitlementName,
                    itemId,
                    offset,
                    limit,
                    entitlementClazz,
                    entitlementAppType,
                    callback));
        }
Beispiel #12
0
        public IEnumerator DeregisterLocalServer(string name, string accessToken, ResultCallback callback)
        {
            Assert.IsNotNull(name, "Deregister failed. name is null!");
            Assert.IsNotNull(accessToken, "Can't update a slot! accessToken parameter is null!");

            if (this.serverType != ServerType.LOCALSERVER)
            {
                callback.TryError(ErrorCode.Conflict, "Server not registered as Local Server.");

                yield break;
            }

            var request = HttpRequestBuilder.CreatePost(this.baseUrl + "/namespaces/{namespace}/servers/local/deregister")
                          .WithPathParam("namespace", this.namespace_)
                          .WithBearerAuth(accessToken)
                          .WithContentType(MediaType.ApplicationJson)
                          .Accepts(MediaType.ApplicationJson)
                          .WithBody(string.Format("{{\"name\": \"{0}\"}}", name))
                          .GetResult();

            IHttpResponse response = null;

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

            var result = response.TryParse();

            serverType = ServerType.NONE;

            callback.Try(result);
        }
        private IEnumerator <ITask> LoginWithDeviceIdAsync(DeviceProvider deviceProvider, ResultCallback callback)
        {
            if (this.IsLoggedIn)
            {
                this.Logout();
            }

            Result <TokenData> loginResult = null;

            yield return(Task.Await(
                             this.authApi.GetUserTokenWithDeviceId(
                                 this.@namespace, this.clientId, this.clientSecret, deviceProvider.DeviceType,
                                 deviceProvider.DeviceId,
                                 result => loginResult = result)));

            if (loginResult.IsError)
            {
                callback.TryError(loginResult.Error.Code, loginResult.Error.Message);

                yield break;
            }

            this.tokenData       = loginResult.Value;
            this.nextRefreshTime = User.ScheduleNormalRefresh(this.tokenData.expires_in);

            callback.TryOk();
        }
        /// <summary>
        /// Register local server to DSM and mark this machine as ready
        /// </summary>
        /// <param name="ip">Local IP Address</param>
        /// <param name="port">Port number</param>
        /// <param name="name">Name to uniquely identify this local server</param>
        /// <param name="callback">Returns a Result via callback when completed</param>
        public void RegisterLocalServer(string ip, uint port, string name, ResultCallback callback)
        {
            Report.GetFunctionLog(this.GetType().Name);

            Assert.IsNotNull(name, "Can't Register server; podName is null!");

            if (!this.serverSession.IsValid())
            {
                callback.TryError(ErrorCode.IsNotLoggedIn);

                return;
            }

            this.name = name;
            var request = new RegisterLocalServerRequest {
                ip = ip, port = port, name = name
            };
            string authToken = this.serverSession.AuthorizationToken;

            this.coroutineRunner.Run(this.api.RegisterLocalServer(request, authToken, callback));

            if (this.isHeartBeatAutomatic)
            {
                this.heartBeatCoroutine = this.coroutineRunner.Run(RunPeriodicHeartBeat());
            }
        }
        public IEnumerator LoginWithDeviceId(ResultCallback callback)
        {
            Report.GetFunctionLog(this.GetType().Name);
            DeviceProvider deviceProvider = DeviceProvider.GetFromSystemInfo();

            IHttpRequest request = HttpRequestBuilder.CreatePost(this.baseUrl + "/oauth/platforms/{platformId}/token")
                                   .WithPathParam("platformId", deviceProvider.DeviceType)
                                   .WithBasicAuth(this.clientId, this.clientSecret)
                                   .WithContentType(MediaType.ApplicationForm)
                                   .Accepts(MediaType.ApplicationJson)
                                   .WithFormParam("device_id", deviceProvider.DeviceId)
                                   .WithFormParam("namespace", this.@namespace)
                                   .GetResult();

            IHttpResponse response = null;

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

            Result <TokenData> result = response.TryParseJson <TokenData>();

            this.tokenData = result.Value;

            if (!result.IsError)
            {
                this.maintainAccessTokenCoroutine = this.coroutineRunner.Run(MaintainAccessToken());
                callback.TryOk();
            }
            else
            {
                callback.TryError(result.Error);
            }
        }
        public IEnumerator LoginWithUsername(string username, string password, ResultCallback callback)
        {
            Report.GetFunctionLog(this.GetType().Name);
            Assert.IsNotNull(username, "Username parameter is null.");
            Assert.IsNotNull(password, "Password parameter is null.");

            var request = HttpRequestBuilder.CreatePost(this.baseUrl + "/oauth/token")
                          .WithBasicAuth(this.clientId, this.clientSecret)
                          .WithContentType(MediaType.ApplicationForm)
                          .Accepts(MediaType.ApplicationJson)
                          .WithFormParam("grant_type", "password")
                          .WithFormParam("username", username)
                          .WithFormParam("password", password)
                          .WithFormParam("namespace", this.@namespace)
                          .GetResult();

            IHttpResponse response = null;

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

            Result <TokenData> result = response.TryParseJson <TokenData>();

            this.tokenData = result.Value;

            if (!result.IsError)
            {
                this.maintainAccessTokenCoroutine = this.coroutineRunner.Run(MaintainAccessToken());
                callback.TryOk();
            }
            else
            {
                callback.TryError(result.Error);
            }
        }
        public IEnumerator LoginWithOtherPlatform(PlatformType platformType, string platformToken,
                                                  ResultCallback callback)
        {
            Report.GetFunctionLog(this.GetType().Name);
            Assert.IsNotNull(platformToken, "PlatformToken parameter is null.");

            var request = HttpRequestBuilder.CreatePost(this.baseUrl + "/oauth/platforms/{platformId}/token")
                          .WithPathParam("platformId", platformType.ToString().ToLower())
                          .WithBasicAuth(this.clientId, this.clientSecret)
                          .WithContentType(MediaType.ApplicationForm)
                          .Accepts(MediaType.ApplicationJson)
                          .WithFormParam("platform_token", platformToken)
                          .WithFormParam("namespace", this.@namespace)
                          .GetResult();

            IHttpResponse response = null;

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

            Result <TokenData> result = response.TryParseJson <TokenData>();

            this.tokenData = result.Value;

            if (!result.IsError)
            {
                this.maintainAccessTokenCoroutine = this.coroutineRunner.Run(MaintainAccessToken());
                callback.TryOk();
            }
            else
            {
                callback.TryError(result.Error);
            }
        }
        private IEnumerator LoginAsync(Func <ResultCallback, IEnumerator> loginMethod, ResultCallback callback)
        {
            if (this.sessionAdapter.IsValid())
            {
                callback.TryError(ErrorCode.InvalidRequest, "User is already logged in.");

                yield break;
            }

            Result loginResult = null;

            yield return(loginMethod(r => loginResult = r));

            if (loginResult.IsError)
            {
                callback.TryError(loginResult.Error);

                yield break;
            }

            this.sessionAdapter.AuthorizationToken = this.loginSession.AuthorizationToken;

            if (this.needsUserId)
            {
                Result <UserData> userDataResult = null;

                yield return(RefreshDataAsync(result => userDataResult = result));

                if (userDataResult.IsError)
                {
                    callback.TryError(userDataResult.Error);

                    yield break;
                }

                this.sessionAdapter.UserId = this.userDataCache.userId;
            }
            else
            {
                this.sessionAdapter.UserId = this.loginSession.UserId;
            }

            callback.TryOk();
        }
Beispiel #19
0
        /// <summary>
        /// Get current active season.
        /// </summary>
        /// <param name="language">The language of the Season.</param>
        /// <param name="callback">Returns a Result that contains SeasonInfo via callback when completed.</param>
        public void GetCurrentSeason(string language, ResultCallback <SeasonInfo> callback)
        {
            Report.GetFunctionLog(this.GetType().Name);

            if (!this.session.IsValid())
            {
                callback.TryError(ErrorCode.IsNotLoggedIn);
                return;
            }

            this.coroutineRunner.Run(this.api.GetCurrentSeason(this.@namespace, this.session.AuthorizationToken, language, callback));
        }
Beispiel #20
0
        /// <summary>
        /// Get user profile for current logged in user.
        /// </summary>
        /// <param name="callback">Returns a Result that contains UserProfile via callback when completed.</param>
        public void GetUserProfile(ResultCallback <UserProfile> callback)
        {
            Report.GetFunctionLog(this.GetType().Name);
            if (!this.session.IsValid())
            {
                callback.TryError(ErrorCode.IsNotLoggedIn);

                return;
            }

            this.coroutineRunner.Run(this.api.GetUserProfile(this.@namespace, this.session.AuthorizationToken, callback));
        }
        /// <summary>
        /// Enqueue Game Server to Joinable Session Queue.
        /// this will make this server joinable by other parties while already in a session.
        /// </summary>
        /// <param name="body">the session's data (get this data from QuerySessionStatus)</param>
        /// <param name="callback">the result of this operation</param>
        public void EnqueueJoinableSession(MatchmakingResult body, ResultCallback callback)
        {
            Report.GetFunctionLog(this.GetType().Name);

            if (!this.serverSession.IsValid())
            {
                callback.TryError(ErrorCode.IsNotLoggedIn);
                return;
            }

            coroutineRunner.Run(api.EnqueueJoinableSession(this.@namespace, serverSession.AuthorizationToken, body, callback));
        }
Beispiel #22
0
        /// <summary>
        /// Claim Season Rewards.
        /// </summary>
        /// <param name="rewardRequest">Detail information for the Reward Request.</param>
        /// <param name="callback">Returns a Result that contains SeasonClaimRewardResponse via callback when completed.</param>
        public void ClaimRewards(SeasonClaimRewardRequest rewardRequest, ResultCallback <SeasonClaimRewardResponse> callback)
        {
            Report.GetFunctionLog(this.GetType().Name);

            if (!this.session.IsValid())
            {
                callback.TryError(ErrorCode.IsNotLoggedIn);
                return;
            }

            this.coroutineRunner.Run(this.api.ClaimRewards(this.@namespace, this.session.AuthorizationToken, this.session.UserId, rewardRequest, callback));
        }
        /// <summary>
        /// Get all profiles of specified users
        /// </summary>
        /// <param name="userIds">Id of some users to get</param>
        /// <param name="callback">Returns all profiles for specified users via callback when completed.</param>
        public void BatchGetGameProfiles(ICollection <string> userIds, ResultCallback <UserGameProfiles[]> callback)
        {
            Report.GetFunctionLog(this.GetType().Name);
            if (!this.session.IsValid())
            {
                callback.TryError(ErrorCode.IsNotLoggedIn);

                return;
            }

            this.coroutineRunner.Run(
                this.api.BatchGetGameProfiles(this.@namespace, userIds, this.session.AuthorizationToken, callback));
        }
        /// <summary>
        /// Get user data from another user by email
        /// </summary>
        /// <param name="emailOrDisplayName"> email or display name that needed to get user data</param>
        /// <param name="callback"> Return a Result that contains UserData when completed. </param>
        public void SearchUsers(string emailOrDisplayName, ResultCallback <PagedPublicUsersInfo> callback)
        {
            Report.GetFunctionLog(this.GetType().Name);

            if (!this.sessionAdapter.IsValid())
            {
                callback.TryError(ErrorCode.IsNotLoggedIn);

                return;
            }

            this.coroutineRunner.Run(this.userAccount.SearchUsers(emailOrDisplayName, callback));
        }
        /// <summary>
        /// Get user data from another user by user id
        /// </summary>
        /// <param name="userId"> user id that needed to get user data</param>
        /// <param name="callback"> Return a Result that contains UserData when completed. </param>
        public void GetUserByUserId(string userId, ResultCallback <UserData> callback)
        {
            Report.GetFunctionLog(this.GetType().Name);

            if (!this.sessionAdapter.IsValid())
            {
                callback.TryError(ErrorCode.IsNotLoggedIn);

                return;
            }

            this.coroutineRunner.Run(this.userAccount.GetUserByUserId(userId, callback));
        }
        /// <summary>
        /// Get array of other platforms this user linked to
        /// </summary>
        /// <param name="callback">Returns a Result that contains PlatformLink array via callback when
        /// completed.</param>
        public void GetPlatformLinks(ResultCallback <PagedPlatformLinks> callback)
        {
            Report.GetFunctionLog(this.GetType().Name);

            if (!this.sessionAdapter.IsValid())
            {
                callback.TryError(ErrorCode.IsNotLoggedIn);

                return;
            }

            this.coroutineRunner.Run(this.userAccount.GetPlatformLinks(callback));
        }
        /// <summary>
        /// Unlink other platform that has been linked to the currently logged in user. The change will take effect
        /// after user has been re-login.
        /// </summary>
        /// <param name="platformType">Other platform's type (Google, Steam, Facebook, etc)</param>
        /// <param name="platformTicket">Ticket / token from other platform to unlink from this user</param>
        /// <param name="callback">Returns a result via callback when completed</param>
        public void UnlinkOtherPlatform(PlatformType platformType, string platformTicket, ResultCallback callback)
        {
            Report.GetFunctionLog(this.GetType().Name);

            if (!this.sessionAdapter.IsValid())
            {
                callback.TryError(ErrorCode.IsNotLoggedIn);

                return;
            }

            this.coroutineRunner.Run(this.userAccount.UnlinkOtherPlatform(platformType, callback));
        }
Beispiel #28
0
        public IEnumerator ShutdownServer(ShutdownServerRequest shutdownServerRequest, string accessToken,
                                          ResultCallback callback)
        {
            if (IsCurrentProvider(Provider.AGONES) && serverType != ServerType.LOCALSERVER)
            {
#if ENABLE_AGONES_PLUGIN
                yield return(ShutdownAgones(callback));
#else
                callback.TryError(ErrorCode.NotFound,
                                  "Can't request shutdown server. Agones provider arguments is passed but Agones plugin is not found.");
#endif
                yield break;
            }
            Assert.IsNotNull(shutdownServerRequest, "Register failed. shutdownServerNotif is null!");
            Assert.IsNotNull(accessToken, "Can't update a slot! accessToken parameter is null!");
            if (this.serverType != ServerType.CLOUDSERVER)
            {
                callback.TryError(ErrorCode.Conflict, "Server not registered as Cloud Server.");

                yield break;
            }

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

            IHttpResponse response = null;

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

            var result = response.TryParse();
            serverType = ServerType.NONE;
            callback.Try(result);
        }
Beispiel #29
0
        private IEnumerator GetUserEntitlementOwnershipTokenAsync(string key, string[] itemIds, string[] appIds, string[] skus, bool verifyPublicKey, bool verifyExpiration, bool verifyUserId,
                                                                  ResultCallback <OwnershipEntitlement[]> callback)
        {
            if (!this.session.IsValid())
            {
                callback.TryError(ErrorCode.IsNotLoggedIn);
                yield break;
            }

            Result <OwnershipToken> result = null;

            yield return(this.api.GetUserEntitlementOwnershipToken(
                             AccelBytePlugin.Config.PublisherNamespace,
                             this.session.AuthorizationToken,
                             itemIds,
                             appIds,
                             skus,
                             r => result = r));

            if (result.IsError)
            {
                callback.TryError(result.Error.Code);
                yield break;
            }

            if (!JsonWebToken.TryDecodeToken <OwnershipTokenPayload>(key, result.Value.ownershipToken, out var payloadResult, verifyPublicKey, verifyExpiration))
            {
                callback.TryError(ErrorCode.InvalidResponse);
                yield break;
            }

            if (verifyUserId && this.session.UserId != payloadResult.sub)
            {
                callback.TryError(ErrorCode.InvalidResponse);
                yield break;
            }

            callback.TryOk(payloadResult.entitlements);
        }
        /// <summary>
        /// Send any data with class T to Telemetry service. The data type must be serializable by implementing
        /// DataContract attribute.
        /// </summary>
        /// <param name="eventTag">Event tag</param>
        /// <param name="eventData">Event data</param>
        /// <param name="callback">Returns a Result via callback when completed.</param>
        /// <typeparam name="T">A class that implements DataContract and DataMember attribute</typeparam>
        public void SendEvent <T>(TelemetryEventTag eventTag, T eventData, ResultCallback callback)
            where T : class
        {
            if (!this.user.IsLoggedIn)
            {
                callback.TryError(ErrorCode.IsNotLoggedIn);
                return;
            }

            if (eventData is string)
            {
                callback.TryError(ErrorCode.InvalidRequest, "string is not allowed as event data");
                return;
            }

            this.taskDispatcher.Start(
                Task.Retry(
                    cb => this.api.SendEvent(this.user.Namespace, this.clientId,
                                             this.user.UserId, eventTag, eventData, result => cb(result)),
                    result => this.coroutineRunner.Run(() => callback((Result)result)),
                    this.user));
        }