From bf52c4de83022baa626c56e81f1c7b4a6e958774 Mon Sep 17 00:00:00 2001 From: FxQnLr Date: Sun, 28 Apr 2024 15:34:26 +0200 Subject: working handshake plus response --- main.lua | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 main.lua (limited to 'main.lua') diff --git a/main.lua b/main.lua new file mode 100644 index 0000000..fe9ea57 --- /dev/null +++ b/main.lua @@ -0,0 +1,52 @@ +local funsaac = RegisterMod("funsaac", 1) +local json = require("json") + +requestServerInfo = { + Id = 1, + ClientName = "Funsaac", + MessageVersion = 1 +} + +-- +-- local client = require("websocket").new("192.168.178.28", 12345) +local client = require("websocket").new("127.0.0.1", 12345) +-- local msg = '"{ RequestServerInfo": ' .. json.encode(requestServerInfo) .. "}" +-- client:send(msg) +-- print(client:read()) +-- function client:onopen() +-- client:update() +-- res = client:read() +-- print(res) +-- local msg = '[{"RequestServerInfo": ' .. json.encode(requestServerInfo) .. "}]" +-- print(msg) +-- client:send(msg) +-- -- local msg = '"[{ RequestServerInfo": ' .. json.encode(requestServerInfo) .. "}]" +-- -- client:send(msg) +-- -- print(client:read()) +-- -- client:send("") +-- end +--client:update() + +local function onEnemyDamage(_, entity, amount, damage_flags, source, countdown_frames) + print(reqestServerInfo) + client:update() + local msg = '[{"RequestServerInfo": ' .. json.encode(requestServerInfo) .. "}]" + print(msg) + client:send(msg) + print(client:read()) + client:update() +end + +local function onStart() + client:update() + res = client:read() + -- print(res) + local msg = '[{"RequestServerInfo": ' .. json.encode(requestServerInfo) .. "}]" + print(msg) + client:send(msg) + local t = client:read() + print(t) +end + +funsaac:AddCallback(ModCallbacks.MC_ENTITY_TAKE_DMG, onEnemyDamage) +funsaac:AddCallback(ModCallbacks.MC_POST_GAME_STARTED, onStart) -- cgit v1.2.3