*Reorganized code so that further expansion is possible in a very organized manner.
*modpol.add_member() -- added a check if the member is already a member of that organized *storage -- fixed bug by moving storageref to top of file *added on_joinplayer to add players to instance *moved minetest specific code in init.lua to modpol_minetest, organized in folders. All overrides in one folder, all chatcommands in another, the on_joinplayer in modpol_minetest/orgs/instance.lua
This commit is contained in:
117
storage/storage-local.lua
Normal file
117
storage/storage-local.lua
Normal file
@ -0,0 +1,117 @@
|
||||
-- ===================================================================
|
||||
-- /storage-local.lua
|
||||
-- Persistent storage in /data using Serpent Serializer
|
||||
-- Unix systems only
|
||||
|
||||
-- ===================================================================
|
||||
-- Set directories and filenames
|
||||
|
||||
modpol.datadir = modpol.topdir .. "/data"
|
||||
modpol.file_ledger = modpol.datadir .. "/ledger.dat"
|
||||
modpol.file_orgs = modpol.datadir .. "/orgs.dat"
|
||||
|
||||
os.execute ("mkdir -p " .. modpol.datadir)
|
||||
|
||||
modpol.ocutil.setlogdir (modpol.datadir)
|
||||
modpol.ocutil.setlogname ("modpol.log")
|
||||
|
||||
-- ===================================================================
|
||||
-- Set up the Serpent Serializer functions.
|
||||
|
||||
modpol.serpent = {}
|
||||
dofile (modpol.topdir .. "/util/serpent/serpent.lua")
|
||||
|
||||
-- ===================================================================
|
||||
-- This function stores "ledger" data to disk.
|
||||
|
||||
local store_ledger = function()
|
||||
local ok = modpol.ocutil.file_write (modpol.file_ledger,
|
||||
modpol.serpent.dump (modpol.ledger))
|
||||
|
||||
if ok ~= true then
|
||||
modpol.ocutil.fatal_error ("store_data: ledger")
|
||||
end
|
||||
|
||||
local nn = modpol.ocutil.table_length (modpol.ledger)
|
||||
local str = "entries"
|
||||
if nn == 1 then str = "entry" end
|
||||
modpol.ocutil.log (nn .. " global ledger entries stored to disk")
|
||||
end
|
||||
|
||||
-- ===================================================================
|
||||
-- This function stores "orgs" data to disk.
|
||||
|
||||
local store_orgs = function()
|
||||
local ok = modpol.ocutil.file_write (modpol.file_orgs,
|
||||
modpol.serpent.dump (modpol.orgs))
|
||||
|
||||
if ok ~= true then
|
||||
modpol.ocutil.fatal_error ("store_data: orgs")
|
||||
end
|
||||
|
||||
local nn = modpol.ocutil.table_length (modpol.orgs)
|
||||
local str = "entries"
|
||||
if nn == 1 then str = "entry" end
|
||||
modpol.ocutil.log (nn .. " orgs stored to disk")
|
||||
end
|
||||
|
||||
-- ===================================================================
|
||||
-- This function stores data to disk.
|
||||
|
||||
modpol.store_data = function()
|
||||
store_ledger()
|
||||
store_orgs()
|
||||
end
|
||||
|
||||
-- ===================================================================
|
||||
-- This function loads "ledger" data from disk.
|
||||
|
||||
local load_ledger = function()
|
||||
local obj = modpol.ocutil.file_read (modpol.file_ledger )
|
||||
if obj ~= nil then
|
||||
local func, err = load (obj)
|
||||
if err then
|
||||
modpol.ocutil.fatal_error ("load_data: ledger" )
|
||||
end
|
||||
modpol.ledger = func()
|
||||
|
||||
local nn = modpol.ocutil.table_length (modpol.ledger)
|
||||
local str = "entries"
|
||||
if nn == 1 then str = "entry" end
|
||||
modpol.ocutil.log (nn .. " global ledger entries loaded from disk")
|
||||
else
|
||||
modpol.ocutil.log ("No stored global ledger data found")
|
||||
end
|
||||
end
|
||||
|
||||
-- ===================================================================
|
||||
-- This function loads "orgs" data from disk.
|
||||
|
||||
local load_orgs = function()
|
||||
local obj = modpol.ocutil.file_read (modpol.file_orgs )
|
||||
if obj ~= nil then
|
||||
local func, err = load (obj)
|
||||
if err then
|
||||
modpol.ocutil.fatal_error ("load_data: orgs" )
|
||||
end
|
||||
modpol.orgs = func()
|
||||
|
||||
local nn = modpol.ocutil.table_length (modpol.orgs)
|
||||
local str = "entries"
|
||||
if nn == 1 then str = "entry" end
|
||||
modpol.ocutil.log (nn .. " orgs loaded from disk")
|
||||
else
|
||||
modpol.ocutil.log ("No stored orgs data found")
|
||||
end
|
||||
end
|
||||
|
||||
-- ===================================================================
|
||||
-- This function loads stored data from disk.
|
||||
|
||||
modpol.load_storage = function()
|
||||
load_ledger()
|
||||
load_orgs()
|
||||
end
|
||||
|
||||
-- ===================================================================
|
||||
-- End of file.
|
34
storage/storage-mod_storage.lua
Normal file
34
storage/storage-mod_storage.lua
Normal file
@ -0,0 +1,34 @@
|
||||
-- ===================================================================
|
||||
-- /storage-mod_storage.lua
|
||||
-- Persistent storage via Minetest's mod_storage method
|
||||
-- See https://dev.minetest.net/StorageRef
|
||||
|
||||
-- Loads content of stored orgs and ledger from mod_storage
|
||||
|
||||
|
||||
--get modstorageref
|
||||
local mod_storage = minetest.get_mod_storage()
|
||||
|
||||
|
||||
|
||||
modpol.load_storage = function()
|
||||
|
||||
-- load orgs
|
||||
local stored_orgs = minetest.deserialize(mod_storage:get_string("orgs"))
|
||||
if (stored_orgs ~= nil) then
|
||||
modpol.orgs = stored_orgs
|
||||
end
|
||||
-- load orgs
|
||||
local stored_ledger = minetest.deserialize(mod_storage:get_string("ledger"))
|
||||
if (stored_ledger ~= nil) then
|
||||
modpol.ledger = stored_ledger
|
||||
end
|
||||
end
|
||||
|
||||
-- Stores content of current orgs and ledger to mod_storage
|
||||
modpol.store_data = function()
|
||||
|
||||
-- write to storage
|
||||
mod_storage:set_string("orgs", minetest.serialize(modpol.orgs))
|
||||
mod_storage:set_string("ledger", minetest.serialize(modpol.ledger))
|
||||
end
|
Reference in New Issue
Block a user