Changeset 7659 in orxonox.OLD for branches/network/src
- Timestamp:
- May 17, 2006, 11:07:53 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/network/src/lib/network/network_stream.cc
r7631 r7659 581 581 continue; 582 582 583 packetLength = peer->second.socket->readPacket( buf, UDP_PACKET_SIZE ); 584 585 if ( packetLength < 4*INTSIZE ) 586 { 587 if ( packetLength != 0 ) 588 PRINTF(1)("got too small packet: %d\n", packetLength); 589 continue; 590 } 591 592 assert( Converter::byteArrayToInt( buf, &length ) == INTSIZE ); 593 assert( Converter::byteArrayToInt( buf + INTSIZE, &state ) == INTSIZE ); 594 assert( Converter::byteArrayToInt( buf + 2*INTSIZE, &fromState ) == INTSIZE ); 595 assert( Converter::byteArrayToInt( buf + 3*INTSIZE, &ackedState ) == INTSIZE ); 596 offset = 4*INTSIZE; 597 598 PRINTF(0)("got packet: %d, %d\n", length, packetLength); 583 while ( packetLength = peer->second.socket->readPacket( buf, UDP_PACKET_SIZE ) > 0 ) 584 { 585 586 if ( packetLength < 4*INTSIZE ) 587 { 588 if ( packetLength != 0 ) 589 PRINTF(1)("got too small packet: %d\n", packetLength); 590 continue; 591 } 592 593 assert( Converter::byteArrayToInt( buf, &length ) == INTSIZE ); 594 assert( Converter::byteArrayToInt( buf + INTSIZE, &state ) == INTSIZE ); 595 assert( Converter::byteArrayToInt( buf + 2*INTSIZE, &fromState ) == INTSIZE ); 596 assert( Converter::byteArrayToInt( buf + 3*INTSIZE, &ackedState ) == INTSIZE ); 597 offset = 4*INTSIZE; 598 599 PRINTF(0)("got packet: %d, %d\n", length, packetLength); 599 600 600 601 //if this is an old state drop it 601 if ( state <= peer->second.lastRecvedState )602 continue;603 604 if ( packetLength != length )605 {606 PRINTF(1)("real packet length (%d) and transmitted packet length (%d) do not match!\n", packetLength, length);607 peer->second.socket->disconnectServer();608 continue;609 }610 611 while ( offset < length )612 {613 assert( Converter::byteArrayToInt( buf + offset, &uniqueId ) == INTSIZE );614 offset += INTSIZE;615 616 assert( Converter::byteArrayToInt( buf + offset, &syncDataLength ) == INTSIZE );617 offset += INTSIZE;618 619 Synchronizeable * sync = NULL;620 621 for ( SynchronizeableList::iterator it = synchronizeables.begin(); it != synchronizeables.end(); it++ )622 {602 if ( state <= peer->second.lastRecvedState ) 603 continue; 604 605 if ( packetLength != length ) 606 { 607 PRINTF(1)("real packet length (%d) and transmitted packet length (%d) do not match!\n", packetLength, length); 608 peer->second.socket->disconnectServer(); 609 continue; 610 } 611 612 while ( offset < length ) 613 { 614 assert( Converter::byteArrayToInt( buf + offset, &uniqueId ) == INTSIZE ); 615 offset += INTSIZE; 616 617 assert( Converter::byteArrayToInt( buf + offset, &syncDataLength ) == INTSIZE ); 618 offset += INTSIZE; 619 620 Synchronizeable * sync = NULL; 621 622 for ( SynchronizeableList::iterator it = synchronizeables.begin(); it != synchronizeables.end(); it++ ) 623 { 623 624 // client thinks his handshake has id 0!!!!! 624 if ( (*it)->getUniqueID() == uniqueId || ( uniqueId == 0 && (*it)->getUniqueID() == peer->second.userId ) )625 {626 sync = *it;627 break;628 }629 }630 631 if ( sync == NULL )632 {633 if ( oldSynchronizeables.find( uniqueId ) != oldSynchronizeables.end() )634 {635 offset += syncDataLength;636 continue;637 }625 if ( (*it)->getUniqueID() == uniqueId || ( uniqueId == 0 && (*it)->getUniqueID() == peer->second.userId ) ) 626 { 627 sync = *it; 628 break; 629 } 630 } 631 632 if ( sync == NULL ) 633 { 634 if ( oldSynchronizeables.find( uniqueId ) != oldSynchronizeables.end() ) 635 { 636 offset += syncDataLength; 637 continue; 638 } 638 639 639 640 //TODO dont accept new object from all peers (probably only servers) 640 int leafClassId;641 if ( INTSIZE > length - offset )642 {643 offset += syncDataLength;644 continue;645 }641 int leafClassId; 642 if ( INTSIZE > length - offset ) 643 { 644 offset += syncDataLength; 645 continue; 646 } 646 647 647 Converter::byteArrayToInt( buf + offset, &leafClassId );648 Converter::byteArrayToInt( buf + offset, &leafClassId ); 648 649 649 BaseObject * b;650 /* These are some small exeptions in creation: Not all objects can/should be created via Factory */651 /* Exception 1: NullParent */652 if( leafClassId == CL_NULL_PARENT || leafClassId == CL_SYNCHRONIZEABLE )653 {654 PRINTF(1)("Can not create Class with ID %x!\n", (int)leafClassId);655 offset += syncDataLength;656 continue;657 }658 else659 b = Factory::fabricate( (ClassID)leafClassId );660 661 if ( !b )662 {663 PRINTF(1)("Could not fabricate Object with classID %x\n", leafClassId);664 offset += syncDataLength;665 continue;666 }650 BaseObject * b; 651 /* These are some small exeptions in creation: Not all objects can/should be created via Factory */ 652 /* Exception 1: NullParent */ 653 if( leafClassId == CL_NULL_PARENT || leafClassId == CL_SYNCHRONIZEABLE ) 654 { 655 PRINTF(1)("Can not create Class with ID %x!\n", (int)leafClassId); 656 offset += syncDataLength; 657 continue; 658 } 659 else 660 b = Factory::fabricate( (ClassID)leafClassId ); 661 662 if ( !b ) 663 { 664 PRINTF(1)("Could not fabricate Object with classID %x\n", leafClassId); 665 offset += syncDataLength; 666 continue; 667 } 667 668 668 if ( b->isA(CL_SYNCHRONIZEABLE) ) 669 { 670 sync = dynamic_cast<Synchronizeable*>(b); 671 sync->setUniqueID( uniqueId ); 672 sync->setSynchronized(true); 673 674 PRINTF(0)("Fabricated %s with id %d\n", sync->getClassName(), sync->getUniqueID()); 675 } 676 else 677 { 678 PRINTF(1)("Class with ID %x is not a synchronizeable!\n", (int)leafClassId); 679 delete b; 680 offset += syncDataLength; 681 continue; 682 } 669 if ( b->isA(CL_SYNCHRONIZEABLE) ) 670 { 671 sync = dynamic_cast<Synchronizeable*>(b); 672 sync->setUniqueID( uniqueId ); 673 sync->setSynchronized(true); 674 675 PRINTF(0)("Fabricated %s with id %d\n", sync->getClassName(), sync->getUniqueID()); 676 } 677 else 678 { 679 PRINTF(1)("Class with ID %x is not a synchronizeable!\n", (int)leafClassId); 680 delete b; 681 offset += syncDataLength; 682 continue; 683 } 684 } 685 686 offset += sync->setStateDiff( peer->second.userId, buf+offset, length-offset, state, fromState ); 683 687 } 684 685 offset += sync->setStateDiff( peer->second.userId, buf+offset, length-offset, state, fromState ); 686 } 687 688 if ( offset != length ) 689 { 690 peer->second.socket->disconnectServer(); 691 } 692 693 peer->second.lastAckedState = ackedState; 694 } 695 696 } 697 698 699 700 701 702 688 689 if ( offset != length ) 690 { 691 peer->second.socket->disconnectServer(); 692 } 693 694 peer->second.lastAckedState = ackedState; 695 } 696 697 } 698 699 } 700 701 702 703 704 705
Note: See TracChangeset
for help on using the changeset viewer.