commit bd4e1398a14d8d7379f65bf307d9351ea7a3de41
parent e3f7dd6818b357b7dfe9af3aad0295c48b1fc73e
Author: anon <anon@example.com>
Date: Sun, 25 Oct 2026 07:46:27 +0000
Sell supported map reader upgrades at original terminals
Diffstat:
6 files changed, 314 insertions(+), 6 deletions(-)
diff --git a/TODO.md b/TODO.md
@@ -613,9 +613,18 @@ introduction and starting-item gameplay remain open below.
native live object delivery and any packing rules before admitting these categories.
Cover full inventory, freed sale slots, partial failure and stable ownership
across reconnect/restart without inventing extra packet identity fields.
-- [ ] Recover map-terminal stock membership and sell the supported area maps
- and reader upgrades. Verify exact item/price delivery, purchase-to-upload,
- faction and skill rejection, duplicate purchases and durable consumption.
+- [x] Sell the five supported map-reader upgrades through the three original
+ Maps terminal templates. Verify native quotes, one-charge delivery,
+ purchase-to-upload, rejected low-skill/duplicate uploads, basket cancellation,
+ insufficient cash/space, atomic rollback and cold recovery. The fixed subset
+ is an explicit reconstruction; see [shops](docs/shops.md).
+- [ ] Recover complete historical map-terminal stock membership, including
+ area maps and any Startup bundle sales, faction/grade differences and
+ generation. Do not infer membership from item existence or the later wiki.
+ Resolve Broken Shores' period unavailability and Broken Crest's absent world.
+ Reuse the original records and dated source ledger in `local/map-shop-research/`.
+ Then verify exact item/price delivery, purchase-to-upload, authored faction
+ and skill rejection, duplicate purchases and durable consumption.
- [ ] Recover medical and ammunition stock membership and QL generation beyond
the current basic QL1 recovery subset. Original medical descriptions establish
broad families, while tier descriptors differ; do not copy basic stock into
diff --git a/docs/shops.md b/docs/shops.md
@@ -7,6 +7,7 @@ Cancel and removing an offer restore the same item. Tools, Devices and General
Tools and Bases expose documented fixed entries. Basic medical terminals offer
a supported QL1 subset with authored charges. Complete historical
stock membership, random generation and stock rotation remain unresolved.
+Map terminals offer the five supported reader upgrades described below.
## Original placements and access
@@ -199,6 +200,54 @@ debit algorithm was not recovered. The finalizer inspected in the client
contains no purchase debit. Native procedures, fields and remaining boundaries
are recorded in `local/shop-purchase-research/native/README.md`.
+## Map-reader upgrade subset
+
+The three original Maps templates are OT Maps 117649, Clan Maps 117749 and
+Maps 118050. Their shared category descriptor is TIAM; the selected client has
+one placement in each combined shop room 1180..1187 and one developer-world
+placement. The vendor modifiers remain authored: Omni sale/buy 6/100, Clan
+and neutral 4/105. Their faction criteria belong to action 0, so they do not
+add a faction restriction to the native vending Use action 3.
+
+The shipped `cd_image/text/help/The Map Window.txt` says area maps and radar
+upgrades are sold in shops. It describes People, Monsters, Machines and
+Directional Arrow functionality. The original item catalog supplies the five
+complete reader-upgrade contracts:
+
+| Template | Upgrade | Base price | Required effective Map Navigation |
+| --- | --- | --- | --- |
+| 116683 | Side | 35000 | 450 |
+| 116684 | Monsters | 12000 | 130 |
+| 116685 | People | 3500 | 80 |
+| 116692 | Machines | 1200 | 50 |
+| 116694 | Directional Arrow | 350 | 25 |
+
+Offering those five fixed QL1 entries at all three templates is a bounded
+reconstruction policy. The help does not name Side, enumerate template IDs or
+prove identical faction/grade stock. Later player documentation corroborates
+all five, including the [later map-terminal list](https://wiki.aodb.us/wiki/Map_terminal),
+but does not establish their exact 14.9.1 availability. Neither the
+TIAM descriptor nor a complete scan of all 278644 resource payloads recovered
+an authoritative membership list or generator. Raw vendor/item/placement
+records, hashes and the dated source ledger are retained under
+`local/map-shop-research/catalog/` and `sources/`.
+
+Area maps and Startup bundles remain outside this purchase subset. Their
+authored records establish upload behavior, rather than retail availability.
+A [13 May 2002 player report](https://forums-archive.anarchy-online.com/showthread.php?25099-Map-for-Broken-Shores-City-of-Home=)
+could not find Broken Shores in Clan stores; its status in 14.9.1 is unresolved.
+Broken Crest retains an upload contract but has no corresponding playfield
+resource in the selected client. The later wiki includes post-target zones;
+importing its list would silently mix versions. These gaps remain in TODO.
+
+Reader upgrades are nonstackable one-charge items. One purchase creates one
+durable record, one free slot and an AddTemplate count of 1. Checkout does not
+apply upload skill or known-map criteria: an unskilled player can buy an
+upgrade, and an installed upgrade can be bought again. The shared
+[map upload](map-uploads.md) path checks use requirements, consumes an eligible
+owned item and commits its flags atomically. A rejected duplicate or low-skill
+upload retains the purchased item and its already-paid purchase price.
+
## Native handshake and inventory references
The target is `anarchy-vanilla-14.9.1/kkr.dll`, SHA-256
@@ -427,3 +476,26 @@ Cleanup removed only the two test-owned players and their 34 remaining items.
All unrelated database rows
were unchanged, foreign-key and integrity checks passed, and the single shared
HTTPS preview remains available on port 8443.
+
+Map-reader purchase tests cover all eight standard-room catalogs and the
+five exact upgrade templates, six-item single-charge delivery, original quote
+rounding, purchased-item uploads, replays, retained duplicates and low-skill
+rejection. Cancellation, removal, forged rows, insufficient final cash, full
+inventory and a failed second SQLite insertion preserve ownership and credits;
+retry allocates each item once. Focused shop tests, purchase race checks and
+vet pass. The final complete tracked Go suite passed (server 719 seconds,
+gamedata 8 seconds); purchase race checks passed in 103 seconds.
+
+Actual HTTPS WASM clients on the GPU bought upgrades from Omni, Clan and
+neutral terminals. At effective Computer Literacy 40, the six-item Omni basket
+cost 51881; an Arrow cost 347 there and 364 at Clan/neutral terminals. Native
+quotes and paid balances matched. All five purchased upgrades uploaded, while
+an extra Arrow and a low-skill buyer's paid Arrow remained owned on rejection.
+Cold server/client recovery retained map flags, balances and durable IDs; a
+recovered purchased Arrow could then be used after raising Map Navigation.
+Nineteen native/SQLite snapshots and five draft totals agree, with no browser
+errors. `local/map-shop-smoke/` retains screenshots, warm/cold WebSocket traces,
+native snapshots, database snapshots and the assertion script. Both test clients
+are closed. Cleanup removed only the two owned players and three remaining
+items; unrelated rows were unchanged and SQLite integrity/foreign-key checks
+passed. The sole shared HTTPS preview remains on port 8443.
diff --git a/server/gamedata/shop_stock.yaml b/server/gamedata/shop_stock.yaml
@@ -36,3 +36,9 @@
99481: [25812, 85366, 25820]
99508: [25812, 85366, 25820]
99574: [25812, 85366, 25820]
+
+# Maps: the five original reader upgrades. Fixed subset, not recovered TIAM stock.
+# Shipped map-window help and original upgrade contracts; see docs/shops.md.
+117649: [116683, 116684, 116685, 116692, 116694]
+117749: [116683, 116684, 116685, 116692, 116694]
+118050: [116683, 116684, 116685, 116692, 116694]
diff --git a/server/map_purchases_test.go b/server/map_purchases_test.go
@@ -0,0 +1,216 @@
+package main
+
+import (
+ "ao/server/gamedata"
+ "encoding/binary"
+ "reflect"
+ "slices"
+ "testing"
+)
+
+func newMapPurchaseWorld(t *testing.T) (*server, *combatTestConn) {
+ t.Helper()
+ world, conn := newPurchaseWorld(t)
+ player := world.characters[1]
+ machine := gamedata.ShopMachines[3221685407]
+ player.playfield, player.position = machine.Playfield, machine.Position
+ player.inventory.Credits = 100000
+ player.stats.Navigation.MapNavigation = 700
+ if err := world.saveUser_locked(player); err != nil {
+ t.Fatal(err)
+ }
+ if err := world.saveInventory_locked(player, player.inventory); err != nil {
+ t.Fatal(err)
+ }
+ request := shopUseRequest(2)
+ binary.BigEndian.PutUint32(request[44:48], 3221685407)
+ if err := world.handleShopUse(world.clients[1], request); err != nil {
+ t.Fatal(err)
+ }
+ return world, conn
+}
+
+func TestMapTerminalsExposeOnlyTheSupportedReaderUpgradeSubset(t *testing.T) {
+ for _, identity := range []uint32{3223848092, 3221750941, 3223913630, 3221685407, 3225552032, 3222602913, 3222537378, 3221226659} {
+ world, conn := newCombatWorld()
+ player, client := world.characters[1], world.clients[1]
+ machine, exists := gamedata.ShopMachines[identity]
+ if !exists {
+ t.Fatal("missing original map placement", identity)
+ }
+ player.playfield, player.position = machine.Playfield, machine.Position
+ // The original faction action0 does not restrict vending Use action3.
+ player.appearance = 0x115
+ request := shopUseRequest(1)
+ binary.BigEndian.PutUint32(request[44:48], identity)
+
+ err := world.handleShopUse(client, request)
+
+ expected := []uint32{116683, 116684, 116685, 116692, 116694}
+ if err != nil || client.shop == nil || !slices.Equal(client.shop.stock, expected) || len(conn.packets) != 5 {
+ t.Fatal("wrong map-terminal catalog", identity, err)
+ }
+ packet := conn.packets[2]
+ if len(packet) != 96 || binary.BigEndian.Uint32(packet[16:20]) != 0x58362220 || binary.BigEndian.Uint32(packet[24:28]) != identity || binary.BigEndian.Uint32(packet[29:33]) != 6054 {
+ t.Fatal("wrong map ShopUpdate owner/count", identity)
+ }
+ for index, template := range expected {
+ for field, value := range []uint32{template, template, 1} {
+ if binary.BigEndian.Uint32(packet[33+12*index+4*field:]) != value {
+ t.Fatal("wrong fixed upgrade template/quality", identity, index, field)
+ }
+ }
+ }
+ }
+ for template, stock := range gamedata.ShopStock {
+ for _, item := range stock {
+ if slices.Contains([]uint32{116683, 116684, 116685, 116692, 116694}, item) && template != 117649 && template != 117749 && template != 118050 {
+ t.Fatal("reader upgrade leaked into another terminal family", template)
+ }
+ }
+ }
+}
+
+func TestMapPurchaseDeliversAllFiveUpgradesThenUploadsExactlyOnce(t *testing.T) {
+ world, conn := newMapPurchaseWorld(t)
+ client, player := world.clients[1], world.characters[1]
+ for _, index := range []uint32{4, 0, 1, 2, 3, 4} {
+ if err := world.handleShopTrade(client, shopTradePacket([2]uint32{50000, 1}, 4, [2]uint32{51035, 3221685407}, [2]uint32{111, index})[20:]); err != nil {
+ t.Fatal(err)
+ }
+ }
+ conn.packets = nil
+
+ err := world.handleShopTrade(client, shopTradePacket([2]uint32{50000, 1}, 1, [2]uint32{}, [2]uint32{})[20:])
+ purchased := newTestInventoryServer(t).characters[1].inventory
+
+ if err != nil || purchased.Credits != 48119 || len(purchased.Items) != 7 || world.nextItem != 7 || len(conn.packets) != 8 {
+ t.Fatal("upgrade basket cash/ownership/delivery mismatch", err, purchased)
+ }
+ for index, template := range []uint32{116683, 116684, 116685, 116692, 116694, 116694} {
+ expected := ownedItem{ID: uint32(index + 2), Type: 51005, Template: template, Quality: 1, Slot: uint32(index + 65), Count: 1}
+ if purchased.Items[index+1] != expected {
+ t.Fatal("map package lost its single charge or durable identity", purchased.Items[index+1])
+ }
+ packet := conn.packets[index+1]
+ if len(packet) != 48 || binary.BigEndian.Uint32(packet[16:20]) != 0x052e2f0c {
+ t.Fatal("wrong upgrade delivery packet")
+ }
+ for field, value := range []uint32{template, template, 1, 1} {
+ if binary.BigEndian.Uint32(packet[29+field*4:]) != value {
+ t.Fatal("map AddTemplate lost its one-charge contract")
+ }
+ }
+ }
+
+ // Consume the purchased upgrades, replay each request, then try the spare.
+ for index := range 6 {
+ request := backpackUseRequest(1, uint32(index+65), uint32(index+3))[20:]
+ if err := world.handleOwnedItemUse(client, request); err != nil {
+ t.Fatal(err)
+ }
+ world.handleOwnedItemUse(client, request)
+ }
+ restored := newTestInventoryServer(t).characters[1].inventory
+
+ if restored.MapFlags != [3]uint32{31, 0, 0} || restored.Credits != 48119 || len(restored.Items) != 2 ||
+ restored.Items[1] != (ownedItem{ID: 7, Type: 51005, Template: 116694, Quality: 1, Slot: 70, Count: 1}) || !reflect.DeepEqual(restored, player.inventory) {
+ t.Fatal("purchase/upload/replay lost knowledge, cash or the rejected spare", restored)
+ }
+}
+
+func TestMapPurchaseDoesNotApplyUploadSkillRequirementsAtCheckout(t *testing.T) {
+ world, _ := newMapPurchaseWorld(t)
+ client, player := world.clients[1], world.characters[1]
+ player.stats.Navigation.MapNavigation = 0
+ if err := world.saveUser_locked(player); err != nil {
+ t.Fatal(err)
+ }
+ for _, request := range [][]byte{
+ shopTradePacket([2]uint32{50000, 1}, 4, [2]uint32{51035, 3221685407}, [2]uint32{111, 4})[20:],
+ shopTradePacket([2]uint32{50000, 1}, 1, [2]uint32{}, [2]uint32{})[20:],
+ } {
+ if err := world.handleShopTrade(client, request); err != nil {
+ t.Fatal(err)
+ }
+ }
+
+ err := world.handleOwnedItemUse(client, backpackUseRequest(1, 65, 3)[20:])
+ restored := newTestInventoryServer(t).characters[1].inventory
+
+ if err != nil || restored.Credits != 99653 || restored.MapFlags != [3]uint32{} || len(restored.Items) != 2 || restored.Items[1].Template != 116694 || restored.Items[1].Count != 1 {
+ t.Fatal("low skill blocked purchase or consumed the rejected upload", err, restored)
+ }
+}
+
+func TestMapPurchaseRollbackKeepsBasketRetryableWithoutPartialOwnership(t *testing.T) {
+ world, conn := newMapPurchaseWorld(t)
+ client, player := world.clients[1], world.characters[1]
+ for _, index := range []uint32{3, 4} {
+ world.handleShopTrade(client, shopTradePacket([2]uint32{50000, 1}, 4, [2]uint32{51035, 3221685407}, [2]uint32{111, index})[20:])
+ }
+ if _, err := world.db.Exec("CREATE TRIGGER reject_map BEFORE INSERT ON items WHEN NEW.id=3 BEGIN SELECT RAISE(FAIL, 'second map'); END"); err != nil {
+ t.Fatal(err)
+ }
+ conn.packets = nil
+ accept := shopTradePacket([2]uint32{50000, 1}, 1, [2]uint32{}, [2]uint32{})[20:]
+
+ failed := world.handleShopTrade(client, accept)
+ rejected := newTestInventoryServer(t).characters[1].inventory
+
+ if failed == nil || rejected.Credits != 100000 || len(rejected.Items) != 1 || !reflect.DeepEqual(rejected, player.inventory) || world.nextItem != 1 || len(conn.packets) != 0 || client.shop == nil {
+ t.Fatal("failed map basket published partial state", rejected)
+ }
+ if _, err := world.db.Exec("DROP TRIGGER reject_map"); err != nil {
+ t.Fatal(err)
+ }
+
+ err := world.handleShopTrade(client, accept)
+ restored := newTestInventoryServer(t).characters[1].inventory
+
+ if err != nil || restored.Credits != 98464 || len(restored.Items) != 3 || restored.Items[1].ID != 2 || restored.Items[2].ID != 3 || restored.Items[1].Template != 116692 || restored.Items[2].Template != 116694 || world.nextItem != 3 {
+ t.Fatal("map basket retry duplicated or lost ownership", err, restored)
+ }
+}
+
+func TestMapPurchaseRejectedOrAbandonedBasketPreservesCashAndItems(t *testing.T) {
+ for _, scenario := range []string{"full inventory", "cash changed", "cancel", "remove", "unknown row"} {
+ t.Run(scenario, func(t *testing.T) {
+ world, _ := newMapPurchaseWorld(t)
+ client, player := world.clients[1], world.characters[1]
+ add := shopTradePacket([2]uint32{50000, 1}, 4, [2]uint32{51035, 3221685407}, [2]uint32{111, 4})[20:]
+ if err := world.handleShopTrade(client, add); err != nil {
+ t.Fatal(err)
+ }
+ request := shopTradePacket([2]uint32{50000, 1}, 1, [2]uint32{}, [2]uint32{})[20:]
+ switch scenario {
+ case "full inventory":
+ for slot := uint32(65); slot < 94; slot++ {
+ player.inventory.Items = append(player.inventory.Items, ownedItem{ID: slot - 63, Type: 51005, Template: 116694, Quality: 1, Slot: slot, Count: 1})
+ }
+ player.inventory.LastID = 30
+ case "cash changed":
+ player.inventory.Credits = 346
+ case "cancel":
+ request = shopTradePacket([2]uint32{50000, 1}, 2, [2]uint32{}, [2]uint32{})[20:]
+ case "remove":
+ world.handleShopTrade(client, shopTradePacket([2]uint32{50000, 1}, 5, [2]uint32{51035, 3221685407}, [2]uint32{111, 4})[20:])
+ case "unknown row":
+ request = shopTradePacket([2]uint32{50000, 1}, 4, [2]uint32{51035, 3221685407}, [2]uint32{111, 5})[20:]
+ }
+ if err := world.saveInventory_locked(player, player.inventory); err != nil {
+ t.Fatal(err)
+ }
+ before := player.inventory
+ before.Items = slices.Clone(before.Items)
+ next := world.nextItem
+
+ err := world.handleShopTrade(client, request)
+ restored := newTestInventoryServer(t).characters[1].inventory
+
+ if err != nil || client.shop != nil || !reflect.DeepEqual(restored, before) || !reflect.DeepEqual(player.inventory, before) || world.nextItem != next {
+ t.Fatal("map rejection or cancellation changed cash/ownership", err, restored)
+ }
+ })
+ }
+}
diff --git a/server/shop_machines_test.go b/server/shop_machines_test.go
@@ -58,8 +58,13 @@ func TestShopUseEvaluatesAuthoredAccessContracts(t *testing.T) {
t.Fatalf("shop admission = %v, want %v", client.shop != nil, scenario.accepted)
}
if scenario.accepted {
- if len(conn.packets) != 4 || client.shop.machine != scenario.machine || binary.BigEndian.Uint32(conn.packets[3][41:45]) != scenario.machine ||
- binary.BigEndian.Uint32(conn.packets[3][45:49]) != 111 || binary.BigEndian.Uint32(conn.packets[3][49:53]) != 0 {
+ packets := 4
+ if scenario.machine == 3221685407 {
+ packets = 5
+ }
+ start := conn.packets[len(conn.packets)-1]
+ if len(conn.packets) != packets || client.shop.machine != scenario.machine || binary.BigEndian.Uint32(start[41:45]) != scenario.machine ||
+ binary.BigEndian.Uint32(start[45:49]) != 111 || binary.BigEndian.Uint32(start[49:53]) != 0 {
t.Fatal("opened the wrong shop contract")
}
} else if len(conn.packets) != 1 || binary.BigEndian.Uint32(conn.packets[0][29:33]) != 2 {
diff --git a/server/shop_purchases_test.go b/server/shop_purchases_test.go
@@ -71,7 +71,7 @@ func TestShopKnownStockOnlyAdmitsSupportedFixedTemplateItems(t *testing.T) {
}
item := ownedItem{Type: definition.HeaderWords[0], Template: template}
charges := int32(itemStat(definition, 212))
- if (item.isStackable() && (charges < 1 || charges > 65535)) || (!item.isStackable() && charges > 0) {
+ if (item.isStackable() && (charges < 1 || charges > 65535)) || (!item.isStackable() && charges > 1) {
t.Fatalf("stock %d cannot represent its authored package count %d", template, charges)
}
}