Skip to content

Commit

Permalink
Fix n-ice login
Browse files Browse the repository at this point in the history
* Fault: creation of md5salt from given password

* Fix: Use Md5 new interface, and fmt

* Fix: visual studio include error

---------

Co-authored-by: Miguel Horta <[email protected]>
  • Loading branch information
AdminChucky and MiguelHorta authored Apr 20, 2024
1 parent 35cbdf8 commit dc9e1d5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
22 changes: 19 additions & 3 deletions src/citymania/cm_commands_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Check warning on line 40 in src/citymania/cm_commands_gui.cpp

View workflow job for this annotation

GitHub Actions / Mac OS (arm64)

unused variable 'NOVAPOLIS_STRING' [-Wunused-const-variable]

Check warning on line 40 in src/citymania/cm_commands_gui.cpp

View workflow job for this annotation

GitHub Actions / Emscripten

unused variable 'NOVAPOLIS_STRING' [-Wunused-const-variable]

Check warning on line 40 in src/citymania/cm_commands_gui.cpp

View workflow job for this annotation

GitHub Actions / Linux (Clang - Debug)

unused variable 'NOVAPOLIS_STRING' [-Wunused-const-variable]

Check warning on line 40 in src/citymania/cm_commands_gui.cpp

View workflow job for this annotation

GitHub Actions / Linux (Clang - Release)

unused variable 'NOVAPOLIS_STRING' [-Wunused-const-variable]
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[] = {

Check warning on line 44 in src/citymania/cm_commands_gui.cpp

View workflow job for this annotation

GitHub Actions / Mac OS (arm64)

unused variable 'NOVA_IP_ADDRESSES' [-Wunused-const-variable]

Check warning on line 44 in src/citymania/cm_commands_gui.cpp

View workflow job for this annotation

GitHub Actions / Emscripten

unused variable 'NOVA_IP_ADDRESSES' [-Wunused-const-variable]

Check warning on line 44 in src/citymania/cm_commands_gui.cpp

View workflow job for this annotation

GitHub Actions / Linux (Clang - Debug)

unused variable 'NOVA_IP_ADDRESSES' [-Wunused-const-variable]

Check warning on line 44 in src/citymania/cm_commands_gui.cpp

View workflow job for this annotation

GitHub Actions / Linux (Clang - Release)

unused variable 'NOVA_IP_ADDRESSES' [-Wunused-const-variable]
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down
16 changes: 8 additions & 8 deletions src/citymania/generated/cm_gen_commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down

0 comments on commit dc9e1d5

Please sign in to comment.