Small TOCLIENT_HELLO logging fix
[oweals/minetest.git] / src / network / networkprotocol.h
index 599b70006c7d22c082d65440da4094c3b4de41dc..852f2ee0390c880bce058873fc556dd99ea20106 100644 (file)
@@ -120,14 +120,19 @@ with this program; if not, write to the Free Software Foundation, Inc.,
                        permit translation
                Add TOCLIENT_DELETE_PARTICLESPAWNER (0x53), fixing the u16 read and
                        reading u32
-               Add TOSERVER_INIT new opcode (0x02) for client presentation to server
-               Add TOSERVER_AUTH new opcode (0x03) for client authentication
+               Add new opcode TOSERVER_INIT for client presentation to server
+               Add new opcodes TOSERVER_FIRST_SRP, TOSERVER_SRP_BYTES_A,
+                       TOSERVER_SRP_BYTES_M, TOCLIENT_SRP_BYTES_S_B
+                       for the three supported auth mechanisms around srp
+               Add new opcodes TOCLIENT_ACCEPT_SUDO_MODE and TOCLIENT_DENY_SUDO_MODE
+                       for sudo mode handling (auth mech generic way of changing password).
                Add TOCLIENT_HELLO for presenting server to client after client
                        presentation
-               Add TOCLIENT_AUTH_ACCEPT to accept connexion from client
+               Add TOCLIENT_AUTH_ACCEPT to accept connection from client
+               Rename GENERIC_CMD_SET_ATTACHMENT to GENERIC_CMD_ATTACH_TO
 */
 
-#define LATEST_PROTOCOL_VERSION 24
+#define LATEST_PROTOCOL_VERSION 25
 
 // Server's supported network protocol range
 #define SERVER_PROTOCOL_VERSION_MIN 13
@@ -151,14 +156,33 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 enum ToClientCommand
 {
        TOCLIENT_HELLO = 0x02,
-       TOCLIENT_AUTH_ACCEPT = 0x03,
-       TOCLIENT_ACCESS_DENIED = 0x0A,
        /*
-               u16 command
-               u16 reason_length
-               wstring reason
+               Sent after TOSERVER_INIT.
+
+               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)
        */
+       TOCLIENT_AUTH_ACCEPT = 0x03,
+       /*
+               Message from server to accept auth.
 
+               v3s16 player's position + v3f(0,BS/2,0) floatToInt'd
+               u64 map seed
+               f1000 recommended send interval
+               u32 : supported auth methods for sudo mode
+                     (where the user can change their password)
+       */
+       TOCLIENT_ACCEPT_SUDO_MODE = 0x04,
+       /*
+               Sent to client to show it is in sudo mode now.
+       */
+       TOCLIENT_DENY_SUDO_MODE = 0x05,
+       /*
+               Signals client that sudo mode auth failed.
+       */
        TOCLIENT_INIT_LEGACY = 0x10,
        /*
                Server's reply to TOSERVER_INIT.
@@ -173,7 +197,11 @@ enum ToClientCommand
                NOTE: The position in here is deprecated; position is
                      explicitly sent afterwards
        */
-
+       TOCLIENT_ACCESS_DENIED = 0x0A,
+       /*
+               u8 reason
+               std::string custom reason (if reason == SERVER_ACCESSDENIED_CUSTOM_STRING)
+       */
        TOCLIENT_BLOCKDATA = 0x20, //TODO: Multiple blocks
        TOCLIENT_ADDNODE = 0x21,
        /*
@@ -589,7 +617,16 @@ enum ToClientCommand
                u32 id
        */
 
-       TOCLIENT_NUM_MSG_TYPES = 0x54,
+       TOCLIENT_SRP_BYTES_S_B = 0x60,
+       /*
+               Belonging to AUTH_MECHANISM_LEGACY_PASSWORD and AUTH_MECHANISM_SRP.
+
+               u16 command
+               std::string bytes_s
+               std::string bytes_B
+       */
+
+       TOCLIENT_NUM_MSG_TYPES = 0x61,
 };
 
 enum ToServerCommand
@@ -598,25 +635,18 @@ enum ToServerCommand
        /*
                Sent first after connected.
 
-               [0] u16 TOSERVER_INIT
-               [2] u8 SER_FMT_VER_HIGHEST_READ
-               [3] u8 compression_modes
-       */
-
-       TOSERVER_AUTH = 0x03,
-       /*
-               Sent first after presentation (INIT).
-               [0] std::string player_name
-               [0+*] std::string password (new in some version)
-               [0+*+*] u16 minimum supported network protocol version (added sometime)
-               [0+*+*+2] u16 maximum supported network protocol version (added later than the previous one)
+               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,
        /*
                Sent first after connected.
 
-               [0] u16 TOSERVER_INIT
+               [0] u16 TOSERVER_INIT_LEGACY
                [2] u8 SER_FMT_VER_HIGHEST_READ
                [3] u8[20] player_name
                [23] u8[28] password (new in some version)
@@ -817,15 +847,6 @@ enum ToServerCommand
                        u8[len] field value
        */
 
