summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFxQnLr <[email protected]>2024-04-29 17:00:24 +0200
committerFxQnLr <[email protected]>2024-04-29 17:00:24 +0200
commit9233e47a7afa1bee87c53b2bff22bfc5a862c435 (patch)
treeff93168047b8e062aaf0793303311dae01eb315a
parentbf52c4de83022baa626c56e81f1c7b4a6e958774 (diff)
downloadfunsaac-9233e47a7afa1bee87c53b2bff22bfc5a862c435.tar
funsaac-9233e47a7afa1bee87c53b2bff22bfc5a862c435.tar.gz
funsaac-9233e47a7afa1bee87c53b2bff22bfc5a862c435.zip
seems to connect reliably
-rw-r--r--.gitignore2
-rw-r--r--main.lua48
2 files changed, 12 insertions, 38 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..21c8fbc
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
1.vscode
2.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 @@
1local funsaac = RegisterMod("funsaac", 1) 1local funsaac = RegisterMod("funsaac", 1)
2local json = require("json") 2local json = require("json")
3 3
4requestServerInfo = { 4local requestServerInfo = {
5 Id = 1, 5 Id = 1,
6 ClientName = "Funsaac", 6 ClientName = "Funsaac v.0.0.1",
7 MessageVersion = 1 7 MessageVersion = 3
8} 8}
9 9
10--
11-- local client = require("websocket").new("192.168.178.28", 12345)
12local client = require("websocket").new("127.0.0.1", 12345) 10local client = require("websocket").new("127.0.0.1", 12345)
13-- local msg = '"{ RequestServerInfo": ' .. json.encode(requestServerInfo) .. "}" 11function client:onmessage(message)
14-- client:send(msg) 12 print(message)
15-- print(client:read()) 13end
16-- function client:onopen() 14function client:onopen()
17-- client:update()
18-- res = client:read()
19-- print(res)
20-- local msg = '[{"RequestServerInfo": ' .. json.encode(requestServerInfo) .. "}]"
21-- print(msg)
22-- client:send(msg)
23-- -- local msg = '"[{ RequestServerInfo": ' .. json.encode(requestServerInfo) .. "}]"
24-- -- client:send(msg)
25-- -- print(client:read())
26-- -- client:send("")
27-- end
28--client:update()
29
30local function onEnemyDamage(_, entity, amount, damage_flags, source, countdown_frames)
31 print(reqestServerInfo)
32 client:update()
33 local msg = '[{"RequestServerInfo": ' .. json.encode(requestServerInfo) .. "}]" 15 local msg = '[{"RequestServerInfo": ' .. json.encode(requestServerInfo) .. "}]"
34 print(msg) 16 print(msg)
35 client:send(msg) 17 self:send(msg)
36 print(client:read())
37 client:update()
38end 18end
39 19
40local function onStart() 20local function onUpdate()
41 client:update() 21 client:update()
42 res = client:read()
43 -- print(res)
44 local msg = '[{"RequestServerInfo": ' .. json.encode(requestServerInfo) .. "}]"
45 print(msg)
46 client:send(msg)
47 local t = client:read()
48 print(t)
49end 22end
50 23
51funsaac:AddCallback(ModCallbacks.MC_ENTITY_TAKE_DMG, onEnemyDamage) 24funsaac:AddCallback(ModCallbacks.MC_POST_UPDATE, onUpdate) \ No newline at end of file
52funsaac:AddCallback(ModCallbacks.MC_POST_GAME_STARTED, onStart)