Skip to content

Commit

Permalink
Implements 'Suicidal Mode' and an option to supress the Error Box com…
Browse files Browse the repository at this point in the history
…plaining about running on privileged user.

For #56
  • Loading branch information
Lisias committed Mar 29, 2024
1 parent 49109be commit 90db64b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
7 changes: 6 additions & 1 deletion Source/KSPe/FatalErrors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ internal static void Show(Exception e)

internal static class RunningAsPrivilegedUser
{
private const string URL = "https://github.com/net-lisias-ksp/KSPe/issues/56";
private const string URL = "http://ksp.lisias.net/add-ons/KSPe/Support/running-KSP-as-privileged-user";
private static readonly string MSG = @"KSPe detected you are running KSP on an Priviledged Account (<b>Administrator</b> on Windows, <b>root</b> on UNIX).
<B>THIS IS A SECURITY NIGHTMARE</B>, you are putting youself in serious risk and KSPe urges you to reach us for help and fix whatever is the underlying issue that made you do this stunt.
Expand All @@ -278,6 +278,11 @@ internal static void Show()

Startup.QuitOnDestroy = shown = true;
if (null != GameObject.Find("KSPe.FatalError.RunningAsPrivilegedUser")) return; // Already being shown.
if (OPTIONS.AllowRunningAsPrivilegedUser)
{
Log.error("Fatal Error RunningAsPrivilegedUser was omitted. You really should visit {0}", URL);
return;
}

GameObject go = new GameObject("KSPe.FatalError.RunningAsPrivilegedUser");
FatalErrorMsgBox dlg = go.AddComponent<FatalErrorMsgBox>();
Expand Down
15 changes: 14 additions & 1 deletion Source/KSPe/Globals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ You should have received a copy of the GNU General Public License 2.0
*/
using System;
using System.Collections.Generic;

using KSPE = KSPe;

namespace KSPe
{
// CAUTION! This class CAN NOT use the KSPe Logging Facilities, as it's a dependency from it!!
// CAUTION! This class CAN NOT use the KSPe Logging Facilities, as it's a dependency for it!!
public class Globals
{
public class LogConfig
Expand Down Expand Up @@ -190,4 +191,16 @@ internal static void info(string msg, params object[] @params)
}
}

public static class OPTIONS
{
public static readonly bool SuicidalMode;
public static readonly bool AllowRunningAsPrivilegedUser;

static OPTIONS()
{
SuicidalMode = -1 != Environment.GetCommandLineArgs().IndexOf("-i-am-suicidal");
AllowRunningAsPrivilegedUser = SuicidalMode && -1 != Environment.GetCommandLineArgs().IndexOf("-allows-running-as-privileged-user");
}
}

}
13 changes: 12 additions & 1 deletion Source/KSPe/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,24 @@ private void Start()
{
Log.force("Version {0}, on KSP {1} under Unity {2}", Version.Text, Versioning.GetVersionStringFull(), UnityEngine.Application.unityVersion);
SanityChecks.DoIt();
if (OPTIONS.SuicidalMode)
Log.force("You configured KSP to run in Suicidal Mode. Good luck!");
}

private void Awake()
{
if (Multiplatform.LowLevelTools.Security.isElevated)
{
FatalErrors.RunningAsPrivilegedUser.Show();
return;
if (!OPTIONS.AllowRunningAsPrivilegedUser) return;
}

if (null != myGameObject)
{
Log.warn("Whoopsy... It looks KSPe was loaded twice. Aborting the redundant initialisation.");
return;
}

myGameObject = new GameObject(typeof(Startup).AssemblyQualifiedName);
try
{
Expand Down Expand Up @@ -90,6 +93,14 @@ public static bool QuitOnDestroy
{
if (value)
{
if (OPTIONS.SuicidalMode)
{
Log.force("I was told to quit the game, but you are in Suicidal Mode and so it will be ignored.");
Log.force("**BE ADVISED**: your savegames are at risk and any tragedy that follows will be your own fault!");
Log.error("Stackdump of the caller follows.");
Log.stack(typeof(Startup), true);
return;
}
Log.fatal(1, "I was told to quit the game. Stackdump of the caller follows.");
Log.stack(typeof(Startup), true);
quitOnDestroy = value;
Expand Down

0 comments on commit 90db64b

Please sign in to comment.