From 519e1946cad3484653cafe771188a61a0130ba2a Mon Sep 17 00:00:00 2001 From: fanyx Date: Sat, 24 Dec 2022 13:40:42 +0100 Subject: [PATCH] Changes to custom playlist parsing Disable custom playlists by default Guide on how to enable persistent playlist.xml usage --- .env-example | 2 ++ README.md | 34 ++++++++++++++++++++++++++++++++++ docker-compose.yml | 2 +- tmserver/bin/eval_playlist.sh | 12 ++++++++---- 4 files changed, 45 insertions(+), 5 deletions(-) diff --git a/.env-example b/.env-example index 29811cd..20c0a81 100644 --- a/.env-example +++ b/.env-example @@ -34,6 +34,8 @@ CUP_ROUNDSPERCHALLENGE=5 CUP_NBWINNERS=3 CUP_WARMUPDURATION=2 +CUSTOM_PLAYLIST= + # XASECO MASTERADMIN_LOGIN= diff --git a/README.md b/README.md index 242a17e..c8765b6 100644 --- a/README.md +++ b/README.md @@ -135,6 +135,7 @@ in the `tracks/` folder and mounting it to `/var/lib/tmserver/GameData/Tracks/Cu You can add tracks to a playlist in a simple way. Create a plaintext file like in the example below and mount it to `/var/lib/tmserver/playlist.txt`. +To enable parsing of this file set `CUSTOM_PLAYLIST` in your env-file to anything but an empty string. The tracks for the server are stored relative to `/var/lib/tmserver/GameData/Tracks`. Creating your own playlist is as easy as specifying each track on a separate line in the `playlist.txt` @@ -158,6 +159,39 @@ Custom/mini01.Challenge.Gbx Custom/SpeedxZxZ.Challenge.Gbx ``` +--- +**NOTE** + +When mounting your own `playlist.xml` file to the container you overwrite a lot of +customization options that usually would be parsed from environment variables. + +```xml + + @GAMEMODE@ + @CHATTIME@ + @FINISHTIMEOUT@ + @DISABLERESPAWN@ + @ROUNDS_POINTSLIMIT@ + @TEAM_POINTSLIMIT@ + @TEAM_MAXPOINTS@ + @TIMEATTACK_LIMIT@ + 0 + @LAPS_NBLAPS@ + @LAPS_TIMELIMIT@ + @CUP_POINTSLIMIT@ + @CUP_ROUNDSPERCHALLENGE@ + @CUP_NBWINNERS@ + @CUP_WARMUPDURATION@ + +``` + +If you're familiar with these options anyway, you can mount `playlist.xml` to +`/var/lib/tmserver/GameData/MatchSettings/playlist.xml` and use it as a complete +and persistent configuration file that can be written to by plugins or external tools +like RemoteCP. + +--- + ### Custom configuration files Most plugins need you to provide valid configuration files to function in the first place. diff --git a/docker-compose.yml b/docker-compose.yml index 14976df..e6ba974 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ version: '3.8' services: tmserver: - image: fanyx/tmserver:2.1.0 + image: fanyx/tmserver:2.1.1 container_name: trackmania_tmserver depends_on: - db diff --git a/tmserver/bin/eval_playlist.sh b/tmserver/bin/eval_playlist.sh index 181eff6..d288e4f 100755 --- a/tmserver/bin/eval_playlist.sh +++ b/tmserver/bin/eval_playlist.sh @@ -2,19 +2,23 @@ echo "INFO | Parsing custom playlist..." -CUSTOM_PLAYLIST=${CUSTOM_PLAYLIST:-playlist.txt} +[[ -z "${CUSTOM_PLAYLIST}" ]] && \ + echo "INFO | Custom Playlist is not enabled, keeping default or user-edited playlist" && \ + exit 0 + +PLAYLIST_PATH=${PLAYLIST_PATH:-playlist.txt} PLAYLIST_FILE='GameData/Tracks/MatchSettings/playlist.xml' -if [[ -f "${CUSTOM_PLAYLIST}" ]]; then +if [[ -f "${PLAYLIST_PATH}" ]]; then count=1 while read l; do xmlstarlet ed -L -s /playlist -t elem -n challenge $PLAYLIST_FILE xmlstarlet ed -L -s "/playlist/challenge[${count}]" -t elem -n file -v "${l}" $PLAYLIST_FILE count=$((count+1)) - done < $CUSTOM_PLAYLIST + done < $PLAYLIST_PATH else xmlstarlet ed -L -s /playlist -t elem -n challenge $PLAYLIST_FILE xmlstarlet ed -L -s "playlist/challenge[1]" -t elem -n file -v "Challenges/Nadeo/A01-Race.Challenge.Gbx" $PLAYLIST_FILE fi -echo "INFO | Finished parsing playlist files." +echo "INFO | Finished parsing playlist files"