client: add ConnectWithConn, WithConn, WithDialer, LoginRawAddr

- ConnectWithConn wraps an existing net.Conn into a versioned proto.Conn
- DialFunc is a context-aware dial function type
- WithConn uses a pre-established net.Conn (version required, no DNS)
- WithDialer replaces net.Dialer with a custom dial function
- LoginRawAddr accepts an explicit handshake host address
- Login() wired to support all three connection modes
This commit is contained in:
adman
2026-07-31 14:30:25 +02:00
parent 492dae8e83
commit 8bd54a04f2
2 changed files with 97 additions and 8 deletions
+20
View File
@@ -60,3 +60,23 @@ func ConnectVersionLess(ctx context.Context, addr string) (ret *proto.Conn, err
ret.W = ret.Conn
return
}
// ConnectWithConn wraps an existing net.Conn into a proto.Conn with the given
// Minecraft version. The version must be non-empty.
func ConnectWithConn(ctx context.Context, conn net.Conn, version string) (ret *proto.Conn, err error) {
if ctx == nil {
ctx = context.Background()
}
ret = proto.NewConnCtx(ctx)
ret.Actor = proto_base.Client
ret.Conn = conn
ret.R = conn
ret.W = conn
v, err := data.LookUpVersionByName(version)
if err != nil {
return
}
ret.ProtocolVersion = v.Version
ret.Version = version
return
}