added loading of local server files for overriding existing functionality

This commit is contained in:
Sokomine 2023-01-28 22:32:33 +01:00
parent 204b3cfc93
commit af250b2a77

View File

@ -39,11 +39,67 @@ yl_speak_up.fs_version = {}
yl_speak_up.custom_server_functions = {}
-- Some files may or may not exist on the server - they contain adjustments
-- local to the server.
-- Here you can override what you need for YOUR SERVER.
-- Note: These files here are NOT part of the git repository and will NOT be
-- overwritten when the mod is updated. You need to maintain them
-- yourself for your server!
-- This is a local function for security reasons.
local yl_speak_up_execute_if_file_exists = function(reason)
if(reason == "config") then
-- This mod is configured through a config file. Here in this
-- file you can keep and maintain your own local config.
--
-- This file will be loaded and executed (if it exists) at
-- startup AND each time when the command /npc_talk_reload
-- is given.
file_name = modpath.."local_server_config.lua"
elseif(reason == "reload") then
-- Add functions that exist only on your server. This is for
-- example useful for overriding and adding functions found
-- in the file:
-- custom_functions_you_can_override.lua
--
-- This file will be loaded and executed (if it exists) at
-- startup AND each time when the command /npc_talk_reload
-- is given.
file_name = modpath.."local_server_do_on_reload.lua"
elseif(reason == "startup") then
-- Add functionality that exists only on your server and that
-- is exectuted only ONCE when this mod here is LOADED - not
-- each time the reload command is executed.
-- This is useful for calling minetest.register_* functions,
-- i.e. for registering new chat commands.
file_name = modpath.."local_server_do_once_on_startup.lua"
else
-- *only* the file names above are allowed
return
end
-- actually check if the file exists (it's optional after all)
local file, err = io.open(file_name, "r")
if(err) then
minetest.log("action","[MOD] yl_speak_up Ignoring non-existing file \'"..file_name..
"\' (may contain server-side adjustments).")
return
end
io.close(file)
minetest.log("action","[MOD] yl_speak_up Found and executing file \'"..file_name..
"\' with server-side adjustments.")
dofile(file_name)
end
-- the functions in here can be reloaded without restarting the server
-- log_entry: what to write in the logfile
yl_speak_up.reload = function(modpath, log_entry)
-- the server-specific configuration
dofile(modpath .. "config.lua")
-- Here you can override config values for YOUR SERVER.
yl_speak_up_execute_if_file_exists("config")
-- those paths are set in config.lua - so make sure they exist
minetest.mkdir(yl_speak_up.worldpath..yl_speak_up.path)
minetest.mkdir(yl_speak_up.worldpath..yl_speak_up.inventory_path)
@ -66,12 +122,16 @@ yl_speak_up.reload = function(modpath, log_entry)
dofile(modpath .. "fs_save_or_discard_or_back.lua")
-- the player wants to change something regarding the dialog
dofile(modpath .. "edit_mode_apply_changes.lua")
-- as the name says: a collection of custom functions that you can
-- As the name says: a collection of custom functions that you can
-- override on your server or in your game to suit your needs;
-- Note: No special privs are needed to call custom functions. But...
-- of course you can change them only if you have access to
-- the server's file system or can execute lua code.
-- Note: Please do not edit this file. Instead, create and edit the
-- file "local_server_do_on_reload.lua"!
dofile(modpath .. "custom_functions_you_can_override.lua")
-- execute preconditions, actions and effects
dofile(modpath .. "exec_eval_preconditions.lua")
dofile(modpath .. "exec_actions.lua")
@ -142,13 +202,21 @@ yl_speak_up.reload = function(modpath, log_entry)
for i, f in ipairs(yl_speak_up.inform_when_reloaded) do
f()
end
-- Add functionality that exist only on your server.
yl_speak_up_execute_if_file_exists("reload")
end
-- register all the necessary things; this ought to be done only once
-- (although most might work without a server restart as well; but we
-- better want to be on the safe side here)
dofile(modpath .. "register_once.lua")
-- Register things that are only used on your server.
yl_speak_up_execute_if_file_exists("startup")
-- load all those files that can also be reloaded without a server restart
-- load here for the first time:
yl_speak_up.reload(modpath, "loaded")