Exemple #1
0
        /// <summary>
        /// Registers existing Hoard game. This game must exist on Hoard platform.
        /// This function performs initial setup of game contract.
        /// </summary>
        /// <param name="game">[in/out] game object must contain valid ID. Other fields will be retrieved from platform</param>
        /// <returns></returns>
        public async Task RegisterHoardGame(GameID game)
        {
            if (gameContracts.ContainsKey(game))
            {
                ErrorCallbackProvider.ReportWarning("Game already registered!");
                return;
            }

            string gameAddress = await gameCenter.GetGameContractAsync(game.ID);

            if (gameAddress != Eth.Utils.EMPTY_ADDRESS && gameAddress != "0x")
            {
                GameContract gameContract = new GameContract(web, gameAddress);

                string url = await gameContract.GetGameServerURLAsync();

                game.Name = await gameContract.GetName();

                game.GameOwner = await gameContract.GetOwner();

                if ((url != null) && (url.Length > 0))
                {
                    game.Url = !url.StartsWith("http") ? "http://" + url : url;
                }

                gameContracts.Add(game, gameContract);
                return;
            }

            throw new HoardException($"Game is not registered in Hoard Game Center: game = {game.ID}!");
        }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="profilesDir"></param>
        /// <param name="enumFunc"></param>
        /// <returns></returns>
        public static async Task EnumerateProfiles(string profilesDir, Func <string, Task> enumFunc)
        {
            ErrorCallbackProvider.ReportInfo(string.Format("Loading profiles from path: {0}", profilesDir));

            if (!Directory.Exists(profilesDir))
            {
                ErrorCallbackProvider.ReportWarning("Not found any profile files.");
                return;
            }

            var accountsFiles = Directory.GetFiles(profilesDir, "*.keystore");

            if (accountsFiles.Length == 0)
            {
                ErrorCallbackProvider.ReportWarning("Not found any profiles files.");
                return;
            }

            foreach (var fullPath in accountsFiles)
            {
                string fileName = Path.GetFileName(fullPath);
                if ((fileName != null) && (fileName != System.String.Empty))
                {
                    await enumFunc(fileName);
                }
            }
        }
Exemple #3
0
        /// <summary>
        ///   Closes top view but not go back to previous view.
        /// </summary>
        public static void CloseTopView()
        {
            if (stackedControlers.Count == 0)
            {
                ErrorCallbackProvider.ReportWarning(string.Format("Attempt to call {0} when controllers count is 0. Check code logic"));
                return;
            }
            var view = stackedControlers.Pop();

            view.CloseAndDisable();
        }
Exemple #4
0
        /// <summary>
        /// Connects to Hoard Game Server
        /// </summary>
        /// <returns></returns>
        public async Task Connect()
        {
            //1. connect to REST server
            if (!string.IsNullOrEmpty(Game.Url))
            {
                await ConnectToGameServer();
            }
            else
            {
                ErrorCallbackProvider.ReportWarning("Game.Url is empty - all data will be provided by BlockChain provider!");
            }

            //2. check also fallback connector
            if (SecureProvider != null)
            {
                await SecureProvider.Connect();
            }
        }
        /// <summary>
        ///   Reads the profiles from the storage and store them in AvailableProfileNames property
        /// </summary>
        public void GetProfiles()
        {
            // Enumerate all *.keystore files located in ProfilesDir directory.
            /// NOTE That is hardly easy to use
            ErrorCallbackProvider.ReportWarning("Reading from : " + ProfilesDir);
            Hoard.Utils.KeyStoreUtils.EnumerateProfiles(ProfilesDir, (Func <string, Task>)(async(fileName) =>
            {
                await Task.Yield();
                StreamReader jsonReader = new StreamReader(Path.Combine(ProfilesDir, fileName));
                JObject jobj            = JObject.Parse(jsonReader.ReadToEnd());
                jsonReader.Close();
                JToken valueAddress;
                JToken valueName;

                // Valid keystore file should contain address and name.
                if (jobj.TryGetValue("address", out valueAddress) && jobj.TryGetValue("name", out valueName))
                {
                    AvailableProfileNames.Add(new ProfileDescription((string)valueName.Value <string>(), (HoardID) new HoardID((string)valueAddress.Value <string>())));
                }
            })).ContinueGUISynch(x => Initialized = true);
        }