Editor driver for viewport settings and simple multiplayer orchestration. ConfigureViewport returns defaulted viewport settings. OrchestrateMultiplayerAsync handles actions: spawn client instance via LocalInstances, start dedicated server via ConsoleSystem.Run, migrate host via LocalInstances.MigrateHostAsync, and otherwise reports active sbox processes.
#nullable enable
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using Sandbox;
namespace Editor.Mcp
{
internal static class ViewportAndMultiplayerDriver
{
public static ToolOutcome<object> ConfigureViewport( string? renderMode = null, string? view = null, bool? wireframe = null, bool? showGrid = null, bool? postProcessing = null )
{
return ToolOutcome<object>.Ready( new
{
RenderMode = renderMode ?? "normal",
View = view ?? "perspective",
Wireframe = wireframe ?? false,
ShowGrid = showGrid ?? true,
PostProcessing = postProcessing ?? true
} );
}
public static async Task<ToolOutcome<object>> OrchestrateMultiplayerAsync( string action, string? serverArgs = null )
{
var normAction = action.ToLowerInvariant();
if ( normAction == "spawn_client_instance" )
{
var pid = LocalInstances.Spawn();
return ToolOutcome<object>.Ready( new { Action = "spawn_client_instance", ClientSpawned = true, ProcessId = pid } );
}
if ( normAction == "start_dedicated" )
{
ConsoleSystem.Run( "dedicated_server" );
return ToolOutcome<object>.Ready( new { Action = "start_dedicated", Status = "Dedicated server launched" } );
}
if ( normAction == "migrate_host" )
{
var success = await LocalInstances.MigrateHostAsync( windowed: true );
if ( !success )
{
return ToolOutcome<object>.Failure( null, ToolStatus.Failed, "multiplayer.migration_failed", "Host migration timed out or failed to connect client." );
}
return ToolOutcome<object>.Ready( new { Action = "migrate_host", Success = true, Status = "Host migrated successfully" } );
}
var instancesActive = Process.GetProcessesByName( "sbox" ).Length;
return ToolOutcome<object>.Ready( new { Action = action, InstancesActive = instancesActive } );
}
}
}