Index: /code/branches/network/src/network/Client.cc
===================================================================
--- /code/branches/network/src/network/Client.cc	(revision 1738)
+++ /code/branches/network/src/network/Client.cc	(revision 1739)
@@ -61,4 +61,5 @@
     isSynched_=false;
     gameStateFailure_=false;
+    isServer_ = false;
   }
 
@@ -72,4 +73,5 @@
     isSynched_=false;
     gameStateFailure_=false;
+    isServer_ = false;
   }
 
@@ -83,4 +85,5 @@
     isSynched_=false;
     gameStateFailure_=false;
+    isServer_ = false;
   }
 
@@ -151,5 +154,5 @@
     if(client_connection.isConnected() && isSynched_){
       COUT(4) << "popping partial gamestate: " << std::endl;
-      /*packet::Gamestate *gs = gamestate.getGamestate();
+      packet::Gamestate *gs = gamestate.getGamestate();
       if(gs){
         COUT(4) << "client tick: sending gs " << gs << std::endl;
@@ -157,5 +160,5 @@
           COUT(3) << "Problem adding partial gamestate to queue" << std::endl;
         // gs gets automatically deleted by enet callback
-      }*/
+      }
     }
     ENetEvent *event;
@@ -168,8 +171,8 @@
     }
     int gameStateID = gamestate.processGamestates();
-    /*if(gameStateID==GAMESTATEID_INITIAL)
+    if(gameStateID==GAMESTATEID_INITIAL)
       if(gameStateFailure_){
-        packet::Acknowledgement ack(GAMESTATEID_INITIAL, 0);
-        if(!ack.send())
+        packet::Acknowledgement *ack = new packet::Acknowledgement(GAMESTATEID_INITIAL, 0);
+        if(!ack->send())
           COUT(3) << "could not (negatively) ack gamestate" << std::endl;
         else 
@@ -183,8 +186,8 @@
         isSynched_=true;
       gameStateFailure_=false;
-      packet::Acknowledgement ack(gameStateID, 0);
-      if(!ack.send())
+      packet::Acknowledgement *ack = new packet::Acknowledgement(gameStateID, 0);
+      if(!ack->send())
         COUT(3) << "could not ack gamestate" << std::endl;
-    }*/// otherwise we had no gamestate to load
+    }// otherwise we had no gamestate to load
     gamestate.cleanup();
     return;
Index: /code/branches/network/src/network/GamestateClient.cc
===================================================================
--- /code/branches/network/src/network/GamestateClient.cc	(revision 1738)
+++ /code/branches/network/src/network/GamestateClient.cc	(revision 1739)
@@ -73,10 +73,15 @@
       return 0;
     int id = GAMESTATEID_INITIAL;
-    bool b = saveShipCache();
-    if(processGamestate(tempGamestate_)){
-      if(b)
-        loadShipCache();
-      id = tempGamestate_->getID();
-    }
+    //bool b = saveShipCache();
+    packet::Gamestate *processed = processGamestate(tempGamestate_);
+    assert(processed);
+    //successfully loaded data from gamestate. now save gamestate for diff and delete the old gs
+    tempGamestate_=0;
+    gamestateMap_[processed->getID()]=processed;
+    last_diff_ = processed->getBaseID();
+    last_gamestate_ = processed->getID();
+    //if(b)
+      //loadShipCache();
+    id = processed->getID();
     cleanup();
     return id;
@@ -151,9 +156,19 @@
   }
 
