This commit is contained in:
Thomas Rudin 2019-05-04 20:57:57 +02:00
parent a7c44c3c30
commit 3fe8525ce0
28 changed files with 0 additions and 660 deletions

View File

@ -1,6 +1,5 @@
OUT_DIR=output OUT_DIR=output
MOD_ZIP=$(OUT_DIR)/mapserver-mod.zip
VERSION=git-$(shell git rev-parse HEAD) VERSION=git-$(shell git rev-parse HEAD)
all: builder_image $(OUT_DIR) $(MOD_ZIP) all: builder_image $(OUT_DIR) $(MOD_ZIP)
@ -18,20 +17,9 @@ builder_image:
# build the docker image with all dependencies # build the docker image with all dependencies
$(MAKE) -C docker_builder build $(MAKE) -C docker_builder build
$(OUT_DIR): $(OUT_DIR):
mkdir $@ mkdir $@
$(MOD_ZIP): builder_image $(OUT_DIR)
# lint with luacheck
sudo docker run --rm -it\
-v $(shell pwd)/mapserver_mod/mapserver:/app\
-w /app\
mapserver-builder\
luacheck .
# zip mod
zip -r $(OUT_DIR)/mapserver-mod.zip mapserver_mod
clean: clean:
rm -rf $(OUT_DIR) rm -rf $(OUT_DIR)
$(MAKE) -C server clean $(MAKE) -C server clean

View File

@ -1,24 +0,0 @@
unused_args = false
allow_defined_top = true
globals = {
"mapserver"
}
read_globals = {
-- Stdlib
string = {fields = {"split"}},
table = {fields = {"copy", "getn"}},
-- Minetest
"minetest",
"vector", "ItemStack",
"dump",
-- Deps
"unified_inventory", "default", "advtrains",
"minecart",
-- optional mods
"xban"
}

View File

@ -1,81 +0,0 @@
local last_index = 0
local last_name = ""
local update_formspec = function(meta)
local name = meta:get_string("name")
local index = meta:get_string("index")
local color = meta:get_string("color") or "rgb(10,10,200)"
meta:set_string("infotext", "Border: Name=" .. name .. ", Index=" .. index)
meta:set_string("formspec", "size[8,4;]" ..
-- col 1
"field[0,1;4,1;name;Name;" .. name .. "]" ..
"button_exit[4,1;4,1;save;Save]" ..
-- col 2
"field[4,2.5;4,1;index;Index;" .. index .. "]" ..
-- col 3
"field[4,3.5;4,1;color;Color;" .. color .. "]" ..
"")
end
minetest.register_node("mapserver:border", {
description = "Mapserver Border",
tiles = {
"mapserver_border.png"
},
groups = {cracky=3,oddly_breakable_by_hand=3},
sounds = default.node_sound_glass_defaults(),
can_dig = mapserver.can_dig,
after_place_node = mapserver.after_place_node,
on_construct = function(pos)
local meta = minetest.get_meta(pos)
last_index = last_index + 5
meta:set_string("color", "rgb(10,10,200)")
meta:set_string("name", last_name)
meta:set_int("index", last_index)
update_formspec(meta)
end,
on_receive_fields = function(pos, formname, fields, sender)
if not mapserver.can_interact(pos, sender) then
return
end
local meta = minetest.get_meta(pos)
if fields.save then
last_name = fields.name
meta:set_string("name", fields.name)
meta:set_string("color", fields.color)
local index = tonumber(fields.index)
if index ~= nil then
last_index = index
meta:set_int("index", index)
end
end
update_formspec(meta)
end
})
if mapserver.enable_crafting then
minetest.register_craft({
output = 'mapserver:border',
recipe = {
{"", "default:steel_ingot", ""},
{"default:paper", "default:goldblock", "default:paper"},
{"", "default:glass", ""}
}
})
end

View File

@ -1,31 +0,0 @@
mapserver.bridge.add_advtrains = function(data)
data.trains = {}
for _, train in pairs(advtrains.trains) do
local t = {
text_outside = train.text_outside,
text_inside = train.text_inside,
line = train.line,
pos = train.last_pos,
velocity = train.velocity,
off_track = train.off_track,
id = train.id,
wagons = {}
}
for _, part in pairs(train.trainparts) do
local wagon = advtrains.wagons[part]
if wagon ~= nil then
table.insert(t.wagons, {
id = wagon.id,
type = wagon.type,
pos_in_train = wagon.pos_in_train,
})
end
end
table.insert(data.trains, t)
end
end

