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

Also remove the setting 'send_pre_v25_init'
Keep old enum entries for obsolete commands
master
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

@ -773,12 +773,6 @@ address (Server address) string
# Note that the port field in the main menu overrides this setting.
remote_port (Remote port) int 30000 1 65535
# Whether to support older servers before protocol version 25.
# Enable if you want to connect to 0.4.12 servers and before.
# Servers starting with 0.4.13 will work, 0.4.12-dev servers may work.
# Disabling this option will protect your password better.
send_pre_v25_init (Support older servers) bool false
# Save the map received by the client on disk.
enable_local_map_saving (Saving map received from server) bool false

View File

@ -933,13 +933,6 @@
# type: int min: 1 max: 65535
# remote_port = 30000
# Whether to support older servers before protocol version 25.
# Enable if you want to connect to 0.4.12 servers and before.
# Servers starting with 0.4.13 will work, 0.4.12-dev servers may work.
# Disabling this option will protect your password better.
# type: bool
# send_pre_v25_init = false
# Save the map received by the client on disk.
# type: bool
# enable_local_map_saving = false

View File

@ -309,31 +309,7 @@ void Client::step(float dtime)
LocalPlayer *myplayer = m_env.getLocalPlayer();
FATAL_ERROR_IF(myplayer == NULL, "Local player not found in environment.");
u16 proto_version_min = g_settings->getFlag("send_pre_v25_init") ?
CLIENT_PROTOCOL_VERSION_MIN_LEGACY : CLIENT_PROTOCOL_VERSION_MIN;
if (proto_version_min < 25) {
// Send TOSERVER_INIT_LEGACY
// [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)
char pName[PLAYERNAME_SIZE];
char pPassword[PASSWORD_SIZE];
memset(pName, 0, PLAYERNAME_SIZE * sizeof(char));
memset(pPassword, 0, PASSWORD_SIZE * sizeof(char));
std::string hashed_password = translate_password(myplayer->getName(), m_password);
snprintf(pName, PLAYERNAME_SIZE, "%s", myplayer->getName());
snprintf(pPassword, PASSWORD_SIZE, "%s", hashed_password.c_str());
sendLegacyInit(pName, pPassword);
}
if (CLIENT_PROTOCOL_VERSION_MAX >= 25)
sendInit(myplayer->getName());
sendInit(myplayer->getName());
}
// Not connected, return
@ -428,11 +404,6 @@ void Client::step(float dtime)
m_client_event_queue.push(event);
}
}
// Protocol v29 or greater obsoleted this event
else if (envEvent.type == CEE_PLAYER_BREATH && m_proto_ver < 29) {
u16 breath = envEvent.player_breath.amount;
sendBreath(breath);
}
}
/*
@ -949,10 +920,10 @@ void Client::deleteAuthData()
case AUTH_MECHANISM_FIRST_SRP:
break;
case AUTH_MECHANISM_SRP:
case AUTH_MECHANISM_LEGACY_PASSWORD:
srp_user_delete((SRPUser *) m_auth_data);
m_auth_data = NULL;
break;
case AUTH_MECHANISM_LEGACY_PASSWORD:
case AUTH_MECHANISM_NONE:
break;
}
@ -968,28 +939,9 @@ AuthMechanism Client::choseAuthMech(const u32 mechs)
if (mechs & AUTH_MECHANISM_FIRST_SRP)
return AUTH_MECHANISM_FIRST_SRP;
if (mechs & AUTH_MECHANISM_LEGACY_PASSWORD)
return AUTH_MECHANISM_LEGACY_PASSWORD;
return AUTH_MECHANISM_NONE;
}
void Client::sendLegacyInit(const char* playerName, const char* playerPassword)
{
NetworkPacket pkt(TOSERVER_INIT_LEGACY,
1 + PLAYERNAME_SIZE + PASSWORD_SIZE + 2 + 2);
u16 proto_version_min = g_settings->getFlag("send_pre_v25_init") ?
CLIENT_PROTOCOL_VERSION_MIN_LEGACY : CLIENT_PROTOCOL_VERSION_MIN;
pkt << (u8) SER_FMT_VER_HIGHEST_READ;
pkt.putRawString(playerName,PLAYERNAME_SIZE);
pkt.putRawString(playerPassword, PASSWORD_SIZE);
pkt << (u16) proto_version_min << (u16) CLIENT_PROTOCOL_VERSION_MAX;
Send(&pkt);
}
void Client::sendInit(const std::string &playerName)
{
NetworkPacket pkt(TOSERVER_INIT, 1 + 2 + 2 + (1 + playerName.size()));
@ -997,11 +949,8 @@ void Client::sendInit(const std::string &playerName)
// we don't support network compression yet
u16 supp_comp_modes = NETPROTO_COMPRESSION_NONE;
u16 proto_version_min = g_settings->getFlag("send_pre_v25_init") ?
CLIENT_PROTOCOL_VERSION_MIN_LEGACY : CLIENT_PROTOCOL_VERSION_MIN;
pkt << (u8) SER_FMT_VER_HIGHEST_READ << (u16) supp_comp_modes;
pkt << (u16) proto_version_min << (u16) CLIENT_PROTOCOL_VERSION_MAX;
pkt << (u16) CLIENT_PROTOCOL_VERSION_MIN << (u16) CLIENT_PROTOCOL_VERSION_MAX;
pkt << playerName;
Send(&pkt);
@ -1025,14 +974,8 @@ void Client::startAuth(AuthMechanism chosen_auth_mechanism)
Send(&resp_pkt);
break;
}
case AUTH_MECHANISM_SRP:
case AUTH_MECHANISM_LEGACY_PASSWORD: {
u8 based_on = 1;
if (chosen_auth_mechanism == AUTH_MECHANISM_LEGACY_PASSWORD) {
m_password = translate_password(getPlayerName(), m_password);
based_on = 0;
}
case AUTH_MECHANISM_SRP: {
u8 legacy_based_on = 1;
std::string playername_u = lowercase(getPlayerName());
m_auth_data = srp_user_new(SRP_SHA256, SRP_NG_2048,
@ -1047,10 +990,11 @@ void Client::startAuth(AuthMechanism chosen_auth_mechanism)
FATAL_ERROR_IF(res != SRP_OK, "Creating local SRP user failed.");
NetworkPacket resp_pkt(TOSERVER_SRP_BYTES_A, 0);
resp_pkt << std::string(bytes_A, len_A) << based_on;
resp_pkt << std::string(bytes_A, len_A) << legacy_based_on;
Send(&resp_pkt);
break;
}
case AUTH_MECHANISM_LEGACY_PASSWORD:
case AUTH_MECHANISM_NONE:
break; // not handled in this method
}
@ -1201,27 +1145,10 @@ void Client::sendChangePassword(const std::string &oldpassword,
if (player == NULL)
return;
std::string playername = player->getName();
if (m_proto_ver >= 25) {
// get into sudo mode and then send new password to server
m_password = oldpassword;
m_new_password = newpassword;
startAuth(choseAuthMech(m_sudo_auth_methods));
} else {
std::string oldpwd = translate_password(playername, oldpassword);
std::string newpwd = translate_password(playername, newpassword);
NetworkPacket pkt(TOSERVER_PASSWORD_LEGACY, 2 * PASSWORD_SIZE);
for (u8 i = 0; i < PASSWORD_SIZE; i++) {
pkt << (u8) (i < oldpwd.length() ? oldpwd[i] : 0);
}
for (u8 i = 0; i < PASSWORD_SIZE; i++) {
pkt << (u8) (i < newpwd.length() ? newpwd[i] : 0);
}
Send(&pkt);
}
// get into sudo mode and then send new password to server
m_password = oldpassword;
m_new_password = newpassword;
startAuth(choseAuthMech(m_sudo_auth_methods));
}
@ -1232,17 +1159,6 @@ void Client::sendDamage(u8 damage)
Send(&pkt);
}
void Client::sendBreath(u16 breath)
{
// Protocol v29 make this obsolete
if (m_proto_ver >= 29)
return;
NetworkPacket pkt(TOSERVER_BREATH, sizeof(u16));
pkt << breath;
Send(&pkt);
}
void Client::sendRespawn()
{
NetworkPacket pkt(TOSERVER_RESPAWN, 0);

View File

@ -184,7 +184,6 @@ public:
void handleCommand_AuthAccept(NetworkPacket* pkt);
void handleCommand_AcceptSudoMode(NetworkPacket* pkt);
void handleCommand_DenySudoMode(NetworkPacket* pkt);
void handleCommand_InitLegacy(NetworkPacket* pkt);
void handleCommand_AccessDenied(NetworkPacket* pkt);
void handleCommand_RemoveNode(NetworkPacket* pkt);
void handleCommand_AddNode(NetworkPacket* pkt);
@ -244,7 +243,6 @@ public:
void sendChangePassword(const std::string &oldpassword,
const std::string &newpassword);
void sendDamage(u8 damage);
void sendBreath(u16 breath);
void sendRespawn();
void sendReady();
@ -447,7 +445,6 @@ private:
// helper method shared with clientpackethandler
static AuthMechanism choseAuthMech(const u32 mechs);
void sendLegacyInit(const char* playerName, const char* playerPassword);
void sendInit(const std::string &playerName);
void startAuth(AuthMechanism chosen_auth_mechanism);
void sendDeletedBlocks(std::vector<v3s16> &blocks);

View File

@ -242,78 +242,6 @@ void ClientEnvironment::step(float dtime)
m_script->environment_step(dtime);
}
// Protocol v29 make this behaviour obsolete
if (getGameDef()->getProtoVersion() < 29) {
if (m_lava_hurt_interval.step(dtime, 1.0)) {
v3f pf = lplayer->getPosition();
// Feet, middle and head
v3s16 p1 = floatToInt(pf + v3f(0, BS * 0.1, 0), BS);
MapNode n1 = m_map->getNodeNoEx(p1);
v3s16 p2 = floatToInt(pf + v3f(0, BS * 0.8, 0), BS);
MapNode n2 = m_map->getNodeNoEx(p2);
v3s16 p3 = floatToInt(pf + v3f(0, BS * 1.6, 0), BS);
MapNode n3 = m_map->getNodeNoEx(p3);
u32 damage_per_second = 0;
damage_per_second = MYMAX(damage_per_second,
m_client->ndef()->get(n1).damage_per_second);
damage_per_second = MYMAX(damage_per_second,
m_client->ndef()->get(n2).damage_per_second);
damage_per_second = MYMAX(damage_per_second,
m_client->ndef()->get(n3).damage_per_second);
if (damage_per_second != 0)
damageLocalPlayer(damage_per_second, true);
}
/*
Drowning
*/
if (m_drowning_interval.step(dtime, 2.0)) {
v3f pf = lplayer->getPosition();
// head
v3s16 p = floatToInt(pf + v3f(0, BS * 1.6, 0), BS);
MapNode n = m_map->getNodeNoEx(p);
ContentFeatures c = m_client->ndef()->get(n);
u8 drowning_damage = c.drowning;
if (drowning_damage > 0 && lplayer->hp > 0) {
u16 breath = lplayer->getBreath();
if (breath > 10) {
breath = 11;
}
if (breath > 0) {
breath -= 1;
}
lplayer->setBreath(breath);
updateLocalPlayerBreath(breath);
}
if (lplayer->getBreath() == 0 && drowning_damage > 0) {
damageLocalPlayer(drowning_damage, true);
}
}
if (m_breathing_interval.step(dtime, 0.5)) {
v3f pf = lplayer->getPosition();
// head
v3s16 p = floatToInt(pf + v3f(0, BS * 1.6, 0), BS);
MapNode n = m_map->getNodeNoEx(p);
ContentFeatures c = m_client->ndef()->get(n);
if (!lplayer->hp) {
lplayer->setBreath(11);
} else if (c.drowning == 0) {
u16 breath = lplayer->getBreath();
if (breath <= 10) {
breath += 1;
lplayer->setBreath(breath);
updateLocalPlayerBreath(breath);
}
}
}
}
// Update lighting on local player (used for wield item)
u32 day_night_ratio = getDayNightRatio();
{

View File

@ -454,8 +454,7 @@ void RemoteClient::notifyEvent(ClientStateEvent event)
{
case CSE_AuthAccept:
m_state = CS_AwaitingInit2;
if ((chosen_mech == AUTH_MECHANISM_SRP)
|| (chosen_mech == AUTH_MECHANISM_LEGACY_PASSWORD))
if (chosen_mech == AUTH_MECHANISM_SRP)
srp_verifier_delete((SRPVerifier *) auth_data);
chosen_mech = AUTH_MECHANISM_NONE;
break;
@ -464,8 +463,7 @@ void RemoteClient::notifyEvent(ClientStateEvent event)
break;
case CSE_SetDenied:
m_state = CS_Denied;
if ((chosen_mech == AUTH_MECHANISM_SRP)
|| (chosen_mech == AUTH_MECHANISM_LEGACY_PASSWORD))
if (chosen_mech == AUTH_MECHANISM_SRP)
srp_verifier_delete((SRPVerifier *) auth_data);
chosen_mech = AUTH_MECHANISM_NONE;
break;
@ -543,8 +541,7 @@ void RemoteClient::notifyEvent(ClientStateEvent event)
break;
case CSE_SudoSuccess:
m_state = CS_SudoMode;
if ((chosen_mech == AUTH_MECHANISM_SRP)
|| (chosen_mech == AUTH_MECHANISM_LEGACY_PASSWORD))
if (chosen_mech == AUTH_MECHANISM_SRP)
srp_verifier_delete((SRPVerifier *) auth_data);
chosen_mech = AUTH_MECHANISM_NONE;
break;

View File

@ -49,30 +49,30 @@ class EmergeManager;
| |
\-----------------/
| depending of the incoming packet
+---------------------------------------
v v
+-----------------------------+ +-----------------------------+
|IN: | |IN: |
| TOSERVER_INIT_LEGACY |----- | TOSERVER_INIT | invalid playername,
+-----------------------------+ | +-----------------------------+ password (for _LEGACY),
| | | or denied by mod
| Auth ok -------------------+---------------------------------
v v |
+-----------------------------+ +-----------------------------+ |
|OUT: | |OUT: | |
| TOCLIENT_INIT_LEGACY | | TOCLIENT_HELLO | |
+-----------------------------+ +-----------------------------+ |
| | |
| | |
v v |
/-----------------\ /-----------------\ |
| | | | |
| AwaitingInit2 |<--------- | HelloSent | |
| | | | | |
\-----------------/ | \-----------------/ |
| | | |
+-----------------------------+ | *-----------------------------* Auth fails |
|IN: | | |Authentication, depending on |-----------------+
----------------------------------------
v
+-----------------------------+
|IN: |
| TOSERVER_INIT |
+-----------------------------+
| invalid playername
| or denied by mod
v
+-----------------------------+
|OUT: |
| TOCLIENT_HELLO |
+-----------------------------+
|
|
v
/-----------------\ /-----------------\
| | | |
| AwaitingInit2 |<--------- | HelloSent |
| | | | |
\-----------------/ | \-----------------/
| | |
+-----------------------------+ | *-----------------------------* Auth fails
|IN: | | |Authentication, depending on |------------------
| TOSERVER_INIT2 | | | packet sent by client | |
+-----------------------------+ | *-----------------------------* |
| | | |
@ -101,18 +101,18 @@ class EmergeManager;
| | +-----------------------------+ |
| DefinitionsSent | |IN: | |
| | | TOSERVER_REQUEST_MEDIA | |
\-----------------/ | TOSERVER_RECEIVED_MEDIA | |
\-----------------/ | | |
| +-----------------------------+ |
| ^ | |
| ----------------------------- |
v |
v v
+-----------------------------+ --------------------------------+
|IN: | | |
|IN: | | ^
| TOSERVER_CLIENT_READY | v |
+-----------------------------+ +-------------------------------+ |
| |OUT: | |
v | TOCLIENT_ACCESS_DENIED_LEGAGY | |
+-----------------------------+ +-------------------------------+ |
+-----------------------------+ +------------------------+ |
| |OUT: | |
v | TOCLIENT_ACCESS_DENIED | |
+-----------------------------+ +------------------------+ |
|OUT: | | |
| TOCLIENT_MOVE_PLAYER | v |
| TOCLIENT_PRIVILEGES | /-----------------\ |

View File

@ -49,8 +49,7 @@ void set_default_settings(Settings *settings)
settings->setDefault("screenshot_quality", "0");
settings->setDefault("client_unload_unused_data_timeout", "600");
settings->setDefault("client_mapblock_limit", "5000");
settings->setDefault("enable_build_where_you_stand", "false" );
settings->setDefault("send_pre_v25_init", "false");
settings->setDefault("enable_build_where_you_stand", "false");
settings->setDefault("curl_timeout", "5000");
settings->setDefault("curl_parallel_limit", "8");
settings->setDefault("curl_file_download_timeout", "300000");

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()

View File

@ -928,9 +928,7 @@ int ModApiMainMenu::l_get_screen_info(lua_State *L)
/******************************************************************************/
int ModApiMainMenu::l_get_min_supp_proto(lua_State *L)
{
u16 proto_version_min = g_settings->getFlag("send_pre_v25_init") ?
CLIENT_PROTOCOL_VERSION_MIN_LEGACY : CLIENT_PROTOCOL_VERSION_MIN;
lua_pushinteger(L, proto_version_min);
lua_pushinteger(L, CLIENT_PROTOCOL_VERSION_MIN);
return 1;
}

View File

@ -1534,9 +1534,6 @@ void Server::SendInventory(PlayerSAO* playerSAO)
void Server::SendChatMessage(u16 peer_id, const ChatMessage &message)
{
NetworkPacket legacypkt(TOCLIENT_CHAT_MESSAGE_OLD, 0, peer_id);
legacypkt << message.message;
NetworkPacket pkt(TOCLIENT_CHAT_MESSAGE, 0, peer_id);
u8 version = 1;
u8 type = message.type;
@ -1547,12 +1544,9 @@ void Server::SendChatMessage(u16 peer_id, const ChatMessage &message)
if (!player)
return;
if (player->protocol_version < 35)
Send(&legacypkt);
else
Send(&pkt);
Send(&pkt);
} else {
m_clients.sendToAllCompat(&pkt, &legacypkt, 35);
m_clients.sendToAll(&pkt);
}
}
@ -1668,17 +1662,15 @@ void Server::SendAddParticleSpawner(u16 peer_id, u16 protocol_version,
void Server::SendDeleteParticleSpawner(u16 peer_id, u32 id)
{
NetworkPacket pkt(TOCLIENT_DELETE_PARTICLESPAWNER_LEGACY, 2, peer_id);
NetworkPacket pkt(TOCLIENT_DELETE_PARTICLESPAWNER, 4, peer_id);
// Ugly error in this packet
pkt << (u16) id;
pkt << id;
if (peer_id != PEER_ID_INEXISTENT) {
if (peer_id != PEER_ID_INEXISTENT)
Send(&pkt);
}
else {
else
m_clients.sendToAll(&pkt);
}
}
@ -2572,14 +2564,7 @@ void Server::DenySudoAccess(u16 peer_id)
void Server::DenyAccessVerCompliant(u16 peer_id, u16 proto_ver, AccessDeniedCode reason,
const std::string &str_reason, bool reconnect)
{
if (proto_ver >= 25) {
SendAccessDenied(peer_id, reason, str_reason, reconnect);
} else {
std::wstring wreason = utf8_to_wide(
reason == SERVER_ACCESSDENIED_CUSTOM_STRING ? str_reason :
accessDeniedStrings[(u8)reason]);
SendAccessDenied_Legacy(peer_id, wreason);
}
SendAccessDenied(peer_id, reason, str_reason, reconnect);
m_clients.event(peer_id, CSE_SetDenied);
m_con->DisconnectPeer(peer_id);

View File

@ -143,7 +143,6 @@ public:
void handleCommand_Null(NetworkPacket* pkt) {};
void handleCommand_Deprecated(NetworkPacket* pkt);
void handleCommand_Init(NetworkPacket* pkt);
void handleCommand_Init_Legacy(NetworkPacket* pkt);
void handleCommand_Init2(NetworkPacket* pkt);
void handleCommand_RequestMedia(NetworkPacket* pkt);
void handleCommand_ClientReady(NetworkPacket* pkt);

View File

@ -70,8 +70,7 @@ std::vector<ServerListSpec> getOnline()
{
std::ostringstream geturl;
u16 proto_version_min = g_settings->getFlag("send_pre_v25_init") ?
CLIENT_PROTOCOL_VERSION_MIN_LEGACY : CLIENT_PROTOCOL_VERSION_MIN;
u16 proto_version_min = CLIENT_PROTOCOL_VERSION_MIN;
geturl << g_settings->get("serverlist_url") <<
"/list?proto_version_min=" << proto_version_min <<