Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/local-profile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ jobs:
- run: php tests/local/controls.php
- run: php tests/local/gaia-host.php vendor/autoload.php
- run: php tests/local/shard-region.php vendor/autoload.php
- run: php tests/local/tdm-group-configuration.php
- run: php tests/local/systemd-unit.php vendor/autoload.php
- run: php tests/local/server-compatibility.php vendor/autoload.php
timeout-minutes: 2
Expand Down
50 changes: 8 additions & 42 deletions bot.php
Original file line number Diff line number Diff line change
Expand Up @@ -446,48 +446,14 @@ function loadEnv(string $filePath, bool $explicit = false): array
'attack' => '1139614643954921593',
],
];
// Sharded TDM (docs/shard-group.md): the always-on Barracks world (region "barracks", port 1714) and the battle
// world (region "battle", port 1715) of Civ13 shard group "tdm", both driven by shard_group.py. Until the group's
// config exists the single civ13-tdm.service server above stays in use, so this file can ship before the move.
$tdm_group = '/home/civ13/tdm.json';
if (is_file($tdm_group)) {
// The script lives in the group's own Civ13 checkout ("repository" in tdm.json), which the host keeps current.
$tdm_repository = json_decode((string) file_get_contents($tdm_group), true)['repository'] ?? null;
$tdm_script = is_string($tdm_repository) && $tdm_repository !== '' ? rtrim($tdm_repository, '/').'/scripts/shard-group/shard_group.py' : '';
$tdm_shard_group = static fn (string $region): array => [
'enabled' => true,
'python' => '/usr/bin/python3',
'script' => $tdm_script, // empty or missing: host controls refuse with the reason
'config' => $tdm_group,
'region' => $region,
'kill' => 'stop', // save if the world saves, then stop; 'kill' forces it down without saving
];
unset($civ13_server_settings['tdm']['systemd']);
// "tdm" is the group's front door, the world on port 1714 that posts to /webhook/tdm: the Barracks, or the
// gateway once `shard_group.py set-gate` puts one in front. Follow it like a portable profile's
// follow_front_door (basedir, and the shared front-door/SQL/admins.txt), so a gate move needs only a bot
// restart. An unreadable group file or a front door that is not set up keeps the Barracks.
$tdm_front = \Civ13\PortableProfile::followFrontDoor(['region_group' => $tdm_group, 'basedir' => '/home/civ13/tdm/barracks']);
$civ13_server_settings['tdm']['basedir'] = $tdm_front['basedir'];
if (isset($tdm_front['admin_file'])) {
$civ13_server_settings['tdm']['admin_file'] = $tdm_front['admin_file'];
}
$civ13_server_settings['tdm']['shard_group'] = $tdm_shard_group(basename($tdm_front['basedir']));
$civ13_server_settings['tdm']['region_group'] = $tdm_group; // the player-count channel counts every region
// Battle posts to /webhook/tdmbattle and shares the TDM channels. It never renames the player-count channel
// (the front door counts it) but keeps its own round embed there; Discord OOC goes to the front door only,
// which shares it with the other worlds in game (Civ13 region OOC).
$civ13_server_settings['tdmbattle'] = array_merge($civ13_server_settings['tdm'], [
'supported' => false, // hidden from the hub
'name' => 'TDM Battle',
'port' => '1715',
'basedir' => '/home/civ13/tdm/battle',
'shard_group' => $tdm_shard_group('battle'),
'shard_of' => 'tdm',
]);
// Battle keeps the inherited TDM Play link, so its round embed in the TDM channel enters through the front door
// too; the aggregate status skips shards (shard_of), so it still shows one TDM button.
unset($civ13_server_settings['tdmbattle']['region_group']);
// Use one validated snapshot for the official front door and Battle. A configured
// group that cannot be read must never put the old single-world service back in use.
try {
$civ13_server_settings = array_replace($civ13_server_settings,
\Civ13\Local\TdmGroupConfiguration::profiles('/home/civ13/tdm.json', $civ13_server_settings['tdm']));
} catch (\UnexpectedValueException $error) {
unset($civ13_server_settings['tdm'], $civ13_server_settings['tdmbattle']);
$logger->error('TDM integrations disabled: '.$error->getMessage());
}
foreach ($civ13_server_settings as $key => $value) {
$civ13_server_settings[$key]['key'] = $key;
Expand Down
2 changes: 2 additions & 0 deletions docs/local-profile.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ The local endpoint permits only authenticated `GET /v1/verification-replica`, ma

## Supervision and remaining limits

Bot code, dependency updates and bot restarts belong to the installation operator, not Discord or the bot's HTTP server. Deploy a reviewed revision and run `composer install` from its lockfile in the operator's deployment procedure; then manage the bot process using the installation's service supervisor. The staff dashboard no longer offers Git or Composer actions. Stale `/pull` and `/update` interactions and the old `updatedeps` and `stop` text commands do not execute anything. The old maintenance HTTP routes return `410 Gone` to admitted callers (`/githubupdated` still rejects missing or invalid signatures); remove update webhooks targeting that route. `ts` no longer manages the TypeSpess process; use the TypeSpess host's operator procedure. These changes do not retire game-server controls.

Legacy restart remains the default. Explicit `restart_mode:supervised` stops the current bot gracefully and leaves replacement to its supervisor; it never self-spawns PHP. Repeated requests stop once, and selecting another entry point is rejected. Games need independently supervised fixed units/scopes and narrowly reviewed helper permissions. A bot unit using KillMode=control-group can kill game descendants launched by legacy PHP. Nohup/disown do not detach cgroups. KillMode=process leaves child ownership/orphan risks and requires a separate reviewed compatibility decision.

Replica publication uses a private lock, staged file flush/fsync and same-directory rename. Tests cover process interruption before publication and lock exclusion. They do not prove power-loss directory fsync ordering, hostile-owner filesystem races, production exporter consistency, multiweek freshness or actual guild permissions. No official cutover or live activation is included.
48 changes: 40 additions & 8 deletions docs/shard-group.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,37 @@ own worktree with its own port, `serverdata.txt`, IPC files and webhooks (see
Civ13's `scripts/shard-group/README.md`). The bot treats each region as a normal
game server entry and drives it with `scripts/shard-group/shard_group.py`.

civ13.com's TDM is the first such group: shard group `tdm` with the always-on
**Barracks** (region `barracks`, port 1714, server key `tdm`) and the **battle**
world (region `battle`, port 1715, server key `tdmbattle`). `bot.php` switches
to it by itself once `/home/civ13/tdm.json` exists; until then the single
`civ13-tdm.service` server stays in use.
For civ13.com's TDM, `bot.php` reads one validated `/home/civ13/tdm.json`
snapshot. The `tdm` entry follows the configured front door (Barracks or
gateway), and `tdmbattle` follows the configured Battle region. Each uses its
actual region directory and port. Battle keeps the public TDM Play link and
does not produce another aggregate Play button. A genuinely absent group file
keeps legacy single-world status only; an invalid configured file disables
the TDM integrations rather than falling back to the wrong service.

The official TDM aliases are **status-only for lifecycle management**.
`tdmrestart` previously acted on the front door, including the gateway.
`tdmbattlerestart` only acted on Battle. The old host, kill, restart, update,
and map-swap handlers now refuse for these entries across text, slash, and
panel surfaces. Use the maintainer runbook, not a Discord alias.

### TDM operator checks

1. Fast-forward the configured shared TDM source checkout, and reload the
`civ13-tdm-host` service. This refreshes the coordinator, not the separate
running world processes.
2. Use the coordinator's group `restart` **without a region argument**.
Expect all intended non-gateway regions under `accepted`. When a gateway
exists, the coordinator deliberately lists it under `refused` with the
reason that it stays on its port. Treat any other refusal as a failure,
even when the aggregate reply says `ok`.
3. Check the worlds and hub listing after they finish. An accepted operation
is queued, not proof they are ready. Restart the gateway by name only
when deliberately updating the front door.

The bot itself is updated by fast-forwarding its own checkout and restarting
the operator-managed `civilizationbot` unit. The bot no longer runs these
updates or restarts through its retired maintenance commands.

## Host controls

Expand All @@ -36,8 +62,8 @@ DreamDaemon itself.
| Discord | shard_group.py |
| --- | --- |
| `<key>host`, panel Host | `start --region=<id>` |
| `<key>kill`, panel Kill | `stop --region=<id>` (or `kill`, see above), announced in OOC first |
| `<key>restart`, panel Restart, `/restart_server` | `restart --region=<id>`, announced in OOC first |
| `<key>kill`, panel Kill | `stop --region=<id>` (or `kill`, see above) |
| `<key>restart`, panel Restart, `/restart_server` | `restart --region=<id>` |
| `<key>update` | `update --region=<id>` |
| `<key>hoststatus` | `status --region=<id>`: region name, port, world ready, players, last action, map |
| `<key>activity` (Ambassador, Admin) | none: reads `<group root>/player-activity-weekly.json` from the server's `region_group` |
Expand All @@ -57,7 +83,13 @@ per ckey whenever that ckey's karma changes; the bot never opens its database.
start, stop, restart and update are accepted within seconds and finish in the
script's detached worker; `hoststatus` shows progress. The bot runs as the same
user as the group (`civ13`), so no sudo is involved. Roles are the same as for
[gaia_host](gaia-host.md).
[gaia_host](gaia-host.md). A frozen region may accept an update as build staging;
its running version has not changed. The table describes explicitly managed
non-TDM entries that have not retired their legacy aliases.

Awards belong to the world that writes them. Do not use an empty awards file
on the gateway as a substitute for the awarding world. Missing awards now
leave the ranking unchanged rather than creating a placeholder or wiping it.

## Following the front door (`follow_front_door`)

Expand Down
Loading
Loading