Antispoof: fix error state

This commit is contained in:
east 2015-08-23 12:29:41 +02:00
parent 982737909f
commit 09166494a5
2 changed files with 22 additions and 23 deletions

View file

@ -301,7 +301,8 @@ class CNetServer
void OnTokenCtrlMsg(NETADDR &Addr, int ControlMsg, const CNetPacketConstruct &Packet); void OnTokenCtrlMsg(NETADDR &Addr, int ControlMsg, const CNetPacketConstruct &Packet);
void OnPreConnMsg(NETADDR &Addr, CNetPacketConstruct &Packet); void OnPreConnMsg(NETADDR &Addr, CNetPacketConstruct &Packet);
bool ClientExists(const NETADDR &Addr); bool ClientExists(const NETADDR &Addr) { return GetClientSlot(Addr) != -1; };
int GetClientSlot(const NETADDR &Addr);
void SendControl(NETADDR &Addr, int ControlMsg, const void *pExtra, int ExtraSize, SECURITY_TOKEN SecurityToken); void SendControl(NETADDR &Addr, int ControlMsg, const void *pExtra, int ExtraSize, SECURITY_TOKEN SecurityToken);
int TryAcceptClient(NETADDR &Addr, SECURITY_TOKEN SecurityToken, bool VanillaAuth=false); int TryAcceptClient(NETADDR &Addr, SECURITY_TOKEN SecurityToken, bool VanillaAuth=false);

View file

@ -143,7 +143,8 @@ int CNetServer::NumClientsWithAddr(NETADDR Addr)
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 ||
m_aSlots[i].m_Connection.State() == NET_CONNSTATE_ERROR)
continue; continue;
OtherAddr = *m_aSlots[i].m_Connection.PeerAddress(); OtherAddr = *m_aSlots[i].m_Connection.PeerAddress();
@ -404,20 +405,22 @@ void CNetServer::OnTokenCtrlMsg(NETADDR &Addr, int ControlMsg, const CNetPacketC
} }
} }
bool CNetServer::ClientExists(const NETADDR &Addr) int CNetServer::GetClientSlot(const NETADDR &Addr)
{ {
int Slot = -1;
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 &&
m_aSlots[i].m_Connection.State() != NET_CONNSTATE_ERROR &&
net_addr_comp(m_aSlots[i].m_Connection.PeerAddress(), &Addr) == 0) net_addr_comp(m_aSlots[i].m_Connection.PeerAddress(), &Addr) == 0)
{ {
// found Slot = i;
return true;
} }
} }
// doesn't exist return Slot;
return false;
} }
/* /*
@ -463,26 +466,21 @@ int CNetServer::Recv(CNetChunk *pChunk)
else else
{ {
// normal packet, find matching slot // normal packet, find matching slot
bool Found = false; int Slot = GetClientSlot(Addr);
for(int i = 0; i < MaxClients(); i++)
{
if(net_addr_comp(m_aSlots[i].m_Connection.PeerAddress(), &Addr) == 0)
{
if(m_aSlots[i].m_Connection.State() == NET_CONNSTATE_OFFLINE ||
m_aSlots[i].m_Connection.State() == NET_CONNSTATE_ERROR)
continue;
Found = true; if (Slot != -1)
if(m_aSlots[i].m_Connection.Feed(&m_RecvUnpacker.m_Data, &Addr)) {
{ // found
if(m_RecvUnpacker.m_Data.m_DataSize) if(m_aSlots[Slot].m_Connection.Feed(&m_RecvUnpacker.m_Data, &Addr))
m_RecvUnpacker.Start(&Addr, &m_aSlots[i].m_Connection, i); {
} if(m_RecvUnpacker.m_Data.m_DataSize)
m_RecvUnpacker.Start(&Addr, &m_aSlots[Slot].m_Connection, Slot);
} }
} }
else
if (!Found)
{ {
// not found, client that wants to connect
if(m_RecvUnpacker.m_Data.m_Flags&NET_PACKETFLAG_CONTROL && if(m_RecvUnpacker.m_Data.m_Flags&NET_PACKETFLAG_CONTROL &&
m_RecvUnpacker.m_Data.m_DataSize > 1) m_RecvUnpacker.m_Data.m_DataSize > 1)
// got control msg with extra size (should support token) // got control msg with extra size (should support token)