View File

@ -1,24 +0,0 @@
local function explode(sep, input)
local t={}
local i=0
for k in string.gmatch(input,"([^"..sep.."]+)") do
t[i]=k
i=i+1
end
return t
end
local function get_max_lag()
local arrayoutput = explode(", ",minetest.get_server_status())
arrayoutput = explode("=",arrayoutput[4])
return arrayoutput[1]
end
mapserver.bridge.add_defaults = function(data)
data.time = minetest.get_timeofday() * 24000
data.uptime = minetest.get_server_uptime()
data.max_lag = tonumber(get_max_lag())
end

View File

@ -1,69 +0,0 @@
local MP = minetest.get_modpath("mapserver")
dofile(MP .. "/bridge/defaults.lua")
dofile(MP .. "/bridge/players.lua")
dofile(MP .. "/bridge/advtrains.lua")
dofile(MP .. "/bridge/minecart.lua")
-- mapserver http bridge
local has_advtrains = minetest.get_modpath("advtrains")
local has_minecart = minetest.get_modpath("minecart")
local http, url, key
function send_stats()
local t0 = minetest.get_us_time()
-- data to send to mapserver
local data = {}
mapserver.bridge.add_players(data)
mapserver.bridge.add_defaults(data)
if has_minecart then
-- send minecarts positions if mod is installed
mapserver.bridge.add_minecart(data)
end
if has_advtrains then
-- send trains if 'advtrains' mod installed
mapserver.bridge.add_advtrains(data)
end
local json = minetest.write_json(data)
--print(json)--XXX
local t1 = minetest.get_us_time()
local process_time = t1 - t0
if process_time > 10000 then
minetest.log("warning", "[mapserver-bridge] processing took " .. process_time .. " us")
end
http.fetch({
url = url .. "/api/minetest",
extra_headers = { "Content-Type: application/json", "Authorization: " .. key },
timeout = 1,
post_data = json
}, function(res)
local t2 = minetest.get_us_time()
local post_time = t2 - t1
if post_time > 1000000 then -- warn if over a second
minetest.log("warning", "[mapserver-bridge] post took " .. post_time .. " us")
end
-- TODO: error-handling
minetest.after(2, send_stats)
end)
end
function mapserver.bridge_init(_http, _url, _key)
http = _http
url = _url
key = _key
minetest.after(2, send_stats)
end

View File

@ -1,4 +0,0 @@
mapserver.bridge.add_minecart = function(data)
data.minecarts = minecart.get_cart_list()
end

View File

@ -1,23 +0,0 @@
mapserver.bridge.add_players = function(data)
data.players = {}
for _, player in ipairs(minetest.get_connected_players()) do
local is_hidden = minetest.check_player_privs(player:get_player_name(), {mapserver_hide_player = true})
local info = {
name = player:get_player_name(),
pos = player:get_pos(),
hp = player:get_hp(),
breath = player:get_breath(),
velocity = player:get_player_velocity()
}
if not is_hidden then
table.insert(data.players, info)
end
end
end

View File

@ -1,28 +0,0 @@
mapserver.can_dig = function(pos, player)
local meta = minetest.get_meta(pos)
local owner = meta:get_string("owner")
return player and player:get_player_name() == owner
end
mapserver.after_place_node = function(pos, placer)
local meta = minetest.get_meta(pos)
meta:set_string("owner", placer:get_player_name() or "")
end
mapserver.can_interact = function(pos, player)
local meta = minetest.get_meta(pos)
local owner = meta:get_string("owner")
local playername = player:get_player_name()
if playername == owner then
return true
end
if minetest.check_player_privs(playername, {protection_bypass = true}) then
return true
end
return false
end

View File

@ -1,4 +0,0 @@
default
dye
advtrains?
minecart?

View File

@ -1,39 +0,0 @@
mapserver = {
enable_crafting = minetest.settings:get("mapserver.enable_crafting"),
bridge = {}
}
local MP = minetest.get_modpath("mapserver")
dofile(MP.."/common.lua")
dofile(MP.."/poi.lua")
dofile(MP.."/train.lua")
dofile(MP.."/label.lua")
dofile(MP.."/border.lua")
dofile(MP.."/legacy.lua")
dofile(MP.."/privs.lua")
-- optional mapserver-bridge stuff below
local http = minetest.request_http_api()
if http then
local mapserver_url = minetest.settings:get("mapserver.url")
local mapserver_key = minetest.settings:get("mapserver.key")
if not mapserver_url then error("mapserver.url is not defined") end
if not mapserver_key then error("mapserver.key is not defined") end
print("[Mapserver] starting mapserver-bridge with endpoint: " .. mapserver_url)
dofile(MP .. "/bridge/init.lua")
mapserver.bridge_init(http, mapserver_url, mapserver_key)
else
print("[Mapserver] bridge not active, additional infos will not be visible on the map")
end
print("[OK] Mapserver")

View File

@ -1,78 +0,0 @@
local update_formspec = function(meta)
local text = meta:get_string("text")
local size = meta:get_string("size")
local direction = meta:get_string("direction")
local color = meta:get_string("color") or "rgb(0,0,0)"
meta:set_string("infotext", "Label, Text:" .. text .. ", Size:" .. size .. ", Direction:" .. direction)
meta:set_string("formspec", "size[8,6;]" ..
-- col 1
"field[0,1;4,1;text;Text;" .. text .. "]" ..
"button_exit[4,1;4,1;save;Save]" ..
-- col 2
"field[0,2.5;4,1;size;Size (1-10);" .. size .. "]" ..
-- col 3
"field[0,3.5;8,1;direction;Direction (0-360);" .. direction .. "]" ..
-- col 4
"field[0,4.5;8,1;color;Color;" .. color .. "]" ..
"")
end
minetest.register_node("mapserver:label", {
description = "Mapserver Label",
tiles = {
"mapserver_label.png"
},
groups = {cracky=3,oddly_breakable_by_hand=3},
sounds = default.node_sound_glass_defaults(),
can_dig = mapserver.can_dig,
after_place_node = mapserver.after_place_node,
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("text", "")
meta:set_string("direction", "0")
meta:set_string("size", "20")
meta:set_string("color", "rgb(0,0,0)")
update_formspec(meta)
end,
on_receive_fields = function(pos, formname, fields, sender)
if not mapserver.can_interact(pos, sender) then
return
end
local meta = minetest.get_meta(pos)
if fields.save then
meta:set_string("color", fields.color)
meta:set_string("text", fields.text)
meta:set_string("direction", fields.direction)
meta:set_string("size", fields.size)
end
update_formspec(meta)
end
})
if mapserver.enable_crafting then
minetest.register_craft({
output = 'mapserver:label',
recipe = {
{"", "default:paper", ""},
{"default:paper", "default:goldblock", "default:paper"},
{"", "default:glass", ""}
}
})
end

View File

@ -1,20 +0,0 @@
minetest.register_lbm({
label = "Tileserver->Mapserver poi upgrade",
name = "mapserver:poi",
nodenames = {"tileserver:poi"},
run_at_every_load = true,
action = function(pos, node)
minetest.swap_node(pos, { name="mapserver:poi" })
end
})
minetest.register_lbm({
label = "Tileserver->Mapserver train upgrade",
name = "mapserver:train",
nodenames = {"tileserver:train"},
run_at_every_load = true,
action = function(pos, node)
minetest.swap_node(pos, { name="mapserver:train" })
end
})

View File

@ -1,87 +0,0 @@
-- possible icons: https://fontawesome.com/icons?d=gallery&s=brands,regular,solid&m=free
-- default: "home"
local update_formspec = function(meta)
local name = meta:get_string("name")
local icon = meta:get_string("icon") or "home"
local url = meta:get_string("url") or ""
meta:set_string("infotext", "POI, name:" .. name .. ", icon:" .. icon)
meta:set_string("formspec", "size[8,5;]" ..
-- col 1
"field[0,1;4,1;name;Name;" .. name .. "]" ..
"button_exit[4,1;4,1;save;Save]" ..
-- col 2
"field[0,2.5;4,1;icon;Icon;" .. icon .. "]" ..
-- col 3
"field[0,3.5;8,1;url;URL;" .. url .. "]" ..
"")
end
local on_receive_fields = function(pos, formname, fields, sender)
if not mapserver.can_interact(pos, sender) then
return
end
local meta = minetest.get_meta(pos)
if fields.save then
meta:set_string("name", fields.name)
meta:set_string("url", fields.url)
meta:set_string("icon", fields.icon or "home")
end
update_formspec(meta)
end
local register_poi = function(color, dye)
minetest.register_node("mapserver:poi_" .. color, {
description = "Mapserver POI (" .. color .. ")",
tiles = {
"[combine:16x16:0,0=mapserver_gold_block.png:3,2=mapserver_poi_" .. color .. ".png"
},
groups = {cracky=3,oddly_breakable_by_hand=3},
sounds = default.node_sound_glass_defaults(),
can_dig = mapserver.can_dig,
after_place_node = mapserver.after_place_node,
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("name", "<unconfigured>")
meta:set_string("icon", "home")
meta:set_string("url", "")
update_formspec(meta)
end,
on_receive_fields = on_receive_fields
})
if mapserver.enable_crafting then
minetest.register_craft({
output = 'mapserver:poi_' .. color,
recipe = {
{"", "dye:" .. dye, ""},
{"default:paper", "default:goldblock", "default:paper"},
{"", "default:glass", ""}
}
})
end
end
register_poi("blue", "blue")
register_poi("green", "green")
register_poi("orange", "orange")
register_poi("red", "red")
register_poi("purple", "violet")
-- default poi was always blue
minetest.register_alias("mapserver:poi", "mapserver:poi_blue")

