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

Methods

GetServerPort(string)

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

public int? GetServerPort(string propertiesPath)

Parameters

propertiesPath string

Returns

int?

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>