Phase8
Some checks failed
CI / Node — lint, typecheck, test, build (push) Failing after 9s
CI / Go — node-agent tests (push) Failing after 9s
CI / Go — edge-gateway build (push) Successful in 17s

This commit is contained in:
smueller
2026-06-26 13:33:03 +02:00
parent ab21f53cdd
commit b335f6a497
39 changed files with 1477 additions and 20 deletions

View File

@@ -0,0 +1,59 @@
package mc
import (
"bytes"
"testing"
)
func TestExtractSlug(t *testing.T) {
if got := ExtractSlug("abc.play.example.net", "play.example.net"); got != "abc" {
t.Fatalf("got %q want abc", got)
}
if got := ExtractSlug("other.net", "play.example.net"); got != "" {
t.Fatalf("expected empty slug")
}
}
func TestReadHandshake(t *testing.T) {
var payload bytes.Buffer
writeVarInt(&payload, 0)
writeVarInt(&payload, 763)
writeString(&payload, "demo.play.example.net")
payload.WriteByte(0x63)
payload.WriteByte(0xdd)
writeVarInt(&payload, 2)
var packet bytes.Buffer
writeVarInt(&packet, int32(payload.Len()))
packet.Write(payload.Bytes())
hs, err := ReadHandshake(&packet)
if err != nil {
t.Fatalf("read handshake: %v", err)
}
if hs.ServerAddress != "demo.play.example.net" {
t.Fatalf("address %q", hs.ServerAddress)
}
if hs.ServerPort != 25565 {
t.Fatalf("port %d", hs.ServerPort)
}
}
func writeVarInt(buf *bytes.Buffer, value int32) {
for {
temp := byte(value & 0x7F)
value >>= 7
if value != 0 {
temp |= 0x80
}
buf.WriteByte(temp)
if value == 0 {
break
}
}
}
func writeString(buf *bytes.Buffer, value string) {
writeVarInt(buf, int32(len(value)))
buf.WriteString(value)
}