Skip to content

Commit ee9a442

Browse files
authoredSep 12, 2017
Network: Remove large parts of deprecated legacy code (#6404)
Also remove the setting 'send_pre_v25_init' Keep old enum entries for obsolete commands
1 parent 7f2a19d commit ee9a442

17 files changed

+143
-882
lines changed
 

Diff for: ‎builtin/settingtypes.txt

-6
Original file line numberDiff line numberDiff line change
@@ -773,12 +773,6 @@ address (Server address) string
773773
# Note that the port field in the main menu overrides this setting.
774774
remote_port (Remote port) int 30000 1 65535
775775

776-
# Whether to support older servers before protocol version 25.
777-
# Enable if you want to connect to 0.4.12 servers and before.
778-
# Servers starting with 0.4.13 will work, 0.4.12-dev servers may work.
779-
# Disabling this option will protect your password better.
780-
send_pre_v25_init (Support older servers) bool false
781-
782776
# Save the map received by the client on disk.
783777
enable_local_map_saving (Saving map received from server) bool false
784778

Diff for: ‎minetest.conf.example

-7
Original file line numberDiff line numberDiff line change
@@ -933,13 +933,6 @@
933933
# type: int min: 1 max: 65535
934934
# remote_port = 30000
935935

936-
# Whether to support older servers before protocol version 25.
937-
# Enable if you want to connect to 0.4.12 servers and before.
938-
# Servers starting with 0.4.13 will work, 0.4.12-dev servers may work.
939-
# Disabling this option will protect your password better.
940-
# type: bool
941-
# send_pre_v25_init = false
942-
943936
# Save the map received by the client on disk.
944937
# type: bool
945938
# enable_local_map_saving = false

Diff for: ‎src/client.cpp

+11-95
Original file line numberDiff line numberDiff line change
@@ -309,31 +309,7 @@ void Client::step(float dtime)
309309
LocalPlayer *myplayer = m_env.getLocalPlayer();
310310
FATAL_ERROR_IF(myplayer == NULL, "Local player not found in environment.");
311311

312-
u16 proto_version_min = g_settings->getFlag("send_pre_v25_init") ?
313-
CLIENT_PROTOCOL_VERSION_MIN_LEGACY : CLIENT_PROTOCOL_VERSION_MIN;
314-
315-
if (proto_version_min < 25) {
316-
// Send TOSERVER_INIT_LEGACY
317-
// [0] u16 TOSERVER_INIT_LEGACY
318-
// [2] u8 SER_FMT_VER_HIGHEST_READ
319-
// [3] u8[20] player_name
320-
// [23] u8[28] password (new in some version)
321-
// [51] u16 minimum supported network protocol version (added sometime)
322-
// [53] u16 maximum supported network protocol version (added later than the previous one)
323-
324-
char pName[PLAYERNAME_SIZE];
325-
char pPassword[PASSWORD_SIZE];
326-
memset(pName, 0, PLAYERNAME_SIZE * sizeof(char));
327-
memset(pPassword, 0, PASSWORD_SIZE * sizeof(char));
328-
329-
std::string hashed_password = translate_password(myplayer->getName(), m_password);
330-
snprintf(pName, PLAYERNAME_SIZE, "%s", myplayer->getName());
331-
snprintf(pPassword, PASSWORD_SIZE, "%s", hashed_password.c_str());
332-
333-
sendLegacyInit(pName, pPassword);
334-
}
335-
if (CLIENT_PROTOCOL_VERSION_MAX >= 25)
336-
sendInit(myplayer->getName());
312+
sendInit(myplayer->getName());
337313
}
338314

339315
// Not connected, return
@@ -428,11 +404,6 @@ void Client::step(float dtime)
428404
m_client_event_queue.push(event);
429405
}
430406
}
431-
// Protocol v29 or greater obsoleted this event
432-
else if (envEvent.type == CEE_PLAYER_BREATH && m_proto_ver < 29) {
433-
u16 breath = envEvent.player_breath.amount;
434-
sendBreath(breath);
435-
}
436407
}
437408

