Skip to content

About

Gateway Proxy for the Frostfire Forge Game Engine

Resources

Contributing

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

Frostfire Forge Gateway

Centralized Authentication & Reverse Proxy for Frostfire Forge MMO Platform

A production-grade authentication and reverse proxy gateway for Frostfire Forge game servers. Provides centralized user authentication, game server registration, automatic failover, real-time health monitoring, and realm-based server routing.

Docker Beta GitHub Stars


Note

Project Status: This project is currently a work in progress

Core Development Team: Lillious, Deph0

Community: Join our Discord


Table of Contents


Overview

The Frostfire Forge Gateway is a critical infrastructure component of the Frostfire Forge MMO platform. It acts as the central hub for:

  • User Authentication - Login, registration, email verification, and password reset
  • Game Server Management - Registration, health monitoring, and automatic failover
  • Client Routing - Realm based server selection and connection token generation
  • Asset Serving - Fast delivery of compressed game data and static assets
  • Monitoring & Administration - Real-time dashboard and health status APIs

The gateway works in conjunction with the Frostfire Forge Game Engine and Frostfire Forge Assets to provide a complete MMO platform.


Features

  • Game Server Authentication & Registration: Automatic server discovery and registration with heartbeat monitoring
  • User Authentication: Login, registration, email verification, password reset
  • Automatic Server Failover: Detects dead servers and migrates active client sessions automatically
  • Real-Time Monitoring Dashboard: Server health, CPU/RAM usage, connection counts, latency metrics
  • HTTP Proxying: Intelligent routing to game servers
  • SSL/TLS Support: Full HTTPS support for both webserver and gateway
  • Realm Routing: Client requests routed to appropriate game server realms
  • Asset Delivery: Gzip-compressed asset data serving
  • Documentation Site: Searchable docs for the engine, gateway, asset server, editors and players, served at /docs
  • Docker Ready: Development and production-ready containerization

Requirements

Important

Required Software:

  • Bun - JavaScript runtime & package manager
  • MySQL - Database for users and game state
  • Frostfire Forge Game Engine - Game servers that register with gateway
  • Frostfire Forge Assets - Asset server for game data
  • Docker (Optional) - For containerized deployment
  • SMTP Server (Optional) - For email verification (recommended for production)

Architecture

Server Design

The gateway consists of three independent processes:

┌─────────────────────────────────────────────────────────────┐
│                      GAME CLIENTS                           │
└──────────────────────────┬──────────────────────────────────┘
                           │
                    HTTP/HTTPS (80/443)
                           │
        ┌──────────────────▼────────────────────┐
        │    REVERSE PROXY (80/443)             │
        │  - TLS termination                    │
        │  - IP blacklist / whitelist           │
        │  - Malicious path filtering           │
        │  - Domain host validation             │
        │  - Forwards X-Real-Client-IP          │
        └──────────────────┬────────────────────┘
                           │
                    HTTP (127.0.0.1:8080)
                           │
        ┌──────────────────▼────────────────────┐
        │    WEBSERVER (internal 8080)          │
        │  - User authentication                │
        │  - Connection token generation        │
        │  - Static asset delivery              │
        └──────────────────┬────────────────────┘
                           │
                    HTTP/HTTPS (9999/9443)
                           │
        ┌──────────────────▼────────────────────┐
        │  GATEWAY SERVER (9999/9443)           │
        │  - Game server registration           │
        │  - Heartbeat monitoring               │
        │  - Failover & session migration       │
        │  - Health monitoring dashboard        │
        │  - Server status API                  │
        └──────────────────────┬────────────────┘
                               │
            ┌──────────────────┼──────────────────┐
            │                  │                  │
            ▼                  ▼                  ▼
    ┌──────────────┐   ┌──────────────┐   ┌──────────────┐
    │  Game Srv 1  │   │  Game Srv 2  │   │  Game Srv 3  │
    │  :3000/3001  │   │  :3000/3001  │   │  :3000/3001  │
    └──────────────┘   └──────────────┘   └──────────────┘

Server Responsibilities

Reverse Proxy (port 80/443):

  • Owns the public HTTP/HTTPS ports and terminates TLS
  • Enforces all security checks before any request reaches the webserver:
    • IP blacklist (b_ips) and whitelist (w_ips) enforcement
    • Malicious path filtering via src/webserver/config/security.cfg (auto-blacklists offending IPs)
    • HTTP method restrictions (blocks CONNECT, TRACE, TRACK, OPTIONS)
    • Domain host validation against DOMAIN
  • Redirects HTTP to HTTPS when SSL is enabled
  • Forwards approved requests to the internal webserver, injecting the real client IP via the X-Real-Client-IP header

