Skip to content

Commit

Permalink
Merge pull request ddnet#9409 from Robyt3/Server-GetClientAddr-Fixes
Browse files Browse the repository at this point in the history
Add assertions to `CServer::GetClientAddr` functions, avoid string-based address comparison for `sv_vote_kick_min`
  • Loading branch information
def- authored Dec 20, 2024
2 parents b52f1a4 + b8af61d commit 168391f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions src/engine/server/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -621,8 +621,9 @@ void CServer::SetClientDDNetVersion(int ClientId, int DDNetVersion)

void CServer::GetClientAddr(int ClientId, char *pAddrStr, int Size) const
{
if(ClientId >= 0 && ClientId < MAX_CLIENTS && m_aClients[ClientId].m_State == CClient::STATE_INGAME)
net_addr_str(m_NetServer.ClientAddr(ClientId), pAddrStr, Size, false);
NETADDR Addr;
GetClientAddr(ClientId, &Addr);
net_addr_str(&Addr, pAddrStr, Size, false);
}

const char *CServer::ClientName(int ClientId) const
Expand Down Expand Up @@ -3968,10 +3969,9 @@ CServer *CreateServer() { return new CServer(); }

void CServer::GetClientAddr(int ClientId, NETADDR *pAddr) const
{
if(ClientId >= 0 && ClientId < MAX_CLIENTS && m_aClients[ClientId].m_State == CClient::STATE_INGAME)
{
*pAddr = *m_NetServer.ClientAddr(ClientId);
}
dbg_assert(ClientId >= 0 && ClientId < MAX_CLIENTS, "ClientId is not valid");
dbg_assert(m_aClients[ClientId].m_State != CServer::CClient::STATE_EMPTY, "Client slot is empty");
*pAddr = *m_NetServer.ClientAddr(ClientId);
}

void CServer::ReadAnnouncementsFile()
Expand Down
6 changes: 3 additions & 3 deletions src/game/server/gamecontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2326,12 +2326,12 @@ void CGameContext::OnCallVoteNetMessage(const CNetMsg_Cl_CallVote *pMsg, int Cli

if(g_Config.m_SvVoteKickMin && !GetDDRaceTeam(ClientId))
{
char aaAddresses[MAX_CLIENTS][NETADDR_MAXSTRSIZE] = {{0}};
NETADDR aAddresses[MAX_CLIENTS];
for(int i = 0; i < MAX_CLIENTS; i++)
{
if(m_apPlayers[i])
{
Server()->GetClientAddr(i, aaAddresses[i], NETADDR_MAXSTRSIZE);
Server()->GetClientAddr(i, &aAddresses[i]);
}
}
int NumPlayers = 0;
Expand All @@ -2344,7 +2344,7 @@ void CGameContext::OnCallVoteNetMessage(const CNetMsg_Cl_CallVote *pMsg, int Cli
{
if(m_apPlayers[j] && m_apPlayers[j]->GetTeam() != TEAM_SPECTATORS && !GetDDRaceTeam(j))
{
if(str_comp(aaAddresses[i], aaAddresses[j]) == 0)
if(!net_addr_comp_noport(&aAddresses[i], &aAddresses[j]))
{
NumPlayers--;
break;
Expand Down

0 comments on commit 168391f

Please sign in to comment.