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/storeand 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
pinofor fast, structured logging, making it easy to monitor and debug in a production environment.
Getting Started
Prerequisites
Installation
- Clone the Inglorious Engine repository:
git clone https://github.com/IngloriousCoderz/inglorious-engine.git- Navigate to the
@inglorious/serverdirectory:
cd packages/server- Install the dependencies:
pnpm installUsage
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 devRunning in Production Mode
To run the server in a production environment, use the start script.
pnpm startLoading 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.jsProject 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.