Skip to content

Commit

Permalink
fix(minecraft/client): strip FML data from address
Browse files Browse the repository at this point in the history
Forge suffixes the server address with \x00FML3\x00. We remove that by
default in the parsed version of the handshake (the original is left
untouched) to make it easier to work with.
  • Loading branch information
jaredallard committed Sep 23, 2023
1 parent 1af8cfc commit 333d828
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion internal/minecraft/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package minecraft
import (
"encoding/json"
"fmt"
"strings"

mcnet "github.com/Tnze/go-mc/net"
pk "github.com/Tnze/go-mc/net/packet"
Expand Down Expand Up @@ -59,7 +60,10 @@ type Handshake struct {
ProtocolVersion int32

// ServerAddress is the address of the server the client is trying to
// connect to.
// connect to. If there are any NULL characters, they are
// automatically stripped as well as all content after them. This is
// to handle the case of Forge servers where the server address is
// suffixed with \0x00FML3\0x00.
ServerAddress string

// ServerPort is the port of the server the client is trying to
Expand Down Expand Up @@ -89,6 +93,13 @@ func (c *Client) Handshake() (*Handshake, error) {
return nil, fmt.Errorf("failed to scan packet: %w", err)
}

// if there's null characters in the server address, use the data
// before the first null character.
nullData := strings.Split(h.ServerAddress, "\x00")
if len(nullData) > 0 {
h.ServerAddress = nullData[0]
}

// set the protocol version on the client.
c.ProtocolVersion = h.ProtocolVersion

Expand Down

0 comments on commit 333d828

Please sign in to comment.