aboutsummaryrefslogtreecommitdiff
path: root/src/server
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2025-06-02 18:38:41 +0200
committerShauren <shauren.trinity@gmail.com>2025-06-02 18:38:41 +0200
commit74d9da7f3257c510b4f99fca635c5a9971053300 (patch)
tree7a12179eb0b716e82ff755e1f0e90594070f2a4e /src/server
parent2d984fcade155bf860ed20713a95251ad0103318 (diff)
Core/Network: Make ip address formattable with fmt
Diffstat (limited to 'src/server')
-rw-r--r--src/server/game/Server/WorldSocket.cpp69
-rw-r--r--src/server/shared/Networking/ConnectionInitializers/IpBanCheckConnectionInitializer.cpp4
-rw-r--r--src/server/shared/Networking/ConnectionInitializers/IpBanCheckConnectionInitializer.h7
-rw-r--r--src/server/worldserver/RemoteAccess/RASession.cpp1
-rw-r--r--src/server/worldserver/RemoteAccess/RASession.h2
5 files changed, 47 insertions, 36 deletions
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: