aorecomp

Anarchy Online classic in the browser

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


server/simple_item_protocol_test.go (1722B)


      1 package main
      2 
      3 import (
      4 	"bytes"
      5 	"encoding/binary"
      6 	"testing"
      7 )
      8 
      9 func TestTargetSimpleItemFullUpdatePlacement(t *testing.T) {
     10 	for _, row := range []struct {
     11 		name             string
     12 		page, slot, want byte
     13 	}{
     14 		{"first carried", 104, 64, 48},
     15 		{"last carried", 104, 93, 77},
     16 		{"first free", 104, 111, 111},
     17 		{"out of range", 104, 94, 94},
     18 		{"bank", 105, 64, 64},
     19 		{"backpack", 107, 64, 64},
     20 	} {
     21 		t.Run(row.name, func(t *testing.T) {
     22 			var body []byte
     23 			for _, value := range []uint32{11, 50000, 1, 950, 0, 0} {
     24 				body = binary.BigEndian.AppendUint32(body, value)
     25 			}
     26 			body = append(body, row.page, row.slot)
     27 			for _, value := range []uint32{1009, 4} {
     28 				body = binary.BigEndian.AppendUint32(body, value)
     29 			}
     30 			body = append(body, 'K', 'e', 'y', 0)
     31 
     32 			packet := targetPacket(n3Packet(0x3b11256f, 51053, 7, body))
     33 			packet = packet[:binary.BigEndian.Uint16(packet[6:8])]
     34 
     35 			if packet[53] != row.page || packet[54] != row.want || !bytes.Equal(packet[55:], body[26:]) ||
     36 				binary.BigEndian.Uint32(packet[20:24]) != 51053 || binary.BigEndian.Uint32(packet[24:28]) != 7 {
     37 				t.Fatalf("generic SimpleItem changed identity, placement or name bytes: %x", packet)
     38 			}
     39 		})
     40 	}
     41 }
     42 
     43 func TestTargetWorldSimpleItemPreservesTransform(t *testing.T) {
     44 	body := simpleItemBody(28577, 950, [3]float32{}, [4]float32{0, 0, 0, 1}, nil)
     45 	// These opaque quaternion bytes resemble an ordinary page/slot pair.
     46 	binary.BigEndian.PutUint32(body[24:28], 0x68400000)
     47 
     48 	packet := targetPacket(n3Packet(0x3b11256f, 51053, 7, body))
     49 	packet = packet[:binary.BigEndian.Uint16(packet[6:8])]
     50 
     51 	if !bytes.Equal(packet[29:], body) {
     52 		t.Fatalf("parentless SimpleItem transform was treated as inventory placement: %x", packet)
     53 	}
     54 }