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.
Note: This is the post 1.0.0 version of GameGuard that has lots of breaking changes from the last version due to major simplification. All of the previous features still exist but the API has changed to be more simple and streamlined. GameGuard can now be used on it's own but it has been simplified in order to be able to be extended further to suit your needs.
Note About Logging: For now, GameGuard has no logging capability. I've gone back and forth about implementing logging but I've found it to be so customizable it would be much easier for the end user to implement using signals but if there's enough requests then logging can be implemented to be a core part of GameGuard.
Table of Contents
To install GameGuard you need the server side package (this one) and then a client-side package. Currently only gameguard-client is supported but in the future there will be guides on creating your own client side solution to communicate with the GameGuard server.
To install GameGuard you can use:
$ npm install gameguard
and if you need gameguard-client, you can use:
$ npm install gameguard-client
Note: The documentation for gameguard-client will not be covered here but you can head over to the gameguard-client documentation for client side usage.
To initialize GameGuard, you have to initialize it with a reference to a http or https server and an optional set of options.
|server||http.Server||A reference to the http server instance to bind to.|
|options.heartbeatInterval||number||The interval at which each player is pinged, in milliseconds.||30000|
|options.latencyCheckInterval||number||The interval at which each player's latency is calculated, in milliseconds.||5000|
|options.maxLatency||number||The maximum latency, in milliseconds, the player can have before being kicked.||300|
|options.mongodbConnectionString||string||The connection string to use to connect to mongodb.||mongodb://localhost:27017|
A basic example of initializing GameGuard this with my personal favorite http server, fastify, is as follows:
'use strict'const path = ;const fastify = logger: true ;const GameGuard = ;const gg = fastifyserver;fastify;
Here's an example of initializaing GamGuard with options:
'use strict'const path = ;const fastify = logger: false ;const GameGuard = ;// Set the GameGuard server to use a latency check interval of 1000ms.const gg = fastifyserver latencyCheckInterval: 1000 ;// Have the server listen on port 3000.fastify;
Notice how we pass fastify's server instance to GameGuard so that GameGuard can use it to communicate with the client.
Let's also take a look how we can accomplish the same thing we did above but with express:
'use strict'const path = ;const express = ;const GameGuard = ;const app = ;// Have the server listen on port 3000.const server = app;// Set the GameGuard server to use a latency check interval of 1000ms.const gg = server latencyCheckInterval: 1000 ;
Now let's talk about the operation of GameGuard:
The GameGuard server instance is created with a http server instance.
Now, the GameGuard server waits for a WebSocket connection from a page using the GameGuard client and in specific it waits for the client to send a message that contains the id of the player that connected.
Before the client becomes a player, the GameGuard server checks to see if the id of that client corresponds to a player in the database that is banned and if so their connection gets reject. Otherwise, the client is accepted and their player profile is created locally and updated in the database.
Everything is set up now. The player can be kicked, banned, messaged, or put into rooms.
Since GameGuard is not a linear app and it's hard to go in order with what to document, we'll just go over the general aspect of each part of GameGuard and then link to the documentation for that module that goes in detail about it.
The GameGuard server uses the MongoDB to manage players with the mongoose package to manage the schemas and other operations. The database connection info has a default value of
mongodb://localhost:27017/gameguard but you can configure the connection credentials in a
.env file with a sample connection file provided as
Check out the database documentation for more specific database operations.
At it's core, GameGuard works around watching for clients trying to connect to the server and turning those clients into players. Once connected, players can be interacted with in forms of messaging, kicking, banning, or placing in rooms.
Check out the player documentation for more specific player operations.
Rooms are used to group players together to perform similar actions together. For example, you can group players together in a room and easily send messages to all of them.
Check out the room documentation for more specific room operations.
There are a few actions in GameGuard that are global and affect all players connected to the GameGuard server regardless of the rooms they are in.
Check out the global documentation for more specific global operations.
To run the tests for GameGuard server, you can use:
$ npm run test