Skip to content

Define client-server communication flow #7

@Bigorneau

Description

@Bigorneau

Format of messages

Message type and JSON data with a well-defined structure.

emit("type", {"key": "value"})

Client Join

Client -> Server
"join", {
  "nick": "Player nickname",
  "color": "#rrggbb",
  "armaturae": "mirmillo"
}

Server -> Client
(actor:spawn|Error)

Client input

Client -> Server
"input:press", {
  "type": "up"
}
Client -> Server
"input:release", {
  "type": "primary"
}

Available types:

  • up, down, left, right
  • primary, secondary, ternary
  • taunt
  • dash
  • lockDirection

Actor events

Server -> Client
"actor:update", {
  "id": "UUID",
  "changes": {
    "x": 10,
    "y": 0,
    "direction": "east"
  }
}

Available types:

  • create
  • remove
  • update

Examples

# An arrow is shot and hits a player
"actor:create", {
  "id": "arrow_id",
  "x": 0,
  "y": 0
}
"actor:update", {
  "id": "arrow_id",
  "x": 0,
  "y": 10
}
// ...
"actor:update", {
  "id": "player_id",
  "reason": "hit",
  "health": 20,
  "armor": 10
}
"actor:remove", {
  "id": "arrow_id"
}

World state

Server -> Client
"worldstate", {
  "actors": [
    {
      "id": "UUID",
      "type": "player",
      "nick": "Nickname",
      "x": 0,
      "y": 0,
      "direction": "north",
      "armaturae": "mirmillo"
      // ...
    }
    {
      "type": "wall",
      "x": 32,
      "y": 64,
    }
  ]
}

Errors

Server -> Client
"error", {
  "type": "InvalidNickname",
  "message": "Nickname is already in use"
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions