Index: code/branches/network/src/network/GamestateClient.cc
===================================================================
--- code/branches/network/src/network/GamestateClient.cc	(revision 1739)
+++ code/branches/network/src/network/GamestateClient.cc	(revision 1741)
@@ -157,6 +157,8 @@
 
   packet::Gamestate *GamestateClient::processGamestate(packet::Gamestate *gs){
-    if(gs->isCompressed())
-      assert(gs->decompressData());
+    if(gs->isCompressed()){
+      bool b = gs->decompressData();
+      assert(b);
+    }
     if(gs->isDiffed()){
       packet::Gamestate *base = gamestateMap_[gs->getBaseID()];
Index: code/branches/network/src/network/GamestateManager.cc
===================================================================
--- code/branches/network/src/network/GamestateManager.cc	(revision 1739)
+++ code/branches/network/src/network/GamestateManager.cc	(revision 1741)
@@ -129,4 +129,5 @@
     //why are we searching the same client's gamestate id as we searched in
     //Server::sendGameState?
+    packet::Gamestate *gs;
     int gID = ClientInformation::findClient(clientID)->getGamestateID();
     COUT(4) << "G.St.Man: popgamestate: sending gstate_id: " << id_ << " diffed from: " << gID << std::endl;
@@ -134,22 +135,25 @@
     //chose wheather the next gamestate is the first or not
     if(gID != GAMESTATEID_INITIAL){
-      // TODO something with the gamestatemap is wrong
       packet::Gamestate *client=NULL;
       std::map<int, packet::Gamestate*>::iterator it = gamestateMap.find(gID);
       if(it!=gamestateMap.end())
         client = it->second;
-      packet::Gamestate *gs;
       if(client)
         gs = reference->diff(client);
       else
         gs = new packet::Gamestate(*reference);
-      gs->compressData();
-      return gs;
     } else {
       COUT(4) << "we got a GAMESTATEID_INITIAL for clientID: " << clientID << std::endl;
-//       ackGameState(clientID, reference->id);
-      return new packet::Gamestate(*reference);
-      // return an undiffed gamestate and set appropriate flags
-    }
+      gs = new packet::Gamestate(*reference);
+    }
+#ifndef NDEBUG
+    packet::Gamestate *ns = new packet::Gamestate(*gs);
+    ns->compressData();
+    ns->decompressData();
+    assert(*gs==*ns);
+    delete ns;
+#endif
+    assert(gs->compressData());
+    return gs;
   }
   
Index: code/branches/network/src/network/Synchronisable.cc
===================================================================
--- code/branches/network/src/network/Synchronisable.cc	(revision 1739)
+++ code/branches/network/src/network/Synchronisable.cc	(revision 1741)
@@ -98,4 +98,5 @@
     if(!id){
       COUT(3) << "We could not identify a new object; classid: " << classID << " uint: " << (unsigned int)classID << " objectID: " << objectID << " size: " << size << std::endl;
+      assert(0);
       return false; // most probably the gamestate is corrupted
     }
@@ -224,5 +225,4 @@
     // end copy header
     
-    
     COUT(5) << "Synchronisable getting data from objectID: " << objectID << " classID: " << classID << " length: " << size << std::endl;
     // copy to location
Index: code/branches/network/src/network/packet/Gamestate.cc
===================================================================
--- code/branches/network/src/network/packet/Gamestate.cc	(revision 1739)
+++ code/branches/network/src/network/packet/Gamestate.cc	(revision 1741)
@@ -41,5 +41,5 @@
   
 
-#define GAMESTATE_START(data) data + sizeof(GamestateHeader)
+#define GAMESTATE_START(data) (data + sizeof(GamestateHeader))
 #define GAMESTATE_HEADER(data) ((GamestateHeader *)data)
 #define HEADER GAMESTATE_HEADER(data_)
@@ -176,4 +176,19 @@
 }
 
