Index: /code/branches/network/src/network/Client.cc
===================================================================
--- /code/branches/network/src/network/Client.cc	(revision 1007)
+++ /code/branches/network/src/network/Client.cc	(revision 1008)
@@ -204,5 +204,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/network/src/network/ClientInformation.cc
===================================================================
--- /code/branches/network/src/network/ClientInformation.cc	(revision 1007)
+++ /code/branches/network/src/network/ClientInformation.cc	(revision 1008)
@@ -189,5 +189,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) {
@@ -195,5 +195,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();
     }
@@ -210,5 +211,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/network/src/network/ClientInformation.h
===================================================================
--- /code/branches/network/src/network/ClientInformation.h	(revision 1007)
+++ /code/branches/network/src/network/ClientInformation.h	(revision 1008)
@@ -47,5 +47,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/network/src/network/ConnectionManager.cc
===================================================================
--- /code/branches/network/src/network/ConnectionManager.cc	(revision 1007)
+++ /code/branches/network/src/network/ConnectionManager.cc	(revision 1008)
@@ -59,5 +59,7 @@
 {
   boost::thread_group network_threads;
-
+  
+  ConnectionManager::ConnectionManager(){}
+  
   ConnectionManager::ConnectionManager(ClientInformation *head) {
     quit=false;
@@ -87,5 +89,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;
@@ -173,7 +178,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;
@@ -190,5 +197,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;
@@ -198,16 +208,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:
-        COUT(4) << "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;
@@ -231,13 +244,19 @@
     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 +287,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 +294,5 @@
     }
     sendPackets();
+    COUT(4) << "syncClassid:\tall synchClassID packets have been sent" << std::endl;
   }
 
@@ -289,6 +309,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 +322,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/network/src/network/ConnectionManager.h
===================================================================
--- /code/branches/network/src/network/ConnectionManager.h	(revision 1007)
+++ /code/branches/network/src/network/ConnectionManager.h	(revision 1008)
@@ -55,4 +55,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);
@@ -82,12 +104,6 @@
     void deleteClientIDReg( int clientID );
     void deleteObjectIDReg( int objectID );
+    int getNumberOfClients();
   };
-
-
-
-
-
-
-
 
 }
Index: /code/branches/network/src/network/GameStateClient.cc
===================================================================
--- /code/branches/network/src/network/GameStateClient.cc	(revision 1007)
+++ /code/branches/network/src/network/GameStateClient.cc	(revision 1008)
@@ -109,5 +109,5 @@
         
         if(!it){
-          COUT(5) << "classid: " << sync.classID << ", name: " << ID((unsigned int) sync.classID)->getName() << std::endl;
+          COUT(4) << "loadSnapshot:\tclassid: " << sync.classID << ", name: " << ID((unsigned int) sync.classID)->getName() << std::endl;
           Synchronisable *no = (Synchronisable*)(ID((unsigned int) sync.classID)->fabricate());
           no->objectID=sync.objectID;
@@ -197,5 +197,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;
     }
 
Index: /code/branches/network/src/network/GameStateManager.cc
===================================================================
--- /code/branches/network/src/network/GameStateManager.cc	(revision 1007)
+++ /code/branches/network/src/network/GameStateManager.cc	(revision 1008)
@@ -93,7 +93,11 @@
 
   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;
@@ -115,4 +119,5 @@
   GameState *GameStateManager::getSnapshot(int id)
   {
+    //std::cout << "begin getSnapshot" << std::endl;
     //the size of the gamestate
     int totalsize=0;
@@ -127,9 +132,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
@@ -137,15 +142,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;
@@ -154,4 +163,5 @@
           memsize+=tempsize+1000;
         }
+        COUT(5) << "G.St.Man: additional space allocation finished" << std::endl;
       }
 
@@ -166,9 +176,11 @@
       // 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;
   }
@@ -185,4 +197,5 @@
 
   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;
@@ -193,4 +206,5 @@
 
   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);
@@ -235,5 +249,5 @@
 
   GameStateCompressed *GameStateManager::compress_(GameState *a) {
-    COUT(5) << "compressing gamestate" << std::endl;
+    COUT(5) << "G.St.Man: compressing gamestate" << std::endl;
     int size = a->size;
     uLongf buffer = (uLongf)((a->size + 12)*1.01)+1;
@@ -245,10 +259,10 @@
 
     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;
     }
@@ -263,5 +277,5 @@
     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/network/src/network/PacketBuffer.cc
===================================================================
--- /code/branches/network/src/network/PacketBuffer.cc	(revision 1007)
+++ /code/branches/network/src/network/PacketBuffer.cc	(revision 1008)
@@ -60,5 +60,5 @@
       last=first;
       last->next=NULL;
-      // change this!!!!!!!
+      // change this!!!!!!! 
       last->packet = ev->packet;
       last->address = ev->peer->address;
Index: /code/branches/network/src/network/PacketDecoder.cc
===================================================================
--- /code/branches/network/src/network/PacketDecoder.cc	(revision 1007)
+++ /code/branches/network/src/network/PacketDecoder.cc	(revision 1008)
@@ -52,8 +52,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:
@@ -93,5 +98,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
 
