Index: code/branches/network2/CMakeLists.txt
===================================================================
--- code/branches/network2/CMakeLists.txt	(revision 1097)
+++ code/branches/network2/CMakeLists.txt	(revision 1098)
@@ -36,6 +36,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/network2/TODO
===================================================================
--- code/branches/network2/TODO	(revision 1098)
+++ code/branches/network2/TODO	(revision 1098)
@@ -0,0 +1,9 @@
+TODO:
+
+network:
+	-important: fix that fucking bug with stl-list (Synchronisable.cc)
+	-handle variables of Spaceship (registerAllVariables) ------ wait for spaceship to be cleaned up
+	-make NPC class synchronisable ----- hopefully done
+	-make Ambient class synchronisable ----- hopefully done
+	-make Skybox class synchronisable ----- mostly done
+	
Index: code/branches/network2/bin/levels/sample.oxw
===================================================================
--- code/branches/network2/bin/levels/sample.oxw	(revision 1097)
+++ code/branches/network2/bin/levels/sample.oxw	(revision 1098)
@@ -9,14 +9,14 @@
   </audio--> 
 
-<Ambient colourvalue="1,1,1" />
-<Skybox src="Orxonox/StarSkyBox" />
+<!--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" />
 
-<NPC position="0,100,400" scale="1" mesh="razor.mesh"/>
+<!--NPC position="0,100,400" scale="1" mesh="razor.mesh"/>
 <NPC position="0,100,400" scale="1" mesh="razor.mesh"/>
 <NPC position="0,-100,500" scale="1" mesh="razor.mesh"/>
 <NPC position="0,-200,450" scale="1" mesh="razor.mesh"/>
-<NPC position="100,0,400" scale="1" mesh="razor.mesh"/>
+<NPC position="100,0,400" scale="1" mesh="razor.mesh"/-->
 
 <!--Model name="starship" position="200,0,500" scale="10" mesh="starship.mesh" yawpitchroll="-90,-90,0" />
@@ -31,9 +31,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/network2/src/network/CMakeLists.txt
===================================================================
--- code/branches/network2/src/network/CMakeLists.txt	(revision 1097)
+++ code/branches/network2/src/network/CMakeLists.txt	(revision 1098)
@@ -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/network2/src/network/Client.cc
===================================================================
--- code/branches/network2/src/network/Client.cc	(revision 1097)
+++ code/branches/network2/src/network/Client.cc	(revision 1098)
@@ -205,5 +205,5 @@
     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;
     return;
   }
Index: code/branches/network2/src/network/ClientConnection.cc
===================================================================
--- code/branches/network2/src/network/ClientConnection.cc	(revision 1097)
+++ code/branches/network2/src/network/ClientConnection.cc	(revision 1098)
@@ -87,5 +87,5 @@
 
   ENetPacket *ClientConnection::getPacket() {
-    ENetAddress address;
+    ENetAddress address; //sems that address is not needed
     return getPacket(address);
   }
@@ -162,6 +162,6 @@
       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;
         break;
       case ENET_EVENT_TYPE_DISCONNECT:
@@ -203,5 +203,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 +218,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/network2/src/network/ClientInformation.cc
===================================================================
--- code/branches/network2/src/network/ClientInformation.cc	(revision 1097)
+++ code/branches/network2/src/network/ClientInformation.cc	(revision 1098)
@@ -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/network2/src/network/ClientInformation.h
===================================================================
--- code/branches/network2/src/network/ClientInformation.h	(revision 1097)
+++ code/branches/network2/src/network/ClientInformation.h	(revision 1098)
@@ -75,5 +75,7 @@
     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);
 
