From 9233e47a7afa1bee87c53b2bff22bfc5a862c435 Mon Sep 17 00:00:00 2001 From: FxQnLr Date: Mon, 29 Apr 2024 17:00:24 +0200 Subject: seems to connect reliably --- .gitignore | 2 ++ main.lua | 48 ++++++++++-------------------------------------- 2 files changed, 12 insertions(+), 38 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..21c8fbc --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.vscode +.luarc.json \ No newline at end of file diff --git a/main.lua b/main.lua index fe9ea57..40acc5b 100644 --- a/main.lua +++ b/main.lua @@ -1,52 +1,24 @@ local funsaac = RegisterMod("funsaac", 1) local json = require("json") -requestServerInfo = { +local requestServerInfo = { Id = 1, - ClientName = "Funsaac", - MessageVersion = 1 + ClientName = "Funsaac v.0.0.1", + MessageVersion = 3 } --- --- 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() +function client:onmessage(message) + print(message) +end +function client:onopen() local msg = '[{"RequestServerInfo": ' .. json.encode(requestServerInfo) .. "}]" print(msg) - client:send(msg) - print(client:read()) - client:update() + self:send(msg) end -local function onStart() +local function onUpdate() 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) +funsaac:AddCallback(ModCallbacks.MC_POST_UPDATE, onUpdate) \ No newline at end of file -- cgit v1.2.3