@@ -147,5 +152,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;
     }
@@ -156,5 +161,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
@@ -174,8 +179,8 @@
     //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;
@@ -197,5 +202,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);
Index: /code/branches/network/src/network/PacketGenerator.cc
===================================================================
--- /code/branches/network/src/network/PacketGenerator.cc	(revision 1007)
+++ /code/branches/network/src/network/PacketGenerator.cc	(revision 1008)
@@ -50,5 +50,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;
@@ -63,5 +63,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;
@@ -77,5 +77,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;
@@ -126,5 +126,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/network/src/network/Server.cc
===================================================================
--- /code/branches/network/src/network/Server.cc	(revision 1007)
+++ /code/branches/network/src/network/Server.cc	(revision 1008)
@@ -95,9 +95,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;
     }
@@ -126,6 +126,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;
     }
   }
@@ -136,7 +139,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;
   }
@@ -146,40 +151,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/network/src/network/Synchronisable.cc
===================================================================
--- /code/branches/network/src/network/Synchronisable.cc	(revision 1007)
+++ /code/branches/network/src/network/Synchronisable.cc	(revision 1008)
@@ -44,5 +44,5 @@
     // increase datasize
     datasize+=sizeof(int)+size;
-    // push temp to syncList (at the bottom)
+    //std::cout << "push temp to syncList (at the bottom) " << datasize << std::endl;
     syncList.push_back(temp);
   }
