Removed key secure access (it's up to modders to protect their code)

master
Zughy 2020-11-08 20:52:55 +01:00
parent 77ef73a3dd
commit b94d8c562b
2 changed files with 4 additions and 29 deletions

31
api.lua
View File

@ -7,7 +7,6 @@ achievements_lib = {}
---------------------------------------------- ----------------------------------------------
local function update_storage() end local function update_storage() end
local function generate_access_key() end
local storage = minetest.get_mod_storage() local storage = minetest.get_mod_storage()
local achievements = {} -- KEY: mod; VALUE: {KEY: achievement ID; VALUE: {whatever properties} local achievements = {} -- KEY: mod; VALUE: {KEY: achievement ID; VALUE: {whatever properties}
@ -20,8 +19,6 @@ for pl_name, mods in pairs(storage:to_table().fields) do
p_achievements[pl_name] = minetest.deserialize(mods) p_achievements[pl_name] = minetest.deserialize(mods)
end end
minetest.log("action", dump(p_achievements))
@ -32,15 +29,12 @@ minetest.log("action", dump(p_achievements))
function achievements_lib.register_achievements(mod, mod_achievements) function achievements_lib.register_achievements(mod, mod_achievements)
assert(achievements[mod] == nil, "[ACHIEVEMENTS_LIB] There was an attempt to register the mod " .. mod .. " more than once! Be sure you didn't call this function twice and you didn't install any suspicious mod") assert(achievements[mod] == nil, "[ACHIEVEMENTS_LIB] There was an attempt to register the mod " .. mod .. " more than once! Be sure you didn't call this function twice and you didn't install any suspicious mod")
achievements[mod] = mod_achievements achievements[mod] = mod_achievements
return generate_access_key(mod)
end end
function achievements_lib.add_achievement(p_name, mod_key, achvmt_ID) function achievements_lib.add_achievement(p_name, mod, achvmt_ID)
local mod = access_keys[mod_key]
local achievement = achievements[mod][achvmt_ID] local achievement = achievements[mod][achvmt_ID]
if achievement == nil then return end if achievement == nil then return end
@ -108,15 +102,13 @@ end
-----------------GETTERS---------------------- -----------------GETTERS----------------------
---------------------------------------------- ----------------------------------------------
function achievements_lib.get_achievement(mod_key, achvmt_ID) function achievements_lib.get_achievement(mod, achvmt_ID)
local mod = access_keys[mod_key]
return achievements[mod][achvmt_ID] return achievements[mod][achvmt_ID]
end end
function achievements_lib.get_player_achievements(p_name, mod_key) function achievements_lib.get_player_achievements(p_name, mod)
local mod = access_keys[mod_key]
return p_achievements[p_name][mod] return p_achievements[p_name][mod]
end end
@ -131,20 +123,3 @@ end
function update_storage(p_name) function update_storage(p_name)
storage:set_string(p_name, minetest.serialize(p_achievements[p_name])) storage:set_string(p_name, minetest.serialize(p_achievements[p_name]))
end end
function generate_access_key(mod)
local access_key = ""
-- se si è così sfigati da generare due chiavi uguali, continua finché la nuova non è univoca
repeat
for i = 1, 10 do
access_key = access_key .. string.char(math.random(33,126))
end
until (access_keys[access_key] == nil)
access_keys[access_key] = mod
return access_key
end

View File

@ -1,4 +1,4 @@
local version = "0.beta" local version = "1.0.0"
dofile(minetest.get_modpath("achievements_lib") .. "/api.lua") dofile(minetest.get_modpath("achievements_lib") .. "/api.lua")
dofile(minetest.get_modpath("achievements_lib") .. "/player_manager.lua") dofile(minetest.get_modpath("achievements_lib") .. "/player_manager.lua")