View File

@ -1,5 +0,0 @@
minetest.register_privilege("mapserver_hide_player", {
description = "Player is hidden from the map",
give_to_singleplayer = false
})

View File

@ -1,12 +0,0 @@
# mapserver mod
## active mode configuration
minetest.conf
```
secure.http_mods = mapserver
mapserver.url = http://127.0.0.1:8080
mapserver.key = myserverkey
```

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 483 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 900 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 900 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 900 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 891 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 900 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 279 B

View File

@ -1,86 +0,0 @@
local last_index = 0
local last_line = ""
local update_formspec = function(meta)
local line = meta:get_string("line")
local station = meta:get_string("station")
local index = meta:get_string("index")
local color = meta:get_string("color") or ""
meta:set_string("infotext", "Train: Line=" .. line .. ", Station=" .. station)
meta:set_string("formspec", "size[8,4;]" ..
-- col 1
"field[0,1;4,1;line;Line;" .. line .. "]" ..
"button_exit[4,1;4,1;save;Save]" ..
-- col 2
"field[0,2.5;4,1;station;Station;" .. station .. "]" ..
"field[4,2.5;4,1;index;Index;" .. index .. "]" ..
-- col 3
"field[0,3.5;4,1;color;Color;" .. color .. "]" ..
""
)
end
minetest.register_node("mapserver:train", {
description = "Mapserver Train",
tiles = {
"mapserver_train.png"
},
groups = {cracky=3,oddly_breakable_by_hand=3},
sounds = default.node_sound_glass_defaults(),
can_dig = mapserver.can_dig,
after_place_node = mapserver.after_place_node,
on_construct = function(pos)
local meta = minetest.get_meta(pos)
last_index = last_index + 5
meta:set_string("station", "")
meta:set_string("line", last_line)
meta:set_int("index", last_index)
meta:set_string("color", "")
update_formspec(meta)
end,
on_receive_fields = function(pos, formname, fields, sender)
if not mapserver.can_interact(pos, sender) then
return
end
local meta = minetest.get_meta(pos)
if fields.save then
last_line = fields.line
meta:set_string("color", fields.color)
meta:set_string("line", fields.line)
meta:set_string("station", fields.station)
local index = tonumber(fields.index)
if index ~= nil then
last_index = index
meta:set_int("index", index)
end
end
update_formspec(meta)
end
})
if mapserver.enable_crafting then
minetest.register_craft({
output = 'mapserver:train',
recipe = {
{"", "default:steel_ingot", ""},
{"default:paper", "default:goldblock", "default:paper"},
{"", "default:glass", ""}
}
})
end

View File

@ -1,33 +0,0 @@
#!/bin/sh
VERSION=$1
test -z "$VERSION" &&{
echo "Usage: $0 <version>"
exit 1
}
make clean all
git tag $VERSION
export GITHUB_TOKEN=`cat .releasetoken`
gothub="go run github.com/itchio/gothub"
gothub_release="$gothub release --user thomasrudin-mt --repo mapserver"
gothub_upload="$gothub upload --user thomasrudin-mt --repo mapserver"
$gothub_release --tag $VERSION --name "Version $VERSION"
FILES="mapserver-linux-arm mapserver-linux-x86 mapserver-linux-x86_64 mapserver-mod.zip mapserver-windows-x86-64.exe mapserver-windows-x86.exe"
for file in $FILES
do
$gothub_upload --tag $VERSION --name "$file" --file output/$file
done
git push --tags