/// <summary> /// Loads resources file. /// </summary> private static void LoadResources() { ResourceManager.ContentUrlList = new LogicArrayList <string>(); ResourceManager.ChronosContentUrlList = new LogicArrayList <string>(); ResourceManager.AppStoreUrlList = new LogicArrayList <string>(); string resourceFile = WebManager.DownloadConfigString("/res/resources.json"); if (resourceFile != null) { LogicJSONObject jsonObject = (LogicJSONObject)LogicJSONParser.Parse(resourceFile); LogicJSONArray contentArray = jsonObject.GetJSONArray("content"); LogicJSONArray chronosContentArray = jsonObject.GetJSONArray("chronosContent"); LogicJSONArray appStoreArray = jsonObject.GetJSONArray("appstore"); for (int i = 0; i < contentArray.Size(); i++) { ResourceManager.ContentUrlList.Add(contentArray.GetJSONString(i).GetStringValue()); } for (int i = 0; i < chronosContentArray.Size(); i++) { ResourceManager.ChronosContentUrlList.Add(chronosContentArray.GetJSONString(i).GetStringValue()); } for (int i = 0; i < appStoreArray.Size(); i++) { ResourceManager.AppStoreUrlList.Add(appStoreArray.GetJSONString(i).GetStringValue()); } } else { Debugger.Error("ResourceManager::loadResources resources.json not exist"); } }
/// <summary> /// Loads this instance from json. /// </summary> internal void Load(string json) { LogicJSONObject jsonObject = (LogicJSONObject)LogicJSONParser.Parse(json); this.Id = new LogicLong(LogicJSONHelper.GetJSONNumber(jsonObject, "id_hi"), LogicJSONHelper.GetJSONNumber(jsonObject, "id_lo")); this.PassToken = LogicJSONHelper.GetJSONString(jsonObject, "pass_t"); this.PlayTimeSecs = LogicJSONHelper.GetJSONNumber(jsonObject, "pt_secs"); this.AccountCreatedDate = LogicJSONHelper.GetJSONString(jsonObject, "acc_cr"); this.TotalBan = LogicJSONHelper.GetJSONNumber(jsonObject, "t_ban"); LogicJSONArray sessionArray = jsonObject.GetJSONArray("sessions"); if (sessionArray != null) { int size = LogicMath.Min(sessionArray.Size(), 20); for (int i = 0; i < size; i++) { LogicJSONObject obj = sessionArray.GetJSONObject(i); AccountSession session = new AccountSession(); session.Load(obj); this.LastSessions.Add(session); } } LogicJSONObject banObject = jsonObject.GetJSONObject("ban"); if (banObject != null) { this.CurrentBan = new AccountBan(); this.CurrentBan.Load(banObject); } }
private static void LoadFingerprint() { ResourceManager.FINGERPRINT_JSON = ResourceManager.LoadAssetString("fingerprint.json"); if (ResourceManager.FINGERPRINT_JSON != null) { LogicJSONObject jsonObject = (LogicJSONObject)LogicJSONParser.Parse(ResourceManager.FINGERPRINT_JSON); ResourceManager.FINGERPRINT_SHA = LogicJSONHelper.GetString(jsonObject, "sha"); ResourceManager.FINGERPRINT_VERSION = LogicJSONHelper.GetString(jsonObject, "version"); string[] version = ResourceManager.FINGERPRINT_VERSION.Split('.'); if (version.Length == 3) { ResourceManager.m_version = new int[3]; for (int i = 0; i < 3; i++) { ResourceManager.m_version[i] = int.Parse(version[i]); } } else { Logging.Error("ResourceManager.loadFingerprint: invalid fingerprint version: " + ResourceManager.FINGERPRINT_VERSION); } ZLibHelper.CompressInZLibFormat(LogicStringUtil.GetBytes(ResourceManager.FINGERPRINT_JSON), out ResourceManager.COMPRESSED_FINGERPRINT_DATA); } else { Logging.Error("ResourceManager.loadFingerprint: fingerprint.json not exist"); } }
public void LoadNpcDuelState(LogicClientHome home, LogicAvatar homeOwnerAvatar, LogicAvatar visitorAvatar, int currentTimestamp, int secondsSinceLastSave) { if (this.m_state != 0) { Debugger.Error("loadNpcDuelState called from invalid state"); } else { this.m_state = 2; this.m_startTimestamp = currentTimestamp; this.m_configuration.Load((LogicJSONObject)LogicJSONParser.Parse(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.SetMatchType(9, null); this.m_level.SetVillageType(1); this.m_level.SetHome(home, false); this.m_level.SetHomeOwnerAvatar(homeOwnerAvatar); this.m_level.SetVisitorAvatar(visitorAvatar); this.m_level.FastForwardTime(secondsSinceLastSave); this.m_level.LoadingFinished(); this.m_replay = new LogicReplay(this.m_level); } }
/// <summary> /// Loads the fingerprint file. /// </summary> private static void LoadFingeprint() { ResourceManager.FingerprintJson = ResourceManager.LoadAssetFile("fingerprint.json"); if (ResourceManager.FingerprintJson != null) { LogicJSONObject jsonObject = (LogicJSONObject)LogicJSONParser.Parse(ResourceManager.FingerprintJson); ResourceManager.FingerprintSha = LogicJSONHelper.GetJSONString(jsonObject, "sha"); ResourceManager.FingerprintVersion = LogicJSONHelper.GetJSONString(jsonObject, "version"); string[] version = ResourceManager.FingerprintVersion.Split('.'); if (version.Length == 3) { ResourceManager._version = new int[3]; for (int i = 0; i < 3; i++) { ResourceManager._version[i] = int.Parse(version[i]); } } else { Debugger.Error("ResourceManager::loadFingeprint invalid fingerprint version: " + ResourceManager.FingerprintVersion); } ZLibHelper.CompressInZLibFormat(LogicStringUtil.GetBytes(ResourceManager.FingerprintJson), out ResourceManager.CompressedFingeprintJson); } else { Debugger.Error("ResourceManager::loadFingeprint fingerprint.json not exist"); } }
/// <summary> /// Laods the calendar. /// </summary> public void Load(string json, int activeTimestamp) { Debugger.DoAssert(json != null, "Event json NULL"); if (json.Length > 0) { LogicJSONObject jsonObject = (LogicJSONObject)LogicJSONParser.Parse(json); if (jsonObject != null) { LogicJSONArray eventArray = jsonObject.GetJSONArray("events"); if (eventArray != null) { for (int i = 0; i < eventArray.Size(); i++) { LogicJSONObject calendarObject = eventArray.GetJSONObject(i); if (calendarObject != null) { } else { Debugger.Error("Events json malformed!"); } } } } else { Debugger.Error("Events json malformed!"); } } }
/// <summary> /// Initializes this instance. /// </summary> internal static void Initialize() { ResourceManager.FingerprintJson = File.ReadAllText("Assets/fingerprint.json"); LogicJSONObject jsonObject = (LogicJSONObject)LogicJSONParser.Parse(ResourceManager.FingerprintJson); ResourceManager.FingerprintSha = LogicJSONHelper.GetJSONString(jsonObject, "sha"); ResourceManager.FingerprintVersion = LogicJSONHelper.GetJSONString(jsonObject, "version"); }
/// <summary> /// Loads the account info from json. /// </summary> internal void LoadAccount() { if (File.Exists("Files/save.json")) { LogicJSONObject jsonRoot = (LogicJSONObject)LogicJSONParser.Parse(File.ReadAllText("Files/save.json")); this._account.AccountHighId = LogicJSONHelper.GetJSONNumber(jsonRoot, "High"); this._account.AccountLowId = LogicJSONHelper.GetJSONNumber(jsonRoot, "Low"); this._account.AccountPassToken = LogicJSONHelper.GetJSONString(jsonRoot, "Pass"); } }
/// <summary> /// Loads this instance from json. /// </summary> internal void Load(string json) { LogicJSONObject jsonObject = (LogicJSONObject)LogicJSONParser.Parse(json); this.Id = new LogicLong(LogicJSONHelper.GetJSONNumber(jsonObject, "id_hi"), LogicJSONHelper.GetJSONNumber(jsonObject, "id_lo")); LogicJSONObject entryObject = jsonObject.GetJSONObject("entry"); if (entryObject != null) { this.AvatarEntry.Load(entryObject); } }
public void LoadDirectAttackState(LogicClientHome home, LogicAvatar homeOwnerAvatar, LogicAvatar visitorAvatar, int secondsSinceLastSave, bool war, bool village2, int currentTimestamp) { if (this.m_state != 0) { Debugger.Error("loadAttackState called from invalid state"); } this.m_state = 2; this.m_startTimestamp = currentTimestamp; this.m_configuration.Load((LogicJSONObject)LogicJSONParser.Parse(home.GetGlobalJSON())); this.m_calendar.Load(home.GetCalendarJSON(), currentTimestamp); if (this.m_battleTimer != null) { this.m_battleTimer.Destruct(); this.m_battleTimer = null; } this.m_battleTimer = new LogicTimer(); this.m_battleTimer.StartTimer( LogicDataTables.GetGlobals().GetAttackLengthSecs() + (village2 ? LogicDataTables.GetGlobals().GetAttackVillage2PreparationLengthSecs() : LogicDataTables.GetGlobals().GetAttackPreparationLengthSecs()), this.m_level.GetLogicTime(), false, -1); if (!homeOwnerAvatar.IsClientAvatar()) { Debugger.Error("loadDirectAttackState called and home owner is not client avatar"); } this.m_level.SetMatchType(village2 ? 8 : war ? 7 : 3, null); if (village2) { this.m_level.SetVillageType(1); } this.m_level.SetHome(home, false); this.m_level.SetHomeOwnerAvatar(homeOwnerAvatar); homeOwnerAvatar.SetLevel(this.m_level); this.m_level.SetVisitorAvatar(visitorAvatar); this.m_level.FastForwardTime(secondsSinceLastSave); this.m_level.LoadingFinished(); this.m_replay = new LogicReplay(this.m_level); }
/// <summary> /// Verifies the version of assets. /// </summary> private static void VerifyAssets() { string json = ResourceManager.LoadAssetFile("fingerprint.json"); if (json != null) { LogicJSONObject jsonObject = (LogicJSONObject)LogicJSONParser.Parse(json); LogicJSONString shaObject = jsonObject.GetJSONString("sha"); string lastSha = WebManager.DownloadConfigString("/sha"); if (shaObject.GetStringValue() != lastSha) { ResourceManager.DownloadLastAssets(jsonObject); } } else { ResourceManager.DownloadLastAssets(null); } }
private static void LoadCurrentFingerprint() { LogicJSONObject jsonObject = (LogicJSONObject)LogicJSONParser.Parse(File.ReadAllText("assets/fingerprint.json")); LogicJSONString versionString = jsonObject.GetJSONString("version"); if (!string.IsNullOrEmpty(versionString.GetStringValue())) { string[] version = versionString.GetStringValue().Split('.'); if (version.Length == 3) { Program.m_currentVersion = new int[3]; for (int i = 0; i < 3; i++) { Program.m_currentVersion[i] = int.Parse(version[i]); } } } Program.m_currentSha = jsonObject.GetJSONString("sha").GetStringValue(); }
public void LoadVisitState(LogicClientHome home, LogicAvatar homeOwnerAvatar, LogicAvatar visitorAvatar, int currentTimestamp, int secondsSinceLastSave) { if (this.m_state != 0) { Debugger.Error("loadVisitState called from invalid state"); } else { this.m_state = 4; this.m_startTimestamp = currentTimestamp; this.m_configuration.Load((LogicJSONObject)LogicJSONParser.Parse(home.GetGlobalJSON())); this.m_calendar.Load(home.GetCalendarJSON(), currentTimestamp); this.m_level.SetNpcVillage(homeOwnerAvatar.IsNpcAvatar()); this.m_level.SetHome(home, false); this.m_level.SetHomeOwnerAvatar(homeOwnerAvatar); this.m_level.SetVisitorAvatar(visitorAvatar); this.m_level.FastForwardTime(secondsSinceLastSave); homeOwnerAvatar.SetLevel(this.m_level); this.m_level.LoadingFinished(); } }
public void Load(string json, int activeTimestamp) { Debugger.DoAssert(json != null, "Event json NULL"); if (json.Length > 0) { LogicJSONObject jsonObject = (LogicJSONObject)LogicJSONParser.Parse(json); if (jsonObject != null) { LogicArrayList <LogicCalendarEvent> events = new LogicArrayList <LogicCalendarEvent>(); LogicJSONArray eventArray = jsonObject.GetJSONArray("events"); if (eventArray != null) { for (int i = 0; i < eventArray.Size(); i++) { LogicJSONObject calendarObject = eventArray.GetJSONObject(i); if (calendarObject == null) { Debugger.Error("Events json malformed!"); } events.Add(LogicCalendarEventFactory.LoadFromJSON(calendarObject, null)); } } this.LoadingFinished(events, activeTimestamp); } else { Debugger.Error("Events json malformed!"); } } }
/// <summary> /// Loads the home state. /// </summary> public void LoadHomeState(LogicClientHome home, LogicAvatar homeOwnerAvatar, int currentTimestamp, int secondsSinceLastSave, int secondsSinceLastMaintenance) { if (home != null) { this._state = 1; if (LogicDataTables.GetGlobals().StartInLastUsedVillage()) { int lastUsedVillage = homeOwnerAvatar.GetVillageToGoTo(); if (!this._level.GetMissionManager().HasTravel(homeOwnerAvatar)) { lastUsedVillage = 0; } if (lastUsedVillage < 0) { Debugger.Warning("VillageToGoTo<0"); } else { if (lastUsedVillage > 1) { Debugger.Warning("VillageToGoTo too big"); } else { this._level.SetVillageType(lastUsedVillage); } } } this._secondsSinceLastMaintenance = secondsSinceLastMaintenance; this._currentTimestamp = currentTimestamp; this._configuration.Load((LogicJSONObject)LogicJSONParser.Parse(home.GetGlobalJSON())); this._calendar.Load(home.GetCalendarJSON(), currentTimestamp); if (this._battleTimer != null) { this._battleTimer.Destruct(); this._battleTimer = null; } this._level.SetHome(home, true); this._level.SetHomeOwnerAvatar(homeOwnerAvatar); this._level.FastForwardTime(secondsSinceLastSave); homeOwnerAvatar.SetLevel(this._level); this._level.LoadingFinished(); this._shieldTime = LogicTime.GetSecondsInTicks(home.GetShieldDurationSeconds()); this._guardTime = LogicTime.GetSecondsInTicks(home.GetGuardDurationSeconds()); this._maintenanceTime = LogicTime.GetSecondsInTicks(home.GetNextMaintenanceSeconds()); int logicTime = this._level.GetLogicTime(); int startGuardTime = logicTime; if (this._shieldTime >= logicTime) { startGuardTime = this._shieldTime; } this._startGuardTime = startGuardTime; if (LogicDataTables.GetGlobals().UseVillageObjects()) { this._level.LoadVillageObjects(); } } }
/// <summary> /// Downloads assets from config server. /// </summary> private static void DownloadAssets(LogicJSONObject currentFingerprint, string fingerprint) { LogicJSONArray currentFileArray = currentFingerprint?.GetJSONArray("files"); LogicJSONObject jsonObject = (LogicJSONObject)LogicJSONParser.Parse(fingerprint); LogicJSONArray fileArray = jsonObject.GetJSONArray("files"); if (currentFileArray != null) { if (fileArray.Size() != currentFileArray.Size()) { currentFileArray = null; } } string shaFingerprint = LogicJSONHelper.GetJSONString(jsonObject, "sha"); Logging.Print("Download " + shaFingerprint + " assets..."); Parallel.For(0, fileArray.Size(), new ParallelOptions { MaxDegreeOfParallelism = 4 }, i => { LogicJSONObject fileObject = fileArray.GetJSONObject(i); if (fileObject != null) { string fileName = LogicJSONHelper.GetJSONString(fileObject, "file"); string sha = LogicJSONHelper.GetJSONString(fileObject, "sha"); if (currentFileArray != null) { for (int j = 0; j < currentFileArray.Size(); j++) { LogicJSONObject currentFileObject = currentFileArray.GetJSONObject(j); LogicJSONString currentFileNameObject = currentFileObject.GetJSONString("file"); if (fileName == currentFileNameObject.GetStringValue()) { LogicJSONString currentShaObject = currentFileObject.GetJSONString("sha"); if (sha == currentShaObject.GetStringValue()) { return; } } } } WebClient client = new WebClient(); byte[] data = client.DownloadData(ServiceCore.ConfigurationServer + "/assets/" + shaFingerprint + "/" + fileName); client.Dispose(); if (data != null) { Logging.Print("file " + fileName + " downloaded"); switch (Path.GetExtension(fileName)) { case ".csv": using (MemoryStream inputStream = new MemoryStream(data)) { using (MemoryStream outputStream = new MemoryStream()) { Decoder decompresser = new Decoder(); byte[] properties = new byte[5]; byte[] fileLengthBytes = new byte[4]; inputStream.Read(properties, 0, 5); inputStream.Read(fileLengthBytes, 0, 4); int fileLength = fileLengthBytes[0] | fileLengthBytes[1] << 8 | fileLengthBytes[2] << 16 | fileLengthBytes[3] << 24; decompresser.SetDecoderProperties(properties); decompresser.Code(inputStream, outputStream, inputStream.Length, fileLength, null); data = outputStream.ToArray(); } } break; } Directory.CreateDirectory("Assets/" + fileName.Replace(Path.GetFileName(fileName), string.Empty)); File.WriteAllBytes("Assets/" + fileName, data); } else { Logging.Warning("file " + fileName + " not exist"); } } }); File.WriteAllText("Assets/fingerprint.json", fingerprint); Logging.Print("Download completed"); }
/// <summary> /// Loads the service config. /// </summary> private static void LoadConfig() { string json = WebManager.DownloadConfigString("/core/services.json"); if (json != null) { LogicJSONObject jsonObject = (LogicJSONObject)LogicJSONParser.Parse(json); LogicJSONString versionObject = jsonObject.GetJSONString("version"); if (versionObject != null) { ServiceSettings._serviceVersion = versionObject.GetStringValue(); } LogicJSONObject nodeObject = jsonObject.GetJSONObject("node"); if (nodeObject != null) { LogicJSONArray proxyArray = nodeObject.GetJSONArray("proxy"); if (proxyArray != null) { ServiceSettings._serviceIPs[1] = new string[proxyArray.Size()]; for (int i = 0; i < proxyArray.Size(); i++) { ServiceSettings._serviceIPs[1][i] = proxyArray.GetJSONString(i).GetStringValue(); } } LogicJSONArray accountArray = nodeObject.GetJSONArray("account"); if (accountArray != null) { ServiceSettings._serviceIPs[2] = new string[accountArray.Size()]; for (int i = 0; i < accountArray.Size(); i++) { ServiceSettings._serviceIPs[2][i] = accountArray.GetJSONString(i).GetStringValue(); } } LogicJSONArray globalArray = nodeObject.GetJSONArray("global_chat"); if (globalArray != null) { ServiceSettings._serviceIPs[6] = new string[globalArray.Size()]; for (int i = 0; i < globalArray.Size(); i++) { ServiceSettings._serviceIPs[6][i] = globalArray.GetJSONString(i).GetStringValue(); } } LogicJSONArray avatarArray = nodeObject.GetJSONArray("avatar"); if (avatarArray != null) { ServiceSettings._serviceIPs[9] = new string[avatarArray.Size()]; for (int i = 0; i < avatarArray.Size(); i++) { ServiceSettings._serviceIPs[9][i] = avatarArray.GetJSONString(i).GetStringValue(); } } LogicJSONArray homeArray = nodeObject.GetJSONArray("zone"); if (homeArray != null) { ServiceSettings._serviceIPs[10] = new string[homeArray.Size()]; for (int i = 0; i < homeArray.Size(); i++) { ServiceSettings._serviceIPs[10][i] = homeArray.GetJSONString(i).GetStringValue(); } } LogicJSONArray allianceArray = nodeObject.GetJSONArray("party"); if (allianceArray != null) { ServiceSettings._serviceIPs[11] = new string[allianceArray.Size()]; for (int i = 0; i < allianceArray.Size(); i++) { ServiceSettings._serviceIPs[11][i] = allianceArray.GetJSONString(i).GetStringValue(); } } LogicJSONArray leagueArray = nodeObject.GetJSONArray("ranking"); if (leagueArray != null) { ServiceSettings._serviceIPs[13] = new string[leagueArray.Size()]; for (int i = 0; i < leagueArray.Size(); i++) { ServiceSettings._serviceIPs[13][i] = leagueArray.GetJSONString(i).GetStringValue(); } } LogicJSONArray battleArray = nodeObject.GetJSONArray("battle"); if (battleArray != null) { ServiceSettings._serviceIPs[27] = new string[battleArray.Size()]; for (int i = 0; i < battleArray.Size(); i++) { ServiceSettings._serviceIPs[27][i] = battleArray.GetJSONString(i).GetStringValue(); } } } LogicJSONObject databaseObject = jsonObject.GetJSONObject("database"); if (databaseObject != null) { LogicJSONArray urls = databaseObject.GetJSONArray("urls"); if (urls != null) { ServiceSettings._databaseUrls = new string[urls.Size()]; for (int i = 0; i < urls.Size(); i++) { ServiceSettings._databaseUrls[i] = urls.GetJSONString(i).GetStringValue(); } } ServiceSettings._databaseUser = LogicJSONHelper.GetJSONString(databaseObject, "user"); ServiceSettings._databasePassword = LogicJSONHelper.GetJSONString(databaseObject, "pass"); } } }