Beispiel #1
0
        /// <summary>
        ///     Sends a request to server, retrieves all profile values, and applies them to a provided
        ///     profile
        /// </summary>
        public void GetProfileValues(ObservableProfile profile, SuccessCallback callback, ErrorCallback errorCallback)
        {
            if (!Client.IsConnected)
            {
                errorCallback.Invoke("Not connected");
                return;
            }

            Client.SendMessage((ushort)OpCodes.ClientProfileRequest, profile.PropertyCount, (status, response) =>
            {
                if (status != ResponseStatus.Success)
                {
                    errorCallback.Invoke(response.AsString("Unknown error"));
                    return;
                }

                // Use the bytes received, to replicate the profile
                profile.FromBytes(response.AsBytes());

                // Listen to profile updates, and apply them
                Client.SetHandler((ushort)OpCodes.UpdateClientProfile,
                                  message => { profile.ApplyUpdates(message.AsBytes()); });

                callback.Invoke();
            });
        }
Beispiel #2
0
        protected override void Initialize()
        {
            profileView         = ViewsManager.GetView <Profile_View>("ProfileView");
            profileSettingsView = ViewsManager.GetView <ProfileSettings_View>("ProfileSettingsView");

            Profile = new ObservableProfile
            {
                new ObservableString((short)ObservablePropertyCodes.DisplayName)
            };

            Profile.OnPropertyUpdatedEvent += OnPropertyUpdatedEventHandler;
        }
Beispiel #3
0
        protected override void OnInitialize()
        {
            profileView = ViewsManager.GetView<ProfileView>("ProfileView");
            profileSettingsView = ViewsManager.GetView<ProfileSettingsView>("ProfileSettingsView");

            Profile = new ObservableProfile
            {
                new ObservableString((short)ObservablePropertiyCodes.DisplayName),
                new ObservableString((short)ObservablePropertiyCodes.Avatar),
                new ObservableFloat((short)ObservablePropertiyCodes.Bronze),
                new ObservableFloat((short)ObservablePropertiyCodes.Silver),
                new ObservableFloat((short)ObservablePropertiyCodes.Gold)
            };

            Profile.OnPropertyUpdatedEvent += OnPropertyUpdatedEventHandler;
        }
Beispiel #4
0
    private IEnumerator ImitateClient()
    {
        var connection = Msf.Connection;

        connection.Connect("127.0.0.1", 5000);

        // Wait until connected to master
        while (!connection.IsConnected)
        {
            yield return(null);
        }

        //Msf.Client.Auth.LogInAsGuest((accountInfo, error) =>
        Msf.Client.Auth.LogIn("aaaa", "aaaa", (accountInfo, error) =>
        {
            if (accountInfo == null)
            {
                Logs.Error(error);
                return;
            }

            var profile = new ObservableProfile()
            {
                new ObservableInt(0, 5),
                new ObservableString(1, "TEE")
            };

            _username = accountInfo.Username;

            Msf.Client.Profiles.GetProfileValues(profile, (isSuccessful, profileError) =>
            {
                if (!isSuccessful)
                {
                    Logs.Error(profileError);
                    return;
                }

                profile.PropertyUpdated += (code, property) =>
                {
                    Logs.Info("Property changed:" + code + " - " + property.SerializeToString());
                };

                // Imitate game server
                StartCoroutine(ImitateGameServer());
            }, connection);
        }, connection);
    }
    private IEnumerator ImitateClient()
    {
        var connection = Msf.Connection;

        connection.Connect("127.0.0.1", 5000);

        // Wait until connected to master
        while (!connection.IsConnected)
        {
            yield return(null);
        }

        //Msf.Client.Auth.LogInAsGuest((accountInfo, error) =>
        Msf.Client.Auth.LogIn("aaaa", "aaaa", (accountInfo, error) =>
        {
            if (accountInfo == null)
            {
                Logs.Error(error);
                return;
            }

            _username = accountInfo.Username;

            // Create a profile (we're intentionally not constructing all properties)
            var profile = new ObservableProfile()
            {
                new ObservableInt(MyProfileKeys.Coins, 5),
                new ObservableString(MyProfileKeys.Title, "DefaultTitle"),
                new ObservableDictStringInt(MyProfileKeys.Inventory),
            };

            // Send a request to master server, to fill profile values
            Msf.Client.Profiles.GetProfileValues(profile, (isSuccessful, profileError) =>
            {
                if (!isSuccessful)
                {
                    Logs.Error(profileError);
                    return;
                }

                // Listen to property updates
                profile.PropertyUpdated += (code, property) =>
                {
                    // Log a message, when property changes
                    Logs.Info("Property changed:" + code + " - " + property.SerializeToString());
                };

                // Imitate game server
                StartCoroutine(ImitateGameServer());
            }, connection);

            // Listen directly to changes in coins property
            var coinsProp      = profile.GetProperty <ObservableInt>(MyProfileKeys.Coins);
            coinsProp.OnDirty += property =>
            {
                Logs.Info("Coins changed to: " + coinsProp.Value);

                // OR
                // Logs.Info("Coins changed to: " + (property as ObservableInt).Value);
            };
        }, connection);
    }
Beispiel #6
0
 protected override void OnInitialize()
 {
     Profile = new ObservableProfile();
 }