Table of Contents

Class ServerProcessManager

Namespace
McServerLauncher.Services
Assembly
McServerLauncher.dll

Manages the lifecycle of a Minecraft server's java process: startup, clean shutdown (sending "stop" over stdin), command sending and re-emitting the console output in real time.

public class ServerProcessManager
Inheritance
ServerProcessManager
Inherited Members

Properties

CurrentProcess

The running process (for CPU/RAM stats). Null if there is no active server.

public Process? CurrentProcess { get; }

Property Value

Process

IsRunning

public bool IsRunning { get; }

Property Value

bool

StartedAtUtc

When the current (or most recently started) process was launched.

public DateTime StartedAtUtc { get; }

Property Value

DateTime

State

public ServerState State { get; }

Property Value

ServerState

Methods

SendCommand(string)

Sends an arbitrary command over stdin (like typing it into the console).

public void SendCommand(string command)

Parameters

command string

Start(ServerConfig)

Starts the server. Equivalent to run.bat but without a console window.

public void Start(ServerConfig config)

Parameters

config ServerConfig

StopAsync(TimeSpan)

Stops the server cleanly: sends "stop" and waits for it to exit. If it doesn't exit within the given time, it kills the process tree.

public Task StopAsync(TimeSpan timeout)

Parameters

timeout TimeSpan

Returns

Task

Events

OutputReceived

Raised for each output line, saying where it came from.

public event Action<string, ConsoleSource>? OutputReceived

Event Type

Action<string, ConsoleSource>

Remarks

The source used to be thrown away: standard output and standard error were wired to the same handler and re-emitted through one Action<string> that said nothing about which was which. Standard error is the cheapest severity signal a server ever gives — no parsing, nothing a plugin or a locale can reword — and it was being discarded one line before it could be used. Launcher is here because this class also puts its own messages through this event, and those are the app talking rather than the server.

StateChanged

Raised when the server state changes.

public event Action<ServerState>? StateChanged

Event Type

Action<ServerState>

UnexpectedExit

Raised when the process ends WITHOUT us having asked it to (i.e. it crashed, was killed externally, or the JVM exited on its own) — not raised for a clean Stop/StopAsync, including the forced-kill-after-timeout path (that's still a stop WE requested). The exit code is passed when available.

public event Action<int?>? UnexpectedExit

Event Type

Action<int?>