initial version

This commit is contained in:
2026-10-29 21:13:01 +01:00
parent a076b082b8
commit 5532211785
10 changed files with 613 additions and 0 deletions
+18
View File
@@ -0,0 +1,18 @@
#!/bin/sh
# Container entrypoint.
#
# The backend talks to game servers through the address that is advertised to
# browsers (servers.<key>.address, e.g. localhost:7192). Inside the backend
# container "localhost" is the container itself, not the game container, so
# with AL_GAME_RELAY=1 a small TCP forwarder publishes the game port on
# 127.0.0.1 for the backend only.
set -eu
if [ "${AL_GAME_RELAY:-0}" = "1" ]; then
GAME_HOST="${AL_GAME_HOST:-al-game}"
GAME_PORT="${AL_GAME_PORT:-7192}"
echo "Relaying 127.0.0.1:${GAME_PORT} -> ${GAME_HOST}:${GAME_PORT}"
socat "TCP-LISTEN:${GAME_PORT},fork,reuseaddr,bind=127.0.0.1" "TCP:${GAME_HOST}:${GAME_PORT}" &
fi
exec "$@"
+28
View File
@@ -0,0 +1,28 @@
#!/bin/bash
# Initiates the single-node replica set "rs0" if it does not exist yet and
# waits until the member is primary. Runs as a one-shot container.
set -euo pipefail
HOST="${MONGO_HOST:-al-mongo}"
PORT="${MONGO_PORT:-27017}"
echo "Waiting for MongoDB at ${HOST}:${PORT} ..."
until mongosh --host "${HOST}" --port "${PORT}" --quiet \
--eval 'db.adminCommand({ ping: 1 }).ok' >/dev/null 2>&1; do
sleep 2
done
if [ "$(mongosh --host "${HOST}" --port "${PORT}" --quiet \
--eval 'try { rs.status().ok } catch (e) { 0 }')" != "1" ]; then
echo "Initiating replica set rs0 ..."
mongosh --host "${HOST}" --port "${PORT}" --quiet \
--eval 'rs.initiate({ _id: "rs0", members: [{ _id: 0, host: "al-mongo:27017" }] })'
fi
echo "Waiting for primary ..."
until mongosh --host "${HOST}" --port "${PORT}" --quiet \
--eval 'db.hello().isWritablePrimary' | grep -q true; do
sleep 2
done
echo "Replica set rs0 is ready."
+39
View File
@@ -0,0 +1,39 @@
#!/usr/bin/env node
// Local patch for the Adventure Land game server (applied at image build time).
//
// The upstream DRM check in node/server.js (start_character) treats every
// account created after 2019-02-01 as unverified unless it carries a Steam or
// Mac App Store auth id. A self-hosted server cannot issue those ids (Steam
// tickets need the game's private publisher key, and Steam OpenID sign-in needs
// a publisher web API key), so every login gets the "authfail" condition:
// gold/luck -85%, xp -20%.
//
// AL_DRM_CHECK=0 disables the check. Unset or any other value keeps the
// upstream behaviour. The script fails loudly when the upstream line is gone,
// so a code update cannot silently skip the patch.
const fs = require("node:fs");
const file = process.argv[2] || "/app/node/server.js";
const original =
'if (owner.created > new Date(2019, 1, 1) && !gf(owner, "legacy_override")) drm = true;';
const patched =
'if (process.env.AL_DRM_CHECK !== "0" && owner.created > new Date(2019, 1, 1) && !gf(owner, "legacy_override")) drm = true;';
const source = fs.readFileSync(file, "utf8");
if (source.includes(patched)) {
console.log("patch-drm-check: already applied");
process.exit(0);
}
if (source.split(original).length !== 2) {
console.error(
"patch-drm-check: expected exactly one occurrence of the upstream DRM check in " + file,
);
process.exit(1);
}
fs.writeFileSync(file, source.replace(original, patched));
console.log("patch-drm-check: applied to " + file);
Executable
+36
View File
@@ -0,0 +1,36 @@
#!/bin/sh
# Seeds the bundled map geometry into MongoDB.
#
# scripts/seed_mongodb.js only touches a database that has no collections and
# refuses a second run, so this wrapper checks first and skips the import on an
# already seeded volume.
set -eu
cd /app
: "${MONGODB_URI:?MONGODB_URI is not set}"
DB_NAME="${MONGODB_NAME:-adventureland}"
existing=$(node -e '
const { MongoClient } = require("mongodb");
const uri = process.env.MONGODB_URI;
const name = process.env.MONGODB_NAME || "adventureland";
(async () => {
const client = new MongoClient(uri, { serverSelectionTimeoutMS: 15000 });
await client.connect();
const collections = await client.db(name).listCollections({}, { nameOnly: true }).toArray();
await client.close();
process.stdout.write(String(collections.length));
})().catch((error) => {
console.error("MongoDB check failed:", error.message);
process.exit(1);
});
')
if [ "${existing}" -gt 0 ]; then
echo "Database '${DB_NAME}' already has ${existing} collection(s) - skipping seed."
exit 0
fi
echo "Database '${DB_NAME}' is empty - importing map data ..."
exec node scripts/seed_mongodb.js --confirm "${DB_NAME}"