Index: code/branches/merge/CMakeLists.txt
===================================================================
--- code/branches/merge/CMakeLists.txt	(revision 1263)
+++ code/branches/merge/CMakeLists.txt	(revision 1264)
@@ -42,6 +42,6 @@
 
 # global compiler/linker flags. force -O2!
-SET(CMAKE_C_FLAGS "$ENV{CFLAGS} -O2 -Wall -g -ggdb")
-SET(CMAKE_CXX_FLAGS "$ENV{CXXFLAGS} -O2 -Wall -g -ggdb")
+SET(CMAKE_C_FLAGS "$ENV{CFLAGS} -O0 -Wall -g -ggdb")
+SET(CMAKE_CXX_FLAGS "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb")
 SET(CMAKE_LD_FLAGS "$ENV{LDFLAGS}")
 SET(CMAKE_EXE_LINKER_FLAGS " --no-undefined")
Index: code/branches/merge/TODO
===================================================================
--- code/branches/merge/TODO	(revision 1264)
+++ code/branches/merge/TODO	(revision 1264)
@@ -0,0 +1,2 @@
+very urgent: make sure receiver thread of connectionmanager is 
+threadsafe (event_type_receive, findclient)
Index: code/branches/merge/bin/levels/sample.oxw
===================================================================
--- code/branches/merge/bin/levels/sample.oxw	(revision 1263)
+++ code/branches/merge/bin/levels/sample.oxw	(revision 1264)
@@ -9,7 +9,6 @@
   </audio--> 
 
-<Ambient colourvalue="1,1,1" />
+<!--Ambient colourvalue="1,1,1" /-->
 <Skybox src="Orxonox/StarSkyBox" />
-
 <SpaceShip camera="true" position="0,0,0" scale="10" yawpitchroll="-90,-90,0" mesh="assf3.mesh" maxSpeed="500" maxSideAndBackSpeed="50" maxRotation="1.0" transAcc="200" rotAcc="3.0" transDamp="75" rotDamp="1.0" />
 
@@ -31,9 +30,9 @@
 </Model-->
 
-<Model position="-200,1000,500" scale="10" mesh="hoover_body.mesh" yawpitchroll="-90,-90,0" />
+<!--Model position="-200,1000,500" scale="10" mesh="hoover_body.mesh" yawpitchroll="-90,-90,0" />
 <Model position="-200,1000,500" scale="10" mesh="hoover_gear0.mesh" yawpitchroll="-90,-90,0" />
 <Model position="-200,1000,500" scale="10" mesh="hoover_gear1.mesh" yawpitchroll="-90,-90,0" />
 <Model position="-200,1000,500" scale="10" mesh="hoover_gear2.mesh" yawpitchroll="-90,-90,0" />
-<Model position="-200,1000,500" scale="10" mesh="hoover_turbine.mesh" yawpitchroll="-90,-90,0" />
+<Model position="-200,1000,500" scale="10" mesh="hoover_turbine.mesh" yawpitchroll="-90,-90,0" /-->
 
 
Index: code/branches/merge/cmake/FindBoost.cmake
===================================================================
--- code/branches/merge/cmake/FindBoost.cmake	(revision 1263)
+++ code/branches/merge/cmake/FindBoost.cmake	(revision 1264)
@@ -101,4 +101,5 @@
 # Add in some path suffixes. These will have to be updated whenever a new Boost version comes out.
 SET(SUFFIX_FOR_PATH
+ boost
  boost-1_34_1
  boost-1_34_0
Index: code/branches/merge/src/network/CMakeLists.txt
===================================================================
--- code/branches/merge/src/network/CMakeLists.txt	(revision 1263)
+++ code/branches/merge/src/network/CMakeLists.txt	(revision 1264)
@@ -11,5 +11,4 @@
   Server.cc
   Synchronisable.cc
-  dummyserver3.cc
 )
 
@@ -30,4 +29,31 @@
 # build those parts only on request.
 IF(NETWORK_TESTING_ENABLED)
+  ##### 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  
+  )
+
+  ADD_EXECUTABLE(networktest ${TEST_SRC_FILES})
+  TARGET_LINK_LIBRARIES( networktest
+    ${OGRE_LIBRARIES}
+    network
+    ${ENet_LIBRARY}
+    ${ZLIB_LIBRARY}
+    ${WINDOWS_ENET_DEPENDENCIES}
+  )
+  ##### end test for gamestate stuff #####
+ENDIF(NETWORK_TESTING_ENABLED)
+IF(BLABLA)
   SET( CHATCLIENT_SRC_FILES
     ClientConnection.cc
@@ -95,3 +121,4 @@
     ${WINDOWS_ENET_DEPENDENCIES}
   )
-ENDIF(NETWORK_TESTING_ENABLED)
+ENDIF(BLABLA)
+
Index: code/branches/merge/src/network/Client.cc
===================================================================
--- code/branches/merge/src/network/Client.cc	(revision 1263)
+++ code/branches/merge/src/network/Client.cc	(revision 1264)
@@ -40,8 +40,41 @@
 
 #include "Client.h"
+#include "Synchronisable.h"
 #include "core/CoreIncludes.h"
 
 namespace network
 {
+  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; 
+  }
+  
   /**
   * Constructor for the Client class
@@ -51,4 +84,5 @@
     // set server address to localhost
     isConnected=false;
+    isSynched_=false;
   }
 
@@ -60,4 +94,5 @@
   Client::Client(std::string address, int port) : client_connection(port, address){
     isConnected=false;
+    isSynched_=false;
   }
 
@@ -69,6 +104,12 @@
   Client::Client(const char *address, int port) : client_connection(port, address){
     isConnected=false;
-  }
-
+    isSynched_=false;
+  }
+
+  Client::~Client(){
+    if(isConnected)
+      closeConnection();
+  }
+  
   /**
   * Establish the Connection to the Server
@@ -76,5 +117,12 @@
   */
   bool Client::establishConnection(){
+    Synchronisable::setClient(true);
     isConnected=client_connection.createConnection();
+    if(isConnected){
+      COUT(4) << "sending connectrequest" << std::endl;
+      client_connection.addPacket(pck_gen.generateConnectRequest());
+      client_connection.sendPackets();
+    }else
+      COUT(1) << "could not create connection" << std::endl;
     return isConnected;
   }
@@ -181,4 +229,16 @@
   */
   void Client::tick(float time){
+    if(client_connection.isConnected() && isSynched_){
+      COUT(4) << "popping partial gamestate: " << std::endl;
+      GameStateCompressed *gs = gamestate.popPartialGameState();
+      if(gs){
+        COUT(4) << "client tick: sending gs " << gs << std::endl;
+        if(client_connection.addPacket(pck_gen.gstate(gs)))
+          COUT(3) << "Problem adding partial gamestate to queue" << std::endl;
+        // now delete it to save memory
+        delete[] gs->data;
+        delete gs;
+      }
+    }
     ENetPacket *packet;
     // stop if the packet queue is empty
@@ -188,14 +248,20 @@
       elaborate(packet, 0); // ================= i guess we got to change this .... (client_ID is always same = server)
     }
+    if(!client_connection.sendPackets())
+      COUT(3) << "Problem sending packets to server" << std::endl;
     return;
   }
 
-  void Client::processGamestate( GameStateCompressed *data){
+  void Client::processGamestate( GameStateCompressed *data, int clientID){
     int id = data->id;
     COUT(5) << "received gamestate id: " << data->id << std::endl;
-    gamestate.pushGameState(data);
-    client_connection.addPacket(pck_gen.acknowledgement(id));
-    client_connection.sendPackets();
-    return;
+    if(gamestate.pushGameState(data)){
+      if(!isSynched_)
+        isSynched_=true;
+      client_connection.addPacket(pck_gen.acknowledgement(id));
+        // we do this at the end of a tick
+       if(!client_connection.sendPackets())
+         COUT(2) << "Could not send acknowledgment" << std::endl;
+    }
   }
 
@@ -205,5 +271,6 @@
     if(id!=NULL)
       id->setNetworkID(clid->clid);
-    COUT(4) << "received and set network id: " << clid->clid << "; classname: " << clid->message << std::endl;
+    COUT(4) << "Client: received and set network id: " << clid->clid << "; classname: " << clid->message << std::endl;
+    delete clid;
     return;
   }
@@ -211,4 +278,14 @@
   void Client::processChat( chat *data){
     COUT(0) << "Server: " << 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/branches/merge/src/network/Client.h
===================================================================
--- code/branches/merge/src/network/Client.h	(revision 1263)
+++ code/branches/merge/src/network/Client.h	(revision 1264)
@@ -65,8 +65,11 @@
   class _NetworkExport Client : PacketDecoder, public orxonox::Tickable{
   public:
-    Client();
-    Client(std::string address, int port);
-    Client(const char *address, int port);
-
+    
+    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();
@@ -80,17 +83,31 @@
 
     bool sendPackets();
+    
+    int getShipID(){return shipID_;}
+    int getClientID(){return clientID_;}
 
     void tick(float time);
 
   private:
+    Client();
+    Client(std::string address, int port);
+    Client(const char *address, int port);
+    ~Client();
+    
+    static Client* _sClient;
+    
     ClientConnection client_connection;
     PacketGenerator pck_gen;
     GameStateClient gamestate;
     bool isConnected;
+    bool isSynched_;
 
     // implement data processing functions of PacketDecoder
-    void processGamestate( GameStateCompressed *data);
+    void processGamestate( GameStateCompressed *data, int clientID);
     void processClassid(classid *clid);
     void processChat( chat *data);
+    bool processWelcome( welcome *w );
+    int clientID_;     // this is the id the server gave to us
+    int shipID_;
   };
 
Index: code/branches/merge/src/network/ClientConnection.cc
===================================================================
--- code/branches/merge/src/network/ClientConnection.cc	(revision 1263)
+++ code/branches/merge/src/network/ClientConnection.cc	(revision 1264)
@@ -87,5 +87,5 @@
 
   ENetPacket *ClientConnection::getPacket() {
-    ENetAddress address;
+    ENetAddress address; //sems that address is not needed
     return getPacket(address);
   }
@@ -112,7 +112,12 @@
     if(server==NULL)
       return false;
-    if(enet_peer_send(server, 1, packet)!=0)
-      return false;
-    return true;
+    if(packet==NULL){
+      COUT(3) << "Cl.con: addpacket: invalid packet" << std::endl;
+      return false;
+    }
+    if(enet_peer_send(server, 0, packet)<0)
+      return false;
+    else
+      return true;
   }
 
@@ -162,6 +167,7 @@
       case ENET_EVENT_TYPE_CONNECT:
       case ENET_EVENT_TYPE_RECEIVE:
-        COUT(5) << "receiver-Thread: got new packet" << std::endl;
-        processData(&event);
+        COUT(5) << "Cl.Con: receiver-Thread while loop: got new packet" << std::endl;
+        if ( !processData(&event) ) COUT(2) << "Current packet was not pushed to packetBuffer -> ev ongoing SegFault" << std::endl;
+        COUT(5) << "Cl.Con: processed Data in receiver-thread while loop" << std::endl;
         break;
       case ENET_EVENT_TYPE_DISCONNECT:
