How godarklight/darkmultiplayer works
1. What this repo is: DarkMultiPlayer is a two-part multiplayer system for Kerbal Space Program: a client-side game plugin and a standalone server. The server is the authority for shared game state, while the client integrates into KSP and mirrors/sends local player actions.
2. Top-level boundaries: The code is split into Client/, Server/, and Common/. Client depends on KSP runtime APIs and UI, Server is a headless .NET service, and Common holds shared utilities used by both sides for byte handling, compression, recycling, and message serialization support.
3. Client role: The client is the in-game mod. It handles connection setup, local UI, and translating KSP events into network updates. Its major subsystems are organized by responsibility: vessel control/update, chat, player status, groups/permissions, lock management, mod control, warp/time sync, screenshots, scenario sync, and universe conversion/cache.
4. Server role: The server accepts connections, authenticates and tracks clients, enforces bans/whitelist/permissions, and distributes authoritative state. It also manages admin commands, modpack rules, gameplay settings, lock state, and various cleanup/expiration tasks for transient data like screenshots or log records.
5. Network architecture: Communication is message-driven. The server has a Messages/ namespace with explicit message types such as handshake, heartbeat, vessel updates, player status, chat, warp control, lock system, mod data, scenario data, screenshots, and server settings. This implies a protocol where clients send intent/state changes and the server routes, validates, and broadcasts them.
6. Shared-world synchronization: The core gameplay data flow centers on vessels and scene state. Client workers such as VesselWorker, VesselUpdate, VesselProtoUpdate, VesselCtrlUpdate, ScenarioWorker, and CraftLibraryWorker sync KSP entities and persistence data; the server counterpart receives these updates and redistributes them to other players as needed.
7. Time and warp model: A distinct subsystem handles multiplayer time coordination. Files like TimeSyncer, WarpWorker, DynamicTickWorker, Server/Messages/WarpControl.cs, and the repo docs on subspace locking indicate support for subspace-style warp and master-controlled warp, with time synchronization treated as first-class network state.
8. Authority, locks, and access control: Collaborative play is mediated by server-side and client-side lock systems. The repo includes permissions, groups, admin systems, ban/whitelist commands, and lock propagation. These features are central to deciding who can control vessels, edit shared state, or issue administrative actions.
9. Mod and content compatibility: There is explicit support for modpack/mod-control syncing and compatibility checks. The client can generate a DMPModControl.txt, and both client/server include modpack and mod data handling. This means connection acceptance depends not just on network reachability, but also on matching or approved game content.
10. UI and KSP integration: The client has many windows and helpers for connection, server lists, options, debug, permissions, groups, player status, universe conversion, and disclaimers. DMPModInterface, toolbar support, and other wrappers show that the plugin is deeply embedded into KSP’s UI and game lifecycle rather than being a separate launcher app.
11. Runtime and deployment: The project is cross-platform. The README and tree show support for .NET builds, Mono on Unix-like systems, a Dockerfile, and a dmp@.service unit file. External vendored dependencies under External/ provide KSP assemblies and helper libraries for config parsing, message streaming, and UDP mesh functionality.
12. Useful diagram takeaway: The architecture diagram should show a KSP client plugin talking over a custom message protocol to a central authoritative server, with Common as shared serialization infrastructure and separate subsystems for vessel sync, time/warp sync, permissions/locks, chat/admin, modpack enforcement, and persistent server configuration/state.
Main entry points: Handshake.cs Message protocol · ClientHandler.cs Client handler · NetworkWorker.cs Network worker · Main.cs Client core
Components 17
Client
KSP in-game multiplayer plugin and UI
- Client core · KSP mod entry, lifecycle, and top-level client coordination
Client/Main.cs - Network worker · Connection setup, message dispatch, and network orchestration
Client/NetworkWorker.cs - Vessel sync · Vessel updates, control changes, and range/safety handling
Client/VesselWorker.cs - Time sync · Subspace time sync, warp control, and dynamic tick handling
Client/TimeSyncer.cs - Scene sync · Scenario, craft library, asteroid, flag, and universe conversion state
Client/ScenarioWorker.cs - Social state · Chat, player status, color, groups, permissions, and admin actions
Client/ChatWorker.cs - Mod control · Modpack, mod data, install checks, and mod interface integration
Client/ModWorker.cs - UI layer · Connection, server list, options, debug, permissions, groups, and disclaimers windows
Client/ConnectionWindow.cs - KSP wrappers · Toolbar, game hooks, vessel utilities, and plugin-facing helpers
Client/DMPGame.cs
Server
Headless authoritative multiplayer service
- Server core · Headless server entry point and runtime wiring
Server/Main.cs - Client handler · Connection handling, handshake flow, and client session lifecycle
Server/ClientHandler.cs - Message protocol · Handshake, heartbeat, vessel, chat, warp, lock, mod, scenario, and settings messages
Server/Messages/Handshake.cs - World state · Authoritative vessel, lock, groups, permissions, gameplay settings, and plugin state
Server/LockSystem.cs - Access control · Bans, whitelist, kick/admin commands, and moderation boundaries
Server/BanSystem.cs - Modpack rules · Modpack enforcement, backwards compatibility, and plugin interface support
Server/ModpackSystem.cs - Ops tasks · Log and screenshot expiration, file safety, cleanup, and server info
Server/LogExpire.cs
Common
Shared transport and serialization helpers
- Common core · Shared byte, compression, and recycler primitives used by both sides
Common/Common.cs
Connections 21
- Client core → Network worker: drives · Client bootstrap starts and coordinates networking
- Client core → UI layer: opens · Client entry exposes in-game windows and controls
- Client core → KSP wrappers: hooks · Client integrates with KSP lifecycle and wrappers
- Network worker → Client handler: connects · Client session connects to the authoritative server
- Network worker → Message protocol: sends/receives · Message-driven protocol carries all multiplayer traffic
- Vessel sync → Message protocol: syncs · Vessel state and control updates flow through protocol messages
- Time sync → Message protocol: coordinates · Warp and time coordination use dedicated protocol messages
- Scene sync → Message protocol: syncs · Scenario, craft, flags, and universe state are exchanged
- Social state → Message protocol: updates · Chat, player status, groups, and permissions are propagated
- Mod control → Modpack rules: matches · Client modpack and mod data must satisfy server rules
- UI layer → Network worker: controls · UI initiates connections, settings changes, and status actions
- UI layer → Social state: surfaces · Windows expose players, permissions, and admin tools
- Common core → Network worker: shared lib · Client uses shared serialization and buffer utilities
- Common core → Message protocol: shared lib · Server message handling depends on common helpers
- Server core → Client handler: accepts · Server bootstrap creates client/session handlers
- Client handler → World state: updates · Connected clients mutate authoritative shared world state
- Client handler → Access control: checks · Connections are filtered by ban, whitelist, and admin policy
- Client handler → Modpack rules: verifies · Incoming clients are checked against modpack expectations
- World state → Message protocol: broadcasts · Authoritative changes are redistributed through message types
- Ops tasks → World state: cleans · Expiration tasks remove transient records and stale data
- Ops tasks → Client handler: supports · Operational tasks help maintain active sessions and logs