diff options
| author | Elias Fleckenstein <eliasfleckenstein@web.de> | 2022-05-31 14:24:19 +0200 |
|---|---|---|
| committer | Elias Fleckenstein <eliasfleckenstein@web.de> | 2022-05-31 14:24:19 +0200 |
| commit | fae336d1a2d613fd00640ed6ccbb9eb386086c82 (patch) | |
| tree | 48f0fe2cf3a3d86d2d0e192f1b38da55bc18d2f7 /example | |
| parent | 76071affa0f33bef03e323aa0552c750c56a2cab (diff) | |
| download | hydra-dragonfire-fae336d1a2d613fd00640ed6ccbb9eb386086c82.tar.xz | |
Add map component
Diffstat (limited to 'example')
| -rwxr-xr-x | example/dump-traffic.lua | 44 | ||||
| -rwxr-xr-x | example/print-node.lua | 23 |
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() |
