Simplify TOSERVER_INIT and TOCLIENT_HELLO

- Network compression support was never added.
- Client hasn't used the returned playername since at least 0.4-stable.
This commit is contained in:
red-001 2024-09-02 20:50:43 +01:00 committed by GitHub
parent 2bc9dc54ff
commit d5d8fb629b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 13 additions and 39 deletions

@ -1141,10 +1141,7 @@ void Client::sendInit(const std::string &playerName)
{ {
NetworkPacket pkt(TOSERVER_INIT, 1 + 2 + 2 + (1 + playerName.size())); NetworkPacket pkt(TOSERVER_INIT, 1 + 2 + 2 + (1 + playerName.size()));
// we don't support network compression yet pkt << (u8) SER_FMT_VER_HIGHEST_READ << (u16) 0;
u16 supp_comp_modes = NETPROTO_COMPRESSION_NONE;
pkt << (u8) SER_FMT_VER_HIGHEST_READ << (u16) supp_comp_modes;
pkt << (u16) CLIENT_PROTOCOL_VERSION_MIN << (u16) CLIENT_PROTOCOL_VERSION_MAX; pkt << (u16) CLIENT_PROTOCOL_VERSION_MIN << (u16) CLIENT_PROTOCOL_VERSION_MAX;
pkt << playerName; pkt << playerName;

@ -78,11 +78,11 @@ void Client::handleCommand_Hello(NetworkPacket* pkt)
u8 serialization_ver; u8 serialization_ver;
u16 proto_ver; u16 proto_ver;
u16 compression_mode; u16 unused_compression_mode;
u32 auth_mechs; u32 auth_mechs;
std::string username_legacy; // for case insensitivity std::string unused;
*pkt >> serialization_ver >> compression_mode >> proto_ver *pkt >> serialization_ver >> unused_compression_mode >> proto_ver
>> auth_mechs >> username_legacy; >> auth_mechs >> unused;
// Chose an auth method we support // Chose an auth method we support
AuthMechanism chosen_auth_mechanism = choseAuthMech(auth_mechs); AuthMechanism chosen_auth_mechanism = choseAuthMech(auth_mechs);
@ -91,7 +91,6 @@ void Client::handleCommand_Hello(NetworkPacket* pkt)
<< "serialization_ver=" << (u32)serialization_ver << "serialization_ver=" << (u32)serialization_ver
<< ", auth_mechs=" << auth_mechs << ", auth_mechs=" << auth_mechs
<< ", proto_ver=" << proto_ver << ", proto_ver=" << proto_ver
<< ", compression_mode=" << compression_mode
<< ". Doing auth with mech " << chosen_auth_mechanism << std::endl; << ". Doing auth with mech " << chosen_auth_mechanism << std::endl;
if (!ser_ver_supported(serialization_ver)) { if (!ser_ver_supported(serialization_ver)) {
@ -103,10 +102,6 @@ void Client::handleCommand_Hello(NetworkPacket* pkt)
m_server_ser_ver = serialization_ver; m_server_ser_ver = serialization_ver;
m_proto_ver = proto_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) { if (m_chosen_auth_mech != AUTH_MECHANISM_NONE) {
// we received a TOCLIENT_HELLO while auth was already going on // we received a TOCLIENT_HELLO while auth was already going on
errorstream << "Client: TOCLIENT_HELLO while auth was already going on" errorstream << "Client: TOCLIENT_HELLO while auth was already going on"

@ -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_MIN 37
#define CLIENT_PROTOCOL_VERSION_MAX LATEST_PROTOCOL_VERSION #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 // See also formspec [Version History] in doc/lua_api.md
#define FORMSPEC_API_VERSION 7 #define FORMSPEC_API_VERSION 7
@ -260,10 +257,10 @@ enum ToClientCommand : u16
Sent after TOSERVER_INIT. Sent after TOSERVER_INIT.
u8 deployed serialization version u8 deployed serialization version
u16 deployed network compression mode u16 unused (network compression, never implemeneted)
u16 deployed protocol version u16 deployed protocol version
u32 supported auth methods 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, TOCLIENT_AUTH_ACCEPT = 0x03,
/* /*
@ -914,7 +911,7 @@ enum ToServerCommand : u16
Sent first after connected. Sent first after connected.
u8 serialization version (=SER_FMT_VER_HIGHEST_READ) 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 minimum supported network protocol version
u16 maximum supported network protocol version u16 maximum supported network protocol version
std::string player name std::string player name
@ -1149,10 +1146,6 @@ enum AccessDeniedCode : u8 {
SERVER_ACCESSDENIED_MAX, SERVER_ACCESSDENIED_MAX,
}; };
enum NetProtoCompressionMode {
NETPROTO_COMPRESSION_NONE = 0,
};
enum PlayerListModifer : u8 enum PlayerListModifer : u8
{ {
PLAYER_LIST_INIT, PLAYER_LIST_INIT,

@ -101,12 +101,12 @@ void Server::handleCommand_Init(NetworkPacket* pkt)
// First byte after command is maximum supported // First byte after command is maximum supported
// serialization version // serialization version
u8 client_max; u8 client_max;
u16 supp_compr_modes; u16 unused;
u16 min_net_proto_version = 0; u16 min_net_proto_version = 0;
u16 max_net_proto_version; u16 max_net_proto_version;
std::string playerName; 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; >> max_net_proto_version >> playerName;
u8 our_max = SER_FMT_VER_HIGHEST_READ; u8 our_max = SER_FMT_VER_HIGHEST_READ;
@ -190,9 +190,6 @@ void Server::handleCommand_Init(NetworkPacket* pkt)
} }
m_clients.setPlayerName(peer_id, playername); m_clients.setPlayerName(peer_id, playername);
//TODO (later) case insensitivity
std::string legacyPlayerNameCasing = playerName;
if (!isSingleplayer() && strcasecmp(playername, "singleplayer") == 0) { if (!isSingleplayer() && strcasecmp(playername, "singleplayer") == 0) {
actionstream << "Server: Player with the name \"singleplayer\" tried " actionstream << "Server: Player with the name \"singleplayer\" tried "
@ -279,17 +276,14 @@ void Server::handleCommand_Init(NetworkPacket* pkt)
verbosestream << "Sending TOCLIENT_HELLO with auth method field: " verbosestream << "Sending TOCLIENT_HELLO with auth method field: "
<< auth_mechs << std::endl; << auth_mechs << std::endl;
NetworkPacket resp_pkt(TOCLIENT_HELLO, NetworkPacket resp_pkt(TOCLIENT_HELLO, 0, peer_id);
1 + 4 + legacyPlayerNameCasing.size(), peer_id);
u16 depl_compress_mode = NETPROTO_COMPRESSION_NONE; resp_pkt << depl_serial_v << u16(0) << net_proto_version
resp_pkt << depl_serial_v << depl_compress_mode << net_proto_version << auth_mechs << std::string_view();
<< auth_mechs << legacyPlayerNameCasing;
Send(&resp_pkt); Send(&resp_pkt);
client->allowed_auth_mechs = auth_mechs; client->allowed_auth_mechs = auth_mechs;
client->setDeployedCompressionMode(depl_compress_mode);
m_clients.event(peer_id, CSE_Hello); m_clients.event(peer_id, CSE_Hello);
} }

@ -321,9 +321,6 @@ public:
void setPendingSerializationVersion(u8 version) void setPendingSerializationVersion(u8 version)
{ m_pending_serialization_version = version; } { m_pending_serialization_version = version; }
void setDeployedCompressionMode(u16 byteFlag)
{ m_deployed_compression = byteFlag; }
void confirmSerializationVersion() void confirmSerializationVersion()
{ serialization_version = m_pending_serialization_version; } { serialization_version = m_pending_serialization_version; }
@ -449,8 +446,6 @@ private:
std::string m_full_version = "unknown"; std::string m_full_version = "unknown";
u16 m_deployed_compression = 0;
/* /*
time this client was created time this client was created
*/ */