Table of Contents

Class ServerPropertiesService

Namespace
McServerLauncher.Services
Assembly
McServerLauncher.dll

Reads and writes the server.properties file (key=value format, one per line). Used to read values (e.g. the port) and to update them from the visual configuration screen.

public class ServerPropertiesService
Inheritance
ServerPropertiesService
Inherited Members

Fields

DefaultMaxPlayers

The player limit when server.properties sets none: Minecraft's own.

public const int DefaultMaxPlayers = 20

Field Value

int

DefaultMotd

The MOTD a server shows when server.properties sets none: Minecraft's own.

public const string DefaultMotd = "A Minecraft Server"

Field Value

string

Methods

GetBool(IReadOnlyDictionary<string, string>, string, bool)

One true/false key of props, see ParseBool(string?, bool).

public static bool GetBool(IReadOnlyDictionary<string, string> props, string key, bool fallback)

Parameters

props IReadOnlyDictionary<string, string>
key string
fallback bool

Returns

bool

GetServerPort(string)

Returns the server port (server-port) or null if not found.

public int? GetServerPort(string propertiesPath)

Parameters

propertiesPath string

Returns

int?

ParseBool(string?, bool)

A true/false value as the server reads it: only "true" is true, in any case.

public static bool ParseBool(string? raw, bool fallback)

Parameters

raw string

What the file says, or null when the key is not there.

fallback bool

What an absent key means.

Returns

bool

Remarks

Java's Boolean.parseBoolean, which is what the server calls: "yes" or "1" are false, so online-mode=yes is an offline server. The reads that each compared the text themselves had two readings — some took anything but "false" as true.

Read(string)

Reads server.properties and returns a key→value dictionary. Returns empty if the file does not exist.

public Dictionary<string, string> Read(string propertiesPath)

Parameters

propertiesPath string

Returns

Dictionary<string, string>

SanitizeValue(string)

Strips CR/LF from a value (or key) before it's embedded in the line-oriented server.properties format. Without this, a value containing "\n" (e.g. pasted into the MOTD or the server name) would inject arbitrary extra keys — say "enable-rcon=true" — into the file. Same idea as the player-name sanitization for stdin commands.

public static string SanitizeValue(string value)

Parameters

value string

Returns

string

Update(string, IDictionary<string, string>)

Updates the given keys in server.properties, preserving the rest of the lines, comments and order. New keys are appended at the end. Creates the file if it doesn't exist. Keys and values are sanitized (no CR/LF) so no input can inject extra lines.

public void Update(string propertiesPath, IDictionary<string, string> changes)

Parameters

propertiesPath string
changes IDictionary<string, string>