Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions Torch.API/Torch.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@
<HintPath>..\GameBinaries\HavokWrapper.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed">
<HintPath>..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.13.0.4\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\packages\NLog.4.4.12\lib\net45\NLog.dll</HintPath>
Expand Down
2 changes: 1 addition & 1 deletion Torch.API/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Mono.TextTransform" version="1.0.0" targetFramework="net461" />
<package id="Newtonsoft.Json" version="12.0.2" targetFramework="net461" />
<package id="Newtonsoft.Json" version="13.0.4" targetFramework="net48" />
<package id="NLog" version="4.4.12" targetFramework="net461" />
</packages>
324 changes: 293 additions & 31 deletions Torch.Server/Initializer.cs

Large diffs are not rendered by default.

29 changes: 12 additions & 17 deletions Torch.Server/Managers/EntityControlManager.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Controls;
using NLog;
using NLog.Fluent;
using Torch.API;
using Torch.Collections;
using Torch.Collections.Concurrent;
using Torch.Managers;
using Torch.Server.ViewModels.Entities;
using Torch.Utils;
Expand Down Expand Up @@ -87,8 +82,8 @@ protected override EntityControlViewModel Create(EntityViewModel evm)
private readonly List<ModelFactory> _modelFactories = new List<ModelFactory>();
private readonly List<Delegate> _controlFactories = new List<Delegate>();

private readonly List<WeakReference<EntityViewModel>> _boundEntityViewModels = new List<WeakReference<EntityViewModel>>();
private readonly ConditionalWeakTable<EntityViewModel, MtObservableList<EntityControlViewModel>> _boundViewModels = new ConditionalWeakTable<EntityViewModel, MtObservableList<EntityControlViewModel>>();
private readonly ObservableConcurrentList<WeakReference<EntityViewModel>> _boundEntityViewModels = new ObservableConcurrentList<WeakReference<EntityViewModel>>();
private readonly ConditionalWeakTable<EntityViewModel, ObservableConcurrentList<EntityControlViewModel>> _boundViewModels = new ConditionalWeakTable<EntityViewModel, ObservableConcurrentList<EntityControlViewModel>>();

/// <summary>
/// This factory will be used to create component models for matching entity models.
Expand All @@ -109,14 +104,14 @@ public void RegisterModelFactory<TEntityBaseModel>(Func<TEntityBaseModel, Entity
while (i < _boundEntityViewModels.Count)
{
if (_boundEntityViewModels[i].TryGetTarget(out EntityViewModel target) &&
_boundViewModels.TryGetValue(target, out MtObservableList<EntityControlViewModel> components))
_boundViewModels.TryGetValue(target, out ObservableConcurrentList<EntityControlViewModel> components))
{
if (target is TEntityBaseModel tent)
UpdateBinding(target, components);
i++;
}
else
_boundEntityViewModels.RemoveAtFast(i);
_boundEntityViewModels.RemoveAt(i);
}
}
}
Expand Down Expand Up @@ -190,15 +185,15 @@ private void RefreshControls<TEntityComponentModel>() where TEntityComponentMode
while (i < _boundEntityViewModels.Count)
{
if (_boundEntityViewModels[i].TryGetTarget(out EntityViewModel target) &&
_boundViewModels.TryGetValue(target, out MtObservableList<EntityControlViewModel> components))
_boundViewModels.TryGetValue(target, out ObservableConcurrentList<EntityControlViewModel> components))
{
foreach (EntityControlViewModel component in components)
if (component is TEntityComponentModel)
component.InvalidateControl();
i++;
}
else
_boundEntityViewModels.RemoveAtFast(i);
_boundEntityViewModels.RemoveAt(i);
}
}

