Skip to content

Commit

Permalink
Simplify TOSERVER_INIT and TOCLIENT_HELLO
Browse files Browse the repository at this point in the history
- Network compression support was never added.
- Client hasn't used the returned playername since at least 0.4-stable.
  • Loading branch information
red-001 committed Sep 2, 2024
1 parent 2bc9dc5 commit d5d8fb6
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 39 deletions.
5 changes: 1 addition & 4 deletions src/client/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1141,10 +1141,7 @@ void Client::sendInit(const std::string &playerName)
{
NetworkPacket pkt(TOSERVER_INIT, 1 + 2 + 2 + (1 + playerName.size()));

// we don't support network compression yet
u16 supp_comp_modes = NETPROTO_COMPRESSION_NONE;

pkt << (u8) SER_FMT_VER_HIGHEST_READ << (u16) supp_comp_modes;
pkt << (u8) SER_FMT_VER_HIGHEST_READ << (u16) 0;
pkt << (u16) CLIENT_PROTOCOL_VERSION_MIN << (u16) CLIENT_PROTOCOL_VERSION_MAX;
pkt << playerName;

Expand Down
13 changes: 4 additions & 9 deletions src/network/clientpackethandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ void Client::handleCommand_Hello(NetworkPacket* pkt)

u8 serialization_ver;
u16 proto_ver;
u16 compression_mode;
u16 unused_compression_mode;
u32 auth_mechs;
std::string username_legacy; // for case insensitivity
*pkt >> serialization_ver >> compression_mode >> proto_ver
>> auth_mechs >> username_legacy;
std::string unused;
*pkt >> serialization_ver >> unused_compression_mode >> proto_ver
>> auth_mechs >> unused;

// Chose an auth method we support
AuthMechanism chosen_auth_mechanism = choseAuthMech(auth_mechs);
Expand All @@ -91,7 +91,6 @@ void Client::handleCommand_Hello(NetworkPacket* pkt)
<< "serialization_ver=" << (u32)serialization_ver
<< ", auth_mechs=" << auth_mechs
<< ", proto_ver=" << proto_ver
<< ", compression_mode=" << compression_mode
<< ". Doing auth with mech " << chosen_auth_mechanism << std::endl;

if (!ser_ver_supported(serialization_ver)) {
Expand All @@ -103,10 +102,6 @@ void Client::handleCommand_Hello(NetworkPacket* pkt)
m_server_ser_ver = serialization_ver;
m_proto_ver = proto_ver;

//TODO verify that username_legacy matches sent username, only
// differs in casing (make both uppercase and compare)
// This is only necessary though when we actually want to add casing support

if (m_chosen_auth_mech != AUTH_MECHANISM_NONE) {
// we received a TOCLIENT_HELLO while auth was already going on
errorstream << "Client: TOCLIENT_HELLO while auth was already going on"
Expand Down
13 changes: 3 additions & 10 deletions src/network/networkprotocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define CLIENT_PROTOCOL_VERSION_MIN 37
#define CLIENT_PROTOCOL_VERSION_MAX LATEST_PROTOCOL_VERSION

#define PASSWORD_SIZE 28 // Maximum password length. Allows for
// base64-encoded SHA-1 (27+\0).

// See also formspec [Version History] in doc/lua_api.md
#define FORMSPEC_API_VERSION 7

Expand All @@ -260,10 +257,10 @@ enum ToClientCommand : u16
Sent after TOSERVER_INIT.
u8 deployed serialization version
u16 deployed network compression mode
u16 unused (network compression, never implemeneted)
u16 deployed protocol version
u32 supported auth methods
std::string username that should be used for legacy hash (for proper casing)
std::string unused (used to be username)
*/
TOCLIENT_AUTH_ACCEPT = 0x03,
/*
Expand Down Expand Up @@ -914,7 +911,7 @@ enum ToServerCommand : u16
Sent first after connected.
u8 serialization version (=SER_FMT_VER_HIGHEST_READ)
u16 supported network compression modes
u16 unused (supported network compression modes, never implemeneted)
u16 minimum supported network protocol version
u16 maximum supported network protocol version
std::string player name
Expand Down Expand Up @@ -1149,10 +1146,6 @@ enum AccessDeniedCode : u8 {
SERVER_ACCESSDENIED_MAX,
};

enum NetProtoCompressionMode {
NETPROTO_COMPRESSION_NONE = 0,
};

enum PlayerListModifer : u8
{
PLAYER_LIST_INIT,
Expand Down
16 changes: 5 additions & 11 deletions src/network/serverpackethandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@ void Server::handleCommand_Init(NetworkPacket* pkt)
// First byte after command is maximum supported
// serialization version
u8 client_max;
u16 supp_compr_modes;
u16 unused;
u16 min_net_proto_version = 0;
u16 max_net_proto_version;
std::string playerName;

*pkt >> client_max >> supp_compr_modes >> min_net_proto_version
*pkt >> client_max >> unused >> min_net_proto_version
>> max_net_proto_version >> playerName;

u8 our_max = SER_FMT_VER_HIGHEST_READ;
Expand Down Expand Up @@ -190,9 +190,6 @@ void Server::handleCommand_Init(NetworkPacket* pkt)
}

m_clients.setPlayerName(peer_id, playername);
//TODO (later) case insensitivity

std::string legacyPlayerNameCasing = playerName;

if (!isSingleplayer() && strcasecmp(playername, "singleplayer") == 0) {
actionstream << "Server: Player with the name \"singleplayer\" tried "
Expand Down Expand Up @@ -279,17 +276,14 @@ void Server::handleCommand_Init(NetworkPacket* pkt)
verbosestream << "Sending TOCLIENT_HELLO with auth method field: "
<< auth_mechs << std::endl;

NetworkPacket resp_pkt(TOCLIENT_HELLO,
1 + 4 + legacyPlayerNameCasing.size(), peer_id);
NetworkPacket resp_pkt(TOCLIENT_HELLO, 0, peer_id);

u16 depl_compress_mode = NETPROTO_COMPRESSION_NONE;
resp_pkt << depl_serial_v << depl_compress_mode << net_proto_version
<< auth_mechs << legacyPlayerNameCasing;
resp_pkt << depl_serial_v << u16(0) << net_proto_version
<< auth_mechs << std::string_view();

Send(&resp_pkt);

client->allowed_auth_mechs = auth_mechs;
client->setDeployedCompressionMode(depl_compress_mode);

m_clients.event(peer_id, CSE_Hello);
}
Expand Down
5 changes: 0 additions & 5 deletions src/server/clientiface.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,6 @@ class RemoteClient
void setPendingSerializationVersion(u8 version)
{ m_pending_serialization_version = version; }

void setDeployedCompressionMode(u16 byteFlag)
{ m_deployed_compression = byteFlag; }

void confirmSerializationVersion()
{ serialization_version = m_pending_serialization_version; }

Expand Down Expand Up @@ -449,8 +446,6 @@ class RemoteClient

std::string m_full_version = "unknown";

u16 m_deployed_compression = 0;

/*
time this client was created
*/
Expand Down

0 comments on commit d5d8fb6

Please sign in to comment.