Merge control portal work from RPGTheory/aeternalis-portal
RPGTheory/aeternalis-portal had diverged from this repo (the git/CI/CD copy) with an in-progress control portal feature that was never synced back here, so none of it had gone through CI or been deployed: - New site/game/control routing split: index.html becomes a world directory landing page (site.ts), game.html is the renamed former index.html (main.ts), control.html is a new admin panel (control.ts, portal-shared.ts, portal.css). - Server: new internal/store/portal.go (character/world registry, command queue, admin grants) and internal/transport/control.go (portal API routes), plus a new internal/gitops package that lets the portal provision new worlds via a GitOps repo commit. - game.World gains BornAt/DiedAt/DeathReason and an operator Control() path (close/open admissions, awaken boss, end world, per-character rename/heal/unstuck/retire); death no longer reuses the same character id on rejoin, matching the "new life" permadeath model in Plan.md rather than the old bypass-prevention test's expectations. - deploy/: new control-egress network policy and portal/control values (admin role, GitOps repo/branch/values file/CIDRs). - New e2e coverage: tests/portal.spec.ts, tools/capture-world.mjs. Verified this repo's own independent commits (800ms movement-staleness window, 20s boss-attack poll, SRS/TLS deploy values, ubuntu-22.04 runner pin, DOCKER_HOST fix) were already present in the portal copy before merging, so nothing here regresses them. `tsc --noEmit`, the vite client build, and the protocol contract check all pass; no go.mod changes. Could not run `go build`/`go test` locally (no Go toolchain on PATH, Docker daemon not running) — every new/changed Go symbol was manually cross-referenced and resolves, but this should still be built and tested in CI before merging to master. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -27,6 +27,9 @@ type Character struct {
|
||||
MoveZ float64 `json:"-"`
|
||||
LastMove time.Time `json:"-"`
|
||||
Message string `json:"-"`
|
||||
BornAt time.Time `json:"bornAt"`
|
||||
DiedAt *time.Time `json:"diedAt,omitempty"`
|
||||
DeathReason string `json:"deathReason,omitempty"`
|
||||
}
|
||||
type Corpse struct {
|
||||
Entity p.Entity `json:"entity"`
|
||||
@@ -40,24 +43,25 @@ type Mob struct {
|
||||
RespawnAt float64 `json:"respawnAt"`
|
||||
}
|
||||
type World struct {
|
||||
Version int `json:"version"`
|
||||
ID string `json:"id"`
|
||||
Seed int64 `json:"seed"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
EndedAt *time.Time `json:"endedAt,omitempty"`
|
||||
Phase string `json:"phase"`
|
||||
Tick int64 `json:"tick"`
|
||||
BossHP float64 `json:"bossHp"`
|
||||
BossLastAttack float64 `json:"bossLastAttack"`
|
||||
Characters map[string]*Character `json:"characters"`
|
||||
Corpses map[string]*Corpse `json:"corpses"`
|
||||
Depleted map[string]float64 `json:"depleted"`
|
||||
Mobs map[string]*Mob `json:"mobs"`
|
||||
Balance content.Balance `json:"balance"`
|
||||
terrain *Terrain
|
||||
chunks map[string]p.Chunk
|
||||
now time.Time
|
||||
dirty bool
|
||||
Version int `json:"version"`
|
||||
ID string `json:"id"`
|
||||
Seed int64 `json:"seed"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
EndedAt *time.Time `json:"endedAt,omitempty"`
|
||||
Phase string `json:"phase"`
|
||||
AdmissionsClosed bool `json:"admissionsClosed"`
|
||||
Tick int64 `json:"tick"`
|
||||
BossHP float64 `json:"bossHp"`
|
||||
BossLastAttack float64 `json:"bossLastAttack"`
|
||||
Characters map[string]*Character `json:"characters"`
|
||||
Corpses map[string]*Corpse `json:"corpses"`
|
||||
Depleted map[string]float64 `json:"depleted"`
|
||||
Mobs map[string]*Mob `json:"mobs"`
|
||||
Balance content.Balance `json:"balance"`
|
||||
terrain *Terrain
|
||||
chunks map[string]p.Chunk
|
||||
now time.Time
|
||||
dirty bool
|
||||
}
|
||||
|
||||
func ID() string {
|
||||
@@ -122,18 +126,27 @@ func (w *World) Info() p.WorldInfo {
|
||||
}
|
||||
func (w *World) ForAccount(account string) *Character {
|
||||
for _, c := range w.Characters {
|
||||
if c.Account == account {
|
||||
if c.Account == account && c.View.Entity.State != "dead" {
|
||||
return c
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (w *World) LivingCount() int {
|
||||
n := 0
|
||||
for _, c := range w.Characters {
|
||||
if c.View.Entity.State != "dead" {
|
||||
n++
|
||||
}
|
||||
}
|
||||
return n
|
||||
}
|
||||
func (w *World) spawn(exclude string) (p.Vec3, error) {
|
||||
for i := 0; i < 4096; i++ {
|
||||
radius := math.Sqrt(float64(i)) * w.Balance.SpawnSeparation * 0.6
|
||||
angle := float64(i) * 2.399963229728653
|
||||
pos := w.terrain.Position(math.Cos(angle)*radius, math.Sin(angle)*radius)
|
||||
if radius > w.Balance.WorldRadius-32 {
|
||||
if radius > math.Max(0, math.Min(w.Balance.WorldRadius-32, w.SafeRadius()-8)) {
|
||||
break
|
||||
}
|
||||
clear := true
|
||||
@@ -153,10 +166,10 @@ func (w *World) Join(account, name string) (*Character, error) {
|
||||
if c := w.ForAccount(account); c != nil {
|
||||
return c, nil
|
||||
}
|
||||
if w.Phase != "gathering" {
|
||||
if (w.Phase != "gathering" && w.Phase != "cataclysm") || w.AdmissionsClosed {
|
||||
return nil, errors.New("this world is closed to new arrivals")
|
||||
}
|
||||
if len(w.Characters) >= w.Balance.MaxPlayers {
|
||||
if w.LivingCount() >= w.Balance.MaxPlayers {
|
||||
return nil, errors.New("world capacity reached")
|
||||
}
|
||||
pos, err := w.spawn("")
|
||||
@@ -168,11 +181,12 @@ func (w *World) Join(account, name string) (*Character, error) {
|
||||
c.View.Inventory[k] = v
|
||||
}
|
||||
w.Characters[c.View.Entity.ID] = c
|
||||
c.BornAt = w.now
|
||||
w.dirty = true
|
||||
return c, nil
|
||||
}
|
||||
func (w *World) Import(c *Character) error {
|
||||
if w.Phase != "gathering" || w.ForAccount(c.Account) != nil || len(w.Characters) >= w.Balance.MaxPlayers {
|
||||
if w.Phase != "gathering" || w.AdmissionsClosed || w.ForAccount(c.Account) != nil || w.Characters[c.View.Entity.ID] != nil || w.LivingCount() >= w.Balance.MaxPlayers {
|
||||
return errors.New("destination cannot accept character")
|
||||
}
|
||||
if c.View.Entity.State != "eligible" || c.View.Entity.HP <= 0 {
|
||||
@@ -430,8 +444,57 @@ func (w *World) kill(c *Character, reason string) {
|
||||
c.ReturnPosition = nil
|
||||
c.View.HasKeystone = false
|
||||
c.Message = reason
|
||||
died := w.now
|
||||
c.DiedAt = &died
|
||||
c.DeathReason = reason
|
||||
w.dirty = true
|
||||
}
|
||||
|
||||
// Operator changes use the same simulation and persistence path as gameplay.
|
||||
func (w *World) Control(op, target, value, reason string) error {
|
||||
switch op {
|
||||
case "close-admissions", "open-admissions":
|
||||
if w.Phase == "won" || w.Phase == "lost" {
|
||||
return errors.New("world has ended")
|
||||
}
|
||||
w.AdmissionsClosed = op == "close-admissions"
|
||||
case "awaken-boss":
|
||||
return w.TriggerBoss()
|
||||
case "end-world":
|
||||
if w.Phase == "won" || w.Phase == "lost" {
|
||||
return errors.New("world has already ended")
|
||||
}
|
||||
for _, c := range w.Characters {
|
||||
w.kill(c, "World ended by an operator: "+reason)
|
||||
}
|
||||
w.Phase = "lost"
|
||||
ended := w.now
|
||||
w.EndedAt = &ended
|
||||
default:
|
||||
c := w.Characters[target]
|
||||
if c == nil {
|
||||
return errors.New("character not found")
|
||||
}
|
||||
if c.View.Entity.State != "alive" {
|
||||
return errors.New("only living characters in an active world may be changed")
|
||||
}
|
||||
switch op {
|
||||
case "rename":
|
||||
c.View.Entity.Name = value
|
||||
case "heal":
|
||||
c.View.Entity.HP = c.View.Entity.MaxHP
|
||||
case "unstuck":
|
||||
c.View.Entity.Position = w.terrain.Position(0, 0)
|
||||
c.MoveX, c.MoveZ = 0, 0
|
||||
case "retire":
|
||||
w.kill(c, "Character retired by an operator: "+reason)
|
||||
default:
|
||||
return errors.New("unknown control operation")
|
||||
}
|
||||
}
|
||||
w.dirty = true
|
||||
return nil
|
||||
}
|
||||
func (w *World) Advance(now time.Time, dt float64) {
|
||||
playedDT := math.Max(0, dt)
|
||||
w.now = now
|
||||
|
||||
@@ -131,8 +131,17 @@ func TestGatherCraftAndPermanentDeath(t *testing.T) {
|
||||
t.Fatal("dead character reconnected")
|
||||
}
|
||||
same, err := w.Join(c.Account, "Replacement")
|
||||
if err != nil || same.View.Entity.ID != id || same.View.Entity.State != "dead" {
|
||||
t.Fatal("death bypass by rejoining")
|
||||
if err != nil || same.View.Entity.ID == id || same.View.Entity.State != "alive" || c.View.Entity.State != "dead" {
|
||||
t.Fatal("replacement must be a new life, not a resurrection")
|
||||
}
|
||||
if same.DailySeconds != 0 || same.View.Inventory["spear"] != 0 || w.LivingCount() != 1 {
|
||||
t.Fatal("new life inherited old progress or incorrect capacity")
|
||||
}
|
||||
if again, _ := w.Join(c.Account, "Duplicate"); again.View.Entity.ID != same.View.Entity.ID {
|
||||
t.Fatal("second living character")
|
||||
}
|
||||
if c.DiedAt == nil || c.DeathReason != "test death" {
|
||||
t.Fatal("missing durable death record")
|
||||
}
|
||||
if len(c.View.Inventory) != 0 || w.Corpses["corpse:"+id].Inventory["spear"] != 1 {
|
||||
t.Fatal("corpse inventory")
|
||||
|
||||
Reference in New Issue
Block a user