From 949ddbd5ca50910f56f144dd0f08164e63b9bb24 Mon Sep 17 00:00:00 2001 From: Sandertv Date: Thu, 2 May 2024 18:44:00 +0200 Subject: [PATCH] handler.go: Send NewIncomingConnection before any user packets. --- dial.go | 2 +- handler.go | 5 +++-- packet.go | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/dial.go b/dial.go index 571ebac..404383e 100644 --- a/dial.go +++ b/dial.go @@ -267,7 +267,7 @@ func (dialer Dialer) clientListen(rakConn *Conn, conn net.Conn) { continue } if err := rakConn.receive(b[:n]); err != nil { - dialer.ErrorLog.Error("client: handle packet: " + err.Error()) + dialer.ErrorLog.Error("client: " + err.Error()) } } } diff --git a/handler.go b/handler.go index d4a56a0..cdc0658 100644 --- a/handler.go +++ b/handler.go @@ -222,14 +222,15 @@ func handleConnectionRequestAccepted(conn *Conn, b []byte) error { if err := pk.UnmarshalBinary(b); err != nil { return fmt.Errorf("read CONNECTION_REQUEST_ACCEPTED: %w", err) } - select { case <-conn.connected: return errUnexpectedAdditionalCRA default: + // Make sure to send NewIncomingConnection before closing conn.connected. + err := conn.send(&message.NewIncomingConnection{ServerAddress: resolve(conn.raddr), RequestTimestamp: pk.AcceptedTimestamp, AcceptedTimestamp: timestamp()}) close(conn.connected) + return err } - return conn.send(&message.NewIncomingConnection{ServerAddress: resolve(conn.raddr), RequestTimestamp: pk.RequestTimestamp, AcceptedTimestamp: pk.AcceptedTimestamp, SystemAddresses: pk.SystemAddresses}) } // handleNewIncomingConnection handles an incoming connection packet from the diff --git a/packet.go b/packet.go index 645a516..42f5f99 100644 --- a/packet.go +++ b/packet.go @@ -53,11 +53,12 @@ const ( type packet struct { reliability byte - content []byte messageIndex uint24 sequenceIndex uint24 orderIndex uint24 + content []byte + split bool splitCount uint32 splitIndex uint32