Skip to content
Permalink
Browse files

Prepare Protocol v25 init & authentication.

* TOSERVER_INIT and TOCLIENT_INIT renamed to _LEGACY
* TOSERVER_PASSWORD merged from dev-0.5, can use protocol v24 and v25
* TOCLIENT_ACCESS_DENIED merged from dev-0.5, can use protocol v24 and v25, with normalized strings an a custom id for custom errors
* new TOSERVER_INIT packet only send MT version, supported compressions, protocols and serialization, this permit to rework everything later without break the _INIT packet
* new TOSERVER_AUTH packet which auth the client
* new TOCLIENT_HELLO packet which send server serialization version atm
* new TOCLIENT_AUTH_ACCEPTED which is send when TOCLIENT_AUTH was okay. After this packet, the client load datas from servers, like after TOCLIENT_INIT_LEGACY packet
  • Loading branch information
nerzhul committed Mar 13, 2015
1 parent 9f3fc72 commit 74d34da6cbb06a4d5659eb3287a87239c31da22c
@@ -349,7 +349,9 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef

void handleCommand_Null(NetworkPacket* pkt) {};
void handleCommand_Deprecated(NetworkPacket* pkt);
void handleCommand_Init(NetworkPacket* pkt);
void handleCommand_Hello(NetworkPacket* pkt);
void handleCommand_AuthAccept(NetworkPacket* pkt);
void handleCommand_InitLegacy(NetworkPacket* pkt);
void handleCommand_AccessDenied(NetworkPacket* pkt);
void handleCommand_RemoveNode(NetworkPacket* pkt);
void handleCommand_AddNode(NetworkPacket* pkt);
@@ -217,6 +217,7 @@ class RemoteClient
m_version_minor(0),
m_version_patch(0),
m_full_version("unknown"),
m_supported_compressions(0),
m_connection_time(getTime(PRECISION_SECONDS))
{
}
@@ -293,6 +294,9 @@ class RemoteClient
void setPendingSerializationVersion(u8 version)
{ m_pending_serialization_version = version; }

void setSupportedCompressionModes(u8 byteFlag)
{ m_supported_compressions = byteFlag; }

void confirmSerializationVersion()
{ serialization_version = m_pending_serialization_version; }

@@ -370,6 +374,8 @@ class RemoteClient

std::string m_full_version;

u8 m_supported_compressions;

/*
time this client was created
*/
@@ -26,8 +26,8 @@ const ToClientCommandHandler toClientCommandTable[TOCLIENT_NUM_MSG_TYPES] =
{
null_command_handler, // 0x00 (never use this)
null_command_handler, // 0x01
null_command_handler, // 0x02
null_command_handler, // 0x03
{ "TOCLIENT_HELLO", TOCLIENT_STATE_NOT_CONNECTED, &Client::handleCommand_Hello }, // 0x02
{ "TOCLIENT_AUTH_ACCEPT", TOCLIENT_STATE_NOT_CONNECTED, &Client::handleCommand_AuthAccept }, // 0x03
null_command_handler, // 0x04
null_command_handler, // 0x05
null_command_handler, // 0x06
@@ -40,7 +40,7 @@ const ToClientCommandHandler toClientCommandTable[TOCLIENT_NUM_MSG_TYPES] =
null_command_handler, // 0x0D
null_command_handler, // 0x0E
null_command_handler, // 0x0F
{ "TOCLIENT_INIT", TOCLIENT_STATE_NOT_CONNECTED, &Client::handleCommand_Init }, // 0x10
{ "TOCLIENT_INIT", TOCLIENT_STATE_NOT_CONNECTED, &Client::handleCommand_InitLegacy }, // 0x10
null_command_handler,
null_command_handler,
null_command_handler,
@@ -110,14 +110,21 @@ with this program; if not, write to the Free Software Foundation, Inc.,
ContentFeatures: change number of special tiles to 6 (CF_SPECIAL_COUNT)
PROTOCOL_VERSION 25:
Rename TOCLIENT_ACCESS_DENIED to TOCLIENT_ACCESS_DENIED_LEGAGY
Rename TOCLIENT_DELETE_PARTICLESPAWNER to TOCLIENT_DELETE_PARTICLESPAWNER_LEGACY
Rename TOCLIENT_DELETE_PARTICLESPAWNER to
TOCLIENT_DELETE_PARTICLESPAWNER_LEGACY
Rename TOSERVER_PASSWORD to TOSERVER_PASSWORD_LEGACY
Rename TOSERVER_INIT to TOSERVER_INIT_LEGACY
Rename TOCLIENT_INIT to TOCLIENT_INIT_LEGACY
Add TOCLIENT_ACCESS_DENIED new opcode (0x0A), using error codes
for standard error, keeping customisation possible. This
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 TOCLIENT_HELLO for presenting server to client after client
presentation
Add TOCLIENT_AUTH_ACCEPT to accept connexion from client
*/

#define LATEST_PROTOCOL_VERSION 24
@@ -143,14 +150,16 @@ 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
*/

TOCLIENT_INIT = 0x10,
TOCLIENT_INIT_LEGACY = 0x10,
/*
Server's reply to TOSERVER_INIT.
Sent second after connected.
@@ -585,17 +594,22 @@ enum ToClientCommand

enum ToServerCommand
{
TOSERVER_INIT = 0x0F,
TOSERVER_INIT = 0x02,
/*
Sent first after connected.
[0] u16 TOSERVER_INIT
[2] u8 SER_FMT_VER_HIGHEST_READ
[3] u8 compression_modes
[4] std::string player_name
[4+*] std::string password (new in some version)
[4+*+*] u16 minimum supported network protocol version (added sometime)
[4+*+*+2] u16 maximum supported network protocol version (added later than the previous one)
*/

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)
*/

