Skip to content

Commit 147c94f

Browse files
authored
Merge pull request #15 from zznty/fix/xbox
Fixes for EOS & consoles
2 parents 0e2ecf1 + c5c6ef1 commit 147c94f

9 files changed

Lines changed: 143 additions & 62 deletions

File tree

‎Torch.Server/Managers/InstanceManager.cs‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Threading.Tasks;
1010
using Havok;
1111
using NLog;
12+
using Sandbox;
1213
using Sandbox.Engine.Networking;
1314
using Sandbox.Engine.Utils;
1415
using Sandbox.Game;
@@ -56,17 +57,19 @@ public void LoadInstance(string path, bool validate = true)
5657
//Initializes saves path. Why this isn't in Init() we may never know.
5758
MyFileSystem.InitUserSpecific(null);
5859

59-
var configPath = Path.Combine(path, CONFIG_NAME);
60-
if (!File.Exists(configPath))
61-
{
62-
Log.Error($"Failed to load dedicated config at {path}");
63-
return;
64-
}
60+
// why?....
61+
// var configPath = Path.Combine(path, CONFIG_NAME);
62+
// if (!File.Exists(configPath))
63+
// {
64+
// Log.Error($"Failed to load dedicated config at {path}");
65+
// return;
66+
// }
6567

66-
var config = new MyConfigDedicated<MyObjectBuilder_SessionSettings>(configPath);
67-
config.Load(configPath);
68+
69+
// var config = new MyConfigDedicated<MyObjectBuilder_SessionSettings>(configPath);
70+
// config.Load(configPath);
6871

69-
DedicatedConfig = new ConfigDedicatedViewModel(config);
72+
DedicatedConfig = new ConfigDedicatedViewModel((MyConfigDedicated<MyObjectBuilder_SessionSettings>) MySandboxGame.ConfigDedicated);
7073

7174
var worldFolders = Directory.EnumerateDirectories(Path.Combine(Torch.Config.InstancePath, "Saves"));
7275

‎Torch.Server/Managers/MultiplayerManagerDedicated.cs‎

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,21 @@ internal void RaisePromoteChanged(ulong steamId, MyPromoteLevel level)
134134
public override void Attach()
135135
{
136136
base.Attach();
137-
_gameServerValidateAuthTicketReplacer = _gameServerValidateAuthTicketFactory.Invoke();
138-
_gameServerUserGroupStatusReplacer = _gameServerUserGroupStatusFactory.Invoke();
137+
if (Torch.Config.UgcServiceType == UGCServiceType.Steam)
138+
{
139+
_gameServerValidateAuthTicketReplacer = _gameServerValidateAuthTicketFactory.Invoke();
140+
_gameServerUserGroupStatusReplacer = _gameServerUserGroupStatusFactory.Invoke();
141+
}
142+
else
143+
{
144+
_gameServerValidateAuthTicketReplacer = _eosServerValidateAuthTicketFactory.Invoke();
145+
_gameServerUserGroupStatusReplacer = _eosServerUserGroupStatusFactory.Invoke();
146+
}
139147
_gameServerValidateAuthTicketReplacer.Replace(
140148
new Action<ulong, JoinResult, ulong, string>(ValidateAuthTicketResponse), MyGameService.GameServer);
141149
_gameServerUserGroupStatusReplacer.Replace(new Action<ulong, ulong, bool, bool>(UserGroupStatusResponse),
142150
MyGameService.GameServer);
143-
_log.Info("Inserted steam authentication intercept");
151+
_log.Info("Inserted authentication intercept");
144152
}
145153

146154
/// <inheritdoc/>
@@ -150,7 +158,7 @@ public override void Detach()
150158
_gameServerValidateAuthTicketReplacer.Restore(MyGameService.GameServer);
151159
if (_gameServerUserGroupStatusReplacer != null && _gameServerUserGroupStatusReplacer.Replaced)
152160
_gameServerUserGroupStatusReplacer.Restore(MyGameService.GameServer);
153-
_log.Info("Removed steam authentication intercept");
161+
_log.Info("Removed authentication intercept");
154162
base.Detach();
155163
}
156164

