From ca6e7c11ea8a4aec3dfff90d56a718a1f4accde1 Mon Sep 17 00:00:00 2001 From: Renato Date: Tue, 5 Apr 2022 17:48:37 -0300 Subject: [PATCH 1/6] eliminating... --- src/client/game.cpp | 2 +- src/client/game.h | 2 +- src/client/protocolgame.cpp | 2 +- src/client/protocolgame.h | 2 +- src/framework/net/connection.cpp | 35 +++++++++++++++--------------- src/framework/net/connection.h | 27 ++++++++++++----------- src/framework/net/declarations.h | 4 +--- src/framework/net/protocol.cpp | 2 +- src/framework/net/protocol.h | 2 +- src/framework/net/protocolhttp.cpp | 2 +- src/framework/net/protocolhttp.h | 2 +- src/framework/net/server.cpp | 2 +- src/framework/stdext/net.cpp | 12 +++++----- 13 files changed, 47 insertions(+), 49 deletions(-) diff --git a/src/client/game.cpp b/src/client/game.cpp index 6a3577a67f..47737d0f56 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -95,7 +95,7 @@ void Game::resetGameStates() g_map.resetAwareRange(); } -void Game::processConnectionError(const boost::system::error_code& ec) +void Game::processConnectionError(const std::error_code& ec) { // connection errors only have meaning if we still have a protocol if (m_protocolGame) { diff --git a/src/client/game.h b/src/client/game.h index d667f3d246..5baf8e42b1 100644 --- a/src/client/game.h +++ b/src/client/game.h @@ -68,7 +68,7 @@ class Game void resetGameStates(); protected: - void processConnectionError(const boost::system::error_code& ec); + void processConnectionError(const std::error_code& ec); void processDisconnect(); void processPing(); void processPingBack(); diff --git a/src/client/protocolgame.cpp b/src/client/protocolgame.cpp index ced7d18eb8..97f21237c2 100644 --- a/src/client/protocolgame.cpp +++ b/src/client/protocolgame.cpp @@ -70,7 +70,7 @@ void ProtocolGame::onRecv(const InputMessagePtr& inputMessage) recv(); } -void ProtocolGame::onError(const boost::system::error_code& error) +void ProtocolGame::onError(const std::error_code& error) { g_game.processConnectionError(error); disconnect(); diff --git a/src/client/protocolgame.h b/src/client/protocolgame.h index 9d355679c8..5291ee73b5 100644 --- a/src/client/protocolgame.h +++ b/src/client/protocolgame.h @@ -126,7 +126,7 @@ class ProtocolGame : public Protocol protected: void onConnect() override; void onRecv(const InputMessagePtr& inputMessage) override; - void onError(const boost::system::error_code& error) override; + void onError(const std::error_code& error) override; friend class Game; diff --git a/src/framework/net/connection.cpp b/src/framework/net/connection.cpp index a8d089d011..21811d37ad 100644 --- a/src/framework/net/connection.cpp +++ b/src/framework/net/connection.cpp @@ -26,7 +26,6 @@ #include #include -#include asio::io_service g_ioService; std::list> Connection::m_outputStreams; @@ -84,7 +83,7 @@ void Connection::close() m_delayedWriteTimer.cancel(); if (m_socket.is_open()) { - boost::system::error_code ec; + std::error_code ec; m_socket.shutdown(asio::ip::tcp::socket::shutdown_both, ec); m_socket.close(); } @@ -105,7 +104,7 @@ void Connection::connect(const std::string& host, uint16 port, const std::functi }); m_readTimer.cancel(); - m_readTimer.expires_from_now(boost::posix_time::seconds(static_cast(READ_TIMEOUT))); + m_readTimer.expires_from_now(asio::chrono::seconds(static_cast(READ_TIMEOUT))); m_readTimer.async_wait([capture0 = asConnection()](auto&& PH1) { capture0->onTimeout(std::forward(PH1)); @@ -120,7 +119,7 @@ void Connection::internal_connect(const asio::ip::basic_resolver: }); m_readTimer.cancel(); - m_readTimer.expires_from_now(boost::posix_time::seconds(static_cast(READ_TIMEOUT))); + m_readTimer.expires_from_now(asio::chrono::seconds(static_cast(READ_TIMEOUT))); m_readTimer.async_wait([capture0 = asConnection()](auto&& PH1) { capture0->onTimeout(std::forward(PH1)); @@ -141,7 +140,7 @@ void Connection::write(uint8* buffer, size_t size) m_outputStream = std::make_shared(); m_delayedWriteTimer.cancel(); - m_delayedWriteTimer.expires_from_now(boost::posix_time::milliseconds(0)); + m_delayedWriteTimer.expires_from_now(asio::chrono::milliseconds(0)); m_delayedWriteTimer.async_wait([capture0 = asConnection()](auto&& PH1) { capture0->onCanWrite(std::forward(PH1)); @@ -169,7 +168,7 @@ void Connection::internal_write() }); m_writeTimer.cancel(); - m_writeTimer.expires_from_now(boost::posix_time::seconds(static_cast(WRITE_TIMEOUT))); + m_writeTimer.expires_from_now(asio::chrono::seconds(static_cast(WRITE_TIMEOUT))); m_writeTimer.async_wait([capture0 = asConnection()](auto&& PH1) { capture0->onTimeout(std::forward(PH1)); @@ -191,7 +190,7 @@ void Connection::read(uint16 bytes, const RecvCallback& callback) }); m_readTimer.cancel(); - m_readTimer.expires_from_now(boost::posix_time::seconds(static_cast(READ_TIMEOUT))); + m_readTimer.expires_from_now(asio::chrono::seconds(static_cast(READ_TIMEOUT))); m_readTimer.async_wait([capture0 = asConnection()](auto&& PH1) { capture0->onTimeout(std::forward(PH1)); @@ -214,7 +213,7 @@ void Connection::read_until(const std::string& what, const RecvCallback& callbac }); m_readTimer.cancel(); - m_readTimer.expires_from_now(boost::posix_time::seconds(static_cast(READ_TIMEOUT))); + m_readTimer.expires_from_now(asio::chrono::seconds(static_cast(READ_TIMEOUT))); m_readTimer.async_wait([capture0 = asConnection()](auto&& PH1) { capture0->onTimeout(std::forward(PH1)); @@ -235,14 +234,14 @@ void Connection::read_some(const RecvCallback& callback) }); m_readTimer.cancel(); - m_readTimer.expires_from_now(boost::posix_time::seconds(static_cast(READ_TIMEOUT))); + m_readTimer.expires_from_now(asio::chrono::seconds(static_cast(READ_TIMEOUT))); m_readTimer.async_wait([capture0 = asConnection()](auto&& PH1) { capture0->onTimeout(std::forward(PH1)); }); } -void Connection::onResolve(const boost::system::error_code& error, asio::ip::basic_resolver::iterator endpointIterator) +void Connection::onResolve(const std::error_code& error, asio::ip::basic_resolver::iterator endpointIterator) { m_readTimer.cancel(); @@ -255,7 +254,7 @@ void Connection::onResolve(const boost::system::error_code& error, asio::ip::bas handleError(error); } -void Connection::onConnect(const boost::system::error_code& error) +void Connection::onConnect(const std::error_code& error) { m_readTimer.cancel(); m_activityTimer.restart(); @@ -278,7 +277,7 @@ void Connection::onConnect(const boost::system::error_code& error) m_connecting = false; } -void Connection::onCanWrite(const boost::system::error_code& error) +void Connection::onCanWrite(const std::error_code& error) { m_delayedWriteTimer.cancel(); @@ -289,7 +288,7 @@ void Connection::onCanWrite(const boost::system::error_code& error) internal_write(); } -void Connection::onWrite(const boost::system::error_code& error, size_t, const std::shared_ptr& +void Connection::onWrite(const std::error_code& error, size_t, const std::shared_ptr& outputStream) { m_writeTimer.cancel(); @@ -305,7 +304,7 @@ void Connection::onWrite(const boost::system::error_code& error, size_t, const s handleError(error); } -void Connection::onRecv(const boost::system::error_code& error, size_t recvSize) +void Connection::onRecv(const std::error_code& error, size_t recvSize) { m_readTimer.cancel(); m_activityTimer.restart(); @@ -316,7 +315,7 @@ void Connection::onRecv(const boost::system::error_code& error, size_t recvSize) if (m_connected) { if (!error) { if (m_recvCallback) { - auto header = boost::asio::buffer_cast(m_inputStream.data()); + auto header = asio::buffer_cast(m_inputStream.data()); m_recvCallback((uint8*)header, recvSize); } } else @@ -327,7 +326,7 @@ void Connection::onRecv(const boost::system::error_code& error, size_t recvSize) m_inputStream.consume(recvSize); } -void Connection::onTimeout(const boost::system::error_code& error) +void Connection::onTimeout(const std::error_code& error) { if (error == asio::error::operation_aborted) return; @@ -335,7 +334,7 @@ void Connection::onTimeout(const boost::system::error_code& error) handleError(asio::error::timed_out); } -void Connection::handleError(const boost::system::error_code& error) +void Connection::handleError(const std::error_code& error) { if (error == asio::error::operation_aborted) return; @@ -349,7 +348,7 @@ void Connection::handleError(const boost::system::error_code& error) int Connection::getIp() { - boost::system::error_code error; + std::error_code error; const asio::ip::tcp::endpoint ip = m_socket.remote_endpoint(error); if (!error) return asio::detail::socket_ops::host_to_network_long(ip.address().to_v4().to_ulong()); diff --git a/src/framework/net/connection.h b/src/framework/net/connection.h index 66fcd82871..ab50150b21 100644 --- a/src/framework/net/connection.h +++ b/src/framework/net/connection.h @@ -25,10 +25,11 @@ #include #include "declarations.h" +#include class Connection : public LuaObject { - using ErrorCallback = std::function; + using ErrorCallback = std::function; using RecvCallback = std::function; enum @@ -57,7 +58,7 @@ class Connection : public LuaObject void setErrorCallback(const ErrorCallback& errorCallback) { m_errorCallback = errorCallback; } int getIp(); - boost::system::error_code getError() { return m_error; } + std::error_code getError() { return m_error; } bool isConnecting() { return m_connecting; } bool isConnected() { return m_connected; } ticks_t getElapsedTicksSinceLastRead() { return m_connected ? m_activityTimer.elapsed_millis() : -1; } @@ -67,22 +68,22 @@ class Connection : public LuaObject protected: void internal_connect(const asio::ip::basic_resolver::iterator& endpointIterator); void internal_write(); - void onResolve(const boost::system::error_code& error, asio::ip::tcp::resolver::iterator endpointIterator); - void onConnect(const boost::system::error_code& error); - void onCanWrite(const boost::system::error_code& error); - void onWrite(const boost::system::error_code& error, size_t writeSize, const std::shared_ptr& + void onResolve(const std::error_code& error, asio::ip::tcp::resolver::iterator endpointIterator); + void onConnect(const std::error_code& error); + void onCanWrite(const std::error_code& error); + void onWrite(const std::error_code& error, size_t writeSize, const std::shared_ptr& outputStream); - void onRecv(const boost::system::error_code& error, size_t recvSize); - void onTimeout(const boost::system::error_code& error); - void handleError(const boost::system::error_code& error); + void onRecv(const std::error_code& error, size_t recvSize); + void onTimeout(const std::error_code& error); + void handleError(const std::error_code& error); std::function m_connectCallback; ErrorCallback m_errorCallback; RecvCallback m_recvCallback; - asio::deadline_timer m_readTimer; - asio::deadline_timer m_writeTimer; - asio::deadline_timer m_delayedWriteTimer; + asio::basic_waitable_timer m_readTimer; + asio::basic_waitable_timer m_writeTimer; + asio::basic_waitable_timer m_delayedWriteTimer; asio::ip::tcp::resolver m_resolver; asio::ip::tcp::socket m_socket; @@ -91,7 +92,7 @@ class Connection : public LuaObject asio::streambuf m_inputStream; bool m_connected; bool m_connecting; - boost::system::error_code m_error; + std::error_code m_error; stdext::timer m_activityTimer; friend class Server; diff --git a/src/framework/net/declarations.h b/src/framework/net/declarations.h index aa051740d3..eb0dc1652f 100644 --- a/src/framework/net/declarations.h +++ b/src/framework/net/declarations.h @@ -23,10 +23,8 @@ #ifndef FRAMEWORK_NET_DECLARATIONS_H #define FRAMEWORK_NET_DECLARATIONS_H -#include #include - -namespace asio = boost::asio; +#include class InputMessage; class OutputMessage; diff --git a/src/framework/net/protocol.cpp b/src/framework/net/protocol.cpp index da9cefc256..a4aa3678fc 100644 --- a/src/framework/net/protocol.cpp +++ b/src/framework/net/protocol.cpp @@ -241,7 +241,7 @@ void Protocol::onRecv(const InputMessagePtr& inputMessage) callLuaField("onRecv", inputMessage); } -void Protocol::onError(const boost::system::error_code& err) +void Protocol::onError(const std::error_code& err) { callLuaField("onError", err.message(), err.value()); disconnect(); diff --git a/src/framework/net/protocol.h b/src/framework/net/protocol.h index 5204e23a74..b283dd1635 100644 --- a/src/framework/net/protocol.h +++ b/src/framework/net/protocol.h @@ -62,7 +62,7 @@ class Protocol : public LuaObject protected: virtual void onConnect(); virtual void onRecv(const InputMessagePtr& inputMessage); - virtual void onError(const boost::system::error_code& err); + virtual void onError(const std::error_code& err); std::array m_xteaKey; diff --git a/src/framework/net/protocolhttp.cpp b/src/framework/net/protocolhttp.cpp index c62c5f0ae0..4cb265622e 100644 --- a/src/framework/net/protocolhttp.cpp +++ b/src/framework/net/protocolhttp.cpp @@ -79,7 +79,7 @@ void ProtocolHttp::onRecv(uint8* buffer, uint16 size) callLuaField("onRecv", string); } -void ProtocolHttp::onError(const boost::system::error_code& err) +void ProtocolHttp::onError(const std::error_code& err) { callLuaField("onError", err.message(), err.value()); disconnect(); diff --git a/src/framework/net/protocolhttp.h b/src/framework/net/protocolhttp.h index edcbf74cbb..75029132cf 100644 --- a/src/framework/net/protocolhttp.h +++ b/src/framework/net/protocolhttp.h @@ -45,7 +45,7 @@ class ProtocolHttp : public LuaObject protected: void onConnect(); void onRecv(uint8* buffer, uint16 size); - void onError(const boost::system::error_code& err); + void onError(const std::error_code& err); private: ConnectionPtr m_connection; diff --git a/src/framework/net/server.cpp b/src/framework/net/server.cpp index 2335b4959e..320f3c40c4 100644 --- a/src/framework/net/server.cpp +++ b/src/framework/net/server.cpp @@ -52,7 +52,7 @@ void Server::acceptNext() const auto connection = ConnectionPtr(new Connection); connection->m_connecting = true; const auto self = static_self_cast(); - m_acceptor.async_accept(connection->m_socket, [=](const boost::system::error_code& error) { + m_acceptor.async_accept(connection->m_socket, [=](const std::error_code& error) { if (!error) { connection->m_connected = true; connection->m_connecting = false; diff --git a/src/framework/stdext/net.cpp b/src/framework/stdext/net.cpp index 3b63ca6a1e..41be947a42 100644 --- a/src/framework/stdext/net.cpp +++ b/src/framework/stdext/net.cpp @@ -21,21 +21,21 @@ */ #include "net.h" -#include +#include namespace stdext { std::string ip_to_string(uint32 ip) { - ip = boost::asio::detail::socket_ops::network_to_host_long(ip); - const auto address_v4 = boost::asio::ip::address_v4(ip); + ip = asio::detail::socket_ops::network_to_host_long(ip); + const auto address_v4 = asio::ip::address_v4(ip); return address_v4.to_string(); } uint32 string_to_ip(const std::string& string) { - const boost::asio::ip::address_v4 address_v4 = boost::asio::ip::address_v4::from_string(string); - return boost::asio::detail::socket_ops::host_to_network_long(address_v4.to_ulong()); + const asio::ip::address_v4 address_v4 = asio::ip::address_v4::from_string(string); + return asio::detail::socket_ops::host_to_network_long(address_v4.to_ulong()); } std::vector listSubnetAddresses(uint32 address, uint8 mask) @@ -44,7 +44,7 @@ namespace stdext if (mask < 32) { const uint32 bitmask = (0xFFFFFFFF >> mask); for (uint32 i = 0; i <= bitmask; i++) { - uint32 ip = boost::asio::detail::socket_ops::host_to_network_long((boost::asio::detail::socket_ops::network_to_host_long(address) & (~bitmask)) | i); + uint32 ip = asio::detail::socket_ops::host_to_network_long((asio::detail::socket_ops::network_to_host_long(address) & (~bitmask)) | i); if ((ip >> 24) != 0 && (ip >> 24) != 0xFF) list.push_back(ip); } From 03bd21cfbc25382c1230ebef31455de2acc173fe Mon Sep 17 00:00:00 2001 From: Renato Date: Tue, 5 Apr 2022 19:50:02 -0300 Subject: [PATCH 2/6] replace boost::uuid to stduuid it is necessary to remove the %AppData%/otclient folder --- src/framework/net/declarations.h | 2 +- src/framework/util/crypt.cpp | 53 +- src/framework/util/crypt.h | 7 +- src/framework/util/uuid.h | 929 +++++++++++++++++++++++++++++++ vc17/otclient.vcxproj | 1 + vc17/otclient.vcxproj.filters | 3 + 6 files changed, 969 insertions(+), 26 deletions(-) create mode 100644 src/framework/util/uuid.h diff --git a/src/framework/net/declarations.h b/src/framework/net/declarations.h index eb0dc1652f..65aa9cc630 100644 --- a/src/framework/net/declarations.h +++ b/src/framework/net/declarations.h @@ -24,7 +24,7 @@ #define FRAMEWORK_NET_DECLARATIONS_H #include -#include +#include class InputMessage; class OutputMessage; diff --git a/src/framework/util/crypt.cpp b/src/framework/util/crypt.cpp index 780e86a06d..4ce5594c4c 100644 --- a/src/framework/util/crypt.cpp +++ b/src/framework/util/crypt.cpp @@ -26,10 +26,6 @@ #include #include -#include -#include -#include - #include "framework/core/graphicalapplication.h" #ifndef USE_GMP @@ -170,44 +166,52 @@ std::string Crypt::xorCrypt(const std::string& buffer, const std::string& key) std::string Crypt::genUUID() { - boost::uuids::random_generator gen; - const boost::uuids::uuid u = gen(); - return to_string(u); + std::random_device rd; + auto seed_data = std::array {}; + std::generate(std::begin(seed_data), std::end(seed_data), std::ref(rd)); + std::seed_seq seq(std::begin(seed_data), std::end(seed_data)); + std::mt19937 generator(seq); + + return uuids::to_string(uuids::uuid_random_generator{ generator }()); } bool Crypt::setMachineUUID(std::string uuidstr) { if (uuidstr.empty()) return false; + uuidstr = _decrypt(uuidstr, false); - if (uuidstr.length() != 16) + + if (uuidstr.length() != 36) return false; - std::copy(uuidstr.begin(), uuidstr.end(), m_machineUUID.begin()); + + m_machineUUID = uuids::uuid::from_string(uuidstr).value(); + return true; } std::string Crypt::getMachineUUID() { if (m_machineUUID.is_nil()) { - boost::uuids::random_generator gen; - m_machineUUID = gen(); + std::random_device rd; + auto seed_data = std::array {}; + std::generate(std::begin(seed_data), std::end(seed_data), std::ref(rd)); + std::seed_seq seq(std::begin(seed_data), std::end(seed_data)); + std::mt19937 generator(seq); + + m_machineUUID = uuids::uuid_random_generator{ generator }(); } - return _encrypt(std::string(m_machineUUID.begin(), m_machineUUID.end()), false); + return _encrypt(uuids::to_string(m_machineUUID), false); } std::string Crypt::getCryptKey(bool useMachineUUID) { - const boost::hash uuid_hasher; - boost::uuids::uuid uuid; - if (useMachineUUID) { - uuid = m_machineUUID; - } else { - const boost::uuids::nil_generator nilgen; - uuid = nilgen(); - } - const boost::uuids::name_generator namegen(uuid); - const boost::uuids::uuid u = namegen(g_app.getCompactName() + g_platform.getCPUName() + g_platform.getOSName() + g_resources.getUserDir()); + const std::hash uuid_hasher; + const uuids::uuid uuid = useMachineUUID ? m_machineUUID : uuids::uuid(); + const uuids::uuid u = uuids::uuid_name_generator(uuid) + (g_app.getCompactName() + g_platform.getCPUName() + g_platform.getOSName() + g_resources.getUserDir()); const std::size_t hash = uuid_hasher(u); + std::string key; key.assign((const char*)&hash, sizeof(hash)); return key; @@ -215,8 +219,10 @@ std::string Crypt::getCryptKey(bool useMachineUUID) std::string Crypt::_encrypt(const std::string& decrypted_string, bool useMachineUUID) { - std::string tmp = "0000" + decrypted_string; const uint32 sum = stdext::adler32((const uint8*)decrypted_string.c_str(), decrypted_string.size()); + + std::string tmp = "0000" + decrypted_string; + stdext::writeULE32((uint8*)&tmp[0], sum); std::string encrypted = base64Encode(xorCrypt(tmp, getCryptKey(useMachineUUID))); return encrypted; @@ -226,6 +232,7 @@ std::string Crypt::_decrypt(const std::string& encrypted_string, bool useMachine { const std::string decoded = base64Decode(encrypted_string); const std::string tmp = xorCrypt(decoded, getCryptKey(useMachineUUID)); + if (tmp.length() >= 4) { const uint32 readsum = stdext::readULE32((const uint8*)tmp.c_str()); std::string decrypted_string = tmp.substr(4); diff --git a/src/framework/util/crypt.h b/src/framework/util/crypt.h index 1dc76b4268..684eb7213d 100644 --- a/src/framework/util/crypt.h +++ b/src/framework/util/crypt.h @@ -25,7 +25,8 @@ #include -#include +#include "uuid.h" + #ifdef USE_GMP #include #else @@ -57,7 +58,9 @@ class Crypt std::string _encrypt(const std::string& decrypted_string, bool useMachineUUID); std::string _decrypt(const std::string& encrypted_string, bool useMachineUUID); std::string getCryptKey(bool useMachineUUID); - boost::uuids::uuid m_machineUUID; + + uuids::uuid m_machineUUID; + #ifdef USE_GMP mpz_t m_p, m_q, m_n, m_e, m_d; #else diff --git a/src/framework/util/uuid.h b/src/framework/util/uuid.h new file mode 100644 index 0000000000..07a81b513f --- /dev/null +++ b/src/framework/util/uuid.h @@ -0,0 +1,929 @@ +/* + * Copyright (c) 2022 STDUUID V1.2.2 (Rev:191) + */ + +#ifndef STDUUID_H +#define STDUUID_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef _WIN32 + +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif +#ifndef NOMINMAX +#define NOMINMAX +#endif + +#ifdef UUID_SYSTEM_GENERATOR +#include +#endif + +#ifdef UUID_TIME_GENERATOR +#include +#pragma comment(lib, "IPHLPAPI.lib") +#endif + +#elif defined(__linux__) || defined(__unix__) + +#ifdef UUID_SYSTEM_GENERATOR +#include +#endif + +#elif defined(__APPLE__) + +#ifdef UUID_SYSTEM_GENERATOR +#include +#endif + +#endif + +namespace uuids +{ +#ifdef __cpp_lib_span + template + using span = std::span; +#else + template + using span = gsl::span; +#endif + + namespace detail + { + template + constexpr inline unsigned char hex2char(TChar const ch) + { + if (ch >= static_cast('0') && ch <= static_cast('9')) + return static_cast(ch - static_cast('0')); + if (ch >= static_cast('a') && ch <= static_cast('f')) + return static_cast(10 + ch - static_cast('a')); + if (ch >= static_cast('A') && ch <= static_cast('F')) + return static_cast(10 + ch - static_cast('A')); + return 0; + } + + template + constexpr inline bool is_hex(TChar const ch) + { + return + (ch >= static_cast('0') && ch <= static_cast('9')) || + (ch >= static_cast('a') && ch <= static_cast('f')) || + (ch >= static_cast('A') && ch <= static_cast('F')); + } + + template + constexpr std::basic_string_view to_string_view(TChar const* str) + { + if (str) return str; + return {}; + } + + template + constexpr std::basic_string_view< + typename StringType::value_type, + typename StringType::traits_type> + to_string_view(StringType const& str) + { + return str; + } + + class sha1 + { + public: + using digest32_t = uint32_t[5]; + using digest8_t = uint8_t[20]; + + static constexpr unsigned int block_bytes = 64; + + inline static uint32_t left_rotate(uint32_t value, size_t const count) + { + return (value << count) ^ (value >> (32 - count)); + } + + sha1() { reset(); } + + void reset() + { + m_digest[0] = 0x67452301; + m_digest[1] = 0xEFCDAB89; + m_digest[2] = 0x98BADCFE; + m_digest[3] = 0x10325476; + m_digest[4] = 0xC3D2E1F0; + m_blockByteIndex = 0; + m_byteCount = 0; + } + + void process_byte(uint8_t octet) + { + this->m_block[this->m_blockByteIndex++] = octet; + ++this->m_byteCount; + if (m_blockByteIndex == block_bytes) { + this->m_blockByteIndex = 0; + process_block(); + } + } + + void process_block(void const* const start, void const* const end) + { + const uint8_t* begin = static_cast(start); + const uint8_t* finish = static_cast(end); + while (begin != finish) { + process_byte(*begin); + begin++; + } + } + + void process_bytes(void const* const data, size_t const len) + { + const uint8_t* block = static_cast(data); + process_block(block, block + len); + } + + uint32_t const* get_digest(digest32_t digest) + { + size_t const bitCount = this->m_byteCount * 8; + process_byte(0x80); + if (this->m_blockByteIndex > 56) { + while (m_blockByteIndex != 0) { + process_byte(0); + } + while (m_blockByteIndex < 56) { + process_byte(0); + } + } else { + while (m_blockByteIndex < 56) { + process_byte(0); + } + } + process_byte(0); + process_byte(0); + process_byte(0); + process_byte(0); + process_byte(static_cast((bitCount >> 24) & 0xFF)); + process_byte(static_cast((bitCount >> 16) & 0xFF)); + process_byte(static_cast((bitCount >> 8) & 0xFF)); + process_byte(static_cast((bitCount) & 0xFF)); + + memcpy(digest, m_digest, 5 * sizeof(uint32_t)); + return digest; + } + + uint8_t const* get_digest_bytes(digest8_t digest) + { + digest32_t d32; + get_digest(d32); + size_t di = 0; + digest[di++] = static_cast(d32[0] >> 24); + digest[di++] = static_cast(d32[0] >> 16); + digest[di++] = static_cast(d32[0] >> 8); + digest[di++] = static_cast(d32[0] >> 0); + + digest[di++] = static_cast(d32[1] >> 24); + digest[di++] = static_cast(d32[1] >> 16); + digest[di++] = static_cast(d32[1] >> 8); + digest[di++] = static_cast(d32[1] >> 0); + + digest[di++] = static_cast(d32[2] >> 24); + digest[di++] = static_cast(d32[2] >> 16); + digest[di++] = static_cast(d32[2] >> 8); + digest[di++] = static_cast(d32[2] >> 0); + + digest[di++] = static_cast(d32[3] >> 24); + digest[di++] = static_cast(d32[3] >> 16); + digest[di++] = static_cast(d32[3] >> 8); + digest[di++] = static_cast(d32[3] >> 0); + + digest[di++] = static_cast(d32[4] >> 24); + digest[di++] = static_cast(d32[4] >> 16); + digest[di++] = static_cast(d32[4] >> 8); + digest[di++] = static_cast(d32[4] >> 0); + + return digest; + } + + private: + void process_block() + { + uint32_t w[80]; + for (size_t i = 0; i < 16; i++) { + w[i] = static_cast(m_block[i * 4 + 0] << 24); + w[i] |= static_cast(m_block[i * 4 + 1] << 16); + w[i] |= static_cast(m_block[i * 4 + 2] << 8); + w[i] |= static_cast(m_block[i * 4 + 3]); + } + for (size_t i = 16; i < 80; i++) { + w[i] = left_rotate((w[i - 3] ^ w[i - 8] ^ w[i - 14] ^ w[i - 16]), 1); + } + + uint32_t a = m_digest[0]; + uint32_t b = m_digest[1]; + uint32_t c = m_digest[2]; + uint32_t d = m_digest[3]; + uint32_t e = m_digest[4]; + + for (std::size_t i = 0; i < 80; ++i) { + uint32_t f = 0; + uint32_t k = 0; + + if (i < 20) { + f = (b & c) | (~b & d); + k = 0x5A827999; + } else if (i < 40) { + f = b ^ c ^ d; + k = 0x6ED9EBA1; + } else if (i < 60) { + f = (b & c) | (b & d) | (c & d); + k = 0x8F1BBCDC; + } else { + f = b ^ c ^ d; + k = 0xCA62C1D6; + } + uint32_t temp = left_rotate(a, 5) + f + e + k + w[i]; + e = d; + d = c; + c = left_rotate(b, 30); + b = a; + a = temp; + } + + m_digest[0] += a; + m_digest[1] += b; + m_digest[2] += c; + m_digest[3] += d; + m_digest[4] += e; + } + + private: + digest32_t m_digest; + uint8_t m_block[64]; + size_t m_blockByteIndex; + size_t m_byteCount; + }; + + template + inline constexpr CharT empty_guid[37] = "00000000-0000-0000-0000-000000000000"; + + template <> + inline constexpr wchar_t empty_guid[37] = L"00000000-0000-0000-0000-000000000000"; + + template + inline constexpr CharT guid_encoder[17] = "0123456789abcdef"; + + template <> + inline constexpr wchar_t guid_encoder[17] = L"0123456789abcdef"; + } + + // -------------------------------------------------------------------------------------------------------------------------- + // UUID format https://tools.ietf.org/html/rfc4122 + // -------------------------------------------------------------------------------------------------------------------------- + + // -------------------------------------------------------------------------------------------------------------------------- + // Field NDR Data Type Octet # Note + // -------------------------------------------------------------------------------------------------------------------------- + // time_low unsigned long 0 - 3 The low field of the timestamp. + // time_mid unsigned short 4 - 5 The middle field of the timestamp. + // time_hi_and_version unsigned short 6 - 7 The high field of the timestamp multiplexed with the version number. + // clock_seq_hi_and_reserved unsigned small 8 The high field of the clock sequence multiplexed with the variant. + // clock_seq_low unsigned small 9 The low field of the clock sequence. + // node character 10 - 15 The spatially unique node identifier. + // -------------------------------------------------------------------------------------------------------------------------- + // 0 1 2 3 + // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + // | time_low | + // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + // | time_mid | time_hi_and_version | + // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + // |clk_seq_hi_res | clk_seq_low | node (0-1) | + // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + // | node (2-5) | + // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + + // -------------------------------------------------------------------------------------------------------------------------- + // enumerations + // -------------------------------------------------------------------------------------------------------------------------- + + // indicated by a bit pattern in octet 8, marked with N in xxxxxxxx-xxxx-xxxx-Nxxx-xxxxxxxxxxxx + enum class uuid_variant + { + // NCS backward compatibility (with the obsolete Apollo Network Computing System 1.5 UUID format) + // N bit pattern: 0xxx + // > the first 6 octets of the UUID are a 48-bit timestamp (the number of 4 microsecond units of time since 1 Jan 1980 UTC); + // > the next 2 octets are reserved; + // > the next octet is the "address family"; + // > the final 7 octets are a 56-bit host ID in the form specified by the address family + ncs, + + // RFC 4122/DCE 1.1 + // N bit pattern: 10xx + // > big-endian byte order + rfc, + + // Microsoft Corporation backward compatibility + // N bit pattern: 110x + // > little endian byte order + // > formely used in the Component Object Model (COM) library + microsoft, + + // reserved for possible future definition + // N bit pattern: 111x + reserved + }; + + // indicated by a bit pattern in octet 6, marked with M in xxxxxxxx-xxxx-Mxxx-xxxx-xxxxxxxxxxxx + enum class uuid_version + { + none = 0, // only possible for nil or invalid uuids + time_based = 1, // The time-based version specified in RFC 4122 + dce_security = 2, // DCE Security version, with embedded POSIX UIDs. + name_based_md5 = 3, // The name-based version specified in RFS 4122 with MD5 hashing + random_number_based = 4, // The randomly or pseudo-randomly generated version specified in RFS 4122 + name_based_sha1 = 5 // The name-based version specified in RFS 4122 with SHA1 hashing + }; + + // Forward declare uuid & to_string so that we can declare to_string as a friend later. + class uuid; + template , + class Allocator = std::allocator> + std::basic_string to_string(uuid const& id); + + // -------------------------------------------------------------------------------------------------------------------------- + // uuid class + // -------------------------------------------------------------------------------------------------------------------------- + class uuid + { + public: + using value_type = uint8_t; + + constexpr uuid() noexcept = default; + + uuid(value_type(&arr)[16]) noexcept + { + std::copy(std::cbegin(arr), std::cend(arr), std::begin(data)); + } + + constexpr uuid(std::array const& arr) noexcept : data{ arr } {} + + explicit uuid(span bytes) + { + std::copy(std::cbegin(bytes), std::cend(bytes), std::begin(data)); + } + + template + explicit uuid(ForwardIterator first, ForwardIterator last) + { + if (std::distance(first, last) == 16) + std::copy(first, last, std::begin(data)); + } + + constexpr uuid_variant variant() const noexcept + { + if ((data[8] & 0x80) == 0x00) + return uuid_variant::ncs; + else if ((data[8] & 0xC0) == 0x80) + return uuid_variant::rfc; + else if ((data[8] & 0xE0) == 0xC0) + return uuid_variant::microsoft; + else + return uuid_variant::reserved; + } + + constexpr uuid_version version() const noexcept + { + if ((data[6] & 0xF0) == 0x10) + return uuid_version::time_based; + else if ((data[6] & 0xF0) == 0x20) + return uuid_version::dce_security; + else if ((data[6] & 0xF0) == 0x30) + return uuid_version::name_based_md5; + else if ((data[6] & 0xF0) == 0x40) + return uuid_version::random_number_based; + else if ((data[6] & 0xF0) == 0x50) + return uuid_version::name_based_sha1; + else + return uuid_version::none; + } + + constexpr bool is_nil() const noexcept + { + for (size_t i = 0; i < data.size(); ++i) if (data[i] != 0) return false; + return true; + } + + void swap(uuid& other) noexcept + { + data.swap(other.data); + } + + inline span as_bytes() const + { + return span(reinterpret_cast(data.data()), 16); + } + + template + constexpr static bool is_valid_uuid(StringType const& in_str) noexcept + { + auto str = detail::to_string_view(in_str); + bool firstDigit = true; + size_t hasBraces = 0; + size_t index = 0; + + if (str.empty()) + return false; + + if (str.front() == '{') + hasBraces = 1; + if (hasBraces && str.back() != '}') + return false; + + for (size_t i = hasBraces; i < str.size() - hasBraces; ++i) { + if (str[i] == '-') continue; + + if (index >= 16 || !detail::is_hex(str[i])) { + return false; + } + + if (firstDigit) { + firstDigit = false; + } else { + index++; + firstDigit = true; + } + } + + if (index < 16) { + return false; + } + + return true; + } + + template + constexpr static std::optional from_string(StringType const& in_str) noexcept + { + auto str = detail::to_string_view(in_str); + bool firstDigit = true; + size_t hasBraces = 0; + size_t index = 0; + + std::array data{ { 0 } }; + + if (str.empty()) return {}; + + if (str.front() == '{') + hasBraces = 1; + if (hasBraces && str.back() != '}') + return {}; + + for (size_t i = hasBraces; i < str.size() - hasBraces; ++i) { + if (str[i] == '-') continue; + + if (index >= 16 || !detail::is_hex(str[i])) { + return {}; + } + + if (firstDigit) { + data[index] = static_cast(detail::hex2char(str[i]) << 4); + firstDigit = false; + } else { + data[index] = static_cast(data[index] | detail::hex2char(str[i])); + index++; + firstDigit = true; + } + } + + if (index < 16) { + return {}; + } + + return uuid{ data }; + } + + private: + std::array data{ { 0 } }; + + friend bool operator==(uuid const& lhs, uuid const& rhs) noexcept; + friend bool operator<(uuid const& lhs, uuid const& rhs) noexcept; + + template + friend std::basic_ostream& operator<<(std::basic_ostream& s, uuid const& id); + + template + friend std::basic_string to_string(uuid const& id); + + friend std::hash; + }; + + // -------------------------------------------------------------------------------------------------------------------------- + // operators and non-member functions + // -------------------------------------------------------------------------------------------------------------------------- + + inline bool operator== (uuid const& lhs, uuid const& rhs) noexcept + { + return lhs.data == rhs.data; + } + + inline bool operator!= (uuid const& lhs, uuid const& rhs) noexcept + { + return !(lhs == rhs); + } + + inline bool operator< (uuid const& lhs, uuid const& rhs) noexcept + { + return lhs.data < rhs.data; + } + + template + inline std::basic_string to_string(uuid const& id) + { + std::basic_string uustr{ detail::empty_guid }; + + for (size_t i = 0, index = 0; i < 36; ++i) { + if (i == 8 || i == 13 || i == 18 || i == 23) { + continue; + } + uustr[i] = detail::guid_encoder[id.data[index] >> 4 & 0x0f]; + uustr[++i] = detail::guid_encoder[id.data[index] & 0x0f]; + index++; + } + + return uustr; + } + + template + std::basic_ostream& operator<<(std::basic_ostream& s, uuid const& id) + { + s << to_string(id); + return s; + } + + inline void swap(uuids::uuid& lhs, uuids::uuid& rhs) noexcept + { + lhs.swap(rhs); + } + + // -------------------------------------------------------------------------------------------------------------------------- + // namespace IDs that could be used for generating name-based uuids + // -------------------------------------------------------------------------------------------------------------------------- + + // Name string is a fully-qualified domain name + static uuid uuid_namespace_dns{ {0x6b, 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8} }; + + // Name string is a URL + static uuid uuid_namespace_url{ {0x6b, 0xa7, 0xb8, 0x11, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8} }; + + // Name string is an ISO OID (See https://oidref.com/, https://en.wikipedia.org/wiki/Object_identifier) + static uuid uuid_namespace_oid{ {0x6b, 0xa7, 0xb8, 0x12, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8} }; + + // Name string is an X.500 DN, in DER or a text output format (See https://en.wikipedia.org/wiki/X.500, https://en.wikipedia.org/wiki/Abstract_Syntax_Notation_One) + static uuid uuid_namespace_x500{ {0x6b, 0xa7, 0xb8, 0x14, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8} }; + + // -------------------------------------------------------------------------------------------------------------------------- + // uuid generators + // -------------------------------------------------------------------------------------------------------------------------- + +#ifdef UUID_SYSTEM_GENERATOR + class uuid_system_generator + { + public: + using result_type = uuid; + + uuid operator()() + { + #ifdef _WIN32 + + GUID newId; + HRESULT hr = ::CoCreateGuid(&newId); + + if (FAILED(hr)) { + throw std::system_error(hr, std::system_category(), "CoCreateGuid failed"); + } + + std::array bytes = + { { + static_cast((newId.Data1 >> 24) & 0xFF), + static_cast((newId.Data1 >> 16) & 0xFF), + static_cast((newId.Data1 >> 8) & 0xFF), + static_cast((newId.Data1) & 0xFF), + + (unsigned char)((newId.Data2 >> 8) & 0xFF), + (unsigned char)((newId.Data2) & 0xFF), + + (unsigned char)((newId.Data3 >> 8) & 0xFF), + (unsigned char)((newId.Data3) & 0xFF), + + newId.Data4[0], + newId.Data4[1], + newId.Data4[2], + newId.Data4[3], + newId.Data4[4], + newId.Data4[5], + newId.Data4[6], + newId.Data4[7] + } }; + + return uuid{ std::begin(bytes), std::end(bytes) }; + + #elif defined(__linux__) || defined(__unix__) + + uuid_t id; + uuid_generate(id); + + std::array bytes = + { { + id[0], + id[1], + id[2], + id[3], + id[4], + id[5], + id[6], + id[7], + id[8], + id[9], + id[10], + id[11], + id[12], + id[13], + id[14], + id[15] + } }; + + return uuid{ std::begin(bytes), std::end(bytes) }; + + #elif defined(__APPLE__) + auto newId = CFUUIDCreate(NULL); + auto bytes = CFUUIDGetUUIDBytes(newId); + CFRelease(newId); + + std::array arrbytes = + { { + bytes.byte0, + bytes.byte1, + bytes.byte2, + bytes.byte3, + bytes.byte4, + bytes.byte5, + bytes.byte6, + bytes.byte7, + bytes.byte8, + bytes.byte9, + bytes.byte10, + bytes.byte11, + bytes.byte12, + bytes.byte13, + bytes.byte14, + bytes.byte15 + } }; + return uuid{ std::begin(arrbytes), std::end(arrbytes) }; + #else + return uuid{}; + #endif + } + }; +#endif + + template + class basic_uuid_random_generator + { + public: + using engine_type = UniformRandomNumberGenerator; + + explicit basic_uuid_random_generator(engine_type& gen) : + generator(&gen, [](auto) {}) + {} + explicit basic_uuid_random_generator(engine_type* gen) : + generator(gen, [](auto) {}) + {} + + uuid operator()() + { + uint8_t bytes[16]; + for (int i = 0; i < 16; i += 4) + *reinterpret_cast(bytes + i) = distribution(*generator); + + // variant must be 10xxxxxx + bytes[8] &= 0xBF; + bytes[8] |= 0x80; + + // version must be 0100xxxx + bytes[6] &= 0x4F; + bytes[6] |= 0x40; + + return uuid{ std::begin(bytes), std::end(bytes) }; + } + + private: + std::uniform_int_distribution distribution; + std::shared_ptr generator; + }; + + using uuid_random_generator = basic_uuid_random_generator; + + class uuid_name_generator + { + public: + explicit uuid_name_generator(uuid const& namespace_uuid) noexcept + : nsuuid(namespace_uuid) + {} + + template + uuid operator()(StringType const& name) + { + reset(); + process_characters(detail::to_string_view(name)); + return make_uuid(); + } + + private: + void reset() + { + hasher.reset(); + std::byte bytes[16]; + auto nsbytes = nsuuid.as_bytes(); + std::copy(std::cbegin(nsbytes), std::cend(nsbytes), bytes); + hasher.process_bytes(bytes, 16); + } + + template + void process_characters(std::basic_string_view const str) + { + for (uint32_t c : str) { + hasher.process_byte(static_cast(c & 0xFF)); + if constexpr (!std::is_same_v) { + hasher.process_byte(static_cast((c >> 8) & 0xFF)); + hasher.process_byte(static_cast((c >> 16) & 0xFF)); + hasher.process_byte(static_cast((c >> 24) & 0xFF)); + } + } + } + + uuid make_uuid() + { + detail::sha1::digest8_t digest; + hasher.get_digest_bytes(digest); + + // variant must be 0b10xxxxxx + digest[8] &= 0xBF; + digest[8] |= 0x80; + + // version must be 0b0101xxxx + digest[6] &= 0x5F; + digest[6] |= 0x50; + + return uuid{ digest, digest + 16 }; + } + + private: + uuid nsuuid; + detail::sha1 hasher; + }; + +#ifdef UUID_TIME_GENERATOR + // !!! DO NOT USE THIS IN PRODUCTION + // this implementation is unreliable for good uuids + class uuid_time_generator + { + using mac_address = std::array; + + std::optional device_address; + + bool get_mac_address() + { + if (device_address.has_value()) { + return true; + } + + #ifdef _WIN32 + DWORD len = 0; + auto ret = GetAdaptersInfo(nullptr, &len); + if (ret != ERROR_BUFFER_OVERFLOW) return false; + std::vector buf(len); + auto pips = reinterpret_cast(&buf.front()); + ret = GetAdaptersInfo(pips, &len); + if (ret != ERROR_SUCCESS) return false; + mac_address addr; + std::copy(pips->Address, pips->Address + 6, std::begin(addr)); + device_address = addr; + #endif + + return device_address.has_value(); + } + + long long get_time_intervals() + { + auto start = std::chrono::system_clock::from_time_t(time_t(-12219292800)); + auto diff = std::chrono::system_clock::now() - start; + auto ns = std::chrono::duration_cast(diff).count(); + return ns / 100; + } + + static unsigned short get_clock_sequence() + { + static std::mt19937 clock_gen(std::random_device{}()); + static std::uniform_int_distribution clock_dis; + static std::atomic_ushort clock_sequence = clock_dis(clock_gen); + return clock_sequence++; + } + + public: + uuid operator()() + { + if (get_mac_address()) { + std::array data; + + auto tm = get_time_intervals(); + + auto clock_seq = get_clock_sequence(); + + auto ptm = reinterpret_cast(&tm); + + memcpy(&data[0], ptm + 4, 4); + memcpy(&data[4], ptm + 2, 2); + memcpy(&data[6], ptm, 2); + + memcpy(&data[8], &clock_seq, 2); + + // variant must be 0b10xxxxxx + data[8] &= 0xBF; + data[8] |= 0x80; + + // version must be 0b0001xxxx + data[6] &= 0x1F; + data[6] |= 0x10; + + memcpy(&data[10], &device_address.value()[0], 6); + + return uuids::uuid{ std::cbegin(data), std::cend(data) }; + } + + return {}; + } + }; +#endif +} + +namespace std +{ + template <> + struct hash + { + using argument_type = uuids::uuid; + using result_type = std::size_t; + + result_type operator()(argument_type const& uuid) const + { + #ifdef UUID_HASH_STRING_BASED + std::hash hasher; + return static_cast(hasher(uuids::to_string(uuid))); + #else + uint64_t l = + static_cast(uuid.data[0]) << 56 | + static_cast(uuid.data[1]) << 48 | + static_cast(uuid.data[2]) << 40 | + static_cast(uuid.data[3]) << 32 | + static_cast(uuid.data[4]) << 24 | + static_cast(uuid.data[5]) << 16 | + static_cast(uuid.data[6]) << 8 | + static_cast(uuid.data[7]); + uint64_t h = + static_cast(uuid.data[8]) << 56 | + static_cast(uuid.data[9]) << 48 | + static_cast(uuid.data[10]) << 40 | + static_cast(uuid.data[11]) << 32 | + static_cast(uuid.data[12]) << 24 | + static_cast(uuid.data[13]) << 16 | + static_cast(uuid.data[14]) << 8 | + static_cast(uuid.data[15]); + + if constexpr (sizeof(result_type) > 4) { + return result_type(l ^ h); + } else { + uint64_t hash64 = l ^ h; + return result_type(uint32_t(hash64 >> 32) ^ uint32_t(hash64)); + } + #endif + } + }; +} + +#endif diff --git a/vc17/otclient.vcxproj b/vc17/otclient.vcxproj index 35c66d9168..79977b0e32 100644 --- a/vc17/otclient.vcxproj +++ b/vc17/otclient.vcxproj @@ -684,6 +684,7 @@ git rev-list --count head >> ../src/gitinfo.h + diff --git a/vc17/otclient.vcxproj.filters b/vc17/otclient.vcxproj.filters index 8f3df78ecd..4725ee9d3d 100644 --- a/vc17/otclient.vcxproj.filters +++ b/vc17/otclient.vcxproj.filters @@ -1076,6 +1076,9 @@ Header Files\client + + Header Files\framework\util + From 885cfef3b6bb27e7b5f312a32ab4b8349d9a57a5 Mon Sep 17 00:00:00 2001 From: Renato Date: Tue, 5 Apr 2022 20:07:36 -0300 Subject: [PATCH 3/6] boost::tokenizer to stdext::split --- src/framework/otml/otmlparser.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/framework/otml/otmlparser.cpp b/src/framework/otml/otmlparser.cpp index 4d60558100..7cb4c61990 100644 --- a/src/framework/otml/otmlparser.cpp +++ b/src/framework/otml/otmlparser.cpp @@ -21,7 +21,6 @@ */ #include "otmlparser.h" -#include #include "otmldocument.h" #include "otmlexception.h" @@ -188,8 +187,8 @@ void OTMLParser::parseNode(const std::string& data) node->setNull(true); else { if (value.starts_with("[") && value.ends_with("]")) { - std::string tmp = value.substr(1, value.length() - 2); - boost::tokenizer> tokens(tmp); + const std::string tmp = value.substr(1, value.length() - 2); + const std::vector tokens = stdext::split(tmp, ","); for (std::string v : tokens) { stdext::trim(v); node->writeIn(v); From 8a33abf7f393f628bc0aa855b1ebaf816844298b Mon Sep 17 00:00:00 2001 From: Renato Date: Tue, 5 Apr 2022 21:13:39 -0300 Subject: [PATCH 4/6] add uuid.h in cmakelist --- src/framework/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/framework/CMakeLists.txt b/src/framework/CMakeLists.txt index 47722c09ae..4d555c74f0 100644 --- a/src/framework/CMakeLists.txt +++ b/src/framework/CMakeLists.txt @@ -26,6 +26,7 @@ set(framework_SOURCES ${framework_SOURCES} ${CMAKE_CURRENT_LIST_DIR}/util/point.h ${CMAKE_CURRENT_LIST_DIR}/util/rect.h ${CMAKE_CURRENT_LIST_DIR}/util/size.h + ${CMAKE_CURRENT_LIST_DIR}/util/uuid.h # stdext ${CMAKE_CURRENT_LIST_DIR}/stdext/cast.h From 2101afa0c192c43ee07b3b222b989142feab5506 Mon Sep 17 00:00:00 2001 From: Nekiro Date: Wed, 6 Apr 2022 17:57:21 +0200 Subject: [PATCH 5/6] add find asio --- src/framework/CMakeLists.txt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/framework/CMakeLists.txt b/src/framework/CMakeLists.txt index 4d555c74f0..09cb4357a5 100644 --- a/src/framework/CMakeLists.txt +++ b/src/framework/CMakeLists.txt @@ -220,6 +220,16 @@ find_package(Protobuf REQUIRED) find_package(LibLZMA REQUIRED) find_package(nlohmann_json REQUIRED) +find_path(ASIO_INCLUDE_PATH asio.hpp HINTS + "/usr/include" + "/usr/local/include" + "/opt/local/include" +) + +if(ASIO_INCLUDE_PATH) + message(STATUS "Found existing ASIO install") +endif(ASIO_INCLUDE_PATH) + set(framework_LIBRARIES ${framework_LIBRARIES} ${Boost_LIBRARIES} ${LUA_LIBRARY} From 73df90e44524c4d7df3f3ba1ebdc8dff059bcbe0 Mon Sep 17 00:00:00 2001 From: Nekiro Date: Wed, 6 Apr 2022 23:39:12 +0200 Subject: [PATCH 6/6] Remove find boost --- src/framework/CMakeLists.txt | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/framework/CMakeLists.txt b/src/framework/CMakeLists.txt index 09cb4357a5..da3f2cb0c3 100644 --- a/src/framework/CMakeLists.txt +++ b/src/framework/CMakeLists.txt @@ -190,16 +190,6 @@ add_definitions(-D"BUILD_COMMIT=\\\"${BUILD_COMMIT}\\\"") message(STATUS "Build revision: ${BUILD_REVISION}") add_definitions(-D"BUILD_REVISION=\\\"${BUILD_REVISION}\\\"") -# find boost -set(REQUIRED_BOOST_COMPONENTS system thread filesystem) -if(WIN32) - set(Boost_THREADAPI win32) - set(framework_DEFINITIONS ${framework_DEFINITIONS} -DBOOST_THREAD_USE_LIB) # fix boost thread linkage -endif() -set(Boost_USE_MULTITHREADED ON) -set(Boost_USE_STATIC_LIBS ${USE_STATIC_LIBS}) -find_package(Boost 1.48.0 COMPONENTS ${REQUIRED_BOOST_COMPONENTS} REQUIRED) - #find lua if(LUAJIT) find_package(LuaJIT REQUIRED) @@ -231,7 +221,6 @@ if(ASIO_INCLUDE_PATH) endif(ASIO_INCLUDE_PATH) set(framework_LIBRARIES ${framework_LIBRARIES} - ${Boost_LIBRARIES} ${LUA_LIBRARY} ${PHYSFS_LIBRARY} ${ZLIB_LIBRARY} @@ -241,7 +230,6 @@ set(framework_LIBRARIES ${framework_LIBRARIES} ) set(framework_INCLUDE_DIRS ${framework_INCLUDE_DIRS} - ${Boost_INCLUDE_DIRS} ${LUA_INCLUDE_DIR} ${PHYSFS_INCLUDE_DIR} ${framework_INCLUDE_DIRS}