# HG changeset patch # User Steve Losh # Date 1308704362 14400 # Node ID d00a3eb9f3bf510aee430eb210388ffdaebff37c # Parent db332a3d223b2fef17093b4845e1f126f4666000 Moar. diff -r db332a3d223b -r d00a3eb9f3bf src/clojurecraft/core.clj --- a/src/clojurecraft/core.clj Tue Jun 21 20:47:29 2011 -0400 +++ b/src/clojurecraft/core.clj Tue Jun 21 20:59:22 2011 -0400 @@ -5,14 +5,15 @@ (def minecraft-local {:name "localhost" :port 25565}) ; Packet Type Maps ----------------------------------------------------------------- -(def packet-ids { - :keepalive 0x00 - :login 0x01 - :handshake 0x02 - :chat 0x03 - :timeupdate 0x04 +(def packet-types { + 0x00 :keepalive + 0x01 :login + 0x02 :handshake + 0x03 :chat + 0x04 :timeupdate + 0x05 :equipment }) -(def packet-types (apply assoc {} (mapcat reverse packet-ids))) +(def packet-ids (apply assoc {} (mapcat reverse packet-types))) (declare conn-handler) @@ -56,6 +57,11 @@ (doto (:out @conn) (.writeChars s))) +(defn -write-bool [conn b] + (println (str "-> BOOL: " b)) + (doto (:out @conn) + (.writeBoolean b))) + ; Writing Packets ------------------------------------------------------------------ (defn write-packet-keepalive [conn _] @@ -106,6 +112,10 @@ (let [i (.readLong (:in @conn))] i)) +(defn -read-short [conn] + (let [i (.readShort (:in @conn))] + i)) + (defn -read-string16 [conn] (let [str-len (.readShort (:in @conn)) s (apply str (repeatedly str-len #(.readChar (:in @conn))))] @@ -135,6 +145,13 @@ (-> {} (assoc :time (-read-long conn)))) +(defn read-packet-equipment [conn] + (-> {} + (assoc :eid (-read-int conn)) + (assoc :slot (-read-short conn)) + (assoc :itemid (-read-short conn)) + (assoc :unknown (-read-short conn)))) + (defn read-packet [conn packet-id] (let [packet-id (int packet-id)