Support for a default messages file

Hi !
I use your mod on a local server, it's great for displaying tips and news !
But since I'm too lazy to copy-paste the random_messages file from one world to an other, I made this change so if the random_messages file is not in the world folder, it look for a template in the mod folder before the 'blame the admin' last resort.
Anyway I thought it could be useful for others
This commit is contained in:
xisd 2016-10-04 01:43:32 +02:00 committed by GitHub
parent b6b076a5a3
commit 1b7ea87932
1 changed files with 17 additions and 2 deletions

View File

@ -5,6 +5,8 @@ arsdragonfly@gmail.com
--]]
--Time between two subsequent messages.
local MESSAGE_INTERVAL = 0
-- Added default messages file
local default_messages_file = "default_random_messages"
math.randomseed(os.time())
@ -47,14 +49,27 @@ end
function random_messages.read_messages()
local line_number = 1
-- define input
local input = io.open(minetest.get_worldpath().."/random_messages","r")
-- no input file found
if not input then
-- look for default file
local default_input = io.open(minetest.get_modpath("random_messages").."/"..default_messages_file,"r")
local output = io.open(minetest.get_worldpath().."/random_messages","w")
output:write("Blame the server admin! He/She has probably not edited the random messages yet.\n")
output:write("Tell your dumb admin that this line is in (worldpath)/random_messages \n")
if not default_input then
-- blame the admin if not found
output:write("Blame the server admin! He/She has probably not edited the random messages yet.\n")
output:write("Tell your dumb admin that this line is in (worldpath)/random_messages \n")
else
-- or write default_input content in worldpath message file
local content = default_input:read("*all")
output:write(content)
end
io.close(output)
io.close(default_input)
input = io.open(minetest.get_worldpath().."/random_messages","r")
end
-- we should have input by now, so lets read it
for line in input:lines() do
random_messages.messages[line_number] = line
line_number = line_number + 1