aorecomp

Anarchy Online classic in the browser

git clone https://aorecomp.ubeagle.com/code/aorecomp.git


server/bank_attachment_test.go (2072B)


      1 package main
      2 
      3 import (
      4 	"bytes"
      5 	"encoding/binary"
      6 	"reflect"
      7 	"testing"
      8 )
      9 
     10 func TestBankOpeningDoesNotAttachStoredBackpackToCharacterSlots(t *testing.T) {
     11 	for _, row := range []struct {
     12 		name               string
     13 		itemSlot, bankSlot uint32
     14 	}{
     15 		{"worn weapon", 6, 6},
     16 		{"first carried row", 64, 48},
     17 		{"last carried row", 93, 77},
     18 	} {
     19 		t.Run(row.name, func(t *testing.T) {
     20 			world, output := newEquipmentWorld(t)
     21 			player, client := world.characters[1], world.clients[1]
     22 			player.playfield, player.position = 705, [3]float32{985, 20.2001, 580}
     23 			if err := world.saveUser(player); err != nil {
     24 				t.Fatal(err)
     25 			}
     26 			inventory := player.inventory
     27 			inventory.LastID = 2
     28 			inventory.Items = []ownedItem{{ID: 1, Type: 51018, Template: 209283, Quality: 1, Slot: row.itemSlot, Count: 1}}
     29 			inventory.Bank = []ownedItem{{ID: 2, Type: 51017, Template: 99228, Quality: 1, Slot: row.bankSlot, Count: 1}}
     30 			if err := world.saveInventory(player, inventory); err != nil {
     31 				t.Fatal(err)
     32 			}
     33 			before, err := readTestItemStore(world)
     34 			if err != nil {
     35 				t.Fatal(err)
     36 			}
     37 			auditCheckpointWrites(t, world)
     38 			output.packets = nil
     39 
     40 			if err := world.handleTerminalUse(client, bankUseRequest(1)[20:]); err != nil {
     41 				t.Fatal(err)
     42 			}
     43 			after, err := readTestItemStore(world)
     44 			cold := newTestInventoryServer(t)
     45 
     46 			if err != nil || !bytes.Equal(before, after) || len(checkpointWrites(t, world)) != 0 ||
     47 				!reflect.DeepEqual(player.inventory, inventory) || !reflect.DeepEqual(cold.characters[1].inventory, inventory) ||
     48 				world.nextItem != 2 || cold.nextItem != 2 {
     49 				t.Fatal("bank opening wrote state or changed either physical instance", err)
     50 			}
     51 			if len(output.packets) != 2 || binary.BigEndian.Uint32(output.packets[0][16:20]) != 0x52526858 ||
     52 				binary.BigEndian.Uint32(output.packets[1][16:20]) != 0x343c287f ||
     53 				binary.BigEndian.Uint32(output.packets[1][45:49]) != row.bankSlot || binary.BigEndian.Uint32(output.packets[1][57:61]) != 2 {
     54 				t.Fatal("bank opening added a live item to the ordinary character inventory")
     55 			}
     56 		})
     57 	}
     58 }