- Timestamp:
- May 30, 2018, 2:56:24 PM (7 years ago)
- Location:
- code/branches/PresentationFS18
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/PresentationFS18
- Property svn:mergeinfo changed
/code/branches/Masterserver_FS18 (added) merged: 11816,11829,11842,11856,11858,11880,11889,11905,11907,11910,11929-11930,11937,11962-11963,11973,11983,11990
- Property svn:mergeinfo changed
-
code/branches/PresentationFS18/src/libraries/network/packet/Acknowledgement.cc
r11071 r12020 37 37 38 38 #define PACKET_FLAGS_ACK 0 39 // Offset to start of packet ID 39 40 #define _PACKETID 0 41 // Offset to start of ACK ID 40 42 #define _ACKID _PACKETID + sizeof(packet::Type) 41 43 44 /** 45 * Constructor 46 * Acknowledgement.data_ is 40 bits in size: 47 * [0, 7]: Packet Type 48 * [8, 39]: Acknowledgement ID 49 */ 42 50 Acknowledgement::Acknowledgement( unsigned int id, unsigned int peerID ) 43 51 : Packet() 44 52 { 45 flags_ = flags_ |PACKET_FLAGS_ACK;46 data_=new uint8_t[getSize() ];47 *(Type *)( data_ + _PACKETID) = Type::Acknowledgement;48 *(uint32_t *)( data_ + _ACKID) = id;49 peerID_=peerID;53 this->flags_ |= PACKET_FLAGS_ACK; 54 this->data_ = new uint8_t[ this->getSize() ]; 55 *(Type *)(this->data_ + _PACKETID) = Type::Acknowledgement; 56 *(uint32_t *)(this->data_ + _ACKID) = id; 57 this->peerID_ = peerID; 50 58 } 51 59 … … 59 67 } 60 68 61 unsigned int Acknowledgement::getSize() const {69 unsigned int Acknowledgement::getSize() const { 62 70 return _ACKID + sizeof(uint32_t); 63 71 } 64 72 65 bool Acknowledgement::process(orxonox::Host* host) {73 bool Acknowledgement::process(orxonox::Host* host) { 66 74 orxout(verbose_more, context::packets) << "processing ACK with ID: " << getAckID() << endl; 67 75 bool b = host->ackGamestate(getAckID(), peerID_); … … 70 78 } 71 79 72 unsigned int Acknowledgement::getAckID() {80 unsigned int Acknowledgement::getAckID() { 73 81 return *(uint32_t *)(data_ + _ACKID); 74 82 } -
code/branches/PresentationFS18/src/libraries/network/packet/Acknowledgement.h
r11071 r12020 34 34 35 35 namespace orxonox { 36 36 37 const unsigned int ACKID_NACK = 0; 38 37 39 namespace packet { 38 /** 39 @author 40 */ 40 41 41 class _NetworkExport Acknowledgement : public Packet 42 42 { -
code/branches/PresentationFS18/src/libraries/network/packet/Chat.cc
r11071 r12020 38 38 #define PACKET_FLAGS_CHAT PacketFlag::Reliable 39 39 40 /* Some lengths */40 /* Some lengths / offsets */ 41 41 #define _PACKETID 0 42 42 #define _SOURCEID _PACKETID + sizeof(Type) … … 49 49 { 50 50 /* Add chat flag to packet flags */ 51 flags_ = flags_ |PACKET_FLAGS_CHAT;51 this->flags_ |= PACKET_FLAGS_CHAT; 52 52 53 53 /* set message length to length of input string + 1 */ 54 messageLength_ = message.length()+1;54 this->messageLength_ = message.length() + 1; 55 55 56 56 /* allocate memory for the data */ 57 data_=new unsigned char[ getSize() ];57 this->data_ = new unsigned char[ getSize() ]; 58 58 59 59 *(Type *)(data_ + _PACKETID ) = Type::Chat; 60 60 *(unsigned int *)(data_ + _SOURCEID ) = sourceID; 61 61 *(unsigned int *)(data_ + _TARGETID ) = targetID; 62 *(unsigned int *)(data_ + _MESSAGELENGTH ) = messageLength_;62 *(unsigned int *)(data_ + _MESSAGELENGTH ) = this->messageLength_; 63 63 64 64 /* cast the hell out of the message string, and copy it into the 65 65 * data buffer. 66 66 */ 67 memcpy( data_+_MESSAGE, static_cast<void*>(const_cast<char*>(message.c_str())),messageLength_ );67 memcpy( this->data_ + _MESSAGE, static_cast<void*>(const_cast<char*>(message.c_str())), this->messageLength_ ); 68 68 } 69 69 … … 71 71 : Packet(data, clientID) 72 72 { 73 messageLength_ = *(uint32_t *)(data + _MESSAGELENGTH );73 this->messageLength_ = *(uint32_t *)(data + _MESSAGELENGTH ); 74 74 } 75 75 … … 79 79 80 80 unsigned int Chat::getSize() const{ 81 return _MESSAGE + messageLength_;81 return _MESSAGE + this->messageLength_; 82 82 } 83 83 84 84 bool Chat::process(orxonox::Host* host){ 85 host->doReceiveChat(std::string((const char*)data_+_MESSAGE), *(uint32_t *)(data_+_SOURCEID), *(uint32_t *)(data_+_TARGETID)); 85 host->doReceiveChat(std::string((const char*)this->data_ + _MESSAGE), 86 *(uint32_t *)(this->data_+_SOURCEID), 87 *(uint32_t *)(this->data_+_TARGETID)); 86 88 delete this; 87 89 return true; 88 90 } 89 91 90 unsigned char *Chat::getMessage() {91 return data_ + _MESSAGE;92 unsigned char *Chat::getMessage() { 93 return this->data_ + _MESSAGE; 92 94 } 93 95 -
code/branches/PresentationFS18/src/libraries/network/packet/Chat.h
r11071 r12020 55 55 56 56 /* Get the length of the message (not the full size of the packet) */ 57 unsigned int getMessageLength() { returnmessageLength_; };57 unsigned int getMessageLength() { return this->messageLength_; }; 58 58 59 59 /* return message content */ -
code/branches/PresentationFS18/src/libraries/network/packet/ClassID.cc
r11071 r12020 46 46 47 47 48 ClassID::ClassID( ) : Packet(){48 ClassID::ClassID() : Packet() { 49 49 Identifier *id; 50 unsigned int nrOfClasses =0;51 unsigned int packetSize =2*sizeof(uint32_t); //space for the packetID and for the nrofclasses50 unsigned int nrOfClasses = 0; 51 unsigned int packetSize = 2 * sizeof(uint32_t); //space for the packetID and for the nrofclasses 52 52 uint32_t network_id; 53 flags_ = flags_ |PACKET_FLAGS_CLASSID;53 this->flags_ |= PACKET_FLAGS_CLASSID; 54 54 std::queue<std::pair<uint32_t, std::string>> tempQueue; 55 55 56 // calculate total needed size (for all strings and integers)57 for(const auto& mapEntry : IdentifierManager::getInstance().getIdentifierByStringMap()) {56 // calculate total needed size (for all strings and integers) 57 for(const auto& mapEntry : IdentifierManager::getInstance().getIdentifierByStringMap()) { 58 58 id = mapEntry.second; 59 59 if(id == nullptr || !id->hasFactory()) … … 64 64 tempQueue.push( std::pair<unsigned int, std::string>(network_id, classname) ); 65 65 ++nrOfClasses; 66 packetSize += (classname.size() +1)+sizeof(network_id)+sizeof(uint32_t);66 packetSize += (classname.size() + 1) + sizeof(network_id) + sizeof(uint32_t); 67 67 } 68 68 69 this->data_ =new uint8_t[ packetSize ];69 this->data_ = new uint8_t[ packetSize ]; 70 70 //set the appropriate packet id 71 71 assert(this->data_); 72 72 *(Type *)(this->data_ + _PACKETID ) = Type::ClassID; 73 73 74 uint8_t *temp =data_+sizeof(uint32_t);74 uint8_t *temp = this->data_ + sizeof(uint32_t); 75 75 // save the number of all classes 76 *(uint32_t*) temp = nrOfClasses;76 *(uint32_t*) temp = nrOfClasses; 77 77 temp += sizeof(uint32_t); 78 78 79 79 // now save all classids and classnames 80 80 std::pair<uint32_t, std::string> tempPair; 81 uint32_t tempsize = 2 *sizeof(uint32_t); // packetid and nrOfClasses81 uint32_t tempsize = 2 * sizeof(uint32_t); // packetid and nrOfClasses 82 82 while( !tempQueue.empty() ){ 83 83 tempPair = tempQueue.front(); 84 84 tempQueue.pop(); 85 *(uint32_t*) temp = tempPair.first;86 *(uint32_t*) (temp+sizeof(uint32_t)) = tempPair.second.size()+1;87 memcpy(temp +2*sizeof(uint32_t), tempPair.second.c_str(), tempPair.second.size()+1);88 temp +=2*sizeof(uint32_t)+tempPair.second.size()+1;89 tempsize +=2*sizeof(uint32_t)+tempPair.second.size()+1;85 *(uint32_t*) temp = tempPair.first; 86 *(uint32_t*) (temp+sizeof(uint32_t)) = tempPair.second.size() + 1; 87 memcpy(temp + 2 * sizeof(uint32_t), tempPair.second.c_str(), tempPair.second.size() + 1); 88 temp += 2 * sizeof(uint32_t) + tempPair.second.size() + 1; 89 tempsize += 2 * sizeof(uint32_t) + tempPair.second.size() + 1; 90 90 } 91 assert(tempsize ==packetSize);91 assert(tempsize == packetSize); 92 92 93 93 orxout(verbose_more, context::packets) << "classid packetSize is " << packetSize << endl; … … 104 104 } 105 105 106 uint32_t ClassID::getSize() const {107 uint8_t *temp = data_+sizeof(uint32_t); // packet identification106 uint32_t ClassID::getSize() const { 107 uint8_t *temp = this->data_ + sizeof(uint32_t); // packet identification 108 108 uint32_t totalsize = sizeof(uint32_t); // packet identification 109 uint32_t nrOfClasses = *(uint32_t*) temp;109 uint32_t nrOfClasses = *(uint32_t*) temp; 110 110 temp += sizeof(uint32_t); 111 111 totalsize += sizeof(uint32_t); // storage size for nr of all classes 112 112 113 for(unsigned int i=0; i <nrOfClasses; i++){114 totalsize += 2 *sizeof(uint32_t) + *(uint32_t*)(temp + sizeof(uint32_t));115 temp += 2 *sizeof(uint32_t) + *(uint32_t*)(temp + sizeof(uint32_t));113 for(unsigned int i=0; i < nrOfClasses; i++) { 114 totalsize += 2 * sizeof(uint32_t) + *(uint32_t*) (temp + sizeof(uint32_t)); 115 temp += 2 * sizeof(uint32_t) + *(uint32_t*)(temp + sizeof(uint32_t)); 116 116 } 117 117 return totalsize; 118 118 } 119 119 120 121 bool ClassID::process(orxonox::Host* host){ 120 bool ClassID::process(orxonox::Host* host) { 122 121 int nrOfClasses; 123 uint8_t *temp = data_+sizeof(uint32_t); //skip the packetid122 uint8_t *temp = this->data_ + sizeof(uint32_t); //skip the packetid 124 123 uint32_t networkID; 125 124 uint32_t stringsize; 126 125 unsigned char *classname; 127 128 126 129 127 //clear the map of network ids … … 134 132 Identifier *id; 135 133 // read the total number of classes 136 nrOfClasses = *(uint32_t*) temp;134 nrOfClasses = *(uint32_t*) temp; 137 135 temp += sizeof(uint32_t); 138 136 139 for( int i =0; i<nrOfClasses; i++){140 networkID = *(uint32_t*) temp;141 stringsize = *(uint32_t*) (temp+sizeof(uint32_t));142 classname = temp +2*sizeof(uint32_t);143 id =ClassByString( std::string((const char*)classname) );137 for( int i = 0; i < nrOfClasses; i++) { 138 networkID = *(uint32_t*) temp; 139 stringsize = *(uint32_t*) (temp + sizeof(uint32_t)); 140 classname = temp + 2 * sizeof(uint32_t); 141 id = ClassByString( std::string((const char*) classname) ); 144 142 orxout(internal_info, context::packets) << "processing classid: " << networkID << " name: " << classname << " id: " << id << endl; 145 if(id ==nullptr){143 if(id == nullptr) { 146 144 orxout(user_error, context::packets) << "Received a bad classname" << endl; 147 145 abort(); 148 146 } 149 147 id->setNetworkID( networkID ); 150 temp += 2 *sizeof(uint32_t) + stringsize;148 temp += 2 * sizeof(uint32_t) + stringsize; 151 149 } 152 150 delete this; -
code/branches/PresentationFS18/src/libraries/network/packet/DeleteObjects.cc
r11071 r12020 45 45 : Packet() 46 46 { 47 flags_ = flags_ |PACKET_FLAG_DELETE;47 this->flags_ |= PACKET_FLAG_DELETE; 48 48 } 49 49 … … 60 60 { 61 61 unsigned int number = Synchronisable::getNumberOfDeletedObject(); 62 if(number ==0)62 if(number == 0) 63 63 return false; 64 64 orxout(verbose, context::packets) << "sending DeleteObjects: "; … … 83 83 { 84 84 assert(data_); 85 return _OBJECTIDS + *(uint32_t*) (data_+_QUANTITY)*sizeof(uint32_t);85 return _OBJECTIDS + *(uint32_t*) (this->data_ + _QUANTITY) * sizeof(uint32_t); 86 86 } 87 87 88 88 bool DeleteObjects::process(orxonox::Host* host) 89 89 { 90 for(unsigned int i =0; i<*(unsigned int *)(data_+_QUANTITY); i++)90 for(unsigned int i = 0; i < *(unsigned int *) (this->data_+_QUANTITY); i++) 91 91 { 92 92 orxout(verbose, context::packets) << "deleting object with id: " << *(uint32_t*)(data_+_OBJECTIDS+i*sizeof(uint32_t)) << endl; 93 Synchronisable::deleteObject( *(uint32_t*)( data_+_OBJECTIDS+i*sizeof(uint32_t)) );93 Synchronisable::deleteObject( *(uint32_t*)(this->data_ + _OBJECTIDS + i * sizeof(uint32_t)) ); 94 94 } 95 95 delete this; -
code/branches/PresentationFS18/src/libraries/network/packet/FunctionCalls.cc
r11071 r12020 63 63 assert(isDataENetAllocated()); 64 64 65 uint8_t* temp = data_ +sizeof(uint32_t); //skip packetid66 uint32_t nrOfCalls = *(uint32_t*) temp;65 uint8_t* temp = data_ + sizeof(uint32_t); //skip packetid 66 uint32_t nrOfCalls = *(uint32_t*) temp; 67 67 temp += sizeof(uint32_t); 68 this->minGamestateID_ = *(uint32_t*) temp;68 this->minGamestateID_ = *(uint32_t*) temp; 69 69 temp += sizeof(uint32_t); 70 for( unsigned int i = 0; i <nrOfCalls; i++ )70 for( unsigned int i = 0; i < nrOfCalls; i++ ) 71 71 { 72 72 FunctionCall fctCall; … … 95 95 this->minGamestateID_ = host->getCurrentGamestateID(); 96 96 assert(this->functionCalls_.size()); 97 data_=new uint8_t[ currentSize_ ];98 *(Type *)( data_ + _PACKETID ) = Type::FunctionCalls; // Set the Packet ID99 *(uint32_t*)( data_+sizeof(uint32_t)) = this->functionCalls_.size(); // set nrOfCalls100 *(uint32_t*)( data_+2*sizeof(uint32_t)) = this->minGamestateID_; // set minGamestateID_101 uint8_t* temp = data_+3*sizeof(uint32_t);97 this->data_ = new uint8_t[ currentSize_ ]; 98 *(Type *)(this->data_ + _PACKETID ) = Type::FunctionCalls; // Set the Packet ID 99 *(uint32_t*)(this->data_ + sizeof(uint32_t)) = this->functionCalls_.size(); // set nrOfCalls 100 *(uint32_t*)(this->data_ + 2 * sizeof(uint32_t)) = this->minGamestateID_; // set minGamestateID_ 101 uint8_t* temp = this->data_ + 3 * sizeof(uint32_t); 102 102 103 103 while( this->functionCalls_.size() ) … … 107 107 } 108 108 109 assert( temp ==data_+currentSize_ );109 assert( temp == this->data_ + currentSize_ ); 110 110 111 111 Packet::send(host); -
code/branches/PresentationFS18/src/libraries/network/packet/Gamestate.cc
r11083 r12020 46 46 #define GAMESTATE_START(data) (data + GamestateHeader::getSize()) 47 47 48 // #define PACKET_FLAG_GAMESTATE PacketFlag::Reliable49 48 #define PACKET_FLAG_GAMESTATE 0 50 49 … … 102 101 } 103 102 104 103 //AV: This takes all synchronisables and packs it in a GameState, to be sent over the network 105 104 bool Gamestate::collectData(int id, uint8_t mode) 106 105 { … … 128 127 for(it = ObjectList<Synchronisable>().begin(); it; ++it) 129 128 { 130 131 // tempsize=it->getSize(id, mode);132 129 133 130 tempsize = it->getData(mem, this->sizes_, id, mode); … … 173 170 } 174 171 175 172 //AV: This takes the Gamestate received from the network and "unpacks" it back to a list of Objects/Synchronisables, thus updating the data 176 173 bool Gamestate::spreadData(uint8_t mode) 177 174 { … … 196 193 else 197 194 { 198 // orxout(verbose, context::packets) << "not creating object of classid " << objectheader.getClassID() << endl;199 195 mem += objectheader.getDataSize() + ( objectheader.isDiffed() ? SynchronisableHeaderLight::getSize() : SynchronisableHeader::getSize() ); 200 196 } … … 202 198 else 203 199 { 204 // orxout(verbose, context::packets) << "updating object of classid " << objectheader.getClassID() << endl;205 200 OrxVerify(s->updateData(mem, mode), "ERROR: could not update Synchronisable with Gamestate data"); 206 201 } 207 202 } 208 203 assert((uintptr_t)(mem-data_) == GamestateHeader::getSize()+header_.getDataSize()); 209 210 // In debug mode, check first, whether there are no duplicate objectIDs211 #ifndef NDEBUG212 if(this->getID()%1000==1)213 {214 std::list<uint32_t> v1;215 for (Synchronisable* synchronisable : ObjectList<Synchronisable>())216 {217 if (synchronisable->getObjectID() == OBJECTID_UNKNOWN)218 {219 if (synchronisable->objectMode_ != 0x0)220 {221 orxout(user_error, context::packets) << "Found object with OBJECTID_UNKNOWN on the client with objectMode != 0x0!" << endl;222 orxout(user_error, context::packets) << "Possible reason for this error: Client created a synchronized object without the Server's approval." << endl;223 orxout(user_error, context::packets) << "Objects class: " << synchronisable->getIdentifier()->getName() << endl;224 assert(false);225 }226 }227 else228 {229 for (uint32_t id : v1)230 {231 if (synchronisable->getObjectID() == id)232 {233 orxout(user_error, context::packets) << "Found duplicate objectIDs on the client!" << endl234 << "Are you sure you don't create a Sychnronisable objcect with 'new' \235 that doesn't have objectMode = 0x0?" << endl;236 assert(false);237 }238 }239 v1.push_back(synchronisable->getObjectID());240 }241 }242 }243 #endif244 204 return true; 245 205 } … … 276 236 } 277 237 278 238 //AV: This function takes the Gamestate and compresses it for transmission over the network 279 239 bool Gamestate::compressData() 280 240 { … … 313 273 } 314 274 315 275 //AV: This function takes the compressed Gamestate received from the network and decompresses it for further unpacking 316 276 bool Gamestate::decompressData() 317 277 { … … 374 334 if( memcmp( origDataPtr+objectOffset, baseDataPtr+objectOffset, objectHeader.getDataSize()) == 0 ) 375 335 { 376 // orxout(verbose, context::packets) << "skip object " << Synchronisable::getSynchronisable(objectHeader.getObjectID())->getIdentifier()->getName() << endl;377 336 origDataPtr += objectOffset + objectHeader.getDataSize(); // skip the whole object 378 337 baseDataPtr += objectOffset + objectHeader.getDataSize(); … … 430 389 inline void /*Gamestate::*/copyObject( uint8_t*& newData, uint8_t*& origData, uint8_t*& baseData, SynchronisableHeader& objectHeader, std::vector<uint32_t>::iterator& sizes ) 431 390 { 432 // orxout(verbose, context::packets) << "docopy" << endl;433 391 // Just copy over the whole Object 434 392 memcpy( newData, origData, objectHeader.getDataSize()+SynchronisableHeader::getSize() ); … … 437 395 newData += objectHeader.getDataSize()+SynchronisableHeader::getSize(); 438 396 origData += objectHeader.getDataSize()+SynchronisableHeader::getSize(); 439 // SynchronisableHeader baseHeader( baseData ); 440 // baseData += baseHeader.getDataSize()+SynchronisableHeader::getSize(); 441 // orxout(verbose, context::packets) << "copy " << h.getObjectID() << endl; 442 // orxout(verbose, context::packets) << "copy " << h.getObjectID() << ":"; 397 443 398 sizes += Synchronisable::getSynchronisable(objectHeader.getObjectID())->getNrOfVariables(); 444 // for( unsigned int i = 0; i < Synchronisable::getSynchronisable(objectHeader.getObjectID())->getNrOfVariables(); ++i ) 445 // { 446 // // orxout(verbose, context::packets) << " " << *sizes; 447 // ++sizes; 448 // } 449 // orxout(verbose, context::packets) << endl; 399 450 400 } 451 401 … … 501 451 uint8_t *origDataEnd = origDataPtr + header_.getDataSize(); 502 452 uint8_t *baseDataEnd = baseDataPtr + base->header_.getDataSize(); 503 // uint32_t origLength = header_.getDataSize(); 504 // uint32_t baseLength = base->header_.getDataSize(); 453 505 454 506 455 // Allocate new space for diffed gamestate … … 595 544 596 545 597 /*Gamestate* Gamestate::diffData(Gamestate *base)598 {599 assert(this && base); assert(data_ && base->data_);600 assert(!header_.isCompressed() && !base->header_.isCompressed());601 assert(!header_.isDiffed());602 603 uint8_t *basep = GAMESTATE_START(base->data_);604 uint8_t *gs = GAMESTATE_START(this->data_);605 uint32_t dest_length = header_.getDataSize();606 607 if(dest_length==0)608 return nullptr;609 610 uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()];611 uint8_t *dest = GAMESTATE_START(ndata);612 613 rawDiff( dest, gs, basep, header_.getDataSize(), base->header_.getDataSize() );614 #ifndef NDEBUG615 uint8_t *dest2 = new uint8_t[dest_length];616 rawDiff( dest2, dest, basep, header_.getDataSize(), base->header_.getDataSize() );617 assert( memcmp( dest2, gs, dest_length) == 0 );618 delete dest2;619 #endif620 621 Gamestate *g = new Gamestate(ndata, getClientID());622 assert(g->header_);623 *(g->header_) = *header_;624 g->header_.setDiffed( true );625 g->header_.setBaseID( base->getID() );626 g->flags_=flags_;627 g->packetDirection_ = packetDirection_;628 assert(g->isDiffed());629 assert(!g->isCompressed());630 return g;631 }632 633 634 Gamestate* Gamestate::undiff(Gamestate *base)635 {636 assert(this && base); assert(data_ && base->data_);637 assert(!header_.isCompressed() && !base->header_.isCompressed());638 assert(header_.isDiffed());639 640 uint8_t *basep = GAMESTATE_START(base->data_);641 uint8_t *gs = GAMESTATE_START(this->data_);642 uint32_t dest_length = header_.getDataSize();643 644 if(dest_length==0)645 return nullptr;646 647 uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()];648 uint8_t *dest = ndata + GamestateHeader::getSize();649 650 rawDiff( dest, gs, basep, header_.getDataSize(), base->header_.getDataSize() );651 652 Gamestate *g = new Gamestate(ndata, getClientID());653 assert(g->header_);654 *(g->header_) = *header_;655 g->header_.setDiffed( false );656 g->flags_=flags_;657 g->packetDirection_ = packetDirection_;658 assert(!g->isDiffed());659 assert(!g->isCompressed());660 return g;661 }662 663 664 void Gamestate::rawDiff( uint8_t* newdata, uint8_t* data, uint8_t* basedata, uint32_t datalength, uint32_t baselength)665 {666 uint64_t* gd = (uint64_t*)data;667 uint64_t* bd = (uint64_t*)basedata;668 uint64_t* nd = (uint64_t*)newdata;669 670 unsigned int i;671 for( i=0; i<datalength/8; i++ )672 {673 if( i<baselength/8 )674 *(nd+i) = *(gd+i) ^ *(bd+i); // xor the data675 else676 *(nd+i) = *(gd+i); // just copy over the data677 }678 unsigned int j;679 // now process the rest (when datalength isn't a multiple of 4)680 for( j = 8*(datalength/8); j<datalength; j++ )681 {682 if( j<baselength )683 *(newdata+j) = *(data+j) ^ *(basedata+j); // xor684 else685 *(newdata+j) = *(data+j); // just copy686 }687 assert(j==datalength);688 }*/689 690 691 /*Gamestate* Gamestate::doSelection(unsigned int clientID, unsigned int targetSize){692 assert(data_);693 std::list<obj>::iterator it;694 695 // allocate memory for new data696 uint8_t *gdata = new uint8_t[header_.getDataSize()+GamestateHeader::getSize()];697 // create a gamestate out of it698 Gamestate *gs = new Gamestate(gdata);699 uint8_t *newdata = gdata + GamestateHeader::getSize();700 uint8_t *origdata = GAMESTATE_START(data_);701 702 //copy the GamestateHeader703 assert(gs->header_);704 *(gs->header_) = *header_;705 706 uint32_t objectOffset;707 unsigned int objectsize, destsize=0;708 // TODO: Why is this variable not used?709 //Synchronisable *object;710 711 //call TrafficControl712 TrafficControl::getInstance()->processObjectList( clientID, header_.getID(), dataVector_ );713 714 //copy in the zeros715 // std::list<obj>::iterator itt;716 // orxout() << "myvector contains:";717 // for ( itt=dataVector_.begin() ; itt!=dataVector_.end(); itt++ )718 // orxout() << " " << (*itt).objID;719 // orxout() << endl;720 for(it=dataVector_.begin(); it!=dataVector_.end();){721 SynchronisableHeader oldobjectheader(origdata);722 SynchronisableHeader newobjectheader(newdata);723 if ( (*it).objSize == 0 )724 {725 ++it;726 continue;727 }728 objectsize = oldobjectheader.getDataSize()+SynchronisableHeader::getSize();729 objectOffset=SynchronisableHeader::getSize(); //skip the size and the availableData variables in the objectheader730 if ( (*it).objID == oldobjectheader.getObjectID() ){731 memcpy(newdata, origdata, objectsize);732 ++it;733 }else{734 newobjectheader = oldobjectheader;735 memset(newdata+objectOffset, 0, objectsize-objectOffset);736 }737 newdata += objectsize;738 origdata += objectsize;739 destsize += objectsize;740 }741 #ifndef NDEBUG742 uint32_t origsize = destsize;743 while ( origsize < header_.getDataSize() )744 {745 SynchronisableHeader oldobjectheader(origdata);746 objectsize = oldobjectheader.getDataSize()+SynchronisableHeader::getSize();747 origdata += objectsize;748 origsize += objectsize;749 }750 assert(origsize==header_.getDataSize());751 assert(destsize!=0);752 #endif753 gs->header_.setDataSize( destsize );754 return gs;755 }*/756 757 758 546 uint32_t Gamestate::calcGamestateSize(uint32_t id, uint8_t mode) 759 547 { -
code/branches/PresentationFS18/src/libraries/network/packet/Gamestate.h
r11071 r12020 57 57 GamestateHeader(uint8_t* data) 58 58 { assert(data); data_ = data; *(Type*)data_ = Type::Gamestate; } 59 /*GamestateHeader(uint8_t* data, GamestateHeader* h)60 { assert(data); data_=data; memcpy(data_, h->data_, getSize()); }*/61 59 void setData(uint8_t* data) 62 60 { assert(data); data_ = data; *(Type*)data_ = Type::Gamestate; } … … 127 125 inline uint32_t getDataSize() const { return header_.getDataSize(); } 128 126 Gamestate* diffVariables(Gamestate *base); 129 // Gamestate* diffData(Gamestate *base); 130 // Gamestate *undiff(Gamestate *base); 131 // Gamestate* doSelection(unsigned int clientID, unsigned int targetSize); 127 132 128 bool compressData(); 133 129 bool decompressData(); … … 136 132 // Packet functions 137 133 private: 138 // void rawDiff( uint8_t* newdata, uint8_t* data, uint8_t* basedata, uint32_t datalength, uint32_t baselength); 139 // inline uint32_t findObject( const SynchronisableHeader& header, uint8_t* mem, uint32_t dataLength, uint32_t startPosition = 0 ); 134 140 135 virtual uint32_t getSize() const override; 141 136 virtual bool process(orxonox::Host* host) override; 142 137 uint32_t calcGamestateSize(uint32_t id, uint8_t mode=0x0); 143 // inline void diffObject( uint8_t*& newData, uint8_t*& origData, uint8_t*& baseData, SynchronisableHeader& objectHeader, std::vector<uint32_t>::iterator& sizes ); 144 // inline void copyObject( uint8_t*& newData, uint8_t*& origData, uint8_t*& baseData, SynchronisableHeader& objectHeader, std::vector<uint32_t>::iterator& sizes ); 145 138 146 139 std::list<obj> dataVector_; 147 140 GamestateHeader header_; -
code/branches/PresentationFS18/src/libraries/network/packet/Packet.cc
r11071 r12020 129 129 } 130 130 131 /** 132 * Send the Packet. 133 * @param host The host which sends the packet 134 */ 131 135 bool Packet::send(orxonox::Host* host) 132 136 { 137 // Deny sending incoming packets 133 138 if(packetDirection_ != Direction::Outgoing && packetDirection_ != Direction::Bidirectional ) 134 139 { … … 136 141 return false; 137 142 } 143 138 144 if(!enetPacket_) 139 145 { 140 if(!data_){ 146 // Deny sending empty packets 147 if(!data_) { 141 148 assert(0); 142 149 return false; … … 152 159 // without having a reference in the packetMap_ 153 160 Packet::packetMapMutex_.lock(); 154 packetMap_[reinterpret_cast<size_t>(enetPacket_)] = this;161 Packet::packetMap_[reinterpret_cast<size_t>(enetPacket_)] = this; 155 162 Packet::packetMapMutex_.unlock(); 156 163 } … … 173 180 } 174 181 #endif 175 // ENetPacket *temp = enetPacket_; 176 // enetPacket_ = nullptr; // otherwise we have a double free because enet already handles the deallocation of the packet 182 183 // Send via reliable or standard channel respectively 177 184 if( this->flags_ & PacketFlag::Reliable ) 178 185 host->addPacket( enetPacket_, peerID_, NETWORK_CHANNEL_DEFAULT); 179 186 else 180 187 host->addPacket( enetPacket_, peerID_, NETWORK_CHANNEL_UNRELIABLE); 188 181 189 return true; 182 190 } 183 191 192 /** 193 * Given an ENetPacket, create an Orxonox packet 194 * @param packet The ENetPacket 195 * @param peerID The sender 196 */ 184 197 Packet *Packet::createPacket(ENetPacket* packet, uint32_t peerID) 185 198 { 186 199 uint8_t *data = packet->data; 187 // assert(ClientInformation::findClient(&peer->address)->getID() != static_cast<unsigned int>(-2) || !Host::isServer());188 // unsigned int peerID = ClientInformation::findClient(&peer->address)->getID();189 // HACK190 // if( peerID==static_cast<unsigned int>(-2))191 // peerID = NETWORK_PEER_ID_SERVER;192 200 Packet *p = nullptr; 193 // orxout(verbose_ultra, context::packets) << "packet type: " << *(Type *)&data[_PACKETID] << endl;194 201 switch( *(Type *)(data + _PACKETID) ) 195 202 { 196 203 case Type::Acknowledgement: 197 // orxout(verbose_more, context::packets) << "ack" << endl; 198 p = new Acknowledgement( data, peerID ); 204 p = new Acknowledgement( data, peerID ); 199 205 break; 200 206 case Type::Chat: 201 // orxout(verbose_more, context::packets) << "chat" << endl;202 207 p = new Chat( data, peerID ); 203 208 break; 204 209 case Type::ClassID: 205 // orxout(verbose_more, context::packets) << "classid" << endl;206 210 p = new ClassID( data, peerID ); 207 211 break; 208 212 case Type::Gamestate: 209 // orxout(verbose_more, context::packets) << "gamestate" << endl;210 213 p = new Gamestate( data, peerID ); 211 214 break; 212 215 case Type::Welcome: 213 // orxout(verbose_more, context::packets) << "welcome" << endl;214 216 p = new Welcome( data, peerID ); 215 217 break; 216 218 case Type::DeleteObjects: 217 // orxout(verbose_more, context::packets) << "deleteobjects" << endl;218 219 p = new DeleteObjects( data, peerID ); 219 220 break; 220 221 case Type::FunctionCalls: 221 // orxout(verbose_more, context::packets) << "functionCalls" << endl;222 222 p = new FunctionCalls( data, peerID ); 223 223 break; 224 224 case Type::FunctionIDs: 225 // orxout(verbose_more, context::packets) << "functionIDs" << endl;226 225 p = new FunctionIDs( data, peerID ); 227 226 break; … … 247 246 // Get our Packet from a global map with all Packets created in the send() method of Packet. 248 247 Packet::packetMapMutex_.lock(); 249 std::map<size_t, Packet*>::iterator it = packetMap_.find(reinterpret_cast<size_t>(enetPacket)); 248 249 std::map<size_t, Packet*>::iterator it = Packet::packetMap_.find(reinterpret_cast<size_t>(enetPacket)); 250 250 assert(it != packetMap_.end()); 251 251 252 // Make sure we don't delete it again in the destructor 252 253 it->second->enetPacket_ = nullptr; 253 254 delete it->second; 254 255 packetMap_.erase(it); 256 255 257 Packet::packetMapMutex_.unlock(); 256 // orxout(verbose_ultra, context::packets) << "PacketMap size: " << packetMap_.size() << endl;257 258 } 258 259 -
code/branches/PresentationFS18/src/libraries/network/packet/Packet.h
r11071 r12020 68 68 69 69 virtual unsigned char* getData(){ return data_; }; 70 virtual unsigned int getSize() const =0; 71 virtual bool process(orxonox::Host* host)=0; 70 virtual unsigned int getSize() const = 0; 71 72 // Invoke some sort of action associated with the packet 73 virtual bool process(orxonox::Host* host) = 0; 74 72 75 inline uint32_t getFlags() 73 76 { return flags_; } … … 82 85 83 86 virtual bool send(orxonox::Host* host); 87 84 88 protected: 85 89 Packet(); 86 90 Packet(uint8_t *data, unsigned int peerID); 87 // Packet(ENetPacket *packet, ENetPeer *peer);88 91 inline bool isDataENetAllocated() const 89 92 { return bDataENetAllocated_; } … … 100 103 data_ might no correlate with enetPacket_->data. */ 101 104 bool bDataENetAllocated_; 105 102 106 private: 107 // All Packets are contained in this map 103 108 static std::map<size_t, Packet *> packetMap_; 104 109 static boost::mutex packetMapMutex_; -
code/branches/PresentationFS18/src/libraries/network/packet/ServerInformation.cc
r11083 r12020 50 50 // Save Server Round Trip Time 51 51 this->serverRTT_ = event->peer->roundTripTime; 52 52 53 // Save Server Address, leave some space for scope ID 53 54 enet_address_get_host_ip(&event->peer->address, serverIP, 64); 55 54 56 this->serverIP_ = std::string(serverIP); 55 57 // Save ACK … … 57 59 char* ack = nullptr; 58 60 loadAndIncrease((char*&)ack, temp); 59 60 /* Fabian, what is this used for? it crashes the masterserver, hence commenting it */61 // written by Oli: this is just to make sure that loadAndIncrease really writes the whole ACK string into char* ack62 // assert(strcmp(ack, (const char*)LAN_DISCOVERY_ACK)==0);63 64 61 // Save Server Name 65 62 loadAndIncrease(this->serverName_, temp); … … 74 71 void ServerInformation::send(ENetPeer* peer) 75 72 { 76 std::string payload = this->serverName_ + Ogre::StringConverter::toString(this->clientNumber_);73 std::string payload = this->serverName_ + std::to_string(this->clientNumber_); 77 74 uint32_t size = returnSize(LAN_DISCOVERY_ACK) + returnSize(payload); 78 75 uint8_t* temp = new uint8_t[size];
Note: See TracChangeset
for help on using the changeset viewer.