@@ -203,5 +209,5 @@
   bool ClientConnection::establishConnection() {
     ENetEvent event;
-    // connect to peer
+    // connect to peer (server is type ENetPeer*)
     server = enet_host_connect(client, &serverAddress, NETWORK_CLIENT_CHANNELS);
     if(server==NULL)
@@ -218,5 +224,5 @@
 
   bool ClientConnection::processData(ENetEvent *event) {
-    COUT(5) << "got packet, pushing to queue" << std::endl;
+    COUT(5) << "Cl.Con: got packet, pushing to queue" << std::endl;
     // just add packet to the buffer
     // this can be extended with some preprocessing
Index: code/branches/merge/src/network/ClientConnection.h
===================================================================
--- code/branches/merge/src/network/ClientConnection.h	(revision 1263)
+++ code/branches/merge/src/network/ClientConnection.h	(revision 1264)
@@ -53,5 +53,5 @@
 #define NETWORK_PORT 55556
 #define NETWORK_CLIENT_MAX_CONNECTIONS 5
-#define NETWORK_CLIENT_TIMEOUT 10
+#define NETWORK_CLIENT_TIMEOUT 100
 #define NETWORK_SEND_WAIT 5
 #define NETWORK_CLIENT_CHANNELS 2
@@ -76,4 +76,5 @@
     bool sendPackets(ENetEvent *event);
     bool waitEstablished(int milisec);
+    bool isConnected(){return established;}
   private:
     bool processData(ENetEvent *event);
Index: code/branches/merge/src/network/ClientInformation.cc
===================================================================
--- code/branches/merge/src/network/ClientInformation.cc	(revision 1263)
+++ code/branches/merge/src/network/ClientInformation.cc	(revision 1264)
@@ -190,5 +190,5 @@
   * This function should only be applied to the head of the list
   * @param clientID id to look for
-  * @return pointer to the element in the list or 0 if the search was unsuccessfull
+  * @return pointer to the last element in the list or 0 if the search was unsuccessfull
   */
   ClientInformation *ClientInformation::findClient(int clientID, bool look_backwards) {
@@ -196,5 +196,6 @@
     if (temp->head)
       temp=temp->next();
-    while(temp!=0 && temp->getID()!=clientID){
+    //bugfix: temp to temp->next(), get last elem if not found, not segflt
+    while(temp->next()!=0 && temp->getID()!=clientID){
       temp = temp->next();
     }
@@ -211,5 +212,6 @@
   ClientInformation *ClientInformation::findClient(ENetAddress *address, bool look_backwards) {
     ClientInformation *temp = this;
-    while(temp!=0){
+    //bugfix: temp to temp->next(), get last elem if not found, not segflt
+    while(temp->next()!=0){
       if(temp->head){
         temp = temp->next();
Index: code/branches/merge/src/network/ClientInformation.h
===================================================================
--- code/branches/merge/src/network/ClientInformation.h	(revision 1263)
+++ code/branches/merge/src/network/ClientInformation.h	(revision 1264)
@@ -67,13 +67,23 @@
     ClientInformation *insertBefore(ClientInformation *ins);
     ClientInformation *insertBack(ClientInformation *ins);
+    
+    // set functions
     void setID(int clientID);
     void setPeer(ENetPeer *peer);
     void setGamestateID(int id);
+    inline void setShipID(int id){ShipID_=id;}
+    
+    // get functions
+    inline int getShipID(){return ShipID_;}
     int getID();
+    int getGamestateID();
     ENetPeer *getPeer();
-    int getGamestateID();
+    
+    
     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);
 
@@ -82,4 +92,5 @@
 
     bool head;
+    unsigned short failures_;
 
   private:
@@ -90,4 +101,5 @@
     int clientID_;
     int gamestateID_;
+    int ShipID_;   // this is the unique objectID
     bool synched_;
   };
Index: code/branches/merge/src/network/ConnectionManager.cc
===================================================================
--- code/branches/merge/src/network/ConnectionManager.cc	(revision 1263)
+++ code/branches/merge/src/network/ConnectionManager.cc	(revision 1264)
@@ -44,6 +44,10 @@
 
 #include "core/CoreIncludes.h"
+#include "core/BaseObject.h"
+#include "util/Math.h"
+#include "objects/SpaceShip.h"
 #include "ClientInformation.h"
 #include "ConnectionManager.h"
+#include "Synchronisable.h"
 
 namespace std
@@ -60,5 +64,7 @@
 {
   boost::thread_group network_threads;
-
+  
+  ConnectionManager::ConnectionManager(){}
+  
   ConnectionManager::ConnectionManager(ClientInformation *head) {
     quit=false;
@@ -88,5 +94,8 @@
       return NULL;
   }
-
+/**
+This function only pops the first element in PacketBuffer (first in first out)
+used by processQueue in Server.cc
+*/
   ENetPacket *ConnectionManager::getPacket(int &clientID) {
     ENetAddress address;
@@ -156,5 +165,5 @@
     enet_initialize();
     atexit(enet_deinitialize);
-    ENetEvent event;
+    ENetEvent *event = new ENetEvent;
     server = enet_host_create(&bindAddress, NETWORK_MAX_CONNECTIONS, 0, 0);
     if(server==NULL){
@@ -165,25 +174,33 @@
 
     while(!quit){
-      if(enet_host_service(server, &event, NETWORK_WAIT_TIMEOUT)<0){
+      if(enet_host_service(server, event, NETWORK_WAIT_TIMEOUT)<0){
         // we should never reach this point
         quit=true;
         // add some error handling here ========================
       }
-      switch(event.type){
+      switch(event->type){
         // log handling ================
         case ENET_EVENT_TYPE_CONNECT:
-          addClient(&event);
+          addClient(event);
+          //this is a workaround to ensure thread safety
+          /*if(!addFakeConnectRequest(&event))
+            COUT(3) << "Problem pushing fakeconnectRequest to queue" << std::endl;*/
+          COUT(5) << "Con.Man: connection event has occured" << std::endl;
           break;
         case ENET_EVENT_TYPE_RECEIVE:
           //std::cout << "received data" << std::endl;
-          processData(&event);
+          COUT(5) << "Con.Man: receive event has occured" << std::endl;
+          // only add, if client has connected yet and not been disconnected
+          if(head_->findClient(&event->peer->address))
+            processData(event);
           break;
         case ENET_EVENT_TYPE_DISCONNECT:
-          // add some error/log handling here
-          clientDisconnect(event.peer);
+          clientDisconnect(event->peer);
           break;
         case ENET_EVENT_TYPE_NONE:
           break;
       }
+//       usleep(100);
+      //yield(); //TODO: find apropriate
     }
     disconnectClients();
@@ -191,5 +208,8 @@
     enet_host_destroy(server);
   }
-
+  
+  //### added some bugfixes here, but we cannot test them because
+  //### the server crashes everytime because of some gamestates
+  //### (trying to resolve that now)
   void ConnectionManager::disconnectClients() {
     ENetEvent event;
@@ -199,16 +219,19 @@
       temp = temp->next();
     }
-    temp = temp->next();
+    //bugfix: might be the reason why server crashes when clients disconnects
+    //temp = temp->next();
+    temp = head_->next();
     while( temp!=0 && enet_host_service(server, &event, NETWORK_WAIT_TIMEOUT) > 0){
       switch (event.type)
       {
-      case ENET_EVENT_TYPE_NONE:
-      case ENET_EVENT_TYPE_CONNECT:
+      case ENET_EVENT_TYPE_NONE: break;
+      case ENET_EVENT_TYPE_CONNECT: break;
       case ENET_EVENT_TYPE_RECEIVE:
         enet_packet_destroy(event.packet);
         break;
       case ENET_EVENT_TYPE_DISCONNECT:
-        std::cout << "disconnecting client" << std::endl;
+        COUT(4) << "disconnecting all clients" << std::endl;
         delete head_->findClient(&(event.peer->address));
+        //maybe needs bugfix: might also be a reason for the server to crash
         temp = temp->next();
         break;
@@ -224,22 +247,23 @@
   }
 
-  //bool ConnectionManager::clientDisconnect(ENetPeer *peer) {
-  //  return clientDisconnect(*peer);
-  //}
-
   bool ConnectionManager::clientDisconnect(ENetPeer *peer) {
-    return head_->removeClient(peer);
-  }
-
+    COUT(4) << "removing client from list" << std::endl;
+    return removeClient(head_->findClient(&(peer->address))->getID());
+  }
+/**
+This function adds a client that connects to the clientlist of the server
+NOTE: if you change this, don't forget to change the test function
+addClientTest in diffTest.cc since addClient is not good for testing because of syncClassid
+*/
   bool ConnectionManager::addClient(ENetEvent *event) {
     ClientInformation *temp = head_->insertBack(new ClientInformation);
-    if(temp->prev()->head)
+    if(temp->prev()->head) { //not good if you use anything else than insertBack
+      temp->prev()->setID(0); //bugfix: not necessary but usefull
       temp->setID(1);
+    }
     else
       temp->setID(temp->prev()->getID()+1);
     temp->setPeer(event->peer);
-    std::cout << "added client id: " << temp->getID() << std::endl;
-    syncClassid(temp->getID());
-    temp->setSynched(true);
+    COUT(4) << "Con.Man: added client id: " << temp->getID() << std::endl;
     return true;
   }
@@ -268,5 +292,5 @@
       classname = id->getName();
       network_id = id->getNetworkID();
-      COUT(4) << "network_id: " << network_id << ", classname: " << classname << std::endl;
+      COUT(4) << "Con.Man:syncClassid:\tnetwork_id: " << network_id << ", classname: " << classname << std::endl;
 
       addPacket(packet_gen.clid( (int)network_id, classname ), clientID);
@@ -275,36 +299,123 @@
     }
     sendPackets();
-  }
-
-
-
-  void ConnectionManager::addClientsObjectID( int clientID, int objectID ) {
-    COUT(4) << "ship of client: " << clientID << ": " << objectID << " mapped" << std::endl;
-    clientsShip.insert( std::make_pair( clientID, objectID ) );
-  }
+    COUT(4) << "syncClassid:\tall synchClassID packets have been sent" << std::endl;
+  }
+
+  bool ConnectionManager::createClient(int clientID){
+    ClientInformation *temp = head_->findClient(clientID);
+    COUT(4) << "Con.Man: creating client id: " << temp->getID() << std::endl;
+    syncClassid(temp->getID());
+    COUT(4) << "creating spaceship for clientid: " << temp->getID() << std::endl;
+    // TODO: this is only a hack, untill we have a possibility to define default player-join actions
+    createShip(temp);
+    COUT(4) << "created spaceship" << std::endl;
+    temp->setSynched(true);
+    COUT(4) << "sending welcome" << std::endl;
+    sendWelcome(temp->getID(), temp->getShipID(), true);
+    return true;
+  }
+  
+  bool ConnectionManager::removeClient(int clientID){
+    orxonox::Iterator<orxonox::SpaceShip> it = orxonox::ObjectList<orxonox::SpaceShip>::start();
+    while(it){
+      if(it->objectID!=head_->findClient(clientID)->getShipID()){
+        ++it;
+        continue;
+      }
+      orxonox::Iterator<orxonox::SpaceShip> temp=it;
+      ++it;
+      delete  *temp;
+      return head_->removeClient(clientID);
+    }
+    return false;
+  }
+  
+  bool ConnectionManager::createShip(ClientInformation *client){
+    orxonox::Identifier* id = ID("SpaceShip");
+    if(!id){
+      COUT(4) << "We could not create the SpaceShip for client: " << client->getID() << std::endl;
+      return false;
+    }
+    orxonox::SpaceShip *no = dynamic_cast<orxonox::SpaceShip *>(id->fabricate());
+    no->setPosition(orxonox::Vector3(0,80,0));
+    no->setScale(10);
+    no->setYawPitchRoll(orxonox::Degree(-90),orxonox::Degree(-90),orxonox::Degree(0));
+    no->setMesh("assf3.mesh");
+    no->setMaxSpeed(500);
+    no->setMaxSideAndBackSpeed(50);
+    no->setMaxRotation(1.0);
+    no->setTransAcc(200);
+    no->setRotAcc(3.0);
+    no->setTransDamp(75);
+    no->setRotDamp(1.0);
+    no->setCamera("cam_"+client->getID());
+    no->create();
+    
+    client->setShipID(no->objectID);
+    return true;
+  }
+  
+  bool ConnectionManager::removeShip(ClientInformation *client){
+    int id=client->getShipID();
+    orxonox::Iterator<orxonox::SpaceShip> it;
+    for(it = orxonox::ObjectList<orxonox::SpaceShip>::start(); it; ++it){
+      if(it->objectID!=id)
+        continue;
+      delete *it;
+    }
+    return true;
+  }
+  
+  bool ConnectionManager::sendWelcome(int clientID, int shipID, bool allowed){
+    addPacket(packet_gen.generateWelcome(clientID, shipID, allowed),clientID);
+    sendPackets();
+    return true;
+  }
+  
+  void ConnectionManager::disconnectClient(ClientInformation *client){
+    enet_peer_disconnect(client->getPeer(), 0);
+    removeShip(client);
+  }
+  
+  bool ConnectionManager::addFakeConnectRequest(ENetEvent *ev){
+    ENetEvent event;
+    event.peer=ev->peer;
+    event.packet = packet_gen.generateConnectRequest();
+    return buffer.push(&event);
+  }
+  
+  
+//   int ConnectionManager::getNumberOfClients() {
+//     
+//     return clientsShip.size();
+//   }
+  
+  /*void ConnectionManager::addClientsObjectID( int clientID, int objectID ) {
+  COUT(4) << "ship of client: " << clientID << ": " << objectID << " mapped" << std::endl;
+  clientsShip.insert( std::make_pair( clientID, objectID ) );
+}
 
   int ConnectionManager::getClientsShipID( int clientID ) {
-    return clientsShip[clientID];
-  }
+  return clientsShip[clientID];
+}
 
   int ConnectionManager::getObjectsClientID( int objectID ) {
-    std::map<int, int>::iterator iter = clientsShip.begin();
-    while( iter != clientsShip.end() ) {
-      if( iter->second == objectID ) return iter->first;
-    }
-    return -99;
-  }
+  std::map<int, int>::iterator iter;
+  for( iter = clientsShip.begin(); iter != clientsShip.end(); iter++ ) {
+  if( iter->second == objectID ) return iter->first;
+}
+  return -99;
+}
 
   void ConnectionManager::deleteClientIDReg( int clientID ) {
-    clientsShip.erase( clientID );
-  }
+  clientsShip.erase( clientID );
+}
 
   void ConnectionManager::deleteObjectIDReg( int objectID ) {
-    std::map<int, int>::iterator iter = clientsShip.begin();
-    while( iter != clientsShip.end() ) {
-      if( iter->second == objectID ) break;
-    }
-    clientsShip.erase( iter->first );
-  }
-
-}
+  std::map<int, int>::iterator iter = clientsShip.begin();
+  for( iter = clientsShip.begin(); iter != clientsShip.end(); iter++ ) {
+  if( iter->second == objectID ) break;
+}
+  clientsShip.erase( iter->first );
+}*/
+}
Index: code/branches/merge/src/network/ConnectionManager.h
===================================================================
--- code/branches/merge/src/network/ConnectionManager.h	(revision 1263)
+++ code/branches/merge/src/network/ConnectionManager.h	(revision 1264)
@@ -71,4 +71,5 @@
   class ConnectionManager{
   public:
+    ConnectionManager();
     ConnectionManager(ClientInformation *head);
     ConnectionManager(int port, const char *address, ClientInformation *head);
@@ -84,7 +85,10 @@
     bool sendPackets(ENetEvent *event);
     bool sendPackets();
+    bool createClient(int clientID);
+    void disconnectClient(ClientInformation *client);
+
   private:
     bool clientDisconnect(ENetPeer *peer);
-    //bool clientDisconnect(ENetPeer peer);
+    bool removeClient(int clientID);
     bool processData(ENetEvent *event);
     bool addClient(ENetEvent *event);
@@ -95,4 +99,8 @@
     void syncClassid(int clientID);
     ENetPeer *getClientPeer(int clientID);
+    bool createShip(ClientInformation *client);
+    bool removeShip(ClientInformation *client);
+    bool sendWelcome(int clientID, int shipID, bool allowed);
+    bool addFakeConnectRequest(ENetEvent *ev);
     PacketBuffer buffer;
     PacketGenerator packet_gen;
@@ -104,19 +112,14 @@
     ClientInformation *head_;
 
+    
+//     int getNumberOfClients();
     //functions to map what object every clients uses
-    std::map<int, int> clientsShip;
+    /*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 );
+    void deleteObjectIDReg( int objectID );*/
   };
-
-
-
-
-
-
-
 
 }
Index: code/branches/merge/src/network/GameStateClient.cc
===================================================================
--- code/branches/merge/src/network/GameStateClient.cc	(revision 1263)
+++ code/branches/merge/src/network/GameStateClient.cc	(revision 1264)
@@ -32,9 +32,19 @@
 
 #include "core/CoreIncludes.h"
+#include "core/BaseObject.h"
 #include "Synchronisable.h"
+
+#define GAMESTATEID_INITIAL -1
 
 namespace network
 {
+  struct GameStateItem{
+    GameState *state;
+    int id;
+  };
+  
   GameStateClient::GameStateClient() {
+    COUT(5) << "this: " << this << std::endl;
+    last_diff_=0;
   }
 
@@ -43,14 +53,48 @@
 
   bool GameStateClient::pushGameState(GameStateCompressed *compstate) {
-    GameState *gs;
-    if(compstate->diffed)
+    cleanup();
+    printGameStateMap();
+    GameState *gs, *reference;
+    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)
-      return loadSnapshot(gs);
+    if(gs){
+      if (loadSnapshot(gs)){
+        gameStateMap.insert(std::pair<int, GameState*>(gs->id, gs));
+        COUT(4) << "adding decoded gs with id: " << gs->id << " diffed from: " << gs->base_id << std::endl;
+        last_diff_=gs->base_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();
+    GameStateCompressed *cgs = compress_(gs);
+    delete[] gs->data;
+    delete gs;
+    return cgs;
+  }
+  
 
   /**
@@ -78,14 +122,14 @@
     while(data < state->data+state->size){
       // prepare the syncData struct
-      sync.length = (int)*data;
+      sync.length = *(int *)data;
       data+=sizeof(int);
-      sync.objectID = (int)*data;
+      sync.objectID = *(int*)data;
       data+=sizeof(int);
-      sync.classID = (int)*data;
+      sync.classID = *(int*)data;
       data+=sizeof(int);
       sync.data = data;
       data+=sync.length;
 
-      if(it->objectID!=sync.objectID){
+      if(!it || it->objectID!=sync.objectID){
         // bad luck ;)
         // delete the synchronisable (obviously seems to be deleted on the server)
@@ -95,13 +139,22 @@
 
         if(!it){
-          COUT(5) << "classid: " << sync.classID << ", name: " << ID((unsigned int) sync.classID)->getName() << std::endl;
-          Synchronisable *no = (Synchronisable*)(ID((unsigned int) sync.classID)->fabricate());
+          //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(4) << "We could not identify a new object; classid: " << sync.classID << std::endl;
+            continue;
+          }
+          Synchronisable *no = dynamic_cast<Synchronisable *>(id->fabricate());
+          COUT(4) << "loadsnapshot: classid: " << sync.classID << " objectID: " << sync.objectID << " length: " << sync.length << std::endl;
           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;
+          if( !no->create() )
+            COUT(1) << "We couldn't manifest (create() ) the object: " << sync.objectID << std::endl;
           it=orxonox::ObjectList<Synchronisable>::end();
-          // update data and create object/entity...
-          if( !no->updateData(sync) && !no->create() )
-            COUT(1) << "We couldn't create/update the object: " << sync.objectID << std::endl;
-          ++it;
         }
       } else {
@@ -117,20 +170,87 @@
   }
 
-  GameState *GameStateClient::undiff(GameState *a, GameState *b) {
-    unsigned char *ap = a->data, *bp = b->data;
+  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(4) << "getpartialsnapshot: size: " << size << std::endl;
+    }
+    //retval->data = (unsigned char*)malloc(size);
+    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(a->size>=b->size)
-      dest_length=a->size;
+    if(old->size>=diff->size)
+      dest_length=old->size;
     else
-      dest_length=b->size;
-    unsigned char *dp = (unsigned char *)malloc(dest_length*sizeof(unsigned char));
-    while(of<a->size && of<b->size){
+      dest_length=diff->size;
+//     unsigned char *dp = (unsigned char *)malloc(dest_length*sizeof(unsigned char));
+    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(a->size!=b->size){ // do we have to fill up ?
+    if(old->size!=diff->size){ // do we have to fill up ?
       unsigned char n=0;
-      if(a->size<b->size){
+      if(old->size<diff->size){
         while(of<dest_length){
           *(dp+of)=n^*(bp+of);
@@ -147,12 +267,49 @@
     // FIXME: is it true or false now? (struct has changed, producing warnings)
     GameState *r = new GameState;
-    r->id = b->id;
+    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;
+    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;
@@ -162,5 +319,6 @@
     else
       bufsize = normsize;
-    unsigned char* dest = (unsigned char*)malloc( bufsize );
+//     unsigned char* dest = (unsigned char*)malloc( bufsize );
+    unsigned char *dest = new unsigned char[bufsize];
     int retval;
     uLongf length=normsize;
@@ -173,5 +331,5 @@
       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" << std::endl; return NULL;
+      case Z_DATA_ERROR: COUT(2) << "data corrupted (zlib)" << std::endl; return NULL;
     }
 
@@ -180,21 +338,63 @@
     gamestate->size = normsize;
     gamestate->data = dest;
+    gamestate->base_id = a->base_id;
     gamestate->diffed = a->diffed;
-
-    delete a->data; //delete compressed data
-    delete a; //we do not need the old (struct) gamestate anymore
+    gamestate->complete = a->complete;
+
 
     return gamestate;
   }
 
-  GameState *GameStateClient::decode(GameState *a, GameStateCompressed *x) {
-    GameState *t = decompress(x);
-    return undiff(a, t);
+  GameState *GameStateClient::decode(GameState *old, GameStateCompressed *diff) {
+    COUT(4) << "using diffed gamestate" << std::endl;
+    GameState *t = decode(diff);
+    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);
+    }
+  }
+
+  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;
+    
+  }
+  
+  
+    //##### 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/branches/merge/src/network/GameStateClient.h
===================================================================
--- code/branches/merge/src/network/GameStateClient.h	(revision 1263)
+++ code/branches/merge/src/network/GameStateClient.h	(revision 1264)
@@ -41,7 +41,10 @@
 #define _GameStateClient_H__
 
+#include <map>
+// 
 #include "NetworkPrereqs.h"
 #include "core/CorePrereqs.h"
-#include "GameStateManager.h"
+#include "PacketTypes.h"
+
 
 namespace network
@@ -52,14 +55,30 @@
     GameStateClient();
     ~GameStateClient();
+    
     bool pushGameState(GameStateCompressed *compstate);
+    GameStateCompressed *popPartialGameState();
   private:
     bool loadSnapshot(GameState *state);
-    GameState *undiff(GameState *a, GameState *b);
+    GameState *getPartialSnapshot();
+    void cleanup();
+    GameState *undiff(GameState *old, GameState *diff);
+    GameStateCompressed *compress_(GameState *a);
     GameState *decompress(GameStateCompressed *a);
-    GameState *decode(GameState *a, GameStateCompressed *x);
+    GameState *decode(GameState *old, GameStateCompressed *diff);
     GameState *decode(GameStateCompressed *x);
     void removeObject(orxonox::Iterator<Synchronisable> &it);
+    void printGameStateMap();
 
-    GameState *reference;
+    int           last_diff_;
+    std::map<int, GameState *> gameStateMap;
+    
+    
+    
+    
+  public:
+    //#### ADDED FOR TESTING PURPOSE ####
+    GameState* testDecompress( GameStateCompressed* gc );
+    GameState* testUndiff( GameState* g_old, GameState* g_diffed );
+    //#### END TESTING PURPOSE ####
   };
 
Index: code/branches/merge/src/network/GameStateManager.cc
===================================================================
--- code/branches/merge/src/network/GameStateManager.cc	(revision 1263)
+++ code/branches/merge/src/network/GameStateManager.cc	(revision 1264)
@@ -46,4 +46,5 @@
 
 #include "core/CoreIncludes.h"
+#include "core/BaseObject.h"
 #include "ClientInformation.h"
 #include "Synchronisable.h"
@@ -52,5 +53,5 @@
 {
   GameStateManager::GameStateManager(ClientInformation *head) {
-    id=0;
+    id_=0;
     head_=head;
   }
@@ -60,25 +61,78 @@
 
   void GameStateManager::update(){
-    reference = getSnapshot(id);
-    gameStateMap.insert(std::pair<int, GameState*>(id, reference));
-    gameStateUsed[id]=0;
-    ++id;
+    cleanup();
+    reference = getSnapshot();
+    COUT(4) << "inserting gamestate: " << reference << std::endl;
+    gameStateMap.insert(std::pair<int, GameState*>(id_, reference));
+    gameStateUsed[id_]=0;
+    printGameStates();
     return;
   }
+  
+  
+  /**
+   * 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(4) << "GameStateManager: deleting gamestate with id: " << (*it).first << ", uses: " << (*it).second << std::endl;
+        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) << "popgamestate: sending gstate id: " << id << "diffed from: " << gID << std::endl;
-    if(gID!=GAMESTATEID_INITIAL){
-      GameState *client = gameStateMap[gID];
+    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;
       //head_->findClient(clientID)->setGamestateID(id);
-      return encode(client, server);
+      COUT(3) << "client: " << client << " server: " << server << " gamestatemap: " << &gameStateMap << 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);
       //head_->findClient(clientID)->setGamestateID(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;
   }
 
@@ -88,9 +142,10 @@
   * @return struct of type gamestate containing the size of the whole gamestate and a pointer linking to the flat list
   */
-  GameState *GameStateManager::getSnapshot(int id)
+  GameState *GameStateManager::getSnapshot()
   {
+    //std::cout << "begin getSnapshot" << std::endl;
     //the size of the gamestate
     int totalsize=0;
-    int memsize=1000;
+    int memsize=0;
     //the size of one specific synchronisable
     int tempsize=0;
@@ -101,58 +156,148 @@
 
     GameState *retval=new GameState; //return value
-    retval->id=id++;
-    COUT(4) << "producing gamestate with id: " << retval->id << std::endl;
-    // reserve a little memory and increase it later on
-    COUT(5) << "mallocing" << std::endl;
-    retval->data = (unsigned char*)malloc(memsize);
-    COUT(5) << "malloced" << std::endl;
-
+    retval->id=++id_;
+    COUT(4) << "G.ST.Man: producing gamestate with id: " << retval->id << std::endl;
     // offset of memory functions
-    int offset=0;
+    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);
+    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){
-      //std::cout << "gamestatemanager: in for loop" << std::endl;
       //get size of the synchronisable
       tempsize=it->getSize();
-//       COUT(5) << "size of temp gamestate: " << tempsize << std::endl;
-      //COUT(2) << "size of synchronisable: " << tempsize << std::endl;
       // add place for data and 3 ints (length,classid,objectid)
       totalsize+=tempsize+3*sizeof(int);
-      //std::cout << "totalsize: " << totalsize << std::endl;
-      // allocate additional space
-      if(totalsize+tempsize>memsize){
-        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;
-        }
+      // 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));
-      *(retval->data+offset)=(unsigned char)sync.length;
-      *(retval->data+offset+sizeof(int))=(unsigned char)sync.objectID;
-      *(retval->data+offset+2*sizeof(int))=(unsigned char)sync.classID;
+      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);
     }
-    COUT(5) << "Gamestate size: " << totalsize << std::endl;
     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;
+    // 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;
+      COUT(4) << "objectID: " << sync.objectID << " classID: " << sync.classID << std::endl;
+      while(it && it->objectID!=sync.objectID)
+        ++it;
+
+
+      if(!it){
+        // the object 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;
+    }
+    
+    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) {
-    //GameState r = diff(a,b);
-    //r.diffed = true;
-    GameState *r = b;
-    r->diffed = false;
-    return compress_(r);
+    COUT(4) << "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) {
-    a->diffed=false;
+    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;*/
   }
 
@@ -165,5 +310,6 @@
     else
       dest_length=b->size;
-    unsigned char *dp = (unsigned char *)malloc(dest_length*sizeof(unsigned char));
+    //unsigned char *dp = (unsigned char *)malloc(dest_length*sizeof(unsigned char));
+    unsigned char *dp = new unsigned char[dest_length*sizeof(unsigned char)];
     while(of<a->size && of<b->size){
       *(dp+of)=*(ap+of)^*(bp+of); // do the xor
@@ -189,25 +335,34 @@
     r->size = dest_length;
     r->diffed = true;
+    r->base_id = a->id;
     r->data = dp;
+    r->complete = true;
     return r;
   }
 
   GameStateCompressed *GameStateManager::compress_(GameState *a) {
-    COUT(5) << "compressing gamestate" << std::endl;
+    //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;
-    unsigned char* dest = (unsigned char*)malloc( buffer );
+    //COUT(4) << "size: " << size << ", buffer: " << buffer << std::endl;
+    //unsigned char* dest = (unsigned char*)malloc( buffer );
+    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) << "successfully compressed" << std::endl; break;
-      case Z_MEM_ERROR: COUT(1) << "not enough memory available in gamestate.compress" << std::endl;
+      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) << "not enough memory available in the buffer in gamestate.compress" << std::endl;
+      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) << "decompress: data corrupted in gamestate.compress" << std::endl;
+      case Z_DATA_ERROR: COUT(2) << "G.St.Man: compress: data corrupted in gamestate.compress" << std::endl;
       return NULL;
     }
@@ -221,15 +376,56 @@
     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 );
