Skip to content

Commit 570bc83

Browse files
committed
Fix remote API, file copying, entity manager sorting
1 parent 4f30a47 commit 570bc83

9 files changed

Lines changed: 74 additions & 24 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,5 @@ Torch is the successor to SE Server Extender and gives server admins the tools t
2121
# Building
2222
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.
2323

24-
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.
25-
2624
If you have a more enjoyable server experience because of Torch, please consider supporting us on Patreon.
27-
[![Patreon](http://i.imgur.com/VzzIMgn.png)](https://www.patreon.com/bePatron?u=847269)!
25+
[![Patreon](http://i.imgur.com/VzzIMgn.png)](https://www.patreon.com/bePatron?u=847269)

‎Torch.API/Torch.API.csproj‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
<HintPath>..\GameBinaries\HavokWrapper.dll</HintPath>
4040
<Private>False</Private>
4141
</Reference>
42-
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
43-
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
42+
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed">
43+
<HintPath>..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
4444
<Private>True</Private>
4545
</Reference>
4646
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">

‎Torch.API/packages.config‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
33
<package id="Mono.TextTransform" version="1.0.0" targetFramework="net461" />
4-
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net461" />
4+
<package id="Newtonsoft.Json" version="12.0.2" targetFramework="net461" />
55
<package id="NLog" version="4.4.12" targetFramework="net461" />
66
</packages>

‎Torch.Server/Initializer.cs‎

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,30 @@ public bool Initialize(string[] args)
6262
var basePath = new FileInfo(typeof(Program).Assembly.Location).Directory.ToString();
6363
var apiSource = Path.Combine(basePath, "DedicatedServer64", "steam_api64.dll");
6464
var apiTarget = Path.Combine(basePath, "steam_api64.dll");
65-
66-
if (!File.Exists(apiTarget) || File.GetLastWriteTime(apiTarget) < File.GetLastWriteTime(apiSource))
65+
66+
if (!File.Exists(apiTarget))
67+
{
6768
File.Copy(apiSource, apiTarget);
69+
}
70+
else if (File.GetLastWriteTime(apiTarget) < File.GetLastWriteTime(apiSource))
71+
{
72+
File.Delete(apiTarget);
73+
File.Copy(apiSource, apiTarget);
74+
}
6875

6976
var havokSource = Path.Combine(basePath, "DedicatedServer64", "Havok.dll");
7077
var havokTarget = Path.Combine(basePath, "Havok.dll");
71-
72-
if (!File.Exists(havokTarget) || File.GetLastWriteTime(havokTarget) < File.GetLastWriteTime(havokSource))
78+
79+
if (!File.Exists(havokTarget))
80+
{
81+
File.Copy(havokSource, havokTarget);
82+
}
83+
else if (File.GetLastWriteTime(havokTarget) < File.GetLastWriteTime(havokSource))
84+
{
85+
File.Delete(havokTarget);
7386
File.Copy(havokSource, havokTarget);
74-
87+
}
88+
7589
_config = InitConfig();
7690
if (!_config.Parse(args))
7791
return false;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using NLog;
2+
using Sandbox;
3+
using Torch.API;
4+
using Torch.Managers;
5+
using VRage.Dedicated.RemoteAPI;
6+
7+
namespace Torch.Server.Managers
8+
{
9+
public class RemoteAPIManager : Manager
10+
{
11+
/// <inheritdoc />
12+
public RemoteAPIManager(ITorchBase torchInstance) : base(torchInstance)
13+
{
14+
15+
}
16+
17+
/// <inheritdoc />
18+
public override void Attach()
19+
{
20+
if (MySandboxGame.ConfigDedicated.RemoteApiEnabled && !string.IsNullOrEmpty(MySandboxGame.ConfigDedicated.RemoteSecurityKey))
21+
{
22+
var myRemoteServer = new MyRemoteServer(MySandboxGame.ConfigDedicated.RemoteApiPort, MySandboxGame.ConfigDedicated.RemoteSecurityKey);
23+
LogManager.GetCurrentClassLogger().Info($"Remote API started on port {myRemoteServer.Port}");
24+
}
25+
base.Attach();
26+
}
27+
}
28+
}

‎Torch.Server/Torch.Server.csproj‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@
9090
<Reference Include="netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51">
9191
<HintPath>..\GameBinaries\netstandard.dll</HintPath>
9292
</Reference>
93-
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
94-
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
93+
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed">
94+
<HintPath>..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
95+
<Private>True</Private>
9596
</Reference>
9697
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
9798
<HintPath>..\packages\NLog.4.4.12\lib\net45\NLog.dll</HintPath>
@@ -251,6 +252,7 @@
251252
<Compile Include="Managers\InstanceManager.cs" />
252253
<Compile Include="Managers\MultiplayerManagerDedicatedEventShim.cs" />
253254
<Compile Include="Managers\MultiplayerManagerDedicatedPatchShim.cs" />
255+
<Compile Include="Managers\RemoteAPIManager.cs" />
254256
<Compile Include="NativeMethods.cs" />
255257
<Compile Include="Initializer.cs" />
256258
<Compile Include="Patches\PromotePatch.cs" />

‎Torch.Server/TorchServer.cs‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public TorchServer(TorchConfig config = null)
5454
DedicatedInstance = new InstanceManager(this);
5555
AddManager(DedicatedInstance);
5656
AddManager(new EntityControlManager(this));
57+
AddManager(new RemoteAPIManager(this));
5758
Config = config ?? new TorchConfig();
5859

5960
var sessionManager = Managers.GetManager<ITorchSessionManager>();
@@ -127,13 +128,6 @@ public override void Start()
127128
_hasRun = true;
128129
Log.Info("Starting server.");
129130
MySandboxGame.ConfigDedicated = DedicatedInstance.DedicatedConfig.Model;
130-
//Are you serious, Keen? This is going away until it stops hanging.
131-
//if (MySandboxGame.ConfigDedicated.RemoteApiEnabled && !string.IsNullOrEmpty(MySandboxGame.ConfigDedicated.RemoteSecurityKey))
132-
//{
133-
// var myRemoteServer = new MyRemoteServer(MySandboxGame.ConfigDedicated.RemoteApiPort, MySandboxGame.ConfigDedicated.RemoteSecurityKey);
134-
// Log.Info($"Remote API started on port {myRemoteServer.Port}");
135-
//}
136-
Log.Warn("Remote API is disabled because it hangs the server start process. Blame Keen.");
137131

138132
_uptime = Stopwatch.StartNew();
139133
base.Start();

‎Torch.Server/packages.config‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<package id="Markdown.Xaml" version="1.0.0" targetFramework="net461" />
66
<package id="Microsoft.Win32.Registry" version="4.4.0" targetFramework="net461" />
77
<package id="Mono.TextTransform" version="1.0.0" targetFramework="net461" />
8-
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net461" />
8+
<package id="Newtonsoft.Json" version="12.0.2" targetFramework="net461" />
99
<package id="NLog" version="4.4.12" targetFramework="net461" />
1010
<package id="protobuf-net" version="2.4.0" targetFramework="net461" />
1111
<package id="SteamKit2" version="2.1.0" targetFramework="net461" />

‎Torch/Collections/SortedView.cs‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@
44
using System.Collections.Specialized;
55
using System.Linq;
66
using System.Text;
7+
using System.Threading;
78
using System.Threading.Tasks;
9+
using Havok;
10+
using NLog;
811

912
namespace Torch.Collections
1013
{
1114
public class SortedView<T>: IReadOnlyCollection<T>, INotifyCollectionChanged
1215
{
16+
private readonly Logger _log = LogManager.GetCurrentClassLogger();
1317
private readonly MtObservableCollectionBase<T> _backing;
1418
private IComparer<T> _comparer;
1519
private readonly List<T> _store;
@@ -106,9 +110,19 @@ public void Sort(IComparer<T> comparer = null)
106110

107111
public void Refresh()
108112
{
109-
_store.Clear();
110-
_store.AddRange(_backing);
111-
Sort();
113+
//HACK, fix the multithreading
114+
try
115+
{
116+
_store.Clear();
117+
_store.AddRange(_backing);
118+
Sort();
119+
}
120+
catch (IndexOutOfRangeException e)
121+
{
122+
_log.Error(e);
123+
Thread.Sleep(10);
124+
Refresh();
125+
}
112126
}
113127

114128
public void SetComparer(IComparer<T> comparer, bool resort = true)

0 commit comments

Comments
 (0)