e207b5fdb092

now working with protocol 23 (modulo a few intermittent errors)
[view raw] [browse files]
author Jason Dufair <jase@dufair.org>
date Tue, 31 Jan 2012 12:57:17 -0500
parents 9874586e98d1
children 9020faafe119
branches/tags (none)
files src/clojurecraft/core.clj src/clojurecraft/in.clj src/clojurecraft/mappings.clj src/clojurecraft/out.clj

Changes

--- a/src/clojurecraft/core.clj	Tue Jan 31 11:39:50 2012 -0500
+++ b/src/clojurecraft/core.clj	Tue Jan 31 12:57:17 2012 -0500
@@ -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)))
--- a/src/clojurecraft/in.clj	Tue Jan 31 11:39:50 2012 -0500
+++ b/src/clojurecraft/in.clj	Tue Jan 31 12:57:17 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]))))))
--- a/src/clojurecraft/mappings.clj	Tue Jan 31 11:39:50 2012 -0500
+++ b/src/clojurecraft/mappings.clj	Tue Jan 31 12:57:17 2012 -0500
@@ -59,6 +59,7 @@
   0x82 :updatesign
   0x83 :mapdata
   0xC8 :incrementstatistic
+  0xC9 :playerlistitem
   0xFF :disconnectkick
 })
 (def packet-ids (invert packet-types))
--- a/src/clojurecraft/out.clj	Tue Jan 31 11:39:50 2012 -0500
+++ b/src/clojurecraft/out.clj	Tue Jan 31 12:57:17 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))