Compare commits

..

8 Commits

Author SHA1 Message Date
zznty
aa7426dfa2 push to new nuget
All checks were successful
Release / Get Version (push) Successful in 5s
Release / Build and Publish Nuget (Torch.API) (push) Successful in 2m0s
Release / Build and Publish Nuget (Torch) (push) Successful in 3m6s
Release / Build and Publish Nuget (Torch.Server) (push) Successful in 3m29s
Release / Build and Publish Package (push) Successful in 4m59s
2024-11-09 19:33:43 +07:00
zznty
7ea0a4f8b9 add optional restart save timeout 2024-11-09 19:28:27 +07:00
zznty
d15985e918 ensure restart save is exclusive to prevent save corruption 2024-11-09 19:06:10 +07:00
zznty
58340e0f5d fix reoccurring entry dll path in args when application restarts 2024-11-09 19:05:40 +07:00
zznty
67bb3fd00c update autoupdate default config
All checks were successful
Release / Get Version (push) Successful in 6s
Release / Build and Publish Package (push) Successful in 8m10s
Release / Build and Publish Nuget (push) Successful in 2m1s
2024-11-01 07:15:49 +07:00
90546a78c2 Update README.md
Some checks failed
Release / Build and Publish Nuget (push) Has been cancelled
Release / Build and Publish Package (push) Has been cancelled
Release / Get Version (push) Has been cancelled
2024-10-27 13:54:31 +00:00
zznty
d301955609 move ui lifetime to a manager for better lifetime control
All checks were successful
Release / Get Version (push) Successful in 4s
Release / Build and Publish Nuget (push) Successful in 2m21s
Release / Build and Publish Package (push) Successful in 2m58s
2024-10-23 16:52:10 +07:00
zznty
264daf7515 fix torch not restarting when start occurs second time 2024-10-23 16:51:41 +07:00
13 changed files with 131 additions and 93 deletions

View File

@@ -5,7 +5,6 @@ on:
branches: [master]
env:
BUILD_CONFIGURATION: Release
DOTNET_NOLOGO: true
DOTNET_CLI_TELEMETRY_OPTOUT: true
@@ -33,36 +32,24 @@ jobs:
name: Build and Publish Nuget
runs-on: ubuntu-latest
needs: [get-version]
strategy:
matrix:
project: [ Torch.API, Torch, Torch.Server ]
steps:
- uses: actions/checkout@master
name: Checkout
- uses: actions/setup-dotnet@v3
- uses: actions/setup-dotnet@v4
name: Setup dotnet
with:
dotnet-version: '8.0.x'
- name: Restore dependencies
run: dotnet restore Torch.Server/Torch.Server.csproj --locked-mode
run: dotnet restore ${{ matrix.project }}/${{ matrix.project }}.csproj --locked-mode
- name: Build
run: dotnet build Torch.Server/Torch.Server.csproj --no-restore -c ${{ env.BUILD_CONFIGURATION }} -p:Version="${{ needs.get-version.outputs.version }}" -p:AssemblyVersion="${{ needs.get-version.outputs.version }}"
- name: Pack
run: dotnet pack ${{ matrix.project }}/${{ matrix.project }}.csproj -o pack --no-restore -p:Version="${{ needs.get-version.outputs.version }}" -p:AssemblyVersion="${{ needs.get-version.outputs.version }}"
- run: dotnet pack -c Release ./Torch.API/Torch.API.csproj -o pack -p:Version="${{ needs.get-version.outputs.version }}" -p:AssemblyVersion="${{ needs.get-version.outputs.version }}" --no-build
- run: dotnet pack -c Release ./Torch/Torch.csproj -o pack -p:Version="${{ needs.get-version.outputs.version }}" -p:AssemblyVersion="${{ needs.get-version.outputs.version }}" --no-build
- run: dotnet pack -c Release ./Torch.Server/Torch.Server.csproj -o pack -p:Version="${{ needs.get-version.outputs.version }}" -p:AssemblyVersion="${{ needs.get-version.outputs.version }}" --no-build
- name: Install Sleet
run: dotnet tool install -g sleet --version 5.1.3
- name: Push Nuget Package
env:
SLEET_FEED_TYPE: s3
SLEET_FEED_PATH: https://nuget.storage.yandexcloud.net
SLEET_FEED_BUCKETNAME: nuget
SLEET_FEED_SERVICEURL: https://storage.yandexcloud.net
SLEET_FEED_ACCESSKEYID: ${{ secrets.S3_KEY_ID }}
SLEET_FEED_SECRETACCESSKEY: ${{ secrets.S3_KEY }}
run: /root/.dotnet/tools/sleet push ./pack
- name: Push
run: dotnet nuget push -s https://ng.zznty.ru/v3/index.json -k ${{ secrets.NUGET_API_KEY }} ./pack/${{ matrix.project }}.${{ needs.get-version.outputs.version }}.nupkg
build:
name: Build and Publish Package
@@ -72,16 +59,14 @@ jobs:
- uses: actions/checkout@master
name: Checkout
- uses: actions/setup-dotnet@v3
- uses: actions/setup-dotnet@v4
name: Setup dotnet
with:
dotnet-version: '8.0.x'
- name: Restore dependencies
run: dotnet restore Torch.Server/Torch.Server.csproj --locked-mode -r win-x64
- name: Publish
run: dotnet publish Torch.Server/Torch.Server.csproj --no-restore --sc -r win-x64 -c ${{ env.BUILD_CONFIGURATION }} -o ./publish -p:Version="${{ needs.get-version.outputs.version }}" -p:AssemblyVersion="${{ needs.get-version.outputs.version }}"
run: dotnet publish Torch.Server/Torch.Server.csproj --no-restore --sc -r win-x64 -o ./publish -p:Version="${{ needs.get-version.outputs.version }}" -p:AssemblyVersion="${{ needs.get-version.outputs.version }}"
- uses: vimtor/action-zip@v1
name: Zip Release

