7472035
Branches > main > 7472035 > files / src / net / bowmap / server / protocol
Respond to server list ping via packet
Commit: 7472035c8019b03dbf2c9414adb6703312c6c1b4
Parent: b5a67b0
2 changed files:
src/net/bowmap/server/runtime/packets.clj view file
@@ -1,8 +1,10 @@ (ns net.bowmap.server.runtime.packets (:require+ [net.bowmap.server.protocol.clientbound-packets :as clientbound] [net.bowmap.server.protocol.packet :as packet] [net.bowmap.server.protocol.phase :as phase]- [net.bowmap.server.protocol.serverbound-packets :as serverbound]))+ [net.bowmap.server.protocol.serverbound-packets :as serverbound]+ [net.bowmap.server.protocol.types :as t])) (defn apply-packet "'Applies' a serverbound packet to a client.@@ -11,7 +13,9 @@ (let [{::packet/keys! [id]} packet] (case id ::serverbound/handshaking [(assoc client ::phase/phase (req! packet ::phase/phase))]- ::serverbound/status-request [client]+ ::serverbound/status-request [client [{::packet/id ::clientbound/status-response+ ::t/status-response {:version-name "26.2"+ :protocol 776}}]] ::serverbound/login-acknowledged [(assoc client ::phase/phase ::phase/config)] ::serverbound/finish-config [(assoc client ::phase/phase ::phase/play)] [client])))src/net/bowmap/server/runtime/server.clj view file
@@ -1,27 +1,40 @@ (ns net.bowmap.server.runtime.server (:require- [clojure.core.async :refer [<!! chan io-thread put!]]+ [clojure.core.async :refer [<!! alts!! chan io-thread put!]] [net.bowmap.server.network.connection :as connection]+ [net.bowmap.server.protocol.client :as client] [net.bowmap.server.protocol.codec :as codec] [net.bowmap.server.protocol.phase :as phase] [net.bowmap.server.runtime.packets :as packets])) (defn client-step ([_] {::phase/phase ::phase/handshaking})- ([client in frame]+ ([client in x] (case in- ::connection/serverbound-frames- (packets/apply-packet client (codec/decode-frame client frame)))))+ ::connection/serverbound-frame+ (let [[client' packets] (packets/apply-packet client (codec/decode-frame client x))]+ [client' {::client/clientbound-packets packets}])++ ::client/clientbound-packet+ [client {::connection/clientbound-frames (codec/encode-packet client x)}]))) (defn handle-connection! [{::connection/keys! [serverbound-frames clientbound-frames]}] (let [clientbound-packets (chan 1024)] (io-thread (loop [client-state (client-step nil)]- (when-some [frame (<!! serverbound-frames)]- (let [[client' packets] (client-step client-state ::connection/serverbound-frames frame)]- (doseq [packet packets]- (put! clientbound-packets packet))- (recur client')))))))+ (let [[x ch] (alts!! [serverbound-frames clientbound-packets])+ in (condp = ch+ serverbound-frames ::connection/serverbound-frame+ clientbound-packets ::client/clientbound-packet)]+ (when (some? x)+ (let [[client' {frames ::connection/clientbound-frames+ packets ::client/clientbound-packets}]+ (client-step client-state in x)]+ (doseq [frame frames]+ (put! clientbound-frames frame))+ (doseq [packet packets]+ (put! clientbound-packets packet))+ (recur client')))))))) (defn run-server! "Starts running the given server, where server is a channel of connections.