6ebf2a4
Branches > refactor/use-spec-1 > 6ebf2a4 > files / src / net / bowmap
Split byte and packet handling
Commit: 6ebf2a4e43acd85a78bee5b60e349197b78a393b
Parent: 4ef8d83
1 changed file:
src/net/bowmap/core.clj view file
@@ -11,16 +11,8 @@ [io.netty.buffer ByteBuf Unpooled] [io.netty.channel ChannelOption])) -;; TODO disconnect client on exception--(defn handle-bytes- "Handles a byte array of one TCP packet, splits it into Minecraft protocol packets,- sends response packets to the client, and returns a new client.- Packets are parsed and handled synchronously as packet decoding can update- client state, so is impure."- [client bs]- (let [{::keys [buf stream]} client- buf (ByteBuf/.writeBytes buf bs)]+(defn handle-packet [client]+ (let [{::keys [buf stream]} client] (loop [client client] (if (read/can-read-packet? buf) (let [pk (sp/decode-packet! buf (::state/state client))@@ -32,6 +24,19 @@ (recur client)) client)))) +(defn handle-bytes+ "Handles a byte array of one TCP packet, splits it into Minecraft protocol packets,+ sends response packets to the client, and returns a new client.+ Packets are parsed and handled synchronously as packet decoding can update+ client state, so is impure."+ [client bs]+ (ByteBuf/.writeBytes (::buf client) bs)+ (try (handle-packet client)+ (catch Exception e+ (prn "Exception in bytes:" e)+ ;; Can disconnect as well :)+ (.close (::stream client)))))+ (defn client-handler [stream _] (let [client {::state/state ::state/handshaking ::buf (Unpooled/buffer)