From 335fffa72f49836fbca80273af82083be55ffb53 Mon Sep 17 00:00:00 2001 From: Sandertv Date: Mon, 5 Sep 2022 18:18:43 +0200 Subject: [PATCH] login/request.go: Only add `[]` around IPv6 addresses if it isn't already there. --- minecraft/protocol/login/request.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/minecraft/protocol/login/request.go b/minecraft/protocol/login/request.go index e6171dd0..545a2294 100644 --- a/minecraft/protocol/login/request.go +++ b/minecraft/protocol/login/request.go @@ -124,9 +124,10 @@ 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: + if strings.Count(cData.ServerAddress, ":") > 1 && cData.ServerAddress[0] != '[' { + // IPv6: We can't net.ResolveUDPAddr this directly, because Mojang does + // not always put [] around the IP if it isn't added by the player in + // the External Server adding screen. We'll have to do this manually: ind := strings.LastIndex(cData.ServerAddress, ":") cData.ServerAddress = "[" + cData.ServerAddress[:ind] + "]" + cData.ServerAddress[ind:] }