599e72a
Branches > main > 599e72a > files / .tickets / replace-aleph.md
Yeah server stuff
Commit: 599e72a9b56b2484fca04f4eb0729be42272e5bd
Parent: c571574
2 changed files:
src/net/bowmap/network/minecraft_server.clj view file
@@ -13,7 +13,7 @@ [net.bowmap.server.step :as step])) (defn handle-incoming-frame [client frame outgoing-messages]- (let [message (serverbound/frame->message frame (::state/connection-state client))+ (let [message (serverbound/frame->message frame (req! client ::state/connection-state)) {::client/keys! [client] ::a/keys [messages keep-alive?]} (a/handle-message message client)] (doseq [message messages] (put! outgoing-messages message))@@ -27,22 +27,28 @@ client)) (defn handle-client!! [client outgoing-messages]- (let [{::server/keys! [incoming-frames outgoing-frames]} client]+ (let [{::server/keys! [incoming-frames outgoing-frames] :keys! [::state/connection-state]} client] (alt!! incoming-frames ([frame] (if (some? frame)- (handle-incoming-frame client frame outgoing-messages)+ (try (handle-incoming-frame client frame outgoing-messages)+ (catch Throwable t+ ; This isn't really good.+ ; Just keep track of client and server sockets, they're fine.+ (close! outgoing-frames)+ (throw t))) (raise "client incoming frame channel closed!"))) outgoing-messages ([message] (if (some? message)- (do (>!! outgoing-frames (clientbound/message->frame message (::state/connection-state client)))+ (do (>!! outgoing-frames (clientbound/message->frame message connection-state)) client) (raise "client outgoing message channel closed!")))))) (defn connect! [client]- (let [outgoing-messages (chan 1024)]+ (let [outgoing-messages (chan 1024)+ client (assoc client ::state/connection-state ::state/handshaking)] (io-thread (loop [client client] (recur (handle-client!! client outgoing-messages))))src/net/bowmap/network/server.clj view file
@@ -4,7 +4,7 @@ [net.bowmap.network.stream :as stream]) (:import [java.io Closeable]- [java.net ServerSocket Socket]))+ [java.net InetAddress ServerSocket Socket])) (defn new-client [socket] (let [incoming-frames (chan)@@ -20,8 +20,9 @@ (io-thread (loop []- (let [frame (<!! outgoing-frames)]- (stream/write-frame!! frame (Socket/.getOutputStream socket)))+ (if-some [frame (<!! outgoing-frames)]+ (stream/write-frame!! frame (Socket/.getOutputStream socket))+ (Socket/.close socket)) (recur))) {::incoming-frames incoming-frames ::outgoing-frames outgoing-frames}))@@ -30,7 +31,7 @@ "Starts a TCP server at the given port. Returns a channel of clients as they connect. When the server closes, client channel will be closed, and vice versa." [& {:keys! [port]}]- (let [server (ServerSocket. port)+ (let [server (ServerSocket. port 50 (InetAddress/getByName "0.0.0.0")) clients (chan 64)] (io-thread (try