67 lines
1.8 KiB
Go
67 lines
1.8 KiB
Go
package sbproxy
|
|
|
|
import (
|
|
"context"
|
|
"net"
|
|
|
|
"github.com/sandertv/go-raknet"
|
|
"github.com/sagernet/sing-box/adapter"
|
|
N "github.com/sagernet/sing/common/network"
|
|
)
|
|
|
|
func (h *Inbound) handleBedrockPacket(ctx context.Context, conn N.PacketConn, metadata adapter.InboundContext, onClose N.CloseHandlerFunc) {
|
|
}
|
|
|
|
func (h *Inbound) startBedrockListener() {
|
|
l, err := raknet.Listen(h.options.ListenOptions.Listen)
|
|
if err != nil {
|
|
h.logger.Error("failed to start Bedrock listener: ", err)
|
|
return
|
|
}
|
|
defer l.Close()
|
|
|
|
// Setup RakNet Pong Data (Active scanning response)
|
|
motd := h.options.MOTD
|
|
if motd == "" {
|
|
motd = "A Minecraft Server"
|
|
}
|
|
ver := h.options.Version
|
|
if ver == "" {
|
|
ver = "1.20.1"
|
|
}
|
|
|
|
// Bedrock Pong format: MCPE;MOTD;Protocol;Version;Online;Max;ServerID;SubMOTD;GameMode;1;Port;Port;
|
|
pongData := fmt.Sprintf("MCPE;%s;594;%s;0;%d;%d;SBProxy;Creative;1;19132;19132;",
|
|
motd, ver, h.options.MaxPlayers, time.Now().UnixNano())
|
|
l.ExpirablePongData(func(p net.Addr) []byte {
|
|
return []byte(pongData)
|
|
})
|
|
|
|
h.logger.Info("Bedrock listener started with Version: ", ver)
|
|
|
|
for {
|
|
conn, err := l.Accept()
|
|
if err != nil {
|
|
break
|
|
}
|
|
go h.handleBedrockConnection(conn)
|
|
}
|
|
}
|
|
|
|
func (h *Inbound) handleBedrockConnection(conn net.Conn) {
|
|
defer conn.Close()
|
|
h.logger.Info("Bedrock connection accepted from: ", conn.RemoteAddr())
|
|
|
|
// For Bedrock, we eventually want to do a similar handshake
|
|
// using Bedrock-specific packets (e.g., Login, RequestChunkRadius, etc.)
|
|
// and then a custom Play-state packet for encapsulated proxy data.
|
|
|
|
// Implementation follows the same pattern as Java:
|
|
// Handle Handshake -> Handle Login -> Handle Play -> Tunnel data.
|
|
|
|
// KeepAlive is handled by RakNet itself.
|
|
|
|
// Placeholder for Bedrock-specific tunneling logic
|
|
select {}
|
|
}
|