Skip to content

Commit c81f139

Browse files
authored
add gslt login option (#515)
1 parent d98e61c commit c81f139

4 files changed

Lines changed: 48 additions & 2 deletions

File tree

‎Torch.API/ITorchConfig.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public interface ITorchConfig
3232
TorchBranchType BranchName { get; set; }
3333
bool SendLogsToKeen { get; set; }
3434
bool DeleteMiniDumps { get; set; }
35+
string LoginToken { get; set; }
3536

3637
void Save(string path = null);
3738
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System.Reflection;
2+
using NLog;
3+
using Steamworks;
4+
using Torch.Managers.PatchManager;
5+
using Torch.Utils;
6+
7+
namespace Torch.Patches
8+
{
9+
[PatchShim]
10+
public static class SteamLoginPatch
11+
{
12+
private static readonly ILogger Log = LogManager.GetCurrentClassLogger();
13+
14+
#pragma warning disable CS0649
15+
[ReflectedMethodInfo(null, "LogOnAnonymous", TypeName = "VRage.Steam.MySteamGameServer, VRage.Steam")]
16+
private static readonly MethodInfo LoginMethod;
17+
[ReflectedMethodInfo(typeof(SteamLoginPatch), nameof(Prefix))]
18+
private static readonly MethodInfo PrefixMethod;
19+
#pragma warning restore CS0649
20+
21+
public static void Patch(PatchContext context)
22+
{
23+
context.GetPattern(LoginMethod).Prefixes.Add(PrefixMethod);
24+
}
25+
26+
private static bool Prefix()
27+
{
28+
#pragma warning disable CS0618
29+
var token = TorchBase.Instance.Config.LoginToken;
30+
#pragma warning restore CS0618
31+
32+
if (string.IsNullOrEmpty(token))
33+
return true;
34+
35+
Log.Info("Logging in to Steam with GSLT");
36+
SteamGameServer.LogOn(token);
37+
return false;
38+
}
39+
}
40+
}

‎Torch.Server/Torch.Server.csproj‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@
253253
<Compile Include="Initializer.cs" />
254254
<Compile Include="Patches\PromotePatch.cs" />
255255
<Compile Include="Patches\ServerResponsePatch.cs" />
256+
<Compile Include="Patches\SteamLoginPatch.cs" />
256257
<Compile Include="Patches\WorldLoadExceptionPatch.cs" />
257258
<Compile Include="Properties\Annotations.cs" />
258259
<Compile Include="Properties\AssemblyInfo.cs" />

‎Torch.Server/TorchConfig.cs‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public class TorchConfig : CommandLine, ITorchConfig, INotifyPropertyChanged
4444
private TorchBranchType _torchBranch = TorchBranchType.master;
4545
private bool _sendLogsToKeen;
4646
private bool _deleteMiniDumps = true;
47+
private string _loginToken;
4748

4849

4950
/// <inheritdoc />
@@ -179,8 +180,11 @@ public TorchBranchType BranchName
179180
[Arg("delteminidumps", "Delete mini dumps after they are created")]
180181
[Display(Name = "Delete Mini Dumps", Description = "Delete mini dumps after they are created", GroupName = "Logging")]
181182
public bool DeleteMiniDumps { get => _deleteMiniDumps; set => Set(value, ref _deleteMiniDumps); }
182-
183-
183+
184+
[Arg("logintoken", "Steam GSLT")]
185+
[Display(Name = "Login Token", Description = "Steam GSLT (can be used if you have dynamic ip)", GroupName = "Server")]
186+
public string LoginToken { get => _loginToken; set => Set(value, ref _loginToken); }
187+
184188

185189
public event PropertyChangedEventHandler PropertyChanged;
186190

0 commit comments

Comments
 (0)