Skip to content

Commit

Permalink
Support Minecraft 1.21.2-3 (#411)
Browse files Browse the repository at this point in the history
* Initial upgrade for Minecraft 1.21.2-3

* fix: show disconnect message in login state

* fix: test
  • Loading branch information
robinbraemer authored Oct 25, 2024
1 parent fc11e84 commit 133de6f
Show file tree
Hide file tree
Showing 17 changed files with 164 additions and 62 deletions.
12 changes: 6 additions & 6 deletions .examples/extend/simple-proxy/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
github.com/Tnze/go-mc v1.20.2 // indirect
github.com/agext/levenshtein v1.2.3 // indirect
github.com/coder/websocket v1.8.12 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect
github.com/dboslee/lru v0.0.1 // indirect
github.com/edwingeng/deque/v2 v2.1.1 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
Expand All @@ -30,13 +30,13 @@ require (
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/jellydator/ttlcache/v3 v3.3.0 // indirect
github.com/knadh/koanf/providers/file v1.1.1 // indirect
github.com/knadh/koanf/providers/file v1.1.2 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mitchellh/mapstructure v1.5.1-0.20220423185008-bf980b35cac4 // indirect
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/pires/go-proxyproto v0.7.1-0.20240628150027-b718e7ce4964 // indirect
github.com/pires/go-proxyproto v0.8.0 // indirect
github.com/rs/xid v1.6.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sagikazarmark/locafero v0.6.0 // indirect
Expand All @@ -48,7 +48,7 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.19.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/urfave/cli/v2 v2.27.4 // indirect
github.com/urfave/cli/v2 v2.27.5 // indirect
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
github.com/zyedidia/generic v1.2.1 // indirect
go.minekube.com/connect v0.6.2 // indirect
Expand All @@ -58,8 +58,8 @@ require (
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.24.0 // indirect
golang.org/x/text v0.18.0 // indirect
golang.org/x/time v0.6.0 // indirect
golang.org/x/text v0.19.0 // indirect
golang.org/x/time v0.7.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect
google.golang.org/grpc v1.67.1 // indirect
google.golang.org/protobuf v1.34.2 // indirect
Expand Down
6 changes: 6 additions & 0 deletions .examples/extend/simple-proxy/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ github.com/cpuguy83/go-md2man/v2 v2.0.3 h1:qMCsGGgs+MAzDFyp9LpAe1Lqy/fY/qCovCm0q
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/cpuguy83/go-md2man/v2 v2.0.5/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
Expand Down Expand Up @@ -115,6 +116,7 @@ github.com/knadh/koanf/providers/file v1.1.0 h1:MTjA+gRrVl1zqgetEAIaXHqYje0XSosx
github.com/knadh/koanf/providers/file v1.1.0/go.mod h1:/faSBcv2mxPVjFrXck95qeoyoZ5myJ6uxN8OOVNJJCI=
github.com/knadh/koanf/providers/file v1.1.1 h1:AyYV0SMrEzfw5O3cX5pGmKfq61/bhj19u7OQeFH5AHs=
github.com/knadh/koanf/providers/file v1.1.1/go.mod h1:/faSBcv2mxPVjFrXck95qeoyoZ5myJ6uxN8OOVNJJCI=
github.com/knadh/koanf/providers/file v1.1.2/go.mod h1:/faSBcv2mxPVjFrXck95qeoyoZ5myJ6uxN8OOVNJJCI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
Expand Down Expand Up @@ -151,6 +153,7 @@ github.com/pires/go-proxyproto v0.7.1-0.20231012122632-e5b291b295b4 h1:VM7Tse0I0
github.com/pires/go-proxyproto v0.7.1-0.20231012122632-e5b291b295b4/go.mod h1:hm9CitpinLa2As6mIQh1AzhxHULm1BCYGUTbNcO6f2Q=
github.com/pires/go-proxyproto v0.7.1-0.20240628150027-b718e7ce4964 h1:ct/vxNBgHpASQ4sT8NaBX9LtsEtluZqaUJydLG50U3E=
github.com/pires/go-proxyproto v0.7.1-0.20240628150027-b718e7ce4964/go.mod h1:iknsfgnH8EkjrMeMyvfKByp9TiBZCKZM0jx2xmKqnVY=
github.com/pires/go-proxyproto v0.8.0/go.mod h1:iknsfgnH8EkjrMeMyvfKByp9TiBZCKZM0jx2xmKqnVY=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
Expand Down Expand Up @@ -240,6 +243,7 @@ github.com/urfave/cli/v2 v2.27.3 h1:/POWahRmdh7uztQ3CYnaDddk0Rm90PyOgIxgW2rr41M=
github.com/urfave/cli/v2 v2.27.3/go.mod h1:m4QzxcD2qpra4z7WhzEGn74WZLViBnMpb1ToCAKdGRQ=
github.com/urfave/cli/v2 v2.27.4 h1:o1owoI+02Eb+K107p27wEX9Bb8eqIoZCfLXloLUSWJ8=
github.com/urfave/cli/v2 v2.27.4/go.mod h1:m4QzxcD2qpra4z7WhzEGn74WZLViBnMpb1ToCAKdGRQ=
github.com/urfave/cli/v2 v2.27.5/go.mod h1:3Sevf16NykTbInEnD0yKkjDAeZDS0A6bzhBH5hrMvTQ=
github.com/viant/assertly v0.4.8/go.mod h1:aGifi++jvCrUaklKEKT0BU95igDNaqkvz+49uaYMPRU=
github.com/viant/toolbox v0.24.0/go.mod h1:OxMCG57V0PXuIP2HNQrtJf2CjqdmbrOx5EkMILuUhzM=
github.com/xrash/smetrics v0.0.0-20231213231151-1d8dd44e695e h1:+SOyEddqYF09QP7vr7CgJ1eti3pY9Fn3LHO1M1r/0sI=
Expand Down Expand Up @@ -343,12 +347,14 @@ golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=
golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
golang.org/x/time v0.6.0 h1:eTDhh4ZXt5Qf0augr54TN6suAUudPcawVZeIAPU7D4U=
golang.org/x/time v0.6.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
golang.org/x/time v0.7.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20181030000716-a0a13e073c7b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand Down
12 changes: 0 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk
github.com/coder/websocket v1.8.12 h1:5bUXkEPPIbewrnkU8LTCLVaxi4N4J8ahufH2vlo4NAo=
github.com/coder/websocket v1.8.12/go.mod h1:LNVeNrXQZfe5qhS9ALED3uA+l5pPqvwXg3CKoDBB2gs=
github.com/coreos/go-systemd v0.0.0-20181012123002-c6f51f82210d/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/cpuguy83/go-md2man/v2 v2.0.5 h1:ZtcqGrnekaHpVLArFSe4HK5DoKx1T0rq2DwVB0alcyc=
github.com/cpuguy83/go-md2man/v2 v2.0.5/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -98,8 +96,6 @@ github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.17.2 h1:RlWWUY/Dr4fL8qk9YG7DTZ7PDgME2V4csBXA8L/ixi4=
github.com/klauspost/compress v1.17.2/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
github.com/knadh/koanf/providers/file v1.1.1 h1:AyYV0SMrEzfw5O3cX5pGmKfq61/bhj19u7OQeFH5AHs=
github.com/knadh/koanf/providers/file v1.1.1/go.mod h1:/faSBcv2mxPVjFrXck95qeoyoZ5myJ6uxN8OOVNJJCI=
github.com/knadh/koanf/providers/file v1.1.2 h1:aCC36YGOgV5lTtAFz2qkgtWdeQsgfxUkxDOe+2nQY3w=
github.com/knadh/koanf/providers/file v1.1.2/go.mod h1:/faSBcv2mxPVjFrXck95qeoyoZ5myJ6uxN8OOVNJJCI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
Expand Down Expand Up @@ -130,8 +126,6 @@ github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S
github.com/openzipkin/zipkin-go v0.1.1/go.mod h1:NtoC/o8u3JlF1lSlyPNswIbeQH9bJTmOf0Erfk+hxe8=
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
github.com/pires/go-proxyproto v0.7.1-0.20240628150027-b718e7ce4964 h1:ct/vxNBgHpASQ4sT8NaBX9LtsEtluZqaUJydLG50U3E=
github.com/pires/go-proxyproto v0.7.1-0.20240628150027-b718e7ce4964/go.mod h1:iknsfgnH8EkjrMeMyvfKByp9TiBZCKZM0jx2xmKqnVY=
github.com/pires/go-proxyproto v0.8.0 h1:5unRmEAPbHXHuLjDg01CxJWf91cw3lKHc/0xzKpXEe0=
github.com/pires/go-proxyproto v0.8.0/go.mod h1:iknsfgnH8EkjrMeMyvfKByp9TiBZCKZM0jx2xmKqnVY=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down Expand Up @@ -211,8 +205,6 @@ github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA=
github.com/urfave/cli/v2 v2.27.4 h1:o1owoI+02Eb+K107p27wEX9Bb8eqIoZCfLXloLUSWJ8=
github.com/urfave/cli/v2 v2.27.4/go.mod h1:m4QzxcD2qpra4z7WhzEGn74WZLViBnMpb1ToCAKdGRQ=
github.com/urfave/cli/v2 v2.27.5 h1:WoHEJLdsXr6dDWoJgMq/CboDmyY/8HMMH1fTECbih+w=
github.com/urfave/cli/v2 v2.27.5/go.mod h1:3Sevf16NykTbInEnD0yKkjDAeZDS0A6bzhBH5hrMvTQ=
github.com/viant/assertly v0.4.8/go.mod h1:aGifi++jvCrUaklKEKT0BU95igDNaqkvz+49uaYMPRU=
Expand Down Expand Up @@ -305,14 +297,10 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.6.0 h1:eTDhh4ZXt5Qf0augr54TN6suAUudPcawVZeIAPU7D4U=
golang.org/x/time v0.6.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
golang.org/x/time v0.7.0 h1:ntUhktv3OPE6TgYxXWv9vKvUSJyIFJlyohwbkEwPrKQ=
golang.org/x/time v0.7.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand Down
7 changes: 4 additions & 3 deletions pkg/edition/java/proto/nbtconv/snbt_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/Tnze/go-mc/nbt"
"gopkg.in/yaml.v3"
"io"
"log/slog"
"regexp"
"strconv"
"strings"

"github.com/Tnze/go-mc/nbt"
"gopkg.in/yaml.v3"
)

// formatSNBT adds spaces after colons that are not within quotes.
Expand Down Expand Up @@ -219,7 +220,7 @@ func SnbtToBinaryTag(snbt string) (nbt.RawMessage, error) {

var m nbt.RawMessage
if _, err = dec.Decode(&m); err != nil {
return m, fmt.Errorf("error decoding binary tag: %w", err)
return m, fmt.Errorf("error decoding snbt to binary tag: %w", err)
}
return m, nil
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/edition/java/proto/packet/chat/component_holder.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ package chat
import (
"encoding/json"
"fmt"
"io"
"log/slog"

"github.com/Tnze/go-mc/nbt"
"go.minekube.com/common/minecraft/component"

"go.minekube.com/gate/pkg/edition/java/proto/nbtconv"
"go.minekube.com/gate/pkg/edition/java/proto/util"
"go.minekube.com/gate/pkg/edition/java/proto/version"
"go.minekube.com/gate/pkg/gate/proto"
"io"
"log/slog"
)

func FromComponent(comp component.Component) *ComponentHolder {
Expand Down
18 changes: 14 additions & 4 deletions pkg/edition/java/proto/packet/clientsettings.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package packet

import (
"io"

"go.minekube.com/gate/pkg/edition/java/proto/util"
"go.minekube.com/gate/pkg/edition/java/proto/version"
"go.minekube.com/gate/pkg/gate/proto"
"io"
)

type ClientSettings struct {
Expand All @@ -15,8 +16,9 @@ type ClientSettings struct {
Difficulty byte // 1.7 Protocol
SkinParts byte
MainHand int
ChatFilteringEnabled bool // 1.17+
TextFilteringEnabled bool // 1.17+
ClientListingAllowed bool // 1.18+, overwrites server-list "anonymous" mode
ParticleStatus int // Added in 1.21.2
}

func (s *ClientSettings) Encode(c *proto.PacketContext, wr io.Writer) error {
Expand All @@ -32,10 +34,14 @@ func (s *ClientSettings) Encode(c *proto.PacketContext, wr io.Writer) error {
if c.Protocol.GreaterEqual(version.Minecraft_1_9) {
w.VarInt(s.MainHand)
if c.Protocol.GreaterEqual(version.Minecraft_1_17) {
w.Bool(s.ChatFilteringEnabled)
w.Bool(s.TextFilteringEnabled)
}
if c.Protocol.GreaterEqual(version.Minecraft_1_18) {
w.Bool(s.ClientListingAllowed)

if c.Protocol.GreaterEqual(version.Minecraft_1_21_2) {
w.VarInt(s.ParticleStatus)
}
}
}
return nil
Expand All @@ -54,10 +60,14 @@ func (s *ClientSettings) Decode(c *proto.PacketContext, rd io.Reader) (err error
if c.Protocol.GreaterEqual(version.Minecraft_1_9) {
r.VarInt(&s.MainHand)
if c.Protocol.GreaterEqual(version.Minecraft_1_17) {
r.Bool(&s.ChatFilteringEnabled)
r.Bool(&s.TextFilteringEnabled)
}
if c.Protocol.GreaterEqual(version.Minecraft_1_18) {
r.Bool(&s.ClientListingAllowed)

if c.Protocol.GreaterEqual(version.Minecraft_1_21_2) {
r.VarInt(&s.ParticleStatus)
}
}
}
return nil
Expand Down
16 changes: 8 additions & 8 deletions pkg/edition/java/proto/packet/disconnect.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,35 @@ package packet

import (
"errors"
"io"
"log/slog"

"go.minekube.com/common/minecraft/component"

"go.minekube.com/gate/pkg/edition/java/proto/packet/chat"
"go.minekube.com/gate/pkg/edition/java/proto/state/states"
"io"
"log/slog"

"go.minekube.com/gate/pkg/edition/java/proto/version"
"go.minekube.com/gate/pkg/gate/proto"
)

type Disconnect struct {
Reason *chat.ComponentHolder // nil-able

// Not part of the packet data itself,
// but used to determine the state of the client.
State states.State
}

func (d *Disconnect) Encode(c *proto.PacketContext, wr io.Writer) error {
if d.Reason == nil {
return errors.New("no reason specified")
}
if c.PacketID == 0x00 && c.Direction == proto.ClientBound { // states.LoginState
c.Protocol = version.Minecraft_1_20_2.Protocol
}
return d.Reason.Write(wr, c.Protocol)
}

func (d *Disconnect) Decode(c *proto.PacketContext, rd io.Reader) (err error) {
protocol := c.Protocol
if d.State == states.LoginState {
if c.PacketID == 0x00 && c.Direction == proto.ClientBound { // states.LoginState
protocol = version.Minecraft_1_20_2.Protocol
}
d.Reason, err = chat.ReadComponentHolder(rd, protocol)
Expand All @@ -49,6 +50,5 @@ func NewDisconnect(reason component.Component, protocol proto.Protocol, stat sta
}
return &Disconnect{
Reason: chat.FromComponentProtocol(reason, protocol),
State: stat,
}
}
8 changes: 8 additions & 0 deletions pkg/edition/java/proto/packet/joingame.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type JoinGame struct {
SimulationDistance int // 1.18+
LastDeathPosition *DeathPosition // 1.19+
PortalCooldown int // 1.20+
SeaLevel int // 1.21.2+
EnforcesSecureChat bool // 1.20.5+
}

Expand Down Expand Up @@ -211,6 +212,9 @@ func (j *JoinGame) encode1202Up(c *proto.PacketContext, wr io.Writer) error {
} else {
w.Bool(false)
}
if c.Protocol.GreaterEqual(version.Minecraft_1_21_2) {
w.VarInt(j.SeaLevel)
}
w.VarInt(j.PortalCooldown)
if c.Protocol.GreaterEqual(version.Minecraft_1_20_5) {
w.Bool(j.EnforcesSecureChat)
Expand Down Expand Up @@ -392,6 +396,10 @@ func (j *JoinGame) decode1202Up(c *proto.PacketContext, rd io.Reader) error {
}
}

if c.Protocol.GreaterEqual(version.Minecraft_1_21_2) {
r.VarInt(&j.SeaLevel)
}

r.VarInt(&j.PortalCooldown)
if c.Protocol.GreaterEqual(version.Minecraft_1_20_5) {
r.Bool(&j.EnforcesSecureChat)
Expand Down
7 changes: 7 additions & 0 deletions pkg/edition/java/proto/packet/respawn.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Respawn struct {
CurrentDimensionData util.CompoundBinaryTag // 1.16.2+
LastDeathPosition *DeathPosition // 1.19+
PortalCooldown int // 1.20+
SeaLevel int // 1.21.2+
}

func (r *Respawn) Encode(c *proto.PacketContext, wr io.Writer) (err error) {
Expand Down Expand Up @@ -70,6 +71,9 @@ func (r *Respawn) Encode(c *proto.PacketContext, wr io.Writer) (err error) {
if c.Protocol.GreaterEqual(version.Minecraft_1_20) {
w.VarInt(r.PortalCooldown)
}
if c.Protocol.GreaterEqual(version.Minecraft_1_21_2) {
w.VarInt(r.SeaLevel)
}
if c.Protocol.GreaterEqual(version.Minecraft_1_20_2) {
w.Byte(r.DataToKeep)
}
Expand Down Expand Up @@ -138,6 +142,9 @@ func (r *Respawn) Decode(c *proto.PacketContext, rd io.Reader) (err error) {
if c.Protocol.GreaterEqual(version.Minecraft_1_20) {
pr.VarInt(&r.PortalCooldown)
}
if c.Protocol.GreaterEqual(version.Minecraft_1_21_2) {
pr.VarInt(&r.SeaLevel)
}
if c.Protocol.GreaterEqual(version.Minecraft_1_20_2) {
pr.Byte(&r.DataToKeep)
}
Expand Down
16 changes: 15 additions & 1 deletion pkg/edition/java/proto/packet/tablist/playerinfo/upsert.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ type (
Listed bool
Latency int // in milliseconds
GameMode int
DisplayName *chat.ComponentHolder // nil-able
DisplayName *chat.ComponentHolder // nil-able
ListOrder int
RemoteChatSession *chat.RemoteChatSession // nil-able
}
)
Expand Down Expand Up @@ -103,6 +104,7 @@ var (
UpdateListedAction UpsertAction = &updateListedAction{}
UpdateLatencyAction UpsertAction = &updateLatencyAction{}
UpdateDisplayNameAction UpsertAction = &updateDisplayNameAction{}
UpdateListOrderAction UpsertAction = &updateListOrderAction{}

UpsertActions = []UpsertAction{
AddPlayerAction,
Expand All @@ -111,6 +113,7 @@ var (
UpdateListedAction,
UpdateLatencyAction,
UpdateDisplayNameAction,
UpdateListOrderAction,
}
)

Expand Down Expand Up @@ -235,3 +238,14 @@ func (a *updateDisplayNameAction) Decode(c *proto.PacketContext, rd io.Reader, i
}
return err
}

type updateListOrderAction struct{}

func (a *updateListOrderAction) Encode(c *proto.PacketContext, wr io.Writer, info *Entry) error {
return util.WriteVarInt(wr, info.ListOrder)
}

func (a *updateListOrderAction) Decode(c *proto.PacketContext, rd io.Reader, info *Entry) (err error) {
info.ListOrder, err = util.ReadVarInt(rd)
return err
}
Loading

0 comments on commit 133de6f

Please sign in to comment.