]> git.lizzy.rs Git - elidragon_v2.git/commitdiff
Add database system, split plot mod into plot and plotmg
authorElias Fleckenstein <eliasfleckenstein@web.de>
Sat, 27 Feb 2021 20:45:21 +0000 (21:45 +0100)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Sat, 27 Feb 2021 20:45:21 +0000 (21:45 +0100)
20 files changed:
.gitignore
mods/elidragon/init.lua
mods/elidragon/mod.conf
mods/elidragon_class/init.lua [new file with mode: 0644]
mods/elidragon_creative/init.lua
mods/elidragon_creative/mod.conf
mods/elidragon_db/init.lua [new file with mode: 0644]
mods/elidragon_db/mod.conf [new file with mode: 0644]
mods/elidragon_playerdb/init.lua [new file with mode: 0644]
mods/elidragon_playerdb/mod.conf [new file with mode: 0644]
mods/elidragon_plot/init.lua
mods/elidragon_plot/mod.conf
mods/elidragon_plotmg/init.lua [new file with mode: 0644]
mods/elidragon_plotmg/mod.conf [new file with mode: 0644]
mods/elidragon_skyblock/init.lua
mods/elidragon_skyblock/mod.conf
worlds/creative/world.mt
worlds/lobby/world.mt
worlds/skyblock/world.mt
worlds/survival/world.mt

index 6beaa5b736ba6ae190f64f56f7eb21a541c2cf92..debf00bdb46339984ec4e3817c97c22680b5af05 100644 (file)
@@ -1,2 +1,4 @@
 cache/
 storage/
+players/
+!players/.gitkeep
index b3f68a1f47ac6bd2db5f32434ca02950c0c0129c..3dd48db1d715b02370bfcb0ee684d4cf6864f25c 100644 (file)
@@ -1 +1,13 @@
-elidragon = {} 
+local proxy = {
+       WORLDS = {"lobby", "creative", "survival", "skyblock"},
+}
+
+elidragon = setmetatable({}, {
+       __index = function(t, k)
+               return proxy[k]
+       end,
+       __newindex = function(t, k, v)
+               assert(not proxy[k])
+               proxy[k] = v
+       end,
+})
index 18cda9c74ff3f6125474163664d97dff8a74ef9c..a9ee1492e27ab825ee78876c1348245a87b989f8 100644 (file)
@@ -1,3 +1,3 @@
 name = elidragon
 author = Fleckenstein
-description = Initalizer for the Elidragon v2 API
+description = Safe API Initalizer for the Elidragon v2, makes sure that every module is only defined once. Also contains constants
diff --git a/mods/elidragon_class/init.lua b/mods/elidragon_class/init.lua
new file mode 100644 (file)
index 0000000..fac9209
--- /dev/null
@@ -0,0 +1,15 @@
+local function class(classdef)
+       local metatable = {
+               __index = classdef,
+       }
+
+       return function (...)
+               local object = setmetatable({}, metatable)
+               if object.constructor then
+                       object:constructor(...)
+               end
+               return object
+       end
+end
+
+elidragon.class = class
index 0e0f6c47030a84d34d792ef255fe87aba7a535b8..23d3f55bcfdfd331445a1a0b678733b6445db5a1 100644 (file)
@@ -1,19 +1,18 @@
-local plot, schems = elidragon.plot, elidragon.schems
+local plot, plotmg, schems = elidragon.plot, elidragon.plotmg, elidragon.schems
 
 plot.config = {
        gap = 50,
        road_width = 10,
-       mapgen = {
-               min_y = 9,
-               max_y = 9,
-               c_border = minetest.get_content_id("mcl_stairs:slab_stonebrick"),
-               road_schem = "elidragon_creative_road",
-               road_schem_offset = -3,
-       },
-       claiming = {
-               enable_autoclaim_command = true,
-               max_plots = 5,
-       },
+       enable_autoclaim_command = true,
+       max_plots_per_player = 5,
+}
+
+plotmg.config = {
+       min_y = 9,
+       max_y = 9,
+       c_border = minetest.get_content_id("mcl_stairs:slab_stonebrick"),
+       road_schem = "elidragon_creative_road",
+       road_schem_offset = -3,
 }
 
 schems.load("elidragon_creative_road")
