mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 14:38:18 +00:00
DRY with net_addr_comp_noport
This commit is contained in:
parent
254ff3dc6b
commit
5b95eddca1
|
@ -239,13 +239,9 @@ int CRegister::RegisterProcessPacket(CNetChunk *pPacket)
|
||||||
{
|
{
|
||||||
// check for masterserver address
|
// check for masterserver address
|
||||||
bool Valid = false;
|
bool Valid = false;
|
||||||
NETADDR Addr1 = pPacket->m_Address;
|
|
||||||
Addr1.port = 0;
|
|
||||||
for(int i = 0; i < IMasterServer::MAX_MASTERSERVERS; i++)
|
for(int i = 0; i < IMasterServer::MAX_MASTERSERVERS; i++)
|
||||||
{
|
{
|
||||||
NETADDR Addr2 = m_aMasterserverInfo[i].m_Addr;
|
if(net_addr_comp_noport(&pPacket->m_Address, &m_aMasterserverInfo[i].m_Addr) == 0)
|
||||||
Addr2.port = 0;
|
|
||||||
if(net_addr_comp(&Addr1, &Addr2) == 0)
|
|
||||||
{
|
{
|
||||||
Valid = true;
|
Valid = true;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -312,12 +312,8 @@ int CNetConnection::Feed(CNetPacketConstruct *pPacket, NETADDR *pAddr, SECURITY_
|
||||||
{
|
{
|
||||||
if(CtrlMsg == NET_CTRLMSG_CONNECT)
|
if(CtrlMsg == NET_CTRLMSG_CONNECT)
|
||||||
{
|
{
|
||||||
NETADDR nAddr;
|
|
||||||
mem_copy(&nAddr, pAddr, sizeof(nAddr));
|
|
||||||
nAddr.port = 0;
|
|
||||||
m_PeerAddr.port = 0;
|
|
||||||
#ifndef FUZZING
|
#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;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -168,11 +168,7 @@ void CNetServer::SendControl(NETADDR &Addr, int ControlMsg, const void *pExtra,
|
||||||
|
|
||||||
int CNetServer::NumClientsWithAddr(NETADDR Addr)
|
int CNetServer::NumClientsWithAddr(NETADDR Addr)
|
||||||
{
|
{
|
||||||
NETADDR ThisAddr = Addr, OtherAddr;
|
|
||||||
|
|
||||||
int FoundAddr = 0;
|
int FoundAddr = 0;
|
||||||
ThisAddr.port = 0;
|
|
||||||
|
|
||||||
for(int i = 0; i < MaxClients(); ++i)
|
for(int i = 0; i < MaxClients(); ++i)
|
||||||
{
|
{
|
||||||
if(m_aSlots[i].m_Connection.State() == NET_CONNSTATE_OFFLINE ||
|
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)))
|
!m_aSlots[i].m_Connection.m_TimeoutSituation)))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
OtherAddr = *m_aSlots[i].m_Connection.PeerAddress();
|
if(!net_addr_comp_noport(&Addr, m_aSlots[i].m_Connection.PeerAddress()))
|
||||||
OtherAddr.port = 0;
|
|
||||||
if(!net_addr_comp(&ThisAddr, &OtherAddr))
|
|
||||||
FoundAddr++;
|
FoundAddr++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -351,12 +351,10 @@ void CGameContext::VoteMute(IConsole::IResult *pResult, NETADDR *pAddr, int Secs
|
||||||
char aBuf[128];
|
char aBuf[128];
|
||||||
bool Found = 0;
|
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
|
// find a matching vote mute for this ip, update expiration time if found
|
||||||
for(int i = 0; i < m_NumVoteMutes; i++)
|
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()
|
m_aVoteMutes[i].m_Expire = Server()->Tick()
|
||||||
+ Secs * Server()->TickSpeed();
|
+ 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");
|
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)
|
const char *pDisplayName)
|
||||||
{
|
{
|
||||||
char aBuf[128];
|
char aBuf[128];
|
||||||
int Found = 0;
|
int Found = 0;
|
||||||
|
|
||||||
Addr->port = 0; // ignore port number for mutes
|
|
||||||
|
|
||||||
// find a matching mute for this ip, update expiration time if found
|
// find a matching mute for this ip, update expiration time if found
|
||||||
for (int i = 0; i < m_NumMutes; i++)
|
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()
|
m_aMutes[i].m_Expire = Server()->Tick()
|
||||||
+ Secs * Server()->TickSpeed();
|
+ Secs * Server()->TickSpeed();
|
||||||
|
@ -412,7 +408,7 @@ void CGameContext::Mute(IConsole::IResult *pResult, NETADDR *Addr, int Secs,
|
||||||
{
|
{
|
||||||
if (m_NumMutes < MAX_MUTES)
|
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()
|
m_aMutes[m_NumMutes].m_Expire = Server()->Tick()
|
||||||
+ Secs * Server()->TickSpeed();
|
+ Secs * Server()->TickSpeed();
|
||||||
m_NumMutes++;
|
m_NumMutes++;
|
||||||
|
@ -464,7 +460,7 @@ void CGameContext::ConMuteID(IConsole::IResult *pResult, void *pUserData)
|
||||||
{
|
{
|
||||||
CGameContext *pSelf = (CGameContext *) pUserData;
|
CGameContext *pSelf = (CGameContext *) pUserData;
|
||||||
int Victim = pResult->GetVictim();
|
int Victim = pResult->GetVictim();
|
||||||
|
|
||||||
if (Victim < 0 || Victim > MAX_CLIENTS || !pSelf->m_apPlayers[Victim])
|
if (Victim < 0 || Victim > MAX_CLIENTS || !pSelf->m_apPlayers[Victim])
|
||||||
{
|
{
|
||||||
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "muteid", "Client id not found.");
|
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)
|
void CGameContext::ConMutes(IConsole::IResult *pResult, void *pUserData)
|
||||||
{
|
{
|
||||||
CGameContext *pSelf = (CGameContext *) pUserData;
|
CGameContext *pSelf = (CGameContext *) pUserData;
|
||||||
|
|
||||||
if (pSelf->m_NumMutes <= 0)
|
if (pSelf->m_NumMutes <= 0)
|
||||||
{
|
{
|
||||||
// Just to make sure.
|
// Just to make sure.
|
||||||
|
@ -523,7 +519,7 @@ void CGameContext::ConMutes(IConsole::IResult *pResult, void *pUserData)
|
||||||
"There are no active mutes.");
|
"There are no active mutes.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
char aIpBuf[64];
|
char aIpBuf[64];
|
||||||
char aBuf[128];
|
char aBuf[128];
|
||||||
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "mutes",
|
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.");
|
str_format(aBuf, sizeof(aBuf), "Server kick/spec votes are no longer actively moderated.");
|
||||||
|
|
||||||
pSelf->SendChat(-1, CHAT_ALL, aBuf, 0);
|
pSelf->SendChat(-1, CHAT_ALL, aBuf, 0);
|
||||||
|
|
||||||
if(pPlayer->m_Moderating)
|
if(pPlayer->m_Moderating)
|
||||||
pSelf->SendChatTarget(pResult->m_ClientID, "Active moderator mode enabled for you.");
|
pSelf->SendChatTarget(pResult->m_ClientID, "Active moderator mode enabled for you.");
|
||||||
else
|
else
|
||||||
|
@ -636,6 +632,6 @@ void CGameContext::ConUnFreezeHammer(IConsole::IResult *pResult, void *pUserData
|
||||||
void CGameContext::ConVoteNo(IConsole::IResult *pResult, void *pUserData)
|
void CGameContext::ConVoteNo(IConsole::IResult *pResult, void *pUserData)
|
||||||
{
|
{
|
||||||
CGameContext *pSelf = (CGameContext *)pUserData;
|
CGameContext *pSelf = (CGameContext *)pUserData;
|
||||||
|
|
||||||
pSelf->ForceVote(pResult->m_ClientID, false);
|
pSelf->ForceVote(pResult->m_ClientID, false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1382,10 +1382,9 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID)
|
||||||
|
|
||||||
NETADDR Addr;
|
NETADDR Addr;
|
||||||
Server()->GetClientAddr(ClientID, &Addr);
|
Server()->GetClientAddr(ClientID, &Addr);
|
||||||
Addr.port = 0; // ignore port number
|
|
||||||
int VoteMuted = 0;
|
int VoteMuted = 0;
|
||||||
for(int i = 0; i < m_NumVoteMutes && !VoteMuted; i++)
|
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();
|
VoteMuted = (m_aVoteMutes[i].m_Expire - Server()->Tick()) / Server()->TickSpeed();
|
||||||
if(VoteMuted > 0)
|
if(VoteMuted > 0)
|
||||||
{
|
{
|
||||||
|
@ -3280,12 +3279,11 @@ int CGameContext::ProcessSpamProtection(int ClientID)
|
||||||
m_apPlayers[ClientID]->m_LastChat = Server()->Tick();
|
m_apPlayers[ClientID]->m_LastChat = Server()->Tick();
|
||||||
NETADDR Addr;
|
NETADDR Addr;
|
||||||
Server()->GetClientAddr(ClientID, &Addr);
|
Server()->GetClientAddr(ClientID, &Addr);
|
||||||
Addr.port = 0; // ignore port number for mutes
|
|
||||||
int Muted = 0;
|
int Muted = 0;
|
||||||
|
|
||||||
for(int i = 0; i < m_NumMutes && !Muted; i++)
|
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();
|
Muted = (m_aMutes[i].m_Expire - Server()->Tick()) / Server()->TickSpeed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue