Table of Contents

Class IdlePolicy

Namespace
McServerLauncher.Services
Assembly
McServerLauncher.dll

The rules for stopping an empty server and for leaving it alone after it was woken, as plain functions of their inputs.

public static class IdlePolicy
Inheritance
IdlePolicy
Inherited Members

Remarks

Kept apart from the controller that applies them so each rule can be checked directly: getting one wrong means either a server that never stops or — far worse — one that stops while people are playing.

Fields

WakeGrace

How long after waking the idle timer is ignored, so a player has time to actually get in.

public static readonly TimeSpan WakeGrace

Field Value

TimeSpan

Remarks

Without this, a server set to stop after a minute would wake, find itself still empty while the world loads, and shut down before the player finished connecting — over and over.

Methods

FormatCountdown(TimeSpan)

Formats the countdown, rounding seconds up.

public static string FormatCountdown(TimeSpan left)

Parameters

left TimeSpan

Returns

string

Remarks

Truncating would park the display on 0:00 for up to a second while the server is still perfectly alive, which reads as a stuck clock. Rounding up means it shows 0:01 until the moment it really is zero.

IdleRemaining(int, DateTime, DateTime)

How long is left before an empty server stops itself. Never negative.

public static TimeSpan IdleRemaining(int minutes, DateTime emptySinceUtc, DateTime nowUtc)

Parameters

minutes int
emptySinceUtc DateTime
nowUtc DateTime

Returns

TimeSpan

IsIdleLongEnough(int, DateTime, DateTime)

Whether it has been empty long enough to stop.

public static bool IsIdleLongEnough(int minutes, DateTime emptySinceUtc, DateTime nowUtc)

Parameters

minutes int
emptySinceUtc DateTime
nowUtc DateTime

Returns

bool

IsWithinWakeGrace(DateTime?, DateTime)

Whether the server was woken so recently that its emptiness does not count yet.

public static bool IsWithinWakeGrace(DateTime? wokeAtUtc, DateTime nowUtc)

Parameters

wokeAtUtc DateTime?
nowUtc DateTime

Returns

bool

ShouldCountIdle(int, bool, int)

Whether the empty-server clock should be running at all.

public static bool ShouldCountIdle(int minutes, bool running, int playerCount)

Parameters

minutes int
running bool
playerCount int

Returns

bool