Webserver (internal port 8080):

  • Binds to 127.0.0.1 only (never exposed publicly)
  • User login, registration, email verification
  • Password reset functionality
  • Static asset delivery (HTML, CSS, JS, images, fonts, music)
  • Tileset and map chunk delivery (gzip compressed)
  • HTTP request proxying to registered game servers
  • Realm-based server routing
  • Reads the client IP from the X-Real-Client-IP header (set by the reverse proxy) for login/verification

Gateway Server (port 9999/9443):

  • Game server registration and management
  • Heartbeat health monitoring
  • Automatic dead server cleanup
  • Session migration on server failure
  • Real-time monitoring dashboard
  • Server status API endpoints
  • Administrative authentication

Reverse Proxy

The reverse proxy (src/webserver/proxy.ts) is the only process bound to the public ports. It centralizes all edge security so that individual route handlers no longer need to perform IP checks, and the webserver is never directly reachable from the internet.

Request flow:

  1. Client connects to the proxy on WEBSRV_PORT / WEBSRV_PORTSSL (TLS terminated here when WEBSRV_USESSL=true).
  2. The proxy runs the security pipeline: method restrictions → IP blacklist → whitelist-aware malicious path filtering → domain host validation.
  3. Requests that fail any check receive a 403 (and offending IPs matched against security.cfg are added to the blacklist automatically).
  4. Approved requests are forwarded to the webserver at http://127.0.0.1:${WEBSRV_INTERNAL_PORT} with the real client IP added as the X-Real-Client-IP header.

Notes:

  • The webserver binds to 127.0.0.1 on WEBSRV_INTERNAL_PORT (default 8080) and serves plain HTTP; TLS lives entirely at the proxy.
  • The dynamic IP blacklist is loaded from the database and updated at runtime by the proxy -- no restart or config regeneration is required.
  • Malicious path rules are defined one-per-line in src/webserver/config/security.cfg.
  • All three processes (proxy, webserver, gateway) are started together by src/start.ts.

Environment Variables

# Database Configuration
DATABASE_ENGINE=mysql
DATABASE_HOST=localhost
DATABASE_NAME=frostfire_gateway
DATABASE_USER=gateway_user
DATABASE_PASSWORD=your_password
DATABASE_PORT=3306
SQL_SSL_MODE=DISABLED

# Gateway Server
GATEWAY_PORT=9999
GATEWAY_PORTSSL=9443
GATEWAY_USESSL=false
GATEWAY_AUTH_KEY=your-uuid-key-here
GATEWAY_GAME_SERVER_SECRET=your-shared-secret

# TLS Certificates (shared by the Gateway and Webserver)
TLS_CERT_PATH=./src/certs/cert.pem
TLS_KEY_PATH=./src/certs/key.pem
TLS_CA_PATH=./src/certs/cert.ca-bundle

# Webserver
WEBSRV_PORT=80
WEBSRV_PORTSSL=443
WEBSRV_INTERNAL_PORT=8080
WEBSRV_USESSL=false

# Asset Server Configuration
ASSET_SERVER_URL="http://127.0.0.1:8000"
ASSET_SERVER_AUTH_KEY=your-asset-server-key

# Email (Optional but recommended)
EMAIL_SERVICE=smtp.mailtrap.io
EMAIL_PORT=465
EMAIL_USER=your-email@example.com
EMAIL_PASSWORD=your-email-password

# Application Settings
LOG_LEVEL=debug
CACHE=memory
HEARTBEAT_INTERVAL=30000
SERVER_TIMEOUT=90000
SESSION_TIMEOUT=300000
GUEST_MODE_ENABLED=true
DOMAIN=http://localhost
GAME_NAME=Frostfire Forge
GATEWAY_URL=http://localhost:9999
PLAYER_Z_INDEX=4

# Client Configuration (injected into the game client at startup)
GATEWAY_ENABLED=true
VERSION=
# Optional: pin the game server certificate hash (base64 SHA-256 of the DER cert).
# Leave empty to fetch it automatically from the game server, or set to "off" to disable pinning.
GAME_WT_CERT_HASH=

Quick Start

Development Setup

Option 1: Use prebuilt Docker image:

docker run -d --name frostfire-gateway-dev -p 80:80 -p 443:443 -p 443:443/udp -p 9999:9999 -p 9443:9443 -p 9443:9443/udp ghcr.io/Frostfire-Interactive/frostfire-forge-gateway-dev:latest

Option 2: Build and run from source:

bun development

Optional: Update .env.development before running

Access the game client at http://localhost and the monitoring dashboard at http://localhost:9999/dashboard