Index: code/branches/network2/src/network/ConnectionManager.cc
===================================================================
--- code/branches/network2/src/network/ConnectionManager.cc	(revision 1097)
+++ code/branches/network2/src/network/ConnectionManager.cc	(revision 1098)
@@ -60,5 +60,7 @@
 {
   boost::thread_group network_threads;
-
+  
+  ConnectionManager::ConnectionManager(){}
+  
   ConnectionManager::ConnectionManager(ClientInformation *head) {
     quit=false;
@@ -88,5 +90,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;
@@ -174,7 +179,9 @@
         case ENET_EVENT_TYPE_CONNECT:
           addClient(&event);
+          COUT(5) << "Con.Man: connection event has occured" << std::endl;
           break;
         case ENET_EVENT_TYPE_RECEIVE:
           //std::cout << "received data" << std::endl;
+          COUT(5) << "Con.Man: receive event has occured" << std::endl;
           processData(&event);
           break;
@@ -191,5 +198,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 +209,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;
@@ -229,15 +242,22 @@
 
   bool ConnectionManager::clientDisconnect(ENetPeer *peer) {
+    COUT(4) << "removing client from list" << std::endl;
     return head_->removeClient(peer);
   }
-
+/**
+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;
+    COUT(4) << "Con.Man: added client id: " << temp->getID() << std::endl;
     syncClassid(temp->getID());
     temp->setSynched(true);
@@ -268,5 +288,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,4 +295,5 @@
     }
     sendPackets();
+    COUT(4) << "syncClassid:\tall synchClassID packets have been sent" << std::endl;
   }
 
@@ -289,6 +310,6 @@
 
   int ConnectionManager::getObjectsClientID( int objectID ) {
-    std::map<int, int>::iterator iter = clientsShip.begin();
-    while( iter != clientsShip.end() ) {
+    std::map<int, int>::iterator iter;
+    for( iter = clientsShip.begin(); iter != clientsShip.end(); iter++ ) {
       if( iter->second == objectID ) return iter->first;
     }
@@ -302,9 +323,11 @@
   void ConnectionManager::deleteObjectIDReg( int objectID ) {
     std::map<int, int>::iterator iter = clientsShip.begin();
-    while( iter != clientsShip.end() ) {
+    for( iter = clientsShip.begin(); iter != clientsShip.end(); iter++ ) {
       if( iter->second == objectID ) break;
     }
     clientsShip.erase( iter->first );
   }
-
+  int ConnectionManager::getNumberOfClients() {
+    return clientsShip.size();
+  }
 }
Index: code/branches/network2/src/network/ConnectionManager.h
===================================================================
--- code/branches/network2/src/network/ConnectionManager.h	(revision 1097)
+++ code/branches/network2/src/network/ConnectionManager.h	(revision 1098)
@@ -84,4 +84,26 @@
     bool sendPackets(ENetEvent *event);
     bool sendPackets();
+
+    //##### for testing purpose only #####
+    ConnectionManager();
+    std::map<int, int> testGetClientsShip() { 
+      return clientsShip; 
+    }
+    void testAddClientsShipID( int clientID, int objectID ) {
+      addClientsObjectID( clientID, objectID );
+    }
+    int testGetClientsShipID( int clientID ) { 
+      return getClientsShipID( clientID ); 
+    }
+    int testGetObjectsClientID( int objectID ) {
+       return getObjectsClientID( objectID );
+    }
+    void testDeleteClientsIDReg( int clientID ) { 
+      deleteClientIDReg( clientID );
+    }
+    void testDeleteObjectIDReg( int objectID ) {
+      deleteObjectIDReg( objectID );
+    }
+    //##### for testing purpose only #####
   private:
     bool clientDisconnect(ENetPeer *peer);
@@ -111,12 +133,6 @@
     void deleteClientIDReg( int clientID );
     void deleteObjectIDReg( int objectID );
+    int getNumberOfClients();
   };
-
-
-
-
-
-
-
 
 }
Index: code/branches/network2/src/network/GameStateClient.cc
===================================================================
--- code/branches/network2/src/network/GameStateClient.cc	(revision 1097)
+++ code/branches/network2/src/network/GameStateClient.cc	(revision 1098)
@@ -32,9 +32,16 @@
 
 #include "core/CoreIncludes.h"
+#include "core/BaseObject.h"
 #include "Synchronisable.h"
 
 namespace network
 {
+  struct GameStateItem{
+    GameState *state;
+    int id;
+  };
+  
   GameStateClient::GameStateClient() {
+    COUT(5) << "this: " << this << std::endl;
   }
 
@@ -44,6 +51,18 @@
   bool GameStateClient::pushGameState(GameStateCompressed *compstate) {
     GameState *gs;
-    if(compstate->diffed)
-      gs = decode(reference, compstate);
+    if(compstate->diffed){
+      while(compstate->base_id > gameStateList.front()->id){
+        // clean up old gamestates
+        free(gameStateList.front()->data);
+        // TODO: critical section
+        delete gameStateList.front();
+        gameStateList.pop();
+      }
+      if(compstate->base_id!=gameStateList.front()->id){
+        COUT(4) << "pushGameState: no reference found to diff" << std::endl;
+        return false;
+      }
+      gs = decode(gameStateList.front(), compstate);
+    }
     else
       gs = decode(compstate);
@@ -95,13 +114,14 @@
 
         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;
+          Synchronisable *no = dynamic_cast<Synchronisable *>(ID((unsigned int) sync.classID)->fabricate());
           no->objectID=sync.objectID;
           no->classID=sync.classID;
           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;
+          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 {
@@ -154,5 +174,16 @@
   }
 
+  //##### 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 #####
+
   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;
@@ -173,5 +204,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;
     }
 
@@ -189,10 +220,19 @@
 
   GameState *GameStateClient::decode(GameState *a, GameStateCompressed *x) {
-    GameState *t = decompress(x);
-    return undiff(a, t);
+    GameState *t = decode(x);
+    gameStateList.push(t);
+    //return undiff(a, t);
+    return t;
   }
 
   GameState *GameStateClient::decode(GameStateCompressed *x) {
-    GameState *t = decompress(x);
+    //GameState *t = decompress(x);
+    GameState *t = new GameState;
+    t->base_id = x->base_id;
+    t->id = x->id;
+    t->diffed = x->diffed;
+    t->data = x->data;
+    t->size = x->normsize;
+    gameStateList.push(t);
     return t;
   }
Index: code/branches/network2/src/network/GameStateClient.h
===================================================================
--- code/branches/network2/src/network/GameStateClient.h	(revision 1097)
+++ code/branches/network2/src/network/GameStateClient.h	(revision 1098)
@@ -41,7 +41,9 @@
 #define _GameStateClient_H__
 
+#include <queue>
+
 #include "NetworkPrereqs.h"
 #include "core/CorePrereqs.h"
-#include "GameStateManager.h"
+#include "PacketTypes.h"
 
 namespace network
@@ -52,4 +54,8 @@
     GameStateClient();
     ~GameStateClient();
+    //#### ADDED FOR TESTING PURPOSE ####
+    GameState* testDecompress( GameStateCompressed* gc );
+    GameState* testUndiff( GameState* g_old, GameState* g_diffed );
+    //#### END TESTING PURPOSE ####
     bool pushGameState(GameStateCompressed *compstate);
   private:
@@ -61,5 +67,6 @@
     void removeObject(orxonox::Iterator<Synchronisable> &it);
 
-    GameState *reference;
+    GameState     *reference;
+    std::queue<GameState *> gameStateList;
   };
 
Index: code/branches/network2/src/network/GameStateManager.cc
===================================================================
--- code/branches/network2/src/network/GameStateManager.cc	(revision 1097)
+++ code/branches/network2/src/network/GameStateManager.cc	(revision 1098)
@@ -60,4 +60,5 @@
 
   void GameStateManager::update(){
+    cleanup();
     reference = getSnapshot(id);
     gameStateMap.insert(std::pair<int, GameState*>(id, reference));
@@ -66,9 +67,33 @@
     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( (*it).second <= 0 ){
+        free(gameStateMap[(*it).first]->data);
+        delete gameStateMap[(*it).first];
+        gameStateMap.erase((*it).first);
+        gameStateUsed.erase(it++);
+      }else  //as soon as we got a used gamestate break here because we could use newer gamestates in future
+        break;
+    }
+  }
 
   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){
+    COUT(4) << "G.St.Man: popgamestate: sending gstate_id: " << id << " diffed from: " << gID << " (not diffed yet)" << std::endl;
+    
+    //chose wheather the next gamestate is the first or not
+    if(gID != GAMESTATEID_INITIAL){
       GameState *client = gameStateMap[gID];
       GameState *server = reference;
@@ -90,4 +115,5 @@
   GameState *GameStateManager::getSnapshot(int id)
   {
+    //std::cout << "begin getSnapshot" << std::endl;
     //the size of the gamestate
     int totalsize=0;
@@ -102,9 +128,9 @@
     GameState *retval=new GameState; //return value
     retval->id=id++;
-    COUT(4) << "producing gamestate with id: " << retval->id << std::endl;
+    COUT(4) << "G.ST.Man: producing gamestate with id: " << retval->id << std::endl;
     // reserve a little memory and increase it later on
-    COUT(5) << "mallocing" << std::endl;
+    COUT(5) << "G.ST.Man: mallocing: " << memsize << std::endl;
     retval->data = (unsigned char*)malloc(memsize);
-    COUT(5) << "malloced" << std::endl;
+    COUT(5) << "G.ST.Man: malloced: " << memsize << std::endl;
 
     // offset of memory functions
@@ -112,15 +138,19 @@
     // go through all Synchronisables
     for(it = orxonox::ObjectList<Synchronisable>::start(); it; ++it){
+      //std::cout << "begin inner loop" << std::endl;
       //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(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;
+      //COUT(5) << "G.St.Man: current totalsize=" << totalsize << std::endl;
+      //COUT(5) << "G.St.Man: current it->classID=" << it->classID << " it->objectID=" << it->objectID << std::endl;
       // allocate additional space
-      if(totalsize+tempsize>memsize){
-        if(tempsize<1000){
+      if((totalsize+tempsize) > memsize){
+        COUT(5) << "G.St.Man: need additional memory" << std::endl;
+        if(tempsize < 1000){
           retval->data = (unsigned char *)realloc((void *)retval->data, totalsize+1000);
           memsize+=1000;
@@ -129,30 +159,65 @@
           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));
+      //*(retval->data+offset)=sync.length;
+      memcpy(retval->data+offset+sizeof(int), (void *)&sync.objectID, sizeof(int));
+      //*(retval->data+offset+sizeof(int))=sync.objectID;
+      memcpy(retval->data+offset+2*sizeof(int), (void *)&sync.classID, sizeof(int));
+      //*(retval->data+offset+2*sizeof(int))=sync.classID;
       // increase data pointer
       offset+=tempsize+3*sizeof(int);
-    }
-    COUT(5) << "Gamestate size: " << totalsize << std::endl;
+      //std::cout << "end inner loop" << std::endl;
+    }
     retval->size=totalsize;
+    //#### bugfix
+    retval->diffed = false;
+    //std::cout << "end snapShot" << std::endl;
+    COUT(5) << "G.ST.Man: Gamestate size: " << totalsize << std::endl;
     return retval;
   }
 
+  //##### ADDED FOR TESTING PURPOSE #####
+  GameStateCompressed* GameStateManager::testCompress( GameState* g ) {
+    return compress_( g );
+  }
+
+  GameState* GameStateManager::testDiff( GameState* a, GameState* b ) {
+    return diff( a, b );
+  }
+  //##### END TESTING PURPOSE #####
+
   GameStateCompressed *GameStateManager::encode(GameState *a, GameState *b) {
+    COUT(5) << "G.St.Man: this will be a DIFFED gamestate" << std::endl;
     //GameState r = diff(a,b);
     //r.diffed = true;
     GameState *r = b;
     r->diffed = false;
-    return compress_(r);
+    //return compress_(r);
+    GameStateCompressed *g = new GameStateCompressed;
+    g->base_id = b->base_id;
+    g->id = b->id;
+    g->diffed = b->diffed;
+    g->data = b->data;
+    g->normsize = b->size;
+    g->compsize = b->size;
+    return g;
   }
 
   GameStateCompressed *GameStateManager::encode(GameState *a) {
+    COUT(5) << "G.St.Man: this will be a not diffed gamestate" << std::endl;
     a->diffed=false;
-    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;
   }
 
@@ -189,4 +254,5 @@
     r->size = dest_length;
     r->diffed = true;
+    r->base_id = a->id;
     r->data = dp;
     return r;
@@ -194,20 +260,26 @@
 
   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;
+    //COUT(4) << "size: " << size << ", buffer: " << buffer << std::endl;
     unsigned char* dest = (unsigned char*)malloc( 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,5 +293,6 @@
     compressedGamestate->data = dest;
     compressedGamestate->diffed = a->diffed;
-
+    compressedGamestate->base_id = a->base_id;
+    //COUT(5) << "G.St.Man: saved compressed data in GameStateCompressed:" << std::endl;
     return compressedGamestate;
   }
Index: code/branches/network2/src/network/GameStateManager.h
===================================================================
--- code/branches/network2/src/network/GameStateManager.h	(revision 1097)
+++ code/branches/network2/src/network/GameStateManager.h	(revision 1098)
@@ -71,4 +71,8 @@
     GameStateManager(ClientInformation *head);
     ~GameStateManager();
+    //#### ADDED FOR TESTING PURPOSE ####
+    GameStateCompressed* testCompress( GameState* g );
+    GameState* testDiff( GameState* a, GameState* b );
+    //#### END TESTING PURPOSE ####
     void update();
     GameStateCompressed *popGameState(int clientID);
@@ -76,4 +80,5 @@
     int id;
   private:
+    void cleanup(); // "garbage handler"
     GameState *getSnapshot(int id);
     GameStateCompressed *encode(GameState *a, GameState *b);
Index: code/branches/network2/src/network/PacketBuffer.cc
===================================================================
--- code/branches/network2/src/network/PacketBuffer.cc	(revision 1097)
+++ code/branches/network2/src/network/PacketBuffer.cc	(revision 1098)
@@ -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/network2/src/network/PacketDecoder.cc
===================================================================
--- code/branches/network2/src/network/PacketDecoder.cc	(revision 1097)
+++ code/branches/network2/src/network/PacketDecoder.cc	(revision 1098)
@@ -54,8 +54,13 @@
   {
     int client = clientId;
-    COUT(5) << "clientId: " << client << std::endl; //control cout, not important, just debugging info
+    COUT(5) << "PacketDecoder: clientId: " << client << 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:
@@ -95,5 +100,5 @@
 
 
-    COUT(5) << "got ack id: " << a->id << std::endl;
+    COUT(5) << "PacketDecoder: got ack id: " << a->id << std::endl;
     processAck( a, clientId ); //debug info
 
@@ -149,5 +154,5 @@
     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;
     }
@@ -159,5 +164,5 @@
     //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;
+    COUT(5) << "PacketDecoder: received gs id: " << currentState->id << std::endl;
 //     std::cout << "id: " << currentState->id << std::endl;
     //copy the size of the GameStateCompressed compressed data into the new GameStateCompressed struct, located at 3th
@@ -168,16 +173,17 @@
     //size of uncompressed data
     memcpy( (void*)&(currentState->normsize), (const void*)(packet->data+3*sizeof( int )), sizeof( int ) );
+    memcpy( (void*)&(currentState->base_id), (const void*)(packet->data+4*sizeof( int )), sizeof( int ) );
     //currentState->normsize = (int)*(data+3*sizeof(int));
 //     std::cout << "normsize. " << currentState->normsize << std::endl;
     //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));
+    memcpy( (void*)&(currentState->diffed), (const void*)(packet->data+5*sizeof(int)), sizeof(bool));
     //currentState->diffed = (bool)*(data+4*sizeof(int));
 //     std::cout << "diffed: " << currentState->diffed << std::endl;
     //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;
+      COUT(2) << "PacketDecoder: compsize is 0" << std::endl;
     currentState->data = (unsigned char*)(malloc( 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;
@@ -199,5 +205,5 @@
     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);
@@ -214,4 +220,6 @@
   void PacketDecoder::processGamestate( GameStateCompressed *state )
   {
+    COUT(5) << "PacketDecoder: processing Gamestate" << std::endl;
+    //printGamestate( state );
   }
 
Index: code/branches/network2/src/network/PacketGenerator.cc
===================================================================
--- code/branches/network2/src/network/PacketGenerator.cc	(revision 1097)
+++ code/branches/network2/src/network/PacketGenerator.cc	(revision 1098)
@@ -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;
@@ -65,5 +65,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;
@@ -79,5 +79,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;
@@ -115,15 +115,8 @@
     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->data, states->compsize );
     //create an enet packet with the generated bytestream
     ENetPacket *packet = enet_packet_create( data , totalLen, reliable );
@@ -135,5 +128,5 @@
   {
     unsigned char* data = (unsigned char *)malloc(3*sizeof(int)+classname.length()+1);
-    std::cout << "classid: " << classid << ", name: " << classname << std::endl;
+    std::cout << "PacketGenerator: classid: " << classid << ", name: " << classname << std::endl;
     *(int *)data = CLASSID;
     *((int *)data+1) = classname.length()+1;
Index: code/branches/network2/src/network/PacketTypes.h
===================================================================
--- code/branches/network2/src/network/PacketTypes.h	(revision 1097)
+++ code/branches/network2/src/network/PacketTypes.h	(revision 1098)
@@ -65,4 +65,5 @@
     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;
     unsigned char *data;            //!< pointer to data
@@ -80,4 +81,5 @@
     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;
     unsigned char *data;            //!< gamestate data
Index: code/branches/network2/src/network/Server.cc
===================================================================
--- code/branches/network2/src/network/Server.cc	(revision 1097)
+++ code/branches/network2/src/network/Server.cc	(revision 1098)
@@ -124,9 +124,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;
     }
@@ -155,6 +155,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 +168,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,40 +180,45 @@
   */
   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(4) << "Server: packet with client id (cid): " << cid << " not sended" << std::endl; 
       //std::cout << "added gamestate" << std::endl;
       added=true;
       temp=temp->next();
     }
-    if(added)
+    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;
+    COUT(5) << "Server: processing ack from client: " << clientID << "; ack-id: " << data->id << std::endl;
     clients->findClient(clientID)->setGamestateID(data->a);
   }
