void C4Network2ResDlg::Update()
{
	// check through own resources and current res list
	ListItem *pItem = static_cast<ListItem *>(pClientWindow->GetFirst()), *pNext;
	C4Network2Res *pRes; int iResID=-1;
	while ((pRes = ::Network.ResList.getRefNextRes(++iResID)))
	{
		iResID = pRes->getResID();
		// resource checking: deleted resource(s) present?
		while (pItem && (pItem->GetResID() < iResID))
		{
			pNext = static_cast<ListItem *>(pItem->GetNext());
			delete pItem; pItem = pNext;
		}
		// same resource present for update?
		if (pItem && pItem->GetResID() == iResID)
		{
			pItem->Update(pRes);
			pItem = static_cast<ListItem *>(pItem->GetNext());
		}
		else
			// not present: insert (or add if pItem=NULL)
			InsertElement(new ListItem(this, pRes), pItem);
	}
	// del trailing items
	while (pItem)
	{
		pNext = static_cast<ListItem *>(pItem->GetNext());
		delete pItem; pItem = pNext;
	}
}
예제 #2
0
void C4Network2ClientListBox::Update()
{
	// sync with client list
	ListItem *pItem = static_cast<ListItem *>(pClientWindow->GetFirst()), *pNext;
	const C4Client *pClient = nullptr;
	while ((pClient = Game.Clients.getClient(pClient)))
	{
		// skip host in startup board
		if (IsStartup() && pClient->isHost()) continue;
		// deleted client(s) present? this will also delete unneeded client connections of previous client
		while (pItem && (pItem->GetClientID() < pClient->getID()))
		{
			pNext = static_cast<ListItem *>(pItem->GetNext());
			delete pItem; pItem = pNext;
		}
		// same present for update?
		// need not check for connection ID, because a client item will always be placed before the corresponding connection items
		if (pItem && pItem->GetClientID() == pClient->getID())
		{
			pItem->Update();
			pItem = static_cast<ListItem *>(pItem->GetNext());
		}
		else
			// not present: insert (or add if pItem=nullptr)
			InsertElement(new ClientListItem(this, pClient->getID()), pItem);
		// update connections for client
		// but no connections in startup board
		if (IsStartup()) continue;
		// enumerate client connections
		C4Network2Client *pNetClient = pClient->getNetClient();
		if (!pNetClient) continue; // local client does not have connections
		C4Network2IOConnection *pLastConn = nullptr;
		for (int i = 0; i<2; ++i)
		{
			C4Network2IOConnection *pConn = i ? pNetClient->getMsgConn() : pNetClient->getDataConn();
			if (!pConn) continue;
			if (pConn == pLastConn) continue; // combined connection: Display only one
			pLastConn = pConn;
			// del leading items
			while (pItem && ((pItem->GetClientID() < pClient->getID()) || ((pItem->GetClientID() == pClient->getID()) && (pItem->GetConnectionID() < i))))
			{
				pNext = static_cast<ListItem *>(pItem->GetNext());
				delete pItem; pItem = pNext;
			}
			// update connection item
			if (pItem && pItem->GetClientID() == pClient->getID() && pItem->GetConnectionID() == i)
			{
				pItem->Update();
				pItem = static_cast<ListItem *>(pItem->GetNext());
			}
			else
			{
				// new connection: create it
				InsertElement(new ConnectionListItem(this, pClient->getID(), i), pItem);
			}
		}
	}
	// del trailing items
	while (pItem)
	{
		pNext = static_cast<ListItem *>(pItem->GetNext());
		delete pItem; pItem = pNext;
	}
}