Standardize version update announcements
Announce to global chat on startup (for chat bridges) and to each player on join, if the version is different than the last time.
This commit is contained in:
parent
a0d1c69ddc
commit
4acf592b86
@ -388,6 +388,8 @@ IDEAS: Possible future additions/improvements to the game
|
||||
that are saved in worlddir
|
||||
- If mod is removed, items are replaced with their fallbacks
|
||||
by the game to avoid unknown_nodes.
|
||||
- More complex items can register ingredients for "uncrafting"
|
||||
and automatic recycling; could work recursively.
|
||||
|
||||
........................................................................
|
||||
========================================================================
|
||||
|
@ -141,3 +141,5 @@ include("item_dig_destroy")
|
||||
|
||||
include("item_groupdump")
|
||||
include("item_tiledump")
|
||||
|
||||
include("setup_serverversion")
|
||||
|
50
mods/nc_api/setup_serverversion.lua
Normal file
50
mods/nc_api/setup_serverversion.lua
Normal file
@ -0,0 +1,50 @@
|
||||
-- LUALOCALS < ---------------------------------------------------------
|
||||
local minetest, nodecore, os
|
||||
= minetest, nodecore, os
|
||||
local os_time
|
||||
= os.time
|
||||
-- LUALOCALS > ---------------------------------------------------------
|
||||
|
||||
local modname = minetest.get_current_modname()
|
||||
local modstore = minetest.get_mod_storage()
|
||||
|
||||
local updated = "NodeCore Updated: @1 -> @2"
|
||||
nodecore.translate_inform(updated)
|
||||
|
||||
local verkey = modname .. "_version"
|
||||
local updkey = modname .. "_updated"
|
||||
|
||||
local function vercomp(meta)
|
||||
local newver = nodecore.version or "?"
|
||||
local oldver = meta:get_string(verkey)
|
||||
if oldver == "" then
|
||||
meta:set_string(verkey, newver)
|
||||
return
|
||||
end
|
||||
oldver = oldver ~= "" and oldver or "?"
|
||||
if newver == oldver then return end
|
||||
meta:set_string(verkey, newver)
|
||||
meta:set_int(updkey, os_time())
|
||||
return nodecore.translate(updated, oldver, newver)
|
||||
end
|
||||
|
||||
-- Announce in public chat (for chat bridges)
|
||||
local function announce(depth)
|
||||
if depth > 0 then
|
||||
return minetest.after(0, function()
|
||||
return announce(depth - 1)
|
||||
end)
|
||||
end
|
||||
local text = vercomp(modstore)
|
||||
if not text then return end
|
||||
nodecore.log("warning", text)
|
||||
return minetest.chat_send_all(text)
|
||||
end
|
||||
announce(5)
|
||||
|
||||
-- Notify players on connect
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
local text = vercomp(player:get_meta())
|
||||
if not text then return end
|
||||
return minetest.chat_send_player(player:get_player_name(), text)
|
||||
end)
|
Loading…
x
Reference in New Issue
Block a user