commit 9df11c7e57b65b57279497ac41340a409e0f63d4
parent c62c42deaddd1dee5c6aa56dad9091021ef5eadc
Author: anon <anon@example.com>
Date: Wed, 4 Nov 2026 12:06:45 +0000
Reject social commands during authoritative swimming
Diffstat:
6 files changed, 282 insertions(+), 9 deletions(-)
diff --git a/TODO.md b/TODO.md
@@ -3079,8 +3079,17 @@ disconnect retention and succession policy still need period corroboration.
observer receive the raw Swimming base before refreshing movement; both native
limits read 16.004999 for trained3000 plus ability trickle. Finish shoreline,
shallow/deep transitions, encumbrance, cached lateral controls, water smoothing
- cadence and action restrictions. The native social sender refuses gestures in
- mode4; cover that independently in server eligibility tests.
+ cadence and remaining action restrictions. The independently verified social
+ restriction is recorded below.
+- [x] [P2] Reject social commands processed during authoritative swimming.
+ The original sender refuses physical mode4, but the server accepted and
+ relayed a late native wave. Apply that mode gate with owner-only verification2
+ and the exact command reference; preserve movement, posture, resources and
+ database state. Public water entry/exit regressions cover standing and seated
+ swimmers. A short controlled WASM check reproduces the defect and verifies
+ refusal, land retry, no prior-gesture replay and cold resource conservation.
+ It models withheld mode publication, not natural shoreline travel. Broader
+ swimming remains open above; see [gestures](docs/gestures.md).
- [ ] [P2] Apply authoritative environmental damage from original hazard volumes.
Recover the volume kinds, timing and damage rules, then share normal damage,
death and persistence paths. Check entry, continued exposure, exit, overlapping
diff --git a/docs/gestures.md b/docs/gestures.md
@@ -36,9 +36,9 @@ verification 0 bypasses the native completion protocol.
Verification 2 removes a pending local reference without triggering social
animation. The social local-execution function itself returns 2 on failure.
-Using that completion for a current but dead, unready or loading player is this
-server's rejection policy; the exact historical enum label and full original
-server policy have not been recovered.
+Using that completion for a current but dead, unready, loading or swimming
+player is this server's rejection policy; the exact historical enum label and
+full original server policy have not been recovered.
The handler validates owned subject identity, pass-on 1, verification 0,
exact length, the native enum range 1..63, and the authenticated current
@@ -57,9 +57,12 @@ meaning remain unresolved. The handler follows the recovered numeric range
without inventing a name or a special animation for it.
The sender explicitly refuses social commands while swimming (movement mode
-4). The server does not yet model authoritative water transitions; that broader
-movement work remains in TODO. No additional swimming threshold, gesture
-cooldown, posture restriction or combat restriction is inferred here.
+4). The server applies the same physical-mode restriction, including commands
+processed after authoritative water entry. A refusal preserves the exact
+command reference and is sent only to the owner. Leaving water restores normal
+eligibility independently of retained rest posture. The broader swimming model
+remains in TODO; no additional threshold, gesture cooldown, posture restriction
+or combat restriction is inferred here.
The actor controller stores a social enum for the next update, clears it, and
asks the native mesh to play the breed/sex-specific animation once. That field
@@ -103,6 +106,27 @@ malformed and unauthorized requests, stale/dead/loading sessions, observer
filtering, late joins, unchanged posture/held input/casting, and zero database
writes through SQLite audit triggers.
+`server/social_swimming_test.go` reproduces water entry through the public
+movement handler and original terrain/water geometry. Standing and seated
+swimmers receive verification 2 for references 0, 1 and 0xffffffff without
+observer relay, movement/resource changes or database writes. Public water exit
+restores acceptance while preserving rest posture. The original sender's
+physical-mode comparison is at `kkr.dll` 0x1002b39f, retained in
+`client/game/kkr.dll/lifted-0016.c::sub_3602B360`.
+
+The focused WASM regression (`server/browser_social_swimming_test.go` and
+`tools/client/test_social_swimming.mjs`) sends actual `/wave` input while a
+controlled fixture withholds the server's water-mode publication. This models
+a late command from a client still viewing land, not natural shoreline travel.
+Before the fix the command received verification 1 and reached the observer;
+afterward it receives 2 privately, then a new land command receives 1 and reaches
+the observer once. Page reconnect replays no prior gesture, and cold loading
+retains resources and empty inventory. This does not claim that rejection
+cancels an animation already started locally. The 10.97-second fixed run and
+failing baseline are retained under `local/social-swimming/`.
+The focused social/water selection passes 22 roots and 61 results both normally
+and under the race detector; vet passes for all maintained Go packages.
+
Runtime evidence is retained under `local/gesture-smoke/`. Read-only native
probes follow the actual mesh animation list and the pending-command list;
they do not call guest functions or modify game memory. LLR's pending count
diff --git a/server/browser_social_swimming_test.go b/server/browser_social_swimming_test.go
@@ -0,0 +1,91 @@
+package main
+
+import (
+ "context"
+ "crypto/sha256"
+ "encoding/binary"
+ "encoding/json"
+ "fmt"
+ "net/http"
+ "net/http/httptest"
+ "os"
+ "os/exec"
+ "path/filepath"
+ "runtime"
+ "testing"
+ "time"
+)
+
+func TestBrowserSocialSwimmingRefusal(t *testing.T) {
+ if os.Getenv("AO_GAME_TEST") != "1" {
+ t.Skip("set AO_GAME_TEST=1 for the swimming social-command check")
+ }
+
+ _, source, _, _ := runtime.Caller(0)
+ root := filepath.Dir(filepath.Dir(source))
+ output := filepath.Join(root, "local/social-swimming", time.Now().Format("20060102-150405"))
+ world := newTestServer(t)
+ player, peer := world.newCharacter(), world.newCharacter()
+ world.characters = map[uint32]*character{player.id: player, peer.id: peer}
+ for _, actor := range []*character{player, peer} {
+ actor.playfield, actor.position = 1183, [3]float32{193.79826, 5.01, 136.83983}
+ }
+ peer.position[2] += 2
+ player.browserTokenHash = fmt.Sprintf("%x", sha256.Sum256([]byte("social-swimming")))
+ for _, actor := range []*character{player, peer} {
+ if err := world.saveUser_locked(actor); err != nil {
+ t.Fatal(err)
+ }
+ }
+ observer := &combatTestConn{}
+ peerClient := &worldClient{id: 2, target: true, ready: true, conn: observer}
+ world.clients[2] = peerClient
+ mux := http.NewServeMux()
+ mux.Handle("/", world.httpHandler())
+ mux.HandleFunc("GET /test-state", func(w http.ResponseWriter, r *http.Request) {
+ world.mutex.Lock()
+ defer world.mutex.Unlock()
+ peerClient.mutex.Lock()
+ defer peerClient.mutex.Unlock()
+ count := 0
+ for _, packet := range observer.packets {
+ if binary.BigEndian.Uint32(packet[16:20]) == 0x3b290771 {
+ count++
+ }
+ }
+ json.NewEncoder(w).Encode(map[string]any{"mode": player.movement.components[0], "observerCommands": count,
+ "health": player.health, "nano": player.nano, "inventory": player.inventory})
+ })
+ // Model a command emitted on land but processed after authoritative water entry.
+ // Withhold movement publication so the native sender can submit that late command.
+ mux.HandleFunc("POST /test-water", func(w http.ResponseWriter, r *http.Request) {
+ world.updateMutex.Lock()
+ defer world.updateMutex.Unlock()
+ world.mutex.Lock()
+ defer world.mutex.Unlock()
+ player.movement.prepare(player, time.Now())
+ if player.movement.components[0] == 4 {
+ player.movement.components[0], player.movement.deepWater = 2, false
+ } else {
+ player.movement.components[0], player.movement.deepWater = 4, true
+ }
+ })
+ host := httptest.NewServer(mux)
+ t.Cleanup(host.Close)
+ closeTestBrowserStreams(t, world)
+ ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
+ defer cancel()
+
+ command := exec.CommandContext(ctx, "node", filepath.Join(root, "tools/client/test_social_swimming.mjs"), host.URL, output)
+ command.Dir, command.Stdout, command.Stderr = root, os.Stdout, os.Stderr
+ err := command.Run()
+ t.Logf("Browser artifacts: %s", output)
+
+ if err != nil {
+ t.Fatal(err)
+ }
+ cold := newTestInventoryServer(t).characters[1]
+ if cold.health != player.health || cold.nano != player.nano || len(cold.inventory.Items) != 0 || world.nextItem != 0 {
+ t.Fatal("social-command eligibility changed durable player resources or inventory")
+ }
+}
diff --git a/server/social_actions.go b/server/social_actions.go
@@ -24,7 +24,7 @@ func (server *server) handleSocialAction(client *worldClient, body []byte) error
return nil
}
verification := uint32(1)
- if !client.ready || client.loading || player.health == 0 {
+ if !client.ready || client.loading || player.health == 0 || player.movement.components[0] == 4 {
verification = 2
}
playfield := player.playfield
diff --git a/server/social_swimming_test.go b/server/social_swimming_test.go
@@ -0,0 +1,79 @@
+package main
+
+import (
+ "encoding/binary"
+ "fmt"
+ "testing"
+)
+
+func TestSocialActionSwimmingRefusalPreservesMovementAndPendingReference(t *testing.T) {
+ for _, sitting := range []bool{false, true} {
+ t.Run(fmt.Sprint(sitting), func(t *testing.T) {
+ world := newPlayerCollisionWorld(t)
+ player, client := world.characters[1], world.clients[1]
+ player.position, player.sitting = [3]float32{100, 8, 25}, sitting
+ submerged := *player
+ submerged.position[1] = 6.5
+ if err := world.handleMovement(client, playerMovementRequest(&submerged, 20)); err != nil {
+ t.Fatal(err)
+ }
+ if player.movement.components[0] != 4 || !player.movement.deepWater {
+ t.Fatal("fixture did not enter authoritative swimming")
+ }
+ owner, observer := &combatTestConn{}, &combatTestConn{}
+ client.conn = owner
+ world.characters[2] = &character{id: 2, playfield: player.playfield, health: 100}
+ world.clients[2] = &worldClient{id: 2, target: true, ready: true, conn: observer}
+ before, vitals := player.movement, player.vitals()
+ auditCheckpointWrites(t, world)
+
+ for _, reference := range []uint32{0, 1, 0xffffffff} {
+ body := socialActionRequest(61)
+ binary.BigEndian.PutUint32(body[20:24], reference)
+ if err := world.handleSocialAction(client, body); err != nil {
+ t.Fatal(err)
+ }
+ }
+
+ if len(owner.packets) != 3 || len(observer.packets) != 0 || player.movement != before || player.vitals() != vitals || player.sitting != sitting ||
+ len(checkpointWrites(t, world)) != 0 {
+ t.Fatal("swimming social action reached an observer or changed movement/state", len(owner.packets), len(observer.packets))
+ }
+ for index, reference := range []uint32{0, 1, 0xffffffff} {
+ packet := owner.packets[index]
+ if binary.BigEndian.Uint32(packet[16:20]) != 0x3b290771 || binary.BigEndian.Uint32(packet[29:33]) != 2 ||
+ binary.BigEndian.Uint32(packet[33:37]) != reference || binary.BigEndian.Uint32(packet[37:41]) != 61 {
+ t.Fatalf("swimming refusal lost its exact pending social command: %x", packet)
+ }
+ }
+ })
+ }
+}
+
+func TestSocialActionWaterExitRestoresEligibilityWithRetainedRestPosture(t *testing.T) {
+ world := newPlayerCollisionWorld(t)
+ player, client := world.characters[1], world.clients[1]
+ player.position, player.sitting = [3]float32{100, 8, 25}, true
+ submerged := *player
+ submerged.position[1] = 6.5
+ if err := world.handleMovement(client, playerMovementRequest(&submerged, 20)); err != nil {
+ t.Fatal(err)
+ }
+ outside := *player
+ outside.position[1] = 8
+ owner := &combatTestConn{}
+ client.conn = owner
+
+ if err := world.handleMovement(client, playerMovementRequest(&outside, 20)); err != nil {
+ t.Fatal(err)
+ }
+ owner.packets = nil
+ if err := world.handleSocialAction(client, socialActionRequest(61)); err != nil {
+ t.Fatal(err)
+ }
+
+ if player.movement.components[0] != 2 || player.movement.deepWater || !player.sitting || len(owner.packets) != 1 ||
+ binary.BigEndian.Uint32(owner.packets[0][29:33]) != 1 {
+ t.Fatal("water exit did not restore normal social eligibility independently of rest posture")
+ }
+}
diff --git a/tools/client/test_social_swimming.mjs b/tools/client/test_social_swimming.mjs
@@ -0,0 +1,70 @@
+import assert from 'node:assert/strict';
+import fs from 'node:fs/promises';
+import {createRequire} from 'node:module';
+import {GameTest} from './game_test.mjs';
+
+const {chromium} = createRequire(import.meta.url)('playwright');
+const [url, output] = process.argv.slice(2);
+const browser = await chromium.launch({executablePath: '/usr/bin/chromium', args: [
+ '--enable-gpu', '--use-gl=angle', '--use-angle=gl', '--no-sandbox', '--disable-dev-shm-usage',
+ '--disable-background-timer-throttling', '--disable-renderer-backgrounding']});
+let game;
+const evidence = {};
+try {
+ const context = await browser.newContext({viewport: {width: 1024, height: 768}});
+ await context.addCookies([{name: 'ao_client', value: 'social-swimming', url}]);
+ const page = await context.newPage();
+ game = await GameTest.attach(page);
+ await page.goto(url);
+ await game.ready();
+ const server = async () => (await page.request.get(url + '/test-state')).json();
+ const wave = async () => {
+ const sequence = game.sequence;
+ await game.key('Enter');
+ await game.key('Slash');
+ await page.keyboard.type('wave');
+ await game.key('Enter');
+ await game.wait('actual native wave command', () => game.events.some(event => event.sequence > sequence &&
+ event.direction === 'framesent' && event.opcode === '3b290771'));
+ const request = game.events.find(event => event.sequence > sequence && event.direction === 'framesent' && event.opcode === '3b290771');
+ const reference = Buffer.from(request.hex, 'hex').readUInt32BE(33);
+ assert.equal(Buffer.from(request.hex, 'hex').readUInt32BE(37), 61);
+ await game.wait('matching social command completion', () => game.events.some(event => event.sequence > sequence &&
+ event.direction === 'framereceived' && event.opcode === '3b290771' && Buffer.from(event.hex, 'hex').readUInt32BE(33) === reference));
+ const response = game.events.find(event => event.sequence > sequence && event.direction === 'framereceived' &&
+ event.opcode === '3b290771' && Buffer.from(event.hex, 'hex').readUInt32BE(33) === reference);
+ return {reference, verification: Buffer.from(response.hex, 'hex').readUInt32BE(29)};
+ };
+ assert((await page.request.post(url + '/test-water')).ok());
+ evidence.before = await server();
+ assert.equal(evidence.before.mode, 4);
+ evidence.refusedCommand = await wave();
+ evidence.refused = await server();
+ await game.save(output + '/refused');
+ assert.equal(evidence.refusedCommand.verification, 2);
+ assert.deepEqual(evidence.refused, evidence.before);
+
+ assert((await page.request.post(url + '/test-water')).ok());
+ evidence.acceptedCommand = await wave();
+ evidence.after = await server();
+ assert.equal(evidence.acceptedCommand.verification, 1);
+ assert.equal(evidence.after.mode, 2);
+ assert.equal(evidence.after.observerCommands, 1);
+ assert.deepEqual(evidence.after.inventory, evidence.before.inventory);
+ assert.equal(evidence.after.health, evidence.before.health);
+ assert.equal(evidence.after.nano, evidence.before.nano);
+ await game.save(output + '/accepted');
+ await page.reload();
+ await game.ready();
+ assert(!game.events.some(event => event.navigation === game.navigation &&
+ event.direction === 'framereceived' && event.opcode === '3b290771'));
+ assert.equal(game.errors.length, 0);
+ assert.equal(game.dropped, 0);
+ console.log('PASS: late swimming social command receives exact rejection, stays private and succeeds again on land');
+} finally {
+ try {
+ await fs.mkdir(output, {recursive: true});
+ await fs.writeFile(output + '/verification.json', JSON.stringify(evidence, null, 2) + '\n');
+ if (game) await game.save(output + '/final');
+ } finally { await browser.close(); }
+}