Index: code/branches/network2/src/network/Synchronisable.cc
===================================================================
--- code/branches/network2/src/network/Synchronisable.cc	(revision 1097)
+++ code/branches/network2/src/network/Synchronisable.cc	(revision 1098)
@@ -57,4 +57,5 @@
     datasize=0;
     objectID=idCounter++;
+    syncList = new std::list<synchronisableVariable *>;
     //registerAllVariables();
   }
@@ -71,9 +72,14 @@
   void Synchronisable::registerVar(const void *var, int size, variableType t){
     // create temporary synch.Var struct
-    synchronisableVariable temp={size, var, t};
+    synchronisableVariable *temp = new synchronisableVariable;
+    temp->size = size;
+    temp->var = var;
+    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 +97,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 +113,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,5 +140,6 @@
   */
   syncData Synchronisable::getData(unsigned char *mem){
-    std::list<synchronisableVariable>::iterator i;
+    //std::cout << "inside getData" << std::endl;
+    std::list<synchronisableVariable *>::iterator i;
     syncData retVal;
     retVal.objectID=this->objectID;
@@ -141,18 +148,17 @@
     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) );
+      memcpy( (void *)(retVal.data+n), (const void *)&((*i)->size), sizeof(int) );
       n+=sizeof(int);
-      switch(i->type){
+      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), (const 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;
+        std::memcpy( retVal.data+n, (const void*)( ( (std::string *) (*i)->var)->c_str()), (*i)->size);
+        n+=(*i)->size;
         break;
       }
