Finalize init packets and enable protocol v25
authorest31 <MTest31@outlook.com>
Fri, 15 May 2015 23:19:43 +0000 (01:19 +0200)
committerest31 <MTest31@outlook.com>
Sat, 16 May 2015 19:17:28 +0000 (21:17 +0200)
This enables srp.

src/client.cpp
src/clientiface.h
src/network/clientpackethandler.cpp
src/network/networkprotocol.h
src/network/serveropcodes.cpp
src/network/serverpackethandler.cpp

index 8cfcc85a7bbe04730027c70ec4f0574670aeac1e..780b07872d4d90a9cc6dbadf0d9f3d5fdba2e169 100644 (file)
@@ -1000,8 +1000,9 @@ void Client::sendInit(const std::string &playerName)
 {
        NetworkPacket pkt(TOSERVER_INIT, 1 + 2 + 2 + (1 + playerName.size()));
 
-       // TODO (later) actually send supported compression modes
-       pkt << (u8) SER_FMT_VER_HIGHEST_READ << (u8) 42;
+       // 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 << (u16) CLIENT_PROTOCOL_VERSION_MIN << (u16) CLIENT_PROTOCOL_VERSION_MAX;
        pkt << playerName;
 
index 070559c3a7d3cf1a2706e8978cd10c0d420ca762..4707f4d9aabf81068ee6d8e09e79d1afe58deae9 100644 (file)
@@ -337,7 +337,7 @@ public:
        void setPendingSerializationVersion(u8 version)
                { m_pending_serialization_version = version; }
 
-       void setSupportedCompressionModes(u8 byteFlag)
+       void setSupportedCompressionModes(u16 byteFlag)
                { m_supported_compressions = byteFlag; }
 
        void confirmSerializationVersion()
@@ -416,7 +416,7 @@ private:
 
        std::string m_full_version;
 
-       u8 m_supported_compressions;
+       u16 m_supported_compressions;
 
        /*
                time this client was created
index 2106e4368b5ed6ca1b77774ba0f111e495a0f9d2..1f13c62f9abd8fe068ec5679edff6c97dcf27bb4 100644 (file)
@@ -44,26 +44,31 @@ void Client::handleCommand_Hello(NetworkPacket* pkt)
        if (pkt->getSize() < 1)
                return;
 
-       u8 deployed;
+       u8 serialization_ver;
+       u16 proto_ver;
+       u16 compression_mode;
        u32 auth_mechs;
        std::string username_legacy; // for case insensitivity
-       *pkt >> deployed >> auth_mechs >> username_legacy;
+       *pkt >> serialization_ver >> compression_mode >> proto_ver
+               >> auth_mechs >> username_legacy;
 
        // Chose an auth method we support
        AuthMechanism chosen_auth_mechanism = choseAuthMech(auth_mechs);
 
        infostream << "Client: TOCLIENT_HELLO received with "
-                       "deployed=" << ((int)deployed & 0xff) << ", auth_mechs="
-                       << auth_mechs << ", chosen=" << chosen_auth_mechanism << std::endl;
+                       << "serialization_ver=" << serialization_ver
+                       << ", auth_mechs=" << auth_mechs
+                       << ", compression_mode=" << compression_mode
+                       << ". Doing auth with mech " << chosen_auth_mechanism << std::endl;
 
-       if (!ser_ver_supported(deployed)) {
+       if (!ser_ver_supported(serialization_ver)) {
                infostream << "Client: TOCLIENT_HELLO: Server sent "
                                << "unsupported ser_fmt_ver"<< std::endl;
                return;
        }
 
-       m_server_ser_ver = deployed;
-       m_proto_ver = deployed;
+       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)
index ba12a206ed91a76368518d87758e328aabd53d11..09617c9d9f1193af4f43eedc50d8c4334033ca72 100644 (file)
@@ -131,7 +131,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
                Add TOCLIENT_AUTH_ACCEPT to accept connection from client
 */
 
-#define LATEST_PROTOCOL_VERSION 24
+#define LATEST_PROTOCOL_VERSION 25
 
 // Server's supported network protocol range
 #define SERVER_PROTOCOL_VERSION_MIN 13
@@ -158,7 +158,9 @@ enum ToClientCommand
        /*
                Sent after TOSERVER_INIT.
 
-               u8 deployed version
+               u8 deployed serialisation version
+               u16 deployed network compression mode
+               u16 deployed protocol version
                u32 supported auth methods
                std::string username that should be used for legacy hash (for proper casing)
        */
@@ -632,11 +634,11 @@ enum ToServerCommand
        /*
                Sent first after connected.
 
-               [2] u8 SER_FMT_VER_HIGHEST_READ
-               [3] u8 compression_modes
-               [4] u16 minimum supported network protocol version
-               [6] u16 maximum supported network protocol version
-               [8] std::string player name
+               u8 serialisation version (=SER_FMT_VER_HIGHEST_READ)
+               u16 supported network compression modes
+               u16 minimum supported network protocol version
+               u16 maximum supported network protocol version
+               std::string player name
        */
 
        TOSERVER_INIT_LEGACY = 0x10,
@@ -936,7 +938,7 @@ enum AccessDeniedCode {
 };
 
 enum NetProtoCompressionMode {
-       NETPROTO_COMPRESSION_ZLIB = 0,
+       NETPROTO_COMPRESSION_NONE = 0,
 };
 
 const static std::string accessDeniedStrings[SERVER_ACCESSDENIED_MAX] = {
index 92d24fe40b714da6cc23d5dc6d7a96c7932c1b86..9b14a1be3aa00d43e32bbd32e743287e6d0a471e 100644 (file)
@@ -115,7 +115,7 @@ const ClientCommandFactory clientCommandFactoryTable[TOCLIENT_NUM_MSG_TYPES] =
 {
        null_command_factory, // 0x00
        null_command_factory, // 0x01
-       null_command_factory, // 0x02
+       { "TOCLIENT_HELLO",             0, true }, // 0x02
        { "TOCLIENT_AUTH_ACCEPT",       0, true }, // 0x03
        { "TOCLIENT_ACCEPT_SUDO_MODE",  0, true }, // 0x04
        { "TOCLIENT_DENY_SUDO_MODE",    0, true }, // 0x05
index a6f5ffca1b5222c212f68082338eec8a745422da..38b8b3cffa327c42f316117ecb44258f28d33145 100644 (file)
@@ -91,22 +91,22 @@ void Server::handleCommand_Init(NetworkPacket* pkt)
        // First byte after command is maximum supported
        // serialization version
        u8 client_max;
-       u8 compression_modes;
+       u16 supp_compr_modes;
        u16 min_net_proto_version = 0;
        u16 max_net_proto_version;
        std::string playerName;
 
-       *pkt >> client_max >> compression_modes >> min_net_proto_version
+       *pkt >> client_max >> supp_compr_modes >> min_net_proto_version
                        >> max_net_proto_version >> playerName;
 
        u8 our_max = SER_FMT_VER_HIGHEST_READ;
        // Use the highest version supported by both
-       u8 deployed = std::min(client_max, our_max);
+       u8 depl_serial_v = std::min(client_max, our_max);
        // If it's lower than the lowest supported, give up.
-       if (deployed < SER_FMT_VER_LOWEST)
-               deployed = SER_FMT_VER_INVALID;
+       if (depl_serial_v < SER_FMT_VER_LOWEST)
+               depl_serial_v = SER_FMT_VER_INVALID;
 
-       if (deployed == SER_FMT_VER_INVALID) {
+       if (depl_serial_v == SER_FMT_VER_INVALID) {
                actionstream << "Server: A mismatched client tried to connect from "
                                << addr_s << std::endl;
                infostream<<"Server: Cannot negotiate serialization version with "
@@ -115,7 +115,7 @@ void Server::handleCommand_Init(NetworkPacket* pkt)
                return;
        }
 
-       client->setPendingSerializationVersion(deployed);
+       client->setPendingSerializationVersion(depl_serial_v);
 
        /*
                Read and check network protocol version
@@ -274,7 +274,9 @@ void Server::handleCommand_Init(NetworkPacket* pkt)
        NetworkPacket resp_pkt(TOCLIENT_HELLO, 1 + 4
                + legacyPlayerNameCasing.size(), pkt->getPeerId());
 
-       resp_pkt << deployed << auth_mechs << legacyPlayerNameCasing;
+       u16 depl_compress_mode = NETPROTO_COMPRESSION_NONE;
+       resp_pkt << depl_serial_v << depl_compress_mode << net_proto_version
+               << auth_mechs << legacyPlayerNameCasing;
 
        Send(&resp_pkt);