commit ccaf019160aefac853ccb514dfb822229aaed90d
parent 50d1b3fcd9c9da28d5c1f69b39ff16db006f9bc0
Author: anon <anon@example.com>
Date: Sun, 25 Oct 2026 00:07:03 +0000
Restore skill cooldowns directly in character snapshots
Diffstat:
8 files changed, 182 insertions(+), 92 deletions(-)
diff --git a/TODO.md b/TODO.md
@@ -139,12 +139,18 @@ unverified mass/deletion/reclaim policies are in [backpacks](docs/backpacks.md).
- [ ] Expand implant admission to complete catalog contracts and slots.
Check Jobe SkillLockModifier382 sources, signed bonuses, strict requirements,
surgery access, removal and cold recovery with actual WASM gear changes.
- Verify native OnWear replay order and countdown reconstruction under a changed
- modifier when those real implant sources become usable.
+ Verify live use and cold restoration with changed real implant modifiers.
+ Native FullCharacter applies installed OnWear effects before directly restoring
+ its remaining-second lock pairs; it does not rescale those pairs.
Original modifier-only fixtures include chest178218/219, leg191026/027 and
hand193502/503; QL1 bonuses are positive and QL200 negative. Exact records are
retained in `local/skill-lock-research/catalog/`. Do not infer intermediate
qualities or silently admit unsupported OnWear effects.
+ The complete 44,356-definition implant audit and 13-slot fixtures are in
+ `local/implant-catalog-research/`. Authored QLs are 1, 200, 201 and 300;
+ there are no QL400 implants. Respect multi-slot masks, reject complete items
+ with unsupported effect stats or unknown section contracts, and evaluate
+ action7 for removal independently of action6 installation requirements.
- [x] Equip one belt. Check: the corresponding deck slots become available and
invalid belt removal cannot strand installed equipment.
- [x] Install one NCU memory. Check: available NCU changes by the item's amount
@@ -464,9 +470,9 @@ replay/failure tests and WASM checks are recorded in [IP training](docs/ip-train
- [x] Generalize persistent skill locks for Nano Rechargers and other SkillTime
effects. Check: patient TimeSpace131 locks remain distinct from Treatment124
and user FirstAid123, survive restart and expire correctly. Apply the native
- SkillLockModifier382 formula coherently on use and on lock reconstruction,
- including equipment/nano modifiers and timing boundaries; avoid scaling the
- remaining duration twice at login. Use the same rule across kits, clinics
+ SkillLockModifier382 formula on use, including equipment/nano modifiers and
+ timing boundaries. Restore remaining seconds directly in FullCharacter,
+ independently of the current modifier. Use the same rule across kits, clinics
and specials where their recovered contracts agree.
One actor-owned map/table now replaces separate inventory/patient/special
representations. The three authored rechargers, private native lock ownership,
diff --git a/docs/skill-locks.md b/docs/skill-locks.md
@@ -35,33 +35,43 @@ decimal percentages or round a negative value down.
| 600 | 629 | 899 | 570 | 300 |
Use-time action170 carries the authored raw duration. The server persists its
-already-scaled deadline. On a fresh connection, it instead finds the smallest
-raw argument whose native calculation reaches `ceil(deadline-now)` under the
-current modifier. Sending scaled remaining seconds directly would scale the
-cooldown twice. Positive modifiers can leave integer gaps in representable
-durations; authoritative expiry164 removes any excess client countdown.
-An existing native lock ignores another action170, including after gear changes.
+already-scaled deadline. On a fresh connection, FullCharacter's seventh encoded
+list carries `(skill, ceil(deadline-now))` pairs. The native activation handler
+copies those remaining seconds directly into the lock vector, bypassing the
+SkillTime calculation. Restoring a lock therefore neither samples the current
+modifier nor needs an action170 replay. Expired locks are omitted. An existing
+native lock ignores another action170, including after gear changes.
This reproduces the proven ordinary-duration contract. Original x87 precision
control remains unpinned; pathological billion-second inputs can differ from
the translated client's binary64 result. Native one-second countdown phase can
-also differ from the server's wall-clock expiry by less than one second.
-If gear changes to modifier <= -100 during a positive lock, ordinary positive
-raw arguments cannot reconstruct its countdown. The server preserves the
-deadline and expiry notification but omits an unrepresentable start. No
-negative-argument or integer-overflow trick is used to fabricate a display.
+also differ from the server's wall-clock expiry by less than one second once
+active. Countdown starts on native actor activation; asset loading can delay
+that relative to packet receipt. Observed cold-load displays lagged wall time
+by a few seconds. Authoritative expiry164 still clears the lock at its saved
+deadline, independently of that display delay.
+Direct snapshot restoration also preserves positive locks after a gear change
+to modifier <= -100. The original deadline remains authoritative; expiry164
+removes the native lock once.
## Evidence and checks
The original binary hash, 19 complete retained REA records, translated source,
-53 arithmetic fixtures, exact removal route and inverse examples are under
+53 arithmetic fixtures and exact removal route are under
`local/skill-lock-research/native/`. Setter assembly evidence is
`ev_7b0b159708714234fe2b12acaa00c1561360f684f87d83a192764c032f4d5787`;
removal is `ev_d3c272efae71f0e9f1fb434009133f7fd20de4805140ed3e5fafc0a54d9c7a17`.
+FullCharacter reader1007f5b0 is
+`ev_44ff34167a7b005d7ab9e5a881b06b21d3d2fa958cbd8d5bb9adcd88df40a5ce`;
+activation1007eea0 is
+`ev_536ab4204cf8d5b82781e8a0435782a6a0f0b6e1318a57c7591fd4bb03f3167b`.
+Complete records and the encoded-list mapping are retained under
+`local/implant-catalog-research/native/`. The activation applies installed
+implant OnWear effects before directly appending the snapshot's lock pairs.
Tests exercise public kit, clinic, equipment-move and special-attack handlers,
cold reopening, recipient ownership, unrelated skills, last-charge rollback,
-reconnect conversion and one-time expiry without database churn. Modifier
+direct snapshot recovery and one-time expiry without database churn. Modifier
aggregation tests substitute complete OnWear/nano Modify effects to isolate the stat;
they do not claim that implant101173 originally modifies382. The original
modifier sources are Jobe implants/components and require further implant
@@ -69,9 +79,28 @@ catalog support before ordinary players can use those sources. Their complete
records and original-payload verification are under
`local/skill-lock-research/catalog/`.
-The full Go suite passed in 577.287 seconds, with focused race tests passing
-in 112.788 seconds and vet clean. Supplemental normal/race runs verify combined
-modifiers; a separate 94.251-second race run verifies that two competing
-healers restore once and consume only one charge for the same patient.
-Logs are under `local/skill-lock-research/`.
+Snapshot regression tests cover seven current modifiers, including -100/-150,
+multiple independent skills, learned nanos, expired entries between simulation
+ticks, cold database recovery and private connection initialization without
+action170 replay. The full Go suite passed in 552.551 seconds, focused race
+checks passed in 99.637 seconds, and vet was clean. Logs are under
+`local/skill-lock-bootstrap/`. Earlier medical/special aggregation, atomicity,
+concurrent-healer and use-time checks remain under `local/skill-lock-research/`.
+An actual GPU/OpenGL WASM client used the clinic's raw600 lock and a nano
+stim's raw40 lock. A fresh connection and page reload restored their direct
+FullCharacter pairs without start replays. Reuse during the restored stim lock
+preserved its 24 charges; expiry sent one164 at the saved deadline, then a new
+use reduced it to23. The independent clinic deadline never changed. Original
+Jobe modifier gear remains pending implant admission: the inventory validator
+correctly rejected an attempted equipped cold-load fixture, which was restored
+to ordinary inventory. This run's native modifier was zero; nonzero snapshot
+independence is covered by the regression fixtures and original activation
+code, not a claimed real-Jobe gameplay test.
+
+Read-only native snapshots, complete world-stream parsing and verification are
+under `local/skill-lock-bootstrap/`. Owned fixtures were removed with
+FK/integrity checks and unchanged hashes for all unrelated rows. Browser runs
+had no errors. Earlier two-client patient TimeSpace131 ownership, last-charge
+use and private delivery checks remain under `local/nano-recharger-smoke/` and
+are described in [medical consumables](medical-consumables.md).
diff --git a/server/fling_shot_test.go b/server/fling_shot_test.go
@@ -353,19 +353,20 @@ func TestFlingShotReconnectPublishesRemainingLockBeforeReady(t *testing.T) {
conn := &combatInterestConn{input: bytes.NewReader(input)}
err := world.serveWorldClient(&worldClient{conn: conn, loading: true})
- locks := 0
+ var locks map[uint32]uint32
+ snapshots := 0
for _, packet := range conn.packets {
- if len(packet) >= 56 && binary.BigEndian.Uint32(packet[20:24]) == 0x5e477770 &&
- binary.BigEndian.Uint32(packet[36:40]) == 170 && binary.BigEndian.Uint32(packet[48:52]) == 150 {
- locks++
- if binary.BigEndian.Uint32(packet[52:56]) < 18 || binary.BigEndian.Uint32(packet[52:56]) > 19 {
- t.Fatal("wrong remaining special lock")
- }
+ if binary.BigEndian.Uint32(packet[20:24]) == 0x29304349 {
+ snapshots++
+ locks = nativeSnapshotSkillLocks(t, targetPacket(append([]byte(nil), packet...)))
+ }
+ if binary.BigEndian.Uint32(packet[20:24]) == 0x5e477770 && binary.BigEndian.Uint32(packet[36:40]) == 170 {
+ t.Fatal("reconnect replayed an already restored special lock")
}
}
- if err != nil || locks != 1 {
- t.Fatalf("reconnect did not restore exactly one native lock: %d, %v", locks, err)
+ if err != nil || snapshots != 1 || len(locks) != 1 || locks[150] < 18 || locks[150] > 19 {
+ t.Fatalf("reconnect did not restore exactly one native lock: %v, %v", locks, err)
}
}
diff --git a/server/implants_test.go b/server/implants_test.go
@@ -63,7 +63,9 @@ func TestImplantClinicEquipBonusesAndRestart(t *testing.T) {
t.Fatal("observer equipment snapshot lost an item")
}
packet := fullCharacterPacket(restored)
- cursor := 64 + len(restored.inventory.Items)*32
+ // The first stat list follows the remaining-second skill-lock list.
+ cursor := 60 + len(restored.inventory.Items)*32
+ cursor += 4 + 8*int(binary.BigEndian.Uint32(packet[cursor:])/1009-1)
count := int(binary.BigEndian.Uint32(packet[cursor:])/1009 - 1)
values := make(map[uint32]uint32)
for offset := cursor + 4; offset < cursor+4+count*8; offset += 8 {
diff --git a/server/main.go b/server/main.go
@@ -391,7 +391,6 @@ func (server *server) serveWorldClient(client *worldClient) error {
}
}
updates = append(updates, equippedWeaponPackets(character)...)
- updates = append(updates, character.skillLockPackets(time.Now())...)
updates = append(updates, server.combatInterest_locked(client, nil)...)
if client.target {
for _, id := range []uint32{0xc00003b6, 0xc00003b8} {
diff --git a/server/skill_locks.go b/server/skill_locks.go
@@ -3,7 +3,6 @@ package main
import (
"database/sql"
"fmt"
- "math"
"time"
)
@@ -71,25 +70,3 @@ func scaledSkillLockSeconds(raw uint32, modifier int32) int32 {
func (player *character) skillLockSeconds(raw uint32) int32 {
return scaledSkillLockSeconds(raw, player.equipmentBonus(382)+player.nanoBonus(382))
}
-
-func (player *character) skillLockPackets(now time.Time) [][]byte {
- var packets [][]byte
- modifier := player.equipmentBonus(382) + player.nanoBonus(382)
- for skill, deadline := range player.skillLocks {
- if !now.Before(deadline) || modifier <= -100 {
- continue
- }
- // Reconstruct raw seconds without applying the current modifier twice.
- seconds := uint32((deadline.Sub(now) + time.Second - 1) / time.Second)
- raw := uint32(math.Ceil(float64(seconds) / (1 + float64(modifier)*float64(float32(0.01)))))
- for scaledSkillLockSeconds(raw, modifier) < int32(seconds) {
- raw++
- }
- for raw > 1 && scaledSkillLockSeconds(raw-1, modifier) >= int32(seconds) {
- raw--
- }
- // Some durations are unrepresentable; authoritative expiry also sends action164.
- packets = append(packets, skillLockPacket(player.id, skill, raw))
- }
- return packets
-}
diff --git a/server/skill_locks_test.go b/server/skill_locks_test.go
@@ -4,6 +4,7 @@ import (
"ao/server/gamedata"
"encoding/binary"
"fmt"
+ "net"
"slices"
"testing"
"time"
@@ -71,34 +72,71 @@ func setTestSkillModifier(t *testing.T, world *server, player *character, modifi
}
}
-func TestSkillLockReplayUsesCurrentModifierWithoutChangingDeadline(t *testing.T) {
- for _, scenario := range []struct {
- modifier int32
- seconds uint32
- raw uint32
- }{
- {0, 10, 10}, {-50, 10, 20}, {-15, 34, 40}, {50, 10, 7}, {100, 2, 2}, {100, 10, 6},
- } {
- t.Run(fmt.Sprintf("%d/%d", scenario.modifier, scenario.seconds), func(t *testing.T) {
+func nativeSnapshotSkillLocks(t *testing.T, packet []byte) map[uint32]uint32 {
+ t.Helper()
+ // Skip inventory, its native auxiliary list, learned nanos and three empty lists.
+ cursor := 37 + 32*int(binary.BigEndian.Uint32(packet[33:37])/1009-1)
+ if binary.BigEndian.Uint32(packet[cursor:]) != 1009 {
+ t.Fatal("unexpected inventory auxiliary list")
+ }
+ cursor += 4
+ cursor += 4 + 4*int(binary.BigEndian.Uint32(packet[cursor:])/1009-1)
+ for range 3 {
+ if binary.BigEndian.Uint32(packet[cursor:]) != 1009 {
+ t.Fatal("unexpected list before skill locks")
+ }
+ cursor += 4
+ }
+
+ // The seventh list contains plain skill/remaining-second pairs.
+ count := int(binary.BigEndian.Uint32(packet[cursor:])/1009 - 1)
+ cursor += 4
+ locks := make(map[uint32]uint32)
+ for range count {
+ locks[binary.BigEndian.Uint32(packet[cursor:])] = binary.BigEndian.Uint32(packet[cursor+4:])
+ cursor += 8
+ }
+ if len(locks) != count {
+ t.Fatal("snapshot repeated a skill lock")
+ }
+ return locks
+}
+
+func TestSkillLockSnapshotRestoresRemainingSecondsRegardlessOfModifier(t *testing.T) {
+ for _, modifier := range []int32{0, -15, -50, 50, 100, -100, -150} {
+ t.Run(fmt.Sprint(modifier), func(t *testing.T) {
world, conn := newNanoKitWorld(t)
player := world.characters[1]
- setTestSkillModifier(t, world, player, scenario.modifier)
+ setTestSkillModifier(t, world, player, modifier)
+ player.inventory.LearnedNanos = []uint32{43324, 29618}
+ if err := world.saveInventory_locked(player, player.inventory); err != nil {
+ t.Fatal(err)
+ }
now := time.Now()
- deadline := now.Add(time.Duration(scenario.seconds)*time.Second - time.Millisecond)
+ deadline := now.Add(600 * time.Second)
setTestSkillLock(t, world, player, 123, deadline)
+ setTestSkillLock(t, world, player, 124, now.Add(-time.Second))
+ setTestSkillLock(t, world, player, 131, now.Add(1200*time.Second))
restored := newTestInventoryServer(t).characters[1]
- packets := restored.skillLockPackets(now)
- for _, packet := range packets {
- if err := world.clients[1].send(packet); err != nil {
- t.Fatal(err)
- }
+ // An expired entry can also remain in memory until the next simulation tick.
+ restored.skillLocks[124] = now.Add(-time.Second)
+ before := time.Now()
+ if err := world.clients[1].send(fullCharacterPacket(restored)); err != nil {
+ t.Fatal(err)
}
+ after := time.Now()
+ locks := nativeSnapshotSkillLocks(t, conn.packets[0])
- if len(conn.packets) != 1 || binary.BigEndian.Uint32(conn.packets[0][29:33]) != 170 ||
- binary.BigEndian.Uint32(conn.packets[0][41:45]) != 123 || binary.BigEndian.Uint32(conn.packets[0][45:49]) != scenario.raw ||
- !restored.skillLocks[123].Equal(deadline) {
- t.Fatalf("replay scaled an absolute deadline twice or selected the wrong raw duration: packets=%x lock=%v want=%v modifier=%d", packets, restored.skillLocks[123], deadline, restored.equipmentBonus(382))
+ if len(conn.packets) != 1 || len(locks) != 2 || !restored.skillLocks[123].Equal(deadline) || restored.equipmentBonus(382) != modifier {
+ t.Fatalf("snapshot changed lock ownership, deadline or gear: locks=%v deadline=%v modifier=%d", locks, restored.skillLocks[123], restored.equipmentBonus(382))
+ }
+ for _, skill := range []uint32{123, 131} {
+ minimum := uint32((restored.skillLocks[skill].Sub(after) + time.Second - 1) / time.Second)
+ maximum := uint32((restored.skillLocks[skill].Sub(before) + time.Second - 1) / time.Second)
+ if locks[skill] < minimum || locks[skill] > maximum {
+ t.Fatalf("snapshot rescaled skill %d: seconds=%d want=%d..%d", skill, locks[skill], minimum, maximum)
+ }
}
})
}
@@ -203,22 +241,46 @@ func TestWeaponSpecialSharesScaledSkillLock(t *testing.T) {
}
}
-func TestUnrepresentableReplayRetainsAuthoritativeLock(t *testing.T) {
- for _, modifier := range []int32{-100, -150} {
- t.Run(fmt.Sprint(modifier), func(t *testing.T) {
- world, conn := newNanoKitWorld(t)
- player := world.characters[1]
- setTestSkillModifier(t, world, player, modifier)
- deadline := time.Now().Add(time.Minute)
- setTestSkillLock(t, world, player, 123, deadline)
+func TestSkillLockReconnectRestoresOnlyOwnerWithoutStartReplay(t *testing.T) {
+ world, patient, _ := newNanoRechargerWorld(t, true)
+ deadline := time.Now().Add(10 * time.Minute)
+ setTestSkillLock(t, world, world.characters[1], 124, deadline)
+ setTestSkillLock(t, world, patient, 131, deadline)
+ world = newTestInventoryServer(t)
+ client, connection := net.Pipe()
+ defer client.Close()
+ client.SetDeadline(time.Now().Add(5 * time.Second))
+ done := make(chan error, 1)
+ go func() { defer connection.Close(); done <- world.serveWorldConnection(connection) }()
+ cookie := systemPacket(0x1b, []byte{0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0})
+ binary.BigEndian.PutUint16(cookie, 0xdfdf)
- packets := player.skillLockPackets(time.Now())
- world.advanceItemEffects(deadline)
+ client.Write(cookie)
+ var locks map[uint32]uint32
+ for {
+ packet, err := readPacket(client)
+ if err != nil {
+ t.Fatal(err)
+ }
+ key := binary.BigEndian.Uint32(packet[16:20])
+ if key == 0x29304349 {
+ locks = nativeSnapshotSkillLocks(t, packet)
+ }
+ if key == 0x5e477770 && binary.BigEndian.Uint32(packet[29:33]) == 170 {
+ t.Fatal("reconnect replayed an already restored skill lock")
+ }
+ if key == 0x5f52412e {
+ break
+ }
+ }
+ client.Close()
+ if err := <-done; err != nil {
+ t.Fatal(err)
+ }
- if len(packets) != 0 || len(conn.packets) != 1 || binary.BigEndian.Uint32(conn.packets[0][29:33]) != 164 {
- t.Fatal("unrepresentable replay fabricated a positive duration or lost authoritative expiry")
- }
- })
+ if len(locks) != 1 || locks[131] < 599 || locks[131] > 600 ||
+ len(world.characters[2].skillLocks) != 1 || !world.characters[2].skillLocks[131].Equal(deadline) {
+ t.Fatal("reconnect lost the patient lock or disclosed another owner's lock", locks)
}
}
diff --git a/server/world.go b/server/world.go
@@ -181,9 +181,23 @@ func fullCharacterPacket(character *character) []byte {
for _, id := range character.inventory.LearnedNanos {
body = binary.BigEndian.AppendUint32(body, id)
}
- for range 4 {
+ for range 3 {
body = binary.BigEndian.AppendUint32(body, 1009)
}
+ // FullCharacter restores remaining seconds directly, without SkillTime scaling.
+ var locks [][2]uint32
+ now := time.Now()
+ for skill, deadline := range character.skillLocks {
+ if now.Before(deadline) {
+ seconds := uint32((deadline.Sub(now) + time.Second - 1) / time.Second)
+ locks = append(locks, [2]uint32{skill, seconds})
+ }
+ }
+ body = binary.BigEndian.AppendUint32(body, uint32(len(locks)+1)*1009)
+ for _, lock := range locks {
+ body = binary.BigEndian.AppendUint32(body, lock[0])
+ body = binary.BigEndian.AppendUint32(body, lock[1])
+ }
lowerXP, upperXP := character.experienceBounds()
stats := [][2]uint32{{54, uint32(character.level)}, {52, lowerXP + character.experience}, {57, lowerXP}, {350, upperXP}, {236, max(lowerXP, character.insuredExperience)}}
stats = append(stats, character.baseStats().nativeStats()...)