mod.io support and eos fix

This commit is contained in:
zznty
2021-05-07 19:02:28 +07:00
parent a5743701ea
commit 3e01cecdcc
7 changed files with 124 additions and 52 deletions

View File

@@ -134,13 +134,21 @@ namespace Torch.Server.Managers
public override void Attach() public override void Attach()
{ {
base.Attach(); base.Attach();
if (Torch.Config.UgcServiceType == UGCServiceType.Steam)
{
_gameServerValidateAuthTicketReplacer = _gameServerValidateAuthTicketFactory.Invoke(); _gameServerValidateAuthTicketReplacer = _gameServerValidateAuthTicketFactory.Invoke();
_gameServerUserGroupStatusReplacer = _gameServerUserGroupStatusFactory.Invoke(); _gameServerUserGroupStatusReplacer = _gameServerUserGroupStatusFactory.Invoke();
}
else
{
_gameServerValidateAuthTicketReplacer = _eosServerValidateAuthTicketFactory.Invoke();
_gameServerUserGroupStatusReplacer = _eosServerUserGroupStatusFactory.Invoke();
}
_gameServerValidateAuthTicketReplacer.Replace( _gameServerValidateAuthTicketReplacer.Replace(
new Action<ulong, JoinResult, ulong, string>(ValidateAuthTicketResponse), MyGameService.GameServer); new Action<ulong, JoinResult, ulong, string>(ValidateAuthTicketResponse), MyGameService.GameServer);
_gameServerUserGroupStatusReplacer.Replace(new Action<ulong, ulong, bool, bool>(UserGroupStatusResponse), _gameServerUserGroupStatusReplacer.Replace(new Action<ulong, ulong, bool, bool>(UserGroupStatusResponse),
MyGameService.GameServer); MyGameService.GameServer);
_log.Info("Inserted steam authentication intercept"); _log.Info("Inserted authentication intercept");
} }
/// <inheritdoc/> /// <inheritdoc/>
@@ -150,7 +158,7 @@ namespace Torch.Server.Managers
_gameServerValidateAuthTicketReplacer.Restore(MyGameService.GameServer); _gameServerValidateAuthTicketReplacer.Restore(MyGameService.GameServer);
if (_gameServerUserGroupStatusReplacer != null && _gameServerUserGroupStatusReplacer.Replaced) if (_gameServerUserGroupStatusReplacer != null && _gameServerUserGroupStatusReplacer.Replaced)
_gameServerUserGroupStatusReplacer.Restore(MyGameService.GameServer); _gameServerUserGroupStatusReplacer.Restore(MyGameService.GameServer);
_log.Info("Removed steam authentication intercept"); _log.Info("Removed authentication intercept");
base.Detach(); base.Detach();
} }
@@ -164,6 +172,14 @@ namespace Torch.Server.Managers
typeof(MyDedicatedServerBase), "GameServer_UserGroupStatus")] typeof(MyDedicatedServerBase), "GameServer_UserGroupStatus")]
private static Func<ReflectedEventReplacer> _gameServerUserGroupStatusFactory; private static Func<ReflectedEventReplacer> _gameServerUserGroupStatusFactory;
[ReflectedEventReplace("VRage.EOS.MyEOSGameServer, VRage.EOS", "ValidateAuthTicketResponse",
typeof(MyDedicatedServerBase), "GameServer_ValidateAuthTicketResponse")]
private static Func<ReflectedEventReplacer> _eosServerValidateAuthTicketFactory;
[ReflectedEventReplace("VRage.EOS.MyEOSGameServer, VRage.EOS", "UserGroupStatusResponse",
typeof(MyDedicatedServerBase), "GameServer_UserGroupStatus")]
private static Func<ReflectedEventReplacer> _eosServerUserGroupStatusFactory;
private ReflectedEventReplacer _gameServerValidateAuthTicketReplacer; private ReflectedEventReplacer _gameServerValidateAuthTicketReplacer;
private ReflectedEventReplacer _gameServerUserGroupStatusReplacer; private ReflectedEventReplacer _gameServerUserGroupStatusReplacer;
#pragma warning restore 649 #pragma warning restore 649