438409
/*
@@ -949,10 +920,10 @@ void Client::deleteAuthData()
949920
case AUTH_MECHANISM_FIRST_SRP:
950921
break;
951922
case AUTH_MECHANISM_SRP:
952-
case AUTH_MECHANISM_LEGACY_PASSWORD:
953923
srp_user_delete((SRPUser *) m_auth_data);
954924
m_auth_data = NULL;
955925
break;
926+
case AUTH_MECHANISM_LEGACY_PASSWORD:
956927
case AUTH_MECHANISM_NONE:
957928
break;
958929
}
@@ -968,40 +939,18 @@ AuthMechanism Client::choseAuthMech(const u32 mechs)
968939
if (mechs & AUTH_MECHANISM_FIRST_SRP)
969940
return AUTH_MECHANISM_FIRST_SRP;
970941

971-
if (mechs & AUTH_MECHANISM_LEGACY_PASSWORD)
972-
return AUTH_MECHANISM_LEGACY_PASSWORD;
973-
974942
return AUTH_MECHANISM_NONE;
975943
}
976944

977-
void Client::sendLegacyInit(const char* playerName, const char* playerPassword)
978-
{
979-
NetworkPacket pkt(TOSERVER_INIT_LEGACY,
980-
1 + PLAYERNAME_SIZE + PASSWORD_SIZE + 2 + 2);
981-
982-
u16 proto_version_min = g_settings->getFlag("send_pre_v25_init") ?
983-
CLIENT_PROTOCOL_VERSION_MIN_LEGACY : CLIENT_PROTOCOL_VERSION_MIN;
984-
985-
pkt << (u8) SER_FMT_VER_HIGHEST_READ;
986-
pkt.putRawString(playerName,PLAYERNAME_SIZE);
987-
pkt.putRawString(playerPassword, PASSWORD_SIZE);
988-
pkt << (u16) proto_version_min << (u16) CLIENT_PROTOCOL_VERSION_MAX;
989-
990-
Send(&pkt);
991-
}
992-
993945
void Client::sendInit(const std::string &playerName)
994946
{
995947
NetworkPacket pkt(TOSERVER_INIT, 1 + 2 + 2 + (1 + playerName.size()));
996948

997949
// we don't support network compression yet
998950
u16 supp_comp_modes = NETPROTO_COMPRESSION_NONE;
999951

1000-
u16 proto_version_min = g_settings->getFlag("send_pre_v25_init") ?
1001-
CLIENT_PROTOCOL_VERSION_MIN_LEGACY : CLIENT_PROTOCOL_VERSION_MIN;
1002-
1003952
pkt << (u8) SER_FMT_VER_HIGHEST_READ << (u16) supp_comp_modes;
1004-
pkt << (u16) proto_version_min << (u16) CLIENT_PROTOCOL_VERSION_MAX;
953+
pkt << (u16) CLIENT_PROTOCOL_VERSION_MIN << (u16) CLIENT_PROTOCOL_VERSION_MAX;
1005954
pkt << playerName;
1006955

1007956
Send(&pkt);
@@ -1025,14 +974,8 @@ void Client::startAuth(AuthMechanism chosen_auth_mechanism)
1025974
Send(&resp_pkt);
1026975
break;
1027976
}
1028-
case AUTH_MECHANISM_SRP:
1029-
case AUTH_MECHANISM_LEGACY_PASSWORD: {
1030-
u8 based_on = 1;
1031-
1032-
if (chosen_auth_mechanism == AUTH_MECHANISM_LEGACY_PASSWORD) {
1033-
m_password = translate_password(getPlayerName(), m_password);
1034-
based_on = 0;
1035-
}
977+
case AUTH_MECHANISM_SRP: {
978+
u8 legacy_based_on = 1;
1036979

1037980
std::string playername_u = lowercase(getPlayerName());
1038981
m_auth_data = srp_user_new(SRP_SHA256, SRP_NG_2048,
@@ -1047,10 +990,11 @@ void Client::startAuth(AuthMechanism chosen_auth_mechanism)
1047990
FATAL_ERROR_IF(res != SRP_OK, "Creating local SRP user failed.");
1048991

1049992
NetworkPacket resp_pkt(TOSERVER_SRP_BYTES_A, 0);
1050-
resp_pkt << std::string(bytes_A, len_A) << based_on;
993+
resp_pkt << std::string(bytes_A, len_A) << legacy_based_on;
1051994
Send(&resp_pkt);
1052995
break;
1053996
}
997+
case AUTH_MECHANISM_LEGACY_PASSWORD:
1054998
case AUTH_MECHANISM_NONE:
1055999
break; // not handled in this method
10561000
}
@@ -1201,27 +1145,10 @@ void Client::sendChangePassword(const std::string &oldpassword,
12011145
if (player == NULL)
12021146
return;
12031147

1204-
std::string playername = player->getName();
1205-
if (m_proto_ver >= 25) {
1206-
// get into sudo mode and then send new password to server
1207-
m_password = oldpassword;
1208-
m_new_password = newpassword;
1209-
startAuth(choseAuthMech(m_sudo_auth_methods));
1210-
} else {
1211-
std::string oldpwd = translate_password(playername, oldpassword);
1212-
std::string newpwd = translate_password(playername, newpassword);
1213-
1214-
NetworkPacket pkt(TOSERVER_PASSWORD_LEGACY, 2 * PASSWORD_SIZE);
1215-
1216-
for (u8 i = 0; i < PASSWORD_SIZE; i++) {
1217-
pkt << (u8) (i < oldpwd.length() ? oldpwd[i] : 0);
1218-
}
1219-
1220-
for (u8 i = 0; i < PASSWORD_SIZE; i++) {
1221-
pkt << (u8) (i < newpwd.length() ? newpwd[i] : 0);
1222-
}
1223-
Send(&pkt);
1224-
}
1148+
// get into sudo mode and then send new password to server
1149+
m_password = oldpassword;
1150+
m_new_password = newpassword;
1151+
startAuth(choseAuthMech(m_sudo_auth_methods));
12251152
}
12261153

12271154

@@ -1232,17 +1159,6 @@ void Client::sendDamage(u8 damage)
12321159
Send(&pkt);
12331160
}
12341161

1235-
void Client::sendBreath(u16 breath)
1236-
{
1237-
// Protocol v29 make this obsolete
1238-
if (m_proto_ver >= 29)
1239-
return;
1240-
1241-
NetworkPacket pkt(TOSERVER_BREATH, sizeof(u16));
1242-
pkt << breath;
1243-
Send(&pkt);
1244-
}
1245-
12461162
void Client::sendRespawn()
12471163
{
12481164
NetworkPacket pkt(TOSERVER_RESPAWN, 0);

Diff for: ‎src/client.h

-3
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
184184
void handleCommand_AuthAccept(NetworkPacket* pkt);
185185
void handleCommand_AcceptSudoMode(NetworkPacket* pkt);
186186
void handleCommand_DenySudoMode(NetworkPacket* pkt);
187-
void handleCommand_InitLegacy(NetworkPacket* pkt);
188187
void handleCommand_AccessDenied(NetworkPacket* pkt);
189188
void handleCommand_RemoveNode(NetworkPacket* pkt);
190189
void handleCommand_AddNode(NetworkPacket* pkt);
@@ -244,7 +243,6 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
244243
void sendChangePassword(const std::string &oldpassword,
245244
const std::string &newpassword);
246245
void sendDamage(u8 damage);
247-
void sendBreath(u16 breath);
248246
void sendRespawn();
249247
void sendReady();
250248

@@ -447,7 +445,6 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
447445
// helper method shared with clientpackethandler
448446
static AuthMechanism choseAuthMech(const u32 mechs);
449447

450-
void sendLegacyInit(const char* playerName, const char* playerPassword);
451448
void sendInit(const std::string &playerName);
452449
void startAuth(AuthMechanism chosen_auth_mechanism);
453450
void sendDeletedBlocks(std::vector<v3s16> &blocks);

Diff for: ‎src/clientenvironment.cpp

-72
Original file line numberDiff line numberDiff line change
@@ -242,78 +242,6 @@ void ClientEnvironment::step(float dtime)
242242
m_script->environment_step(dtime);
243243
}
244244

245-
// Protocol v29 make this behaviour obsolete
246-
if (getGameDef()->getProtoVersion() < 29) {
247-
if (m_lava_hurt_interval.step(dtime, 1.0)) {
248-
v3f pf = lplayer->getPosition();
249-
250-
// Feet, middle and head
251-
v3s16 p1 = floatToInt(pf + v3f(0, BS * 0.1, 0), BS);
252-
MapNode n1 = m_map->getNodeNoEx(p1);
253-
v3s16 p2 = floatToInt(pf + v3f(0, BS * 0.8, 0), BS);
254-
MapNode n2 = m_map->getNodeNoEx(p2);
255-
v3s16 p3 = floatToInt(pf + v3f(0, BS * 1.6, 0), BS);
256-
MapNode n3 = m_map->getNodeNoEx(p3);
257-
258-
u32 damage_per_second = 0;
259-
damage_per_second = MYMAX(damage_per_second,
260-
m_client->ndef()->get(n1).damage_per_second);
261-
damage_per_second = MYMAX(damage_per_second,
262-
m_client->ndef()->get(n2).damage_per_second);
263-
damage_per_second = MYMAX(damage_per_second,
264-
m_client->ndef()->get(n3).damage_per_second);
265-
266-
if (damage_per_second != 0)
267-
damageLocalPlayer(damage_per_second, true);
268-
}
269-
270-
/*
271-
Drowning
272-
*/
273-
if (m_drowning_interval.step(dtime, 2.0)) {
274-
v3f pf = lplayer->getPosition();
275-
276-
// head
277-
v3s16 p = floatToInt(pf + v3f(0, BS * 1.6, 0), BS);
278-
MapNode n = m_map->getNodeNoEx(p);
279-
ContentFeatures c = m_client->ndef()->get(n);
280-
u8 drowning_damage = c.drowning;
281-
if (drowning_damage > 0 && lplayer->hp > 0) {
282-
u16 breath = lplayer->getBreath();
283-
if (breath > 10) {
284-
breath = 11;
285-
}
286-
if (breath > 0) {
287-
breath -= 1;
288-
}
289-
lplayer->setBreath(breath);
290-
updateLocalPlayerBreath(breath);
291-
}
292-
293-
if (lplayer->getBreath() == 0 && drowning_damage > 0) {
294-
damageLocalPlayer(drowning_damage, true);
295-
}
296-
}
297-
if (m_breathing_interval.step(dtime, 0.5)) {
298-
v3f pf = lplayer->getPosition();
299-
300-
// head
301-
v3s16 p = floatToInt(pf + v3f(0, BS * 1.6, 0), BS);
302-
MapNode n = m_map->getNodeNoEx(p);
303-
ContentFeatures c = m_client->ndef()->get(n);
304-
if (!lplayer->hp) {
305-
lplayer->setBreath(11);
306-
} else if (c.drowning == 0) {
307-
u16 breath = lplayer->getBreath();
308-
if (breath <= 10) {
309-
breath += 1;
310-
lplayer->setBreath(breath);
311-
updateLocalPlayerBreath(breath);
312-
}
313-
}
314-
}
315-
}
316-
317245
// Update lighting on local player (used for wield item)
318246
u32 day_night_ratio = getDayNightRatio();
319247
{

Diff for: ‎src/clientiface.cpp

+3-6
Original file line numberDiff line numberDiff line change
@@ -454,8 +454,7 @@ void RemoteClient::notifyEvent(ClientStateEvent event)
454454
{
455455
case CSE_AuthAccept:
456456
m_state = CS_AwaitingInit2;
457-
if ((chosen_mech == AUTH_MECHANISM_SRP)
458-
|| (chosen_mech == AUTH_MECHANISM_LEGACY_PASSWORD))
457+
if (chosen_mech == AUTH_MECHANISM_SRP)
459458
srp_verifier_delete((SRPVerifier *) auth_data);
460459
chosen_mech = AUTH_MECHANISM_NONE;
461460
break;
@@ -464,8 +463,7 @@ void RemoteClient::notifyEvent(ClientStateEvent event)
464463
break;
465464
case CSE_SetDenied:
466465
m_state = CS_Denied;
467-
if ((chosen_mech == AUTH_MECHANISM_SRP)
468-
|| (chosen_mech == AUTH_MECHANISM_LEGACY_PASSWORD))
466+
if (chosen_mech == AUTH_MECHANISM_SRP)
469467
srp_verifier_delete((SRPVerifier *) auth_data);
470468
chosen_mech = AUTH_MECHANISM_NONE;
471469
break;
@@ -543,8 +541,7 @@ void RemoteClient::notifyEvent(ClientStateEvent event)
543541
break;
544542
case CSE_SudoSuccess:
545543
m_state = CS_SudoMode;
546-
if ((chosen_mech == AUTH_MECHANISM_SRP)
547-
|| (chosen_mech == AUTH_MECHANISM_LEGACY_PASSWORD))
544+
if (chosen_mech == AUTH_MECHANISM_SRP)
548545
srp_verifier_delete((SRPVerifier *) auth_data);
549546
chosen_mech = AUTH_MECHANISM_NONE;
550547
break;

0 commit comments

Comments
 (0)
Please sign in to comment.