Skip to content

Commit

Permalink
Announce player revival (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
SwissalpS authored Dec 31, 2024
1 parent 1a2c8c4 commit 391e566
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
unused_args = false

globals = {
"core",
"minetest",
"pandorabox",
"default",
Expand Down
52 changes: 52 additions & 0 deletions announce_player.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
-- No join/leave announcements for some players.
--
-- Priv is given to players e.g. with bad internet connection.
local no_announce_priv = "no_announce"

core.register_privilege(no_announce_priv, {
description = "player does not get announced",
give_to_singleplayer = false,
})

--
-- chat commands so players can announce themselves

core.register_chatcommand("announce_join", {
description = "join message",
privs = { [no_announce_priv] = true },
func = function(player_name)
core.chat_send_all("*** " .. player_name .. " joined the game")
end,
})


core.register_chatcommand("announce_leave", {
description = "leave message",
privs = { [no_announce_priv] = true },
func = function(player_name)
core.chat_send_all("*** " .. player_name .. " left the game.")
end,
})

--
-- Override functions implementing the priv

local core_send_join_message = core.send_join_message
core.send_join_message = function(player_name)
if core.check_player_privs(player_name, { [no_announce_priv] = true }) then
return
end

core_send_join_message(player_name)
end


local core_send_leave_message = core.send_leave_message
core.send_leave_message = function(player_name, timed_out)
if core.check_player_privs(player_name, { [no_announce_priv] = true }) then
return
end

core_send_leave_message(player_name, timed_out)
end

3 changes: 3 additions & 0 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ dofile(MP.."/cleanup.lua")
-- prejoin log
dofile(MP.."/prejoin.lua")

-- no-announce priv, chatcommands and functions
dofile(MP .. "/announce_player.lua")

-- bucket and xp limitation
if minetest.get_modpath("bucket") and minetest.get_modpath("xp_redo") then
dofile(MP.."/onplace_restriction.lua")
Expand Down

0 comments on commit 391e566

Please sign in to comment.