Files
WhoDidIt/tools/Publish-RaidTimes.ps1
T
bdot1andClaude Opus 5.5 fd438ebe37 v1.24.4: 5-man runs published only with every member's names agreed (review T1, option b)
The maintainer chose option (b): publish only runs whose members all
share their runs, and name only members who have WhoDidIt.

What counts as "shares" can't come from a message's say-so (anyone can
make up a group with real names, B18). It's what this PC saw itself:
- rec.ok lists the members seen sharing the group's runs: their own WDI5
  vote with sharing on, or the run sent by them on the realm channel
  (the server says who sent it). A better run of the same group keeps the
  names already seen. Runs from the download count all their members,
  since only such runs are published.
- Once the sharer has named a run, every member with sharing on sends it
  too, not only the sharer, so the maintainer's WhoDidIt can hear each of
  them.
- The master's runs file gets a 12th field, ok.
- Publish-RaidTimes takes an R5 line only when every member is in ok
  (case-sensitive), and writes the old 11 fields so every client reads
  them. It says how many it left out.
- Website-Export (format 3): a member has a name only if in ok, the
  others are only a class. An older 11-field line names nobody.
- README (5-man download, maintainer publish, website, privacy), the
  in-game Website panel, Dungeons.lua comments and CLAUDE.md say so.

Tested offline (LuaJIT, stubbed game API):
- A five-player BRD run where we lead and Bob and Carl vote gives
  ok = Upsilon,Bob,Carl. Dina's copy from the channel adds Dina, and a
  stranger's copy is refused.
- A better run from Eve keeps all five names.
- A made-up group from "Liar" that uses Bob and Carl gets ok = Liar only.
- A seeded run gets all its members, and the runs file has 12 fields.
- Scratch copies of both scripts: only the two fully seen groups were
  published, as 11 fields. The made-up, partly seen, case-trick and old
  lines were left out. The website named only members in ok.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 08:17:50 +01:00

120 lines
6.9 KiB
PowerShell
Vendored

