924dc67

Branches > main > 924dc67 > files

Ignore packets that failed to decode

Grahp, 2026-08-25

Commit: 924dc67fe2bf3e9beb4faf6939c8aa55fe5a052a
Parent: bf482fd

1 changed file:

src/net/bowmap/transport/connection.clj modified (view file)

@@ -16,17 +16,21 @@ (defn handle-serverbound-frame!   [state conn frame]   (let [{::phase/keys! [phase]} @state-        {::pk/keys! [id] :as packet} (decode-packet! frame phase)]-    (case id-      ::serverbound/handshaking        (swap! state assoc ::phase/phase (req! packet ::phase/phase))-      ::serverbound/login-acknowledged (swap! state assoc ::phase/phase ::phase/config)-      ::serverbound/finish-config      (swap! state assoc ::phase/phase ::phase/play)-      ::serverbound/login-start-      (let [{:keys! [username uuid]} packet]-        (swap! state assoc ::player/username username ::player/uuid uuid))-      nil)-    ; Just kinda crudely passing the connection into the serverbound packet right now-    (merge packet {::connection conn} (select-keys @state [::player/uuid]))))+        packet (try (decode-packet! frame phase)+                    (catch Exception e+                      (Throwable/.printStackTrace (Exception. "Failed to decode packet!" e))+                      nil))]+    (when-let [{::pk/keys! [id]} packet]+      (case id+        ::serverbound/handshaking        (swap! state assoc ::phase/phase (req! packet ::phase/phase))+        ::serverbound/login-acknowledged (swap! state assoc ::phase/phase ::phase/config)+        ::serverbound/finish-config      (swap! state assoc ::phase/phase ::phase/play)+        ::serverbound/login-start+        (let [{:keys! [username uuid]} packet]+          (swap! state assoc ::player/username username ::player/uuid uuid))+        nil)+      ; Just kinda crudely passing the connection into the serverbound packet right now+      (merge packet {::connection conn} (select-keys @state [::player/uuid])))))  (defn connection   "Creates a connection object from a java.net.Socket@@ -61,7 +65,8 @@     (io-thread       (try         (loop []-          (put! serverbound-packets (handle-serverbound-frame! state conn (streams/read-frame!! input-stream)))+          (when-let [packet (handle-serverbound-frame! state conn (streams/read-frame!! input-stream))]+            (put! serverbound-packets packet))           (recur))         (catch EOFException _)         (catch SocketException _)