diff --git a/Minecraft.Client/AuthScreen.cpp b/Minecraft.Client/AuthScreen.cpp index 9376b9ef..c640f0da 100644 --- a/Minecraft.Client/AuthScreen.cpp +++ b/Minecraft.Client/AuthScreen.cpp @@ -6,6 +6,7 @@ #include "..\Minecraft.World\HttpClient.h" #include "..\Minecraft.World\StringHelpers.h" #include "Common/vendor/nlohmann/json.hpp" +#include #include #include @@ -351,7 +352,7 @@ void AuthFlow::microsoftFlowThread() for (int ms = 0; ms < interval * 1000; ms += 250) { if (cancelRequested) return; - Sleep(250); + std::this_thread::sleep_for(std::chrono::milliseconds(250)); } auto pollResp = HttpClient::post( diff --git a/Minecraft.Client/ClientConnection.cpp b/Minecraft.Client/ClientConnection.cpp index b584ffb5..c85e61b2 100644 --- a/Minecraft.Client/ClientConnection.cpp +++ b/Minecraft.Client/ClientConnection.cpp @@ -4141,9 +4141,9 @@ ClientConnection::DeferredEntityLinkPacket::DeferredEntityLinkPacket(shared_ptr< void ClientConnection::beginAuth() { handshakeManager = new HandshakeManager(false); - handshakeManager->registerModule(new SessionAuthModule()); - handshakeManager->registerModule(new KeypairOfflineAuthModule()); - handshakeManager->registerModule(new OfflineAuthModule()); + handshakeManager->registerModule(std::make_unique()); + handshakeManager->registerModule(std::make_unique()); + handshakeManager->registerModule(std::make_unique()); const auto &profiles = AuthProfileManager::getProfiles(); int idx = AuthProfileManager::getSelectedIndex(); diff --git a/Minecraft.Client/PendingConnection.cpp b/Minecraft.Client/PendingConnection.cpp index 6ff5cac1..090decd3 100644 --- a/Minecraft.Client/PendingConnection.cpp +++ b/Minecraft.Client/PendingConnection.cpp @@ -413,9 +413,9 @@ void PendingConnection::initAuth() { handshakeManager = new HandshakeManager(true); if (server->authMode == "session") - handshakeManager->registerModule(new SessionAuthModule()); + handshakeManager->registerModule(std::make_unique()); else - handshakeManager->registerModule(new OfflineAuthModule()); + handshakeManager->registerModule(std::make_unique()); } void PendingConnection::handleAuth(const shared_ptr &packet) diff --git a/Minecraft.World/HandshakeManager.cpp b/Minecraft.World/HandshakeManager.cpp index 969c1a53..931a0116 100644 --- a/Minecraft.World/HandshakeManager.cpp +++ b/Minecraft.World/HandshakeManager.cpp @@ -19,15 +19,10 @@ HandshakeManager::HandshakeManager(bool isServer) { } -HandshakeManager::~HandshakeManager() +void HandshakeManager::registerModule(unique_ptr module) { - for (auto &[name, module] : modules) - delete module; -} - -void HandshakeManager::registerModule(AuthModule *module) -{ - modules[module->schemeName()] = module; + wstring name = module->schemeName(); + modules[std::move(name)] = std::move(module); } void HandshakeManager::setCredentials(const wstring &token, const wstring &uid, const wstring &username, const wstring &variation) @@ -70,7 +65,7 @@ shared_ptr HandshakeManager::handleServer(const shared_ptrsecond; + activeModule = modules.begin()->second.get(); state = HandshakeState::SCHEME_DECLARED; return makePacket(AuthStage::DECLARE_SCHEME, { {L"version", PROTOCOL_VERSION}, @@ -145,7 +140,7 @@ shared_ptr HandshakeManager::handleClient(const shared_ptrsecond; + activeModule = it->second.get(); auto variations = activeModule->supportedVariations(); if (!preferredVariation.empty() && diff --git a/Minecraft.World/HandshakeManager.h b/Minecraft.World/HandshakeManager.h index 360f53ea..716f40a3 100644 --- a/Minecraft.World/HandshakeManager.h +++ b/Minecraft.World/HandshakeManager.h @@ -28,7 +28,7 @@ class HandshakeManager private: bool isServer; HandshakeState state; - unordered_map modules; + unordered_map> modules; AuthModule *activeModule; wstring activeVariation; wstring protocolVersion; @@ -45,9 +45,9 @@ public: wstring finalUsername; HandshakeManager(bool isServer); - ~HandshakeManager(); + ~HandshakeManager() = default; - void registerModule(AuthModule *module); + void registerModule(unique_ptr module); void setCredentials(const wstring &token, const wstring &uid, const wstring &username, const wstring &variation = L""); shared_ptr handlePacket(const shared_ptr &packet); shared_ptr createInitialPacket(); diff --git a/Minecraft.World/UUID.cpp b/Minecraft.World/UUID.cpp index 381349cb..4ca8173a 100644 --- a/Minecraft.World/UUID.cpp +++ b/Minecraft.World/UUID.cpp @@ -2,6 +2,7 @@ #include "UUID.h" #include "Random.h" #include +#include static void sha1_block(uint32_t h[5], const uint8_t block[64]) { uint32_t w[80]; @@ -119,15 +120,12 @@ GameUUID GameUUID::v4(uint64_t high, uint64_t low) GameUUID GameUUID::v5(const GameUUID& ns, const std::string& name) { - uint8_t input[256]; - ns.toBytes(input); - size_t total = 16 + name.size(); - // names over 240 chars would be insane but just in case - if (name.size() <= sizeof(input) - 16) - memcpy(input + 16, name.data(), name.size()); + std::vector input(16 + name.size()); + ns.toBytes(input.data()); + memcpy(input.data() + 16, name.data(), name.size()); uint8_t hash[20]; - sha1(input, total, hash); + sha1(input.data(), input.size(), hash); GameUUID u = fromBytes(hash); u.msb = (u.msb & ~0xF000ULL) | 0x5000ULL; u.lsb = (u.lsb & ~0xC000000000000000ULL) | 0x8000000000000000ULL;