Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 10, 2018, 3:06:55 PM (6 years ago)
Author:
merholzl
Message:

Merged Masterserver, refresh button had to be removed

Location:
code/branches/mergeFS18
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • code/branches/mergeFS18

  • code/branches/mergeFS18/src/libraries/network/packet/Acknowledgement.cc

    r11071 r12027  
    3737
    3838#define PACKET_FLAGS_ACK    0
     39// Offset to start of packet ID
    3940#define _PACKETID           0
     41// Offset to start of ACK ID
    4042#define _ACKID              _PACKETID + sizeof(packet::Type)
    4143
     44/**
     45 * Constructor
     46 * Acknowledgement.data_ is 40 bits in size:
     47 * [0, 7]:   Packet Type
     48 * [8, 39]:  Acknowledgement ID
     49 */
    4250Acknowledgement::Acknowledgement( unsigned int id, unsigned int peerID )
    4351 : Packet()
    4452{
    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;
    5058}
    5159
     
    5967}
    6068
    61 unsigned int Acknowledgement::getSize() const{
     69unsigned int Acknowledgement::getSize() const {
    6270  return _ACKID + sizeof(uint32_t);
    6371}
    6472
    65 bool Acknowledgement::process(orxonox::Host* host){
     73bool Acknowledgement::process(orxonox::Host* host) {
    6674  orxout(verbose_more, context::packets) << "processing ACK with ID: " << getAckID() << endl;
    6775  bool b = host->ackGamestate(getAckID(), peerID_);
     
    7078}
    7179
    72 unsigned int Acknowledgement::getAckID(){
     80unsigned int Acknowledgement::getAckID() {
    7381  return *(uint32_t *)(data_ + _ACKID);
    7482}
  • code/branches/mergeFS18/src/libraries/network/packet/Acknowledgement.h

    r11071 r12027  
    3434
    3535namespace orxonox {
     36       
    3637const unsigned int ACKID_NACK = 0;
     38
    3739namespace packet {
    38 /**
    39     @author
    40 */
     40
    4141class _NetworkExport Acknowledgement : public Packet
    4242{
  • code/branches/mergeFS18/src/libraries/network/packet/Chat.cc

    r11071 r12027  
    3838#define   PACKET_FLAGS_CHAT PacketFlag::Reliable
    3939
    40 /* Some lengths */
     40/* Some lengths / offsets */
    4141#define _PACKETID         0
    4242#define _SOURCEID         _PACKETID + sizeof(Type)
     
    4949{
    5050  /* Add chat flag to packet flags */
    51   flags_ = flags_ | PACKET_FLAGS_CHAT;
     51  this->flags_ |= PACKET_FLAGS_CHAT;
    5252
    5353  /* set message length to length of input string + 1 */
    54   messageLength_ = message.length()+1;
     54  this->messageLength_ = message.length() + 1;
    5555
    5656  /* allocate memory for the data */
    57   data_=new unsigned char[ getSize() ];
     57  this->data_ = new unsigned char[ getSize() ];
    5858
    5959  *(Type *)(data_ + _PACKETID ) = Type::Chat;
    6060  *(unsigned int *)(data_ + _SOURCEID ) = sourceID;
    6161  *(unsigned int *)(data_ + _TARGETID ) = targetID;
    62   *(unsigned int *)(data_ + _MESSAGELENGTH ) = messageLength_;
     62  *(unsigned int *)(data_ + _MESSAGELENGTH ) = this->messageLength_;
    6363
    6464  /* cast the hell out of the message string, and copy it into the
    6565   * data buffer.
    6666   */
    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_ );
    6868}
    6969
     
    7171  : Packet(data, clientID)
    7272{
    73   messageLength_ = *(uint32_t *)(data + _MESSAGELENGTH );
     73  this->messageLength_ = *(uint32_t *)(data + _MESSAGELENGTH );
    7474}
    7575
     
    7979
    8080unsigned int Chat::getSize() const{
    81   return _MESSAGE + messageLength_;
     81  return _MESSAGE + this->messageLength_;
    8282}
    8383
    8484bool 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));
    8688  delete this;
    8789  return true;
    8890}
    8991
    90 unsigned char *Chat::getMessage(){
    91   return data_ + _MESSAGE;
     92unsigned char *Chat::getMessage() {
     93  return this->data_ + _MESSAGE;
    9294}
    9395
  • code/branches/mergeFS18/src/libraries/network/packet/Chat.h

    r11071 r12027  
    5555
    5656  /* Get the length of the message (not the full size of the packet) */
    57   unsigned int getMessageLength(){ return messageLength_; };
     57  unsigned int getMessageLength() { return this->messageLength_; };
    5858
    5959  /* return message content */
  • code/branches/mergeFS18/src/libraries/network/packet/ClassID.cc

    r11071 r12027  
    4646
    4747
    48 ClassID::ClassID( ) : Packet(){
     48ClassID::ClassID() : Packet() {
    4949  Identifier *id;
    50   unsigned int nrOfClasses=0;
    51   unsigned int packetSize=2*sizeof(uint32_t); //space for the packetID and for the nrofclasses
     50  unsigned int nrOfClasses = 0;
     51  unsigned int packetSize = 2 * sizeof(uint32_t); //space for the packetID and for the nrofclasses
    5252  uint32_t network_id;
    53   flags_ = flags_ | PACKET_FLAGS_CLASSID;
     53  this->flags_ |= PACKET_FLAGS_CLASSID;
    5454  std::queue<std::pair<uint32_t, std::string>> tempQueue;
    5555
    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()) {
    5858    id = mapEntry.second;
    5959    if(id == nullptr || !id->hasFactory())
     
    6464    tempQueue.push( std::pair<unsigned int, std::string>(network_id, classname) );
    6565    ++nrOfClasses;
    66     packetSize += (classname.size()+1)+sizeof(network_id)+sizeof(uint32_t);
     66    packetSize += (classname.size() + 1) + sizeof(network_id) + sizeof(uint32_t);
    6767  }
    6868
    69   this->data_=new uint8_t[ packetSize ];
     69  this->data_ = new uint8_t[ packetSize ];
    7070  //set the appropriate packet id
    7171  assert(this->data_);
    7272  *(Type *)(this->data_ + _PACKETID ) = Type::ClassID;
    7373
    74   uint8_t *temp=data_+sizeof(uint32_t);
     74  uint8_t *temp = this->data_ + sizeof(uint32_t);
    7575  // save the number of all classes
    76   *(uint32_t*)temp = nrOfClasses;
     76  *(uint32_t*) temp = nrOfClasses;
    7777  temp += sizeof(uint32_t);
    7878
    7979  // now save all classids and classnames
    8080  std::pair<uint32_t, std::string> tempPair;
    81   uint32_t tempsize = 2*sizeof(uint32_t); // packetid and nrOfClasses
     81  uint32_t tempsize = 2 * sizeof(uint32_t); // packetid and nrOfClasses
    8282  while( !tempQueue.empty() ){
    8383    tempPair = tempQueue.front();
    8484    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;
    9090  }
    91   assert(tempsize==packetSize);
     91  assert(tempsize == packetSize);
    9292
    9393  orxout(verbose_more, context::packets) << "classid packetSize is " << packetSize << endl;
     
    104104}
    105105
    106 uint32_t ClassID::getSize() const{
    107   uint8_t *temp = data_+sizeof(uint32_t); // packet identification
     106uint32_t ClassID::getSize() const {
     107  uint8_t *temp = this->data_ + sizeof(uint32_t); // packet identification
    108108  uint32_t totalsize = sizeof(uint32_t); // packet identification
    109   uint32_t nrOfClasses = *(uint32_t*)temp;
     109  uint32_t nrOfClasses = *(uint32_t*) temp;
    110110  temp += sizeof(uint32_t);
    111111  totalsize += sizeof(uint32_t); // storage size for nr of all classes
    112112
    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));
    116116  }
    117117  return totalsize;
    118118}
    119119
    120 
    121 bool ClassID::process(orxonox::Host* host){
     120bool ClassID::process(orxonox::Host* host) {
    122121  int nrOfClasses;
    123   uint8_t *temp = data_+sizeof(uint32_t); //skip the packetid
     122  uint8_t *temp = this->data_ + sizeof(uint32_t); //skip the packetid
    124123  uint32_t networkID;
    125124  uint32_t stringsize;
    126125  unsigned char *classname;
    127 
    128126
    129127  //clear the map of network ids
     
    134132  Identifier *id;
    135133  // read the total number of classes
    136   nrOfClasses = *(uint32_t*)temp;
     134  nrOfClasses = *(uint32_t*) temp;
    137135  temp += sizeof(uint32_t);
    138136
    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) );
    144142    orxout(internal_info, context::packets) << "processing classid: " << networkID << " name: " << classname << " id: " << id << endl;
    145     if(id==nullptr){
     143    if(id == nullptr) {
    146144      orxout(user_error, context::packets) << "Received a bad classname" << endl;
    147145      abort();
    148146    }
    149147    id->setNetworkID( networkID );
    150     temp += 2*sizeof(uint32_t) + stringsize;
     148    temp += 2 * sizeof(uint32_t) + stringsize;
    151149  }
    152150  delete this;
  • code/branches/mergeFS18/src/libraries/network/packet/DeleteObjects.cc

    r11071 r12027  
    4545 : Packet()
    4646{
    47   flags_ = flags_ | PACKET_FLAG_DELETE;
     47  this->flags_ |= PACKET_FLAG_DELETE;
    4848}
    4949
     
    6060{
    6161  unsigned int number = Synchronisable::getNumberOfDeletedObject();
    62   if(number==0)
     62  if(number == 0)
    6363    return false;
    6464  orxout(verbose, context::packets) << "sending DeleteObjects: ";
     
    8383{
    8484  assert(data_);
    85   return _OBJECTIDS + *(uint32_t*)(data_+_QUANTITY)*sizeof(uint32_t);
     85  return _OBJECTIDS + *(uint32_t*) (this->data_ + _QUANTITY) * sizeof(uint32_t);
    8686}
    8787
    8888bool DeleteObjects::process(orxonox::Host* host)
    8989{
    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++)
    9191  {
    9292    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)) );
    9494  }
    9595  delete this;
  • code/branches/mergeFS18/src/libraries/network/packet/FunctionCalls.cc

    r11071 r12027  
    6363  assert(isDataENetAllocated());
    6464 
    65   uint8_t* temp = data_+sizeof(uint32_t); //skip packetid
    66   uint32_t nrOfCalls = *(uint32_t*)temp;
     65  uint8_t* temp = data_ + sizeof(uint32_t); //skip packetid
     66  uint32_t nrOfCalls = *(uint32_t*) temp;
    6767  temp += sizeof(uint32_t);
    68   this->minGamestateID_ = *(uint32_t*)temp;
     68  this->minGamestateID_ = *(uint32_t*) temp;
    6969  temp += sizeof(uint32_t);
    70   for( unsigned int i = 0; i<nrOfCalls; i++ )
     70  for( unsigned int i = 0; i < nrOfCalls; i++ )
    7171  {
    7272    FunctionCall fctCall;
     
    9595  this->minGamestateID_ = host->getCurrentGamestateID();
    9696  assert(this->functionCalls_.size());
    97   data_=new uint8_t[ currentSize_ ];
    98   *(Type *)(data_ + _PACKETID ) = Type::FunctionCalls; // Set the Packet ID
    99   *(uint32_t*)(data_+sizeof(uint32_t)) = this->functionCalls_.size(); // set nrOfCalls
    100   *(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);
    102102 
    103103  while( this->functionCalls_.size() )
     
    107107  }
    108108 
    109   assert( temp==data_+currentSize_ );
     109  assert( temp == this->data_ + currentSize_ );
    110110 
    111111  Packet::send(host);
  • code/branches/mergeFS18/src/libraries/network/packet/Gamestate.cc

    r11083 r12027  
    4646#define GAMESTATE_START(data) (data + GamestateHeader::getSize())
    4747
    48 // #define PACKET_FLAG_GAMESTATE  PacketFlag::Reliable
    4948#define PACKET_FLAG_GAMESTATE  0
    5049
     
    102101}
    103102
    104 
     103//AV: This takes all synchronisables and packs it in a GameState, to be sent over the network
    105104bool Gamestate::collectData(int id, uint8_t mode)
    106105{
     
    128127  for(it = ObjectList<Synchronisable>().begin(); it; ++it)
    129128  {
    130 
    131 //     tempsize=it->getSize(id, mode);
    132129
    133130    tempsize = it->getData(mem, this->sizes_, id, mode);
     
    173170}
    174171
    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
    176173bool Gamestate::spreadData(uint8_t mode)
    177174{
     
    196193      else
    197194      {
    198 //         orxout(verbose, context::packets) << "not creating object of classid " << objectheader.getClassID() << endl;
    199195        mem += objectheader.getDataSize() + ( objectheader.isDiffed() ? SynchronisableHeaderLight::getSize() : SynchronisableHeader::getSize() );
    200196      }
     
    202198    else
    203199    {
    204 //       orxout(verbose, context::packets) << "updating object of classid " << objectheader.getClassID() << endl;
    205200      OrxVerify(s->updateData(mem, mode), "ERROR: could not update Synchronisable with Gamestate data");
    206201    }
    207202  }
    208203  assert((uintptr_t)(mem-data_) == GamestateHeader::getSize()+header_.getDataSize());
    209  
    210    // In debug mode, check first, whether there are no duplicate objectIDs
    211 #ifndef NDEBUG
    212   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       else
    228       {
    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!" << endl
    234                                                  << "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 #endif
    244204  return true;
    245205}
     
    276236}
    277237
    278 
     238//AV: This function takes the Gamestate and compresses it for transmission over the network
    279239bool Gamestate::compressData()
    280240{
     
    313273}
    314274
    315 
     275//AV: This function takes the compressed Gamestate received from the network and decompresses it for further unpacking
    316276bool Gamestate::decompressData()
    317277{
     
    374334  if( memcmp( origDataPtr+objectOffset, baseDataPtr+objectOffset, objectHeader.getDataSize()) == 0 )
    375335  {
    376 //     orxout(verbose, context::packets) << "skip object " << Synchronisable::getSynchronisable(objectHeader.getObjectID())->getIdentifier()->getName() << endl;
    377336    origDataPtr += objectOffset + objectHeader.getDataSize(); // skip the whole object
    378337    baseDataPtr += objectOffset + objectHeader.getDataSize();
     
    430389inline void /*Gamestate::*/copyObject( uint8_t*& newData, uint8_t*& origData, uint8_t*& baseData, SynchronisableHeader& objectHeader, std::vector<uint32_t>::iterator& sizes )
    431390{
    432   //       orxout(verbose, context::packets) << "docopy" << endl;
    433391  // Just copy over the whole Object
    434392  memcpy( newData, origData, objectHeader.getDataSize()+SynchronisableHeader::getSize() );
     
    437395  newData += objectHeader.getDataSize()+SynchronisableHeader::getSize();
    438396  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
    443398  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
    450400}
    451401
     
    501451  uint8_t *origDataEnd = origDataPtr + header_.getDataSize();
    502452  uint8_t *baseDataEnd = baseDataPtr + base->header_.getDataSize();
    503 //   uint32_t origLength = header_.getDataSize();
    504 //   uint32_t baseLength = base->header_.getDataSize();
     453
    505454
    506455  // Allocate new space for diffed gamestate
     
    595544
    596545
    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 NDEBUG
    615   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 #endif
    620 
    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 data
    675     else
    676       *(nd+i) = *(gd+i); // just copy over the data
    677   }
    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); // xor
    684     else
    685       *(newdata+j) = *(data+j); // just copy
    686   }
    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 data
    696   uint8_t *gdata = new uint8_t[header_.getDataSize()+GamestateHeader::getSize()];
    697   // create a gamestate out of it
    698   Gamestate *gs = new Gamestate(gdata);
    699   uint8_t *newdata = gdata + GamestateHeader::getSize();
    700   uint8_t *origdata = GAMESTATE_START(data_);
    701 
    702   //copy the GamestateHeader
    703   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 TrafficControl
    712   TrafficControl::getInstance()->processObjectList( clientID, header_.getID(), dataVector_ );
    713 
    714   //copy in the zeros
    715 //   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 objectheader
    730     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 NDEBUG
    742   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 #endif
    753   gs->header_.setDataSize( destsize );
    754   return gs;
    755 }*/
    756 
    757 
    758546uint32_t Gamestate::calcGamestateSize(uint32_t id, uint8_t mode)
    759547{
  • code/branches/mergeFS18/src/libraries/network/packet/Gamestate.h

    r11071 r12027  
    5757    GamestateHeader(uint8_t* data)
    5858      { 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()); }*/
    6159    void setData(uint8_t* data)
    6260      { assert(data); data_ = data; *(Type*)data_ = Type::Gamestate; }
     
    127125    inline uint32_t getDataSize() const { return header_.getDataSize(); }
    128126    Gamestate* diffVariables(Gamestate *base);
    129 //     Gamestate* diffData(Gamestate *base);
    130 //     Gamestate *undiff(Gamestate *base);
    131 //     Gamestate* doSelection(unsigned int clientID, unsigned int targetSize);
     127
    132128    bool compressData();
    133129    bool decompressData();
     
    136132    // Packet functions
    137133  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
    140135    virtual uint32_t getSize() const override;
    141136    virtual bool process(orxonox::Host* host) override;
    142137    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   
    146139    std::list<obj>          dataVector_;
    147140    GamestateHeader         header_;
  • code/branches/mergeFS18/src/libraries/network/packet/Packet.cc

    r11071 r12027  
    129129}
    130130
     131/**
     132 * Send the Packet.
     133 * @param host The host which sends the packet
     134 */
    131135bool Packet::send(orxonox::Host* host)
    132136{
     137  // Deny sending incoming packets
    133138  if(packetDirection_ != Direction::Outgoing && packetDirection_ != Direction::Bidirectional )
    134139  {
     
    136141    return false;
    137142  }
     143
    138144  if(!enetPacket_)
    139145  {
    140     if(!data_){
     146    // Deny sending empty packets
     147    if(!data_) {
    141148      assert(0);
    142149      return false;
     
    152159      // without having a reference in the packetMap_
    153160      Packet::packetMapMutex_.lock();
    154       packetMap_[reinterpret_cast<size_t>(enetPacket_)] = this;
     161      Packet::packetMap_[reinterpret_cast<size_t>(enetPacket_)] = this;
    155162      Packet::packetMapMutex_.unlock();
    156163    }
     
    173180  }
    174181#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
    177184  if( this->flags_ & PacketFlag::Reliable )
    178185    host->addPacket( enetPacket_, peerID_, NETWORK_CHANNEL_DEFAULT);
    179186  else
    180187    host->addPacket( enetPacket_, peerID_, NETWORK_CHANNEL_UNRELIABLE);
     188
    181189  return true;
    182190}
    183191
     192/**
     193 * Given an ENetPacket, create an Orxonox packet
     194 * @param packet The ENetPacket
     195 * @param peerID The sender
     196 */
    184197Packet *Packet::createPacket(ENetPacket* packet, uint32_t peerID)
    185198{
    186199  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   // HACK
    190 //   if( peerID==static_cast<unsigned int>(-2))
    191 //     peerID = NETWORK_PEER_ID_SERVER;
    192200  Packet *p = nullptr;
    193 //   orxout(verbose_ultra, context::packets) << "packet type: " << *(Type *)&data[_PACKETID] << endl;
    194201  switch( *(Type *)(data + _PACKETID) )
    195202  {
    196203    case Type::Acknowledgement:
    197 //       orxout(verbose_more, context::packets) << "ack" << endl;
    198     p = new Acknowledgement( data, peerID );
     204      p = new Acknowledgement( data, peerID );
    199205      break;
    200206    case Type::Chat:
    201 //       orxout(verbose_more, context::packets) << "chat" << endl;
    202207      p = new Chat( data, peerID );
    203208      break;
    204209    case Type::ClassID:
    205 //       orxout(verbose_more, context::packets) << "classid" << endl;
    206210      p = new ClassID( data, peerID );
    207211      break;
    208212    case Type::Gamestate:
    209 //       orxout(verbose_more, context::packets) << "gamestate" << endl;
    210213      p = new Gamestate( data, peerID );
    211214      break;
    212215    case Type::Welcome:
    213 //       orxout(verbose_more, context::packets) << "welcome" << endl;
    214216      p = new Welcome( data, peerID );
    215217      break;
    216218    case Type::DeleteObjects:
    217 //       orxout(verbose_more, context::packets) << "deleteobjects" << endl;
    218219      p = new DeleteObjects( data, peerID );
    219220      break;
    220221    case Type::FunctionCalls:
    221 //       orxout(verbose_more, context::packets) << "functionCalls" << endl;
    222222      p = new FunctionCalls( data, peerID );
    223223      break;
    224224    case Type::FunctionIDs:
    225 //       orxout(verbose_more, context::packets) << "functionIDs" << endl;
    226225      p = new FunctionIDs( data, peerID );
    227226      break;
     
    247246  // Get our Packet from a global map with all Packets created in the send() method of Packet.
    248247  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));
    250250  assert(it != packetMap_.end());
     251
    251252  // Make sure we don't delete it again in the destructor
    252253  it->second->enetPacket_ = nullptr;
    253254  delete it->second;
    254255  packetMap_.erase(it);
     256
    255257  Packet::packetMapMutex_.unlock();
    256 //   orxout(verbose_ultra, context::packets) << "PacketMap size: " << packetMap_.size() << endl;
    257258}
    258259
  • code/branches/mergeFS18/src/libraries/network/packet/Packet.h

    r11071 r12027  
    6868
    6969    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   
    7275    inline uint32_t getFlags()
    7376      { return flags_; }
     
    8285
    8386    virtual bool send(orxonox::Host* host);
     87
    8488  protected:
    8589    Packet();
    8690    Packet(uint8_t *data, unsigned int peerID);
    87 //    Packet(ENetPacket *packet, ENetPeer *peer);
    8891    inline bool isDataENetAllocated() const
    8992      { return bDataENetAllocated_; }
     
    100103        data_ might no correlate with enetPacket_->data. */
    101104    bool bDataENetAllocated_;
     105
    102106  private:
     107    // All Packets are contained in this map
    103108    static std::map<size_t, Packet *> packetMap_;
    104109    static boost::mutex               packetMapMutex_;
  • code/branches/mergeFS18/src/libraries/network/packet/ServerInformation.cc

    r11083 r12027  
    5050      // Save Server Round Trip Time
    5151      this->serverRTT_ = event->peer->roundTripTime;
     52
    5253      // Save Server Address, leave some space for scope ID
    5354      enet_address_get_host_ip(&event->peer->address, serverIP, 64);
     55
    5456      this->serverIP_ = std::string(serverIP);
    5557      // Save ACK
     
    5759      char* ack = nullptr;
    5860      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* ack
    62 //       assert(strcmp(ack, (const char*)LAN_DISCOVERY_ACK)==0);
    63 
    6461      // Save Server Name
    6562      loadAndIncrease(this->serverName_, temp);
     
    7471    void ServerInformation::send(ENetPeer* peer)
    7572    {
    76       std::string payload = this->serverName_ + Ogre::StringConverter::toString(this->clientNumber_);
     73      std::string payload = this->serverName_ + std::to_string(this->clientNumber_);
    7774      uint32_t size = returnSize(LAN_DISCOVERY_ACK) + returnSize(payload);
    7875      uint8_t* temp = new uint8_t[size];
Note: See TracChangeset for help on using the changeset viewer.