handle.clj
Branches > main > 1629b2d > files / src / net / bowmap / server / game / handle.clj
(ns net.bowmap.server.game.handle
(:require
[net.bowmap.server.protocol.clientbound-packets :as clientbound]
[net.bowmap.server.protocol.component :as component]
[net.bowmap.server.protocol.packet :as packet]
[net.bowmap.server.protocol.schema :as p]
[net.bowmap.server.protocol.serverbound-packets :as serverbound]))
(defmulti handle-packet
"Handles a packet from a player, returning [player' [packets*]?]."
(fn [player packet]
(::packet/id packet)))
(defmethod handle-packet :default [player _] [player])
(defmethod handle-packet ::serverbound/status-request [player _]
[player
[{::packet/id ::clientbound/status-response
::p/version-name "26.2"
::p/protocol 776
::p/motd {::component/text "Bowmap!"
::component/color "#9f9f9f"}
::p/online-player-count 0
::p/max-player-count 1000}]])
(defmethod handle-packet ::serverbound/ping-request [player {::p/keys! [timestamp]}]
[player
[{::packet/id ::clientbound/pong-response
::p/timestamp timestamp}]])
(defmethod handle-packet ::serverbound/login-start [player {::p/keys! [uuid username]}]
[(assoc player
::p/uuid uuid
::p/username username)
[{::packet/id ::clientbound/login-success
::p/game-profile {::p/uuid uuid
::p/username username
::p/game-profile-properties []}
::p/session-uuid (random-uuid)}]])