From 8a310b2d27797a73e04a6388b0c5307e351f8189 Mon Sep 17 00:00:00 2001 From: Sandertv Date: Mon, 6 Jun 2022 12:24:40 +0200 Subject: [PATCH] login/request.go: Add brackets around IP in IPv6 addresses sent in ServerAddress field. Resolves #128. --- minecraft/protocol/login/request.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/minecraft/protocol/login/request.go b/minecraft/protocol/login/request.go index 803dad78..e6171dd0 100644 --- a/minecraft/protocol/login/request.go +++ b/minecraft/protocol/login/request.go @@ -10,6 +10,7 @@ import ( "fmt" "gopkg.in/square/go-jose.v2" "gopkg.in/square/go-jose.v2/jwt" + "strings" "time" ) @@ -123,6 +124,12 @@ func Parse(request []byte) (IdentityData, ClientData, AuthResult, error) { if err := parseFullClaim(req.RawToken, key, &cData); err != nil { return iData, cData, res, fmt.Errorf("parse client data: %w", err) } + if strings.Count(cData.ServerAddress, ":") > 1 { + // IPv6: We can't net.ResolveUDPAddr this directly, because Mojang does not put [] around the IP. We'll have to + // do this manually: + ind := strings.LastIndex(cData.ServerAddress, ":") + cData.ServerAddress = "[" + cData.ServerAddress[:ind] + "]" + cData.ServerAddress[ind:] + } if err := cData.Validate(); err != nil { return iData, cData, res, fmt.Errorf("validate client data: %w", err) }