public override void Connect()
        {
            var gachaData = Dot.Object("gacha", Hub.DataStore.LoginDataStore.LoginData, null);

            if (gachaData != null)
            {
                var sets = Dot.Object("sets", gachaData, null);
                if (sets != null)
                {
                    this.OnFetchSets(null, sets);
                }
                else
                {
                    this._api.FetchSets(this._config.Groups, OnFetchSets);
                }

                var tokens = Dot.Array("tokens", gachaData, null);
                if (tokens != null)
                {
                    this.OnSyncTokens(null, tokens);
                }
                else
                {
                    this.Sync(null);
                }
            }
            else
            {
                this.Sync(delegate(Dictionary <string, int> tokens){});
                this._api.FetchSets(this._config.Groups, OnFetchSets);
            }
        }
Exemple #2
0
        public Account(object obj)
        {
            AccountId = Dot.Long("naid", obj, AccountId);

            ArrayList users = Dot.Array("users", obj, null);

            if (users != null)
            {
                Users = new User[users.Count];
                for (int i = 0; i < Users.Length; ++i)
                {
                    Users[i] = Hub.Instance.UserManager.GetUser(users[i] as Hashtable);
                }
            }

            var auth = Dot.Object("auth", obj, null);

            if (auth != null)
            {
                var list = new List <AuthData>();
                foreach (DictionaryEntry entry in auth)
                {
                    var authData = new AuthData(entry.Key.ToString(), entry.Value);
                    list.Add(authData);
                }
                Authenticators = list.ToArray();
            }
        }
        void OnLoadPayouts(string err, Hashtable data)
        {
            if (!string.IsNullOrEmpty(err))
            {
                EB.Debug.LogError("获取商品失败:" + err);
                _config.Listener.OnOffersFetched();
                return;
            }

            _externalId = EB.Dot.String("externalTrkid", data, _externalId);
            int end = _externalId.LastIndexOf(':');

            _externalId = _externalId.Substring(0, end + 1);//去掉平台数据,后面用到的自己去拼,处理多平台问题
            _sale       = null;
            _bonusItems.Clear();
            _payouts.Clear();
            _enumerated = false;

            var currentSet = EB.Dot.Find <object>("data.payoutSets.0", data);

            if (currentSet != null)
            {
                var sale = EB.Dot.Object("sale", currentSet, null);
                if (sale != null)
                {
                    _sale = new PayoutSale(sale);
                }

                var bonus = EB.Dot.Array("redeemers", currentSet, new ArrayList());
                foreach (object candidate in bonus)
                {
                    Hashtable item = candidate as Hashtable;
                    if (item != null)
                    {
                        RedeemerItem redeemerItem = new RedeemerItem(item);
                        if (redeemerItem.IsValid == true)
                        {
                            _bonusItems.Add(redeemerItem);
                        }
                    }
                }

                var payouts = Dot.Array("payouts", currentSet, new ArrayList());
                EB.Debug.Log("【商城】加载商品成功,数量:{0}", payouts.Count);
                foreach (Hashtable payout in payouts)
                {
                    var item = new EB.IAP.Item(_externalId, payout);
                    _payouts.Add(item);
                }
            }
            _iapManager.Enumerate(_payouts);

            _config.Listener.OnOffersFetchSuceeded();
        }
Exemple #4
0
        public void FillInventory(Hashtable data)
        {
            ArrayList rawInventory = Dot.Array("inventory", data, null);

            if (null == rawInventory)
            {
                return;
            }

            foreach (Hashtable item in rawInventory)
            {
                Inventory.Add(item);
            }
        }
        IEnumerator DoVerify(ContentPack pack)
        {
            var infoPath = Path.Combine(pack.folder, "info.txt");
            var info     = ReadJsonFile(infoPath);

            if (info == null)
            {
                EB.Debug.Log("failed to load info file for content path: " + pack.folder);
                yield break;
            }

            yield return(null);

            pack.version = Dot.Integer("cl", info, -1);
            foreach (var file in Dot.Array("files", info, new ArrayList()))
            {
                pack.packs.Add(Dot.String("pack", file, string.Empty));
            }

            if (pack.version < Version.GetChangeList())
            {
                // too old
                EB.Debug.LogWarning("pack is too old, deleting " + pack.version);
                pack.Delete();
                yield break;
            }

            if (pack.packs.Count == 0)
            {
                EB.Debug.LogWarning("pack is empty, removing ");
                pack.Delete();
                yield break;
            }

            foreach (string p in pack.packs)
            {
                var folder = Path.Combine(pack.folder, p);
                if (!Verify(folder))
                {
                    EB.Debug.LogWarning("pack verification failed for pack " + p);
                    pack.Delete();
                    yield break;
                }
            }

            EB.Debug.Log("content is ok at " + pack.folder);
            _packs.Add(pack);

            yield break;
        }
        public override void Connect()
        {
            var data = Dot.Object("tele", Hub.DataStore.LoginDataStore.LoginData, null);

            _flushInterval = Dot.Single("interval", data, _flushInterval);
            _flushTimer    = _buffer.Count > 0 ? 0.0f : _flushInterval;

            // get the filter list
            var filter = Dot.Array("filter", data, null);

            if (filter != null)
            {
                _filter.Clear();
                foreach (var name in filter)
                {
                    _filter.Add(name.ToString());
                }
            }
            State = SubSystemState.Connected;
        }
