1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-11 17:51:04 +00:00

Network: Remove large parts of deprecated legacy code (#6404)

Also remove the setting 'send_pre_v25_init'
Keep old enum entries for obsolete commands
This commit is contained in:
SmallJoker 2017-09-12 19:48:09 +02:00 committed by GitHub
parent 7f2a19da11
commit ee9a442ecc
17 changed files with 143 additions and 882 deletions

View file

@ -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_InitLegacy }, // 0x10
null_command_handler, // 0x10
null_command_handler,
null_command_handler,
null_command_handler,
@ -96,7 +96,7 @@ const ToClientCommandHandler toClientCommandTable[TOCLIENT_NUM_MSG_TYPES] =
{ "TOCLIENT_MOVEMENT", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_Movement }, // 0x45
{ "TOCLIENT_SPAWN_PARTICLE", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_SpawnParticle }, // 0x46
{ "TOCLIENT_ADD_PARTICLESPAWNER", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_AddParticleSpawner }, // 0x47
{ "TOCLIENT_DELETE_PARTICLESPAWNER_LEGACY", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_DeleteParticleSpawner }, // 0x48
null_command_handler,
{ "TOCLIENT_HUDADD", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_HudAdd }, // 0x49
{ "TOCLIENT_HUDRM", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_HudRemove }, // 0x4a
{ "TOCLIENT_HUDCHANGE", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_HudChange }, // 0x4b
@ -143,7 +143,7 @@ const ServerCommandFactory serverCommandFactoryTable[TOSERVER_NUM_MSG_TYPES] =
null_command_factory, // 0x0d
null_command_factory, // 0x0e
null_command_factory, // 0x0F
{ "TOSERVER_INIT_LEGACY", 1, false }, // 0x10
null_command_factory, // 0x10
{ "TOSERVER_INIT2", 1, true }, // 0x11
null_command_factory, // 0x12
null_command_factory, // 0x13
@ -166,22 +166,22 @@ const ServerCommandFactory serverCommandFactoryTable[TOSERVER_NUM_MSG_TYPES] =
{ "TOSERVER_GOTBLOCKS", 2, true }, // 0x24
{ "TOSERVER_DELETEDBLOCKS", 2, true }, // 0x25
null_command_factory, // 0x26
{ "TOSERVER_CLICK_OBJECT", 0, false }, // 0x27
{ "TOSERVER_GROUND_ACTION", 0, false }, // 0x28
{ "TOSERVER_RELEASE", 0, false }, // 0x29
null_command_factory, // 0x27
null_command_factory, // 0x28
null_command_factory, // 0x29
null_command_factory, // 0x2a
null_command_factory, // 0x2b
null_command_factory, // 0x2c
null_command_factory, // 0x2d
null_command_factory, // 0x2e
null_command_factory, // 0x2f
{ "TOSERVER_SIGNTEXT", 0, false }, // 0x30
null_command_factory, // 0x30
{ "TOSERVER_INVENTORY_ACTION", 0, true }, // 0x31
{ "TOSERVER_CHAT_MESSAGE", 0, true }, // 0x32
{ "TOSERVER_SIGNNODETEXT", 0, false }, // 0x33
{ "TOSERVER_CLICK_ACTIVEOBJECT", 0, false }, // 0x34
null_command_factory, // 0x33
null_command_factory, // 0x34
{ "TOSERVER_DAMAGE", 0, true }, // 0x35
{ "TOSERVER_PASSWORD_LEGACY", 0, true }, // 0x36
null_command_factory, // 0x36
{ "TOSERVER_PLAYERITEM", 0, true }, // 0x37
{ "TOSERVER_RESPAWN", 0, true }, // 0x38
{ "TOSERVER_INTERACT", 0, true }, // 0x39
@ -192,7 +192,7 @@ const ServerCommandFactory serverCommandFactoryTable[TOSERVER_NUM_MSG_TYPES] =
null_command_factory, // 0x3e
null_command_factory, // 0x3f
{ "TOSERVER_REQUEST_MEDIA", 1, true }, // 0x40
{ "TOSERVER_RECEIVED_MEDIA", 1, true }, // 0x41
null_command_factory, // 0x41
{ "TOSERVER_BREATH", 0, true }, // 0x42 old TOSERVER_BREATH. Ignored by servers
{ "TOSERVER_CLIENT_READY", 0, true }, // 0x43
null_command_factory, // 0x44

View file

