Skip to content

Commit 740b4be

Browse files
red-001SmallJoker
authored andcommittedJun 9, 2017
Fix sending color codes to clients that don't support them. (#5950)
Also remove `disable_escape_sequences` since it's not needed anymore.
1 parent 44495ea commit 740b4be

File tree

3 files changed

+22
-42
lines changed

3 files changed

+22
-42
lines changed
 

‎builtin/common/misc_helpers.lua

+13-31
Original file line numberDiff line numberDiff line change
@@ -642,44 +642,26 @@ end
642642

643643
local ESCAPE_CHAR = string.char(0x1b)
644644

645-
-- Client-side mods don't have access to settings
646-
if core.settings and core.settings:get_bool("disable_escape_sequences") then
647-
648-
function core.get_color_escape_sequence(color)
649-
return ""
650-
end
651-
652-
function core.get_background_escape_sequence(color)
653-
return ""
654-
end
655-
656-
function core.colorize(color, message)
657-
return message
658-
end
659-
660-
else
661-
662-
function core.get_color_escape_sequence(color)
663-
return ESCAPE_CHAR .. "(c@" .. color .. ")"
664-
end
665-
666-
function core.get_background_escape_sequence(color)
667-
return ESCAPE_CHAR .. "(b@" .. color .. ")"
668-
end
645+
function core.get_color_escape_sequence(color)
646+
return ESCAPE_CHAR .. "(c@" .. color .. ")"
647+
end
669648

670-
function core.colorize(color, message)
671-
local lines = tostring(message):split("\n", true)
672-
local color_code = core.get_color_escape_sequence(color)
649+
function core.get_background_escape_sequence(color)
650+
return ESCAPE_CHAR .. "(b@" .. color .. ")"
651+
end
673652

674-
for i, line in ipairs(lines) do
675-
lines[i] = color_code .. line
676-
end
653+
function core.colorize(color, message)
654+
local lines = tostring(message):split("\n", true)
655+
local color_code = core.get_color_escape_sequence(color)
677656

678-
return table.concat(lines, "\n") .. core.get_color_escape_sequence("#ffffff")
657+
for i, line in ipairs(lines) do
658+
lines[i] = color_code .. line
679659
end
680660

661+
return table.concat(lines, "\n") .. core.get_color_escape_sequence("#ffffff")
681662
end
682663

664+
683665
function core.strip_foreground_colors(str)
684666
return (str:gsub(ESCAPE_CHAR .. "%(c@[^)]+%)", ""))
685667
end

‎builtin/settingtypes.txt

-5
Original file line numberDiff line numberDiff line change
@@ -721,11 +721,6 @@ server_announce (Announce server) bool false
721721
# If you want to announce your ipv6 address, use serverlist_url = v6.servers.minetest.net.
722722
serverlist_url (Serverlist URL) string servers.minetest.net
723723

724-
# Disable escape sequences, e.g. chat coloring.
725-
# Use this if you want to run a server with pre-0.4.14 clients and you want to disable
726-
# the escape sequences generated by mods.
727-
disable_escape_sequences (Disable escape sequences) bool false
728-
729724
[*Network]
730725

731726
# Network port to listen (UDP).

‎src/server.cpp

+9-6
Original file line numberDiff line numberDiff line change
@@ -1643,15 +1643,18 @@ void Server::SendInventory(PlayerSAO* playerSAO)
16431643
void Server::SendChatMessage(u16 peer_id, const std::wstring &message)
16441644
{
16451645
DSTACK(FUNCTION_NAME);
1646+
if (peer_id != PEER_ID_INEXISTENT) {
1647+
NetworkPacket pkt(TOCLIENT_CHAT_MESSAGE, 0, peer_id);
16461648

1647-
NetworkPacket pkt(TOCLIENT_CHAT_MESSAGE, 0, peer_id);
1648-
pkt << message;
1649+
if (m_clients.getProtocolVersion(peer_id) < 27)
1650+
pkt << unescape_enriched(message);
1651+
else
1652+
pkt << message;
16491653

1650-
if (peer_id != PEER_ID_INEXISTENT) {
16511654
Send(&pkt);
1652-
}
1653-
else {
1654-
m_clients.sendToAll(&pkt);
1655+
} else {
1656+
for (u16 id : m_clients.getClientIDs())
1657+
SendChatMessage(id, message);
16551658
}
16561659
}
16571660

0 commit comments

Comments
 (0)
Please sign in to comment.