@@ -163,6 +171,14 @@ public override void Detach()
163171
[ReflectedEventReplace("VRage.Steam.MySteamGameServer, VRage.Steam", "UserGroupStatusResponse",
164172
typeof(MyDedicatedServerBase), "GameServer_UserGroupStatus")]
165173
private static Func<ReflectedEventReplacer> _gameServerUserGroupStatusFactory;
174+
175+
[ReflectedEventReplace("VRage.EOS.MyEOSGameServer, VRage.EOS", "ValidateAuthTicketResponse",
176+
typeof(MyDedicatedServerBase), "GameServer_ValidateAuthTicketResponse")]
177+
private static Func<ReflectedEventReplacer> _eosServerValidateAuthTicketFactory;
178+
179+
[ReflectedEventReplace("VRage.EOS.MyEOSGameServer, VRage.EOS", "UserGroupStatusResponse",
180+
typeof(MyDedicatedServerBase), "GameServer_UserGroupStatus")]
181+
private static Func<ReflectedEventReplacer> _eosServerUserGroupStatusFactory;
166182

167183
private ReflectedEventReplacer _gameServerValidateAuthTicketReplacer;
168184
private ReflectedEventReplacer _gameServerUserGroupStatusReplacer;

‎Torch.Server/ViewModels/ModItemInfo.cs‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
using System.Windows.Threading;
88
using System.Runtime.CompilerServices;
99
using NLog;
10+
using Sandbox.Engine.Networking;
1011
using VRage.Game;
1112
using Torch.Server.Annotations;
13+
using Torch.Utils;
1214
using Torch.Utils.SteamWorkshopTools;
1315

1416
namespace Torch.Server.ViewModels
@@ -84,6 +86,15 @@ public string Description
8486
}
8587
}
8688

89+
public string UgcService
90+
{
91+
get { return _modItem.PublishedServiceName; }
92+
set
93+
{
94+
SetValue(ref _modItem.PublishedServiceName, value);
95+
}
96+
}
97+
8798
/// <summary>
8899
/// Constructor, returns a new ModItemInfo instance
89100
/// </summary>
@@ -101,6 +112,9 @@ public ModItemInfo(MyObjectBuilder_Checkpoint.ModItem mod)
101112
/// <returns></returns>
102113
public async Task<bool> UpdateModInfoAsync()
103114
{
115+
if (UgcService.ToLower() == "mod.io")
116+
return true;
117+
104118
var msg = "";
105119
var workshopService = WebAPI.Instance;
106120
PublishedItemDetails modInfo = null;
@@ -127,5 +141,10 @@ public async Task<bool> UpdateModInfoAsync()
127141
return true;
128142
}
129143
}
144+
145+
public override string ToString()
146+
{
147+
return $"{PublishedFileId}-{UgcService}";
148+
}
130149
}
131150
}

‎Torch.Server/Views/ModListControl.xaml‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
<ColumnDefinition Width="Auto"/>
104104
<ColumnDefinition Width="Auto"/>
105105
<ColumnDefinition Width="Auto"/>
106+
<ColumnDefinition Width="Auto"/>
106107
</Grid.ColumnDefinitions>
107108
<Grid.RowDefinitions>
108109
<RowDefinition/>
@@ -115,10 +116,11 @@
115116
VerticalAlignment="Center" Grid.Column="0" Grid.Row="1"/>
116117
<TextBox Name="AddModIDTextBox" Grid.Column="1" VerticalContentAlignment="Center"
117118
HorizontalAlignment="Stretch" MinWidth="100px" Margin="6px 4px" Grid.Row="1"/>
118-
<Button Content="Add" Grid.Column="2" Margin="6px 0" Width="60px" Height="40px" Click="AddBtn_OnClick" Grid.Row="1"/>
119-
<Button Content="Remove" Grid.Column="3" Margin="6px 0" Width="60px" Height="40px" Click="RemoveBtn_OnClick" Grid.Row="1"
119+
<ComboBox Grid.Column="2" Grid.Row="1" x:Name="UgcServiceTypeBox" SelectionChanged="UgcServiceTypeBox_OnSelectionChanged" SelectedValuePath="Value" DisplayMemberPath="Key"/>
120+
<Button Content="Add" Grid.Column="3" Margin="6px 0" Width="60px" Height="40px" Click="AddBtn_OnClick" Grid.Row="1"/>
121+
<Button Content="Remove" Grid.Column="4" Margin="6px 0" Width="60px" Height="40px" Click="RemoveBtn_OnClick" Grid.Row="1"
120122
IsEnabled="{Binding ElementName=ModList, Path=SelectedItems.Count}"/>
121-
<Button Content="Bulk Edit" Grid.Column="4" Margin="6px 0" Width="60px" Height="40px" Click="BulkButton_OnClick" Grid.Row="1"/>
123+
<Button Content="Bulk Edit" Grid.Column="5" Margin="6px 0" Width="60px" Height="40px" Click="BulkButton_OnClick" Grid.Row="1"/>
122124
</Grid>
123125

