diff --git a/game-api/src/games/common-helpers.js b/game-api/src/games/common-helpers.js index 1253d50..5b60a19 100644 --- a/game-api/src/games/common-helpers.js +++ b/game-api/src/games/common-helpers.js @@ -23,6 +23,12 @@ function dockerComposeStart() { function dockerComposeStop() { compose.down({ dir: gameDir }); } +function dockerComposePull(params) { + return compose.pullAll({ + dir: gameDir, + ...params, + }); +} function dockerComposeBuild(params) { return compose.buildOne(game, { dir: gameDir, @@ -214,6 +220,7 @@ module.exports = { dockerComposeStart, dockerComposeStop, dockerComposeBuild, + dockerComposePull, dockerIsProcessRunning, dockerLogs, dockerLogRead, diff --git a/game-api/src/games/docker.js b/game-api/src/games/docker.js index 33817fb..acd31e5 100644 --- a/game-api/src/games/docker.js +++ b/game-api/src/games/docker.js @@ -6,6 +6,7 @@ const { dockerComposeStart, dockerComposeStop, dockerComposeBuild, + dockerComposePull, dockerIsProcessRunning, dockerLogRead, rconSRCDSConnect, @@ -63,16 +64,24 @@ module.exports = class GenericDockerManager { return false; } } - update() { - dockerComposeBuild({ - commandOptions: [["--build-arg", `TRIGGER_UPDATE=${Date.now()}`]], - }) + async update() { + dockerComposePull() .then(res => { - console.log("finished update: ", res); + console.log("finished docker pull: ", res); this.setStatus("stopped"); }) .catch(e => { - console.error("update error: ", e); + console.log("docker pull failed:", e, ", attempting build:"); + dockerComposeBuild({ + commandOptions: [["--build-arg", `TRIGGER_UPDATE=${Date.now()}`]], + }) + .then(res => { + console.log("finished update: ", res); + this.setStatus("stopped"); + }) + .catch(e => { + console.error("update error: ", e); + }); }); } }; diff --git a/game-api/src/games/valheim.js b/game-api/src/games/valheim.js new file mode 100644 index 0000000..f7687d9 --- /dev/null +++ b/game-api/src/games/valheim.js @@ -0,0 +1,48 @@ +const stripAnsi = require("strip-ansi"); +const Gamedig = require("gamedig"); +const compose = require("docker-compose"); + +const { game, gameId, debugLog, connectUrl, rconPort } = require("../cliArgs"); +const { dockerComposeStop, dockerComposePull } = require("./common-helpers"); +const GenericDockerManager = require("./docker"); + +module.exports = class ValheimManager extends GenericDockerManager { + getConnectUrl() { + return `steam://connect/${connectUrl} (though use Steam Server browser)`; + } + stop() { + // just docker-compose stop doesn't seem to shutdown cleanly (saving)... + compose + .exec(game, "bash -c 'cd /home/steam/valheim && ~steam/.odin/odin/stop") + .then(() => { + dockerComposeStop(); + }); + } + async getPlayerCount() { + try { + const response = await Gamedig.query({ + type: "css", // Gamedig lacks Valheim but css is compatible + host: `localhost`, + port: rconPort, + socketTimeout: 3000, + }); + return response.players.length; + } catch (err) { + debugLog(`getPlayerCount err: ${err}`); + return false; + } + } + async update() { + dockerComposePull() + .then(res => { + console.log("finished docker pull: ", res); + this.setStatus("stopped"); + }) + .catch(e => { + console.log("docker pull failed:", e); + }); + } + async filesToBackup() { + return ["saves"]; + } +}; diff --git a/game-setups/valheim/docker-compose.yml b/game-setups/valheim/docker-compose.yml new file mode 100644 index 0000000..2ffd2bb --- /dev/null +++ b/game-setups/valheim/docker-compose.yml @@ -0,0 +1,18 @@ +version: "3" +services: + valheim: + container_name: valheim + image: mbround18/valheim:latest + environment: + - PORT=2456 + - NAME="Nebtown Yngheim" + - PASSWORD="1234" + - TZ=America/Vancouver + - WORLD=Yngheim + ports: + - "2456:2456/udp" + - "2457:2457/udp" + - "2458:2458/udp" + volumes: + - ./saves:/home/steam/.config/unity3d/IronGate/Valheim + - ./server:/home/steam/valheim \ No newline at end of file