+    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);
-    int curid = temp->getID();
+    int curid = temp->getGamestateID();
+    COUT(4) << "acking gamestate " << gamestateID << " for clientid: " << clientID << " curid: " << curid << std::endl;
     // decrease usage of gamestate and save it
-    deleteUnusedGameState(curid);
+//     deleteUnusedGameState(curid);
     //increase gamestateused
-    ++gameStateUsed.find(gamestateID)->second;
+    --(gameStateUsed.find(curid)->second);
+    ++(gameStateUsed.find(gamestateID)->second);
     temp->setGamestateID(gamestateID);
     /*
@@ -239,13 +435,22 @@
   }
 
-  bool GameStateManager::deleteUnusedGameState(int gamestateID) {
-    int used = --(gameStateUsed.find(gamestateID)->second);
-    if(id-gamestateID>KEEP_GAMESTATES && used==0){
-      // delete gamestate
-      delete gameStateMap.find(gamestateID)->second;
-      gameStateMap.erase(gamestateID);
-      return true;
-    }
-    return false;
+  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;
+  }
+  
+  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){
+    gameStateUsed[client->getGamestateID()]--;
+    head_->removeClient(client->getID());
   }
 
Index: code/branches/merge/src/network/GameStateManager.h
===================================================================
--- code/branches/merge/src/network/GameStateManager.h	(revision 1263)
+++ code/branches/merge/src/network/GameStateManager.h	(revision 1264)
@@ -50,5 +50,5 @@
 {
 
-#define KEEP_GAMESTATES 20
+#define KEEP_GAMESTATES 10
 
   /**
@@ -71,15 +71,21 @@
     GameStateManager(ClientInformation *head);
     ~GameStateManager();
+    
     void update();
     GameStateCompressed *popGameState(int clientID);
+    bool pushGameState(GameStateCompressed *gs, int clientID);
     void ackGameState(int clientID, int gamestateID);
-    int id;
+    void removeClient(ClientInformation *client);
   private:
-    GameState *getSnapshot(int id);
+    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 *a, GameState *b);
     GameStateCompressed *compress_(GameState *a);
-    bool deleteUnusedGameState(int gamestateID);
+    GameState *decompress(GameStateCompressed *a);
+    bool printGameStates();
+    bool checkAccess(int clientID, int objectID);
 
     std::map<int, GameState*> gameStateMap; //map gsID to gamestate*
@@ -87,4 +93,14 @@
     GameState *reference;
     ClientInformation *head_;
+    int id_;
+    
+    
+    
+    
+  public:
+    //#### ADDED FOR TESTING PURPOSE ####
+    GameStateCompressed* testCompress( GameState* g );
+    GameState* testDiff( GameState* a, GameState* b );
+  //#### END TESTING PURPOSE ####
   };
 
Index: code/branches/merge/src/network/NetworkPrereqs.h
===================================================================
--- code/branches/merge/src/network/NetworkPrereqs.h	(revision 1263)
+++ code/branches/merge/src/network/NetworkPrereqs.h	(revision 1264)
@@ -78,4 +78,6 @@
   struct chat;
   struct classid;
+  struct welcome;
+  struct connectRequest;
   struct ClientList;
   struct GameState;
Index: code/branches/merge/src/network/PacketBuffer.cc
===================================================================
--- code/branches/merge/src/network/PacketBuffer.cc	(revision 1263)
+++ code/branches/merge/src/network/PacketBuffer.cc	(revision 1264)
@@ -61,7 +61,7 @@
       last=first;
       last->next=NULL;
-      // change this!!!!!!!
+      // change this!!!!!!! 
       last->packet = ev->packet;
-      last->address = ev->peer->address;
+      //last->address = ev->peer->address;
     } else {
       //insert a new element at the bottom
@@ -72,9 +72,13 @@
       // save the packet to the new element
       last->packet = ev->packet;
-      last->address = ev->peer->address;
+      //last->address = ev->peer->address;
     }
-    return true;
+    // pseudo bugfix: added a return false statement for error handling
+    if ( last->packet == ev->packet ) return true;
+    return false;
   }
 
+  //returns the first element in the list without deleting it but
+  //moving first pointer to next element
   ENetPacket *PacketBuffer::pop() {
     boost::mutex::scoped_lock lock(networkPacketBufferMutex);
Index: code/branches/merge/src/network/PacketDecoder.cc
===================================================================
--- code/branches/merge/src/network/PacketDecoder.cc	(revision 1263)
+++ code/branches/merge/src/network/PacketDecoder.cc	(revision 1264)
@@ -53,37 +53,43 @@
   bool PacketDecoder::elaborate( ENetPacket* packet, int clientId )
   {
-    int client = clientId;
-    COUT(5) << "clientId: " << client << std::endl; //control cout, not important, just debugging info
+    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) << "packet id: " << id << std::endl;
-//     COUT(5) << "packet size inside packetdecoder: " << packet->dataLength << std::endl;
+    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;
-    break;
-  case MOUSE:
-    mousem( packet, clientId );
-    return true;
-    break;
-  case KEYBOARD:
-    keystrike( packet, clientId );
-    return true;
-    break;
-  case CHAT:
-    chatMessage( packet, clientId );
-    return true;
-    break;
-  case GAMESTATE:
-    gstate( packet );
-    return true;
-    break;
-  case CLASSID:
-    clid(packet);
-    return true;
-    break;
+    case ACK:
+      acknowledgement( packet, clientId );
+      return true;
+    case COMMAND:
+      return command( packet, clientId );
+    case MOUSE:
+      mousem( packet, clientId );
+      return true;
+    case KEYBOARD:
+      keystrike( packet, clientId );
+      return true;
+    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;
   }
+  
+  // 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
@@ -92,12 +98,18 @@
   {
     ack* a = new ack;
-    *a = *(ack*)packet->data; //press pattern of ack on new data
-
-
-    COUT(5) << "got ack id: " << a->id << std::endl;
+    *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 );
+    //clean memory
+    enet_packet_destroy( packet );
+  }
+  
+  bool PacketDecoder::command( ENetPacket* packet, int clientId ){
+    int length = *(int*)((unsigned char *)packet->data+sizeof(int));
+    void *data = (void *)new unsigned char[length];
+    memcpy(data, (void *)(packet->data+2*sizeof(int)), length);
+    return true;
   }
 
@@ -110,5 +122,4 @@
     //clean memory
     enet_packet_destroy( packet );
-
     printMouse( mouseMove ); //debug info
   }
@@ -121,5 +132,4 @@
     //clean memory
     enet_packet_destroy( packet );
-
     printKey( key ); //debug info
 
@@ -144,10 +154,10 @@
   }
 
-  void PacketDecoder::gstate( ENetPacket* packet )
+  void PacketDecoder::gstate( ENetPacket* packet, int clientID )
   {
     GameStateCompressed* currentState = NULL;
     currentState = new GameStateCompressed;
     if(currentState == NULL){
-      COUT(3) << "could not generate new GameStateCompressed" << std::endl;
+      COUT(3) << "PacketDecoder: could not generate new GameStateCompressed" << std::endl;
       return;
     }
@@ -156,36 +166,28 @@
     unsigned char* data = (unsigned char *)(packet->data);
     //copy the GameStateCompressed id into the struct, which is located at second place data+sizeof( int )
-    //memcpy( (void*)&(currentState->id), (const void*)(data+sizeof( int )), sizeof( int ) );
-    //currentState->id = *((int *)packet->data+sizeof(int));
     memcpy( (void*)&(currentState->id), (const void*)(packet->data+1*sizeof( int )), sizeof( int) );
-    COUT(5) << "decoder: received gs id: " << currentState->id << std::endl;
-//     std::cout << "id: " << currentState->id << std::endl;
+    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) );
-    //currentState->compsize = (int)*(data+2*sizeof(int));
-//     std::cout << "compsize: " << currentState->compsize << std::endl;
     //size of uncompressed data
     memcpy( (void*)&(currentState->normsize), (const void*)(packet->data+3*sizeof( int )), sizeof( int ) );
-    //currentState->normsize = (int)*(data+3*sizeof(int));
-//     std::cout << "normsize. " << currentState->normsize << std::endl;
+    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+4*sizeof(int)), sizeof(bool));
-    //currentState->diffed = (bool)*(data+4*sizeof(int));
-//     std::cout << "diffed: " << currentState->diffed << std::endl;
+    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) << "compsize is 0" << std::endl;
-    currentState->data = (unsigned char*)(malloc( currentState->compsize ));
+      COUT(2) << "PacketDecoder: compsize is 0" << std::endl;
+//     currentState->data = (unsigned char*)(malloc( currentState->compsize ));
+    currentState->data = new unsigned char[currentState->compsize];
     if(currentState->data==NULL)
-      COUT(2) << "Gamestatepacket-decoder: memory leak" << std::endl;
+      COUT(2) << "PacketDecoder: Gamestatepacket-decoder: memory leak" << std::endl;
     //copy the GameStateCompressed data
-    //std::cout << "packet size (enet): " << packet->dataLength << std::endl;
-    //std::cout << "totallen: " << 4*sizeof(int)+sizeof(bool)+currentState->compsize << std::endl;
-    memcpy( (void*)(currentState->data), (const void*)(packet->data+4*sizeof( int ) + sizeof(bool)), currentState->compsize );
-
-    //clean memory
-    enet_packet_destroy( packet );
-    processGamestate(currentState);
+    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);
   }
 
@@ -196,11 +198,30 @@
     cid->id = ((classid *)(packet->data))->id;
     cid->clid = ((classid *)(packet->data))->clid;
-    cid->message = (const char *)malloc(cid->length);
+//     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) << "classid: " << cid->clid << ", name: " << cid->message << std::endl;
+    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 );
+  }
 
 
@@ -210,8 +231,14 @@
   {
     printChat(data, clientId);
-  }
-
-  void PacketDecoder::processGamestate( GameStateCompressed *state )
-  {
+    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;
   }
 
@@ -219,4 +246,5 @@
   {
     printClassid(cid);
+    delete cid;
     return;
   }
@@ -225,7 +253,18 @@
   {
     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
Index: code/branches/merge/src/network/PacketGenerator.cc
===================================================================
--- code/branches/merge/src/network/PacketGenerator.cc	(revision 1263)
+++ code/branches/merge/src/network/PacketGenerator.cc	(revision 1264)
@@ -52,5 +52,5 @@
   ENetPacket* PacketGenerator::acknowledgement( int state, int reliable )
   {
-    COUT(4) << "generating new acknowledgement, id: " << state << std::endl;
+    COUT(4) << "PacketGenerator: generating new acknowledgement, id: " << state << std::endl;
     ack* ackreq = new ack;
     ackreq->id = ACK;
@@ -58,5 +58,19 @@
 
     ENetPacket *packet = enet_packet_create( ackreq , sizeof( *ackreq ), reliable );
-
+    delete ackreq;
+    return packet;
+  }
+  
+  ENetPacket* command( int dataLength, void *data, int reliable = ENET_PACKET_FLAG_RELIABLE )
+  {
+    void *stream = new 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;
   }
@@ -65,5 +79,5 @@
   ENetPacket* PacketGenerator::mousem( double x, double y, int reliable )
   {
-    COUT(4) << "generating new mouse" << std::endl;
+    COUT(4) << "PacketGenerator: generating new mouse" << std::endl;
     mouse* mousemove = new mouse;
     mousemove->id = MOUSE;
@@ -72,5 +86,5 @@
 
     ENetPacket *packet = enet_packet_create( mousemove , sizeof( *mousemove ), reliable );
-
+    delete mousemove;
     return packet;
   }
@@ -79,5 +93,5 @@
   ENetPacket* PacketGenerator::keystrike( char press, int reliable )
   {
-    COUT(4) << "generating new keyboard" << std::endl;
+    COUT(4) << "PacketGenerator: generating new keyboard" << std::endl;
     keyboard* key = new keyboard;
     key->id = KEYBOARD;
@@ -85,5 +99,5 @@
 
     ENetPacket *packet = enet_packet_create( key , sizeof( *key ), reliable );
-
+    delete key;
     return packet;
   }
@@ -97,5 +111,5 @@
     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;
   }
@@ -108,25 +122,21 @@
     //std::cout << "states->compsize " << states->compsize << std::endl;
     int gid = GAMESTATE; //first assign the correct enet id
-    int totalLen = 4*sizeof( int ) + sizeof(bool) + states->compsize; //calculate the total size of the datastream memory
+    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
+    //unsigned char *data = (unsigned char*)malloc( totalLen ); //allocate the memory for datastream
+    unsigned char *data = new unsigned char[totalLen];
     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->diffed), sizeof(bool));
-    /*(int)*(data) = gid;
-    (int)*(data+sizeof(int)) = states->id;
-    //this is the compressed size of the GameStateCompressed data, place at 3th position of the enet datastream
-    (int)*(data+2*sizeof(int)) = states->compsize;
-    //this is the uncompressed size of GameStateCompressed data
-    (int)*(data+3*sizeof(int)) = states->normsize;
-    //since there is a new parameter inside GameStateCompressed, change this function to create packet
-    (bool)*(data+4*sizeof(int)) = states->diffed;*/
+    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+4*sizeof( int ) + sizeof(bool)), (const void*)states->data, states->compsize );
+    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;
     ENetPacket *packet = enet_packet_create( data , totalLen, reliable );