124126
<Button Content="Save Config" Grid.Row="2" VerticalAlignment="Bottom" HorizontalAlignment="Right" Margin="6px" Grid.Column="3" Width="80px" Height="40px" Click="SaveBtn_OnClick"/>

‎Torch.Server/Views/ModListControl.xaml.cs‎

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
using VRage.Game;
2222
using NLog;
2323
using Sandbox.Engine.Networking;
24+
using Torch.API;
2425
using Torch.Server.Managers;
2526
using Torch.API.Managers;
2627
using Torch.Server.ViewModels;
@@ -41,6 +42,7 @@ public partial class ModListControl : UserControl, INotifyPropertyChanged
4142
ModItemInfo _draggedMod;
4243
bool _hasOrderChanged = false;
4344
bool _isSortedByLoadOrder = true;
45+
private readonly ITorchConfig _config;
4446

4547
//private List<BindingExpression> _bindingExpressions = new List<BindingExpression>();
4648
/// <summary>
@@ -51,11 +53,16 @@ public ModListControl()
5153
InitializeComponent();
5254
_instanceManager = TorchBase.Instance.Managers.GetManager<InstanceManager>();
5355
_instanceManager.InstanceLoaded += _instanceManager_InstanceLoaded;
56+
_config = TorchBase.Instance.Config;
5457
//var mods = _instanceManager.DedicatedConfig?.Mods;
5558
//if( mods != null)
5659
// DataContext = new ObservableCollection<MyObjectBuilder_Checkpoint.ModItem>();
5760
DataContext = _instanceManager.DedicatedConfig?.Mods;
58-
61+
UgcServiceTypeBox.ItemsSource = new[]
62+
{
63+
new KeyValuePair<string, string>("Steam", "steam"),
64+
new KeyValuePair<string, string>("Mod.Io", "mod.io")
65+
};
5966
// Gets called once all children are loaded
6067
//Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new Action(ApplyStyles));
6168
}
@@ -98,8 +105,8 @@ private void AddBtn_OnClick(object sender, RoutedEventArgs e)
98105
{
99106
if (TryExtractId(AddModIDTextBox.Text, out ulong id))
100107
{
101-
var mod = new ModItemInfo(ModItemUtils.Create(id));
102-
//mod.PublishedFileId = id;
108+
var mod = new ModItemInfo(ModItemUtils.Create(id, UgcServiceTypeBox.SelectedValue?.ToString()));
109+
103110
_instanceManager.DedicatedConfig.Mods.Add(mod);
104111
Task.Run(mod.UpdateModInfoAsync)
105112
.ContinueWith((t) =>
@@ -254,33 +261,41 @@ private void BulkButton_OnClick(object sender, RoutedEventArgs e)
254261

255262
//let's see just how poorly we can do this
256263
var modList = ((MtObservableList<ModItemInfo>)DataContext).ToList();
257-
var idList = modList.Select(m => m.PublishedFileId).ToList();
264+
var idList = modList.Select(m => m.ToString()).ToList();
258265
var tasks = new List<Task>();
259266
//blocking
260-
editor.Edit<ulong>(idList, "Mods");
267+
editor.Edit<string>(idList, "Mods");
261268

262-
modList.RemoveAll(m => !idList.Contains(m.PublishedFileId));
263-
foreach (var id in idList)
269+
modList.RemoveAll(m =>
264270
{
265-
if (!modList.Any(m => m.PublishedFileId == id))
266-
{
267-
var mod = new ModItemInfo(ModItemUtils.Create(id));
268-
tasks.Add(Task.Run(mod.UpdateModInfoAsync));
269-
modList.Add(mod);
270-
}
271-
}
271+
var mod = m.ToString();
272+
return idList.Any(mod.Equals);
273+
});
274+
modList.AddRange(idList.Select(id =>
275+
{
276+
var info = new ModItemInfo(ModItemUtils.Create(id));
277+
tasks.Add(Task.Run(info.UpdateModInfoAsync));
278+
return info;
279+
}));
272280
_instanceManager.DedicatedConfig.Mods.Clear();
273281
foreach (var mod in modList)
274282
_instanceManager.DedicatedConfig.Mods.Add(mod);
275283

276284
if (tasks.Any())
277285
Task.WaitAll(tasks.ToArray());
278-
286+
279287
Dispatcher.Invoke(() =>
280288
{
281289
_instanceManager.DedicatedConfig.Save();
282290
});
283291

284292
}
293+
294+
private void UgcServiceTypeBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
295+
{
296+
if ((string) UgcServiceTypeBox.SelectedValue == UGCServiceType.Steam.ToString() &&
297+
_config.UgcServiceType == UGCServiceType.EOS)
298+
MessageBox.Show("Steam workshop is not available with current ugc service!");
299+
}
285300
}
286301
}

