diff --git a/README.md b/README.md index f553aaa..35ed4cd 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,5 @@ Torch is the successor to SE Server Extender and gives server admins the tools t # Building To build Torch you must first have a complete SE Dedicated installation somewhere. Before you open the solution, run the Setup batch file and enter the path of that installation's DedicatedServer64 folder. The script will make a symlink to that folder so the Torch solution can find the DLL references it needs. -In both cases you will need to set the InstancePath in TorchConfig.xml to an existing dedicated server instance as Torch can't fully generate it on its own yet. - If you have a more enjoyable server experience because of Torch, please consider supporting us on Patreon. -[![Patreon](http://i.imgur.com/VzzIMgn.png)](https://www.patreon.com/bePatron?u=847269)! +[![Patreon](http://i.imgur.com/VzzIMgn.png)](https://www.patreon.com/bePatron?u=847269) diff --git a/Torch.API/Torch.API.csproj b/Torch.API/Torch.API.csproj index aa0dea8..028a6bb 100644 --- a/Torch.API/Torch.API.csproj +++ b/Torch.API/Torch.API.csproj @@ -39,8 +39,8 @@ ..\GameBinaries\HavokWrapper.dll False - - ..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll + + ..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll True diff --git a/Torch.API/packages.config b/Torch.API/packages.config index 5221eb5..fbd3f14 100644 --- a/Torch.API/packages.config +++ b/Torch.API/packages.config @@ -1,6 +1,6 @@  - + \ No newline at end of file diff --git a/Torch.Server/Initializer.cs b/Torch.Server/Initializer.cs index 9d794a1..61e7ee6 100644 --- a/Torch.Server/Initializer.cs +++ b/Torch.Server/Initializer.cs @@ -71,16 +71,30 @@ quit"; var basePath = new FileInfo(typeof(Program).Assembly.Location).Directory.ToString(); var apiSource = Path.Combine(basePath, "DedicatedServer64", "steam_api64.dll"); var apiTarget = Path.Combine(basePath, "steam_api64.dll"); - + if (!File.Exists(apiTarget)) + { File.Copy(apiSource, apiTarget); + } + else if (File.GetLastWriteTime(apiTarget) < File.GetLastWriteTime(apiSource)) + { + File.Delete(apiTarget); + File.Copy(apiSource, apiTarget); + } var havokSource = Path.Combine(basePath, "DedicatedServer64", "Havok.dll"); var havokTarget = Path.Combine(basePath, "Havok.dll"); - + if (!File.Exists(havokTarget)) + { + File.Copy(havokSource, havokTarget); + } + else if (File.GetLastWriteTime(havokTarget) < File.GetLastWriteTime(havokSource)) + { + File.Delete(havokTarget); File.Copy(havokSource, havokTarget); - + } + _config = InitConfig(); if (!_config.Parse(args)) return false; diff --git a/Torch.Server/Managers/MultiplayerManagerDedicated.cs b/Torch.Server/Managers/MultiplayerManagerDedicated.cs index 34fd09e..f5c52ba 100644 --- a/Torch.Server/Managers/MultiplayerManagerDedicated.cs +++ b/Torch.Server/Managers/MultiplayerManagerDedicated.cs @@ -219,7 +219,12 @@ namespace Torch.Server.Managers _log.Info($"Connection attempt by {steamId} from {ip}"); - if (Torch.CurrentSession.KeenSession.OnlineMode == MyOnlineModeEnum.OFFLINE && + if (Players.ContainsKey(steamId)) + { + _log.Warn($"Player {steamId} already has already joined!"); + UserRejected(steamId, JoinResult.AlreadyJoined); + } + else if (Torch.CurrentSession.KeenSession.OnlineMode == MyOnlineModeEnum.OFFLINE && promoteLevel < MyPromoteLevel.Admin) { _log.Warn($"Rejecting user {steamId}, world is set to offline and user is not admin."); @@ -337,4 +342,4 @@ namespace Torch.Server.Managers #endregion } -} \ No newline at end of file +} diff --git a/Torch.Server/Managers/RemoteAPIManager.cs b/Torch.Server/Managers/RemoteAPIManager.cs new file mode 100644 index 0000000..4d7fe1c --- /dev/null +++ b/Torch.Server/Managers/RemoteAPIManager.cs @@ -0,0 +1,28 @@ +using NLog; +using Sandbox; +using Torch.API; +using Torch.Managers; +using VRage.Dedicated.RemoteAPI; + +namespace Torch.Server.Managers +{ + public class RemoteAPIManager : Manager + { + /// + public RemoteAPIManager(ITorchBase torchInstance) : base(torchInstance) + { + + } + + /// + public override void Attach() + { + if (MySandboxGame.ConfigDedicated.RemoteApiEnabled && !string.IsNullOrEmpty(MySandboxGame.ConfigDedicated.RemoteSecurityKey)) + { + var myRemoteServer = new MyRemoteServer(MySandboxGame.ConfigDedicated.RemoteApiPort, MySandboxGame.ConfigDedicated.RemoteSecurityKey); + LogManager.GetCurrentClassLogger().Info($"Remote API started on port {myRemoteServer.Port}"); + } + base.Attach(); + } + } +} \ No newline at end of file diff --git a/Torch.Server/Program.cs b/Torch.Server/Program.cs index 731dd02..9abb67c 100644 --- a/Torch.Server/Program.cs +++ b/Torch.Server/Program.cs @@ -34,7 +34,7 @@ namespace Torch.Server //HACK for block skins update var badDlls = new[] { - "System.Security.Principal.Windows.dll" + "System.Security.Principal.Windows.dll", }; try @@ -45,9 +45,11 @@ namespace Torch.Server File.Delete(file); } } - catch + catch (Exception e) { - LogManager.GetCurrentClassLogger().Error($"Error updating. Please delete the following files from the Torch root folder manually:\r\n{string.Join("\r\n", badDlls)}"); + var log = LogManager.GetCurrentClassLogger(); + log.Error($"Error updating. Please delete the following files from the Torch root folder manually:\r\n{string.Join("\r\n", badDlls)}"); + log.Error(e); return; } @@ -71,4 +73,4 @@ namespace Torch.Server initializer.Run(); } } -} \ No newline at end of file +} diff --git a/Torch.Server/Torch.Server.csproj b/Torch.Server/Torch.Server.csproj index 798c6a8..2265911 100644 --- a/Torch.Server/Torch.Server.csproj +++ b/Torch.Server/Torch.Server.csproj @@ -90,8 +90,9 @@ ..\GameBinaries\netstandard.dll - - ..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll + + ..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll + True ..\packages\NLog.4.4.12\lib\net45\NLog.dll @@ -251,6 +252,7 @@ + diff --git a/Torch.Server/TorchConfig.cs b/Torch.Server/TorchConfig.cs index 2c2d635..7c86e24 100644 --- a/Torch.Server/TorchConfig.cs +++ b/Torch.Server/TorchConfig.cs @@ -21,9 +21,38 @@ namespace Torch.Server [Arg("instancename", "The name of the Torch instance.")] public string InstanceName { get; set; } + + private string _instancePath; + /// [Arg("instancepath", "Server data folder where saves and mods are stored.")] - public string InstancePath { get; set; } + public string InstancePath + { + get => _instancePath; + set + { + if(String.IsNullOrEmpty(value)) + { + _instancePath = value; + return; + } + try + { + if(value.Contains("\"")) + throw new InvalidOperationException(); + + var s = Path.GetFullPath(value); + Console.WriteLine(s); //prevent compiler opitmization - just in case + } + catch (Exception ex) + { + _log.Error(ex, "Invalid path assigned to InstancePath! Please report this immediately! Value: " + value); + //throw; + } + + _instancePath = value; + } + } /// [XmlIgnore, Arg("noupdate", "Disable automatically downloading game and plugin updates.")] diff --git a/Torch.Server/TorchServer.cs b/Torch.Server/TorchServer.cs index 30c177d..7835f39 100644 --- a/Torch.Server/TorchServer.cs +++ b/Torch.Server/TorchServer.cs @@ -54,6 +54,7 @@ namespace Torch.Server DedicatedInstance = new InstanceManager(this); AddManager(DedicatedInstance); AddManager(new EntityControlManager(this)); + AddManager(new RemoteAPIManager(this)); Config = config ?? new TorchConfig(); var sessionManager = Managers.GetManager(); @@ -127,13 +128,6 @@ namespace Torch.Server _hasRun = true; Log.Info("Starting server."); MySandboxGame.ConfigDedicated = DedicatedInstance.DedicatedConfig.Model; - //Are you serious, Keen? This is going away until it stops hanging. - //if (MySandboxGame.ConfigDedicated.RemoteApiEnabled && !string.IsNullOrEmpty(MySandboxGame.ConfigDedicated.RemoteSecurityKey)) - //{ - // var myRemoteServer = new MyRemoteServer(MySandboxGame.ConfigDedicated.RemoteApiPort, MySandboxGame.ConfigDedicated.RemoteSecurityKey); - // Log.Info($"Remote API started on port {myRemoteServer.Port}"); - //} - Log.Warn("Remote API is disabled because it hangs the server start process. Blame Keen."); _uptime = Stopwatch.StartNew(); base.Start(); diff --git a/Torch.Server/packages.config b/Torch.Server/packages.config index 24c621a..b1ff266 100644 --- a/Torch.Server/packages.config +++ b/Torch.Server/packages.config @@ -5,7 +5,7 @@ - + diff --git a/Torch/Collections/SortedView.cs b/Torch/Collections/SortedView.cs index ddf4a05..392e0dc 100644 --- a/Torch/Collections/SortedView.cs +++ b/Torch/Collections/SortedView.cs @@ -6,12 +6,16 @@ using System.ComponentModel; using System.Linq; using System.Runtime.CompilerServices; using System.Text; +using System.Threading; using System.Threading.Tasks; +using Havok; +using NLog; namespace Torch.Collections { public class SortedView: IReadOnlyCollection, INotifyCollectionChanged, INotifyPropertyChanged { + private readonly Logger _log = LogManager.GetCurrentClassLogger(); private readonly MtObservableCollectionBase _backing; private IComparer _comparer; private readonly List _store;