UNPKG

gameguard

Version:

GameGuard is a NodeJS game server that can be used to manage the players connecting to your game, manage rooms and the players in them, and more.

27 lines (20 loc) 1.16 kB
'use strict' const path = require('path'); const express = require('express'); const app = express(); // We use the public folder to serve the game and the gameguard-client module // folder so serve that. app.use(express.static(path.resolve(__dirname, '..', 'public'))); app.use(express.static(path.resolve(__dirname, '..', '..', '..', 'node_modules', 'gameguard-client'))); // Require the compiled version of GameGuard server. const GameGuard = require('../../../build/index'); // Have the server listen on port 3000. const server = app.listen(3000, () => console.log('Listening on port 3000')); // Set the GameGuard server to use a latency check interval of 1000ms. const gg = new GameGuard(server, { latencyCheckInterval: 1000 }); // When a client has successfully connected to the GameGuard server and has // become a player, we log the player's id server side. gg.playerConnected.add(player => console.log(`Player ${player.id} joined.`)); // When a player leaves and their connection to GameGuard is closed, we log // their id server side. gg.playerDisconnected.add(player => console.log(`Player ${player.id} left.`));