Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 25, 2006, 8:10:18 PM (18 years ago)
Author:
patrick
Message:

proxy server should now be accepted

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/proxy/src/lib/network/network_stream.cc

    r9463 r9464  
    316316  {
    317317    // execute everytthing the master server shoudl do
    318     if ( clientSocket )
    319       clientSocket->update();
     318    if ( this->clientSocket )
     319      this->clientSocket->update();
     320    if( this->proxySocket)
     321      this->proxySocket->update();
    320322
    321323    this->updateConnectionList();
     
    326328    if ( clientSocket )
    327329      clientSocket->update();
     330    if( this->proxySocket)
     331      this->proxySocket->update();
    328332
    329333    this->updateConnectionList();
     
    368372  //check for new connections
    369373
    370   NetworkSocket* tempNetworkSocket = clientSocket->getNewSocket();
    371 
    372   // we got new network node
     374  NetworkSocket* tempNetworkSocket = this->clientSocket->getNewSocket();
     375  int userId;
     376
     377  // we got new NET_CLIENT connecting
    373378  if ( tempNetworkSocket )
    374379  {
    375     int clientId;
    376380    // determine the network node id
    377381    if ( freeSocketSlots.size() > 0 )
    378382    {
    379       clientId = freeSocketSlots.back();
     383      userId = freeSocketSlots.back();
    380384      freeSocketSlots.pop_back();
    381385    }
    382386    else
    383387    {
    384       clientId = 1;
     388      userId = 1;
    385389
    386390      for ( PeerList::iterator it = peers.begin(); it != peers.end(); it++ )
    387         if ( it->first >= clientId )
    388           clientId = it->first + 1;
     391        if ( it->first >= userId )
     392          userId = it->first + 1;
    389393    }
    390394    // this creates a new entry in the peers list
    391     peers[clientId].socket = tempNetworkSocket;
    392 
    393 
    394     // create new handshake and init its variables
    395     peers[clientId].handshake = new Handshake(this->pInfo->nodeType, clientId, this->networkGameManager->getUniqueID(), MessageManager::getInstance()->getUniqueID());
    396     peers[clientId].handshake->setUniqueID(clientId);
    397 
    398     peers[clientId].connectionMonitor = new ConnectionMonitor( clientId );
    399     peers[clientId].userId = clientId;
    400 
    401     PRINTF(0)("num sync: %d\n", synchronizeables.size());
    402 
    403     // get the proxy server informations and write them to the handshake, if any (proxy)
    404     assert( this->networkMonitor != NULL);
    405     PeerInfo* pi = this->networkMonitor->getFirstChoiceProxy();
    406     if( pi != NULL)
    407     {
    408       peers[clientId].handshake->setProxy1Address( pi->ip);
    409     }
    410     pi = this->networkMonitor->getSecondChoiceProxy();
    411     if( pi != NULL)
    412       peers[clientId].handshake->setProxy2Address( pi->ip);
    413 
    414     // check if the connecting client should reconnect to a proxy server
    415     peers[clientId].handshake->setRedirect(this->networkMonitor->isReconnectNextClient());
    416 
    417     // the connecting node of course is a client
    418     peers[clientId].nodeType = NET_CLIENT;
    419     peers[clientId].ip = peers[clientId].socket->getRemoteAddress();
    420 
    421 
    422     // check if there are too many clients connected (DEPRECATED: new: the masterserver sends a list of proxy servers)
    423 //     if ( clientId > SharedNetworkData::getInstance()->getMaxPlayer() )
    424 //     {
    425 // //       peers[clientId].handshake->setRedirect(true);
    426 // //
    427 // //       peers[clientId].handshake->doReject( "too many connections" );
    428 //       PRINTF(0)("Will reject client %d because there are to many connections!\n", clientId);
    429 //     }
    430 //     else
    431 //     {
    432 //       PRINTF(0)("New Client: %d\n", clientId);
    433 //     }
    434     PRINTF(0)("New Client: %d\n", clientId);
    435 
    436 
     395    peers[userId].socket = tempNetworkSocket;
     396    this->handleConnect(userId);
     397
     398    PRINTF(0)("New Client: %d\n", userId);
     399  }
     400
     401  tempNetworkSocket = this->proxySocket->getNewSocket();
     402
     403  // we got new NET_PROXY_SERVER_ACTIVE connecting
     404  if ( tempNetworkSocket )
     405  {
     406    // determine the network node id
     407    if ( freeSocketSlots.size() > 0 )
     408    {
     409      userId = freeSocketSlots.back();
     410      freeSocketSlots.pop_back();
     411    }
     412    else
     413    {
     414      userId = 1;
     415
     416      for ( PeerList::iterator it = peers.begin(); it != peers.end(); it++ )
     417        if ( it->first >= userId )
     418          userId = it->first + 1;
     419    }
     420
     421    // this creates a new entry in the peers list
     422    peers[userId].socket = tempNetworkSocket;
     423    this->handleConnect(userId);
     424
     425    PRINTF(0)("New Proxy: %d\n", userId);
    437426  }
    438427
     
    465454
    466455
     456}
     457
     458
     459void NetworkStream::handleConnect( int userId)
     460{
     461  // create new handshake and init its variables
     462  peers[userId].handshake = new Handshake(this->pInfo->nodeType, userId, this->networkGameManager->getUniqueID(), MessageManager::getInstance()->getUniqueID());
     463  peers[userId].handshake->setUniqueID(userId);
     464
     465  peers[userId].connectionMonitor = new ConnectionMonitor( userId );
     466  peers[userId].userId = userId;
     467
     468  PRINTF(0)("num sync: %d\n", synchronizeables.size());
     469
     470    // get the proxy server informations and write them to the handshake, if any (proxy)
     471  assert( this->networkMonitor != NULL);
     472  PeerInfo* pi = this->networkMonitor->getFirstChoiceProxy();
     473  if( pi != NULL)
     474  {
     475    peers[userId].handshake->setProxy1Address( pi->ip);
     476  }
     477  pi = this->networkMonitor->getSecondChoiceProxy();
     478  if( pi != NULL)
     479    peers[userId].handshake->setProxy2Address( pi->ip);
     480
     481    // check if the connecting client should reconnect to a proxy server
     482  peers[userId].handshake->setRedirect(this->networkMonitor->isReconnectNextClient());
     483
     484    // the connecting node of course is a client
     485  peers[userId].nodeType = NET_CLIENT;
     486  peers[userId].ip = peers[userId].socket->getRemoteAddress();
    467487}
    468488
Note: See TracChangeset for help on using the changeset viewer.