index 6da30cfd022a78db082c4ab2087930337a10b6e7..cc423fd2e019d405fcf280cd735e185c63d41878 100644 (file)
@@ -1,4 +1,4 @@
 name = elidragon_creative
 author = Fleckenstein
 description = Creative gamemode for Elidragon v2
-depends = elidragon, elidragon_plot, elidragon_schems, mcl_core
+depends = elidragon, elidragon_plot, elidragon_plotmg, elidragon_schems, mcl_core
diff --git a/mods/elidragon_db/init.lua b/mods/elidragon_db/init.lua
new file mode 100644 (file)
index 0000000..f4f03e8
--- /dev/null
@@ -0,0 +1,46 @@
+local class = elidragon.class
+
+local db = {}
+
+local paths = {}
+local worldpath = minetest.get_worldpath()
+
+function db:constructor(name, initial_data, dir)
+       paths[self] = dir or worldpath .. "/" .. name .. ".json"
+       self:load(initial_data or {})
+end
+
+function db:load(initial_data)
+       local file = io.open(paths[self], "r")
+       local data = file and minetest.parse_json(file:read()) or {}
+       if file then
+               file:close()
+       end
+       for k, v in pairs(data) do
+               self[k] = v
+       end
+       for k, v in pairs(initial_data) do
+               if not rawget(self, k) then
+                       self[k] = v
+               end
+       end
+end
+
+function db:save()
+       local file = assert(io.open(paths[self], "w"))
+       file:write(minetest.write_json(self))
+       file:close()
+end
+
+function db:close()
+       self:save()
+       paths[self] = nil
+end
+
+minetest.register_on_shutdown(function()
+       for d in pairs(private) do
+               d:save()
+       end
+end)
+
+elidragon.db = class(db)
diff --git a/mods/elidragon_db/mod.conf b/mods/elidragon_db/mod.conf
new file mode 100644 (file)
index 0000000..4065b30
--- /dev/null
@@ -0,0 +1,4 @@
+name = elidragon_db
+author = Fleckenstein
+description = Easily migratable JSON databases for Elidragon v2, supports custom paths and safe usage of insecure environment
+depends = elidragon, elidragon_class
diff --git a/mods/elidragon_playerdb/init.lua b/mods/elidragon_playerdb/init.lua
new file mode 100644 (file)
index 0000000..6f53276
--- /dev/null
@@ -0,0 +1,26 @@
+local db = elidragon.db
+
+local playerdb = {
+       initial_data = {},
+       players = {},
+}
+
+local players = playerdb.players
+local env = assert(minetest.request_insecure_environment())
+
+minetest.register_on_joinplayer(function (player)
+       local name = player:get_player_name()
+       if name ~= "rpc" then
+               players[name] = db(name, playerdb.initial_data, "players", env)
+       end
+end)
+
+minetest.register_on_leaveplayer(function (player)
+       local name = player:get_player_name()
+       if name ~= "rpc" then
+               players[name]:close()
+               players[name] = nil
+       end
+end)
+
+elidragon.playerdb = playerdb
diff --git a/mods/elidragon_playerdb/mod.conf b/mods/elidragon_playerdb/mod.conf
new file mode 100644 (file)
index 0000000..e746514
--- /dev/null
@@ -0,0 +1,4 @@
+name = elidragon_playerdb
+author = Fleckenstein
+description = Per-player modular storage shared between worlds for Elidragon v2, multiserver compatible
+depends = elidragon, elidragon_db
index f22d1e3d7409696b4c7e8b40de232ba3bcb10f3f..7942f2ad6cd90181c9c2b77dcc879548026129aa 100644 (file)
@@ -1,79 +1,9 @@
 local plot = {}
 