View File

@@ -11,7 +11,7 @@ Torch is the successor to SE Server Extender and gives server admins the tools t
* Extensible using the Torch plugin system
### Fork Difference
* .NET 6.0 runtime
* .NET 8.0 runtime
* Optimized in-game scripts (also newer compiler & language versions)
* Better configuration via cli arguments, environment variables or xml config
* Designed to run multiple instance from same install directory without having you to waste disk space
@@ -19,7 +19,9 @@ Torch is the successor to SE Server Extender and gives server admins the tools t
### Discord
If you have any questions or issues please join our [discord](https://discord.gg/UyYFSe3TyQ)
If you have any questions or issues please join our discord
[![](https://dcbadge.vercel.app/api/server/VAb2zgXHAN)](https://discord.gg/VAb2zgXHAN)
### Installation
@@ -30,7 +32,7 @@ If you have any questions or issues please join our [discord](https://discord.gg
# Building
As a regular dotnet project with cli by running `dotnet build Torch.Server/Torch.Server.csproj`, with VS 2022 or higher, with JB Rider or Fleet.
As a regular dotnet project with cli by running `dotnet build Torch.Server/Torch.Server.csproj`, with VS 2022 or higher or JB Rider.
If you have a more enjoyable server experience because of Torch, please consider supporting us on Patreon. (https://www.patreon.com/TorchSE)

View File

@@ -34,6 +34,7 @@ namespace Torch
string LoginToken { get; set; }
UpdateSource UpdateSource { get; set; }
List<string> Packages { get; set; }
int RestartSaveTimeout { get; set; }
void Save(string path = null);
}

View File

@@ -33,6 +33,11 @@
/// <summary>
/// The save operation timed out
/// </summary>
TimedOut = -5
TimedOut = -5,
/// <summary>
/// Another save operation is in progress
/// </summary>
ConcurrentSaveInProgress = -6
}
}

View File

@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
namespace Torch.Server;
internal static class ApplicationRestartHelper
{
public static void RestartApplication()
{
var exe = Path.Combine(AppContext.BaseDirectory, "Torch.Server.exe");
var args = Environment.GetCommandLineArgs().ToList();
args.RemoveAt(0); // dll entry path
args.RemoveConfigItem("--tempAutostart");
args.RemoveConfigItem("--waitForPid");
args.AddRange([
"--waitForPid", Environment.ProcessId.ToString(),
"--tempAutostart", "true"
]);
Process.Start(new ProcessStartInfo(exe, args));
}
private static void RemoveConfigItem(this List<string> list, string item)
{
var index = list.BinarySearch(item, StringComparer.OrdinalIgnoreCase);
if (index < 0) return;
list.RemoveAt(index);
list.RemoveAt(index);
}
}

View File

@@ -94,27 +94,11 @@ namespace Torch.Server
_server.Init();
var uiThread = new Thread(() =>
{
var ui = new TorchUI(_server);
if (!Config.Autostart && !Config.TempAutostart) return;
SynchronizationContext.SetSynchronizationContext(
new DispatcherSynchronizationContext(Dispatcher.CurrentDispatcher));
ui.ShowDialog();
});
uiThread.SetApartmentState(ApartmentState.STA);
uiThread.Start();
if (Config.Autostart || Config.TempAutostart)
{
Config.TempAutostart = false;
_server.Start();
}
uiThread.Join();
}
}
public static async Task RunSteamCmdAsync(IConfiguration configuration)

View File

@@ -0,0 +1,37 @@
using System.Threading;
using System.Windows.Threading;
using JetBrains.Annotations;
using Torch.Managers;
namespace Torch.Server.Managers;
public class UiManager(TorchServer torchInstance) : Manager(torchInstance)
{
[CanBeNull] private Thread _uiThread;
[CanBeNull] private Dispatcher _dispatcher;
public override void Attach()
{
_uiThread = new Thread(() =>
{
var ui = new TorchUI(torchInstance);
_dispatcher = Dispatcher.CurrentDispatcher;
SynchronizationContext.SetSynchronizationContext(
new DispatcherSynchronizationContext(_dispatcher));
ui.ShowDialog();
});
_uiThread.SetApartmentState(ApartmentState.STA);
_uiThread.Start();
}
public override void Detach()
{
_dispatcher?.InvokeShutdown();
if (Thread.CurrentThread != _uiThread)
_uiThread?.Join();
}
}

