Skip to content

Instantly share code, notes, and snippets.

@p2004a
Last active November 25, 2022 19:14
Show Gist options
  • Save p2004a/5311db54df6f26a9a829c9388956275f to your computer and use it in GitHub Desktop.
Save p2004a/5311db54df6f26a9a829c9388956275f to your computer and use it in GitHub Desktop.
BAR assets CDN launcher/lobby integration

BAR assets CDN launcher/lobby integration

Describes how to change integration in lobbies to leverage new BAR CDN setup for distributing game and maps.

Background

As part of the “BAR launcher is speed” project I realized that current hosting of game assets is not meeting the needs of global BAR community. Both maps and game distribution happens from the central server in Germany which is problematic for players from outside of Europe. To mitigate this, I’ve set up an alternative assets hosting mechanism that mirrors required assets and allows for more reliable delivery.

BAR game files are currently being distributed by the Rapid system. To download from it there is a dedicated tool pr-downloader. This document will focus on how to configure it to leverage new hosting. Maps are being downloaded from https://springfiles.springrts.com/ and downloading them is also supported by pr-downloader but some lobbies have a more direct integration.

ℹ️ NOTE: It’s important to use the BAR fork of pr-downloader (distributed together with BAR engine), as upstream doesn’t have required changes.

Game distribution (rapid)

To download game via pr-downloader from CDN lobby needs to set 2 environment variables when launching binary:

  • PRD_RAPID_USE_STREAMER=false
  • PRD_RAPID_REPO_MASTER=https://repos-cdn.beyondallreason.dev/repos.gz

If pr-downloader is also called from the game (e.g. Chobby), the same environment variables need to be also set when launching spring binary.

Additionally an option must be set in springsettings.cfg configuration file to make sure that game resolves rapid tags from the correct repository:

RapidTagResolutionOrder = repos-cdn.beyondallreason.dev

ℹ️ NOTE: If lobby supports changing the repo back to the default, it must also clear RapidTagResolutionOrder tag when doing so.

Initial game download

For initial game download when there aren't any files present in the pool directory, it's highly preferred to download a pool preseed file that contains periodically build (currently weekly) game files: https://pool-init.beyondallreason.dev/data.7z and unpack it to the pool directory following with regular pr-downloader run.

The goal of that is to significantly reduce bandwidth cost of the CDN hosting rapid, shifting it to CDN that is much more cost efficient for bandwidth and single big file downloads but is not suitable for quick partial updates.

Maps distribution (springfiles)

Using pr-downloader

The only required change is to set one additional environment variable:

PRD_HTTP_SEARCH_URL=https://files-cdn.beyondallreason.dev/find

Same variable must be also set to spring binary if the loaded mod is downloading maps too (e.g. Chobby).

Manual fetch

Lobby needs to call https://files-cdn.beyondallreason.dev/find endpoint using GET method with 2 url parameters

  • category equal to map, and
  • springname of the map.

For example to fetch info about “Angel Crossing 1.4”: https://files-cdn.beyondallreason.dev/find?category=map&springname=Angel%20Crossing%201.4

It will return JSON encoded map metadata in the same format as returned from springfiles. Example formated response:

[
  {
    "filename": "angel_crossing_1.4.sd7",
    "springname": "Angel Crossing 1.4",
    "md5": "9fc29b4e9dd666d9f9866280fb3c0861",
    "category": "map",
    "path": "maps",
    "tags": [],
    "size": 83728479,
    "timestamp": "2022-06-18T19:37:47",
    "mirrors": [
      "https://files-cdn.beyondallreason.dev/file/cn2874nc987r239nrx873qny4/angel_crossing_1.4.sd7"
    ]
  }
]

ℹ️ NOTE: Unlike real springfiles, this endpoint doesn’t support full search, and will error if result from springfiles would return multiple entries. It's guaranteed to always return a single entry or a HTTP error like Not Found.

With that metadata information lobby must:

  1. Fetch file pointed by mirrors property. Lobby must not make any assumptions about the returned URLs. In case multiple are returned: it should choose one at random.
  2. Save the downloaded file to a temporary location.
  3. Verify that the md5 sum from metadata matches the downloaded file.
  4. Move the verified map to the destination location maps/{filename} where filename is property from the metadata, not basename from mirror URL, e.g. maps/angel_crossing_1.4.sd7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment