DRY with net_addr_comp_noport

This commit is contained in:
Learath 2018-10-08 21:04:04 +03:00
parent 254ff3dc6b
commit 5b95eddca1
5 changed files with 14 additions and 34 deletions

View file

@ -239,13 +239,9 @@ int CRegister::RegisterProcessPacket(CNetChunk *pPacket)
{
// check for masterserver address
bool Valid = false;
NETADDR Addr1 = pPacket->m_Address;
Addr1.port = 0;
for(int i = 0; i < IMasterServer::MAX_MASTERSERVERS; i++)
{
NETADDR Addr2 = m_aMasterserverInfo[i].m_Addr;
Addr2.port = 0;
if(net_addr_comp(&Addr1, &Addr2) == 0)
if(net_addr_comp_noport(&pPacket->m_Address, &m_aMasterserverInfo[i].m_Addr) == 0)
{
Valid = true;
break;

View file

@ -312,12 +312,8 @@ int CNetConnection::Feed(CNetPacketConstruct *pPacket, NETADDR *pAddr, SECURITY_
{
if(CtrlMsg == NET_CTRLMSG_CONNECT)
{
NETADDR nAddr;
mem_copy(&nAddr, pAddr, sizeof(nAddr));
nAddr.port = 0;
m_PeerAddr.port = 0;
#ifndef FUZZING
if(net_addr_comp(&m_PeerAddr, &nAddr) == 0 && time_get() - m_LastUpdateTime < time_freq() * 3)
if(net_addr_comp_noport(&m_PeerAddr, pAddr) == 0 && time_get() - m_LastUpdateTime < time_freq() * 3)
return 0;
#endif

View file

@ -168,11 +168,7 @@ void CNetServer::SendControl(NETADDR &Addr, int ControlMsg, const void *pExtra,
int CNetServer::NumClientsWithAddr(NETADDR Addr)
{
NETADDR ThisAddr = Addr, OtherAddr;
int FoundAddr = 0;
ThisAddr.port = 0;
for(int i = 0; i < MaxClients(); ++i)
{
if(m_aSlots[i].m_Connection.State() == NET_CONNSTATE_OFFLINE ||
@ -181,9 +177,7 @@ int CNetServer::NumClientsWithAddr(NETADDR Addr)
!m_aSlots[i].m_Connection.m_TimeoutSituation)))
continue;
OtherAddr = *m_aSlots[i].m_Connection.PeerAddress();
OtherAddr.port = 0;
if(!net_addr_comp(&ThisAddr, &OtherAddr))
if(!net_addr_comp_noport(&Addr, m_aSlots[i].m_Connection.PeerAddress()))
FoundAddr++;
}

View file

@ -351,12 +351,10 @@ void CGameContext::VoteMute(IConsole::IResult *pResult, NETADDR *pAddr, int Secs
char aBuf[128];
bool Found = 0;
pAddr->port = 0; // ignore port number for vote mutes
// find a matching vote mute for this ip, update expiration time if found
for(int i = 0; i < m_NumVoteMutes; i++)
{
if(net_addr_comp(&m_aVoteMutes[i].m_Addr, pAddr) == 0)
if(net_addr_comp_noport(&m_aVoteMutes[i].m_Addr, pAddr) == 0)
{
m_aVoteMutes[i].m_Expire = Server()->Tick()
+ Secs * Server()->TickSpeed();
@ -389,18 +387,16 @@ void CGameContext::VoteMute(IConsole::IResult *pResult, NETADDR *pAddr, int Secs
Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "votemute", "vote mute array is full");
}
void CGameContext::Mute(IConsole::IResult *pResult, NETADDR *Addr, int Secs,
void CGameContext::Mute(IConsole::IResult *pResult, NETADDR *pAddr, int Secs,
const char *pDisplayName)
{
char aBuf[128];
int Found = 0;
Addr->port = 0; // ignore port number for mutes
// find a matching mute for this ip, update expiration time if found
for (int i = 0; i < m_NumMutes; i++)
{
if (net_addr_comp(&m_aMutes[i].m_Addr, Addr) == 0)
if (net_addr_comp_noport(&m_aMutes[i].m_Addr, pAddr) == 0)
{
m_aMutes[i].m_Expire = Server()->Tick()
+ Secs * Server()->TickSpeed();
@ -412,7 +408,7 @@ void CGameContext::Mute(IConsole::IResult *pResult, NETADDR *Addr, int Secs,
{
if (m_NumMutes < MAX_MUTES)
{
m_aMutes[m_NumMutes].m_Addr = *Addr;
m_aMutes[m_NumMutes].m_Addr = *pAddr;
m_aMutes[m_NumMutes].m_Expire = Server()->Tick()
+ Secs * Server()->TickSpeed();
m_NumMutes++;
@ -464,7 +460,7 @@ void CGameContext::ConMuteID(IConsole::IResult *pResult, void *pUserData)
{
CGameContext *pSelf = (CGameContext *) pUserData;
int Victim = pResult->GetVictim();
if (Victim < 0 || Victim > MAX_CLIENTS || !pSelf->m_apPlayers[Victim])
{
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "muteid", "Client id not found.");
@ -514,7 +510,7 @@ void CGameContext::ConUnmute(IConsole::IResult *pResult, void *pUserData)
void CGameContext::ConMutes(IConsole::IResult *pResult, void *pUserData)
{
CGameContext *pSelf = (CGameContext *) pUserData;
if (pSelf->m_NumMutes <= 0)
{
// Just to make sure.
@ -523,7 +519,7 @@ void CGameContext::ConMutes(IConsole::IResult *pResult, void *pUserData)
"There are no active mutes.");
return;
}
char aIpBuf[64];
char aBuf[128];
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "mutes",
@ -563,7 +559,7 @@ void CGameContext::ConModerate(IConsole::IResult *pResult, void *pUserData)
str_format(aBuf, sizeof(aBuf), "Server kick/spec votes are no longer actively moderated.");
pSelf->SendChat(-1, CHAT_ALL, aBuf, 0);
if(pPlayer->m_Moderating)
pSelf->SendChatTarget(pResult->m_ClientID, "Active moderator mode enabled for you.");
else
@ -636,6 +632,6 @@ void CGameContext::ConUnFreezeHammer(IConsole::IResult *pResult, void *pUserData
void CGameContext::ConVoteNo(IConsole::IResult *pResult, void *pUserData)
{
CGameContext *pSelf = (CGameContext *)pUserData;
pSelf->ForceVote(pResult->m_ClientID, false);
}

View file

@ -1382,10 +1382,9 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID)
NETADDR Addr;
Server()->GetClientAddr(ClientID, &Addr);
Addr.port = 0; // ignore port number
int VoteMuted = 0;
for(int i = 0; i < m_NumVoteMutes && !VoteMuted; i++)
if(!net_addr_comp(&Addr, &m_aVoteMutes[i].m_Addr))
if(!net_addr_comp_noport(&Addr, &m_aVoteMutes[i].m_Addr))
VoteMuted = (m_aVoteMutes[i].m_Expire - Server()->Tick()) / Server()->TickSpeed();
if(VoteMuted > 0)
{
@ -3280,12 +3279,11 @@ int CGameContext::ProcessSpamProtection(int ClientID)
m_apPlayers[ClientID]->m_LastChat = Server()->Tick();
NETADDR Addr;
Server()->GetClientAddr(ClientID, &Addr);
Addr.port = 0; // ignore port number for mutes
int Muted = 0;
for(int i = 0; i < m_NumMutes && !Muted; i++)
{
if(!net_addr_comp(&Addr, &m_aMutes[i].m_Addr))
if(!net_addr_comp_noport(&Addr, &m_aMutes[i].m_Addr))
Muted = (m_aMutes[i].m_Expire - Server()->Tick()) / Server()->TickSpeed();
}