2020-03-19 06:51:03 -04:00
|
|
|
-- LUALOCALS < ---------------------------------------------------------
|
|
|
|
local math, minetest, pairs, table, tonumber, tostring
|
|
|
|
= math, minetest, pairs, table, tonumber, tostring
|
|
|
|
local math_random, table_concat, table_remove, table_sort
|
|
|
|
= math.random, table.concat, table.remove, table.sort
|
|
|
|
-- LUALOCALS > ---------------------------------------------------------
|
|
|
|
|
|
|
|
local modname = minetest.get_current_modname()
|
2024-08-20 07:46:38 -04:00
|
|
|
local modstore = minetest.get_mod_storage()
|
2020-03-19 06:51:03 -04:00
|
|
|
|
|
|
|
local timedelay = tonumber(minetest.settings:get(modname .. "_time")) or 300
|
|
|
|
local linedelay = tonumber(minetest.settings:get(modname .. "_lines")) or 25
|
|
|
|
local maxnames = tonumber(minetest.settings:get(modname .. "_names")) or 50
|
|
|
|
|
2022-10-06 22:47:37 -04:00
|
|
|
local stpriv = minetest.settings:get(modname .. "_hide") or "stealth"
|
|
|
|
local function isstealth(p) return minetest.check_player_privs(p, stpriv) end
|
|
|
|
|
2020-03-19 06:51:03 -04:00
|
|
|
local lines = 0
|
|
|
|
local exp = 0
|
|
|
|
|
2024-08-20 07:46:38 -04:00
|
|
|
local anyonline = modstore:get_string("online") ~= ""
|
|
|
|
local function setanyonline(val)
|
|
|
|
if anyonline == val then return end
|
|
|
|
anyonline = val
|
|
|
|
return modstore:set_string("online", val and "1" or "")
|
|
|
|
end
|
|
|
|
|
2020-04-16 01:25:47 -04:00
|
|
|
local function announce()
|
2020-03-19 06:51:03 -04:00
|
|
|
local names = {}
|
|
|
|
for _, player in pairs(minetest.get_connected_players()) do
|
2022-10-06 22:47:37 -04:00
|
|
|
if not isstealth(player) then
|
2020-03-19 06:58:42 -04:00
|
|
|
names[#names + 1] = player:get_player_name()
|
|
|
|
end
|
2020-03-19 06:51:03 -04:00
|
|
|
end
|
|
|
|
table_sort(names)
|
|
|
|
|
|
|
|
local more = 0
|
|
|
|
while #names > maxnames do
|
|
|
|
table_remove(names, math_random(1, #names))
|
|
|
|
more = more + 1
|
|
|
|
end
|
|
|
|
if more > 0 then
|
|
|
|
names[#names + 1] = "(" .. more .. " more)"
|
|
|
|
end
|
|
|
|
|
|
|
|
if #names > 0 then
|
2020-04-16 01:25:47 -04:00
|
|
|
minetest.chat_send_all("*** Online: " .. table_concat(names, ", "))
|
2024-08-20 07:46:38 -04:00
|
|
|
setanyonline(true)
|
2020-03-19 06:51:03 -04:00
|
|
|
else
|
2020-04-16 01:25:47 -04:00
|
|
|
minetest.chat_send_all("*** Server is empty.")
|
2024-08-20 07:46:38 -04:00
|
|
|
setanyonline(false)
|
2020-03-19 06:51:03 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-16 01:25:47 -04:00
|
|
|
local function sendall(isann)
|
|
|
|
lines = lines + 1
|
|
|
|
if not isann then return end
|
|
|
|
|
|
|
|
local now = minetest.get_us_time() / 1000000
|
|
|
|
if (lines < linedelay) and (now < exp) then return end
|
|
|
|
exp = now + timedelay
|
|
|
|
lines = 0
|
|
|
|
|
|
|
|
minetest.after(0, announce)
|
|
|
|
end
|
|
|
|
|
2024-08-20 07:46:38 -04:00
|
|
|
if anyonline then sendall(true) end
|
|
|
|
|
2020-03-19 06:51:03 -04:00
|
|
|
do
|
|
|
|
local old_sendall = minetest.chat_send_all
|
|
|
|
function minetest.chat_send_all(text, ...)
|
|
|
|
sendall(tostring(text):match("^%s*%*%*%*%s"))
|
|
|
|
return old_sendall(text, ...)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_on_chat_message(function(pname, text)
|
|
|
|
if text:sub(1, 1) ~= "/"
|
|
|
|
and minetest.check_player_privs(pname, "shout") then
|
|
|
|
sendall()
|
|
|
|
end
|
|
|
|
end)
|