JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 66
  • Score
    100M100P100Q88682F
  • License MIT

A real-time, lightweight server designed to enable multiplayer experiences for games built with the Inglorious Engine.

Package Exports

  • @inglorious/server

Readme

Inglorious Server

A real-time, lightweight server designed to enable multiplayer experiences for games built with the Inglorious Engine. This server is built on Node.js and uses WebSockets to handle real-time communication, ensuring low-latency updates for all connected clients.

Features

  • Real-Time Communication: Uses WebSockets to provide bidirectional, low-latency communication between the server and clients.
  • Server-Authoritative Game State: Manages a central game state using the @inglorious/store and acts as the single source of truth for all clients.
  • Scalable Architecture: The server's logic is modular and split into dedicated files for handling game loading, the main game loop, and WebSocket events.
  • Dynamic Game Loading: Supports loading game data from a specified JavaScript module, allowing you to easily run different game worlds without changing the server code.
  • Production-Ready Logging: Uses pino for fast, structured logging, making it easy to monitor and debug in a production environment.

Getting Started

Prerequisites

  • Node.js (version 22 or higher)
  • pnpm (used for package management)

Installation

  1. Clone the Inglorious Engine repository:
git clone https://github.com/IngloriousCoderz/inglorious-engine.git
  1. Navigate to the @inglorious/server directory:
cd packages/server
  1. Install the dependencies:
pnpm install

Usage

The server can be started using the start or dev scripts. You can optionally provide a path to a game module to load a specific game state.

Running in Development Mode

To run the server with automatic restarts on file changes, use the dev script.

pnpm dev

Running in Production Mode

To run the server in a production environment, use the start script.

pnpm start

Loading a Specific Game

By default, the server will attempt to load a ./default-game.js file. To load a different game, provide the file path as a command-line argument.

pnpm start ./path/to/your-game.js

Project Structure

The server's code is split into several files to maintain a clear separation of concerns.

  • src/index.js: The main entry point for the server. It orchestrates the setup of the HTTP and WebSocket servers and initializes the game store and its core handlers.
  • src/game-loader.js: Handles the dynamic loading of the initial game state from a JavaScript module. It also includes a fallback state if the game file is not found.
  • src/game-loop.js: Contains the core setInterval loop that drives the game logic by calling the store.update() function at a fixed tick rate (60 updates per second).
  • src/websocket-handler.js: Manages all WebSocket events, including new connections, incoming messages, and disconnections. It dispatches client events to the store and broadcasts changes to all clients.

Dependencies

  • @inglorious/store: The state management solution for the game engine.
  • ws: A simple and fast WebSocket library.
  • pino: A highly performant logger for Node.js.

License

MIT License - Free and open source

Created by Matteo Antony Mistretta

You're free to use, modify, and distribute this software. See LICENSE for details.