Table of Contents

Class ServerSettingsDraft

Namespace
McServerLauncher.Views.ServerSettings
Assembly
McServerLauncher.dll

Everything a server's settings page has changed and not yet saved: a copy of its ServerConfig, the server.properties values it shows, and the new icon.

public sealed class ServerSettingsDraft
Inheritance
ServerSettingsDraft
Inherited Members

Remarks

The page used to be three dialogs, and the main one wrote straight into the live config — the same instance the server list shows — and put a snapshot back on Cancel. That only worked because a dialog is modal: nothing else could look at the config while it was half edited. A page in the window is not modal, so the controls edit Config, a copy, and nothing reaches the server until Apply().

Saving copies back only the fields that changed. The live config goes on being written while the page is open — a loader install, the seed read from the console — and copying the whole draft over it would put back whatever it held when the page was opened.

Constructors

ServerSettingsDraft(ServerConfig, PortOwners?)

public ServerSettingsDraft(ServerConfig live, PortOwners? portOwners = null)

Parameters

live ServerConfig

The server being configured.

portOwners PortOwners

The name of another server already on a Bedrock port, or null when none is. Lets the page refuse a port by saying whose it is, instead of letting two servers end up behind one tunnel.

Properties

Config

The copy the controls are bound to.

public ServerConfig Config { get; }

Property Value

ServerConfig

IsDirty

public bool IsDirty { get; }

Property Value

bool

Live

The server's own config, the one the rest of the app shows.

public ServerConfig Live { get; }

Property Value

ServerConfig

NewIcon

The icon picked and not yet written, already rendered the way the server stores it.

public byte[]? NewIcon { get; }

Property Value

byte[]

RemoveIcon

True when the icon is to be taken away on save.

public bool RemoveIcon { get; }

Property Value

bool

Methods

Adopt(params string[])

Takes fields from the live config into both the copy and what counts as saved: something other than this page changed them, and they are not the user's edit.

public void Adopt(params string[] fields)

Parameters

fields string[]

Remarks

A loader install writes the type, the version, the jar and Java straight into the live config and the disk. Without this the page would go on offering the old type's options, and Save would copy the old jar back over the new one.

Apply()

Writes what changed: server.properties, the icon, and the server's config.

public ServerSettingsSaved Apply()

Returns

ServerSettingsSaved

Remarks

The files go first, into the folder the draft names — the folder may be what changed — and the live config last. It used to be the other way round, so a file that could not be written (a folder that had gone missing, a file in use) left the live config already changed: the server list showed the new name and RAM, Discard only put the page back, and the next save of servers.json made the half-done change permanent. Now a failure leaves the server as it was.

Each file counts as saved as soon as it is written, so a failure after it does not leave the page claiming something unsaved that is already on disk. Throws on the first file that cannot be written; the page keeps the rest so it can be saved again.

Last also means the live config's own reactions run with the files already in place: turning on "join to start it" in the same save as a new port opens the listener on the new port.

ClearIcon()

public void ClearIcon()

Detach()

Stops following the live config: the page is gone.

public void Detach()

FileValue(string)

What the file says for key, or null when it does not say.

public string? FileValue(string key)

Parameters

key string

Returns

string

Get(string)

public string Get(string key)

Parameters

key string

Returns

string

IsPageDirty(ServerSettingsPage)

public bool IsPageDirty(ServerSettingsPage page)

Parameters

page ServerSettingsPage

Returns

bool

Revert()

Puts every page back the way it was saved.

public void Revert()

Saved(string)

The value field had when the page was opened or last saved.

public object? Saved(string field)

Parameters

field string

Returns

object

Set(string, string)

public void Set(string key, string value)

Parameters

key string
value string

Track(string, string)

Starts following key, with value as what it holds now.

public void Track(string key, string value)

Parameters

key string
value string

Remarks

The page passes the value as its control would write it, not as the file has it. A file that says pvp=TRUE would otherwise count as changed the moment it is shown, because the switch writes true.

UseIcon(byte[])

public void UseIcon(byte[] png)

Parameters

png byte[]

Validate()

The pages that cannot be saved as they are, each with what is wrong.

public IReadOnlyList<SettingsProblem> Validate()

Returns

IReadOnlyList<SettingsProblem>

Remarks

Only what was changed is checked. A server whose folder has since gone missing must still be able to change its difficulty; it was the edit dialog's to refuse, not this page's.

Events

Changed

Raised on every change, to the config copy, a property or the icon.

public event Action? Changed

Event Type

Action

ChangedOutside

Raised when something other than the page changed a field it shows, and the page took it in.

public event Action? ChangedOutside

Event Type

Action