Changeset 6219 in orxonox.OLD for branches/network/src/lib/network/network_game_manager.cc
- Timestamp:
- Dec 21, 2005, 1:39:20 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/network/src/lib/network/network_game_manager.cc
r6214 r6219 73 73 b = data[i++]; 74 74 75 if ( b == REQUEST_CREATE ) 76 { 77 return; 78 } 79 if ( b == REQUEST_REMOVE ) 80 { 81 return; 82 } 83 if ( b == CREATE_ENTITY ) 84 { 85 return; 86 } 87 if ( b == REMOVE_ENTITY ) 88 { 89 return; 90 } 75 if ( isServer() ) 76 { 77 if ( b == REQUEST_CREATE ) 78 { 79 if ( !handleRequestCreate( i, data, length, sender ) ) 80 return; 81 continue; 82 } 83 if ( b == REQUEST_REMOVE ) 84 { 85 if ( !handleRequestRemove( i, data, length, sender ) ) 86 return; 87 continue; 88 } 89 } 90 91 if ( !isServer() ) 92 { 93 if ( b == CREATE_ENTITY ) 94 { 95 if ( !handleCreateEntity( i, data, length, sender ) ) 96 return; 97 continue; 98 } 99 if ( b == REMOVE_ENTITY ) 100 { 101 if ( !handleRemoveEntity( i, data, length, sender ) ) 102 return; 103 continue; 104 } 105 if ( b == CREATE_ENTITY_LIST ) 106 { 107 if ( !handleCreateEntityList( i, data, length, sender ) ) 108 return; 109 continue; 110 } 111 if ( b == REMOVE_ENTITY_LIST ) 112 { 113 if ( !handleRemoveEntityList( i, data, length, sender ) ) 114 return; 115 continue; 116 } 117 if ( b == YOU_ARE_ENTITY ) 118 { 119 if ( !handleYouAreEntity( i, data, length, sender ) ) 120 return; 121 continue; 122 } 123 } 124 91 125 if ( b == REQUEST_SYNC ) 92 126 { 93 return; 94 } 95 if ( b == YOU_ARE_ENTITY ) 96 { 97 return; 98 } 99 if ( b == CREATE_ENTITY_LIST ) 100 { 101 return; 102 } 103 if ( b == REMOVE_ENTITY_LIST ) 104 { 105 return; 106 } 127 if ( !handleRequestSync( i, data, length, sender ) ) 128 return; 129 continue; 130 } 131 132 //if we get her something with data is wrong 133 PRINTF(1)("Data is not in the right format! i=%d\n", i); 134 return; 107 135 } 108 136 } … … 156 184 * @param classID: The ID of the class of which an entity should be created 157 185 */ 158 void NetworkGameManager::createEntity( ClassID classID)186 void NetworkGameManager::createEntity( ClassID classID, int owner ) 159 187 { 160 188 if ( this->isServer() ) … … 166 194 } 167 195 168 this->executeCreateEntity( classID, newUniqueID++ );196 this->executeCreateEntity( classID, newUniqueID++, owner ); 169 197 } 170 198 else 171 199 { 172 this->requestCreateEntity( classID );200 this->requestCreateEntity( classID ); 173 201 } 174 202 } … … 570 598 } 571 599 600 bool NetworkGameManager::handleRequestCreate( int & i, const byte * data, int length, int sender ) 601 { 602 if ( INTSIZE > length-i ) 603 { 604 PRINTF(1)("Cannot read classID from buffer! Not enough data left!\n"); 605 return false; 606 } 607 int classID = Converter::byteArrayToInt( data ); 608 i += INTSIZE; 609 610 createEntity( (ClassID)classID ); 611 612 return true; 613 } 614 615 bool NetworkGameManager::handleRequestRemove( int & i, const byte * data, int length, int sender ) 616 { 617 if ( INTSIZE > length-i ) 618 { 619 PRINTF(1)("Cannot read uniqueID from buffer! Not enough data left!\n"); 620 return false; 621 } 622 int uniqueID = Converter::byteArrayToInt( data ); 623 i += INTSIZE; 624 625 removeEntity( uniqueID ); 626 627 return true; 628 } 629 630 bool NetworkGameManager::handleCreateEntity( int & i, const byte * data, int length, int sender ) 631 { 632 if ( INTSIZE > length-i ) 633 { 634 PRINTF(1)("Cannot read classID from buffer! Not enough data left!\n"); 635 return false; 636 } 637 int classID = Converter::byteArrayToInt( data ); 638 i += INTSIZE; 639 640 if ( INTSIZE > length-i ) 641 { 642 PRINTF(1)("Cannot read uniqueID from buffer! Not enough data left!\n"); 643 return false; 644 } 645 int uniqueID = Converter::byteArrayToInt( data ); 646 i += INTSIZE; 647 648 if ( INTSIZE > length-i ) 649 { 650 PRINTF(1)("Cannot read owner from buffer! Not enough data left!\n"); 651 return false; 652 } 653 int owner = Converter::byteArrayToInt( data ); 654 i += INTSIZE; 655 656 doCreateEntity( (ClassID)classID, uniqueID, owner ); 657 658 return true; 659 } 660 661 bool NetworkGameManager::handleRemoveEntity( int & i, const byte * data, int length, int sender ) 662 { 663 if ( INTSIZE > length-i ) 664 { 665 PRINTF(1)("Cannot read uniqueID from buffer! Not enough data left!\n"); 666 return false; 667 } 668 int uniqueID = Converter::byteArrayToInt( data ); 669 i += INTSIZE; 670 671 doRemoveEntity( uniqueID ); 672 673 return true; 674 } 675 676 bool NetworkGameManager::handleCreateEntityList( int & i, const byte * data, int length, int sender ) 677 { 678 if ( INTSIZE > length-i ) 679 { 680 PRINTF(1)("Cannot read n from buffer! Not enough data left!\n"); 681 return false; 682 } 683 int n = Converter::byteArrayToInt( data ); 684 i += INTSIZE; 685 686 int classID, uniqueID, owner; 687 688 for ( int j = 0; j<n; j++ ) 689 { 690 691 if ( INTSIZE > length-i ) 692 { 693 PRINTF(1)("Cannot read classID from buffer! Not enough data left!\n"); 694 return false; 695 } 696 classID = Converter::byteArrayToInt( data ); 697 i += INTSIZE; 698 699 if ( INTSIZE > length-i ) 700 { 701 PRINTF(1)("Cannot read uniqueID from buffer! Not enough data left!\n"); 702 return false; 703 } 704 uniqueID = Converter::byteArrayToInt( data ); 705 i += INTSIZE; 706 707 if ( INTSIZE > length-i ) 708 { 709 PRINTF(1)("Cannot read owner from buffer! Not enough data left!\n"); 710 return false; 711 } 712 owner = Converter::byteArrayToInt( data ); 713 i += INTSIZE; 714 715 doCreateEntity( (ClassID)classID, uniqueID, owner ); 716 717 } 718 return true; 719 } 720 721 bool NetworkGameManager::handleRemoveEntityList( int & i, const byte * data, int length, int sender ) 722 { 723 if ( INTSIZE > length-i ) 724 { 725 PRINTF(1)("Cannot read n from buffer! Not enough data left!\n"); 726 return false; 727 } 728 int n = Converter::byteArrayToInt( data ); 729 i += INTSIZE; 730 731 int uniqueID; 732 733 for ( int j = 0; j<n; j++ ) 734 { 735 736 if ( INTSIZE > length-i ) 737 { 738 PRINTF(1)("Cannot read uniqueID from buffer! Not enough data left!\n"); 739 return false; 740 } 741 uniqueID = Converter::byteArrayToInt( data ); 742 i += INTSIZE; 743 744 doRemoveEntity( uniqueID ); 745 } 746 747 return true; 748 } 749 750 bool NetworkGameManager::handleYouAreEntity( int & i, const byte * data, int length, int sender ) 751 { 752 if ( INTSIZE > length-i ) 753 { 754 PRINTF(1)("Cannot read uniqueID from buffer! Not enough data left!\n"); 755 return false; 756 } 757 int uniqueID = Converter::byteArrayToInt( data ); 758 i += INTSIZE; 759 760 doYouAre( uniqueID ); 761 762 return true; 763 } 764 765 bool NetworkGameManager::handleRequestSync( int & i, const byte * data, int length, int sender ) 766 { 767 if ( INTSIZE > length-i ) 768 { 769 PRINTF(1)("Cannot read uniqueID from buffer! Not enough data left!\n"); 770 return false; 771 } 772 int uniqueID = Converter::byteArrayToInt( data ); 773 i += INTSIZE; 774 775 doRequestSync( uniqueID, sender ); 776 777 return true; 778 } 779
Note: See TracChangeset
for help on using the changeset viewer.