# HG changeset patch # User Steve Losh # Date 1328051070 18000 # Node ID 9020faafe1198a12c965107bec1b95f476e34881 # Parent e207b5fdb092d8447231126a1d532f77a5dcb687# Parent 57cb38f18a1710baf2bd2a7eb42f395040d37cef Merge. diff -r 57cb38f18a17 -r 9020faafe119 src/clojurecraft/core.clj --- a/src/clojurecraft/core.clj Sat Sep 10 01:35:47 2011 -0700 +++ b/src/clojurecraft/core.clj Tue Jan 31 18:04:30 2012 -0500 @@ -41,7 +41,7 @@ (read-packet bot nil nil nil) ; Send login - (write-packet bot :login {:version 14 :username username}) + (write-packet bot :login {:version 23 :username username}) ; Get login (get (get (read-packet bot nil nil nil) 0) 1)) @@ -137,7 +137,7 @@ (println "connected and logged in") (println "queueing initial keepalive packet") - (.put outqueue [:keepalive {}]) + (.put outqueue [:keepalive {:keep-alive-id 0}]) (println "starting read handler") (.start (Thread. #(input-handler bot))) diff -r 57cb38f18a17 -r 9020faafe119 src/clojurecraft/in.clj --- a/src/clojurecraft/in.clj Sat Sep 10 01:35:47 2011 -0700 +++ b/src/clojurecraft/in.clj Tue Jan 31 18:04:30 2012 -0500 @@ -104,7 +104,8 @@ ; Reading Packets ------------------------------------------------------------------ (defn- read-packet-keepalive [bot conn] - {}) + (assoc {} + :keep-alive-id (-read-int conn))) (defn- read-packet-handshake [bot conn] (assoc {} @@ -115,7 +116,12 @@ :eid (-read-int conn) :unknown (-read-string-ucs2 conn) :seed (-read-long conn) - :dimension (-read-byte conn))) + :level-type (-read-string-ucs2 conn) + :server-mode (-read-int conn) + :dimension (-read-byte conn) + :difficulty (-read-byte conn) + :world-height (-read-byte conn) + :max-players (-read-byte conn))) (defn- read-packet-chat [bot conn] (let [payload (assoc {} @@ -645,6 +651,12 @@ :statisticid (-read-int conn) :amount (-read-byte conn))) +(defn- read-packet-playerlistitem [bot conn] + (assoc {} + :playername (-read-string-ucs2 conn) + :online (-read-bool conn) + :ping (-read-short conn))) + (defn- read-packet-disconnectkick [bot conn] (assoc {} :reason (-read-string-ucs2 conn))) @@ -702,6 +714,7 @@ :updatesign read-packet-updatesign :mapdata read-packet-mapdata :incrementstatistic read-packet-incrementstatistic + :playerlistitem read-packet-playerlistitem :disconnectkick read-packet-disconnectkick}) ; Reading Wrappers ----------------------------------------------------------------- @@ -732,6 +745,7 @@ (/ 1 0)) (let [payload (do ((packet-type packet-readers) bot conn))] (do + (println (str "--PACKET--> " packet-type)) (when (#{} packet-type) (println (str "--PACKET--> " packet-type))) [[packet-type payload] prev prev-prev])))))) diff -r 57cb38f18a17 -r 9020faafe119 src/clojurecraft/mappings.clj --- a/src/clojurecraft/mappings.clj Sat Sep 10 01:35:47 2011 -0700 +++ b/src/clojurecraft/mappings.clj Tue Jan 31 18:04:30 2012 -0500 @@ -59,6 +59,7 @@ 0x82 :updatesign 0x83 :mapdata 0xC8 :incrementstatistic + 0xC9 :playerlistitem 0xFF :disconnectkick }) (def packet-ids (invert packet-types)) diff -r 57cb38f18a17 -r 9020faafe119 src/clojurecraft/out.clj --- a/src/clojurecraft/out.clj Sat Sep 10 01:35:47 2011 -0700 +++ b/src/clojurecraft/out.clj Tue Jan 31 18:04:30 2012 -0500 @@ -44,8 +44,8 @@ ; Writing Packets ------------------------------------------------------------------ -(defn- write-packet-keepalive [conn _] - nil) +(defn- write-packet-keepalive [conn {keep-alive-id :keep-alive-id}] + (-write-int conn keep-alive-id)) (defn- write-packet-handshake [conn {username :username}] (-write-string-ucs2 conn username)) @@ -54,6 +54,11 @@ (-write-int conn version) (-write-string-ucs2 conn username) (-write-long conn 0) + (-write-string-ucs2 conn "") + (-write-int conn 0) + (-write-byte conn 0) + (-write-byte conn 0) + (-write-byte conn 0) (-write-byte conn 0)) (defn- write-packet-chat [conn {message :message}] diff -r 57cb38f18a17 -r 9020faafe119 src/examples/followbot.clj --- a/src/examples/followbot.clj Sat Sep 10 01:35:47 2011 -0700 +++ b/src/examples/followbot.clj Tue Jan 31 18:04:30 2012 -0500 @@ -17,7 +17,7 @@ (abs (- (:z from) (:z to)))))) (defn- toward-single [from to] - (if (<= (abs (- from to)) 1) + (if (<= (abs (- from to)) 2) 0 (if (< from to) 1 -1))) @@ -38,15 +38,13 @@ (distance-between bot %2)) entities)))) + ; Loops ---------------------------------------------------------------------------- (defn follow [bot] (when (:loc @(:player bot)) (let [players (find-other-players bot) closest (closest-entity bot players)] (when closest - (println (:name @(:player bot)) "following" (:name @closest)) - (println (:loc @(:player bot))) - (println (:loc @closest)) (let [{x :x z :z} (toward bot closest)] [(actions/move bot x 0 z)])))))