Table of Contents

Class IdleShutdownController

Namespace
McServerLauncher.ViewModels
Assembly
McServerLauncher.dll

Stops the server once it has been empty for the configured time, and shows the countdown while that clock runs.

public sealed class IdleShutdownController : IDisposable
Inheritance
IdleShutdownController
Implements
Inherited Members

Remarks

The clock starts when the last player leaves — or when the server finishes starting, if nobody ever joins — and is reset by anyone connecting, so a server in use is never stopped out from under its players. The rules themselves are in IdlePolicy.

Check() is called off the server's 2 s stats timer, which is the right cadence for deciding when to stop but the wrong one for a clock: a seconds display driven by it would skip every other second. The countdown therefore has its own one-second timer, which only runs while there is something to count.

Constructors

IdleShutdownController(IdleHost, Func<DateTime>?)

public IdleShutdownController(IdleHost host, Func<DateTime>? utcNow = null)

Parameters

host IdleHost

The server being watched.

utcNow Func<DateTime>

The clock. The real one unless a test supplies its own.

Properties

IsCounting

Whether the clock is running, i.e. the server is empty and being counted down.

public bool IsCounting { get; }

Property Value

bool

Methods

Check()

Decides whether the clock runs, and stops the server when it has run out.

public void Check()

Dispose()

Stops the countdown timer for good.

public void Dispose()

Reset()

Forgets the clock and takes the countdown away.

public void Reset()

Remarks

Called explicitly when the server stops, not left to the next Check(): that runs off the stats timer, which has just been stopped, so a server that went straight from Running to Stopped between two ticks would leave a countdown ticking away on a dead server.