aboutsummaryrefslogtreecommitdiff
path: root/example
diff options
context:
space:
mode:
authorElias Fleckenstein <eliasfleckenstein@web.de>2022-05-31 14:24:19 +0200
committerElias Fleckenstein <eliasfleckenstein@web.de>2022-05-31 14:24:19 +0200
commitfae336d1a2d613fd00640ed6ccbb9eb386086c82 (patch)
tree48f0fe2cf3a3d86d2d0e192f1b38da55bc18d2f7 /example
parent76071affa0f33bef03e323aa0552c750c56a2cab (diff)
downloadhydra-dragonfire-fae336d1a2d613fd00640ed6ccbb9eb386086c82.tar.xz
Add map component
Diffstat (limited to 'example')
-rwxr-xr-xexample/dump-traffic.lua44
-rwxr-xr-xexample/print-node.lua23
2 files changed, 62 insertions, 5 deletions
diff --git a/example/dump-traffic.lua b/example/dump-traffic.lua
index b3d89da..5dc83b6 100755
--- a/example/dump-traffic.lua
+++ b/example/dump-traffic.lua
@@ -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
diff --git a/example/print-node.lua b/example/print-node.lua
new file mode 100755
index 0000000..3cf514e
--- /dev/null
+++ b/example/print-node.lua
@@ -0,0 +1,23 @@
+#!/usr/bin/env hydra-dragonfire
+local client = require("client")()
+client:enable("map")
+
+client:subscribe("move_player")
+client:connect()
+
+local pos
+
+while not hydra.canceled() do
+ local pkt, interrupted = client:poll(1)
+
+ if pkt then
+ pos = (pkt.pos / hydra.BS + vec3(0, -1, 0)):round()
+ elseif not interrupted then
+ break
+ elseif pos then
+ local node = client.map:node(pos)
+ print(pos, node and node.param0)
+ end
+end
+
+client:close()