Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 17, 2006, 10:15:33 AM (18 years ago)
Author:
patrick
Message:

work from this weekend in the train :D

  • the ip should now synchronize over network in the handshake (always the favorite 2 proxy server ips)
  • the network monitor now keeps track of all network nodes answers with proxy server lists if asked/needed
  • it is untested :D
File:
1 edited

Legend:

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

    r9296 r9300  
    8181  this->peers[0].nodeType = NET_MASTER_SERVER;
    8282  this->peers[0].connectionMonitor = new ConnectionMonitor( 0 );
     83  this->peers[0].ip = this->peers[0].socket->getDestAddress();
    8384  // and set also the localhost
    8485  this->pInfo->nodeType = NET_CLIENT;
     86  // get the local ip address
     87  SDLNet_ResolveHost( &this->pInfo->ip, "localhost", port );
     88
    8589}
    8690
     
    9599  this->serverSocket = new UdpServerSocket(port);
    96100  this->pInfo->nodeType = NET_MASTER_SERVER;
     101  // get the local ip address
     102  SDLNet_ResolveHost( &this->pInfo->ip, "localhost", port );
    97103}
    98104
     
    164170  if( this->pInfo)
    165171    delete this->pInfo;
     172
     173  if( this->networkMonitor)
     174    delete this->networkMonitor;
    166175}
    167176
     
    182191/**
    183192 * starts the network handshake
     193 * handsakes are always initialized from the client side first. this starts the handshake and therefore is only
     194 * executed as client
    184195 */
    185196void NetworkStream::startHandshake()
     
    190201  peers[0].handshake = hs;
    191202
     203  // set the preferred nick name
    192204  hs->setPreferedNickName( Preferences::getInstance()->getString( "multiplayer", "nickname", "Player" ) );
    193   //hs->set
    194205
    195206//   peers[0].handshake->setSynchronized( true );
     
    314325      peers[clientId].socket = tempNetworkSocket;
    315326      peers[clientId].handshake = new Handshake(this->pInfo->nodeType, clientId, this->networkGameManager->getUniqueID(), MessageManager::getInstance()->getUniqueID() );
     327      peers[clientId].handshake->setUniqueID(clientId);
     328
     329      // get the proxy server informations and write them to the handshake, if any (proxy)
     330      PeerInfo* pi = this->networkMonitor->getFirstChoiceProxy();
     331      if( pi != NULL)
     332        peers[clientId].handshake->setProxy1Address( pi->ip);
     333      pi = this->networkMonitor->getSecondChoiceProxy();
     334      if( pi != NULL)
     335        peers[clientId].handshake->setProxy2Address( pi->ip);
     336
     337       // check if the connecting client should reconnect to a proxy server
     338      peers[clientId].handshake->setRedirect(this->networkMonitor->reconnectNextClient());
     339
    316340      peers[clientId].connectionMonitor = new ConnectionMonitor( clientId );
    317       peers[clientId].handshake->setUniqueID(clientId);
    318341      peers[clientId].userId = clientId;
    319342      peers[clientId].nodeType = NET_CLIENT;
     
    328351
    329352      peers[clientId].socket = tempNetworkSocket;
     353      // handshake handling
    330354      peers[clientId].handshake = new Handshake(this->pInfo->nodeType, clientId, this->networkGameManager->getUniqueID(), MessageManager::getInstance()->getUniqueID());
    331355      peers[clientId].handshake->setUniqueID(clientId);
     356      // get the proxy server informations and write them to the handshake, if any (proxy)
     357      PeerInfo* pi = this->networkMonitor->getFirstChoiceProxy();
     358      if( pi != NULL)
     359        peers[clientId].handshake->setProxy1Address( pi->ip);
     360      pi = this->networkMonitor->getSecondChoiceProxy();
     361      if( pi != NULL)
     362        peers[clientId].handshake->setProxy2Address( pi->ip);
     363
     364       // check if the connecting client should reconnect to a proxy server
     365      peers[clientId].handshake->setRedirect(this->networkMonitor->reconnectNextClient());
     366
    332367      peers[clientId].connectionMonitor = new ConnectionMonitor( clientId );
    333368      peers[clientId].userId = clientId;
     
    337372    }
    338373
    339     // check if there are too many clients connected
     374    // check if there are too many clients connected (DEPRECATED: new: the masterserver sends a list of proxy servers)
    340375    if ( clientId > NET_MAX_CONNECTIONS )
    341376    {
    342       peers[clientId].handshake->doReject( "too many connections" );
     377//       peers[clientId].handshake->setRedirect(true);
     378//
     379//       peers[clientId].handshake->doReject( "too many connections" );
    343380      PRINTF(0)("Will reject client %d because there are to many connections!\n", clientId);
    344381    }
     
    467504              this->networkMonitor->addNode(&it->second);
    468505
     506              // get proxy 1 address and add it
     507              this->networkMonitor->addNode(it->second.handshake->getProxy1Address());
     508              // get proxy 2 address and add it
     509              this->networkMonitor->addNode(it->second.handshake->getProxy2Address());
     510
     511
     512              // now check if there server accepted the connection
     513              if( it->second.handshake->redirect())
     514              {
     515                // handle the redirection
     516                PRINTF(0)("===============================================\n");
     517                PRINTF(0)("Client is redirected to the other proxy servers\n");
     518                PRINTF(0)("===============================================\n");
     519
     520                // disconnect from the current server and reconnect to proxy server
     521//                 it->second.socket->disconnectServer();
     522
     523              }
     524
     525              // create the new network game manager and init it
    469526              this->networkGameManager = NetworkGameManager::getInstance();
    470527              this->networkGameManager->setUniqueID( it->second.handshake->getNetworkGameManagerId() );
     528              // init the new message manager
    471529              MessageManager::getInstance()->setUniqueID( it->second.handshake->getMessageManagerId() );
    472530            }
Note: See TracChangeset for help on using the changeset viewer.