server/depleted_stack_split_test.go (2296B)
1 package main 2 3 import ( 4 "bytes" 5 "encoding/binary" 6 "fmt" 7 "reflect" 8 "testing" 9 ) 10 11 func TestDepletedStackSplitCorrectsWithoutWriting(t *testing.T) { 12 for _, slot := range []uint32{64, 93} { 13 t.Run(fmt.Sprint(slot), func(t *testing.T) { 14 world, output := newStackWorld(t) 15 player, client := world.characters[1], world.clients[1] 16 inventory := playerInventory{LastID: 2, Items: []ownedItem{ 17 {ID: 1, Type: 51018, Template: 209283, Quality: 1, Slot: 6, Count: 1}, 18 {ID: 2, Type: 51005, Template: 25812, Quality: 2, Slot: slot, Count: 1}}} 19 if err := world.saveInventory(player, inventory); err != nil { 20 t.Fatal(err) 21 } 22 before, err := readTestItemStore(world) 23 if err != nil { 24 t.Fatal(err) 25 } 26 auditCheckpointWrites(t, world) 27 request := stackActionPacket(1, 52, slot, 1)[20:] 28 29 for range 2 { 30 output.packets = nil 31 if err := world.handleInventory(client, request); err != nil { 32 t.Fatal(err) 33 } 34 35 count := 31 36 if slot == 93 { 37 count++ 38 } 39 if len(output.packets) != count { 40 t.Fatal("equal-count split did not rebuild the exact ordinary stack page", len(output.packets)) 41 } 42 for index := range 30 { 43 if !bytes.Equal(output.packets[index], targetPacket(characterActionPacket(1, [5]uint32{112, 104, uint32(64 + index)}))) { 44 t.Fatal("correction did not clear only ordinary stack/empty slots", index) 45 } 46 } 47 add := output.packets[30] 48 if binary.BigEndian.Uint32(add[16:20]) != 0x052e2f0c || 49 !bytes.Equal(add[29:45], []byte{0, 0, 100, 212, 0, 0, 100, 211, 0, 0, 0, 2, 0, 0, 0, 1}) { 50 t.Fatal("correction lost selected laboratory endpoints, quality or remaining charge") 51 } 52 if slot == 93 && !bytes.Equal(output.packets[31], targetPacket(itemMovePacket(1, 64, 93))) { 53 t.Fatal("correction did not restore the last logical slot") 54 } 55 } 56 after, err := readTestItemStore(world) 57 cold := newTestInventoryServer(t) 58 if err != nil || !bytes.Equal(before, after) || len(checkpointWrites(t, world)) != 0 || 59 !reflect.DeepEqual(player.inventory, inventory) || !reflect.DeepEqual(cold.characters[1].inventory, inventory) || 60 world.nextItem != 2 || cold.nextItem != 2 { 61 t.Fatal("equal-count correction changed storage, ownership, ammunition or allocation", err) 62 } 63 }) 64 } 65 }