void CNetTokenCache::AddToken(const NETADDR *pAddr, TOKEN Token, int TokenFLag) { if(Token == NET_TOKEN_NONE) return; // 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 || ((TokenFLag&NET_TOKENFLAG_ALLOWBROADCAST) && net_addr_comp(&pInfo->m_Addr, &NullAddr) == 0)) { // notify the user that the packet gets delivered if(pInfo->m_pfnCallback) pInfo->m_pfnCallback(pInfo->m_TrackID, pInfo->m_pCallbackUser); CNetBase::SendPacketConnless(m_Socket, &(pInfo->m_Addr), Token, m_pTokenManager->GenerateToken(pAddr), pInfo->m_aData, pInfo->m_DataSize); CConnlessPacketInfo *pNext = pInfo->m_pNext; if(pPrevInfo) pPrevInfo->m_pNext = pNext; if(pInfo == m_pConnlessPacketList) m_pConnlessPacketList = pNext; delete pInfo; pInfo = pNext; } else { if(pPrevInfo) pPrevInfo = pPrevInfo->m_pNext; else pPrevInfo = pInfo; 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::AddToken(const NETADDR *pAddr, TOKEN Token) { 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; while(pInfo) { static NETADDR NullAddr = { 0 }; NullAddr.type = 7; // cover broadcasts NullAddr.port = pAddr->port; if(net_addr_comp(&pInfo->m_Addr, pAddr) == 0 || net_addr_comp(&pInfo->m_Addr, &NullAddr) == 0) { // notify the user that the packet gets delivered if(pInfo->m_pfnCallback) pInfo->m_pfnCallback(pInfo->m_TrackID, pInfo->m_pCallbackUser); // todo: make sure if we got the result of a broadcast or not CNetBase::SendPacketConnless(m_Socket, &(pInfo->m_Addr), Token, m_pTokenManager->GenerateToken(pAddr), pInfo->m_aData, pInfo->m_DataSize); CConnlessPacketInfo *pNext = pInfo->m_pNext; if(pPrevInfo) pPrevInfo->m_pNext = pNext; if(pInfo == m_pConnlessPacketList) m_pConnlessPacketList = pNext; delete pInfo; pInfo = pNext; } else { if(pPrevInfo) pPrevInfo = pPrevInfo->m_pNext; else pPrevInfo = pInfo; pInfo = pInfo->m_pNext; } } }