diff --git a/src/engine/server/register.cpp b/src/engine/server/register.cpp index 8dc4f9a75..db2ff25f9 100644 --- a/src/engine/server/register.cpp +++ b/src/engine/server/register.cpp @@ -266,6 +266,7 @@ int CRegister::RegisterProcessPacket(CNetChunk *pPacket, TOKEN Token) if(m_RegisterFirst && m_RegisterState != REGISTERSTATE_REGISTERED) m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "register", "no firewall/nat problems detected"); RegisterNewState(REGISTERSTATE_REGISTERED); + m_pNetServer->AddToken(&pPacket->m_Address, Token); return 1; } else if(pPacket->m_DataSize == sizeof(SERVERBROWSE_FWERROR) && diff --git a/src/engine/shared/network.h b/src/engine/shared/network.h index 5500167b9..cd9d094c2 100644 --- a/src/engine/shared/network.h +++ b/src/engine/shared/network.h @@ -82,16 +82,19 @@ enum NET_PACKETFLAG_CONNLESS=8, // token - NET_SEEDTIME = 10, + NET_SEEDTIME = 16, NET_TOKENCACHE_SIZE = 64, - NET_TOKENCACHE_ADDRESSEXPIRY = NET_SEEDTIME/2, - NET_TOKENCACHE_PACKETEXPIRY = NET_TOKENCACHE_ADDRESSEXPIRY, + NET_TOKENCACHE_ADDRESSEXPIRY = NET_SEEDTIME, + NET_TOKENCACHE_PACKETEXPIRY = 5, NET_TOKEN_MAX = 0xfffff, NET_TOKEN_NONE = NET_TOKEN_MAX, NET_TOKEN_MASK = NET_TOKEN_MAX, + NET_TOKENFLAG_ALLOWBROADCAST = 1, + NET_TOKENFLAG_RESPONSEONLY = 2, + // NET_MAX_CLIENTS = 16, NET_MAX_CONSOLE_CLIENTS = 4, @@ -218,7 +221,7 @@ public: void SendPacketConnless(const NETADDR *pAddr, const void *pData, int DataSize, CSendCBData *pCallbackData = 0); void PurgeStoredPacket(int TrackID); void FetchToken(const NETADDR *pAddr); - void AddToken(const NETADDR *pAddr, TOKEN PeerToken, bool AllowBroadcasts); + void AddToken(const NETADDR *pAddr, TOKEN PeerToken, int TokenFlag); TOKEN GetToken(const NETADDR *pAddr); void Update(); @@ -423,6 +426,7 @@ public: int Recv(CNetChunk *pChunk, TOKEN *pResponseToken = 0); int Send(CNetChunk *pChunk, TOKEN Token = NET_TOKEN_NONE); int Update(); + void AddToken(const NETADDR *pAddr, TOKEN Token) { m_TokenCache.AddToken(pAddr, Token, 0); }; // int Drop(int ClientID, const char *pReason); diff --git a/src/engine/shared/network_client.cpp b/src/engine/shared/network_client.cpp index a575f3a03..f24b64159 100644 --- a/src/engine/shared/network_client.cpp +++ b/src/engine/shared/network_client.cpp @@ -97,7 +97,7 @@ int CNetClient::Recv(CNetChunk *pChunk, TOKEN *pResponseToken) if(m_RecvUnpacker.m_Data.m_Flags&NET_PACKETFLAG_CONTROL) { if(m_RecvUnpacker.m_Data.m_aChunkData[0] == NET_CTRLMSG_TOKEN) - m_TokenCache.AddToken(&Addr, m_RecvUnpacker.m_Data.m_ResponseToken, true); + m_TokenCache.AddToken(&Addr, m_RecvUnpacker.m_Data.m_ResponseToken, NET_TOKENFLAG_ALLOWBROADCAST|NET_TOKENFLAG_RESPONSEONLY); } else if(m_RecvUnpacker.m_Data.m_Flags&NET_PACKETFLAG_CONNLESS && Accept != -1) { diff --git a/src/engine/shared/network_server.cpp b/src/engine/shared/network_server.cpp index 8996a6dfb..d1236ea53 100644 --- a/src/engine/shared/network_server.cpp +++ b/src/engine/shared/network_server.cpp @@ -212,7 +212,7 @@ int CNetServer::Recv(CNetChunk *pChunk, TOKEN *pResponseToken) } } else if(m_RecvUnpacker.m_Data.m_aChunkData[0] == NET_CTRLMSG_TOKEN) - m_TokenCache.AddToken(&Addr, m_RecvUnpacker.m_Data.m_ResponseToken, false); + m_TokenCache.AddToken(&Addr, m_RecvUnpacker.m_Data.m_ResponseToken, NET_TOKENFLAG_RESPONSEONLY); } else if(m_RecvUnpacker.m_Data.m_Flags&NET_PACKETFLAG_CONNLESS) { diff --git a/src/engine/shared/network_token.cpp b/src/engine/shared/network_token.cpp index 227f9c18d..31b69aef8 100644 --- a/src/engine/shared/network_token.cpp +++ b/src/engine/shared/network_token.cpp @@ -255,28 +255,22 @@ void CNetTokenCache::FetchToken(const NETADDR *pAddr) NET_CTRLMSG_TOKEN, m_pTokenManager->GenerateToken(pAddr)); } -void CNetTokenCache::AddToken(const NETADDR *pAddr, TOKEN Token, bool AllowBroadcasts) +void CNetTokenCache::AddToken(const NETADDR *pAddr, TOKEN Token, int TokenFLag) { if(Token == NET_TOKEN_NONE) return; - CAddressInfo Info; - Info.m_Addr = *pAddr; - Info.m_Token = Token; - Info.m_Expiry = time_get() + time_freq() * NET_TOKENCACHE_ADDRESSEXPIRY; - - (*m_TokenCache.Allocate(sizeof(Info))) = Info; - // search the list of packets to be sent // for this address CConnlessPacketInfo *pPrevInfo = 0; CConnlessPacketInfo *pInfo = m_pConnlessPacketList; + bool Found = false; while(pInfo) { static NETADDR NullAddr = { 0 }; NullAddr.type = 7; // cover broadcasts NullAddr.port = pAddr->port; - if(net_addr_comp(&pInfo->m_Addr, pAddr) == 0 || (AllowBroadcasts && net_addr_comp(&pInfo->m_Addr, &NullAddr) == 0)) + if(net_addr_comp(&pInfo->m_Addr, pAddr) == 0 || ((TokenFLag&NET_TOKENFLAG_ALLOWBROADCAST) && net_addr_comp(&pInfo->m_Addr, &NullAddr) == 0)) { // notify the user that the packet gets delivered if(pInfo->m_pfnCallback) @@ -301,6 +295,16 @@ void CNetTokenCache::AddToken(const NETADDR *pAddr, TOKEN Token, bool AllowBroad pInfo = pInfo->m_pNext; } } + + // add the token + if(Found || !(TokenFLag&NET_TOKENFLAG_RESPONSEONLY)) + { + CAddressInfo Info; + Info.m_Addr = *pAddr; + Info.m_Token = Token; + Info.m_Expiry = time_get() + time_freq() * NET_TOKENCACHE_ADDRESSEXPIRY; + (*m_TokenCache.Allocate(sizeof(Info))) = Info; + } } void CNetTokenCache::Update()