Index: code/trunk/src/network/Client.cc
===================================================================
--- code/trunk/src/network/Client.cc	(revision 3196)
+++ code/trunk/src/network/Client.cc	(revision 3198)
@@ -169,4 +169,5 @@
       bool b = packet->process();
       assert(b);
+      delete event;
     }
     if(gamestate.processGamestates())
Index: code/trunk/src/network/ClientConnection.cc
===================================================================
--- code/trunk/src/network/ClientConnection.cc	(revision 3196)
+++ code/trunk/src/network/ClientConnection.cc	(revision 3198)
@@ -169,6 +169,6 @@
 // 	        assert(0);
           printf("ClientConnection: ENet returned with an error!\n");
-          quit_=true;
-          break;
+//           quit_=true;
+          continue;
           // add some error handling here ========================
         }
@@ -197,10 +197,16 @@
       }
     }
+    delete event;
     // now disconnect
 
     if(!disconnectConnection())
+    {
+      printf("could not disconnect properly\n");
       // if disconnecting failed destroy conn.
       boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
       enet_peer_reset(server);
+    }
+    else
+      printf("properly disconnected\n");
     return;
   }
@@ -221,4 +227,5 @@
         break;
       case ENET_EVENT_TYPE_DISCONNECT:
+        printf("received disconnect confirmation from server");
         return true;
       }
Index: code/trunk/src/network/ClientInformation.h
===================================================================
--- code/trunk/src/network/ClientInformation.h	(revision 3196)
+++ code/trunk/src/network/ClientInformation.h	(revision 3198)
@@ -91,5 +91,4 @@
     bool getSynched();
 
-
   private:
     static ClientInformation *head_;
Index: code/trunk/src/network/ConnectionManager.cc
===================================================================
--- code/trunk/src/network/ConnectionManager.cc	(revision 3196)
+++ code/trunk/src/network/ConnectionManager.cc	(revision 3198)
@@ -132,4 +132,5 @@
     quit_=true;
     receiverThread_->join();
+    delete receiverThread_;
     return true;
   }
@@ -206,6 +207,6 @@
           // we should never reach this point
           printf("ConnectionManager: ENet returned with an error\n");
-          quit_=true;
-          printf("waaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaahhhhhhhhhhhhhhhh\n");
+//           quit_=true;
+//           printf("waaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaahhhhhhhhhhhhhhhh\n");
           continue;
           // add some error handling here ========================
@@ -218,11 +219,12 @@
 //             printf("====================================================================");
         case ENET_EVENT_TYPE_DISCONNECT:
+//           printf("====================================================================");
         case ENET_EVENT_TYPE_RECEIVE:
-            processData(event);
-            event = new ENetEvent;
+          processData(event);
+          event = new ENetEvent;
           break;
         case ENET_EVENT_TYPE_NONE:
           //receiverThread_->yield();
-          msleep(10);
+          msleep(1);
           break;
       }
Index: code/trunk/src/network/ConnectionManager.h
===================================================================
--- code/trunk/src/network/ConnectionManager.h	(revision 3196)
+++ code/trunk/src/network/ConnectionManager.h	(revision 3198)
@@ -55,5 +55,5 @@
     const int NETWORK_PORT = 55556;
     const int NETWORK_MAX_CONNECTIONS = 50;
-    const int NETWORK_WAIT_TIMEOUT = 10;
+    const int NETWORK_WAIT_TIMEOUT = 1;
     const int NETWORK_DEFAULT_CHANNEL = 0;
 
Index: code/trunk/src/network/GamestateManager.cc
===================================================================
--- code/trunk/src/network/GamestateManager.cc	(revision 3196)
+++ code/trunk/src/network/GamestateManager.cc	(revision 3198)
@@ -63,4 +63,8 @@
   GamestateManager::~GamestateManager()
   {
+    if( this->reference )
+      delete this->reference;
+    for( std::map<unsigned int, packet::Gamestate*>::iterator it = gamestateQueue.begin(); it != gamestateQueue.end(); it++ )
+      delete (*it).second;
     delete trafficControl_;
   }
@@ -133,5 +137,8 @@
 //       COUT(3) << "diffing" << std::endl;
 //       packet::Gamestate* gs1  = gs;
-      gs = gs->diff(client);
+      packet::Gamestate *diffed = gs->diff(client);
+      //packet::Gamestate *gs2 = diffed->undiff(gs);
+//       assert(*gs == *gs2);
+      gs = diffed;
 //       packet::Gamestate* gs2 = gs->undiff(client);
 //       gs = new packet::Gamestate(*gs);
Index: code/trunk/src/network/Server.cc
===================================================================
--- code/trunk/src/network/Server.cc	(revision 3196)
+++ code/trunk/src/network/Server.cc	(revision 3198)
@@ -128,4 +128,13 @@
   */
   void Server::close() {
+    ClientInformation *temp = ClientInformation::getBegin();
+    ClientInformation *temp2;
+    // disconnect all connected clients
+    while( temp )
+    {
+      temp2 = temp;
+      temp = temp->next();
+      disconnectClient( temp2 );
+    }
     connection->quitListener();
     return;
@@ -198,5 +207,5 @@
       switch( event->type ) {
       case ENET_EVENT_TYPE_CONNECT:
-        COUT(3) << "processing event_Type_connect" << std::endl;
+        COUT(4) << "processing event_Type_connect" << std::endl;
         addClient(event);
         break;
@@ -304,4 +313,5 @@
       // gs gets automatically deleted by enet callback
     }
+    delete del;
     return true;
   }
@@ -381,24 +391,25 @@
     if(!client)
       return false;
+    else
+      disconnectClient( client );
+    return true;
+  }
+
+  void Server::disconnectClient(int clientID){
+    ClientInformation *client = ClientInformation::findClient(clientID);
+    if(client)
+      disconnectClient(client);
+  }
+  
+  void Server::disconnectClient( ClientInformation *client){
+    connection->disconnectClient(client);
     gamestates_->removeClient(client);
-
 // inform all the listeners
     ObjectList<ClientConnectionListener>::iterator listener = ObjectList<ClientConnectionListener>::begin();
     while(listener){
       listener->clientDisconnected(client->getID());
-      listener++;
-    }
-
-    return ClientInformation::removeClient(event->peer);
-  }
-
-  void Server::disconnectClient(int clientID){
-    ClientInformation *client = ClientInformation::findClient(clientID);
-    if(client)
-      disconnectClient(client);
-  }
-  void Server::disconnectClient( ClientInformation *client){
-    connection->disconnectClient(client);
-    gamestates_->removeClient(client);
+      ++listener;
+    }
+    delete client; //remove client from list
   }
 
Index: code/trunk/src/network/TrafficControl.cc
===================================================================
--- code/trunk/src/network/TrafficControl.cc	(revision 3196)
+++ code/trunk/src/network/TrafficControl.cc	(revision 3198)
@@ -137,4 +137,6 @@
 	void TrafficControl::ack(unsigned int clientID, unsigned int gamestateID)
 	{
+    if ( !this->bActive_ )
+      return;
 	  std::list<obj>::iterator itvec;  // iterator to iterate through the acked objects
 
@@ -189,5 +191,5 @@
   void TrafficControl::updateClientListTemp(std::list<obj>& list)
   {
-    clientListTemp_[currentClientID][currentGamestateID] = std::list<obj>(list);
+    clientListTemp_[currentClientID][currentGamestateID] = list;
   }
 
@@ -227,32 +229,32 @@
 	{
 
-	  //now the sorting
-
-	  //compare listToProcess vs clientListPerm
-    //if listToProcess contains new Objects, add them to clientListPerm
-    std::list<obj>::iterator itvec;
+    if( bActive_ )
+    {
+      //now the sorting
+
+      //compare listToProcess vs clientListPerm
+      //if listToProcess contains new Objects, add them to clientListPerm
+      std::list<obj>::iterator itvec;
     
-    std::map<unsigned int, objInfo >& objectListPerm = clientListPerm_[clientID];
+      std::map<unsigned int, objInfo >& objectListPerm = clientListPerm_[clientID];
     
-	  for( itvec=list.begin(); itvec != list.end(); itvec++)
-	  {
-	    if ( objectListPerm.find( (*itvec).objID) != objectListPerm.end() )
-      {
+      for( itvec=list.begin(); itvec != list.end(); itvec++)
+      {
+        if ( objectListPerm.find( (*itvec).objID) != objectListPerm.end() )
+        {
         // we already have the object in our map
         //obj bleibt in liste und permanente prio wird berechnet
-        objectListPerm[(*itvec).objID].objDiffGS = currentGamestateID - objectListPerm[(*itvec).objID].objCurGS;
-        continue;//check next objId
-      }
-      else
-      {
+          objectListPerm[(*itvec).objID].objDiffGS = currentGamestateID - objectListPerm[(*itvec).objID].objCurGS;
+          continue;//check next objId
+        }
+        else
+        {
         // insert the object into clientListPerm
-        insertinClientListPerm(clientID,*itvec);
-        continue;//check next objId
-      }
-    }
-	  //end compare listToProcess vs clientListPerm
-
-    if( bActive_ )
-    {
+          insertinClientListPerm(clientID,*itvec);
+          continue;//check next objId
+        }
+      }
+    //end compare listToProcess vs clientListPerm
+      
       //sort copied list according to priorities
       // use boost bind here because we need to pass a memberfunction to stl sort
@@ -275,8 +277,9 @@
 //       sort(list.begin(), list.end(), boost::bind(&TrafficControl::dataSort, this, _1, _2) );
       list.sort( boost::bind(&TrafficControl::dataSort, this, _1, _2) );
+      
+      //diese Funktion updateClientList muss noch gemacht werden
+      updateClientListTemp(list);
+      //end of sorting
     }
-    //diese Funktion updateClientList muss noch gemacht werden
-    updateClientListTemp(list);
-    //end of sorting
   }
 
Index: code/trunk/src/network/packet/Acknowledgement.cc
===================================================================
--- code/trunk/src/network/packet/Acknowledgement.cc	(revision 3196)
+++ code/trunk/src/network/packet/Acknowledgement.cc	(revision 3198)
@@ -64,5 +64,5 @@
 
 bool Acknowledgement::process(){
-COUT(6) << "processing ACK with ID: " << getAckID() << endl;
+  COUT(5) << "processing ACK with ID: " << getAckID() << endl;
   bool b = GamestateHandler::ackGamestate(getAckID(), clientID_);
   delete this;
Index: code/trunk/src/network/packet/Gamestate.cc
===================================================================
--- code/trunk/src/network/packet/Gamestate.cc	(revision 3196)
+++ code/trunk/src/network/packet/Gamestate.cc	(revision 3198)
@@ -79,4 +79,6 @@
 Gamestate::~Gamestate()
 {
+  if( header_ )
+    delete header_;
 }
 
@@ -98,4 +100,5 @@
   
   // create the header object
+  assert( header_ == 0 );
   header_ = new GamestateHeader(data_);
 
@@ -137,4 +140,5 @@
   header_->setDataSize( currentsize );
   header_->setID( id );
+  header_->setBaseID( GAMESTATEID_INITIAL );
   header_->setDiffed( false );
   header_->setComplete( true );
@@ -207,5 +211,4 @@
   }
 #endif
-
   return true;
 }
@@ -320,5 +323,5 @@
 }
 
-Gamestate *Gamestate::diff(Gamestate *base)
+/*Gamestate *Gamestate::diff(Gamestate *base)
 {
   assert(data_);
@@ -355,5 +358,70 @@
   g->packetDirection_ = packetDirection_;
   return g;
-}
+}*/
+
+Gamestate *Gamestate::diff(Gamestate *base)
+{
+  assert(this && base); assert(data_ && base->data_);
+  assert(!header_->isCompressed() && !base->header_->isCompressed());
+  assert(!header_->isDiffed());
+  
+  uint8_t *basep = GAMESTATE_START(base->data_);
+  uint8_t *gs = GAMESTATE_START(this->data_);
+  uint32_t dest_length = header_->getDataSize();
+  
+  if(dest_length==0)
+    return NULL;
+  
+  uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()];
+  uint8_t *dest = GAMESTATE_START(ndata);
+  
+  rawDiff( dest, gs, basep, header_->getDataSize(), base->header_->getDataSize() );
+#ifndef NDEBUG
+  uint8_t *dest2 = new uint8_t[dest_length];
+  rawDiff( dest2, dest, basep, header_->getDataSize(), base->header_->getDataSize() );
+  assert( memcmp( dest2, gs, dest_length) == 0 );
+#endif
+
+  Gamestate *g = new Gamestate(ndata, getClientID());
+  assert(g->header_);
+  *(g->header_) = *header_;
+  g->header_->setDiffed( true );
+  g->header_->setBaseID( base->getID() );
+  g->flags_=flags_;
+  g->packetDirection_ = packetDirection_;
+  assert(g->isDiffed());
+  assert(!g->isCompressed());
+  return g;
+}
+
+Gamestate *Gamestate::undiff(Gamestate *base)
+{
+  assert(this && base); assert(data_ && base->data_);
+  assert(!header_->isCompressed() && !base->header_->isCompressed());
+  assert(header_->isDiffed());
+  
+  uint8_t *basep = GAMESTATE_START(base->data_);
+  uint8_t *gs = GAMESTATE_START(this->data_);
+  uint32_t dest_length = header_->getDataSize();
+  
+  if(dest_length==0)
+    return NULL;
+  
+  uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()];
+  uint8_t *dest = ndata + GamestateHeader::getSize();
+  
+  rawDiff( dest, gs, basep, header_->getDataSize(), base->header_->getDataSize() );
+  
+  Gamestate *g = new Gamestate(ndata, getClientID());
+  assert(g->header_);
+  *(g->header_) = *header_;
+  g->header_->setDiffed( false );
+  g->flags_=flags_;
+  g->packetDirection_ = packetDirection_;
+  assert(!g->isDiffed());
+  assert(!g->isCompressed());
+  return g;
+}
+
 
 // Gamestate *Gamestate::diff(Gamestate *base)
@@ -409,4 +477,31 @@
 // }
 
+
+void Gamestate::rawDiff( uint8_t* newdata, uint8_t* data, uint8_t* basedata, uint32_t datalength, uint32_t baselength)
+{
+  uint64_t* gd = (uint64_t*)data;
+  uint64_t* bd = (uint64_t*)basedata;
+  uint64_t* nd = (uint64_t*)newdata;
+  
+  unsigned int i;
+  for( i=0; i<datalength/8; i++ )
+  {
+    if( i<baselength/8 )
+      *(nd+i) = *(gd+i) ^ *(bd+i);  // xor the data
+    else
+      *(nd+i) = *(gd+i); // just copy over the data
+  }
+  unsigned int j;
+  // now process the rest (when datalength isn't a multiple of 4)
+  for( j = 8*(datalength/8); j<datalength; j++ )
+  {
+    if( j<baselength )
+      *(newdata+j) = *(data+j) ^ *(basedata+j); // xor
+    else
+      *(newdata+j) = *(data+j); // just copy
+  }
+  assert(j==datalength);
+}
+
 Gamestate* Gamestate::doSelection(unsigned int clientID, unsigned int targetSize){
   assert(data_);
@@ -478,5 +573,5 @@
 
 
-Gamestate *Gamestate::undiff(Gamestate *base)
+/*Gamestate *Gamestate::undiff(Gamestate *base)
 {
   assert(this && base);assert(data_);
@@ -514,6 +609,5 @@
   assert(!g->isCompressed());
   return g;
-}
-
+}*/
 
 uint32_t Gamestate::calcGamestateSize(int32_t id, uint8_t mode)
Index: code/trunk/src/network/packet/Gamestate.h
===================================================================
--- code/trunk/src/network/packet/Gamestate.h	(revision 3196)
+++ code/trunk/src/network/packet/Gamestate.h	(revision 3198)
@@ -124,4 +124,5 @@
     // Packet functions
   private:
+    void rawDiff( uint8_t* newdata, uint8_t* data, uint8_t* basedata, uint32_t datalength, uint32_t baselength);
     virtual uint32_t getSize() const;
     virtual inline bool process();
Index: code/trunk/src/network/synchronisable/Synchronisable.cc
===================================================================
--- code/trunk/src/network/synchronisable/Synchronisable.cc	(revision 3196)
+++ code/trunk/src/network/synchronisable/Synchronisable.cc	(revision 3198)
@@ -98,8 +98,12 @@
     // delete callback function objects
     if(!Identifier::isCreatingHierarchy()){
+      // remove object from the static objectMap
+      if (this->objectMode_ != 0x0 && (Host::running() && Host::isServer()))
+        deletedObjects_.push(objectID);
+      // delete all Synchronisable Variables from syncList ( which are also in stringList )
       for(std::vector<SynchronisableVariableBase*>::iterator it = syncList.begin(); it!=syncList.end(); it++)
         delete (*it);
-      if (this->objectMode_ != 0x0 && (Host::running() && Host::isServer()))
-        deletedObjects_.push(objectID);
+      syncList.clear();
+      stringList.clear();
     }
     std::map<uint32_t, Synchronisable*>::iterator it;
@@ -174,4 +178,6 @@
     COUT(4) << "fabricate objectID: " << no->objectID << " classID: " << no->classID << std::endl;
           // update data and create object/entity...
+    assert( Synchronisable::objectMap_.find(header.getObjectID()) == Synchronisable::objectMap_.end() );
+    Synchronisable::objectMap_[header.getObjectID()] = no;
     bool b = no->updateData(mem, mode, true);
     assert(b);
@@ -213,11 +219,12 @@
       return it1->second;
 
-    ObjectList<Synchronisable>::iterator it;
-    for(it = ObjectList<Synchronisable>::begin(); it; ++it){
-      if( it->getObjectID()==objectID ){
-        objectMap_[objectID] = *it;
-        return *it;
-      }
-    }
+//     ObjectList<Synchronisable>::iterator it;
+//     for(it = ObjectList<Synchronisable>::begin(); it; ++it){
+//       if( it->getObjectID()==objectID ){
+//         objectMap_[objectID] = *it;
+//         return *it;
+//       }
+//     }
+    // if the objects not in the map it should'nt exist at all anymore
     return NULL;
   }
