]> git.lizzy.rs Git - hydra-dragonfire.git/blobdiff - example/dump-traffic.lua
Add map component
[hydra-dragonfire.git] / example / dump-traffic.lua
index b3d89da1869febf2522f1b384c49d004d4aeca68..5dc83b6eea4ffad1db81006ba892a8f6f74f35a6 100755 (executable)
@@ -1,19 +1,53 @@
 #!/usr/bin/env hydra-dragonfire
+local escapes = require("escapes")
+local base64 = require("base64")
 local client = require("client")()
 
 client:wildcard(true)
 client:connect()
 
+local function dump(val, indent)
+       local t = type(val)
+       local mt = getmetatable(val)
+
+       if t ~= "table" or mt and mt.__tostring then
+               if t == "string" then
+                       val = val:gsub("\n", "\\n")
+               end
+               print(val)
+       else
+               print(val._type or "")
+
+               local idt = (indent or "") .. "  "
+               for k, v in pairs(val) do
+                       if k ~= "_type" then
+                               io.write(idt .. k .. " ")
+                               dump(v, idt)
+                       end
+               end
+       end
+end
+
 while not hydra.canceled() do
        local pkt, interrupt = client:poll()
 
        if pkt then
-               print(pkt._type)
-               for k, v in pairs(pkt) do
-                       if k ~= "_type" then
-                               print("", k, v)
-                       end
+               if pkt._type == "srp_bytes_salt_b" then
+                       pkt.b = base64.encode(pkt.b)
+                       pkt.salt = base64.encode(pkt.salt)
+               end
+
+               if pkt._type == "chat_msg" then
+                       pkt.text = escapes.strip_all(pkt.text)
+               end
+
+               if pkt._type == "blk_data" then
+                       pkt.blk.param0 = {}
+                       pkt.blk.param1 = {}
+                       pkt.blk.param2 = {}
                end
+
+               dump(pkt)
        elseif not interrupt then
                print("disconnected")
                break