Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 56 additions & 65 deletions Core/LocalAdmin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public sealed class LocalAdmin : IDisposable
private static int _restarts = -1, _restartsLimit = 4, _restartsTimeWindow = 480; //480 seconds = 8 minutes

internal readonly CommandService CommandService = new();
private readonly string _scpslExecutable;
private readonly string _scpslExecutable = string.Empty;
private volatile bool _processClosing;
private bool _idleMode;
private uint _heartbeatSpanMaxThreshold;
Expand Down Expand Up @@ -107,17 +107,14 @@ internal enum HeartbeatStatus : byte

internal LocalAdmin()
{
if (OperatingSystem.IsWindows())
_scpslExecutable = "SCPSL.exe";
else if (OperatingSystem.IsLinux())
_scpslExecutable = "SCPSL.x86_64";
else
{
ConsoleUtil.WriteLine("Failed - Unsupported platform! Please switch to the Windows, or Linux platform to continue.", ConsoleColor.Red);
// shut up dotnet
_scpslExecutable = string.Empty;
Exit(1);
}
#if OS_WIN32 // Haha, precompiler definitions go brr.
_scpslExecutable = "SCPSL.exe";
#elif OS_LINUX
_scpslExecutable = "SCPSL.x86_64";
#else
ConsoleUtil.WriteLine("Failed - Unsupported platform! Please switch to Windows, or any Linux distribution to continue.", ConsoleColor.Red);
Exit(1);
#endif
}

