Ejemplo n.º 1
0
        /// <summary>
        /// Initialise the RUYI net client and switch to the game context.
        /// </summary>
        /// <param name="appId">The App ID of the game to initialise for.</param>
        /// <param name="appSecret">The App secret of the game. NOTE: This is a password and should be treated as such.</param>
        public async Task Initialise(string appId, string appSecret)
        {
            if (Initialised)
            {
                return;
            }

            AppId     = appId;
            AppSecret = appSecret;

            var hostString = Dns.GetHostName();

            IPHostEntry hostInfo = await Dns.GetHostEntryAsync(hostString);

            foreach (IPAddress ip in hostInfo.AddressList)
            {
                if (ip.AddressFamily == AddressFamily.InterNetwork)
                {
                    RemoteIpAddress = ip.ToString();
                }
            }

            for (int i = 0; i < MAX_PLAYERS; ++i)
            {
                CurrentPlayers[i] = null;
                var jsonResponse = await BCService.Identity_SwitchToSingletonChildProfileAsync(AppId, true, i, token);

                var childProfile = JsonConvert.DeserializeObject <RuyiNetSwitchToChildProfileResponse>(jsonResponse);
                if (childProfile.status != RuyiNetHttpStatus.OK)
                {
                    continue;
                }

                var profileId   = childProfile.data.parentProfileId;
                var profileName = childProfile.data.playerName;

                NewUser = childProfile.data.newUser;

                jsonResponse = await BCService.Friend_GetSummaryDataForProfileIdAsync(profileId, i, token);

                var pdata = JsonConvert.DeserializeObject <RuyiNetGetSummaryDataForProfileIdResponse>(jsonResponse);
                if (pdata.status != RuyiNetHttpStatus.OK)
                {
                    continue;
                }
                CurrentPlayers[i] = new RuyiNetProfile()
                {
                    profileId   = pdata.data.playerId,
                    profileName = pdata.data.playerName,
                    pictureUrl  = pdata.data.pictureUrl,
                    email       = pdata.data.email,
                };
            }

            Initialised = true;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Queue up a request to the online service that needs to be called on the RUYI platform level.
        /// </summary>
        /// <typeparam name="Response">A serialisiable class we can receive the data in.</typeparam>
        /// <param name="index">The index of user</param>
        /// <param name="onExecute">The method to call when we execute the task.</param>
        internal async Task <Response> EnqueuePlatformTask <Response>(int index, RuyiNetTask <Response> .ExecuteType onExecute)
        {
            await BCService.Identity_SwitchToParentProfileAsync("RUYI", index, token);

            var response = await onExecute();

            await BCService.Identity_SwitchToSingletonChildProfileAsync(AppId, false, index, token);

            var data = JsonConvert.DeserializeObject <Response>(response, jsonSerializerSettings);

            return(data);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Cleanup native resources before destruction.
        /// </summary>
        /// <param name="disposing">Whether or not we are disposing resources.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (BCService != null)
                {
                    for (int i = 0; i < MAX_PLAYERS; ++i)
                    {
                        if (CurrentPlayers[i] != null)
                        {
                            BCService.Script_RunParentScript("RUYI_Cleanup", "{}", "RUYI", i);
                            BCService.Identity_SwitchToParentProfile("RUYI", i);
                        }
                    }

                    BCService.Dispose();
                    BCService = null;
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initialise the RUYI net client and switch to the game context.
        /// </summary>
        /// <param name="appId">The App ID of the game to initialise for.</param>
        /// <param name="appSecret">The App secret of the game. NOTE: This is a password and should be treated as such.</param>
        /// <param name="onInitialised">The function to call whe initialisation completes.</param>
        public void Initialise(string appId, string appSecret, Action onInitialised)
        {
            if (Initialised)
            {
                onInitialised?.Invoke();

                return;
            }

            AppId     = appId;
            AppSecret = appSecret;

            EnqueueTask(() =>
            {
                var hostString = Dns.GetHostName();

                IPHostEntry hostInfo = Dns.GetHostEntry(hostString);
                foreach (IPAddress ip in hostInfo.AddressList)
                {
                    if (ip.AddressFamily == AddressFamily.InterNetwork)
                    {
                        RemoteIpAddress = ip.ToString();
                    }
                }

                for (int i = 0; i < MAX_PLAYERS; ++i)
                {
                    CurrentPlayers[i] = null;
                    var jsonResponse  = BCService.Identity_SwitchToSingletonChildProfile(AppId, true, i);
                    var childProfile  = JsonConvert.DeserializeObject <RuyiNetSwitchToChildProfileResponse>(jsonResponse);
                    if (childProfile.status != RuyiNetHttpStatus.OK)
                    {
                        continue;
                    }

                    var profileId   = childProfile.data.parentProfileId;
                    var profileName = childProfile.data.playerName;

                    NewUser = childProfile.data.newUser;

                    var payload = new RuyiNetProfileIdRequest()
                    {
                        profileId = profileId
                    };
                    jsonResponse = BCService.Script_RunParentScript("GetProfile", JsonConvert.SerializeObject(payload), "RUYI", i);

                    var profileData = JsonConvert.DeserializeObject <RuyiNetGetProfileResponse>(jsonResponse);
                    if (profileData.status != RuyiNetHttpStatus.OK ||
                        profileData.data.success == false)
                    {
                        continue;
                    }

                    CurrentPlayers[i] = profileData.data.response;
                }

                var response = new RuyiNetResponse()
                {
                    status = RuyiNetHttpStatus.OK
                };

                return(JsonConvert.SerializeObject(response));
            }, (RuyiNetResponse response) =>
            {
                Initialised = true;

                onInitialised?.Invoke();
            });
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Initialise the RUYI net client and switch to the game context.
        /// </summary>
        /// <param name="appId">The App ID of the game to initialise for.</param>
        /// <param name="appSecret">The App secret of the game. NOTE: This is a password and should be treated as such.</param>
        /// <param name="onInitialised">The function to call whe initialisation completes.</param>
        public void Initialise(string appId, string appSecret, Action onInitialised)
        {
            if (Initialised)
            {
                onInitialised?.Invoke();

                return;
            }

            AppId     = appId;
            AppSecret = appSecret;

            EnqueueTask(() =>
            {
                var hostString = Dns.GetHostName();

                IPHostEntry hostInfo = Dns.GetHostEntry(hostString);
                foreach (IPAddress ip in hostInfo.AddressList)
                {
                    if (ip.AddressFamily == AddressFamily.InterNetwork)
                    {
                        RemoteIpAddress = ip.ToString();
                    }
                }

                for (int i = 0; i < MAX_PLAYERS; ++i)
                {
                    CurrentPlayers[i] = null;
                    var jsonResponse  = BCService.Identity_SwitchToSingletonChildProfile(AppId, true, i);
                    var childProfile  = JsonConvert.DeserializeObject <RuyiNetSwitchToChildProfileResponse>(jsonResponse);
                    if (childProfile.status != RuyiNetHttpStatus.OK)
                    {
                        continue;
                    }

                    var profileId   = childProfile.data.parentProfileId;
                    var profileName = childProfile.data.playerName;

                    NewUser = childProfile.data.newUser;

                    jsonResponse = BCService.Friend_GetSummaryDataForProfileId(profileId, i);
                    var pdata    = JsonConvert.DeserializeObject <RuyiNetGetSummaryDataForProfileIdResponse>(jsonResponse);
                    if (pdata.status != RuyiNetHttpStatus.OK)
                    {
                        continue;
                    }
                    CurrentPlayers[i] = new RuyiNetProfile()
                    {
                        profileId   = pdata.data.playerId,
                        profileName = pdata.data.playerName,
                        pictureUrl  = pdata.data.pictureUrl,
                        email       = pdata.data.email,
                    };
                    Logging.Logger.Log($"{pdata.data.playerId} {pdata.data.playerName} {pdata.data.pictureUrl} {pdata.data.email}", Logging.LogLevel.Info);
                }

                var response = new RuyiNetResponse()
                {
                    status = RuyiNetHttpStatus.OK
                };

                return(JsonConvert.SerializeObject(response));
            }, (RuyiNetResponse response) =>
            {
                Initialised = true;

                onInitialised?.Invoke();
            });
        }