# 80o/plusemu architecture

> Architecture diagram of the GitHub repository 80o/plusemu, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/80o/plusemu
- Repository: https://github.com/80o/plusemu

## Overview

##### Project type and purpose
- This is a server-side emulator for the Habbo Hotel game (“PlusEMU++”), written in C#/.NET. It implements the network protocols, encryption, packet handling, game logic (“HabboHotel” domain), persistence (MySQL/SQL), plus an RCON command interface and plugin extension system.

##### High-level layering and main components
A. Clients (FlashClient, NitroClient)
– Represent actual game clients (Flash or Nitro) connecting over TCP or WebSocket.
B. Communication Layer
– TcpGameServer / WebsocketGameServer (I​​GameServer implementations)
– Handshake / encryption modules (DiffieHellman, ARC4, RSA)
– PacketFactory → PacketManager → IPacketEvent handlers (Incoming) / IServerPacket composers (Outgoing)
C. Core & Configuration
– Core services: IStartable, IServerStatusUpdater, SettingsManager, LanguageManager, Logging (NLog)
– Configuration (config.json, nlog.config, figuredata.xml)
D. Domain Logic (“HabboHotel” namespace)
– Subsystems: Users (Authentication, Inventory, Effects, Messenger, Navigator, Permissions)
– Rooms (RoomManager, RoomItemHandling, PathFinding, AI bots)
– Catalog, Marketplace, Friends, Groups, Achievements, Quests, Moderation, Games, Rewards, Subscriptions
– Each manager implements an interface (e.g., IItemDataManager, IUserDataFactory).
E. Database Layer
– DatabaseConnection / QueryAdapter → NormalQueryReactor
– IDatabaseClient, IRegularQueryAdapter abstractions
F. Plugin & RCON System
– IPluginDefinition / IPlugin / PluginsCache → dynamic assembly loading
– RCON socket → IRconSocket → CommandManager → IRCONCommand implementations
G. Utilities
– DependencyInjection attributes, text handling, randomizer, encoding, converters

##### Data flow & component interactions
- Client initiates connection → Communication Layer handles handshake/encryption → Once session established, TcpSessionProxy or WsSessionProxy abstracts the stream.
- Incoming bytes go to PacketFactory → PacketManager routes to specific IPacketEvent handler under “Communication/Packets/Incoming”.
- Each handler invokes Domain Logic (HabboHotel.* Managers, e.g., RoomManager, CatalogManager). Domain logic may:
– Query or update persistent state via Database Layer
– Update cache (HabboHotel/Cache)
– Trigger outgoing responses (via IServerPacket composers under Communication/Packets/Outgoing)
- Configuration Managers (SettingsManager, LanguageManager) provide runtime parameters to encryption, game logic, and plugin loader.
- Plugin system hooks into packet events or domain events to allow extension.
- RCON commands connect over a separate TCP port (RCONSocket) to trigger administrative actions (reload bans, kick users).

