Update instance manager for new config format
This commit is contained in:
@@ -119,8 +119,8 @@ namespace Torch.Server.Managers
|
||||
{
|
||||
DedicatedConfig.Mods.Clear();
|
||||
//remove the Torch mod to avoid running multiple copies of it
|
||||
DedicatedConfig.SelectedWorld.Checkpoint.Mods.RemoveAll(m => m.PublishedFileId == TorchModCore.MOD_ID);
|
||||
foreach (var m in DedicatedConfig.SelectedWorld.Checkpoint.Mods)
|
||||
DedicatedConfig.SelectedWorld.WorldConfiguration.Mods.RemoveAll(m => m.PublishedFileId == TorchModCore.MOD_ID);
|
||||
foreach (var m in DedicatedConfig.SelectedWorld.WorldConfiguration.Mods)
|
||||
DedicatedConfig.Mods.Add(new ModItemInfo(m));
|
||||
Task.Run(() => DedicatedConfig.UpdateAllModInfosAsync());
|
||||
}
|
||||
@@ -134,8 +134,8 @@ namespace Torch.Server.Managers
|
||||
{
|
||||
DedicatedConfig.Mods.Clear();
|
||||
//remove the Torch mod to avoid running multiple copies of it
|
||||
DedicatedConfig.SelectedWorld.Checkpoint.Mods.RemoveAll(m => m.PublishedFileId == TorchModCore.MOD_ID);
|
||||
foreach (var m in DedicatedConfig.SelectedWorld.Checkpoint.Mods)
|
||||
DedicatedConfig.SelectedWorld.WorldConfiguration.Mods.RemoveAll(m => m.PublishedFileId == TorchModCore.MOD_ID);
|
||||
foreach (var m in DedicatedConfig.SelectedWorld.WorldConfiguration.Mods)
|
||||
DedicatedConfig.Mods.Add(new ModItemInfo(m));
|
||||
Task.Run(() => DedicatedConfig.UpdateAllModInfosAsync());
|
||||
}
|
||||
@@ -149,7 +149,7 @@ namespace Torch.Server.Managers
|
||||
private void ImportWorldConfig(WorldViewModel world, bool modsOnly = true)
|
||||
{
|
||||
var mods = new MtObservableList<ModItemInfo>();
|
||||
foreach (var mod in world.Checkpoint.Mods)
|
||||
foreach (var mod in world.WorldConfiguration.Mods)
|
||||
mods.Add(new ModItemInfo(mod));
|
||||
DedicatedConfig.Mods = mods;
|
||||
|
||||
@@ -157,7 +157,7 @@ namespace Torch.Server.Managers
|
||||
Log.Debug("Loaded mod list from world");
|
||||
|
||||
if (!modsOnly)
|
||||
DedicatedConfig.SessionSettings = world.Checkpoint.Settings;
|
||||
DedicatedConfig.SessionSettings = world.WorldConfiguration.Settings;
|
||||
}
|
||||
|
||||
private void ImportWorldConfig(bool modsOnly = true)
|
||||
@@ -203,29 +203,22 @@ namespace Torch.Server.Managers
|
||||
|
||||
try
|
||||
{
|
||||
var sandboxPath = Path.Combine(DedicatedConfig.LoadWorld, "Sandbox.sbc");
|
||||
MyObjectBuilderSerializer.DeserializeXML(sandboxPath, out MyObjectBuilder_Checkpoint checkpoint, out ulong sizeInBytes);
|
||||
if (checkpoint == null)
|
||||
{
|
||||
Log.Error($"Failed to load {DedicatedConfig.LoadWorld}, checkpoint null ({sizeInBytes} bytes, instance {Torch.Config.InstancePath})");
|
||||
return;
|
||||
}
|
||||
var world = DedicatedConfig.Worlds.FirstOrDefault(x => x.WorldPath == DedicatedConfig.LoadWorld) ?? new WorldViewModel(DedicatedConfig.LoadWorld);
|
||||
|
||||
checkpoint.SessionName = DedicatedConfig.WorldName;
|
||||
checkpoint.Settings = DedicatedConfig.SessionSettings;
|
||||
checkpoint.Mods.Clear();
|
||||
world.Checkpoint.SessionName = DedicatedConfig.WorldName;
|
||||
world.WorldConfiguration.Settings = DedicatedConfig.SessionSettings;
|
||||
world.WorldConfiguration.Mods.Clear();
|
||||
|
||||
foreach (var mod in DedicatedConfig.Mods)
|
||||
{
|
||||
var savedMod = new MyObjectBuilder_Checkpoint.ModItem(mod.Name, mod.PublishedFileId, mod.FriendlyName);
|
||||
savedMod.IsDependency = mod.IsDependency;
|
||||
checkpoint.Mods.Add(savedMod);
|
||||
world.WorldConfiguration.Mods.Add(savedMod);
|
||||
}
|
||||
Task.Run(() => DedicatedConfig.UpdateAllModInfosAsync());
|
||||
|
||||
MyObjectBuilderSerializer.SerializeXML(sandboxPath, false, checkpoint);
|
||||
world.SaveSandbox();
|
||||
|
||||
//MyLocalCache.SaveCheckpoint(checkpoint, DedicatedConfig.LoadWorld);
|
||||
Log.Info("Saved world config.");
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -259,7 +252,10 @@ namespace Torch.Server.Managers
|
||||
public string WorldPath { get; }
|
||||
public long WorldSizeKB { get; }
|
||||
private string _checkpointPath;
|
||||
private string _worldConfigPath;
|
||||
public CheckpointViewModel Checkpoint { get; private set; }
|
||||
|
||||
public WorldConfigurationViewModel WorldConfiguration { get; private set; }
|
||||
|
||||
public WorldViewModel(string worldPath)
|
||||
{
|
||||
@@ -268,8 +264,9 @@ namespace Torch.Server.Managers
|
||||
WorldPath = worldPath;
|
||||
WorldSizeKB = new DirectoryInfo(worldPath).GetFiles().Sum(x => x.Length) / 1024;
|
||||
_checkpointPath = Path.Combine(WorldPath, "Sandbox.sbc");
|
||||
_worldConfigPath = Path.Combine(WorldPath, "Sandbox_config.sbc");
|
||||
FolderName = Path.GetFileName(worldPath);
|
||||
BeginLoadCheckpoint();
|
||||
LoadSandbox();
|
||||
}
|
||||
catch (ArgumentException ex)
|
||||
{
|
||||
@@ -278,24 +275,40 @@ namespace Torch.Server.Managers
|
||||
}
|
||||
}
|
||||
|
||||
public async Task SaveCheckpointAsync()
|
||||
public void SaveSandbox()
|
||||
{
|
||||
await Task.Run(() =>
|
||||
{
|
||||
using (var f = File.Open(_checkpointPath, FileMode.Create))
|
||||
MyObjectBuilderSerializer.SerializeXML(f, Checkpoint);
|
||||
});
|
||||
using (var f = File.Open(_checkpointPath, FileMode.Create))
|
||||
MyObjectBuilderSerializer.SerializeXML(f, Checkpoint);
|
||||
|
||||
using (var f = File.Open(_worldConfigPath, FileMode.Create))
|
||||
MyObjectBuilderSerializer.SerializeXML(f, WorldConfiguration);
|
||||
}
|
||||
|
||||
private void BeginLoadCheckpoint()
|
||||
private void LoadSandbox()
|
||||
{
|
||||
//Task.Run(() =>
|
||||
MyObjectBuilderSerializer.DeserializeXML(_checkpointPath, out MyObjectBuilder_Checkpoint checkpoint);
|
||||
Checkpoint = new CheckpointViewModel(checkpoint);
|
||||
|
||||
// migrate old saves
|
||||
if (File.Exists(_worldConfigPath))
|
||||
{
|
||||
Log.Info($"Preloading checkpoint {_checkpointPath}");
|
||||
MyObjectBuilderSerializer.DeserializeXML(_checkpointPath, out MyObjectBuilder_Checkpoint checkpoint);
|
||||
Checkpoint = new CheckpointViewModel(checkpoint);
|
||||
OnPropertyChanged(nameof(Checkpoint));
|
||||
}//);
|
||||
MyObjectBuilderSerializer.DeserializeXML(_worldConfigPath, out MyObjectBuilder_WorldConfiguration worldConfig);
|
||||
WorldConfiguration = new WorldConfigurationViewModel(worldConfig);
|
||||
}
|
||||
else
|
||||
{
|
||||
WorldConfiguration = new WorldConfigurationViewModel(new MyObjectBuilder_WorldConfiguration
|
||||
{
|
||||
Mods = checkpoint.Mods,
|
||||
Settings = checkpoint.Settings
|
||||
});
|
||||
|
||||
checkpoint.Mods = null;
|
||||
checkpoint.Settings = null;
|
||||
}
|
||||
|
||||
OnPropertyChanged(nameof(Checkpoint));
|
||||
OnPropertyChanged(nameof(WorldConfiguration));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -16,12 +16,12 @@ namespace Torch.Server.ViewModels
|
||||
public class CheckpointViewModel : ViewModel
|
||||
{
|
||||
private MyObjectBuilder_Checkpoint _checkpoint;
|
||||
private SessionSettingsViewModel _sessionSettings;
|
||||
//private SessionSettingsViewModel _sessionSettings;
|
||||
|
||||
public CheckpointViewModel(MyObjectBuilder_Checkpoint checkpoint)
|
||||
{
|
||||
_checkpoint = checkpoint;
|
||||
_sessionSettings = new SessionSettingsViewModel(_checkpoint.Settings);
|
||||
//_sessionSettings = new SessionSettingsViewModel(_checkpoint.Settings);
|
||||
}
|
||||
|
||||
public static implicit operator MyObjectBuilder_Checkpoint(CheckpointViewModel model)
|
||||
@@ -59,15 +59,15 @@ namespace Torch.Server.ViewModels
|
||||
|
||||
public SerializableDictionary<long, MyObjectBuilder_Checkpoint.PlayerId> ControlledEntities { get => _checkpoint.ControlledEntities; set => SetValue(ref _checkpoint.ControlledEntities, value); }
|
||||
|
||||
public SessionSettingsViewModel Settings
|
||||
{
|
||||
get => _sessionSettings;
|
||||
set
|
||||
{
|
||||
SetValue(ref _sessionSettings, value);
|
||||
_checkpoint.Settings = _sessionSettings;
|
||||
}
|
||||
}
|
||||
//public SessionSettingsViewModel Settings
|
||||
//{
|
||||
// get => _sessionSettings;
|
||||
// set
|
||||
// {
|
||||
// SetValue(ref _sessionSettings, value);
|
||||
// _checkpoint.Settings = _sessionSettings;
|
||||
// }
|
||||
//}
|
||||
|
||||
public MyObjectBuilder_ScriptManager ScriptManagerData => throw new NotImplementedException();
|
||||
|
||||
@@ -75,7 +75,7 @@ namespace Torch.Server.ViewModels
|
||||
|
||||
public MyObjectBuilder_FactionCollection Factions => throw new NotImplementedException();
|
||||
|
||||
public List<MyObjectBuilder_Checkpoint.ModItem> Mods { get => _checkpoint.Mods; set => SetValue(ref _checkpoint.Mods, value); }
|
||||
//public List<MyObjectBuilder_Checkpoint.ModItem> Mods { get => _checkpoint.Mods; set => SetValue(ref _checkpoint.Mods, value); }
|
||||
|
||||
public SerializableDictionary<ulong, MyPromoteLevel> PromotedUsers { get => _checkpoint.PromotedUsers; set => SetValue(ref _checkpoint.PromotedUsers, value); }
|
||||
|
||||
|
34
Torch.Server/ViewModels/WorldConfigurationViewModel.cs
Normal file
34
Torch.Server/ViewModels/WorldConfigurationViewModel.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System.Collections.Generic;
|
||||
using VRage.Game;
|
||||
|
||||
namespace Torch.Server.ViewModels
|
||||
{
|
||||
public class WorldConfigurationViewModel : ViewModel
|
||||
{
|
||||
private readonly MyObjectBuilder_WorldConfiguration _worldConfiguration;
|
||||
private SessionSettingsViewModel _sessionSettings;
|
||||
|
||||
public WorldConfigurationViewModel(MyObjectBuilder_WorldConfiguration worldConfiguration)
|
||||
{
|
||||
_worldConfiguration = worldConfiguration;
|
||||
_sessionSettings = new SessionSettingsViewModel(worldConfiguration.Settings);
|
||||
}
|
||||
|
||||
public static implicit operator MyObjectBuilder_WorldConfiguration(WorldConfigurationViewModel model)
|
||||
{
|
||||
return model._worldConfiguration;
|
||||
}
|
||||
|
||||
public List<MyObjectBuilder_Checkpoint.ModItem> Mods { get => _worldConfiguration.Mods; set => SetValue(ref _worldConfiguration.Mods, value); }
|
||||
|
||||
public SessionSettingsViewModel Settings
|
||||
{
|
||||
get => _sessionSettings;
|
||||
set
|
||||
{
|
||||
SetValue(ref _sessionSettings, value);
|
||||
_worldConfiguration.Settings = _sessionSettings;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -131,6 +131,13 @@ namespace Torch.Server.Views
|
||||
//w.Show();
|
||||
var d = new RoleEditor();
|
||||
var w = _instanceManager.DedicatedConfig.SelectedWorld;
|
||||
|
||||
if (w == null)
|
||||
{
|
||||
MessageBox.Show("A world is not selected.");
|
||||
return;
|
||||
}
|
||||
|
||||
d.Edit(w.Checkpoint.PromotedUsers.Dictionary);
|
||||
_instanceManager.DedicatedConfig.Administrators = w.Checkpoint.PromotedUsers.Dictionary.Where(k => k.Value >= MyPromoteLevel.Admin).Select(k => k.Key.ToString()).ToList();
|
||||
}
|
||||
|
Reference in New Issue
Block a user