Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 25, 2006, 10:34:28 AM (18 years ago)
Author:
patrick
Message:

using the new id scheme

File:
1 edited

Legend:

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

    r9449 r9450  
    182182 * @param port: the port number
    183183 */
    184 int NetworkStream::connectToMasterServer(std::string host, int port)
    185 {
    186   int node = this->peers.size();
     184void NetworkStream::connectToMasterServer(std::string host, int port)
     185{
     186  int node = NET_ID_MASTER_SERVER;
    187187  // this create the new node in the peers map
    188188  this->peers[node].socket = new UdpSocket( host, port );
    189   this->peers[node].userId = 0;
     189  this->peers[node].userId = NET_ID_MASTER_SERVER;
    190190
    191191  this->peers[node].nodeType = NET_MASTER_SERVER;
    192   this->peers[node].connectionMonitor = new ConnectionMonitor( 0 );
     192  this->peers[node].connectionMonitor = new ConnectionMonitor( NET_ID_MASTER_SERVER );
    193193  this->peers[node].ip = this->peers[node].socket->getRemoteAddress();
    194 
    195   return node;
    196194}
    197195
     
    202200 * @param port: the port number
    203201 */
    204 int NetworkStream::connectToProxyServer(std::string host, int port)
    205 {
    206   int node = this->peers.size();
    207   PRINTF(0)("connect to proxy %s, this is node %i\n", host.c_str(), node);
    208 
    209   // this creates the new node in the peers map
    210   this->peers[node].socket = new UdpSocket( host, port );
    211   this->peers[node].userId = 0;
    212 
    213   this->peers[node].nodeType = NET_PROXY_SERVER_ACTIVE;
    214   this->peers[node].connectionMonitor = new ConnectionMonitor( 0 );
    215   this->peers[node].ip = this->peers[node].socket->getRemoteAddress();
    216 
    217   return node;
     202void NetworkStream::connectToProxyServer(int proxyId,std::string host, int port)
     203{
     204  PRINTF(0)("connect to proxy %s, this is proxyId %i\n", host.c_str(), proxyId);
     205
     206  // this creates the new proxyId in the peers map
     207  this->peers[proxyId].socket = new UdpSocket( host, port );
     208  this->peers[proxyId].userId = proxyId;
     209
     210  this->peers[proxyId].nodeType = NET_PROXY_SERVER_ACTIVE;
     211  this->peers[proxyId].connectionMonitor = new ConnectionMonitor( proxyId );
     212  this->peers[proxyId].ip = this->peers[proxyId].socket->getRemoteAddress();
    218213}
    219214
     
    250245{
    251246  Handshake* hs = new Handshake(this->pInfo->nodeType);
    252   hs->setUniqueID( 0 );
     247  // fake the unique id
     248  hs->setUniqueID( NET_UID_HANDSHAKE );
    253249  assert( peers[userId].handshake == NULL );
    254250  peers[userId].handshake = hs;
     
    327323  {
    328324    // check if the connection is ok else terminate and remove
    329     if ( !peers.empty() && peers[0].socket && ( !peers[0].socket->isOk() || peers[0].connectionMonitor->hasTimedOut() ) )
    330     {
    331       this->handleDisconnect( 0);
     325#warning make this more modular: every proxy/master server connection should be watched for termination
     326    if ( !peers.empty() && peers[NET_ID_MASTER_SERVER].socket &&
     327          ( !peers[NET_ID_MASTER_SERVER].socket->isOk() ||
     328          peers[NET_ID_MASTER_SERVER].connectionMonitor->hasTimedOut() ) )
     329    {
     330      this->handleDisconnect( NET_ID_MASTER_SERVER);
    332331      PRINTF(1)("lost connection to server\n");
    333332    }
     
    335334    if( this->bRedirect)
    336335    {
    337       this->handleReconnect( 0);
     336      this->handleReconnect( NET_ID_MASTER_SERVER);
    338337    }
    339338  }
     
    625624  // disconnect from the current server and reconnect to proxy server
    626625  this->handleDisconnect( userId);
    627   this->connectToProxyServer(proxyIP.ipString(), 9999);
     626  this->connectToProxyServer(NET_ID_PROXY_SERVER_01, proxyIP.ipString(), 9999);
    628627  #warning the ports are not yet integrated correctly in the ip class
    629628
     
    707706
    708707      // do not include synchronizeables with uninit id and syncs that don't want to be synchronized
    709       if ( !sync.beSynchronized() || sync.getUniqueID() < 0 )
     708      if ( !sync.beSynchronized() || sync.getUniqueID() <= NET_UID_UNASSIGNED )
    710709        continue;
    711710
     
    769768      Synchronizeable & sync = **it;
    770769
    771       if ( !sync.beSynchronized() || sync.getUniqueID() < 0 )
     770      // again exclude all unwanted syncs
     771      if ( !sync.beSynchronized() || sync.getUniqueID() <= NET_UID_UNASSIGNED)
    772772        continue;
    773773
     
    969969        Synchronizeable & sync = **it;
    970970
    971         if ( !sync.beSynchronized() || sync.getUniqueID() < 0 )
     971        if ( !sync.beSynchronized() || sync.getUniqueID() <= NET_UID_UNASSIGNED )
    972972          continue;
    973973
Note: See TracChangeset for help on using the changeset viewer.