Architecture Overview
Moongate v2 is organized around a single game-loop thread with explicit queues between subsystems.
Runtime Pipeline
NetworkServiceaccepts TCP data viaMoongateTCPServer/MoongateTCPClient.- Incoming bytes are framed and parsed into
IGameNetworkPacketinstances. - Parsed packets are published to
IMessageBusServiceasIncomingGamePacket. GameLoopServicedrains the message bus and dispatches packets throughIPacketDispatchServicetoIPacketListener.- Listeners and handlers enqueue outbound packets to
IOutgoingPacketQueue. GameLoopServiceflushes outbound packets throughIOutboundPacketSender.
Main Building Blocks
Moongate.Server- Bootstrap, game loop, packet listeners/handlers, session services, file loaders.
Moongate.Network- TCP client/server primitives, span-based readers/writers, transport middleware.
Moongate.Network.Packets- Incoming/outgoing packet models, packet registry, packet attributes and generated definitions.
Moongate.Persistence- Snapshot + journal persistence unit-of-work and repositories.
Moongate.Server/Http(insideMoongate.Server)- Embedded ASP.NET Core HTTP service (
/health,/metrics,/scalar,/openapi/*). - Serves the frontend SPA on
/when UI hosting is enabled (default).
- Embedded ASP.NET Core HTTP service (
Moongate.Server.Metrics- Metrics providers, collection, snapshots, HTTP mapping.
Moongate.Scripting- Lua engine and script module integration.
Moongate.UO.Data- UO domain entities, enums, template models and shared data types.
Moongate.Core- Shared types, geometry, buffers, compression, dice notation, JSON utilities, random, text encoding.
Moongate.Abstractions- Base service contracts (
IMoongateService), email abstractions, service priority types.
- Base service contracts (
Moongate.Email- Email pipeline: Scriban template rendering and SMTP/no-op senders.
Moongate.Generators- 9 source generators for compile-time registration (packets, listeners, events, commands, metrics, scripts, file loaders, Lua user data, version metadata).
Concurrency Model
- Network I/O happens on transport callbacks/threads.
- Game state mutation is centralized in game-loop flow.
- Cross-thread handoff is explicit:
- inbound:
IMessageBusService - outbound:
IOutgoingPacketQueue
- inbound:
IGameEventBusServiceis used for decoupled in-process event publication.
Session Model
GameNetworkSession- Transport state (client reference, pending bytes, protocol state, seed, compression/encryption flags).
GameSession- Gameplay/protocol state (account/character ids, client version, movement state, runtime character).
Design Notes
- Packet registration is attribute-driven (
[PacketHandler(...)]) and materialized byPacketTable.Register(...). - Runtime packet processing uses
IGameNetworkPacket.TryParse(...)andWrite(ref SpanWriter). - Persistence currently stores world data in
save/world.snapshot.bin+save/world.journal.bin. UOMobileEntityintentionally does not include RPG-styleLevel/Experience; the base mobile model follows UO/ModernUO semantics.- Region subsystem is intentionally based on the ModernUO approach (selected as the strongest reference implementation): polymorphic JSON (
$type) plus map/sector indexing. - Region selection for a location uses deterministic ordering:
Prioritydescending, then parent-child depth (ChildLevel) for ties.
Previous: Solution Structure | Next: Network System