public static void LoadDebugJSON(LogicLevel level, string json)
        {
            LogicJSONObject jsonObject = LogicJSONParser.ParseObject(json);

            if (jsonObject != null)
            {
                LogicArrayList <LogicComponent> unitStorageComponents = level.GetComponentManager().GetComponents(LogicComponentType.UNIT_STORAGE);

                for (int i = 0; i < unitStorageComponents.Size(); i++)
                {
                    ((LogicUnitStorageComponent)unitStorageComponents[i]).RemoveAllUnits();
                }

                level.SetLoadingVillageType(0);

                LogicDebugUtil.LoadDebugJSONArray(level, jsonObject.GetJSONArray("buildings"), LogicGameObjectType.BUILDING, 0);
                LogicDebugUtil.LoadDebugJSONArray(level, jsonObject.GetJSONArray("obstacles"), LogicGameObjectType.OBSTACLE, 0);
                LogicDebugUtil.LoadDebugJSONArray(level, jsonObject.GetJSONArray("traps"), LogicGameObjectType.TRAP, 0);
                LogicDebugUtil.LoadDebugJSONArray(level, jsonObject.GetJSONArray("decos"), LogicGameObjectType.DECO, 0);

                level.SetLoadingVillageType(1);

                LogicDebugUtil.LoadDebugJSONArray(level, jsonObject.GetJSONArray("buildings2"), LogicGameObjectType.BUILDING, 1);
                LogicDebugUtil.LoadDebugJSONArray(level, jsonObject.GetJSONArray("obstacles2"), LogicGameObjectType.OBSTACLE, 1);
                LogicDebugUtil.LoadDebugJSONArray(level, jsonObject.GetJSONArray("traps2"), LogicGameObjectType.TRAP, 1);
                LogicDebugUtil.LoadDebugJSONArray(level, jsonObject.GetJSONArray("decos2"), LogicGameObjectType.DECO, 1);

                level.SetLoadingVillageType(-1);
            }
        }
        private void LoadAccount(LogicLong id)
        {
            if (id != null)
            {
                string path = string.Format("accounts/{0}-{1}", id.GetHigherInt(), id.GetLowerInt());

                if (File.Exists(path))
                {
                    LogicJSONObject jsonObject = LogicJSONParser.ParseObject(File.ReadAllText(path));

                    this.m_accountInfo = new AccountInfo
                    {
                        AccountId = new LogicLong(jsonObject.GetJSONNumber("id_high").GetIntValue(), jsonObject.GetJSONNumber("id_low").GetIntValue()),
                        PassToken = jsonObject.GetJSONString("passToken").GetStringValue()
                    };
                }
                else
                {
                    Debugger.Warning("ServerConnection.loadAccount: account doesn't exists!");
                }
            }
            else
            {
                this.m_accountInfo = new AccountInfo();
            }
        }
Esempio n. 3
0
        public static async Task <LogicArrayList <AllianceHeaderEntry> > GetAllianceHeaderList(LogicArrayList <LogicLong> ids)
        {
            LogicArrayList <AllianceHeaderEntry> allianceList = new LogicArrayList <AllianceHeaderEntry>(ids.Size());

            Task <IOperationResult <string> >[] results = new Task <IOperationResult <string> > [ids.Size()];

            for (int i = 0; i < ids.Size(); i++)
            {
                results[i] = ServerSearch.AllianceDatabase.Get(ids[i]);
            }

            for (int i = 0; i < ids.Size(); i++)
            {
                IOperationResult <string> result = await results[i];

                if (result.Success)
                {
                    LogicJSONObject     jsonObject          = LogicJSONParser.ParseObject(result.Value);
                    AllianceHeaderEntry allianceHeaderEntry = new AllianceHeaderEntry();

                    allianceHeaderEntry.Load(jsonObject);
                    allianceHeaderEntry.SetAllianceId(new LogicLong(jsonObject.GetJSONNumber(CouchbaseDocument.JSON_ATTRIBUTE_ID_HIGH).GetIntValue(),
                                                                    jsonObject.GetJSONNumber(CouchbaseDocument.JSON_ATTRIBUTE_ID_LOW).GetIntValue()));
                    allianceList.Add(allianceHeaderEntry);
                }
            }

            return(allianceList);
        }
Esempio n. 4
0
        /// <summary>
        /// Initializes the <see cref="Fingerprint"/> class.
        /// </summary>
        public static void Init()
        {
            if (Fingerprint.Initialized)
            {
                return;
            }

            try
            {
                if (!Fingerprint.Patched)
                {
                    FileInfo file = new FileInfo($@"{Directory.GetCurrentDirectory()}\Gamefiles\fingerprint.json");

                    if (file.Exists)
                    {
                        Fingerprint.Json = file.ReadAllText();

                        LogicJSONObject json = LogicJSONParser.ParseObject(Fingerprint.Json);
                        Fingerprint.Sha     = json.GetJsonString("sha").GetStringValue();
                        Fingerprint.Version = json.GetJsonString("version").GetStringValue().Split('.');
                    }
                    else
                    {
                        Debugger.Error("The Fingerprint cannot be loaded, the file does not exist.");
                    }
                }
            }
            catch (Exception exception)
            {
                Debugger.Error($"{exception.GetType().Name} while parsing the fingerprint.");
            }

            Fingerprint.Initialized = true;
        }
Esempio n. 5
0
        public override void Decode(ByteStream stream)
        {
            this.m_id   = stream.ReadVInt();
            this.m_data = (LogicGameObjectData)LogicDataTables.GetDataById(stream.ReadVInt());
            this.m_json = LogicJSONParser.ParseObject(stream.ReadString(900000) ?? string.Empty);

            base.Decode(stream);
        }
Esempio n. 6
0
        public static void SaveHomeOwnerAvatarInHome(LogicClientAvatar logicClientAvatar, LogicClientHome logicClientHome)
        {
            CompressibleStringHelper.Uncompress(logicClientHome.GetCompressibleHomeJSON());
            LogicJSONObject jsonObject = LogicJSONParser.ParseObject(logicClientHome.GetCompressibleHomeJSON().Get());

            logicClientAvatar.SaveToDirect(jsonObject);
            logicClientHome.SetHomeJSON(LogicJSONParser.CreateJSONString(jsonObject, 512));
            CompressibleStringHelper.Compress(logicClientHome.GetCompressibleHomeJSON());
        }
        public static T Load <T>(string json) where T : CouchbaseDocument, new()
        {
            LogicJSONObject jsonObject = LogicJSONParser.ParseObject(json);

            T document = new T();

            document.Id = LogicLong.ToLong(jsonObject.GetJSONNumber(CouchbaseDocument.JSON_ATTRIBUTE_ID_HIGH).GetIntValue(),
                                           jsonObject.GetJSONNumber(CouchbaseDocument.JSON_ATTRIBUTE_ID_LOW).GetIntValue());
            document.Load(jsonObject);

            return(document);
        }
Esempio n. 8
0
        public static LogicClientAvatar LoadHomeOwnerAvatarFromHome(LogicClientHome home)
        {
            string json = home.GetCompressibleHomeJSON().Get();

            if (json == null)
            {
                ZLibHelper.DecompressInMySQLFormat(home.GetCompressibleHomeJSON().GetCompressed(), out byte[] output);
                json = LogicStringUtil.CreateString(output, 0, output.Length);
            }

            LogicClientAvatar logicClientAvatar = new LogicClientAvatar();

            logicClientAvatar.LoadForReplay(LogicJSONParser.ParseObject(json), true);
            return(logicClientAvatar);
        }
        public static LogicJSONObject DownloadJSON(string path)
        {
            try
            {
                using (WebClient client = ServerHttpClient.CreateWebClient())
                {
                    return(LogicJSONParser.ParseObject(client.DownloadString(string.Format("{0}/{1}", ServerCore.ConfigurationServer, path))));
                }
            }
            catch (Exception)
            {
                Logging.Warning(string.Format("ServerHttpClient: file {0} doesn't exist", path));
            }

            return(null);
        }
        public override void Decode()
        {
            base.Decode();

            this.m_serverChecksum = this.m_stream.ReadInt();
            this.m_clientChecksum = this.m_stream.ReadInt();
            this.m_subtick        = this.m_stream.ReadInt();

            if (this.m_stream.ReadBoolean())
            {
                string json = this.m_stream.ReadString(900000);

                if (json != null)
                {
                    this.m_debugJSON = LogicJSONParser.ParseObject(json);
                }
            }
        }
 public void Decode(ByteStream stream)
 {
     this.ReadFromJSON(LogicJSONParser.ParseObject(stream.ReadString(900000) ?? string.Empty));
 }
