Skip to content

Commit 57d61b1

Browse files
committed
fix: Compatibility with newer FML network markers
1 parent f14f5c2 commit 57d61b1

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

adapter/metadata.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ type MinecraftMetadata struct {
4141
PlayerName string
4242
OriginDestination string
4343
RewrittenDestination string
44+
fmlMarkup string
4445
OriginPort uint16
4546
RewrittenPort uint16
4647
UUID [16]byte
@@ -49,11 +50,19 @@ type MinecraftMetadata struct {
4950
}
5051

5152
func (m *MinecraftMetadata) IsFML() bool {
52-
return strings.HasSuffix(m.OriginDestination, "\x00FML\x00")
53+
return strings.IndexByte(m.OriginDestination, 0) != -1
5354
}
5455

55-
func (m *MinecraftMetadata) CleanOriginDestination() string {
56-
return strings.TrimSuffix(m.OriginDestination, "\x00FML\x00")
56+
func (m *MinecraftMetadata) CleanOriginDestination() (clean string) {
57+
clean, m.fmlMarkup, _ = strings.Cut(m.OriginDestination, "\x00")
58+
return
59+
}
60+
61+
func (m *MinecraftMetadata) FMLMarkup() string {
62+
if m.fmlMarkup == "" {
63+
_, m.fmlMarkup, _ = strings.Cut(m.OriginDestination, "\x00")
64+
}
65+
return m.fmlMarkup
5766
}
5867

5968
type TLSMetadata struct {

protocol/minecraft/outbound.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ func (o *Outbound) InjectConnection(ctx context.Context, conn *bufio.CachedConn,
250250
}
251251
//remoteConn.(*net.TCPConn).SetLinger(0) // for some reason
252252
if metadata.Minecraft.RewrittenDestination == "" {
253-
metadata.Minecraft.RewrittenDestination = metadata.Minecraft.OriginDestination
253+
metadata.Minecraft.RewrittenDestination = metadata.Minecraft.CleanOriginDestination()
254254
}
255255
if metadata.Minecraft.RewrittenPort == 0 {
256256
metadata.Minecraft.RewrittenPort = metadata.Minecraft.OriginPort
@@ -265,10 +265,10 @@ func (o *Outbound) InjectConnection(ctx context.Context, conn *bufio.CachedConn,
265265
hostname = o.config.TargetAddress
266266
}
267267
} else if hostname == "" {
268-
hostname = metadata.Minecraft.OriginDestination
268+
hostname = metadata.Minecraft.CleanOriginDestination()
269269
}
270270
if !o.config.Minecraft.IgnoreFMLSuffix && metadata.Minecraft.IsFML() {
271-
hostname += "\x00FML\x00"
271+
hostname += "\x00" + metadata.Minecraft.FMLMarkup()
272272
}
273273
port := metadata.Minecraft.RewrittenPort
274274
if port <= 0 {
@@ -391,10 +391,10 @@ func (o *Outbound) InjectConnection(ctx context.Context, conn *bufio.CachedConn,
391391
hostname = o.config.TargetAddress
392392
}
393393
} else if hostname == "" {
394-
hostname = metadata.Minecraft.OriginDestination
394+
hostname = metadata.Minecraft.CleanOriginDestination()
395395
}
396396
if !o.config.Minecraft.IgnoreFMLSuffix && metadata.Minecraft.IsFML() {
397-
hostname += "\x00FML\x00"
397+
hostname += "\x00" + metadata.Minecraft.FMLMarkup()
398398
}
399399
port := metadata.Minecraft.RewrittenPort
400400
if port <= 0 {

0 commit comments

Comments
 (0)