Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9494 in orxonox.OLD for trunk/src/lib/network/network_stream.cc


Ignore:
Timestamp:
Jul 27, 2006, 10:44:28 AM (19 years ago)
Author:
bensch
Message:

merged the proxy back

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/network/network_stream.cc

    r9406 r9494  
    6565  this->init();
    6666  /* initialize the references */
    67   this->pInfo->nodeType = NET_CLIENT;
     67  this->pInfo->nodeType = NET_UNASSIGNED;
    6868}
    6969
     
    7979    case NET_MASTER_SERVER:
    8080      // init the shared network data
    81       SharedNetworkData::getInstance()->setHostID(0);
    82 //       SharedNetworkData::getInstance()->setNodeType(NET_MASTER_SERVER);
     81      SharedNetworkData::getInstance()->setHostID(NET_ID_MASTER_SERVER);
    8382      break;
    84 
    8583    case NET_PROXY_SERVER_ACTIVE:
    8684      // init the shared network data
    87       SharedNetworkData::getInstance()->setHostID(0);
    88 //       SharedNetworkData::getInstance()->setNodeType(NET_PROXY_SERVER_ACTIVE);
     85      SharedNetworkData::getInstance()->setHostID(NET_ID_PROXY_SERVER_01);
    8986      break;
    9087    case NET_PROXY_SERVER_PASSIVE:
    91             // init the shared network data
    92       SharedNetworkData::getInstance()->setHostID(0);
    93 //       SharedNetworkData::getInstance()->setNodeType(NET_PROXY_SERVER_PASSIVE);
     88      // init the shared network data
     89      SharedNetworkData::getInstance()->setHostID(NET_ID_PROXY_SERVER_01);
    9490      break;
    9591    case NET_CLIENT:
    96 //       SharedNetworkData::getInstance()->setNodeType(NET_CLIENT);
     92      SharedNetworkData::getInstance()->setHostID(NET_ID_UNASSIGNED);
    9793      break;
    9894  }
     
    115111  /* set the class id for the base object */
    116112  this->setClassID(CL_NETWORK_STREAM, "NetworkStream");
    117   this->serverSocket = NULL;
     113  this->clientSocket = NULL;
     114  this->proxySocket = NULL;
    118115  this->networkGameManager = NULL;
    119116  this->networkMonitor = NULL;
     
    124121  this->pInfo->lastRecvedState = 0;
    125122
     123  this->bRedirect = false;
    126124
    127125  this->currentState = 0;
     
    142140NetworkStream::~NetworkStream()
    143141{
    144   if ( this->serverSocket )
    145   {
    146     serverSocket->close();
    147     delete serverSocket;
    148     serverSocket = NULL;
     142  if ( this->clientSocket )
     143  {
     144    clientSocket->close();
     145    delete clientSocket;
     146    clientSocket = NULL;
     147  }
     148  if ( this->proxySocket)
     149  {
     150    proxySocket->close();
     151    delete proxySocket;
     152    proxySocket = NULL;
    149153  }
    150154  for ( PeerList::iterator i = peers.begin(); i!=peers.end(); i++)
     
    187191void NetworkStream::connectToMasterServer(std::string host, int port)
    188192{
    189   int node = this->peers.size();
     193  int node = NET_ID_MASTER_SERVER;
     194  // this create the new node in the peers map
    190195  this->peers[node].socket = new UdpSocket( host, port );
    191   this->peers[node].userId = 0;
     196  this->peers[node].userId = NET_ID_MASTER_SERVER;
    192197
    193198  this->peers[node].nodeType = NET_MASTER_SERVER;
    194   this->peers[node].connectionMonitor = new ConnectionMonitor( 0 );
     199  this->peers[node].connectionMonitor = new ConnectionMonitor( NET_ID_MASTER_SERVER );
    195200  this->peers[node].ip = this->peers[node].socket->getRemoteAddress();
    196201}
     
    202207 * @param port: the port number
    203208 */
    204 void NetworkStream::connectToProxyServer(std::string host, int port)
    205 {
    206   int node = this->peers.size();
    207   this->peers[node].socket = new UdpSocket( host, port );
    208   this->peers[node].userId = 0;
    209 
    210   this->peers[node].nodeType = NET_PROXY_SERVER_ACTIVE;
    211   this->peers[node].connectionMonitor = new ConnectionMonitor( 0 );
    212   this->peers[node].ip = this->peers[node].socket->getRemoteAddress();
     209void NetworkStream::connectToProxyServer(int proxyId, std::string host, int port)
     210{
     211  PRINTF(0)("connect to proxy %s, this is proxyId %i\n", host.c_str(), proxyId);
     212
     213  // this creates the new proxyId in the peers map
     214  this->peers[proxyId].socket = new UdpSocket( host, port );
     215  this->peers[proxyId].userId = proxyId;
     216
     217  this->peers[proxyId].nodeType = NET_PROXY_SERVER_ACTIVE;
     218  this->peers[proxyId].connectionMonitor = new ConnectionMonitor( proxyId );
     219  this->peers[proxyId].ip = this->peers[proxyId].socket->getRemoteAddress();
    213220}
    214221
     
    218225 * @param port: interface port for all clients
    219226 */
    220 void NetworkStream::createServer(int port)
    221 {
    222   this->serverSocket = new UdpServerSocket(port);
     227void NetworkStream::createServer(int clientPort, int proxyPort)
     228{
     229  PRINTF(0)(" Creating new Server: listening for clients on port %i and for proxies on port %i", clientPort, proxyPort);
     230  this->clientSocket= new UdpServerSocket(clientPort);
     231  this->proxySocket = new UdpServerSocket(proxyPort);
    223232}
    224233
     
    240249 * handsakes are always initialized from the client side first. this starts the handshake and therefore is only
    241250 * executed as client
    242  */
    243 void NetworkStream::startHandshake()
     251 * @param userId: start handshake for this user id (optional, default == 0)
     252 */
     253void NetworkStream::startHandshake(int userId)
    244254{
    245255  Handshake* hs = new Handshake(this->pInfo->nodeType);
    246   hs->setUniqueID( 0 );
    247   assert( peers[0].handshake == NULL );
    248   peers[0].handshake = hs;
     256  // fake the unique id
     257  hs->setUniqueID( NET_UID_HANDSHAKE );
     258  assert( peers[userId].handshake == NULL );
     259  peers[userId].handshake = hs;
    249260
    250261  // set the preferred nick name
     
    259270 * it all over the network and creating it on the other platforms (if and only if it is a
    260271 * server
     272 * @param sync: the synchronizeable to add
    261273 */
    262274void NetworkStream::connectSynchronizeable(Synchronizeable& sync)
     
    264276  this->synchronizeables.push_back(&sync);
    265277  sync.setNetworkStream( this );
    266 
    267 //   this->bActive = true;
    268278}
    269279
     
    271281/**
    272282 * removes the synchronizeable from the list of synchronized entities
     283 * @param sync: the syncronizeable to remove
    273284 */
    274285void NetworkStream::disconnectSynchronizeable(Synchronizeable& sync)
     
    302313  }
    303314
    304   if ( this->pInfo->isMasterServer())
     315  if ( SharedNetworkData::getInstance()->isMasterServer())
    305316  {
    306317    // execute everytthing the master server shoudl do
    307     if ( serverSocket )
    308       serverSocket->update();
     318    if ( this->clientSocket )
     319      this->clientSocket->update();
     320    if( this->proxySocket)
     321      this->proxySocket->update();
    309322
    310323    this->updateConnectionList();
    311324  }
    312   else if( this->pInfo->isProxyServer())
    313   {
    314     // execute everything the proxy server should do
    315     if ( serverSocket )
    316       serverSocket->update();
     325  else if( SharedNetworkData::getInstance()->isProxyServerActive())
     326  {
     327    //execute everything the proxy server should do
     328    if ( this->clientSocket )
     329      this->clientSocket->update();
     330    if( this->proxySocket)
     331      this->proxySocket->update();
    317332
    318333    this->updateConnectionList();
    319334  }
    320   else
     335
     336#warning make this more modular: every proxy/master server connection should be watched for termination
     337  if( !SharedNetworkData::getInstance()->isMasterServer())
    321338  {
    322339    // check if the connection is ok else terminate and remove
    323     if ( peers[0].socket && ( !peers[0].socket->isOk() || peers[0].connectionMonitor->hasTimedOut() ) )
    324     {
     340    if ( !peers.empty() && peers[NET_ID_MASTER_SERVER].socket &&
     341          ( !peers[NET_ID_MASTER_SERVER].socket->isOk() ||
     342          peers[NET_ID_MASTER_SERVER].connectionMonitor->hasTimedOut() ) )
     343    {
     344      this->handleDisconnect( NET_ID_MASTER_SERVER);
    325345      PRINTF(1)("lost connection to server\n");
    326 
    327       peers[0].socket->disconnectServer();
    328       delete peers[0].socket;
    329       peers[0].socket = NULL;
    330 
    331       if ( peers[0].handshake )
    332         delete peers[0].handshake;
    333       peers[0].handshake = NULL;
    334 
    335       if ( peers[0].connectionMonitor )
    336         delete peers[0].connectionMonitor;
    337       peers[0].connectionMonitor = NULL;
    338     }
    339   }
    340 
    341   cleanUpOldSyncList();
    342   handleHandshakes();
     346    }
     347    // check if there is a redirection command
     348    if( this->bRedirect)
     349    {
     350      this->handleReconnect( NET_ID_MASTER_SERVER);
     351    }
     352  }
     353
     354  this->cleanUpOldSyncList();
     355  this->handleHandshakes();
    343356
    344357  // update the network monitor
     
    347360  // order of up/downstream is important!!!!
    348361  // don't change it
    349   handleDownstream( tick );
    350   handleUpstream( tick );
    351 }
    352 
    353 
    354 /**
    355  * if we are a NET_MASTER_SERVER or NET_PROXY_SERVER_ACTIVE update the connection list to accept new
    356  * connections (clients) also start the handsake for the new clients
     362  this->handleDownstream( tick );
     363  this->handleUpstream( tick );
     364}
     365
     366
     367/**
     368 * @brief handles incoming connections
     369 *
     370 * if we are a NET_MASTER_SERVER or NET_PROXY_SERVER_ACTIVE update the connection list to accept new connections (clients)
     371 * start and initialize the handsake for the new clients
    357372 */
    358373void NetworkStream::updateConnectionList( )
     
    360375  //check for new connections
    361376
    362   NetworkSocket* tempNetworkSocket = serverSocket->getNewSocket();
    363 
    364   // we got new network node
    365   if ( tempNetworkSocket )
    366   {
    367     int clientId;
    368     // if there is a list of free client id slots, take these
    369     if ( freeSocketSlots.size() > 0 )
    370     {
    371       clientId = freeSocketSlots.back();
    372       freeSocketSlots.pop_back();
    373     }
    374     else
    375     {
    376       clientId = 1;
    377 
    378       for ( PeerList::iterator it = peers.begin(); it != peers.end(); it++ )
    379         if ( it->first >= clientId )
    380           clientId = it->first + 1;
    381     }
    382     peers[clientId].socket = tempNetworkSocket;
    383 
    384 
    385     // create new handshake and init its variables
    386     peers[clientId].handshake = new Handshake(this->pInfo->nodeType, clientId, this->networkGameManager->getUniqueID(), MessageManager::getInstance()->getUniqueID());
    387     peers[clientId].handshake->setUniqueID(clientId);
    388 
    389     peers[clientId].connectionMonitor = new ConnectionMonitor( clientId );
    390     peers[clientId].userId = clientId;
    391 
    392     PRINTF(0)("num sync: %d\n", synchronizeables.size());
    393 
    394     // get the proxy server informations and write them to the handshake, if any (proxy)
    395     assert( this->networkMonitor != NULL);
    396     PeerInfo* pi = this->networkMonitor->getFirstChoiceProxy();
    397     if( pi != NULL)
    398     {
    399       peers[clientId].handshake->setProxy1Address( pi->ip);
    400     }
    401     pi = this->networkMonitor->getSecondChoiceProxy();
    402     if( pi != NULL)
    403       peers[clientId].handshake->setProxy2Address( pi->ip);
    404 
    405     // check if the connecting client should reconnect to a proxy server
    406     peers[clientId].handshake->setRedirect(/*this->networkMonitor->isReconnectNextClient()*/false);
    407 
    408     // the connecting node of course is a client
    409     peers[clientId].nodeType = NET_CLIENT;
    410     peers[clientId].ip = peers[clientId].socket->getRemoteAddress();
    411 
    412 
    413     // check if there are too many clients connected (DEPRECATED: new: the masterserver sends a list of proxy servers)
    414 //     if ( clientId > SharedNetworkData::getInstance()->getMaxPlayer() )
    415 //     {
    416 // //       peers[clientId].handshake->setRedirect(true);
    417 // //
    418 // //       peers[clientId].handshake->doReject( "too many connections" );
    419 //       PRINTF(0)("Will reject client %d because there are to many connections!\n", clientId);
    420 //     }
    421 //     else
    422 //     {
    423 //       PRINTF(0)("New Client: %d\n", clientId);
    424 //     }
    425     PRINTF(0)("New Client: %d\n", clientId);
    426 
    427 
    428   }
    429 
     377  NetworkSocket* tempNetworkSocket = NULL;
     378  int userId;
     379
     380  if( this->clientSocket != NULL)
     381  {
     382    tempNetworkSocket = this->clientSocket->getNewSocket();
     383
     384    // we got new NET_CLIENT connecting
     385    if ( tempNetworkSocket )
     386    {
     387      // determine the network node id
     388      if ( freeSocketSlots.size() > 0 )
     389      {
     390        userId = freeSocketSlots.back();
     391        freeSocketSlots.pop_back();
     392      }
     393      else
     394      {
     395        userId = 1;
     396
     397        for ( PeerList::iterator it = peers.begin(); it != peers.end(); it++ )
     398          if ( it->first >= userId )
     399            userId = it->first + 1;
     400      }
     401      // this creates a new entry in the peers list
     402      peers[userId].socket = tempNetworkSocket;
     403      peers[userId].nodeType = NET_CLIENT;
     404
     405      // handle the newly connected client
     406      this->handleConnect(userId);
     407
     408      PRINTF(0)("New Client: %d\n", userId);
     409    }
     410  }
     411
     412
     413  if( this->proxySocket != NULL)
     414  {
     415    tempNetworkSocket = this->proxySocket->getNewSocket();
     416
     417    // we got new NET_PROXY_SERVER_ACTIVE connecting
     418    if ( tempNetworkSocket )
     419    {
     420      // determine the network node id
     421      if ( freeSocketSlots.size() > 0 )
     422      {
     423        userId = freeSocketSlots.back();
     424        freeSocketSlots.pop_back();
     425      }
     426      else
     427      {
     428        userId = 1;
     429
     430        for ( PeerList::iterator it = peers.begin(); it != peers.end(); it++ )
     431          if ( it->first >= userId )
     432            userId = it->first + 1;
     433      }
     434
     435      // this creates a new entry in the peers list
     436      peers[userId].socket = tempNetworkSocket;
     437      peers[userId].nodeType = NET_PROXY_SERVER_ACTIVE;
     438
     439      // handle the newly connected proxy server
     440      this->handleConnect(userId);
     441
     442      PRINTF(0)("New proxy connected: %d\n", userId);
     443    }
     444  }
    430445
    431446
     
    446461      PRINTF(0)("Client is gone: %d (%s)\n", it->second.userId, reason.c_str());
    447462
    448 
    449       // clean up the network data
    450       it->second.socket->disconnectServer();
    451       delete it->second.socket;
    452       it->second.socket = NULL;
    453 
    454       // remove the old connectin monitor
    455       if ( it->second.connectionMonitor )
    456         delete it->second.connectionMonitor;
    457       it->second.connectionMonitor = NULL;
    458 
    459       // remove the handshake
    460       if ( it->second.handshake )
    461         delete it->second.handshake;
    462       it->second.handshake = NULL;
    463 
    464       // and cleanup the user infos
    465       for ( SynchronizeableList::iterator it2 = synchronizeables.begin(); it2 != synchronizeables.end(); it2++ )
    466       {
    467         (*it2)->cleanUpUser( it->second.userId );
    468       }
    469 
    470       NetworkGameManager::getInstance()->signalLeftPlayer(it->second.userId);
    471 
    472       freeSocketSlots.push_back( it->second.userId );
    473 
    474       PeerList::iterator delit = it;
     463      this->handleDisconnect( it->second.userId);
     464
    475465      it++;
    476 
    477       peers.erase( delit );
    478 
    479466      continue;
    480467    }
     
    487474
    488475
     476/**
     477 * this handles new connections
     478 * @param userId: the id of the new user node
     479 */
     480void NetworkStream::handleConnect( int userId)
     481{
     482  // create new handshake and init its variables
     483  peers[userId].handshake = new Handshake(this->pInfo->nodeType, userId, this->networkGameManager->getUniqueID(), MessageManager::getInstance()->getUniqueID());
     484  peers[userId].handshake->setUniqueID(userId);
     485
     486  peers[userId].connectionMonitor = new ConnectionMonitor( userId );
     487  peers[userId].userId = userId;
     488
     489  PRINTF(0)("num sync: %d\n", synchronizeables.size());
     490
     491  // get the proxy server informations and write them to the handshake, if any (proxy)
     492  assert( this->networkMonitor != NULL);
     493  PeerInfo* pi = this->networkMonitor->getFirstChoiceProxy();
     494  if( pi != NULL)
     495  {
     496    peers[userId].handshake->setProxy1Address( pi->ip);
     497  }
     498  pi = this->networkMonitor->getSecondChoiceProxy();
     499  if( pi != NULL)
     500    peers[userId].handshake->setProxy2Address( pi->ip);
     501
     502  // check if the connecting client should reconnect to a proxy server
     503  if( SharedNetworkData::getInstance()->isMasterServer())
     504    peers[userId].handshake->setRedirect(/*this->networkMonitor->isReconnectNextClient()*/false);
     505
     506  // the connecting node of course is a client
     507  peers[userId].ip = peers[userId].socket->getRemoteAddress();
     508}
     509
     510
     511
     512/**
     513 * some debug output
     514 */
    489515void NetworkStream::debug()
    490516{
     
    492518    PRINT(0)(" Host ist Master Server with ID: %i\n", this->pInfo->userId);
    493519  }
    494   else if( SharedNetworkData::getInstance()->isProxyServer()) {
     520  else if( SharedNetworkData::getInstance()->isProxyServerActive()) {
    495521    PRINT(0)(" Host ist Proxy Server with ID: %i\n", this->pInfo->userId);
    496522  }
     
    541567        if ( it->second.handshake->ok() )
    542568        {
    543           // the server gave it free for deletion
     569          // write the first informations into the node so they can be read from there for case differentiation
     570          it->second.nodeType = it->second.handshake->getRemoteNodeType();
     571
     572          // the counter part didn't mark it free for deletion yet
    544573          if ( !it->second.handshake->allowDel() )
    545574          {
    546 
    547             if ( this->pInfo->isClient() )
     575            // make sure this is a connection:
     576            // - client       <==> master server
     577            // - proxy server <==> master server
     578            if(  SharedNetworkData::getInstance()->isClient() || SharedNetworkData::getInstance()->isProxyServerActive() && it->second.isMasterServer())
    548579            {
     580              PRINTF(0)("Handshake: i am in client role\n");
     581
    549582              SharedNetworkData::getInstance()->setHostID( it->second.handshake->getHostId() );
    550583              this->pInfo->userId = SharedNetworkData::getInstance()->getHostID();
    551584
    552               it->second.nodeType = it->second.handshake->getRemoteNodeType();
    553               it->second.ip = it->second.socket->getRemoteAddress();
     585#warning the ip address is not set here because it results in a segfault when connecting to a proxy server => trace this later
     586//               it->second.ip = it->second.socket->getRemoteAddress();
     587
     588              // it->second.nodeType = it->second.handshake->getRemoteNodeType();
     589              // it->second.ip = it->second.socket->getRemoteAddress();
    554590              // add the new server to the nodes list (it can be a NET_MASTER_SERVER or NET_PROXY_SERVER)
    555591              this->networkMonitor->addNode(&it->second);
     
    560596
    561597              // now check if the server accepted the connection
    562               if( it->second.handshake->redirect())
    563                 this->handleReconnect( it->second.userId);
     598              if( SharedNetworkData::getInstance()->isClient() && it->second.handshake->redirect() )
     599              {
     600                this->bRedirect = true;
     601              }
    564602
    565603              // create the new network game manager and init it
     
    570608            }
    571609
    572 
    573610            PRINT(0)("handshake finished id=%d\n", it->second.handshake->getNetworkGameManagerId());
    574611            it->second.handshake->del();
     612
    575613          }
    576614          else
     
    580618            {
    581619
    582               if ( this->pInfo->isMasterServer() )
     620              if (  SharedNetworkData::getInstance()->isMasterServer() )
    583621              {
    584                 it->second.nodeType = it->second.handshake->getRemoteNodeType();
    585622                it->second.ip = it->second.socket->getRemoteAddress();
    586623
     
    594631                }
    595632              }
    596               else if ( this->pInfo->isProxyServer() )
     633              else if ( SharedNetworkData::getInstance()->isProxyServerActive() && it->second.isClient() )
    597634              {
    598                 it->second.nodeType = it->second.handshake->getRemoteNodeType();
     635                PRINTF(0)("Handshake: i am in server role\n");
     636
    599637                it->second.ip = it->second.socket->getRemoteAddress();
    600638
     
    632670void NetworkStream::handleReconnect(int userId)
    633671{
     672  this->bRedirect = false;
     673  PeerInfo* pInfo = &this->peers[userId];
     674
    634675  PRINTF(0)("===============================================\n");
    635676  PRINTF(0)("Client is redirected to the other proxy servers\n");
     677  PRINTF(0)("  user id: %i\n", userId);
     678  PRINTF(0)("  connecting to: %s\n", this->networkMonitor->getFirstChoiceProxy()->ip.ipString().c_str());
    636679  PRINTF(0)("===============================================\n");
    637 
    638   return;
    639 
    640   PeerInfo* pInfo = &this->peers[userId];
    641 
    642   // reject the server
    643   pInfo->handshake->doReject( "redirected to different server");
    644680
    645681  // flush the old synchronization states, since the numbering could be completely different
    646682  pInfo->lastAckedState = 0;
    647683  pInfo->lastRecvedState = 0;
    648   // not sure if this works as expected
    649   if( pInfo->handshake)
    650     delete pInfo->handshake;
     684
     685  // temp save the ip address here
     686  IP proxyIP = pInfo->handshake->getProxy1Address();
    651687
    652688  // disconnect from the current server and reconnect to proxy server
    653   pInfo->socket->reconnectToServer( pInfo->handshake->getProxy1Address().ipString(), pInfo->handshake->getProxy1Address().port());
     689  this->handleDisconnect( userId);
     690  this->connectToProxyServer(NET_ID_PROXY_SERVER_01, proxyIP.ipString(), 9999);
     691  #warning the ports are not yet integrated correctly in the ip class
    654692
    655693  // and restart the handshake
    656   this->startHandshake();
    657 }
     694  this->startHandshake( userId);
     695}
     696
     697
     698/**
     699 * handles the disconnect event
     700 * @param userId id of the user to remove
     701 */
     702void NetworkStream::handleDisconnect( int userId )
     703{
     704  peers[userId].socket->disconnectServer();
     705  delete peers[userId].socket;
     706  peers[userId].socket = NULL;
     707
     708  if ( peers[userId].handshake )
     709    delete peers[userId].handshake;
     710  peers[userId].handshake = NULL;
     711
     712  if ( peers[userId].connectionMonitor )
     713    delete peers[userId].connectionMonitor;
     714  peers[userId].connectionMonitor = NULL;
     715
     716
     717  for ( SynchronizeableList::iterator it2 = synchronizeables.begin(); it2 != synchronizeables.end(); it2++ )  {
     718    (*it2)->cleanUpUser( userId );
     719  }
     720
     721  if( SharedNetworkData::getInstance()->isMasterServer())
     722    NetworkGameManager::getInstance()->signalLeftPlayer(userId);
     723
     724  this->freeSocketSlots.push_back( userId );
     725
     726  peers.erase( userId);
     727}
     728
    658729
    659730
    660731/**
    661732 * handle upstream network traffic
     733 * @param tick: seconds elapsed since last update
    662734 */
    663735void NetworkStream::handleUpstream( int tick )
     
    698770
    699771      // do not include synchronizeables with uninit id and syncs that don't want to be synchronized
    700       if ( !sync.beSynchronized() || sync.getUniqueID() < 0 )
     772      if ( !sync.beSynchronized() || sync.getUniqueID() <= NET_UID_UNASSIGNED )
    701773        continue;
    702774
     
    706778
    707779      // if we are a server (both master and proxy servers) and this is not our handshake
    708       if ( ( SharedNetworkData::getInstance()->isMasterServer() || SharedNetworkData::getInstance()->isProxyServer() ) && sync.getLeafClassID() == CL_HANDSHAKE && sync.getUniqueID() != peer->second.userId )
     780      if ( ( SharedNetworkData::getInstance()->isMasterServer() ||
     781             SharedNetworkData::getInstance()->isProxyServerActive() &&  peer->second.isClient())
     782             && sync.getLeafClassID() == CL_HANDSHAKE && sync.getUniqueID() != peer->second.userId )
    709783        continue;
    710784
     
    720794
    721795      // server fakes uniqueid == 0 for handshake
    722       if ( ( SharedNetworkData::getInstance()->isMasterServer() || SharedNetworkData::getInstance()->isProxyServer() ) &&
     796      if ( ( SharedNetworkData::getInstance()->isMasterServer() ||
     797             SharedNetworkData::getInstance()->isProxyServerActive() &&  peer->second.isClient() ) &&
    723798             sync.getUniqueID() <= SharedNetworkData::getInstance()->getMaxPlayer() + 1) // plus one to handle one client more than the max to redirect it
    724799        n = Converter::intToByteArray( 0, buf + offset, UDP_PACKET_SIZE - offset );
     
    760835      Synchronizeable & sync = **it;
    761836
    762       if ( !sync.beSynchronized() || sync.getUniqueID() < 0 )
     837      // again exclude all unwanted syncs
     838      if ( !sync.beSynchronized() || sync.getUniqueID() <= NET_UID_UNASSIGNED)
    763839        continue;
    764840
     
    771847    // now compress the data with the zip library
    772848    int compLength = 0;
    773     if ( SharedNetworkData::getInstance()->isMasterServer() || SharedNetworkData::getInstance()->isProxyServer())
     849    if ( SharedNetworkData::getInstance()->isMasterServer() ||
     850         SharedNetworkData::getInstance()->isProxyServerActive())
    774851      compLength = Zip::getInstance()->zip( buf, offset, compBuf, UDP_PACKET_SIZE, dictServer );
    775852    else
     
    888965          }
    889966
    890           // if the node we got this unknown sync from is a client we ignore it (since it has no rights to create a new sync)
    891           if ( peers[peer->second.userId].isClient() )
     967          // if the node we got this unknown sync we ignore it if:
     968          //  - the remote host is a client
     969          //  - the remote host is a proxy server and we are master server
     970          // (since it has no rights to create a new sync)
     971          if ( peers[peer->second.userId].isClient() ||
     972               (peers[peer->second.userId].isProxyServerActive() && SharedNetworkData::getInstance()->isMasterServer()))
    892973          {
    893974            offset += syncDataLength;
     
    9601041        Synchronizeable & sync = **it;
    9611042
    962         if ( !sync.beSynchronized() || sync.getUniqueID() < 0 )
     1043        if ( !sync.beSynchronized() || sync.getUniqueID() <= NET_UID_UNASSIGNED )
    9631044          continue;
    9641045
Note: See TracChangeset for help on using the changeset viewer.