C4Network2Client *C4Network2ClientList::GetNextClientAfterID( int32_t iSmallerClientID) const { // return client with smallest ID > iSmallerClientID C4Network2Client *pBest = NULL; for (C4Network2Client *pClient = pFirst; pClient; pClient = pClient->pNext) if (pClient->getID() > iSmallerClientID) if (!pBest || pBest->getID() > pClient->getID()) pBest = pClient; return pBest; }
void C4Network2ClientList::UpdateClientActivity() { for (C4Network2Client *pClient = pFirst; pClient; pClient = pClient->getNext()) if (pClient->isActivated()) if (::Players.GetAtClient(pClient->getID())) pClient->SetLastActivity(Game.FrameCounter); }
bool C4Network2ClientList::BroadcastMsgToClients(const C4NetIOPacket &rPkt) { // Send a msg to all clients, including clients that are not connected to // this computer (will get forwarded by host). C4PacketFwd Fwd; Fwd.SetListType(true); // lock pIO->BeginBroadcast(false); // select connections for broadcast for (C4Network2Client *pClient = pFirst; pClient; pClient = pClient->getNext()) if (!pClient->isHost()) if (pClient->isConnected()) { pClient->getMsgConn()->SetBroadcastTarget(true); Fwd.AddClient(pClient->getID()); } // broadcast bool fSuccess = pIO->Broadcast(rPkt); // unlock pIO->EndBroadcast(); // clients: send forward request to host if (!fHost) { Fwd.SetData(rPkt); fSuccess &= SendMsgToHost(MkC4NetIOPacket(PID_FwdReq, Fwd)); } return fSuccess; }
C4Network2Client *C4Network2ClientList::RegClient(C4Client *pClient) { // security if (pClient->getNetClient()) return pClient->getNetClient(); // find insert position C4Network2Client *pPos = pFirst, *pLast = NULL; for (; pPos; pLast = pPos, pPos = pPos->getNext()) if (pPos->getID() > pClient->getID()) break; assert(!pLast || pLast->getID() != pClient->getID()); // create new client C4Network2Client *pNetClient = new C4Network2Client(pClient); // add to list pNetClient->pNext = pPos; (pLast ? pLast->pNext : pFirst) = pNetClient; pNetClient->pParent = this; // local? if (pClient->isLocal()) pLocal = pNetClient; else // set auto-accept pIO->AddAutoAccept(pClient->getCore()); // add return pNetClient; }
C4Network2Client *C4Network2ClientList::GetClientByID(int32_t iID) const { for (C4Network2Client *pClient = pFirst; pClient; pClient = pClient->pNext) if (pClient->getID() == iID) return pClient; return NULL; }