forked from googolgl/lp_api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.lua
34 lines (31 loc) · 1.3 KB
/
init.lua
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
lp_api = {}
lp_api.enabled = minetest.settings:get_bool("lp_api.enabled", false)
if not lp_api.enabled then return end
lp_api.http = minetest.request_http_api()
lp_api.url = minetest.settings:get("lp_api.url") or "http://localhost:8003"
lp_api.channel_id = minetest.settings:get("lp_api.channel_id") or "minetest"
lp_api.timeout = minetest.settings:get("lp_api.timeout") or 30
-- For secure connect set header value (Authorization: Basic bG9naW46cGFzc3dvcmQ=)
-- where bG9naW46cGFzc3dvcmQ= is the base64(login:password) "Content-Type: application/json; charset=utf8"
lp_api.header = minetest.settings:get("lp_api.header") or nil
function lp_api.request_http(ext_url,pd,response_handler,pmethod)
local req = {
url = lp_api.url..ext_url,
method = pmethod,
post_data = pd,
extra_headers = {lp_api.header},
timeout = lp_api.timeout
}
lp_api.http.fetch(req, function(result)
pcall(response_handler, result)
end)
end
if lp_api.http then
local default_path = minetest.get_modpath("lp_api")
dofile(default_path.."/router.lua")
dofile(default_path.."/publisher.lua")
dofile(default_path.."/subscriber.lua")
minetest.log("[lp_api] Loading... [OK]")
else
minetest.log("[lp_api] Please setup (secure.http_mod = lp_api) in minetest.conf... [ERROR]")
end