ServerEngine

ServerEngine

ServerEngine is the main server-side singleton code. Extend this class with your own server-side logic, and start a single instance.

This class should not be used to contain the actual game logic. That belongs in the GameEngine class, where the mechanics of the gameplay are actually implemented. The ServerEngine singleton is typically a lightweight implementation, logging gameplay statistics and registering user activity and user data.

The base class implementation is responsible for starting the server, initiating each game step, accepting new connections and dis-connections, emitting periodic game-state updates, and capturing remote user inputs.

Constructor

new ServerEngine(io, gameEngine, options) → {ServerEngine}

create a ServerEngine instance

Parameters:
Name Type Description
io SocketIO

the SocketIO server

gameEngine GameEngine

instance of GameEngine

options Object

server options

Properties
Name Type Default Description
stepRate Number

number of steps per second

updateRate Number

number of steps in each update (sync)

fullSyncRate Number

rate at which full-syncs are sent, in step count

tracesPath String

path where traces should go

countConnections Boolean

should ping player connections to lance.gg

updateOnObjectCreation Boolean

should send update immediately when new object is created

timeoutInterval Number 180

number of seconds after which a player is automatically disconnected if no input is received. Set to 0 for no timeout

Source:
Returns:

serverEngine - self

Type
ServerEngine

Members

serializer :GameEngine

reference to game engine

Source:

Methods

assignObjectToRoom(obj, roomName)

Assign an object to a room

Parameters:
Name Type Description
obj Object

the object to move

roomName String

the target room

Source:

assignPlayerToRoom(playerId, roomName)

Assign a player to a room

Parameters:
Name Type Description
playerId Number

the playerId

roomName String

the target room

Source:

createRoom(roomName)

Create a room

There is a default room called "/lobby". All newly created players and objects are assigned to the default room. When the server sends periodic syncs to the players, each player is only sent those objects which are present in his room.

Parameters:
Name Type Description
roomName String

the new room name

Source:

gameStatus() → {String}

Report game status This method is only relevant if the game uses MatchMaker functionality. This method must return the game status.

Source:
Returns:

Stringified game status object.

Type
String