Skip to content

Commit

Permalink
Merge pull request ddnet#8574 from Learath2/dd_pr_antibot_netaddr
Browse files Browse the repository at this point in the history
net_addr_str only once
  • Loading branch information
def- authored Jul 9, 2024
2 parents 076bfc6 + 7fa0ef5 commit fa9f7b4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/engine/server/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2285,7 +2285,7 @@ void CServer::FillAntibot(CAntibotRoundData *pData)
for(int i = 0; i < MAX_CLIENTS; i++)
{
CAntibotPlayerData *pPlayer = &pData->m_aPlayers[i];
net_addr_str(m_NetServer.ClientAddr(i), pPlayer->m_aAddress, sizeof(pPlayer->m_aAddress), true);
str_copy(pPlayer->m_aAddress, m_NetServer.ClientAddrString(i));
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/engine/shared/network.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ class CNetConnection
NETSOCKET m_Socket;
NETSTATS m_Stats;

char m_aPeerAddrStr[NETADDR_MAXSTRSIZE];

//
void ResetStats();
void SetError(const char *pString);
Expand Down Expand Up @@ -268,6 +270,7 @@ class CNetConnection
void SignalResend();
int State() const { return m_State; }
const NETADDR *PeerAddress() const { return &m_PeerAddr; }
const char *PeerAddressString() const { return m_aPeerAddrStr; }
void ConnectAddresses(const NETADDR **ppAddrs, int *pNumAddrs) const
{
*ppAddrs = m_aConnectAddrs;
Expand Down Expand Up @@ -417,6 +420,7 @@ class CNetServer

// 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(); }
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; }
Expand Down
4 changes: 4 additions & 0 deletions src/engine/shared/network_conn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ void CNetConnection::Reset(bool Rejoin)
m_Buffer.Init();

mem_zero(&m_Construct, sizeof(m_Construct));
m_aPeerAddrStr[0] = '\0';
}

const char *CNetConnection::ErrorString()
Expand Down Expand Up @@ -240,6 +241,7 @@ void CNetConnection::DirectInit(const NETADDR &Addr, SECURITY_TOKEN SecurityToke
m_State = NET_CONNSTATE_ONLINE;

m_PeerAddr = Addr;
net_addr_str(&Addr, m_aPeerAddrStr, sizeof(m_aPeerAddrStr), true);
mem_zero(m_aErrorString, sizeof(m_aErrorString));

int64_t Now = time_get();
Expand Down Expand Up @@ -353,6 +355,7 @@ int CNetConnection::Feed(CNetPacketConstruct *pPacket, NETADDR *pAddr, SECURITY_
Reset();
m_State = NET_CONNSTATE_PENDING;
m_PeerAddr = *pAddr;
net_addr_str(pAddr, m_aPeerAddrStr, sizeof(m_aPeerAddrStr), true);
mem_zero(m_aErrorString, sizeof(m_aErrorString));
m_LastSendTime = Now;
m_LastRecvTime = Now;
Expand Down Expand Up @@ -380,6 +383,7 @@ int CNetConnection::Feed(CNetPacketConstruct *pPacket, NETADDR *pAddr, SECURITY_
if(CtrlMsg == NET_CTRLMSG_CONNECTACCEPT)
{
m_PeerAddr = *pAddr;
net_addr_str(pAddr, m_aPeerAddrStr, sizeof(m_aPeerAddrStr), true);
if(m_SecurityToken == NET_SECURITY_TOKEN_UNKNOWN && pPacket->m_DataSize >= (int)(1 + sizeof(SECURITY_TOKEN_MAGIC) + sizeof(m_SecurityToken)) && !mem_comp(&pPacket->m_aChunkData[1], SECURITY_TOKEN_MAGIC, sizeof(SECURITY_TOKEN_MAGIC)))
{
m_SecurityToken = ToSecurityToken(&pPacket->m_aChunkData[1 + sizeof(SECURITY_TOKEN_MAGIC)]);
Expand Down

0 comments on commit fa9f7b4

Please sign in to comment.