fix timeout protection with tokens

timeout protection code now transfers the token properly
This commit is contained in:
eeeee 2015-03-05 22:33:01 -08:00
parent 1d061986d3
commit 0dc332c931
3 changed files with 8 additions and 6 deletions

View file

@ -205,7 +205,8 @@ 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; }
void SetTimedOut(const NETADDR *pAddr, int Sequence, int Ack); int SecurityToken() const { return m_SecurityToken; }
void SetTimedOut(const NETADDR *pAddr, int Sequence, int Ack, SECURITY_TOKEN SecurityToken);
}; };
class CConsoleNetConnection class CConsoleNetConnection

View file

@ -200,17 +200,17 @@ void CNetConnection::Disconnect(const char *pReason)
int CNetConnection::Feed(CNetPacketConstruct *pPacket, NETADDR *pAddr, SECURITY_TOKEN SecurityToken) int CNetConnection::Feed(CNetPacketConstruct *pPacket, NETADDR *pAddr, SECURITY_TOKEN SecurityToken)
{ {
if (m_SecurityToken != NET_SECURITY_TOKEN_UNKNOWN && m_SecurityToken != NET_SECURITY_TOKEN_UNSUPPORTED) if (State() != NET_CONNSTATE_OFFLINE && m_SecurityToken != NET_SECURITY_TOKEN_UNKNOWN && m_SecurityToken != NET_SECURITY_TOKEN_UNSUPPORTED)
{ {
// supposed to have a valid token in this packet, check it // supposed to have a valid token in this packet, check it
if (pPacket->m_DataSize < sizeof(m_SecurityToken)) if (pPacket->m_DataSize < sizeof(m_SecurityToken))
return -1; return 0;
pPacket->m_DataSize -= sizeof(m_SecurityToken); pPacket->m_DataSize -= sizeof(m_SecurityToken);
if (m_SecurityToken != *(SECURITY_TOKEN*)&pPacket->m_aChunkData[pPacket->m_DataSize]) if (m_SecurityToken != *(SECURITY_TOKEN*)&pPacket->m_aChunkData[pPacket->m_DataSize])
{ {
if(g_Config.m_Debug) if(g_Config.m_Debug)
dbg_msg("security", "token mismatch, expected %d got %d", m_SecurityToken, *(SECURITY_TOKEN*)&pPacket->m_aChunkData[pPacket->m_DataSize]); dbg_msg("security", "token mismatch, expected %d got %d", m_SecurityToken, *(SECURITY_TOKEN*)&pPacket->m_aChunkData[pPacket->m_DataSize]);
return -1; return 0;
} }
} }
@ -418,7 +418,7 @@ int CNetConnection::Update()
return 0; return 0;
} }
void CNetConnection::SetTimedOut(const NETADDR *pAddr, int Sequence, int Ack) void CNetConnection::SetTimedOut(const NETADDR *pAddr, int Sequence, int Ack, SECURITY_TOKEN SecurityToken)
{ {
int64 Now = time_get(); int64 Now = time_get();
@ -432,5 +432,6 @@ void CNetConnection::SetTimedOut(const NETADDR *pAddr, int Sequence, int Ack)
m_LastSendTime = Now; m_LastSendTime = Now;
m_LastRecvTime = Now; m_LastRecvTime = Now;
m_LastUpdateTime = Now; m_LastUpdateTime = Now;
m_SecurityToken = SecurityToken;
m_Buffer.Init(); m_Buffer.Init();
} }

View file

@ -294,7 +294,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[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.Reset(); m_aSlots[OrigID].m_Connection.Reset();
return true; return true;
} }