Beispiel #1
0
        /// <summary>
        /// Returns TRUE while there are tasks in the queue.
        /// </summary>
        //public bool IsWorking { get { return mTaskQueue.Work > 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_RunParentScriptAsync("RUYI_Cleanup", "{}", "RUYI", i, token).Wait();
                            BCService.Identity_SwitchToParentProfileAsync("RUYI", i, token).Wait();
                        }
                    }

                    BCService.Dispose();
                    BCService = null;
                }
            }
        }
Beispiel #2
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();
            });
        }