-    //delete data;
+    delete[] data;
     return packet;
   }
@@ -134,6 +144,7 @@
   ENetPacket* PacketGenerator::clid( int classid, std::string classname, int reliable )
   {
-    unsigned char* data = (unsigned char *)malloc(3*sizeof(int)+classname.length()+1);
-    std::cout << "classid: " << classid << ", name: " << classname << std::endl;
+    //unsigned char* data = (unsigned char *)malloc(3*sizeof(int)+classname.length()+1);
+    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;
@@ -141,4 +152,24 @@
     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;
   }
Index: code/branches/merge/src/network/PacketManager.h
===================================================================
--- code/branches/merge/src/network/PacketManager.h	(revision 1263)
+++ code/branches/merge/src/network/PacketManager.h	(revision 1264)
@@ -54,4 +54,5 @@
     //call one of this functions out of an instance of PacketGenerator to create a packet
     ENetPacket* acknowledgement( int state, int reliable = ENET_PACKET_FLAG_RELIABLE );
+    ENetPacket* command( int dataLength, void *data, int reliable = ENET_PACKET_FLAG_RELIABLE );
     ENetPacket* mousem( double x, double y, int reliable = ENET_PACKET_FLAG_RELIABLE );
     ENetPacket* keystrike( char press, int reliable = ENET_PACKET_FLAG_RELIABLE );
@@ -59,4 +60,6 @@
     ENetPacket* gstate( GameStateCompressed *states, int reliable = ENET_PACKET_FLAG_RELIABLE );
     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:
   };
@@ -85,15 +88,20 @@
 
     void acknowledgement( ENetPacket* packet, int clientId = CLIENTID_CLIENT );
+    bool command( ENetPacket* packet, int clientId );
     void mousem( ENetPacket* packet, int clientId = CLIENTID_CLIENT );
     void keystrike( ENetPacket* packet, int clientId = CLIENTID_CLIENT );
-    void chatMessage( ENetPacket* packet, int clientId = CLIENTID_CLIENT);
-    void gstate( ENetPacket* packet );
+    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);
+    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);
 
Index: code/branches/merge/src/network/PacketTypes.h
===================================================================
--- code/branches/merge/src/network/PacketTypes.h	(revision 1263)
+++ code/branches/merge/src/network/PacketTypes.h	(revision 1264)
@@ -49,8 +49,11 @@
     ACK,
     MOUSE,
+    COMMAND,
     KEYBOARD,
     CHAT,
     GAMESTATE ,
-    CLASSID
+    CLASSID,
+    WELCOME,
+    CONNECT,
   };
 
@@ -65,5 +68,7 @@
     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
   };
@@ -80,5 +85,7 @@
     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
   };
@@ -114,4 +121,14 @@
   };
 
+  struct welcome {
+    int id;
+    int clientID;
+    int shipID;
+    bool allowed;
+  };
+  
+  struct connectRequest{
+    int id;
+  };
 }
 
Index: code/branches/merge/src/network/Server.cc
===================================================================
--- code/branches/merge/src/network/Server.cc	(revision 1263)
+++ code/branches/merge/src/network/Server.cc	(revision 1264)
@@ -53,4 +53,9 @@
 namespace network
 {
+  
+  
+#define MAX_FAILURES 20;
+  
+  
   /**
   * Constructor for default values (bindaddress is set to ENET_HOST_ANY
@@ -124,9 +129,9 @@
   bool Server::sendMSG(const char *msg) {
     ENetPacket *packet = packet_gen.chatMessage(msg);
-    std::cout <<"adding Packets" << std::endl;
+    COUT(4) <<"Server: adding Packets" << std::endl;
     connection->addPacketAll(packet);
     //std::cout <<"added packets" << std::endl;
     if (connection->sendPackets()){
-      std::cout << "Sucessfully" << std::endl;
+      COUT(4) << "Server: Sucessfully" << std::endl;
       return true;
     }
@@ -143,5 +148,5 @@
     updateGamestate();
 
-    sleep(1); // TODO remove
+//     usleep(500000); // TODO remove
     return;
   }
@@ -155,6 +160,9 @@
     while(!connection->queueEmpty()){
       //std::cout << "Client " << clientID << " sent: " << std::endl;
+      //clientID here is a reference to grab clientID from ClientInformation
       packet = connection->getPacket(clientID);
-      elaborate(packet, clientID);
+      //if statement to catch case that packetbuffer is empty
+      if( !elaborate(packet, clientID) ) 
+        COUT(4) << "Server: PacketBuffer empty" << std::endl;
     }
   }
@@ -165,7 +173,9 @@
   void Server::updateGamestate() {
     gamestates->update();
+    COUT(4) << "Server: one gamestate update complete, goig to sendGameState" << std::endl;
     //std::cout << "updated gamestate, sending it" << std::endl;
     //if(clients->getGamestateID()!=GAMESTATEID_INITIAL)
-      sendGameState();
+    sendGameState();
+    COUT(4) << "Server: one sendGameState turn complete, repeat in next tick" << std::endl;
     //std::cout << "sent gamestate" << std::endl;
   }
@@ -175,42 +185,80 @@
   */
   bool Server::sendGameState() {
-    COUT(5) << "starting sendGameState" << std::endl;
+    COUT(5) << "Server: starting function sendGameState" << std::endl;
     ClientInformation *temp = clients;
     bool added=false;
-    while(temp!=NULL){
+    while(temp != NULL){
       if(temp->head){
         temp=temp->next();
+        //think this works without continue
         continue;
       }
       if( !(temp->getSynched()) ){
-        COUT(5) << "not sending gamestate" << std::endl;
+        COUT(5) << "Server: not sending gamestate" << std::endl;
         temp=temp->next();
+        //think this works without continue
         continue;
       }
-      COUT(5) << "doing gamestate gamestate preparation" << std::endl;
-      int gid = temp->getGamestateID();
-      int cid = temp->getID();
-      COUT(5) << "server, got acked (gamestate) ID: " << gid << std::endl;
+      COUT(5) << "Server: doing gamestate gamestate preparation" << std::endl;
+      int gid = temp->getGamestateID(); //get gamestate id
+      int cid = temp->getID(); //get client id
+      COUT(5) << "Server: got acked (gamestate) ID from clientlist: " << gid << std::endl;
       GameStateCompressed *gs = gamestates->popGameState(cid);
       if(gs==NULL){
-        COUT(2) << "could not generate gamestate" << std::endl;
+        COUT(2) << "Server: could not generate gamestate (NULL from compress)" << std::endl;
         return false;
       }
       //std::cout << "adding gamestate" << std::endl;
-      connection->addPacket(packet_gen.gstate(gs), cid);
+      if ( !(connection->addPacket(packet_gen.gstate(gs), cid)) ){
+        COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp->failures_ << std::endl; 
+        temp->failures_++;
+        if(temp->failures_ > 20 )
+          disconnectClient(temp);
       //std::cout << "added gamestate" << std::endl;
+      }
       added=true;
       temp=temp->next();
-    }
-    if(added)
+      // now delete gamestate
+      delete[] gs->data;
+      delete gs;
+    }
+    if(added) {
+      //std::cout << "send gamestates from server.cc in sendGameState" << std::endl;
       return connection->sendPackets();
-    COUT(5) << "had no gamestates to send" << std::endl;
+    }
+    COUT(5) << "Server: had no gamestates to send" << std::endl;
     return false;
   }
 
   void Server::processAck( ack *data, int clientID) {
-    COUT(5) << "processing ack from client: " << clientID << "; ack-id: " << data->id << std::endl;
-    clients->findClient(clientID)->setGamestateID(data->a);
-  }
-
+    COUT(4) << "\b\b\b\n\n\n\n\nServer: 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(4) << "processing connectRequest " << std::endl;
+    //connection->addPacket(packet_gen.gstate(gamestates->popGameState(clientID)) , clientID);
+    connection->createClient(clientID);
+    delete con;
+    return true;
+  }
+  
+  void Server::processGamestate( GameStateCompressed *data, int clientID){
+    COUT(4) << "processing partial gamestate from client " << clientID << std::endl;
+    if(!gamestates->pushGameState(data, clientID))
+        COUT(3) << "Could not push gamestate\t\t\t\t=====" << std::endl;
+    else
+        clients->findClient(clientID)->failures_=0;
+  }
+
+  void Server::disconnectClient(int clientID){
+    ClientInformation *client = clients->findClient(clientID);
+    disconnectClient(client);
+  }
+  void Server::disconnectClient( ClientInformation *client){
+    connection->disconnectClient(client);
+    gamestates->removeClient(client);
+  }
+  
 }
Index: code/branches/merge/src/network/Server.h
===================================================================
--- code/branches/merge/src/network/Server.h	(revision 1263)
+++ code/branches/merge/src/network/Server.h	(revision 1264)
@@ -71,6 +71,10 @@
     void updateGamestate();
   private:
+    void disconnectClient(int clientID);
+    void disconnectClient( ClientInformation *client);
     bool sendGameState();
     void processAck( ack *data, int clientID);
+    bool processConnectRequest( connectRequest *con, int clientID );
+    void processGamestate( GameStateCompressed *data, int clientID);
     ConnectionManager *connection;
     GameStateManager *gamestates;