‎Torch/Session/TorchSessionManager.cs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ public class TorchSessionManager : Manager, ITorchSessionManager
4646
public TorchSessionManager(ITorchBase torchInstance) : base(torchInstance)
4747
{
4848
_overrideMods = new Dictionary<ulong, MyObjectBuilder_Checkpoint.ModItem>();
49-
_overrideMods.Add(TorchModCore.MOD_ID, ModItemUtils.Create(TorchModCore.MOD_ID));
49+
if (Torch.Config.UgcServiceType == UGCServiceType.Steam)
50+
_overrideMods.Add(TorchModCore.MOD_ID, ModItemUtils.Create(TorchModCore.MOD_ID));
5051
}
5152

5253
/// <inheritdoc/>

‎Torch/Torch.csproj‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
44
<PropertyGroup>

‎Torch/Utils/ModItemUtils.cs‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
1-
using Sandbox.Engine.Networking;
1+
using System.Collections.Generic;
2+
using System.Threading.Tasks;
3+
using Sandbox.Engine.Networking;
4+
using Torch.API;
25
using VRage.Game;
36

47
namespace Torch.Utils
58
{
69
public static class ModItemUtils
710
{
8-
public static MyObjectBuilder_Checkpoint.ModItem Create(ulong modId)
11+
public static MyObjectBuilder_Checkpoint.ModItem Create(ulong modId, string serviceType = null)
912
{
10-
return new MyObjectBuilder_Checkpoint.ModItem(modId, GetDefaultServiceName());
13+
return new MyObjectBuilder_Checkpoint.ModItem(modId, serviceType ?? GetDefaultServiceName());
14+
}
15+
16+
public static MyObjectBuilder_Checkpoint.ModItem Create(string str)
17+
{
18+
var arr = str.Split('-');
19+
return new MyObjectBuilder_Checkpoint.ModItem(ulong.Parse(arr[0]), arr[1]);
1120
}
1221

1322
//because KEEEN!

‎Torch/VRageGame.cs‎

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -159,31 +159,33 @@ private void Create()
159159

160160
MyFileSystem.Reset();
161161
MyInitializer.InvokeBeforeRun(_appSteamId, _appName, _userDataPath);
162+
163+
_log.Info("Loading Dedicated Config");
164+
// object created in SpaceEngineersGame.SetupPerGameSettings()
165+
MySandboxGame.ConfigDedicated.Load();
166+
MyPlatformGameSettings.CONSOLE_COMPATIBLE = MySandboxGame.ConfigDedicated.ConsoleCompatibility;
162167

163168
//Type.GetType("VRage.Steam.MySteamService, VRage.Steam").GetProperty("IsActive").GetSetMethod(true).Invoke(service, new object[] {SteamAPI.Init()});
164-
_log.Info("Initializing UGC services");
165-
IMyGameService service;
166-
IMyUGCService serviceInstance;
167-
var aggregator = new MyServerDiscoveryAggregator();
168-
if (TorchBase.Instance.Config.UgcServiceType == UGCServiceType.Steam)
169+
_log.Info("Initializing network services");
170+
171+
var isEos = TorchBase.Instance.Config.UgcServiceType == UGCServiceType.EOS;
172+
173+
if (isEos)
169174
{
170-
service = MySteamGameService.Create(dedicated, _appSteamId);
171-
serviceInstance = MySteamUgcService.Create(_appSteamId, service);
172-
MySteamGameService.InitNetworking(dedicated,
173-
service,
174-
"Space Engineers",
175-
aggregator);
175+
_log.Info("Running on Epic Online Services.");
176+
_log.Warn("Steam workshop will not work with current settings. Some functions might not work properly!");
176177
}
177-
else
178+
179+
var aggregator = new MyServerDiscoveryAggregator();
180+
MyServiceManager.Instance.AddService<IMyServerDiscovery>(aggregator);
181+
182+
IMyGameService service;
183+
if (isEos)
178184
{
179185
service = MyEOSService.Create();
180186

181-
serviceInstance = MyModIoService.Create(service, "spaceengineers", "264",
182-
"1fb4489996a5e8ffc6ec1135f9985b5b", "331", "f2b64abe55452252b030c48adc0c1f0e",
183-
MyPlatformGameSettings.UGC_TEST_ENVIRONMENT, true);
184-
185187
MyEOSService.InitNetworking(dedicated,
186-
dedicated ? MyPerServerSettings.GameDSName : MyPerServerSettings.GameNameSafe,
188+
"Space Engineers",
187189
service,
188190
"xyza7891A4WeGrpP85BTlBa3BSfUEABN",
189191
"ZdHZVevSVfIajebTnTmh5MVi3KPHflszD9hJB7mRkgg",
@@ -194,25 +196,39 @@ private void Create()
194196
MyEOSService.CreatePlatform(),
195197
MySandboxGame.ConfigDedicated.VerboseNetworkLogging,
196198
Enumerable.Empty<string>(),
197-
(MyServerDiscoveryAggregator) MyGameService.ServerDiscovery,
198-
null);
199-
199+
aggregator,
200+
MyMultiplayer.Channels);
201+
200202
var mockingInventory = new MyMockingInventory(service);
201203
MyServiceManager.Instance.AddService<IMyInventoryService>(mockingInventory);
202204
}
203-
MyServiceManager.Instance.AddService<IMyGameService>(service);
204-
MyServiceManager.Instance.AddService<IMyUGCService>(serviceInstance);
205-
MyGameService.WorkshopService.AddAggregate(serviceInstance);
205+
else
206+
{
207+
service = MySteamGameService.Create(dedicated, _appSteamId);
208+
MyGameService.WorkshopService.AddAggregate(MySteamUgcService.Create(_appSteamId, service));
209+
MySteamGameService.InitNetworking(dedicated,
210+
service,
211+
"Space Engineers",
212+
aggregator);
213+
}
214+
215+
MyServiceManager.Instance.AddService(service);
206216

207-
_log.Info("Initializing services");
208-
MyServiceManager.Instance.AddService(new MyNullMicrophone());
217+
MyGameService.WorkshopService.AddAggregate(MyModIoService.Create(service, "spaceengineers", "264",
218+
"1fb4489996a5e8ffc6ec1135f9985b5b", "331", "f2b64abe55452252b030c48adc0c1f0e",
219+
MyPlatformGameSettings.UGC_TEST_ENVIRONMENT, true));
209220

210-
if (!MyGameService.HasGameServer)
221+
if (!isEos && !MyGameService.HasGameServer)
211222
{
212223
_log.Warn("Network service is not running! Please reinstall dedicated server.");
213224
return;
214225
}
226+
227+
_log.Info("Initializing services");
228+
MyServiceManager.Instance.AddService<IMyMicrophoneService>(new MyNullMicrophone());
215229

230+
MyNetworkMonitor.Init();
231+
216232
_log.Info("Services initialized");
217233
MySandboxGame.InitMultithreading();
218234
// MyInitializer.InitCheckSum();

0 commit comments

Comments
 (0)