Skip to content

Commit

Permalink
Allowed gt to receive resourcepacksinfo packet before playstatus (req…
Browse files Browse the repository at this point in the history
…uires a change in the expected packets in several places I believe), always send all packs downloaded and ignore the resource pack stack packet
  • Loading branch information
Sandertv committed Mar 22, 2024
1 parent 25a6403 commit c7a7a34
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 17 deletions.
2 changes: 1 addition & 1 deletion config.toml
@@ -1,4 +1,4 @@

[Connection]
LocalAddress = "0.0.0.0:19132"
RemoteAddress = ""
RemoteAddress = "play.enchanted.gg:19132"
6 changes: 4 additions & 2 deletions go.mod
@@ -1,6 +1,8 @@
module github.com/sandertv/gophertunnel

go 1.19
go 1.21.0

Check failure on line 3 in go.mod

View workflow job for this annotation

GitHub Actions / Build

invalid go version '1.21.0': must match format 1.23

toolchain go1.22.1

Check failure on line 5 in go.mod

View workflow job for this annotation

GitHub Actions / Build

unknown directive: toolchain

require (
github.com/go-gl/mathgl v1.0.0
Expand All @@ -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
Expand Down
9 changes: 7 additions & 2 deletions go.sum
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
24 changes: 14 additions & 10 deletions minecraft/conn.go
Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions minecraft/dial.go
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down

0 comments on commit c7a7a34

Please sign in to comment.