View File

@@ -7,8 +7,10 @@ using System.Threading.Tasks;
using System.Windows.Threading; using System.Windows.Threading;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using NLog; using NLog;
using Sandbox.Engine.Networking;
using VRage.Game; using VRage.Game;
using Torch.Server.Annotations; using Torch.Server.Annotations;
using Torch.Utils;
using Torch.Utils.SteamWorkshopTools; using Torch.Utils.SteamWorkshopTools;
namespace Torch.Server.ViewModels namespace Torch.Server.ViewModels
@@ -84,6 +86,15 @@ namespace Torch.Server.ViewModels
} }
} }
public string UgcService
{
get { return _modItem.PublishedServiceName; }
set
{
SetValue(ref _modItem.PublishedServiceName, value);
}
}
/// <summary> /// <summary>
/// Constructor, returns a new ModItemInfo instance /// Constructor, returns a new ModItemInfo instance
/// </summary> /// </summary>
@@ -101,6 +112,9 @@ namespace Torch.Server.ViewModels
/// <returns></returns> /// <returns></returns>
public async Task<bool> UpdateModInfoAsync() public async Task<bool> UpdateModInfoAsync()
{ {
if (UgcService.ToLower() == "mod.io")
return true;
var msg = ""; var msg = "";
var workshopService = WebAPI.Instance; var workshopService = WebAPI.Instance;
PublishedItemDetails modInfo = null; PublishedItemDetails modInfo = null;
@@ -127,5 +141,10 @@ namespace Torch.Server.ViewModels
return true; return true;
} }
} }
public override string ToString()
{
return $"{PublishedFileId}-{UgcService}";
}
} }
} }

View File

@@ -103,6 +103,7 @@
<ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition/> <RowDefinition/>
@@ -115,10 +116,11 @@
VerticalAlignment="Center" Grid.Column="0" Grid.Row="1"/> VerticalAlignment="Center" Grid.Column="0" Grid.Row="1"/>
<TextBox Name="AddModIDTextBox" Grid.Column="1" VerticalContentAlignment="Center" <TextBox Name="AddModIDTextBox" Grid.Column="1" VerticalContentAlignment="Center"
HorizontalAlignment="Stretch" MinWidth="100px" Margin="6px 4px" Grid.Row="1"/> HorizontalAlignment="Stretch" MinWidth="100px" Margin="6px 4px" Grid.Row="1"/>
<Button Content="Add" Grid.Column="2" Margin="6px 0" Width="60px" Height="40px" Click="AddBtn_OnClick" Grid.Row="1"/> <ComboBox Grid.Column="2" Grid.Row="1" x:Name="UgcServiceTypeBox" SelectionChanged="UgcServiceTypeBox_OnSelectionChanged" SelectedValuePath="Value" DisplayMemberPath="Key"/>
<Button Content="Remove" Grid.Column="3" Margin="6px 0" Width="60px" Height="40px" Click="RemoveBtn_OnClick" Grid.Row="1" <Button Content="Add" Grid.Column="3" Margin="6px 0" Width="60px" Height="40px" Click="AddBtn_OnClick" Grid.Row="1"/>
<Button Content="Remove" Grid.Column="4" Margin="6px 0" Width="60px" Height="40px" Click="RemoveBtn_OnClick" Grid.Row="1"
IsEnabled="{Binding ElementName=ModList, Path=SelectedItems.Count}"/> IsEnabled="{Binding ElementName=ModList, Path=SelectedItems.Count}"/>
<Button Content="Bulk Edit" Grid.Column="4" Margin="6px 0" Width="60px" Height="40px" Click="BulkButton_OnClick" Grid.Row="1"/> <Button Content="Bulk Edit" Grid.Column="5" Margin="6px 0" Width="60px" Height="40px" Click="BulkButton_OnClick" Grid.Row="1"/>
</Grid> </Grid>
<Button Content="Save Config" Grid.Row="2" VerticalAlignment="Bottom" HorizontalAlignment="Right" Margin="6px" Grid.Column="3" Width="80px" Height="40px" Click="SaveBtn_OnClick"/> <Button Content="Save Config" Grid.Row="2" VerticalAlignment="Bottom" HorizontalAlignment="Right" Margin="6px" Grid.Column="3" Width="80px" Height="40px" Click="SaveBtn_OnClick"/>

