diff --git a/Torch.API/ITorchConfig.cs b/Torch.API/ITorchConfig.cs index 34107bc..9e348e1 100644 --- a/Torch.API/ITorchConfig.cs +++ b/Torch.API/ITorchConfig.cs @@ -31,6 +31,8 @@ namespace Torch int FontSize { get; set; } UGCServiceType UgcServiceType { get; set; } bool EntityManagerEnabled { get; set; } + string LoginToken { get; set; } + void Save(string path = null); } } \ No newline at end of file diff --git a/Torch.Server/Patches/SteamLoginPatch.cs b/Torch.Server/Patches/SteamLoginPatch.cs new file mode 100644 index 0000000..8663285 --- /dev/null +++ b/Torch.Server/Patches/SteamLoginPatch.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using NLog; +using Steamworks; +using Torch.Managers.PatchManager; +using Torch.Utils; + +namespace Torch.Patches; + +[PatchShim] +public static class SteamLoginPatch +{ + private static readonly ILogger Log = LogManager.GetCurrentClassLogger(); + + [ReflectedMethodInfo(null, "LogOnAnonymous", TypeName = "VRage.Steam.MySteamGameServer, VRage.Steam")] + private static readonly MethodInfo LoginMethod; + + public static void Patch(PatchContext context) + { + context.GetPattern(LoginMethod).AddPrefix(); + } + + private static bool Prefix() + { +#pragma warning disable CS0618 + var token = TorchBase.Instance.Config.LoginToken; +#pragma warning restore CS0618 + + if (string.IsNullOrEmpty(token)) + return true; + + Log.Info("Logging in to Steam with GSLT"); + SteamGameServer.LogOn(token); + return false; + } +} \ No newline at end of file diff --git a/Torch.Server/TorchConfig.cs b/Torch.Server/TorchConfig.cs index 397d7c9..b0bb9d6 100644 --- a/Torch.Server/TorchConfig.cs +++ b/Torch.Server/TorchConfig.cs @@ -109,6 +109,9 @@ public class TorchConfig : ViewModel, ITorchConfig GroupName = "Server")] public bool EntityManagerEnabled { get; set; } = true; + [Display(Name = "Login Token", Description = "Steam GSLT (can be used if you have dynamic ip)", GroupName = "Server")] + public string LoginToken { get; set; } + // for backward compatibility public void Save(string path = null) => Initializer.Instance?.ConfigPersistent?.Save(path); } \ No newline at end of file