-       TOSERVER_PASSWORD = 0x3d,
-       /*
-               Sent to change password.
-
-               [0] u16 TOSERVER_PASSWORD
-               [2] std::string old password
-               [2+*] std::string new password
-       */
-
        TOSERVER_REQUEST_MEDIA = 0x40,
        /*
                u16 command
@@ -857,40 +878,82 @@ enum ToServerCommand
                u8[len] full_version_string
        */
 
-       TOSERVER_NUM_MSG_TYPES = 0x44,
+       TOSERVER_FIRST_SRP = 0x50,
+       /*
+               Belonging to AUTH_MECHANISM_FIRST_SRP.
+
+               std::string srp salt
+               std::string srp verification key
+               u8 is_empty (=1 if password is empty, 0 otherwise)
+       */
+
+       TOSERVER_SRP_BYTES_A = 0x51,
+       /*
+               Belonging to AUTH_MECHANISM_LEGACY_PASSWORD and AUTH_MECHANISM_SRP,
+                       depending on current_login_based_on.
+
+               std::string bytes_A
+               u8 current_login_based_on : on which version of the password's
+                                           hash this login is based on (0 legacy hash,
+                                           or 1 directly the password)
+       */
+
+       TOSERVER_SRP_BYTES_M = 0x52,
+       /*
+               Belonging to AUTH_MECHANISM_LEGACY_PASSWORD and AUTH_MECHANISM_SRP.
+
+               std::string bytes_M
+       */
+
+       TOSERVER_NUM_MSG_TYPES = 0x53,
+};
+
+enum AuthMechanism
+{
+       // reserved
+       AUTH_MECHANISM_NONE = 0,
+
+       // SRP based on the legacy hash
+       AUTH_MECHANISM_LEGACY_PASSWORD = 1 << 0,
+
+       // SRP based on the srp verification key
+       AUTH_MECHANISM_SRP = 1 << 1,
+
+       // Establishes a srp verification key, for first login and password changing
+       AUTH_MECHANISM_FIRST_SRP = 1 << 2,
 };
 
 enum AccessDeniedCode {
-       SERVER_ACCESSDENIED_WRONG_PASSWORD = 0,
-       SERVER_ACCESSDENIED_UNEXPECTED_DATA = 1,
-       SERVER_ACCESSDENIED_SINGLEPLAYER = 2,
-       SERVER_ACCESSDENIED_WRONG_VERSION = 3,
-       SERVER_ACCESSDENIED_WRONG_CHARS_IN_NAME = 4,
-       SERVER_ACCESSDENIED_WRONG_NAME = 5,
-       SERVER_ACCESSDENIED_TOO_MANY_USERS = 6,
-       SERVER_ACCESSDENIED_EMPTY_PASSWORD = 7,
-       SERVER_ACCESSDENIED_ALREADY_CONNECTED = 8,
-       SERVER_ACCESSDENIED_SERVER_FAIL = 9,
-       SERVER_ACCESSDENIED_CUSTOM_STRING = 10,
-       SERVER_ACCESSDENIED_MAX = 11,
+       SERVER_ACCESSDENIED_WRONG_PASSWORD,
+       SERVER_ACCESSDENIED_UNEXPECTED_DATA,
+       SERVER_ACCESSDENIED_SINGLEPLAYER,
+       SERVER_ACCESSDENIED_WRONG_VERSION,
+       SERVER_ACCESSDENIED_WRONG_CHARS_IN_NAME,
+       SERVER_ACCESSDENIED_WRONG_NAME,
+       SERVER_ACCESSDENIED_TOO_MANY_USERS,
+       SERVER_ACCESSDENIED_EMPTY_PASSWORD,
+       SERVER_ACCESSDENIED_ALREADY_CONNECTED,
+       SERVER_ACCESSDENIED_SERVER_FAIL,
+       SERVER_ACCESSDENIED_CUSTOM_STRING,
+       SERVER_ACCESSDENIED_MAX,
 };
 
 enum NetProtoCompressionMode {
-       NETPROTO_COMPRESSION_ZLIB = 0,
+       NETPROTO_COMPRESSION_NONE = 0,
 };
 
-const static std::wstring accessDeniedStrings[SERVER_ACCESSDENIED_MAX] = {
-       L"Invalid password",
-       L"Your client sent something server didn't expect. Try reconnecting or updating your client",
-       L"The server is running in simple singleplayer mode. You cannot connect.",
-       L"Your client's version is not supported.\nPlease contact server administrator.",
-       L"Name contains unallowed characters",
-       L"Name is not allowed",
-       L"Too many users.",
-       L"Empty passwords are disallowed. Set a password and try again.",
-       L"Another client is connected with this name. If your client closed unexpectedly, try again in a minute.",
-       L"Server authenticator failed. Maybe the servers has some problems."
-       L"",
+const static std::string accessDeniedStrings[SERVER_ACCESSDENIED_MAX] = {
+       "Invalid password",
+       "Your client sent something the server didn't expect.  Try reconnecting or updating your client",
+       "The server is running in simple singleplayer mode.  You cannot connect.",
+       "Your client's version is not supported.\nPlease contact server administrator.",
+       "Player name contains disallowed characters.",
+       "Player name not allowed.",
+       "Too many users.",
+       "Empty passwords are disallowed.  Set a password and try again.",
+       "Another client is connected with this name.  If your client closed unexpectedly, try again in a minute.",
+       "Server authention failed.  This is likely a server error."
+       "",
 };
 
 #endif