From 108d0dc715978893f5aca7957bfec85b6683fe91 Mon Sep 17 00:00:00 2001 From: Dennis Felsing Date: Wed, 10 Jul 2024 12:18:32 +0200 Subject: [PATCH] Make FillAntibot faster --- src/engine/server/server.cpp | 6 +++++- src/engine/shared/network.h | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp index dba3bf89d..ab641ddc6 100644 --- a/src/engine/server/server.cpp +++ b/src/engine/server/server.cpp @@ -2285,7 +2285,11 @@ void CServer::FillAntibot(CAntibotRoundData *pData) for(int i = 0; i < MAX_CLIENTS; i++) { CAntibotPlayerData *pPlayer = &pData->m_aPlayers[i]; - str_copy(pPlayer->m_aAddress, m_NetServer.ClientAddrString(i)); + // No need for expensive str_copy since we don't truncate and the string is + // ASCII anyway + static_assert(std::size((CAntibotPlayerData{}).m_aAddress) >= NETADDR_MAXSTRSIZE); + static_assert(sizeof(*(CNetServer{}).ClientAddrString(i)) == NETADDR_MAXSTRSIZE); + mem_copy(pPlayer->m_aAddress, m_NetServer.ClientAddrString(i), NETADDR_MAXSTRSIZE); } } diff --git a/src/engine/shared/network.h b/src/engine/shared/network.h index 4e27d16e7..2e2ec65c6 100644 --- a/src/engine/shared/network.h +++ b/src/engine/shared/network.h @@ -270,7 +270,7 @@ public: void SignalResend(); int State() const { return m_State; } const NETADDR *PeerAddress() const { return &m_PeerAddr; } - const char *PeerAddressString() const { return m_aPeerAddrStr; } + const char (*PeerAddressString() const)[NETADDR_MAXSTRSIZE] { return &m_aPeerAddrStr; } void ConnectAddresses(const NETADDR **ppAddrs, int *pNumAddrs) const { *ppAddrs = m_aConnectAddrs; @@ -420,7 +420,7 @@ public: // status requests const NETADDR *ClientAddr(int ClientId) const { return m_aSlots[ClientId].m_Connection.PeerAddress(); } - const char *ClientAddrString(int ClientID) const { return m_aSlots[ClientID].m_Connection.PeerAddressString(); } + const char (*ClientAddrString(int ClientID) const)[NETADDR_MAXSTRSIZE] { return m_aSlots[ClientID].m_Connection.PeerAddressString(); } bool HasSecurityToken(int ClientId) const { return m_aSlots[ClientId].m_Connection.SecurityToken() != NET_SECURITY_TOKEN_UNSUPPORTED; } NETADDR Address() const { return m_Address; } NETSOCKET Socket() const { return m_Socket; }