Skip to content

Commit 74d34da

Browse files
committedMar 13, 2015
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
1 parent 9f3fc72 commit 74d34da

File tree

10 files changed

+448
-70
lines changed

10 files changed

+448
-70
lines changed
 

Diff for: ‎src/client.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,9 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
349349

350350
void handleCommand_Null(NetworkPacket* pkt) {};
351351
void handleCommand_Deprecated(NetworkPacket* pkt);
352-
void handleCommand_Init(NetworkPacket* pkt);
352+
void handleCommand_Hello(NetworkPacket* pkt);
353+
void handleCommand_AuthAccept(NetworkPacket* pkt);
354+
void handleCommand_InitLegacy(NetworkPacket* pkt);
353355
void handleCommand_AccessDenied(NetworkPacket* pkt);
354356
void handleCommand_RemoveNode(NetworkPacket* pkt);
355357
void handleCommand_AddNode(NetworkPacket* pkt);

Diff for: ‎src/clientiface.h

+6
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ class RemoteClient
217217
m_version_minor(0),
218218
m_version_patch(0),
219219
m_full_version("unknown"),
220+
m_supported_compressions(0),
220221
m_connection_time(getTime(PRECISION_SECONDS))
221222
{
222223
}
@@ -293,6 +294,9 @@ class RemoteClient
293294
void setPendingSerializationVersion(u8 version)
294295
{ m_pending_serialization_version = version; }
295296

297+
void setSupportedCompressionModes(u8 byteFlag)
298+
{ m_supported_compressions = byteFlag; }
299+
296300
void confirmSerializationVersion()
297301
{ serialization_version = m_pending_serialization_version; }
298302

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

371375
std::string m_full_version;
372376

377+
u8 m_supported_compressions;
378+
373379
/*
374380
time this client was created
375381
*/

