Table of Contents

Class PlayerHistoryStore

Namespace
McServerLauncher.Services
Assembly
McServerLauncher.dll

One server's player history: who came, when, for how long, and what they did and said.

public sealed class PlayerHistoryStore : IDisposable
Inheritance
PlayerHistoryStore
Implements
Inherited Members

Remarks

Lives in %APPDATA%\McServerLauncher\players\<serverId>\, outside the server's folder, so it neither travels with the world nor fills its backups. index.json holds one summary per player; events/<name>.jsonl holds that player's events, one short JSON object per line.

Kept small on purpose. Events files are only ever appended to, and compacted in one go when they pass the per-player limit by a quarter — the same trick the console uses to avoid rewriting on every line. Old events and long-gone players are dropped at start-up. The IP address the server logs at every login is never read, so it cannot be stored.

Every public member takes the one lock: the live console records from the UI thread, the import from a background one, and the settings dialog can clear everything at any moment.

Constructors

PlayerHistoryStore(string, Func<PlayerHistorySettings>?, Func<DateTime>?)

public PlayerHistoryStore(string directory, Func<PlayerHistorySettings>? settings = null, Func<DateTime>? utcNow = null)

Parameters

directory string
settings Func<PlayerHistorySettings>
utcNow Func<DateTime>

Properties

Imported

Whether this server's old logs have already been imported.

public bool Imported { get; }

Property Value

bool

RootDirectory

Where every server's history lives.

public static string RootDirectory { get; set; }

Property Value

string

Methods

BeginImport()

From here until EndImport(), a line already stored is not stored again.

public void BeginImport()

Clear(string)

Forgets one player completely.

public void Clear(string player)

Parameters

player string

ClearAll()

Forgets every player of this server. Imported logs are not imported again.

public void ClearAll()

ClearEverything()

Forgets every player of every server.

public static void ClearEverything()

CloseOpenSessions(IEnumerable<string>?, DateTime?)

The same, for only these players; null means everyone.

public void CloseOpenSessions(IEnumerable<string>? players, DateTime? atUtc)

Parameters

players IEnumerable<string>
atUtc DateTime?

CloseOpenSessions(DateTime?)

Ends every session still open: the server stopped or crashed without saying who left.

public void CloseOpenSessions(DateTime? atUtc)

Parameters

atUtc DateTime?

When they ended; null means each player's own last event, for a log that just stops.

DirectorySize()

How much this store's own folder takes on disk, in bytes.

public long DirectorySize()

Returns

long

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

EndImport()

Marks the import done, so it never runs again for this server.

public void EndImport()

Events(string)

One player's events, newest first.

public IReadOnlyList<StoredEvent> Events(string player)

Parameters

player string

Returns

IReadOnlyList<StoredEvent>

Remarks

Sorted rather than read backwards: an import can add older events after newer live ones, and a file this small (a few hundred lines at most) costs nothing to sort.

Flush()

Writes the index if anything changed. Called on a timer, on stop and on exit.

public void Flush()

FlushAll()

Writes every open store's index. Called when the app exits.

public static void FlushAll()

For(string)

The store for a server, shared by everything that asks for it.

public static PlayerHistoryStore For(string serverId)

Parameters

serverId string

Returns

PlayerHistoryStore

Get(string)

A copy of one player's summary, or null.

public PlayerRecord? Get(string player)

Parameters

player string

Returns

PlayerRecord

Players()

A copy of every player's summary.

public IReadOnlyList<PlayerRecord> Players()

Returns

IReadOnlyList<PlayerRecord>

Prune()

Drops what the settings no longer allow: events past the retention, players not seen within it, and anything over the per-player limit.

public void Prune()

PruneOrphans(IEnumerable<string>, DateTime, int)

Deletes the history of servers that are no longer in the app and have not been touched within the retention period. A server removed and added back straight away keeps nothing either way — it gets a new id — so there is no reason to keep these for ever.

public static void PruneOrphans(IEnumerable<string> liveServerIds, DateTime utcNow, int retentionDays)

Parameters

liveServerIds IEnumerable<string>
utcNow DateTime
retentionDays int

Record(PlayerEvent, DateTime)

Records something a player did at atUtc.

public void Record(PlayerEvent e, DateTime atUtc)

Parameters

e PlayerEvent
atUtc DateTime

RecordUuid(string, string)

Remembers a player's UUID, which is what the server's own statistics are filed under.

public void RecordUuid(string player, string uuid)

Parameters

player string
uuid string

SizeOf(string)

How much one server's history takes on disk, in bytes, without opening its store.

public static long SizeOf(string serverId)

Parameters

serverId string

Returns

long

Remarks

What the server's own configuration shows beside its "forget this server's players" button — a total across every server would be the wrong number next to a button that deletes one of them. Deliberately static: merely looking at a size must not create a store, and so a folder, for a server whose history nobody has ever opened.

SizeOnDisk()

How much every server's history takes on disk, in bytes.

public static long SizeOnDisk()

Returns

long