Intercept all chat messages

Post Reply
User avatar
texmex
Member
Posts: 1753
Joined: Mon Jul 11, 2016 21:08
GitHub: tacotexmex
In-game: tacotexmex

Intercept all chat messages

by texmex » Post

I want to intercept all messages that goes into the chat, not just player messages. I know of minetest.register_on_chat_message but as the docs state it's only
Called always when a player says something
and not every message.

What I really want to do is to move the chat's position but since that seems hardcoded I figure I'll intercept all messages instead. What can I do?

User avatar
Krock
Developer
Posts: 4650
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker
Location: Switzerland
Contact:

Re: Intercept all chat messages

by Krock » Post

Work around the builtin command handler. Code untested; for demonstrative purposes only.

Code: Select all

-- Run custom callback before builtin
table.insert(minetest.registered_on_chat_message, 1, function(name, message)
    -- Loop through minetest.registered_on_chat_message to execute chat commands or whatever

    -- Message handled, abort callback call loop
    return true
end)

-- Bad Practice starts here
function minetest.chat_send_player(name, text)
    -- custom handler
end
function minetest.chat_send_all(text)
    -- custom handler
end
You won't be able to intercept some of the core messages, such as the death message.
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>

User avatar
texmex
Member
Posts: 1753
Joined: Mon Jul 11, 2016 21:08
GitHub: tacotexmex
In-game: tacotexmex

Re: Intercept all chat messages

by texmex » Post

Thank you! A better solution if not perfect. What are some other type of core messages I won’t be able to intercept and apart from death messages, are they common?

User avatar
Krock
Developer
Posts: 4650
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker
Location: Switzerland
Contact:

Re: Intercept all chat messages

by Krock » Post

texmex wrote:Thank you! A better solution if not perfect. What are some other type of core messages I won’t be able to intercept and apart from death messages, are they common?
Probably just the "You died." message because player joins/leaves and the server status are all done with chat_send_player now.
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>

User avatar
texmex
Member
Posts: 1753
Joined: Mon Jul 11, 2016 21:08
GitHub: tacotexmex
In-game: tacotexmex

Re: Intercept all chat messages

by texmex » Post

Nice. But what about error messages?

User avatar
Krock
Developer
Posts: 4650
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker
Location: Switzerland
Contact:

Re: Intercept all chat messages

by Krock » Post

Right, the client error messages are sometimes also visible in-game. You could try to write a CSM to prevent the client from using the regular chat - but error messages are written to the chat internally (no modification possible). For the regular case where you want to chat it's totally sufficient to only replace the server-side commands.
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>

User avatar
texmex
Member
Posts: 1753
Joined: Mon Jul 11, 2016 21:08
GitHub: tacotexmex
In-game: tacotexmex

Re: Intercept all chat messages

by texmex » Post

Oh okay. I think I’ll open an issue on the subject of chat positioning instead and re-layout my project’s HUD in the meanwhile. Seems to be time better spent. :)

Thank you for your knowledge!

Post Reply

Who is online

Users browsing this forum: No registered users and 10 guests