Example #1
0
void C4Network2ClientList::HandlePacket(char cStatus,
                                        const C4PacketBase *pBasePkt,
                                        C4Network2IOConnection *pConn) {
  // find associated client
  C4Network2Client *pClient = GetClient(pConn);
  if (!pClient) return;

#define GETPKT(type, name) \
  assert(pBasePkt);        \
  const type &name = /*dynamic_cast*/ static_cast<const type &>(*pBasePkt);

  switch (cStatus) {
    case PID_Addr:  // address propagation
    {
      GETPKT(C4PacketAddr, rPkt)
      // find client
      pClient = GetClientByID(rPkt.getClientID());
      if (pClient) {
        C4Network2Address addr = rPkt.getAddr();
        // IP zero? Set to IP from where the packet came
        if (addr.isIPNull()) addr.SetIP(pConn->getPeerAddr().sin_addr);
        // add (no announce)
        if (pClient->AddAddr(addr, true))
          // new address? Try to connect
          pClient->DoConnectAttempt(pIO);
      }
    } break;
  }

#undef GETPKT
}
Example #2
0
void C4Network2ClientList::DoConnectAttempts()
{
	// check interval
	time_t t; time(&t);
	for (C4Network2Client *pClient = pFirst; pClient; pClient = pClient->getNext())
		if (!pClient->isLocal() && !pClient->isRemoved() && pClient->getNextConnAttempt() && pClient->getNextConnAttempt() <= t)
			// attempt connect
			pClient->DoConnectAttempt(pIO);
}