f4f8533

Branches > main > f4f8533 > files / src / net

Warn on unread packet

Grahp, 2026-06-03

Commit: f4f85336e9fbf2373ce6f567b65f341a2f9a95c3
Parent: a4bb565

2 changed files:

src/dev/grahp/error.clj modified (view file)

@@ -1,8 +1,15 @@ (ns dev.grahp.error   "Some error handling macros."-  (:require [clojure.spec.alpha :as s]+  (:require [clojure.alpha.spec :as s]             [clojure.string :as str])) +(defmacro guard+  "Calls form, if it throws an exception, returns 'else', default nil."+  ([form] `(guard ~form nil))+  ([form else]+   `(try ~form+         (catch Exception ~'_ ~else))))+ (defmacro raise   "Throws an error with msg and an optional map and cause."   {:arglists '([msg]

src/net/bowmap/minecraft_server.clj modified (view file)

@@ -1,6 +1,7 @@ (ns net.bowmap.minecraft-server   (:require    [clojure.core.async :refer [<!! >!! alt!! chan io-thread put! timeout]]+   [dev.grahp.error :refer [guard]]    [net.bowmap.message-application :as a]    [net.bowmap.network.client :as client]    [net.bowmap.network.message.client :as cl]@@ -25,8 +26,10 @@    Because packet reading is dependent on the state of the client, and handling a packet can update the state of the client,    Reading and handling must be synchronized!"   [pk client messages-out process-chan]-  (when-some [msg (srv/packet->message pk (::state/connection-state client))]-    (run-effects! messages-out process-chan (a/apply-message msg client))))+  (if-some [msg (guard (srv/packet->message pk (::state/connection-state client)))]+    (run-effects! messages-out process-chan (a/apply-message msg client))+    (do (prn "Unprocessed message!" {:pk pk :client client})+        client)))  (defn handle-process! [process client messages-out process-chan]   (run-effects! messages-out process-chan (a/apply-process process client)))