Skip to content

Commit

Permalink
Add Valheim
Browse files Browse the repository at this point in the history
  • Loading branch information
Nebual committed Feb 11, 2021
1 parent e6b2e5c commit f8bdcb7
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 6 deletions.
7 changes: 7 additions & 0 deletions game-api/src/games/common-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -214,6 +220,7 @@ module.exports = {
dockerComposeStart,
dockerComposeStop,
dockerComposeBuild,
dockerComposePull,
dockerIsProcessRunning,
dockerLogs,
dockerLogRead,
Expand Down
21 changes: 15 additions & 6 deletions game-api/src/games/docker.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const {
dockerComposeStart,
dockerComposeStop,
dockerComposeBuild,
dockerComposePull,
dockerIsProcessRunning,
dockerLogRead,
rconSRCDSConnect,
Expand Down Expand Up @@ -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);
});
});
}
};
48 changes: 48 additions & 0 deletions game-api/src/games/valheim.js
Original file line number Diff line number Diff line change
@@ -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"];
}
};
18 changes: 18 additions & 0 deletions game-setups/valheim/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f8bdcb7

Please sign in to comment.