This repository is the home of WeirdConstructor's web based Go board. It's mainly for playing AI and analyzing Go/Baduk/Weiqi games. It's written in Rust and JavaScript.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

109 lines
3.4 KiB

--" (let ((f (http-bind 18099)))\n"
--" (do ((req (mp-wait f) (mp-wait f)))\n"
--" (#t #t)\n"
--" (let ((handle (@1 f)))\n"
--" (http-response\n"
--" handle ; srv-handle\n"
--" (@1 req) ; req-token\n"
--" { :action :json :data { :x 1 :y 2 } }))))\n"
function read_cfg()
local f = io.open("config.json.tmp", "rb")
local d = {}
if f then
local cont = f:read("*a")
d = util.from_json(cont)
f:close()
end
return d
end
function write_cfg(cfg)
local f = io.open("config.json.tmp", "wb")
local x = util.to_json(cfg)
f:write(x)
f:close()
end
local chld_pid = proc.spawn([[
function main()
local mod = require 'gtp_backend'
mod.main()
end
]])
--mp.wait_infinite('foobar')\n"
local cfg = read_cfg()
if not cfg.port then cfg.port = 18099 end
local http_srv = http.bind(cfg.port)
print("TOKEN:" .. rt.dump(http_srv))
while true do
local req = mp.wait({ http_srv[1], "gtp_startup" }, 1000)
if (req) then
print("REQQ:" .. rt.dump(req))
if (req[3] == "gtp_startup") then
print("GTP!")
else
print("REQ: " .. req[4].url)
local fp = string.match(req[4].url, "^/files/(.*)")
local data = {}
if (string.match(req[4].content_type, "application/json")) then
data = util.from_json(req[4].body)
end
local default_ok_response = false
if (string.match(req[4].url, "^/$")) then
http.response(http_srv[2], req[2], {
action = 'file',
path = "webdata/index.html",
})
elseif (fp) then
http.response(http_srv[2], req[2], {
action = 'file',
path = "webdata/" .. fp,
})
elseif (string.match(req[4].url, "^/data/cfg")) then
elseif (string.match(req[4].url, "^/action/connect_engine")) then
print("DTA:" .. rt.dump(data))
mp.send(chld_pid, { "gtp_connect", data })
default_ok_response = true
elseif (string.match(req[4].url, "^/action/gtp/genmove_from_board")) then
print("DTA:" .. rt.dump(data))
mp.send(chld_pid, { "genmove_from_board", data })
local m = mp.wait_infinite("genmove_from_board")
print("RESPO" .. rt.dump(m))
http.response(http_srv[2], req[2], {
action = 'json',
data = { move = m[4], color = m[5] },
})
elseif (string.match(req[4].url, "^/action/engine/")) then
local gt = string.match(req[4].url, "^/action/engine/(%d+)/([^/]+)/(.*)")
print("GOGO" .. rt.dump(gt))
http.response(http_srv[2], req[2], {
action = 'json',
data = {
state_id = 1,
},
})
else
http.response(http_srv[2], req[2], {
action = 'json',
data = { x = 1, y = 2 }
})
end
if default_ok_response then
http.response(http_srv[2], req[2], { action = 'json', data = { ok = true } })
end
end
end
end