@@ -104,5 +104,6 @@
   */
   syncData Synchronisable::getData(unsigned char *mem){
-    std::list<synchronisableVariable>::iterator i;
+    //std::cout << "inside getData" << std::endl;
+    std::list<SYNCVAR>::iterator i;
     syncData retVal;
     retVal.objectID=this->objectID;
@@ -113,5 +114,4 @@
     int n=0;
     for(i=syncList.begin(); n<datasize && i!=syncList.end(); ++i){
-      //COUT(2) << "size of variable: " << i->size << std::endl;
       //(std::memcpy(retVal.data+n, (const void*)(&(i->size)), sizeof(int));
       memcpy( (void *)(retVal.data+n), (const void*)&(i->size), sizeof(int) );
@@ -166,15 +166,15 @@
   int Synchronisable::getSize(){
     int tsize=0;
-    std::list<synchronisableVariable>::iterator i;
+    std::list<SYNCVAR>::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;
+      case DATA:
+        tsize+=sizeof(int);
+        tsize+=i->size;
+        break;
+      case STRING:
+        tsize+=sizeof(int);
+        tsize+=((std::string *)i->var)->length()+1;
+        break;
       }
     }
Index: /code/branches/network/src/network/Synchronisable.h
===================================================================
--- /code/branches/network/src/network/Synchronisable.h	(revision 1007)
+++ /code/branches/network/src/network/Synchronisable.h	(revision 1008)
@@ -47,5 +47,5 @@
   public:
 
-      virtual ~Synchronisable();
+    virtual ~Synchronisable();
     int objectID;
     int classID;
Index: /code/branches/network/src/network/diffTest.cc
===================================================================
--- /code/branches/network/src/network/diffTest.cc	(revision 1007)
+++ /code/branches/network/src/network/diffTest.cc	(revision 1008)
@@ -1,10 +1,17 @@
+#include "enet/enet.h"
+#include "Orxonox.h"
+#include "NetworkPrereqs.h"
+#include "PacketTypes.h"
 #include "GameStateManager.h"
 #include "Synchronisable.h"
 #include "GameStateClient.h"
-#include "NetworkPrereqs.h"
-#include "PacketTypes.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;
@@ -17,5 +24,5 @@
 
 void printGameStateCompressed( GameStateCompressed* gc ) {
-  std::cout << "=================================================" << std::endl;
+  //std::cout << "=================================================" << std::endl;
   std::cout << "GameStateCompressed id:\t\t" << gc->id << std::endl;
   std::cout << "GameStateCompressed normsize:\t" << gc->normsize << std::endl;
@@ -24,5 +31,5 @@
   //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;
+  std::cout << "=================================================" << std::endl;
   return;
 }
@@ -30,9 +37,9 @@
 bool compareData( GameState* g1, GameState* g2 ) {
   if ( g1->id != g2->id ) {
-    std::cout << "GameStates are not comparable -> not same id" << std::endl;
+    std::cout << "\t--> GameStates are not comparable -> not same id" << std::endl;
     return 1;
   }
   else if ( g1->size != g2->size ) {
-    std::cout << "GameStates are not the same size!!" << std::endl;
+    std::cout << "\t--> GameStates are not the same size!!" << std::endl;
     std::cout << g1->size << " != " << g2->size << std::endl;
   }
@@ -40,9 +47,9 @@
   for ( int i=0; i<length; i++ ) {
     if ( g1->data[i] != g2->data[i] ) {
-      std::cout << "data of both GameStates are not identical" << std::endl;
+      std::cout << "\t--> data of both GameStates are not identical" << std::endl;
       return false;
     }
   }
-  std::cout << "GameStates are identical" << std::endl;
+  std::cout << "\t--> GameStates are identical (compareData)" << std::endl;
   return true;
 }
@@ -50,30 +57,29 @@
 bool compareGameStates( GameState* g1, GameState* g2 ) {
   if ( g1->id != g2->id ) {
-    std::cout << "GameState id's not identical" << std::endl;
+    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->size != g2->size ) {
-    std::cout << "GameState sizes are not identical" << std::endl;
+  else if ( g1->diffed != g2->diffed ) {
+    std::cout << "\t==> GameState diffed params not identical (GameStateCompare)" << std::endl;
     return false;
   }
-  else if ( g1->diffed != g2->diffed ) {
-    std::cout << "GameState diffed params not identical" << std::endl;
+  else if ( !compareData( g1, g2 ) ) {
+    std::cout << "\t==> GameState data are not identical (GameStateCompare)" << std::endl;
     return false;
   }
-  else if ( !compareData( g1, g2 ) ) {
-    std::cout << "GameState data are not identical" << std::endl;
-    return false;
-  }
-  std::cout << "==>GameStates are identical (GameStateCompare)" << std::endl;
+  std::cout << "\t==> GameStates are identical (GameStateCompare)" << std::endl;
   return true;
 }
 
 void printGameState( GameState* gstate ) {
-  std::cout << "=================================================" << std::endl;
+  //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;
+  std::cout << "=================================================" << std::endl;
   return;
 }
@@ -81,5 +87,4 @@
 unsigned char* createData( int length, int mode ) {
   char* data = new char[ length ];
-  
   if ( mode == 1 ) {
     for ( int i=0; i<length; i++ )
@@ -93,14 +98,9 @@
   }
   else if ( mode == 3 ) {
-    for ( int i=0; i<length; i++ ) {
-      data[i] = (char)(i%255);
-    }
-  }
-  else if ( mode == 4 ) {
     for ( int i=0; i<length; i++ ){
       data[i] = (char)(rand()%255);
     }
   }
-  else if ( mode == 5 ) {
+  else if ( mode == 4 ) {
     for ( int i=0; i<length; i++ ){
       data[i] = (char)(rand()%127);
@@ -121,5 +121,5 @@
 
   if ( mode == 1 ) {
-    b->data = new unsigned char[a->size];
+    b->data = new unsigned char[length];
     b->size = a->size;
     for ( int i=0; i<length; i++ ) {
@@ -129,13 +129,13 @@
   }
   else if ( mode == 2 ) {
-    b->data = new unsigned char[a->size];
-    b->size = a->size;
+    b->data = new unsigned char[length];
+    b->size = length;
     for ( int i=0; i<length; i++ ) {
-      if ( i%5 == 0 ) b->data[i] = rand()%255;
+      if ( i%(rand()%((length)/11)) == 0 ) b->data[i] = rand()%255;
       else b->data[i] = a->data[i];
     }
   }
   else if ( mode == 3 ) {
-    int s = a->size + (a->size)/3;
+    int s = length + (rand()%(length));
     b->data = new unsigned char[s];
     b->size = s;
@@ -148,4 +148,25 @@
     }
   }
+  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)) == 0 ) b->data[i] = 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] = rand()%255;
+      else b->data[i] = a->data[i];
+    }
+  }
 
   return b;
@@ -182,5 +203,5 @@
             << modeCreateData << " modeChangeData = " << modeChangeData << std::endl; 
   GameStateClient* g_client;
-  GameStateManager* g_manager;;
+  GameStateManager* g_manager;
   
   GameState* g_undiff1 = new GameState;
@@ -267,18 +288,255 @@
 }
 
+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;
   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 << "testDifferentiation:\t td [datalength] [mode Data] [mode Change]" << std::endl;
+  std::cout << "testCompressWithDiff:\t tcd [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::cout << "possible tests: testcompression [datalength] [mode]" << std::endl;
-    std::cout << "testdiff [datalength] [mode Data] [mode Change]" << std::endl;
-    std::cout << "tcd [datalength] [mode Data] [mode Change]" << std::endl;
     std::cin >> dec;
-    if ( dec.compare("testcompression") == 0 ) {
+    if ( dec.compare("tc") == 0 ) {
       std::cin >> a; std::cin >> b;
       testCompression( a, b );
     }
-    else if ( dec.compare("testdiff") == 0 ) {
+    else if ( dec.compare("td") == 0 ) {
       std::cin>> a; std::cin >> b; std::cin >> c;
       testDifferentiation( a, b, c );
@@ -288,4 +546,18 @@
       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();
+    }   
+    std::cout << "################## END ONE TURN ##################@" << std::endl;
   }
   return 0;
@@ -294,4 +566,4 @@
 int main() {
   std::cout << "############### START TEST (quit q) ###############" << std::endl;
-  testCompressWithDiff( 5000, 5, 1 );
+  testClientInformation( 10 );
 }*/
