Skip to content
Permalink
Browse files

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

Also remove the setting 'send_pre_v25_init'
Keep old enum entries for obsolete commands
  • Loading branch information...
SmallJoker committed Sep 12, 2017
1 parent 7f2a19d commit ee9a442ecc26f2623a1b085344d37636342973eb
@@ -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

@@ -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
@@ -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,40 +939,18 @@ 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()));

// 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);
@@ -184,7 +184,6 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
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 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
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 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
// 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);
@@ -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();
{
@@ -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;
Oops, something went wrong.

0 comments on commit ee9a442

Please sign in to comment.
You can’t perform that action at this time.