Esempio n. 12
0
        public void LoadHomeState(LogicClientHome home, LogicAvatar homeOwnerAvatar, int secondsSinceLastSave, int villageType, int currentTimestamp,
                                  int secondsSinceLastMaintenance, int reengagementSeconds)
        {
            if (villageType == 2)
            {
                this.m_level.SetVillageType(villageType);
            }

            if (home != null)
            {
                this.m_state       = 1;
                this.m_villageType = villageType;

                if (LogicDataTables.GetGlobals().StartInLastUsedVillage())
                {
                    int lastUsedVillage = homeOwnerAvatar.GetVillageToGoTo();

                    if (!this.m_level.GetMissionManager().HasTravel(homeOwnerAvatar))
                    {
                        lastUsedVillage = 0;
                    }

                    if (lastUsedVillage < 0)
                    {
                        Debugger.Warning("VillageToGoTo<0");
                    }
                    else
                    {
                        if (lastUsedVillage > 1)
                        {
                            Debugger.Warning("VillageToGoTo too big");
                        }
                        else
                        {
                            this.m_level.SetVillageType(lastUsedVillage);
                        }
                    }
                }

                this.m_secondsSinceLastMaintenance = secondsSinceLastMaintenance;
                this.m_startTimestamp = currentTimestamp;
                this.m_configuration.Load(LogicJSONParser.ParseObject(home.GetGlobalJSON()));
                this.m_calendar.Load(home.GetCalendarJSON(), currentTimestamp);

                if (this.m_battleTimer != null)
                {
                    this.m_battleTimer.Destruct();
                    this.m_battleTimer = null;
                }

                this.m_level.SetHome(home, false);
                this.m_level.SetHomeOwnerAvatar(homeOwnerAvatar);
                this.m_level.FastForwardTime(secondsSinceLastSave);

                homeOwnerAvatar.SetLevel(this.m_level);

                this.m_level.ReengageLootCart(reengagementSeconds);
                this.m_level.LoadingFinished();

                this.m_shieldTime        = LogicTime.GetSecondsInTicks(home.GetShieldDurationSeconds());
                this.m_guardTime         = LogicTime.GetSecondsInTicks(home.GetGuardDurationSeconds());
                this.m_personalBreakTime = LogicTime.GetSecondsInTicks(home.GetPersonalBreakSeconds());

                int logicTime      = this.m_level.GetLogicTime().GetTick();
                int startGuardTime = logicTime;

                if (this.m_shieldTime >= logicTime)
                {
                    startGuardTime = this.m_shieldTime;
                }

                this.m_startGuardTime = startGuardTime;

                if (LogicDataTables.GetGlobals().UseVillageObjects())
                {
                    this.m_level.LoadVillageObjects();
                }
            }
        }
        public static void DownloadDataUpdate(string fingerprintJSON, string contentUrl)
        {
            LogicJSONObject     oldFingerprintJSON = LogicJSONParser.ParseObject(ResourceManager.FINGERPRINT_JSON);
            LogicJSONObject     newFingerprintJSON = LogicJSONParser.ParseObject(fingerprintJSON);
            LogicJSONArray      oldfileArray       = oldFingerprintJSON.GetJSONArray("files");
            LogicJSONArray      newfileArray       = newFingerprintJSON.GetJSONArray("files");
            List <DownloadTask> results            = new List <DownloadTask>();

            string fingerprintSha = newFingerprintJSON.GetJSONString("sha").GetStringValue();

            for (int i = 0; i < newfileArray.Size(); i++)
            {
                LogicJSONObject newFileObject = newfileArray.GetJSONObject(i);
                string          newFileName   = newFileObject.GetJSONString("file").GetStringValue();
                string          newFileSha    = newFileObject.GetJSONString("sha").GetStringValue();
                bool            needUpdate    = true;

                for (int j = 0; j < oldfileArray.Size(); j++)
                {
                    LogicJSONObject oldFileObject = oldfileArray.GetJSONObject(j);
                    string          oldFileName   = oldFileObject.GetJSONString("file").GetStringValue();

                    if (oldFileName == newFileName)
                    {
                        string oldFileSha = oldFileObject.GetJSONString("sha").GetStringValue();

                        if (oldFileSha == newFileSha)
                        {
                            needUpdate = false;
                        }

                        break;
                    }
                }

                if (needUpdate)
                {
                    results.Add(new DownloadTask(contentUrl, fingerprintSha, newFileName));
                }
            }

            bool success = true;

            for (int i = 0; i < results.Count; i++)
            {
                DownloadTask task = results[i];
                byte[]       data = task.Result;

                if (data != null)
                {
                    File.WriteAllBytes("assets/" + task.FileName, data);
                }
                else
                {
                    Debugger.Warning("ResourceManager.downloadDataUpdate: download file failed: " + task.FileName);
                    success = false;
                }
            }

            if (success)
            {
                File.WriteAllBytes("assets/fingerprint.json", LogicStringUtil.GetBytes(fingerprintJSON));
                ResourceManager.Init();
            }
        }