@@ -168,19 +174,25 @@
   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){
-      case DATA:
-        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;
+    std::list<synchronisableVariable *>::iterator i;
+    if(syncList->empty()){
+      COUT(4) << "Synchronisable::updateData syncList is empty" << std::endl;
+      return false;
+    }
+    COUT(5) << "Synchronisable: objectID " << objectID << ", classID " << classID << " synchronising data" << std::endl;
+    for(i=syncList->begin(); i!=syncList->end(); i++){
+      COUT(5) << "element size: " << (*i)->size << " type: " << (*i)->type << std::endl;
+      if(*(int *)data==(*i)->size || (*i)->type==STRING){
+        switch((*i)->type){
+        case DATA:
+          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
@@ -196,15 +208,16 @@
   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++){
+      switch((*i)->type){
+      case DATA:
+        tsize+=sizeof(int);
+        tsize+=(*i)->size;
+        break;
+      case STRING:
+        tsize+=sizeof(int);
+        (*i)->size=((std::string *)(*i)->var)->length()+1;
+        tsize+=(*i)->size;
+        break;
       }
     }
Index: code/branches/network2/src/network/Synchronisable.h
===================================================================
--- code/branches/network2/src/network/Synchronisable.h	(revision 1097)
+++ code/branches/network2/src/network/Synchronisable.h	(revision 1098)
@@ -75,5 +75,5 @@
   public:
 
-      virtual ~Synchronisable();
+    virtual ~Synchronisable();
     int objectID;
     int classID;
@@ -91,5 +91,5 @@
     /*  bool removeObject(Iterator<Synchronisable> it);*/
 
-    std::list<SYNCVAR> syncList;
+    std::list<synchronisableVariable *> *syncList;
     int datasize;
   };
Index: code/branches/network2/src/network/diffTest.cc
===================================================================
--- code/branches/network2/src/network/diffTest.cc	(revision 1098)
+++ code/branches/network2/src/network/diffTest.cc	(revision 1098)
@@ -0,0 +1,706 @@
+#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 <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 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;
+  testClientInformation( 10 );
+}*/
Index: code/branches/network2/src/orxonox/Orxonox.cc
===================================================================
--- code/branches/network2/src/orxonox/Orxonox.cc	(revision 1097)
+++ code/branches/network2/src/orxonox/Orxonox.cc	(revision 1098)
@@ -305,5 +305,6 @@
     hudOverlay->show();
 
-    client_g->establishConnection();
+    if( !client_g->establishConnection() )
+      COUT(1) <<"CLIENT COULD NOT ESTABLISH CONNECTION" << std::endl;
     client_g->tick(0);
 
Index: code/branches/network2/src/orxonox/objects/Ambient.cc
===================================================================
--- code/branches/network2/src/orxonox/objects/Ambient.cc	(revision 1097)
+++ code/branches/network2/src/orxonox/objects/Ambient.cc	(revision 1098)
@@ -57,4 +57,5 @@
         RegisterObject(Ambient);
         Ambient::instance_s = this;
+        registerAllVariables();
     }
 
