port messenger to more versions

This commit is contained in:
Admin Else
2026-08-04 19:28:43 +02:00
parent d9bca7e517
commit acb5fe8d90
3 changed files with 111 additions and 23 deletions
+20
View File
@@ -9,6 +9,7 @@ import (
"github.com/admin-else/strom/mc/proto"
"github.com/admin-else/strom/mc/proto_base"
"github.com/admin-else/strom/mc/proto_generated/v1_21_8"
"github.com/admin-else/strom/mc/proto_generated/v1_8"
"github.com/admin-else/strom/mc/server"
)
@@ -36,6 +37,23 @@ func (s *StatusClient) OnPong(p *v1_21_8.StatusToClientPacketPing) (err error) {
return
}
func (s *StatusClient) OnStatusV1_8(p *v1_8.StatusToClientPacketServerInfo) (err error) {
s.Status = p.Response
s.PingSendTime = time.Now()
if s.DoPingRoundTripTime {
err = s.Send(&v1_21_8.StatusToServerPacketPing{Time: s.PingSendTime.UnixMilli()})
} else {
err = event.HandlerDoneErr{}
}
return
}
func (s *StatusClient) OnPongV1_8(p *v1_8.StatusToClientPacketPing) (err error) {
s.PingReceiveTime = time.Now()
err = event.HandlerDoneErr{}
return
}
// StatusRaw returns a StatusClient that is not connected to a server.
// So ignore the resource leak warning. And maybe attach a warn ignore comment.
// It does not resolve SRV records.
@@ -59,6 +77,8 @@ func StatusRawWithVersion(ctx context.Context, addr, version string) (s *StatusC
}
s.RegisterCriticalUntilLatest(s.OnStatus)
s.RegisterCriticalUntilLatest(s.OnPong)
s.RegisterCritical(s.OnStatusV1_8)
s.RegisterCritical(s.OnPongV1_8)
p, err := MakeHandshakePacketAddr(s.Conn, proto_base.Status, addr)
if err != nil {