Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Dec 30, 2005, 1:57:12 AM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the network branche back to the trunk, so we do not get away from each other to fast

File:
1 edited

Legend:

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

    r6144 r6341  
    2727#include "synchronizeable.h"
    2828#include "network_manager.h"
     29#include "network_game_manager.h"
     30
    2931#include "debug.h"
    3032#include "class_list.h"
     
    6466  this->connectSynchronizeable(*hs);
    6567  PRINTF(0)("NetworkStream: %s\n", hs->getName());
     68  this->maxConnections = 1;
    6669}
    6770
     
    7780  this->handshakes.push_back( NULL );
    7881  this->bActive = true;
     82  this->networkGameManager = NetworkGameManager::getInstance();
     83  // setUniqueID( maxCon+2 ) because we need one id for every handshake
     84  // and one for handshake to reject client maxCon+1
     85  this->networkGameManager->setUniqueID( this->maxConnections+2 );
     86  this->connectSynchronizeable( *(this->networkGameManager) );
    7987
    8088  this->setMaxConnections( 10 );
     
    8896  this->bActive = false;
    8997  this->serverSocket = NULL;
     98  this->networkGameManager = NULL;
    9099  myHostId = 0;
    91100}
     
    176185            NetworkManager::getInstance()->setHostID( handshakes[i]->getHostId() );
    177186            myHostId = NetworkManager::getInstance()->getHostID();
    178           }
    179           PRINT(0)("handshake finished\n");
     187
     188            this->networkGameManager = NetworkGameManager::getInstance();
     189            this->networkGameManager->setUniqueID( handshakes[i]->getNetworkGameManagerId() );
     190            this->connectSynchronizeable( *(this->networkGameManager) );
     191          }
     192          else
     193          {
     194            //this->networkGameManager->sendEntityList( i );
     195          }
     196          PRINT(0)("handshake finished id=%d\n", handshakes[i]->getNetworkGameManagerId());
     197
     198
    180199          delete handshakes[i];
    181200          handshakes[i] = NULL;
    182           //TODO: replace handshake by entitymanager
    183201        }
    184202        else
     
    202220  for (SynchronizeableList::iterator it = synchronizeables.begin(); it!=synchronizeables.end(); it++)
    203221  {
    204     //TODO: remove items from synchronizeables if they dont exist
    205     if ( (*it)!=NULL && (*it)->getOwner() == myHostId )
     222    if ( (*it)!=NULL /*&& (*it)->getOwner() == myHostId*/ )
    206223    {
    207224      do {
     
    217234        dataLength = networkProtocol->createHeader((byte*)downBuffer, dataLength, DATA_STREAM_BUFFER_SIZE, static_cast<const Synchronizeable&>(*(*it)));
    218235
    219         //FIXME: this is a hack, find a better way
    220236        Header* header = (Header*)downBuffer;
    221         if ( header->synchronizeableID<100 )
     237        if ( header->synchronizeableID < this->maxConnections+2 )
     238        {
     239          //if ( !isServer() ) PRINTF(0)("RESET UNIQUEID FROM %d TO 0 maxCon=%d\n", header->synchronizeableID, this->maxConnections);
    222240          header->synchronizeableID = 0;
     241        }
     242        else
     243        {
     244          //if ( !isServer() ) PRINTF(0)("UNIQUEID=%d\n", header->synchronizeableID);
     245        }
    223246
    224247        if ( dataLength<=0 )
     
    229252          if ( networkSockets[reciever] != NULL )
    230253          {
    231             PRINTF(5)("write %d bytes to socket %d\n", dataLength, reciever);
     254            PRINTF(0)("write %d bytes to socket %d\n", dataLength, reciever);
    232255            networkSockets[reciever]->writePacket(downBuffer, dataLength);
    233256          }
     
    243266            if ( networkSockets[i] != NULL )
    244267            {
    245               PRINTF(5)("write %d bytes to socket %d\n", dataLength, reciever);
     268              PRINTF(0)("write %d bytes to socket %d\n", dataLength, reciever);
    246269              networkSockets[i]->writePacket(downBuffer, dataLength);
    247270            }
     
    251274      } while( reciever!=0 );
    252275    }
    253     else
    254     {
    255       PRINTF(0)("synchronizeables == NULL");
    256     }
    257276  }
    258277
     
    269288          continue;
    270289
    271         PRINTF(5)("read %d bytes from socket\n", dataLength);
    272290        header = networkProtocol->extractHeader(upBuffer, dataLength);
    273291        dataLength -= sizeof(header);
    274292
     293        PRINTF(0)("read %d bytes from socket uniqueID = %d\n", dataLength, header.synchronizeableID);
     294
    275295        if ( dataLength != header.length )
    276296        {
     
    287307        {
    288308          if ( *it && (*it)->getUniqueID()==header.synchronizeableID )
    289             (*it)->writeBytes(upBuffer+sizeof(header), dataLength);
     309          {
     310            if ( (*it)->writeBytes(upBuffer+sizeof(header), dataLength, i) != header.length )
     311            {
     312              PRINTF(1)("%s did not read all the data!\n", (*it)->getClassName());
     313              break;
     314            }
     315            continue;
     316          }
    290317        }
    291318
     
    309336      freeSocketSlots.pop_back();
    310337      networkSockets[clientId] = tempNetworkSocket;
    311       handshakes[clientId] = new Handshake(true, clientId);
     338      handshakes[clientId] = new Handshake(true, clientId, this->networkGameManager->getUniqueID());
    312339      handshakes[clientId]->setUniqueID(clientId);
    313340    } else
     
    315342      clientId = networkSockets.size();
    316343      networkSockets.push_back(tempNetworkSocket);
    317       Handshake* tHs = new Handshake(true, clientId);
     344      Handshake* tHs = new Handshake(true, clientId, this->networkGameManager->getUniqueID());
    318345      tHs->setUniqueID(clientId);
    319346      handshakes.push_back(tHs);
     
    376403    return;
    377404  }
     405
     406  if ( n > MAX_CONNECTIONS )
     407  {
     408    PRINTF(1)("Cannot set maxConnectiosn to %d because of hardcoded limit %d\n", n, MAX_CONNECTIONS);
     409    return;
     410  }
     411
    378412  this->maxConnections = n;
    379 }
    380 
    381 
     413  this->networkGameManager->setUniqueID( n+2 );
     414}
     415
     416
Note: See TracChangeset for help on using the changeset viewer.