-  bool GamestateClient::processGamestate(packet::Gamestate *gs){
-    assert(gs->decompressData());
-    if(gs->isDiffed())
-      assert(gs->undiff(gamestateMap_[gs->getBaseID()]));
-    return gs->spreadData();
+  packet::Gamestate *GamestateClient::processGamestate(packet::Gamestate *gs){
+    if(gs->isCompressed())
+      assert(gs->decompressData());
+    if(gs->isDiffed()){
+      packet::Gamestate *base = gamestateMap_[gs->getBaseID()];
+      assert(base);
+      packet::Gamestate *undiffed = gs->undiff(base);
+      delete gs;
+      gs=undiffed;
+      COUT(3) << "successfully undiffed gamestate id: " << undiffed->getID() << std::endl;
+    }
+    if(gs->spreadData())
+      return gs;
+    else
+      return NULL;
   }
 
Index: /code/branches/network/src/network/GamestateClient.h
===================================================================
--- /code/branches/network/src/network/GamestateClient.h	(revision 1738)
+++ /code/branches/network/src/network/GamestateClient.h	(revision 1739)
@@ -66,5 +66,5 @@
     void cleanup();
   private:
-    bool processGamestate(packet::Gamestate *gs);
+    packet::Gamestate *processGamestate(packet::Gamestate *gs);
     void removeObject(orxonox::Iterator<Synchronisable> &it);
     void printGamestateMap();
Index: /code/branches/network/src/network/GamestateManager.cc
===================================================================
--- /code/branches/network/src/network/GamestateManager.cc	(revision 1738)
+++ /code/branches/network/src/network/GamestateManager.cc	(revision 1739)
@@ -194,9 +194,9 @@
     if(client->getGamestateID()>=0)
       gamestateUsed[client->getGamestateID()]--;
-    ClientInformation::removeClient(client->getID());
   }
   
   bool GamestateManager::processGamestate(packet::Gamestate *gs){
-    assert(gs->decompressData());
+    if(gs->isCompressed())
+       assert(gs->decompressData());
     assert(!gs->isDiffed());
     return gs->spreadData();
Index: /code/branches/network/src/network/Host.cc
===================================================================
--- /code/branches/network/src/network/Host.cc	(revision 1738)
+++ /code/branches/network/src/network/Host.cc	(revision 1739)
@@ -1,2 +1,30 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Oliver Scheuss <scheusso [at] ee.ethz.ch>, (C) 2008
+ *   Co-authors:
+ *      ...
+ *
+ */
+
 #include <assert.h>
 
Index: /code/branches/network/src/network/Host.h
===================================================================
--- /code/branches/network/src/network/Host.h	(revision 1738)
+++ /code/branches/network/src/network/Host.h	(revision 1739)
@@ -54,4 +54,5 @@
     ~Host();
     static Host *instance_;
+    bool isServer_;	
     
   public:
@@ -64,4 +65,5 @@
     static void setClientID(unsigned int id){ instance_->clientID_ = id; }
     static void setShipID(unsigned int id){ instance_->shipID_ = id; }
+    static bool isServer(){ return instance_->isServer_; }		
   private:
     unsigned int clientID_;
Index: /code/branches/network/src/network/Server.cc
===================================================================
--- /code/branches/network/src/network/Server.cc	(revision 1738)
+++ /code/branches/network/src/network/Server.cc	(revision 1739)
@@ -53,4 +53,5 @@
 #include "packet/Packet.h"
 #include "packet/Welcome.h"
+#include <util/Convert.h>
 
 namespace network
@@ -67,4 +68,5 @@
     connection = new ConnectionManager();
     gamestates_ = new GamestateManager();
+    isServer_ = true;
   }
   
@@ -73,4 +75,5 @@
     connection = new ConnectionManager(port);
     gamestates_ = new GamestateManager();
+    isServer_ = true;
   }
 
@@ -84,4 +87,5 @@
     connection = new ConnectionManager(port, bindAddress);
     gamestates_ = new GamestateManager();
+    isServer_ = true;
   }
 
@@ -95,4 +99,5 @@
     connection = new ConnectionManager(port, bindAddress);
     gamestates_ = new GamestateManager();
+    isServer_ = true;
   }
 
@@ -348,5 +353,5 @@
     no->setTransDamp(75);
     no->setRotDamp(1.0);
-    no->setCamera("cam_"+client->getID());
+    no->setCamera(std::string("cam_") + convertToString(client->getID()));
     no->create();
     no->setBacksync(true);
@@ -364,4 +369,5 @@
     if(!client)
       return false;
+    gamestates_->removeClient(client);
     while(it){
       if(it->objectID!=client->getShipID()){
Index: /code/branches/network/src/network/packet/Acknowledgement.cc
===================================================================
--- /code/branches/network/src/network/packet/Acknowledgement.cc	(revision 1738)
+++ /code/branches/network/src/network/packet/Acknowledgement.cc	(revision 1739)
@@ -45,5 +45,5 @@
   data_=new unsigned char[ getSize() ];
   *(ENUM::Type *)(data_ + _PACKETID ) = ENUM::Acknowledgement;
-  *(unsigned int *)&data_[ _ACKID ] = id;
+  *(unsigned int *)(data_ + _ACKID ) = id;
   clientID_=clientID;
 }
Index: /code/branches/network/src/network/packet/Gamestate.cc
===================================================================
--- /code/branches/network/src/network/packet/Gamestate.cc	(revision 1738)
+++ /code/branches/network/src/network/packet/Gamestate.cc	(revision 1739)
@@ -120,5 +120,7 @@
 bool Gamestate::spreadData(int mode)
 {
-  assert(data_ && !HEADER->compressed && !HEADER->diffed);
+  assert(data_);
+  assert(!HEADER->compressed);
+  assert(!HEADER->diffed);
   unsigned int size, objectID, classID;
   unsigned char *mem=data_+sizeof(GamestateHeader);
@@ -141,5 +143,5 @@
         //fabricate the new synchronisable
         if(!Synchronisable::fabricate(mem, mode))
-          /*return false*/;
+          return false;
         it=orxonox::ObjectList<Synchronisable>::end();
       }
@@ -276,5 +278,9 @@
   *GAMESTATE_HEADER(ndata) = *HEADER;
   GAMESTATE_HEADER(ndata)->diffed = true;
+  GAMESTATE_HEADER(ndata)->base_id = base->getID();
   Gamestate *g = new Gamestate(ndata, 0);
+  g->flags_=flags_;
+  g->packetDirection_ = packetDirection_;
+  g->clientID_ = clientID_;
   return g;
 }
@@ -310,4 +316,9 @@
   GAMESTATE_HEADER(ndata)->diffed = false;
   Gamestate *g = new Gamestate(ndata, 0);
+  g->flags_=flags_;
+  g->packetDirection_ = packetDirection_;
+  g->clientID_ = clientID_;
+  assert(!g->isDiffed());
+  assert(!g->isCompressed());
   return g;
 }
@@ -341,4 +352,8 @@
   }
   
+  bool Gamestate::isCompressed(){
+    return HEADER->compressed;
+  }
+  
   int Gamestate::getBaseID(){
     return HEADER->base_id;
Index: /code/branches/network/src/network/packet/Gamestate.h
===================================================================
--- /code/branches/network/src/network/packet/Gamestate.h	(revision 1738)
+++ /code/branches/network/src/network/packet/Gamestate.h	(revision 1739)
@@ -64,4 +64,5 @@
     int getID();
     bool isDiffed();
+    bool isCompressed();
     int getBaseID();
     Gamestate *diff(Gamestate *base);
Index: /code/branches/network/src/network/packet/Packet.cc
===================================================================
--- /code/branches/network/src/network/packet/Packet.cc	(revision 1738)
+++ /code/branches/network/src/network/packet/Packet.cc	(revision 1739)
@@ -113,5 +113,6 @@
     packetMap_[enetPacket_] = this;
   }
-  /*switch( *(ENUM::Type *)(data_ + _PACKETID) )
+#ifndef NDEBUG
+  switch( *(ENUM::Type *)(data_ + _PACKETID) )
   {
     case ENUM::Acknowledgement:
@@ -120,10 +121,10 @@
     case ENUM::Gamestate:
     case ENUM::Welcome:
-      COUT(3) << "welcome" << std::endl;
-      p = new Welcome( data, clientID );
+      break;
     default:
       assert(0); //TODO: repair this
       break;
-  }*/
+  }
+#endif
   network::Host::addPacket( enetPacket_, clientID_);
   enetPacket_ = 0; // otherwise we have a double free because enet already handles the deallocation of the packet
Index: /code/branches/network/src/network/packet/Packet.h
===================================================================
--- /code/branches/network/src/network/packet/Packet.h	(revision 1738)
+++ /code/branches/network/src/network/packet/Packet.h	(revision 1739)
@@ -78,9 +78,9 @@
     enet_uint32 flags_;
     int clientID_;
+    ENUM::Direction packetDirection_;
     unsigned char *data_;
   private:
     static std::map<ENetPacket *, Packet *> packetMap_;
     ENetPacket *enetPacket_;
-    ENUM::Direction packetDirection_;
 };
 