Diff for: ‎src/network/clientopcodes.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ const ToClientCommandHandler toClientCommandTable[TOCLIENT_NUM_MSG_TYPES] =
2626
{
2727
null_command_handler, // 0x00 (never use this)
2828
null_command_handler, // 0x01
29-
null_command_handler, // 0x02
30-
null_command_handler, // 0x03
29+
{ "TOCLIENT_HELLO", TOCLIENT_STATE_NOT_CONNECTED, &Client::handleCommand_Hello }, // 0x02
30+
{ "TOCLIENT_AUTH_ACCEPT", TOCLIENT_STATE_NOT_CONNECTED, &Client::handleCommand_AuthAccept }, // 0x03
3131
null_command_handler, // 0x04
3232
null_command_handler, // 0x05
3333
null_command_handler, // 0x06
@@ -40,7 +40,7 @@ const ToClientCommandHandler toClientCommandTable[TOCLIENT_NUM_MSG_TYPES] =
4040
null_command_handler, // 0x0D
4141
null_command_handler, // 0x0E
4242
null_command_handler, // 0x0F
43-
{ "TOCLIENT_INIT", TOCLIENT_STATE_NOT_CONNECTED, &Client::handleCommand_Init }, // 0x10
43+
{ "TOCLIENT_INIT", TOCLIENT_STATE_NOT_CONNECTED, &Client::handleCommand_InitLegacy }, // 0x10
4444
null_command_handler,
4545
null_command_handler,
4646
null_command_handler,

Diff for: ‎src/network/networkprotocol.h

+25-9
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,21 @@ with this program; if not, write to the Free Software Foundation, Inc.,
110110
ContentFeatures: change number of special tiles to 6 (CF_SPECIAL_COUNT)
111111
PROTOCOL_VERSION 25:
112112
Rename TOCLIENT_ACCESS_DENIED to TOCLIENT_ACCESS_DENIED_LEGAGY
113-
Rename TOCLIENT_DELETE_PARTICLESPAWNER to TOCLIENT_DELETE_PARTICLESPAWNER_LEGACY
113+
Rename TOCLIENT_DELETE_PARTICLESPAWNER to
114+
TOCLIENT_DELETE_PARTICLESPAWNER_LEGACY
114115
Rename TOSERVER_PASSWORD to TOSERVER_PASSWORD_LEGACY
115116
Rename TOSERVER_INIT to TOSERVER_INIT_LEGACY
117+
Rename TOCLIENT_INIT to TOCLIENT_INIT_LEGACY
116118
Add TOCLIENT_ACCESS_DENIED new opcode (0x0A), using error codes
117119
for standard error, keeping customisation possible. This
118120
permit translation
119121
Add TOCLIENT_DELETE_PARTICLESPAWNER (0x53), fixing the u16 read and
120122
reading u32
123+
Add TOSERVER_INIT new opcode (0x02) for client presentation to server
124+
Add TOSERVER_AUTH new opcode (0x03) for client authentication
125+
Add TOCLIENT_HELLO for presenting server to client after client
126+
presentation
127+
Add TOCLIENT_AUTH_ACCEPT to accept connexion from client
121128
*/
122129

123130
#define LATEST_PROTOCOL_VERSION 24
@@ -143,14 +150,16 @@ with this program; if not, write to the Free Software Foundation, Inc.,
143150

144151
enum ToClientCommand
145152
{
153+
TOCLIENT_HELLO = 0x02,
154+
TOCLIENT_AUTH_ACCEPT = 0x03,
146155
TOCLIENT_ACCESS_DENIED = 0x0A,
147156
/*
148157
u16 command
149158
u16 reason_length
150159
wstring reason
151160
*/
152161

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

586595
enum ToServerCommand
587596
{
588-
TOSERVER_INIT = 0x0F,
597+
TOSERVER_INIT = 0x02,
589598
/*
590599
Sent first after connected.
591600
592601
[0] u16 TOSERVER_INIT
593602
[2] u8 SER_FMT_VER_HIGHEST_READ
594603
[3] u8 compression_modes
595-
[4] std::string player_name
596-
[4+*] std::string password (new in some version)
597-
[4+*+*] u16 minimum supported network protocol version (added sometime)
598-
[4+*+*+2] u16 maximum supported network protocol version (added later than the previous one)
604+
*/
605+
606+
TOSERVER_AUTH = 0x03,
607+
/*
608+
Sent first after presentation (INIT).
609+
[0] std::string player_name
610+
[0+*] std::string password (new in some version)
611+
[0+*+*] u16 minimum supported network protocol version (added sometime)
612+
[0+*+*+2] u16 maximum supported network protocol version (added later than the previous one)
599613
*/
600614

601615
TOSERVER_INIT_LEGACY = 0x10,
@@ -856,8 +870,9 @@ enum AccessDeniedCode {
856870
SERVER_ACCESSDENIED_TOO_MANY_USERS = 6,
857871
SERVER_ACCESSDENIED_EMPTY_PASSWORD = 7,
858872
SERVER_ACCESSDENIED_ALREADY_CONNECTED = 8,
859-
SERVER_ACCESSDENIED_CUSTOM_STRING = 9,
860-
SERVER_ACCESSDENIED_MAX = 10,
873+
SERVER_ACCESSDENIED_SERVER_FAIL = 9,
874+
SERVER_ACCESSDENIED_CUSTOM_STRING = 10,
875+
SERVER_ACCESSDENIED_MAX = 11,
861876
};
862877

863878
enum NetProtoCompressionMode {
@@ -874,6 +889,7 @@ const static std::wstring accessDeniedStrings[SERVER_ACCESSDENIED_MAX] = {
874889
L"Too many users.",
875890
L"Empty passwords are disallowed. Set a password and try again.",
876891
L"Another client is connected with this name. If your client closed unexpectedly, try again in a minute.",
892+
L"Server authenticator failed. Maybe the servers has some problems."
877893
L"",
878894
};
879895

Diff for: ‎src/network/packethandlers/client.cpp

+52-6
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,64 @@ void Client::handleCommand_Deprecated(NetworkPacket* pkt)
3838
<< pkt->getPeerId() << "!" << std::endl;
3939
}
4040

41-
void Client::handleCommand_Init(NetworkPacket* pkt)
41+
void Client::handleCommand_Hello(NetworkPacket* pkt)
4242
{
4343
if (pkt->getSize() < 1)
4444
return;
4545

4646
u8 deployed;
4747
*pkt >> deployed;
4848

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

5252
if (!ser_ver_supported(deployed)) {
53-
infostream << "Client: TOCLIENT_INIT: Server sent "
53+
infostream << "Client: TOCLIENT_HELLO: Server sent "
54+
<< "unsupported ser_fmt_ver"<< std::endl;
55+
return;
56+
}
57+
58+
m_server_ser_ver = deployed;
59+
60+
// @ TODO auth to server
61+
}
62+
63+
void Client::handleCommand_AuthAccept(NetworkPacket* pkt)
64+
{
65+
v3f playerpos;
66+
*pkt >> playerpos >> m_map_seed >> m_recommended_send_interval;
67+
68+
playerpos -= v3f(0, BS / 2, 0);
69+
70+
// Set player position
71+
Player *player = m_env.getLocalPlayer();
72+
assert(player != NULL);
73+
player->setPosition(playerpos);
74+
75+
infostream << "Client: received map seed: " << m_map_seed << std::endl;
76+
infostream << "Client: received recommended send interval "
77+
<< m_recommended_send_interval<<std::endl;
78+
79+
// Reply to server
80+
NetworkPacket* resp_pkt = new NetworkPacket(TOSERVER_INIT2, 0);
81+
Send(resp_pkt);
82+
83+
m_state = LC_Init;
84+
}
85+
86+
void Client::handleCommand_InitLegacy(NetworkPacket* pkt)
87+
{
88+
if (pkt->getSize() < 1)
89+
return;
90+
91+
u8 deployed;
92+
*pkt >> deployed;
93+
94+
infostream << "Client: TOCLIENT_INIT_LEGACY received with "
95+
"deployed=" << ((int)deployed & 0xff) << std::endl;
96+
97+
if (!ser_ver_supported(deployed)) {
98+
infostream << "Client: TOCLIENT_INIT_LEGACY: Server sent "
5499
<< "unsupported ser_fmt_ver"<< std::endl;
55100
return;
56101
}
@@ -98,10 +143,11 @@ void Client::handleCommand_AccessDenied(NetworkPacket* pkt)
98143
m_access_denied_reason = L"Unknown";
99144

100145
if (pkt->getCommand() == TOCLIENT_ACCESS_DENIED) {
146+
if (pkt->getSize() < 1)
147+
return;
148+
101149
u8 denyCode = SERVER_ACCESSDENIED_UNEXPECTED_DATA;
102-
if(pkt->getSize() >= 1) {
103-
*pkt >> denyCode;
104-
}
150+
*pkt >> denyCode;
105151
if (denyCode == SERVER_ACCESSDENIED_CUSTOM_STRING) {
106152
*pkt >> m_access_denied_reason;
107153
}

0 commit comments

Comments
 (0)
Please sign in to comment.