Skip to content

Commit

Permalink
Remove client-side chat prediction. (#5055)
Browse files Browse the repository at this point in the history
Network lag isn't really a big issue with chat and chat prediction makes writing mods harder.
  • Loading branch information
red-001 authored and nerzhul committed Jan 16, 2017
1 parent d2f5732 commit 2f56a00
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions builtin/game/features.lua
Expand Up @@ -10,6 +10,7 @@ core.features = {
texture_names_parens = true,
area_store_custom_ids = true,
add_entity_with_staticdata = true,
no_chat_message_prediction = true,
}

function core.has_feature(arg)
Expand Down
11 changes: 7 additions & 4 deletions src/client.cpp
Expand Up @@ -1563,10 +1563,13 @@ void Client::typeChatMessage(const std::wstring &message)
}
else
{
LocalPlayer *player = m_env.getLocalPlayer();
assert(player != NULL);
std::wstring name = narrow_to_wide(player->getName());
m_chat_queue.push((std::wstring)L"<" + name + L"> " + message);
// compatibility code
if (m_proto_ver < 29) {
LocalPlayer *player = m_env.getLocalPlayer();
assert(player != NULL);
std::wstring name = narrow_to_wide(player->getName());
m_chat_queue.push((std::wstring)L"<" + name + L"> " + message);
}
}
}

Expand Down
1 change: 1 addition & 0 deletions src/network/networkprotocol.h
Expand Up @@ -142,6 +142,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
Server doesn't accept TOSERVER_BREATH anymore
serialization of TileAnimation params changed
TAT_SHEET_2D
Removed client-sided chat perdiction
*/

#define LATEST_PROTOCOL_VERSION 29
Expand Down
8 changes: 8 additions & 0 deletions src/server.cpp
Expand Up @@ -2826,7 +2826,15 @@ std::wstring Server::handleChat(const std::string &name, const std::wstring &wna

std::vector<u16> clients = m_clients.getClientIDs();

/*
Send the message back to the inital sender
if they are using protocol version >= 29
*/

u16 peer_id_to_avoid_sending = (player ? player->peer_id : PEER_ID_INEXISTENT);
if (player->protocol_version >= 29)
peer_id_to_avoid_sending = PEER_ID_INEXISTENT;

This comment has been minimized.

Copy link
@HybridDog

HybridDog Jan 22, 2017

Contributor

@red-001, this looks like peer_id_to_avoid_sending is set to PEER_ID_INEXISTENT if player is 0, so player->protocol_version could cause a crash, couldn't it?

How about this?
u16 peer_id_to_avoid_sending = player && player->protocol_version < 29 ? player->peer_id : PEER_ID_INEXISTENT;

This comment has been minimized.

Copy link
@sfan5

sfan5 Jan 22, 2017

Member

Yes indeed, the if() should be changed to:
if (player && player->protocol_version >= 29)

This comment has been minimized.

Copy link
@nerzhul

nerzhul Jan 22, 2017

Member

@HybridDog yes could be better, can you provide a pr ?

This comment has been minimized.

Copy link
@HybridDog

HybridDog Jan 24, 2017

Contributor

nerzhul, sfan5 pushed a commit: 43822de

This comment has been minimized.

Copy link
@nerzhul

nerzhul Jan 24, 2017

Member
for (u16 i = 0; i < clients.size(); i++) {
u16 cid = clients[i];
if (cid != peer_id_to_avoid_sending)
Expand Down

0 comments on commit 2f56a00

Please sign in to comment.