Index: code/trunk/src/network/CMakeLists.txt
===================================================================
--- code/trunk/src/network/CMakeLists.txt	(revision 1639)
+++ code/trunk/src/network/CMakeLists.txt	(revision 1735)
@@ -4,11 +4,18 @@
   ClientInformation.cc
   ConnectionManager.cc
-  GameStateManager.cc
-  GameStateClient.cc
+  GamestateManager.cc
+  GamestateClient.cc
+  GamestateHandler.cc
   PacketBuffer.cc
-  PacketDecoder.cc
-  PacketGenerator.cc
   Server.cc
   Synchronisable.cc
+  Host.cc
+  packet/Packet.cc
+  packet/Chat.cc
+  packet/ClassID.cc
+  packet/Acknowledgement.cc
+  packet/Gamestate.cc
+  packet/Welcome.cc
+  Host.cc
 )
 
@@ -31,18 +38,6 @@
   ##### test for gamestate stuff #####
   SET( TEST_SRC_FILES
-    ConnectionManager.cc
-    GameStateManager.cc
-    PacketBuffer.cc
-    PacketDecoder.cc
-    PacketGenerator.cc
-    ClientConnection.cc
-    ClientInformation.cc
-    diffTest.cc
-    GameStateClient.cc
-    Server.cc
-    Client.cc  
-    Synchronisable.cc  
+    ${NETWORK_SRC_FILES}
   )
-
   ADD_EXECUTABLE(networktest ${TEST_SRC_FILES})
   TARGET_LINK_LIBRARIES( networktest
@@ -55,128 +50,2 @@
   ##### end test for gamestate stuff #####
 ENDIF(NETWORK_TESTING_ENABLED)
-# build this if you want dummyserver4 and dummyclient4
-IF(NETWORKTRAFFIC_TESTING_ENABLED)
-  ##### test network traffic #####
-  SET( DUMMYSERVER4_SRC_FILES
-    ConnectionManager.cc
-    GameStateManager.cc
-    PacketBuffer.cc
-    PacketDecoder.cc
-    PacketGenerator.cc
-    ClientConnection.cc
-    ClientInformation.cc
-    GameStateClient.cc
-    Server.cc
-    Client.cc  
-    Synchronisable.cc
-    dummyserver4.cc
-  )
-
-  SET( DUMMYCLIENT4_SRC_FILES
-    ConnectionManager.cc
-    GameStateManager.cc
-    PacketBuffer.cc
-    PacketDecoder.cc
-    PacketGenerator.cc
-    ClientConnection.cc
-    ClientInformation.cc
-    GameStateClient.cc
-    Server.cc
-    Client.cc  
-    Synchronisable.cc
-    dummyclient4.cc
-  )
-
-  ADD_EXECUTABLE(dummyserver4 ${DUMMYSERVER4_SRC_FILES})
-  TARGET_LINK_LIBRARIES( dummyserver4
-    network
-    ${ENet_LIBRARY}
-    ${ZLIB_LIBRARY}
-    ${WINDOWS_ENET_DEPENDENCIES}
-    ${Boost_thread_LIBRARIES}
-    core
-    orxonoxs
-    audio
-  )
-
-  ADD_EXECUTABLE(dummyclient4 ${DUMMYCLIENT4_SRC_FILES})
-  TARGET_LINK_LIBRARIES( dummyclient4
-    network
-    ${ENet_LIBRARY}
-    ${ZLIB_LIBRARY}
-    ${WINDOWS_ENET_DEPENDENCIES}
-    ${Boost_thread_LIBRARIES}
-    core
-    orxonoxs
-    audio
-  )
-ENDIF(NETWORKTRAFFIC_TESTING_ENABLED)
-
-IF(BLABLA)
-  SET( CHATCLIENT_SRC_FILES
-    ClientConnection.cc
-    Client.cc
-    PacketBuffer.cc
-    PacketDecoder.cc
-    PacketGenerator.cc
-    dummyclient3.cc
-  )
-
-  SET( CHATSERVER_SRC_FILES
-    ConnectionManager.cc
-    GameStateManager.cc
-    PacketBuffer.cc
-    PacketDecoder.cc
-    PacketGenerator.cc
-    dummyserver3.cc
-  )
-
-  # chatserver for testing purposes
-  ADD_EXECUTABLE(chatserver ${CHATSERVER_SRC_FILES})
-  TARGET_LINK_LIBRARIES( chatserver
-    ${OGRE_LIBRARIES}
-    network
-    core
-    #objects
-    ${ENet_LIBRARY}
-    ${ZLIB_LIBRARY}
-    ${WINDOWS_ENET_DEPENDENCIES}
-  )
-
-  # chatclient for testing purpose
-  ADD_EXECUTABLE(chatclient ${CHATCLIENT_SRC_FILES})
-  TARGET_LINK_LIBRARIES( chatclient
-    ${OGRE_LIBRARIES}
-    network
-    core
-    #objects
-    ${ENet_LIBRARY}
-    ${ZLIB_LIBRARY}
-    ${WINDOWS_ENET_DEPENDENCIES}
-  )
-
-  # client for testing purpose
-  ADD_EXECUTABLE(client dummyclient2.cc)
-  TARGET_LINK_LIBRARIES( client
-    ${OGRE_LIBRARIES}
-    network
-    core
-    #objects
-    ${ENet_LIBRARY}
-    ${ZLIB_LIBRARY}
-    ${WINDOWS_ENET_DEPENDENCIES}
-  )
-
-  # server for testing purpose
-  ADD_EXECUTABLE(server dummyserver.cc)
-  TARGET_LINK_LIBRARIES( server
-    ${OGRE_LIBRARIES}
-    network
-    core
-    #objects
-    ${ENet_LIBRARY}
-    ${ZLIB_LIBRARY}
-    ${WINDOWS_ENET_DEPENDENCIES}
-  )
-ENDIF(BLABLA)
-
Index: code/trunk/src/network/Client.cc
===================================================================
--- code/trunk/src/network/Client.cc	(revision 1639)
+++ code/trunk/src/network/Client.cc	(revision 1735)
@@ -40,44 +40,15 @@
 
 #include "Client.h"
+#include "Host.h"
 #include "Synchronisable.h"
 #include "core/CoreIncludes.h"
 #include "core/ConsoleCommand.h"
-#include "Server.h"
+#include "packet/Packet.h"
+#include "packet/Acknowledgement.h"
 
 namespace network
 {
-  SetConsoleCommandShortcut(Client, Chat);
+//   SetConsoleCommandShortcut(Client, chat);
   
-  Client* Client::_sClient = 0;
-  
-  Client* Client::createSingleton(){
-    if(!_sClient){
-      _sClient = new Client();
-    }
-    return _sClient;
-  }
-  
-  Client* Client::createSingleton(std::string address, int port){
-    if(!_sClient)
-      _sClient = new Client(address, port);
-    return _sClient;
-  }
-  
-  Client* Client::createSingleton(const char *address, int port){
-    if(!_sClient)
-      _sClient = new Client(address, port);
-    return _sClient;
-  }
-  
-  void Client::destroySingleton(){
-    if(_sClient){
-      delete _sClient;
-      _sClient = 0;
-    }
-  }
-  
-  Client* Client::getSingleton(){
-    return _sClient; 
-  }
   
   /**
@@ -144,14 +115,17 @@
   }
 
+  bool Client::queuePacket(ENetPacket *packet, int clientID){
+    return client_connection.addPacket(packet);
+  }
   
-
-  void Client::Chat( std::string message ){
-    if(Client::getSingleton())
-      Client::getSingleton()->sendChat(message);
-    else if(Server::getSingleton())
-      Server::getSingleton()->sendChat(message);
-    else
-      COUT(1) << "do you want to monologize ??" << std::endl;
+  bool Client::processChat(packet::Chat *message, unsigned int clientID){
+    return message->process();
   }
+  
+  /*bool Client::sendChat(packet::Chat *chat){
+    chat->process();
+    packet::Packet *p = new packet::Packet(chat);
+    return p->send();
+  }*/
   
 
@@ -165,8 +139,7 @@
     if(!isConnected)
       return false;
-    return client_connection.addPacket(pck_gen.chatMessage( message.c_str() ));
-      //return client_connection.sendPackets();
+    packet::Chat chat(message, 0);
+    return chat.send();
     // send packets
-    return false;
   }
 
@@ -178,14 +151,11 @@
     if(client_connection.isConnected() && isSynched_){
       COUT(4) << "popping partial gamestate: " << std::endl;
-      GameStateCompressed *gs = gamestate.popPartialGameState();
+      /*packet::Gamestate *gs = gamestate.getGamestate();
       if(gs){
         COUT(4) << "client tick: sending gs " << gs << std::endl;
-        ENetPacket *packet = pck_gen.gstate(gs);
-        if( packet == NULL || !client_connection.addPacket(packet))
+        if( !gs->send() )
           COUT(3) << "Problem adding partial gamestate to queue" << std::endl;
-        // now delete it to save memory
-        delete[] gs->data;
-        delete gs;
-      }
+        // gs gets automatically deleted by enet callback
+      }*/
     }
     ENetEvent *event;
@@ -194,10 +164,12 @@
       event = client_connection.getEvent();
       COUT(5) << "tick packet size " << event->packet->dataLength << std::endl;
-      elaborate(event->packet, 0); // ================= i guess we got to change this .... (client_ID is always same = server)
+      packet::Packet *packet = packet::Packet::createPacket(event->packet, event->peer);
+      assert(packet->process());
     }
-    int gameStateID = gamestate.processGameState();
-    if(gameStateID==GAMESTATEID_INITIAL)
+    int gameStateID = gamestate.processGamestates();
+    /*if(gameStateID==GAMESTATEID_INITIAL)
       if(gameStateFailure_){
-        if(!client_connection.addPacket(pck_gen.acknowledgement(GAMESTATEID_INITIAL)))
+        packet::Acknowledgement ack(GAMESTATEID_INITIAL, 0);
+        if(!ack.send())
           COUT(3) << "could not (negatively) ack gamestate" << std::endl;
         else 
@@ -211,42 +183,11 @@
         isSynched_=true;
       gameStateFailure_=false;
-      if(!client_connection.addPacket(pck_gen.acknowledgement(gameStateID)))
+      packet::Acknowledgement ack(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();
-    /*if(!client_connection.sendPackets())
-      COUT(3) << "Problem sending packets to server" << std::endl;*/
     return;
   }
 
-  void Client::processGamestate( GameStateCompressed *data, int clientID){
-    COUT(5) << "received gamestate id: " << data->id << std::endl;
-    gamestate.addGameState(data);
-  }
-
-  void Client::processClassid(classid *clid){
-    orxonox::Identifier *id;
-    id=ID(std::string(clid->message));
-    if(id!=NULL)
-      id->setNetworkID(clid->clid);
-    COUT(4) << "Client: received and set network id: " << clid->clid << "; classname: " << clid->message << std::endl;
-    COUT(4) << "id(classid)->getName " << ID((unsigned int)clid->clid)->getName() << std::endl;
-    delete clid;
-    return;
-  }
-
-  void Client::processChat( chat *data, int clientId){
-    COUT(1) << data->message << std::endl;
-    delete[] data->message;
-    delete data;
-  }
-  
-  bool Client::processWelcome( welcome *w ){
-    COUT(4) << "processing welcome message" << std::endl;
-    clientID_ = w->clientID;
-    shipID_ = w->shipID;
-    delete w;
-    return true;
-  }
-
 }
Index: code/trunk/src/network/Client.h
===================================================================
--- code/trunk/src/network/Client.h	(revision 1639)
+++ code/trunk/src/network/Client.h	(revision 1735)
@@ -46,7 +46,8 @@
 #include <string>
 
+#include "Host.h"
+#include "packet/Chat.h"
 #include "ClientConnection.h"
-#include "PacketManager.h"
-#include "GameStateClient.h"
+#include "GamestateClient.h"
 //#include "NetworkFrameListener.h"
 
@@ -62,24 +63,6 @@
   *
   */
-  class _NetworkExport Client : PacketDecoder{
+  class _NetworkExport Client : public Host{
   public:
-    
-    static Client* createSingleton();
-    static Client* createSingleton(std::string address, int port);
-    static Client* createSingleton(const char *address, int port);
-    static void destroySingleton();
-    static Client *getSingleton();
-    
-    bool establishConnection();
-    bool closeConnection();
-
-    static void Chat( std::string message );
-    
-    int getShipID(){return shipID_;}
-    int getClientID(){return clientID_;}
-
-    void tick(float time);
-
-  private:
     Client();
     Client(std::string address, int port);
@@ -87,9 +70,23 @@
     ~Client();
     
-    static Client* _sClient;
+    bool establishConnection();
+    bool closeConnection();
+    bool queuePacket(ENetPacket *packet, int clientID);
+    bool processChat(packet::Chat *message, unsigned int clientID);
+    //bool sendChat(packet::Chat *chat);
+    
+//    static void Chat( std::string message );
+    
+    unsigned int shipID(){return shipID_;}
+    int playerID(){return clientID_;}
+    //static void setShipID( unsigned int shipID){ dynamic_cast<Client *>(instance_)->shipID_=shipID; }
+    static void setClientID( unsigned int clientID){ dynamic_cast<Client *>(instance_)->clientID_=clientID; }
+    
+    void tick(float time);
+
+  private:
     
     ClientConnection client_connection;
-    PacketGenerator pck_gen;
-    GameStateClient gamestate;
+    GamestateClient gamestate;
     bool isConnected;
     bool isSynched_;
@@ -98,8 +95,5 @@
     
     // implement data processing functions of PacketDecoder
-    void processGamestate( GameStateCompressed *data, int clientID);
-    void processClassid(classid *clid);
-    void processChat( chat *data, int clientId );
-    bool processWelcome( welcome *w );
+//     void processChat( chat *data, int clientId );
     int clientID_;     // this is the id the server gave to us
     int shipID_;
Index: code/trunk/src/network/ClientInformation.cc
===================================================================
--- code/trunk/src/network/ClientInformation.cc	(revision 1639)
+++ code/trunk/src/network/ClientInformation.cc	(revision 1735)
@@ -46,41 +46,19 @@
 {
   
+  ClientInformation *ClientInformation::head_=0;
+  
   ClientInformation::ClientInformation() {
+    if(!head_)
+      head_=this;
     gamestateID_=GAMESTATEID_INITIAL;
     preve=0;
     nexte=0;
     partialGamestateID_=GAMESTATEID_INITIAL-1;
-    this->head_=false;
     synched_=false;
   }
 
-  ClientInformation::ClientInformation(bool head) {
-    gamestateID_=GAMESTATEID_INITIAL;
-    preve=0;
-    nexte=0;
-    partialGamestateID_=GAMESTATEID_INITIAL-1;
-    this->head_=head;
-    synched_=false;
-  }
-
-  // ClientInformation::ClientInformation(ClientInformation *prev) {
-  //   if(prev->next()!=0){
-  //     this->nexte=prev->next();
-  //     this->nexte->setPrev(this);
-  //   }
-  //   else
-  //     this->nexte = 0;
-  //   prev->setNext(this);
-  //   this->preve = pref;
-  // }
-  //
-  // ClientInformation::ClientInformation(ClientInformation *prev, ClientInformation *next){
-  //   this->nexte = next;
-  //   this->preve = prev;
-  //   this->preve->setNext(this);
-  //   this->nexte->setPrev(this);
-  // }
-
   ClientInformation::~ClientInformation() {
+    if(this==head_)
+      head_=next();
     if(prev()!=0)
       prev()->setNext(this->next());
@@ -103,8 +81,7 @@
 
   bool ClientInformation::setPrev(ClientInformation *prev) {
-    if(!head_)
-      this->preve = prev;
-    else
-      return false;
+    if(this==head_)
+      head_=prev;
+    this->preve = prev;
     return true;
   }
@@ -146,5 +123,5 @@
   }
 
-  bool ClientInformation::setGameStateID(int id){
+  bool ClientInformation::setGamestateID(int id){
     if(!this)
       return false;
@@ -172,12 +149,4 @@
     else
       return NULL;
-  }
-  
-  bool ClientInformation::getHead(){
-    return head_;
-  }
-  
-  void ClientInformation::setHead(bool h){
-    head_=h;
   }
   
@@ -215,7 +184,8 @@
 
   ClientInformation *ClientInformation::insertBack(ClientInformation *ins) {
-    if(!this)
-      return NULL;
-    ClientInformation *temp = this;
+    ClientInformation *temp = head_;
+    if(temp==head_){
+      return head_;
+    }
     while(temp->next()!=0){
       temp = temp->next();
@@ -227,7 +197,7 @@
 
   bool ClientInformation::removeClient(int clientID) {
-    if(!this || clientID==CLIENTID_UNKNOWN)
-      return false;
-    ClientInformation *temp = this;
+    if(clientID==CLIENTID_UNKNOWN)
+      return false;
+    ClientInformation *temp = head_;
     while(temp!=0 && temp->getID()!=clientID)
       temp = temp->next();
@@ -239,11 +209,10 @@
 
   bool ClientInformation::removeClient(ENetPeer *peer) {
-    if(!this || !peer)
-      return false;
-    ClientInformation *temp = this;
+    if(!peer)
+      return false;
+    ClientInformation *temp = head_;
     while(temp!=0){
-      if(!temp->head_)
-        if(temp->getPeer()->address.host==peer->address.host && temp->getPeer()->address.port==peer->address.port)
-          break;
+      if(temp->getPeer()->address.host==peer->address.host && temp->getPeer()->address.port==peer->address.port)
+        break;
       temp = temp->next();
     }
@@ -261,7 +230,5 @@
   */
   ClientInformation *ClientInformation::findClient(int clientID, bool look_backwards) {
-    ClientInformation *temp = this;
-    if (temp->head_)
-      temp=temp->next();
+    ClientInformation *temp = head_;
     while(temp!=0 && temp->getID()!=clientID){
       temp = temp->next();
@@ -278,10 +245,6 @@
   */
   ClientInformation *ClientInformation::findClient(ENetAddress *address, bool look_backwards) {
-    ClientInformation *temp = this;
+    ClientInformation *temp = head_;
     while(temp!=0){
-      if(temp->head_){
-        temp = temp->next();
-        continue;
-      }
       if(temp->getPeer()->address.host==address->host && temp->getPeer()->address.port == address->port)
         break;
Index: code/trunk/src/network/ClientInformation.h
===================================================================
--- code/trunk/src/network/ClientInformation.h	(revision 1639)
+++ code/trunk/src/network/ClientInformation.h	(revision 1735)
@@ -60,5 +60,4 @@
   public:
     ClientInformation();
-    ClientInformation(bool head);
     //   ClientInformation(ClientInformation *prev, ClientInformation *next);
     //   ClientInformation(ClientInformation *prev);
@@ -66,21 +65,19 @@
     ClientInformation *next();
     ClientInformation *prev();
-    ClientInformation *insertBack(ClientInformation *ins);
+    static ClientInformation *insertBack(ClientInformation *ins);
     
     // set functions
     void setID(int clientID);
     bool setPeer(ENetPeer *peer);
-    bool setGameStateID(int id);
+    bool setGamestateID(int id);
     bool setPartialGamestateID(int id);
-    inline void setShipID(int id){ShipID_=id;}
+    inline void setShipID(unsigned int id){ShipID_=id;}
     
     // get functions
-    inline int getShipID(){return ShipID_;}
+    inline unsigned int getShipID(){return ShipID_;}
     int getID();
     int getGamestateID();
     int getPartialGamestateID();
     ENetPeer *getPeer();
-    bool getHead();
-    void setHead(bool h);
     
     int getFailures();
@@ -90,10 +87,9 @@
     enet_uint32 getPacketLoss();
     
-    bool removeClient(int clientID);
-    bool removeClient(ENetPeer *peer);
-    //## add bool mask-function eventually
-    ClientInformation *findClient(int clientID, bool look_backwards=false);
-    //## add bool mask-function eventually
-    ClientInformation *findClient(ENetAddress *address, bool look_backwards=false);
+    static bool removeClient(int clientID);
+    static bool removeClient(ENetPeer *peer);
+    static ClientInformation *findClient(int clientID, bool look_backwards=false);
+    static ClientInformation *findClient(ENetAddress *address, bool look_backwards=false);
+    static ClientInformation *getBegin(){return head_;}
 
     bool setSynched(bool s);
@@ -101,7 +97,9 @@
 
 
-    private:
-      bool setNext(ClientInformation *next);
-      bool setPrev(ClientInformation *prev);
+  private:
+    static ClientInformation *head_;
+    
+    bool setNext(ClientInformation *next);
+    bool setPrev(ClientInformation *prev);
     ClientInformation *insertAfter(ClientInformation *ins);
     ClientInformation *insertBefore(ClientInformation *ins);
@@ -114,7 +112,6 @@
     int gamestateID_;
     int partialGamestateID_;
-    int ShipID_;   // this is the unique objectID
+    unsigned int ShipID_;   // this is the unique objectID
     bool synched_;
-    bool head_;
     unsigned short failures_;
     
Index: code/trunk/src/network/ConnectionManager.cc
===================================================================
--- code/trunk/src/network/ConnectionManager.cc	(revision 1639)
+++ code/trunk/src/network/ConnectionManager.cc	(revision 1735)
@@ -39,4 +39,5 @@
 
 #include <iostream>
+#include <assert.h>
 // boost.thread library for multithreading support
 #include <boost/bind.hpp>
@@ -50,4 +51,5 @@
 #include "ConnectionManager.h"
 #include "Synchronisable.h"
+#include "packet/ClassID.h"
 
 namespace std
@@ -65,33 +67,51 @@
   //boost::thread_group network_threads;
   
-  ConnectionManager::ConnectionManager():receiverThread_(0){}
-  boost::recursive_mutex ConnectionManager::enet_mutex_;
-  
-  ConnectionManager::ConnectionManager(ClientInformation *head) : receiverThread_(0) {
+  ConnectionManager *ConnectionManager::instance_=0;
+  
+  ConnectionManager::ConnectionManager():receiverThread_(0){
+    assert(instance_==0);
+    instance_=this;
     quit=false;
     bindAddress.host = ENET_HOST_ANY;
     bindAddress.port = NETWORK_PORT;
-    head_ = head;
-  }
-  
-  ConnectionManager::ConnectionManager(ClientInformation *head, int port){
+  }
+  boost::recursive_mutex ConnectionManager::enet_mutex;
+  
+//   ConnectionManager::ConnectionManager(ClientInformation *head) : receiverThread_(0) {
+//     assert(instance_==0);
+//     instance_=this;
+//     quit=false;
+//     bindAddress.host = ENET_HOST_ANY;
+//     bindAddress.port = NETWORK_PORT;
+//   }
+  
+  ConnectionManager::ConnectionManager(int port){
+    assert(instance_==0);
+    instance_=this;
     quit=false;
     bindAddress.host = ENET_HOST_ANY;
     bindAddress.port = port;
-    head_ = head;
-  }
-
-  ConnectionManager::ConnectionManager(int port, std::string address, ClientInformation *head) :receiverThread_(0) {
+  }
+
+  ConnectionManager::ConnectionManager(int port, std::string address) :receiverThread_(0) {
+    assert(instance_==0);
+    instance_=this;
     quit=false;
     enet_address_set_host (& bindAddress, address.c_str());
     bindAddress.port = NETWORK_PORT;
-    head_ = head;
-  }
-
-  ConnectionManager::ConnectionManager(int port, const char *address, ClientInformation *head) : receiverThread_(0) {
+  }
+
+  ConnectionManager::ConnectionManager(int port, const char *address) : receiverThread_(0) {
+    assert(instance_==0);
+    instance_=this;
     quit=false;
     enet_address_set_host (& bindAddress, address);
     bindAddress.port = NETWORK_PORT;
-    head_ = head;
+  }
+  
+  ConnectionManager::~ConnectionManager(){
+    instance_=0;
+    if(!quit)
+      quitListener();
   }
 
@@ -140,11 +160,19 @@
     return true;
   }
-
+  
+//   bool ConnectionManager::addPacket(Packet::Packet *packet){
+//     ClientInformation *temp = instance_->head_->findClient(packet->getClientID());
+//     if(!temp){
+//       COUT(3) << "C.Man: addPacket findClient failed" << std::endl;
+//       return false;
+//     }
+//     ENetPacket *packet = new ENetPacket;
+//     //  TODO: finish implementation
+//   }
+//   
+  
   bool ConnectionManager::addPacket(ENetPacket *packet, ENetPeer *peer) {
-    ClientInformation *temp = head_->findClient(&(peer->address));
-    if(!temp)
-      return false;
-    boost::recursive_mutex::scoped_lock lock(enet_mutex_);
-    if(enet_peer_send(peer, (enet_uint8)temp->getID() , packet)!=0)
+    boost::recursive_mutex::scoped_lock lock(instance_->enet_mutex);
+    if(enet_peer_send(peer, NETWORK_DEFAULT_CHANNEL, packet)!=0)
       return false;
     return true;
@@ -152,20 +180,17 @@
 
   bool ConnectionManager::addPacket(ENetPacket *packet, int clientID) {
-    ClientInformation *temp = head_->findClient(clientID);
+    ClientInformation *temp = ClientInformation::findClient(clientID);
     if(!temp){
       COUT(3) << "C.Man: addPacket findClient failed" << std::endl;
       return false;
     }
-    boost::recursive_mutex::scoped_lock lock(enet_mutex_);
-    if(enet_peer_send(temp->getPeer(), 0, packet)!=0){
-      COUT(3) << "C.Man: addPacket enet_peer_send failed" << std::endl;
-      return false;
-    }
-    return true;
+    return addPacket(packet, temp->getPeer());
   }
 
   bool ConnectionManager::addPacketAll(ENetPacket *packet) {
-    boost::recursive_mutex::scoped_lock lock(enet_mutex_);
-    for(ClientInformation *i=head_->next(); i!=0; i=i->next()){
+    if(!instance_)
+      return false;
+    boost::recursive_mutex::scoped_lock lock(instance_->enet_mutex);
+    for(ClientInformation *i=ClientInformation::getBegin()->next(); i!=0; i=i->next()){
       COUT(3) << "adding broadcast packet for client: " << i->getID() << std::endl;
       if(enet_peer_send(i->getPeer(), 0, packet)!=0)
@@ -177,7 +202,7 @@
   // we actually dont need that function, because host_service does that for us
   bool ConnectionManager::sendPackets() {
-    if(server==NULL)
-      return false;
-    boost::recursive_mutex::scoped_lock lock(enet_mutex_);
+    if(server==NULL || !instance_)
+      return false;
+    boost::recursive_mutex::scoped_lock lock(enet_mutex);
     enet_host_flush(server);
     lock.unlock();
@@ -190,5 +215,5 @@
     atexit(enet_deinitialize);
     { //scope of the mutex
-      boost::recursive_mutex::scoped_lock lock(enet_mutex_);
+      boost::recursive_mutex::scoped_lock lock(enet_mutex);
       enet_initialize();
       server = enet_host_create(&bindAddress, NETWORK_MAX_CONNECTIONS, 0, 0);
@@ -204,5 +229,5 @@
     while(!quit){
       { //mutex scope
-        boost::recursive_mutex::scoped_lock lock(enet_mutex_);
+        boost::recursive_mutex::scoped_lock lock(enet_mutex);
         if(enet_host_service(server, event, NETWORK_WAIT_TIMEOUT)<0){
           // we should never reach this point
@@ -246,5 +271,5 @@
     // if we're finishied, destroy server
     {
-      boost::recursive_mutex::scoped_lock lock(enet_mutex_);
+      boost::recursive_mutex::scoped_lock lock(enet_mutex);
       enet_host_destroy(server);
       lock.unlock();
@@ -257,8 +282,8 @@
   void ConnectionManager::disconnectClients() {
     ENetEvent event;
-    ClientInformation *temp = head_->next();
+    ClientInformation *temp = ClientInformation::getBegin()->next();
     while(temp!=0){
       {
-        boost::recursive_mutex::scoped_lock lock(enet_mutex_);
+        boost::recursive_mutex::scoped_lock lock(enet_mutex);
         enet_peer_disconnect(temp->getPeer(), 0);
         lock.unlock();
@@ -267,6 +292,6 @@
     }
     //bugfix: might be the reason why server crashes when clients disconnects
-    temp = head_->next();
-    boost::recursive_mutex::scoped_lock lock(enet_mutex_);
+    temp = ClientInformation::getBegin()->next();
+    boost::recursive_mutex::scoped_lock lock(enet_mutex);
     while( temp!=0 && enet_host_service(server, &event, NETWORK_WAIT_TIMEOUT) >= 0){
       switch (event.type)
@@ -279,6 +304,6 @@
       case ENET_EVENT_TYPE_DISCONNECT:
         COUT(4) << "disconnecting all clients" << std::endl;
-        if(head_->findClient(&(event.peer->address)))
-          delete head_->findClient(&(event.peer->address));
+        if(ClientInformation::findClient(&(event.peer->address)))
+          delete ClientInformation::findClient(&(event.peer->address));
         //maybe needs bugfix: might also be a reason for the server to crash
         temp = temp->next();
@@ -302,12 +327,16 @@
 
   int ConnectionManager::getClientID(ENetAddress address) {
-    return head_->findClient(&address)->getID();
+    return ClientInformation::findClient(&address)->getID();
   }
 
   ENetPeer *ConnectionManager::getClientPeer(int clientID) {
-    return head_->findClient(clientID)->getPeer();
-  }
-
-  void ConnectionManager::syncClassid(int clientID) {
+    return ClientInformation::findClient(clientID)->getPeer();
+  }
+
+  /**
+   * 
+   * @param clientID 
+   */
+  void ConnectionManager::syncClassid(unsigned int clientID) {
     unsigned int network_id=0, failures=0;
     std::string classname;
@@ -324,5 +353,7 @@
       COUT(4) << "Con.Man:syncClassid:\tnetwork_id: " << network_id << ", classname: " << classname << std::endl;
 
-      while(!addPacket(packet_gen.clid( (int)network_id, classname ), clientID) && failures < 10){
+      packet::ClassID *classid = new packet::ClassID( network_id, classname );
+      classid->setClientID(clientID);
+      while(!classid->send() && failures < 10){
         failures++;
       }
@@ -336,5 +367,5 @@
   
   bool ConnectionManager::removeShip(ClientInformation *client){
-    int id=client->getShipID();
+    unsigned int id=client->getShipID();
     orxonox::Iterator<orxonox::SpaceShip> it;
     for(it = orxonox::ObjectList<orxonox::SpaceShip>::start(); it; ++it){
@@ -346,15 +377,8 @@
   }
   
-  bool ConnectionManager::sendWelcome(int clientID, int shipID, bool allowed){
-    if(addPacket(packet_gen.generateWelcome(clientID, shipID, allowed),clientID)){
-      //sendPackets();
-      return true;
-    }else
-      return false;
-  }
   
   void ConnectionManager::disconnectClient(ClientInformation *client){
     {
-      boost::recursive_mutex::scoped_lock lock(enet_mutex_);
+      boost::recursive_mutex::scoped_lock lock(enet_mutex);
       enet_peer_disconnect(client->getPeer(), 0);
       lock.unlock();
@@ -363,12 +387,4 @@
   }
   
-  bool ConnectionManager::addFakeConnectRequest(ENetEvent *ev){
-    ENetEvent event;
-    event.peer=ev->peer;
-    event.packet = packet_gen.generateConnectRequest();
-    return buffer.push(&event);
-  }
-  
-  
 
 }
Index: code/trunk/src/network/ConnectionManager.h
===================================================================
--- code/trunk/src/network/ConnectionManager.h	(revision 1639)
+++ code/trunk/src/network/ConnectionManager.h	(revision 1735)
@@ -51,5 +51,5 @@
 
 #include "PacketBuffer.h"
-#include "PacketManager.h"
+#include "packet/Packet.h"
 
 namespace std
@@ -63,4 +63,5 @@
 #define NETWORK_MAX_CONNECTIONS 50
 #define NETWORK_WAIT_TIMEOUT 1
+#define NETWORK_DEFAULT_CHANNEL 0
 
   struct ClientList{
@@ -71,10 +72,12 @@
 
   class ConnectionManager{
-  public:
+    public:
+    static boost::recursive_mutex enet_mutex;
     ConnectionManager();
-    ConnectionManager(ClientInformation *head);
-    ConnectionManager(ClientInformation *head, int port);
-    ConnectionManager(int port, const char *address, ClientInformation *head);
-    ConnectionManager(int port, std::string address, ClientInformation *head);
+    //ConnectionManager(ClientInformation *head);
+    ConnectionManager(int port);
+    ConnectionManager(int port, const char *address);
+    ConnectionManager(int port, std::string address);
+    ~ConnectionManager();
     //ENetPacket *getPacket(ENetAddress &address); // thread1
     //ENetPacket *getPacket(int &clientID);
@@ -83,13 +86,13 @@
     void createListener();
     bool quitListener();
-    bool addPacket(ENetPacket *packet, ENetPeer *peer);
-    bool addPacket(ENetPacket *packet, int ID);
-    bool addPacketAll(ENetPacket *packet);
+//     bool addPacket(Packet::Packet *packet);
+    static bool addPacket(ENetPacket *packet, ENetPeer *peer);
+    static bool addPacket(ENetPacket *packet, int ID);
+    static bool addPacketAll(ENetPacket *packet);
   //  bool sendPackets(ENetEvent *event);
     bool sendPackets();
     //bool createClient(int clientID);
     void disconnectClient(ClientInformation *client);
-    void syncClassid(int clientID);
-    bool sendWelcome(int clientID, int shipID, bool allowed);
+    void syncClassid(unsigned int clientID);
 
   private:
@@ -105,7 +108,5 @@
     //bool createShip(ClientInformation *client);
     bool removeShip(ClientInformation *client);
-    bool addFakeConnectRequest(ENetEvent *ev);
     PacketBuffer buffer;
-    PacketGenerator packet_gen;
 
     ENetHost *server;
@@ -113,16 +114,8 @@
 
     bool quit; // quit-variable (communication with threads)
-    ClientInformation *head_;
 
     boost::thread *receiverThread_;
-    static boost::recursive_mutex enet_mutex_;
-//     int getNumberOfClients();
-    //functions to map what object every clients uses
-    /*std::map<int, int> clientsShip;
-    void addClientsObjectID( int clientID, int objectID );
-    int getClientsShipID( int clientID );
-    int getObjectsClientID( int objectID );
-    void deleteClientIDReg( int clientID );
-    void deleteObjectIDReg( int objectID );*/
+    static ConnectionManager *instance_;
+
   };
 
Index: code/trunk/src/network/GameStateClient.cc
===================================================================
--- code/trunk/src/network/GameStateClient.cc	(revision 1639)
+++ 	(revision )
@@ -1,481 +1,0 @@
-/*
- *   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
- *   Co-authors:
- *      Dumeni Manatschal
- *
- */
-
-#include "GameStateClient.h"
-
-#include <zlib.h>
-
-#include "core/CoreIncludes.h"
-#include "core/BaseObject.h"
-#include "Synchronisable.h"
-#include "objects/SpaceShip.h"
-
-
-namespace network
-{
-  struct GameStateItem{
-    GameState *state;
-    int id;
-  };
-
-  GameStateClient::GameStateClient() {
-    COUT(5) << "this: " << this << std::endl;
-    last_diff_=0;
-    last_gamestate_=GAMESTATEID_INITIAL-1;
-    tempGameState_=NULL;
-    myShip_=NULL;
-  }
-
-  GameStateClient::~GameStateClient() {
-  }
-
-  bool GameStateClient::pushGameState(GameStateCompressed *compstate) {
-    cleanup();
-    printGameStateMap();
-    GameState *gs, *reference;
-    /*if(compstate->id<last_gamestate_){
-      // network packets got messed up
-      COUT(3) << "received an obsolete gamestate" << std::endl;
-      return false;
-    }*/
-    if(compstate->diffed && compstate->base_id!=GAMESTATEID_INITIAL){
-      std::map<int, GameState*>::iterator it = gameStateMap.find(compstate->base_id);
-      if(it!=gameStateMap.end())
-        reference = (it)->second;
-      else
-        reference = NULL;
-      if(!reference){
-        COUT(4) << "pushGameState: no reference found to diff" << std::endl;
-        delete[] compstate->data;
-        delete compstate;
-        return false;
-      }
-      gs = decode(reference, compstate);
-    }
-    else
-      gs = decode(compstate);
-    if(gs){
-      if (loadSnapshot(gs)){
-        gameStateMap.insert(std::pair<int, GameState*>(gs->id, gs));
-        COUT(5) << "adding decoded gs with id: " << gs->id << " diffed from: " << gs->base_id << std::endl;
-        last_diff_=gs->base_id;
-        //last_gamestate_=gs->id;
-        return true;
-      }else{
-        COUT(4) << "could not decode gs with id: " << gs->id << " diffed from: " << gs->base_id << std::endl;
-        delete[] gs->data;
-        delete gs;
-        return false;
-      }
-    }
-    COUT(4) << "could not use gamestate sent by server" << std::endl;
-    return false;
-  }
-
-  GameStateCompressed *GameStateClient::popPartialGameState(){
-    GameState *gs = getPartialSnapshot();
-    if(!gs)
-      return NULL;
-    GameStateCompressed *cgs = compress_(gs);
-    delete[] gs->data;
-    delete gs;
-    return cgs;
-  }
-
-  void GameStateClient::addGameState(GameStateCompressed *gs){
-    if(tempGameState_!=NULL){
-      //delete the obsolete gamestate
-      if(tempGameState_->id>gs->id)
-        return;
-      delete[] tempGameState_->data;
-      delete tempGameState_;
-    }
-    tempGameState_=gs;
-  }
-  int GameStateClient::processGameState(){
-    if(tempGameState_==NULL)
-      return 0;
-    int id=tempGameState_->id;
-    bool b = saveShipCache();
-    if(pushGameState(tempGameState_)){
-      if(b)
-        loadShipCache();
-      return id;
-    }
-    else
-      return GAMESTATEID_INITIAL;
-  }
-
-
-  /**
-  * This function removes a Synchronisable out of the universe
-  * @param it iterator of the list pointing to the object
-  * @return iterator pointing to the next object in the list
-  */
-  void GameStateClient::removeObject(orxonox::Iterator<Synchronisable> &it) {
-    orxonox::Iterator<Synchronisable> temp=it;
-    ++it;
-    delete  *temp;
-  }
-
-  /**
-  * This function loads a Snapshort of the gamestate into the universe
-  * @param state a GameState struct containing the size of the gamestate and a pointer linking to a flat list (returned by getSnapshot)
-  */
-  bool GameStateClient::loadSnapshot(GameState *state) {
-    unsigned char *data=state->data;
-    COUT(4) << "loadSnapshot: loading gs: " << state->id << std::endl;
-    // get the start of the Synchronisable list
-    orxonox::Iterator<Synchronisable> it=orxonox::ObjectList<Synchronisable>::start();
-    syncData sync;
-    // loop as long as we have some data ;)
-    while(data < state->data+state->size){
-      // prepare the syncData struct
-      sync.length = *(int *)data;
-      data+=sizeof(int);
-      sync.objectID = *(int*)data;
-      data+=sizeof(int);
-      sync.classID = *(int*)data;
-      data+=sizeof(int);
-      sync.data = data;
-      data+=sync.length;
-
-      if(!it || it->objectID!=sync.objectID){
-        // bad luck ;)
-        // delete the synchronisable (obviously seems to be deleted on the server)
-        while(it && it->objectID!=sync.objectID)
-          removeObject(it);
-
-
-        if(!it){
-          //COUT(4) << "loadSnapshot:\tclassid: " << sync.classID << ", name: " << ID((unsigned int) sync.classID)->getName() << std::endl;
-          ///sigsegv may happen here again for some reason
-          ///sigsegv is receved after the COUT(4) above
-          orxonox::Identifier* id = ID((unsigned int)sync.classID);
-          if(!id){
-            COUT(3) << "We could not identify a new object; classid: " << sync.classID << " uint: " << (unsigned int)sync.classID << " objectID: " << sync.objectID << " size: " << sync.length << std::endl;
-            return false; // most probably the gamestate is corrupted
-          }
-          Synchronisable *no = dynamic_cast<Synchronisable *>(id->fabricate());
-          COUT(4) << "loadsnapshot: classid: " << sync.classID << " objectID: " << sync.objectID << " length: " << sync.length << std::endl;
-          if(!no){
-            COUT(2) << "coudl not frabricate classid: " << sync.classID << " objectID: " << sync.objectID << " identifier: " << id << std::endl;
-            break;
-          }
-          no->objectID=sync.objectID;
-          no->classID=sync.classID;
-          // update data and create object/entity...
-          if( !no->updateData(sync) ){
-            COUT(1) << "We couldn't update the object: " << sync.objectID << std::endl;
-            return false;
-          }
-          if( !no->create() )
-          {
-            COUT(1) << "We couldn't manifest (create() ) the object: " << sync.objectID << std::endl;
-          }
-          it=orxonox::ObjectList<Synchronisable>::end();
-        }
-      } else {
-        // we have our object
-        if(! it->updateData(sync))
-        {
-          COUT(1) << "We couldn't update objectID: " \
-          << sync.objectID << "; classID: " << sync.classID << std::endl;
-        }
-      }
-      ++it;
-    }
-
-    return true;
-  }
-
-  GameState *GameStateClient::getPartialSnapshot(){
-    //std::cout << "begin getSnapshot" << std::endl;
-    //the size of the gamestate
-    int totalsize=0;
-    int memsize=0;
-    //the size of one specific synchronisable
-    int tempsize=0;
-    // get the start of the Synchronisable list
-    orxonox::Iterator<Synchronisable> it;
-    // struct for return value of Synchronisable::getData()
-    syncData sync;
-
-    GameState *retval=new GameState; //return value
-//     retval->id=reference->id;
-    if(gameStateMap.size()!=0)
-      retval->id=(--gameStateMap.end())->second->id;
-    retval->diffed=false;
-    retval->complete=false;
-    COUT(4) << "G.ST.Client: producing partial gamestate with id: " << retval->id << std::endl;
-    // offset of memory functions
-    int offset=0, size=0;
-    // get total size of gamestate
-    for(it = orxonox::ObjectList<Synchronisable>::start(); it; ++it){
-      if(!it->getBacksync())
-        continue;
-      size+=it->getSize(); // size of the actual data of the synchronisable
-      size+=3*sizeof(int); // size of datasize, classID and objectID
-      COUT(5) << "getpartialsnapshot: size: " << size << std::endl;
-    }
-    //retval->data = (unsigned char*)malloc(size);
-    if(size==0)
-      return NULL;
-    retval->data = new unsigned char[size];
-    if(!retval->data){
-      COUT(2) << "GameStateClient: could not allocate memory" << std::endl;
-      return NULL;
-    }
-    memsize=size;
-    // go through all Synchronisables
-    for(it = orxonox::ObjectList<Synchronisable>::start(); it; ++it){
-      if(!it->getBacksync())
-        continue;
-      //get size of the synchronisable
-      tempsize=it->getSize();
-      // add place for data and 3 ints (length,classid,objectid)
-      totalsize+=tempsize+3*sizeof(int);
-      // allocate+tempsize additional space
-      if(totalsize > size){
-        COUT(3) << "G.St.Cl: need additional memory" << std::endl;
-      }
-
-      // run Synchronisable::getData with offset and additional place for 3 ints in between (for ids and length)
-      sync=it->getData((retval->data)+offset+3*sizeof(int));
-      memcpy(retval->data+offset, (void *)&(sync.length), sizeof(int));
-      memcpy(retval->data+offset+sizeof(int), (void *)&(sync.objectID), sizeof(int));
-      memcpy(retval->data+offset+2*sizeof(int), (void *)&(sync.classID), sizeof(int));
-      // increase data pointer
-      offset+=tempsize+3*sizeof(int);
-    }
-    retval->size=totalsize;
-    COUT(5) << "G.ST.Cl: Gamestate size: " << totalsize << std::endl;
-    COUT(5) << "G.ST.Cl: 'estimated' Gamestate size: " << size << std::endl;
-    return retval;
-  }
-
-
-  GameState *GameStateClient::undiff(GameState *old, GameState *diff) {
-    if(!old || !diff)
-      return NULL;
-    unsigned char *ap = old->data, *bp = diff->data;
-    int of=0; // pointers offset
-    int dest_length=0;
-    /*if(old->size>=diff->size)
-      dest_length=old->size;
-    else*/
-      dest_length=diff->size;
-//     unsigned char *dp = (unsigned char *)malloc(dest_length*sizeof(unsigned char));
-    if(dest_length==0)
-      return NULL;
-    unsigned char *dp = new unsigned char[dest_length*sizeof(unsigned char)];
-    while(of<old->size && of<diff->size){
-      *(dp+of)=*(ap+of)^*(bp+of); // do the xor
-      ++of;
-    }
-    if(old->size!=diff->size){ // do we have to fill up ?
-      unsigned char n=0;
-      if(old->size<diff->size){
-        while(of<dest_length){
-          *(dp+of)=n^*(bp+of);
-          of++;
-        }
-      } /*else{
-        while(of<dest_length){
-          *(dp+of)=*(ap+of)^n;
-          of++;
-        }
-      }*/
-    }
-    // should be finished now
-    // FIXME: is it true or false now? (struct has changed, producing warnings)
-    GameState *r = new GameState;
-    r->id = diff->id;
-    r->size = dest_length;
-    r->base_id = old->id;
-    r->diffed = false;
-    r->data = dp;
-    r->complete = true;
-    return r;
-  }
-
-
-
-  GameStateCompressed *GameStateClient::compress_(GameState *a) {
-    if(!a)
-      return NULL;
-    int size = a->size;
-
-    uLongf buffer = (uLongf)((a->size + 12)*1.01)+1;
-    if(buffer==0)
-      return NULL;
-    unsigned char *dest = new unsigned char[buffer];
-    int retval;
-    retval = compress( dest, &buffer, a->data, (uLong)size );
-
-    switch ( retval ) {
-      case Z_OK: COUT(5) << "G.St.Cl: compress: successfully compressed" << std::endl; break;
-      case Z_MEM_ERROR: COUT(1) << "G.St.Cl: compress: not enough memory available in gamestate.compress" << std::endl;
-      return NULL;
-      case Z_BUF_ERROR: COUT(2) << "G.St.Cl: compress: not enough memory available in the buffer in gamestate.compress" << std::endl;
-      return NULL;
-      case Z_DATA_ERROR: COUT(2) << "G.St.Cl: compress: data corrupted in gamestate.compress" << std::endl;
-      return NULL;
-    }
-
-    GameStateCompressed *compressedGamestate = new GameStateCompressed;
-    compressedGamestate->compsize = buffer;
-    compressedGamestate->normsize = size;
-    compressedGamestate->id = a->id;
-    compressedGamestate->data = dest;
-    compressedGamestate->diffed = a->diffed;
-    compressedGamestate->complete = a->complete;
-    compressedGamestate->base_id = a->base_id;
-    return compressedGamestate;
-  }
-
-
-  GameState *GameStateClient::decompress(GameStateCompressed *a) {
-    //COUT(4) << "GameStateClient: uncompressing gamestate. id: " << a->id << ", baseid: " << a->base_id << ", normsize: " << a->normsize << ", compsize: " << a->compsize << std::endl;
-    int normsize = a->normsize;
-    int compsize = a->compsize;
-    int bufsize;
-    if(normsize < compsize)
-      bufsize = compsize;
-    else
-      bufsize = normsize;
-//     unsigned char* dest = (unsigned char*)malloc( bufsize );
-    if(bufsize==0)
-      return NULL;
-    unsigned char *dest = new unsigned char[bufsize];
-    int retval;
-    uLongf length=normsize;
-    //std::cout << "gamestateclient" << std::endl;
-    //std::cout << "normsize " << a.normsize << " compsize " << a.compsize << " " << bufsize << std::endl;
-    retval = uncompress( dest, &length, a->data, (uLong)compsize );
-    //std::cout << "length " << length << std::endl;
-    switch ( retval ) {
-      case Z_OK: COUT(5) << "successfully decompressed" << std::endl; break;
-      case Z_MEM_ERROR: COUT(1) << "not enough memory available" << std::endl; return NULL;
-      case Z_BUF_ERROR: COUT(2) << "not enough memory available in the buffer" << std::endl; return NULL;
-      case Z_DATA_ERROR: COUT(2) << "data corrupted (zlib)" << std::endl; return NULL;
-    }
-
-    GameState *gamestate = new GameState;
-    gamestate->id = a->id;
-    gamestate->size = normsize;
-    gamestate->data = dest;
-    gamestate->base_id = a->base_id;
-    gamestate->diffed = a->diffed;
-    gamestate->complete = a->complete;
-
-
-    return gamestate;
-  }
-
-  GameState *GameStateClient::decode(GameState *old, GameStateCompressed *diff) {
-    COUT(5) << "using diffed gamestate" << std::endl;
-    GameState *t = decode(diff);
-    if(!t)
-      return NULL;
-    GameState *r = undiff(old, t);
-    delete[] t->data;
-    delete t;
-    return r;
-  }
-
-  GameState *GameStateClient::decode(GameStateCompressed *x) {
-    GameState *t = decompress(x);
-    delete[] x->data;
-    delete x;
-    return t;
-  }
-
-  void GameStateClient::cleanup(){
-    std::map<int, GameState*>::iterator temp, it = gameStateMap.begin();
-    while(it!=gameStateMap.end()){
-      if(it->first>=last_diff_)
-        break;
-      // otherwise delete that stuff
-      delete[] (*it).second->data;
-      delete (*it).second;
-      temp=it++;
-      gameStateMap.erase(temp);
-    }
-    tempGameState_=NULL;
-  }
-
-  void GameStateClient::printGameStateMap(){
-    std::map<int, GameState*>::iterator it;
-    COUT(4) << "gamestates: ";
-    for(it=gameStateMap.begin(); it!=gameStateMap.end(); it++){
-      COUT(4) << it->first << ":" << it->second << "|";
-    }
-    COUT(4) << std::endl;
-
-  }
-
-  bool GameStateClient::saveShipCache(){
-    if(myShip_==NULL)
-      myShip_ = orxonox::SpaceShip::getLocalShip();
-    if(myShip_){
-      //      unsigned char *data = new unsigned char[myShip_->getSize()];
-      int size=myShip_->getSize(0x3);
-      if(size==0)
-        return false;
-      unsigned char *data = new unsigned char [size];
-      shipCache_ = myShip_->getData(data, 0x1);
-      return true;
-    }else
-      return false;
-  }
-
-  bool GameStateClient::loadShipCache(){
-    if(myShip_){
-      myShip_->updateData(shipCache_, 0x2);
-      if(shipCache_.data){
-        delete[] shipCache_.data;
-      }
-      return true;
-    }else
-      return false;
-  }
-
-    //##### ADDED FOR TESTING PURPOSE #####
-  GameState* GameStateClient::testDecompress( GameStateCompressed* gc ) {
-    return decompress( gc );
-  }
-
-  GameState* GameStateClient::testUndiff( GameState* g_old, GameState* g_diffed ) {
-    return undiff( g_old, g_diffed );
-  }
-  //##### ADDED FOR TESTING PURPOSE #####
-
-
-}
-
Index: code/trunk/src/network/GameStateClient.h
===================================================================
--- code/trunk/src/network/GameStateClient.h	(revision 1639)
+++ 	(revision )
@@ -1,100 +1,0 @@
-/*
- *   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
- *   Co-authors:
- *      Dumeni Manatschal
- *
- */
-
-//
-// C++ Interface: GameStateClient
-//
-// Description:
-//
-//
-// Author:  Oliver Scheuss, (C) 2007
-//
-// Copyright: See COPYING file that comes with this distribution
-//
-//
-#ifndef _GameStateClient_H__
-#define _GameStateClient_H__
-
-#include <map>
-// 
-#include "NetworkPrereqs.h"
-#include "OrxonoxPrereqs.h"
-#include "core/CorePrereqs.h"
-#include "PacketTypes.h"
-#include "Synchronisable.h"
-
-
-#define GAMESTATEID_INITIAL -1
-
-
-namespace network
-{
-  class GameStateClient
-  {
-  public:
-    GameStateClient();
-    ~GameStateClient();
-    
-    void addGameState(GameStateCompressed *gs);
-    int processGameState();
-    GameStateCompressed *popPartialGameState();
-    void cleanup();
-  private:
-    bool pushGameState(GameStateCompressed *compstate);
-    bool loadSnapshot(GameState *state);
-    GameState *getPartialSnapshot();
-    GameState *undiff(GameState *old, GameState *diff);
-    GameStateCompressed *compress_(GameState *a);
-    GameState *decompress(GameStateCompressed *a);
-    GameState *decode(GameState *old, GameStateCompressed *diff);
-    GameState *decode(GameStateCompressed *x);
-    void removeObject(orxonox::Iterator<Synchronisable> &it);
-    void printGameStateMap();
-    bool saveShipCache();
-    bool loadShipCache();
-
-    int           last_diff_;
-    int           last_gamestate_;
-    std::map<int, GameState *> gameStateMap;
-    GameStateCompressed *tempGameState_; // we save the received gamestates here during processQueue
-    orxonox::SpaceShip *myShip_;
-    syncData shipCache_;
-    
-    
-    
-    
-  public:
-    //#### ADDED FOR TESTING PURPOSE ####
-    GameState* testDecompress( GameStateCompressed* gc );
-    GameState* testUndiff( GameState* g_old, GameState* g_diffed );
-    //#### END TESTING PURPOSE ####
-  };
-
-}
-
-#endif /* _GameStateClient_H__ */
Index: code/trunk/src/network/GameStateManager.cc
===================================================================
--- code/trunk/src/network/GameStateManager.cc	(revision 1639)
+++ 	(revision )
@@ -1,531 +1,0 @@
-/*
- *   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, (C) 2007
- *   Co-authors:
- *      ...
- *
- */
-
-//
-// C++ Implementation: GameStateManager
-//
-// Description:
-//
-//
-// Author:  Oliver Scheuss, (C) 2007
-//
-// Copyright: See COPYING file that comes with this distribution
-//
-//
-
-#include "GameStateManager.h"
-
-#include <utility>
-#include <iostream>
-#include <zlib.h>
-#include <assert.h>
-#include <string.h>
-
-#include "core/CoreIncludes.h"
-#include "core/BaseObject.h"
-#include "ClientInformation.h"
-#include "Synchronisable.h"
-
-namespace network
-{
-  GameStateManager::GameStateManager(ClientInformation *head) {
-    id_=0;
-    head_=head;
-  }
-
-  GameStateManager::~GameStateManager() {
-  }
-
-  void GameStateManager::update(){
-    cleanup();
-    reference = getSnapshot();
-    COUT(4) << "inserting gamestate: " << reference << std::endl;
-    gameStateMap.insert(std::pair<int, GameState*>(id_, reference));
-    gameStateUsed[id_]=0;
-    printGameStates();
-    return;
-  }
-
-  void GameStateManager::addGameState(GameStateCompressed *gs, int clientID){
-    if(!gs)
-      return;
-    std::map<int, GameStateCompressed*>::iterator it = gameStateQueue.find(clientID);
-    if(it!=gameStateQueue.end()){
-      // delete obsolete gamestate
-      delete[] it->second->data;
-      delete it->second;
-    }
-    gameStateQueue[clientID] = gs;
-    return;
-  }
-
-  void GameStateManager::processGameStates(){
-    std::map<int, GameStateCompressed*>::iterator it;
-    // now push only the most recent gamestates we received (ignore obsolete ones)
-    for(it = gameStateQueue.begin(); it!=gameStateQueue.end(); it++){
-      pushGameState(it->second, it->first);
-    }
-    // now clear the queue
-    gameStateQueue.clear();
-  }
-
-
-  /**
-   * this function is used to keep the memory usage low
-   * it tries to delete all the unused gamestates
-   *
-   *
-   */
-  void GameStateManager::cleanup(){
-    std::map<int,int>::iterator it = gameStateUsed.begin();
-    while(it!=gameStateUsed.end()){
-      if((id_-(*it).first)<KEEP_GAMESTATES)
-        break;
-      if( (*it).second <= 0 ){
-        COUT(5) << "GameStateManager: deleting gamestate with id: " << (*it).first << ", uses: " << (*it).second << std::endl;
-        std::map<int, GameState *>::iterator tempit = gameStateMap.find((*it).first);
-        if( tempit != gameStateMap.end() ){
-          GameState *temp = tempit->second;
-          if(temp){
-            delete[] gameStateMap[(*it).first]->data;
-            delete gameStateMap[(*it).first];
-            gameStateMap.erase((*it).first);
-          }
-        }
-        gameStateUsed.erase(it++);
-        continue;
-      }/*else if(id_-it->first<=KEEP_GAMESTATES){  //as soon as we got a used gamestate break here because we could use newer gamestates in future but only if we do not exceed KEEP_GAMESTATES # of gamestates in cache
-        COUT(4) << "breaking " << std::endl;
-        break;
-      }*/
-      it++;
-    }
-  }
-
-  GameStateCompressed *GameStateManager::popGameState(int clientID) {
-    //why are we searching the same client's gamestate id as we searched in
-    //Server::sendGameState?
-    int gID = head_->findClient(clientID)->getGamestateID();
-    COUT(4) << "G.St.Man: popgamestate: sending gstate_id: " << id_ << " diffed from: " << gID << std::endl;
-//     COUT(3) << "gamestatemap: " << &gameStateMap << std::endl;
-    //chose wheather the next gamestate is the first or not
-    if(gID != GAMESTATEID_INITIAL){
-      // TODO something with the gamestatemap is wrong
-      GameState *client=NULL;
-      std::map<int, GameState*>::iterator it = gameStateMap.find(gID);
-      if(it!=gameStateMap.end())
-        client = it->second;
-      GameState *server = reference;
-      //COUT(4) << "client: " << client << " server: " << server << " gamestatemap: " << &gameStateMap << " size: " << server->size << std::endl;
-      //FIXME complains about precision loss on int conversion
-//       COUT(4) << "client: " << (client!=0 ? client->id : (int)client) << " server: " << server->id << " gamestatemap: " << &gameStateMap << " size: " << server->size << std::endl;
-      if(client)
-        return encode(client, server);
-      else
-        return encode(server);
-    } else {
-      COUT(4) << "we got a GAMESTATEID_INITIAL for clientID: " << clientID << std::endl;
-      GameState *server = reference;
-//       ackGameState(clientID, reference->id);
-      return encode(server);
-      // return an undiffed gamestate and set appropriate flags
-    }
-  }
-
-  bool GameStateManager::pushGameState( GameStateCompressed *gs, int clientID ){
-    GameState *ugs = decompress(gs);
-    delete[] gs->data;
-    delete gs;
-    bool result = loadPartialSnapshot(ugs, clientID);
-    delete[] ugs->data;
-    delete ugs;
-    return result;
-  }
-
-  /**
-  * This function goes through the whole list of synchronisables and
-  * saves all the synchronisables to a flat "list".
-  * @return struct of type gamestate containing the size of the whole gamestate and a pointer linking to the flat list
-  */
-  GameState *GameStateManager::getSnapshot()
-  {
-    //std::cout << "begin getSnapshot" << std::endl;
-    //the size of the gamestate
-    int totalsize=0;
-    int memsize=0;
-    //the size of one specific synchronisable
-    int tempsize=0;
-    // get the start of the Synchronisable list
-    orxonox::Iterator<Synchronisable> it;
-    // struct for return value of Synchronisable::getData()
-    syncData sync;
-
-    GameState *retval=new GameState; //return value
-    retval->id=++id_;
-    COUT(4) << "G.ST.Man: producing gamestate with id: " << retval->id << std::endl;
-    // offset of memory functions
-    int offset=0, size=0;
-    // get total size of gamestate
-    for(it = orxonox::ObjectList<Synchronisable>::start(); it; ++it){
-      size+=it->getSize(); // size of the actual data of the synchronisable
-      size+=3*sizeof(int); // size of datasize, classID and objectID
-    }
-    //retval->data = (unsigned char*)malloc(size);
-    if(size==0)
-      return NULL;
-    retval->data = new unsigned char[size];
-    if(!retval->data){
-      COUT(2) << "GameStateManager: could not allocate memory" << std::endl;
-      return NULL;
-    }
-    memsize=size;
-    // go through all Synchronisables
-    for(it = orxonox::ObjectList<Synchronisable>::start(); it; ++it){
-      //get size of the synchronisable
-      tempsize=it->getSize();
-      // add place for data and 3 ints (length,classid,objectid)
-      totalsize+=tempsize+3*sizeof(int);
-      // allocate+tempsize additional space
-      if(totalsize > size){
-        COUT(3) << "G.St.Man: need additional memory" << std::endl;
-//         if(tempsize < 1000){
-//           retval->data = (unsigned char *)realloc((void *)retval->data, totalsize+1000);
-//           memsize+=1000;
-//         } else {
-//           retval->data = (unsigned char *)realloc((void *)retval->data, totalsize+1000);
-//           memsize+=tempsize+1000;
-//         }
-//         COUT(5) << "G.St.Man: additional space allocation finished" << std::endl;
-      }
-
-      // run Synchronisable::getData with offset and additional place for 3 ints in between (for ids and length)
-      sync=it->getData((retval->data)+offset+3*sizeof(int));
-      memcpy(retval->data+offset, (void *)&(sync.length), sizeof(int));
-      memcpy(retval->data+offset+sizeof(int), (void *)&(sync.objectID), sizeof(int));
-      memcpy(retval->data+offset+2*sizeof(int), (void *)&(sync.classID), sizeof(int));
-      // increase data pointer
-      offset+=tempsize+3*sizeof(int);
-    }
-    retval->size=totalsize;
-    //#### bugfix
-    retval->diffed = false;
-    retval->complete = true;
-    //std::cout << "end snapShot" << std::endl;
-    COUT(5) << "G.ST.Man: Gamestate size: " << totalsize << std::endl;
-    COUT(5) << "G.ST.Man: 'estimated' Gamestate size: " << size << std::endl;
-    return retval;
-  }
-
-  bool GameStateManager::loadPartialSnapshot(GameState *state, int clientID){
-    if(!state)
-      return false;
-    unsigned char *data=state->data;
-    COUT(4) << "loadSnapshot: loading gs: " << state->id << std::endl;
-    // get the start of the Synchronisable list
-    orxonox::Iterator<Synchronisable> it=orxonox::ObjectList<Synchronisable>::start();
-    syncData sync;
-    /*ClientInformation *client = head_->findClient(clientID);
-    if(client)
-      if(client->getPartialGamestateID()>state->id){
-        COUT(3) << "we received an obsolete partial gamestate" << std::endl;
-        return false;
-      }
-    else;*/
-        //what should we do now ??
-    // loop as long as we have some data ;)
-    while(data < state->data+state->size){
-      // prepare the syncData struct
-      sync.length = *(int *)data;
-      data+=sizeof(int);
-      sync.objectID = *(int*)data;
-      data+=sizeof(int);
-      sync.classID = *(int*)data;
-      if(sync.classID == 0) // TODO: remove this
-        COUT(3) << "received a classid 0" << std::endl;
-      data+=sizeof(int);
-      sync.data = data;
-      data+=sync.length;
-      COUT(5) << "objectID: " << sync.objectID << " classID: " << sync.classID << std::endl;
-      while(it && it->objectID!=sync.objectID)
-        ++it;
-
-
-      if(!it){
-        // the objectaber ich glaub die  does not exist yet
-        COUT(4) << "loadsnapshot: creating new object " << std::endl;
-        //COUT(4) << "loadSnapshot:\tclassid: " << sync.classID << ", name: " << ID((unsigned int) sync.classID)->getName() << std::endl;
-        orxonox::Identifier* id = ID((unsigned int)sync.classID);
-        if(!id){
-          COUT(4) << "We could not identify a new object; classid: " << sync.classID << std::endl;
-          continue;
-        }
-        Synchronisable *no = dynamic_cast<Synchronisable *>(id->fabricate());
-        COUT(4) << "loadpartialsnapshot (generating new object): classid: " << sync.classID << " objectID: " << sync.objectID << " length: " << sync.length << std::endl;
-        no->objectID=sync.objectID;
-        no->classID=sync.classID;
-        it=orxonox::ObjectList<Synchronisable>::end();
-        // update data and create object/entity...
-        if( !no->updateData(sync) )
-          COUT(1) << "We couldn't update the object: " << sync.objectID << std::endl;
-        if( !no->create() )
-          COUT(1) << "We couldn't manifest (create() ) the object: " << sync.objectID << std::endl;
-      }else{
-        // we have our object
-        COUT(4) << "loadpartialsnapshot: we found the appropriate object" << std::endl;
-        if(checkAccess(clientID, sync.objectID)){
-          if(! it->updateData(sync))
-            COUT(1) << "We couldn't update objectID: " \
-              << sync.objectID << "; classID: " << sync.classID << std::endl;
-        }else
-          COUT(4) << "loadPartialSnapshot: no access to change objectID: " << sync.objectID << std::endl;
-      }
-      ++it;
-    }
-    //client->setPartialGamestateID(state->id);
-    return true;
-  }
-
-
-  //##### ADDED FOR TESTING PURPOSE #####
-  GameStateCompressed* GameStateManager::testCompress( GameState* g ) {
-    return compress_( g );
-  }
-
-  GameState* GameStateManager::testDiff( GameState* a, GameState* b ) {
-    return diff( a, b );
-  }
-  //##### END TESTING PURPOSE #####
-
-  GameStateCompressed *GameStateManager::encode(GameState *a, GameState *b) {
-    COUT(5) << "G.St.Man: this will be a DIFFED gamestate" << std::endl;
-    GameState *r = diff(a,b);
-    GameStateCompressed *c = compress_(r);
-    delete[] r->data;
-    delete r;
-    return c;
-  }
-
-  GameStateCompressed *GameStateManager::encode(GameState *a) {
-    COUT(5) << "G.St.Man: encoding gamestate (compress)" << std::endl;
-    a->base_id=GAMESTATEID_INITIAL;
-    return compress_(a);
-    /*GameStateCompressed *g = new GameStateCompressed;
-    g->base_id = a->base_id;
-    g->id = a->id;
-    g->diffed = a->diffed;
-    g->data = a->data;
-    g->normsize = a->size;
-    g->compsize = a->size;
-    return g;*/
-  }
-
-  GameState *GameStateManager::diff(GameState *alt, GameState *neu) {
-    unsigned char *ap = alt->data, *bp = neu->data;
-    int of=0; // pointers offset
-    int dest_length=0;
-    /*if(alt->size>neu->size)
-      dest_length=alt->size;
-    else*/
-      dest_length=neu->size;
-    if(dest_length==0)
-      return NULL;
-    //unsigned char *dp = (unsigned char *)malloc(dest_length*sizeof(unsigned char));
-    unsigned char *dp = new unsigned char[dest_length*sizeof(unsigned char)];
-    while(of<alt->size && of<neu->size){
-      *(dp+of)=*(ap+of)^*(bp+of); // do the xor
-      ++of;
-    }
-    if(alt->size!=neu->size){ // do we have to fill up ?
-      unsigned char n=0;
-      if(alt->size<neu->size){
-        while(of<dest_length){
-          *(dp+of)=n^*(bp+of);
-          of++;
-        }
-      } /*else{
-        while(of<dest_length){
-          *(dp+of)=*(ap+of)^n;
-          of++;
-        }
-      }*/
-    }
-
-    GameState *r = new GameState;
-    r->id = neu->id;
-    r->size = dest_length;
-    r->diffed = true;
-    r->base_id = alt->id;
-    r->data = dp;
-    r->complete = true;
-    return r;
-  }
-
-  GameStateCompressed *GameStateManager::compress_(GameState *a) {
-    //COUT(4) << "G.St.Man: compressing gamestate" << std::endl;
-
-    //COUT(4) << "G.St.Man: a: id: " << a->id << " base_id: " << a->base_id << " size: " << a->size << " diffed: " << a->diffed << std::endl;
-    int size = a->size;
-
-    uLongf buffer = (uLongf)((a->size + 12)*1.01)+1;
-    //COUT(4) << "size: " << size << ", buffer: " << buffer << std::endl;
-    //unsigned char* dest = (unsigned char*)malloc( buffer );
-    if(buffer==0)
-      return NULL;
-    unsigned char *dest = new unsigned char[buffer];
-    //COUT(4) << "dest: " << dest << std::endl;
-    int retval;
-    //std::cout << "before ziped " << buffer << std::endl;
-    retval = compress( dest, &buffer, a->data, (uLong)size );
-    //COUT(4) << "bloablabla aft3er compress" << std::endl;
-    //std::cout << "after ziped " << buffer << std::endl;
-
-    switch ( retval ) {
-      case Z_OK: COUT(5) << "G.St.Man: compress: successfully compressed" << std::endl; break;
-      case Z_MEM_ERROR: COUT(1) << "G.St.Man: compress: not enough memory available in gamestate.compress" << std::endl;
-      return NULL;
-      case Z_BUF_ERROR: COUT(2) << "G.St.Man: compress: not enough memory available in the buffer in gamestate.compress" << std::endl;
-      return NULL;
-      case Z_DATA_ERROR: COUT(2) << "G.St.Man: compress: data corrupted in gamestate.compress" << std::endl;
-      return NULL;
-    }
-
-    GameStateCompressed *compressedGamestate = new GameStateCompressed;
-    compressedGamestate->compsize = buffer;
-//     std::cout << "compressedGamestate.compsize = buffer; " << buffer << std::endl;
-    compressedGamestate->normsize = size;
-//     std::cout << "compressedGamestate.normsize = size; " << size << std::endl;
-    compressedGamestate->id = a->id;
-    compressedGamestate->data = dest;
-    compressedGamestate->diffed = a->diffed;
-    compressedGamestate->complete = a->complete;
-    compressedGamestate->base_id = a->base_id;
-    //COUT(5) << "G.St.Man: saved compressed data in GameStateCompressed:" << std::endl;
-    return compressedGamestate;
-  }
-
-  GameState *GameStateManager::decompress(GameStateCompressed *a) {
-    //COUT(4) << "GameStateClient: uncompressing gamestate. id: " << a->id << ", baseid: " << a->base_id << ", normsize: " << a->normsize << ", compsize: " << a->compsize << std::endl;
-    int normsize = a->normsize;
-    int compsize = a->compsize;
-    int bufsize;
-    if(normsize < compsize)
-      bufsize = compsize;
-    else
-      bufsize = normsize;
-//     unsigned char* dest = (unsigned char*)malloc( bufsize );
-    if(bufsize==0)
-      return NULL;
-    unsigned char *dest = new unsigned char[bufsize];
-    int retval;
-    uLongf length=normsize;
-    //std::cout << "gamestateclient" << std::endl;
-    //std::cout << "normsize " << a.normsize << " compsize " << a.compsize << " " << bufsize << std::endl;
-    retval = uncompress( dest, &length, a->data, (uLong)compsize );
-    //std::cout << "length " << length << std::endl;
-    switch ( retval ) {
-      case Z_OK: COUT(5) << "successfully decompressed" << std::endl; break;
-      case Z_MEM_ERROR: COUT(1) << "not enough memory available" << std::endl; return NULL;
-      case Z_BUF_ERROR: COUT(2) << "not enough memory available in the buffer" << std::endl; return NULL;
-      case Z_DATA_ERROR: COUT(2) << "data corrupted (zlib)" << std::endl; return NULL;
-    }
-
-    GameState *gamestate = new GameState;
-    gamestate->id = a->id;
-    gamestate->size = normsize;
-    gamestate->data = dest;
-    gamestate->base_id = a->base_id;
-    gamestate->diffed = a->diffed;
-    gamestate->complete = a->complete;
-
-
-    return gamestate;
-  }
-
-
-  void GameStateManager::ackGameState(int clientID, int gamestateID) {
-    ClientInformation *temp = head_->findClient(clientID);
-    if(temp==0)
-      return;
-    int curid = temp->getGamestateID();
-
-    if(gamestateID == GAMESTATEID_INITIAL){
-      temp->setGameStateID(GAMESTATEID_INITIAL);
-      if(curid!=GAMESTATEID_INITIAL){
-        assert(gameStateUsed.find(curid)!=gameStateUsed.end());
-        --(gameStateUsed.find(curid)->second);
-      }
-      return;
-    }
-    if(curid > gamestateID)
-      // the network packets got messed up
-      return;
-    COUT(4) << "acking gamestate " << gamestateID << " for clientid: " << clientID << " curid: " << curid << std::endl;
-    // decrease usage of gamestate and save it
-//     deleteUnusedGameState(curid);
-    //increase gamestateused
-    std::map<int, int>::iterator it = gameStateUsed.find(curid);
-    if(curid!=GAMESTATEID_INITIAL){
-      if(it!=gameStateUsed.end())
-        --(it->second);
-    }
-    it = gameStateUsed.find(gamestateID);
-    if(it!=gameStateUsed.end()){
-      ++(it->second);
-      temp->setGameStateID(gamestateID);
-    }
-    /*
-    GameState *old = clientGameState[clientID];
-    deleteUnusedGameState(old);
-    clientGameState[clientID]=idGameState[gamestateID];*/
-  }
-
-  bool GameStateManager::printGameStates() {
-    std::map<int, GameState*>::iterator it;
-    COUT(4) << "gamestates: ";
-    for(it = gameStateMap.begin(); it!=gameStateMap.end(); it++){
-      COUT(4) << (*it).first << ":" << (*it).second << " | ";
-    }
-    COUT(4) << std::endl;
-    return true;
-  }
-
-  bool GameStateManager::checkAccess(int clientID, int objectID){
-    // currently we only check, wheter the object is the clients spaceship
-//     return head_->findClient(objectID)->getShipID()==objectID;
-    return true; // TODO: change this
-  }
-
-  void GameStateManager::removeClient(ClientInformation* client){
-    if(!client)
-      return;
-    if(client->getGamestateID()>=0)
-      gameStateUsed[client->getGamestateID()]--;
-    head_->removeClient(client->getID());
-  }
-
-}
Index: code/trunk/src/network/GameStateManager.h
===================================================================
--- code/trunk/src/network/GameStateManager.h	(revision 1639)
+++ 	(revision )
@@ -1,113 +1,0 @@
-/*
- *   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, (C) 2007
- *   Co-authors:
- *      ...
- *
- */
-
-//
-// C++ Interface: GameStateManager
-//
-// Description:
-//
-//
-// Author:  Oliver Scheuss, (C) 2007
-//
-// Copyright: See COPYING file that comes with this distribution
-//
-//
-#ifndef _GameStateManager_H__
-#define _GameStateManager_H__
-
-#include "NetworkPrereqs.h"
-
-#include <map>
-
-#include "PacketTypes.h"
-
-namespace network
-{
-
-#define KEEP_GAMESTATES 10
-
-  /**
-  * This Class implements a manager for gamestates:
-  * - creating snapshots of gamestates
-  * - writing gamestates to universe
-  * - diffing gamestates ?
-  *
-  * EN/DECODATION:
-  * a: last Gamestate a client has received
-  * b: new Gamestate
-  * x: diffed and compressed gamestate
-  * x=(a^b)
-  * b=(a^x)
-  * diff(a,diff(a,x))=x (hope this is correct)
-  * @author Oliver Scheuss
-  */
-  class GameStateManager{
-  public:
-    GameStateManager(ClientInformation *head);
-    ~GameStateManager();
-    
-    void addGameState(GameStateCompressed *gs, int clientID);
-    void processGameStates();
-    
-    void update();
-    GameStateCompressed *popGameState(int clientID);
-    void ackGameState(int clientID, int gamestateID);
-    void removeClient(ClientInformation *client);
-    private:
-    bool pushGameState(GameStateCompressed *gs, int clientID);
-    void cleanup(); // "garbage handler"
-    GameState *getSnapshot();
-    bool loadPartialSnapshot(GameState *state, int clientID);
-    GameStateCompressed *encode(GameState *a, GameState *b);
-    GameStateCompressed *encode(GameState *a);
-    GameState *diff(GameState *alt, GameState *neu);
-    GameStateCompressed *compress_(GameState *a);
-    GameState *decompress(GameStateCompressed *a);
-    bool printGameStates();
-    bool checkAccess(int clientID, int objectID);
-
-    std::map<int, GameState*> gameStateMap; //map gsID to gamestate*
-    std::map<int, int> gameStateUsed; // save the number of clients, that use the specific gamestate
-    std::map<int, GameStateCompressed*> gameStateQueue;
-    GameState *reference;
-    ClientInformation *head_;
-    int id_;
-    
-    
-    
-    
-  public:
-    //#### ADDED FOR TESTING PURPOSE ####
-    GameStateCompressed* testCompress( GameState* g );
-    GameState* testDiff( GameState* a, GameState* b );
-  //#### END TESTING PURPOSE ####
-  };
-
-}
-
-#endif /* _GameStateManager_H__ */
Index: code/trunk/src/network/GamestateClient.cc
===================================================================
--- code/trunk/src/network/GamestateClient.cc	(revision 1735)
+++ code/trunk/src/network/GamestateClient.cc	(revision 1735)
@@ -0,0 +1,161 @@
+/*
+ *   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
+ *   Co-authors:
+ *      Dumeni Manatschal
+ *
+ */
+
+#include "GamestateClient.h"
+
+#include <zlib.h>
+
+#include "core/CoreIncludes.h"
+#include "core/BaseObject.h"
+#include "Synchronisable.h"
+
+
+namespace network
+{
+  struct GameStateItem{
+    packet::Gamestate *state;
+    int id;
+  };
+
+  GamestateClient::GamestateClient() {
+    COUT(5) << "this: " << this << std::endl;
+    last_diff_=0;
+    last_gamestate_=GAMESTATEID_INITIAL-1;
+    tempGamestate_=NULL;
+    myShip_=NULL;
+  }
+
+  GamestateClient::~GamestateClient() {
+  }
+
+  bool GamestateClient::ack(int gamestateID, int clientID){
+    return true;
+  }
+
+  bool GamestateClient::add(packet::Gamestate *gs, int clientID){
+    if(tempGamestate_!=NULL){
+      //delete the obsolete gamestate
+      if(tempGamestate_->getID()>gs->getID())
+        return false;
+      delete tempGamestate_;
+    }
+    tempGamestate_=gs;
+    return true;
+  }
+  
+  int GamestateClient::processGamestates(){
+    if(tempGamestate_==NULL)
+      return 0;
+    int id = GAMESTATEID_INITIAL;
+    bool b = saveShipCache();
+    if(processGamestate(tempGamestate_)){
+      if(b)
+        loadShipCache();
+      id = tempGamestate_->getID();
+    }
+    cleanup();
+    return id;
+  }
+
+
+  /**
+  * This function removes a Synchronisable out of the universe
+  * @param it iterator of the list pointing to the object
+  * @return iterator pointing to the next object in the list
+  */
+  void GamestateClient::removeObject(orxonox::Iterator<Synchronisable> &it) {
+    orxonox::Iterator<Synchronisable> temp=it;
+    ++it;
+    delete  *temp;
+  }
+
+  packet::Gamestate *GamestateClient::getGamestate(){
+    packet::Gamestate *gs = new packet::Gamestate();
+    gs->collectData(GAMESTATEID_INITIAL);
+    return gs;
+  }
+
+  void GamestateClient::cleanup(){
+    std::map<int, packet::Gamestate*>::iterator temp, it = gamestateMap_.begin();
+    while(it!=gamestateMap_.end()){
+      if(it->first>=last_diff_)
+        break;
+      // otherwise delete that stuff
+      delete (*it).second;
+      temp=it++;
+      gamestateMap_.erase(temp);
+    }
+    tempGamestate_=NULL;
+  }
+
+  void GamestateClient::printGamestateMap(){
+    std::map<int, packet::Gamestate*>::iterator it;
+    COUT(4) << "gamestates: ";
+    for(it=gamestateMap_.begin(); it!=gamestateMap_.end(); it++){
+      COUT(4) << it->first << ":" << it->second << "|";
+    }
+    COUT(4) << std::endl;
+
+  }
+
+  bool GamestateClient::saveShipCache(){
+    if(myShip_==NULL)
+      myShip_ = orxonox::SpaceShip::getLocalShip();
+    if(myShip_){
+      //      unsigned char *data = new unsigned char[myShip_->getSize()];
+      int size=myShip_->getSize(0x1);
+      if(size==0)
+        return false;
+      shipCache_ = new unsigned char [size];
+      unsigned char *temp = shipCache_;
+      if(!myShip_->getData2(temp, 0x1))
+        COUT(3) << "could not save shipCache" << std::endl;
+      return true;
+    }else
+      return false;
+  }
+
+  bool GamestateClient::loadShipCache(){
+    if(myShip_ && shipCache_){
+      unsigned char *temp = shipCache_;
+      myShip_->updateData(temp, 0x2);
+      delete shipCache_;
+      return true;
+    }else
+      return false;
+  }
+
+  bool GamestateClient::processGamestate(packet::Gamestate *gs){
+    assert(gs->decompressData());
+    if(gs->isDiffed())
+      assert(gs->undiff(gamestateMap_[gs->getBaseID()]));
+    return gs->spreadData();
+  }
+
+}
+
Index: code/trunk/src/network/GamestateClient.h
===================================================================
--- code/trunk/src/network/GamestateClient.h	(revision 1735)
+++ code/trunk/src/network/GamestateClient.h	(revision 1735)
@@ -0,0 +1,85 @@
+/*
+ *   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
+ *   Co-authors:
+ *      Dumeni Manatschal
+ *
+ */
+
+//
+// C++ Interface: GameStateClient
+//
+// Description:
+//
+//
+// Author:  Oliver Scheuss, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+#ifndef _GamestateClient_H__
+#define _GamestateClient_H__
+
+#include <map>
+// 
+#include "NetworkPrereqs.h"
+#include "core/CorePrereqs.h"
+#include "packet/Gamestate.h"
+#include "objects/SpaceShip.h"
+#include "GamestateHandler.h"
+
+#define GAMESTATEID_INITIAL -1
+
+namespace network
+{
+  class GamestateClient: public GamestateHandler
+  {
+  public:
+    GamestateClient();
+    ~GamestateClient();
+    
+    bool add(packet::Gamestate *gs, int clientID);
+    bool ack(int gamestateID, int clientID);
+    
+    int processGamestates();
+    packet::Gamestate *getGamestate();
+    void cleanup();
+  private:
+    bool processGamestate(packet::Gamestate *gs);
+    void removeObject(orxonox::Iterator<Synchronisable> &it);
+    void printGamestateMap();
+    bool saveShipCache();
+    bool loadShipCache();
+
+    int           last_diff_;
+    int           last_gamestate_;
+    std::map<int, packet::Gamestate *> gamestateMap_;
+    packet::Gamestate *tempGamestate_; // we save the received gamestates here during processQueue
+    orxonox::SpaceShip *myShip_;
+    unsigned char *shipCache_;
+    
+  };
+
+}
+
+#endif /* _GamestateClient_H__ */
Index: code/trunk/src/network/GamestateHandler.cc
===================================================================
--- code/trunk/src/network/GamestateHandler.cc	(revision 1735)
+++ code/trunk/src/network/GamestateHandler.cc	(revision 1735)
@@ -0,0 +1,24 @@
+#include <assert.h>
+
+#include "GamestateHandler.h"
+#include "packet/Packet.h"
+
+namespace network {
+
+GamestateHandler *GamestateHandler::instance_=0;
+  
+GamestateHandler::GamestateHandler()
+{
+  assert(instance_==0);
+  instance_=this;
+}
+
+
+GamestateHandler::~GamestateHandler()
+{
+  instance_=0;
+}
+
+
+
+}//namespace network
Index: code/trunk/src/network/GamestateHandler.h
===================================================================
--- code/trunk/src/network/GamestateHandler.h	(revision 1735)
+++ code/trunk/src/network/GamestateHandler.h	(revision 1735)
@@ -0,0 +1,60 @@
+/*
+ *   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:
+ *      ...
+ *
+ */
+#ifndef NETWORKGAMESTATEHANDLER_H
+#define NETWORKGAMESTATEHANDLER_H
+
+#include <string>
+
+#include "NetworkPrereqs.h"
+#include "packet/Chat.h"
+
+namespace network {
+
+/**
+	@author Oliver Scheuss
+*/
+class GamestateHandler{
+  private:
+    virtual bool add(packet::Gamestate *gs, int clientID)=0;
+    virtual bool ack(int gamestateID, int clientID)=0;
+    
+    static GamestateHandler *instance_;
+    
+    
+  protected:
+    GamestateHandler();
+    ~GamestateHandler();
+    
+  public:
+    static bool addGamestate(packet::Gamestate *gs, int clientID){ return instance_->add(gs, clientID); }
+    static bool ackGamestate(int gamestateID, int clientID){ return instance_->ack(gamestateID, clientID); }
+};
+
+}
+
+#endif
Index: code/trunk/src/network/GamestateManager.cc
===================================================================
--- code/trunk/src/network/GamestateManager.cc	(revision 1735)
+++ code/trunk/src/network/GamestateManager.cc	(revision 1735)
@@ -0,0 +1,205 @@
+/*
+ *   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, (C) 2007
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+//
+// C++ Implementation: GameStateManager
+//
+// Description:
+//
+//
+// Author:  Oliver Scheuss, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+#include "GamestateManager.h"
+
+#include <utility>
+#include <iostream>
+#include <zlib.h>
+#include <assert.h>
+
+#include "core/CoreIncludes.h"
+#include "core/BaseObject.h"
+#include "ClientInformation.h"
+#include "Synchronisable.h"
+
+namespace network
+{
+  GamestateManager::GamestateManager() {
+    id_=0;
+  }
+
+  GamestateManager::~GamestateManager() {
+  }
+
+  bool GamestateManager::update(){
+    cleanup();
+    return getSnapshot();
+  }
+  
+  bool GamestateManager::add(packet::Gamestate *gs, int clientID){
+    assert(gs);
+    std::map<int, packet::Gamestate*>::iterator it = gamestateQueue.find(clientID);
+    if(it!=gamestateQueue.end()){
+      // delete obsolete gamestate
+      delete it->second;
+    }
+    gamestateQueue[clientID] = gs;
+    return true;
+  }
+  
+  bool GamestateManager::processGamestates(){
+    std::map<int, packet::Gamestate*>::iterator it;
+    // now push only the most recent gamestates we received (ignore obsolete ones)
+    for(it = gamestateQueue.begin(); it!=gamestateQueue.end(); it++){
+      assert(processGamestate(it->second));
+      delete it->second;
+    }
+    // now clear the queue
+    gamestateQueue.clear();
+    return true;
+  }
+  
+  
+  bool GamestateManager::getSnapshot(){
+    reference = new packet::Gamestate();
+    reference->collectData(++id_);
+    COUT(4) << "inserting gamestate: " << reference << std::endl;
+    gamestateMap.insert(std::pair<int, packet::Gamestate*>(id_, reference));
+    gamestateUsed[id_]=0;
+    return true;
+  }
+  
+  /**
+   * this function is used to keep the memory usage low
+   * it tries to delete all the unused gamestates
+   * 
+   * 
+   */
+  void GamestateManager::cleanup(){
+    std::map<int,int>::iterator it = gamestateUsed.begin();
+    while(it!=gamestateUsed.end()){
+      if((id_-(*it).first)<KEEP_GAMESTATES)
+        break;
+      if( (*it).second <= 0 ){
+        COUT(5) << "GameStateManager: deleting gamestate with id: " << (*it).first << ", uses: " << (*it).second << std::endl;
+        std::map<int, packet::Gamestate *>::iterator tempit = gamestateMap.find((*it).first);
+        if( tempit != gamestateMap.end() ){
+          packet::Gamestate *temp = tempit->second;
+          if(temp){
+            delete gamestateMap[(*it).first];
+            gamestateMap.erase((*it).first);
+          }
+        }
+        gamestateUsed.erase(it++);
+        continue;
+      }
+      it++;
+    }
+  }
+
+  packet::Gamestate *GamestateManager::popGameState(int clientID) {
+    //why are we searching the same client's gamestate id as we searched in
+    //Server::sendGameState?
+    int gID = ClientInformation::findClient(clientID)->getGamestateID();
+    COUT(4) << "G.St.Man: popgamestate: sending gstate_id: " << id_ << " diffed from: " << gID << std::endl;
+//     COUT(3) << "gamestatemap: " << &gameStateMap << std::endl;
+    //chose wheather the next gamestate is the first or not
+    if(gID != GAMESTATEID_INITIAL){
+      // TODO something with the gamestatemap is wrong
+      packet::Gamestate *client=NULL;
+      std::map<int, packet::Gamestate*>::iterator it = gamestateMap.find(gID);
+      if(it!=gamestateMap.end())
+        client = it->second;
+      packet::Gamestate *gs;
+      if(client)
+        gs = reference->diff(client);
+      else
+        gs = new packet::Gamestate(*reference);
+      gs->compressData();
+      return gs;
+    } else {
+      COUT(4) << "we got a GAMESTATEID_INITIAL for clientID: " << clientID << std::endl;
+//       ackGameState(clientID, reference->id);
+      return new packet::Gamestate(*reference);
+      // return an undiffed gamestate and set appropriate flags
+    }
+  }
+  
+  
+  bool GamestateManager::ack(int gamestateID, int clientID) {
+    ClientInformation *temp = ClientInformation::findClient(clientID);
+    if(temp==0)
+      return false;
+    int curid = temp->getGamestateID();
+    
+    if(gamestateID == GAMESTATEID_INITIAL){
+      temp->setGamestateID(GAMESTATEID_INITIAL);
+      if(curid!=GAMESTATEID_INITIAL){
+        assert(gamestateUsed.find(curid)!=gamestateUsed.end());
+        --(gamestateUsed.find(curid)->second);
+      }
+      return false;
+    }
+    if(curid > gamestateID)
+      // the network packets got messed up 
+      return true;
+    COUT(4) << "acking gamestate " << gamestateID << " for clientid: " << clientID << " curid: " << curid << std::endl;
+    // decrease usage of gamestate and save it
+//     deleteUnusedGameState(curid);
+    //increase gamestateused
+    std::map<int, int>::iterator it = gamestateUsed.find(curid);
+    if(curid!=GAMESTATEID_INITIAL){
+      if(it!=gamestateUsed.end())
+        --(it->second);
+    }
+    it = gamestateUsed.find(gamestateID);
+    if(it!=gamestateUsed.end()){
+      ++(it->second);
+      temp->setGamestateID(gamestateID);
+    }
+    return true;
+  }
+
+  void GamestateManager::removeClient(ClientInformation* client){
+    if(!client)
+      return;
+    if(client->getGamestateID()>=0)
+      gamestateUsed[client->getGamestateID()]--;
+    ClientInformation::removeClient(client->getID());
+  }
+  
+  bool GamestateManager::processGamestate(packet::Gamestate *gs){
+    assert(gs->decompressData());
+    assert(!gs->isDiffed());
+    return gs->spreadData();
+  }
+
+}
Index: code/trunk/src/network/GamestateManager.h
===================================================================
--- code/trunk/src/network/GamestateManager.h	(revision 1735)
+++ code/trunk/src/network/GamestateManager.h	(revision 1735)
@@ -0,0 +1,95 @@
+/*
+ *   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, (C) 2007
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+//
+// C++ Interface: GamestateManager
+//
+// Description:
+//
+//
+// Author:  Oliver Scheuss, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+#ifndef _GamestateManager_H__
+#define _GamestateManager_H__
+
+#include "NetworkPrereqs.h"
+#include "GamestateHandler.h"
+#include <map>
+
+#include "packet/Gamestate.h"
+
+namespace network
+{
+
+#define KEEP_GAMESTATES 10
+
+  /**
+  * This Class implements a manager for gamestates:
+  * - creating snapshots of gamestates
+  * - writing gamestates to universe
+  * - diffing gamestates
+  * EN/DECODATION:
+  * a: last Gamestate a client has received
+  * b: new Gamestate
+  * x: diffed and compressed gamestate
+  * x=(a^b)
+  * b=(a^x)
+  * diff(a,diff(a,x))=x (hope this is correct)
+  * @author Oliver Scheuss
+  */
+  class GamestateManager: public GamestateHandler{
+  public:
+    GamestateManager();
+    ~GamestateManager();
+    
+    bool add(packet::Gamestate *gs, int clientID);
+    bool processGamestates();
+    bool update();
+    packet::Gamestate *popGameState(int clientID);
+
+    bool getSnapshot();
+    
+    bool ack(int gamestateID, int clientID);
+    void removeClient(ClientInformation *client);
+    private:
+    void cleanup(); // "garbage handler"
+    bool processGamestate(packet::Gamestate *gs);
+    
+    std::map<int, packet::Gamestate*> gamestateMap; //map gsID to gamestate*
+    std::map<int, int> gamestateUsed; // save the number of clients, that use the specific gamestate
+    std::map<int, packet::Gamestate*> gamestateQueue;
+    packet::Gamestate *reference;
+    int id_;
+  };
+
+}
+
+#endif /* _GameStateManager_H__ */
Index: code/trunk/src/network/Host.cc
===================================================================
--- code/trunk/src/network/Host.cc	(revision 1735)
+++ code/trunk/src/network/Host.cc	(revision 1735)
@@ -0,0 +1,56 @@
+#include <assert.h>
+
+#include "Host.h"
+#include "packet/Packet.h"
+
+namespace network {
+
+Host *Host::instance_=0;
+  
+Host::Host()
+{
+  assert(instance_==0);
+  instance_=this;
+}
+
+
+Host::~Host()
+{
+  instance_=0;
+}
+
+bool Host::addPacket(ENetPacket *packet, int clientID){
+  if(instance_)
+    return instance_->queuePacket(packet, clientID);
+  else
+    return false;
+}
+
+
+// bool Host::chat(std::string& message){
+//   if(!instance_)
+//     return false;
+//   packet::Chat *c = new packet::Chat(message, getPlayerID());
+//   return instance_->sendChat(c);
+// }
+
+// bool Host::receiveChat(network::packet::Chat *message, unsigned int clientID){
+//   if(instance_)
+//     return instance_->processChat(message, clientID);
+//   else
+//     return false;
+// }
+
+int Host::getPlayerID(){ 
+  if(!instance_)
+    return 0;
+  return instance_->playerID();
+}
+
+// unsigned int Host::getShipID(){ 
+//   if(!instance_)
+//     assert(0);
+//   return instance_->shipID();
+// }
+
+}//namespace network
Index: code/trunk/src/network/Host.h
===================================================================
--- code/trunk/src/network/Host.h	(revision 1735)
+++ code/trunk/src/network/Host.h	(revision 1735)
@@ -0,0 +1,73 @@
+/*
+ *   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:
+ *      ...
+ *
+ */
+#ifndef NETWORKHOST_H
+#define NETWORKHOST_H
+
+#include <string>
+
+#include "NetworkPrereqs.h"
+#include "packet/Chat.h"
+
+namespace network {
+
+/**
+	@author Oliver Scheuss
+*/
+class Host{
+  private:
+    //TODO add theese functions or adequate
+    //virtual bool processChat(packet::Chat *message, unsigned int clientID)=0;
+    //virtual bool sendChat(packet::Chat *chat)=0;
+    virtual bool queuePacket(ENetPacket *packet, int clientID)=0;
+    virtual unsigned int shipID()=0;
+    virtual int playerID()=0;
+    
+    
+    
+  protected:
+    Host();
+    ~Host();
+    static Host *instance_;
+    
+  public:
+    static bool running(){return instance_!=0;}
+    static bool addPacket(ENetPacket *packet, int clientID=0);
+    //static bool chat(std::string& message);
+//     static bool receiveChat(packet::Chat *message, unsigned int clientID);
+    static int getPlayerID();
+    static unsigned int getShipID(){return instance_->shipID_;}
+    static void setClientID(unsigned int id){ instance_->clientID_ = id; }
+    static void setShipID(unsigned int id){ instance_->shipID_ = id; }
+  private:
+    unsigned int clientID_;
+    unsigned int shipID_;
+};
+
+}
+
+#endif
Index: code/trunk/src/network/NetworkPrereqs.h
===================================================================
--- code/trunk/src/network/NetworkPrereqs.h	(revision 1639)
+++ code/trunk/src/network/NetworkPrereqs.h	(revision 1735)
@@ -66,26 +66,24 @@
   class ClientInformation;
   class ConnectionManager;
-  class GameStateClient;
-  class GameStateManager;
+  class GamestateClient;
+  class GamestateManager;
+  class GamestateHandler;
   class PacketBuffer;
-  class PacketDecoder;
-  class PacketGenerator;
   class Server;
   class ServerFrameListener;
   class Synchronisable;
-  struct ack;
-  struct chat;
-  struct classid;
-  struct welcome;
-  struct connectRequest;
   struct ClientList;
-  struct GameState;
-  struct GameStateCompressed;
-  struct keyboard;
-  struct mouse;
   struct PacketEnvelope;
   struct QueueItem;
   struct syncData;
   struct synchronisableVariable;
+  namespace packet{
+    class Gamestate;
+    class Packet;
+    class Acknowledgement;
+    class ClassID;
+    class Welcome;
+    class Chat;
+  }
 }
 
Index: code/trunk/src/network/PacketDecoder.cc
===================================================================
--- code/trunk/src/network/PacketDecoder.cc	(revision 1639)
+++ 	(revision )
@@ -1,308 +1,0 @@
-/*
- *   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:
- *      Dumeni Manatschal, (C) 2007
- *   Co-authors:
- *      ...
- *
- */
-
-/*
-* Class contains functions to determine and decode incomming packages
-* ->don't read this without the class PacketGenerator, since they belong together
-*
-* Autor: Dumeni Manatschal
-*
-*/
-
-#include "PacketTypes.h"
-#include "PacketManager.h"
-
-#include <iostream>
-#include <string.h>
-
-#include "core/Debug.h"
-
-namespace network
-{
-
-  PacketDecoder::PacketDecoder(){}
-
-  PacketDecoder::~PacketDecoder(){}
-
-  //call this function out of an instance of PacketDecoder
-  //it will determine the type id and call the right decode function
-  bool PacketDecoder::elaborate( ENetPacket* packet, int clientId )
-  {
-    COUT(5) << "PacketDecoder: clientId: " << clientId << std::endl; //control cout, not important, just debugging info
-    int id = (int)*packet->data; //the first 4 bytes are always the enet packet id
-    COUT(5) << "PacketDecoder: packet id: " << id << std::endl;
-    //COUT(5) << "packet size inside packetdecoder: " << packet->dataLength << std::endl;
-
-    if ( packet == NULL ) {
-      COUT(4) << "PacketDecoder: no packets->packetbuffer queue is empty" << std::endl;
-      return false;
-    }
-    switch( id ) {
-    case ACK:
-      acknowledgement( packet, clientId );
-      return true;
-    case COMMAND:
-      return command( packet, clientId );
-    case CHAT:
-      chatMessage( packet, clientId );
-      return true;
-    case GAMESTATE:
-      gstate( packet, clientId );
-      return true;
-    case CLASSID:
-      clid(packet);
-      return true;
-    case WELCOME:
-      return decodeWelcome( packet, clientId );
-    case CONNECT:
-      return decodeConnectRequest( packet, clientId );
-    }
-    return false;
-  }
-
-  bool PacketDecoder::testAndRemoveCRC(ENetPacket *packet){
-    uint32_t submittetcrc;
-    int dataLength = packet->dataLength;
-    // get the submittet crc code
-    memcpy(&submittetcrc, &packet->data[dataLength-sizeof(uint32_t)], sizeof(uint32_t));
-    unsigned char *data = packet->data;
-    uint32_t crc32=calcCRC(data, packet->dataLength-sizeof(uint32_t));
-    // now append the crc to the packet data
-    if(crc32==submittetcrc){
-      dataLength-=sizeof(uint32_t);
-      enet_packet_resize(packet, dataLength);
-      return true;
-    }
-    COUT(3) << "gamestate crc: " << crc32 << std::endl;
-    COUT(3) << "submitted crc: " << submittetcrc << std::endl;
-    return false;
-  }
-
-  // ATTENTION: TODO watch, that arguments we pass over to the processFunction gets deleted in THE PROCESSXXX function
-
-  //following are the decode functions for the data of the packets
-
-  void PacketDecoder::acknowledgement( ENetPacket* packet, int clientId )
-  {
-    ack* a = new ack;
-    *a = *(ack*)(packet->data); //press pattern of ack on new data
-
-
-    COUT(4) << "PacketDecoder: got ack id: " << a->a << std::endl;
-    processAck( a, clientId ); //debug info
-    //clean memory
-    enet_packet_destroy( packet );
-  }
-
-  bool PacketDecoder::command( ENetPacket* packet, int clientId ){
-    int length = *(int*)((unsigned char *)packet->data+sizeof(int));
-    if(length<=0)
-      return false;
-    void *data = (void *)new unsigned char[length];
-    memcpy(data, (void *)(packet->data+2*sizeof(int)), length);
-    enet_packet_destroy( packet );
-    return true;
-  }
-
-  void PacketDecoder::chatMessage( ENetPacket* packet, int clientId )
-  {
-    chat* chatting = new chat;
-    if(packet->dataLength==4)
-      return;
-    chatting->id = (int)*packet->data; //first copy id into new struct
-    //since the chat message is a char*, allocate the memory needed
-    char* reserve = new char[packet->dataLength-4];
-    //copy the transmitted bytestream into the new generated char*,
-    //note the lenght of the message is represented as "packet->dataLength-sizeof( int )"
-    memcpy( &reserve[0], packet->data+sizeof(int), packet->dataLength-sizeof(int) );
-    //put pointer of chatting struct to the begining of the new generated char*
-    chatting->message = reserve;
-
-    //clean memory
-    enet_packet_destroy( packet );
-
-    processChat( chatting, clientId ); //debug info
-  }
-
-  void PacketDecoder::gstate( ENetPacket* packet, int clientID )
-  {
-//    if(!testAndRemoveCRC(packet)){
-//     COUT(3) << "crc test of gamestate failed - dropping packet" << std::endl;
-//      return;
-//    }
-    GameStateCompressed* currentState = NULL;
-    currentState = new GameStateCompressed;
-    if(currentState == NULL){
-      COUT(3) << "PacketDecoder: could not generate new GameStateCompressed" << std::endl;
-      return;
-    }
-    //copy the GameStateCompressed id into the struct, which is located at second place data+sizeof( int )
-    memcpy( (void*)&(currentState->id), (const void*)(packet->data+1*sizeof( int )), sizeof( int) );
-    COUT(5) << "PacketDecoder: received gs id: " << currentState->id << std::endl;
-    //copy the size of the GameStateCompressed compressed data into the new GameStateCompressed struct, located at 3th
-    //position of the data stream, data+2*sizeof( int )
-    memcpy( (void*)&(currentState->compsize), (const void*)(packet->data+2*sizeof( int )), sizeof( int) );
-    //size of uncompressed data
-    memcpy( (void*)&(currentState->normsize), (const void*)(packet->data+3*sizeof( int )), sizeof( int ) );
-    memcpy( (void*)&(currentState->base_id), (const void*)(packet->data+4*sizeof( int )), sizeof( int ) );
-    //since the packetgenerator was changed, due to a new parameter, change this function too
-    memcpy( (void*)&(currentState->diffed), (const void*)(packet->data+5*sizeof(int)), sizeof(bool));
-    memcpy( (void*)&(currentState->complete), (const void*)(packet->data+5*sizeof(int)+sizeof(bool)), sizeof(bool));
-    //since data is not allocated, because it's just a pointer, allocate it with size of gamestatedatastream
-    if(currentState->compsize==0)
-    {
-      COUT(2) << "PacketDecoder: compsize is 0" << std::endl;
-    }
-//     currentState->data = (unsigned char*)(malloc( currentState->compsize ));
-    if(currentState->compsize==0)
-      return;
-    currentState->data = new unsigned char[currentState->compsize];
-    if(currentState->data==NULL)
-    {
-      COUT(2) << "PacketDecoder: Gamestatepacket-decoder: memory leak" << std::endl;
-    }
-    //copy the GameStateCompressed data
-    memcpy( (void*)(currentState->data), (const void*)(packet->data+5*sizeof( int ) + 2*sizeof(bool)), currentState->compsize );
-
-    //clean memory
-    enet_packet_destroy( packet );
-    processGamestate(currentState, clientID);
-  }
-
-  void PacketDecoder::clid( ENetPacket *packet)
-  {
-    classid* cid = new classid;
-    cid->length = ((classid*)(packet->data))->length;
-    cid->id = ((classid *)(packet->data))->id;
-    cid->clid = ((classid *)(packet->data))->clid;
-    if(cid->length==0)
-      return;
-//     cid->message = (const char *)malloc(cid->length);
-    cid->message = new char[cid->length];
-    void *data  = (void *)cid->message;
-    memcpy(data, (const void*)(packet->data+3*sizeof(int)), cid->length);
-    COUT(4) << "PacketDecoder: classid: " << cid->clid << ", name: " << cid->message << std::endl;
-    enet_packet_destroy( packet );
-    processClassid(cid);
-  }
-
-
-  bool PacketDecoder::decodeWelcome( ENetPacket* packet, int clientID ){
-    welcome *w = new welcome;
-    w->allowed = ((welcome *)(packet->data))->allowed;
-    w->shipID = ((welcome *)(packet->data))->shipID;
-    w->clientID = ((welcome *)(packet->data))->clientID;
-    w->id = ((welcome *)(packet->data))->id;
-    enet_packet_destroy( packet );
-    return processWelcome(w);
-  }
-
-  bool PacketDecoder::decodeConnectRequest( ENetPacket *packet, int clientID ){
-    connectRequest *con = new connectRequest;
-    con->id = ((connectRequest *)(packet->data))->id;
-    enet_packet_destroy( packet );
-    return processConnectRequest(con, clientID );
-  }
-
-
-  // now the data processing functions:
-
-  void PacketDecoder::processChat( chat *data, int clientId)
-  {
-    printChat(data, clientId);
-    delete[] data->message;
-    delete data;
-  }
-
-  void PacketDecoder::processGamestate( GameStateCompressed *state, int clientID )
-  {
-    COUT(3) << "PacketDecoder-process: processing Gamestate" << std::endl;
-    //printGamestate( state );
-//     delete[] state->data;
-//     delete state;
-  }
-
-  void PacketDecoder::processClassid( classid *cid)
-  {
-    printClassid(cid);
-    delete cid;
-    return;
-  }
-
-  void PacketDecoder::processAck( ack *data, int clientID)
-  {
-    printAck(data);
-    delete data;
-    return;
-  }
-
-  bool PacketDecoder::processWelcome( welcome *w ){
-    delete w;
-    return true;
-  }
-
-  bool PacketDecoder::processConnectRequest( connectRequest *con, int clientID ){
-    COUT(3) << "packetdecoder: processing connectRequest" << std::endl;
-    delete con;
-    return true;
-  }
-
-  //these are some print functions for test stuff
-
-  void PacketDecoder::printAck( ack* data )
-  {
-    COUT(5) << "data id: " << data->id << std::endl;
-    COUT(5) << "data:    " << data->a << std::endl;
-  }
-
-
-  void PacketDecoder::printChat( chat* data, int clientId )
-  {
-    if(clientId!=CLIENTID_CLIENT)
-    {
-      COUT(5) << "client: " << clientId << std::endl;
-    }
-    COUT(5) << "data id: " << data->id << std::endl;
-    COUT(5) << "data:    " << data->message << std::endl;
-  }
-
-  void PacketDecoder::printGamestate( GameStateCompressed* data )
-  {
-    COUT(5) << "id of GameStateCompressed:   " << data->id << std::endl;
-    COUT(5) << "size of GameStateCompressed: " << data->compsize << std::endl;
-  }
-
-  void PacketDecoder::printClassid( classid *cid)
-  {
-    COUT(5) << "id of classid:    " << cid->id << std::endl;
-    COUT(5) << "size of classid:  " << cid->length << std::endl;
-    COUT(5) << "ID of classid:    " << cid->clid << std::endl;
-    COUT(5) << "data of classid:  " << cid->message << std::endl;
-  }
-
-}
Index: code/trunk/src/network/PacketGenerator.cc
===================================================================
--- code/trunk/src/network/PacketGenerator.cc	(revision 1639)
+++ 	(revision )
@@ -1,201 +1,0 @@
-/*
- *   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:
- *      Dumeni Manatschal, (C) 2007
- *   Co-authors:
- *      ...
- *
- */
-
-/*
-* Class generates packets that can be send by enet
-* ->don't read this without the class PacketDecoder, since they belong together
-*
-* Autor: Dumeni Manatschal
-*
-*/
-
-#include "PacketManager.h"
-#include "PacketTypes.h"
-
-#include <iostream>
-#include <list>
-#include <string>
-#include <cstring>
-
-
-namespace network
-{
-  void calcCRCBit(uint32_t &crc32, int bit){
-    int hbit;
- 
-    hbit=(crc32 & 0x80000000) ? 1 : 0;
-    if (hbit != bit)
-      crc32=(crc32<<1) ^ NETWORK_CRC32POLY;
-    else
-      crc32=crc32<<1;
-  }
-  
-  uint32_t calcCRC(unsigned char *data, unsigned int dataLength){
-    uint32_t crc32=0;
-    for(unsigned int i=0; i<dataLength; i++){
-      calcCRCBit(crc32, (data[i]&0x1)>>0); // 1st bit
-      calcCRCBit(crc32, (data[i]&0x2)>>1); // 2nd bit
-      calcCRCBit(crc32, (data[i]&0x3)>>2); // 3rd bit
-      calcCRCBit(crc32, (data[i]&0x4)>>3); // 4th bit
-      calcCRCBit(crc32, (data[i]&0x5)>>4); // 5th bit
-      calcCRCBit(crc32, (data[i]&0x6)>>5); // 6th bit
-      calcCRCBit(crc32, (data[i]&0x7)>>6); // 7th bit
-      calcCRCBit(crc32, (data[i]&0x8)>>7); // 8th bit
-    }
-    return crc32;
-  }
-  
-  PacketGenerator::PacketGenerator() { }
-
-  //following functions create a packet in form of bytestream
-
-  ENetPacket* PacketGenerator::acknowledgement( int state, int reliable )
-  {
-    COUT(4) << "PacketGenerator: generating new acknowledgement, id: " << state << std::endl;
-    
-    ENetPacket *packet = enet_packet_create( NULL , sizeof( ack ), reliable );
-    ack* ackreq = (ack *)packet->data;
-    ackreq->id = ACK;
-    ackreq->a = state;
-    //delete ackreq;
-    return packet;
-  }
-  
-  ENetPacket* command( int dataLength, void *data, int reliable = ENET_PACKET_FLAG_RELIABLE )
-  {
-    if(dataLength==0)
-      return NULL;
-    unsigned char *stream = new unsigned char[dataLength + 2*sizeof(int)];
-    if(!stream)
-      return NULL;
-    packet_id a = COMMAND;
-    memcpy(stream, (void*)&a, sizeof(int));
-    memcpy((unsigned char *)stream+sizeof(int), (void*)&dataLength, sizeof(int));
-    memcpy((unsigned char *)stream+2*sizeof(int), data, dataLength);
-    ENetPacket *packet = enet_packet_create(stream, dataLength+2*sizeof(int), reliable);
-    delete[] stream; // TODO: we could also tell enet not to copy the data, but to use the exisiting memory
-    return packet;
-  }
-
-
-  /*### chat messages packet */
-  ENetPacket* PacketGenerator::chatMessage( const char* message, int reliable )
-  {
-    int* trans = new int[sizeof(int) + strlen(message) + 1];
-    *trans = CHAT;
-    //be carefull here, don't forget to allocate the space before using it ;-)
-    memcpy( &trans[1], (const void*)message, strlen( message ) + 1);
-    ENetPacket *packet = enet_packet_create( trans , sizeof( int ) + strlen( message ) + 1, reliable );
-    delete[] trans;
-    return packet;
-  }
-
-  /*### gamestate packet */
-  ENetPacket* PacketGenerator::gstate( GameStateCompressed* states, int reliable )
-  {
-    //std::cout << "packetgenerator" << std::endl;
-    //std::cout << "states->normsize " << states->normsize << std::endl;
-    //std::cout << "states->compsize " << states->compsize << std::endl;
-    int gid = GAMESTATE; //first assign the correct enet id
-    int totalLen = 5*sizeof( int ) + 2*sizeof(bool) + states->compsize; //calculate the total size of the datastream memory
-    //std::cout << "totalLen " << totalLen << std::endl;
-    //unsigned char *data = (unsigned char*)malloc( totalLen ); //allocate the memory for datastream
-    if(totalLen==0)
-      return NULL;
-    ENetPacket *packet = enet_packet_create( NULL , totalLen+sizeof(uint32_t), reliable );
-    //unsigned char *data = new unsigned char[totalLen];
-    unsigned char *data = packet->data;
-    memcpy( (void*)(data), (const void*)&gid, sizeof( int ) ); //this is the enet id
-    memcpy( (void*)(data+sizeof(int)), (const void*)&(states->id), sizeof(int) ); //the GameStateCompressed id
-    memcpy( (void*)(data+2*sizeof(int)), (const void*)&(states->compsize), sizeof(int));
-    memcpy( (void*)(data+3*sizeof(int)), (const void*)&(states->normsize), sizeof(int));
-    memcpy( (void*)(data+4*sizeof(int)), (const void*)&(states->base_id), sizeof(int));
-    memcpy( (void*)(data+5*sizeof(int)), (const void*)&(states->diffed), sizeof(bool));
-    //place the GameStateCompressed data at the end of the enet datastream
-    memcpy( (void*)(data+5*sizeof( int ) + sizeof(bool)), (const void*)&(states->complete), sizeof(bool) );
-    memcpy( (void*)(data+5*sizeof( int ) + 2*sizeof(bool)), (const void*)states->data, states->compsize );
-    
-    //create an enet packet with the generated bytestream
-    COUT(4) << "PacketGenerator generating totalLen " << totalLen << std::endl;
-    //delete[] data;
-//    if(!addCRC(packet))
-//      COUT(3) << "could not add crc to gamestate packet" << std::endl;
-    return packet;
-  }
-
-  ENetPacket* PacketGenerator::clid( int classid, std::string classname, int reliable )
-  {
-    //unsigned char* data = (unsigned char *)malloc(3*sizeof(int)+classname.length()+1);
-    if(classname.length()==0)
-      return NULL;
-    unsigned char *data = new unsigned char[3*sizeof(int)+classname.length()+1];
-    std::cout << "PacketGenerator: classid: " << classid << ", name: " << classname << std::endl;
-    *(int *)data = CLASSID;
-    *((int *)data+1) = classname.length()+1;
-    *((int *)data+2) = classid;
-    memcpy( (void *)(data+3*sizeof(int)), classname.c_str(), classname.length()+1);
-    ENetPacket *packet = enet_packet_create( data , 3*sizeof(int)+classname.length()+1, reliable );
-    delete[] data;
-    return packet;
-  }
-  
-  ENetPacket* PacketGenerator::generateWelcome( int clientID,int shipID, bool allowed , int reliable ){
-    welcome *wc = new welcome;
-    wc->id = WELCOME;
-    wc->clientID = clientID;
-    wc->shipID = shipID;
-    wc->allowed = true;
-    ENetPacket *packet = enet_packet_create( wc, sizeof(welcome), reliable);
-    delete wc;
-    return packet;
-  }
-  
-  ENetPacket* PacketGenerator::generateConnectRequest( int reliable ){
-    connectRequest *con = new connectRequest;
-    con->id=CONNECT;
-    ENetPacket *packet = enet_packet_create( con, sizeof(connectRequest), reliable);
-    delete con;
-    return packet;
-  }
-  
-  
-  bool PacketGenerator::addCRC( ENetPacket *packet){
-    unsigned char *data = packet->data;
-    uint32_t crc32=calcCRC(data, packet->dataLength-sizeof(uint32_t));
-    // now append the crc to the packet data
-    int oldlength = packet->dataLength-sizeof(uint32_t);
-    //if(enet_packet_resize(packet, packet->dataLength+sizeof(uint32_t))==0){
-      memcpy(&packet->data[oldlength], &crc32, sizeof(uint32_t));
-      return true;
-    //}else{
-     // COUT(3) << "could not add crc to gamestate" << std::endl;
-     // return false;
-    //}
-  }
-
-}
Index: code/trunk/src/network/PacketManager.h
===================================================================
--- code/trunk/src/network/PacketManager.h	(revision 1639)
+++ 	(revision )
@@ -1,117 +1,0 @@
-/*
- *   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:
- *      Dumeni Manatschal, (C) 2007
- *   Co-authors:
- *      ...
- *
- */
-
-#ifndef _PacketManager_H__
-#define _PacketManager_H__
-
-#include "NetworkPrereqs.h"
-
-#include <string>
-#include <enet/enet.h>
-
-#include "core/CoreIncludes.h"
-
-#define CLIENTID_CLIENT -1
-#define NETWORK_CRC32POLY 0x04C11DB7 /* CRC-32 Polynom */
-
-//enum netowk generally used to set the type ID of a packet
-namespace network
-{
-  /*
-  * class to generate packets
-  *
-  * @autor: Dumeni Manatschal
-  *
-  */
-  //void calcCRC(uint32_t &crc32, int bit);
-  uint32_t calcCRC(unsigned char *data, unsigned int dataLength);
-  
-  class PacketGenerator
-  {
-  public:
-    PacketGenerator();
-    //call one of this functions out of an instance of PacketGenerator to create a packet
-    ENetPacket* acknowledgement( int state, int reliable = 0 ); // we do not want reliability
-    ENetPacket* command( int dataLength, void *data, int reliable = ENET_PACKET_FLAG_RELIABLE );
-    ENetPacket* chatMessage( const char* message, int reliable = ENET_PACKET_FLAG_RELIABLE );
-    ENetPacket* gstate( GameStateCompressed *states, int reliable = 0 ); // we do not want reliability of gamestates
-    ENetPacket* clid( int classid, std::string classname, int reliable = ENET_PACKET_FLAG_RELIABLE );
-    ENetPacket* generateWelcome( int clientID,int shipID, bool allowed, int reliable = ENET_PACKET_FLAG_RELIABLE );
-    ENetPacket* generateConnectRequest( int reliable = ENET_PACKET_FLAG_RELIABLE );
-  private:
-    bool addCRC( ENetPacket *packet);
-  };
-
-  /*
-  * class used to decode incoming packets
-  *
-  * @autor: Dumeni Manatschal
-  *
-  */
-  class _NetworkExport PacketDecoder
-  {
-  public:
-    PacketDecoder();
-    virtual ~PacketDecoder();
-    //call this function to decode, it calls the right decoding function below
-    bool elaborate( ENetPacket* packet, int clientId );
-  protected:
-
-    virtual void processChat( chat *data, int clientId);
-
-
-  private:
-    bool testAndRemoveCRC(ENetPacket *packet);
-
-
-    void acknowledgement( ENetPacket* packet, int clientId = CLIENTID_CLIENT );
-    bool command( ENetPacket* packet, int clientId );
-    void chatMessage( ENetPacket* packet, int clientId = CLIENTID_CLIENT );
-    void gstate( ENetPacket* packet, int clientID = CLIENTID_CLIENT );
-    void clid( ENetPacket *packet);
-    bool decodeWelcome( ENetPacket* packet, int clientID = CLIENTID_CLIENT );
-    bool decodeConnectRequest( ENetPacket *packet, int clientID = CLIENTID_CLIENT );
-
-    //process data
-    //two functions are note yet implemented!
-    virtual void processGamestate(GameStateCompressed *state, int clientID);
-    virtual void processAck( ack *data, int clientID);
-    virtual void processClassid( classid *cid);
-    virtual bool processWelcome( welcome *w );
-    virtual bool processConnectRequest( connectRequest *con, int clientID );
-    //virtual void processAck( ack *data);
-
-    //print functions
-    void printAck( ack* data );
-    void printChat( chat* data, int clientId );
-    void printGamestate( GameStateCompressed *data );
-    void printClassid( classid *cid);
-  };
-}
-
-#endif /* _PacketManager_H__ */
Index: code/trunk/src/network/PacketTypes.h
===================================================================
--- code/trunk/src/network/PacketTypes.h	(revision 1639)
+++ 	(revision )
@@ -1,123 +1,0 @@
-/*
- *   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:
- *      ...
- *   Co-authors:
- *      ...
- *
- */
-
-//
-// C++ Interface: PacketTypes
-//
-// Description:
-//
-//
-// Author:  <>, (C) 2007
-//
-// Copyright: See COPYING file that comes with this distribution
-//
-//
-
-#ifndef _PacketTypes_H__
-#define _PacketTypes_H__
-
-#include "NetworkPrereqs.h"
-
-namespace network
-{
-  enum packet_id {
-    ACK,
-    COMMAND,
-    CHAT,
-    GAMESTATE ,
-    CLASSID,
-    WELCOME,
-    CONNECT,
-  };
-
-
-  /**
-  * This struct defines a gamestate:
-  * size: total size of the data in *data
-  * data: pointer to the data allocated in the memory
-  */
-  struct GameState{
-    int id;
-    int size;                       //!< total size of data
-    // new ---- change functions
-    int base_id;                    // if gamestate is diffed this is the id of the old gamestate (base)
-    bool diffed;
-    bool complete;                  // this determines, wheter all objects are in this gamestate (server) or only few objects (client)
-    unsigned char *data;            //!< pointer to data
-  };
-
-  /**
-  * this struct defines a gamestate:
-  * compsize is the size of the compressed data
-  * normsize is the size of the uncompressed data
-  * data are the gamestates
-  */
-  struct GameStateCompressed{
-    int id;
-    int compsize;                   //!< size of compressed data
-    int normsize;                   //!< size of uncompressed data
-    // new ----- change functions
-    int base_id;                  // if gamestate is diffed this is the id of the old gamestate (base)
-    bool diffed;
-    bool complete;                  // this determines, wheter all objects are in this gamestate (server) or only few objects (client)
-    unsigned char *data;            //!< gamestate data
-  };
-
-  struct classid{
-    int id;
-    int length;
-    int clid;
-    const char *message;
-  };
-
-
-  struct ack {
-    int id;
-    int a;
-  };
-
-  //only in this class, not PacketGenerator, used as pattern to put incoming
-  //bytes inside
-  struct chat {
-    int id;
-    const char* message;
-  };
-
-  struct welcome {
-    int id;
-    int clientID;
-    int shipID;
-    bool allowed;
-  };
-  
-  struct connectRequest{
-    int id;
-  };
-}
-
-#endif /* _PacketTypes_H__ */
Index: code/trunk/src/network/Server.cc
===================================================================
--- code/trunk/src/network/Server.cc	(revision 1639)
+++ code/trunk/src/network/Server.cc	(revision 1735)
@@ -45,11 +45,12 @@
 
 #include "ConnectionManager.h"
-#include "PacketTypes.h"
-#include "GameStateManager.h"
+#include "GamestateManager.h"
 #include "ClientInformation.h"
-//#include "NetworkFrameListener.h"
 #include "util/Sleep.h"
 #include "objects/SpaceShip.h"
 #include "core/ConsoleCommand.h"
+#include "packet/Chat.h"
+#include "packet/Packet.h"
+#include "packet/Welcome.h"
 
 namespace network
@@ -58,32 +59,4 @@
   #define NETWORK_FREQUENCY 30
   
-  Server *Server::instance_=0;
-  
-  Server *Server::createSingleton(){
-    if(!instance_)
-      instance_ = new Server();
-    return instance_;
-  }
-  Server *Server::createSingleton(int port){
-    if(!instance_)
-      instance_ = new Server(port);
-    return instance_;
-  }
-  Server *Server::createSingleton(int port, std::string bindAddress){
-    if(!instance_)
-      instance_ = new Server(port, bindAddress);
-    return instance_;
-  }
-  Server *Server::createSingleton(int port, const char *bindAddress){
-    if(!instance_)
-      instance_ = new Server(port, bindAddress);
-    return instance_;
-  }
-  
-  Server *Server::getSingleton(){
-    return instance_;
-  }
-  
-  
   /**
   * Constructor for default values (bindaddress is set to ENET_HOST_ANY
@@ -92,16 +65,12 @@
   Server::Server() {
     timeSinceLastUpdate_=0;
-    packet_gen = PacketGenerator();
-    clients = new ClientInformation(true);
-    connection = new ConnectionManager(clients);
-    gamestates = new GameStateManager(clients);
+    connection = new ConnectionManager();
+    gamestates_ = new GamestateManager();
   }
   
   Server::Server(int port){
     timeSinceLastUpdate_=0;
-    packet_gen = PacketGenerator();
-    clients = new ClientInformation(true);
-    connection = new ConnectionManager(clients, port);
-    gamestates = new GameStateManager(clients);
+    connection = new ConnectionManager(port);
+    gamestates_ = new GamestateManager();
   }
 
@@ -113,8 +82,6 @@
   Server::Server(int port, std::string bindAddress) {
     timeSinceLastUpdate_=0;
-    packet_gen = PacketGenerator();
-    clients = new ClientInformation();
-    connection = new ConnectionManager(port, bindAddress, clients);
-    gamestates = new GameStateManager(clients);
+    connection = new ConnectionManager(port, bindAddress);
+    gamestates_ = new GamestateManager();
   }
 
@@ -126,8 +93,6 @@
   Server::Server(int port, const char *bindAddress) {
     timeSinceLastUpdate_=0;
-    packet_gen = PacketGenerator();
-    clients = new ClientInformation();
-    connection = new ConnectionManager(port, bindAddress, clients);
-    gamestates = new GameStateManager(clients);
+    connection = new ConnectionManager(port, bindAddress);
+    gamestates_ = new GamestateManager();
   }
 
@@ -148,4 +113,15 @@
   }
 
+  bool Server::processChat(packet::Chat *message, unsigned int clientID){
+    ClientInformation *temp = ClientInformation::getBegin();
+    while(temp){
+      message->setClientID(temp->getID());
+      if(!message->send())
+        COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl;
+      temp = temp->next();
+    }
+    return message->process();
+  }
+  
   /**
   * This function sends out a message to all clients
@@ -153,6 +129,14 @@
   * @return true/false
   */
-  bool Server::sendChat(std::string msg) {
-    return sendChat(msg.c_str());
+  bool Server::sendChat(packet::Chat *chat) {
+    //TODO: change this (no informations about who wrote a message)
+    assert(0);
+    ClientInformation *temp = ClientInformation::getBegin();
+    while(temp){
+      chat->setClientID(temp->getID());
+      if(!chat->send())
+        COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl;
+    }
+    return chat->process();;
   }
 
@@ -162,12 +146,12 @@
   * @return true/false
   */
-  bool Server::sendChat(const char *msg) {
-    char *message = new char [strlen(msg)+10+1];
-    sprintf(message, "Player %d: %s", CLIENTID_SERVER, msg);
-    COUT(1) << message << std::endl;
-    ENetPacket *packet = packet_gen.chatMessage(message);
-    COUT(5) <<"Server: adding Packets" << std::endl;
-    return connection->addPacketAll(packet);
-  }
+//   bool Server::sendChat(const char *msg) {
+//     char *message = new char [strlen(msg)+10+1];
+//     sprintf(message, "Player %d: %s", CLIENTID_SERVER, msg);
+//     COUT(1) << message << std::endl;
+//     ENetPacket *packet = packet_gen.chatMessage(message);
+//     COUT(5) <<"Server: adding Packets" << std::endl;
+//     return connection->addPacketAll(packet);
+//   }
 
   /**
@@ -183,5 +167,5 @@
       timeSinceLastUpdate_=(float)((int)(timeSinceLastUpdate_*NETWORK_FREQUENCY))/timeSinceLastUpdate_;
 //      timeSinceLastUpdate_-=1./NETWORK_FREQUENCY;
-      gamestates->processGameStates();
+      gamestates_->processGamestates();
       updateGamestate();
     }
@@ -191,4 +175,8 @@
     return;
   }
+  
+  bool Server::queuePacket(ENetPacket *packet, int clientID){
+    return connection->addPacket(packet, clientID);
+  }
 
   /**
@@ -197,5 +185,4 @@
   void Server::processQueue() {
     ENetEvent *event;
-    int clientID=-1;
     while(!connection->queueEmpty()){
       //std::cout << "Client " << clientID << " sent: " << std::endl;
@@ -211,13 +198,10 @@
         break;
       case ENET_EVENT_TYPE_DISCONNECT:
-        if(clients->findClient(&event->peer->address))
+        if(ClientInformation::findClient(&event->peer->address))
           disconnectClient(event);
         break;
       case ENET_EVENT_TYPE_RECEIVE:
-        if(clients->findClient(&event->peer->address)){
-          clientID = clients->findClient(&event->peer->address)->getID();
-          if( !elaborate(event->packet, clientID) ) 
-            COUT(3) << "Server: could not elaborate" << std::endl;
-        }
+        if(!processPacket(event->packet, event->peer))
+          COUT(3) << "processing incoming packet failed" << std::endl;
         break;
       default:
@@ -233,5 +217,5 @@
   */
   void Server::updateGamestate() {
-    gamestates->update();
+    gamestates_->update();
     COUT(5) << "Server: one gamestate update complete, goig to sendGameState" << std::endl;
     //std::cout << "updated gamestate, sending it" << std::endl;
@@ -242,4 +226,9 @@
   }
 
+  bool Server::processPacket( ENetPacket *packet, ENetPeer *peer ){
+    packet::Packet *p = packet::Packet::createPacket(packet, peer);
+    return p->process();
+  }
+  
   /**
   * sends the gamestate
@@ -247,15 +236,12 @@
   bool Server::sendGameState() {
     COUT(5) << "Server: starting function sendGameState" << std::endl;
-    ClientInformation *temp = clients;
+    ClientInformation *temp = ClientInformation::getBegin();
     bool added=false;
     while(temp != NULL){
-      if(temp->getHead()){
-        temp=temp->next();
-        //think this works without continue
-        continue;
-      }
       if( !(temp->getSynched()) ){
         COUT(5) << "Server: not sending gamestate" << std::endl;
         temp=temp->next();
+        if(!temp)
+          break;
         //think this works without continue
         continue;
@@ -266,5 +252,5 @@
       int cid = temp->getID(); //get client id
       COUT(5) << "Server: got acked (gamestate) ID from clientlist: " << gid << std::endl;
-      GameStateCompressed *gs = gamestates->popGameState(cid);
+      packet::Gamestate *gs = gamestates_->popGameState(cid);
       if(gs==NULL){
         COUT(2) << "Server: could not generate gamestate (NULL from compress)" << std::endl;
@@ -272,20 +258,14 @@
       }
       //std::cout << "adding gamestate" << std::endl;
-      ENetPacket *packet = packet_gen.gstate(gs);
-      if(!packet)
-	continue;
-      if ( !(connection->addPacket(packet, cid)) ){
+      gs->setClientID(cid);
+      assert(gs->compressData());
+      if ( !gs->send() ){
         COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp->getFailures() << std::endl; 
         temp->addFailure();
-        /*if(temp->getFailures() > 0 )
-          disconnectClient(temp);*/
-      //std::cout << "added gamestate" << std::endl;
       }else
         temp->resetFailures();
       added=true;
       temp=temp->next();
-      // now delete gamestate
-      delete[] gs->data;
-      delete gs;
+      // gs gets automatically deleted by enet callback
     }
     /*if(added) {
@@ -296,45 +276,22 @@
     return true;
   }
-
-  void Server::processAck( ack *data, int clientID) {
-    COUT(4) << "Server: processing ack from client: " << clientID << "; ack-id: " << data->a << std::endl;
-    gamestates->ackGameState(clientID, data->a);
-    delete data;
-  }
-  
-  bool Server::processConnectRequest( connectRequest *con, int clientID ){
-    //(COUT(3) << "processing connectRequest " << std::endl;
-    //connection->addPacket(packet_gen.gstate(gamestates->popGameState(clientID)) , clientID);
-    //createClient(clientID);
-    delete con;
-    return true;
-  }
-  
-  void Server::processGamestate( GameStateCompressed *data, int clientID){
-    COUT(4) << "processing partial gamestate from client " << clientID << std::endl;
-    gamestates->addGameState(data, clientID);
-        /*COUT(3) << "Could not push gamestate\t\t\t\t=====" << std::endl;
-    else
-      if(clients->findClient(clientID))
-        clients->findClient(clientID)->resetFailures();*/
-  }
-  
-  void Server::processChat( chat *data, int clientId){
-    char *message = new char [strlen(data->message)+10+1];
-    sprintf(message, "Player %d: %s", clientId, data->message);
-    COUT(1) << message << std::endl;
-    ENetPacket *pck = packet_gen.chatMessage(message);
-    connection->addPacketAll(pck);
-    delete[] data->message;
-    delete data;
-  }
+  
+//   void Server::processChat( chat *data, int clientId){
+//     char *message = new char [strlen(data->message)+10+1];
+//     sprintf(message, "Player %d: %s", clientId, data->message);
+//     COUT(1) << message << std::endl;
+//     ENetPacket *pck = packet_gen.chatMessage(message);
+//     connection->addPacketAll(pck);
+//     delete[] data->message;
+//     delete data;
+//   }
   
   bool Server::addClient(ENetEvent *event){
-    ClientInformation *temp = clients->insertBack(new ClientInformation);
+    ClientInformation *temp = ClientInformation::insertBack(new ClientInformation);
     if(!temp){
       COUT(2) << "Server: could not add client" << std::endl;
       return false;
     }
-    if(temp->prev()->getHead()) { //not good if you use anything else than insertBack
+    if(temp->prev()->getBegin()) { //not good if you use anything else than insertBack
       temp->prev()->setID(0); //bugfix: not necessary but usefull
       temp->setID(1);
@@ -348,5 +305,5 @@
   
   bool Server::createClient(int clientID){
-    ClientInformation *temp = clients->findClient(clientID);
+    ClientInformation *temp = ClientInformation::findClient(clientID);
     if(!temp){
       COUT(2) << "Conn.Man. could not create client with id: " << clientID << std::endl;
@@ -363,5 +320,7 @@
     temp->setSynched(true);
     COUT(3) << "sending welcome" << std::endl;
-    connection->sendWelcome(temp->getID(), temp->getShipID(), true);
+    packet::Welcome *w = new packet::Welcome(temp->getID(), temp->getShipID());
+    w->setClientID(temp->getID());
+    assert(w->send());
     return true;
   }
@@ -376,4 +335,6 @@
     }
     orxonox::SpaceShip *no = dynamic_cast<orxonox::SpaceShip *>(id->fabricate());
+    no->classID = id->getNetworkID();
+    client->setShipID(no->objectID);
     no->setPosition(orxonox::Vector3(0,0,80));
     no->setScale(10);
@@ -388,8 +349,7 @@
     no->setRotDamp(1.0);
     no->setCamera("cam_"+client->getID());
-    no->classID = id->getNetworkID();
     no->create();
+    no->setBacksync(true);
     
-    client->setShipID(no->objectID);
     return true;
   }
@@ -401,5 +361,5 @@
     //boost::recursive_mutex::scoped_lock lock(head_->mutex_);
     orxonox::Iterator<orxonox::SpaceShip> it = orxonox::ObjectList<orxonox::SpaceShip>::start();
-    ClientInformation *client = clients->findClient(&event->peer->address);
+    ClientInformation *client = ClientInformation::findClient(&event->peer->address);
     if(!client)
       return false;
@@ -412,5 +372,5 @@
       ++it;
       delete  *temp;
-      return clients->removeClient(event->peer);
+      return ClientInformation::removeClient(event->peer);
     }
     return false;
@@ -418,5 +378,5 @@
 
   void Server::disconnectClient(int clientID){
-    ClientInformation *client = clients->findClient(clientID);
+    ClientInformation *client = ClientInformation::findClient(clientID);
     if(client)
       disconnectClient(client);
@@ -424,5 +384,5 @@
   void Server::disconnectClient( ClientInformation *client){
     connection->disconnectClient(client);
-    gamestates->removeClient(client);
+    gamestates_->removeClient(client);
   }
   
Index: code/trunk/src/network/Server.h
===================================================================
--- code/trunk/src/network/Server.h	(revision 1639)
+++ code/trunk/src/network/Server.h	(revision 1735)
@@ -46,7 +46,6 @@
 #include <string>
 
-#include "PacketManager.h"
-
-
+#include "Host.h"
+#include "GamestateManager.h"
 
 namespace network
@@ -58,17 +57,16 @@
   * It implements all functions necessary for a Server
   */
-  class _NetworkExport Server : public PacketDecoder{
+  class _NetworkExport Server : public Host{
   public:
-    static Server *createSingleton();
-    static Server *createSingleton(int port);
-    static Server *createSingleton(int port, std::string bindAddress);
-    static Server *createSingleton(int port, const char *bindAddress);
-    
-    static Server *getSingleton();
+    Server();
+    Server(int port);
+    Server(int port, std::string bindAddress);
+    Server(int port, const char *bindAddress);
     
     void open();
     void close();
-    bool sendChat(std::string msg);
-    bool sendChat(const char *msg);
+    bool processChat(packet::Chat *message, unsigned int clientID);
+    bool sendChat(packet::Chat *chat);
+    bool queuePacket(ENetPacket *packet, int clientID);
     void tick(float time);
   protected:
@@ -76,10 +74,6 @@
     void updateGamestate();
   private:
-    Server();
-    Server(int port);
-    Server(int port, std::string bindAddress);
-    Server(int port, const char *bindAddress);
-    
-    static Server *instance_;
+    unsigned int shipID(){return 0;}
+    int playerID(){return 0;}
     
     bool addClient(ENetEvent *event);
@@ -89,14 +83,13 @@
     void disconnectClient(int clientID);
     void disconnectClient( ClientInformation *client);
+    bool processPacket( ENetPacket *packet, ENetPeer *peer );
     bool sendGameState();
-    void processAck( ack *data, int clientID);
-    bool processConnectRequest( connectRequest *con, int clientID );
-    void processGamestate( GameStateCompressed *data, int clientID);
-    void processChat( chat *data, int clientId);
+    
+    
+    //void processChat( chat *data, int clientId);
     ConnectionManager *connection;
-    GameStateManager *gamestates;
-    PacketGenerator packet_gen;
+    GamestateManager *gamestates_;
 
-    ClientInformation *clients;
+    
     float timeSinceLastUpdate_;
   };
Index: code/trunk/src/network/Synchronisable.cc
===================================================================
--- code/trunk/src/network/Synchronisable.cc	(revision 1639)
+++ code/trunk/src/network/Synchronisable.cc	(revision 1735)
@@ -43,7 +43,8 @@
 #include <string>
 #include <iostream>
-#include <string.h>
+#include <assert.h>
 
 #include "core/CoreIncludes.h"
+#include "core/BaseObject.h"
 // #include "core/Identifier.h"
 
@@ -85,4 +86,35 @@
     else  // server
       state_=0x1;
+  }
+  
+  bool Synchronisable::fabricate(unsigned char*& mem, int mode)
+  {
+    unsigned int size, objectID, classID;
+    size = *(unsigned int *)mem;
+    objectID = *(unsigned int*)(mem+sizeof(unsigned int));
+    classID = *(unsigned int*)(mem+2*sizeof(unsigned int));
+    
+    orxonox::Identifier* id = ID(classID);
+    if(!id){
+      COUT(3) << "We could not identify a new object; classid: " << classID << " uint: " << (unsigned int)classID << " objectID: " << objectID << " size: " << size << std::endl;
+      return false; // most probably the gamestate is corrupted
+    }
+    orxonox::BaseObject *bo = id->fabricate();
+    Synchronisable *no = dynamic_cast<Synchronisable *>(bo);
+    assert(no);
+    no->objectID=objectID;
+    no->classID=classID;
+    COUT(3) << "fabricate objectID: " << no->objectID << " classID: " << no->classID << std::endl;
+          // update data and create object/entity...
+    if( !no->updateData(mem, mode) ){
+      COUT(1) << "We couldn't update the object: " << objectID << std::endl;
+      return false;
+    }
+    if( !no->create() )
+    {
+      COUT(1) << "We couldn't manifest (create() ) the object: " << objectID << std::endl;
+      return false;
+    }
+    return true;
   }
 
@@ -109,49 +141,5 @@
   }
 
-  /**
-  * note: only use this function for debug use, because it's inefficient (in order to produce a gamestate, you have to copy the whole data again to another memory location after this process)
-  * This function takes all SynchronisableVariables out of the Synchronisable and saves it into a syncData struct
-  * structure of the bitstream:
-  * (var1_size,var1,var2_size,var2,...)
-  * varx_size: size = sizeof(int)
-  * varx: size = varx_size
-  * @return data containing all variables and their sizes
-  */
-  // syncData Synchronisable::getData(){
-  //   std::list<synchronisableVariable>::iterator i;
-  //   int totalsize=0;
-  //   //figure out size of data to be allocated
-  //   for(i=syncList->begin(); i!=syncList->end(); i++){
-  //     // increase size (size of variable and size of size of variable ;)
-  //     if(i->type == STRING)
-  //       totalsize+=sizeof(int)+((std::string *)i->var)->length()+1;
-  //     else
-  //       totalsize+=sizeof(int)+i->size;
-  //   }
-  //   syncData retVal;
-  //   retVal.objectID=this->objectID;
-  //   retVal.classID=this->classID;
-  //   retVal.length=totalsize;
-  //   // allocate memory
-  //   retVal.data = (unsigned char *)malloc(totalsize);
-  //   // copy to location
-  //   //CHANGED: REMOVED DECLARATION int n=0 FROM LOOP
-  //   int n=0;
-  //   for(i=syncList->begin(); n<totalsize && i!=syncList->end(); i++){
-  //     std::memcpy(retVal.data+n, (const void*)(i->size), sizeof(int));
-  //     n+=sizeof(int);
-  //     switch(i->type){
-  //     case STRING:
-  //       std::memcpy(retVal.data+n, (const void *)(((std::string *)i->var)->c_str()), ((std::string *)i->var)->length()+1);
-  //       n+=((std::string *)i->var)->length()+1;
-  //       break;
-  //     case DATA:
-  //       std::memcpy(retVal.data+n, ((const void*)i->var), i->size);
-  //       n+=i->size;
-  //       break;
-  //     }
-  //   }
-  //   return retVal;
-  // }
+
   /**
   * This function takes all SynchronisableVariables out of the Synchronisable and saves it into a syncData struct
@@ -203,5 +191,106 @@
     return retVal;
   }
-
+  
+  /**
+   * This function takes all SynchronisableVariables out of the Synchronisable and saves it into a syncData struct
+  * Difference to the above function:
+   * takes a pointer to already allocated memory (must have at least getSize bytes length)
+  * structure of the bitstream:
+   * (var1_size,var1,var2_size,var2,...)
+   * varx_size: size = sizeof(int)
+   * varx: size = varx_size
+   * @return data containing all variables and their sizes
+   */
+  bool Synchronisable::getData2(unsigned char*& mem, int mode){
+    //std::cout << "inside getData" << std::endl;
+    unsigned int tempsize = 0;
+    if(mode==0x0)
+      mode=state_;
+    if(classID==0)
+      COUT(3) << "classid 0 " << this->getIdentifier()->getName() << std::endl;
+    this->classID=this->getIdentifier()->getNetworkID();
+    std::list<synchronisableVariable *>::iterator i;
+    unsigned int size;
+    size=getSize2(mode);
+    
+    // start copy header
+    memcpy(mem, &size, sizeof(unsigned int));
+    mem+=sizeof(unsigned int);
+    memcpy(mem, &(this->objectID), sizeof(unsigned int));
+    mem+=sizeof(unsigned int);
+    memcpy(mem, &(this->classID), sizeof(unsigned int));
+    mem+=sizeof(unsigned int);
+    tempsize+=12;
+    // end copy header
+    
+    
+    COUT(5) << "Synchronisable getting data from objectID: " << objectID << " classID: " << classID << " length: " << size << std::endl;
+    // copy to location
+    for(i=syncList->begin(); i!=syncList->end(); ++i){
+      //(std::memcpy(retVal.data+n, (const void*)(&(i->size)), sizeof(int));
+      if( ((*i)->mode & mode) == 0 ){
+        COUT(5) << "not getting data: " << std::endl;
+        continue;  // this variable should only be received
+      }
+      switch((*i)->type){
+        case DATA:
+          memcpy( (void *)(mem), (void*)((*i)->var), (*i)->size);
+          mem+=(*i)->size;
+          tempsize+=(*i)->size;
+          break;
+        case STRING:
+          memcpy( (void *)(mem), (void *)&((*i)->size), sizeof(int) );
+          mem+=sizeof(int);
+          const char *data = ( ( *(std::string *) (*i)->var).c_str());
+          memcpy( mem, (void*)data, (*i)->size);
+          COUT(5) << "synchronisable: char: " << (const char *)(mem) << " data: " << data << " string: " << *(std::string *)((*i)->var) << std::endl;
+          mem+=(*i)->size;
+          tempsize+=(*i)->size + 4;
+          break;
+      }
+    }
+    assert(tempsize==size);
+    return true;
+  }
+
+  /*bool Synchronisable::getData(Bytestream& bs, int mode)
+  {
+    //std::cout << "inside getData" << std::endl;
+    if(mode==0x0)
+      mode=state_;
+    if(classID==0)
+      COUT(3) << "classid 0 " << this->getIdentifier()->getName() << std::endl;
+    this->classID=this->getIdentifier()->getNetworkID();
+    std::list<synchronisableVariable *>::iterator i;
+    bs << this->getSize();
+    bs << this->objectID;
+    bs << this->classID;
+    // copy to location
+    for(i=syncList->begin(); i!=syncList->end(); ++i){
+      if( ((*i)->mode & mode) == 0 ){
+        COUT(5) << "not getting data: " << std::endl;
+        continue;  // this variable should only be received
+      }
+      switch((*i)->type){
+        case DATA:
+          bs << *(*i)->var;
+          //std::memcpy( (void *)(retVal.data+n), (void*)((*i)->var), (*i)->size);
+          //n+=(*i)->size;
+          break;
+        case STRING:
+          bs << *(String *)((*i)->var);
+          //memcpy( (void *)(retVal.data+n), (void *)&((*i)->size), sizeof(int) );
+          //n+=sizeof(int);
+          //const char *data = ( ( *(std::string *) (*i)->var).c_str());
+          //std::memcpy( retVal.data+n, (void*)data, (*i)->size);
+          //COUT(5) << "synchronisable: char: " << (const char *)(retVal.data+n) << " data: " << data << " string: " << *(std::string *)((*i)->var) << std::endl;
+          //n+=(*i)->size;
+          break;
+      }
+    }
+    return true;
+  }*/
+
+  
   /**
   * This function takes a syncData struct and takes it to update the variables
@@ -247,5 +336,67 @@
       }
       // call the callback function, if defined
-      if(callback)
+      if(callback && (*i)->callback)
+        (*i)->callback->call();
+    }
+    return true;
+  }
+  
+  /**
+   * This function takes a syncData struct and takes it to update the variables
+   * @param vars data of the variables
+   * @return true/false
+   */
+  bool Synchronisable::updateData(unsigned char*& mem, int mode){
+    unsigned char *data = mem;
+    if(mode==0x0)
+      mode=state_;
+    std::list<synchronisableVariable *>::iterator i;
+    if(syncList->empty()){
+      COUT(4) << "Synchronisable::updateData syncList is empty" << std::endl;
+      return false;
+    }
+    
+    // start extract header
+    unsigned int objectID, classID, size;
+    size = *(int *)mem;
+    mem+=sizeof(size);
+    objectID = *(int *)mem;
+    mem+=sizeof(objectID);
+    classID = *(int *)mem;
+    mem+=sizeof(classID);
+    // stop extract header
+    assert(this->objectID==objectID);
+    assert(this->classID==classID);
+    
+    COUT(5) << "Synchronisable: objectID " << objectID << ", classID " << classID << " size: " << size << " synchronising data" << std::endl;
+    for(i=syncList->begin(); i!=syncList->end() && mem <= data+size; i++){
+      if( ((*i)->mode ^ mode) == 0 ){
+        COUT(5) << "synchronisable: not updating variable " << std::endl;
+        continue;  // this variable should only be set
+      }
+      COUT(5) << "Synchronisable: element size: " << (*i)->size << " type: " << (*i)->type << std::endl;
+      bool callback=false;
+      switch((*i)->type){
+        case DATA:
+          if((*i)->callback) // check whether this variable changed (but only if callback was set)
+            if(strncmp((char *)(*i)->var, (char *)mem, (*i)->size)!=0)
+              callback=true;
+          memcpy((void*)(*i)->var, mem, (*i)->size);
+          mem+=(*i)->size;
+          break;
+        case STRING:
+          (*i)->size = *(int *)mem;
+          COUT(5) << "string size: " << (*i)->size << std::endl;
+          mem+=sizeof(int);
+          if((*i)->callback) // check whether this string changed
+            if( *(std::string *)((*i)->var) != std::string((char *)mem) )
+              callback=true;
+          *((std::string *)((*i)->var)) = std::string((const char*)mem);
+          COUT(5) << "synchronisable: char: " << (const char*)mem << " string: " << std::string((const char*)mem) << std::endl;
+          mem += (*i)->size;
+          break;
+      }
+      // call the callback function, if defined
+      if(callback && (*i)->callback)
         (*i)->callback->call();
     }
@@ -280,4 +431,26 @@
   }
 
+  /**
+   * This function returns the total amount of bytes needed by getData to save the whole content of the variables
+   * @return amount of bytes
+   */
+  int Synchronisable::getSize2(int mode){
+    return 3*sizeof(unsigned int) + getSize( mode );
+  }
+  
+  bool Synchronisable::isMyData(unsigned char* mem)
+  {
+    unsigned int objectID, classID, size;
+    size = *(int *)mem;
+    mem+=sizeof(size);
+    objectID = *(int *)mem;
+    mem+=sizeof(objectID);
+    classID = *(int *)mem;
+    mem+=sizeof(classID);
+    
+    assert(classID == this->classID);
+    return (objectID == this->objectID);
+  }
+  
   void Synchronisable::setBacksync(bool sync){
     backsync_=sync;
Index: code/trunk/src/network/Synchronisable.h
===================================================================
--- code/trunk/src/network/Synchronisable.h	(revision 1639)
+++ code/trunk/src/network/Synchronisable.h	(revision 1735)
@@ -44,12 +44,12 @@
 
   struct syncData{
-    int length;
-    int objectID;
-    int classID;
+    unsigned int length;
+    unsigned int objectID;
+    unsigned int classID;
     unsigned char *data;
   };
 
   typedef struct synchronisableVariable{
-    int size;
+    unsigned int size;
     int mode; // this determines in which direction the variable gets synchronised
     void *var;
@@ -69,12 +69,17 @@
 
     virtual ~Synchronisable();
-    int objectID;
-    int classID;
+    unsigned int objectID;
+    unsigned int classID;
 
     void registerVar(void *var, int size, variableType t, int mode=1, NetworkCallbackBase *cb=0);
     //  syncData getData();
     syncData getData(unsigned char *mem, int mode=0x0);
+    bool getData2(unsigned char*& men, int mode=0x0);
+    //bool getData(Bytestream& bs, int mode=0x0);
     int getSize(int mode=0x0);
+    int getSize2(int mode=0x0);
     bool updateData(syncData vars, int mode=0x0);
+    bool updateData(unsigned char*& mem, int mode=0x0);
+    bool isMyData(unsigned char* mem);
     void setBacksync(bool sync);
     bool getBacksync();
@@ -82,4 +87,6 @@
     virtual bool create();
     static void setClient(bool b);
+    
+    static bool fabricate(unsigned char*& mem, int mode=0x0);
   protected:
     Synchronisable();
Index: code/trunk/src/network/dummyclient.cc
===================================================================
--- code/trunk/src/network/dummyclient.cc	(revision 1639)
+++ 	(revision )
@@ -1,124 +1,0 @@
-/*
- *   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, (C) 2007
- *   Co-authors:
- *      ...
- *
- */
-
-//o
-// Dummy client to test ConnectionManager and PacketBuffer classes
-//
-// Author: Oliver Scheuss
-
-#include <iostream>
-#include <string>
-#include <enet/enet.h>
-
-#include "util/Sleep.h"
-#include "PacketManager.h"
-#include "PacketTypes.h"
-
-using namespace std;
-
-int main(){
-  ENetHost * client;
-  ENetAddress address;
-  ENetEvent event;
-  ENetPeer *peer;
-  network::PacketGenerator pck;
-
-  enet_initialize();
-  atexit(enet_deinitialize);
-
-  cout << "Enter address of the server xxx.xxx.xxx.xxx (enter for localhost)" << endl;
-  string str;
-  getline(cin, str);
-  cout << "You entered: " << str << endl;
-  if(str.compare("")==0)
-    str="127.0.0.1";
-
-  enet_address_set_host(&address, str.c_str());
-  address.port = 55556;
-
-  // create client object
-  client = enet_host_create(NULL, 2, 0, 0);
-
-  if(client==NULL){
-    fprintf(stderr, "An error occured");
-    exit(EXIT_FAILURE);
-  }
-  // connect peer
-  peer = enet_host_connect(client, &address, 2);
-  if(peer==NULL){
-    fprintf(stderr, "Peer establishing error");
-    exit(EXIT_FAILURE);
-  }
-  // wait 5 seconds for the connection attempt to succeed
-  if(enet_host_service(client, &event, 5000) > 0 && event.type == ENET_EVENT_TYPE_CONNECT){
-    cout << "Connection to " << str << " succeeded." << endl;
-    //puts("Connection to localhost:5555 succeeded.");
-  }else{
-    enet_peer_reset(peer);
-    cout << "Connection to " << str << " failed." << endl;
-    //puts("Connection to localhost:5555 failed.");
-    exit(EXIT_FAILURE);
-  }
-
-  for(int i=0; i<10; i++){
-    // weihnachtsmann bringt packete
-    //ENetPacket *packet = enet_packet_create ("packet1234", strlen("packet1234") + 1, ENET_PACKET_FLAG_RELIABLE);
-    // extend the packet and append the string foo to it
-    // send packet to peer on channel id 0
-    enet_peer_send(peer, 1, pck.chatMessage("test2"));
-    // keep the timeout very small for low delay
-    if(enet_host_service(client, &event, 1)==0){
-      cout << "successfully sent: " << event.type << endl;
-    }else{
-      cout << "failed sending" << endl;
-    }
-    usleep(1000000);
-  }
-
-  // now disconnect
-  //   enet_peer_disconnect (peer);
-  enet_peer_disconnect (peer, 0);
-  // 3 seconds timeout
-  while(enet_host_service(client, &event, 3000) > 0){
-    switch (event.type)
-    {
-    case ENET_EVENT_TYPE_RECEIVE:
-      enet_packet_destroy(event.packet);
-      break;
-    case ENET_EVENT_TYPE_DISCONNECT:
-      puts("Disconnection succeeded.");
-      return 0;
-    }
-  }
-  // if disconnect failed
-  enet_peer_reset(peer);
-
-
-
-  return 0;
-}
Index: code/trunk/src/network/dummyclient2.cc
===================================================================
--- code/trunk/src/network/dummyclient2.cc	(revision 1639)
+++ 	(revision )
@@ -1,92 +1,0 @@
-/*
- *   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, (C) 2007
- *   Co-authors:
- *      ...
- *
- */
-
-//
-// Dummy client to test ConnectionManager, PacketBuffer, ClientConnection and other classes
-//
-// Author: Oliver Scheuss
-
-#include <iostream>
-#include <string>
-#include <enet/enet.h>
-
-#include "util/Sleep.h"
-#include "PacketManager.h"
-#include "PacketTypes.h"
-#include "ClientConnection.h"
-
-using namespace network;
-
-int main(){
-  network::PacketGenerator pck;
-
-  std::cout << "Enter address of the server xxx.xxx.xxx.xxx (enter for localhost)" << std::endl;
-  std::string str;
-  std::getline(std::cin, str);
-  std::cout << "You entered: " << str << std::endl;
-  if(str.compare("")==0)
-    str="127.0.0.1";
-
-  ClientConnection client = ClientConnection(55556, str);
-
-  client.createConnection();
-
-  if(client.waitEstablished(10000))
-    std::cout << "Connection established" << std::endl;
-  else
-    std::cout << "Connection failed" << std::endl;
-
-  ENetPacket *packet;  //FIXME: unused var!
-  ENetEvent event;
-
-
-
-  for(int i=0; i<10; i++){
-    // weihnachtsmann bringt packete
-    // extend the packet and append the string foo to it
-    // send packet to peer on channel id 0
-    client.addPacket(pck.chatMessage("test"));
-    // keep the timeout very small for low delay
-    if(client.sendPackets(&event)){
-      std::cout << "successfully sent: " << event.type << std::endl;
-    }else{
-      std::cout << "failed sending" << std::endl;
-    }
-    //    usleep(1000000);
-  }
-  usleep(1000000);
-  // now disconnect
-  if(client.closeConnection())
-    std::cout << "Connection successfully closed" << std::endl;
-  else
-    std::cout << "Connection closing failed" << std::endl;
-
-  // 3 seconds timeout
-  return 0;
-}
-
Index: code/trunk/src/network/dummyclient3.cc
===================================================================
--- code/trunk/src/network/dummyclient3.cc	(revision 1639)
+++ 	(revision )
@@ -1,115 +1,0 @@
-/*
- *   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:
- *      ...
- *   Co-authors:
- *      ...
- *
- */
-
-#include "Client.h"
-
-#include <iostream>
-#include <string>
-
-#include "util/Sleep.h"
-#include "PacketManager.h"
-#include "PacketTypes.h"
-
-using namespace network;
-
-void sender(){
-
-  network::PacketGenerator pck;
-  const int PORT = 55556;
-  COUT(0) << "Enter address of the server xxx.xxx.xxx.xxx (enter for localhost)" << std::endl;
-  std::string str;
-  std::getline(std::cin, str);
-  COUT(3) << "You entered: " << str << std::endl;
-  if(str.compare("")==0)
-    str="127.0.0.1";
-
-  Client client( str, PORT );
-  if ( client.establishConnection() )
-  {
-    COUT(3) << "connection established" << std::endl;
-  }
-  else
-  {
-    COUT(0) << "problems establishing connection" << std::endl;
-  }
-  char message[10000];
-  char signs[] = "abcdefghijklmnopqrstuvwxy";
-  while (true) {
-    client.tick(0);
-
-    std::cout << "your message2: ";
-    for ( int i=0; i<9999; i++ ) {
-      message[i] = signs[0];
-    }
-    message[9999] = 'z';
-    std::string str( message );
-    client.sendChat( str );
-    std::cout << str << std::endl;
-    std::cin.get(); std::cin.get();
-  }
-
-
-
-}
-
-void listener(){
-
-  const int PORT = 55556;
-  std::cout << "Enter address of the server xxx.xxx.xxx.xxx (enter for localhost)" << std::endl;
-  std::string str;
-  std::getline(std::cin, str);
-  std::cout << "You entered: " << str << std::endl;
-  if(str.compare("")==0)
-    str="127.0.0.1";
-
-  Client client( str, PORT );
-  if ( client.establishConnection() )
-    std::cout << "connection established" << std::endl;
-  else std::cout << "problems establishing connection" << std::endl;
-
-  while (true) {
-    client.tick(0);
-    usleep(100);
-  }
-
-
-
-}
-
-
-int main(int argc, char **argv[]){
-  std::string in;
-  std::cout << "Please choose: sender(s) oder listener(l)" << std::endl;
-  std::getline(std::cin, in);
-  if(in.compare("l")==0)
-    listener();
-  else if(in.compare("s")==0)
-    sender();
-  else
-    std::cout << "wrong answer" << std::endl;
-}
Index: code/trunk/src/network/dummyclient4.cc
===================================================================
--- code/trunk/src/network/dummyclient4.cc	(revision 1639)
+++ 	(revision )
@@ -1,29 +1,0 @@
-#include <iostream>
-#include <string>
-#include <enet/enet.h>
-#include <network/PacketManager.h>
-#include <network/PacketTypes.h>
-#include <network/Client.h>
-#include "core/Tickable.h"
-#include "core/BaseObject.h"
-#include "Synchronisable.h"
-#include "core/CoreIncludes.h"
-#include "objects/SpaceShip.h"
-
-int main() {
-  std::cout << "dummyclient4" << std::endl;
-  network::Client* client;
-  client = network::Client::createSingleton( "127.0.0.1", 55556 );
-  if(client->establishConnection())
-    std::cout << "established connection" << std::endl;
-  else{
-    std::cout << "could not establish connection" << std::endl;
-    return -1;
-  }
-  if(client->closeConnection())
-    std::cout << "closed connection" << std::endl;
-  else
-    std::cout << "could not close connection" << std::endl;
-}
-
-
Index: code/trunk/src/network/dummyserver.cc
===================================================================
--- code/trunk/src/network/dummyserver.cc	(revision 1639)
+++ 	(revision )
@@ -1,74 +1,0 @@
-/*
- *   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, (C) 2007
- *   Co-authors:
- *      ...
- *
- */
-
-//
-// Dummy server to test ConnectionManager and PacketBuffer classes
-//
-// Author: Oliver Scheuss
-
-#include <iostream>
-#include <enet/enet.h>
-
-#include "util/Sleep.h"
-#include "ConnectionManager.h"
-#include "PacketManager.h"
-#include "PacketTypes.h"
-#include "ClientInformation.h"
-
-using namespace network;
-
-int main(){
-  bool quit=false;
-  ENetPacket *packet;
-  ClientInformation clients;
-  ConnectionManager server = ConnectionManager(&clients);
-  server.createListener();
-
-  PacketDecoder dec;
-
-  while(!quit){
-    if(server.queueEmpty())
-      // Warning: usleep(100) is Sleep(100/1000) = Sleep(0), which is nothing!
-      usleep(1);
-    else{
-      ENetAddress addr;
-      packet=server.getPacket(addr);
-      if(packet==NULL){
-        // there was some error
-        //std::cout << "null pointer" << std::endl;
-        quit=true;
-      }
-      else{
-        //std::cout << "We received: " << packet->data << std::endl;
-        dec.elaborate(packet, 1);
-      }
-    }
-  }
-  server.quitListener();
-  return 0;
-}
Index: code/trunk/src/network/dummyserver3.cc
===================================================================
--- code/trunk/src/network/dummyserver3.cc	(revision 1639)
+++ 	(revision )
@@ -1,81 +1,0 @@
-/*
- *   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, (C) 2007
- *   Co-authors:
- *      ...
- *
- */
-
-#include "Server.h"
-
-#include <iostream>
-
-#include "util/Sleep.h"
-#include "PacketManager.h"
-#include "PacketTypes.h"
-
-namespace network
-{
-
-  class dummyserver3 : public Server
-  {
-  public:
-    dummyserver3();
-    ~dummyserver3();
-    void loop();
-  private:
-    void tick();
-    void processChat( chat *data, int clientId);
-
-
-  };
-
-  dummyserver3::dummyserver3(){
-  }
-  dummyserver3::~dummyserver3(){
-  }
-
-  void dummyserver3::loop(){
-    open();
-    while(true){
-      tick();
-      usleep(100);
-    }
-  }
-
-  void dummyserver3::processChat( chat *data, int clientId){
-    std::cout << "Client " << clientId << " sent: " << data->message << std::endl;
-    sendMSG(data->message);
-  }
-
-  void dummyserver3::tick(){
-    processQueue();
-  }
-
-}
-
-int main(int argc, char **argv[]){
-  network::dummyserver3 server;
-  server.loop();
-  return 0;
-}
Index: code/trunk/src/network/dummyserver4.cc
===================================================================
--- code/trunk/src/network/dummyserver4.cc	(revision 1639)
+++ 	(revision )
@@ -1,22 +1,0 @@
-#include <iostream>
-#include <string>
-#include <enet/enet.h>
-#include <network/PacketManager.h>
-#include <network/PacketTypes.h>
-#include <network/Server.h>
-#include "core/Tickable.h"
-#include "core/BaseObject.h"
-#include "Synchronisable.h"
-#include "core/CoreIncludes.h"
-#include "objects/SpaceShip.h"
-#include "util/Sleep.h"
-
-int main() {
-  network::Server *server = new network::Server();
-  server->open();
-  while(true){
-    usleep( 1000 );
-  }
-  server->close();
-  return 0;
-}
Index: code/trunk/src/network/packet/Acknowledgement.cc
===================================================================
--- code/trunk/src/network/packet/Acknowledgement.cc	(revision 1735)
+++ code/trunk/src/network/packet/Acknowledgement.cc	(revision 1735)
@@ -0,0 +1,75 @@
+/*
+ *   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, (C) 2008
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+
+#include "Acknowledgement.h"
+#include "network/Host.h"
+#include "network/GamestateHandler.h"
+
+namespace network {
+namespace packet {
+
+#define PACKET_FLAGS_ACK    0
+#define _PACKETID           0
+#define _ACKID              _PACKETID + sizeof(network::packet::ENUM::Type)
+  
+Acknowledgement::Acknowledgement( unsigned int id, int clientID )
+ : Packet()
+{
+  flags_ = flags_ | PACKET_FLAGS_ACK;
+  data_=new unsigned char[ getSize() ];
+  *(ENUM::Type *)(data_ + _PACKETID ) = ENUM::Acknowledgement;
+  *(unsigned int *)&data_[ _ACKID ] = id;
+  clientID_=clientID;
+}
+
+Acknowledgement::Acknowledgement( unsigned char *data, int clientID )
+  : Packet(data, clientID)
+{
+}
+
+Acknowledgement::~Acknowledgement()
+{
+}
+
+unsigned int Acknowledgement::getSize() const{
+  return _ACKID + sizeof(unsigned int);
+}
+
+bool Acknowledgement::process(){
+  bool b = GamestateHandler::ackGamestate(data_[_ACKID], clientID_);
+  delete this;
+  return b;
+}
+
+unsigned int Acknowledgement::getAckID(){
+  return *(unsigned int *)&data_[ _ACKID ];
+}
+
+} //namespace packet
+} //namespace network
Index: code/trunk/src/network/packet/Acknowledgement.h
===================================================================
--- code/trunk/src/network/packet/Acknowledgement.h	(revision 1735)
+++ code/trunk/src/network/packet/Acknowledgement.h	(revision 1735)
@@ -0,0 +1,56 @@
+/*
+ *   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:
+ *      ...
+ *
+ */
+#ifndef NETWORKACKNOLEDGEMENT_H
+#define NETWORKACKNOLEDGEMENT_H
+
+#include "Packet.h"
+
+
+namespace network {
+namespace packet {
+/**
+	@author 
+*/
+class Acknowledgement : public Packet
+{
+public:
+  Acknowledgement( unsigned int id, int clientID );
+  Acknowledgement( unsigned char* data, int clientID );
+  ~Acknowledgement();
+  
+  inline unsigned int getSize() const;
+  bool process();
+  
+  unsigned int getAckID();
+private:
+};
+
+} //namespace packet
+} //namespace network
+
+#endif
Index: code/trunk/src/network/packet/Chat.cc
===================================================================
--- code/trunk/src/network/packet/Chat.cc	(revision 1735)
+++ code/trunk/src/network/packet/Chat.cc	(revision 1735)
@@ -0,0 +1,78 @@
+/*
+ *   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 "Chat.h"
+#include <assert.h>
+
+namespace network {
+namespace packet {
+  
+#define PACKET_FLAGS_CHAT ENET_PACKET_FLAG_RELIABLE
+#define _PACKETID         0
+#define _MESSAGELENGTH    _PACKETID + sizeof(ENUM::Type)
+#define _MESSAGE          _MESSAGELENGTH + sizeof(unsigned int)
+
+Chat::Chat( std::string& message, int clientID )
+ : Packet()
+{
+  flags_ = flags_ | PACKET_FLAGS_CHAT;
+  messageLength_ = message.length()+1;
+  data_=new unsigned char[ getSize() ];
+  *(ENUM::Type *)&data_[ _PACKETID ] = ENUM::Chat;
+  *(unsigned int *)&data_[ _MESSAGELENGTH ] = messageLength_;
+  memcpy( &data_[ _MESSAGE ], (void *)message.c_str(), messageLength_ );
+  clientID_=clientID;
+}
+
+Chat::Chat( unsigned char *data, int clientID )
+  : Packet(data, clientID)
+{
+  messageLength_ = *(unsigned int *)&data[ _MESSAGELENGTH ];
+}
+
+Chat::~Chat()
+{
+}
+
+unsigned int Chat::getSize() const{
+  return _MESSAGE + messageLength_;
+}
+
+bool Chat::process(){
+  //TODO: change this !!!
+  assert(0);
+  delete this;
+  return true;
+}
+
+unsigned char *Chat::getMessage(){
+  return &data_[ _MESSAGE ];
+}
+
+} //namespace packet
+} //namespace network
Index: code/trunk/src/network/packet/Chat.h
===================================================================
--- code/trunk/src/network/packet/Chat.h	(revision 1735)
+++ code/trunk/src/network/packet/Chat.h	(revision 1735)
@@ -0,0 +1,34 @@
+
+#ifndef NETWORKCHAT_H
+#define NETWORKCHAT_H
+
+#include <string>
+
+#include "Packet.h"
+
+namespace network {
+namespace packet {
+/**
+	@author 
+*/
+class Chat : public Packet
+{
+public:
+  Chat( std::string& message, int clientID );
+  Chat( unsigned char* data, int clientID );
+  ~Chat();
+  
+  inline unsigned int getSize() const;
+  bool process();
+  
+  unsigned int getMessageLength(){ return messageLength_; };
+  unsigned char *getMessage();
+private:
+  unsigned int messageLength_;
+  int clientID_;
+};
+
+} //namespace packet
+} //namespace network
+
+#endif
Index: code/trunk/src/network/packet/ClassID.cc
===================================================================
--- code/trunk/src/network/packet/ClassID.cc	(revision 1735)
+++ code/trunk/src/network/packet/ClassID.cc	(revision 1735)
@@ -0,0 +1,88 @@
+/*
+ *   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, (C) 2008
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+
+
+#include "ClassID.h"
+#include "core/CoreIncludes.h"
+#include <string>
+#include <assert.h>
+
+namespace network {
+namespace packet {
+
+#define PACKET_FLAGS_CLASSID  ENET_PACKET_FLAG_RELIABLE
+#define _PACKETID             0
+#define _CLASSID              _PACKETID + sizeof(ENUM::Type)
+#define _CLASSNAMELENGTH      _CLASSID + sizeof(unsigned int)
+#define _CLASSNAME            _CLASSNAMELENGTH + sizeof(classNameLength_)
+  
+  ClassID::ClassID( unsigned int classID, std::string className )
+ : Packet()
+{
+  flags_ = flags_ | PACKET_FLAGS_CLASSID;
+  classNameLength_=className.length()+1;
+  assert(getSize());
+  data_=new unsigned char[ getSize() ];
+  assert(data_);
+  *(ENUM::Type *)(data_ + _PACKETID ) = ENUM::ClassID;
+  *(unsigned int *)(data_ + _CLASSID ) = classID;
+  *(unsigned int *)(data_ + _CLASSNAMELENGTH ) = classNameLength_;
+  memcpy( data_+_CLASSNAME, (void *)className.c_str(), classNameLength_ );
+}
+
+ClassID::ClassID( unsigned char *data, int clientID )
+  : Packet(data, clientID)
+{
+  memcpy( (void *)&classNameLength_, &data[ _CLASSNAMELENGTH ], sizeof(classNameLength_) );
+}
+
+ClassID::~ClassID()
+{
+}
+
+unsigned int ClassID::getSize() const{
+  return sizeof(network::packet::ENUM::Type) + 2*sizeof(unsigned int) + classNameLength_;
+}
+
+bool ClassID::process(){
+  COUT(3) << "processing classid: " << getClassID() << " name: " << (const char*)(data_+_CLASSNAME) << std::endl;
+  orxonox::Identifier *id=ID( std::string((const char*)(data_+_CLASSNAME) ));
+  if(id==NULL)
+    return false;
+  id->setNetworkID( getClassID() );
+  delete this;
+  return true;
+}
+
+unsigned int ClassID::getClassID(){
+  return *(unsigned int *)&data_[ _CLASSID ];
+}
+
+} //namespace packet
+}//namespace network
Index: code/trunk/src/network/packet/ClassID.h
===================================================================
--- code/trunk/src/network/packet/ClassID.h	(revision 1735)
+++ code/trunk/src/network/packet/ClassID.h	(revision 1735)
@@ -0,0 +1,61 @@
+/*
+ *   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:
+ *      ...
+ *
+ */
+#ifndef NETWORKCLASSID_H
+#define NETWORKCLASSID_H
+
+#include <string>
+
+#include "Packet.h"
+
+namespace network {
+namespace packet {
+
+/**
+	@author 
+*/
+class ClassID : public Packet
+{
+public:
+  ClassID( unsigned int classID, std::string className );
+  ClassID( unsigned char* data, int clientID );
+  ~ClassID();
+  
+  inline unsigned int getSize() const;
+  bool process();
+  
+  unsigned int getClassID();
+  unsigned int getClassNameLength(){ return classNameLength_; }
+  unsigned char *getClassName();
+private:
+  unsigned int classNameLength_;
+};
+
+} //namespace packet
+} //namespace network
+
+#endif
Index: code/trunk/src/network/packet/Gamestate.cc
===================================================================
--- code/trunk/src/network/packet/Gamestate.cc	(revision 1735)
+++ code/trunk/src/network/packet/Gamestate.cc	(revision 1735)
@@ -0,0 +1,348 @@
+/*
+ *   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, (C) 2008
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "Gamestate.h"
+#include "network/ClientInformation.h"
+#include "network/GamestateHandler.h"
+
+#include <zlib.h>
+#include <assert.h>
+
+
+
+namespace network {
+
+namespace packet {
+  
+
+#define GAMESTATE_START(data) data + sizeof(GamestateHeader)
+#define GAMESTATE_HEADER(data) ((GamestateHeader *)data)
+#define HEADER GAMESTATE_HEADER(data_)
+  
+Gamestate::Gamestate()
+{
+}
+
+Gamestate::Gamestate(unsigned char *data, int clientID):
+    Packet(data, clientID)
+{
+}
+
+
+Gamestate::~Gamestate()
+{
+}
+
+bool Gamestate::collectData(int id, int mode)
+{
+  int tempsize=0, currentsize=0;
+  assert(data_==0 /*&& bs_==0*/);
+  int size = calcGamestateSize(mode);
+  
+  COUT(4) << "G.ST.Man: producing gamestate with id: " << id << std::endl;
+    //retval->data = (unsigned char*)malloc(size);
+  if(size==0)
+    return false;
+  data_ = new unsigned char[size + sizeof(GamestateHeader)];
+  //bs_ = new Bytestream(data_+sizeof(GamestateHeader), size);
+  if(!data_){
+    COUT(2) << "GameStateManager: could not allocate memory" << std::endl;
+    return false;
+  }
+
+  //start collect data synchronisable by synchronisable
+  unsigned char *mem=data_;
+  mem+=sizeof(GamestateHeader);
+  orxonox::Iterator<Synchronisable> it;
+  for(it = orxonox::ObjectList<Synchronisable>::start(); it; ++it){
+    tempsize=it->getSize2(mode);
+    
+    if(currentsize+tempsize > size){
+      // start allocate additional memory
+      COUT(3) << "G.St.Man: need additional memory" << std::endl;
+      orxonox::Iterator<Synchronisable> temp = it;
+      int addsize=tempsize;
+      while(++temp)
+        addsize+=temp->getSize2(mode);
+      data_ = (unsigned char *)realloc(data_, sizeof(GamestateHeader) + currentsize + addsize);
+      if(!data_)
+        return false;
+      size = currentsize+addsize;
+    }// stop allocate additional memory
+
+    if(!it->getData2(mem, mode))
+      return false; // mem pointer gets automatically increased because of call by reference
+    // increase size counter by size of current synchronisable
+    currentsize+=tempsize;
+  }
+  
+  
+  //start write gamestate header
+  HEADER->packetType = ENUM::Gamestate;
+  assert( *(ENUM::Type *)(data_) == ENUM::Gamestate); 
+  HEADER->normsize = currentsize;
+  HEADER->id = id;
+  HEADER->diffed = false;
+  HEADER->complete = true;
+  HEADER->compressed = false;
+  //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;
+  return true;
+}
+
+bool Gamestate::spreadData(int mode)
+{
+  assert(data_ && !HEADER->compressed && !HEADER->diffed);
+  unsigned int size, objectID, classID;
+  unsigned char *mem=data_+sizeof(GamestateHeader);
+    // get the start of the Synchronisable list
+  orxonox::Iterator<Synchronisable> it=orxonox::ObjectList<Synchronisable>::start();
+  
+  while(mem < data_+sizeof(GamestateHeader)+HEADER->normsize){
+      // extract synchronisable header
+    size = *(unsigned int *)mem;
+    objectID = *(unsigned int*)(mem+sizeof(unsigned int));
+    classID = *(unsigned int*)(mem+2*sizeof(unsigned int));
+
+    if(!it || it->objectID!=objectID || it->classID!=classID){
+        // bad luck ;)
+        // delete the synchronisable (obviously seems to be deleted on the server)
+      while(it && it->objectID!=objectID)
+        removeObject(it);
+
+      if(!it){
+        //fabricate the new synchronisable
+        if(!Synchronisable::fabricate(mem, mode))
+          /*return false*/;
+        it=orxonox::ObjectList<Synchronisable>::end();
+      }
+    } else 
+    {
+        // we have our object
+      if(! it->updateData(mem, mode))
+      {
+        COUT(1) << "We couldn't update objectID: " \
+            << objectID << "; classID: " << classID << std::endl;
+      }
+    }
+    ++it;
+  }
+
+  return true;
+}
+
+int Gamestate::getID(){
+  return HEADER->id;
+}
+
+unsigned int Gamestate::getSize() const
+{
+  assert(data_);
+  if(HEADER->compressed)
+    return HEADER->compsize+sizeof(GamestateHeader);
+  else
+  {
+    return HEADER->normsize+sizeof(GamestateHeader);
+  }
+}
+
+bool Gamestate::process()
+{
+  return GamestateHandler::addGamestate(this, getClientID());
+}
+
+bool Gamestate::compressData()
+{
+  assert(HEADER);
+  uLongf buffer = (uLongf)((HEADER->normsize + 12)*1.01)+1;
+  if(buffer==0)
+    return false;
+  
+  unsigned char *ndata = new unsigned char[buffer+sizeof(GamestateHeader)];
+  unsigned char *dest = GAMESTATE_START(ndata);
+  int retval;
+  retval = compress( dest, &buffer, GAMESTATE_START(data_), (uLong)(HEADER->normsize) );
+  switch ( retval ) {
+    case Z_OK: COUT(5) << "G.St.Man: compress: successfully compressed" << std::endl; break;
+    case Z_MEM_ERROR: COUT(1) << "G.St.Man: compress: not enough memory available in gamestate.compress" << std::endl; 
+    return false;
+    case Z_BUF_ERROR: COUT(2) << "G.St.Man: compress: not enough memory available in the buffer in gamestate.compress" << std::endl;
+    return false;
+    case Z_DATA_ERROR: COUT(2) << "G.St.Man: compress: data corrupted in gamestate.compress" << std::endl;
+    return false;
+  }
+
+  //copy and modify header
+  HEADER->compsize = buffer;
+  HEADER->compressed = true;
+  *GAMESTATE_HEADER(ndata) = *HEADER;
+  //delete old data
+  delete[] data_;
+  //save new data
+  data_ = ndata;
+  assert(HEADER->compressed);
+  COUT(3) << "gamestate compress normsize: " << HEADER->normsize << " compsize: " << HEADER->compsize << std::endl;
+  return true;
+}
+bool Gamestate::decompressData()
+{
+  assert(HEADER->compressed);
+  //COUT(4) << "GameStateClient: uncompressing gamestate. id: " << a->id << ", baseid: " << a->base_id << ", normsize: " << a->normsize << ", compsize: " << a->compsize << std::endl;
+  int normsize = HEADER->normsize;
+  int compsize = HEADER->compsize;
+  int bufsize;
+  if(normsize < compsize)
+    bufsize = compsize;
+  else
+    bufsize = normsize;
+  if(bufsize==0)
+    return NULL;
+  unsigned char *ndata = new unsigned char[bufsize + sizeof(GamestateHeader)];
+  unsigned char *dest = ndata + sizeof(GamestateHeader);
+  int retval;
+  uLongf length=normsize;
+  retval = uncompress( dest, &length, data_+sizeof(GamestateHeader), (uLong)compsize );
+  switch ( retval ) {
+    case Z_OK: COUT(5) << "successfully decompressed" << std::endl; break;
+    case Z_MEM_ERROR: COUT(1) << "not enough memory available" << std::endl; return false;
+    case Z_BUF_ERROR: COUT(2) << "not enough memory available in the buffer" << std::endl; return false;
+    case Z_DATA_ERROR: COUT(2) << "data corrupted (zlib)" << std::endl; return false;
+  }
+  
+  HEADER->compressed = false;
+  //copy over the header
+  *GAMESTATE_HEADER(ndata) = *HEADER;
+  //delete old (compressed data)
+  delete[] data_;
+  //set new pointers and create bytestream
+  data_ = ndata;
+  //bs_ = new Bytestream(getGs(), GAMESTATE_HEADER->normsize);
+  
+  return true;
+}
+
+Gamestate *Gamestate::diff(Gamestate *base)
+{
+  //unsigned char *basep = base->getGs()/*, *gs = getGs()*/;
+  unsigned char *basep = GAMESTATE_START(base->data_), *gs = GAMESTATE_START(this->data_);
+  unsigned int of=0; // pointers offset
+  unsigned int dest_length=0;
+  dest_length=HEADER->normsize;
+  if(dest_length==0)
+    return NULL;
+  unsigned char *ndata = new unsigned char[dest_length*sizeof(unsigned char)+sizeof(GamestateHeader)];
+  unsigned char *dest = ndata + sizeof(GamestateHeader);
+  while(of < GAMESTATE_HEADER(base->data_)->normsize && of < HEADER->normsize){
+    *(dest+of)=*(basep+of)^*(gs+of); // do the xor
+    ++of;
+  }
+  if(GAMESTATE_HEADER(base->data_)->normsize!=HEADER->normsize){
+    unsigned char n=0;
+    if(GAMESTATE_HEADER(base->data_)->normsize < HEADER->normsize){
+      while(of<dest_length){
+        *(dest+of)=n^*(gs+of);
+        of++;
+      }
+    }
+  }
+
+  *GAMESTATE_HEADER(ndata) = *HEADER;
+  GAMESTATE_HEADER(ndata)->diffed = true;
+  Gamestate *g = new Gamestate(ndata, 0);
+  return g;
+}
+
+Gamestate *Gamestate::undiff(Gamestate *base)
+{
+  assert(this && base);
+  assert(!HEADER->compressed && !GAMESTATE_HEADER(base->data_)->compressed);
+  //unsigned char *basep = base->getGs()/*, *gs = getGs()*/;
+  unsigned char *basep = GAMESTATE_START(base->data_);
+  unsigned char *gs = GAMESTATE_START(this->data_);
+  unsigned int of=0; // pointers offset
+  unsigned int dest_length=0;
+  dest_length=HEADER->normsize;
+  if(dest_length==0)
+    return NULL;
+  unsigned char *ndata = new unsigned char[dest_length*sizeof(unsigned char)+sizeof(GamestateHeader)];
+  unsigned char *dest = ndata + sizeof(GamestateHeader);
+  while(of < GAMESTATE_HEADER(base->data_)->normsize && of < HEADER->normsize){
+    *(dest+of)=*(basep+of)^*(gs+of); // do the xor
+    ++of;
+  }
+  if(GAMESTATE_HEADER(base->data_)->normsize!=HEADER->normsize){
+    unsigned char n=0;
+    if(GAMESTATE_HEADER(base->data_)->normsize < HEADER->normsize){
+      while(of < dest_length){
+        *(dest+of)=n^*(gs+of);
+        of++;
+      }
+    }
+  }
+  *GAMESTATE_HEADER(ndata) = *HEADER;
+  GAMESTATE_HEADER(ndata)->diffed = false;
+  Gamestate *g = new Gamestate(ndata, 0);
+  return g;
+}
+
+
+unsigned int Gamestate::calcGamestateSize(int mode)
+{
+  int size=0;
+    // get the start of the Synchronisable list
+  orxonox::Iterator<Synchronisable> it;
+    // get total size of gamestate
+  for(it = orxonox::ObjectList<Synchronisable>::start(); it; ++it)
+    size+=it->getSize2(mode); // size of the actual data of the synchronisable
+//  size+=sizeof(GamestateHeader);
+  return size;
+}
+
+/**
+ * This function removes a Synchronisable out of the universe
+ * @param it iterator of the list pointing to the object
+ * @return iterator pointing to the next object in the list
+ */
+  void Gamestate::removeObject(orxonox::Iterator<Synchronisable> &it) {
+    orxonox::Iterator<Synchronisable> temp=it;
+    ++it;
+    delete  *temp;
+  }
+
+  bool Gamestate::isDiffed(){
+    return HEADER->diffed;
+  }
+  
+  int Gamestate::getBaseID(){
+    return HEADER->base_id;
+  }
+}
+
+}
Index: code/trunk/src/network/packet/Gamestate.h
===================================================================
--- code/trunk/src/network/packet/Gamestate.h	(revision 1735)
+++ code/trunk/src/network/packet/Gamestate.h	(revision 1735)
@@ -0,0 +1,90 @@
+/*
+ *   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, (C) 2008
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "Packet.h"
+#include "network/Synchronisable.h"
+//#include "util/Bytestream.h"
+#include "core/CoreIncludes.h"
+
+#ifndef NETWORK_PACKETGAMESTATE_H
+#define NETWORK_PACKETGAMESTATE_H
+
+namespace network {
+
+namespace packet {
+  
+struct GamestateHeader{
+  ENUM::Type packetType;
+  int id; // id of the gamestate
+  unsigned int compsize;
+  unsigned int normsize;
+  int base_id; // id of the base-gamestate diffed from
+  bool diffed; // wheter diffed or not
+  bool complete; // wheter it is a complete gamestate or only partial
+  bool compressed;
+};
+
+/**
+	@author 
+*/
+class Gamestate: public Packet{
+  public:
+    Gamestate();
+    Gamestate(unsigned char *data, int clientID);
+    
+    ~Gamestate();
+    
+    bool collectData(int id, int mode=0x0);
+    bool spreadData(int mode=0x0);
+    int getID();
+    bool isDiffed();
+    int getBaseID();
+    Gamestate *diff(Gamestate *base);
+    Gamestate *undiff(Gamestate *base);
+    bool compressData();
+    bool decompressData();
+    
+    // Packet functions
+    virtual unsigned int getSize() const;
+    virtual bool process();
+
+    
+  private:
+    unsigned int calcGamestateSize(int mode=0x0);
+    void removeObject(orxonox::Iterator<Synchronisable> &it);
+
+    
+    //Bytestream *bs_;
+    //GamestateHeader *header_;
+};
+
+}
+
+}
+
+#endif
Index: code/trunk/src/network/packet/Packet.cc
===================================================================
--- code/trunk/src/network/packet/Packet.cc	(revision 1735)
+++ code/trunk/src/network/packet/Packet.cc	(revision 1735)
@@ -0,0 +1,176 @@
+/*
+ *   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, (C) 2008
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+
+#include <enet/enet.h>
+#include <boost/bind.hpp>
+
+#include "Packet.h"
+#include "network/ConnectionManager.h"
+#include "network/ClientInformation.h"
+
+#include "Acknowledgement.h"
+#include "Chat.h"
+#include "ClassID.h"
+#include "Gamestate.h"
+#include "Welcome.h"
+#include "network/Host.h"
+#include "core/CoreIncludes.h"
+
+namespace network{
+
+namespace packet{
+  
+#define PACKET_FLAG_DEFAULT ENET_PACKET_FLAG_NO_ALLOCATE
+#define _PACKETID           0
+  
+std::map<ENetPacket *, Packet *> Packet::packetMap_;
+  
+Packet::Packet(){
+  flags_ = PACKET_FLAG_DEFAULT;
+  packetDirection_ = ENUM::Outgoing;
+  clientID_=0;
+  data_=0;
+  enetPacket_=0;
+}
+
+void blub(ENetPacket *packet){
+  COUT(4) << "blubb" << std::endl;
+}
+
+Packet::Packet(unsigned char *data, int clientID){
+  flags_ = PACKET_FLAG_DEFAULT;
+  packetDirection_ = ENUM::Incoming;
+  clientID_=clientID;
+  data_=data;
+  enetPacket_=0;
+}
+
+/*Packet::Packet(ENetPacket *packet, ENetPeer *peer){
+  packetDirection_ = ENUM::Incoming;
+  enetPacket_ = packet;
+  clientID_ = ClientInformation::findClient(&peer->address)->getID();
+  data_ = packet->data;
+}*/
+
+Packet::Packet(const Packet &p){
+  enetPacket_=p.enetPacket_;
+  flags_=p.flags_;
+  packetDirection_ = p.packetDirection_;
+  clientID_ = p.clientID_;
+  if(p.data_){
+    data_ = new unsigned char[p.getSize()];
+    memcpy(data_, p.data_, p.getSize());
+  }else
+    data_=0;
+}
+
+Packet::~Packet(){
+  if(enetPacket_)
+    enet_packet_destroy(enetPacket_);
+  if(data_)
+    delete[] data_;
+}
+
+bool Packet::send(){
+  if(packetDirection_ != ENUM::Outgoing && packetDirection_ != ENUM::Bidirectional ){
+    assert(0);
+    return false;
+  }
+  if(!enetPacket_){
+    if(!data_){
+      assert(0);
+      return false;
+    }
+    enetPacket_ = enet_packet_create(getData(), getSize(), getFlags());
+    //enetPacket_->freeCallback = &Packet::deletePacket;
+    enetPacket_->freeCallback = &blub;
+    packetMap_[enetPacket_] = this;
+  }
+  /*switch( *(ENUM::Type *)(data_ + _PACKETID) )
+  {
+    case ENUM::Acknowledgement:
+    case ENUM::Chat:
+    case ENUM::ClassID:
+    case ENUM::Gamestate:
+    case ENUM::Welcome:
+      COUT(3) << "welcome" << std::endl;
+      p = new Welcome( data, clientID );
+    default:
+      assert(0); //TODO: repair this
+      break;
+  }*/
+  network::Host::addPacket( enetPacket_, clientID_);
+  enetPacket_ = 0; // otherwise we have a double free because enet already handles the deallocation of the packet
+  return true;
+}
+
+Packet *Packet::createPacket(ENetPacket *packet, ENetPeer *peer){
+  unsigned char *data = packet->data;
+  unsigned int clientID = ClientInformation::findClient(&peer->address)->getID();
+  Packet *p;
+  COUT(3) << "packet type: " << *(ENUM::Type *)&data[_PACKETID] << std::endl;
+  switch( *(ENUM::Type *)(data + _PACKETID) )
+  {
+    case ENUM::Acknowledgement:
+      COUT(3) << "ack" << std::endl;
+      p = new Acknowledgement( data, clientID );
+      break;
+    case ENUM::Chat:
+      COUT(3) << "chat" << std::endl;
+      p = new Chat( data, clientID );
+      break;
+    case ENUM::ClassID:
+      COUT(3) << "classid" << std::endl;
+      p = new ClassID( data, clientID );
+      break;
+    case ENUM::Gamestate:
+      COUT(3) << "gamestate" << std::endl;
+      // TODO: remove brackets
+      p = new Gamestate( data, clientID );
+      break;
+    case ENUM::Welcome:
+      COUT(3) << "welcome" << std::endl;
+      p = new Welcome( data, clientID );
+      break;
+    default:
+      assert(0); //TODO: repair this
+      break;
+  }
+  return p;
+}
+
+void Packet::deletePacket(ENetPacket *packet){
+  assert(packetMap_[packet]);
+  delete packetMap_[packet];
+}
+
+} // namespace packet
+
+} // namespace network
+
Index: code/trunk/src/network/packet/Packet.h
===================================================================
--- code/trunk/src/network/packet/Packet.h	(revision 1735)
+++ code/trunk/src/network/packet/Packet.h	(revision 1735)
@@ -0,0 +1,91 @@
+/*
+ *   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:
+ *      ...
+ *
+ */
+#ifndef NETWORKPACKET_H
+#define NETWORKPACKET_H
+
+#include <map>
+#include <enet/enet.h>
+
+namespace network {
+
+namespace packet{
+  
+namespace ENUM{
+  enum Direction{
+    Incoming,
+    Outgoing,
+    Bidirectional
+  };
+  enum Type{
+    Acknowledgement,
+    Gamestate,
+    ClassID,
+    Chat,
+    Welcome
+  };
+}
+  
+/**
+	@author Oliver Scheuss <scheusso [at] ee.ethz.ch>
+*/
+class Packet{
+  public:
+    Packet(const Packet &p);
+    virtual ~Packet();
+    static Packet *createPacket(ENetPacket *packet, ENetPeer *peer);
+    static void deletePacket(ENetPacket *packet);
+    
+    virtual unsigned char *getData(){ return data_; };
+    virtual unsigned int getSize() const =0;
+    virtual bool process()=0;
+    enet_uint32 getFlags()
+      { return flags_; }
+    int getClientID()
+      { return clientID_; }
+    void setClientID( int id )
+      { clientID_ = id; }
+    
+    bool send();
+  protected:
+    Packet();
+    Packet(unsigned char *data, int clientID);
+//    Packet(ENetPacket *packet, ENetPeer *peer);
+    enet_uint32 flags_;
+    int clientID_;
+    unsigned char *data_;
+  private:
+    static std::map<ENetPacket *, Packet *> packetMap_;
+    ENetPacket *enetPacket_;
+    ENUM::Direction packetDirection_;
+};
+
+} //namespace packet
+
+} //namespace network
+
+#endif
Index: code/trunk/src/network/packet/Welcome.cc
===================================================================
--- code/trunk/src/network/packet/Welcome.cc	(revision 1735)
+++ code/trunk/src/network/packet/Welcome.cc	(revision 1735)
@@ -0,0 +1,87 @@
+
+
+/*
+ *   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, (C) 2008
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+
+#include "Welcome.h"
+#include "network/Host.h"
+#include "core/CoreIncludes.h"
+#include <assert.h>
+
+namespace network {
+namespace packet {
+
+#define PACKET_FLAGS_CLASSID  ENET_PACKET_FLAG_RELIABLE
+#define _PACKETID             0
+#define _CLIENTID             _PACKETID + sizeof(ENUM::Type)
+#define _SHIPID               _CLIENTID + sizeof(unsigned int)
+  
+  Welcome::Welcome( unsigned int clientID, unsigned int shipID )
+ : Packet()
+{
+  flags_ = flags_ | PACKET_FLAGS_CLASSID;
+  assert(getSize());
+  data_=new unsigned char[ getSize() ];
+  assert(data_);
+  *(packet::ENUM::Type *)(data_ + _PACKETID ) = packet::ENUM::Welcome;
+  *(unsigned int *)&data_[ _CLIENTID ] = clientID;
+  *(unsigned int *)&data_[ _SHIPID ] = shipID;
+}
+
+Welcome::Welcome( unsigned char *data, int clientID )
+  : Packet(data, clientID)
+{
+}
+
+Welcome::~Welcome()
+{
+}
+
+unsigned char *Welcome::getData(){
+  return data_;
+}
+
+unsigned int Welcome::getSize() const{
+  return sizeof(network::packet::ENUM::Type) + 2*sizeof(unsigned int);
+}
+
+bool Welcome::process(){
+  unsigned int shipID, clientID;
+  clientID = *(unsigned int *)&data_[ _CLIENTID ];
+  shipID = *(unsigned int *)&data_[ _SHIPID ];
+  Host::setClientID(clientID);
+  Host::setShipID(shipID);
+  COUT(3) << "Welcome set clientId: " << clientID << " shipID: " << shipID << std::endl;
+  delete this;
+  return true;
+}
+
+
+} //namespace packet
+}//namespace network
Index: code/trunk/src/network/packet/Welcome.h
===================================================================
--- code/trunk/src/network/packet/Welcome.h	(revision 1735)
+++ code/trunk/src/network/packet/Welcome.h	(revision 1735)
@@ -0,0 +1,56 @@
+/*
+ *   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:
+ *      ...
+ *
+ */
+#ifndef NETWORKWELCOME_H
+#define NETWORKWELCOME_H
+
+#include "Packet.h"
+
+namespace network {
+namespace packet {
+
+/**
+	@author 
+*/
+class Welcome : public Packet
+{
+public:
+  Welcome( unsigned int clientID, unsigned int shipID );
+  Welcome( unsigned char* data, int clientID );
+  virtual ~Welcome();
+  
+  unsigned char *getData();
+  inline unsigned int getSize() const;
+  bool process();
+  
+private:
+};
+
+} //namespace packet
+} //namespace network
+
+#endif