+bool Gamestate::operator==(packet::Gamestate gs){
+  unsigned char *d1 = data_+sizeof(GamestateHeader);
+  unsigned char *d2 = gs.data_+sizeof(GamestateHeader);
+  assert(!isCompressed());
+  assert(!gs.isCompressed());
+  while(d1<data_+HEADER->normsize)
+  {
+    if(*d1!=*d2)
+      return false;
+    d1++;
+    d2++;
+  }
+  return true;
+}
+
 bool Gamestate::process()
 {
@@ -184,5 +199,5 @@
 {
   assert(HEADER);
-  uLongf buffer = (uLongf)((HEADER->normsize + 12)*1.01)+1;
+  uLongf buffer = (uLongf)(((HEADER->normsize + 12)*1.01)+1);
   if(buffer==0)
     return false;
@@ -190,19 +205,27 @@
   unsigned char *ndata = new unsigned char[buffer+sizeof(GamestateHeader)];
   unsigned char *dest = GAMESTATE_START(ndata);
+  //unsigned char *dest = new unsigned char[buffer];
+  unsigned char *source = GAMESTATE_START(data_);
   int retval;
-  retval = compress( dest, &buffer, GAMESTATE_START(data_), (uLong)(HEADER->normsize) );
+  retval = compress( dest, &buffer, source, (uLong)(HEADER->normsize) );
   switch ( retval ) {
     case Z_OK: COUT(5) << "G.St.Man: compress: successfully compressed" << std::endl; break;
-    case Z_MEM_ERROR: COUT(1) << "G.St.Man: compress: not enough memory available in gamestate.compress" << std::endl; 
-    return false;
-    case Z_BUF_ERROR: COUT(2) << "G.St.Man: compress: not enough memory available in the buffer in gamestate.compress" << std::endl;
-    return false;
-    case Z_DATA_ERROR: COUT(2) << "G.St.Man: compress: data corrupted in gamestate.compress" << std::endl;
-    return false;
-  }
+    case Z_MEM_ERROR: COUT(1) << "G.St.Man: compress: not enough memory available in gamestate.compress" << std::endl; return false;
+    case Z_BUF_ERROR: COUT(2) << "G.St.Man: compress: not enough memory available in the buffer in gamestate.compress" << std::endl; return false;
+    case Z_DATA_ERROR: COUT(2) << "G.St.Man: compress: data corrupted in gamestate.compress" << std::endl; return false;
+  }
+#ifndef NDEBUG
+  //decompress and compare the start and the decompressed data
+  unsigned char *rdata = new unsigned char[HEADER->normsize+sizeof(GamestateHeader)];
+  unsigned char *d2 = GAMESTATE_START(rdata);
+  uLongf length2 = HEADER->normsize;
+  uncompress(d2, &length2, dest, buffer);
+  for(unsigned int i=0; i<HEADER->normsize; i++){
+    assert(*(source+i)==*(d2+i));
+  }
+  delete[] rdata;
+#endif
 
   //copy and modify header
-  HEADER->compsize = buffer;
-  HEADER->compressed = true;
   *GAMESTATE_HEADER(ndata) = *HEADER;
   //delete old data
@@ -210,4 +233,6 @@
   //save new data
   data_ = ndata;
+  HEADER->compsize = buffer;
+  HEADER->compressed = true;
   assert(HEADER->compressed);
   COUT(3) << "gamestate compress normsize: " << HEADER->normsize << " compsize: " << HEADER->compsize << std::endl;
@@ -217,19 +242,17 @@
 {
   assert(HEADER->compressed);
-  //COUT(4) << "GameStateClient: uncompressing gamestate. id: " << a->id << ", baseid: " << a->base_id << ", normsize: " << a->normsize << ", compsize: " << a->compsize << std::endl;
-  int normsize = HEADER->normsize;
-  int compsize = HEADER->compsize;
-  int bufsize;
-  if(normsize < compsize)
-    bufsize = compsize;
-  else
-    bufsize = normsize;
-  if(bufsize==0)
-    return NULL;
+  COUT(3) << "GameStateClient: uncompressing gamestate. id: " << HEADER->id << ", baseid: " << HEADER->base_id << ", normsize: " << HEADER->normsize << ", compsize: " << HEADER->compsize << std::endl;
+  unsigned int normsize = HEADER->normsize;
+  unsigned int compsize = HEADER->compsize;
+  unsigned int bufsize;
+  assert(compsize<=normsize);
+  bufsize = normsize;
+  assert(bufsize!=0);
   unsigned char *ndata = new unsigned char[bufsize + sizeof(GamestateHeader)];
   unsigned char *dest = ndata + sizeof(GamestateHeader);
+  unsigned char *source = data_ + sizeof(GamestateHeader);
   int retval;
-  uLongf length=normsize;
-  retval = uncompress( dest, &length, data_+sizeof(GamestateHeader), (uLong)compsize );
+  uLongf length=bufsize;
+  retval = uncompress( dest, &length, source, (uLong)compsize );
   switch ( retval ) {
     case Z_OK: COUT(5) << "successfully decompressed" << std::endl; break;
@@ -239,13 +262,13 @@
   }
   
-  HEADER->compressed = false;
   //copy over the header
   *GAMESTATE_HEADER(ndata) = *HEADER;
   //delete old (compressed data)
   delete[] data_;
-  //set new pointers and create bytestream
+  //set new pointers
   data_ = ndata;
-  //bs_ = new Bytestream(getGs(), GAMESTATE_HEADER->normsize);
-  
+  HEADER->compressed = false;
+  assert(HEADER->normsize==normsize);
+  assert(HEADER->compsize==compsize);
   return true;
 }
@@ -279,8 +302,7 @@
   GAMESTATE_HEADER(ndata)->diffed = true;
   GAMESTATE_HEADER(ndata)->base_id = base->getID();
-  Gamestate *g = new Gamestate(ndata, 0);
+  Gamestate *g = new Gamestate(ndata, getClientID());
   g->flags_=flags_;
   g->packetDirection_ = packetDirection_;
-  g->clientID_ = clientID_;
   return g;
 }
@@ -315,8 +337,7 @@
   *GAMESTATE_HEADER(ndata) = *HEADER;
   GAMESTATE_HEADER(ndata)->diffed = false;
-  Gamestate *g = new Gamestate(ndata, 0);
+  Gamestate *g = new Gamestate(ndata, getClientID());
   g->flags_=flags_;
   g->packetDirection_ = packetDirection_;
-  g->clientID_ = clientID_;
   assert(!g->isDiffed());
   assert(!g->isCompressed());
Index: code/branches/network/src/network/packet/Gamestate.h
===================================================================
--- code/branches/network/src/network/packet/Gamestate.h	(revision 1739)
+++ code/branches/network/src/network/packet/Gamestate.h	(revision 1741)
@@ -75,5 +75,5 @@
     virtual bool process();
 
-    
+    bool operator ==(packet::Gamestate gs);
   private:
     unsigned int calcGamestateSize(int mode=0x0);
Index: code/branches/network/src/network/packet/Packet.cc
===================================================================
--- code/branches/network/src/network/packet/Packet.cc	(revision 1739)
+++ code/branches/network/src/network/packet/Packet.cc	(revision 1741)
@@ -113,5 +113,5 @@
     packetMap_[enetPacket_] = this;
   }
-#ifndef NDEBUG
+#ifndef NDEBUG 
   switch( *(ENUM::Type *)(data_ + _PACKETID) )
   {
@@ -123,5 +123,5 @@
       break;
     default:
-      assert(0); //TODO: repair this
+      assert(0); //there was some error, if this is the case
       break;
   }
