# arturohe/darkmultiplayerenchanced architecture

> Architecture diagram of the GitHub repository arturohe/darkmultiplayerenchanced, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/arturohe/darkmultiplayerenchanced
- Repository: https://github.com/arturohe/darkmultiplayerenchanced

## Overview

1. **What this repository is**
   DarkMultiPlayer is a **client-server multiplayer mod for Kerbal Space Program**. The repo is split into a **game client plugin** and a **standalone server**, with a small **shared common library** used by both sides.

2. **Top-level architecture**
   The main boundaries are:
   - **Client/**: code that runs inside the KSP game process and integrates with the game/UI.
   - **Server/**: headless multiplayer server that manages sessions, state, permissions, and persistence.
   - **Common/**: shared low-level utilities for message buffering, compression, recycling, and serialization support.
   - **External/**: vendored third-party dependencies and KSP-managed assemblies required to compile against the game API.
   - **Documentation/**: protocol and behavior notes that describe key subsystems like network messages and subspace locking.

3. **Runtime model**
   The client is a **game plugin** loaded by KSP and is responsible for syncing local gameplay with multiplayer state.  
   The server is a **separate .NET application** intended to run cross-platform; the README notes .NET/Mono support and a server config folder. This is a classic **authoritative server** model rather than peer-to-peer.

4. **Shared protocol layer**
   `Common/` contains infrastructure used by both sides:
   - byte-array pooling/recycling for network efficiency,
   - compression utilities,
   - serializers and shared helpers.
   
   The presence of `Documentation/network-message-format.txt` and many message-specific classes on the server indicates a **custom binary message protocol** between client and server.

5. **Server responsibilities**
   The server is the authoritative coordinator for multiplayer state. Its major subsystems include:
   - **Connection and client management** (`ClientHandler`, `ServerInfo`, `Main`)
   - **Administrative controls** (`AdminSystem`, `AdminCommand`, `KickCommand`, `PMCommand`, `WhitelistCommand`)
   - **Access control and policy** (`Permissions`, `BanSystem`, `WhitelistSystem`, `Groups`)
   - **Gameplay synchronization** (`LockSystem`, `ModpackSystem`, `GameplaySettings`, `WarpControl`, vessel and kerbal messages)
   - **Persistence/safety helpers** (`SafeFile`, log expiration, screenshot expiration)

6. **Server message surface**
   `Server/Messages/` is a strong architectural clue: each file maps to a protocol domain such as:
   - handshake and heartbeat,
   - chat,
   - vessel updates/removal/requests,
   - time sync and warp control,
   - player status/color,
   - scenario and kerbal data,
   - modpack and server settings,
   - screenshots, craft library, flags, permissions, and lock state.
   
   This suggests the server is organized around **domain messages**, not a single monolithic sync loop.

7. **Client responsibilities**
   The client side is a set of coordinated workers and UI windows that embed multiplayer behavior into KSP. Key areas include:
   - **Network/session management** (`NetworkWorker`, `ConnectionWindow`, `ServerListConnection`)
   - **Vessel synchronization** (`VesselWorker`, `VesselUpdate`, `VesselProtoUpdate`, `VesselRecorder`, `VesselCtrlUpdate`)
   - **Time and warp** (`TimeSyncer`, `WarpWorker`, `DynamicTickWorker`)
   - **Game-state sync** (`ScenarioWorker`, `CraftLibraryWorker`, `FlagSyncer`, `PlayerColorWorker`, `PlayerStatusWorker`)
   - **Social/admin features** (`ChatWorker`, `AdminSystem`, `PermissionsWindow`, `GroupsWindow`)
   - **Safety and gameplay helpers** (`SafetyBubble`, `PartKiller`, `KerbalReassigner`, `VesselRangeBumper`)

8. **Client UI and integration boundary**
   The numerous `*Window.cs` files show that the client includes in-game UI for connection, options, mod control, server lists, debugging, permissions, groups, disclaimers, and universe conversion.  
   This indicates a boundary between:
   - **presentation/UI logic**
   - **sync/control workers**
   - **KSP game object manipulation**
   
   The client appears to use KSP’s mod/plugin extension points rather than a separate launcher as its primary runtime.

9. **Gameplay and state synchronization**
   A central design goal is preserving consistency across players while allowing KSP gameplay to continue. Important state domains include:
   - **Vessels**: state, control, prototypes, deletion, and range constraints
   - **Kerbals**: status and reassignment
   - **Scenarios**: persisted game/scenario data
   - **Flags and craft libraries**
   - **Player presence/status**
   - **Subspace time / warp control**
   
   The `Documentation/subspace-locking.txt` file and the README mention **subspace-style warping** and **master-controlled warp**, so time handling is a first-class system, not a simple clock sync.

10. **Mod and compatibility control**
   Mod compatibility is treated as part of the multiplayer contract:
   - `ModpackSystem` on the server
   - `ModWorker`, `ModpackWorker`, `DMPModInterface` on the client
   - README references `DMPModControl.txt` and whitelist/blacklist mode
   
   This means connection eligibility depends not just on the server address, but also on **mod set compatibility**, which is enforced as part of session setup.

11. **External dependencies and KSP coupling**
   The `External/` folder contains third-party parsing, messaging, and KSP-specific assemblies. That implies:
   - the client compiles against **Kerbal Space Program managed assemblies**,
   - the networking/serialization stack is partly vendored,
   - the repo is designed to be buildable from source with game binaries present.

12. **Configuration and operational model**
   Server behavior is driven by editable config files such as `Config/Settings.txt` and `Config/GameplaySettings.txt` per the README.  
   The server therefore acts as an **operator-managed multiplayer authority**: admins configure rules, permissions, whitelists, bans, groups, and gameplay settings externally from the code.

13. **Diagram-friendly summary**
   For an architecture diagram, the key nodes are:
   - **KSP Game Client + DarkMultiPlayer plugin**
   - **DarkMultiPlayer Server**
   - **Shared Common library**
   - **External KSP/utility dependencies**
   
   The main arrows are:
   - client ↔ server over a custom binary message protocol,
   - server → clients for authoritative state sync,
   - clients → server for user actions and local game events,
   - both sides using shared serialization/compression utilities.

Main entry points: [`Client/Main.cs`](https://github.com/arturohe/darkmultiplayerenchanced/blob/master/Client/Main.cs) (Game plugin), [`Server/Main.cs`](https://github.com/arturohe/darkmultiplayerenchanced/blob/master/Server/Main.cs) (Server core), [`Server/Messages/Handshake.cs`](https://github.com/arturohe/darkmultiplayerenchanced/blob/master/Server/Messages/Handshake.cs) (Message types), [`Client/NetworkWorker.cs`](https://github.com/arturohe/darkmultiplayerenchanced/blob/master/Client/NetworkWorker.cs) (Network worker)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Client"]
  node_client_main["Game plugin<br/>KSP client runtime<br/>[Main.cs]"]
  node_client_net["Network worker<br/>session/network<br/>[NetworkWorker.cs]"]
  node_client_vessel["Vessel sync<br/>state sync<br/>[VesselWorker.cs]"]
  node_client_time["Time sync<br/>warp/time<br/>[TimeSyncer.cs]"]
  node_client_game["Game sync<br/>world sync<br/>[ScenarioWorker.cs]"]
  node_client_ui["UI windows<br/>in-game UI"]
  node_client_admin["Client controls<br/>admin/social<br/>[AdminSystem.cs]"]
  node_client_safety["Safety helpers<br/>gameplay guardrails<br/>[SafetyBubble.cs]"]
end

subgraph group_server["Server"]
  node_server_main["Server core<br/>authoritative server<br/>[Main.cs]"]
  node_server_client["Client handler<br/>connection/session<br/>[ClientHandler.cs]"]
  node_server_sync["Sync systems<br/>world authority<br/>[LockSystem.cs]"]
  node_server_policy["Policy layer<br/>admin/access control<br/>[AdminSystem.cs]"]
  node_server_messages["Message types<br/>protocol domains<br/>[Handshake.cs]"]
  node_server_ops["Ops helpers<br/>persistence/ops<br/>[SafeFile.cs]"]
end

subgraph group_shared["Shared"]
  node_shared_common["Common lib<br/>shared core<br/>[Common.cs]"]
end

subgraph group_deps["Dependencies"]
  node_deps_ksp[("KSP assemblies<br/>game API deps<br/>[files_go_here.txt]")]
  node_deps_vendor[("Vendored libs<br/>third-party deps")]
end

subgraph group_docs["Docs"]
  node_docs_proto["Protocol docs<br/>documentation"]
end

node_client_main -->|"starts"| node_client_net
node_client_main -->|"runs"| node_client_vessel
node_client_main -->|"runs"| node_client_time
node_client_main -->|"runs"| node_client_game
node_client_main -->|"shows"| node_client_ui
node_client_main -->|"uses"| node_client_admin
node_client_main -->|"enforces"| node_client_safety
node_client_net -->|"connects to"| node_server_main
node_client_vessel -->|"exchanges"| node_server_messages
node_client_time -->|"exchanges"| node_server_messages
node_client_game -->|"exchanges"| node_server_messages
node_client_admin -->|"exchanges"| node_server_messages
node_server_main -->|"manages"| node_server_client
node_server_main -->|"orchestrates"| node_server_sync
node_server_main -->|"applies"| node_server_policy
node_server_main -->|"routes"| node_server_messages
node_server_main -->|"uses"| node_server_ops
node_server_messages -.->|"defined by"| node_docs_proto
node_client_main -->|"uses"| node_shared_common
node_server_main -->|"uses"| node_shared_common
node_client_main -->|"depends on"| node_deps_ksp
node_client_main -->|"depends on"| node_deps_vendor
node_server_main -->|"depends on"| node_deps_vendor

click node_client_main "https://github.com/arturohe/darkmultiplayerenchanced/blob/master/Client/Main.cs"
click node_client_net "https://github.com/arturohe/darkmultiplayerenchanced/blob/master/Client/NetworkWorker.cs"
click node_client_vessel "https://github.com/arturohe/darkmultiplayerenchanced/blob/master/Client/VesselWorker.cs"
click node_client_time "https://github.com/arturohe/darkmultiplayerenchanced/blob/master/Client/TimeSyncer.cs"
click node_client_game "https://github.com/arturohe/darkmultiplayerenchanced/blob/master/Client/ScenarioWorker.cs"
click node_client_ui "https://github.com/arturohe/darkmultiplayerenchanced/blob/master/Client/ConnectionWindow.cs"
click node_client_admin "https://github.com/arturohe/darkmultiplayerenchanced/blob/master/Client/AdminSystem.cs"
click node_client_safety "https://github.com/arturohe/darkmultiplayerenchanced/blob/master/Client/SafetyBubble.cs"
click node_shared_common "https://github.com/arturohe/darkmultiplayerenchanced/blob/master/Common/Common.cs"
click node_server_main "https://github.com/arturohe/darkmultiplayerenchanced/blob/master/Server/Main.cs"
click node_server_client "https://github.com/arturohe/darkmultiplayerenchanced/blob/master/Server/ClientHandler.cs"
click node_server_sync "https://github.com/arturohe/darkmultiplayerenchanced/blob/master/Server/LockSystem.cs"
click node_server_policy "https://github.com/arturohe/darkmultiplayerenchanced/blob/master/Server/AdminSystem.cs"
click node_server_messages "https://github.com/arturohe/darkmultiplayerenchanced/blob/master/Server/Messages/Handshake.cs"
click node_server_ops "https://github.com/arturohe/darkmultiplayerenchanced/blob/master/Server/SafeFile.cs"
click node_docs_proto "https://github.com/arturohe/darkmultiplayerenchanced/blob/master/Documentation/network-message-format.txt"
click node_deps_ksp "https://github.com/arturohe/darkmultiplayerenchanced/blob/master/External/KSPManaged/files_go_here.txt"
click node_deps_vendor "https://github.com/arturohe/darkmultiplayerenchanced/tree/master/External/MessageStream2"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_client_main,node_client_net,node_client_vessel,node_client_time,node_client_game,node_client_ui,node_client_admin,node_client_safety toneBlue
class node_server_main,node_server_client,node_server_sync,node_server_policy,node_server_messages,node_server_ops toneAmber
class node_shared_common toneMint
class node_deps_ksp,node_deps_vendor toneRose
class node_docs_proto toneIndigo
```

## Components

### Client

In-game KSP plugin and UI/runtime workers

- [Game plugin](https://github.com/arturohe/darkmultiplayerenchanced/blob/master/Client/Main.cs): KSP client runtime · Entry point and integration with Kerbal Space Program · `Client/Main.cs`
- [Network worker](https://github.com/arturohe/darkmultiplayerenchanced/blob/master/Client/NetworkWorker.cs): session/network · Handles server connection, session setup, and message flow · `Client/NetworkWorker.cs`
- [Vessel sync](https://github.com/arturohe/darkmultiplayerenchanced/blob/master/Client/VesselWorker.cs): state sync · Coordinates vessel updates, control, recording, and range rules · `Client/VesselWorker.cs`
- [Time sync](https://github.com/arturohe/darkmultiplayerenchanced/blob/master/Client/TimeSyncer.cs): warp/time · Manages subspace timing, warp control, and tick behavior · `Client/TimeSyncer.cs`
- [Game sync](https://github.com/arturohe/darkmultiplayerenchanced/blob/master/Client/ScenarioWorker.cs): world sync · Synchronizes scenarios, flags, craft library, colors, status, and screenshots · `Client/ScenarioWorker.cs`
- [UI windows](https://github.com/arturohe/darkmultiplayerenchanced/blob/master/Client/ConnectionWindow.cs): in-game UI · Connection, options, permissions, groups, debug, and conversion screens · `Client/ConnectionWindow.cs`
- [Client controls](https://github.com/arturohe/darkmultiplayerenchanced/blob/master/Client/AdminSystem.cs): admin/social · Chat, admin actions, permissions, groups, and mod control · `Client/AdminSystem.cs`
- [Safety helpers](https://github.com/arturohe/darkmultiplayerenchanced/blob/master/Client/SafetyBubble.cs): gameplay guardrails · Prevents desync-prone or unsafe gameplay behavior · `Client/SafetyBubble.cs`

### Server

Standalone authoritative multiplayer server

- [Server core](https://github.com/arturohe/darkmultiplayerenchanced/blob/master/Server/Main.cs): authoritative server · Main process for client management, session orchestration, and server lifecycle · `Server/Main.cs`
- [Client handler](https://github.com/arturohe/darkmultiplayerenchanced/blob/master/Server/ClientHandler.cs): connection/session · Tracks connected players and per-client state · `Server/ClientHandler.cs`
- [Sync systems](https://github.com/arturohe/darkmultiplayerenchanced/blob/master/Server/LockSystem.cs): world authority · Authoritative systems for vessels, time, locks, settings, and modpack state · `Server/LockSystem.cs`
- [Policy layer](https://github.com/arturohe/darkmultiplayerenchanced/blob/master/Server/AdminSystem.cs): admin/access control · Admins, bans, whitelists, permissions, and groups · `Server/AdminSystem.cs`
- [Message types](https://github.com/arturohe/darkmultiplayerenchanced/blob/master/Server/Messages/Handshake.cs): protocol domains · Custom binary message handlers for handshake, chat, vessels, time, players, scenarios, and settings · `Server/Messages/Handshake.cs`
- [Ops helpers](https://github.com/arturohe/darkmultiplayerenchanced/blob/master/Server/SafeFile.cs): persistence/ops · Safe file handling, log expiration, screenshot expiration, and server info · `Server/SafeFile.cs`

### Shared

Code and assets used by both client and server

- [Common lib](https://github.com/arturohe/darkmultiplayerenchanced/blob/master/Common/Common.cs): shared core · Shared byte buffers, recycling, compression, and common helpers · `Common/Common.cs`

### Dependencies

Vendored external libraries and game assemblies

- [KSP assemblies](https://github.com/arturohe/darkmultiplayerenchanced/blob/master/External/KSPManaged/files_go_here.txt): game API deps · Kerbal Space Program managed assemblies needed by the client plugin · `External/KSPManaged/files_go_here.txt`
- [Vendored libs](https://github.com/arturohe/darkmultiplayerenchanced/tree/master/External/MessageStream2): third-party deps · Parser, messaging, and utility libraries bundled for builds · `External/MessageStream2`

### Docs

Protocol and behavior documentation

- [Protocol docs](https://github.com/arturohe/darkmultiplayerenchanced/blob/master/Documentation/network-message-format.txt): documentation · Network message format and subspace locking behavior · `Documentation/network-message-format.txt`

## Connections

- Game plugin → Network worker: starts · Bootstraps networking and session setup
- Game plugin → Vessel sync: runs · Coordinates vessel sync workers
- Game plugin → Time sync: runs · Coordinates warp and time sync
- Game plugin → Game sync: runs · Coordinates scenario and world-state sync
- Game plugin → UI windows: shows · Presents in-game windows and dialogs
- Game plugin → Client controls: uses · Provides chat, admin, and mod-control features
- Game plugin → Safety helpers: enforces · Applies gameplay safety constraints
- Network worker → Server core: connects to · Client session reaches the authoritative server
- Vessel sync → Message types: exchanges · Sends and receives vessel protocol messages
- Time sync → Message types: exchanges · Syncs time and warp control messages
- Game sync → Message types: exchanges · Syncs scenario, flags, screenshots, and player state
- Client controls → Message types: exchanges · Uses chat, permissions, and admin-related messages
- Server core → Client handler: manages · Accepts and tracks connected clients
- Server core → Sync systems: orchestrates · Coordinates authoritative multiplayer subsystems
- Server core → Policy layer: applies · Loads and enforces access and admin policy
- Server core → Message types: routes · Dispatches protocol messages to domain handlers
- Server core → Ops helpers: uses · Handles persistence and operational housekeeping
- Message types → Protocol docs: defined by · Protocol domains are documented in message format notes
- Game plugin → Common lib: uses · Shares serialization and buffer utilities
- Server core → Common lib: uses · Shares serialization and buffer utilities
- Game plugin → KSP assemblies: depends on · Runs inside the KSP game process and API
- Game plugin → Vendored libs: depends on · Uses bundled parsing and utility libraries
- Server core → Vendored libs: depends on · Uses bundled parsing and utility libraries