@ -86,8 +86,7 @@ void Client::handleCommand_Hello(NetworkPacket* pkt)
// we recieved a TOCLIENT_HELLO while auth was already going on
errorstream << "Client: TOCLIENT_HELLO while auth was already going on"
<< "(chosen_mech=" << m_chosen_auth_mech << ")." << std::endl;
if ((m_chosen_auth_mech == AUTH_MECHANISM_SRP)
|| (m_chosen_auth_mech == AUTH_MECHANISM_LEGACY_PASSWORD)) {
if (m_chosen_auth_mech == AUTH_MECHANISM_SRP) {
srp_user_delete((SRPUser *) m_auth_data);
m_auth_data = 0;
}
@ -157,60 +156,6 @@ void Client::handleCommand_DenySudoMode(NetworkPacket* pkt)
// reset everything and be sad
deleteAuthData();
}
void Client::handleCommand_InitLegacy(NetworkPacket* pkt)
{
if (pkt->getSize() < 1)
return;
u8 server_ser_ver;
*pkt >> server_ser_ver;
infostream << "Client: TOCLIENT_INIT_LEGACY received with "
"server_ser_ver=" << ((int)server_ser_ver & 0xff) << std::endl;
if (!ser_ver_supported(server_ser_ver)) {
infostream << "Client: TOCLIENT_INIT_LEGACY: Server sent "
<< "unsupported ser_fmt_ver"<< std::endl;
return;
}
m_server_ser_ver = server_ser_ver;
// We can be totally wrong with this guess
// but we only need some value < 25.
m_proto_ver = 24;
// Get player position
v3s16 playerpos_s16(0, BS * 2 + BS * 20, 0);
if (pkt->getSize() >= 1 + 6) {
*pkt >> playerpos_s16;
}
v3f playerpos_f = intToFloat(playerpos_s16, BS) - v3f(0, BS / 2, 0);
// Set player position
LocalPlayer *player = m_env.getLocalPlayer();
assert(player != NULL);
player->setPosition(playerpos_f);
if (pkt->getSize() >= 1 + 6 + 8) {
// Get map seed
*pkt >> m_map_seed;
infostream << "Client: received map seed: " << m_map_seed << std::endl;
}
if (pkt->getSize() >= 1 + 6 + 8 + 4) {
*pkt >> m_recommended_send_interval;
infostream << "Client: received recommended send interval "
<< m_recommended_send_interval<<std::endl;
}
// Reply to server
NetworkPacket resp_pkt(TOSERVER_INIT2, 0);
Send(&resp_pkt);
m_state = LC_Init;
}
void Client::handleCommand_AccessDenied(NetworkPacket* pkt)
{
@ -220,44 +165,44 @@ void Client::handleCommand_AccessDenied(NetworkPacket* pkt)
m_access_denied = true;
m_access_denied_reason = "Unknown";
if (pkt->getCommand() == TOCLIENT_ACCESS_DENIED) {
if (pkt->getSize() < 1)
return;
u8 denyCode = SERVER_ACCESSDENIED_UNEXPECTED_DATA;
*pkt >> denyCode;
if (denyCode == SERVER_ACCESSDENIED_SHUTDOWN ||
denyCode == SERVER_ACCESSDENIED_CRASH) {
*pkt >> m_access_denied_reason;
if (m_access_denied_reason.empty()) {
m_access_denied_reason = accessDeniedStrings[denyCode];
}
u8 reconnect;
*pkt >> reconnect;
m_access_denied_reconnect = reconnect & 1;
} else if (denyCode == SERVER_ACCESSDENIED_CUSTOM_STRING) {
*pkt >> m_access_denied_reason;
} else if (denyCode < SERVER_ACCESSDENIED_MAX) {
m_access_denied_reason = accessDeniedStrings[denyCode];
} else {
// Allow us to add new error messages to the
// protocol without raising the protocol version, if we want to.
// Until then (which may be never), this is outside
// of the defined protocol.
*pkt >> m_access_denied_reason;
if (m_access_denied_reason.empty()) {
m_access_denied_reason = "Unknown";
}
}
}
// 13/03/15 Legacy code from 0.4.12 and lesser. must stay 1 year
// for compat with old clients
else {
if (pkt->getCommand() != TOCLIENT_ACCESS_DENIED) {
// 13/03/15 Legacy code from 0.4.12 and lesser but is still used
// in some places of the server code
if (pkt->getSize() >= 2) {
std::wstring wide_reason;
*pkt >> wide_reason;
m_access_denied_reason = wide_to_utf8(wide_reason);
}
return;
}
if (pkt->getSize() < 1)
return;
u8 denyCode = SERVER_ACCESSDENIED_UNEXPECTED_DATA;
*pkt >> denyCode;
if (denyCode == SERVER_ACCESSDENIED_SHUTDOWN ||
denyCode == SERVER_ACCESSDENIED_CRASH) {
*pkt >> m_access_denied_reason;
if (m_access_denied_reason.empty()) {
m_access_denied_reason = accessDeniedStrings[denyCode];
}
u8 reconnect;
*pkt >> reconnect;
m_access_denied_reconnect = reconnect & 1;
} else if (denyCode == SERVER_ACCESSDENIED_CUSTOM_STRING) {
*pkt >> m_access_denied_reason;
} else if (denyCode < SERVER_ACCESSDENIED_MAX) {
m_access_denied_reason = accessDeniedStrings[denyCode];
} else {
// Allow us to add new error messages to the
// protocol without raising the protocol version, if we want to.
// Until then (which may be never), this is outside
// of the defined protocol.
*pkt >> m_access_denied_reason;
if (m_access_denied_reason.empty()) {
m_access_denied_reason = "Unknown";
}
}
}
@ -1065,23 +1010,12 @@ void Client::handleCommand_AddParticleSpawner(NetworkPacket* pkt)
void Client::handleCommand_DeleteParticleSpawner(NetworkPacket* pkt)
{
u16 legacy_id;
u32 id;
// Modification set 13/03/15, 1 year of compat for protocol v24
if (pkt->getCommand() == TOCLIENT_DELETE_PARTICLESPAWNER_LEGACY) {
*pkt >> legacy_id;
}
else {
*pkt >> id;
}
*pkt >> id;
ClientEvent *event = new ClientEvent();
event->type = CE_DELETE_PARTICLESPAWNER;
event->delete_particlespawner.id =
(pkt->getCommand() == TOCLIENT_DELETE_PARTICLESPAWNER_LEGACY ?
(u32) legacy_id : id);
event->delete_particlespawner.id = id;
m_client_event_queue.push(event);
}
@ -1360,9 +1294,8 @@ void Client::handleCommand_UpdatePlayerList(NetworkPacket* pkt)
void Client::handleCommand_SrpBytesSandB(NetworkPacket* pkt)
{
if ((m_chosen_auth_mech != AUTH_MECHANISM_LEGACY_PASSWORD)
&& (m_chosen_auth_mech != AUTH_MECHANISM_SRP)) {
errorstream << "Client: Recieved SRP S_B login message,"
if (m_chosen_auth_mech != AUTH_MECHANISM_SRP) {
errorstream << "Client: Received SRP S_B login message,"
<< " but wasn't supposed to (chosen_mech="
<< m_chosen_auth_mech << ")." << std::endl;
return;
@ -1375,7 +1308,7 @@ void Client::handleCommand_SrpBytesSandB(NetworkPacket* pkt)
std::string B;
*pkt >> s >> B;
infostream << "Client: Recieved TOCLIENT_SRP_BYTES_S_B." << std::endl;
infostream << "Client: Received TOCLIENT_SRP_BYTES_S_B." << std::endl;
srp_user_process_challenge(usr, (const unsigned char *) s.c_str(), s.size(),
(const unsigned char *) B.c_str(), B.size(),

View file

@ -191,7 +191,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
// The minimal version depends on whether
// send_pre_v25_init is enabled or not
#define CLIENT_PROTOCOL_VERSION_MIN 36
#define CLIENT_PROTOCOL_VERSION_MIN_LEGACY 24
#define CLIENT_PROTOCOL_VERSION_MAX LATEST_PROTOCOL_VERSION
// Constant that differentiates the protocol from random data and other protocols
@ -235,26 +234,15 @@ enum ToClientCommand
/*
Signals client that sudo mode auth failed.
*/
TOCLIENT_INIT_LEGACY = 0x10,
/*
Server's reply to TOSERVER_INIT.
Sent second after connected.
[0] u16 TOSERVER_INIT
[2] u8 deployed version
[3] v3s16 player's position + v3f(0,BS/2,0) floatToInt'd
[12] u64 map seed (new as of 2011-02-27)
[20] f1000 recommended send interval (in seconds) (new as of 14)
NOTE: The position in here is deprecated; position is
explicitly sent afterwards
*/
TOCLIENT_ACCESS_DENIED = 0x0A,
/*
u8 reason
std::string custom reason (if needed, otherwise "")
u8 (bool) reconnect
*/
TOCLIENT_INIT_LEGACY = 0x10, // Obsolete
TOCLIENT_BLOCKDATA = 0x20, //TODO: Multiple blocks
TOCLIENT_ADDNODE = 0x21,
/*
@ -265,34 +253,9 @@ enum ToClientCommand
TOCLIENT_REMOVENODE = 0x22,
TOCLIENT_PLAYERPOS = 0x23, // Obsolete
/*
[0] u16 command
// Followed by an arbitary number of these:
// Number is determined from packet length.
[N] u16 peer_id
[N+2] v3s32 position*100
[N+2+12] v3s32 speed*100
[N+2+12+12] s32 pitch*100
[N+2+12+12+4] s32 yaw*100
*/
TOCLIENT_PLAYERINFO = 0x24, // Obsolete
/*
[0] u16 command
// Followed by an arbitary number of these:
// Number is determined from packet length.
[N] u16 peer_id
[N] char[20] name
*/
TOCLIENT_OPT_BLOCK_NOT_FOUND = 0x25, // Obsolete
TOCLIENT_SECTORMETA = 0x26, // Obsolete
/*
[0] u16 command
[2] u8 sector count
[3...] v2s16 pos + sector metadata
*/
TOCLIENT_INVENTORY = 0x27,
/*
@ -301,21 +264,6 @@ enum ToClientCommand
*/
TOCLIENT_OBJECTDATA = 0x28, // Obsolete
/*
Sent as unreliable.
u16 number of player positions
for each player:
u16 peer_id
v3s32 position*100
v3s32 speed*100
s32 pitch*100
s32 yaw*100
u16 count of blocks
for each block:
v3s16 blockpos
block objects
*/
TOCLIENT_TIME_OF_DAY = 0x29,
/*
@ -341,11 +289,7 @@ enum ToClientCommand
wstring message
*/
TOCLIENT_CHAT_MESSAGE_OLD = 0x30, // Deprecated by proto v35
/*
u16 length
wstring message
*/
TOCLIENT_CHAT_MESSAGE_OLD = 0x30, // Obsolete
TOCLIENT_ACTIVE_OBJECT_REMOVE_ADD = 0x31,
/*
@ -391,14 +335,6 @@ enum ToClientCommand
*/
TOCLIENT_PLAYERITEM = 0x36, // Obsolete
/*
u16 count of player items
for all player items {
u16 peer id
u16 length of serialized item
string serialized item
}
*/
TOCLIENT_DEATHSCREEN = 0x37,
/*
@ -557,10 +493,7 @@ enum ToClientCommand
u8 collision_removal
*/
TOCLIENT_DELETE_PARTICLESPAWNER_LEGACY = 0x48,
/*
u16 id
*/
TOCLIENT_DELETE_PARTICLESPAWNER_LEGACY = 0x48, // Obsolete
TOCLIENT_HUDADD = 0x49,
/*
@ -679,7 +612,7 @@ enum ToClientCommand
TOCLIENT_SRP_BYTES_S_B = 0x60,
/*
Belonging to AUTH_MECHANISM_LEGACY_PASSWORD and AUTH_MECHANISM_SRP.
Belonging to AUTH_MECHANISM_SRP.
std::string bytes_s
std::string bytes_B
@ -701,17 +634,7 @@ enum ToServerCommand
std::string player name
*/
TOSERVER_INIT_LEGACY = 0x10,
/*
Sent first after connected.
[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)
[51] u16 minimum supported network protocol version (added sometime)
[53] u16 maximum supported network protocol version (added later than the previous one)
*/
TOSERVER_INIT_LEGACY = 0x10, // Obsolete
TOSERVER_INIT2 = 0x11,
/*
@ -721,7 +644,7 @@ enum ToServerCommand
[0] u16 TOSERVER_INIT2
*/
TOSERVER_GETBLOCK=0x20, // Obsolete
TOSERVER_GETBLOCK = 0x20, // Obsolete
TOSERVER_ADDNODE = 0x21, // Obsolete
TOSERVER_REMOVENODE = 0x22, // Obsolete
@ -756,48 +679,10 @@ enum ToServerCommand
*/
TOSERVER_ADDNODE_FROM_INVENTORY = 0x26, // Obsolete
/*
[0] u16 command
[2] v3s16 pos
[8] u16 i
*/
TOSERVER_CLICK_OBJECT = 0x27, // Obsolete
/*
length: 13
[0] u16 command
[2] u8 button (0=left, 1=right)
[3] v3s16 blockpos
[9] s16 id
[11] u16 item
*/
TOSERVER_GROUND_ACTION = 0x28, // Obsolete
/*
length: 17
[0] u16 command
[2] u8 action
[3] v3s16 nodepos_undersurface
[9] v3s16 nodepos_abovesurface
[15] u16 item
actions:
0: start digging (from undersurface)
1: place block (to abovesurface)
2: stop digging (all parameters ignored)
3: digging completed
*/
TOSERVER_RELEASE = 0x29, // Obsolete
// (oops, there is some gap here)
TOSERVER_SIGNTEXT = 0x30, // Old signs, obsolete
/*
v3s16 blockpos
s16 id
u16 textlen
textdata
*/
TOSERVER_SIGNTEXT = 0x30, // Obsolete
TOSERVER_INVENTORY_ACTION = 0x31,
/*
@ -810,35 +695,15 @@ enum ToServerCommand
wstring message
*/
TOSERVER_SIGNNODETEXT = 0x33, // obsolete
/*
v3s16 p
u16 textlen
textdata
*/
TOSERVER_SIGNNODETEXT = 0x33, // Obsolete
TOSERVER_CLICK_ACTIVEOBJECT = 0x34, // Obsolete
/*
length: 7
[0] u16 command
[2] u8 button (0=left, 1=right)
[3] u16 id
[5] u16 item
*/
TOSERVER_DAMAGE = 0x35,
/*
u8 amount
*/
TOSERVER_PASSWORD_LEGACY = 0x36,
/*
Sent to change password.
[0] u16 TOSERVER_PASSWORD
[2] u8[28] old password
[30] u8[28] new password
*/
TOSERVER_PASSWORD_LEGACY = 0x36, // Obsolete
TOSERVER_PLAYERITEM = 0x37,
/*
@ -866,8 +731,6 @@ enum ToServerCommand
2: digging completed
3: place block or item (to abovesurface)
4: use item
(Obsoletes TOSERVER_GROUND_ACTION and TOSERVER_CLICK_ACTIVEOBJECT.)
*/
TOSERVER_REMOVED_SOUNDS = 0x3a,
@ -908,17 +771,10 @@ enum ToServerCommand
u16 length of name
string name
}
*/
TOSERVER_RECEIVED_MEDIA = 0x41,
/*
<no payload data>
*/
TOSERVER_RECEIVED_MEDIA = 0x41, // Obsolete
TOSERVER_BREATH = 0x42, // Obsolete
/*
u16 breath
*/
TOSERVER_CLIENT_READY = 0x43,
/*
@ -941,7 +797,7 @@ enum ToServerCommand
TOSERVER_SRP_BYTES_A = 0x51,
/*
Belonging to AUTH_MECHANISM_LEGACY_PASSWORD and AUTH_MECHANISM_SRP,
Belonging to AUTH_MECHANISM_SRP,
depending on current_login_based_on.
std::string bytes_A
@ -952,7 +808,7 @@ enum ToServerCommand
TOSERVER_SRP_BYTES_M = 0x52,
/*
Belonging to AUTH_MECHANISM_LEGACY_PASSWORD and AUTH_MECHANISM_SRP.
Belonging to AUTH_MECHANISM_SRP.
std::string bytes_M
*/

View file

@ -40,7 +40,7 @@ const ToServerCommandHandler toServerCommandTable[TOSERVER_NUM_MSG_TYPES] =
null_command_handler, // 0x0d
null_command_handler, // 0x0e
null_command_handler, // 0x0f
{ "TOSERVER_INIT_LEGACY", TOSERVER_STATE_NOT_CONNECTED, &Server::handleCommand_Init_Legacy }, // 0x10
null_command_handler, // 0x10
{ "TOSERVER_INIT2", TOSERVER_STATE_NOT_CONNECTED, &Server::handleCommand_Init2 }, // 0x11
null_command_handler, // 0x12
null_command_handler, // 0x13
@ -63,22 +63,22 @@ const ToServerCommandHandler toServerCommandTable[TOSERVER_NUM_MSG_TYPES] =
{ "TOSERVER_GOTBLOCKS", TOSERVER_STATE_STARTUP, &Server::handleCommand_GotBlocks }, // 0x24
{ "TOSERVER_DELETEDBLOCKS", TOSERVER_STATE_INGAME, &Server::handleCommand_DeletedBlocks }, // 0x25
null_command_handler, // 0x26
{ "TOSERVER_CLICK_OBJECT", TOSERVER_STATE_INGAME, &Server::handleCommand_Deprecated }, // 0x27
{ "TOSERVER_GROUND_ACTION", TOSERVER_STATE_INGAME, &Server::handleCommand_Deprecated }, // 0x28
{ "TOSERVER_RELEASE", TOSERVER_STATE_INGAME, &Server::handleCommand_Deprecated }, // 0x29
null_command_handler, // 0x27
null_command_handler, // 0x28
null_command_handler, // 0x29
null_command_handler, // 0x2a
null_command_handler, // 0x2b
null_command_handler, // 0x2c
null_command_handler, // 0x2d
null_command_handler, // 0x2e
null_command_handler, // 0x2f
{ "TOSERVER_SIGNTEXT", TOSERVER_STATE_INGAME, &Server::handleCommand_Deprecated }, // 0x30
null_command_handler, // 0x30
{ "TOSERVER_INVENTORY_ACTION", TOSERVER_STATE_INGAME, &Server::handleCommand_InventoryAction }, // 0x31
{ "TOSERVER_CHAT_MESSAGE", TOSERVER_STATE_INGAME, &Server::handleCommand_ChatMessage }, // 0x32
{ "TOSERVER_SIGNNODETEXT", TOSERVER_STATE_INGAME, &Server::handleCommand_Deprecated }, // 0x33
{ "TOSERVER_CLICK_ACTIVEOBJECT", TOSERVER_STATE_INGAME, &Server::handleCommand_Deprecated }, // 0x34
null_command_handler, // 0x33
null_command_handler, // 0x34
{ "TOSERVER_DAMAGE", TOSERVER_STATE_INGAME, &Server::handleCommand_Damage }, // 0x35
{ "TOSERVER_PASSWORD_LEGACY", TOSERVER_STATE_INGAME, &Server::handleCommand_Password }, // 0x36
null_command_handler, // 0x36
{ "TOSERVER_PLAYERITEM", TOSERVER_STATE_INGAME, &Server::handleCommand_PlayerItem }, // 0x37
{ "TOSERVER_RESPAWN", TOSERVER_STATE_INGAME, &Server::handleCommand_Respawn }, // 0x38
{ "TOSERVER_INTERACT", TOSERVER_STATE_INGAME, &Server::handleCommand_Interact }, // 0x39
@ -89,8 +89,8 @@ const ToServerCommandHandler toServerCommandTable[TOSERVER_NUM_MSG_TYPES] =
null_command_handler, // 0x3e
null_command_handler, // 0x3f
{ "TOSERVER_REQUEST_MEDIA", TOSERVER_STATE_STARTUP, &Server::handleCommand_RequestMedia }, // 0x40
{ "TOSERVER_RECEIVED_MEDIA", TOSERVER_STATE_STARTUP, &Server::handleCommand_Deprecated }, // 0x41 not used by the server since protocol version 23
{ "TOSERVER_BREATH", TOSERVER_STATE_INGAME, &Server::handleCommand_Deprecated }, // 0x42 Old breath model which is now deprecated for anticheating
null_command_handler, // 0x41
null_command_handler, // 0x42
{ "TOSERVER_CLIENT_READY", TOSERVER_STATE_STARTUP, &Server::handleCommand_ClientReady }, // 0x43
null_command_handler, // 0x44
null_command_handler, // 0x45
@ -161,18 +161,18 @@ const ClientCommandFactory clientCommandFactoryTable[TOCLIENT_NUM_MSG_TYPES] =
null_command_factory,
null_command_factory,
{ "TOCLIENT_CHAT_MESSAGE", 0, true }, // 0x2F
{ "TOCLIENT_CHAT_MESSAGE_OLD", 0, true }, // 0x30
null_command_factory, // 0x30
{ "TOCLIENT_ACTIVE_OBJECT_REMOVE_ADD", 0, true }, // 0x31
{ "TOCLIENT_ACTIVE_OBJECT_MESSAGES", 0, true }, // 0x32 Special packet, sent by 0 (rel) and 1 (unrel) channel
{ "TOCLIENT_HP", 0, true }, // 0x33
{ "TOCLIENT_MOVE_PLAYER", 0, true }, // 0x34
{ "TOCLIENT_ACCESS_DENIED_LEGACY", 0, true }, // 0x35
{ "TOCLIENT_PLAYERITEM", 0, false }, // 0x36 obsolete
null_command_factory, // 0x36
{ "TOCLIENT_DEATHSCREEN", 0, true }, // 0x37
{ "TOCLIENT_MEDIA", 2, true }, // 0x38
{ "TOCLIENT_TOOLDEF", 0, false }, // 0x39 obsolete
null_command_factory, // 0x39
{ "TOCLIENT_NODEDEF", 0, true }, // 0x3a
{ "TOCLIENT_CRAFTITEMDEF", 0, false }, // 0x3b obsolete
null_command_factory, // 0x3b
{ "TOCLIENT_ANNOUNCE_MEDIA", 0, true }, // 0x3c
{ "TOCLIENT_ITEMDEF", 0, true }, // 0x3d
null_command_factory,
@ -185,7 +185,7 @@ const ClientCommandFactory clientCommandFactoryTable[TOCLIENT_NUM_MSG_TYPES] =
{ "TOCLIENT_MOVEMENT", 0, true }, // 0x45
{ "TOCLIENT_SPAWN_PARTICLE", 0, true }, // 0x46
{ "TOCLIENT_ADD_PARTICLESPAWNER", 0, true }, // 0x47
{ "TOCLIENT_DELETE_PARTICLESPAWNER_LEGACY", 0, true }, // 0x48
null_command_factory, // 0x48
{ "TOCLIENT_HUDADD", 1, true }, // 0x49
{ "TOCLIENT_HUDRM", 1, true }, // 0x4a
{ "TOCLIENT_HUDCHANGE", 0, true }, // 0x4b

View file

@ -141,8 +141,7 @@ void Server::handleCommand_Init(NetworkPacket* pkt)
client->net_proto_version = net_proto_version;
// On this handler at least protocol version 25 is required
if (net_proto_version < 25 ||
if (g_settings->getBool("strict_protocol_version_checking") ||
net_proto_version < SERVER_PROTOCOL_VERSION_MIN ||
net_proto_version > SERVER_PROTOCOL_VERSION_MAX) {
actionstream << "Server: A mismatched client tried to connect from "
@ -151,15 +150,6 @@ void Server::handleCommand_Init(NetworkPacket* pkt)
return;
}
if (g_settings->getBool("strict_protocol_version_checking")) {
if (net_proto_version != LATEST_PROTOCOL_VERSION) {
actionstream << "Server: A mismatched (strict) client tried to "
<< "connect from " << addr_s << std::endl;
DenyAccess(pkt->getPeerId(), SERVER_ACCESSDENIED_WRONG_VERSION);
return;
}
}
/*
Validate player name
*/
@ -242,9 +232,6 @@ void Server::handleCommand_Init(NetworkPacket* pkt)
DenyAccess(pkt->getPeerId(), SERVER_ACCESSDENIED_SERVER_FAIL);
return;
}
} else if (base64_is_valid(encpwd)) {
auth_mechs |= AUTH_MECHANISM_LEGACY_PASSWORD;
client->enc_pwd = encpwd;
} else {
actionstream << "User " << playername
<< " tried to log in, but password field"
@ -287,320 +274,6 @@ void Server::handleCommand_Init(NetworkPacket* pkt)
m_clients.event(pkt->getPeerId(), CSE_Hello);
}
void Server::handleCommand_Init_Legacy(NetworkPacket* pkt)
{
// [0] u8 SER_FMT_VER_HIGHEST_READ
// [1] u8[20] player_name
// [21] u8[28] password <--- can be sent without this, from old versions
if (pkt->getSize() < 1+PLAYERNAME_SIZE)
return;
RemoteClient* client = getClient(pkt->getPeerId(), CS_Created);
std::string addr_s;
try {
Address address = getPeerAddress(pkt->getPeerId());
addr_s = address.serializeString();
}
catch (con::PeerNotFoundException &e) {
/*
* no peer for this packet found
* most common reason is peer timeout, e.g. peer didn't
* respond for some time, your server was overloaded or
* things like that.
*/
infostream << "Server::ProcessData(): Canceling: peer "
<< pkt->getPeerId() << " not found" << std::endl;
return;
}
// If net_proto_version is set, this client has already been handled
if (client->getState() > CS_Created) {
verbosestream << "Server: Ignoring multiple TOSERVER_INITs from "
<< addr_s << " (peer_id=" << pkt->getPeerId() << ")" << std::endl;
return;
}
verbosestream << "Server: Got TOSERVER_INIT_LEGACY from " << addr_s << " (peer_id="
<< pkt->getPeerId() << ")" << std::endl;
// Do not allow multiple players in simple singleplayer mode.
// This isn't a perfect way to do it, but will suffice for now
if (m_simple_singleplayer_mode && m_clients.getClientIDs().size() > 1) {
infostream << "Server: Not allowing another client (" << addr_s
<< ") to connect in simple singleplayer mode" << std::endl;
DenyAccess_Legacy(pkt->getPeerId(), L"Running in simple singleplayer mode.");
return;
}
// First byte after command is maximum supported
// serialization version
u8 client_max;
*pkt >> client_max;
u8 our_max = SER_FMT_VER_HIGHEST_READ;
// Use the highest version supported by both
int deployed = std::min(client_max, our_max);
// If it's lower than the lowest supported, give up.
if (deployed < SER_FMT_VER_LOWEST_READ)
deployed = SER_FMT_VER_INVALID;
if (deployed == SER_FMT_VER_INVALID) {
actionstream << "Server: A mismatched client tried to connect from "
<< addr_s << std::endl;
infostream<<"Server: Cannot negotiate serialization version with "
<< addr_s << std::endl;
DenyAccess_Legacy(pkt->getPeerId(), std::wstring(
L"Your client's version is not supported.\n"
L"Server version is ")
+ utf8_to_wide(g_version_string) + L"."
);
return;
}
client->setPendingSerializationVersion(deployed);
/*
Read and check network protocol version
*/
u16 min_net_proto_version = 0;
if (pkt->getSize() >= 1 + PLAYERNAME_SIZE + PASSWORD_SIZE + 2)
min_net_proto_version = pkt->getU16(1 + PLAYERNAME_SIZE + PASSWORD_SIZE);
// Use same version as minimum and maximum if maximum version field
// doesn't exist (backwards compatibility)
u16 max_net_proto_version = min_net_proto_version;
if (pkt->getSize() >= 1 + PLAYERNAME_SIZE + PASSWORD_SIZE + 2 + 2)
max_net_proto_version = pkt->getU16(1 + PLAYERNAME_SIZE + PASSWORD_SIZE + 2);
// Start with client's maximum version
u16 net_proto_version = max_net_proto_version;
// Figure out a working version if it is possible at all
if (max_net_proto_version >= SERVER_PROTOCOL_VERSION_MIN ||
min_net_proto_version <= SERVER_PROTOCOL_VERSION_MAX) {
// If maximum is larger than our maximum, go with our maximum
if (max_net_proto_version > SERVER_PROTOCOL_VERSION_MAX)
net_proto_version = SERVER_PROTOCOL_VERSION_MAX;
// Else go with client's maximum
else
net_proto_version = max_net_proto_version;
}
// The client will send up to date init packet, ignore this one
if (net_proto_version >= 25)
return;
verbosestream << "Server: " << addr_s << ": Protocol version: min: "
<< min_net_proto_version << ", max: " << max_net_proto_version
<< ", chosen: " << net_proto_version << std::endl;
client->net_proto_version = net_proto_version;
if (net_proto_version < SERVER_PROTOCOL_VERSION_MIN ||
net_proto_version > SERVER_PROTOCOL_VERSION_MAX) {
actionstream << "Server: A mismatched client tried to connect from "
<< addr_s << std::endl;
DenyAccess_Legacy(pkt->getPeerId(), std::wstring(
L"Your client's version is not supported.\n"
L"Server version is ")
+ utf8_to_wide(g_version_string) + L",\n"
+ L"server's PROTOCOL_VERSION is "
+ utf8_to_wide(itos(SERVER_PROTOCOL_VERSION_MIN))
+ L"..."
+ utf8_to_wide(itos(SERVER_PROTOCOL_VERSION_MAX))
+ L", client's PROTOCOL_VERSION is "
+ utf8_to_wide(itos(min_net_proto_version))
+ L"..."
+ utf8_to_wide(itos(max_net_proto_version))
);
return;
}
if (g_settings->getBool("strict_protocol_version_checking")) {
if (net_proto_version != LATEST_PROTOCOL_VERSION) {
actionstream << "Server: A mismatched (strict) client tried to "
<< "connect from " << addr_s << std::endl;
DenyAccess_Legacy(pkt->getPeerId(), std::wstring(
L"Your client's version is not supported.\n"
L"Server version is ")
+ utf8_to_wide(g_version_string) + L",\n"
+ L"server's PROTOCOL_VERSION (strict) is "
+ utf8_to_wide(itos(LATEST_PROTOCOL_VERSION))
+ L", client's PROTOCOL_VERSION is "
+ utf8_to_wide(itos(min_net_proto_version))
+ L"..."
+ utf8_to_wide(itos(max_net_proto_version))
);
return;
}
}
/*
Set up player
*/
char playername[PLAYERNAME_SIZE];
unsigned int playername_length = 0;
for (; playername_length < PLAYERNAME_SIZE; playername_length++ ) {
playername[playername_length] = pkt->getChar(1+playername_length);
if (pkt->getChar(1+playername_length) == 0)
break;
}
if (playername_length == PLAYERNAME_SIZE) {
actionstream << "Server: Player with name exceeding max length "
<< "tried to connect from " << addr_s << std::endl;
DenyAccess_Legacy(pkt->getPeerId(), L"Name too long");
return;
}
if (playername[0]=='\0') {
actionstream << "Server: Player with an empty name "
<< "tried to connect from " << addr_s << std::endl;
DenyAccess_Legacy(pkt->getPeerId(), L"Empty name");
return;
}
if (!string_allowed(playername, PLAYERNAME_ALLOWED_CHARS)) {
actionstream << "Server: Player with an invalid name "
<< "tried to connect from " << addr_s << std::endl;
DenyAccess_Legacy(pkt->getPeerId(), L"Name contains unallowed characters");
return;
}
if (!isSingleplayer() && strcasecmp(playername, "singleplayer") == 0) {
actionstream << "Server: Player with the name \"singleplayer\" "
<< "tried to connect from " << addr_s << std::endl;
DenyAccess_Legacy(pkt->getPeerId(), L"Name is not allowed");
return;
}
{
std::string reason;
if (m_script->on_prejoinplayer(playername, addr_s, &reason)) {
actionstream << "Server: Player with the name \"" << playername << "\" "
<< "tried to connect from " << addr_s << " "
<< "but it was disallowed for the following reason: "
<< reason << std::endl;
DenyAccess_Legacy(pkt->getPeerId(), utf8_to_wide(reason));
return;
}
}
infostream<<"Server: New connection: \""<<playername<<"\" from "
<<addr_s<<" (peer_id="<<pkt->getPeerId()<<")"<<std::endl;
// Get password
char given_password[PASSWORD_SIZE];
if (pkt->getSize() < 1 + PLAYERNAME_SIZE + PASSWORD_SIZE) {
// old version - assume blank password
given_password[0] = 0;
}
else {
for (u16 i = 0; i < PASSWORD_SIZE - 1; i++) {
given_password[i] = pkt->getChar(21 + i);
}
given_password[PASSWORD_SIZE - 1] = 0;
}
if (!base64_is_valid(given_password)) {
actionstream << "Server: " << playername
<< " supplied invalid password hash" << std::endl;
DenyAccess_Legacy(pkt->getPeerId(), L"Invalid password hash");
return;
}
// Enforce user limit.
// Don't enforce for users that have some admin right
if (m_clients.isUserLimitReached() &&
!checkPriv(playername, "server") &&
!checkPriv(playername, "ban") &&
!checkPriv(playername, "privs") &&
!checkPriv(playername, "password") &&
playername != g_settings->get("name")) {
actionstream << "Server: " << playername << " tried to join, but there"
<< " are already max_users="
<< g_settings->getU16("max_users") << " players." << std::endl;
DenyAccess_Legacy(pkt->getPeerId(), L"Too many users.");
return;
}
std::string checkpwd; // Password hash to check against
bool has_auth = m_script->getAuth(playername, &checkpwd, NULL);
// If no authentication info exists for user, create it
if (!has_auth) {
if (!isSingleplayer() &&
g_settings->getBool("disallow_empty_password") &&
std::string(given_password).empty()) {
actionstream << "Server: " << playername
<< " supplied empty password" << std::endl;
DenyAccess_Legacy(pkt->getPeerId(), L"Empty passwords are "
L"disallowed. Set a password and try again.");
return;
}
std::string raw_default_password =
g_settings->get("default_password");
std::string initial_password =
translate_password(playername, raw_default_password);
// If default_password is empty, allow any initial password
if (raw_default_password.length() == 0)
initial_password = given_password;
m_script->createAuth(playername, initial_password);
}
has_auth = m_script->getAuth(playername, &checkpwd, NULL);
if (!has_auth) {
actionstream << "Server: " << playername << " cannot be authenticated"
<< " (auth handler does not work?)" << std::endl;
DenyAccess_Legacy(pkt->getPeerId(), L"Not allowed to login");
return;
}
if (given_password != checkpwd) {
actionstream << "Server: User " << playername
<< " at " << addr_s
<< " supplied wrong password (auth mechanism: legacy)."
<< std::endl;
DenyAccess_Legacy(pkt->getPeerId(), L"Wrong password");
return;
}
RemotePlayer *player =
static_cast<RemotePlayer*>(m_env->getPlayer(playername));
if (player && player->peer_id != 0) {
actionstream << "Server: " << playername << ": Failed to emerge player"
<< " (player allocated to an another client)" << std::endl;
DenyAccess_Legacy(pkt->getPeerId(), L"Another client is connected with this "
L"name. If your client closed unexpectedly, try again in "
L"a minute.");
}
m_clients.setPlayerName(pkt->getPeerId(), playername);
/*
Answer with a TOCLIENT_INIT
*/
NetworkPacket resp_pkt(TOCLIENT_INIT_LEGACY, 1 + 6 + 8 + 4,
pkt->getPeerId());
resp_pkt << (u8) deployed << (v3s16) floatToInt(v3f(0,0,0), BS)
<< (u64) m_env->getServerMap().getSeed()
<< g_settings->getFloat("dedicated_server_step");
Send(&resp_pkt);
m_clients.event(pkt->getPeerId(), CSE_InitLegacy);
}
void Server::handleCommand_Init2(NetworkPacket* pkt)
{
verbosestream << "Server: Got TOSERVER_INIT2 from "
@ -765,7 +438,7 @@ void Server::handleCommand_GotBlocks(NetworkPacket* pkt)
void Server::process_PlayerPos(RemotePlayer *player, PlayerSAO *playersao,
NetworkPacket *pkt)
{
if (pkt->getRemainingBytes() < 12 + 12 + 4 + 4)
if (pkt->getRemainingBytes() < 12 + 12 + 4 + 4 + 4 + 1 + 1)
return;
v3s32 ps, ss;
@ -785,14 +458,10 @@ void Server::process_PlayerPos(RemotePlayer *player, PlayerSAO *playersao,
f32 fov = 0;
u8 wanted_range = 0;
if (pkt->getRemainingBytes() >= 4)
*pkt >> keyPressed;
if (pkt->getRemainingBytes() >= 1) {
*pkt >> f32fov;
fov = (f32)f32fov / 80.0f;
}
if (pkt->getRemainingBytes() >= 1)
*pkt >> wanted_range;
*pkt >> keyPressed;
*pkt >> f32fov;
fov = (f32)f32fov / 80.0f;
*pkt >> wanted_range;
v3f position((f32)ps.X / 100.0f, (f32)ps.Y / 100.0f, (f32)ps.Z / 100.0f);
v3f speed((f32)ss.X / 100.0f, (f32)ss.Y / 100.0f, (f32)ss.Z / 100.0f);
@ -1909,8 +1578,7 @@ void Server::handleCommand_SrpBytesA(NetworkPacket* pkt)
<< "based_on=" << int(based_on) << " and len_A="
<< bytes_A.length() << "." << std::endl;
AuthMechanism chosen = (based_on == 0) ?
AUTH_MECHANISM_LEGACY_PASSWORD : AUTH_MECHANISM_SRP;
AuthMechanism chosen = AUTH_MECHANISM_SRP;
if (wantSudo) {
if (!client->isSudoMechAllowed(chosen)) {
@ -1985,7 +1653,7 @@ void Server::handleCommand_SrpBytesM(NetworkPacket* pkt)
bool wantSudo = (cstate == CS_Active);
verbosestream << "Server: Recieved TOCLIENT_SRP_BYTES_M." << std::endl;
verbosestream << "Server: Received TOCLIENT_SRP_BYTES_M." << std::endl;
if (!((cstate == CS_HelloSent) || (cstate == CS_Active))) {
actionstream << "Server: got SRP _M packet in wrong state "
@ -1995,8 +1663,7 @@ void Server::handleCommand_SrpBytesM(NetworkPacket* pkt)
return;
}
if ((client->chosen_mech != AUTH_MECHANISM_SRP)
&& (client->chosen_mech != AUTH_MECHANISM_LEGACY_PASSWORD)) {
if (client->chosen_mech != AUTH_MECHANISM_SRP) {
actionstream << "Server: got SRP _M packet, while auth"
<< "is going on with mech " << client->chosen_mech
<< " from " << getPeerAddress(pkt->getPeerId()).serializeString()