Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 10, 2006, 4:48:27 PM (18 years ago)
Author:
rennerc
Message:

fixed some bugs

File:
1 edited

Legend:

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

    r7571 r7575  
    6464  this->networkProtocol = new NetworkProtocol();
    6565  this->connectionMonitor = new ConnectionMonitor();
    66   this->maxConnections = MAX_CONNECTIONS;
    6766}
    6867
     
    131130  // setUniqueID( maxCon+2 ) because we need one id for every handshake
    132131  // and one for handshake to reject client maxCon+1
    133   this->networkGameManager->setUniqueID( this->maxConnections + 2 );
     132  this->networkGameManager->setUniqueID( MAX_CONNECTIONS + 2 );
    134133
    135134}
     
    142141  assert( peers[0].handshake == NULL );
    143142  peers[0].handshake = hs;
     143//   peers[0].handshake->setSynchronized( true );
     144  this->connectSynchronizeable(*hs);
    144145  //this->connectSynchronizeable(*hs);
    145   PRINTF(0)("NetworkStream: %s\n", hs->getName());
     146  PRINTF(0)("NetworkStream: Handshake created: %s\n", hs->getName());
    146147}
    147148
     
    194195  }
    195196
     197  handleHandshakes();
     198  handleUpstream();
     199  handleDownstream();
    196200
    197201
     
    354358    } else
    355359    {
    356       clientId = 0;
     360      clientId = 1;
    357361     
    358362      for ( PeerList::iterator it = peers.begin(); it != peers.end(); it++ )
     
    366370    }
    367371
    368     if ( clientId > this->maxConnections )
     372    if ( clientId > MAX_CONNECTIONS )
    369373    {
    370374      peers[clientId].handshake->doReject( "too many connections" );
     
    419423               (*it)->getUniqueID(), (*it)->beSynchronized());
    420424  }
    421   PRINT(0)(" Maximal Connections: %i\n", this->maxConnections);
     425  PRINT(0)(" Maximal Connections: %i\n", MAX_CONNECTIONS );
    422426
    423427}
     
    486490    offset = INTSIZE; //make already space for length
    487491   
    488     if ( peer->second.socket )
     492    if ( !peer->second.socket )
    489493      continue;
    490494   
     
    504508    {
    505509      Synchronizeable & sync = **it;
     510
     511      if ( !sync.beSynchronized() || sync.getUniqueID() < 0 )
     512        continue;
     513
     514      //if handshake not finished only sync handshake
     515      if ( peer->second.handshake && sync.getLeafClassID() != CL_HANDSHAKE )
     516        continue;
     517
     518      PRINTF(0)("syncing: id:%d name:%s\n", sync.getUniqueID(), sync.getClassName());
    506519     
    507520      assert( offset + INTSIZE <= UDP_PACKET_SIZE );
    508521     
    509       n = Converter::intToByteArray( sync.getUniqueID(), buf + offset, UDP_PACKET_SIZE - offset );
     522      //server fakes uniqueid=0 for handshake
     523      if ( this->isServer() && sync.getUniqueID() < MAX_CONNECTIONS - 1 )
     524        n = Converter::intToByteArray( 0, buf + offset, UDP_PACKET_SIZE - offset );
     525      else
     526        n = Converter::intToByteArray( sync.getUniqueID(), buf + offset, UDP_PACKET_SIZE - offset );
    510527      assert( n == INTSIZE );
    511528      offset += n;
     
    517534   
    518535    assert( peer->second.socket->writePacket( buf, offset ) );
     536    PRINTF(0)("send packet: %d\n", offset);
    519537  }
    520538}
     
    537555  for ( PeerList::iterator peer = peers.begin(); peer != peers.end(); peer++ )
    538556  {
     557    if ( !peer->second.socket )
     558      continue;
     559
    539560    packetLength = peer->second.socket->readPacket( buf, UDP_PACKET_SIZE );
     561
     562    if ( packetLength < 4*INTSIZE )
     563    {
     564      if ( packetLength != 0 )
     565        PRINTF(1)("got too small packet: %d\n", packetLength);
     566      continue;
     567    }
    540568   
    541569    assert( Converter::byteArrayToInt( buf, &length ) == INTSIZE );
     
    543571    assert( Converter::byteArrayToInt( buf + 2*INTSIZE, &fromState ) == INTSIZE );
    544572    assert( Converter::byteArrayToInt( buf + 3*INTSIZE, &ackedState ) == INTSIZE );
     573
     574    PRINTF(0)("got packet: %d, %d\n", length, packetLength);
    545575   
    546576    //if this is an old state drop it
     
    565595     
    566596      for ( SynchronizeableList::iterator it = synchronizeables.begin(); it != synchronizeables.end(); it++ )
    567       {
    568         if ( (*it)->getUniqueID() == uniqueId )
     597      {
     598        //                                        client thinks his handshake has id 0!!!!!
     599        if ( (*it)->getUniqueID() == uniqueId || ( uniqueId == 0 && (*it)->getUniqueID() == peer->second.userId ) )
    569600        {
    570601          sync = *it;
Note: See TracChangeset for help on using the changeset viewer.