Index: code/branches/merge/src/network/Synchronisable.cc
===================================================================
--- code/branches/merge/src/network/Synchronisable.cc	(revision 1263)
+++ code/branches/merge/src/network/Synchronisable.cc	(revision 1264)
@@ -48,4 +48,8 @@
 namespace network
 {
+  
+  
+  int Synchronisable::state_=0x1; // detemines wheter we are server (default) or client
+  
   /**
   * Constructor:
@@ -57,8 +61,16 @@
     datasize=0;
     objectID=idCounter++;
+    syncList = new std::list<synchronisableVariable *>;
     //registerAllVariables();
   }
 
   Synchronisable::~Synchronisable(){
+  }
+  
+  void Synchronisable::setClient(bool b){
+    if(b) // client
+      state_=0x2;
+    else  // server
+      state_=0x1;
   }
 
@@ -69,11 +81,17 @@
   * @param size size of the datatype the variable consists of
   */
-  void Synchronisable::registerVar(const void *var, int size, variableType t){
+  void Synchronisable::registerVar(void *var, int size, variableType t, int mode){
     // create temporary synch.Var struct
-    synchronisableVariable temp={size, var, t};
+    synchronisableVariable *temp = new synchronisableVariable;
+    temp->size = size;
+    temp->var = var;
+    temp->mode = mode; 
+    temp->type = t;
+    COUT(5) << "Syncronisable::registering var with size: " << temp->size << " and type: " << temp->type << std::endl; 
     // increase datasize
     datasize+=sizeof(int)+size;
-    // push temp to syncList (at the bottom)
-    syncList.push_back(temp);
+    //std::cout << "push temp to syncList (at the bottom) " << datasize << std::endl;
+    COUT(5) << "Syncronisable::objectID: " << objectID << " this: " << this << " name: " << this->getIdentifier()->getName() << " networkID: " << this->getIdentifier()->getNetworkID() << std::endl;
+    syncList->push_back(temp);
   }
 
@@ -91,5 +109,5 @@
   //   int totalsize=0;
   //   //figure out size of data to be allocated
-  //   for(i=syncList.begin(); i!=syncList.end(); i++){
+  //   for(i=syncList->begin(); i!=syncList->end(); i++){
   //     // increase size (size of variable and size of size of variable ;)
   //     if(i->type == STRING)
@@ -107,5 +125,5 @@
   //   //CHANGED: REMOVED DECLARATION int n=0 FROM LOOP
   //   int n=0;
-  //   for(i=syncList.begin(); n<totalsize && i!=syncList.end(); i++){
+  //   for(i=syncList->begin(); n<totalsize && i!=syncList->end(); i++){
   //     std::memcpy(retVal.data+n, (const void*)(i->size), sizeof(int));
   //     n+=sizeof(int);
@@ -134,25 +152,33 @@
   */
   syncData Synchronisable::getData(unsigned char *mem){
-    std::list<synchronisableVariable>::iterator i;
+    //std::cout << "inside getData" << std::endl;
+    classID=this->getIdentifier()->getNetworkID();
+    std::list<synchronisableVariable *>::iterator i;
     syncData retVal;
     retVal.objectID=this->objectID;
     retVal.classID=this->classID;
     retVal.length=getSize();
+    COUT(5) << "Synchronisable getting data from objectID: " << retVal.objectID << " classID: " << retVal.classID << " length: " << retVal.length << std::endl;
     retVal.data=mem;
     // copy to location
-    int n=0;
-    for(i=syncList.begin(); n<datasize && i!=syncList.end(); ++i){
-      //COUT(2) << "size of variable: " << i->size << std::endl;
+    int n=0; //offset
+    for(i=syncList->begin(); n<datasize && i!=syncList->end(); ++i){
       //(std::memcpy(retVal.data+n, (const void*)(&(i->size)), sizeof(int));
-      memcpy( (void *)(retVal.data+n), (const void*)&(i->size), sizeof(int) );
-      n+=sizeof(int);
-      switch(i->type){
+      if( ((*i)->mode & state_) == 0 ){
+        COUT(5) << "not getting data: " << std::endl;
+        continue;  // this variable should only be received
+      }
+      switch((*i)->type){
       case DATA:
-        std::memcpy( (void *)(retVal.data+n), (const void*)(i->var), i->size);
-        n+=i->size;
+        std::memcpy( (void *)(retVal.data+n), (void*)((*i)->var), (*i)->size);
+        n+=(*i)->size;
         break;
       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;
+        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;
       }
@@ -168,22 +194,30 @@
   bool Synchronisable::updateData(syncData vars){
     unsigned char *data=vars.data;
-    std::list<synchronisableVariable>::iterator i;
-    for(i=syncList.begin(); i!=syncList.end(); i++){
-      if((int)*data==i->size || i->type==STRING){
-        switch(i->type){
+    std::list<synchronisableVariable *>::iterator i;
+    if(syncList->empty()){
+      COUT(4) << "Synchronisable::updateData syncList is empty" << std::endl;
+      return false;
+    }
+    COUT(5) << "Synchronisable: objectID " << vars.objectID << ", classID " << vars.classID << " size: " << vars.length << " synchronising data" << std::endl;
+    for(i=syncList->begin(); i!=syncList->end(); i++){
+      if( ((*i)->mode ^ state_) == 0 ){
+        COUT(5) << "synchronisable: not updating variable " << std::endl;
+        continue;  // this variable should only be updated
+      }
+      COUT(5) << "Synchronisable: element size: " << (*i)->size << " type: " << (*i)->type << std::endl;
+      switch((*i)->type){
       case DATA:
+        memcpy((void*)(*i)->var, data, (*i)->size);
+        data+=(*i)->size;
+        break;
+      case STRING:
+        (*i)->size = *(int *)data;
+        COUT(5) << "string size: " << (*i)->size << std::endl;
         data+=sizeof(int);
-        memcpy((void*)i->var, data, i->size);
-        data+=i->size;
-        break;
-      case STRING:
-        i->size = (int)*data;
-        data+=sizeof(int);
-        *((std::string *)i->var) = std::string((const char*)data);
-        data += i->size;
-        break;
-        }
-      } else
-        return false; //there was some problem with registerVar
+        *((std::string *)((*i)->var)) = std::string((const char*)data);
+        COUT(5) << "synchronisable: char: " << (const char*)data << " string: " << std::string((const char*)data) << std::endl;
+        data += (*i)->size;
+        break;
+      }
     }
     return true;
@@ -196,19 +230,30 @@
   int Synchronisable::getSize(){
     int tsize=0;
-    std::list<synchronisableVariable>::iterator i;
-    for(i=syncList.begin(); i!=syncList.end(); i++){
-      switch(i->type){
-    case DATA:
-      tsize+=sizeof(int);
-      tsize+=i->size;
-      break;
-    case STRING:
-      tsize+=sizeof(int);
-      tsize+=((std::string *)i->var)->length()+1;
-      break;
+    std::list<synchronisableVariable *>::iterator i;
+    for(i=syncList->begin(); i!=syncList->end(); i++){
+      if( ((*i)->mode & state_) == 0 )
+        continue;  // this variable should only be received, so dont add its size to the send-size
+      switch((*i)->type){
+      case DATA:
+        tsize+=(*i)->size;
+        break;
+      case STRING:
+        tsize+=sizeof(int);
+        (*i)->size=((std::string *)(*i)->var)->length()+1;
+        COUT(5) << "String size: " << (*i)->size << std::endl;
+        tsize+=(*i)->size;
+        break;
       }
     }
     return tsize;
   }
-
+  
+  void Synchronisable::setBacksync(bool sync){
+    backsync_=sync;
+  }
+
+  bool Synchronisable::getBacksync(){
+    return backsync_;
+  }
+  
 }
Index: code/branches/merge/src/network/Synchronisable.h
===================================================================
--- code/branches/merge/src/network/Synchronisable.h	(revision 1263)
+++ code/branches/merge/src/network/Synchronisable.h	(revision 1264)
@@ -62,5 +62,6 @@
   typedef struct synchronisableVariable{
     int size;
-    const void *var;
+    int mode; // this determines in which direction the variable gets synchronised
+    void *var;
     variableType type;
   }SYNCVAR;
@@ -69,5 +70,6 @@
   /**
   * This class is the base class of all the Objects in the universe that need to be synchronised over the network
-  * Every class, that inherits from this class has to link the DATA THAT NEEDS TO BE SYNCHRONISED into the linked list. Additionally it also has to provide a Constructor, that takes exactly the variables in this linked list.
+   * Every class, t
+  int mode;hat inherits from this class has to link the DATA THAT NEEDS TO BE SYNCHRONISED into the linked list. Additionally it also has to provide a Constructor, that takes exactly the variables in this linked list.
   * @author Oliver Scheuss
   */
@@ -75,15 +77,18 @@
   public:
 
-      virtual ~Synchronisable();
+    virtual ~Synchronisable();
     int objectID;
     int classID;
 
-    void registerVar(const void *var, int size, variableType t);
+    void registerVar(void *var, int size, variableType t, int mode=1);
     //  syncData getData();
     syncData getData(unsigned char *mem);
     int getSize();
     bool updateData(syncData vars);
+    void setBacksync(bool sync);
+    bool getBacksync();
     virtual void registerAllVariables()=0;
     virtual bool create()=0;
+    static void setClient(bool b);
   protected:
     Synchronisable();
@@ -91,6 +96,8 @@
     /*  bool removeObject(Iterator<Synchronisable> it);*/
 
-    std::list<SYNCVAR> syncList;
+    std::list<synchronisableVariable *> *syncList;
     int datasize;
+    static int state_; // detemines wheter we are server (default) or client
+    bool backsync_; // if true the variables with mode > 1 will be synchronised to server (client -> server)
   };
 }
Index: code/branches/merge/src/network/diffTest.cc
===================================================================
--- code/branches/merge/src/network/diffTest.cc	(revision 1264)
+++ code/branches/merge/src/network/diffTest.cc	(revision 1264)
@@ -0,0 +1,723 @@
+#include "enet/enet.h"
+#include "Orxonox.h"
+#include "NetworkPrereqs.h"
+#include "PacketTypes.h"
+#include "GameStateManager.h"
+#include "Synchronisable.h"
+#include "GameStateClient.h"
+#include "iostream"
+#include "core/CoreIncludes.h"
+#include "time.h"
+#include "ConnectionManager.h"
+#include "ClientInformation.h"
+#include "Synchronisable.h"
+#include <boost/thread/thread.hpp>
+#include <boost/bind.hpp>
+#include "util/Sleep.h"
+
+using namespace network;
+
+void printData( unsigned char* data, int length ) {
+  for ( int i=0; i<length; i++ )
+    std::cout << (int)data[i] << " ";
+  std::cout << std::endl;
+}
+
+void printGameStateCompressed( GameStateCompressed* gc ) {
+  //std::cout << "=================================================" << std::endl;
+  std::cout << "GameStateCompressed id:\t\t" << gc->id << std::endl;
+  std::cout << "GameStateCompressed normsize:\t" << gc->normsize << std::endl;
+  std::cout << "GameStateCompressed compsize:\t" << gc->compsize << std::endl;
+  std::cout << "GameStateCompressed diffed:\t" << gc->diffed << std::endl;
+  //std::cout << "GameState data:\t" << gc->data << std::endl;
+  std::cout << "GameStateCompressed compressing rate:\t" << 100.0-((100.0/(gc->normsize))*(gc->compsize)) << "%" << std::endl;
+  std::cout << "=================================================" << std::endl;
+  return;
+}
+
+bool compareData( GameState* g1, GameState* g2 ) {
+  if ( g1->id != g2->id ) {
+    std::cout << "\t--> GameStates are not comparable -> not same id" << std::endl;
+    return true;
+  }
+  else if ( g1->size != g2->size ) {
+    std::cout << "\t--> GameStates are not the same size!!" << std::endl;
+    std::cout << g1->size << " != " << g2->size << std::endl;
+  }
+  int length = g1->size;
+  for ( int i=0; i<length; i++ ) {
+    if ( g1->data[i] != g2->data[i] ) {
+      std::cout << "\t--> data of both GameStates are not identical" << std::endl;
+      return false;
+    }
+  }
+  //std::cout << "\t--> GameData are identical (compareData)" << std::endl;
+  return true;
+}
+
+bool compareData2( GameState* g1, GameState* g2 ) {
+  int length = g1->size;
+  for ( int i=0; i<length; i++ ) {
+    if ( g1->data[i] != g2->data[i] ) {
+      return false;
+    }
+  }
+  //std::cout << "\t--> GameData are identical (compareData)" << std::endl;
+  return true;
+}
+
+bool compareGameStates( GameState* g1, GameState* g2 ) {
+  if ( g1->id != g2->id ) {
+    std::cout << "\t==> GameState id's not identical (GameStateCompare)" << std::endl;
+  }
+  if( g1->size != g2->size ) {
+    std::cout << "\t==> GameState sizes are not identical (GameStateCompare)" << std::endl;
+    return false;
+  }
+  else if ( g1->diffed != g2->diffed ) {
+    std::cout << "\t==> GameState diffed params not identical (GameStateCompare)" << std::endl;
+    return false;
+  }
+  else if ( !compareData2( g1, g2 ) ) {
+    std::cout << "\t==> GameState data are not identical (GameStateCompare)" << std::endl;
+    return false;
+  }
+  //std::cout << "\t==> GameStates are identical (GameStateCompare)" << std::endl;
+  return true;
+}
+
+void printGameState( GameState* gstate ) {
+  //std::cout << "=================================================" << std::endl;
+  std::cout << "GameState id:\t\t" << gstate->id << std::endl;
+  std::cout << "GameState size:\t\t" << gstate->size << std::endl;
+  std::cout << "GameState diffed:\t" << gstate->diffed << std::endl;
+  //std::cout << "GameState data:\t" << gstate->data << std::endl;
+  std::cout << "=================================================" << std::endl;
+  return;
+}
+
+unsigned char* createData( int length, int mode ) {
+  char* data = new char[ length ];
+  if ( mode == 1 ) {
+    for ( int i=0; i<length; i++ )
+      data[i] = (char)(i%255);
+  }
+  else if ( mode == 2 ) {
+    for ( int i=0; i<length; i++ ) {
+      if ( i%98 == 0 ) data[i] = (char)(i%255);
+      else data[i] = (char)0;
+    }
+  }
+  else if ( mode == 3 ) {
+    for ( int i=0; i<length; i++ ){
+      data[i] = (char)(rand()%255);
+    }
+  }
+  else if ( mode == 4 ) {
+    for ( int i=0; i<length; i++ ){
+      data[i] = (char)(rand()%127);
+    }
+  }
+
+  //printData( data, length );  
+
+  unsigned char* dat = (unsigned char*)data;
+  return dat;
+}
+
+GameState* changeGameStateABit( GameState* a, int mode ) {
+  int length = a->size;
+  GameState* b = new GameState;
+  b->id = a->id;
+  b->diffed = a->diffed;
+
+  if ( mode == 1 ) {
+    b->data = new unsigned char[length];
+    b->size = a->size;
+    for ( int i=0; i<length; i++ ) {
+      if ( i%10 == 0 ) b->data[i] = rand()%255;
+      else b->data[i] = a->data[i];
+    }
+  }
+  else if ( mode == 2 ) {
+    b->data = new unsigned char[length];
+    b->size = length;
+    for ( int i=0; i<length; i++ ) {
+      if ( i%(rand()%((length)/11)+rand()) == 0 ) b->data[i] = (char)rand()%255;
+      else b->data[i] = a->data[i];
+    }
+  }
+  else if ( mode == 3 ) {
+    int s = length + (rand()%(length));
+    b->data = new unsigned char[s];
+    b->size = s;
+    for ( int i=0; i<length; i++ ) {
+      if ( i%10 == 0 ) b->data[i] = (char)rand()%255;
+      else b->data[i] = a->data[i];
+    }
+    for( int i=length; i<s; i++ ) {
+      b->data[i] = (char)rand()%255;
+    }
+  }
+  else if ( mode == 4 ) {
+    int s = length + (rand()%(length));
+    b->data = new unsigned char[s];
+    b->size = s;
+    for ( int i=0; i<length; i++ ) {
+      if ( i%(rand()%(length)+rand()) == 0 ) b->data[i] = (char)rand()%255;
+      else b->data[i] = a->data[i];
+    }
+    for( int i=length; i<s; i++ ) {
+      b->data[i] = rand()%255;
+    }
+  }
+    else if ( mode == 5 ) {
+    int s = (length)/2;
+    b->data = new unsigned char[s];
+    b->size = s;
+    for ( int i=0; i<s; i++ ) {
+      if ( i%10 == 0 ) b->data[i] = (char)rand()%255;
+      else b->data[i] = a->data[i];
+    }
+  }
+
+  return b;
+}
+
+void testCompression( int size, int mode ) {
+  std::cout << "testing compression with: size = " << size << " ,mode = " << mode << std::endl; 
+  GameStateClient* g_client;
+  GameStateManager* g_manager;;
+  
+  GameState* g_new = new GameState;
+  GameState* g_old = new GameState;
+  GameStateCompressed* gc = new GameStateCompressed;
+  
+  g_old->data = createData( size, mode );
+  g_old->size = size;
+  g_old->id = 0;
+  g_old->diffed = false;
+  printGameState( g_old );
+  
+  gc = g_manager->testCompress( g_old );
+  printGameStateCompressed( gc );
+
+  g_new = g_client->testDecompress( gc );
+  printGameState( g_new );
+
+  compareGameStates( g_new, g_old );
+
+  return;
+}
+
+void testDifferentiation( int size, int modeCreateData, int modeChangeData ) {
+  std::cout << "testing diff with: size = " << size << " modeCreateData = " 
+            << modeCreateData << " modeChangeData = " << modeChangeData << std::endl; 
+  GameStateClient* g_client;
+  GameStateManager* g_manager;
+  
+  GameState* g_undiff1 = new GameState;
+  GameState* g_undiff2 = new GameState;
+  GameState* g_diffed;
+  GameState* g_result;
+
+  g_undiff1->data = createData( size, modeCreateData );
+  g_undiff1->size = size;
+  g_undiff1->id = 1;
+  g_undiff1->diffed = false;
+  printGameState( g_undiff1 );
+
+  g_undiff2 = changeGameStateABit( g_undiff1, modeChangeData );
+  printGameState( g_undiff2 );
+
+  if( !compareData( g_undiff1, g_undiff2 ) ) std::cout << " BUT THAT'S HOW IT HAS TO BE" << std::endl;
+
+  //printData( g_undiff1->data, g_undiff1->size );
+  //printData( g_undiff2->data, g_undiff2->size );
+  
+  g_diffed = g_manager->testDiff( g_undiff1, g_undiff2 );
+  printGameState( g_diffed );
+  //printData( g_diffed->data, g_diffed->size );
+  
+  g_result = g_client->testUndiff( g_undiff1, g_diffed );
+  compareGameStates( g_result, g_undiff2 );
+
+  return;
+}
+
+void testCompressWithDiff( int size, int modeCreateData, int modeChangeData ) {
+  std::cout << "testing CompressWithDiff with: size = " << size << " modeCreateData = " 
+            << modeCreateData << " modeChangeData = " << modeChangeData << std::endl; 
+  GameStateClient* g_client;
+  GameStateManager* g_manager;;
+  
+  GameStateCompressed* gc = new GameStateCompressed;
+  GameStateCompressed* g_compressedNoDiff;
+  GameState* g_undiff1 = new GameState;
+  GameState* g_undiff2 = new GameState;
+  GameState* g_diffed;
+  GameState* g_resultDiffed;
+  GameState* g_resultUndiffed;
+
+  g_undiff1->data = createData( size, modeCreateData );
+  g_undiff1->size = size;
+  g_undiff1->id = 1;
+  g_undiff1->diffed = false;
+  
+  std::cout << "---First generated Gamestate" << std::endl;
+  printGameState( g_undiff1 );
+
+  g_undiff2 = changeGameStateABit( g_undiff1, modeChangeData );
+  std::cout << "---First gererated Gamestate with some changes ev. longer" << std::endl;
+  printGameState( g_undiff2 );  
+
+  if( !compareData( g_undiff1, g_undiff2 ) ) std::cout << " DATA not identical.. ok" << std::endl;
+
+  g_diffed = g_manager->testDiff( g_undiff1, g_undiff2 );
+  std::cout << "---Diffed Gamestate not compressed" << std::endl;
+  printGameState( g_diffed );
+
+  gc = g_manager->testCompress( g_diffed );
+  std::cout << "---Diffed Gamestate compressed" << std::endl;
+  printGameStateCompressed( gc );
+
+  g_compressedNoDiff = g_manager->testCompress( g_undiff2 );
+  std::cout << "---Same not Diffed Gamestate compressen" << std::endl;
+  printGameStateCompressed( g_compressedNoDiff ); 
+
+  g_resultDiffed = g_client->testDecompress( gc );
+  std::cout << "---Diffed Gamestate of above uncompressed" << std::endl;
+  printGameState( g_resultDiffed );
+
+  std::cout << "---Diffed Gamestates before compressed and after uncompress comparsion" << std::endl;
+  if ( compareGameStates( g_resultDiffed, g_diffed ) ) std::cout << "GAMESTATES IDENTICAL" << std::endl;
+ 
+  g_resultUndiffed = g_client->testUndiff( g_undiff1, g_resultDiffed );
+  std::cout << "---New Gamestate of pseudo Server compared with new gamestate that Client gets" << std::endl;
+  if ( compareGameStates( g_resultUndiffed, g_undiff2 ) ) std::cout << "GAMESTATES IDENTICAL" << std::endl;
+
+  return;  
+}
+
+bool testNCompressWithDiff( int n, int size, int modeCreateData, int modeChangeData ) { 
+
+  GameStateClient* g_client;
+  GameStateManager* g_manager;;
+  
+  GameStateCompressed* gc = new GameStateCompressed;
+  GameState* g_undiff1 = new GameState;
+  GameState* g_undiff2 = new GameState;
+  GameState* g_diffed;
+  GameState* g_resultDiffed;
+  GameState* g_resultUndiffed;
+
+  g_undiff1->data = createData( size, modeCreateData );
+  g_undiff1->size = size;
+  g_undiff1->id = 1;
+  g_undiff1->diffed = false;
+  //l = -1;
+  g_undiff2 = changeGameStateABit( g_undiff1, modeChangeData );
+
+  while( compareData2( g_undiff1, g_undiff2 ) ) {
+    delete g_undiff2->data;
+    g_undiff2 = changeGameStateABit( g_undiff1, modeChangeData );
+  } 
+  //l = -2;
+  g_diffed = g_manager->testDiff( g_undiff1, g_undiff2 );
+  gc = g_manager->testCompress( g_diffed );
+  g_resultDiffed = g_client->testDecompress( gc );
+
+  if ( !compareGameStates( g_resultDiffed, g_diffed ) ) return false;
+  //l = -3;
+  g_resultUndiffed = g_client->testUndiff( g_undiff1, g_resultDiffed );
+  if ( !compareGameStates( g_resultUndiffed, g_undiff2 ) ) return false;
+  //l = 1;
+  /*if ( gc != NULL && gc->data != NULL )
+    delete gc->data;
+  //l = 2;
+  //if ( gc != NULL ) 
+    //delete gc;
+  //l = 3;
+  if ( g_undiff1 != NULL && g_undiff1->data != NULL )
+    delete g_undiff1->data;
+  //l = 4; 
+  //if ( g_undiff1 != NULL )
+   //delete g_undiff1;
+  //l = 5;
+  if ( g_undiff2 != NULL && g_undiff2->data )
+    delete g_undiff2->data;
+  //l = 6; 
+  //if ( g_undiff2 != NULL )
+    //delete g_undiff2;
+  //l = 7;
+  if ( g_diffed != NULL && g_diffed->data )
+    //delete g_diffed->data;
+  //l = 8; 
+  //if ( g_diffed )
+    //delete g_diffed;
+  //l = 9;
+  if ( g_resultDiffed != NULL && g_resultDiffed->data )
+    delete g_resultDiffed->data;
+  //l = 10; 
+  //if ( g_resultDiffed )
+    //delete g_resultDiffed;
+  //l = 11;*/
+  
+  return true;
+}
+
+bool testNCompression( int n, int size, int mode ) { 
+  GameStateClient* g_client;
+  GameStateManager* g_manager;;
+  
+  GameState* g_new = new GameState;
+  GameState* g_old = new GameState;
+  GameStateCompressed* gc = new GameStateCompressed;
+  
+  g_old->data = createData( size, mode );
+  g_old->size = size;
+  g_old->id = 0;
+  g_old->diffed = false;
+  
+  gc = g_manager->testCompress( g_old );
+
+  g_new = g_client->testDecompress( gc );
+
+  if ( !compareGameStates( g_new, g_old ) ) return false;
+  
+  
+  if ( g_new != NULL && g_new->data != NULL )
+    delete g_new->data;
+
+  if ( g_old != NULL && g_old->data != NULL )
+    delete g_old->data;
+
+  if ( gc != NULL && gc->data )
+    delete gc->data;
+
+  return true;
+}
+
+void printClientObjectMapping( ConnectionManager* cmanager, int clients ) {
+  std::map<int, int>::iterator iter;
+  std::map<int, int> clientsmap = cmanager->testGetClientsShip();   
+  for( iter = clientsmap.begin(); iter != clientsmap.end(); iter++ ) {
+    std::cout << "clientID: " << iter->first << "\t-> objectID: " << iter->second << std::endl;
+  }
+  return;
+}
+
+bool is( int a[], int b, int size ) {
+  for ( int i=0; i<size; i++ ) {
+    if ( a[i] == b ) return true;
+  }
+  return false;
+}
+
+void testClientObjectMapping( int clients ) {
+  ConnectionManager* cmanager = new ConnectionManager();
+  int shift = 2;
+  std::cout << "create a map length [clients]" << std::endl;
+  for ( int i=0; i<clients; i++ ) {
+    cmanager->testAddClientsShipID( i, i+shift );
+  }
+  printClientObjectMapping( cmanager, clients );
+  
+  std::cout << "get random client's ship id" << std::endl;
+  int id;
+  for ( int i=0; i<(clients/3); i++ ) {
+    id = rand()%clients;
+    std::cout << "client: " << id << "\t-> ship: " << cmanager->testGetClientsShipID( id ) << std::endl;  
+  }
+
+  std::cout <<"get random ship's client id" << std::endl;
+  for ( int i=0; i<(clients/3); i++ ) {
+    id = (rand()%clients)+shift;
+    std::cout << "ship:   " << id << "\t-> client: " << cmanager->testGetObjectsClientID( id ) << std::endl;  
+  }
+
+  std::cout << "delete random client from map" << std::endl;
+  int deleted[clients/3];
+  for ( int i=0; i<(clients/3); i++ ) {
+    id = rand()%clients;
+    if ( !is( deleted, id, clients/3 ) ) {
+      std::cout << "delete client " << id << std::endl;
+      cmanager->testDeleteClientsIDReg( id ); 
+    }
+    deleted[i] = id;
+  }
+  std::cout << "resulting list:" << std::endl;
+  printClientObjectMapping( cmanager, clients-(clients/3));
+  
+  std::cout << "delete random object from map" << std::endl;
+  int jap = 0;
+  while( jap < 3 ) {
+    id = (rand()%clients) + shift;
+    if ( !is( deleted, id, clients/3 ) ) {
+      std::cout << "delete object: " << id << std::endl;
+      cmanager->testDeleteObjectIDReg( id );
+      jap++;
+    }
+  }
+  std::cout << "resulting list:" << std::endl;
+  printClientObjectMapping( cmanager, clients-(clients/3)-3);
+}
+
+bool addClientTest( ENetEvent* event, ClientInformation*& head ) {
+  ClientInformation *temp = head->insertBack(new ClientInformation);
+  if(temp->prev()->head) {
+    temp->prev()->setID(0);
+    temp->setID(1);
+  }
+  else
+    temp->setID(temp->prev()->getID()+1);
+  temp->setPeer(event->peer);
+  std::cout << "added client id: " << temp->getID() << std::endl;
+
+  temp->setSynched(true);
+  return true;
+}
+
+void printClientInformationBox( ClientInformation* box ) {
+  std::cout << "ClientList: id: " << box->getID() << "\t";
+  std::cout << "g_id: " << box->getGamestateID() << " \t";
+  std::cout << "synched: " << box->getSynched() << "\t";
+  std::cout << "is head: " << box->head << std::endl;
+}
+
+void printClientInformationList( ClientInformation* list ) {
+  printClientInformationBox( list );
+  list = list->next();
+  
+  while( list != 0 ) {
+    printClientInformationBox( list );
+    list = list->next();
+  }
+  return;
+}
+
+void testClientInformation( int numberOfClients ) {
+  ClientInformation* head = new ClientInformation( true );
+  ConnectionManager* connectionManager;
+  ENetEvent event;
+  
+  for ( int i=0; i<numberOfClients; i++ ) {
+    if ( !addClientTest( &event, head ) ) {
+      std::cout << "addClientTest didn't work with: " << i << std::endl;
+    }
+  }
+  std::cout << "(now id should be synched, since that works and this is test of list, this step is left out)" << std::endl;
+
+  printClientInformationList( head );
+
+  std::cout << "remove some clients" << std::endl;
+  if ( head->removeClient( numberOfClients/3 ) ) std::cout << "client " << numberOfClients/3 << " removed" << std::endl;
+  else std::cout << "could not remove client: " << numberOfClients/3 << std::endl;
+  if ( head->removeClient( numberOfClients ) ) std::cout << "client " << numberOfClients << " removed" << std::endl;
+  else std::cout << "could not remove client: " << numberOfClients << std::endl;
+  if ( head->removeClient( 1 ) ) std::cout << "client " << 1 << " removed" << std::endl;
+  else std::cout << "could not remove client: " << 1 << std::endl;
+  if ( head->removeClient( 1 ) ) std::cout << "client " << 1 << " removed a second time" << std::endl;
+  else std::cout << "could not remove client: " << 1 << std::endl;
+  if ( head->removeClient( numberOfClients + 100 ) ) std::cout << "client " << numberOfClients + 100 << " removed a second time" << std::endl;
+  else std::cout << "could not remove client: " << numberOfClients + 100 << std::endl;
+
+  printClientInformationList( head );
+  
+  std::cout << "try to find some clients with findClient(..., false)" << std::endl;
+  ClientInformation* temp = head->findClient( 2 );
+  printClientInformationBox( temp );
+  temp = head->findClient( numberOfClients/3 );
+  printClientInformationBox( temp );
+  temp = head->findClient( 0 );
+  printClientInformationBox( temp );
+  temp = head->findClient( 8 );
+  printClientInformationBox( temp );
+
+  std::cout << "find the same, output should be identical with above but with findClient(..., TRUE)" << std::endl;
+  temp = head->findClient( 2, true );
+  printClientInformationBox( temp );
+  temp = head->findClient( numberOfClients/3, true );
+  printClientInformationBox( temp );
+  temp = head->findClient( 0, true );
+  printClientInformationBox( temp );
+  temp = head->findClient( 8, true );
+  printClientInformationBox( temp );
+
+  std::cout << "test setGamestateID" << std::endl;
+  temp->setGamestateID( 8 );
+  printClientInformationBox( temp );
+
+  std::cout << "test insertAfter() and insertBefore()" << std::endl;
+  ClientInformation* newInfo = new ClientInformation;
+  ClientInformation* toool = new ClientInformation;
+  newInfo->setGamestateID( 200 );
+  newInfo->setID( numberOfClients+2);
+  newInfo->setSynched( true );
+  newInfo->setPeer( NULL );
+  toool->setGamestateID( 199 );
+  toool->setID( numberOfClients+1);
+  toool->setSynched( true );
+  toool->setPeer( NULL );
+
+  //never use the same ClientInformation box in this situation
+  //-> results in endless loop
+  temp->insertAfter( newInfo );
+  temp->insertBefore( toool );
+
+  printClientInformationList( head );
+  return;
+}
+
+//### following stuff is to test buffer, took from PacketBufferTestExt.cc ###
+
+void write(PacketBuffer *test){
+  ENetEvent event;
+  ENetPacket *packet;
+  if(test->isEmpty())
+    std::cout << "buffer is empty" << std::endl;
+  for(int i=0; i<10; i++){
+    std::string temp = "packet ";
+    packet = enet_packet_create("packet", strlen("packet ")+1,
+      ENET_PACKET_FLAG_RELIABLE);
+    std::cout << i << ": pushing " << packet->data << std::endl;
+    event.packet=packet;
+    test->push(&event);
+    if(i==5)
+      usleep(200000);
+  }
+  test->setClosed(true);
+  return;
+}
+
+void read(PacketBuffer *test){
+  //test->print();
+  // exit if the queue is closed and empty
+  while(!test->isClosed() || !test->isEmpty()){
+    // only pop if the queue isn't empty
+    while(!test->isEmpty()){
+      std::cout << "We popped the value " << test->pop()->data << std::endl;
+    }
+  }
+  return;
+}
+
+void testPacketBuffer() {
+  PacketBuffer test = PacketBuffer();
+  boost::thread thrd1(boost::bind(&write, &test));
+  boost::thread thrd2(boost::bind(&read, &test));
+
+  thrd1.join();
+  thrd2.join();
+  return;
+}
+
+//### end packetbuffer test stuff ###
+
+void testSynchronisable() {
+  Synchronisable* synchtest;
+  unsigned char* data = new unsigned char[100];
+  for( int i=0; i<100; i++ ) {
+    data[i] = i%10;
+  }
+  //synchtest->registerVar( (const void*)data, 100, network::DATA );
+}
+
+//#########################################################################
+//### this stuff is only a loop to chose one of the prev test functions ###
+//#########################################################################
+void displayModes() {
+  std::cout << "mode datalength: length of data array to create" << std::endl;
+  std::cout << "mode Data:" << std::endl;
+  std::cout << "\t-1 -> array[length] with numbers length%255" << std::endl;
+  std::cout << "\t-2 -> array[length] with numbers length%255, every %98 is != 0" << std::endl;
+  std::cout << "\t-3 -> array[length] with random numbers (-126:127) no modulo zeros" << std::endl;
+  std::cout << "\t-4 -> array[length] with random numbers (0:127) no modulo zeros" << std::endl;
+  std::cout << "---------------------------------------------------------------------------------" << std::endl;
+  std::cout << "mode Change:" << std::endl;
+  std::cout << "\t-1 -> every %10 == 0 index is different from original" << std::endl;
+  std::cout << "\t-2 -> every %(rand()%(length/11)) is different from original" << std::endl;
+  std::cout << "\t-3 -> every %10 == 0 index is different and randomly longer till 2xlonger" << std::endl;
+  std::cout << "\t-4 -> random differences and randomly longer" << std::endl;
+  std::cout << "\t-5 -> only half as long and ever %10 == 0 index is different" << std::endl;
+}
+
+int main( int argc, char* argv[] ) {
+  int a,b,c,n;
+  std::string dec = "nothing";
+  std::cout << "############### START TEST (quit q) ###############" << std::endl;
+  std::cout << "possible tests: " << std::endl;
+  std::cout << "displayModes:\t\t modes" << std::endl;
+  std::cout << "testCompression:\t tc [datalength] [mode Data]" << std::endl;
+  std::cout << "testNCompression:\t tnc [#of loops] [datalength] [mode Data]" << std::endl;
+  std::cout << "testDifferentiation:\t td [datalength] [mode Data] [mode Change]" << std::endl;
+  std::cout << "testCompressWithDiff:\t tcd [datalength] [mode Data] [mode Change]" << std::endl;
+  std::cout << "testNCompressWithDiff:\t tncd [#of loops] [datalength] [mode Data] [mode Change]" << std::endl;
+  std::cout << "testClientObjectMapping: tcom [#clients]" << std::endl;
+  std::cout << "testClientInformation:\t tci [#clients] (call with >10)" << std::endl;
+  std::cout << "testPacketBuffer:\t tbuf (comment address assignements in PacketBuffer.cc!)" << std::endl;
+  while ( dec.compare("q") != 0 ) {
+    std::cin >> dec;
+    if ( dec.compare("tc") == 0 ) {
+      std::cin >> a; std::cin >> b;
+      testCompression( a, b );
+    }
+    else if ( dec.compare("td") == 0 ) {
+      std::cin>> a; std::cin >> b; std::cin >> c;
+      testDifferentiation( a, b, c );
+    }
+    else if ( dec.compare("tcd") == 0 ) {
+      std::cin>> a; std::cin >> b; std::cin >> c;
+      testCompressWithDiff( a, b, c );
+    }
+    else if ( dec.compare("modes") == 0 )
+      displayModes();
+    else if ( dec.compare("tcom") == 0 ) {
+      std::cin>> a;
+      testClientObjectMapping( a );
+    }
+    else if ( dec.compare("tci") == 0 ) {
+      std::cin >> a;
+      testClientInformation( a );
+    } 
+    else if ( dec.compare("tbuf") == 0 ) {
+      testPacketBuffer();
+    } 
+    else if ( dec.compare("tncd") == 0 ) {
+      std::cin >> n; std::cin >> a; std::cin >> b; std::cin >> c;
+      for ( int i=1; i<=n; i++ ) {  
+        std::cout << i << " s" << a << " ";      
+        //std::cout << "start loop test " << i << std::endl;
+        if ( !testNCompressWithDiff( i, a, b, c ) ) {
+          std::cout << "#COMPARSION ERROR->VERYVERY BAD" << std::endl;
+          break;
+        }
+      }
+      std::cout << "end loop comparsion test" << std::endl;
+    }
+    else if ( dec.compare("tnc") == 0 ) {
+      std::cin >> n; std::cin >> a; std::cin >> b;
+      for ( int i=1; i<=n; i++ ) {  
+        std::cout << i << " s" << a << " ";      
+        //std::cout << "start loop test " << i << std::endl;
+        if ( !testNCompression( i, a, b ) ) {
+          std::cout << "#COMPARSION ERROR->VERYVERY BAD" << std::endl;
+          break;
+        }
+      }
+      std::cout << "end loop comparsion test" << std::endl;
+    }
+    else std::cout << "invalid input" << std::endl;  
+    std::cout << "################## END ONE TURN ##################@" << std::endl;
+  }
+  return 0;
+}
+/*
+int main() {
+  std::cout << "############### START TEST (quit q) ###############" << std::endl;
+  testSynchronisable();
+}*/
+
+//#########################################################################
+//### the prev loop is only to chose one prev prev test functions       ###
+//#########################################################################
Index: code/branches/merge/src/orxonox/CMakeLists.txt
===================================================================
--- code/branches/merge/src/orxonox/CMakeLists.txt	(revision 1263)
+++ code/branches/merge/src/orxonox/CMakeLists.txt	(revision 1264)
@@ -16,4 +16,5 @@
   objects/Ambient.cc
   objects/Camera.cc
+  objects/CameraHandler.cc
   objects/Explosion.cc
   objects/Model.cc
Index: code/branches/merge/src/orxonox/Main.cc
===================================================================
--- code/branches/merge/src/orxonox/Main.cc	(revision 1263)
+++ code/branches/merge/src/orxonox/Main.cc	(revision 1264)
Index: code/branches/merge/src/orxonox/Orxonox.cc
===================================================================
--- code/branches/merge/src/orxonox/Orxonox.cc	(revision 1263)
+++ code/branches/merge/src/orxonox/Orxonox.cc	(revision 1264)
@@ -189,9 +189,10 @@
     GraphicsEngine::getSingleton().destroy();
 
-    if (client_g)
-      delete client_g;
+    if (network::Client::getSingleton())
+      network::Client::destroySingleton();
     if (server_g)
       delete server_g;
   }
+
 
   /**
@@ -395,7 +396,7 @@
 
     if (serverIp_.compare("") == 0)
-      client_g = new network::Client();
+      client_g = network::Client::createSingleton();
     else
-      client_g = new network::Client(serverIp_, NETWORK_PORT);
+      client_g = network::Client::createSingleton(serverIp_, NETWORK_PORT);
 
     client_g->establishConnection();
@@ -511,4 +512,8 @@
 	  }
 
+    if(mode_==CLIENT)
+      network::Client::getSingleton()->closeConnection();
+    else if(mode_==SERVER)
+      server_g->close();
     return true;
   }
Index: code/branches/merge/src/orxonox/Orxonox.h
===================================================================
--- code/branches/merge/src/orxonox/Orxonox.h	(revision 1263)
+++ code/branches/merge/src/orxonox/Orxonox.h	(revision 1264)
Index: code/branches/merge/src/orxonox/objects/Ambient.cc
===================================================================
--- code/branches/merge/src/orxonox/objects/Ambient.cc	(revision 1263)
+++ code/branches/merge/src/orxonox/objects/Ambient.cc	(revision 1264)
@@ -57,4 +57,5 @@
         RegisterObject(Ambient);
         Ambient::instance_s = this;
+        registerAllVariables();
     }
 
@@ -63,4 +64,14 @@
     }
 
+    bool Ambient::create(){
+      GraphicsEngine::getSingleton().getSceneManager()->setAmbientLight(ambientLight_);
+      return true;
+    }
+    
+    void Ambient::registerAllVariables(){
+      registerVar(&ambientLight_, sizeof(ColourValue), network::DATA);
+      
+    }
+    
     void Ambient::loadParams(TiXmlElement* xmlElem)
     {
@@ -83,4 +94,5 @@
    {
     	GraphicsEngine::getSingleton().getSceneManager()->setAmbientLight(colour);
+      ambientLight_=colour;	
    }
 
@@ -96,4 +108,5 @@
 
         XMLPortParamLoadOnly(Ambient, "colourvalue", setAmbientLight, xmlelement, mode);
+        create();
     }
 }
Index: code/branches/merge/src/orxonox/objects/Ambient.h
===================================================================
--- code/branches/merge/src/orxonox/objects/Ambient.h	(revision 1263)
+++ code/branches/merge/src/orxonox/objects/Ambient.h	(revision 1264)
@@ -34,8 +34,9 @@
 #include "util/Math.h"
 #include "core/BaseObject.h"
+#include "network/Synchronisable.h"
 
 namespace orxonox
 {
-    class _OrxonoxExport Ambient : public BaseObject
+    class _OrxonoxExport Ambient : public BaseObject, network::Synchronisable
     {
         public:
@@ -46,4 +47,6 @@
             virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
             void setAmbientLight(const ColourValue& colour);
+            bool create();
+            void registerAllVariables();
 
             static void setAmbientLightTest(const ColourValue& colour)
@@ -52,4 +55,5 @@
         private:
             static Ambient* instance_s;
+            ColourValue ambientLight_;
 
     };
Index: code/branches/merge/src/orxonox/objects/Camera.cc
===================================================================
--- code/branches/merge/src/orxonox/objects/Camera.cc	(revision 1263)
+++ code/branches/merge/src/orxonox/objects/Camera.cc	(revision 1264)
@@ -47,56 +47,104 @@
 namespace orxonox
 {
-    CreateFactory(Camera);
+  //CreateFactory(Camera);
 
-    Camera::Camera()
+  Camera::Camera(Ogre::SceneNode* node)
+  {
+    //RegisterObject(Camera);
+    this->bHasFocus_ = false;
+    if( node != NULL )
+      this->setCameraNode(node);
+
+  }
+
+  Camera::~Camera()
+  {
+  }
+
+  /*void Camera::loadParams(TiXmlElement* xmlElem)
+  {
+    Ogre::SceneManager* mgr = GraphicsEngine::getSingleton().getSceneManager();
+
+    if (xmlElem->Attribute("name") && xmlElem->Attribute("pos") && xmlElem->Attribute("lookat") && xmlElem->Attribute("node"))
     {
-        RegisterObject(Camera);
+      //    <Camera name="Camera" pos="0,0,-250" lookat="0,0,0" />
+
+      std::string name = xmlElem->Attribute("name");
+      std::string pos = xmlElem->Attribute("pos");
+      std::string lookat = xmlElem->Attribute("lookat");
+
+      this->cam_ = mgr->createCamera(name);
+
+      float x, y, z;
+      SubString posVec(xmlElem->Attribute("pos"), ',');
+      convertValue<std::string, float>(&x, posVec[0]);
+      convertValue<std::string, float>(&y, posVec[1]);
+      convertValue<std::string, float>(&z, posVec[2]);
+
+      setPosition(Vector3(x,y,z));
+
+      //std::string target = xmlElem->Attribute("lookat");
+      posVec.split(xmlElem->Attribute("lookat"), ',');
+      convertValue<std::string, float>(&x, posVec[0]);
+      convertValue<std::string, float>(&y, posVec[1]);
+      convertValue<std::string, float>(&z, posVec[2]);
+
+      cam_->lookAt(Vector3(x,y,z));
+
+      /*std::string node = xmlElem->Attribute("node");
+
+      Ogre::SceneNode* sceneNode = (Ogre::SceneNode*)mgr->getRootSceneNode()->createChildSceneNode(node); //getChild(node);
+      sceneNode->attachObject((Ogre::MovableObject*)cam_);
+      */
+
+      // FIXME: unused var
+      //Ogre::Viewport* vp =
+      //GraphicsEngine::getSingleton().getRenderWindow()->addViewport(cam_);
+    /*
+
+      COUT(4) << "Loader: Created camera "<< name  << std::endl << std::endl;
     }
+  }*/
 
-    Camera::~Camera()
-    {
-    }
+  void Camera::setCameraNode(Ogre::SceneNode* node)
+  {
+    this->positionNode_ = node;
+    // set camera to node values according to camera mode
+  }
 
-    void Camera::loadParams(TiXmlElement* xmlElem)
-    {
-      Ogre::SceneManager* mgr = GraphicsEngine::getSingleton().getSceneManager();
+  void Camera::setTargetNode(Ogre::SceneNode* obj)
+  {
+    this->targetNode_ = obj;
+  }
 
-      if (xmlElem->Attribute("name") && xmlElem->Attribute("pos") && xmlElem->Attribute("lookat") && xmlElem->Attribute("node"))
-      {
-        //    <Camera name="Camera" pos="0,0,-250" lookat="0,0,0" />
+  /**
+    don't move anything before here! here the Ogre camera is set to values of this camera
+    always call update after changes
+  */
+  void Camera::update()
+  {
+    COUT(0) << "p " << this->positionNode_->getPosition() << std::endl;
+    COUT(0) << "t " << this->targetNode_->getPosition() << std::endl;
+    if(this->positionNode_ != NULL)
+      this->cam_->setPosition(this->positionNode_->getPosition());
+    if(this->targetNode_ != NULL)
+      this->cam_->lookAt(this->targetNode_->getPosition());
+  }
 
-        std::string name = xmlElem->Attribute("name");
-        std::string pos = xmlElem->Attribute("pos");
-        std::string lookat = xmlElem->Attribute("lookat");
+  /**
+    what to do when camera loses focus (do not request focus in this function!!)
+    this is called by the CameraHandler singleton class to notify the camera
+  */
+  void Camera::removeFocus()
+  {
+    this->bHasFocus_ = false;
+    this->positionNode_->detachObject(cam_);
+  }
 
-        Ogre::Camera *cam = mgr->createCamera(name);
-
-        float x, y, z;
-        SubString posVec(xmlElem->Attribute("pos"), ',');
-        convertValue<std::string, float>(&x, posVec[0]);
-        convertValue<std::string, float>(&y, posVec[1]);
-        convertValue<std::string, float>(&z, posVec[2]);
-
-        cam->setPosition(Vector3(x,y,z));
-
-        posVec = SubString(xmlElem->Attribute("lookat"), ',');
-        convertValue<std::string, float>(&x, posVec[0]);
-        convertValue<std::string, float>(&y, posVec[1]);
-        convertValue<std::string, float>(&z, posVec[2]);
-
-        cam->lookAt(Vector3(x,y,z));
-
-        std::string node = xmlElem->Attribute("node");
-
-        Ogre::SceneNode* sceneNode = (Ogre::SceneNode*)mgr->getRootSceneNode()->createChildSceneNode(node); //getChild(node);
-        sceneNode->attachObject((Ogre::MovableObject*)cam);
-
-        // FIXME: unused var
-        //Ogre::Viewport* vp = 
-        GraphicsEngine::getSingleton().getRenderWindow()->addViewport(cam);
-
-
-        COUT(4) << "Loader: Created camera "<< name  << std::endl << std::endl;
-      }
-   }
+  void Camera::setFocus(Ogre::Camera* ogreCam)
+  {
+    this->bHasFocus_ = true;
+    this->cam_ = ogreCam;
+    this->positionNode_->attachObject(cam_);
+  }
 }
Index: code/branches/merge/src/orxonox/objects/Camera.h
===================================================================
--- code/branches/merge/src/orxonox/objects/Camera.h	(revision 1263)
+++ code/branches/merge/src/orxonox/objects/Camera.h	(revision 1264)
@@ -30,22 +30,38 @@
 #define _Camera_H__
 
+#include <OgrePrerequisites.h>
+#include <OgreSceneNode.h>
+#include <OgreCamera.h>
+
 #include "OrxonoxPrereqs.h"
-
-#include "core/BaseObject.h"
 
 namespace orxonox
 {
-    class _OrxonoxExport Camera : public BaseObject
+    class _OrxonoxExport Camera
     {
-        public:
-            Camera();
-            virtual ~Camera();
+      friend class CameraHandler;
+      public:
+        Camera(Ogre::SceneNode* node = NULL);
+        virtual ~Camera();
+
+        //inline void setPosition(Ogre::Vector3 pos) { position_->setPosition(pos); cam_->setPosition(pos); }
+        void setCameraNode(Ogre::SceneNode* node);
+        inline Ogre::SceneNode* getCameraNode() { return this->positionNode_; }
+        // maybe also BaseObject
+        void setTargetNode(Ogre::SceneNode* obj);
 
 
-            void loadParams(TiXmlElement* xmlElem);
+        void update();
+        inline bool hasFocus() { return this->bHasFocus_; }
 
-        private:
+      private:
+        void removeFocus();
+        void setFocus(Ogre::Camera* ogreCam);
 
-
+      private:
+        Ogre::SceneNode* targetNode_;
+        Ogre::SceneNode* positionNode_;
+        Ogre::Camera* cam_;
+        bool bHasFocus_;
     };
 }
Index: code/branches/merge/src/orxonox/objects/CameraHandler.cc
===================================================================
--- code/branches/merge/src/orxonox/objects/CameraHandler.cc	(revision 1264)
+++ code/branches/merge/src/orxonox/objects/CameraHandler.cc	(revision 1264)
@@ -0,0 +1,94 @@
+/*
+ *   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:
+ *      Benjamin Knecht
+ *   Co-authors:
+ *      ...
+ *
+ */
+#include <OgreSceneManager.h>
+#include <OgreRenderWindow.h>
+
+#include "OrxonoxStableHeaders.h"
+#include "core/ObjectList.h"
+#include "CameraHandler.h"
+#include "Camera.h"
+#include "GraphicsEngine.h"
+
+#include <OgreCamera.h>
+
+namespace orxonox {
+
+  CameraHandler* CameraHandler::singletonRef = NULL;
+
+  CameraHandler::CameraHandler()
+  {
+    this->cam_ = GraphicsEngine::getSingleton().getSceneManager()->createCamera("Cam");
+    GraphicsEngine::getSingleton().getRenderWindow()->addViewport(this->cam_);
+    /*this->activeCamera_ = *ObjectList<Camera>::begin();
+    this->activeCamera_->cam_ = this->cam_;*/
+  }
+
+  void CameraHandler::requestFocus(Camera* requestCam)
+  {
+    // notify old camera (if it exists)
+    if(focusList_.size() > 0)
+      focusList_.back()->removeFocus();
+    // add to list
+    focusList_.push_back(requestCam);
+    // set focus to new camera and update (if necessary)
+    if(!requestCam->hasFocus()) {
+      requestCam->setFocus(this->cam_);
+      requestCam->update();
+    }
+    // delete dublicates
+    focusList_.unique();
+  }
+
+  void CameraHandler::releaseFocus(Camera* cam)
+  {
+    // notify the cam of releasing the focus
+    if(cam->hasFocus())
+      cam->removeFocus();
+    // delete camera from list
+    focusList_.remove(cam);
+    // set new focus if necessary
+    if(!(focusList_.back()->hasFocus()))
+      focusList_.back()->setFocus(this->cam_);
+  }
+/*
+  void CameraHandler::changeActiveCamera(Camera* setCam)
+  {
+    cam_->getParentSceneNode()->detachObject(cam_);
+    //setCam->attachCamera(cam_);
+    activeCamera_ = setCam;
+  }
+*/
+/*  bool isInVector(Camera* cam)
+  {
+    for(std::vector<Camera*>::iterator it = cams_.begin(); it != cams_.end(); it++)
+    {
+      if (*it == cam) return true;
+    }
+    return false;
+  }*/
+}
Index: code/branches/merge/src/orxonox/objects/CameraHandler.h
===================================================================
--- code/branches/merge/src/orxonox/objects/CameraHandler.h	(revision 1264)
+++ code/branches/merge/src/orxonox/objects/CameraHandler.h	(revision 1264)
@@ -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:
+ *      Benjamin Knecht
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+ /**
+ @file  CameraHandler.h
+ @brief Handles the instances of Camera class
+ @author Benjamin Knecht <beni_at_orxonox.net>
+  */
+
+#ifndef _Camera_Handler_H__
+#define _Camera_Handler_H__
+
+#include <list>
+
+#include <OgreCamera.h>
+
+#include "OrxonoxPrereqs.h"
+
+#include "core/BaseObject.h"
+
+#include "Camera.h"
+
+namespace orxonox
+{
+  class _OrxonoxExport CameraHandler
+  {
+
+    public:
+      inline static CameraHandler* getInstance() { if (!CameraHandler::singletonRef) CameraHandler::singletonRef = new CameraHandler(); return CameraHandler::singletonRef; }
+      inline ~CameraHandler() { CameraHandler::singletonRef = NULL; }
+      inline Camera* getActiveCamera() { return this->focusList_.back(); }
+      /*void registerCamera(Camera* newCam);
+      void changeActiveCamera(Camera* setCam);*/
+      void requestFocus(Camera* requestCam);
+      void releaseFocus(Camera* cam);
+
+    private:
+      CameraHandler();
+      //bool isInVector(Camera* cam);
+
+    private:
+      static CameraHandler* singletonRef;
+      Ogre::Camera* cam_;
+      std::list<Camera*> focusList_;
+      //std::vector<Camera*> cams_;
+
+  };
+}
+
+#endif /* _Camera_Handler_H__ */
Index: code/branches/merge/src/orxonox/objects/Model.cc
===================================================================
--- code/branches/merge/src/orxonox/objects/Model.cc	(revision 1263)
+++ code/branches/merge/src/orxonox/objects/Model.cc	(revision 1264)
@@ -62,5 +62,5 @@
         XMLPortParamLoadOnly(Model, "mesh", setMesh, xmlelement, mode);
 
-        create();
+        Model::create();
     }
 
@@ -71,10 +71,11 @@
 
     bool Model::create(){
-      WorldEntity::create();
+      if(!WorldEntity::create())
+        return false;
       if ((this->meshSrc_ != "") && (this->meshSrc_.size() > 0))
       {
         this->mesh_.setMesh(meshSrc_);
         this->attachObject(this->mesh_.getEntity());
-        COUT(4) << "Loader: Created model" << std::endl;
+        COUT(4) << "Loader (Model.cc): Created model" << std::endl;
       }
       return true;
@@ -82,5 +83,6 @@
 
     void Model::registerAllVariables(){
-      WorldEntity::registerAllVariables();
+//       WorldEntity::registerAllVariables();
+      COUT(5) << "Model.cc:registering new meshsrc with size: " << meshSrc_.length()+1 << " this: " << this << std::endl;
       registerVar(&meshSrc_, meshSrc_.length() + 1, network::STRING);
     }
Index: code/branches/merge/src/orxonox/objects/NPC.cc
===================================================================
--- code/branches/merge/src/orxonox/objects/NPC.cc	(revision 1263)
+++ code/branches/merge/src/orxonox/objects/NPC.cc	(revision 1264)
@@ -40,4 +40,5 @@
   {
     RegisterObject(NPC);
+    registerAllVariables();
   }
 
@@ -59,4 +60,14 @@
     this->translate(location);
     movable_ = movable;
+  }
+  
+  void NPC::registerAllVariables(){
+    Model::registerAllVariables();
+    registerVar(&movable_, sizeof(movable_), network::DATA);
+  }
+  
+  bool NPC::create(){
+    Model::create();
+    return true;
   }
 
Index: code/branches/merge/src/orxonox/objects/NPC.h
===================================================================
--- code/branches/merge/src/orxonox/objects/NPC.h	(revision 1263)
+++ code/branches/merge/src/orxonox/objects/NPC.h	(revision 1264)
@@ -52,4 +52,6 @@
       void update();
       void setValues(Vector3 location, Vector3 speed, Vector3 acceleration, bool movable);
+      void registerAllVariables();
+      bool create();
 
     private:
Index: code/branches/merge/src/orxonox/objects/Skybox.cc
===================================================================
--- code/branches/merge/src/orxonox/objects/Skybox.cc	(revision 1263)
+++ code/branches/merge/src/orxonox/objects/Skybox.cc	(revision 1264)
@@ -47,4 +47,5 @@
     {
         RegisterObject(Skybox);
+        registerAllVariables();
     }
 
@@ -57,8 +58,8 @@
     	if (xmlElem->Attribute("src"))
     	{
-    		std::string skyboxSrc = xmlElem->Attribute("src");
-	    	this->setSkybox(skyboxSrc);
+    		skyboxSrc_ = xmlElem->Attribute("src");
+        this->create();
 
-	    	COUT(4) << "Loader: Set skybox: "<< skyboxSrc << std::endl << std::endl;
+	    	COUT(4) << "Loader: Set skybox: "<< skyboxSrc_ << std::endl << std::endl;
     	}
    }
@@ -69,4 +70,8 @@
    }
 
+   void Skybox::setSkyboxSrc(const std::string& src){
+     skyboxSrc_ = src;
+   }
+   
     /**
         @brief XML loading and saving.
@@ -79,5 +84,16 @@
         BaseObject::XMLPort(xmlelement, mode);
 
-        XMLPortParamLoadOnly(Skybox, "src", setSkybox, xmlelement, mode);
+        XMLPortParamLoadOnly(Skybox, "src", setSkyboxSrc, xmlelement, mode);
+        create();
     }
+    
+    bool Skybox::create(){
+      this->setSkybox(skyboxSrc_);
+      return true;
+    }
+    
+    void Skybox::registerAllVariables(){
+      registerVar(&skyboxSrc_, skyboxSrc_.length()+1 ,network::STRING);
+    }
+    
 }
Index: code/branches/merge/src/orxonox/objects/Skybox.h
===================================================================
--- code/branches/merge/src/orxonox/objects/Skybox.h	(revision 1263)
+++ code/branches/merge/src/orxonox/objects/Skybox.h	(revision 1264)
@@ -33,8 +33,9 @@
 
 #include "core/BaseObject.h"
+#include "network/Synchronisable.h"
 
 namespace orxonox
 {
-    class _OrxonoxExport Skybox : public BaseObject
+    class _OrxonoxExport Skybox : public BaseObject, public network::Synchronisable
     {
         public:
@@ -45,6 +46,11 @@
             virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
             void setSkybox(const std::string& skyboxname);
+            
+            bool create();
+            void registerAllVariables();
+            void setSkyboxSrc(const std::string &src);
 
         private:
+            std::string skyboxSrc_;
 
 
Index: code/branches/merge/src/orxonox/objects/SpaceShip.cc
===================================================================
--- code/branches/merge/src/orxonox/objects/SpaceShip.cc	(revision 1263)
+++ code/branches/merge/src/orxonox/objects/SpaceShip.cc	(revision 1264)
@@ -23,5 +23,5 @@
  *      Fabian 'x3n' Landau
  *   Co-authors:
- *      ...
+ *      Benjamin Knecht
  *
  */
@@ -37,4 +37,5 @@
 #include <OgreSceneNode.h>
 
+#include "CameraHandler.h"
 #include "tinyxml/tinyxml.h"
 #include "ois/OIS.h"
@@ -50,4 +51,5 @@
 #include "core/XMLPort.h"
 #include "core/ConsoleCommand.h"
+#include "network/Client.h"
 
 namespace orxonox
@@ -64,5 +66,10 @@
     SpaceShip::SpaceShip()
     {
+        RegisterObject(SpaceShip);
+        this->registerAllVariables();
+
         SpaceShip::instance_s = this;
+
+        this->setConfigValues();
 
         this->setMouseEventCallback_ = false;
@@ -73,4 +80,5 @@
 
         this->camNode_ = 0;
+        this->camName_ = "camNode";
 
         this->tt_ = 0;
@@ -96,45 +104,7 @@
         this->setRotationAxis(1, 0, 0);
         this->setStatic(false);
-/*
-        this->moveForward_ = 0;
-        this->rotateUp_ = 0;
-        this->rotateDown_ = 0;
-        this->rotateRight_ = 0;
-        this->rotateLeft_ = 0;
-        this->loopRight_ = 0;
-        this->loopLeft_ = 0;
-        this->brakeForward_ = 0;
-        this->brakeRotate_ = 0;
-        this->brakeLoop_ = 0;
-        this->speedForward_ = 0;
-        this->speedRotateUpDown_ = 0;
-        this->speedRotateRightLeft_ = 0;
-        this->speedLoopRightLeft_ = 0;
-        this->maxSpeedForward_ = 0;
-        this->maxSpeedRotateUpDown_ = 0;
-        this->maxSpeedRotateRightLeft_ = 0;
-        this->maxSpeedLoopRightLeft_ = 0;
-        this->accelerationForward_ = 0;
-        this->accelerationRotateUpDown_ = 0;
-        this->accelerationRotateRightLeft_ = 0;
-        this->accelerationLoopRightLeft_ = 0;
-
-        this->speed = 250;
-        this->loop = 100;
-        this->rotate = 10;
-        this->mouseX = 0;
-        this->mouseY = 0;
-        this->maxMouseX = 0;
-        this->minMouseX = 0;
-        this->moved = false;
-
-        this->brakeRotate(rotate*10);
-        this->brakeLoop(loop);
-*/
-//         this->create();
-
-        RegisterObject(SpaceShip);
-        this->registerAllVariables();
-        this->setConfigValues();
+
+        server_=false;
+
 
         COUT(3) << "Info: SpaceShip was loaded" << std::endl;
@@ -156,7 +126,14 @@
 
     void SpaceShip::registerAllVariables(){
-      Model::registerAllVariables();
-
-
+      registerVar( &camName_, camName_.length()+1, network::STRING, 0x1);
+      registerVar( &maxSpeed_, sizeof(maxSpeed_), network::DATA, 0x1);
+      registerVar( &maxSideAndBackSpeed_, sizeof(maxSideAndBackSpeed_), network::DATA, 0x1);
+      registerVar( &maxRotation_, sizeof(maxRotation_), network::DATA, 0x1);
+      registerVar( &translationAcceleration_, sizeof(translationAcceleration_), network::DATA, 0x1);
+      registerVar( &rotationAcceleration_, sizeof(rotationAcceleration_), network::DATA, 0x1);
+      registerVar( &rotationAccelerationRadian_, sizeof(rotationAccelerationRadian_), network::DATA, 0x1);
+      registerVar( &translationDamping_, sizeof(translationDamping_), network::DATA, 0x1);
+      registerVar( &rotationDamping_, sizeof(rotationDamping_), network::DATA, 0x1);
+      registerVar( &rotationDampingRadian_, sizeof(rotationDampingRadian_), network::DATA, 0x1);
 
     }
@@ -164,9 +141,12 @@
     void SpaceShip::init()
     {
-        if (!setMouseEventCallback_)
-        {
-          InputManager::addMouseHandler(this, "SpaceShip");
-          setMouseEventCallback_ = true;
-        }
+		if ((!network::Client::getSingleton() || network::Client::getSingleton()->getShipID()==objectID ))
+		{
+        	if (!setMouseEventCallback_)
+        	{
+          		InputManager::addMouseHandler(this, "SpaceShip");
+          		setMouseEventCallback_ = true;
+        	}
+		}
 
         // START CREATING THRUSTER
@@ -222,4 +202,5 @@
         this->chFarNode_->setScale(0.4, 0.4, 0.4);
 
+        createCamera();
         // END of testing crosshair
     }
@@ -236,4 +217,5 @@
         Model::loadParams(xmlElem);
         this->create();
+        this->getFocus();
 /*
         if (xmlElem->Attribute("forward") && xmlElem->Attribute("rotateupdown") && xmlElem->Attribute("rotaterightleft") && xmlElem->Attribute("looprightleft"))
@@ -286,6 +268,21 @@
     void SpaceShip::setCamera(const std::string& camera)
     {
-        Ogre::Camera *cam = GraphicsEngine::getSingleton().getSceneManager()->createCamera("ShipCam");
-        this->camNode_ = this->getNode()->createChildSceneNode("CamNode");
+      camName_=camera;
+      // change camera attributes here, if you want to ;)
+    }
+    
+    void SpaceShip::getFocus(){
+      COUT(4) << "requesting focus" << std::endl;
+      if(network::Client::getSingleton()==0 || network::Client::getSingleton()->getShipID()==objectID)
+        CameraHandler::getInstance()->requestFocus(cam_);
+      
+    }
+    
+    void SpaceShip::createCamera(){
+//       COUT(4) << "begin camera creation" << std::endl;
+      this->camNode_ = this->getNode()->createChildSceneNode(camName_);
+      COUT(4) << "position: (this)" << this->getNode()->getPosition() << std::endl;
+      this->camNode_->setPosition(/*this->getNode()->getPosition() +*/ Vector3(-50,0,10));
+      COUT(4) << "position: (cam)" << this->camNode_->getPosition() << std::endl;
 /*
 //        node->setInheritOrientation(false);
@@ -293,13 +290,14 @@
         cam->lookAt(Vector3(0,20,0));
         cam->roll(Degree(0));
-*/
-
-        cam->setPosition(Vector3(-200,0,35));
+      *//*COUT(4) << "creating new camera" << std::endl;*/
+      cam_ = new Camera(this->camNode_);
+
+      cam_->setTargetNode(this->getNode());
 //        cam->setPosition(Vector3(0,-350,0));
-        cam->lookAt(Vector3(0,0,35));
-        cam->roll(Degree(-90));
-
-        this->camNode_->attachObject(cam);
-        GraphicsEngine::getSingleton().getRenderWindow()->addViewport(cam);
+      if(network::Client::getSingleton()!=0 && network::Client::getSingleton()->getShipID()==objectID){
+        this->setBacksync(true);
+        CameraHandler::getInstance()->requestFocus(cam_);
+      }
+
     }
 
@@ -337,4 +335,7 @@
         XMLPortParamLoadOnly(SpaceShip, "transDamp", setTransDamp, xmlelement, mode);
         XMLPortParamLoadOnly(SpaceShip, "rotDamp", setRotDamp, xmlelement, mode);
+        server_=true; // TODO: this is only a hack
+        SpaceShip::create();
+        getFocus();
     }
 
