some token polishing

This commit is contained in:
oy 2018-11-20 19:58:01 +01:00
parent 3010a3ad54
commit 7b51a1f03e
4 changed files with 8 additions and 14 deletions

View file

@ -182,9 +182,9 @@ public:
void GenerateSeed();
int ProcessMessage(const NETADDR *pAddr, const CNetPacketConstruct *pPacket, bool Notify);
int ProcessMessage(const NETADDR *pAddr, const CNetPacketConstruct *pPacket);
bool CheckToken(const NETADDR *pAddr, TOKEN Token, TOKEN ResponseToken, bool Notify, bool *BroadcastResponse);
bool CheckToken(const NETADDR *pAddr, TOKEN Token, TOKEN ResponseToken, bool *BroadcastResponse);
TOKEN GenerateToken(const NETADDR *pAddr) const;
static TOKEN GenerateToken(const NETADDR *pAddr, int64 Seed);

View file

@ -90,7 +90,7 @@ int CNetClient::Recv(CNetChunk *pChunk, TOKEN *pResponseToken)
}
else
{
int Accept = m_TokenManager.ProcessMessage(&Addr, &m_RecvUnpacker.m_Data, true);
int Accept = m_TokenManager.ProcessMessage(&Addr, &m_RecvUnpacker.m_Data);
if(!Accept)
continue;

View file

@ -159,7 +159,7 @@ int CNetServer::Recv(CNetChunk *pChunk, TOKEN *pResponseToken)
if(Found)
continue;
int Accept = m_TokenManager.ProcessMessage(&Addr, &m_RecvUnpacker.m_Data, true);
int Accept = m_TokenManager.ProcessMessage(&Addr, &m_RecvUnpacker.m_Data);
if(Accept <= 0)
continue;
@ -199,7 +199,6 @@ int CNetServer::Recv(CNetChunk *pChunk, TOKEN *pResponseToken)
Found = true;
m_aSlots[i].m_Connection.SetToken(m_RecvUnpacker.m_Data.m_Token);
m_aSlots[i].m_Connection.Feed(&m_RecvUnpacker.m_Data, &Addr);
m_aSlots[i].m_Connection.SetToken(m_RecvUnpacker.m_Data.m_Token); // HACK!
if(m_pfnNewClient)
m_pfnNewClient(i, m_UserPtr);
break;
@ -212,8 +211,6 @@ int CNetServer::Recv(CNetChunk *pChunk, TOKEN *pResponseToken)
CNetBase::SendControlMsg(m_Socket, &Addr, m_RecvUnpacker.m_Data.m_ResponseToken, 0, NET_CTRLMSG_CLOSE, FullMsg, sizeof(FullMsg));
}
}
else if(m_RecvUnpacker.m_Data.m_aChunkData[0] == NET_CTRLMSG_TOKEN)
m_TokenCache.AddToken(&Addr, m_RecvUnpacker.m_Data.m_ResponseToken, false);
}
else if(m_RecvUnpacker.m_Data.m_Flags&NET_PACKETFLAG_CONNLESS)
{

View file

@ -35,11 +35,11 @@ void CNetTokenManager::Update()
GenerateSeed();
}
int CNetTokenManager::ProcessMessage(const NETADDR *pAddr, const CNetPacketConstruct *pPacket, bool Notify)
int CNetTokenManager::ProcessMessage(const NETADDR *pAddr, const CNetPacketConstruct *pPacket)
{
bool BroadcastResponse = false;
if(pPacket->m_Token != NET_TOKEN_NONE
&& !CheckToken(pAddr, pPacket->m_Token, pPacket->m_ResponseToken, Notify, &BroadcastResponse))
&& !CheckToken(pAddr, pPacket->m_Token, pPacket->m_ResponseToken, &BroadcastResponse))
return 0; // wrong token, silent ignore
bool Verified = pPacket->m_Token != NET_TOKEN_NONE;
@ -113,7 +113,7 @@ TOKEN CNetTokenManager::GenerateToken(const NETADDR *pAddr, int64 Seed)
return Result;
}
bool CNetTokenManager::CheckToken(const NETADDR *pAddr, TOKEN Token, TOKEN ResponseToken, bool Notify, bool *BroadcastResponse)
bool CNetTokenManager::CheckToken(const NETADDR *pAddr, TOKEN Token, TOKEN ResponseToken, bool *BroadcastResponse)
{
TOKEN CurrentToken = GenerateToken(pAddr, m_Seed);
if(CurrentToken == Token)
@ -121,10 +121,7 @@ bool CNetTokenManager::CheckToken(const NETADDR *pAddr, TOKEN Token, TOKEN Respo
if(GenerateToken(pAddr, m_PrevSeed) == Token)
{
if(Notify)
CNetBase::SendControlMsgWithToken(m_Socket, (NETADDR *)pAddr,
ResponseToken, 0, NET_CTRLMSG_TOKEN, CurrentToken);
// notify the peer about the new token
// no need to notify the peer, just a one time thing
return true;
}
else if(Token == m_GlobalToken)