@@ -63,4 +64,14 @@
     }
 
+    bool Ambient::create(){
+      Orxonox::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/network2/src/orxonox/objects/Ambient.h
===================================================================
--- code/branches/network2/src/orxonox/objects/Ambient.h	(revision 1097)
+++ code/branches/network2/src/orxonox/objects/Ambient.h	(revision 1098)
@@ -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/network2/src/orxonox/objects/Model.cc
===================================================================
--- code/branches/network2/src/orxonox/objects/Model.cc	(revision 1097)
+++ code/branches/network2/src/orxonox/objects/Model.cc	(revision 1098)
@@ -82,10 +82,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;
@@ -93,5 +94,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/network2/src/orxonox/objects/NPC.cc
===================================================================
--- code/branches/network2/src/orxonox/objects/NPC.cc	(revision 1097)
+++ code/branches/network2/src/orxonox/objects/NPC.cc	(revision 1098)
@@ -40,4 +40,5 @@
     RegisterObject(NPC);
     movable_ = true;
+    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/network2/src/orxonox/objects/NPC.h
===================================================================
--- code/branches/network2/src/orxonox/objects/NPC.h	(revision 1097)
+++ code/branches/network2/src/orxonox/objects/NPC.h	(revision 1098)
@@ -52,4 +52,6 @@
       void update();
       void setValues(Vector3 location, Vector3 speed, Vector3 acceleration, bool movable);
+      void registerAllVariables();
+      bool create();
 
     private:
Index: code/branches/network2/src/orxonox/objects/Skybox.cc
===================================================================
--- code/branches/network2/src/orxonox/objects/Skybox.cc	(revision 1097)
+++ code/branches/network2/src/orxonox/objects/Skybox.cc	(revision 1098)
@@ -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(std::string src){
+     skyboxSrc_ = src;
+   }
+   
     /**
         @brief XML loading and saving.
@@ -80,4 +85,16 @@
 
         XMLPortParamLoadOnly(Skybox, "src", setSkybox, xmlelement, mode);
+        XMLPortParamLoadOnly(Skybox, "src", setSkyboxSrc, xmlelement, loading);
+        create();
     }
+    
+    bool Skybox::create(){
+      this->setSkybox(skyboxSrc_);
+      return true;
+    }
+    
+    void Skybox::registerAllVariables(){
+      registerVar(&skyboxSrc_, skyboxSrc_.length()+1 ,network::STRING);
+    }
+    
 }
Index: code/branches/network2/src/orxonox/objects/Skybox.h
===================================================================
--- code/branches/network2/src/orxonox/objects/Skybox.h	(revision 1097)
+++ code/branches/network2/src/orxonox/objects/Skybox.h	(revision 1098)
@@ -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(std::string src);
 
         private:
+            std::string skyboxSrc_;
 
 
Index: code/branches/network2/src/orxonox/objects/WorldEntity.cc
===================================================================
--- code/branches/network2/src/orxonox/objects/WorldEntity.cc	(revision 1097)
+++ code/branches/network2/src/orxonox/objects/WorldEntity.cc	(revision 1098)
@@ -72,4 +72,5 @@
         }
     }
+    
 
     WorldEntity::~WorldEntity()
@@ -162,4 +163,5 @@
 */
     }
+    
 
     void WorldEntity::setYawPitchRoll(const Degree& yaw, const Degree& pitch, const Degree& roll)
@@ -188,4 +190,6 @@
 
         XMLPortObject(WorldEntity, WorldEntity, "attached", attachWorldEntity, getAttachedWorldEntity, xmlelement, mode, false, true);
+        
+        //create();
     }
 
