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

Fix sending color codes to clients that don't support them. #5950

Merged
merged 3 commits into from
Jun 9, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 13 additions & 31 deletions builtin/common/misc_helpers.lua
Expand Up @@ -642,44 +642,26 @@ end

local ESCAPE_CHAR = string.char(0x1b)

-- Client-side mods don't have access to settings
if core.settings and core.settings:get_bool("disable_escape_sequences") then

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.get_color_escape_sequence(color)
return ESCAPE_CHAR .. "(c@" .. color .. ")"
end

function core.colorize(color, message)
local lines = tostring(message):split("\n", true)
local color_code = core.get_color_escape_sequence(color)
function core.get_background_escape_sequence(color)
return ESCAPE_CHAR .. "(b@" .. color .. ")"
end

for i, line in ipairs(lines) do
lines[i] = color_code .. line
end
function core.colorize(color, message)
local lines = tostring(message):split("\n", true)
local color_code = core.get_color_escape_sequence(color)

return table.concat(lines, "\n") .. core.get_color_escape_sequence("#ffffff")
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)
return (str:gsub(ESCAPE_CHAR .. "%(c@[^)]+%)", ""))
end
Expand Down
5 changes: 0 additions & 5 deletions builtin/settingtypes.txt
Expand Up @@ -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.
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 port to listen (UDP).
Expand Down
15 changes: 10 additions & 5 deletions src/server.cpp
Expand Up @@ -1643,15 +1643,20 @@ void Server::SendInventory(PlayerSAO* playerSAO)
void Server::SendChatMessage(u16 peer_id, const std::wstring &message)
{
DSTACK(FUNCTION_NAME);

NetworkPacket pkt(TOCLIENT_CHAT_MESSAGE, 0, peer_id);
pkt << message;

if (peer_id != PEER_ID_INEXISTENT) {
std::wstring processed_message;
if (m_clients.getProtocolVersion(peer_id) < 27)
processed_message = unescape_enriched(message);
else
processed_message = message;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i forget to tell you to remove this temporary variable and write directly to packet in the condition members

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ty


NetworkPacket pkt(TOCLIENT_CHAT_MESSAGE, 0, peer_id);
pkt << processed_message;
Send(&pkt);
}
else {
m_clients.sendToAll(&pkt);
for (u16 id: m_clients.getClientIDs())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please change function to be properly recursive if needed, here we create a packet and verify the peer_id in broadcast mode, please move packet ceration into unicast mode and the proto version check

SendChatMessage(id, message);
}
}

Expand Down