Skip to content

amokmen/wespar

Repository files navigation

Wesnoth duel replay parser

Extract from a Wesnoth replay: game settings, sides info, chat log.

Semantic Versioning 2.0.0 Conventional Commits 1.0.0 Commitizen friendly

GPL3 Logo

Features

App consists from:

  • NodeJS back-end with web-server fastify and API endpoint;
  • Front-end (at the same web-server).

This app is for parsing replays from official server 'replays.wesnoth.org'. App gather game settings, sides info, and chat log with unique feature - show all chat lines with binding to current turn number.

I wish it could help somehow tournament organizers.
Players also could use it to get quick glance at replay.

Although this app created for 1v1 replays (for 2 sides/players), it still could be used with any replay with some disclaimers - for example app would show chat log, but there could be wrong colorizing and so on.

Example of colorized chat log with binding to turn numbers:

SVG-file Chat Example

User's manual

  1. Find a replay at official Wesnoth replays server. Supported only 1.14.X versions (probably other versions could work too).
  2. Copy link to replay (example: link).
  3. Open app https://wespar.onrender.com/.
  4. Insert link and press button.
  5. Server would download that replay, decompress and parse info.
  6. Result would be shown.

Users FAQ

Q: Does it say if a player picked?
A: No, I could not gather such info from replay file structure.

Q: Why there are no factions?
A: There is no simply universal way to get factions from replay structure. So, there are only leaders as faction's representative.

Q: Why there are "unknown_time" for messages from server?
A: It's my placeholder, because there are really no timestamp for server's messages in replay structure. Interesting, that if you render replay with Wesnoth-client, there would be your local time.

Q: Could you know for sure from replay who was winner?
A: There currently is nothing recorded about who won or lost. The issue is that while it would be possible to determine the winner in the case of a leader death (in regular scenarios) or if a side surrendered, there's no way to determine a winner (ie in case of a rage quit) or if a winner even needs to be determined (ie in case of a game being saved in order to be continued later). (Pentarctagon, Wesnoth forums)

API

REQUEST

POST to path /url with JSON payload:

{
  "urlFileForParsing": "https://replays.wesnoth.org/1.14/2021/04/30/2p__Swamp_of_Dread_Turn_10_(31797).bz2"
}

RESPONSE

JSON would be like this:

{
  "errorInRequest": null or string,
  "answer": {
    "errorWhileParsing": null or string,
    "meta": null or {},
    "gameSettings": null or {
      "addons": null or [{}],
      "settings": null or {},
      "turns": null or integer
    },
    "sides": null or [{}],
    "chat": null or [{}],
    "mTime": null or integer
  }
}

Example for cURL:

APP_URL="https://wespar.onrender.com"
ENDPOINT="/url"

curl --header "Content-Type: application/json" \
     --request POST \
     --data '{"urlFileForParsing":"https://replays.wesnoth.org/1.14/2021/03/22/2p__Weldyn_Channel_Turn_14_(155976).bz2"}' \
     $APP_URL$ENDPOINT

Installing

For GNU/Linux:

git clone https://github.com/amokmen/wespar/
cd wespar
npm install
npx husky install
npm run start

Starting point for back-end is ./index.js and config is at ./config.js.

ENV variables that app could use: PORT (web-server listening port number), LOG_LEVEL and LOG_LEVEL_FASTIFY (trace, debug, info, warn, error, fatal, silent).

Afterword

This is a hobby/learning project and I want to develop it in my way. I could make life a bit easier for me if use official Wesnoth WML parser for creating JSON from WML. But I intentionally decided to not do this.

It was rather painful experience trying to research and understand Wesnoth replay file structure. More words and pictures are here, including monstrous algorithm of parsing.

And remember:
One Does Not Simply Parse Wesnoth Replay

P. S. I spent more than 2 month for active developing this app (including time for tooling).

Software Disclaimer

  • This software is provided "as is," and you use the software at your own risk.
  • There are no any warranties.

Donation (sponsorship) Disclaimer

  • All donations are non-refundable.
  • Therefore, donors explicitly release recipient from any restrictions on how those funds are spent.
  • No goods or services were provided in return for any contribution.

Links

  1. Original Wesnoth WML parser - could be used to convert replay files to JSON or XML.
  2. Original Wesnoth WML indent utility - could be used to indent WML files for easy understanding inner structure.
  3. Meme generator.
  4. Cool service for showing key codes, including mobile devices.
  5. Great free app for online creating diagrams - Draw.io

UI screenshots

Before work:

GPL3 Logo

After work:

GPL3 Logo