Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1715


Ignore:
Timestamp:
Sep 6, 2008, 3:16:11 PM (16 years ago)
Author:
scheusso
Message:

further bugfixes concerning packet handling

Location:
code/branches/network/src/network/packet
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/network/src/network/packet/Gamestate.cc

    r1713 r1715  
    4949}
    5050
    51 Gamestate::Gamestate(unsigned char *data, bool compressed, int clientID):
     51Gamestate::Gamestate(unsigned char *data, int clientID):
    5252    Packet(data, clientID)
    5353{
    54   compressed_ = compressed;
    5554}
    5655
     
    106105  //start write gamestate header
    107106  HEADER->packetType = ENUM::Gamestate;
    108   assert( *(ENUM::Type *)&data_[ 0 ] == ENUM::Gamestate);
     107  assert( *(ENUM::Type *)(data_) == ENUM::Gamestate);
    109108  HEADER->normsize = currentsize;
    110109  HEADER->id = id;
    111110  HEADER->diffed = false;
    112111  HEADER->complete = true;
    113   compressed_=false;
     112  HEADER->compressed = false;
    114113  //stop write gamestate header
    115114 
     
    121120bool Gamestate::spreadData(int mode)
    122121{
    123   assert(data_ && !compressed_ && !HEADER->diffed);
     122  assert(data_ && !HEADER->compressed && !HEADER->diffed);
    124123  unsigned int size, objectID, classID;
    125124  unsigned char *mem=data_+sizeof(GamestateHeader);
     
    167166{
    168167  assert(data_);
    169   if(compressed_)
     168  if(HEADER->compressed)
    170169    return HEADER->compsize+sizeof(GamestateHeader);
    171170  else
     
    203202  //copy and modify header
    204203  HEADER->compsize = buffer;
     204  HEADER->compressed = true;
    205205  *GAMESTATE_HEADER(ndata) = *HEADER;
    206206  //delete old data
     
    208208  //save new data
    209209  data_ = ndata;
    210   compressed_ = true;
    211210  return true;
    212211}
    213212bool Gamestate::decompressData()
    214213{
    215   assert(compressed_);
     214  assert(HEADER->compressed);
    216215  //COUT(4) << "GameStateClient: uncompressing gamestate. id: " << a->id << ", baseid: " << a->base_id << ", normsize: " << a->normsize << ", compsize: " << a->compsize << std::endl;
    217216  int normsize = HEADER->normsize;
     
    236235  }
    237236 
    238   compressed_ = false;
     237  HEADER->compressed = false;
    239238  //copy over the header
    240239  *GAMESTATE_HEADER(ndata) = *HEADER;
     
    273272  }
    274273
    275   Gamestate *g = new Gamestate(ndata, false, 0);
     274  *GAMESTATE_HEADER(ndata) = *HEADER;
     275  GAMESTATE_HEADER(ndata)->diffed = true;
     276  Gamestate *g = new Gamestate(ndata, 0);
    276277  return g;
    277278}
     
    280281{
    281282  assert(this && base);
    282   assert(!this->compressed_ && !base->compressed_);
     283  assert(!HEADER->compressed && !GAMESTATE_HEADER(base->data_)->compressed);
    283284  //unsigned char *basep = base->getGs()/*, *gs = getGs()*/;
    284285  unsigned char *basep = GAMESTATE_START(base->data_);
     
    304305    }
    305306  }
    306  
    307   Gamestate *g = new Gamestate(ndata, false, 0);
     307  *GAMESTATE_HEADER(ndata) = *HEADER;
     308  GAMESTATE_HEADER(ndata)->diffed = false;
     309  Gamestate *g = new Gamestate(ndata, 0);
    308310  return g;
    309311}
  • code/branches/network/src/network/packet/Gamestate.h

    r1712 r1715  
    4747  bool diffed; // wheter diffed or not
    4848  bool complete; // wheter it is a complete gamestate or only partial
     49  bool compressed;
    4950};
    5051
     
    5556  public:
    5657    Gamestate();
    57     Gamestate(unsigned char *data, bool compressed, int clientID);
     58    Gamestate(unsigned char *data, int clientID);
    5859   
    5960    ~Gamestate();
     
    8182    //Bytestream *bs_;
    8283    //GamestateHeader *header_;
    83     bool compressed_;
    8484};
    8585
  • code/branches/network/src/network/packet/Packet.cc

    r1713 r1715  
    111111    packetMap_[enetPacket_] = this;
    112112  }
     113  /*switch( *(ENUM::Type *)(data_ + _PACKETID) )
     114  {
     115    case ENUM::Acknowledgement:
     116    case ENUM::Chat:
     117    case ENUM::ClassID:
     118    case ENUM::Gamestate:
     119    case ENUM::Welcome:
     120      COUT(3) << "welcome" << std::endl;
     121      p = new Welcome( data, clientID );
     122    default:
     123      assert(0); //TODO: repair this
     124      break;
     125  }*/
    113126  network::Host::addPacket( enetPacket_, clientID_);
    114127  enetPacket_ = 0; // otherwise we have a double free because enet already handles the deallocation of the packet
     
    121134  Packet *p;
    122135  COUT(3) << "packet type: " << *(ENUM::Type *)&data[_PACKETID] << std::endl;
    123   switch( *(ENUM::Type *)&data[_PACKETID] )
     136  switch( *(ENUM::Type *)(data + _PACKETID) )
    124137  {
    125138    case ENUM::Acknowledgement:
     
    138151      COUT(3) << "gamestate" << std::endl;
    139152      // TODO: remove brackets
    140       p = new Gamestate( data, true, clientID );
     153      p = new Gamestate( data, clientID );
    141154      break;
    142155    case ENUM::Welcome:
    143156      COUT(3) << "welcome" << std::endl;
    144157      p = new Welcome( data, clientID );
     158      break;
    145159    default:
    146160      assert(0); //TODO: repair this
Note: See TracChangeset for help on using the changeset viewer.