Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Announce player revival [beerchat] interception #86

Merged
merged 5 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 38 additions & 28 deletions .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,55 @@ unused_args = false
globals = {
"core",
"minetest",
"pandorabox",

-- Advtrains global functions
"atdebug", "atwarn",
"beerchat",
"bonemeal",
"ccompass",
"default",
"travelnet",
"sethome",
"jumpdrive",
"unified_inventory",
"telemosaic",
"farming",
"farmingNG",
"gravity_manager",
"jumpdrive",
"mobs",
"pandorabox",
"protector",
"sethome",
"spacecannon",
"stamina",
"bonemeal",
"mobs",
"telemosaic",
"travelnet",
"unified_inventory",
"unpack",
"farming",
"farmingNG",
"protector",
-- Advtrains global functions
"atdebug", "atwarn"
}

read_globals = {
-- Stdlib
string = {fields = {"split"}},
table = {fields = {"copy", "getn"}},

-- mod deps
"technic_cnc", "technic",
"loot", "mesecon", "skybox",
"xp_redo",
string = { fields = { "split" } },
table = { fields = { "copy", "getn" } },

-- Minetest
"vector", "ItemStack",
"dump", "screwdriver",
-- Luanti / Minetest
"dump",
"ItemStack",
"vector",

-- Deps
-- mod deps
"advtrains",
"letters", "player_monoids",
"pipeworks", "planetoidgen",
"xban", "beerchat", "drawers",
"toolranks", "stealthnode"
"drawers",
"letters",
"loot",
"mesecon",
"pipeworks",
"planetoidgen",
"player_monoids",
"screwdriver",
"skybox",
"stealthnode",
"technic",
"technic_cnc",
"toolranks",
"xban",
"xp_redo",
}

44 changes: 42 additions & 2 deletions announce_player.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
--
-- No join/leave announcements for some players.
--

-- Priv is given to players e.g. with bad internet connection.
local no_announce_priv = "no_announce"

Expand All @@ -8,14 +10,47 @@ core.register_privilege(no_announce_priv, {
give_to_singleplayer = false,
})


--
-- [beerchat] compat.
--
local has_beerchat = core.get_modpath("beerchat") and true
local beerchat_on_channel_message
if has_beerchat then
-- Intercept sending to remote bridge.
beerchat_on_channel_message = beerchat.on_channel_message
beerchat.on_channel_message = function(channel, player_name, message, event)
if channel == beerchat.main_channel_name
-- New players are always announced.
and (message == "❱ Joined the game"
-- Catch time-out messages too. (❰ is 3 bytes long)
or message:sub(1, 17) == "❰ Left the game")
and core.check_player_privs(player_name, { [no_announce_priv] = true })
then
return
end

-- Send normally.
beerchat_on_channel_message(channel, player_name, message, event)
end
else
-- Noop to satisfy luacheck.
beerchat_on_channel_message = function() end
end

--
-- chat commands so players can announce themselves.
--
-- 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")
if has_beerchat then
beerchat_on_channel_message(beerchat.main_channel_name,
player_name, "❱ Joined the game")
end
end,
})

Expand All @@ -25,11 +60,16 @@ core.register_chatcommand("announce_leave", {
privs = { [no_announce_priv] = true },
func = function(player_name)
core.chat_send_all("*** " .. player_name .. " left the game.")
if has_beerchat then
beerchat_on_channel_message(beerchat.main_channel_name,
player_name, "❰ Left the game")
end
end,
})

--
-- Override functions implementing the priv
-- Override functions implementing the priv.
--

local core_send_join_message = core.send_join_message
core.send_join_message = function(player_name)
Expand Down
Loading