Merge pull request #300 from east/timeoutfix

Fixes current problems with timeout protection
This commit is contained in:
Dennis Felsing 2015-08-23 14:11:23 +02:00
commit 466fcf063a
3 changed files with 25 additions and 23 deletions

View file

@ -301,7 +301,8 @@ class CNetServer
void OnTokenCtrlMsg(NETADDR &Addr, int ControlMsg, const 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);
int TryAcceptClient(NETADDR &Addr, SECURITY_TOKEN SecurityToken, bool VanillaAuth=false);

View file

@ -98,6 +98,9 @@ int CNetConnection::Flush()
int CNetConnection::QueueChunkEx(int Flags, int DataSize, const void *pData, int Sequence)
{
if (m_State == NET_CONNSTATE_OFFLINE || m_State == NET_CONNSTATE_ERROR)
return -1;
unsigned char *pChunkData;
// check if we have space for it, if not, flush the connection

View file

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