示例#1
0
        internal RuyiNetClient(TProtocol protocol, StorageLayerService.Client storageLayerService)
        {
            BCService = new BrainCloudService.Client(protocol);

            AppId      = string.Empty;
            AppSecret  = string.Empty;
            mTaskQueue = new RuyiNetTaskQueue();

            CloudService        = new RuyiNetCloudService(this, storageLayerService);
            FriendService       = new RuyiNetFriendService(this);
            GamificationService = new RuyiNetGamificationService(this);
            LeaderboardService  = new RuyiNetLeaderboardService(this);
            LobbyService        = new RuyiNetLobbyService(this);
            PartyService        = new RuyiNetPartyService(this);
            PatchService        = new RuyiNetPatchService(this);
            ProfileService      = new RuyiNetProfileService(this);
            TelemetryService    = new RuyiNetTelemetryService(this);
            UserFileService     = new RuyiNetUserFileService(this);
            VideoService        = new RuyiNetVideoService(this);

            CurrentPlayers = new RuyiNetProfile[MAX_PLAYERS];

            RemoteIpAddress = string.Empty;

            Initialised = false;
        }
示例#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>
        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;
        }
示例#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_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();
            });
        }