Websocket protocole - fuwu-yuan/gameserver-go GitHub Wiki

Table of contents

  1. Connected to server
  2. New player joins the server
  3. A player leaves the server
  4. Broadcast

Websocket protocole

This is the websocket protocole between websocket server and websocket clients

All response will have same format :

Required

status ["success"|"error"]
data: [Object] Custom data object depending on message

Optional

sender: [string] UID of player sending the message ("server" if message from server)
code: [string] A simple string without representing the message in camel_case format

Connected to server

When the client connect to the server

Success Response:

 {
   "status": "success",
   "code": "connected",
   "sender": "server",
   "data": {
     "players": [],
     "server": {
        "id": 12,
        "game": "Kobbo",
        "version": "0.0.1",
        "name": "My personal game",
        "description": "Join my funny game!",
        "open": true,
        "limit": 4,
        "players": []
      }
   }
 }

Error Response:

  • Server full
    The number of clients is equal of server.limit Content:
    {
      "status": "error",
      "code": "room_full",
      "sender": "server",
      "data": {
        "server": {
          "id": 12,
          "game": "Kobbo",
          "version": "0.0.1",
          "name": "My personal game",
          "description": "Join my funny game!",
          "open": true,
          "limit": 4,
          "players": []
        }
      }
    }
    

New player joins the server

When a new player joins the server, all others players (except sender) are notified by a broadcast

Message

 {
   "code": "player_join",
   "sender": "62e5e6a1-01a5-4730-8410-e9e907a36805" // UID of new player
 }

A player leaves the server

When a player leaves the server, all others players are notified by a broadcast

Message

 {
   "code": "player_leave",
   "sender": "62e5e6a1-01a5-4730-8410-e9e907a36805" // UID of left player
 }

Broadcast

When a client send data to server, it broadcasts it to all others players

Message

 {
   "code": "broadcast",
   "sender": "62e5e6a1-01a5-4730-8410-e9e907a36805", // UID of left player
   "data": {} // message received by client for the broadcast as JSON data
 }
⚠️ **GitHub.com Fallback** ⚠️