Skip to content
Snippets Groups Projects
Commit 06a979f0 authored by NatureFreshMilk's avatar NatureFreshMilk
Browse files

read key and url from mapserver.json (fixes https://github.com/minetest-tools/mapserver/issues/55)

parent 3d8e2616
No related branches found
No related tags found
No related merge requests found
...@@ -20,9 +20,34 @@ dofile(MP.."/privs.lua") ...@@ -20,9 +20,34 @@ dofile(MP.."/privs.lua")
local http = minetest.request_http_api() local http = minetest.request_http_api()
if http then if http then
-- check if the mapserver.json is in the world-folder
local path = minetest.get_worldpath().."/mapserver.json";
local mapserver_cfg
local file = io.open( path, "r" );
if file then
local json = file:read("*all");
mapserver_cfg = minetest.parse_json(json);
file:close();
print("[Mapserver] read settings from 'mapserver.json'")
end
print(dump(mapserver_cfg))
local mapserver_url = minetest.settings:get("mapserver.url") local mapserver_url = minetest.settings:get("mapserver.url")
local mapserver_key = minetest.settings:get("mapserver.key") local mapserver_key = minetest.settings:get("mapserver.key")
if mapserver_cfg and mapserver_cfg.webapi then
if not mapserver_key then
-- apply key from json
mapserver_key = mapserver_cfg.webapi.secretkey
end
if not mapserver_url then
-- assemble url from json
mapserver_url = "http://127.0.0.1:" .. mapserver_cfg.port
end
end
if not mapserver_url then error("mapserver.url is not defined") end if not mapserver_url then error("mapserver.url is not defined") end
if not mapserver_key then error("mapserver.key is not defined") end if not mapserver_key then error("mapserver.key is not defined") end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment