Index: /code/branches/network5/src/libraries/network/CMakeLists.txt
===================================================================
--- /code/branches/network5/src/libraries/network/CMakeLists.txt	(revision 7776)
+++ /code/branches/network5/src/libraries/network/CMakeLists.txt	(revision 7777)
@@ -28,5 +28,5 @@
   FunctionCallManager.cc
   GamestateManager.cc
-  GamestateClient.cc
+  #GamestateClient.cc
   GamestateHandler.cc
   LANDiscoverable.cc
@@ -53,5 +53,5 @@
   FunctionCall.h
   FunctionCallManager.h
-  GamestateClient.h
+  #GamestateClient.h
   GamestateHandler.h
   GamestateManager.h
Index: /code/branches/network5/src/libraries/network/Client.cc
===================================================================
--- /code/branches/network5/src/libraries/network/Client.cc	(revision 7776)
+++ /code/branches/network5/src/libraries/network/Client.cc	(revision 7777)
@@ -64,5 +64,4 @@
   */
   Client::Client():
-      gamestate(0),
       isSynched_(false),
       gameStateFailure_(false),
@@ -85,8 +84,8 @@
   {
     Synchronisable::setClient(true);
-    this->gamestate = new GamestateClient();
     if( ClientConnection::establishConnection() )
     {
       Host::setActive(true);
+      GamestateManager::addPeer(NETWORK_PEER_ID_SERVER);
       return true;
     }
@@ -101,8 +100,6 @@
   bool Client::closeConnection()
   {
-    assert(this->gamestate);
-    delete this->gamestate;
-    this->gamestate = 0;
     Host::setActive(false);
+    GamestateManager::removePeer(NETWORK_PEER_ID_SERVER);
     return ClientConnection::closeConnection();
   }
@@ -138,5 +135,5 @@
   {
     packet::Chat *m = new packet::Chat(message, Host::getPlayerID());
-    return m->send();
+    return m->send(static_cast<Host*>(this));
   }
 
@@ -157,13 +154,20 @@
       {
         COUT(4) << "popping partial gamestate: " << std::endl;
-        packet::Gamestate *gs = gamestate->getGamestate();
+//         packet::Gamestate *gs = GamestateClient::getGamestate();
+        GamestateManager::update();
+        std::vector<packet::Gamestate*> gamestates = GamestateManager::getGamestates();
+        std::vector<packet::Gamestate*>::iterator it;
+        for( it = gamestates.begin(); it != gamestates.end(); ++it )
+        {
+          (*it)->send( static_cast<Host*>(this) );
+        }
         //assert(gs); <--- there might be the case that no data has to be sent, so its commented out now
-        if(gs){
-          COUT(4) << "client tick: sending gs " << gs << std::endl;
-          if( !gs->send() )
-            COUT(2) << "Problem adding partial gamestate to queue" << std::endl;
-        // gs gets automatically deleted by enet callback
-        }
-        FunctionCallManager::sendCalls();
+//         if(gs){
+//           COUT(4) << "client tick: sending gs " << gs << std::endl;
+//           if( !gs->send() )
+//             COUT(2) << "Problem adding partial gamestate to queue" << std::endl;
+//         // gs gets automatically deleted by enet callback
+//         }
+        FunctionCallManager::sendCalls(static_cast<Host*>(this));
       }
     }
@@ -171,5 +175,5 @@
 
     Connection::processQueue();
-    if(gamestate->processGamestates())
+    if(GamestateManager::processGamestates())
     {
       FunctionCallManager::processBufferedFunctionCalls();
@@ -177,5 +181,5 @@
         isSynched_=true;
     }
-    gamestate->cleanup();
+//     GamestateManager::cleanup();;
 //     Connection::sendPackets();
 
@@ -198,4 +202,18 @@
     Game::getInstance().popState();
   }
+  
+  void Client::processPacket(packet::Packet* packet)
+  {
+    if( packet->isReliable() )
+    {
+      if( this->getLastProcessedGamestateID(packet->getPeerID()) >= packet->getRequiredGamestateID() )
+        packet->process(static_cast<Host*>(this));
+      else
+        this->packetQueue_.push_back(packet);
+    }
+    else
+      packet->process(static_cast<Host*>(this));
+  }
+
 
 
Index: /code/branches/network5/src/libraries/network/Client.h
===================================================================
--- /code/branches/network5/src/libraries/network/Client.h	(revision 7776)
+++ /code/branches/network5/src/libraries/network/Client.h	(revision 7777)
@@ -45,9 +45,10 @@
 
 #include <string>
+#include <deque>
 
 #include "util/UtilPrereqs.h"
 #include "util/Singleton.h"
 #include "ClientConnection.h"
-#include "GamestateClient.h"
+// #include "GamestateClient.h"
 #include "Host.h"
 #include "LANDiscovery.h"
@@ -90,8 +91,9 @@
     Client(const Client& copy); // not used
     virtual bool isServer_(){return false;}
+    void processPacket(packet::Packet* packet);
 
     static Client* singletonPtr_s;
-    GamestateClient* gamestate;
     bool isSynched_;
+    std::deque<packet::Packet*> packetQueue_;
 
     bool gameStateFailure_;
Index: /code/branches/network5/src/libraries/network/ClientConnection.h
===================================================================
--- /code/branches/network5/src/libraries/network/ClientConnection.h	(revision 7776)
+++ /code/branches/network5/src/libraries/network/ClientConnection.h	(revision 7777)
@@ -44,7 +44,7 @@
     void setPort( unsigned int port );
 
-    ENetEvent *getEvent();
+//     ENetEvent *getEvent();
     // check wheter the packet queue is empty
-    bool queueEmpty();
+//     bool queueEmpty();
     // create a new listener thread
     virtual bool establishConnection();
Index: /code/branches/network5/src/libraries/network/ClientInformation.cc
===================================================================
--- /code/branches/network5/src/libraries/network/ClientInformation.cc	(revision 7776)
+++ /code/branches/network5/src/libraries/network/ClientInformation.cc	(revision 7777)
@@ -56,5 +56,4 @@
     preve=0;
     nexte=0;
-    partialGamestateID_=GAMESTATEID_INITIAL-1;
     synched_=false;
   }
@@ -133,11 +132,4 @@
   }
 
-  bool ClientInformation::setPartialGamestateID(int id){
-    if(!this)
-      return false;
-    partialGamestateID_=id;
-    return true;
-  }
-
   unsigned int ClientInformation::getID() {
     if(!this)
@@ -154,14 +146,4 @@
   }
 
-  int ClientInformation::getFailures(){
-    return failures_;
-  }
-  void ClientInformation::addFailure(){
-    failures_++;
-  }
-  void ClientInformation::resetFailures(){
-    failures_=0;
-  }
-
   uint32_t ClientInformation::getRTT(){
     return this->peer_->roundTripTime;
@@ -175,11 +157,4 @@
     if(this)
       return gamestateID_;
-    else
-      return static_cast<unsigned int>(-1);
-  }
-
-  unsigned int ClientInformation::getPartialGamestateID() {
-    if(this)
-      return partialGamestateID_;
     else
       return static_cast<unsigned int>(-1);
Index: /code/branches/network5/src/libraries/network/ClientInformation.h
===================================================================
--- /code/branches/network5/src/libraries/network/ClientInformation.h	(revision 7776)
+++ /code/branches/network5/src/libraries/network/ClientInformation.h	(revision 7777)
@@ -66,5 +66,4 @@
     bool setPeer(ENetPeer *peer);
     bool setGamestateID(int id);
-    bool setPartialGamestateID(int id);
     inline void setShipID(unsigned int id){ShipID_=id;}
 
@@ -73,10 +72,6 @@
     unsigned int getID();
     unsigned int getGamestateID();
-    unsigned int getPartialGamestateID();
     ENetPeer *getPeer();
 
-    int getFailures();
-    void addFailure();
-    void resetFailures();
     uint32_t getRTT();
     double getPacketLoss();
@@ -106,8 +101,6 @@
     unsigned int clientID_;
     unsigned int gamestateID_;
-    unsigned int partialGamestateID_;
     unsigned int ShipID_;   // this is the unique objectID
     bool synched_;
-    unsigned short failures_;
 
   };
Index: /code/branches/network5/src/libraries/network/Connection.cc
===================================================================
--- /code/branches/network5/src/libraries/network/Connection.cc	(revision 7776)
+++ /code/branches/network5/src/libraries/network/Connection.cc	(revision 7777)
@@ -177,4 +177,5 @@
     while( incomingEventsCount > 0 )
     {
+      packet::Packet* p;
       this->incomingEventsMutex_->lock();
       event = this->incomingEvents_.front();
@@ -193,5 +194,6 @@
         case ENET_EVENT_TYPE_RECEIVE:
 //           COUT(0) << "ENET_EVENT_TYPE_RECEIVE" << endl;
-          processPacket( &event );
+          p = createPacket( &event );
+          processPacket(p);
           break;
         case ENET_EVENT_TYPE_NONE:
@@ -205,8 +207,9 @@
   }
 
-  bool Connection::processPacket(ENetEvent* event)
+  packet::Packet* Connection::createPacket(ENetEvent* event)
   {
     packet::Packet *p = packet::Packet::createPacket(event->packet, event->peer);
-    return p->process();
+    return p;
+//     return p->process();
   }
   
Index: /code/branches/network5/src/libraries/network/Connection.h
===================================================================
--- /code/branches/network5/src/libraries/network/Connection.h	(revision 7776)
+++ /code/branches/network5/src/libraries/network/Connection.h	(revision 7777)
@@ -84,5 +84,5 @@
     void addPacket(ENetPacket *packet, ENetPeer *peer, uint8_t channelID);
     void broadcastPacket(ENetPacket* packet, uint8_t channelID);
-    ENetHost* getHost(){ return this->host_; }
+//     ENetHost* getHost(){ return this->host_; }
 
   protected:
@@ -101,9 +101,8 @@
     virtual void addPeer(ENetEvent* event)=0;
     virtual void removePeer(ENetEvent* event)=0;
-    virtual bool processPacket(ENetEvent* event);
+    virtual void processPacket( packet::Packet* packet)=0;
+    virtual packet::Packet* createPacket(ENetEvent* event);
 
     ENetHost*                   host_;
-    boost::mutex*               incomingEventsMutex_;
-    boost::mutex*               outgoingEventsMutex_;
   private:
     boost::thread*              communicationThread_;
@@ -112,4 +111,6 @@
     std::deque<ENetEvent>       incomingEvents_;
     std::deque<outgoingEvent>   outgoingEvents_;
+    boost::mutex*               incomingEventsMutex_;
+    boost::mutex*               outgoingEventsMutex_;
 
 //     static Connection *instance_;
Index: /code/branches/network5/src/libraries/network/FunctionCallManager.cc
===================================================================
--- /code/branches/network5/src/libraries/network/FunctionCallManager.cc	(revision 7776)
+++ /code/branches/network5/src/libraries/network/FunctionCallManager.cc	(revision 7777)
@@ -34,62 +34,62 @@
 namespace orxonox {
 
-std::map<uint32_t, packet::FunctionCalls*> FunctionCallManager::sClientMap_;
+std::map<uint32_t, packet::FunctionCalls*> FunctionCallManager::sPeerMap_;
 std::vector<std::pair<FunctionCall, std::pair<uint32_t, uint32_t> > > FunctionCallManager::sIncomingFunctionCallBuffer_;
 
 // Static calls
 
-void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID)
+void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t peerID)
 {
-  if(sClientMap_.find(clientID)==sClientMap_.end())
+  if(sPeerMap_.find(peerID)==sPeerMap_.end())
   {
-    FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
-    FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
+    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
+    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
   }
-  FunctionCallManager::sClientMap_[clientID]->addCallStatic(functionID);
+  FunctionCallManager::sPeerMap_[peerID]->addCallStatic(functionID);
 }
-void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1)
+void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1)
 {
-  if(sClientMap_.find(clientID)==sClientMap_.end())
+  if(sPeerMap_.find(peerID)==sPeerMap_.end())
   {
-    FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
-    FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
+    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
+    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
   }
-  FunctionCallManager:: sClientMap_[clientID]->addCallStatic(functionID, &mt1);
+  FunctionCallManager:: sPeerMap_[peerID]->addCallStatic(functionID, &mt1);
 }
-void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2)
+void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2)
 {
-  if(sClientMap_.find(clientID)==sClientMap_.end())
+  if(sPeerMap_.find(peerID)==sPeerMap_.end())
   {
-    FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
-    FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
+    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
+    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
   }
-  FunctionCallManager:: sClientMap_[clientID]->addCallStatic(functionID, &mt1, &mt2);
+  FunctionCallManager:: sPeerMap_[peerID]->addCallStatic(functionID, &mt1, &mt2);
 }
-void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3)
+void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3)
 {
-  if(sClientMap_.find(clientID)==sClientMap_.end())
+  if(sPeerMap_.find(peerID)==sPeerMap_.end())
   {
-    FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
-    FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
+    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
+    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
   }
-  FunctionCallManager:: sClientMap_[clientID]->addCallStatic(functionID, &mt1, &mt2, &mt3);
+  FunctionCallManager:: sPeerMap_[peerID]->addCallStatic(functionID, &mt1, &mt2, &mt3);
 }
-void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4)
+void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4)
 {
-  if(sClientMap_.find(clientID)==sClientMap_.end())
+  if(sPeerMap_.find(peerID)==sPeerMap_.end())
   {
-    FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
-    FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
+    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
+    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
   }
-  FunctionCallManager:: sClientMap_[clientID]->addCallStatic(functionID, &mt1, &mt2, &mt3, &mt4);
+  FunctionCallManager:: sPeerMap_[peerID]->addCallStatic(functionID, &mt1, &mt2, &mt3, &mt4);
 }
-void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5)
+void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5)
 {
-  if(sClientMap_.find(clientID)==sClientMap_.end())
+  if(sPeerMap_.find(peerID)==sPeerMap_.end())
   {
-    FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
-    FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
+    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
+    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
   }
-  FunctionCallManager:: sClientMap_[clientID]->addCallStatic(functionID, &mt1, &mt2, &mt3, &mt4, &mt5);
+  FunctionCallManager:: sPeerMap_[peerID]->addCallStatic(functionID, &mt1, &mt2, &mt3, &mt4, &mt5);
 }
 
@@ -97,75 +97,75 @@
 // MemberCalls
 
-void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID)
+void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID)
 {
-  if(sClientMap_.find(clientID)==sClientMap_.end())
+  if(sPeerMap_.find(peerID)==sPeerMap_.end())
   {
-    FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
-    FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
+    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
+    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
   }
-  FunctionCallManager::sClientMap_[clientID]->addCallMember(functionID, objectID);
+  FunctionCallManager::sPeerMap_[peerID]->addCallMember(functionID, objectID);
 }
-void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1)
+void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1)
 {
-  if(sClientMap_.find(clientID)==sClientMap_.end())
+  if(sPeerMap_.find(peerID)==sPeerMap_.end())
   {
-    FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
-    FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
+    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
+    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
   }
-  FunctionCallManager::sClientMap_[clientID]->addCallMember(functionID, objectID, &mt1);
+  FunctionCallManager::sPeerMap_[peerID]->addCallMember(functionID, objectID, &mt1);
 }
-void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2)
+void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2)
 {
-  if(sClientMap_.find(clientID)==sClientMap_.end())
+  if(sPeerMap_.find(peerID)==sPeerMap_.end())
   {
-    FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
-    FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
+    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
+    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
   }
-  FunctionCallManager::sClientMap_[clientID]->addCallMember(functionID, objectID, &mt1, &mt2);
+  FunctionCallManager::sPeerMap_[peerID]->addCallMember(functionID, objectID, &mt1, &mt2);
 }
-void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3)
+void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3)
 {
-  if(sClientMap_.find(clientID)==sClientMap_.end())
+  if(sPeerMap_.find(peerID)==sPeerMap_.end())
   {
-    FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
-    FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
+    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
+    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
   }
-  FunctionCallManager::sClientMap_[clientID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3);
+  FunctionCallManager::sPeerMap_[peerID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3);
 }
-void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4)
+void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4)
 {
-  if(sClientMap_.find(clientID)==sClientMap_.end())
+  if(sPeerMap_.find(peerID)==sPeerMap_.end())
   {
-    FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
-    FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
+    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
+    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
   }
-  FunctionCallManager::sClientMap_[clientID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3, &mt4);
+  FunctionCallManager::sPeerMap_[peerID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3, &mt4);
 }
-void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5)
+void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5)
 {
-  if(sClientMap_.find(clientID)==sClientMap_.end())
+  if(sPeerMap_.find(peerID)==sPeerMap_.end())
   {
-    FunctionCallManager::sClientMap_[clientID] = new packet::FunctionCalls;
-    FunctionCallManager::sClientMap_[clientID]->setClientID(clientID);
+    FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls;
+    FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID);
   }
-  FunctionCallManager::sClientMap_[clientID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3, &mt4, &mt5);
+  FunctionCallManager::sPeerMap_[peerID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3, &mt4, &mt5);
 }
 
 // Send calls
 
-void FunctionCallManager::sendCalls()
+void FunctionCallManager::sendCalls(orxonox::Host* host)
 {
   std::map<uint32_t, packet::FunctionCalls*>::iterator it;
-  for (it = FunctionCallManager::sClientMap_.begin(); it != FunctionCallManager::sClientMap_.end(); ++it )
+  for (it = FunctionCallManager::sPeerMap_.begin(); it != FunctionCallManager::sPeerMap_.end(); ++it )
   {
-    assert(!FunctionCallManager::sClientMap_.empty());
-    it->second->send();
+    assert(!FunctionCallManager::sPeerMap_.empty());
+    it->second->send(host);
   }
-  FunctionCallManager::sClientMap_.clear();
+  FunctionCallManager::sPeerMap_.clear();
 }
 
-void FunctionCallManager::bufferIncomingFunctionCall(const orxonox::FunctionCall& fctCall, uint32_t minGamestateID, uint32_t clientID)
+void FunctionCallManager::bufferIncomingFunctionCall(const orxonox::FunctionCall& fctCall, uint32_t minGamestateID, uint32_t peerID)
 {
-  FunctionCallManager::sIncomingFunctionCallBuffer_.push_back( std::make_pair(fctCall, std::make_pair(minGamestateID, clientID)));
+  FunctionCallManager::sIncomingFunctionCallBuffer_.push_back( std::make_pair(fctCall, std::make_pair(minGamestateID, peerID)));
 }
 
@@ -175,7 +175,5 @@
   while( it!=FunctionCallManager::sIncomingFunctionCallBuffer_.end() )
   {
-    uint32_t minGamestateID = it->second.first;
-    uint32_t clientID       = it->second.second;
-    if( minGamestateID <= GamestateHandler::getInstance()->getLastProcessedGamestateID(clientID) && it->first.execute() )
+    if( it->first.execute() )
       FunctionCallManager::sIncomingFunctionCallBuffer_.erase(it);
     else
Index: /code/branches/network5/src/libraries/network/FunctionCallManager.h
===================================================================
--- /code/branches/network5/src/libraries/network/FunctionCallManager.h	(revision 7776)
+++ /code/branches/network5/src/libraries/network/FunctionCallManager.h	(revision 7777)
@@ -46,24 +46,24 @@
 {
 public:
-  static void addCallStatic(uint32_t functionID, uint32_t clientID);
-  static void addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1);
-  static void addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2);
-  static void addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3);
-  static void addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4);
-  static void addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5);
+  static void addCallStatic(uint32_t functionID, uint32_t peerID);
+  static void addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1);
+  static void addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2);
+  static void addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3);
+  static void addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4);
+  static void addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5);
 
-  static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID);
-  static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1);
-  static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2);
-  static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3);
-  static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4);
-  static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5);
+  static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID);
+  static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1);
+  static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2);
+  static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3);
+  static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4);
+  static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5);
 
-  static void sendCalls();
+  static void sendCalls(orxonox::Host* host);
   
-  static void bufferIncomingFunctionCall( const FunctionCall& fctCall, uint32_t minGamestateID, uint32_t clientID );
+  static void bufferIncomingFunctionCall( const FunctionCall& fctCall, uint32_t minGamestateID, uint32_t peerID );
   static void processBufferedFunctionCalls();
 
-  static std::map<uint32_t, packet::FunctionCalls*>                           sClientMap_;
+  static std::map<uint32_t, packet::FunctionCalls*>                           sPeerMap_;
   static std::vector<std::pair<FunctionCall,std::pair<uint32_t, uint32_t> > > sIncomingFunctionCallBuffer_;
 protected:
Index: /code/branches/network5/src/libraries/network/GamestateClient.cc
===================================================================
--- /code/branches/network5/src/libraries/network/GamestateClient.cc	(revision 7776)
+++ /code/branches/network5/src/libraries/network/GamestateClient.cc	(revision 7777)
@@ -62,10 +62,10 @@
   }
 
-  bool GamestateClient::ack(unsigned int gamestateID, unsigned int clientID)
+  bool GamestateClient::ackGamestate(unsigned int gamestateID, unsigned int clientID)
   {
     return true;
   }
 
-  bool GamestateClient::add(packet::Gamestate *gs, unsigned int clientID)
+  bool GamestateClient::addGamestate(packet::Gamestate *gs, unsigned int clientID)
   {
     if(tempGamestate_!=NULL)
Index: /code/branches/network5/src/libraries/network/GamestateClient.h
===================================================================
--- /code/branches/network5/src/libraries/network/GamestateClient.h	(revision 7776)
+++ /code/branches/network5/src/libraries/network/GamestateClient.h	(revision 7777)
@@ -57,7 +57,7 @@
     ~GamestateClient();
 
-    virtual bool      add(packet::Gamestate *gs, unsigned int clientID);
-    virtual bool      ack(unsigned int gamestateID, unsigned int clientID);
-    virtual uint32_t  getLastProcessedGamestateID(unsigned int clientID) { return this->lastProcessedGamestateID_; }
+    virtual bool      addGamestate(packet::Gamestate *gs, unsigned int clientID);
+    virtual bool      ackGamestate(unsigned int gamestateID, unsigned int clientID);
+    virtual uint32_t  getLastProcessedGamestateID(unsigned int clientID=0) { return this->lastProcessedGamestateID_; }
     virtual uint32_t  getCurrentGamestateID(){ return this->lastProcessedGamestateID_; }
 
Index: /code/branches/network5/src/libraries/network/GamestateHandler.cc
===================================================================
--- /code/branches/network5/src/libraries/network/GamestateHandler.cc	(revision 7776)
+++ /code/branches/network5/src/libraries/network/GamestateHandler.cc	(revision 7777)
@@ -32,10 +32,8 @@
 namespace orxonox {
 
-GamestateHandler *GamestateHandler::instance_=0;
+// GamestateHandler *GamestateHandler::instance_=0;
 
 GamestateHandler::GamestateHandler()
 {
-  assert(instance_==0);
-  instance_=this;
 }
 
@@ -43,5 +41,4 @@
 GamestateHandler::~GamestateHandler()
 {
-  instance_=0;
 }
 
Index: /code/branches/network5/src/libraries/network/GamestateHandler.h
===================================================================
--- /code/branches/network5/src/libraries/network/GamestateHandler.h	(revision 7776)
+++ /code/branches/network5/src/libraries/network/GamestateHandler.h	(revision 7777)
@@ -39,10 +39,7 @@
     @author Oliver Scheuss
 */
-class _NetworkExport GamestateHandler{
+class _NetworkExport GamestateHandler
+{
   private:
-    virtual bool      add(packet::Gamestate *gs, unsigned int clientID)=0;
-    virtual bool      ack(unsigned int gamestateID, unsigned int clientID)=0;
-
-    static GamestateHandler* instance_;
 
 
@@ -52,8 +49,6 @@
 
   public:
-    static bool     addGamestate(packet::Gamestate *gs, unsigned int clientID){ return instance_->add(gs, clientID); }
-    static bool     ackGamestate(unsigned int gamestateID, unsigned int clientID){ return instance_->ack(gamestateID, clientID); }
-    static GamestateHandler* getInstance(){ assert(instance_); return instance_; }
-    
+    virtual bool      addGamestate(packet::Gamestate* gs, unsigned int clientID) = 0;
+    virtual bool      ackGamestate(unsigned int gamestateID, unsigned int clientID) = 0;
     virtual uint32_t  getLastProcessedGamestateID( unsigned int clientID )=0;
     virtual uint32_t  getCurrentGamestateID()=0;
Index: /code/branches/network5/src/libraries/network/GamestateManager.cc
===================================================================
--- /code/branches/network5/src/libraries/network/GamestateManager.cc	(revision 7776)
+++ /code/branches/network5/src/libraries/network/GamestateManager.cc	(revision 7777)
@@ -43,22 +43,23 @@
 #include <cassert>
 #include <queue>
-#include "util/Clock.h"
 // #include <boost/thread/mutex.hpp>
 
-#include "util/Debug.h"
-#include "core/ThreadPool.h"
-#include "core/command/Executor.h"
-#include "ClientInformation.h"
 #include "packet/Acknowledgement.h"
 #include "packet/Gamestate.h"
 #include "synchronisable/NetworkCallbackManager.h"
-#include "TrafficControl.h"
+
+#include "core/ThreadPool.h"
+#include "core/command/Executor.h"
+#include "core/GameMode.h"
+#include "util/Debug.h"
+#include "util/Clock.h"
+// #include "TrafficControl.h"
 
 namespace orxonox
 {
   GamestateManager::GamestateManager() :
-  reference(0), id_(0)
-  {
-    trafficControl_ = new TrafficControl();
+  currentGamestate_(0), id_(0)
+  {
+//     trafficControl_ = new TrafficControl();
 //     threadMutex_ = new boost::mutex();
 //     threadPool_ = new ThreadPool();
@@ -67,16 +68,16 @@
   GamestateManager::~GamestateManager()
   {
-    if( this->reference )
-        delete this->reference;std::map<unsigned int, packet::Gamestate*>::iterator it;
+    if( this->currentGamestate_ )
+        delete this->currentGamestate_;std::map<unsigned int, packet::Gamestate*>::iterator it;
     for( it = gamestateQueue.begin(); it != gamestateQueue.end(); ++it )
       delete it->second;
-    std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> >::iterator it1;
-    std::map<unsigned int, packet::Gamestate*>::iterator it2;
-    for( it1 = gamestateMap_.begin(); it1 != gamestateMap_.end(); ++it1 )
-    {
-      for( it2 = it1->second.begin(); it2 != it1->second.end(); ++it2 )
-        delete it2->second;
-    }
-    this->trafficControl_->destroy();
+    std::map<uint32_t, peerInfo>::iterator peerIt;
+    std::map<uint32_t, packet::Gamestate*>::iterator gamestateIt;
+    for( peerIt = peerMap_.begin(); peerIt != peerMap_.end(); ++peerIt )
+    {
+      for( gamestateIt = peerIt->second.gamestates.begin(); gamestateIt != peerIt->second.gamestates.end(); ++gamestateIt )
+        delete gamestateIt->second;
+    }
+//     this->trafficControl_->destroy();
 //     delete this->threadMutex_;
 //     delete this->threadPool_;
@@ -88,5 +89,6 @@
   }
 
-  bool GamestateManager::add(packet::Gamestate *gs, unsigned int clientID){
+  bool GamestateManager::addGamestate(packet::Gamestate *gs, unsigned int clientID)
+  {
     assert(gs);
     std::map<unsigned int, packet::Gamestate*>::iterator it = gamestateQueue.find(clientID);
@@ -99,5 +101,6 @@
   }
 
-  bool GamestateManager::processGamestates(){
+  bool GamestateManager::processGamestates()
+  {
     if( this->gamestateQueue.empty() )
         return true;
@@ -118,68 +121,71 @@
 
   bool GamestateManager::getSnapshot(){
-    if ( reference != 0 )
-      delete reference;
-    reference = new packet::Gamestate();
-    if(!reference->collectData(++id_, 0x1)){ //we have no data to send
-      delete reference;
-      reference=0;
+    if ( currentGamestate_ != 0 )
+      delete currentGamestate_;
+    currentGamestate_ = new packet::Gamestate();
+    uint8_t gsMode;
+    if( GameMode::isMaster() )
+      gsMode = packet::GAMESTATE_MODE_SERVER;
+    else
+      gsMode = packet::GAMESTATE_MODE_CLIENT;
+    uint32_t newID;
+    if( GameMode::isMaster() )
+      newID = ++id_;
+    else
+      newID = peerMap_[NETWORK_PEER_ID_SERVER].lastProcessedGamestateID;
+    
+    if(!currentGamestate_->collectData(newID, gsMode)){ //we have no data to send
+      delete currentGamestate_;
+      currentGamestate_=0;
     }
     return true;
   }
 
-  void GamestateManager::sendGamestates()
-  {
-    ClientInformation *temp = ClientInformation::getBegin();
-    std::queue<packet::Gamestate*> clientGamestates;
-    while(temp != NULL){
-      if( !(temp->getSynched()) ){
+  std::vector<packet::Gamestate*> GamestateManager::getGamestates()
+  {
+    if(!currentGamestate_)
+      return std::vector<packet::Gamestate*>();
+    std::vector<packet::Gamestate*> peerGamestates;
+    
+    std::map<uint32_t, peerInfo>::iterator peerIt;
+    for( peerIt=peerMap_.begin(); peerIt!=peerMap_.end(); ++peerIt )
+    {
+      if( !peerIt->second.isSynched )
+      {
         COUT(5) << "Server: not sending gamestate" << std::endl;
-        temp=temp->next();
-        if(!temp)
-          break;
         continue;
       }
-      COUT(4) << "client id: " << temp->getID() << " RTT: " << temp->getRTT() << " loss: " << temp->getPacketLoss() << std::endl;
+      COUT(4) << "client id: " << peerIt->first << std::endl;
       COUT(5) << "Server: doing gamestate gamestate preparation" << std::endl;
-      int cid = temp->getID(); //get client id
-
-      unsigned int gID = temp->getGamestateID();
-      if(!reference)
-        return;
-
-      packet::Gamestate *client=0;
-      if(gID != GAMESTATEID_INITIAL){
-        assert(gamestateMap_.find(cid)!=gamestateMap_.end());
-        std::map<unsigned int, packet::Gamestate*>::iterator it = gamestateMap_[cid].find(gID);
-        if(it!=gamestateMap_[cid].end())
-        {
-          client = it->second;
-        }
-      }
-
-      clientGamestates.push(0);
-      finishGamestate( cid, clientGamestates.back(), client, reference );
+      int peerID = peerIt->first; //get client id
+
+      unsigned int lastAckedGamestateID = peerIt->second.lastAckedGamestateID;
+
+      packet::Gamestate* baseGamestate=0;
+      if(lastAckedGamestateID != GAMESTATEID_INITIAL)
+      {
+        assert(peerMap_.find(peerID)!=peerMap_.end());
+        std::map<uint32_t, packet::Gamestate*>::iterator it = peerMap_[peerID].gamestates.find(lastAckedGamestateID);
+        assert(it!=peerMap_[peerID].gamestates.end());
+        baseGamestate = it->second;
+      }
+
+      peerGamestates.push_back(0);  // insert an empty gamestate* to change
+      finishGamestate( peerID, peerGamestates.back(), baseGamestate, currentGamestate_ );
       //FunctorMember<GamestateManager>* functor =
 //       ExecutorMember<GamestateManager>* executor = createExecutor( createFunctor(&GamestateManager::finishGamestate, this) );
-//       executor->setDefaultValues( cid, &clientGamestates.back(), client, reference );
+//       executor->setDefaultValues( cid, &clientGamestates.back(), client, currentGamestate_ );
 //       (*static_cast<Executor*>(executor))();
 //       this->threadPool_->passFunction( executor, true );
-//       (*functor)( cid, &(clientGamestates.back()), client, reference );
-
-      temp = temp->next();
+//       (*functor)( cid, &(clientGamestates.back()), client, currentGamestate_ );
     }
 
 //     threadPool_->synchronise();
 
-    while( !clientGamestates.empty() )
-    {
-      if(clientGamestates.front())
-        clientGamestates.front()->send();
-      clientGamestates.pop();
-    }
-  }
-
-
-  void GamestateManager::finishGamestate( unsigned int clientID, packet::Gamestate*& destgamestate, packet::Gamestate* base, packet::Gamestate* gamestate ) {
+    return peerGamestates;
+  }
+
+
+  void GamestateManager::finishGamestate( unsigned int peerID, packet::Gamestate*& destgamestate, packet::Gamestate* base, packet::Gamestate* gamestate ) {
     //why are we searching the same client's gamestate id as we searched in
     //Server::sendGameState?
@@ -194,8 +200,8 @@
 //     gs->collectData( id_, 0x1 );
 //     this->threadMutex_->lock();
-    gamestateMap_[clientID][gamestate->getID()]=gs;
+    peerMap_[peerID].gamestates[gamestate->getID()]=gs;
 //     this->threadMutex_->unlock();
-      Clock clock;
-      clock.capture();
+    Clock clock;
+    clock.capture();
 
     if(base)
@@ -218,6 +224,6 @@
 //     bool b = gs->compressData();
 //     assert(b);
-      clock.capture();
-      COUT(4) << "diff and compress time: " << clock.getDeltaTime() << endl;
+    clock.capture();
+    COUT(4) << "diff and compress time: " << clock.getDeltaTime() << endl;
 //     COUT(5) << "sending gamestate with id " << gs->getID();
 //     if(gamestate->isDiffed())
@@ -225,59 +231,100 @@
 //     else
 //       COUT(5) << endl;
-    gs->setClientID(clientID);
+    gs->setPeerID(peerID);
     destgamestate = gs;
   }
 
 
-  bool GamestateManager::ack(unsigned int gamestateID, unsigned int clientID) {
-    ClientInformation *temp = ClientInformation::findClient(clientID);
-    assert(temp);
-    unsigned int curid = temp->getGamestateID();
+  bool GamestateManager::ackGamestate(unsigned int gamestateID, unsigned int peerID) {
+//     ClientInformation *temp = ClientInformation::findClient(peerID);
+//     assert(temp);
+    std::map<uint32_t, peerInfo>::iterator it = this->peerMap_.find(peerID);
+    assert(it!=this->peerMap_.end());
+    unsigned int curid = it->second.lastAckedGamestateID;
 
     if(gamestateID == ACKID_NACK){
-      temp->setGamestateID(GAMESTATEID_INITIAL);
+      it->second.lastAckedGamestateID = GAMESTATEID_INITIAL;
+//       temp->setGamestateID(GAMESTATEID_INITIAL);
       // now delete all saved gamestates for this client
-      std::map<unsigned int, packet::Gamestate*>::iterator it;
-      for(it = gamestateMap_[clientID].begin(); it!=gamestateMap_[clientID].end(); ){
-        delete it->second;
-
-        gamestateMap_[clientID].erase(it++);
-      }
+      std::map<uint32_t, packet::Gamestate*>::iterator it2;
+      for(it2 = it->second.gamestates.begin(); it2!=it->second.gamestates.end(); ++it2 ){
+        delete it2->second;
+      }
+      it->second.gamestates.clear();
       return true;
     }
 
     assert(curid==GAMESTATEID_INITIAL || curid<gamestateID);
-    COUT(5) << "acking gamestate " << gamestateID << " for clientid: " << clientID << " curid: " << curid << std::endl;
-    std::map<unsigned int, packet::Gamestate*>::iterator it;
-    for(it = gamestateMap_[clientID].begin(); it!=gamestateMap_[clientID].end() && it->first<gamestateID; ){
-      delete it->second;
-      gamestateMap_[clientID].erase(it++);
-    }
-    temp->setGamestateID(gamestateID);
-    TrafficControl::processAck(clientID, gamestateID);
+    COUT(5) << "acking gamestate " << gamestateID << " for peerID: " << peerID << " curid: " << curid << std::endl;
+    std::map<uint32_t, packet::Gamestate*>::iterator it2;
+    for( it2=it->second.gamestates.begin(); it2!=it->second.gamestates.end(); )
+    {
+      if( it2->second->getID() < gamestateID )
+      {
+        delete it2->second;
+        it->second.gamestates.erase(it2++);
+      }
+      else
+        ++it2;
+    }
+    
+//     std::map<unsigned int, packet::Gamestate*>::iterator it;
+//     for(it = gamestateMap_[peerID].begin(); it!=gamestateMap_[peerID].end() && it->first<gamestateID; ){
+//       delete it->second;
+//       gamestateMap_[peerID].erase(it++);
+//     }
+    it->second.lastAckedGamestateID = gamestateID;
+//     temp->setGamestateID(gamestateID);
+//     TrafficControl::processAck(peerID, gamestateID);
     return true;
   }
   
-  uint32_t GamestateManager::getLastProcessedGamestateID(unsigned int clientID)
-  {
-    assert( this->lastProcessedGamestateID_.find(clientID) != this->lastProcessedGamestateID_.end() );
-    if( this->lastProcessedGamestateID_.find(clientID) != this->lastProcessedGamestateID_.end() )
-      return this->lastProcessedGamestateID_[clientID];
+  uint32_t GamestateManager::getLastProcessedGamestateID(unsigned int peerID)
+  {
+    assert( this->peerMap_.find(peerID)!=this->peerMap_.end() );
+    if( this->peerMap_.find(peerID) != this->peerMap_.end() )
+      return this->peerMap_[peerID].lastProcessedGamestateID;
     else
       return GAMESTATEID_INITIAL;
   }
-
-  void GamestateManager::removeClient(ClientInformation* client){
-    assert(client);
-    std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> >::iterator clientMap = gamestateMap_.find(client->getID());
-    // first delete all remained gamestates
-    std::map<unsigned int, packet::Gamestate*>::iterator it;
-    for(it=clientMap->second.begin(); it!=clientMap->second.end(); it++)
-      delete it->second;
-    // now delete the clients gamestatemap
-    gamestateMap_.erase(clientMap);
-  }
-
-  bool GamestateManager::processGamestate(packet::Gamestate *gs){
+  
+  
+  void GamestateManager::addPeer(uint32_t peerID)
+  {
+    assert(peerMap_.find(peerID)==peerMap_.end());
+    peerMap_[peerID].peerID = peerID;
+    peerMap_[peerID].lastProcessedGamestateID = GAMESTATEID_INITIAL;
+    peerMap_[peerID].lastAckedGamestateID = GAMESTATEID_INITIAL;
+    if( GameMode::isMaster() )
+      peerMap_[peerID].isSynched = false;
+    else
+      peerMap_[peerID].isSynched = true;
+  }
+
+  void GamestateManager::removePeer(uint32_t peerID)
+  {
+    assert(peerMap_.find(peerID)!=peerMap_.end());
+    std::map<uint32_t, packet::Gamestate*>::iterator peerIt;
+    for( peerIt = peerMap_[peerID].gamestates.begin(); peerIt!=peerMap_[peerID].gamestates.end(); ++peerIt )
+    {
+      delete peerIt->second;
+    }
+    peerMap_.erase(peerMap_.find(peerID));
+  }
+
+
+//   void GamestateManager::removeClient(ClientInformation* client){
+//     assert(client);
+//     std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> >::iterator clientMap = gamestateMap_.find(client->getID());
+//     // first delete all remained gamestates
+//     std::map<unsigned int, packet::Gamestate*>::iterator it;
+//     for(it=clientMap->second.begin(); it!=clientMap->second.end(); it++)
+//       delete it->second;
+//     // now delete the clients gamestatemap
+//     gamestateMap_.erase(clientMap);
+//   }
+
+  bool GamestateManager::processGamestate(packet::Gamestate *gs)
+  {
     if(gs->isCompressed())
     {
@@ -286,7 +333,12 @@
     }
     assert(!gs->isDiffed());
-    if( gs->spreadData(0x1) )
-    {
-      this->lastProcessedGamestateID_[gs->getClientID()] = gs->getID();
+    uint8_t gsMode;
+    if( GameMode::isMaster() )
+      gsMode = packet::GAMESTATE_MODE_SERVER;
+    else
+      gsMode = packet::GAMESTATE_MODE_CLIENT;
+    if( gs->spreadData(gsMode) )
+    {
+      this->peerMap_[gs->getPeerID()].lastProcessedGamestateID = gs->getID();
       return true;
     }
Index: /code/branches/network5/src/libraries/network/GamestateManager.h
===================================================================
--- /code/branches/network5/src/libraries/network/GamestateManager.h	(revision 7776)
+++ /code/branches/network5/src/libraries/network/GamestateManager.h	(revision 7777)
@@ -47,4 +47,5 @@
 #include "core/CorePrereqs.h"
 #include "packet/Gamestate.h"
+#include <boost/concept_check.hpp>
 
 namespace orxonox
@@ -67,31 +68,46 @@
   * @author Oliver Scheuss
   */
-  class _NetworkExport GamestateManager: public GamestateHandler{
+  class _NetworkExport GamestateManager: public GamestateHandler
+  {
+    struct peerInfo
+    {
+      uint32_t  peerID;
+      uint32_t  lastProcessedGamestateID;
+      uint32_t  lastAckedGamestateID;
+      bool      isSynched;
+      std::map< uint32_t, packet::Gamestate* > gamestates;
+    };
+    
   public:
+    
     GamestateManager();
     ~GamestateManager();
 
-    virtual bool      add(packet::Gamestate *gs, unsigned int clientID);
-    virtual bool      ack(unsigned int gamestateID, unsigned int clientID);
-    virtual uint32_t  getLastProcessedGamestateID( unsigned int clientID );
-    virtual uint32_t  getCurrentGamestateID(){ return reference->getID(); }
+    virtual bool      addGamestate(packet::Gamestate *gs, unsigned int peerID);
+    virtual bool      ackGamestate(unsigned int gamestateID, unsigned int peerID);
+    virtual uint32_t  getLastProcessedGamestateID( unsigned int peerID );
+    virtual uint32_t  getCurrentGamestateID(){ return currentGamestate_->getID(); }
     
     bool processGamestates();
     bool update();
-    void sendGamestates();
-//     packet::Gamestate *popGameState(unsigned int clientID);
-    void finishGamestate( unsigned int clientID, packet::Gamestate*& destgamestate, packet::Gamestate* base, packet::Gamestate* gamestate );
+    std::vector<packet::Gamestate*> getGamestates();
+    void finishGamestate( unsigned int peerID, packet::Gamestate*& destgamestate, packet::Gamestate* base, packet::Gamestate* gamestate );
 
     bool getSnapshot();
 
-    void removeClient(ClientInformation *client);
+    void addPeer( uint32_t peerID );
+    void setSynched( uint32_t peerID )
+      { assert(peerMap_.find(peerID)!=peerMap_.end()); peerMap_[peerID].isSynched = true; }
+    void removePeer( uint32_t peerID );
+//     void removeClient(ClientInformation *client);
   private:
     bool processGamestate(packet::Gamestate *gs);
 
-    std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> > gamestateMap_;
+//     std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> > gamestateMap_;
     std::map<unsigned int, packet::Gamestate*> gamestateQueue;
-    std::map<unsigned int, uint32_t> lastProcessedGamestateID_;
-    packet::Gamestate *reference;
-    TrafficControl *trafficControl_;
+//     std::map<unsigned int, uint32_t> lastProcessedGamestateID_;
+    std::map<uint32_t, peerInfo> peerMap_;
+    packet::Gamestate* currentGamestate_;
+//     TrafficControl *trafficControl_;
     unsigned int id_;
 //     boost::mutex* threadMutex_;
Index: /code/branches/network5/src/libraries/network/Host.cc
===================================================================
--- /code/branches/network5/src/libraries/network/Host.cc	(revision 7776)
+++ /code/branches/network5/src/libraries/network/Host.cc	(revision 7777)
@@ -45,5 +45,5 @@
   // Host*               Host::instance_=0;
   uint32_t            Host::clientID_s=0;
-  uint32_t            Host::shipID_s=-1;
+//   uint32_t            Host::shipID_s=-1;
   std::vector<Host*>  Host::instances_s;
 
Index: /code/branches/network5/src/libraries/network/Host.h
===================================================================
--- /code/branches/network5/src/libraries/network/Host.h	(revision 7776)
+++ /code/branches/network5/src/libraries/network/Host.h	(revision 7777)
@@ -31,4 +31,5 @@
 
 #include "NetworkPrereqs.h"
+#include "GamestateManager.h"
 #include "core/CorePrereqs.h"
 
@@ -49,5 +50,6 @@
 *       @author Oliver Scheuss
 */
-class _NetworkExport Host{
+class _NetworkExport Host: public GamestateManager
+{
   private:
     //TODO add these functions or adequate
@@ -75,7 +77,5 @@
 //     static bool receiveChat(packet::Chat *message, unsigned int clientID);
     static unsigned int getPlayerID(){ return clientID_s; }
-    static unsigned int getShipID(){return shipID_s;}
     static void setClientID(unsigned int id){ clientID_s = id; }
-    static void setShipID(unsigned int id){ shipID_s = id; }
     static bool isServer();
     static void Chat(const std::string& message);
@@ -86,5 +86,4 @@
   private:
     static uint32_t clientID_s;
-    static uint32_t shipID_s;
     static std::vector<Host*> instances_s;
     bool bIsActive_;
Index: /code/branches/network5/src/libraries/network/Server.cc
===================================================================
--- /code/branches/network5/src/libraries/network/Server.cc	(revision 7776)
+++ /code/branches/network5/src/libraries/network/Server.cc	(revision 7777)
@@ -162,6 +162,6 @@
     while(temp){
       chat = new packet::Chat(message, playerID);
-      chat->setClientID(temp->getID());
-      if(!chat->send())
+      chat->setPeerID(temp->getID());
+      if(!chat->send( static_cast<Host*>(this) ))
         COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl;
       temp = temp->next();
@@ -220,5 +220,5 @@
 
       // send function calls to clients
-      FunctionCallManager::sendCalls();
+      FunctionCallManager::sendCalls( static_cast<Host*>(this) );
 
       //this steers our network frequency
@@ -271,57 +271,27 @@
       return;
     GamestateManager::update();
-    COUT(5) << "Server: one gamestate update complete, goig to sendGameState" << std::endl;
+//     COUT(5) << "Server: one gamestate update complete, goig to sendGameState" << std::endl;
     //std::cout << "updated gamestate, sending it" << std::endl;
     //if(clients->getGamestateID()!=GAMESTATEID_INITIAL)
-    sendGameState();
+    sendGameStates();
     sendObjectDeletes();
-    COUT(5) << "Server: one sendGameState turn complete, repeat in next tick" << std::endl;
+//     COUT(5) << "Server: one sendGameState turn complete, repeat in next tick" << std::endl;
     //std::cout << "sent gamestate" << std::endl;
   }
 
-  bool Server::processPacket( ENetPacket *packet, ENetPeer *peer ){
-    packet::Packet *p = packet::Packet::createPacket(packet, peer);
-    return p->process();
-  }
-
-  /**
-  * sends the gamestate
-  */
-  bool Server::sendGameState()
-  {
-//     COUT(5) << "Server: starting function sendGameState" << std::endl;
-//     ClientInformation *temp = ClientInformation::getBegin();
-//     bool added=false;
-//     while(temp != NULL){
-//       if( !(temp->getSynched()) ){
-//         COUT(5) << "Server: not sending gamestate" << std::endl;
-//         temp=temp->next();
-//         if(!temp)
-//           break;
-//         continue;
-//       }
-//       COUT(4) << "client id: " << temp->getID() << " RTT: " << temp->getRTT() << " loss: " << temp->getPacketLoss() << std::endl;
-//       COUT(5) << "Server: doing gamestate gamestate preparation" << std::endl;
-//       int cid = temp->getID(); //get client id
-//       packet::Gamestate *gs = GamestateManager::popGameState(cid);
-//       if(gs==NULL){
-//         COUT(2) << "Server: could not generate gamestate (NULL from compress)" << std::endl;
-//         temp = temp->next();
-//         continue;
-//       }
-//       //std::cout << "adding gamestate" << std::endl;
-//       gs->setClientID(cid);
-//       if ( !gs->send() ){
-//         COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp->getFailures() << std::endl;
-//         temp->addFailure();
-//       }else
-//         temp->resetFailures();
-//       added=true;
-//       temp=temp->next();
-//       // gs gets automatically deleted by enet callback
-//     }
-    GamestateManager::sendGamestates();
+  /**
+  * sends the current gamestate to all peers
+  */
+  bool Server::sendGameStates()
+  {
+    std::vector<packet::Gamestate*> gamestates = GamestateManager::getGamestates();
+    std::vector<packet::Gamestate*>::iterator it;
+    for( it = gamestates.begin(); it != gamestates.end(); ++it )
+    {
+      (*it)->send(static_cast<Host*>(this));
+    }
     return true;
   }
+
 
   bool Server::sendObjectDeletes()
@@ -348,7 +318,7 @@
       packet::DeleteObjects *cd = new packet::DeleteObjects(*del);
       assert(cd);
-      cd->setClientID(cid);
-      if ( !cd->send() )
-        COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp->getFailures() << std::endl;
+      cd->setPeerID(cid);
+      if ( !cd->send( static_cast<Host*>(this) ) )
+        COUT(3) << "Server: packet with client id (cid): " << cid << " not sended" << std::endl;
       temp=temp->next();
       // gs gets automatically deleted by enet callback
@@ -374,4 +344,5 @@
     // inform all the listeners
     ClientConnectionListener::broadcastClientConnected(newid);
+    GamestateManager::addPeer(newid);
 
     ++newid;
@@ -394,4 +365,18 @@
     }
   }
+  
+  void Server::processPacket(packet::Packet* packet)
+  {
+    if( packet->isReliable() )
+    {
+      if( this->getLastProcessedGamestateID(packet->getPeerID()) >= packet->getRequiredGamestateID() )
+        packet->process(static_cast<Host*>(this));
+      else
+        this->packetQueue_.push_back(packet);
+    }
+    else
+      packet->process(static_cast<Host*>(this));
+  }
+
 
   bool Server::createClient(int clientID)
@@ -403,5 +388,5 @@
       return false;
     }
-    COUT(5) << "Con.Man: creating client id: " << temp->getID() << std::endl;
+    COUT(4) << "Con.Man: creating client id: " << temp->getID() << std::endl;
 
     // synchronise class ids
@@ -410,22 +395,25 @@
     // now synchronise functionIDs
     packet::FunctionIDs *fIDs = new packet::FunctionIDs();
-    fIDs->setClientID(clientID);
-    bool b = fIDs->send();
+    fIDs->setPeerID(clientID);
+    bool b = fIDs->send( static_cast<Host*>(this) );
     assert(b);
 
     temp->setSynched(true);
+    GamestateManager::setSynched(clientID);
+    
     COUT(4) << "sending welcome" << std::endl;
     packet::Welcome *w = new packet::Welcome(temp->getID(), temp->getShipID());
-    w->setClientID(temp->getID());
-    b = w->send();
+    w->setPeerID(temp->getID());
+    b = w->send( static_cast<Host*>(this) );
     assert(b);
     packet::Gamestate *g = new packet::Gamestate();
-    g->setClientID(temp->getID());
-    b = g->collectData(0,0x1);
+    g->setPeerID(temp->getID());
+    b = g->collectData(0,packet::GAMESTATE_MODE_SERVER);
+    assert(b);
     if(!b)
       return false; //no data for the client
 //     b = g->compressData();
 //     assert(b);
-    b = g->send();
+    b = g->send( static_cast<Host*>(this) );
     assert(b);
     return true;
@@ -435,5 +423,5 @@
   {
     ServerConnection::disconnectClient( client );
-    GamestateManager::removeClient(client);
+    GamestateManager::removePeer(client->getID());
     // inform all the listeners
     // ClientConnectionListener::broadcastClientDisconnected(client->getID()); // this is done in ClientInformation now
@@ -457,6 +445,6 @@
     {
       chat = new packet::Chat(message, clientID);
-      chat->setClientID(temp->getID());
-      if(!chat->send())
+      chat->setPeerID(temp->getID());
+      if(!chat->send( static_cast<Host*>(this) ))
         COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl;
       temp = temp->next();
@@ -473,6 +461,6 @@
     int failures=0;
     packet::ClassID *classid = new packet::ClassID();
-    classid->setClientID(clientID);
-    while(!classid->send() && failures < 10){
+    classid->setPeerID(clientID);
+    while(!classid->send( static_cast<Host*>(this) ) && failures < 10){
       failures++;
     }
Index: /code/branches/network5/src/libraries/network/Server.h
===================================================================
--- /code/branches/network5/src/libraries/network/Server.h	(revision 7776)
+++ /code/branches/network5/src/libraries/network/Server.h	(revision 7777)
@@ -32,8 +32,10 @@
 #include "NetworkPrereqs.h"
 
+#include <deque>
+
 #include "util/UtilPrereqs.h"
 #include "core/CorePrereqs.h"
 #include "Host.h"
-#include "GamestateManager.h"
+// #include "GamestateManager.h"
 #include "ServerConnection.h"
 #include "LANDiscoverable.h"
@@ -49,5 +51,5 @@
   * It implements all functions necessary for a Server
   */
-  class _NetworkExport Server : public Host, public ServerConnection, public GamestateManager, public LANDiscoverable{
+  class _NetworkExport Server : public Host, public ServerConnection, public LANDiscoverable{
   public:
     Server();
@@ -73,14 +75,13 @@
   private:
     virtual bool isServer_(){return true;}
-    unsigned int shipID(){return 0;}
     unsigned int playerID(){return 0;}
 
     void addPeer(ENetEvent *event);
     void removePeer(ENetEvent *event);
+    void processPacket(packet::Packet* packet);
 
     bool createClient(int clientID);
     void disconnectClient( ClientInformation *client);
-    bool processPacket( ENetPacket *packet, ENetPeer *peer );
-    bool sendGameState();
+    bool sendGameStates();
     bool sendObjectDeletes();
     virtual bool chat(const std::string& message);
@@ -91,4 +92,5 @@
     float timeSinceLastUpdate_;
     MasterServerComm msc;
+    std::deque<packet::Packet*> packetQueue_;
   };
 
Index: /code/branches/network5/src/libraries/network/packet/Acknowledgement.cc
===================================================================
--- /code/branches/network5/src/libraries/network/packet/Acknowledgement.cc	(revision 7776)
+++ /code/branches/network5/src/libraries/network/packet/Acknowledgement.cc	(revision 7777)
@@ -31,4 +31,5 @@
 #include "util/Debug.h"
 #include "network/GamestateHandler.h"
+#include "network/Host.h"
 
 namespace orxonox {
@@ -39,5 +40,5 @@
 #define _ACKID              _PACKETID + sizeof(packet::Type::Value)
 
-Acknowledgement::Acknowledgement( unsigned int id, unsigned int clientID )
+Acknowledgement::Acknowledgement( unsigned int id, unsigned int peerID )
  : Packet()
 {
@@ -46,9 +47,9 @@
   *(Type::Value *)(data_ + _PACKETID ) = Type::Acknowledgement;
   *(uint32_t *)(data_ + _ACKID ) = id;
-  clientID_=clientID;
+  peerID_=peerID;
 }
 
-Acknowledgement::Acknowledgement( uint8_t *data, unsigned int clientID )
-  : Packet(data, clientID)
+Acknowledgement::Acknowledgement( uint8_t *data, unsigned int peerID )
+  : Packet(data, peerID)
 {
 }
@@ -62,7 +63,7 @@
 }
 
-bool Acknowledgement::process(){
+bool Acknowledgement::process(orxonox::Host* host){
   COUT(5) << "processing ACK with ID: " << getAckID() << endl;
-  bool b = GamestateHandler::ackGamestate(getAckID(), clientID_);
+  bool b = host->ackGamestate(getAckID(), peerID_);
   delete this;
   return b;
Index: /code/branches/network5/src/libraries/network/packet/Acknowledgement.h
===================================================================
--- /code/branches/network5/src/libraries/network/packet/Acknowledgement.h	(revision 7776)
+++ /code/branches/network5/src/libraries/network/packet/Acknowledgement.h	(revision 7777)
@@ -42,10 +42,10 @@
 {
 public:
-  Acknowledgement( unsigned int id, unsigned int clientID );
-  Acknowledgement( uint8_t* data, unsigned int clientID );
+  Acknowledgement( unsigned int id, unsigned int peerID );
+  Acknowledgement( uint8_t* data, unsigned int peerID );
   ~Acknowledgement();
 
   inline unsigned int getSize() const;
-  bool process();
+  virtual bool process(orxonox::Host* host);
 
   unsigned int getAckID();
Index: /code/branches/network5/src/libraries/network/packet/Chat.cc
===================================================================
--- /code/branches/network5/src/libraries/network/packet/Chat.cc	(revision 7776)
+++ /code/branches/network5/src/libraries/network/packet/Chat.cc	(revision 7777)
@@ -80,6 +80,6 @@
 }
 
-bool Chat::process(){
-  bool b = Host::incomingChat(std::string((const char*)data_+_MESSAGE), *(uint32_t *)(data_+_PLAYERID));
+bool Chat::process(orxonox::Host* host){
+  bool b = host->incomingChat(std::string((const char*)data_+_MESSAGE), *(uint32_t *)(data_+_PLAYERID));
   delete this;
   return b;
Index: /code/branches/network5/src/libraries/network/packet/Chat.h
===================================================================
--- /code/branches/network5/src/libraries/network/packet/Chat.h	(revision 7776)
+++ /code/branches/network5/src/libraries/network/packet/Chat.h	(revision 7777)
@@ -52,5 +52,5 @@
 
   /* process chat message packet and remove it afterwards */
-  bool process();
+  virtual bool process(orxonox::Host* host);
 
   /* Get the length of the message (not the full size of the packet) */
Index: /code/branches/network5/src/libraries/network/packet/ClassID.cc
===================================================================
--- /code/branches/network5/src/libraries/network/packet/ClassID.cc	(revision 7776)
+++ /code/branches/network5/src/libraries/network/packet/ClassID.cc	(revision 7777)
@@ -120,5 +120,5 @@
 
 
-bool ClassID::process(){
+bool ClassID::process(orxonox::Host* host){
   int nrOfClasses;
   uint8_t *temp = data_+sizeof(uint32_t); //skip the packetid
Index: /code/branches/network5/src/libraries/network/packet/ClassID.h
===================================================================
--- /code/branches/network5/src/libraries/network/packet/ClassID.h	(revision 7776)
+++ /code/branches/network5/src/libraries/network/packet/ClassID.h	(revision 7777)
@@ -48,5 +48,5 @@
 
   uint32_t getSize() const;
-  bool process();
+  virtual bool process(orxonox::Host* host);
 
 private:
Index: /code/branches/network5/src/libraries/network/packet/DeleteObjects.cc
===================================================================
--- /code/branches/network5/src/libraries/network/packet/DeleteObjects.cc	(revision 7776)
+++ /code/branches/network5/src/libraries/network/packet/DeleteObjects.cc	(revision 7777)
@@ -57,5 +57,6 @@
 }
 
-bool DeleteObjects::fetchIDs(){
+bool DeleteObjects::fetchIDs()
+{
   unsigned int number = Synchronisable::getNumberOfDeletedObject();
   if(number==0)
@@ -79,11 +80,14 @@
 }
 
-unsigned int DeleteObjects::getSize() const{
+unsigned int DeleteObjects::getSize() const
+{
   assert(data_);
   return _OBJECTIDS + *(uint32_t*)(data_+_QUANTITY)*sizeof(uint32_t);
 }
 
-bool DeleteObjects::process(){
-  for(unsigned int i=0; i<*(unsigned int *)(data_+_QUANTITY); i++){
+bool DeleteObjects::process(orxonox::Host* host)
+{
+  for(unsigned int i=0; i<*(unsigned int *)(data_+_QUANTITY); i++)
+  {
     COUT(4) << "deleting object with id: " << *(uint32_t*)(data_+_OBJECTIDS+i*sizeof(uint32_t)) << std::endl;
     Synchronisable::deleteObject( *(uint32_t*)(data_+_OBJECTIDS+i*sizeof(uint32_t)) );
Index: /code/branches/network5/src/libraries/network/packet/DeleteObjects.h
===================================================================
--- /code/branches/network5/src/libraries/network/packet/DeleteObjects.h	(revision 7776)
+++ /code/branches/network5/src/libraries/network/packet/DeleteObjects.h	(revision 7777)
@@ -32,6 +32,8 @@
 #include "Packet.h"
 
-namespace orxonox {
-namespace packet {
+namespace orxonox
+{
+namespace packet
+{
 /**
     @author
@@ -47,5 +49,5 @@
 
   inline unsigned int getSize() const;
-  bool process();
+  virtual bool process(orxonox::Host* host);
 
 private:
Index: /code/branches/network5/src/libraries/network/packet/FunctionCalls.cc
===================================================================
--- /code/branches/network5/src/libraries/network/packet/FunctionCalls.cc	(revision 7776)
+++ /code/branches/network5/src/libraries/network/packet/FunctionCalls.cc	(revision 7777)
@@ -58,5 +58,6 @@
 
 
-bool FunctionCalls::process(){
+bool FunctionCalls::process(orxonox::Host* host)
+{
   assert(isDataENetAllocated());
   
@@ -70,7 +71,7 @@
     FunctionCall fctCall;
     fctCall.loadData(temp);
-    if( this->minGamestateID_ > GamestateHandler::getInstance()->getLastProcessedGamestateID(this->getClientID()) || !fctCall.execute() )
+    if( this->minGamestateID_ > host->getLastProcessedGamestateID(this->getPeerID()) || !fctCall.execute() )
     {
-      FunctionCallManager::bufferIncomingFunctionCall( fctCall, minGamestateID_, this->getClientID() );
+      FunctionCallManager::bufferIncomingFunctionCall( fctCall, minGamestateID_, this->getPeerID() );
     }
   }
@@ -80,5 +81,6 @@
 }
 
-void FunctionCalls::addCallStatic( uint32_t networkID, const MultiType* mt1, const MultiType* mt2, const MultiType* mt3, const MultiType* mt4, const MultiType* mt5){
+void FunctionCalls::addCallStatic( uint32_t networkID, const MultiType* mt1, const MultiType* mt2, const MultiType* mt3, const MultiType* mt4, const MultiType* mt5)
+{
   assert(!isDataENetAllocated());
   
@@ -88,5 +90,6 @@
 }
 
-void FunctionCalls::addCallMember( uint32_t networkID, uint32_t objectID, const MultiType* mt1, const MultiType* mt2, const MultiType* mt3, const MultiType* mt4, const MultiType* mt5){
+void FunctionCalls::addCallMember( uint32_t networkID, uint32_t objectID, const MultiType* mt1, const MultiType* mt2, const MultiType* mt3, const MultiType* mt4, const MultiType* mt5)
+{
   assert(!isDataENetAllocated());
   
@@ -96,7 +99,7 @@
 }
 
-bool FunctionCalls::send()
+bool FunctionCalls::send(orxonox::Host* host)
 {
-  this->minGamestateID_ = GamestateHandler::getInstance()->getCurrentGamestateID();
+  this->minGamestateID_ = host->getCurrentGamestateID();
   assert(this->functionCalls_.size());
   data_=new uint8_t[ currentSize_ ];
@@ -114,5 +117,5 @@
   assert( temp==data_+currentSize_ );
   
-  Packet::send();
+  Packet::send(host);
   return true;
 }
Index: /code/branches/network5/src/libraries/network/packet/FunctionCalls.h
===================================================================
--- /code/branches/network5/src/libraries/network/packet/FunctionCalls.h	(revision 7776)
+++ /code/branches/network5/src/libraries/network/packet/FunctionCalls.h	(revision 7777)
@@ -54,9 +54,9 @@
   inline unsigned int getSize() const
     { assert(!this->isDataENetAllocated()); return currentSize_; }
-  bool process();
+  virtual bool process(orxonox::Host* host);
 
   void addCallStatic( uint32_t networkID, const MultiType* mt1=0, const MultiType* mt2=0, const MultiType* mt3=0, const MultiType* mt4=0, const MultiType* mt5=0);
   void addCallMember( uint32_t networkID, uint32_t objectID, const MultiType* mt1=0, const MultiType* mt2=0, const MultiType* mt3=0, const MultiType* mt4=0, const MultiType* mt5=0);
-  virtual bool send();
+  virtual bool send(orxonox::Host* host);
 private:
   std::queue<orxonox::FunctionCall> functionCalls_;
Index: /code/branches/network5/src/libraries/network/packet/FunctionIDs.cc
===================================================================
--- /code/branches/network5/src/libraries/network/packet/FunctionIDs.cc	(revision 7776)
+++ /code/branches/network5/src/libraries/network/packet/FunctionIDs.cc	(revision 7777)
@@ -46,5 +46,6 @@
 
 
-FunctionIDs::FunctionIDs( ) : Packet(){
+FunctionIDs::FunctionIDs( ) : Packet()
+{
   unsigned int nrOfFunctions=0;
   unsigned int packetSize=2*sizeof(uint32_t); //space for the packetID and for the nroffunctions
@@ -55,5 +56,6 @@
   //calculate total needed size (for all strings and integers)
   ObjectList<NetworkFunctionBase>::iterator it;
-  for(it = ObjectList<NetworkFunctionBase>::begin(); it; ++it){
+  for(it = ObjectList<NetworkFunctionBase>::begin(); it; ++it)
+  {
     const std::string& functionname = it->getName();
     networkID = it->getNetworkID();
@@ -76,5 +78,6 @@
   // now save all classids and classnames
   std::pair<uint32_t, std::string> tempPair;
-  while( !tempQueue.empty() ){
+  while( !tempQueue.empty() )
+  {
     tempPair = tempQueue.front();
     tempQueue.pop();
@@ -98,5 +101,6 @@
 }
 
-uint32_t FunctionIDs::getSize() const{
+uint32_t FunctionIDs::getSize() const
+{
   assert(this->data_);
   uint8_t *temp = data_+sizeof(uint32_t); // packet identification
@@ -114,5 +118,6 @@
 
 
-bool FunctionIDs::process(){
+bool FunctionIDs::process(orxonox::Host* host)
+{
   int nrOfFunctions;
   uint8_t *temp = data_+sizeof(uint32_t); //skip the packetid
@@ -127,5 +132,6 @@
   temp += sizeof(uint32_t);
 
-  for( int i=0; i<nrOfFunctions; i++){
+  for( int i=0; i<nrOfFunctions; i++)
+  {
     networkID = *(uint32_t*)temp;
     stringsize = *(uint32_t*)(temp+sizeof(uint32_t));
Index: /code/branches/network5/src/libraries/network/packet/FunctionIDs.h
===================================================================
--- /code/branches/network5/src/libraries/network/packet/FunctionIDs.h	(revision 7776)
+++ /code/branches/network5/src/libraries/network/packet/FunctionIDs.h	(revision 7777)
@@ -47,6 +47,6 @@
   ~FunctionIDs();
 
-  uint32_t getSize() const;
-  bool process();
+  virtual uint32_t getSize() const;
+  virtual bool process(orxonox::Host* host);
 
 private:
Index: /code/branches/network5/src/libraries/network/packet/Gamestate.cc
===================================================================
--- /code/branches/network5/src/libraries/network/packet/Gamestate.cc	(revision 7776)
+++ /code/branches/network5/src/libraries/network/packet/Gamestate.cc	(revision 7777)
@@ -36,4 +36,5 @@
 #include "network/synchronisable/Synchronisable.h"
 #include "network/GamestateHandler.h"
+#include "network/Host.h"
 
 namespace orxonox {
@@ -44,6 +45,6 @@
 
 // #define PACKET_FLAG_GAMESTATE  PacketFlag::Unsequenced
-// #define PACKET_FLAG_GAMESTATE  0
-#define PACKET_FLAG_GAMESTATE  PacketFlag::Reliable
+#define PACKET_FLAG_GAMESTATE  0
+// #define PACKET_FLAG_GAMESTATE  PacketFlag::Reliable
 
 inline bool memzero( uint8_t* data, uint32_t datalength)
@@ -138,5 +139,5 @@
       assert(0); // if we don't use multithreading this part shouldn't be neccessary
       // start allocate additional memory
-      COUT(3) << "G.St.Man: need additional memory" << std::endl;
+      COUT(3) << "Gamestate: need additional memory" << std::endl;
       ObjectList<Synchronisable>::iterator temp = it;
       uint32_t addsize=tempsize;
@@ -165,6 +166,6 @@
   //stop write gamestate header
 
-  COUT(5) << "G.ST.Man: Gamestate size: " << currentsize << std::endl;
-  COUT(5) << "G.ST.Man: 'estimated' (and corrected) Gamestate size: " << size << std::endl;
+  COUT(5) << "Gamestate: Gamestate size: " << currentsize << std::endl;
+  COUT(5) << "Gamestate: 'estimated' (and corrected) Gamestate size: " << size << std::endl;
   return true;
 }
@@ -173,5 +174,5 @@
 bool Gamestate::spreadData(uint8_t mode)
 {
-  COUT(4) << "processing gamestate with id " << header_.getID() << endl;
+  COUT(5) << "processing gamestate with id " << header_.getID() << endl;
   assert(data_);
   assert(!header_.isCompressed());
@@ -204,4 +205,6 @@
     }
   }
+  assert(mem-data_ == GamestateHeader::getSize()+header_.getDataSize());
+  
    // In debug mode, check first, whether there are no duplicate objectIDs
 #ifndef NDEBUG
@@ -269,7 +272,7 @@
 
 
-bool Gamestate::process()
-{
-  return GamestateHandler::addGamestate(this, getClientID());
+bool Gamestate::process(orxonox::Host* host)
+{
+  return host->addGamestate(this, getPeerID());
 }
 
@@ -585,5 +588,5 @@
 
 
-  Gamestate *g = new Gamestate(newData, getClientID());
+  Gamestate *g = new Gamestate(newData, getPeerID());
   (g->header_) = header_;
   g->header_.setBaseID( base->getID() );
@@ -757,5 +760,5 @@
 
 
-uint32_t Gamestate::calcGamestateSize(int32_t id, uint8_t mode)
+uint32_t Gamestate::calcGamestateSize(uint32_t id, uint8_t mode)
 {
   uint32_t size = 0;
Index: /code/branches/network5/src/libraries/network/packet/Gamestate.h
===================================================================
--- /code/branches/network5/src/libraries/network/packet/Gamestate.h	(revision 7776)
+++ /code/branches/network5/src/libraries/network/packet/Gamestate.h	(revision 7777)
@@ -42,9 +42,15 @@
 #include "Packet.h"
 
-namespace orxonox {
+namespace orxonox
+{
 
-namespace packet {
+namespace packet
+{
+    
+static const uint8_t GAMESTATE_MODE_SERVER = 0x1;
+static const uint8_t GAMESTATE_MODE_CLIENT = 0x2;
 
-class _NetworkExport GamestateHeader{
+class _NetworkExport GamestateHeader
+{
   public:
     GamestateHeader(){ data_=0; }
@@ -58,13 +64,13 @@
       { return 21; }
 
-    inline int32_t getID() const
-      { assert(data_); return *(int32_t*)(data_+4); }
-    inline void setID(int32_t id)
-      { assert(data_); *(int32_t*)(data_+4) = id; }
+    inline uint32_t getID() const
+      { assert(data_); return *(uint32_t*)(data_+4); }
+    inline void setID(uint32_t id)
+      { assert(data_); *(uint32_t*)(data_+4) = id; }
 
-    inline int32_t getBaseID() const
-      { assert(data_); return *(int32_t*)(data_+8); }
-    inline void setBaseID(int32_t id)
-      { assert(data_); *(int32_t*)(data_+8) = id; }
+    inline uint32_t getBaseID() const
+      { assert(data_); return *(uint32_t*)(data_+8); }
+    inline void setBaseID(uint32_t id)
+      { assert(data_); *(uint32_t*)(data_+8) = id; }
 
     inline uint32_t getDataSize() const
@@ -103,5 +109,6 @@
     @author Oliver Scheuss
 */
-class _NetworkExport Gamestate: public Packet{
+class _NetworkExport Gamestate: public Packet
+{
   public:
     Gamestate();
@@ -114,5 +121,5 @@
     bool collectData(int id, uint8_t mode=0x0);
     bool spreadData( uint8_t mode=0x0);
-    inline int32_t getID() const { return header_.getID(); }
+    inline uint32_t getID() const { return header_.getID(); }
     inline bool isDiffed() const { return header_.isDiffed(); }
     inline bool isCompressed() const { return header_.isCompressed(); }
@@ -132,6 +139,6 @@
 //     inline uint32_t findObject( const SynchronisableHeader& header, uint8_t* mem, uint32_t dataLength, uint32_t startPosition = 0 );
     virtual uint32_t getSize() const;
-    virtual inline bool process();
-    uint32_t calcGamestateSize(int32_t id, uint8_t mode=0x0);
+    virtual bool process(orxonox::Host* host);
+    uint32_t calcGamestateSize(uint32_t id, uint8_t mode=0x0);
 //     inline void diffObject( uint8_t*& newData, uint8_t*& origData, uint8_t*& baseData, SynchronisableHeader& objectHeader, std::vector<uint32_t>::iterator& sizes );
 //     inline void copyObject( uint8_t*& newData, uint8_t*& origData, uint8_t*& baseData, SynchronisableHeader& objectHeader, std::vector<uint32_t>::iterator& sizes );
Index: /code/branches/network5/src/libraries/network/packet/Packet.cc
===================================================================
--- /code/branches/network5/src/libraries/network/packet/Packet.cc	(revision 7776)
+++ /code/branches/network5/src/libraries/network/packet/Packet.cc	(revision 7777)
@@ -68,5 +68,5 @@
   flags_ = PACKET_FLAG_DEFAULT;
   packetDirection_ = Direction::Outgoing;
-  clientID_=0;
+  peerID_=0;
   data_=0;
   enetPacket_=0;
@@ -74,9 +74,9 @@
 }
 
-Packet::Packet(uint8_t *data, unsigned int clientID)
+Packet::Packet(uint8_t *data, unsigned int peerID)
 {
   flags_ = PACKET_FLAG_DEFAULT;
   packetDirection_ = Direction::Incoming;
-  clientID_=clientID;
+  peerID_=peerID;
   data_=data;
   enetPacket_=0;
@@ -89,5 +89,5 @@
   flags_=p.flags_;
   packetDirection_ = p.packetDirection_;
-  clientID_ = p.clientID_;
+  peerID_ = p.peerID_;
   if(p.data_){
     data_ = new uint8_t[p.getSize()];
@@ -125,5 +125,5 @@
 }
 
-bool Packet::send(){
+bool Packet::send(orxonox::Host* host){
   if(packetDirection_ != Direction::Outgoing && packetDirection_ != Direction::Bidirectional ){
     assert(0);
@@ -169,7 +169,7 @@
 //  enetPacket_ = 0; // otherwise we have a double free because enet already handles the deallocation of the packet
   if( this->flags_ & PacketFlag::Reliable )
-    Host::addPacket( enetPacket_, clientID_, NETWORK_CHANNEL_DEFAULT);
+    host->addPacket( enetPacket_, peerID_, NETWORK_CHANNEL_DEFAULT);
   else
-    Host::addPacket( enetPacket_, clientID_, NETWORK_CHANNEL_UNRELIABLE);
+    host->addPacket( enetPacket_, peerID_, NETWORK_CHANNEL_UNRELIABLE);
   return true;
 }
@@ -178,5 +178,5 @@
   uint8_t *data = packet->data;
   assert(ClientInformation::findClient(&peer->address)->getID() != static_cast<unsigned int>(-2) || !Host::isServer());
-  unsigned int clientID = ClientInformation::findClient(&peer->address)->getID();
+  unsigned int peerID = ClientInformation::findClient(&peer->address)->getID();
   Packet *p = 0;
 //   COUT(6) << "packet type: " << *(Type::Value *)&data[_PACKETID] << std::endl;
@@ -185,33 +185,33 @@
     case Type::Acknowledgement:
 //       COUT(5) << "ack" << std::endl;
-      p = new Acknowledgement( data, clientID );
+    p = new Acknowledgement( data, peerID );
       break;
     case Type::Chat:
 //       COUT(5) << "chat" << std::endl;
-      p = new Chat( data, clientID );
+      p = new Chat( data, peerID );
       break;
     case Type::ClassID:
 //       COUT(5) << "classid" << std::endl;
-      p = new ClassID( data, clientID );
+      p = new ClassID( data, peerID );
       break;
     case Type::Gamestate:
 //       COUT(5) << "gamestate" << std::endl;
-      p = new Gamestate( data, clientID );
+      p = new Gamestate( data, peerID );
       break;
     case Type::Welcome:
 //       COUT(5) << "welcome" << std::endl;
-      p = new Welcome( data, clientID );
+      p = new Welcome( data, peerID );
       break;
     case Type::DeleteObjects:
 //       COUT(5) << "deleteobjects" << std::endl;
-      p = new DeleteObjects( data, clientID );
+      p = new DeleteObjects( data, peerID );
       break;
     case Type::FunctionCalls:
 //       COUT(5) << "functionCalls" << std::endl;
-      p = new FunctionCalls( data, clientID );
+      p = new FunctionCalls( data, peerID );
       break;
     case Type::FunctionIDs:
 //       COUT(5) << "functionIDs" << std::endl;
-      p = new FunctionIDs( data, clientID );
+      p = new FunctionIDs( data, peerID );
       break;
     default:
Index: /code/branches/network5/src/libraries/network/packet/Packet.h
===================================================================
--- /code/branches/network5/src/libraries/network/packet/Packet.h	(revision 7776)
+++ /code/branches/network5/src/libraries/network/packet/Packet.h	(revision 7777)
@@ -68,16 +68,20 @@
     virtual unsigned char *getData(){ return data_; };
     virtual unsigned int getSize() const =0;
-    virtual bool process()=0;
+    virtual bool process(orxonox::Host* host)=0;
     inline uint32_t getFlags()
       { return flags_; }
-    inline int getClientID()
-      { return clientID_; }
-    inline void setClientID( int id )
-      { clientID_ = id; }
+    inline int getPeerID()
+      { return peerID_; }
+    inline void setPeerID( int id )
+      { peerID_ = id; }
+    inline bool isReliable()
+      { return this->flags_ & PacketFlag::Reliable; }
+    inline uint32_t getRequiredGamestateID()
+      { return this->requiredGamestateID_; }
 
-    virtual bool send();
+    virtual bool send(orxonox::Host* host);
   protected:
     Packet();
-    Packet(uint8_t *data, unsigned int clientID);
+    Packet(uint8_t *data, unsigned int peerID);
 //    Packet(ENetPacket *packet, ENetPeer *peer);
     inline bool isDataENetAllocated() const
@@ -85,5 +89,6 @@
 
     uint32_t flags_;
-    unsigned int clientID_;
+    unsigned int peerID_;
+    uint32_t requiredGamestateID_;
     Direction::Value packetDirection_;
     /** Pointer to the data. Be careful when deleting it because it might
Index: /code/branches/network5/src/libraries/network/packet/Welcome.cc
===================================================================
--- /code/branches/network5/src/libraries/network/packet/Welcome.cc	(revision 7776)
+++ /code/branches/network5/src/libraries/network/packet/Welcome.cc	(revision 7777)
@@ -73,9 +73,9 @@
 }
 
-bool Welcome::process(){
+bool Welcome::process(orxonox::Host* host){
   uint32_t clientID;
   clientID = *(uint32_t *)(data_ + _CLIENTID );
   assert(*(uint32_t *)(data_ + _ENDIANTEST ) == 0xFEDC4321);
-  Host::setClientID(clientID);
+  host->setClientID(clientID);
   COUT(3) << "Welcome set clientId: " << clientID << endl;
   Synchronisable::setClient(true);
Index: /code/branches/network5/src/libraries/network/packet/Welcome.h
===================================================================
--- /code/branches/network5/src/libraries/network/packet/Welcome.h	(revision 7776)
+++ /code/branches/network5/src/libraries/network/packet/Welcome.h	(revision 7777)
@@ -47,5 +47,5 @@
   uint8_t *getData();
   inline unsigned int getSize() const;
-  bool process();
+  virtual bool process(orxonox::Host* host);
 
 private:
Index: /code/branches/network5/src/orxonox/PlayerManager.cc
===================================================================
--- /code/branches/network5/src/orxonox/PlayerManager.cc	(revision 7776)
+++ /code/branches/network5/src/orxonox/PlayerManager.cc	(revision 7777)
@@ -54,4 +54,5 @@
     void PlayerManager::clientConnected(unsigned int clientID)
     {
+      COUT(0) << "PlayerManager: client connected with id: " << clientID << endl;
         if (GameMode::isMaster())
         {
Index: /code/branches/network5/src/orxonox/gametypes/Gametype.cc
===================================================================
--- /code/branches/network5/src/orxonox/gametypes/Gametype.cc	(revision 7776)
+++ /code/branches/network5/src/orxonox/gametypes/Gametype.cc	(revision 7777)
@@ -171,4 +171,5 @@
     void Gametype::playerEntered(PlayerInfo* player)
     {
+      COUT(0) << "Gametype: playerentered" << endl;
         this->players_[player].state_ = PlayerState::Joined;
     }
@@ -411,4 +412,5 @@
     void Gametype::spawnPlayer(PlayerInfo* player)
     {
+      COUT(0) << "Gametype: spawnPlayer" << endl;
         SpawnPoint* spawnpoint = this->getBestSpawnPoint(player);
         if (spawnpoint)
Index: /code/branches/network5/src/orxonox/infos/HumanPlayer.cc
===================================================================
--- /code/branches/network5/src/orxonox/infos/HumanPlayer.cc	(revision 7776)
+++ /code/branches/network5/src/orxonox/infos/HumanPlayer.cc	(revision 7777)
@@ -45,4 +45,5 @@
     HumanPlayer::HumanPlayer(BaseObject* creator) : PlayerInfo(creator)
     {
+      COUT(0) << "new HumanPlayer" << endl;
         RegisterObject(HumanPlayer);
 
@@ -133,4 +134,5 @@
     void HumanPlayer::networkcallback_client_initialized()
     {
+      COUT(0) << "networkcallback_client_initialized" << endl;
         if (this->getGametype())
             this->getGametype()->playerEntered(this);
Index: /code/branches/network5/src/orxonox/worldentities/pawns/Spectator.cc
===================================================================
--- /code/branches/network5/src/orxonox/worldentities/pawns/Spectator.cc	(revision 7776)
+++ /code/branches/network5/src/orxonox/worldentities/pawns/Spectator.cc	(revision 7777)
@@ -43,4 +43,5 @@
     Spectator::Spectator(BaseObject* creator) : ControllableEntity(creator)
     {
+      COUT(0) << "creating specator" << endl;
         RegisterObject(Spectator);
 