##### Architectural patterns & principles
- Layered architecture: clear separation of network / core / domain / persistence.
- Dependency inversion: interfaces for every manager and adapter, DI attributes (Scoped/Singleton).
- Event-driven packet dispatch: decouple network I/O from business logic.
- Plugin architecture: dynamic assembly load context, cache, and hook points.
- Single Responsibility: each folder / class group handles one concern (e.g., “Rooms/PathFinding” vs “Rooms/AI”).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Clients Layer
    subgraph "Clients"
        FC["FlashClient"]:::clients
        NC["NitroClient"]:::clients
    end

    %% Communication Layer
    subgraph "Communication Layer"
        subgraph "Server Implementations"
            TGS["TcpGameServer"]:::comm
            WGS["WebsocketGameServer"]:::comm
        end
        subgraph "Handshake & Encryption"
            DH["DiffieHellman"]:::comm
            ARC4["ARC4"]:::comm
            RSA["RSAKey"]:::comm
            HE["HabboEncryptionV2"]:::comm
        end
        subgraph "Packet Processing"
            PF["PacketFactory"]:::comm
            PM["PacketManager"]:::comm
            IPH["Incoming Packet Handlers"]:::comm
            OPH["Outgoing Packet Composers"]:::comm
        end
        RCONSock["RCONSocket"]:::plugin
    end

    %% Core & Configuration
    subgraph "Core & Configuration"
        IS["IStartable"]:::core
        SSU["IServerStatusUpdater"]:::core
        SS["ServerStatusUpdater"]:::core
        SM["SettingsManager"]:::core
        LM["LanguageManager"]:::core
        CFGJSON["config.json"]:::core
        NLOG["nlog.config"]:::core
        FIG["figuredata.xml"]:::core
        LOG["NLog"]:::core
    end

    %% Domain Logic
    subgraph "Domain Logic"
        subgraph "Users"
            AUTH["Authenticator"]:::domain
            EFFECTS["EffectsComponent"]:::domain
        end
        subgraph "Rooms"
            RM["RoomManager"]:::domain
            PFND["PathFinder"]:::domain
        end
        CM["CatalogManager"]:::domain
        MM["MarketplaceManager"]:::domain
        FD["MessengerDataLoader"]:::domain
        GM["GroupManager"]:::domain
        QM["QuestManager"]:::domain
        AM["AchievementManager"]:::domain
        MOD["ModerationManager"]:::domain
        GM2["GameDataManager"]:::domain
        SM2["SubscriptionManager"]:::domain
        subgraph "Cache"
            CMGR["CacheManager"]:::domain
            RC["RevisionsCache"]:::domain
        end
    end

    %% Database Layer
    subgraph "Database Layer"
        DBC["DatabaseConnection"]:::db
        QA["QueryAdapter"]:::db
        NQR["NormalQueryReactor"]:::db
        IQA["IQueryAdapter"]:::db
        IDC["IDatabaseClient"]:::db
    end

    %% Plugin & RCON
    subgraph "Plugin & RCON"
        PLC["PluginLoadContext"]:::plugin
        PC["PluginsCache"]:::plugin
        PD["IPluginDefinition"]:::plugin
        PL["IPlugin"]:::plugin
        RCONConn["RCONConnection"]:::plugin
        CMGRcon["CommandManager"]:::plugin
        IRC["IRCONCommand"]:::plugin
    end

    %% Utilities
    subgraph "Utilities"
        SA["ScopedAttribute"]:::util
        UNA["SingletonAttribute"]:::util
        RAND["Randomizer"]:::util
        ENC["HabboEncoding"]:::util
        TXT["TextHandling"]:::util
    end

    %% Data Flows
    FC -->|"connects"| TGS
    NC -->|"connects"| WGS

    TGS -->|"handshake"| DH
    WGS -->|"handshake"| DH
    DH --> ARC4 --> RSA --> HE

    HE --> PF
    PF --> PM
    PM --> IPH
    PM --> OPH

    IPH -->|"invoke"| AUTH
    IPH -->|"invoke"| RM
    IPH -->|"invoke"| CM
    IPH -->|"invoke"| GM
    AUTH --> DBC
    RM --> DBC
    CM --> DBC
    GM --> DBC

    AUTH -->|"load cache"| CMGR
    PM --> FC
    OPH --> FC

    SM --> HE
    LM --> HE
    SM --> PLC
    LM --> PLC

    PLC --> PD
    PLC --> PL
    PL --> PM
    PD --> PL

    RCONSock --> RCONConn
    RCONConn --> CMGRcon
    CMGRcon --> IRC

    DBC --> QA --> NQR
    QA --> IDC
    DBC --> IDC

    %% Click Events
    click FC "https://github.com/80o/plusemu/blob/master/Communication/Flash/FlashGameClient.cs"
    click NC "https://github.com/80o/plusemu/blob/master/Communication/Nitro/NitroServer.cs"
    click TGS "https://github.com/80o/plusemu/blob/master/Communication/Abstractions/TcpGameServer.cs"
    click WGS "https://github.com/80o/plusemu/blob/master/Communication/Abstractions/WebsocketGameServer.cs"
    click DH "https://github.com/80o/plusemu/blob/master/Communication/Encryption/KeyExchange/DiffieHellman.cs"
    click ARC4 "https://github.com/80o/plusemu/blob/master/Communication/Encryption/Crypto/Prng/ARC4.cs"
    click RSA "https://github.com/80o/plusemu/blob/master/Communication/Encryption/Crypto/RSA/RSAKey.cs"
    click HE "https://github.com/80o/plusemu/blob/master/Communication/Encryption/HabboEncryptionV2.cs"
    click PF "https://github.com/80o/plusemu/blob/master/Communication/Flash/FlashPacketFactory.cs"
    click PM "https://github.com/80o/plusemu/blob/master/Communication/PacketManager.cs"
    click IPH "https://github.com/80o/plusemu/tree/master/Communication/Packets/Incoming"
    click OPH "https://github.com/80o/plusemu/tree/master/Communication/Packets/Outgoing"
    click IS "https://github.com/80o/plusemu/blob/master/Core/IStartable.cs"
    click SSU "https://github.com/80o/plusemu/blob/master/Core/IServerStatusUpdater.cs"
    click SS "https://github.com/80o/plusemu/blob/master/Core/ServerStatusUpdater.cs"
    click SM "https://github.com/80o/plusemu/blob/master/Core/Settings/SettingsManager.cs"
    click LM "https://github.com/80o/plusemu/blob/master/Core/Language/LanguageManager.cs"
    click CFGJSON "https://github.com/80o/plusemu/blob/master/Config/config.json"
    click NLOG "https://github.com/80o/plusemu/blob/master/Config/nlog.config"
    click FIG "https://github.com/80o/plusemu/blob/master/Config/figuredata.xml"
    click DBC "https://github.com/80o/plusemu/blob/master/Database/DatabaseConnection.cs"
    click QA "https://github.com/80o/plusemu/blob/master/Database/Adapter/QueryAdapter.cs"
    click NQR "https://github.com/80o/plusemu/blob/master/Database/Adapter/NormalQueryReactor.cs"
    click IQA "https://github.com/80o/plusemu/blob/master/Database/Interfaces/IQueryAdapter.cs"
    click IDC "https://github.com/80o/plusemu/blob/master/Database/Interfaces/IDatabaseClient.cs"
    click AUTH "https://github.com/80o/plusemu/blob/master/HabboHotel/Users/Authentication/Authenticator.cs"
    click EFFECTS "https://github.com/80o/plusemu/blob/master/HabboHotel/Users/Effects/EffectsComponent.cs"
    click RM "https://github.com/80o/plusemu/blob/master/HabboHotel/Rooms/RoomManager.cs"
    click PFND "https://github.com/80o/plusemu/blob/master/HabboHotel/Rooms/PathFinding/PathFinder.cs"
    click CM "https://github.com/80o/plusemu/blob/master/HabboHotel/Catalog/CatalogManager.cs"
    click MM "https://github.com/80o/plusemu/blob/master/HabboHotel/Catalog/Marketplace/MarketplaceManager.cs"
    click FD "https://github.com/80o/plusemu/blob/master/HabboHotel/Friends/MessengerDataLoader.cs"
    click GM "https://github.com/80o/plusemu/blob/master/HabboHotel/Groups/GroupManager.cs"
    click QM "https://github.com/80o/plusemu/blob/master/HabboHotel/Quests/QuestManager.cs"
    click AM "https://github.com/80o/plusemu/blob/master/HabboHotel/Achievements/AchievementManager.cs"
    click MOD "https://github.com/80o/plusemu/blob/master/HabboHotel/Moderation/ModerationManager.cs"
    click GM2 "https://github.com/80o/plusemu/blob/master/HabboHotel/Games/GameDataManager.cs"
    click SM2 "https://github.com/80o/plusemu/blob/master/HabboHotel/Subscriptions/SubscriptionManager.cs"
    click CMGR "https://github.com/80o/plusemu/blob/master/HabboHotel/Cache/CacheManager.cs"
    click RC "https://github.com/80o/plusemu/blob/master/Communication/Revisions/RevisionsCache.cs"
    click PLC "https://github.com/80o/plusemu/blob/master/Plugins/PluginLoadContext.cs"
    click PC "https://github.com/80o/plusemu/blob/master/Plugins/PluginsCache.cs"
    click PD "https://github.com/80o/plusemu/blob/master/Plugins/IPluginDefinition.cs"
    click PL "https://github.com/80o/plusemu/blob/master/Plugins/IPlugin.cs"
    click RCONSock "https://github.com/80o/plusemu/blob/master/Communication/RCON/RCONSocket.cs"
    click RCONConn "https://github.com/80o/plusemu/blob/master/Communication/RCON/RCONConnection.cs"
    click CMGRcon "https://github.com/80o/plusemu/blob/master/Communication/RCON/Commands/CommandManager.cs"
    click IRC "https://github.com/80o/plusemu/blob/master/Communication/RCON/Commands/IRCONCommand.cs"
    click SA "https://github.com/80o/plusemu/blob/master/Utilities/DependencyInjection/ScopedAttribute.cs"
    click UNA "https://github.com/80o/plusemu/blob/master/Utilities/DependencyInjection/SingletonAttribute.cs"
    click RAND "https://github.com/80o/plusemu/blob/master/Utilities/Randomizer.cs"
    click ENC "https://github.com/80o/plusemu/blob/master/Utilities/HabboEncoding.cs"
    click TXT "https://github.com/80o/plusemu/blob/master/Utilities/TextHandling.cs"

    %% Styles
    classDef clients fill:#E0FFFF,stroke:#333,stroke-width:1px
    classDef comm fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef core fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef domain fill:#90EE90,stroke:#333,stroke-width:1px
    classDef db fill:#FFA500,stroke:#333,stroke-width:1px
    classDef plugin fill:#D8BFD8,stroke:#333,stroke-width:1px
    classDef util fill:#D8BFD8,stroke:#333,stroke-width:1px
```