<#
Publish-RaidTimes - for the WhoDidIt maintainer: puts every guild's raid
times into the download, so a fresh install shows full Rankings at once
(even while the master is offline) and the master feed only has to send
what's newer.
It reads the sync helper's file (CustomData\WhoDidIt_Chronicle.txt),
keeps the guilds' kill and clear times (C / K, and C2 / K2 since the raid
scaling change) and the raid details (L), leaves out your own characters'
personal bests (PC / PK), adds the 5-man runs your WhoDidIt saved
(CustomData\WhoDidIt_Runs.txt, R5 lines) whose members were all seen
sharing them (a run lists its members by name, and this file goes into the
public repository), writes RaidTimes.lua and commits and pushes it.
Needs git with push access to the repository.
Run it now and then (weekly is plenty): the older the snapshot, the more
the feed has to send a fresh install.
Publish-RaidTimes.ps1 write, commit and push
Publish-RaidTimes.ps1 -NoPush only write RaidTimes.lua
Publish-RaidTimes.ps1 -Force publish even if it looks much smaller
Publish-RaidTimes.ps1 -Auto (the sync helper, weekly) skip unless main has nothing
unpushed of yours - it never pushes your own commits
#>
param([switch]$NoPush, [switch]$Force, [switch]$Auto)
$ErrorActionPreference = "Stop"
$repo = (Resolve-Path (Join-Path $PSScriptRoot "..")).Path
$wow = (Resolve-Path (Join-Path $PSScriptRoot "..\..\..\..")).Path
$src = Join-Path $wow "CustomData\WhoDidIt_Chronicle.txt"
$dst = Join-Path $repo "RaidTimes.lua"
if (-not (Test-Path -LiteralPath $src)) {
Write-Host "Nothing to publish: the sync helper hasn't written $src yet."
return
}
$lines = ([IO.File]::ReadAllText($src) -replace "`r`n", "`n") -split "`n"
$head = $lines[0] -split '\|'
if ($head[0] -ne "WDICHRON" -or $head[5] -ne "ok") { throw "The helper's file isn't a finished sync (header: $($lines[0])) - try again after its next sync." }
$synced = [long]$head[2]
$server = $head[3]
# only these kinds of line, and each one plain text (it goes inside a Lua [[ ]] string)
$keep = New-Object System.Collections.Generic.List[string]
$counts = @{}
foreach ($l in $lines) {
$t = ($l -split '\|')[0]
if ($t -notin "C", "K", "C2", "K2", "L") { continue }
if ($l -match '\[\[|\]\]|[\x00-\x08\x0b-\x1f]') { throw "A line can't be stored safely, not publishing: $l" }
$keep.Add($l)
$counts[$t] = 1 + [int]$counts[$t]
}
# 5-man runs, only where every member is named with their consent: your WhoDidIt writes
# R5|realm|key|group|secs|date|deaths|faction|members|splits|named|ok
# where ok lists the members it saw share the run themselves (their own vote, or the run
# sent by them on the realm channel: they have WhoDidIt with sharing on). A run with
# anyone else in it (a player without WhoDidIt can't say yes) stays out, and so does an
# older line without ok. Published as the first 11 fields, as WhoDidIt reads them.
$runsFile = Join-Path $wow "CustomData\WhoDidIt_Runs.txt"
if (Test-Path -LiteralPath $runsFile) {
foreach ($l in (([IO.File]::ReadAllText($runsFile) -replace "`r`n", "`n") -split "`n")) {
$p = $l -split '\|'
if ($p[0] -ne "R5" -or $p.Count -ne 12) { continue }
if ($l -match '\[\[|\]\]|[\x00-\x1f]' -or $p[4] -notmatch '^\d+$' -or $p[5] -notmatch '^\d+$') { continue } # (WhoDidIt checks the rest when it loads them)
$ok = @($p[11] -split ',' | Where-Object { $_ -ne "" })
$names = @($p[8] -split ',' | ForEach-Object { ($_ -split ':')[0] } | Where-Object { $_ -ne "" })
if ($names.Count -eq 0) { continue }
$all = $true
foreach ($n in $names) { if ($ok -cnotcontains $n) { $all = $false; break } }
if (-not $all) { $counts["R5 left out"] = 1 + [int]$counts["R5 left out"]; continue }
$keep.Add(($p[0..10] -join '|'))
$counts["R5"] = 1 + [int]$counts["R5"]
}
}
$times = [int]$counts["C"] + [int]$counts["K"]
$now = 0
if (Test-Path -LiteralPath $dst) {
$now = ([regex]::Matches([IO.File]::ReadAllText($dst), '(?m)^[CK]\|')).Count
}
if (-not $Force -and ($times -lt 100 -or $times -lt [math]::Floor($now / 2))) {
throw "Only $times guild times (published now: $now). That looks wrong, so it isn't published. -Force publishes it anyway."
}
$when = [DateTimeOffset]::FromUnixTimeSeconds($synced).ToString("yyyy-MM-dd HH:mm") + " UTC"
$o = New-Object System.Text.StringBuilder
[void]$o.AppendLine("-- Every guild's raid times, as of the WhoDidIt maintainer's sync of $when, so a")
[void]$o.AppendLine("-- fresh install shows full Rankings at once; the master feed sends what's newer.")
[void]$o.AppendLine("-- From Chronicle's public API (chronicleclassic.com). Generated by tools\Publish-RaidTimes.ps1 - do not edit.")
[void]$o.AppendLine("-- C / K: a guild's best clear / kill; C2 / K2: the same since the 6 Oct raid scaling change; L: a raid's bosses;")
[void]$o.AppendLine("-- R5: a 5-man group's best run, only for groups whose members all share their runs with WhoDidIt.")
[void]$o.AppendLine("WDI_RAIDTIMES = { synced = $synced, server = `"$server`", text = [[")
foreach ($l in $keep) { [void]$o.AppendLine($l) }
[void]$o.AppendLine("]] }")
[IO.File]::WriteAllText($dst, $o.ToString(), (New-Object Text.UTF8Encoding($false)))
Write-Host ("RaidTimes.lua: {0} clears, {1} kills, {2} / {3} since the scaling change, {4} raid details, {5} 5-man runs ({6} left out: not every member seen sharing), synced {7} ({8:N0} KB)." -f `
[int]$counts["C"], [int]$counts["K"], [int]$counts["C2"], [int]$counts["K2"], [int]$counts["L"], [int]$counts["R5"], [int]$counts["R5 left out"], $when, ((Get-Item $dst).Length / 1KB))
if ($NoPush) { return }
Push-Location $repo
$ErrorActionPreference = "Continue" # git prints line-ending warnings on stderr
try {
$branch = (git rev-parse --abbrev-ref HEAD 2>$null)
if ($branch -ne "main") { throw "The repository is on '$branch', not main - switch to main first." }
if ($Auto) {
git fetch -q origin main 2>$null
$ahead = [int](git rev-list --count origin/main..HEAD 2>$null)
if ($ahead -gt 0) { Write-Host "Skipped: main has $ahead commit(s) of yours not pushed yet, and this would push them. Next try in a day."; return }
}
git pull -q --rebase --autostash origin main 2>$null
if ($LASTEXITCODE -ne 0) { throw "git pull failed - fix that first (nothing was committed)" }
git add RaidTimes.lua 2>$null
git diff --cached --quiet -- RaidTimes.lua
if ($LASTEXITCODE -eq 0) { Write-Host "No change since the last publish."; return }
git commit -q -m "Raid times snapshot ($when)" -- RaidTimes.lua 2>$null
if ($LASTEXITCODE -ne 0) { throw "git commit failed" }
git push -q origin main 2>$null
if ($LASTEXITCODE -ne 0) { throw "git push failed - check you can push to the repository" }
Write-Host "Published: a fresh install of WhoDidIt now starts with these raid times."
} finally {
Pop-Location
}