public DedicatedConfigDefinition( MyConfigDedicatedData<MyObjectBuilder_SessionSettings> definition ) { _definition = definition; //Limits = definition.SessionSettings.BlockTypeLimits.Dictionary; var dic = definition.SessionSettings.GetType().GetField("BlockTypeLimits", BindingFlags.Public | BindingFlags.Instance)?.GetValue(definition.SessionSettings) as SerializableDictionary<string, short>; Limits = dic?.Dictionary; }
/// <summary> /// Load the dedicated server configuration file /// </summary> /// <param name="fileInfo">Path to the configuration file</param> /// <exception cref="FileNotFoundException">Thrown if configuration file cannot be found at the path specified.</exception> /// <returns></returns> /// <exception cref="ConfigurationErrorsException">Configuration file not understood. See inner exception for details. Ignore configuration file line number in outer exception.</exception> public static MyConfigDedicatedData <MyObjectBuilder_SessionSettings> Load(FileInfo fileInfo) { object fileContent; string filePath = fileInfo.FullName; if (!File.Exists(filePath)) { throw new FileNotFoundException("Game configuration file not found.", filePath); } try { using (TextReader rdr = File.OpenText(filePath)) { XmlSerializer deserializer = new XmlSerializer(typeof(MyConfigDedicatedData <MyObjectBuilder_SessionSettings>)); MyConfigDedicatedData <MyObjectBuilder_SessionSettings> config = (MyConfigDedicatedData <MyObjectBuilder_SessionSettings>)deserializer.Deserialize(rdr); return(config); } } catch (Exception ex) { throw new ConfigurationErrorsException("Configuration file not understood. See inner exception for details. Ignore configuration file line number in outer exception.", ex, filePath, -1); } }
public void Load(string path = null) { if (string.IsNullOrEmpty(path)) { path = GetFilePath(); } if (!File.Exists(path)) { SetDefault(); return; } try { using (FileStream fs = File.OpenRead(path)) { m_data = (MyConfigDedicatedData <T>)m_serializer.Deserialize(fs); } } catch (Exception e) { if (MyLog.Default != null) { MyLog.Default.WriteLine("Exception during DS config load: " + e.ToString()); } SetDefault(); return; } }
public void Load(string path = null) { if (string.IsNullOrEmpty(path)) { path = this.GetFilePath(); } if (!File.Exists(path)) { this.SetDefault(); } else { try { using (FileStream stream = File.OpenRead(path)) { this.m_data = (MyConfigDedicatedData <T>) this.m_serializer.Deserialize(stream); } } catch (Exception exception) { if (MyLog.Default != null) { MyLog.Default.WriteLine("Exception during DS config load: " + exception.ToString()); } this.SetDefault(); return; } if (string.IsNullOrEmpty(this.ServerPasswordSalt) && string.IsNullOrEmpty(this.ServerPasswordHash)) { this.GenerateSalt(); } } }
public MyConfigDedicatedData <MyObjectBuilder_SessionSettings> LoadServerConfig( ) { /* * if ( !registered ) * { * registered = true; * MyObjectBuilderType.RegisterAssemblies( ); * }*/ if (File.Exists(System.IO.Path.Combine(Path, "SpaceEngineers-Dedicated.cfg.restart"))) { File.Copy(System.IO.Path.Combine(Path, "SpaceEngineers-Dedicated.cfg.restart"), System.IO.Path.Combine(Path, "SpaceEngineers-Dedicated.cfg"), true); File.Delete(System.IO.Path.Combine(Path, "SpaceEngineers-Dedicated.cfg.restart")); } if (File.Exists(System.IO.Path.Combine(Path, "SpaceEngineers-Dedicated.cfg"))) { MyConfigDedicatedData <MyObjectBuilder_SessionSettings> config = DedicatedConfigDefinition.Load(new FileInfo(System.IO.Path.Combine(Path, "SpaceEngineers-Dedicated.cfg"))); _dedicatedConfigDefinition = new DedicatedConfigDefinition(config); _cfgWatch = new FileSystemWatcher(Path, "*.cfg"); _cfgWatch.Changed += Config_Changed; _cfgWatch.NotifyFilter = NotifyFilters.Size; _cfgWatch.EnableRaisingEvents = true; return(config); } else { if (ExtenderOptions.IsDebugging) { ApplicationLog.BaseLog.Info("Failed to load session settings"); ApplicationLog.BaseLog.Info(Path); } return(null); } /* * FileInfo fileInfo = new FileInfo(Path + @"\SpaceEngineers-Dedicated.cfg"); * if (fileInfo.Exists) * { * if (!File.Exists(Path + @"\SpaceEngineers-Dedicated.cfg.restart")) * File.Copy(Path + @"\SpaceEngineers-Dedicated.cfg", Path + @"\SpaceEngineers-Dedicated.cfg.restart"); * * MyConfigDedicatedData config = DedicatedConfigDefinition.Load(fileInfo); * * FileInfo restartFileInfo = new FileInfo(Path + @"\SpaceEngineers-Dedicated.cfg.restart"); * * if (restartFileInfo.Exists) * config = DedicatedConfigDefinition.Load(restartFileInfo); * * _dedicatedConfigDefinition = new DedicatedConfigDefinition(config); * return config; * } * else * return null; */ }
public void LoadServerConfig() { FileInfo fileInfo = new FileInfo(Path + @"\SpaceEngineers-Dedicated.cfg"); if (fileInfo.Exists) { MyConfigDedicatedData config = DedicatedConfigDefinition.Load(fileInfo); m_dedicatedConfigDefinition = new DedicatedConfigDefinition(config); } }
public void SetConfigWorld(string worldName) { try { MyConfigDedicatedData config = GetServerConfig(); m_setConfigWorldName.Invoke(GetServerConfigContainer(), new object[] { worldName }); } catch (Exception ex) { LogManager.ErrorLog.WriteLine(ex); return; } }
public MyConfigDedicatedData LoadServerConfig() { FileInfo fileInfo = new FileInfo(Path + @"\SpaceEngineers-Dedicated.cfg.restart"); if (fileInfo.Exists) { File.Copy(Path + @"\SpaceEngineers-Dedicated.cfg.restart", Path + @"\SpaceEngineers-Dedicated.cfg", true); File.Delete(Path + @"\SpaceEngineers-Dedicated.cfg.restart"); } fileInfo = new FileInfo(Path + @"\SpaceEngineers-Dedicated.cfg"); if (fileInfo.Exists) { MyConfigDedicatedData config = DedicatedConfigDefinition.Load(fileInfo); m_dedicatedConfigDefinition = new DedicatedConfigDefinition(config); m_cfgWatch = new FileSystemWatcher(Path, "*.cfg"); m_cfgWatch.Changed += Config_Changed; m_cfgWatch.NotifyFilter = NotifyFilters.Size; m_cfgWatch.EnableRaisingEvents = true; return(config); } else { return(null); } /* * FileInfo fileInfo = new FileInfo(Path + @"\SpaceEngineers-Dedicated.cfg"); * if (fileInfo.Exists) * { * if (!File.Exists(Path + @"\SpaceEngineers-Dedicated.cfg.restart")) * File.Copy(Path + @"\SpaceEngineers-Dedicated.cfg", Path + @"\SpaceEngineers-Dedicated.cfg.restart"); * * MyConfigDedicatedData config = DedicatedConfigDefinition.Load(fileInfo); * * FileInfo restartFileInfo = new FileInfo(Path + @"\SpaceEngineers-Dedicated.cfg.restart"); * * if (restartFileInfo.Exists) * config = DedicatedConfigDefinition.Load(restartFileInfo); * * m_dedicatedConfigDefinition = new DedicatedConfigDefinition(config); * return config; * } * else * return null; */ }
private void Config_Changed(object sender, FileSystemEventArgs e) { if (!e.Name.Contains("SpaceEngineers-Dedicated.cfg") || e.Name.Contains("SpaceEngineers-Dedicated.cfg.restart")) { return; } if (!_serverRan) { return; } if (e.ChangeType == WatcherChangeTypes.Changed) { try { if (!File.Exists(Path + @"\SpaceEngineers-Dedicated.cfg.restart")) { ApplicationLog.BaseLog.Info("SpaceEngineers-Dedicated.cfg has changed updating configuration settings."); MyConfigDedicatedData <MyObjectBuilder_SessionSettings> changedConfig = DedicatedConfigDefinition.Load(new FileInfo(e.FullPath)); Config = new DedicatedConfigDefinition(changedConfig); } else { ApplicationLog.BaseLog.Info("SpaceEngineers-Dedicated.cfg has changed with existing restart file."); MyConfigDedicatedData <MyObjectBuilder_SessionSettings> restartConfig = DedicatedConfigDefinition.Load(new FileInfo(Path + @"\SpaceEngineers-Dedicated.cfg.restart")); MyConfigDedicatedData <MyObjectBuilder_SessionSettings> changedConfig = DedicatedConfigDefinition.Load(new FileInfo(e.FullPath)); restartConfig.Mods = restartConfig.Mods.Union(changedConfig.Mods).ToList( ); restartConfig.Banned = changedConfig.Banned.Union(changedConfig.Banned).ToList( ); restartConfig.Administrators = changedConfig.Administrators.Union(changedConfig.Administrators).ToList( ); DedicatedConfigDefinition config = new DedicatedConfigDefinition(restartConfig); config.Save(new FileInfo(Path + @"\SpaceEngineers-Dedicated.cfg.restart")); Config = config; } } catch (Exception ex) { ApplicationLog.BaseLog.Error("Error on configuration change ({1})", e.FullPath); ApplicationLog.BaseLog.Error(ex); } } }
public MyConfigDedicatedData <MyObjectBuilder_SessionSettings> LoadServerConfig( ) { if (File.Exists(System.IO.Path.Combine(Path, "SpaceEngineers-Dedicated.cfg.restart"))) { File.Copy(System.IO.Path.Combine(Path, "SpaceEngineers-Dedicated.cfg.restart"), System.IO.Path.Combine(Path, "SpaceEngineers-Dedicated.cfg"), true); File.Delete(System.IO.Path.Combine(Path, "SpaceEngineers-Dedicated.cfg.restart")); } if (File.Exists(System.IO.Path.Combine(Path, "SpaceEngineers-Dedicated.cfg"))) { MyConfigDedicatedData <MyObjectBuilder_SessionSettings> config = DedicatedConfigDefinition.Load(new FileInfo(System.IO.Path.Combine(Path, "SpaceEngineers-Dedicated.cfg"))); _dedicatedConfigDefinition = new DedicatedConfigDefinition(config); _cfgWatch = new FileSystemWatcher(Path, "*.cfg"); _cfgWatch.Changed += Config_Changed; _cfgWatch.NotifyFilter = NotifyFilters.Size; _cfgWatch.EnableRaisingEvents = true; return(config); } else { return(null); } /* * FileInfo fileInfo = new FileInfo(Path + @"\SpaceEngineers-Dedicated.cfg"); * if (fileInfo.Exists) * { * if (!File.Exists(Path + @"\SpaceEngineers-Dedicated.cfg.restart")) * File.Copy(Path + @"\SpaceEngineers-Dedicated.cfg", Path + @"\SpaceEngineers-Dedicated.cfg.restart"); * * MyConfigDedicatedData config = DedicatedConfigDefinition.Load(fileInfo); * * FileInfo restartFileInfo = new FileInfo(Path + @"\SpaceEngineers-Dedicated.cfg.restart"); * * if (restartFileInfo.Exists) * config = DedicatedConfigDefinition.Load(restartFileInfo); * * _dedicatedConfigDefinition = new DedicatedConfigDefinition(config); * return config; * } * else * return null; */ }
private void Config_Changed(object sender, FileSystemEventArgs e) { if (!e.Name.Contains("SpaceEngineers-Dedicated.cfg") || e.Name.Contains("SpaceEngineers-Dedicated.cfg.restart")) { return; } if (!m_serverRan) { return; } if (e.ChangeType == WatcherChangeTypes.Changed) { try { if (!File.Exists(Path + @"\SpaceEngineers-Dedicated.cfg.restart")) { LogManager.APILog.WriteLineAndConsole(string.Format("SpaceEngineers-Dedicated.cfg has changed updating configuration settings.")); MyConfigDedicatedData changedConfig = DedicatedConfigDefinition.Load(new FileInfo(e.FullPath)); Config = new DedicatedConfigDefinition(changedConfig); } else { LogManager.APILog.WriteLineAndConsole(string.Format("SpaceEngineers-Dedicated.cfg has changed with existing restart file.")); MyConfigDedicatedData restartConfig = DedicatedConfigDefinition.Load(new FileInfo(Path + @"\SpaceEngineers-Dedicated.cfg.restart")); MyConfigDedicatedData changedConfig = DedicatedConfigDefinition.Load(new FileInfo(e.FullPath)); restartConfig.Mods = restartConfig.Mods.Union(changedConfig.Mods).ToList(); restartConfig.Banned = changedConfig.Banned.Union(changedConfig.Banned).ToList(); restartConfig.Administrators = changedConfig.Administrators.Union(changedConfig.Administrators).ToList(); DedicatedConfigDefinition config = new DedicatedConfigDefinition(restartConfig); config.Save(new FileInfo(Path + @"\SpaceEngineers-Dedicated.cfg.restart")); Config = config; } } catch (Exception ex) { LogManager.APILog.WriteLineAndConsole(string.Format("Error on configuration change ({1}): {0}", e.FullPath, ex.ToString())); } } }
public void UpdateSessionSettings( ) { MyConfigDedicatedData <MyObjectBuilder_SessionSettings> config = Server.Instance.LoadServerConfig( ); ApplicationLog.BaseLog.Info("Loading Session Settings"); try { string worldPath = config.LoadWorld; ulong fileSize; m_checkPoint = LoadSandbox(worldPath, out fileSize); if (m_checkPoint == null) { return; } m_checkPoint.Settings = config.SessionSettings; m_checkPoint.Scenario = config.Scenario; m_checkPoint.Mods.Clear( ); foreach (ulong modid in config.Mods) { m_checkPoint.Mods.Add(new MyObjectBuilder_Checkpoint.ModItem(modid)); } File.Copy(Path.Combine(worldPath, "Sandbox.sbc"), Path.Combine(worldPath, "Sandbox.sbc.bak"), true); SaveSandbox(m_checkPoint, worldPath, out fileSize); ApplicationLog.BaseLog.Info("{0}Max Players: {1}", Environment.NewLine, m_checkPoint.Settings.MaxPlayers); ApplicationLog.BaseLog.Info("OnlineMode: {0}", m_checkPoint.Settings.OnlineMode); ApplicationLog.BaseLog.Info("GameMode: {0}", m_checkPoint.Settings.GameMode); ApplicationLog.BaseLog.Info("Scenario: {0}", m_checkPoint.Scenario.SubtypeId); ApplicationLog.BaseLog.Info("World Size: {0}{1}", m_checkPoint.Settings.WorldSizeKm, Environment.NewLine); } catch (Exception ex) { if (ExtenderOptions.IsDebugging) { ApplicationLog.BaseLog.Error(ex, "Session Manager Exception: {0}"); } } }
public void UpdateSessionSettings() { ulong fileSize = 0UL; MyConfigDedicatedData config = Server.Instance.LoadServerConfig(); Console.WriteLine("Loading Session Settings"); try { var worldPath = config.LoadWorld; m_checkPoint = LoadSandbox(worldPath, out fileSize); if (m_checkPoint == null) { return; } m_checkPoint.Settings = config.SessionSettings; m_checkPoint.Scenario = config.Scenario; m_checkPoint.Mods.Clear(); foreach (ulong modid in config.Mods) { m_checkPoint.Mods.Add(new MyObjectBuilder_Checkpoint.ModItem(modid)); } File.Copy(worldPath + "\\Sandbox.sbc", worldPath + "\\Sandbox.sbc.bak", true); SaveSandbox(m_checkPoint, worldPath, out fileSize); Console.WriteLine(Environment.NewLine + "Max Players: " + m_checkPoint.Settings.MaxPlayers); Console.WriteLine("OnlineMode: " + m_checkPoint.Settings.OnlineMode); Console.WriteLine("GameMode: " + m_checkPoint.Settings.GameMode); Console.WriteLine("Scenario: " + m_checkPoint.Scenario.SubtypeId); Console.WriteLine("World Size: " + m_checkPoint.Settings.WorldSizeKm + Environment.NewLine); } catch (Exception ex) { LogManager.ErrorLog.WriteLineAndConsole("Session Manager Exception: " + ex.ToString()); return; } }
public MyConfigDedicatedData GetServerConfig() { try { Object configContainer = GetServerConfigContainer(); MyConfigDedicatedData config = (MyConfigDedicatedData)BaseObject.GetEntityFieldValue(configContainer, ConfigContainerDedicatedDataField); if (config == null) { BaseObject.InvokeEntityMethod(configContainer, ConfigContainerGetConfigDataMethod); config = (MyConfigDedicatedData)BaseObject.GetEntityFieldValue(configContainer, ConfigContainerDedicatedDataField); } return(config); } catch (Exception ex) { LogManager.ErrorLog.WriteLine(ex); return(null); } }
public bool LoadServerConfig() { FileInfo fileInfo = new FileInfo(Path + @"\SpaceEngineers-Dedicated.cfg"); if (fileInfo.Exists) { try { MyConfigDedicatedData config = DedicatedConfigDefinition.Load(fileInfo); m_dedicatedConfigDefinition = new DedicatedConfigDefinition(config); } catch (GameInstallationInfoException ex) { LogManager.APILog.WriteLineAndConsole("GameInstallationInfoException - " + ex.StateRepresentation[ex.ExceptionStateId] + " File: " + ex.AdditionnalInfo); LogManager.ErrorLog.WriteLine("GameInstallationInfoException - " + ex.StateRepresentation[ex.ExceptionStateId] + " File: " + ex.AdditionnalInfo); return(false); } } return(true); }
public MyConfigDedicatedData GetServerConfig() { try { Object configContainer = GetServerConfigContainer(); MyConfigDedicatedData config = (MyConfigDedicatedData)m_configContainerDedicatedDataField.GetValue(configContainer); if (config == null) { MethodInfo loadConfigDataMethod = m_configContainerField.FieldType.GetMethod(ConfigContainerGetConfigData, BindingFlags.Public | BindingFlags.Instance); loadConfigDataMethod.Invoke(configContainer, new object[] { }); config = (MyConfigDedicatedData)m_configContainerDedicatedDataField.GetValue(configContainer); } return(config); } catch (Exception ex) { LogManager.ErrorLog.WriteLine(ex); return(null); } }
void SetDefault() { m_data = new MyConfigDedicatedData <T>(); }
public DedicatedConfigDefinition( MyConfigDedicatedData<MyObjectBuilder_SessionSettings> definition ) { _definition = definition; }
public DedicatedConfigDefinition(MyConfigDedicatedData definition) { m_definition = definition; Changed = false; }
public DedicatedConfigDefinition( MyConfigDedicatedData definition ) { _definition = definition; }
private void SetDefault() { this.m_data = new MyConfigDedicatedData <T>(); this.GenerateSalt(); this.GenerateRemoteSecurityKey(); }
public DedicatedConfigDefinition(MyConfigDedicatedData definition) { _definition = definition; }
public DedicatedConfigDefinition(MyConfigDedicatedData <MyObjectBuilder_SessionSettings> definition) { _definition = definition; }