Code/SboxSuperuser/Superuser.cs

Static helper class exposing host administration entry points: diagnostics, resolving a player identity from a Connection, and checking owner membership. It forwards calls into the active scene's SuperuserSession system and its runtime, and returns safe defaults when no scene/runtime is available.

Networking
using Sandbox;
using SboxSuperuser.Systems;

namespace SboxSuperuser;

/// <summary>Entry points for host administration, authenticated dispatch, storage and chat integration.</summary>
public static partial class Superuser
{
	/// <summary>Returns local bootstrap health without exposing owner IDs or granting authority.</summary>
	public static BootstrapDiagnostics GetDiagnostics()
	{
		var scene = Game.ActiveScene;
		var diagnostics = scene.IsValid() ? scene.GetSystem<SuperuserSession>()?.GetDiagnostics() : null;
		return diagnostics ?? new BootstrapDiagnostics( BootstrapState.Disabled, null, 0, 0, null, "No active runtime scene." );
	}

	/// <summary>Resolves only a live host-authenticated engine connection; null or stale connections fail.</summary>
	public static bool TryGetPlayerIdentity( Connection connection, out ActorIdentity identity )
	{
		identity = null;
		var scene = Game.ActiveScene;
		var runtime = scene.IsValid() ? scene.GetSystem<SuperuserSession>()?.GetRuntime() : null;
		return runtime is not null && runtime.TryResolvePlayer( connection, out identity );
	}

	/// <summary>Checks explicit owner membership after revalidating the live connection on the host.</summary>
	public static bool IsOwner( Connection connection )
	{
		var scene = Game.ActiveScene;
		var runtime = scene.IsValid() ? scene.GetSystem<SuperuserSession>()?.GetRuntime() : null;
		return runtime is not null && runtime.IsOwner( connection );
	}
}