@@ -448,5 +449,6 @@
         if (this->bLMousePressed_ && this->timeToReload_ <= 0)
         {
-            new Projectile(this);
+            Projectile *p = new Projectile(this);
+            p->setBacksync(true);
             this->timeToReload_ = this->reloadTime_;
         }
@@ -520,24 +522,28 @@
         }
 
-        if (mKeyboard->isKeyDown(OIS::KC_UP) || mKeyboard->isKeyDown(OIS::KC_W))
+        if( (network::Client::getSingleton() &&  network::Client::getSingleton()->getShipID() == objectID) || server_ ){
+          COUT(4) << "steering our ship: " << objectID << " mkeyboard: " << mKeyboard << std::endl;
+          if (mKeyboard->isKeyDown(OIS::KC_UP) || mKeyboard->isKeyDown(OIS::KC_W))
             this->acceleration_.x = this->translationAcceleration_;
-        else if(mKeyboard->isKeyDown(OIS::KC_DOWN) || mKeyboard->isKeyDown(OIS::KC_S))
+          else if(mKeyboard->isKeyDown(OIS::KC_DOWN) || mKeyboard->isKeyDown(OIS::KC_S))
             this->acceleration_.x = -this->translationAcceleration_;
-        else
+          else
             this->acceleration_.x = 0;
 
-        if (mKeyboard->isKeyDown(OIS::KC_RIGHT) || mKeyboard->isKeyDown(OIS::KC_D))
+          if (mKeyboard->isKeyDown(OIS::KC_RIGHT) || mKeyboard->isKeyDown(OIS::KC_D))
             this->acceleration_.y = -this->translationAcceleration_;
-        else if (mKeyboard->isKeyDown(OIS::KC_LEFT) || mKeyboard->isKeyDown(OIS::KC_A))
+          else if (mKeyboard->isKeyDown(OIS::KC_LEFT) || mKeyboard->isKeyDown(OIS::KC_A))
             this->acceleration_.y = this->translationAcceleration_;
-        else
+          else
             this->acceleration_.y = 0;
 
-        if (mKeyboard->isKeyDown(OIS::KC_DELETE) || mKeyboard->isKeyDown(OIS::KC_Q))
+          if (mKeyboard->isKeyDown(OIS::KC_DELETE) || mKeyboard->isKeyDown(OIS::KC_Q))
             this->momentum_ = Radian(-this->rotationAccelerationRadian_);
-        else if (mKeyboard->isKeyDown(OIS::KC_PGDOWN) || mKeyboard->isKeyDown(OIS::KC_E))
+          else if (mKeyboard->isKeyDown(OIS::KC_PGDOWN) || mKeyboard->isKeyDown(OIS::KC_E))
             this->momentum_ = Radian(this->rotationAccelerationRadian_);
-        else
+          else
             this->momentum_ = 0;
+        }/*else
+          COUT(4) << "not steering ship: " << objectID << " our ship: " << network::Client::getSingleton()->getShipID() << std::endl;*/
 
         WorldEntity::tick(dt);
