Remove mod storage checks

This commit is contained in:
upsilon 2017-06-23 13:47:41 +02:00
parent 4c81b43032
commit ce9544d2bf
No known key found for this signature in database
GPG Key ID: A80DAE1F266E1C3C
4 changed files with 17 additions and 71 deletions

View File

@ -3,21 +3,11 @@ local get = vector.get_data_from_pos
local set = vector.set_data_to_pos
local remove = vector.remove_data_from_pos
local jammers
local enable_lbm = moremesecons.setting("jammer", "enable_lbm", false)
local storage
if not minetest.get_mod_storage then
enable_lbm = true -- No mod storage (<= 0.4.15-stable): force registration of LBM
jammers = {}
else
storage = minetest.get_mod_storage()
jammers = minetest.deserialize(storage:get_string("jammers")) or {}
end
local storage = minetest.get_mod_storage()
local jammers = minetest.deserialize(storage:get_string("jammers")) or {}
local function update_mod_storage()
if not storage then
return
end
storage:set_string("jammers", minetest.serialize(jammers))
end
@ -143,7 +133,7 @@ minetest.register_craft({
{"", "moremesecons_wireless:jammer_off", ""}}
})
if enable_lbm then
if moremesecons.setting("jammer", "enable_lbm", false) then
minetest.register_lbm({
name = "moremesecons_jammer:add_jammer",
nodenames = {"moremesecons_jammer:jammer_on"},

View File

@ -1,26 +1,13 @@
local hash_table
local md5
local storage
if minetest.get_mod_storage then
md5 = dofile(minetest.get_modpath(minetest.get_current_modname()).."/md5_lua/md5.lua")
storage = minetest.get_mod_storage()
hash_table = minetest.deserialize(storage:get_string("hash_table")) or {}
else
minetest.log("warning", "[moremesecons_luablock] Your version of Minetest does not provide a mod storage API. The mod storage allows moremesecons_luablock to store md5 checksums, which avoids some potential security breaches.")
end
local md5 = dofile(minetest.get_modpath(minetest.get_current_modname()).."/md5_lua/md5.lua")
local storage = minetest.get_mod_storage()
local hash_table = minetest.deserialize(storage:get_string("hash_table")) or {}
local function set_md5(pos, code)
if not hash_table then
return
end
vector.set_data_to_pos(hash_table, pos.z,pos.y,pos.x, md5.sum(code))
storage:set_string("hash_table", minetest.serialize(hash_table))
end
local function check_md5(pos, code)
if not hash_table then
return true
end
local stored_sum = vector.get_data_from_pos(hash_table, pos.z,pos.y,pos.x)
if not stored_sum then
-- Legacy

View File

@ -1,25 +1,10 @@
local teleporters
local teleporters_rids
local storage = minetest.get_mod_storage()
local enable_lbm = moremesecons.setting("teleporter", "enable_lbm", false)
local storage
if not minetest.get_mod_storage then
enable_lbm = true -- No mod storage (<= 0.4.15-stable): force registration of LBM
teleporters = {}
teleporters_rids = {}
jammers = {}
else
storage = minetest.get_mod_storage()
teleporters = minetest.deserialize(storage:get_string("teleporters")) or {}
teleporters_rids = minetest.deserialize(storage:get_string("teleporters_rids")) or {}
jammers = minetest.deserialize(storage:get_string("jammers")) or {}
end
local teleporters = minetest.deserialize(storage:get_string("teleporters")) or {}
local teleporters_rids = minetest.deserialize(storage:get_string("teleporters_rids")) or {}
local jammers = minetest.deserialize(storage:get_string("jammers")) or {}
local function update_mod_storage()
if not storage then
return
end
storage:set_string("teleporters", minetest.serialize(teleporters))
storage:set_string("teleporters_rids", minetest.serialize(teleporters_rids))
end
@ -113,7 +98,7 @@ minetest.register_node("moremesecons_teleporter:teleporter", {
end,
})
if enable_lbm then
if moremesecons.setting("teleporter", "enable_lbm", false) then
minetest.register_lbm({
name = "moremesecons_teleporter:add_teleporter",
nodenames = {"moremesecons_teleporter:teleporter"},

View File

@ -1,26 +1,10 @@
local wireless
local wireless_meta -- This table contains wireless metadatas, it is a lot faster to access
local jammers
local storage = minetest.get_mod_storage()
local enable_lbm = moremesecons.setting("wireless", "enable_lbm", false)
local storage
if not minetest.get_mod_storage then
enable_lbm = true -- No mod storage (<= 0.4.15-stable): force registration of LBM
wireless = {}
wireless_meta = {owners = {}, channels = {}, ids = {}}
jammers = {}
else
storage = minetest.get_mod_storage()
wireless = minetest.deserialize(storage:get_string("wireless")) or {}
wireless_meta = minetest.deserialize(storage:get_string("wireless_meta")) or {owners = {}, channels = {}, ids = {}}
jammers = minetest.deserialize(storage:get_string("jammers")) or {}
end
local wireless = minetest.deserialize(storage:get_string("wireless")) or {}
local wireless_meta = minetest.deserialize(storage:get_string("wireless_meta")) or {owners = {}, channels = {}, ids = {}}
local jammers = minetest.deserialize(storage:get_string("jammers")) or {}
local function update_mod_storage()
if not storage then
return
end
storage:set_string("wireless", minetest.serialize(wireless))
storage:set_string("wireless_meta", minetest.serialize(wireless_meta))
storage:set_string("jammers", minetest.serialize(jammers))
@ -377,7 +361,7 @@ minetest.register_craft({
}
})
if enable_lbm then
if moremesecons.setting("wireless", "enable_lbm", false) then
minetest.register_lbm({
name = "moremesecons_wireless:add_jammer",
nodenames = {"moremesecons_wireless:jammer_on"},