View File

@@ -21,6 +21,7 @@ using System.Windows.Threading;
using VRage.Game; using VRage.Game;
using NLog; using NLog;
using Sandbox.Engine.Networking; using Sandbox.Engine.Networking;
using Torch.API;
using Torch.Server.Managers; using Torch.Server.Managers;
using Torch.API.Managers; using Torch.API.Managers;
using Torch.Server.ViewModels; using Torch.Server.ViewModels;
@@ -41,6 +42,7 @@ namespace Torch.Server.Views
ModItemInfo _draggedMod; ModItemInfo _draggedMod;
bool _hasOrderChanged = false; bool _hasOrderChanged = false;
bool _isSortedByLoadOrder = true; bool _isSortedByLoadOrder = true;
private readonly ITorchConfig _config;
//private List<BindingExpression> _bindingExpressions = new List<BindingExpression>(); //private List<BindingExpression> _bindingExpressions = new List<BindingExpression>();
/// <summary> /// <summary>
@@ -51,11 +53,16 @@ namespace Torch.Server.Views
InitializeComponent(); InitializeComponent();
_instanceManager = TorchBase.Instance.Managers.GetManager<InstanceManager>(); _instanceManager = TorchBase.Instance.Managers.GetManager<InstanceManager>();
_instanceManager.InstanceLoaded += _instanceManager_InstanceLoaded; _instanceManager.InstanceLoaded += _instanceManager_InstanceLoaded;
_config = TorchBase.Instance.Config;
//var mods = _instanceManager.DedicatedConfig?.Mods; //var mods = _instanceManager.DedicatedConfig?.Mods;
//if( mods != null) //if( mods != null)
// DataContext = new ObservableCollection<MyObjectBuilder_Checkpoint.ModItem>(); // DataContext = new ObservableCollection<MyObjectBuilder_Checkpoint.ModItem>();
DataContext = _instanceManager.DedicatedConfig?.Mods; DataContext = _instanceManager.DedicatedConfig?.Mods;
UgcServiceTypeBox.ItemsSource = new[]
{
new KeyValuePair<string, string>("Steam", "steam"),
new KeyValuePair<string, string>("Mod.Io", "mod.io")
};
// Gets called once all children are loaded // Gets called once all children are loaded
//Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new Action(ApplyStyles)); //Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new Action(ApplyStyles));
} }
@@ -98,8 +105,8 @@ namespace Torch.Server.Views
{ {
if (TryExtractId(AddModIDTextBox.Text, out ulong id)) if (TryExtractId(AddModIDTextBox.Text, out ulong id))
{ {
var mod = new ModItemInfo(ModItemUtils.Create(id)); var mod = new ModItemInfo(ModItemUtils.Create(id, UgcServiceTypeBox.SelectedValue?.ToString()));
//mod.PublishedFileId = id;
_instanceManager.DedicatedConfig.Mods.Add(mod); _instanceManager.DedicatedConfig.Mods.Add(mod);
Task.Run(mod.UpdateModInfoAsync) Task.Run(mod.UpdateModInfoAsync)
.ContinueWith((t) => .ContinueWith((t) =>
@@ -254,21 +261,22 @@ namespace Torch.Server.Views
//let's see just how poorly we can do this //let's see just how poorly we can do this
var modList = ((MtObservableList<ModItemInfo>)DataContext).ToList(); var modList = ((MtObservableList<ModItemInfo>)DataContext).ToList();
var idList = modList.Select(m => m.PublishedFileId).ToList(); var idList = modList.Select(m => m.ToString()).ToList();
var tasks = new List<Task>(); var tasks = new List<Task>();
//blocking //blocking
editor.Edit<ulong>(idList, "Mods"); editor.Edit<string>(idList, "Mods");
modList.RemoveAll(m => !idList.Contains(m.PublishedFileId)); modList.RemoveAll(m =>
foreach (var id in idList)
{ {
if (!modList.Any(m => m.PublishedFileId == id)) var mod = m.ToString();
return idList.Any(mod.Equals);
});
modList.AddRange(idList.Select(id =>
{ {
var mod = new ModItemInfo(ModItemUtils.Create(id)); var info = new ModItemInfo(ModItemUtils.Create(id));
tasks.Add(Task.Run(mod.UpdateModInfoAsync)); tasks.Add(Task.Run(info.UpdateModInfoAsync));
modList.Add(mod); return info;
} }));
}
_instanceManager.DedicatedConfig.Mods.Clear(); _instanceManager.DedicatedConfig.Mods.Clear();
foreach (var mod in modList) foreach (var mod in modList)
_instanceManager.DedicatedConfig.Mods.Add(mod); _instanceManager.DedicatedConfig.Mods.Add(mod);
@@ -282,5 +290,12 @@ namespace Torch.Server.Views
}); });
} }
private void UgcServiceTypeBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
if ((string) UgcServiceTypeBox.SelectedValue == UGCServiceType.Steam.ToString() &&
_config.UgcServiceType == UGCServiceType.EOS)
MessageBox.Show("Steam workshop is not available with current ugc service!");
}
} }
} }