Index: code/branches/merge/src/orxonox/objects/SpaceShip.h
===================================================================
--- code/branches/merge/src/orxonox/objects/SpaceShip.h	(revision 1263)
+++ code/branches/merge/src/orxonox/objects/SpaceShip.h	(revision 1264)
@@ -23,5 +23,5 @@
  *      Fabian 'x3n' Landau
  *   Co-authors:
- *      ...
+ *      Benjamin Knecht
  *
  */
@@ -35,4 +35,5 @@
 
 #include "core/InputHandler.h"
+#include "Camera.h"
 #include "Model.h"
 #include "../tools/BillboardSet.h"
@@ -62,4 +63,6 @@
             void setRotDamp(float value);
 
+            void getFocus();
+
             static void setMaxSpeedTest(float value)
                 { SpaceShip::instance_s->setMaxSpeed(value); }
@@ -72,4 +75,5 @@
 
         private:
+            void createCamera();
             static SpaceShip* instance_s;
 
@@ -81,4 +85,7 @@
 
             Ogre::SceneNode* camNode_;
+            Camera* cam_;  
+            std::string camName_;
+
 
             ParticleInterface* tt_;
@@ -117,4 +124,5 @@
 
             float emitterRate_;
+            bool server_;
     };
 }
Index: code/branches/merge/src/orxonox/objects/WorldEntity.cc
===================================================================
--- code/branches/merge/src/orxonox/objects/WorldEntity.cc	(revision 1263)
+++ code/branches/merge/src/orxonox/objects/WorldEntity.cc	(revision 1264)
@@ -66,7 +66,11 @@
         }
     }
