From c7a7a341bbfe2d2e367c1adce505d15541e1a570 Mon Sep 17 00:00:00 2001 From: Sandertv Date: Fri, 22 Mar 2024 17:46:45 +0100 Subject: [PATCH] Allowed gt to receive resourcepacksinfo packet before playstatus (requires a change in the expected packets in several places I believe), always send all packs downloaded and ignore the resource pack stack packet --- config.toml | 2 +- go.mod | 6 ++++-- go.sum | 9 +++++++-- minecraft/conn.go | 24 ++++++++++++++---------- minecraft/dial.go | 4 ++-- 5 files changed, 28 insertions(+), 17 deletions(-) diff --git a/config.toml b/config.toml index e2a22bc4..6a60c936 100644 --- a/config.toml +++ b/config.toml @@ -1,4 +1,4 @@ [Connection] LocalAddress = "0.0.0.0:19132" - RemoteAddress = "" + RemoteAddress = "play.enchanted.gg:19132" diff --git a/go.mod b/go.mod index 0724260e..4dbccacf 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,8 @@ module github.com/sandertv/gophertunnel -go 1.19 +go 1.21.0 + +toolchain go1.22.1 require ( github.com/go-gl/mathgl v1.0.0 @@ -10,7 +12,7 @@ require ( github.com/klauspost/compress v1.15.1 github.com/muhammadmuzzammil1998/jsonc v1.0.0 github.com/pelletier/go-toml v1.9.4 - github.com/sandertv/go-raknet v1.12.0 + github.com/sandertv/go-raknet v1.13.0 golang.org/x/net v0.7.0 golang.org/x/oauth2 v0.4.0 golang.org/x/text v0.7.0 diff --git a/go.sum b/go.sum index 8ed1a6a3..142566bf 100644 --- a/go.sum +++ b/go.sum @@ -27,8 +27,12 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/sandertv/go-raknet v1.12.0 h1:olUzZlIJyX/pgj/mrsLCZYjKLNDsYiWdvQ4NIm3z0DA= github.com/sandertv/go-raknet v1.12.0/go.mod h1:Gx+WgZBMQ0V2UoouGoJ8Wj6CDrMBQ4SB2F/ggpl5/+Y= +github.com/sandertv/go-raknet v1.12.1 h1:CXDfeXGaQD8kwlatlaAS1wQsMBLLGlDSH6upZv28Pss= +github.com/sandertv/go-raknet v1.12.1/go.mod h1:Gx+WgZBMQ0V2UoouGoJ8Wj6CDrMBQ4SB2F/ggpl5/+Y= +github.com/sandertv/go-raknet v1.13.0 h1:Jkovqz4FrBP7PCIBBirBRoWm7mQKNP/UTYbOOyBK1TY= +github.com/sandertv/go-raknet v1.13.0/go.mod h1:E/DgMFQUMvWOvXwQRLEsTNOoYqzNubfcgzqL0nMoPso= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= +github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE= @@ -78,5 +82,6 @@ google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/square/go-jose.v2 v2.6.0 h1:NGk74WTnPKBNUhNzQX7PYcTLUjoq7mzKk2OKbvwk2iI= +gopkg.in/square/go-jose.v2 v2.6.0/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/minecraft/conn.go b/minecraft/conn.go index ce1cbc39..35a66fb1 100644 --- a/minecraft/conn.go +++ b/minecraft/conn.go @@ -894,15 +894,16 @@ func (conn *Conn) handleResourcePacksInfo(pk *packet.ResourcePacksInfo) error { } } - if len(packsToDownload) != 0 { - conn.expect(packet.IDResourcePackDataInfo, packet.IDResourcePackChunkData) - _ = conn.WritePacket(&packet.ResourcePackClientResponse{ - Response: packet.PackResponseSendPacks, - PacksToDownload: packsToDownload, - }) - return nil - } - conn.expect(packet.IDResourcePackStack) + // if len(packsToDownload) != 0 { + // fmt.Println(packsToDownload) + // conn.expect(packet.IDResourcePackDataInfo, packet.IDResourcePackChunkData, packet.IDPlayStatus, packet.IDResourcePacksInfo) + // _ = conn.WritePacket(&packet.ResourcePackClientResponse{ + // Response: packet.PackResponseSendPacks, + // PacksToDownload: packsToDownload, + // }) + // return nil + // } + conn.expect(packet.IDResourcePackStack, packet.IDPlayStatus) _ = conn.WritePacket(&packet.ResourcePackClientResponse{Response: packet.PackResponseAllPacksDownloaded}) return nil @@ -911,6 +912,9 @@ func (conn *Conn) handleResourcePacksInfo(pk *packet.ResourcePacksInfo) error { // handleResourcePackStack handles a ResourcePackStack packet sent by the server. The stack defines the order // that resource packs are applied in. func (conn *Conn) handleResourcePackStack(pk *packet.ResourcePackStack) error { + conn.expect(packet.IDStartGame) + _ = conn.WritePacket(&packet.ResourcePackClientResponse{Response: packet.PackResponseCompleted}) + return nil // We currently don't apply resource packs in any way, so instead we just check if all resource packs in // the stacks are also downloaded. for _, pack := range pk.TexturePacks { @@ -1326,7 +1330,7 @@ func (conn *Conn) handlePlayStatus(pk *packet.PlayStatus) error { return fmt.Errorf("error sending client cache status: %v", err) } // The next packet we expect is the ResourcePacksInfo packet. - conn.expect(packet.IDResourcePacksInfo) + conn.expect(packet.IDResourcePacksInfo, packet.IDResourcePackStack) return conn.Flush() case packet.PlayStatusLoginFailedClient: _ = conn.Close() diff --git a/minecraft/dial.go b/minecraft/dial.go index b1a03a5d..82353b59 100644 --- a/minecraft/dial.go +++ b/minecraft/dial.go @@ -220,7 +220,7 @@ func (d Dialer) DialContext(ctx context.Context, network, address string) (conn l, c := make(chan struct{}), make(chan struct{}) go listenConn(conn, d.ErrorLog, l, c) - conn.expect(packet.IDNetworkSettings, packet.IDPlayStatus) + conn.expect(packet.IDNetworkSettings) if err := conn.WritePacket(&packet.RequestNetworkSettings{ClientProtocol: d.Protocol.ID()}); err != nil { return nil, err } @@ -233,7 +233,7 @@ func (d Dialer) DialContext(ctx context.Context, network, address string) (conn return nil, conn.wrap(ctx.Err(), "dial") case <-l: // We've received our network settings, so we can now send our login request. - conn.expect(packet.IDServerToClientHandshake, packet.IDPlayStatus) + conn.expect(packet.IDServerToClientHandshake, packet.IDPlayStatus, packet.IDResourcePacksInfo) if err := conn.WritePacket(&packet.Login{ConnectionRequest: request, ClientProtocol: d.Protocol.ID()}); err != nil { return nil, err }