From dc9e1d54b53188762b7fc8dec2ee3e88e1b9ab55 Mon Sep 17 00:00:00 2001 From: Chucky <65466645+AdminChucky@users.noreply.github.com> Date: Sat, 20 Apr 2024 10:20:26 +0200 Subject: [PATCH] Fix n-ice login * Fault: creation of md5salt from given password * Fix: Use Md5 new interface, and fmt * Fix: visual studio include error --------- Co-authored-by: Miguel Horta --- src/citymania/cm_commands_gui.cpp | 22 ++++++++++++++++++--- src/citymania/generated/cm_gen_commands.cpp | 16 +++++++-------- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/citymania/cm_commands_gui.cpp b/src/citymania/cm_commands_gui.cpp index 31b50a2f50..19068f7100 100644 --- a/src/citymania/cm_commands_gui.cpp +++ b/src/citymania/cm_commands_gui.cpp @@ -38,7 +38,7 @@ static const char * const NOVAPOLIS_IPV6_PRIMARY = "2a02:2b88:2:1::1d73:1"; static const char * const NOVAPOLIS_IPV4_SECONDARY = "89.111.65.225"; static const char * const NOVAPOLIS_IPV6_SECONDARY = "fe80::20e:7fff:fe23:bee0"; static const char * const NOVAPOLIS_STRING = "CityMania"; -static constexpr std::string_view NICE_HTTP_LOGIN = "http://n-ice.org/openttd/gettoken.php?user={}&password={}"; +static constexpr std::string_view NICE_HTTP_LOGIN = "http://n-ice.org/openttd/gettoken_md5salt.php?user={}&password={}"; static constexpr std::string_view BTPRO_HTTP_LOGIN = "http://openttd.btpro.nl/gettoken-enc.php?user={}&password={}"; static const char * const NOVA_IP_ADDRESSES[] = { @@ -666,7 +666,7 @@ void AccountLogin(CommunityName community){ NetworkClientSendChatToServer(fmt::format("!login {} {}", _inilogindata[NOVAPOLISUSER], _inilogindata[NOVAPOLISPW])); return; case NICE: - uri = fmt::format("http://n-ice.org/openttd/gettoken.php?user={}&password={}", GetLoginItem(NICE_LOGIN), GetLoginItem(NICE_PW)); + uri = fmt::format(NICE_HTTP_LOGIN, GetLoginItem(NICE_LOGIN), GetLoginItem(NICE_PW)); break; case BTPRO: { uri = fmt::format(BTPRO_HTTP_LOGIN, @@ -759,13 +759,29 @@ struct LoginWindow : Window { break; } case LQW_NICE_LOGIN: - case LQW_NICE_PW: case LQW_BTPRO_LOGIN: case LQW_BTPRO_PW: { auto item = urlencode(str); SetLoginItem(INI_LOGIN_KEYS[this->query_widget - 3], item); // - LWW_NICE_LOGIN + NICE_LOGIN break; } + case LQW_NICE_PW: { + Md5 password, salted_password; + MD5Hash digest; + + password.Append(str, strlen(str)); + password.Finish(digest); + auto first_pass = fmt::format("{:02x}", fmt::join(digest, "")); + + auto tobe_salted = fmt::format("nice{}client", first_pass); + salted_password.Append(tobe_salted.c_str(),tobe_salted.length()); + salted_password.Finish(digest); + auto second_pass = fmt::format("{:02x}", fmt::join(digest, "")); + + // Save the result to citymania.cfg + SetLoginItem(NICE_PW, second_pass); + break; + } default: return; } this->SetDirty(); diff --git a/src/citymania/generated/cm_gen_commands.cpp b/src/citymania/generated/cm_gen_commands.cpp index 1913792d99..315a1c1b3b 100644 --- a/src/citymania/generated/cm_gen_commands.cpp +++ b/src/citymania/generated/cm_gen_commands.cpp @@ -2,14 +2,14 @@ #include "../../stdafx.h" #include "cm_gen_commands.hpp" -#include "../../src/misc_cmd.h" -#include "../../src/object_cmd.h" -#include "../../src/order_cmd.h" -#include "../../src/rail_cmd.h" -#include "../../src/road_cmd.h" -#include "../../src/station_cmd.h" -#include "../../src/town_cmd.h" -#include "../../src/tunnelbridge_cmd.h" +#include "../../misc_cmd.h" +#include "../../object_cmd.h" +#include "../../order_cmd.h" +#include "../../rail_cmd.h" +#include "../../road_cmd.h" +#include "../../station_cmd.h" +#include "../../town_cmd.h" +#include "../../tunnelbridge_cmd.h" namespace citymania { namespace cmd {