+    
 
     WorldEntity::~WorldEntity()
     {
+      // just to make sure we clean out all scene nodes
+      if(this->getNode())
+        this->getNode()->removeAndDestroyAllChildren();
     }
 
@@ -75,4 +79,5 @@
         if (!this->bStatic_)
         {
+//             COUT(4) << "acceleration: " << this->acceleration_ << " velocity: " << this->velocity_ << std::endl;
             this->velocity_ += (dt * this->acceleration_);
             this->translate(dt * this->velocity_, Ogre::Node::TS_LOCAL);
@@ -89,4 +94,5 @@
         create();
     }
+    
 
     void WorldEntity::setYawPitchRoll(const Degree& yaw, const Degree& pitch, const Degree& roll)
@@ -115,4 +121,6 @@
 
         XMLPortObject(WorldEntity, WorldEntity, "attached", attachWorldEntity, getAttachedWorldEntity, xmlelement, mode, false, true);
+        
+        WorldEntity::create();
     }
 
@@ -121,22 +129,32 @@
     {
       // register coordinates
-      registerVar( (void*) &(this->getPosition().x), sizeof(this->getPosition().x), network::DATA);
-      registerVar( (void*) &(this->getPosition().y), sizeof(this->getPosition().y), network::DATA);
-      registerVar( (void*) &(this->getPosition().z), sizeof(this->getPosition().z), network::DATA);
+      registerVar( (void*) &(this->getPosition().x), sizeof(this->getPosition().x), network::DATA, 0x3);
+      registerVar( (void*) &(this->getPosition().y), sizeof(this->getPosition().y), network::DATA, 0x3);
+      registerVar( (void*) &(this->getPosition().z), sizeof(this->getPosition().z), network::DATA, 0x3);
       // register orientation
-      registerVar( (void*) &(this->getOrientation().w), sizeof(this->getOrientation().w), network::DATA);
-      registerVar( (void*) &(this->getOrientation().x), sizeof(this->getOrientation().x), network::DATA);
-      registerVar( (void*) &(this->getOrientation().y), sizeof(this->getOrientation().y), network::DATA);
-      registerVar( (void*) &(this->getOrientation().z), sizeof(this->getOrientation().z), network::DATA);
-      // not needed at the moment, because we don't have prediction yet
+      registerVar( (void*) &(this->getOrientation().w), sizeof(this->getOrientation().w), network::DATA, 0x3);
+      registerVar( (void*) &(this->getOrientation().x), sizeof(this->getOrientation().x), network::DATA, 0x3);
+      registerVar( (void*) &(this->getOrientation().y), sizeof(this->getOrientation().y), network::DATA, 0x3);
+      registerVar( (void*) &(this->getOrientation().z), sizeof(this->getOrientation().z), network::DATA, 0x3);
       // register velocity_
-      registerVar( (void*) &(this->getVelocity().x), sizeof(this->getVelocity().x), network::DATA);
-      registerVar( (void*) &(this->getVelocity().y), sizeof(this->getVelocity().y), network::DATA);
-      registerVar( (void*) &(this->getVelocity().z), sizeof(this->getVelocity().z), network::DATA);
-      // register rotationAxis/rate
-      registerVar( (void*) &(this->getRotationRate()), sizeof(this->getRotationRate()), network::DATA);
-      registerVar( (void*) &(this->getRotationAxis().x), sizeof(this->getRotationAxis().x), network::DATA);
-      registerVar( (void*) &(this->getRotationAxis().y), sizeof(this->getRotationAxis().y), network::DATA);
-      registerVar( (void*) &(this->getRotationAxis().z), sizeof(this->getRotationAxis().z), network::DATA);
+//       registerVar( (void*) &(this->getVelocity().x), sizeof(this->getVelocity().x), network::DATA, 0x3);
+//       registerVar( (void*) &(this->getVelocity().y), sizeof(this->getVelocity().y), network::DATA, 0x3);
+//       registerVar( (void*) &(this->getVelocity().z), sizeof(this->getVelocity().z), network::DATA, 0x3);
+//       // register rotationAxis/rate
+//       registerVar( (void*) &(this->getRotationRate()), sizeof(this->getRotationRate()), network::DATA, 0x3);
+//       registerVar( (void*) &(this->getRotationAxis().x), sizeof(this->getRotationAxis().x), network::DATA, 0x3);
+//       registerVar( (void*) &(this->getRotationAxis().y), sizeof(this->getRotationAxis().y), network::DATA, 0x3);
+//       registerVar( (void*) &(this->getRotationAxis().z), sizeof(this->getRotationAxis().z), network::DATA, 0x3);
+      // register scale of node
+      registerVar( (void*) &(this->getScale().x), sizeof(this->getScale().x), network::DATA, 0x3);
+      registerVar( (void*) &(this->getScale().y), sizeof(this->getScale().y), network::DATA, 0x3);
+      registerVar( (void*) &(this->getScale().z), sizeof(this->getScale().z), network::DATA, 0x3);
+      //register staticity
+      registerVar( (void*) &(this->bStatic_), sizeof(this->bStatic_), network::DATA, 0x3);
+      //register acceleration
+      // register velocity_
+//       registerVar( (void*) &(this->getAcceleration().x), sizeof(this->getAcceleration().x), network::DATA, 0x3);
+//       registerVar( (void*) &(this->getAcceleration().y), sizeof(this->getAcceleration().y), network::DATA, 0x3);
+//       registerVar( (void*) &(this->getAcceleration().z), sizeof(this->getAcceleration().z), network::DATA, 0x3);
     }
 
Index: code/branches/merge/src/orxonox/particle/ParticleInterface.cc
===================================================================
--- code/branches/merge/src/orxonox/particle/ParticleInterface.cc	(revision 1263)
+++ code/branches/merge/src/orxonox/particle/ParticleInterface.cc	(revision 1264)
@@ -63,4 +63,6 @@
   ParticleInterface::~ParticleInterface(void)
   {
+    while(particleSystem_->getNumEmitters()>0)
+      particleSystem_->removeEmitter(particleSystem_->getNumEmitters()-1);
     sceneManager_->destroyParticleSystem(particleSystem_);
   }
