Skip to content

Commit

Permalink
fix: Resource pack response disconnects
Browse files Browse the repository at this point in the history
  • Loading branch information
robinbraemer committed Mar 14, 2023
1 parent cfbebd9 commit f5bdd12
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
4 changes: 2 additions & 2 deletions pkg/edition/java/proto/packet/resourcepack.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const (
)

func (r *ResourcePackResponse) Encode(c *proto.PacketContext, wr io.Writer) error {
if c.Protocol.GreaterEqual(version.Minecraft_1_19) {
if c.Protocol.LowerEqual(version.Minecraft_1_9_4) {
err := util.WriteString(wr, r.Hash)
if err != nil {
return err
Expand All @@ -114,7 +114,7 @@ func (r *ResourcePackResponse) Encode(c *proto.PacketContext, wr io.Writer) erro
}

func (r *ResourcePackResponse) Decode(c *proto.PacketContext, rd io.Reader) (err error) {
if c.Protocol.GreaterEqual(version.Minecraft_1_19) {
if c.Protocol.LowerEqual(version.Minecraft_1_9_4) {
r.Hash, err = util.ReadString(rd)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion pkg/edition/java/proxy/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ func (p *connectedPlayer) Disconnect(reason component.Component) {
}

if netmc.CloseWith(p, packet.DisconnectWithProtocol(reason, p.Protocol())) == nil {
p.log.Info("Player has been disconnected", "reason", r)
p.log.Info("player has been disconnected", "reason", r)
}
}

Expand Down
17 changes: 14 additions & 3 deletions pkg/edition/java/proxy/session_backend_play.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,12 @@ func (b *backendPlaySessionHandler) handleResourcePacketRequest(p *packet.Resour
}

if p.Hash != "" && sha1HexRegex.MatchString(p.Hash) {
packInfo.Hash, _ = hex.DecodeString(p.Hash)
var err error
packInfo.Hash, err = hex.DecodeString(p.Hash)
if err != nil {
b.serverConn.log.V(1).Error(err, "error decoding resource pack hash")
return
}
}

e := &ServerResourcePackSendEvent{
Expand All @@ -255,12 +260,18 @@ func (b *backendPlaySessionHandler) handleResourcePacketRequest(p *packet.Resour
toSend.Origin = DownstreamServerResourcePackOrigin
}

_ = b.serverConn.player.queueResourcePack(toSend)
err := b.serverConn.player.queueResourcePack(toSend)
if err != nil {
b.serverConn.log.V(1).Error(err, "error queuing resource pack")
}
} else if smc, ok := b.serverConn.ensureConnected(); ok {
_ = smc.WritePacket(&packet.ResourcePackResponse{
err := smc.WritePacket(&packet.ResourcePackResponse{
Hash: p.Hash,
Status: DeclinedResourcePackResponseStatus,
})
if err != nil {
b.serverConn.log.V(1).Error(err, "error sending resource pack response")
}
}
}

Expand Down

1 comment on commit f5bdd12

@NecrossIT
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was me a pleasure helping you with that <3

Sincerely Cerberus.PRCLK#7121

Please sign in to comment.