Server side - worldscapes/engine GitHub Wiki

Simulation layer

Simulation layer contains game world state. Its responsibility is to process and update it with time according to events that come from client.

After Simulation layer processed all events, world state snapshot goes to Clent side.

Except Events, Simulation can be driven by recurring Rules that do updates with time.

Server-side passes only updates to client-side, so it does change detection.

Domains

  • World simulation
    • AI
    • Physics
    • User Input reactions
  • World persistence

Server Engine Example

const engine = new ServerEngine({

  // Network server implementation that will be used by Engine
  networkServer: new NetworkServer(),

  // List of systems for pipeline, in order of execution
  systemsPipeline: [
    buildDamageSystem({ enableLogging: true }),
  ],

  // Function that will handle errrors if they happen inside of entity
  errorHandlerWrap: callback => {
    try {
        return callback;
    } 
    catch (error) {
        // handling

        throw new HandlerWrapWorkedError(); // this is needed to notify Engine that error was handled, so it keeps old component states
    }
  }
});

Framing layer

Framing layer is layer that defines which data update will go to client. The main purpose of it is to prevent cheating. Any information that should not go to client can be restricted.

Framing layer serves several purposes:

  • Hide server data to prevent cheatin
  • Decrease network load by sending atomic updates only

Basically, what it does - it defines which parts of game world should be passed to user and which not. Each user has whitelist of Entities and Resources they get. This whitelist is calculated by Framing layer. Engine automatically generates list of update commands.

Framing layer returns update for every client, so all the processing should be done several time. Performance degrades with each client, so calculations should be kept here as simple as possible.

Overall framing allows to safely implement mechanics such as fog of war, invisibility or team private information.

If you need to do some client-related calculations but those are too slow or do not require secret information - put them to client simulation layer.

Example of Fog of War implementation

In Framing layer we create new Rule. If client sees new objects this frame and it so, this Rule will create (or forward) command that add this entity on client-side. If something left client view - Rule creates command to remove it. If something updated - Rule creates update command. So Rule creates list of updates for each client and returns them.

After that on client-side of given client in Merging layer we can apply commands to client world state so we add or remove or update new entities.

In case of cheating hackers can only break how game works on client-side, but not what you get from client, so it's not possible to create vision hacks and so on.