View File

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup> <PropertyGroup>

View File

@@ -1,13 +1,22 @@
using Sandbox.Engine.Networking; using System.Collections.Generic;
using System.Threading.Tasks;
using Sandbox.Engine.Networking;
using Torch.API;
using VRage.Game; using VRage.Game;
namespace Torch.Utils namespace Torch.Utils
{ {
public static class ModItemUtils public static class ModItemUtils
{ {
public static MyObjectBuilder_Checkpoint.ModItem Create(ulong modId) public static MyObjectBuilder_Checkpoint.ModItem Create(ulong modId, string serviceType = null)
{ {
return new MyObjectBuilder_Checkpoint.ModItem(modId, GetDefaultServiceName()); return new MyObjectBuilder_Checkpoint.ModItem(modId, serviceType ?? GetDefaultServiceName());
}
public static MyObjectBuilder_Checkpoint.ModItem Create(string str)
{
var arr = str.Split('-');
return new MyObjectBuilder_Checkpoint.ModItem(ulong.Parse(arr[0]), arr[1]);
} }
//because KEEEN! //because KEEEN!

View File

@@ -161,29 +161,26 @@ namespace Torch
MyInitializer.InvokeBeforeRun(_appSteamId, _appName, _userDataPath); MyInitializer.InvokeBeforeRun(_appSteamId, _appName, _userDataPath);
//Type.GetType("VRage.Steam.MySteamService, VRage.Steam").GetProperty("IsActive").GetSetMethod(true).Invoke(service, new object[] {SteamAPI.Init()}); //Type.GetType("VRage.Steam.MySteamService, VRage.Steam").GetProperty("IsActive").GetSetMethod(true).Invoke(service, new object[] {SteamAPI.Init()});
_log.Info("Initializing UGC services"); _log.Info("Initializing network services");
IMyGameService service;
IMyUGCService serviceInstance; var isEos = TorchBase.Instance.Config.UgcServiceType == UGCServiceType.EOS;
var aggregator = new MyServerDiscoveryAggregator();
if (TorchBase.Instance.Config.UgcServiceType == UGCServiceType.Steam) if (isEos)
{ {
service = MySteamGameService.Create(dedicated, _appSteamId); _log.Info("Running on Epic Online Services.");
serviceInstance = MySteamUgcService.Create(_appSteamId, service); _log.Warn("Steam workshop will not work with current settings. Some functions might not work properly!");
MySteamGameService.InitNetworking(dedicated,
service,
"Space Engineers",
aggregator);
} }
else
var aggregator = new MyServerDiscoveryAggregator();
MyServiceManager.Instance.AddService<IMyServerDiscovery>(aggregator);
IMyGameService service;
if (isEos)
{ {
service = MyEOSService.Create(); service = MyEOSService.Create();
serviceInstance = MyModIoService.Create(service, "spaceengineers", "264",
"1fb4489996a5e8ffc6ec1135f9985b5b", "331", "f2b64abe55452252b030c48adc0c1f0e",
MyPlatformGameSettings.UGC_TEST_ENVIRONMENT, true);
MyEOSService.InitNetworking(dedicated, MyEOSService.InitNetworking(dedicated,
dedicated ? MyPerServerSettings.GameDSName : MyPerServerSettings.GameNameSafe, "Space Engineers",
service, service,
"xyza7891A4WeGrpP85BTlBa3BSfUEABN", "xyza7891A4WeGrpP85BTlBa3BSfUEABN",
"ZdHZVevSVfIajebTnTmh5MVi3KPHflszD9hJB7mRkgg", "ZdHZVevSVfIajebTnTmh5MVi3KPHflszD9hJB7mRkgg",
@@ -194,25 +191,39 @@ namespace Torch
MyEOSService.CreatePlatform(), MyEOSService.CreatePlatform(),
MySandboxGame.ConfigDedicated.VerboseNetworkLogging, MySandboxGame.ConfigDedicated.VerboseNetworkLogging,
Enumerable.Empty<string>(), Enumerable.Empty<string>(),
(MyServerDiscoveryAggregator) MyGameService.ServerDiscovery, aggregator,
null); Array.Empty<byte>());
var mockingInventory = new MyMockingInventory(service); var mockingInventory = new MyMockingInventory(service);
MyServiceManager.Instance.AddService<IMyInventoryService>(mockingInventory); MyServiceManager.Instance.AddService<IMyInventoryService>(mockingInventory);
} }
MyServiceManager.Instance.AddService<IMyGameService>(service); else
MyServiceManager.Instance.AddService<IMyUGCService>(serviceInstance); {
MyGameService.WorkshopService.AddAggregate(serviceInstance); service = MySteamGameService.Create(dedicated, _appSteamId);
MyGameService.WorkshopService.AddAggregate(MySteamUgcService.Create(_appSteamId, service));
MySteamGameService.InitNetworking(dedicated,
service,
"Space Engineers",
aggregator);
}
_log.Info("Initializing services"); MyServiceManager.Instance.AddService(service);
MyServiceManager.Instance.AddService(new MyNullMicrophone());
if (!MyGameService.HasGameServer) MyGameService.WorkshopService.AddAggregate(MyModIoService.Create(service, "spaceengineers", "264",
"1fb4489996a5e8ffc6ec1135f9985b5b", "331", "f2b64abe55452252b030c48adc0c1f0e",
MyPlatformGameSettings.UGC_TEST_ENVIRONMENT, true));
if (!isEos && !MyGameService.HasGameServer)
{ {
_log.Warn("Network service is not running! Please reinstall dedicated server."); _log.Warn("Network service is not running! Please reinstall dedicated server.");
return; return;
} }
_log.Info("Initializing services");
MyServiceManager.Instance.AddService<IMyMicrophoneService>(new MyNullMicrophone());
MyNetworkMonitor.Init();
_log.Info("Services initialized"); _log.Info("Services initialized");
MySandboxGame.InitMultithreading(); MySandboxGame.InitMultithreading();
// MyInitializer.InitCheckSum(); // MyInitializer.InitCheckSum();