-minetest.register_on_generated(function(minp, maxp)
-       local config = assert(plot.config)
-       
-       local mgconfig = config.mapgen
-       
-       if not mgconfig then
-               return
-       end
+local old_is_protected = minetest.is_protected
 
-       local min_y, max_y = mgconfig.min_y, mgconfig.max_y
-
-       if maxp.y < min_y or minp.y > max_y then
-               return
-       end
-
-       local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
-       local data = vm:get_data()
-       local area = VoxelArea:new({MinEdge = emin, MaxEdge = emax})
-
-       local void_layer = mgconfig.void_layer
-
-       if void_layer then
-               for idx in area:iter(minp.x, math.max(minp.y, void_layer.min_y), minp.z, maxp.x, math.min(maxp.y, void_layer.max_y), mapx.z) do
-                       data[idx] = void_layer.c_void
-               end
-       end
-
-       local function do_multiples(low, high, base, add, func)
-               for p = math.ceil(low / base), math.floor(high / base) do
-                       func(p * base + add)
-               end
-       end
-       
-       local function do_borders(low, high, base, road, func)
-               do_multiples(low - road, high - road, base,  road, func)
-               do_multiples(low + road, high + road, base, -road, func)
-       end
-       
-       min_y, max_y = math.max(minp.y, min_y), math.min(maxp.y, max_y)
-       
-       local gap, road_width = config.gap, config.road_width
-       local road_width_half = road_width / 2
-
-       do_borders(minp.x, maxp.x, gap, road_width_half, function(x)
-               do_multiples(minp.z - gap + road_width_half, maxp.z - road_width_half, gap, road_width_half, function(start_z)
-                       for idx in area:iter(x, min_y, math.max(minp.z, start_z), x, max_y, math.min(maxp.z, start_z + gap - road_width)) do
-                               data[idx] = mgconfig.c_border
-                       end
-               end)
-       end)
-
-       do_borders(minp.z, maxp.z, gap, road_width_half, function(z)
-               do_multiples(minp.x - gap + road_width_half, maxp.x - road_width_half, gap, road_width_half, function(start_x)
-                       for idx in area:iter(math.max(minp.x, start_x), min_y, z, math.min(maxp.x, start_x + gap - road_width), max_y, z) do
-                               data[idx] = mgconfig.c_border
-                       end
-               end)
-       end)
-       
-       vm:set_data(data)
-       vm:calc_lighting()
-       vm:update_liquids()
-       vm:write_to_map()
-       
-       local road_schem = mgconfig.road_schem
-       
-       if road_schem and min_y == mgconfig.min_y then
-               do_multiples(minp.x, maxp.x, gap, 0, function(x)
-                       do_multiples(minp.z, maxp.z, gap, 0, function(z)
-                               elidragon.schems.add(vector.new(x + road_width_half, min_y + mgconfig.road_schem_offset, z - road_width_half + 1), road_schem)
-                               elidragon.schems.add(vector.new(x - road_width_half + 1, min_y + mgconfig.road_schem_offset, z + road_width_half), road_schem .. "_flipped")
-                       end)
-               end)
-       end
-end)
+function minetest.is_protected(pos, name)
+       return old_is_protected(pos, name)
+end
 
 elidragon.plot = plot
index 25a6f16d51d931dfe0fb1f4389569f9b67356588..9a574b232d75b80f79470e23040709b862d15a92 100644 (file)
@@ -1,4 +1,4 @@
 name = elidragon_plot
 author = Fleckenstein
 description = Flexible plot system for Elidragon v2
