Changeset 7575 in orxonox.OLD for branches/network/src/lib/network/network_stream.cc
- Timestamp:
- May 10, 2006, 4:48:27 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/network/src/lib/network/network_stream.cc
r7571 r7575 64 64 this->networkProtocol = new NetworkProtocol(); 65 65 this->connectionMonitor = new ConnectionMonitor(); 66 this->maxConnections = MAX_CONNECTIONS;67 66 } 68 67 … … 131 130 // setUniqueID( maxCon+2 ) because we need one id for every handshake 132 131 // and one for handshake to reject client maxCon+1 133 this->networkGameManager->setUniqueID( this->maxConnections+ 2 );132 this->networkGameManager->setUniqueID( MAX_CONNECTIONS + 2 ); 134 133 135 134 } … … 142 141 assert( peers[0].handshake == NULL ); 143 142 peers[0].handshake = hs; 143 // peers[0].handshake->setSynchronized( true ); 144 this->connectSynchronizeable(*hs); 144 145 //this->connectSynchronizeable(*hs); 145 PRINTF(0)("NetworkStream: %s\n", hs->getName());146 PRINTF(0)("NetworkStream: Handshake created: %s\n", hs->getName()); 146 147 } 147 148 … … 194 195 } 195 196 197 handleHandshakes(); 198 handleUpstream(); 199 handleDownstream(); 196 200 197 201 … … 354 358 } else 355 359 { 356 clientId = 0;360 clientId = 1; 357 361 358 362 for ( PeerList::iterator it = peers.begin(); it != peers.end(); it++ ) … … 366 370 } 367 371 368 if ( clientId > this->maxConnections)372 if ( clientId > MAX_CONNECTIONS ) 369 373 { 370 374 peers[clientId].handshake->doReject( "too many connections" ); … … 419 423 (*it)->getUniqueID(), (*it)->beSynchronized()); 420 424 } 421 PRINT(0)(" Maximal Connections: %i\n", this->maxConnections);425 PRINT(0)(" Maximal Connections: %i\n", MAX_CONNECTIONS ); 422 426 423 427 } … … 486 490 offset = INTSIZE; //make already space for length 487 491 488 if ( peer->second.socket )492 if ( !peer->second.socket ) 489 493 continue; 490 494 … … 504 508 { 505 509 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()); 506 519 507 520 assert( offset + INTSIZE <= UDP_PACKET_SIZE ); 508 521 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 ); 510 527 assert( n == INTSIZE ); 511 528 offset += n; … … 517 534 518 535 assert( peer->second.socket->writePacket( buf, offset ) ); 536 PRINTF(0)("send packet: %d\n", offset); 519 537 } 520 538 } … … 537 555 for ( PeerList::iterator peer = peers.begin(); peer != peers.end(); peer++ ) 538 556 { 557 if ( !peer->second.socket ) 558 continue; 559 539 560 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 } 540 568 541 569 assert( Converter::byteArrayToInt( buf, &length ) == INTSIZE ); … … 543 571 assert( Converter::byteArrayToInt( buf + 2*INTSIZE, &fromState ) == INTSIZE ); 544 572 assert( Converter::byteArrayToInt( buf + 3*INTSIZE, &ackedState ) == INTSIZE ); 573 574 PRINTF(0)("got packet: %d, %d\n", length, packetLength); 545 575 546 576 //if this is an old state drop it … … 565 595 566 596 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 ) ) 569 600 { 570 601 sync = *it;
Note: See TracChangeset
for help on using the changeset viewer.