Skip to content

Commit

Permalink
login/request.go: Add brackets around IP in IPv6 addresses sent in Se…
Browse files Browse the repository at this point in the history
…rverAddress field. Resolves #128.
  • Loading branch information
Sandertv committed Jun 6, 2022
1 parent d95010a commit 8a310b2
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions minecraft/protocol/login/request.go
Expand Up @@ -10,6 +10,7 @@ import (
"fmt"
"gopkg.in/square/go-jose.v2"
"gopkg.in/square/go-jose.v2/jwt"
"strings"
"time"
)

Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 8a310b2

Please sign in to comment.