Expand All @@ -207,7 +202,7 @@ private void RefreshControls<TEntityComponentModel>() where TEntityComponentMode
/// </summary>
/// <param name="entity">view model to query</param>
/// <returns></returns>
public MtObservableList<EntityControlViewModel> BoundModels(EntityViewModel entity)
public ObservableConcurrentList<EntityControlViewModel> BoundModels(EntityViewModel entity)
{
return _boundViewModels.GetValue(entity, CreateFreshBinding);
}
Expand All @@ -231,9 +226,9 @@ public Control CreateControl(EntityControlViewModel model)
return null;
}

private MtObservableList<EntityControlViewModel> CreateFreshBinding(EntityViewModel key)
private ObservableConcurrentList<EntityControlViewModel> CreateFreshBinding(EntityViewModel key)
{
var binding = new MtObservableList<EntityControlViewModel>();
var binding = new ObservableConcurrentList<EntityControlViewModel>();
lock (this)
{
_boundEntityViewModels.Add(new WeakReference<EntityViewModel>(key));
Expand All @@ -246,7 +241,7 @@ private MtObservableList<EntityControlViewModel> CreateFreshBinding(EntityViewMo
return binding;
}

private void UpdateBinding(EntityViewModel key, MtObservableList<EntityControlViewModel> binding)
private void UpdateBinding(EntityViewModel key, ObservableConcurrentList<EntityControlViewModel> binding)
{
if (!binding.IsObserved)
return;
Expand Down
78 changes: 60 additions & 18 deletions Torch.Server/Managers/InstanceManager.cs
Original file line number Diff line number Diff line change
@@ -1,33 +1,21 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Havok;
using NLog;
using Sandbox;
using Sandbox.Engine.Networking;
using Sandbox.Engine.Utils;
using Sandbox.Game;
using Sandbox.Game.Gui;
using Torch.API;
using Torch.API.Managers;
using Torch.Collections;
using Torch.Collections.Concurrent;
using Torch.Managers;
using Torch.Mod;
using Torch.Server.ViewModels;
using Torch.Utils;
using VRage;
using VRage.FileSystem;
using VRage.Game;
using VRage.Game.ObjectBuilder;
using VRage.Game.ModAPI;
using VRage.ObjectBuilders;
using VRage.ObjectBuilders.Private;
using VRage.Plugins;

namespace Torch.Server.Managers
{
Expand All @@ -52,7 +40,7 @@ public void LoadInstance(string path, bool validate = true)
ValidateInstance(path);

MyFileSystem.Reset();
MyFileSystem.Init("Content", path);
MyFileSystem.Init("game/Content", path);
//Initializes saves path. Why this isn't in Init() we may never know.
MyFileSystem.InitUserSpecific(null);

Expand Down Expand Up @@ -106,6 +94,7 @@ public void SelectWorld(string worldPath, bool modsOnly = true)
}

DedicatedConfig.SelectedWorld = worldInfo;
DedicatedConfig.RefreshModel();
if (DedicatedConfig.SelectedWorld?.Checkpoint != null)
{
DedicatedConfig.Mods.Clear();
Expand All @@ -114,13 +103,15 @@ public void SelectWorld(string worldPath, bool modsOnly = true)
foreach (var m in DedicatedConfig.SelectedWorld.WorldConfiguration.Mods)
DedicatedConfig.Mods.Add(new ModItemInfo(m));
Task.Run(() => DedicatedConfig.UpdateAllModInfosAsync());
DedicatedConfig.RefreshModel();
}
}

public void SelectWorld(WorldViewModel world, bool modsOnly = true)
{
DedicatedConfig.LoadWorld = world.WorldPath;
DedicatedConfig.SelectedWorld = world;
DedicatedConfig.RefreshModel();
if (DedicatedConfig.SelectedWorld?.Checkpoint != null)
{
DedicatedConfig.Mods.Clear();
Expand All @@ -129,6 +120,7 @@ public void SelectWorld(WorldViewModel world, bool modsOnly = true)
foreach (var m in DedicatedConfig.SelectedWorld.WorldConfiguration.Mods)
DedicatedConfig.Mods.Add(new ModItemInfo(m));
Task.Run(() => DedicatedConfig.UpdateAllModInfosAsync());
DedicatedConfig.RefreshModel();
}
}

Expand All @@ -139,16 +131,44 @@ public void ImportSelectedWorldConfig()

private void ImportWorldConfig(WorldViewModel world, bool modsOnly = true)
{
var mods = new MtObservableList<ModItemInfo>();

var mods = new ObservableConcurrentList<ModItemInfo>();
foreach (var mod in world.WorldConfiguration.Mods)
mods.Add(new ModItemInfo(mod));
DedicatedConfig.Mods = mods;


Log.Debug("Loaded mod list from world");

if (!modsOnly)
DedicatedConfig.SessionSettings = world.WorldConfiguration.Settings;

// Update left pane fields from world checkpoint
if (world.Checkpoint != null)
{
DedicatedConfig.WorldName = world.Checkpoint.SessionName;
DedicatedConfig.ServerDescription = world.Checkpoint.Description;
DedicatedConfig.ServerName = world.Checkpoint.SessionName;
if (!string.IsNullOrEmpty(world.Checkpoint.Password))
DedicatedConfig.Password = world.Checkpoint.Password;
// Update administrators from promoted users
if (world.Checkpoint.PromotedUsers != null)
{
var adminIds = world.Checkpoint.PromotedUsers.Dictionary
.Where(kvp => kvp.Value >= MyPromoteLevel.Admin)
.Select(kvp => kvp.Key.ToString())
.ToList();
DedicatedConfig.Administrators = adminIds;
}
}

// Ensure LoadWorld is set to this world's path
DedicatedConfig.LoadWorld = world.WorldPath;

// Make sure the config uses LoadWorld instead of last session
if (DedicatedConfig.Model is MyConfigDedicated<MyObjectBuilder_SessionSettings> config)
config.IgnoreLastSession = true;

DedicatedConfig.RefreshModel();
}

private void ImportWorldConfig(bool modsOnly = true)
Expand All @@ -170,7 +190,7 @@ private void ImportWorldConfig(bool modsOnly = true)
return;
}

var mods = new MtObservableList<ModItemInfo>();
var mods = new ObservableConcurrentList<ModItemInfo>();
foreach (var mod in checkpoint.Mods)
mods.Add(new ModItemInfo(mod));
DedicatedConfig.Mods = mods;
Expand All @@ -179,6 +199,28 @@ private void ImportWorldConfig(bool modsOnly = true)

if (!modsOnly)
DedicatedConfig.SessionSettings = new SessionSettingsViewModel(checkpoint.Settings);

// Update left pane fields from world checkpoint
DedicatedConfig.WorldName = checkpoint.SessionName;
DedicatedConfig.ServerDescription = checkpoint.Description;
DedicatedConfig.ServerName = checkpoint.SessionName;
if (!string.IsNullOrEmpty(checkpoint.Password))
DedicatedConfig.Password = checkpoint.Password;
// Update administrators from promoted users
if (checkpoint.PromotedUsers != null)
{
var adminIds = checkpoint.PromotedUsers.Dictionary
.Where(kvp => kvp.Value >= MyPromoteLevel.Admin)
.Select(kvp => kvp.Key.ToString())
.ToList();
DedicatedConfig.Administrators = adminIds;
}

// Make sure the config uses LoadWorld instead of last session
if (DedicatedConfig.Model is MyConfigDedicated<MyObjectBuilder_SessionSettings> config)
config.IgnoreLastSession = true;

DedicatedConfig.RefreshModel();
}
catch (Exception e)
{
Expand Down
2 changes: 1 addition & 1 deletion Torch.Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static void Main(string[] args)
Target.Register<FlowDocumentTarget>("FlowDocument");
//Ensures that all the files are downloaded in the Torch directory.
var workingDir = new FileInfo(typeof(Program).Assembly.Location).Directory.ToString();
var binDir = Path.Combine(workingDir, "DedicatedServer64");
var binDir = Path.Combine(workingDir, "game", "DedicatedServer64");
Directory.SetCurrentDirectory(workingDir);

//HACK for block skins update
Expand Down
5 changes: 2 additions & 3 deletions Torch.Server/Torch.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,8 @@
<Reference Include="netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51">
<HintPath>..\GameBinaries\netstandard.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed">
<HintPath>..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.13.0.4\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\packages\NLog.4.4.12\lib\net45\NLog.dll</HintPath>
Expand Down
12 changes: 4 additions & 8 deletions Torch.Server/ViewModels/ConfigDedicatedViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NLog;
using Sandbox.Engine.Utils;
using Torch.Collections;
using Torch.Server.Managers;
using VRage.Game;
using VRage.Game.ModAPI;
using Torch.Utils.SteamWorkshopTools;
using Torch.Collections;
using Torch.Collections.Concurrent;

namespace Torch.Server.ViewModels
{
Expand Down Expand Up @@ -64,7 +60,7 @@ public bool Validate()
private SessionSettingsViewModel _sessionSettings;
public SessionSettingsViewModel SessionSettings { get => _sessionSettings; set { _sessionSettings = value; OnPropertyChanged(); } }

public MtObservableList<WorldViewModel> Worlds { get; } = new MtObservableList<WorldViewModel>();
public ObservableConcurrentList<WorldViewModel> Worlds { get; } = new ObservableConcurrentList<WorldViewModel>();
private WorldViewModel _selectedWorld;
public WorldViewModel SelectedWorld
{
Expand Down Expand Up @@ -118,8 +114,8 @@ public async Task UpdateAllModInfosAsync(Action<string> messageHandler = null)

public List<ulong> Banned { get => _config.Banned; set => SetValue(x => _config.Banned = x, value); }

private MtObservableList<ModItemInfo> _mods = new MtObservableList<ModItemInfo>();
public MtObservableList<ModItemInfo> Mods
private ObservableConcurrentList<ModItemInfo> _mods = new ObservableConcurrentList<ModItemInfo>();
public ObservableConcurrentList<ModItemInfo> Mods
{
get => _mods;
set
Expand Down
3 changes: 2 additions & 1 deletion Torch.Server/ViewModels/Entities/Blocks/BlockViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Sandbox.ModAPI;
using Sandbox.ModAPI.Interfaces;
using Torch.Collections;
using Torch.Collections.Concurrent;
using Torch.Server.ViewModels.Entities;
using VRage.Game.ModAPI;

Expand All @@ -18,7 +19,7 @@ namespace Torch.Server.ViewModels.Blocks
public class BlockViewModel : EntityViewModel
{
public IMyTerminalBlock Block => (IMyTerminalBlock) Entity;
public MtObservableList<PropertyViewModel> Properties { get; } = new MtObservableList<PropertyViewModel>();
public ObservableConcurrentList<PropertyViewModel> Properties { get; } = new ObservableConcurrentList<PropertyViewModel>();

public string FullName => $"{Block?.CubeGrid.CustomName} - {Block?.CustomName}";

Expand Down
4 changes: 2 additions & 2 deletions Torch.Server/ViewModels/Entities/EntityViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using NLog;
using Sandbox.Game.Entities;
using Torch.API.Managers;
using Torch.Collections;
using Torch.Collections.Concurrent;
using Torch.Server.Managers;
using Torch.Utils;
using VRage.ModAPI;
Expand Down Expand Up @@ -33,7 +33,7 @@ private set

public long Id => Entity?.EntityId ?? 0; // Throws null then gives entity id

public MtObservableList<EntityControlViewModel> EntityControls { get; private set; }
public ObservableConcurrentList<EntityControlViewModel> EntityControls { get; private set; }

public virtual string Name
{
Expand Down
Loading