Documentation

General

This section covers documentation on the protocol that is invariant between leagues. It describes the authorization, starting a new game, and the general game loop that each game will send the game state and how players should send their desired actions.

Authorization

Once you sign up for a game, you can retrieve your credentials in your profile and use them to join games.

{
"id": "123-123-1234",
"secret": "12323123123"
}

Starting a Game

Make an HTTP POST request to https://brawl.dev/api/games with a JSON formatted body containing the id and secret. You'll receive a websocket url in the response under the property url.

Request Body:

{
"id": "123-123-1234",
"secret": "12323123123",
"league": "xxxxx"
}

Response Body:

{
"url": "wss://xxx-xxx-xxx-xxx.game.brawl.dev/xxx/yyy/zzz"
}

Examples:

const {
data: { url }
} = await axios.post("https://brawl.dev/api/games", {
id: process.env.BRAWL_ID,
secret: process.env.BRAWL_SECRET,
league: process.env.BRAWL_LEAGUE
};

Game Loop

Once you receive the URL, you have 3 seconds to join and play the game. Create a new websocket connection to the URL and start waiting for a message.

  1. Listen for a message
  2. Process the message
  3. Respond on the websocket connection
  4. Repeat 1.
const ws = new WebSocket(url);
ws.on("message", function(data) {
const gameState = JSON.parse(data);
// process gameState here and decide on what action to take.
const action = {};
ws.send(
JSON.stringify(action)
);
});

Once the game is complete the websocket connection will close automatically. You can see the outcome in your game history in your profile

WARNING!! brawl.dev is currently in a PRERELEASED state. We don't expect any of the following, but we will try and minimize: any loss of accounts, loss of ranking progression, inconsistent data and system outages. Expect game parameter changes and rankings reset as we calibrate both the game systems and the ranking system.