View File

@@ -114,14 +114,17 @@ public class TorchConfig : ViewModel, ITorchConfig
public UpdateSource UpdateSource { get; set; } = new()
{
Repository = "PveTeam/Torch",
Url = "https://api.github.com",
Repository = "PvE/Torch",
Url = "https://git.zznty.ru/api/v1",
SourceType = UpdateSourceType.Github
};
[Display(Name = "Packages", Description = "Packages to install and use.", GroupName = "Server")]
public List<string> Packages { get; set; } = new();
[Display(Name = "Restart Save Timeout", Description = "Timeout for save operation on restart in seconds.", GroupName = "Server")]
public int RestartSaveTimeout { get; set; }
// for backward compatibility
public void Save(string path = null) => Initializer.Instance?.ConfigPersistent?.Save(path);
}

View File

@@ -56,6 +56,8 @@ namespace Torch.Server
if (config.EntityManagerEnabled)
AddManager(new EntityControlManager(this));
AddManager(new RemoteAPIManager(this));
if (!ApplicationContext.Current.IsService && !config.NoGui)
AddManager(new UiManager(this));
var sessionManager = Managers.GetManager<ITorchSessionManager>();
sessionManager.AddFactory(_ => new MultiplayerManagerDedicated(this));
@@ -185,7 +187,7 @@ namespace Torch.Server
if (IsRunning || HasRun)
{
Restart();
Restart(false);
return;
}
@@ -246,7 +248,8 @@ namespace Torch.Server
{
if (save)
{
var saveResult = Save().Result;
var saveResult = Save(Config.RestartSaveTimeout == 0 ? -1 : Config.RestartSaveTimeout,
exclusive: true).Result;
if (saveResult is not (GameSaveResult.Success or GameSaveResult.TimedOut))
{
Log.Error("Save failed due to {Reason}. Restart aborted!", saveResult);
@@ -267,24 +270,7 @@ namespace Torch.Server
)
return;
var exe = Path.Combine(AppContext.BaseDirectory, "Torch.Server.exe");
var args = Environment.GetCommandLineArgs();
for (var i = 0; i < args.Length; i++)
{
if (args[i].Contains(' '))
args[i] = $"\"{args[i]}\"";
if (!args[i].Contains("--tempAutostart", StringComparison.InvariantCultureIgnoreCase) &&
!args[i].Contains("--waitForPid", StringComparison.InvariantCultureIgnoreCase))
continue;
args[i] = string.Empty;
args[++i] = string.Empty;
}
Process.Start(exe, $"--waitForPid {Environment.ProcessId} --tempAutostart true {string.Join(" ", args)}");
ApplicationRestartHelper.RestartApplication();
})
{
Name = "Restart thread"

View File

@@ -33,24 +33,7 @@ internal class UnhandledExceptionHandler
Console.WriteLine("Restarting in 5 seconds.");
Thread.Sleep(5000);
var exe = Path.Combine(AppContext.BaseDirectory, "Torch.Server.exe");
var args = Environment.GetCommandLineArgs();
for (var i = 0; i < args.Length; i++)
{
if (args[i].Contains(' '))
args[i] = $"\"{args[i]}\"";
if (!args[i].Contains("--tempAutostart", StringComparison.InvariantCultureIgnoreCase) &&
!args[i].Contains("--waitForPid", StringComparison.InvariantCultureIgnoreCase))
continue;
args[i] = string.Empty;
args[++i] = string.Empty;
}
Process.Start(exe, $"--waitForPid {Environment.ProcessId} --tempAutostart true {string.Join(" ", args)}");
ApplicationRestartHelper.RestartApplication();
}
else
{

View File

@@ -65,7 +65,8 @@ internal static class AssemblyRewriter
{
using var assembly = AssemblyDefinition.ReadAssembly(inputStream, new()
{
AssemblyResolver = resolver
AssemblyResolver = resolver,
ReadSymbols = true
});
foreach (var fieldDefinition in FindAllToRewrite(assembly.MainModule))
{

View File

@@ -293,15 +293,20 @@ namespace Torch
{
}
private bool _disposed = false;
/// <inheritdoc />
public virtual void Destroy()
{
if (_disposed) return;
Game.SignalDestroy();
if (!Game.WaitFor(VRageGame.GameState.Destroyed))
Log.Warn("Failed to wait for the game to be destroyed");
Game = null;
Managers.Detach();
_disposed = true;
}
#endregion
@@ -325,7 +330,7 @@ namespace Torch
if (MyAsyncSaving.InProgress || _inProgressSaves > 0)
{
Log.Error("Failed to save game, game is already saving");
return null;
return Task.FromResult(GameSaveResult.ConcurrentSaveInProgress);
}
}

7
global.json Normal file
View File

@@ -0,0 +1,7 @@
{
"sdk": {
"version": "8.0.0",
"rollForward": "latestFeature",
"allowPrerelease": false
}
}