mirror of
https://github.com/minetest/minetest.git
synced 2024-12-02 12:33:45 +01:00
Fix sending color codes to clients that don't support them. (#5950)
Also remove `disable_escape_sequences` since it's not needed anymore.
This commit is contained in:
parent
f736226c1a
commit
c399f5a541
@ -642,44 +642,26 @@ end
|
|||||||
|
|
||||||
local ESCAPE_CHAR = string.char(0x1b)
|
local ESCAPE_CHAR = string.char(0x1b)
|
||||||
|
|
||||||
-- Client-side mods don't have access to settings
|
function core.get_color_escape_sequence(color)
|
||||||
if core.settings and core.settings:get_bool("disable_escape_sequences") then
|
return ESCAPE_CHAR .. "(c@" .. color .. ")"
|
||||||
|
|
||||||
function core.get_color_escape_sequence(color)
|
|
||||||
return ""
|
|
||||||
end
|
|
||||||
|
|
||||||
function core.get_background_escape_sequence(color)
|
|
||||||
return ""
|
|
||||||
end
|
|
||||||
|
|
||||||
function core.colorize(color, message)
|
|
||||||
return message
|
|
||||||
end
|
|
||||||
|
|
||||||
else
|
|
||||||
|
|
||||||
function core.get_color_escape_sequence(color)
|
|
||||||
return ESCAPE_CHAR .. "(c@" .. color .. ")"
|
|
||||||
end
|
|
||||||
|
|
||||||
function core.get_background_escape_sequence(color)
|
|
||||||
return ESCAPE_CHAR .. "(b@" .. color .. ")"
|
|
||||||
end
|
|
||||||
|
|
||||||
function core.colorize(color, message)
|
|
||||||
local lines = tostring(message):split("\n", true)
|
|
||||||
local color_code = core.get_color_escape_sequence(color)
|
|
||||||
|
|
||||||
for i, line in ipairs(lines) do
|
|
||||||
lines[i] = color_code .. line
|
|
||||||
end
|
|
||||||
|
|
||||||
return table.concat(lines, "\n") .. core.get_color_escape_sequence("#ffffff")
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function core.get_background_escape_sequence(color)
|
||||||
|
return ESCAPE_CHAR .. "(b@" .. color .. ")"
|
||||||
|
end
|
||||||
|
|
||||||
|
function core.colorize(color, message)
|
||||||
|
local lines = tostring(message):split("\n", true)
|
||||||
|
local color_code = core.get_color_escape_sequence(color)
|
||||||
|
|
||||||
|
for i, line in ipairs(lines) do
|
||||||
|
lines[i] = color_code .. line
|
||||||
|
end
|
||||||
|
|
||||||
|
return table.concat(lines, "\n") .. core.get_color_escape_sequence("#ffffff")
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function core.strip_foreground_colors(str)
|
function core.strip_foreground_colors(str)
|
||||||
return (str:gsub(ESCAPE_CHAR .. "%(c@[^)]+%)", ""))
|
return (str:gsub(ESCAPE_CHAR .. "%(c@[^)]+%)", ""))
|
||||||
end
|
end
|
||||||
|
@ -721,11 +721,6 @@ server_announce (Announce server) bool false
|
|||||||
# If you want to announce your ipv6 address, use serverlist_url = v6.servers.minetest.net.
|
# If you want to announce your ipv6 address, use serverlist_url = v6.servers.minetest.net.
|
||||||
serverlist_url (Serverlist URL) string servers.minetest.net
|
serverlist_url (Serverlist URL) string servers.minetest.net
|
||||||
|
|
||||||
# Disable escape sequences, e.g. chat coloring.
|
|
||||||
# Use this if you want to run a server with pre-0.4.14 clients and you want to disable
|
|
||||||
# the escape sequences generated by mods.
|
|
||||||
disable_escape_sequences (Disable escape sequences) bool false
|
|
||||||
|
|
||||||
[*Network]
|
[*Network]
|
||||||
|
|
||||||
# Network port to listen (UDP).
|
# Network port to listen (UDP).
|
||||||
|
@ -1643,15 +1643,18 @@ void Server::SendInventory(PlayerSAO* playerSAO)
|
|||||||
void Server::SendChatMessage(u16 peer_id, const std::wstring &message)
|
void Server::SendChatMessage(u16 peer_id, const std::wstring &message)
|
||||||
{
|
{
|
||||||
DSTACK(FUNCTION_NAME);
|
DSTACK(FUNCTION_NAME);
|
||||||
|
|
||||||
NetworkPacket pkt(TOCLIENT_CHAT_MESSAGE, 0, peer_id);
|
|
||||||
pkt << message;
|
|
||||||
|
|
||||||
if (peer_id != PEER_ID_INEXISTENT) {
|
if (peer_id != PEER_ID_INEXISTENT) {
|
||||||
|
NetworkPacket pkt(TOCLIENT_CHAT_MESSAGE, 0, peer_id);
|
||||||
|
|
||||||
|
if (m_clients.getProtocolVersion(peer_id) < 27)
|
||||||
|
pkt << unescape_enriched(message);
|
||||||
|
else
|
||||||
|
pkt << message;
|
||||||
|
|
||||||
Send(&pkt);
|
Send(&pkt);
|
||||||
}
|
} else {
|
||||||
else {
|
for (u16 id : m_clients.getClientIDs())
|
||||||
m_clients.sendToAll(&pkt);
|
SendChatMessage(id, message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user