Skip to content
Emol edited this page Mar 22, 2017 · 3 revisions

Client side

  • Client side stuff (lobby stuff, css, html etc) is in Public folder

Server side

  • engine.js runs the game for user.

  • Basically it listens for socket events clients send to server, and run the corresponding game Command.

  • All available game commands are specified in Commands.js, this is the interface for game logic.

Example

For example, user want to build a settlement.

In client side:

sock.emit('BUILD_SETTLEMENT', relevant_data);
sock.on('BUILD_SETTLEMENT_SUCCESS', function(received_data){
    // ... do some stuffs with data
    // ... do some jquery to change UI
});

Here, 'BUILD_SETTLEMENT' is an socket.io event.

In server side:

In engine.js, we do

got('BUILD_SETTLEMENT', function(relevant_data){
    Commands.buildSettlement(var1, var2...); 
    // ...
    send('BUILD_SETTLEMENT_SUCCESS', some_data);
}

This listens for 'BUILD_SETTLEMENT' event, builds the settlement, and sends client back an acknowledgement. got and send are wrappers around socket.on and socket.emit, so we can perform logging and additional preprocessing.

For event xxx, there will be a Commands.xxx.

Socket events and their corresponding data format are specified in server/engine/document folder.

To be consistent:

  1. if you add a new socket event, please add it and its data format to document folder.
  2. all events name are UPPERCASE linked with underscores.
Clone this wiki locally