-depends = elidragon, mcl_mapgen_core
+depends = elidragon
diff --git a/mods/elidragon_plotmg/init.lua b/mods/elidragon_plotmg/init.lua
new file mode 100644 (file)
index 0000000..eccf652
--- /dev/null
@@ -0,0 +1,76 @@
+local plot, schems = elidragon.plot, elidragon.schems
+
+local plotmg = {}
+
+minetest.register_on_generated(function(minp, maxp)
+        local config = assert(plot.config)
+        local mgconfig = assert(plotmg.config)
+
+        local min_y, max_y = mgconfig.min_y, mgconfig.max_y
+
+        if maxp.y < min_y or minp.y > max_y then
+                return
+        end
+
+        local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
+        local data = vm:get_data()
+        local area = VoxelArea:new({MinEdge = emin, MaxEdge = emax})
+
+        local void_layer = mgconfig.void_layer
+
+        if void_layer then
+                for idx in area:iter(minp.x, math.max(minp.y, void_layer.min_y), minp.z, maxp.x, math.min(maxp.y, void_layer.max_y), mapx.z) do
+                        data[idx] = void_layer.c_void
+                end
+        end
+
+        local function do_multiples(low, high, base, add, func)
+                for p = math.ceil(low / base), math.floor(high / base) do
+                        func(p * base + add)
+                end
+        end
+
+        local function do_borders(low, high, base, road, func)
+                do_multiples(low - road, high - road, base,  road, func)
+                do_multiples(low + road, high + road, base, -road, func)
+        end
+
+        min_y, max_y = math.max(minp.y, min_y), math.min(maxp.y, max_y)
+
+        local gap, road_width = config.gap, config.road_width
+        local road_width_half = road_width / 2
+
+        do_borders(minp.x, maxp.x, gap, road_width_half, function(x)
+                do_multiples(minp.z - gap + road_width_half, maxp.z - road_width_half, gap, road_width_half, function(start_z)
+                        for idx in area:iter(x, min_y, math.max(minp.z, start_z), x, max_y, math.min(maxp.z, start_z + gap - road_width)) do
+                                data[idx] = mgconfig.c_border
+                        end
+                end)
+        end)
+
+        do_borders(minp.z, maxp.z, gap, road_width_half, function(z)
+                do_multiples(minp.x - gap + road_width_half, maxp.x - road_width_half, gap, road_width_half, function(start_x)
+                        for idx in area:iter(math.max(minp.x, start_x), min_y, z, math.min(maxp.x, start_x + gap - road_width), max_y, z) do
+                                data[idx] = mgconfig.c_border
+                        end
+                end)
+        end)
+
+        vm:set_data(data)
+        vm:calc_lighting()
+        vm:update_liquids()
+        vm:write_to_map()
+
+        local road_schem = mgconfig.road_schem
+
+        if road_schem and min_y == mgconfig.min_y then
+                do_multiples(minp.x, maxp.x, gap, 0, function(x)
+                        do_multiples(minp.z, maxp.z, gap, 0, function(z)
+                                schems.add(vector.new(x + road_width_half, min_y + mgconfig.road_schem_offset, z - road_width_half + 1), road_schem)
+                                schems.add(vector.new(x - road_width_half + 1, min_y + mgconfig.road_schem_offset, z + road_width_half), road_schem .. "_flipped")
+                        end)
+                end)
+        end
+end)
+
+elidragon.plotmg = plotmg
diff --git a/mods/elidragon_plotmg/mod.conf b/mods/elidragon_plotmg/mod.conf
new file mode 100644 (file)
index 0000000..b1a066c
--- /dev/null
@@ -0,0 +1,4 @@
+name = elidragon_plotmg
+author = Fleckenstein
+description = Plot map generation for Elidragon v2
+depends = elidragon, elidragon_plot, elidragon_schems, mcl_mapgen_core
index 4940ad373ccb2764099c64c5f95d8328ac2bdfbd..c3ef330b3b99137dca8d55bd5f559fc2d47075ab 100644 (file)
@@ -1,25 +1,24 @@
-local plot = elidragon.plot
+local plot, plotmg = elidragon.plot, elidragon.plotmg
 
 plot.config = {
        gap = 1000,
        road_width = 100,
-       --[[min_y = 2000,
-       max_y = 31000,]]--
-       mapgen = {
+       min_y = 2000,
+       max_y = 31000,
+       auto_allocation = true,
+       on_claim = function() -- create island and move there
+       end
+}
+
+plotmg.config = {
+       min_y = 1000,
+       max_y = 31000,
+       void_layer = {
                min_y = 1000,
-               max_y = 31000,
-               void_layer = {
-                       min_y = 1000,
-                       max_y = 2000,
-                       c_void = minetest.get_content_id("mcl_core:void"),
-               },
-               c_border = minetest.get_content_id("mcl_core:barrier"), -- ToDo: make world border
+               max_y = 2000,
+               c_void = minetest.get_content_id("mcl_core:void"),
        },
-       --[[claiming = {
-               auto_allocation = true,
-               on_claim = function() -- create island and move there
-               end
-       },]]--
+       c_border = minetest.get_content_id("mcl_core:barrier"), -- ToDo: make world border      
 }
 
 elidragon.skyblock = {}
index 35ae6350b4de256514bd683a649a2f098a0556a2..99d07d8837a4cf4a11083b0a437e13fcfc251d25 100644 (file)
@@ -1,4 +1,4 @@
 name = elidragon_skyblock
 author = Fleckenstein
 description = Skyblock gamemode for Elidragon v2
-depends = elidragon, elidragon_plot, mcl_core
+depends = elidragon, elidragon_plot, elidragon_plotmg, mcl_core
index 31be860287808968261a6945635cf4e110bb5469..d1c4aa36f4b0ce540e67b4f6b810c32de03f1b6d 100644 (file)
@@ -6,10 +6,14 @@ auth_backend = sqlite3
 player_backend = sqlite3
 load_mod_default = false
 load_mod_elidragon = true
+load_mod_elidragon_class = true
 load_mod_elidragon_creative = true
+load_mod_elidragon_db = true
 load_mod_elidragon_grouplist = false
 load_mod_elidragon_luckyblock = false
+load_mod_elidragon_playerdb = true
 load_mod_elidragon_plot = true
+load_mod_elidragon_plotmg = true
 load_mod_elidragon_random = false
 load_mod_elidragon_request = true
 load_mod_elidragon_schems = true
index 370bb10b81bfb1e273d5233a3175975e256a851f..4375d0b615c7b896a5243c5b576a23ea0c307431 100644 (file)
@@ -6,10 +6,14 @@ auth_backend = sqlite3
 player_backend = sqlite3
 load_mod_default = false
 load_mod_elidragon = true
+load_mod_elidragon_class = true
 load_mod_elidragon_creative = false
+load_mod_elidragon_db = false
 load_mod_elidragon_grouplist = false
 load_mod_elidragon_luckyblock = false
+load_mod_elidragon_playerdb = true
 load_mod_elidragon_plot = false
+load_mod_elidragon_plotmg = false
 load_mod_elidragon_random = false
 load_mod_elidragon_request = false
 load_mod_elidragon_schems = false
index 9c131d8927cc6d7f8490d07fcc19f14e0b124b30..cfd77d71a63822010a71bf5c04dffbc3c19da664 100644 (file)
@@ -6,10 +6,14 @@ auth_backend = sqlite3
 player_backend = sqlite3
 load_mod_default = true
 load_mod_elidragon = true
+load_mod_elidragon_class = true
 load_mod_elidragon_creative = false
+load_mod_elidragon_db = true
 load_mod_elidragon_grouplist = true
 load_mod_elidragon_luckyblock = true
+load_mod_elidragon_playerdb = true
 load_mod_elidragon_plot = true
+load_mod_elidragon_plotmg = true
 load_mod_elidragon_random = false
 load_mod_elidragon_request = true
 load_mod_elidragon_schems = false
index b3ac373f7fe5f521bc439b2618202ef9a016debe..9de9a2bf355372f8a3f8c10376fb7af7635c0741 100644 (file)
@@ -6,10 +6,14 @@ auth_backend = sqlite3
 player_backend = sqlite3
 load_mod_default = false
 load_mod_elidragon = true
+load_mod_elidragon_class = true
 load_mod_elidragon_creative = false
+load_mod_elidragon_db = true
 load_mod_elidragon_grouplist = false
 load_mod_elidragon_luckyblock = false
+load_mod_elidragon_playerdb = true
 load_mod_elidragon_plot = false
+load_mod_elidragon_plotmg = false
 load_mod_elidragon_random = false
 load_mod_elidragon_request = true
 load_mod_elidragon_schems = false