Merge pull request #475 from east/timeoutprotfix

Copy resendbuffer on timeout protection
This commit is contained in:
Dennis Felsing 2016-05-07 23:41:54 +02:00
commit 6c771f6bff
3 changed files with 16 additions and 3 deletions

View file

@ -220,7 +220,9 @@ public:
int AckSequence() const { return m_Ack; } int AckSequence() const { return m_Ack; }
int SeqSequence() const { return m_Sequence; } int SeqSequence() const { return m_Sequence; }
int SecurityToken() const { return m_SecurityToken; } int SecurityToken() const { return m_SecurityToken; }
void SetTimedOut(const NETADDR *pAddr, int Sequence, int Ack, SECURITY_TOKEN SecurityToken); TStaticRingBuffer<CNetChunkResend, NET_CONN_BUFFERSIZE> *ResendBuffer() { return &m_Buffer; };
void SetTimedOut(const NETADDR *pAddr, int Sequence, int Ack, SECURITY_TOKEN SecurityToken, TStaticRingBuffer<CNetChunkResend, NET_CONN_BUFFERSIZE> *pResendBuffer);
// anti spoof // anti spoof
void DirectInit(NETADDR &Addr, SECURITY_TOKEN SecurityToken); void DirectInit(NETADDR &Addr, SECURITY_TOKEN SecurityToken);

View file

@ -467,7 +467,7 @@ int CNetConnection::Update()
return 0; return 0;
} }
void CNetConnection::SetTimedOut(const NETADDR *pAddr, int Sequence, int Ack, SECURITY_TOKEN SecurityToken) void CNetConnection::SetTimedOut(const NETADDR *pAddr, int Sequence, int Ack, SECURITY_TOKEN SecurityToken, TStaticRingBuffer<CNetChunkResend, NET_CONN_BUFFERSIZE> *pResendBuffer)
{ {
int64 Now = time_get(); int64 Now = time_get();
@ -482,5 +482,16 @@ void CNetConnection::SetTimedOut(const NETADDR *pAddr, int Sequence, int Ack, SE
m_LastRecvTime = Now; m_LastRecvTime = Now;
m_LastUpdateTime = Now; m_LastUpdateTime = Now;
m_SecurityToken = SecurityToken; m_SecurityToken = SecurityToken;
// copy resend buffer
m_Buffer.Init(); m_Buffer.Init();
while (pResendBuffer->First())
{
CNetChunkResend *First = pResendBuffer->First();
CNetChunkResend *pResend = m_Buffer.Allocate(sizeof(CNetChunkResend)+First->m_DataSize);
mem_copy(pResend, First, sizeof(CNetChunkResend)+First->m_DataSize);
pResendBuffer->PopFirst();
}
} }

View file

@ -684,7 +684,7 @@ bool CNetServer::SetTimedOut(int ClientID, int OrigID)
if (m_aSlots[ClientID].m_Connection.State() != NET_CONNSTATE_ERROR) if (m_aSlots[ClientID].m_Connection.State() != NET_CONNSTATE_ERROR)
return false; return false;
m_aSlots[ClientID].m_Connection.SetTimedOut(ClientAddr(OrigID), m_aSlots[OrigID].m_Connection.SeqSequence(), m_aSlots[OrigID].m_Connection.AckSequence(), m_aSlots[OrigID].m_Connection.SecurityToken()); m_aSlots[ClientID].m_Connection.SetTimedOut(ClientAddr(OrigID), m_aSlots[OrigID].m_Connection.SeqSequence(), m_aSlots[OrigID].m_Connection.AckSequence(), m_aSlots[OrigID].m_Connection.SecurityToken(), m_aSlots[OrigID].m_Connection.ResendBuffer());
m_aSlots[OrigID].m_Connection.Reset(); m_aSlots[OrigID].m_Connection.Reset();
return true; return true;
} }