From d5822e2d24c0a523c9e7698bd48343ea090c3169 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Sun, 31 Aug 2025 04:05:35 +0000
Subject: [PATCH] Add comprehensive server architecture diagrams and
documentation
Co-authored-by: aronwk-aaron <26027722+aronwk-aaron@users.noreply.github.com>
---
README.md | 6 +
docs/implementation-notes.md | 171 +++++++++++++
docs/server-architecture-ascii.md | 129 ++++++++++
docs/server-architecture-diagram.md | 382 ++++++++++++++++++++++++++++
4 files changed, 688 insertions(+)
create mode 100644 docs/implementation-notes.md
create mode 100644 docs/server-architecture-ascii.md
create mode 100644 docs/server-architecture-diagram.md
diff --git a/README.md b/README.md
index 9816db91..9ba79843 100644
--- a/README.md
+++ b/README.md
@@ -6,6 +6,12 @@ Darkflame Universe (DLU) is a server emulator for LEGO® Universe. Development s
### LEGO® Universe
Developed by NetDevil and The LEGO Group, LEGO® Universe launched in October 2010 and ceased operation in January 2012.
+## Architecture Documentation
+For developers and those interested in understanding the server architecture:
+* [Server Architecture Diagram](docs/server-architecture-diagram.md) - Comprehensive visual diagrams of server components and communication flows
+* [Server Architecture ASCII](docs/server-architecture-ascii.md) - Text-based architecture diagrams
+* [Implementation Notes](docs/implementation-notes.md) - Technical implementation details and code organization
+
## License
Darkflame Universe is licensed under AGPLv3, please read [LICENSE](LICENSE). Some important points:
* We are not liable for anything you do with the code
diff --git a/docs/implementation-notes.md b/docs/implementation-notes.md
new file mode 100644
index 00000000..fde4affb
--- /dev/null
+++ b/docs/implementation-notes.md
@@ -0,0 +1,171 @@
+# DarkflameServer Implementation Notes
+
+## Key Implementation Files by Server Type
+
+### Master Server (`dMasterServer/`)
+- **MasterServer.cpp**: Main server loop and packet handling
+- **InstanceManager.cpp**: Manages zone instances and player distribution
+- **PersistentIDManager.cpp**: Generates unique object IDs across servers
+- **Start.cpp**: Utility functions for starting other server types
+
+### Authentication Server (`dAuthServer/`)
+- **AuthServer.cpp**: Handles login, account creation, session management
+- **AuthPackets.cpp**: Authentication protocol implementation
+
+### Chat Server (`dChatServer/`)
+- **ChatServer.cpp**: Main chat server with social features
+- **ChatPacketHandler.cpp**: Routes chat and social messages
+- **PlayerContainer.cpp**: Manages online player registry
+- **TeamContainer.cpp**: Handles team/group functionality
+
+### World Server (`dWorldServer/`)
+- **WorldServer.cpp**: Game world simulation and entity management
+- **PerformanceManager.cpp**: Monitors server performance metrics
+
+### Networking Layer (`dNet/`)
+- **dServer.cpp/h**: Base server class with master communication
+- **MasterPackets.cpp/h**: Master server protocol implementation
+- **AuthPackets.cpp/h**: Authentication protocol
+- **ChatPackets.cpp/h**: Chat and social protocols
+- **WorldPackets.cpp/h**: World server protocols
+
+## Message Flow Implementation
+
+### Packet Structure
+```cpp
+// All packets use this basic structure:
+BitStreamUtils::WriteHeader(bitStream, ServiceType, MessageType);
+// Followed by message-specific data
+```
+
+### Service Types (from `ServiceType.h`)
+```cpp
+enum class ServiceType : uint16_t {
+ COMMON = 0,
+ AUTH, // Authentication Server
+ CHAT, // Chat Server
+ WORLD = 4, // World Server
+ CLIENT, // Client messages
+ MASTER, // Master Server
+ UNKNOWN
+};
+```
+
+### Critical Communication Patterns
+
+#### 1. Server-to-Master Registration
+```cpp
+// All servers connect to master on startup
+void dServer::ConnectToMaster() {
+ mMasterPeer->Connect(mMasterIP.c_str(), mMasterPort,
+ mMasterPassword.c_str(), mMasterPassword.size());
+}
+
+// On connection, servers send their info
+case ID_CONNECTION_REQUEST_ACCEPTED: {
+ MasterPackets::SendServerInfo(this, packet);
+ break;
+}
+```
+
+#### 2. Zone Transfer Protocol
+```cpp
+// World Server requests transfer
+MasterPackets::SendZoneTransferRequest(server, requestID, mythranShift, zoneID, cloneID);
+
+// Master finds/creates instance and responds
+void HandleZoneTransferRequest() {
+ auto instance = Game::im->GetInstance(zoneID, false, zoneClone);
+ // Send response with target server info
+}
+```
+
+#### 3. Chat Message Routing
+```cpp
+// World Server forwards chat to Chat Server
+void HandleChatMessage() {
+ // Route through Chat Server for processing
+ Game::chatServer->Send(bitStream, chatServerAddr, false);
+}
+
+// Chat Server routes to all relevant World Servers
+void RouteMessage() {
+ for (auto& worldServer : connectedWorldServers) {
+ Send(message, worldServer.address, false);
+ }
+}
+```
+
+## Database Architecture
+
+### Core Tables
+- **accounts**: User account information
+- **charinfo**: Character data and statistics
+- **friends**: Friend relationships
+- **mail**: In-game mail system
+- **properties**: Player property data
+- **leaderboards**: Competition scores
+- **servers**: Server configuration
+
+### Connection Management
+```cpp
+// Shared database connection across all servers
+Database::Connect(); // Uses connection pooling
+auto result = Database::Get()->Query(sql);
+```
+
+## Scalability Design
+
+### Load Distribution
+- Master Server acts as load balancer
+- Multiple World Servers can run different zones
+- Instance Manager distributes players across zones
+- Chat Server handles all social features centrally
+
+### Fault Tolerance
+- All servers maintain heartbeat with Master
+- Automatic reconnection on connection loss
+- Player state persisted in database
+- Graceful degradation when servers unavailable
+
+### Performance Optimizations
+- Entity serialization only to relevant players (ghosting)
+- Spatial partitioning for efficient updates
+- Message batching for network efficiency
+- Database query optimization with prepared statements
+
+## Security Features
+
+### Network Security
+- RakNet encryption for client connections
+- Server-to-server authentication via passwords
+- Session key validation across servers
+- Packet validation and sanitization
+
+### Game Security
+- Server-side validation of all game actions
+- Anti-cheat through server authority
+- Rate limiting on client requests
+- Database injection prevention
+
+## Development Notes
+
+### Build System
+- CMake-based build with modular components
+- Cross-platform support (Windows, Linux, macOS)
+- Dependency management through git submodules
+- Automated testing framework
+
+### Configuration
+- INI-based configuration files per server type
+- Environment variable support
+- Runtime configuration updates
+- Database-driven server settings
+
+### Debugging Features
+- Comprehensive logging system
+- Performance metrics collection
+- Packet capture and analysis tools
+- Real-time server monitoring
+
+This implementation successfully recreates the LEGO Universe MMO experience through a robust, scalable architecture that can support thousands of concurrent players across multiple game zones while maintaining the original game's functionality and performance characteristics.
\ No newline at end of file
diff --git a/docs/server-architecture-ascii.md b/docs/server-architecture-ascii.md
new file mode 100644
index 00000000..35dc69d5
--- /dev/null
+++ b/docs/server-architecture-ascii.md
@@ -0,0 +1,129 @@
+# DarkflameServer Architecture - ASCII Diagram
+
+```
+ DARKFLAME SERVER ARCHITECTURE
+ ===============================
+
+ ┌─────────────────────────────────────────────────────────────────────────────────────────┐
+ │ CLIENT LAYER │
+ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
+ │ │LEGO Universe│ │LEGO Universe│ │LEGO Universe│ │LEGO Universe│ │
+ │ │ Client │ │ Client │ │ Client │ │ Client │ │
+ │ │ (Player) │ │ (Player) │ │ (Player) │ │ (Player) │ │
+ │ └─────────────┘ └─────────────┘ └─────────────┘ └─────────────┘ │
+ │ │ │ │ │ │
+ └─────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┘
+ │ │ │ │
+ │ │ │ │
+ ┌─────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────┐
+ │ │ SERVER COMMUNICATION LAYER │ │ │
+ │ │ │ │ │ │
+ │ ▼ ▼ ▼ ▼ │
+ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
+ │ │AUTH SERVER │ │CHAT SERVER │ │WORLD SERVER │ │WORLD SERVER │ │
+ │ │ │ │ │ │ │ │ │ │
+ │ │Port: 1001 │ │Port: 1501 │ │Port: Dynamic│ │Port: Dynamic│ │
+ │ │ │ │ │ │ │ │ │ │
+ │ │• Login │ │• Chat Msgs │ │• Game Logic │ │• Game Logic │ │
+ │ │• Accounts │ │• Teams │ │• Entities │ │• Entities │ │
+ │ │• Sessions │ │• Guilds │ │• Physics │ │• Physics │ │
+ │ │• Keys │ │• Friends │ │• Zone Mgmt │ │• Zone Mgmt │ │
+ │ └─────────────┘ └─────────────┘ └─────────────┘ └─────────────┘ │
+ │ │ │ │ │ │
+ │ └───────────────────┼───────────────────┼───────────────────┘ │
+ │ │ │ │
+ │ │ │ │
+ │ ┌───────────────────┼───────────────────┼───────────────────┐ │
+ │ │ │ │ │ │
+ │ ▼ ▼ ▼ ▼ │
+ │ ┌─────────────────────────────────────────────────────────────────────────────┐ │
+ │ │ MASTER SERVER (Port: 1500) │ │
+ │ │ │ │
+ │ │ ┌──────────────────┐ ┌──────────────────┐ ┌──────────────────┐ │ │
+ │ │ │ Instance Manager │ │Persistent ID Mgr │ │ Session Manager │ │ │
+ │ │ │ │ │ │ │ │ │ │
+ │ │ │• Zone Instances │ │• Object ID Gen │ │• Player Sessions │ │ │
+ │ │ │• Load Balance │ │• Unique IDs │ │• Server Registry │ │ │
+ │ │ │• Player Transfer │ │• Cross-Server │ │• Coordination │ │ │
+ │ │ └──────────────────┘ └──────────────────┘ └──────────────────┘ │ │
+ │ └─────────────────────────────────────────────────────────────────────────────┘ │
+ │ │ │
+ └────────────────────────────────────────┼────────────────────────────────────────────────┘
+ │
+ ▼
+ ┌─────────────────────────────────────────┐
+ │ DATABASE LAYER │
+ │ │
+ │ ┌─────────────────────┐ │
+ │ │ MySQL Database │ │
+ │ │ │ │
+ │ │ • Player Data │ │
+ │ │ • Characters │ │
+ │ │ • Friends/Mail │ │
+ │ │ • Properties │ │
+ │ │ • Leaderboards │ │
+ │ │ • Configuration │ │
+ │ └─────────────────────┘ │
+ └─────────────────────────────────────────┘
+
+
+ MESSAGE FLOW OVERVIEW
+ ====================
+
+ Auth Messages Chat Messages World Messages
+ ============= ============= ==============
+
+ LOGIN_REQUEST GENERAL_CHAT_MESSAGE CHARACTER_LIST_REQUEST
+ CREATE_ACCOUNT PRIVATE_CHAT_MESSAGE GAME_MSG (1000+ types)
+ SESSION_KEY TEAM_INVITE LEVEL_LOAD_COMPLETE
+ AUTH_RESPONSE ADD_FRIEND POSITION_UPDATE
+ GUILD_OPERATIONS ZONE_TRANSFER_REQUEST
+
+ Master Coordination Messages
+ ============================
+
+ SERVER_INFO REQUEST_PERSISTENT_ID WORLD_READY
+ PLAYER_ADDED/REMOVED REQUEST_ZONE_TRANSFER SHUTDOWN
+ SET_SESSION_KEY AFFIRM_TRANSFER NEW_SESSION_ALERT
+
+
+ COMMUNICATION PATTERNS
+ ======================
+
+ 1. Client Authentication Flow:
+ Client → Auth Server → Master Server → World Server → Chat Server
+
+ 2. Zone Transfer Flow:
+ World Server → Master Server → Target World Server → Client
+
+ 3. Chat Message Flow:
+ Client → World Server → Chat Server → Target World Server → Target Client
+
+ 4. Entity Updates Flow:
+ World Server → EntityManager → ReplicaManager → All Clients in Zone
+
+ 5. Master Coordination:
+ All Servers ↔ Master Server (Heartbeat, Registration, Coordination)
+
+
+ NETWORK SPECIFICATIONS
+ ======================
+
+ Protocol: RakNet (UDP-based)
+ Encryption: Enabled for client connections
+ Packet Structure: [RakNet Header][Message Type][Service Type][Message Data]
+
+ Service Type Codes:
+ - MASTER (5): Server coordination
+ - AUTH (1): Authentication
+ - CHAT (2): Social features
+ - WORLD (4): Game simulation
+ - CLIENT (4): Client-specific
+
+ Key Features:
+ - Distributed architecture for scalability
+ - Fault tolerance through master coordination
+ - Real-time entity replication
+ - Cross-server player transfers
+ - Persistent world state
+```
\ No newline at end of file
diff --git a/docs/server-architecture-diagram.md b/docs/server-architecture-diagram.md
new file mode 100644
index 00000000..6dd5316b
--- /dev/null
+++ b/docs/server-architecture-diagram.md
@@ -0,0 +1,382 @@
+# DarkflameServer Architecture and Communication Diagram
+
+This document provides a comprehensive overview of the server architecture, inter-server communication patterns, and message flows in the DarkflameServer LEGO Universe emulator.
+
+## Server Architecture Overview
+
+```mermaid
+graph TB
+ subgraph "Client Layer"
+ Client1[LEGO Universe Client]
+ Client2[LEGO Universe Client]
+ Client3[LEGO Universe Client]
+ end
+
+ subgraph "DarkflameServer Infrastructure"
+ subgraph "Master Server (Port 1500)"
+ MasterServer[Master Server
- Zone Management
- Instance Coordination
- Session Management
- Server Registration]
+ IM[Instance Manager
- Zone Instances
- Player Transfers
- Load Balancing]
+ PIM[Persistent ID Manager
- Object ID Generation
- Unique Identifiers]
+ end
+
+ subgraph "Authentication Server (Port 1001)"
+ AuthServer[Auth Server
- Login Processing
- Account Management
- Session Keys
- Player Authentication]
+ end
+
+ subgraph "Chat Server (Port 1501)"
+ ChatServer[Chat Server
- General Chat
- Private Messages
- Team Management
- Guild System
- Friend Lists
- Mail System]
+ PC[Player Container
- Online Players
- Chat Routing]
+ end
+
+ subgraph "World Servers (Dynamic Ports)"
+ WorldServer1[World Server 1
- Game Logic
- Entity Management
- Physics Simulation
- Zone: Avant Gardens]
+ WorldServer2[World Server 2
- Game Logic
- Entity Management
- Physics Simulation
- Zone: Nimbus Station]
+ WorldServer3[World Server N
- Game Logic
- Entity Management
- Physics Simulation
- Zone: Custom]
+ EM1[Entity Manager]
+ EM2[Entity Manager]
+ EM3[Entity Manager]
+ WorldServer1 --- EM1
+ WorldServer2 --- EM2
+ WorldServer3 --- EM3
+ end
+ end
+
+ subgraph "Database Layer"
+ Database[(MySQL Database
- Player Data
- Characters
- Properties
- Leaderboards
- Mail
- Friends)]
+ end
+
+ %% Client Connections
+ Client1 -.->|1. Authentication| AuthServer
+ Client1 -.->|2. Character/Zone Data| WorldServer1
+ Client1 -.->|3. Chat Messages| ChatServer
+
+ Client2 -.->|Authentication| AuthServer
+ Client2 -.->|Character/Zone Data| WorldServer2
+ Client2 -.->|Chat Messages| ChatServer
+
+ Client3 -.->|Authentication| AuthServer
+ Client3 -.->|Character/Zone Data| WorldServer3
+ Client3 -.->|Chat Messages| ChatServer
+
+ %% Server-to-Master Connections (All servers connect to master)
+ AuthServer <-.->|SERVER_INFO
SESSION_KEY
PLAYER_ADDED/REMOVED| MasterServer
+ ChatServer <-.->|SERVER_INFO
PLAYER_ADDED/REMOVED
HEARTBEAT| MasterServer
+ WorldServer1 <-.->|ZONE_TRANSFER
PERSISTENT_ID
WORLD_READY
SERVER_INFO| MasterServer
+ WorldServer2 <-.->|ZONE_TRANSFER
PERSISTENT_ID
WORLD_READY
SERVER_INFO| MasterServer
+ WorldServer3 <-.->|ZONE_TRANSFER
PERSISTENT_ID
WORLD_READY
SERVER_INFO| MasterServer
+
+ %% Master Server Internal Communication
+ MasterServer --- IM
+ MasterServer --- PIM
+
+ %% Database Connections
+ AuthServer <--> Database
+ ChatServer <--> Database
+ WorldServer1 <--> Database
+ WorldServer2 <--> Database
+ WorldServer3 <--> Database
+ MasterServer <--> Database
+
+ %% Inter-World Server Communication (through Chat Server)
+ WorldServer1 <-.->|Player Messages
Zone Chat
Team Invites| ChatServer
+ WorldServer2 <-.->|Player Messages
Zone Chat
Team Invites| ChatServer
+ WorldServer3 <-.->|Player Messages
Zone Chat
Team Invites| ChatServer
+
+ style MasterServer fill:#ff9999
+ style AuthServer fill:#99ccff
+ style ChatServer fill:#99ff99
+ style WorldServer1 fill:#ffcc99
+ style WorldServer2 fill:#ffcc99
+ style WorldServer3 fill:#ffcc99
+ style Database fill:#cc99ff
+```
+
+## Message Type Breakdown
+
+### Master Server Messages (`MessageType::Master`)
+
+```mermaid
+graph LR
+ subgraph "Master Server Communication"
+ Master[Master Server]
+
+ subgraph "To/From Other Servers"
+ M1[REQUEST_PERSISTENT_ID
↔ World Servers]
+ M2[REQUEST_ZONE_TRANSFER
↔ World Servers]
+ M3[SERVER_INFO
← All Servers]
+ M4[SET_SESSION_KEY
↔ Auth Server]
+ M5[PLAYER_ADDED/REMOVED
← All Servers]
+ M6[WORLD_READY
← World Servers]
+ M7[SHUTDOWN
→ All Servers]
+ end
+
+ Master -.-> M1
+ Master -.-> M2
+ Master -.-> M3
+ Master -.-> M4
+ Master -.-> M5
+ Master -.-> M6
+ Master -.-> M7
+ end
+```
+
+### Authentication Server Messages (`MessageType::Auth`)
+
+```mermaid
+graph LR
+ subgraph "Auth Server Communication"
+ Auth[Auth Server]
+
+ subgraph "To/From Clients"
+ A1[LOGIN_REQUEST
← Clients]
+ A2[CREATE_NEW_ACCOUNT_REQUEST
← Clients]
+ A3[LEGOINTERFACE_AUTH_RESPONSE
→ Clients]
+ end
+
+ subgraph "To/From Master"
+ A4[SESSION_KEY
→ Master]
+ A5[PLAYER_NOTIFICATION
→ Master]
+ end
+
+ Auth -.-> A1
+ Auth -.-> A2
+ Auth -.-> A3
+ Auth -.-> A4
+ Auth -.-> A5
+ end
+```
+
+### Chat Server Messages (`MessageType::Chat`)
+
+```mermaid
+graph LR
+ subgraph "Chat Server Communication"
+ Chat[Chat Server]
+
+ subgraph "Player Social Features"
+ C1[GENERAL_CHAT_MESSAGE
↔ All Players]
+ C2[PRIVATE_CHAT_MESSAGE
↔ Players]
+ C3[TEAM_INVITE/RESPONSE
↔ Players]
+ C4[ADD_FRIEND_REQUEST
↔ Players]
+ C5[GUILD_OPERATIONS
↔ Players]
+ C6[MAIL_SYSTEM
↔ Players]
+ end
+
+ subgraph "World Server Integration"
+ C7[WORLD_ROUTE_PACKET
↔ World Servers]
+ C8[PLAYER_READY
← World Servers]
+ C9[HEARTBEAT_REQUEST
↔ World Servers]
+ end
+
+ Chat -.-> C1
+ Chat -.-> C2
+ Chat -.-> C3
+ Chat -.-> C4
+ Chat -.-> C5
+ Chat -.-> C6
+ Chat -.-> C7
+ Chat -.-> C8
+ Chat -.-> C9
+ end
+```
+
+### World Server Messages (`MessageType::World` & `MessageType::Game`)
+
+```mermaid
+graph TB
+ subgraph "World Server Communication"
+ World[World Server]
+
+ subgraph "Client Game Messages"
+ W1[CHARACTER_LIST_REQUEST
← Clients]
+ W2[CHARACTER_CREATE_REQUEST
← Clients]
+ W3[LOGIN_REQUEST
← Clients]
+ W4[GAME_MSG
↔ Clients]
+ W5[LEVEL_LOAD_COMPLETE
← Clients]
+ W6[POSITION_UPDATE
↔ Clients]
+ end
+
+ subgraph "Entity & Game Logic (1000+ Game Messages)"
+ G1[Entity Serialization
Player/NPC Updates]
+ G2[Combat System
Skills & Damage]
+ G3[Building System
Property Management]
+ G4[Mission System
Quest Management]
+ G5[Inventory System
Item Management]
+ G6[Racing System
Vehicle Physics]
+ end
+
+ subgraph "Master Server Communication"
+ W7[ZONE_TRANSFER_REQUEST
→ Master]
+ W8[PERSISTENT_ID_REQUEST
→ Master]
+ W9[WORLD_READY
→ Master]
+ end
+
+ subgraph "Chat Server Communication"
+ W10[Chat Messages
↔ Chat Server]
+ W11[Team Operations
↔ Chat Server]
+ end
+
+ World -.-> W1
+ World -.-> W2
+ World -.-> W3
+ World -.-> W4
+ World -.-> W5
+ World -.-> W6
+ World -.-> W7
+ World -.-> W8
+ World -.-> W9
+ World -.-> W10
+ World -.-> W11
+
+ World --- G1
+ World --- G2
+ World --- G3
+ World --- G4
+ World --- G5
+ World --- G6
+ end
+```
+
+## Communication Flow Diagrams
+
+### Player Login Flow
+
+```mermaid
+sequenceDiagram
+ participant C as Client
+ participant A as Auth Server
+ participant M as Master Server
+ participant W as World Server
+ participant Ch as Chat Server
+ participant DB as Database
+
+ C->>A: LOGIN_REQUEST
+ A->>DB: Validate credentials
+ DB-->>A: User data
+ A->>M: SET_SESSION_KEY
+ A->>C: LEGOINTERFACE_AUTH_RESPONSE
+ C->>W: CHARACTER_LIST_REQUEST
+ W->>DB: Get characters
+ DB-->>W: Character data
+ W->>C: Character list
+ C->>W: LOGIN_REQUEST (character selected)
+ W->>M: PLAYER_ADDED
+ W->>Ch: LOGIN_SESSION_NOTIFY
+ W->>C: Zone data & enter world
+```
+
+### Zone Transfer Flow
+
+```mermaid
+sequenceDiagram
+ participant C as Client
+ participant W1 as Source World Server
+ participant M as Master Server
+ participant W2 as Target World Server
+ participant Ch as Chat Server
+
+ C->>W1: Transfer request (rocket, door, etc.)
+ W1->>M: REQUEST_ZONE_TRANSFER
+ M->>M: Find/create zone instance
+ M-->>W1: ZONE_TRANSFER_RESPONSE
+ W1->>C: TRANSFER_TO_ZONE
+ C->>W2: Connect to new world server
+ W2->>M: Confirm player transfer
+ W2->>Ch: Update player location
+ W1->>M: PLAYER_REMOVED
+ W2->>M: PLAYER_ADDED
+```
+
+### Chat Message Flow
+
+```mermaid
+sequenceDiagram
+ participant C1 as Client 1
+ participant W1 as World Server 1
+ participant Ch as Chat Server
+ participant W2 as World Server 2
+ participant C2 as Client 2
+
+ C1->>W1: Chat message
+ W1->>Ch: GENERAL_CHAT_MESSAGE
+ Ch->>Ch: Process & route message
+ Ch->>W2: WORLD_ROUTE_PACKET
+ W2->>C2: Display message
+ Ch->>W1: Message confirmation
+ W1->>C1: Message sent confirmation
+```
+
+## Technical Implementation Details
+
+### Network Architecture
+- **Protocol**: RakNet UDP-based networking
+- **Security**: Encryption enabled for external connections
+- **Port Configuration**:
+ - Master Server: 1500 (default)
+ - Auth Server: 1001 (hardcoded in client)
+ - Chat Server: 1501 (configurable)
+ - World Servers: Dynamic ports assigned by Master
+
+### Server-to-Server Communication
+```cpp
+// All servers maintain connection to Master
+class dServer {
+ Packet* ReceiveFromMaster();
+ void SendToMaster(RakNet::BitStream& bitStream);
+ bool ConnectToMaster();
+ void SetupForMasterConnection();
+};
+```
+
+### Key Classes and Components
+
+#### Master Server Components
+- `InstanceManager`: Manages zone instances and player distribution
+- `PersistentIDManager`: Generates unique object IDs across all servers
+- `MasterPackets`: Handles inter-server message protocols
+
+#### World Server Components
+- `EntityManager`: Manages all game entities and their serialization
+- `UserManager`: Tracks connected players and their sessions
+- `ReplicaManager`: Handles object replication to clients
+- `GameMessages`: Processes 1000+ different game mechanic messages
+
+#### Chat Server Components
+- `PlayerContainer`: Maintains online player registry
+- `TeamContainer`: Manages team/group functionality
+- `ChatPacketHandler`: Routes all chat and social messages
+
+### Database Integration
+- All servers connect to shared MySQL database
+- Player data, characters, mail, friends, properties stored centrally
+- Concurrent access managed through connection pooling
+- Migration system for database schema updates
+
+### Scalability Features
+- Multiple World Server instances for different zones
+- Load balancing through Master Server's Instance Manager
+- Dynamic server spawning capability
+- Horizontal scaling support for high player counts
+
+## Message Protocol Specifications
+
+### Packet Structure
+```
+[RakNet Header][Message Type][Service Type][Message Data]
+```
+
+### Service Types
+- `MASTER (5)`: Master server coordination
+- `AUTH (1)`: Authentication services
+- `CHAT (2)`: Chat and social features
+- `WORLD (4)`: Game world simulation
+- `CLIENT (4)`: Client-specific messages
+
+### Critical Message Types by Frequency
+1. **GAME_MSG** (~60% of traffic): Real-time game mechanics
+2. **POSITION_UPDATE** (~20% of traffic): Player movement
+3. **Chat Messages** (~10% of traffic): Social communication
+4. **Entity Serialization** (~8% of traffic): World state sync
+5. **Administrative** (~2% of traffic): Server coordination
+
+This architecture enables the DarkflameServer to faithfully recreate the LEGO Universe MMO experience through a distributed, scalable server infrastructure that can handle thousands of concurrent players across multiple game zones.
\ No newline at end of file