Exemple #7
0
        void _Login(string authenticatorName, object authData)
        {
            _PreLogin(delegate(Hashtable secData) {
                _api.Login(authenticatorName, authData, secData, delegate(string err, object obj) {
                    if (!string.IsNullOrEmpty(err))
                    {
                        _LoginFailed(err);
                        return;
                    }

                    if (LoginState != LoginState.Authenticating)
                    {
                        EB.Debug.Log("_Login: already authenticated");
                        return;
                    }

                    _lastAuthenticator = authenticatorName;
                    PlayerPrefs.SetString("LastAuthenticator", _lastAuthenticator);

                    SetState(LoginState.Authenticated);

                    var account = Dot.Object("account", obj, null);
                    _account    = new Account(account);

                    var worldList = Dot.Array("worldlist", obj, null);
                    _gameWorlds.Clear();
                    if (worldList != null)
                    {
                        for (var i = 0; i < worldList.Count; i++)
                        {
                            var world = worldList[i];
                            _gameWorlds.Add(new GameWorld(world));
                        }
                    }
                    _gameWorlds.Sort(new WorldCompare());

                    var defaultWorld = _gameWorlds.Find(w => w.Default);
                    if (_user != null && defaultWorld != null && _user.WorldId == defaultWorld.Id)
                    {
                        LocalUser = System.Array.Find(_account.Users, u => u.Id == _user.Id);
                    }

                    // var notice = Dot.String("notice.content", obj, null);
                    Notices.Clear();
                    var notices = Dot.Array("notice.notices", obj, null);
                    if (notices != null)
                    {
                        for (var i = 0; i < notices.Count; i++)
                        {
                            var notice = notices[i];
                            Notices.Add(new NoticeItem(notice));
                        }
                    }
                    Notices.Sort((a, b) => { return(a.id.CompareTo(b.id)); });
                    if (_user != null)
                    {
                        Hashtable charData  = Johny.HashtablePool.Claim();
                        charData["worldId"] = _user.WorldId;
                        EnterGame(charData);
                    }
                    else
                    {
                        LoginExtraListener.OnAuthorized(GetAuthenticator(authenticatorName), _account);
                    }
                });
            });
        }
        IEnumerator DoDownload(Hashtable info)
        {
            var version = Dot.Integer("cl", info, 0);
            var files   = Dot.Array("files", info, null);

            if (files == null || files.Count == 0)
            {
                EB.Debug.LogError("missing file list!");
                yield break;
            }

            var pack = new ContentPack();

            pack.version = version;
            pack.folder  = Path.Combine(BasePath, version.ToString());
            pack.packs   = new List <string>();

            try
            {
                Directory.CreateDirectory(pack.folder);
            }
            catch (System.Exception ex)
            {
                EB.Debug.LogError("failed to create directory  " + pack.folder + " " + ex);
                yield break;
            }

            // write the info file
            if (!WriteJsonFile(Path.Combine(pack.folder, "info.txt"), info))
            {
                yield break;
            }

            var cdn = Dot.String("cdn", info, string.Empty);

            using (var endpoint = new HttpEndPoint(cdn, new EndPointOptions()))
            {
                var filesToDownload = new ArrayList();

                foreach (var file in files)
                {
                    var url       = Dot.String("url", file, string.Empty);
                    var size      = Dot.Long("size", file, 0);
                    var filename  = Path.GetFileName(url);
                    var localPath = Path.Combine(pack.folder, filename);
                    if (!CheckFile(localPath, size))
                    {
                        filesToDownload.Add(file);
                    }

                    pack.packs.Add(Dot.String("pack", file, string.Empty));
                }

                // download all the files
                for (int i = 0; i < filesToDownload.Count; ++i)
                {
                    var file = filesToDownload[i];
                    var url  = Dot.String("url", file, string.Empty);
                    var size = Dot.Long("size", file, 0);
                    //var md5 = Dot.String("md5", file, string.Empty);

                    var filename  = Path.GetFileName(url);
                    var localPath = Path.Combine(pack.folder, filename);

                    // download
                    yield return(Coroutines.Run(DoDownloadFile(i, filesToDownload.Count, size, endpoint, localPath, url)));

                    if (!CheckFile(localPath, size))
                    {
                        EB.Debug.LogError("Failed to download file! " + url);
                        yield break;
                    }
                }
            }

            Notify(Localizer.GetString("ID_SPARX_CONTENT_EXTRACTING"));
            yield return(new WaitForFixedUpdate());

            if (_pool == null)
            {
                _pool = new ThreadPool(1);
            }
            ThreadPool.AsyncTask async = _pool.Queue(this.ThreadTask, pack);

            while (!async.done)
            {
                yield return(new WaitForFixedUpdate());
            }

            if (async.exception != null)
            {
                Error = "ID_SPARX_CONTENT_FAILED_EXTRACT";
                Notify(Localizer.GetString("ID_SPARX_CONTENT_FAILED_EXTRACT"));
                yield break;
            }

            // mount it!
            Mount(pack);

            yield break;
        }