Lobby System Documentation
A complete technical guide to the BlinkBox Lobby System, including client-side Unity components and the Node.js backend server.
Overview
The BlinkBox Lobby System is a robust, multiplayer lobby solution designed for Unity games. It bridges the gap between Unity clients and a centralized backend to manage parties, matchmaking, and real-time state synchronization.
Party Management
Complete party system with Create, Join (via code), Leave, and Kick functionality. Synchronizes ready states and character selections in real-time.
Node.js Backend
Scalable Express.js + WebSocket server that handles connection management, heartbeats, and party logic independent of the game server.
Voice Chat
Integrated ODIN SDK support for high-quality voice chat, including Push-to-Talk, spatial audio, and mute functionality.
Modular UI
Prefab-based UI system with separate panels for Party, Join, and Connection states. Includes player nameplates and dynamic status indicators.
Installation & Setup
1. Unity Client Setup
- Ensure Photon PUN2 is installed and configured in your project.
- Import the ODIN SDK for voice chat functionality.
- Drag the
LobbyManagerprefab into your startup scene (or initialize it via script). - Ensure
LobbySettingsandLobbyVoiceSettingsare present in aResourcesfolder.
2. Server Setup
The backend is a Node.js application located in Assets/Addons/BlinkBox/LobbySystem/Server.
# Navigate to server directory
cd Assets/Addons/BlinkBox/LobbySystem/Server
# Install dependencies
npm install
# Configure environment
cp .env.example .env
# Start the server
npm start
Environment Variables (.env)
| Variable | Default | Description |
|---|---|---|
PORT |
3000 | The port the WebSocket server listens on. |
NODE_ENV |
development | Set to production for live environments. |
ALLOWED_ORIGINS |
* | Comma-separated list of allowed CORS origins. |
MAX_PARTY_SIZE |
32 | Maximum number of players in a single party. |
Architecture
The system uses a Client-Server architecture where Unity clients communicate with a Node.js WebSocket server for lobby state, while using Photon PUN for the actual gameplay networking.
- Unity Client (C#): Handles UI, input, and local state. Uses
NativeWebSocketto talk to the Node server. - Lobby Server (Node.js): Manages the "source of truth" for parties, member lists, and invites.
- Voice Server (ODIN): Handles audio streaming between clients.
Lobby Manager
The bl_LobbyManager class is the heart of the client-side system. It is a singleton that persists across scenes.
Key Responsibilities
- Connection Management: Handles WebSocket connection, reconnection logic, and heartbeat.
- State Synchronization: Keeps local dictionaries (
partyMembers,readyStates,playerCharacters) in sync with the server. - Event Dispatching: Fires C# events when server messages are received.
Public Properties
IsConnected |
Returns true if WebSocket connection is open. |
IsInParty |
Returns true if the local player is currently in a party. |
IsPartyLeader |
Returns true if the local player is the host of the current party. |
CurrentPartyCode |
The 7-digit code used to join the current party. |
UI System
Managed by bl_LobbySystemUI.cs. The UI is state-driven and reacts to events from the Lobby Manager.
Key Panels
- ConnectingPanel: Shown while establishing WebSocket connection.
- PartyPanel: The main lobby view. Shows player nameplates, character models, and "Ready" button.
- JoinPartyPanel: Input field for entering a party code.
- DisconnectedPanel: Shown if connection to server fails.
Player Nameplates
The bl_PlayerNameplate script handles individual player slots. It displays:
- Player Nickname
- Ready Status (Green/Red indicator)
- Leader Icon (Crown)
- Voice Activity (Speaker icon)
Voice Chat
Powered by the ODIN SDK and managed by bl_LobbyVoiceManager.cs.
Features
- Spatial Audio: 3D positional audio support (configurable).
- Push-to-Talk: Configurable key (Default: V) to activate microphone.
- Voice Activity Detection (VAD): Automatically detects speaking when not using PTT.
Configuration
Voice settings are stored in a LobbyVoiceSettings ScriptableObject.
Settings
The system is highly configurable via the bl_LobbySettings ScriptableObject (Right-click > BlinkBox > LobbySystem > Lobby Settings).
Server Settings
- Server Url: WebSocket endpoint (e.g.,
ws://localhost:3000/ws). - Reconnect Delay: Time in seconds to wait before retrying connection.
UI Settings
- Show Voice Indicators: Toggle microphone icons on nameplates.
- Colors: Customize Ready/Not Ready and Speaking/Muted colors.
Logging
Toggle debug logs for Server messages, Party events, and Voice chat independently.
Node.js Server
The server logic resides in server.js. It uses the ws library for WebSockets and express for the HTTP server.
Features
- Rate Limiting: Protects the API from spam (100 reqs / 15 min by default).
- Security: Uses
helmetfor headers and strict CORS policies. - Logging: Rotates log files in the
/logsdirectory automatically.
Socket API
Communication protocol between Unity Client and Node.js Server. All messages are JSON formatted.
Client -> Server Messages
| Type | Payload | Description |
|---|---|---|
identify |
{ clientId, nickname } |
Registers the connection with a user profile. |
create_party |
{ maxSize } |
Requests creation of a new party. |
join_party |
{ code } |
Attempts to join a party by code. |
leave_party |
{} |
Leaves the current party. |
set_ready |
{ isReady } |
Updates the local player's ready state. |
select_character |
{ characterId } |
Updates the selected character index. |
Server -> Client Messages
| Type | Payload | Description |
|---|---|---|
party_created |
{ id, code } |
Confirmation of party creation. |
player_joined |
{ id, nickname } |
Notification that a new member joined. |
party_state |
{ members, readyStates... } |
Full sync of party state (sent on join). |
Web Monitor
The server includes a built-in web dashboard for monitoring server status.
URL: http://your-server-url/
The public/ folder contains the frontend for this dashboard, visualizing:
- Active connections count
- Current parties and their members
- Real-time server logs
C# API Reference
Primary methods available in bl_LobbyManager.
Events
public event Action<string> OnMemberJoined;
public event Action<string> OnMemberLeft;
public event Action<string, bool> OnMemberReadyChanged;
public event Action<string, int> OnMemberCharacterSelected;
public event Action<string> OnPartyLeaderChanged;
public event Action OnPartyLeft;
public event Action OnGameStarted;
public event Action<string> OnPartyCreated;
public event Action OnConnected;
public event Action OnDisconnected;
Methods
// Create a new party
public void CreateParty(int maxSize = 4);
// Join an existing party
public void JoinParty(string code);
// Leave current party
public void LeaveParty();
// Kick a player (Leader only)
public void KickMember(string playerId);
// Set local ready state
public void SetReadyState(bool isReady);
// Select a character
public void SelectCharacter(int characterId);