TOSERVER_INIT_LEGACY = 0x10,
@@ -856,8 +870,9 @@ enum AccessDeniedCode {
SERVER_ACCESSDENIED_TOO_MANY_USERS = 6,
SERVER_ACCESSDENIED_EMPTY_PASSWORD = 7,
SERVER_ACCESSDENIED_ALREADY_CONNECTED = 8,
SERVER_ACCESSDENIED_CUSTOM_STRING = 9,
SERVER_ACCESSDENIED_MAX = 10,
SERVER_ACCESSDENIED_SERVER_FAIL = 9,
SERVER_ACCESSDENIED_CUSTOM_STRING = 10,
SERVER_ACCESSDENIED_MAX = 11,
};

enum NetProtoCompressionMode {
@@ -874,6 +889,7 @@ const static std::wstring accessDeniedStrings[SERVER_ACCESSDENIED_MAX] = {
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"",
};

@@ -38,19 +38,64 @@ void Client::handleCommand_Deprecated(NetworkPacket* pkt)
<< pkt->getPeerId() << "!" << std::endl;
}

void Client::handleCommand_Init(NetworkPacket* pkt)
void Client::handleCommand_Hello(NetworkPacket* pkt)
{
if (pkt->getSize() < 1)
return;

u8 deployed;
*pkt >> deployed;

infostream << "Client: TOCLIENT_INIT received with "
infostream << "Client: TOCLIENT_HELLO received with "
"deployed=" << ((int)deployed & 0xff) << std::endl;

if (!ser_ver_supported(deployed)) {
infostream << "Client: TOCLIENT_INIT: Server sent "
infostream << "Client: TOCLIENT_HELLO: Server sent "
<< "unsupported ser_fmt_ver"<< std::endl;
return;
}

m_server_ser_ver = deployed;

// @ TODO auth to server
}

void Client::handleCommand_AuthAccept(NetworkPacket* pkt)
{
v3f playerpos;
*pkt >> playerpos >> m_map_seed >> m_recommended_send_interval;

playerpos -= v3f(0, BS / 2, 0);

// Set player position
Player *player = m_env.getLocalPlayer();
assert(player != NULL);
player->setPosition(playerpos);

infostream << "Client: received map seed: " << m_map_seed << std::endl;
infostream << "Client: received recommended send interval "
<< m_recommended_send_interval<<std::endl;

// Reply to server
NetworkPacket* resp_pkt = new NetworkPacket(TOSERVER_INIT2, 0);
Send(resp_pkt);

m_state = LC_Init;
}

void Client::handleCommand_InitLegacy(NetworkPacket* pkt)
{
if (pkt->getSize() < 1)
return;

u8 deployed;
*pkt >> deployed;

infostream << "Client: TOCLIENT_INIT_LEGACY received with "
"deployed=" << ((int)deployed & 0xff) << std::endl;

if (!ser_ver_supported(deployed)) {
infostream << "Client: TOCLIENT_INIT_LEGACY: Server sent "
<< "unsupported ser_fmt_ver"<< std::endl;
return;
}
@@ -98,10 +143,11 @@ void Client::handleCommand_AccessDenied(NetworkPacket* pkt)
m_access_denied_reason = L"Unknown";

if (pkt->getCommand() == TOCLIENT_ACCESS_DENIED) {
if (pkt->getSize() < 1)
return;

u8 denyCode = SERVER_ACCESSDENIED_UNEXPECTED_DATA;
if(pkt->getSize() >= 1) {
*pkt >> denyCode;
}
*pkt >> denyCode;
if (denyCode == SERVER_ACCESSDENIED_CUSTOM_STRING) {
*pkt >> m_access_denied_reason;
}

0 comments on commit 74d34da

Please sign in to comment.