bfb52e6
Branches > facts > bfb52e6 > files / src / net / bowmap / server
Implement Server List Ping
Commit: bfb52e66de45b2f456fd06380f9913d55c3da48e
Parent: 70c3677
3 changed files:
src/net/bowmap/network/client.clj view file
@@ -1,7 +1,6 @@ (ns net.bowmap.network.client (:require- [net.bowmap.network.handle :refer [handle-packet]]- [net.bowmap.network.packets.serverbound :refer [decode-packet!]]+ [net.bowmap.network.packets.clientbound :refer [encode-packet!]] [net.bowmap.network.packets.types :as t] [net.bowmap.network.state :as state]) (:import@@ -54,16 +53,10 @@ (OutputStream/.write output-stream arr) (OutputStream/.flush output-stream))) -; When do you actually get these frames?-(defn process-serverbound-packet [client frame]- (let [packet (decode-packet! frame (::state/connection-state client))]- ; Get some packets back- ; Send them out :D- (handle-packet client packet)))--(defn send-clientbound-packet [client]- ;...- )+(defn send-clientbound-packet [client packet]+ (write-frame!! (encode-packet! packet (req! client ::state/connection-state))+ (Socket/.getOutputStream (req! client ::socket)))+ client) (defn client [socket] (agent {::socket socketsrc/net/bowmap/network/handle.clj view file
@@ -1,15 +1,41 @@ (ns net.bowmap.network.handle (:require+ [net.bowmap.network.client :as client] [net.bowmap.network.packet :as pk]- [net.bowmap.network.packets.serverbound :as serverbound]+ [net.bowmap.network.packets.clientbound :as clientbound]+ [net.bowmap.network.packets.serverbound :as serverbound :refer [decode-packet!]] [net.bowmap.network.state :as state])) ; Handles incoming packets from clients (defn handle-packet "Handles a severbound packet from a client"- [client packet]+ [client client-agent packet] (println packet) (case (::pk/id packet) ::serverbound/handshaking (assoc client ::state/connection-state (req! packet :intent))+ ::serverbound/status-request (do (send client-agent client/send-clientbound-packet+ {::pk/id ::clientbound/status-response+ ;; Should be un-bundled yeah.+ :response {:version {:name "26.2"+ :protocol 776}+ :players {:online 0+ :max 1000}+ ; Is this a text component? Could make that interface+ :description {:text "Bowmap!"}+ :enforcesSecureChat false}})+ client)+ ::serverbound/ping-request (do (send client-agent client/send-clientbound-packet+ {::pk/id ::clientbound/pong-response+ :timestamp (:timestamp packet)})+ client) client))++(defn process-serverbound-packet [client client-agent frame]+ (let [packet (decode-packet! frame (req! client ::state/connection-state))]+ ; Get some packets back+ ; Send them out :D+ (handle-packet client client-agent packet)))++(defn process-incoming-frame! [client-agent frame]+ (send client-agent process-serverbound-packet client-agent frame))src/net/bowmap/network/server.clj view file
@@ -1,7 +1,8 @@ (ns net.bowmap.network.server (:require [clojure.core.async :refer [io-thread]]- [net.bowmap.network.client :as client])+ [net.bowmap.network.client :as client]+ [net.bowmap.network.handle :as handle]) (:import [java.io EOFException] [java.net ServerSocket Socket SocketException]))@@ -11,13 +12,12 @@ (loop [] (let [socket (ServerSocket/.accept server) input-stream (Socket/.getInputStream socket)- client (client/client socket)]+ client-agent (client/client socket)] (io-thread (try (loop []- ; Close the client connection when EOF is reached (let [frame (client/read-frame!! input-stream)]- (send client client/process-serverbound-packet frame))+ (handle/process-incoming-frame! client-agent frame)) (recur)) (catch EOFException _) (catch SocketException _)