public void SendScenarioModules(bool highPriority) { lastScenarioSendTime = Client.realtimeSinceStartup; List <string> scenarioName = new List <string>(); List <byte[]> scenarioData = new List <byte[]>(); foreach (ScenarioModule sm in ScenarioRunner.GetLoadedModules()) { string scenarioType = sm.GetType().Name; if (!IsScenarioModuleAllowed(scenarioType)) { continue; } ConfigNode scenarioNode = new ConfigNode(); sm.Save(scenarioNode); byte[] scenarioBytes = configNodeSerializer.Serialize(scenarioNode); string scenarioHash = Common.CalculateSHA256Hash(scenarioBytes); if (scenarioBytes.Length == 0) { DarkLog.Debug("Error writing scenario data for " + scenarioType); continue; } if (checkData.ContainsKey(scenarioType) ? (checkData[scenarioType] == scenarioHash) : false) { //Data is the same since last time - Skip it. continue; } else { checkData[scenarioType] = scenarioHash; } if (scenarioBytes != null) { scenarioName.Add(scenarioType); scenarioData.Add(scenarioBytes); } } if (scenarioName.Count > 0) { if (highPriority) { networkWorker.SendScenarioModuleDataHighPriority(scenarioName.ToArray(), scenarioData.ToArray()); } else { networkWorker.SendScenarioModuleData(scenarioName.ToArray(), scenarioData.ToArray()); } } }
public void SendScenarioModules(bool highPriority) { lastScenarioSendTime = Client.realtimeSinceStartup; List <string> scenarioName = new List <string>(); List <ByteArray> scenarioData = new List <ByteArray>(); foreach (ScenarioModule sm in ScenarioRunner.GetLoadedModules()) { string scenarioType = sm.GetType().Name; if (!IsScenarioModuleAllowed(scenarioType)) { continue; } try { ConfigNode scenarioNode = new ConfigNode(); sm.Save(scenarioNode); ByteArray scenarioBytes = configNodeSerializer.Serialize(scenarioNode); string scenarioHash = Common.CalculateSHA256Hash(scenarioBytes); if (scenarioBytes.Length == 0) { DarkLog.Debug("Error writing scenario data for " + scenarioType); ByteRecycler.ReleaseObject(scenarioBytes); continue; } if (checkData.ContainsKey(scenarioType) ? (checkData[scenarioType] == scenarioHash) : false) { //Data is the same since last time - Skip it. ByteRecycler.ReleaseObject(scenarioBytes); continue; } else { checkData[scenarioType] = scenarioHash; } scenarioName.Add(scenarioType); scenarioData.Add(scenarioBytes); } catch (Exception e) { string fullName = sm.GetType().FullName; if (!warnedModules.Contains(fullName)) { DarkLog.Debug("Unable to save module data from " + fullName + ", skipping upload of this module. Exception: " + e); warnedModules.Add(fullName); if (!fullName.Contains("Expansions.Serenity.DeployedScience")) { ScreenMessages.PostScreenMessage("DMP was unable to save " + fullName + ", this module data will be lost.", 30f, ScreenMessageStyle.UPPER_CENTER); } } } } if (scenarioName.Count > 0) { if (highPriority) { networkWorker.SendScenarioModuleDataHighPriority(scenarioName.ToArray(), scenarioData.ToArray()); } else { networkWorker.SendScenarioModuleData(scenarioName.ToArray(), scenarioData.ToArray()); } } }