diff options
author | Shauren <shauren.trinity@gmail.com> | 2025-06-02 18:38:41 +0200 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2025-06-02 18:38:41 +0200 |
commit | 74d9da7f3257c510b4f99fca635c5a9971053300 (patch) | |
tree | 7a12179eb0b716e82ff755e1f0e90594070f2a4e /src | |
parent | 2d984fcade155bf860ed20713a95251ad0103318 (diff) |
Core/Network: Make ip address formattable with fmt
Diffstat (limited to 'src')
-rw-r--r-- | src/common/network/AsyncAcceptor.h | 4 | ||||
-rw-r--r-- | src/common/network/Http/HttpService.cpp | 6 | ||||
-rw-r--r-- | src/common/network/IpAddress.cpp | 58 | ||||
-rw-r--r-- | src/common/network/IpAddress.h | 20 | ||||
-rw-r--r-- | src/common/network/Socket.h | 5 | ||||
-rw-r--r-- | src/server/game/Server/WorldSocket.cpp | 69 | ||||
-rw-r--r-- | src/server/shared/Networking/ConnectionInitializers/IpBanCheckConnectionInitializer.cpp | 4 | ||||
-rw-r--r-- | src/server/shared/Networking/ConnectionInitializers/IpBanCheckConnectionInitializer.h | 7 | ||||
-rw-r--r-- | src/server/worldserver/RemoteAccess/RASession.cpp | 1 | ||||
-rw-r--r-- | src/server/worldserver/RemoteAccess/RASession.h | 2 |
10 files changed, 133 insertions, 43 deletions
diff --git a/src/common/network/AsyncAcceptor.h b/src/common/network/AsyncAcceptor.h index be9c8d21e41..aaaa9410584 100644 --- a/src/common/network/AsyncAcceptor.h +++ b/src/common/network/AsyncAcceptor.h @@ -98,14 +98,14 @@ public: _acceptor.bind(_endpoint, errorCode); if (errorCode) { - TC_LOG_INFO("network", "Could not bind to {}:{} {}", _endpoint.address().to_string(), _endpoint.port(), errorCode.message()); + TC_LOG_INFO("network", "Could not bind to {}:{} {}", _endpoint.address(), _endpoint.port(), errorCode.message()); return false; } _acceptor.listen(TRINITY_MAX_LISTEN_CONNECTIONS, errorCode); if (errorCode) { - TC_LOG_INFO("network", "Failed to start listening on {}:{} {}", _endpoint.address().to_string(), _endpoint.port(), errorCode.message()); + TC_LOG_INFO("network", "Failed to start listening on {}:{} {}", _endpoint.address(), _endpoint.port(), errorCode.message()); return false; } diff --git a/src/common/network/Http/HttpService.cpp b/src/common/network/Http/HttpService.cpp index 6115fd6b6d2..3ba983ac10e 100644 --- a/src/common/network/Http/HttpService.cpp +++ b/src/common/network/Http/HttpService.cpp @@ -135,7 +135,7 @@ void SessionService::InitAndStoreSessionState(std::shared_ptr<SessionState> stat while (state->Id.is_nil() || _sessions.contains(state->Id)) std::copy_n(Trinity::Crypto::GetRandomBytes<16>().begin(), 16, state->Id.begin()); - TC_LOG_DEBUG(_logger, "Client at {} created new session {}", address.to_string(), boost::uuids::to_string(state->Id)); + TC_LOG_DEBUG(_logger, "Client at {} created new session {}", address, boost::uuids::to_string(state->Id)); _sessions[state->Id] = std::move(state); } } @@ -175,7 +175,7 @@ std::shared_ptr<SessionState> SessionService::FindAndRefreshSessionState(std::st auto itr = _sessions.find(boost::uuids::string_generator()(id.begin(), id.end())); if (itr == _sessions.end()) { - TC_LOG_DEBUG(_logger, "Client at {} attempted to use a session {} that was expired", address.to_string(), id); + TC_LOG_DEBUG(_logger, "Client at {} attempted to use a session {} that was expired", address, id); return nullptr; // no session } @@ -185,7 +185,7 @@ std::shared_ptr<SessionState> SessionService::FindAndRefreshSessionState(std::st if (state->RemoteAddress != address) { TC_LOG_ERROR(_logger, "Client at {} attempted to use a session {} that was last accessed from {}, denied access", - address.to_string(), id, state->RemoteAddress.to_string()); + address, id, state->RemoteAddress); return nullptr; } diff --git a/src/common/network/IpAddress.cpp b/src/common/network/IpAddress.cpp new file mode 100644 index 00000000000..40b3148daa5 --- /dev/null +++ b/src/common/network/IpAddress.cpp @@ -0,0 +1,58 @@ +/* + * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "IpAddress.h" +#include "StringFormat.h" +#include "Util.h" + +template <typename FormatContext> +typename FormatContext::iterator Trinity::Net::Impl::AddressFormatter::format(boost::asio::ip::address_v4 const& address, FormatContext& ctx) const +{ + boost::system::error_code ec; + std::array<char, boost::asio::detail::max_addr_v4_str_len> addr_str; + if (boost::asio::detail::socket_ops::inet_ntop(AF_INET, address.to_bytes().data(), addr_str.data(), addr_str.size(), 0, ec) && !ec) + return std::ranges::copy(addr_str.begin(), CStringSentinel.Checked(addr_str.end()), ctx.out()).out; + + return ctx.out(); +} + +template <typename FormatContext> +typename FormatContext::iterator Trinity::Net::Impl::AddressFormatter::format(boost::asio::ip::address_v6 const& address, FormatContext& ctx) const +{ + boost::system::error_code ec; + std::array<char, boost::asio::detail::max_addr_v6_str_len> addr_str; + if (boost::asio::detail::socket_ops::inet_ntop(AF_INET6, address.to_bytes().data(), addr_str.data(), addr_str.size(), address.scope_id(), ec) && !ec) + return std::ranges::copy(addr_str.begin(), CStringSentinel.Checked(addr_str.end()), ctx.out()).out; + + return ctx.out(); +} + +template <typename FormatContext> +typename FormatContext::iterator Trinity::Net::Impl::AddressFormatter::format(boost::asio::ip::address const& address, FormatContext& ctx) const +{ + if (address.is_v4()) + return this->format(address.to_v4(), ctx); + + if (address.is_v6()) + return this->format(address.to_v6(), ctx); + + return ctx.out(); +} + +template TC_NETWORK_API fmt::appender Trinity::Net::Impl::AddressFormatter::format<fmt::format_context>(boost::asio::ip::address_v4 const&, fmt::format_context&) const; +template TC_NETWORK_API fmt::appender Trinity::Net::Impl::AddressFormatter::format<fmt::format_context>(boost::asio::ip::address_v6 const&, fmt::format_context&) const; +template TC_NETWORK_API fmt::appender Trinity::Net::Impl::AddressFormatter::format<fmt::format_context>(boost::asio::ip::address const&, fmt::format_context&) const; diff --git a/src/common/network/IpAddress.h b/src/common/network/IpAddress.h index b856d7f6340..c19feedf84d 100644 --- a/src/common/network/IpAddress.h +++ b/src/common/network/IpAddress.h @@ -19,6 +19,7 @@ #define TRINITYCORE_IP_ADDRESS_H #include "Define.h" +#include "StringFormatFwd.h" #include <boost/asio/ip/address.hpp> namespace Trinity::Net @@ -28,6 +29,25 @@ namespace Trinity::Net using boost::asio::ip::make_address_v6; using boost::asio::ip::v4_mapped_t::v4_mapped; inline uint32 address_to_uint(boost::asio::ip::address_v4 const& address) { return address.to_uint(); } + + namespace Impl + { + struct AddressFormatter : NoArgFormatterBase + { + template <typename FormatContext> + typename FormatContext::iterator format(boost::asio::ip::address_v4 const& address, FormatContext& ctx) const; + + template <typename FormatContext> + typename FormatContext::iterator format(boost::asio::ip::address_v6 const& address, FormatContext& ctx) const; + + template <typename FormatContext> + typename FormatContext::iterator format(boost::asio::ip::address const& address, FormatContext& ctx) const; + }; + } } +template <> struct fmt::formatter<boost::asio::ip::address_v4, char, void> : Trinity::Net::Impl::AddressFormatter { }; +template <> struct fmt::formatter<boost::asio::ip::address_v6, char, void> : Trinity::Net::Impl::AddressFormatter { }; +template <> struct fmt::formatter<boost::asio::ip::address, char, void> : Trinity::Net::Impl::AddressFormatter { }; + #endif // TRINITYCORE_IP_ADDRESS_H diff --git a/src/common/network/Socket.h b/src/common/network/Socket.h index e91d3198b58..b7542c9c70d 100644 --- a/src/common/network/Socket.h +++ b/src/common/network/Socket.h @@ -19,6 +19,7 @@ #define TRINITYCORE_SOCKET_H #include "Concepts.h" +#include "IpAddress.h" #include "Log.h" #include "MessageBuffer.h" #include "SocketConnectionInitializer.h" @@ -203,7 +204,7 @@ public: boost::system::error_code shutdownError; _socket.shutdown(boost::asio::socket_base::shutdown_send, shutdownError); if (shutdownError) - TC_LOG_DEBUG("network", "Socket::CloseSocket: {} errored when shutting down socket: {} ({})", GetRemoteIpAddress().to_string(), + TC_LOG_DEBUG("network", "Socket::CloseSocket: {} errored when shutting down socket: {} ({})", GetRemoteIpAddress(), shutdownError.value(), shutdownError.message()); this->OnClose(); @@ -262,7 +263,7 @@ protected: _socket.set_option(boost::asio::ip::tcp::no_delay(enable), err); if (err) TC_LOG_DEBUG("network", "Socket::SetNoDelay: failed to set_option(boost::asio::ip::tcp::no_delay) for {} - {} ({})", - GetRemoteIpAddress().to_string(), err.value(), err.message()); + GetRemoteIpAddress(), err.value(), err.message()); } private: diff --git a/src/server/game/Server/WorldSocket.cpp b/src/server/game/Server/WorldSocket.cpp index 210b2098833..86714b78a16 100644 --- a/src/server/game/Server/WorldSocket.cpp +++ b/src/server/game/Server/WorldSocket.cpp @@ -167,7 +167,7 @@ void WorldSocketProtocolInitializer::HandleDataReady() catch (ByteBufferException const& ex) { TC_LOG_ERROR("network", "WorldSocket::InitializeHandler ByteBufferException {} occured while parsing initial packet from {}", - ex.what(), _socket->GetRemoteIpAddress().to_string()); + ex.what(), _socket->GetRemoteIpAddress()); _socket->CloseSocket(); return; } @@ -344,7 +344,7 @@ bool WorldSocket::ReadHeaderHandler() if (header->EncryptedOpcode != CMSG_HOTFIX_REQUEST || header->Size > 0x100000 || !_canRequestHotfixes) { TC_LOG_ERROR("network", "WorldSocket::ReadHeaderHandler(): client {} sent malformed packet (size: {}, opcode {})", - GetRemoteIpAddress().to_string(), header->Size, uint32(header->EncryptedOpcode)); + GetRemoteIpAddress(), header->Size, uint32(header->EncryptedOpcode)); return false; } } @@ -361,7 +361,7 @@ WorldSocket::ReadDataHandlerResult WorldSocket::ReadDataHandler() if (!_authCrypt.DecryptRecv(_packetBuffer.GetReadPointer(), header->Size, header->Tag)) { TC_LOG_ERROR("network", "WorldSocket::ReadHeaderHandler(): client {} failed to decrypt packet (size: {})", - GetRemoteIpAddress().to_string(), header->Size); + GetRemoteIpAddress(), header->Size); return ReadDataHandlerResult::Error; } @@ -370,7 +370,7 @@ WorldSocket::ReadDataHandlerResult WorldSocket::ReadDataHandler() if (!opcodeTable.IsValid(opcode)) { TC_LOG_ERROR("network", "WorldSocket::ReadHeaderHandler(): client {} sent wrong opcode (opcode: {})", - GetRemoteIpAddress().to_string(), uint32(opcode)); + GetRemoteIpAddress(), uint32(opcode)); return ReadDataHandlerResult::Error; } @@ -389,7 +389,7 @@ WorldSocket::ReadDataHandlerResult WorldSocket::ReadDataHandler() WorldPackets::Auth::Ping ping(std::move(packet)); if (!ping.ReadNoThrow()) { - TC_LOG_ERROR("network", "WorldSocket::ReadDataHandler(): client {} sent malformed CMSG_PING", GetRemoteIpAddress().to_string()); + TC_LOG_ERROR("network", "WorldSocket::ReadDataHandler(): client {} sent malformed CMSG_PING", GetRemoteIpAddress()); return ReadDataHandlerResult::Error; } if (!HandlePing(ping)) @@ -410,7 +410,7 @@ WorldSocket::ReadDataHandlerResult WorldSocket::ReadDataHandler() std::shared_ptr<WorldPackets::Auth::AuthSession> authSession = std::make_shared<WorldPackets::Auth::AuthSession>(std::move(packet)); if (!authSession->ReadNoThrow()) { - TC_LOG_ERROR("network", "WorldSocket::ReadDataHandler(): client {} sent malformed CMSG_AUTH_SESSION", GetRemoteIpAddress().to_string()); + TC_LOG_ERROR("network", "WorldSocket::ReadDataHandler(): client {} sent malformed CMSG_AUTH_SESSION", GetRemoteIpAddress()); return ReadDataHandlerResult::Error; } HandleAuthSession(authSession); @@ -430,7 +430,7 @@ WorldSocket::ReadDataHandlerResult WorldSocket::ReadDataHandler() std::shared_ptr<WorldPackets::Auth::AuthContinuedSession> authSession = std::make_shared<WorldPackets::Auth::AuthContinuedSession>(std::move(packet)); if (!authSession->ReadNoThrow()) { - TC_LOG_ERROR("network", "WorldSocket::ReadDataHandler(): client {} sent malformed CMSG_AUTH_CONTINUED_SESSION", GetRemoteIpAddress().to_string()); + TC_LOG_ERROR("network", "WorldSocket::ReadDataHandler(): client {} sent malformed CMSG_AUTH_CONTINUED_SESSION", GetRemoteIpAddress()); return ReadDataHandlerResult::Error; } HandleAuthContinuedSession(authSession); @@ -444,11 +444,11 @@ WorldSocket::ReadDataHandlerResult WorldSocket::ReadDataHandler() _worldSession->ResetTimeOutTime(true); return ReadDataHandlerResult::Ok; } - TC_LOG_ERROR("network", "WorldSocket::ReadDataHandler: client {} sent CMSG_KEEP_ALIVE without being authenticated", GetRemoteIpAddress().to_string()); + TC_LOG_ERROR("network", "WorldSocket::ReadDataHandler: client {} sent CMSG_KEEP_ALIVE without being authenticated", GetRemoteIpAddress()); return ReadDataHandlerResult::Error; case CMSG_LOG_DISCONNECT: LogOpcodeText(opcode, sessionGuard); - TC_LOG_DEBUG("network", "WorldSocket::ReadDataHandler: client {} sent CMSG_LOG_DISCONNECT reason {}", GetRemoteIpAddress().to_string(), packet.read<uint32>()); + TC_LOG_DEBUG("network", "WorldSocket::ReadDataHandler: client {} sent CMSG_LOG_DISCONNECT reason {}", GetRemoteIpAddress(), packet.read<uint32>()); break; case CMSG_ENABLE_NAGLE: LogOpcodeText(opcode, sessionGuard); @@ -462,7 +462,7 @@ WorldSocket::ReadDataHandlerResult WorldSocket::ReadDataHandler() WorldPackets::Auth::ConnectToFailed connectToFailed(std::move(packet)); if (!connectToFailed.ReadNoThrow()) { - TC_LOG_ERROR("network", "WorldSocket::ReadDataHandler(): client {} sent malformed CMSG_CONNECT_TO_FAILED", GetRemoteIpAddress().to_string()); + TC_LOG_ERROR("network", "WorldSocket::ReadDataHandler(): client {} sent malformed CMSG_CONNECT_TO_FAILED", GetRemoteIpAddress()); return ReadDataHandlerResult::Error; } HandleConnectToFailed(connectToFailed); @@ -513,7 +513,7 @@ void WorldSocket::LogOpcodeText(OpcodeClient opcode, std::unique_lock<std::mutex { if (!guard || !_worldSession) { - TC_LOG_TRACE("network.opcode", "C->S: {} {}", GetRemoteIpAddress().to_string(), GetOpcodeNameForLogging(opcode)); + TC_LOG_TRACE("network.opcode", "C->S: {} {}", GetRemoteIpAddress(), GetOpcodeNameForLogging(opcode)); } else { @@ -523,7 +523,7 @@ void WorldSocket::LogOpcodeText(OpcodeClient opcode, std::unique_lock<std::mutex void WorldSocket::SendPacketAndLogOpcode(WorldPacket const& packet) { - TC_LOG_TRACE("network.opcode", "S->C: {} {}", GetRemoteIpAddress().to_string(), GetOpcodeNameForLogging(static_cast<OpcodeServer>(packet.GetOpcode()))); + TC_LOG_TRACE("network.opcode", "S->C: {} {}", GetRemoteIpAddress(), GetOpcodeNameForLogging(static_cast<OpcodeServer>(packet.GetOpcode()))); SendPacket(packet); } @@ -706,13 +706,15 @@ void WorldSocket::HandleAuthSessionCallback(std::shared_ptr<WorldPackets::Auth:: return; } + std::string address = GetRemoteIpAddress().to_string(); + AccountInfo account(result->Fetch()); ClientBuild::Info const* buildInfo = ClientBuild::GetBuildInfo(account.Game.Build); if (!buildInfo) { SendAuthResponseError(ERROR_BAD_VERSION); - TC_LOG_ERROR("network", "WorldSocket::HandleAuthSession: Missing client build info for build {} ({}).", account.Game.Build, GetRemoteIpAddress().to_string()); + TC_LOG_ERROR("network", "WorldSocket::HandleAuthSession: Missing client build info for build {} ({}).", account.Game.Build, address); DelayedCloseSocket(); return; } @@ -724,14 +726,11 @@ void WorldSocket::HandleAuthSessionCallback(std::shared_ptr<WorldPackets::Auth:: SendAuthResponseError(ERROR_BAD_VERSION); TC_LOG_ERROR("network", "WorldSocket::HandleAuthSession: Missing client build auth key for build {} variant {}-{}-{} ({}).", account.Game.Build, ClientBuild::ToCharArray(buildVariant.Platform).data(), ClientBuild::ToCharArray(buildVariant.Arch).data(), - ClientBuild::ToCharArray(buildVariant.Type).data(), GetRemoteIpAddress().to_string()); + ClientBuild::ToCharArray(buildVariant.Type).data(), address); DelayedCloseSocket(); return; } - // For hook purposes, we get Remoteaddress at this point. - std::string address = GetRemoteIpAddress().to_string(); - Trinity::Crypto::SHA512 digestKeyHash; digestKeyHash.UpdateData(account.Game.KeyData.data(), account.Game.KeyData.size()); digestKeyHash.UpdateData(clientBuildAuthKey->Key.data(), clientBuildAuthKey->Key.size()); @@ -795,7 +794,7 @@ void WorldSocket::HandleAuthSessionCallback(std::shared_ptr<WorldPackets::Auth:: if (sWorld->IsClosed()) { SendAuthResponseError(ERROR_DENIED); - TC_LOG_ERROR("network", "WorldSocket::HandleAuthSession: World closed, denying client ({}).", GetRemoteIpAddress().to_string()); + TC_LOG_ERROR("network", "WorldSocket::HandleAuthSession: World closed, denying client ({}).", address); DelayedCloseSocket(); return; } @@ -804,7 +803,7 @@ void WorldSocket::HandleAuthSessionCallback(std::shared_ptr<WorldPackets::Auth:: { SendAuthResponseError(ERROR_DENIED); TC_LOG_ERROR("network", "WorldSocket::HandleAuthSession: Client {} requested connecting with realm id {} but this realm has id {} set in config.", - GetRemoteIpAddress().to_string(), authSession->RealmID, sRealmList->GetCurrentRealmId().Realm); + address, authSession->RealmID, sRealmList->GetCurrentRealmId().Realm); DelayedCloseSocket(); return; } @@ -852,7 +851,7 @@ void WorldSocket::HandleAuthSessionCallback(std::shared_ptr<WorldPackets::Auth:: //! Negative mutetime indicates amount of seconds to be muted effective on next login - which is now. if (mutetime < 0) { - mutetime = GameTime::GetGameTime() + std::llabs(mutetime); + mutetime = GameTime::GetGameTime() - mutetime; stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_MUTE_TIME_LOGIN); stmt->setInt64(0, mutetime); @@ -971,7 +970,7 @@ void WorldSocket::HandleAuthContinuedSessionCallback(std::shared_ptr<WorldPacket if (memcmp(hmac.GetDigest().data(), authSession->Digest.data(), authSession->Digest.size())) { - TC_LOG_ERROR("network", "WorldSocket::HandleAuthContinuedSession: Authentication failed for account: {} ('{}') address: {}", accountId, login, GetRemoteIpAddress().to_string()); + TC_LOG_ERROR("network", "WorldSocket::HandleAuthContinuedSession: Authentication failed for account: {} ('{}') address: {}", accountId, login, GetRemoteIpAddress()); DelayedCloseSocket(); return; } @@ -1059,7 +1058,7 @@ bool WorldSocket::HandlePing(WorldPackets::Auth::Ping& ping) _LastPingTime = now; - if (diff < seconds(27)) + if (diff < 27s) { ++_OverSpeedPings; @@ -1067,12 +1066,16 @@ bool WorldSocket::HandlePing(WorldPackets::Auth::Ping& ping) if (maxAllowed && _OverSpeedPings > maxAllowed) { - std::unique_lock<std::mutex> sessionGuard(_worldSessionLock); + bool ignoresOverspeedPingsLimit = [&] + { + std::lock_guard<std::mutex> sessionGuard(_worldSessionLock); + return _worldSession && !_worldSession->HasPermission(rbac::RBAC_PERM_SKIP_CHECK_OVERSPEED_PING); + }(); - if (_worldSession && !_worldSession->HasPermission(rbac::RBAC_PERM_SKIP_CHECK_OVERSPEED_PING)) + if (!ignoresOverspeedPingsLimit) { TC_LOG_ERROR("network", "WorldSocket::HandlePing: {} kicked for over-speed pings (address: {})", - _worldSession->GetPlayerInfo(), GetRemoteIpAddress().to_string()); + _worldSession->GetPlayerInfo(), GetRemoteIpAddress()); return false; } @@ -1082,16 +1085,22 @@ bool WorldSocket::HandlePing(WorldPackets::Auth::Ping& ping) _OverSpeedPings = 0; } + bool success = [&] { std::lock_guard<std::mutex> sessionGuard(_worldSessionLock); - if (_worldSession) - _worldSession->SetLatency(ping.Latency); - else { - TC_LOG_ERROR("network", "WorldSocket::HandlePing: peer sent CMSG_PING, but is not authenticated or got recently kicked, address = {}", GetRemoteIpAddress().to_string()); - return false; + _worldSession->SetLatency(ping.Latency); + return true; } + return false; + }(); + + if (!success) + { + TC_LOG_ERROR("network", "WorldSocket::HandlePing: peer sent CMSG_PING, but is not authenticated or got recently kicked, address = {}", GetRemoteIpAddress()); + return false; + } SendPacketAndLogOpcode(*WorldPackets::Auth::Pong(ping.Serial).Write()); diff --git a/src/server/shared/Networking/ConnectionInitializers/IpBanCheckConnectionInitializer.cpp b/src/server/shared/Networking/ConnectionInitializers/IpBanCheckConnectionInitializer.cpp index 5996c40faee..4e7d9a4ab72 100644 --- a/src/server/shared/Networking/ConnectionInitializers/IpBanCheckConnectionInitializer.cpp +++ b/src/server/shared/Networking/ConnectionInitializers/IpBanCheckConnectionInitializer.cpp @@ -18,10 +18,10 @@ #include "IpBanCheckConnectionInitializer.h" #include "DatabaseEnv.h" -QueryCallback Trinity::Net::IpBanCheckHelpers::AsyncQuery(std::string_view ipAddress) +QueryCallback Trinity::Net::IpBanCheckHelpers::AsyncQuery(boost::asio::ip::address const& ipAddress) { LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_IP_INFO); - stmt->setString(0, ipAddress); + stmt->setString(0, ipAddress.to_string()); return LoginDatabase.AsyncQuery(stmt); } diff --git a/src/server/shared/Networking/ConnectionInitializers/IpBanCheckConnectionInitializer.h b/src/server/shared/Networking/ConnectionInitializers/IpBanCheckConnectionInitializer.h index 84df525918e..d8badeb1203 100644 --- a/src/server/shared/Networking/ConnectionInitializers/IpBanCheckConnectionInitializer.h +++ b/src/server/shared/Networking/ConnectionInitializers/IpBanCheckConnectionInitializer.h @@ -19,6 +19,7 @@ #define TRINITYCORE_IP_BAN_CHECK_CONNECTION_INITIALIZER_H #include "DatabaseEnvFwd.h" +#include "IpAddress.h" #include "Log.h" #include "QueryCallback.h" #include "SocketConnectionInitializer.h" @@ -27,7 +28,7 @@ namespace Trinity::Net { namespace IpBanCheckHelpers { -TC_SHARED_API QueryCallback AsyncQuery(std::string_view ipAddress); +TC_SHARED_API QueryCallback AsyncQuery(boost::asio::ip::address const& ipAddress); TC_SHARED_API bool IsBanned(PreparedQueryResult const& result); } @@ -38,7 +39,7 @@ struct IpBanCheckConnectionInitializer final : SocketConnectionInitializer void Start() override { - _socket->QueueQuery(IpBanCheckHelpers::AsyncQuery(_socket->GetRemoteIpAddress().to_string()).WithPreparedCallback([socketRef = _socket->weak_from_this(), self = this->shared_from_this()](PreparedQueryResult const& result) + _socket->QueueQuery(IpBanCheckHelpers::AsyncQuery(_socket->GetRemoteIpAddress()).WithPreparedCallback([socketRef = _socket->weak_from_this(), self = this->shared_from_this()](PreparedQueryResult const& result) { std::shared_ptr<SocketImpl> socket = static_pointer_cast<SocketImpl>(socketRef.lock()); if (!socket) @@ -46,7 +47,7 @@ struct IpBanCheckConnectionInitializer final : SocketConnectionInitializer if (IpBanCheckHelpers::IsBanned(result)) { - TC_LOG_ERROR("network", "IpBanCheckConnectionInitializer: IP {} is banned.", socket->GetRemoteIpAddress().to_string()); + TC_LOG_ERROR("network", "IpBanCheckConnectionInitializer: IP {} is banned.", socket->GetRemoteIpAddress()); socket->CloseSocket(); return; } diff --git a/src/server/worldserver/RemoteAccess/RASession.cpp b/src/server/worldserver/RemoteAccess/RASession.cpp index 910cfdf5e4f..6ac93c3afdf 100644 --- a/src/server/worldserver/RemoteAccess/RASession.cpp +++ b/src/server/worldserver/RemoteAccess/RASession.cpp @@ -19,6 +19,7 @@ #include "AccountMgr.h" #include "Config.h" #include "DatabaseEnv.h" +#include "IpAddress.h" #include "Log.h" #include "Util.h" #include "World.h" diff --git a/src/server/worldserver/RemoteAccess/RASession.h b/src/server/worldserver/RemoteAccess/RASession.h index 23fd4e70c55..37717854ba9 100644 --- a/src/server/worldserver/RemoteAccess/RASession.h +++ b/src/server/worldserver/RemoteAccess/RASession.h @@ -36,7 +36,7 @@ public: void Start(); - std::string GetRemoteIpAddress() const { return _socket.remote_endpoint().address().to_string(); } + boost::asio::ip::address GetRemoteIpAddress() const { return _socket.remote_endpoint().address(); } uint16 GetRemotePort() const { return _socket.remote_endpoint().port(); } private: |