internal async Task Start(string[] args)
Expand All @@ -133,22 +130,19 @@ internal async Task Start(string[] args)
{
ConsoleUtil.WriteLine($"Welcome to LocalAdmin version {VersionString}!", ConsoleColor.Red);
ConsoleUtil.WriteLine("Can't obtain a valid user home directory path!", ConsoleColor.Red);
if (OperatingSystem.IsWindows())
{
ConsoleUtil.WriteLine("Such error should never occur on Windows.", ConsoleColor.Red);
ConsoleUtil.WriteLine("Open issue on the LocalAdmin GitHub repository (https://github.com/northwood-studios/LocalAdmin-V2/issues) or contact our technical support!", ConsoleColor.Red);
}
else if (OperatingSystem.IsLinux())
{
ConsoleUtil.WriteLine("Make sure to export a valid path, for example using command: export HOME=/home/username-here", ConsoleColor.Red);
ConsoleUtil.WriteLine("You may want to add that command to the top of ~/.bashrc file and restart the terminal session to avoid having to enter that command every time.", ConsoleColor.Red);
}
else
{
ConsoleUtil.WriteLine("You are running LocalAdmin on an unsupported platform, please switch to Windows or Linux!", ConsoleColor.Red);
throw new PlatformNotSupportedException();
}

#if OS_WIN32
ConsoleUtil.WriteLine("Such error should never occur on Windows.", ConsoleColor.Red);
ConsoleUtil.WriteLine("Open issue on the LocalAdmin GitHub repository (https://github.com/northwood-studios/LocalAdmin-V2/issues) or contact our technical support!", ConsoleColor.Red);
#elif OS_LINUX
ConsoleUtil.WriteLine("Make sure to export a valid path, for example using command: export HOME=/home/username-here", ConsoleColor.Red);
ConsoleUtil.WriteLine("You may want to add that command to the top of ~/.bashrc file and restart the terminal session to avoid having to enter that command every time.", ConsoleColor.Red);
#else
ConsoleUtil.WriteLine("You are running LocalAdmin on an unsupported platform, please switch to Windows or Linux!", ConsoleColor.Red);
throw new PlatformNotSupportedException();
#endif
ConsoleUtil.WriteLine("To skip this check, use --skipHomeCheck argument.", ConsoleColor.Red);

Terminate();
return;
}
Expand Down Expand Up @@ -188,7 +182,7 @@ internal async Task Start(string[] args)
if (args.Contains("--acceptEULA", StringComparer.Ordinal) ||
Environment.GetEnvironmentVariable("ACCEPT_SCPSL_EULA")?.ToUpperInvariant() is "1" or "TRUE")
{
DataJson!.EulaAccepted = DateTime.UtcNow;
DataJson.EulaAccepted = DateTime.UtcNow;
autoEula = true;

await SaveJsonOrTerminate();
Expand All @@ -201,7 +195,7 @@ internal async Task Start(string[] args)
ConsoleUtil.WriteLine("", ConsoleColor.Cyan);
ConsoleUtil.WriteLine("Do you accept the EULA? [yes/no]", ConsoleColor.Cyan);

ReadInput((input) =>
ReadInput(input =>
{
if (input == null)
return false;
Expand Down Expand Up @@ -248,7 +242,7 @@ internal async Task Start(string[] args)
Console.WriteLine(string.Empty);
ConsoleUtil.Write($"Port number (default: {DefaultPort}): ", ConsoleColor.Green);

ReadInput((input) =>
ReadInput(input =>
{
if (!string.IsNullOrEmpty(input))
return ushort.TryParse(input, out GamePort);
Expand All @@ -270,7 +264,7 @@ internal async Task Start(string[] args)
switch (capture)
{
case CaptureArgs.None:
if (arg.StartsWith("-", StringComparison.Ordinal) &&
if (arg.StartsWith('-') &&
!arg.StartsWith("--", StringComparison.Ordinal) && arg.Length > 1)
{
for (var i = 1; i < arg.Length; i++)
Expand Down Expand Up @@ -588,7 +582,7 @@ internal async Task Start(string[] args)
/// </summary>
private void StartSession()
{
// Terminate the game, if the game process is exists
// Terminate the game, if the game process is still running.
if (_gameProcess is { HasExited: false })
TerminateGame();

Expand All @@ -613,7 +607,7 @@ private static void Menu()
ConsoleUtil.WriteLine($"SCP: Secret Laboratory - LocalAdmin v. {VersionString}", ConsoleColor.Cyan);
ConsoleUtil.WriteLine(string.Empty, ConsoleColor.Cyan);
ConsoleUtil.WriteLine("Licensed under The MIT License (use command \"license\" to get license text).", ConsoleColor.Cyan);
ConsoleUtil.WriteLine("Copyright by Łukasz \"zabszk\" Jurczyk and KernelError, 2019 - 2025", ConsoleColor.Cyan);
ConsoleUtil.WriteLine($"Copyright by Łukasz \"zabszk\" Jurczyk and KernelError, 2019 - {DateTime.Now:yyyy}", ConsoleColor.Cyan);
ConsoleUtil.WriteLine(string.Empty, ConsoleColor.Cyan);
ConsoleUtil.WriteLine("Type 'help' to get list of available commands.", ConsoleColor.Cyan);
ConsoleUtil.WriteLine(string.Empty, ConsoleColor.Cyan);
Expand All @@ -624,41 +618,38 @@ private static void SetupExitHandlers()
ProcessHandler.Handler.Setup();
AppDomainHandler.Handler.Setup();

if (OperatingSystem.IsWindows())
WindowsHandler.Handler.Setup();
else if (OperatingSystem.IsLinux())
#if OS_WIN32
WindowsHandler.Handler.Setup();
#elif (OS_LINUX && LINUX_SIGNALS)
try
{
#if LINUX_SIGNALS
try
{
UnixHandler.Handler.Setup();
}
catch (DllNotFoundException ex)
{
if (!CheckMonoException(ex)) throw;
}
catch (EntryPointNotFoundException ex)
{
if (!CheckMonoException(ex)) throw;
}
catch (TypeInitializationException ex)
{
switch (ex.InnerException)
{
case DllNotFoundException dll:
if (!CheckMonoException(dll)) throw;
break;
case EntryPointNotFoundException dll:
if (!CheckMonoException(dll)) throw;
break;
default:
throw;
}
}
UnixHandler.Handler.Setup();
}
catch (DllNotFoundException ex)
{
if (!CheckMonoException(ex)) throw;
}
catch (EntryPointNotFoundException ex)
{
if (!CheckMonoException(ex)) throw;
}
catch (TypeInitializationException ex)
{
switch (ex.InnerException)
{
case DllNotFoundException dll:
if (!CheckMonoException(dll)) throw;
break;
case EntryPointNotFoundException dll:
if (!CheckMonoException(dll)) throw;
break;
default:
throw;
}
}
#else
ConsoleUtil.WriteLine("Invalid Linux build! Please download LocalAdmin from GitHub here: https://github.com/northwood-studios/LocalAdmin-V2/releases", ConsoleColor.Red);
ConsoleUtil.WriteLine("Invalid Linux build! Please download LocalAdmin from GitHub here: https://github.com/northwood-studios/LocalAdmin-V2/releases", ConsoleColor.Red);
#endif
}
}

#if LINUX_SIGNALS
Expand Down
73 changes: 41 additions & 32 deletions LocalAdmin V2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,8 @@
<PackageId>LocalAdmin V2</PackageId>
<Company>Northwood Studios</Company>
<Authors>Łukasz "zabszk" Jurczyk, KernelError</Authors>
<Copyright>Copyright by Łukasz "zabszk" Jurczyk and KernelError, 2019 - 2025</Copyright>
<Copyright>Copyright by Łukasz "zabszk" Jurczyk and KernelError, 2019 - $([System.DateTime]::Now.ToString("yyyy"))</Copyright>

<SuppressAotAnalysisWarnings>true</SuppressAotAnalysisWarnings>
<RootAllApplicationAssemblies>false</RootAllApplicationAssemblies>
<IlcTrimMetadata>true</IlcTrimMetadata>
<IlcGenerateCompleteTypeMetadata>false</IlcGenerateCompleteTypeMetadata>
<IlcDisableReflection>false</IlcDisableReflection>
<IlcGenerateStackTraceData>true</IlcGenerateStackTraceData>
<IlcOptimizationPreference>Speed</IlcOptimizationPreference>
<IlcFoldIdenticalMethodBodies>true</IlcFoldIdenticalMethodBodies>
<Optimize>true</Optimize>
<IsPackable>false</IsPackable>
</PropertyGroup>
Expand All @@ -33,34 +25,30 @@
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
</PropertyGroup>

<!-- Linux only exit handling -->
<PropertyGroup Condition="$(RuntimeIdentifier.StartsWith('linux', StringComparison.OrdinalIgnoreCase))">
<DefineConstants>LINUX_SIGNALS</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<PlatformTarget>x64</PlatformTarget>

<PropertyGroup Label="I don't know what this is ¯\_(ツ)_/¯">
<SuppressAotAnalysisWarnings>true</SuppressAotAnalysisWarnings>
<RootAllApplicationAssemblies>false</RootAllApplicationAssemblies>
<IlcTrimMetadata>true</IlcTrimMetadata>
<IlcGenerateCompleteTypeMetadata>false</IlcGenerateCompleteTypeMetadata>
<IlcDisableReflection>false</IlcDisableReflection>
<IlcGenerateStackTraceData>true</IlcGenerateStackTraceData>
<IlcOptimizationPreference>Speed</IlcOptimizationPreference>
<IlcFoldIdenticalMethodBodies>true</IlcFoldIdenticalMethodBodies>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">

<PropertyGroup Label="Common Build Configurations">
<PlatformTarget>x64</PlatformTarget>
<DebugType>none</DebugType>
</PropertyGroup>
<ItemGroup Condition="$(RuntimeIdentifier.StartsWith('linux', StringComparison.OrdinalIgnoreCase))">
<PackageReference Include="Mono.Posix.NETStandard" Version="1.0.0" />
</ItemGroup>

<PropertyGroup>
<DebugType Condition="'$(Configuration)' == 'Debug'">portable</DebugType>
<DebugType Condition="'$(Configuration)' == 'Release'">none</DebugType>

<PublishAot>true</PublishAot>
</PropertyGroup>

<ItemGroup>
<Content Include="LICENSE">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>

<Content Include="NOTICE-LocalAdmin">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<ItemGroup Label="Dependencies (Sources)">
<Content Include="LICENSE" CopyToOutputDirectory="Always"></Content>
<Content Include="NOTICE-LocalAdmin" CopyToOutputDirectory="Always"></Content>

<None Remove=".editorconfig" />
<None Remove=".gitignore" />
Expand All @@ -69,8 +57,29 @@
<None Remove="Properties\launchSettings.json" />
<None Remove="README.md" />
</ItemGroup>
<ItemGroup>

<ItemGroup Label="Dependencies (Packages)">
<PackageReference Include="System.IO.Compression.ZipFile" Version="4.3.0" />
<PackageReference Include="Utf8Json" Version="1.3.7" />
</ItemGroup>

<!-- ================================== -->
<!-- = Windows Specific Configuration = -->
<!-- ================================== -->

<PropertyGroup Condition="$([MSBuild]::IsOSplatform('Windows'))">
<DefineConstants>OS_WIN32</DefineConstants>
</PropertyGroup>

<!-- ================================== -->
<!-- = Linux Specific Configuration = -->
<!-- ================================== -->

<PropertyGroup Condition="$([MSBuild]::IsOSplatform('Linux'))">
<DefineConstants>OS_LINUX;LINUX_SIGNALS</DefineConstants>
</PropertyGroup>

<ItemGroup Condition="$([MSBuild]::IsOSplatform('Linux'))">
<PackageReference Include="Mono.Posix.NETStandard" Version="1.0.0" />
</ItemGroup>
</Project>
Loading