48 lines
1.5 KiB
Go
48 lines
1.5 KiB
Go
package snapshot7_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/teeworlds-go/go-teeworlds-protocol/internal/testutils/require"
|
|
"github.com/teeworlds-go/go-teeworlds-protocol/protocol7"
|
|
)
|
|
|
|
func TestRepackSnapshot(t *testing.T) {
|
|
// snapshot captured with tcpdump
|
|
// generated by a vanilla teeworlds 0.7.5 server
|
|
// used the go-teeworlds-protocol sample client to connect to the server
|
|
// the package is compressed so the raw bytes are a bit non obvious to look at
|
|
//
|
|
// libtw2 dissector details
|
|
// Teeworlds 0.7 Protocol packet
|
|
// Teeworlds 0.7 Protocol chunk: sys.snap_single
|
|
// Header (non-vital)
|
|
// Message: sys.snap_single
|
|
// Tick: 1510
|
|
// Delta tick: 1511
|
|
// Crc: 16269
|
|
// Data (103 bytes)
|
|
//
|
|
dump := []byte{
|
|
0x10, 0x04, 0x01, 0x01, 0x02, 0x03, 0x04,
|
|
0xe8, 0x93, 0x29, 0x4b, 0x7c, 0x18, 0xe2, 0xe3, 0x47, 0x0d, 0x46, 0x86, 0xb0, 0xbc, 0xd7,
|
|
0x24, 0x0d, 0x93, 0x5e, 0x0f, 0x4d, 0xf2, 0x31, 0xe9, 0x09, 0x4f, 0x98, 0x84, 0x98, 0xf4, 0x2c,
|
|
0x3c, 0x0b, 0x93, 0x3c, 0x4d, 0x7a, 0x9e, 0xe7, 0x06, 0xeb, 0x9b, 0x49, 0x0f, 0xed, 0x61, 0xb9,
|
|
0xb0, 0x5e, 0x3b, 0x9a, 0x84, 0x87, 0xf5, 0xd0, 0x26, 0x54, 0x37, 0xec, 0x76, 0x92, 0x37, 0xef,
|
|
0xf5, 0x0d, 0x3e, 0x26, 0xe5, 0x54, 0xbc, 0x40, 0x5c, 0x69, 0x93, 0x72, 0x58, 0x6f, 0x7d, 0x3d,
|
|
0xde, 0x3f, 0x59, 0x71, 0x03,
|
|
}
|
|
|
|
conn := protocol7.Session{}
|
|
|
|
packet := protocol7.Packet{}
|
|
err := packet.Unpack(dump)
|
|
require.NoError(t, err)
|
|
|
|
conn.Ack = packet.Header.Ack
|
|
repack := packet.Pack(&conn)
|
|
require.Equal(t, dump, repack)
|
|
|
|
// TODO: test if snap items were parsed correctly
|
|
}
|