How To Add Multiple Command Handlers

Diarkis commands (client to server) can have multiple command handler functions registered.

All command handlers will be invoked and executed in the order of their declarations.

The build-in commands' version and command ID are defined and exposed in "github.com/Diarkis/diarkis/util" package.

The following sample explains how to add a command handler before and after the room creation of Room module.

// Make sure to call room.Expose() first

room.Expose()

// Now we define an extra command handler to be invoked AFTER room create

server.HandleCommand(util.CmdBuiltInVer, util.CmdCreateRoom, handleAfterRoomCreate)

func handleAfterRoomCreate(ver uint8, cmd uint16, payload []byte, userData *user.User, next func (error)) {

  // Do something awesome here

  // You must call next in order to Diarkis to invoke next handler function

  next(nil)

}