summaryrefslogtreecommitdiff
path: root/main.lua
blob: fe9ea57805bbba19b4ebb5ec6606f6ba1847fc55 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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)