Beispiel #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;
        }
Beispiel #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);
        }
Beispiel #3
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_SwitchToSingletonChildProfileAsync(AppId, true, i, token).Result;
                    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_RunParentScriptAsync("GetProfile", JsonConvert.SerializeObject(payload), "RUYI", i, token).Result;

                    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();
            });
        }