Skip to content

Commit

Permalink
final fix + new config option to change service between Steam and EOS
Browse files Browse the repository at this point in the history
  • Loading branch information
LTP committed Feb 12, 2021
1 parent b372230 commit 169b543
Show file tree
Hide file tree
Showing 18 changed files with 251 additions and 135 deletions.
7 changes: 6 additions & 1 deletion Torch.API/ITorchConfig.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using Torch.API;

namespace Torch
{
Expand All @@ -24,7 +25,11 @@ public interface ITorchConfig
string ChatColor { get; set; }
string TestPlugin { get; set; }
bool DisconnectOnRestart { get; set; }
int WindowWidth { get; set; }
int WindowHeight { get; set; }
int FontSize { get; set; }
UGCServiceType UgcServiceType { get; set; }

bool Save(string path = null);
void Save(string path = null);
}
}
2 changes: 1 addition & 1 deletion Torch.API/Torch.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@
<Compile Include="Session\ITorchSessionManager.cs" />
<Compile Include="Session\TorchSessionState.cs" />
<Compile Include="TorchGameState.cs" />
<Compile Include="UGCServiceType.cs" />
<Compile Include="Utils\ColorUtils.cs" />
<Compile Include="Utils\ModItemUtils.cs" />
<Compile Include="Utils\StringUtils.cs" />
<Compile Include="WebAPI\JenkinsQuery.cs" />
<Compile Include="WebAPI\PluginQuery.cs" />
Expand Down
8 changes: 8 additions & 0 deletions Torch.API/UGCServiceType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Torch.API
{
public enum UGCServiceType
{
Steam,
EOS
}
}
3 changes: 2 additions & 1 deletion Torch.Server/Commands/WhitelistCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ public void Off()
[Command("add", "Add a Steam ID to the whitelist.")]
public void Add(ulong steamId)
{
if (Config.Whitelist.Add(steamId))
if (!Config.Whitelist.Contains(steamId))
{
Config.Whitelist.Add(steamId);
Context.Respond($"Added {steamId} to the whitelist.");
Config.Save();
}
Expand Down
42 changes: 21 additions & 21 deletions Torch.Server/Initializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ namespace Torch.Server
{
public class Initializer
{
[Obsolete("It's hack. Do not use it!")]
internal static Initializer Instance { get; private set; }

private static readonly Logger Log = LogManager.GetLogger(nameof(Initializer));
private bool _init;
private const string STEAMCMD_DIR = "steamcmd";
Expand All @@ -32,17 +35,17 @@ public class Initializer
login anonymous
app_update 298740
quit";

private TorchConfig _config;
private TorchServer _server;
private string _basePath;

public TorchConfig Config => _config;
internal Persistent<TorchConfig> ConfigPersistent { get; private set; }
public TorchConfig Config => ConfigPersistent?.Data;
public TorchServer Server => _server;

public Initializer(string basePath)
{
_basePath = basePath;
Instance = this;
}

public bool Initialize(string[] args)
Expand Down Expand Up @@ -94,15 +97,15 @@ public bool Initialize(string[] args)
File.Copy(havokSource, havokTarget);
}

_config = InitConfig();
if (!_config.Parse(args))
InitConfig();
if (!Config.Parse(args))
return false;

if (!string.IsNullOrEmpty(_config.WaitForPID))
if (!string.IsNullOrEmpty(Config.WaitForPID))
{
try
{
var pid = int.Parse(_config.WaitForPID);
var pid = int.Parse(Config.WaitForPID);
var waitProc = Process.GetProcessById(pid);
Log.Info("Continuing in 5 seconds.");
Log.Warn($"Waiting for process {pid} to close");
Expand All @@ -124,17 +127,17 @@ public bool Initialize(string[] args)

public void Run()
{
_server = new TorchServer(_config);
_server = new TorchServer(Config);

if (_config.NoGui)
if (Config.NoGui)
{
_server.Init();
_server.Start();
}
else
{
#if !DEBUG
if (!_config.IndependentConsole)
if (!Config.IndependentConsole)
{
Console.SetOut(TextWriter.Null);
NativeMethods.FreeConsole();
Expand All @@ -145,9 +148,9 @@ public void Run()
{
_server.Init();
if (_config.Autostart || _config.TempAutostart)
if (Config.Autostart || Config.TempAutostart)
{
_config.TempAutostart = false;
Config.TempAutostart = false;
_server.Start();
}
});
Expand All @@ -159,22 +162,19 @@ public void Run()
}
}

private TorchConfig InitConfig()
private void InitConfig()
{
var configName = "Torch.cfg";
var configPath = Path.Combine(Directory.GetCurrentDirectory(), configName);
if (File.Exists(configName))
{
Log.Info($"Loading config {configPath}");
return TorchConfig.LoadFrom(configPath);
Log.Info($"Loading config {configName}");
}
else
{
Log.Info($"Generating default config at {configPath}");
var config = new TorchConfig {InstancePath = Path.GetFullPath("Instance")};
config.Save(configPath);
return config;
}
ConfigPersistent = Persistent<TorchConfig>.Load(configPath);
}

public static void RunSteamCmd()
Expand Down Expand Up @@ -267,13 +267,13 @@ private void HandleException(object sender, UnhandledExceptionEventArgs e)
//MyMiniDump.Write(path, options, MyMiniDump.ExceptionInfo.Present);
}
LogManager.Flush();
if (_config.RestartOnCrash)
if (Config.RestartOnCrash)
{
Console.WriteLine("Restarting in 5 seconds.");
Thread.Sleep(5000);
var exe = typeof(Program).Assembly.Location;
_config.WaitForPID = Process.GetCurrentProcess().Id.ToString();
Process.Start(exe, _config.ToString());
Config.WaitForPID = Process.GetCurrentProcess().Id.ToString();
Process.Start(exe, Config.ToString());
}
else
{
Expand Down
1 change: 0 additions & 1 deletion Torch.Server/Torch.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,6 @@
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\TransformOnBuild.targets" />
<PropertyGroup>
Expand Down
Loading

0 comments on commit 169b543

Please sign in to comment.