Production Setup

Update the .env.production file

Configure your production environment variables including SSL certificates if needed.

Start the production server:

bun production

Docker Deployment

Using Docker Compose

# Start development environment
docker compose -f src/docker/docker-compose.dev.yml up -d

# View logs
docker compose -f src/docker/docker-compose.dev.yml logs -f

# Stop
docker compose -f src/docker/docker-compose.dev.yml down

Docker Commands

# Development
bun run docker:dev              # Start dev container
bun run docker:dev:logs         # View logs
bun run docker:dev:rebuild      # Rebuild and restart
bun run docker:dev:down         # Stop dev container

# Production
bun run docker:prod             # Start prod container
bun run docker:prod:logs        # View logs
bun run docker:prod:rebuild     # Rebuild and restart
bun run docker:prod:down        # Stop prod container

Setup Instructions

Database Setup

Create a MySQL database and user for the gateway:

CREATE DATABASE frostfire_forge;
CREATE USER 'gateway_user'@'localhost' IDENTIFIED BY 'secure_password';
GRANT ALL PRIVILEGES ON frostfire_forge.* TO 'gateway_user'@'localhost';
FLUSH PRIVILEGES;

Important

Run bun setup to initialize the database tables before running the engine's bun setup.

SSL/TLS Setup

The Gateway and Webserver share a single certificate (they always run on the same server):

src/certs/
├── cert.pem           # Server certificate
├── key.pem            # Private key
└── cert.ca-bundle     # Full CA chain (optional)

Then update the following environment variables:

WEBSRV_USESSL=true
GATEWAY_USESSL=true
TLS_CERT_PATH=./src/certs/cert.pem
TLS_KEY_PATH=./src/certs/key.pem
TLS_CA_PATH=./src/certs/cert.ca-bundle

Both services read TLS_CERT_PATH, TLS_KEY_PATH, and TLS_CA_PATH. If these variables are not set (or the files are missing), SSL is disabled and the services serve plain HTTP instead. The CA bundle is optional - when missing, only the leaf certificate is served.


Monitoring Dashboard

Access the real-time dashboard at http://localhost:9999/dashboard

Access: log in on the website with an admin account that holds the server.gateway or server.* permission. The dashboard uses that login; GATEWAY_AUTH_KEY does not open it. Opening /gateway on the website redirects to the dashboard on the right port.

Dashboard Features:

  • Real-time server status
  • CPU and RAM usage graphs
  • Connection count per server
  • Latency/RTT monitoring

Documentation Site

The webserver hosts the full documentation at /docs (for example http://localhost/docs).

  • The Player Guide is public. Every other section needs a logged-in, non-guest account.
  • Content is Markdown under src/webserver/documentation/, one file per page. See the README.md in that folder for the page format (code block titles, tabs, callouts).
  • Pages are rendered once at startup and re-rendered when a file changes, so edits show up without a restart.
  • src/webserver/documentation/sections.json sets the section order and which sections are public.

Security

Edge Filtering (Reverse Proxy)

  • Single choke point: All public traffic passes through the reverse proxy before reaching the webserver, which is bound to 127.0.0.1 only.
  • TLS termination: HTTPS is handled at the proxy; internal traffic to the webserver is plain HTTP over loopback.
  • IP allow/deny lists: Blacklisted IPs are rejected with 403; the list is loaded from the database and updated live at runtime.
  • Malicious path filtering: Requests targeting paths listed in src/webserver/config/security.cfg (e.g. .env, wp-admin) are blocked, and the source IP is automatically added to the blacklist.
  • Method & host validation: CONNECT, TRACE, TRACK, and OPTIONS are rejected, and the request host must match DOMAIN.

Authentication

  • Game Servers: Authenticated via GATEWAY_AUTH_KEY (UUID format)

    • All requests from game servers must include authKey in JSON body
    • Key is shared and must be kept secure
  • Dashboard Access: Session-based with HttpOnly cookies

    • Credentials generated on first run, stored in logs
    • Consider implementing LDAP/OAuth for production
  • Client Tokens: HMAC-SHA256 signed with GATEWAY_GAME_SERVER_SECRET

    • One-time use tokens bound to specific game server
    • Prevents token replay across servers

License

Free for noncommercial use under the PolyForm Noncommercial License 1.0.0. Every commercial use needs a paid commercial license from Lillious Networks. See LICENSING.md for which one applies to you.

Contributions are welcome and need a signed Contributor License Agreement; see CONTRIBUTING.md.


Built by the Frostfire Forge Team

About

Gateway Proxy for the Frostfire Forge Game Engine

Resources

Contributing

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages