Index: code/trunk/TODO
===================================================================
--- code/trunk/TODO	(revision 1906)
+++ code/trunk/TODO	(revision 1907)
@@ -1,2 +1,14 @@
-- should we use enet_peer_ping to test if a client is still alive ?
-- enet_host_broadcast ? (to all peers)
+todo: 
+	!!! check that enet does not cause a packet traffic jam when a reliable packet gets missed !!!
+	[implemented] new gamestate concept
+
+	!!! ensure that objects get synched, when newly created, even if not their tick
+
+	setvariable mode
+	objectmode
+	priorities (put into gamestatehandler)
+		manage delete object handling (only send deletes of acked objects)
+	static (sync once) & triggerSync
+
+REMARKS:
+	try to allocate sort the bytestream before copy (putt all 0's in one place)
Index: code/trunk/bin/ogre.cfg-init
===================================================================
--- code/trunk/bin/ogre.cfg-init	(revision 1906)
+++ code/trunk/bin/ogre.cfg-init	(revision 1907)
@@ -4,4 +4,4 @@
 FSAA=0
 Full Screen=No
-RTT Preferred Mode=FBO
-Video Mode=1024 x 768
+RTT Preferred Mode=PBuffer
+Video Mode=640 x 480
Index: code/trunk/src/network/CMakeLists.txt
===================================================================
--- code/trunk/src/network/CMakeLists.txt	(revision 1906)
+++ code/trunk/src/network/CMakeLists.txt	(revision 1907)
@@ -17,4 +17,5 @@
   packet/Gamestate.cc
   packet/Welcome.cc
+  packet/DeleteObjects.cc
 )
 
Index: code/trunk/src/network/Client.cc
===================================================================
--- code/trunk/src/network/Client.cc	(revision 1906)
+++ code/trunk/src/network/Client.cc	(revision 1907)
@@ -43,5 +43,4 @@
 #include "Synchronisable.h"
 #include "core/CoreIncludes.h"
-#include "core/ConsoleCommand.h"
 #include "packet/Packet.h"
 // #include "packet/Acknowledgement.h"
@@ -61,5 +60,4 @@
     isSynched_=false;
     gameStateFailure_=false;
-    isServer_ = false;
   }
 
@@ -73,5 +71,4 @@
     isSynched_=false;
     gameStateFailure_=false;
-    isServer_ = false;
   }
 
@@ -85,5 +82,4 @@
     isSynched_=false;
     gameStateFailure_=false;
-    isServer_ = false;
   }
 
@@ -118,32 +114,24 @@
   }
 
-  bool Client::processChat(packet::Chat *message, unsigned int clientID){
-    return message->process();
+  bool Client::processChat(std::string message, unsigned int playerID){
+    COUT(1) << "Player " << playerID << ": " << message << std::endl;
+    return true;
   }
-
-  /*bool Client::sendChat(packet::Chat *chat){
-    chat->process();
-    packet::Packet *p = new packet::Packet(chat);
-    return p->send();
-  }*/
+  
+  /**
+   * This function implements the method of sending a chat message to the server
+   * @param message message to be sent 
+   * @return result(true/false)
+   */
+  bool Client::chat(std::string message){
+    packet::Chat *m = new packet::Chat(message, Host::getPlayerID());
+    return m->send();
+  }
 
 
   /**
-  * submits a chat message to the server
-  * @param message message to send
-  * @return true/false
-  */
-  bool Client::sendChat( std::string message ){
-    // generate packet and add it to queue
-    if(!isConnected)
-      return false;
-    packet::Chat chat(message, 0);
-    return chat.send();
-    // send packets
-  }
-
-  /**
-  * Performs a GameState update
-  */
+   * Processes incoming packets, sends a gamestate to the server and does the cleanup
+   * @param time 
+   */
   void Client::tick(float time){
 //     COUT(3) << ".";
@@ -164,5 +152,6 @@
       COUT(5) << "tick packet size " << event->packet->dataLength << std::endl;
       packet::Packet *packet = packet::Packet::createPacket(event->packet, event->peer);
-      assert(packet->process());
+      bool b = packet->process();
+      assert(b);
     }
     if(gamestate.processGamestates())
@@ -170,6 +159,5 @@
       if(!isSynched_)
         isSynched_=true;
-    }else
-      COUT(3) << "gamestate has not been processed sucessfully" << std::endl;
+    }
     gamestate.cleanup();
     return;
Index: code/trunk/src/network/Client.h
===================================================================
--- code/trunk/src/network/Client.h	(revision 1906)
+++ code/trunk/src/network/Client.h	(revision 1907)
@@ -73,11 +73,10 @@
     bool closeConnection();
     bool queuePacket(ENetPacket *packet, int clientID);
-    bool processChat(packet::Chat *message, unsigned int clientID);
+    bool processChat(std::string message, unsigned int playerID);
+    virtual bool chat(std::string message);
     //bool sendChat(packet::Chat *chat);
     
 //    static void Chat( std::string message );
     
-    unsigned int shipID(){return shipID_;}
-    int playerID(){return clientID_;}
     //static void setShipID( unsigned int shipID){ dynamic_cast<Client *>(instance_)->shipID_=shipID; }
     static void setClientID( unsigned int clientID){ dynamic_cast<Client *>(instance_)->clientID_=clientID; }
@@ -86,4 +85,5 @@
 
   private:
+    virtual bool isServer_(){return false;}
     
     ClientConnection client_connection;
@@ -91,11 +91,5 @@
     bool isConnected;
     bool isSynched_;
-
-    bool sendChat( std::string message );
     
-    // implement data processing functions of PacketDecoder
-//     void processChat( chat *data, int clientId );
-    int clientID_;     // this is the id the server gave to us
-    int shipID_;
     bool gameStateFailure_;
   };
Index: code/trunk/src/network/ClientConnection.cc
===================================================================
--- code/trunk/src/network/ClientConnection.cc	(revision 1906)
+++ code/trunk/src/network/ClientConnection.cc	(revision 1907)
@@ -77,19 +77,8 @@
   }
 
-
-  /*ENetPacket *ClientConnection::getPacket(ENetAddress &address) {
-    if(!buffer.isEmpty()) {
-      //std::cout << "###BUFFER IS NOT EMPTY###" << std::endl;
-      return buffer.pop(address);
-    }
-    else{
-      return NULL;
-    }
-  }
-
-  ENetPacket *ClientConnection::getPacket() {
-    ENetAddress address; //sems that address is not needed
-    return getPacket(address);
-  }*/
+  ClientConnection::~ClientConnection(){
+    if(established)
+      closeConnection();
+  }
 
   ENetEvent *ClientConnection::getEvent(){
Index: code/trunk/src/network/ClientConnection.h
===================================================================
--- code/trunk/src/network/ClientConnection.h	(revision 1906)
+++ code/trunk/src/network/ClientConnection.h	(revision 1907)
@@ -64,6 +64,5 @@
     ClientConnection(int port, std::string address);
     ClientConnection(int port, const char* address);
-    //ENetPacket *getPacket(ENetAddress &address); // thread1
-    //ENetPacket *getPacket(); // thread1
+    ~ClientConnection();
     ENetEvent *getEvent();
     // check wheter the packet queue is empty
Index: code/trunk/src/network/ConnectionManager.cc
===================================================================
--- code/trunk/src/network/ConnectionManager.cc	(revision 1906)
+++ code/trunk/src/network/ConnectionManager.cc	(revision 1907)
@@ -81,12 +81,4 @@
   boost::recursive_mutex ConnectionManager::enet_mutex;
 
-//   ConnectionManager::ConnectionManager(ClientInformation *head) : receiverThread_(0) {
-//     assert(instance_==0);
-//     instance_=this;
-//     quit=false;
-//     bindAddress.host = ENET_HOST_ANY;
-//     bindAddress.port = NETWORK_PORT;
-//   }
-
   ConnectionManager::ConnectionManager(int port){
     assert(instance_==0);
@@ -114,28 +106,9 @@
 
   ConnectionManager::~ConnectionManager(){
-    instance_=0;
     if(!quit)
       quitListener();
-  }
-
-  /*ENetPacket *ConnectionManager::getPacket(ENetAddress &address) {
-    if(!buffer.isEmpty())
-      return buffer.pop(address);
-    else
-      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;
-    ENetPacket *packet=getPacket(address);
-    ClientInformation *temp =head_->findClient(&address);
-    if(!temp)
-      return NULL;
-    clientID=temp->getID();
-    return packet;
-  }*/
+    instance_=0;
+  }
+
 
   ENetEvent *ConnectionManager::getEvent(){
@@ -164,14 +137,4 @@
   }
 
-//   bool ConnectionManager::addPacket(Packet::Packet *packet){
-//     ClientInformation *temp = instance_->head_->findClient(packet->getClientID());
-//     if(!temp){
-//       COUT(3) << "C.Man: addPacket findClient failed" << std::endl;
-//       return false;
-//     }
-//     ENetPacket *packet = new ENetPacket;
-//     //  TODO: finish implementation
-//   }
-//
 
   bool ConnectionManager::addPacket(ENetPacket *packet, ENetPeer *peer) {
@@ -373,5 +336,5 @@
     orxonox::ObjectList<orxonox::SpaceShip>::iterator it;
     for(it = orxonox::ObjectList<orxonox::SpaceShip>::begin(); it; ++it){
-      if(it->objectID!=id)
+      if(it->getObjectID()!=id)
         continue;
       delete *it;
Index: code/trunk/src/network/GamestateClient.cc
===================================================================
--- code/trunk/src/network/GamestateClient.cc	(revision 1906)
+++ code/trunk/src/network/GamestateClient.cc	(revision 1907)
@@ -156,5 +156,5 @@
     if(myShip_){
       //      unsigned char *data = new unsigned char[myShip_->getSize()];
-      int size=myShip_->getSize2(0, 0x1);
+      int size=myShip_->getSize(0, 0x1);
       if(size==0)
         return false;
@@ -182,5 +182,8 @@
   packet::Gamestate *GamestateClient::processGamestate(packet::Gamestate *gs){
     if(gs->isCompressed())
-      assert(gs->decompressData());
+    {
+      bool b = gs->decompressData();
+      assert(b);
+    }
     if(gs->isDiffed()){
       packet::Gamestate *base = gamestateMap_[gs->getBaseID()];
@@ -189,5 +192,5 @@
         return 0;
       }
-//      assert(base); //TODO: fix this
+//       assert(base); //TODO: fix this
       packet::Gamestate *undiffed = gs->undiff(base);
       delete gs;
Index: code/trunk/src/network/GamestateManager.cc
===================================================================
--- code/trunk/src/network/GamestateManager.cc	(revision 1906)
+++ code/trunk/src/network/GamestateManager.cc	(revision 1907)
@@ -61,5 +61,5 @@
 
   bool GamestateManager::update(){
-    cleanup();
+//     cleanup();
     return getSnapshot();
   }
@@ -92,7 +92,7 @@
     reference = new packet::Gamestate();
     reference->collectData(++id_);
-    COUT(4) << "inserting gamestate: " << reference << std::endl;
-    gamestateMap.insert(std::pair<int, packet::Gamestate*>(id_, reference));
-    gamestateUsed[id_]=0;
+    //COUT(4) << "inserting gamestate: " << reference << std::endl;
+    //gamestateMap_.insert(std::pair<int, packet::Gamestate*>(id_, reference));
+//     gamestateUsed[id_]=0;
     return true;
   }
@@ -104,5 +104,5 @@
    * 
    */
-  void GamestateManager::cleanup(){
+/*  void GamestateManager::cleanup(){
     std::map<int,int>::iterator it = gamestateUsed.begin();
     while(it!=gamestateUsed.end()){
@@ -124,5 +124,5 @@
       it++;
     }
-  }
+  }*/
 
   packet::Gamestate *GamestateManager::popGameState(int clientID) {
@@ -131,20 +131,29 @@
     packet::Gamestate *gs;
     int gID = ClientInformation::findClient(clientID)->getGamestateID();
-    //COUT(4) << "G.St.Man: popgamestate: sending gstate_id: " << id_ << " diffed from: " << gID << std::endl;
+    gs = reference->doSelection(clientID);
+//     gs = new packet::Gamestate(*reference);
+//     gs = new packet::Gamestate(*reference);
+    // save the (undiffed) gamestate in the clients gamestate map
+    gamestateMap_[clientID].insert(std::pair<int, packet::Gamestate*>(gs->getID(), gs));
     //chose wheather the next gamestate is the first or not
+    packet::Gamestate *client=NULL;
     if(gID != GAMESTATEID_INITIAL){
-      packet::Gamestate *client=NULL;
-      std::map<int, packet::Gamestate*>::iterator it = gamestateMap.find(gID);
-      if(it!=gamestateMap.end())
-        client = it->second;
-      if(client)
-        gs = reference->diff(client);
-      else
-        gs = new packet::Gamestate(*reference);
-    } else {
-      COUT(4) << "we got a GAMESTATEID_INITIAL for clientID: " << clientID << std::endl;
-      gs = new packet::Gamestate(*reference);
-    }
-    assert(gs->compressData());
+      std::map<unsigned int, std::map<int, packet::Gamestate*> >::iterator clientMap = gamestateMap_.find(clientID);
+      if(clientMap!=gamestateMap_.end()){
+        std::map<int, packet::Gamestate*>::iterator it = clientMap->second.find(gID);
+        if(it!=clientMap->second.end())
+          client = it->second;
+      }
+    }
+    if(client){
+//       COUT(3) << "diffing" << std::endl;
+      gs = gs->diff(client);
+    }
+    else{
+//       COUT(3) << "not diffing" << std::endl;
+      gs = new packet::Gamestate(*gs);
+    }
+    bool b = gs->compressData();
+    assert(b);
     return gs;
   }
@@ -153,47 +162,41 @@
   bool GamestateManager::ack(int gamestateID, int clientID) {
     ClientInformation *temp = ClientInformation::findClient(clientID);
-    if(temp==0)
-      return false;
+    assert(temp);
     int curid = temp->getGamestateID();
     
     if(gamestateID == 0){
       temp->setGamestateID(GAMESTATEID_INITIAL);
-      if(curid!=GAMESTATEID_INITIAL){
-        assert(gamestateUsed.find(curid)!=gamestateUsed.end());
-        --(gamestateUsed.find(curid)->second);
-      }
       return true;
     }
-    //if(curid > gamestateID)
+    
     assert(curid<gamestateID);
-      // the network packets got messed up 
-      //return true;
     COUT(4) << "acking gamestate " << gamestateID << " for clientid: " << clientID << " curid: " << curid << std::endl;
-    // decrease usage of gamestate and save it
-//     deleteUnusedGameState(curid);
-    //increase gamestateused
-    std::map<int, int>::iterator it = gamestateUsed.find(curid);
-    if(curid!=GAMESTATEID_INITIAL){
-      if(it!=gamestateUsed.end())
-        --(it->second);
-    }
-    it = gamestateUsed.find(gamestateID);
-    if(it!=gamestateUsed.end()){
-      ++(it->second);
-      temp->setGamestateID(gamestateID);
-    }
+    std::map<int, packet::Gamestate*>::iterator it, tempit;
+    for(it = gamestateMap_[clientID].begin(); it!=gamestateMap_[clientID].end() && it->first<gamestateID; it++){
+      delete it->second;
+      tempit=it++;
+      gamestateMap_[clientID].erase(tempit);
+    }
+    temp->setGamestateID(gamestateID);
     return true;
   }
 
   void GamestateManager::removeClient(ClientInformation* client){
-    if(!client)
-      return;
-    if(client->getGamestateID()>=0)
-      gamestateUsed[client->getGamestateID()]--;
+    assert(client);
+    std::map<unsigned int, std::map<int, packet::Gamestate*> >::iterator clientMap = gamestateMap_.find(client->getID());
+    // first delete all remained gamestates
+    std::map<int, packet::Gamestate*>::iterator it;
+    for(it=clientMap->second.begin(); it!=clientMap->second.end(); it++)
+      delete it->second;
+    // now delete the clients gamestatemap
+    gamestateMap_.erase(clientMap);
   }
   
   bool GamestateManager::processGamestate(packet::Gamestate *gs){
     if(gs->isCompressed())
-       assert(gs->decompressData());
+    {
+       bool b = gs->decompressData();
+       assert(b);
+    }
     assert(!gs->isDiffed());
     return gs->spreadData();
Index: code/trunk/src/network/GamestateManager.h
===================================================================
--- code/trunk/src/network/GamestateManager.h	(revision 1906)
+++ code/trunk/src/network/GamestateManager.h	(revision 1907)
@@ -81,9 +81,10 @@
     void removeClient(ClientInformation *client);
     private:
-    void cleanup(); // "garbage handler"
+//     void cleanup(); // "garbage handler"
     bool processGamestate(packet::Gamestate *gs);
 
-    std::map<int, packet::Gamestate*> gamestateMap; //map gsID to gamestate*
-    std::map<int, int> gamestateUsed; // save the number of clients, that use the specific gamestate
+    std::map<unsigned int, std::map<int, packet::Gamestate*> > gamestateMap_;
+    //std::map<int, packet::Gamestate*> gamestateMap; //map gsID to gamestate*
+    //std::map<int, int> gamestateUsed; // save the number of clients, that use the specific gamestate
     std::map<int, packet::Gamestate*> gamestateQueue;
     packet::Gamestate *reference;
Index: code/trunk/src/network/Host.cc
===================================================================
--- code/trunk/src/network/Host.cc	(revision 1906)
+++ code/trunk/src/network/Host.cc	(revision 1907)
@@ -30,12 +30,19 @@
 
 #include "Host.h"
+#include "core/ConsoleCommand.h"
 #include "packet/Packet.h"
 
 namespace network {
 
+SetConsoleCommandShortcut(Host, Chat);
+
 Host *Host::instance_=0;
   
+/**
+ * @brief Constructor: assures that only one reference will be created and sets the pointer
+ */
 Host::Host()
 {
+  clientID_=0;
   assert(instance_==0);
   instance_=this;
@@ -43,4 +50,7 @@
 
 
+/**
+ * @brief Destructor: resets the instance pointer to 0
+ */
 Host::~Host()
 {
@@ -48,4 +58,10 @@
 }
 
+/**
+ * This function is used to add an enetpacket to be sent to another peer
+ * @param packet Packet to be added
+ * @param clientID ID of the client the packet should be sent to
+ * @return success?
+ */
 bool Host::addPacket(ENetPacket *packet, int clientID){
   if(instance_)
@@ -70,15 +86,23 @@
 // }
 
-int Host::getPlayerID(){ 
+/**
+ * This function returns the ID of the player
+ * @return playerID
+ */
+unsigned int Host::getPlayerID(){ 
   if(!instance_)
     return 0;
-  return instance_->playerID();
+  return instance_->clientID_;
 }
 
-// unsigned int Host::getShipID(){ 
-//   if(!instance_)
-//     assert(0);
-//   return instance_->shipID();
-// }
+bool Host::Chat(std::string message){
+  if(!instance_)
+    return false;
+  return instance_->chat(message);
+}
+
+bool Host::incomingChat(std::string message, unsigned int playerID){
+  return instance_->processChat(message, playerID);
+}
 
 }//namespace network
Index: code/trunk/src/network/Host.h
===================================================================
--- code/trunk/src/network/Host.h	(revision 1906)
+++ code/trunk/src/network/Host.h	(revision 1907)
@@ -37,5 +37,10 @@
 
 /**
-	@author Oliver Scheuss
+*       @brief Base class of Server and Client
+*       This is the Base class of the Server and Client classes
+*       - Makes server and client a singleton
+*       - defines static functions available on both server and client
+*       - is the interface to be used when communicating with the network
+*	@author Oliver Scheuss
 */
 class Host{
@@ -45,6 +50,7 @@
     //virtual bool sendChat(packet::Chat *chat)=0;
     virtual bool queuePacket(ENetPacket *packet, int clientID)=0;
-    virtual unsigned int shipID()=0;
-    virtual int playerID()=0;
+    virtual bool chat(std::string message)=0;
+    virtual bool processChat(std::string message, unsigned int playerID)=0;
+    virtual bool isServer_()=0;
 
 
@@ -54,5 +60,6 @@
     virtual ~Host();
     static Host *instance_;
-    bool isServer_;	
+    unsigned int clientID_;
+    unsigned int shipID_;
 
   public:
@@ -61,12 +68,12 @@
     //static bool chat(std::string& message);
 //     static bool receiveChat(packet::Chat *message, unsigned int clientID);
-    static int getPlayerID();
+    static unsigned int getPlayerID();
     static unsigned int getShipID(){return instance_->shipID_;}
     static void setClientID(unsigned int id){ instance_->clientID_ = id; }
     static void setShipID(unsigned int id){ instance_->shipID_ = id; }
-    static bool isServer(){ return instance_->isServer_; }		
+    static bool isServer(){ return instance_->isServer_(); }		
+    static bool Chat(std::string message);
+    static bool incomingChat(std::string message, unsigned int playerID);
   private:
-    unsigned int clientID_;
-    unsigned int shipID_;
 };
 
Index: code/trunk/src/network/Server.cc
===================================================================
--- code/trunk/src/network/Server.cc	(revision 1906)
+++ code/trunk/src/network/Server.cc	(revision 1907)
@@ -56,4 +56,5 @@
 #include "packet/Packet.h"
 #include "packet/Welcome.h"
+#include "packet/DeleteObjects.h"
 #include <util/Convert.h>
 
@@ -71,5 +72,4 @@
     connection = new ConnectionManager();
     gamestates_ = new GamestateManager();
-    isServer_ = true;
   }
 
@@ -78,5 +78,4 @@
     connection = new ConnectionManager(port);
     gamestates_ = new GamestateManager();
-    isServer_ = true;
   }
 
@@ -90,5 +89,4 @@
     connection = new ConnectionManager(port, bindAddress);
     gamestates_ = new GamestateManager();
-    isServer_ = true;
   }
 
@@ -102,5 +100,14 @@
     connection = new ConnectionManager(port, bindAddress);
     gamestates_ = new GamestateManager();
-    isServer_ = true;
+  }
+  
+  /**
+  * @brief Destructor
+  */
+  Server::~Server(){
+    if(connection)
+      delete connection;
+    if(gamestates_)
+      delete gamestates_;
   }
 
@@ -121,45 +128,18 @@
   }
 
-  bool Server::processChat(packet::Chat *message, unsigned int clientID){
+  bool Server::processChat(std::string message, unsigned int playerID){
     ClientInformation *temp = ClientInformation::getBegin();
+    packet::Chat *chat;
     while(temp){
-      message->setClientID(temp->getID());
-      if(!message->send())
-        COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl;
-      temp = temp->next();
-    }
-    return message->process();
-  }
-
-  /**
-  * This function sends out a message to all clients
-  * @param msg message
-  * @return true/false
-  */
-  bool Server::sendChat(packet::Chat *chat) {
-    //TODO: change this (no informations about who wrote a message)
-    assert(0);
-    ClientInformation *temp = ClientInformation::getBegin();
-    while(temp){
+      chat = new packet::Chat(message, playerID);
       chat->setClientID(temp->getID());
       if(!chat->send())
         COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl;
-    }
-    return chat->process();;
-  }
-
-  /**
-  * This function sends out a message to all clients
-  * @param msg message
-  * @return true/false
-  */
-//   bool Server::sendChat(const char *msg) {
-//     char *message = new char [strlen(msg)+10+1];
-//     sprintf(message, "Player %d: %s", CLIENTID_SERVER, msg);
-//     COUT(1) << message << std::endl;
-//     ENetPacket *packet = packet_gen.chatMessage(message);
-//     COUT(5) <<"Server: adding Packets" << std::endl;
-//     return connection->addPacketAll(packet);
-//   }
+      temp = temp->next();
+    }
+    COUT(1) << "Player " << playerID << ": " << message << std::endl;
+    return true;
+  }
+
 
   /**
@@ -174,12 +154,7 @@
     if(timeSinceLastUpdate_>=(1./NETWORK_FREQUENCY)){
       timeSinceLastUpdate_=(float)((int)(timeSinceLastUpdate_*NETWORK_FREQUENCY))/timeSinceLastUpdate_;
-//      timeSinceLastUpdate_-=1./NETWORK_FREQUENCY;
       gamestates_->processGamestates();
       updateGamestate();
     }
-    /*while(timeSinceLastUpdate_>1./NETWORK_FREQUENCY)
-      timeSinceLastUpdate_-=1./NETWORK_FREQUENCY;*/
-//     usleep(5000); // TODO remove
-    return;
   }
 
@@ -230,4 +205,5 @@
     //if(clients->getGamestateID()!=GAMESTATEID_INITIAL)
     sendGameState();
+    sendObjectDeletes();
     COUT(5) << "Server: one sendGameState turn complete, repeat in next tick" << std::endl;
     //std::cout << "sent gamestate" << std::endl;
@@ -276,21 +252,31 @@
       // gs gets automatically deleted by enet callback
     }
-    /*if(added) {
-      //std::cout << "send gamestates from server.cc in sendGameState" << std::endl;
-      return connection->sendPackets();
-    }*/
-    //COUT(5) << "Server: had no gamestates to send" << std::endl;
-    return true;
-  }
-
-//   void Server::processChat( chat *data, int clientId){
-//     char *message = new char [strlen(data->message)+10+1];
-//     sprintf(message, "Player %d: %s", clientId, data->message);
-//     COUT(1) << message << std::endl;
-//     ENetPacket *pck = packet_gen.chatMessage(message);
-//     connection->addPacketAll(pck);
-//     delete[] data->message;
-//     delete data;
-//   }
+    return true;
+  }
+
+  bool Server::sendObjectDeletes(){
+    ClientInformation *temp = ClientInformation::getBegin();
+    packet::DeleteObjects *del = new packet::DeleteObjects();
+    if(!del->fetchIDs())
+      return true;  //everything ok (no deletes this tick)
+//     COUT(3) << "sending DeleteObjects" << std::endl;
+    while(temp != NULL){
+      if( !(temp->getSynched()) ){
+        COUT(5) << "Server: not sending gamestate" << std::endl;
+        temp=temp->next();
+        continue;
+      }
+      int cid = temp->getID(); //get client id
+      packet::DeleteObjects *cd = new packet::DeleteObjects(*del);
+      assert(cd);
+      cd->setClientID(cid);
+      if ( !cd->send() )
+        COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp->getFailures() << std::endl;
+      temp=temp->next();
+      // gs gets automatically deleted by enet callback
+    }
+    return true;
+  }
+
 
   bool Server::addClient(ENetEvent *event){
@@ -328,10 +314,14 @@
     packet::Welcome *w = new packet::Welcome(temp->getID(), temp->getShipID());
     w->setClientID(temp->getID());
-    assert(w->send());
+    bool b = w->send();
+    assert(b);
     packet::Gamestate *g = new packet::Gamestate();
     g->setClientID(temp->getID());
-    assert(g->collectData(0));
-    assert(g->compressData());
-    assert(g->send());
+    b = g->collectData(0);
+    assert(b);
+    b = g->compressData();
+    assert(b);
+    b = g->send();
+    assert(b);
     return true;
   }
@@ -347,5 +337,5 @@
     orxonox::SpaceShip *no = dynamic_cast<orxonox::SpaceShip *>(id->fabricate());
     no->classID = id->getNetworkID();
-    client->setShipID(no->objectID);
+    client->setShipID(no->getObjectID());
     no->setPosition(orxonox::Vector3(0,0,80));
     no->setScale(10);
@@ -376,5 +366,5 @@
     gamestates_->removeClient(client);
     while(it){
-      if(it->objectID!=client->getShipID()){
+      if(it->getObjectID()!=client->getShipID()){
         ++it;
         continue;
@@ -397,4 +387,18 @@
     gamestates_->removeClient(client);
   }
+  
+  bool Server::chat(std::string message){
+    ClientInformation *temp = ClientInformation::getBegin();
+    packet::Chat *chat;
+    while(temp){
+      chat = new packet::Chat(message, Host::getPlayerID());
+      chat->setClientID(temp->getID());
+      if(!chat->send())
+        COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl;
+      temp = temp->next();
+    }
+    COUT(1) << "Player " << Host::getPlayerID() << ": " << message << std::endl;
+    return true;
+  }
 
 }
Index: code/trunk/src/network/Server.h
===================================================================
--- code/trunk/src/network/Server.h	(revision 1906)
+++ code/trunk/src/network/Server.h	(revision 1907)
@@ -63,9 +63,9 @@
     Server(int port, std::string bindAddress);
     Server(int port, const char *bindAddress);
+    ~Server();
     
     void open();
     void close();
-    bool processChat(packet::Chat *message, unsigned int clientID);
-    bool sendChat(packet::Chat *chat);
+    bool processChat(std::string message, unsigned int playerID);
     bool queuePacket(ENetPacket *packet, int clientID);
     void tick(float time);
@@ -74,6 +74,7 @@
     void updateGamestate();
   private:
+    virtual bool isServer_(){return true;}
     unsigned int shipID(){return 0;}
-    int playerID(){return 0;}
+    unsigned int playerID(){return 0;}
     
     bool addClient(ENetEvent *event);
@@ -85,5 +86,6 @@
     bool processPacket( ENetPacket *packet, ENetPeer *peer );
     bool sendGameState();
-    
+    bool sendObjectDeletes();
+    virtual bool chat(std::string message);
     
     //void processChat( chat *data, int clientId);
Index: code/trunk/src/network/Synchronisable.cc
===================================================================
--- code/trunk/src/network/Synchronisable.cc	(revision 1906)
+++ code/trunk/src/network/Synchronisable.cc	(revision 1907)
@@ -51,5 +51,8 @@
 namespace network
 {
-
+  
+
+  std::map<unsigned int, Synchronisable *> Synchronisable::objectMap_;
+  std::queue<unsigned int> Synchronisable::deletedObjects_;
 
   int Synchronisable::state_=0x1; // detemines wheter we are server (default) or client
@@ -57,31 +60,53 @@
   /**
   * Constructor:
-  * calls registarAllVariables, that has to be implemented by the inheriting classID
+  * Initializes all Variables and sets the right objectID
   */
   Synchronisable::Synchronisable(){
     RegisterRootObject(Synchronisable);
-    static int idCounter=0;
-    datasize=0;
+    static uint32_t idCounter=0;
     objectFrequency_=1;
-    objectMode_=0x1; // by default do not send data to servere
+    objectMode_=0x1; // by default do not send data to server
     objectID=idCounter++;
     syncList = new std::list<synchronisableVariable *>;
-    //registerAllVariables();
-  }
-
+  }
+
+  /**
+   * Destructor: 
+   * Delete all callback objects and remove objectID from the objectMap_
+   */
   Synchronisable::~Synchronisable(){
     // delete callback function objects
-    if(!orxonox::Identifier::isCreatingHierarchy())
+    if(!orxonox::Identifier::isCreatingHierarchy()){
       for(std::list<synchronisableVariable *>::iterator it = syncList->begin(); it!=syncList->end(); it++)
         delete (*it)->callback;
-  }
-
+      deletedObjects_.push(objectID);
+//       COUT(3) << "destruct synchronisable +++" << objectID << " | " << classID << std::endl;
+//       COUT(3) << " bump ---" << objectID << " | " << &objectMap_ << std::endl;
+//       assert(objectMap_[objectID]->objectID==objectID);
+//       objectMap_.erase(objectID);
+    }
+  }
+
+  /**
+   * This function gets called after all neccessary data has been passed to the object
+   * Overload this function and recall the create function of the parent class
+   * @return true/false
+   */
   bool Synchronisable::create(){
     this->classID = this->getIdentifier()->getNetworkID();
-    COUT(4) << "creating synchronisable: setting classid from " << this->getIdentifier()->getName() << " to: " << classID << std::endl;
+//     COUT(4) << "creating synchronisable: setting classid from " << this->getIdentifier()->getName() << " to: " << classID << std::endl;
+    
+//     COUT(3) << "construct synchronisable +++" << objectID << " | " << classID << std::endl;
+//     objectMap_[objectID]=this;
+//     assert(objectMap_[objectID]==this);
+//     assert(objectMap_[objectID]->objectID==objectID);
     return true;
   }
 
 
+  /**
+   * This function sets the internal mode for synchronisation
+   * @param b true if this object is located on a client or on a server
+   */
   void Synchronisable::setClient(bool b){
     if(b) // client
@@ -91,41 +116,74 @@
   }
 
-  bool Synchronisable::fabricate(unsigned char*& mem, int mode)
+  /**
+   * This function fabricated a new synchrnisable (and children of it), sets calls updateData and create
+   * After calling this function the mem pointer will be increased by the size of the needed data
+   * @param mem pointer to where the appropriate data is located
+   * @param mode defines the mode, how the data should be loaded
+   * @return pointer to the newly created synchronisable
+   */
+  Synchronisable *Synchronisable::fabricate(uint8_t*& mem, int mode)
   {
-    unsigned int size, objectID, classID;
-    size = *(unsigned int *)mem;
-    objectID = *(unsigned int*)(mem+sizeof(unsigned int));
-    classID = *(unsigned int*)(mem+2*sizeof(unsigned int));
-
-    if(size==3*sizeof(unsigned int)){ //not our turn, dont do anything
-      mem+=3*sizeof(unsigned int);
-      return true;
-    }
-
-    orxonox::Identifier* id = ClassByID(classID);
-    if(!id){
-      COUT(3) << "We could not identify a new object; classid: " << classID << " uint: " << (unsigned int)classID << " objectID: " << objectID << " size: " << size << std::endl;
-      assert(0);
-      return false; // most probably the gamestate is corrupted
-    }
+    synchronisableHeader *header = (synchronisableHeader *)mem;
+
+    COUT(3) << "fabricating object with id: " << header->objectID << std::endl;
+
+    orxonox::Identifier* id = ClassByID(header->classID);
+    assert(id);
     orxonox::BaseObject *bo = id->fabricate();
     Synchronisable *no = dynamic_cast<Synchronisable *>(bo);
     assert(no);
-    no->objectID=objectID;
-    no->classID=classID;
+    no->objectID=header->objectID;
+    no->classID=header->classID;
     COUT(3) << "fabricate objectID: " << no->objectID << " classID: " << no->classID << std::endl;
           // update data and create object/entity...
-    if( !no->updateData(mem, mode) ){
-      COUT(1) << "We couldn't update the object: " << objectID << std::endl;
+    bool b = no->updateData(mem, mode);
+    assert(b);
+    b = no->create();
+    assert(b);
+    return no;
+  }
+
+  
+  /**
+   * Finds and deletes the Synchronisable with the appropriate objectID
+   * @param objectID objectID of the Synchronisable
+   * @return true/false
+   */
+  bool Synchronisable::deleteObject(unsigned int objectID){
+//     assert(getSynchronisable(objectID));
+    if(!getSynchronisable(objectID))
       return false;
-    }
-    if( !no->create() )
-    {
-      COUT(1) << "We couldn't manifest (create() ) the object: " << objectID << std::endl;
+    assert(getSynchronisable(objectID)->objectID==objectID);
+//     delete objectMap_[objectID];
+    Synchronisable *s = getSynchronisable(objectID);
+    if(s)
+      delete s;
+    else
       return false;
-    }
     return true;
   }
-
+  
+  /**
+   * This function looks up the objectID in the objectMap_ and returns a pointer to the right Synchronisable
+   * @param objectID objectID of the Synchronisable
+   * @return pointer to the Synchronisable with the objectID
+   */
+  Synchronisable* Synchronisable::getSynchronisable(unsigned int objectID){
+    orxonox::ObjectList<Synchronisable>::iterator it;
+    for(it = orxonox::ObjectList<Synchronisable>::begin(); it; ++it){
+      if( it->getObjectID()==objectID )
+           return *it;
+    }
+    return NULL;
+
+//     std::map<unsigned int, Synchronisable *>::iterator i = objectMap_.find(objectID);
+//     if(i==objectMap_.end())
+//       return NULL;
+//     assert(i->second->objectID==objectID);
+//     return (*i).second;
+  }
+
+  
   /**
   * This function is used to register a variable to be synchronized
@@ -133,4 +191,7 @@
   * @param var pointer to the variable
   * @param size size of the datatype the variable consists of
+  * @param t the type of the variable (network::DATA or network::STRING
+  * @param mode same as in getData
+  * @param cb callback object that should get called, if the value of the variable changes
   */
   void Synchronisable::registerVar(void *var, int size, variableType t, int mode, NetworkCallbackBase *cb){
@@ -143,22 +204,34 @@
     temp->callback = cb;
     COUT(5) << "Syncronisable::registering var with size: " << temp->size << " and type: " << temp->type << std::endl;
-    // increase datasize
-    datasize+=sizeof(int)+size;
     //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);
-  }
-
-  /**
-   * This function takes all SynchronisableVariables out of the Synchronisable and saves it into a syncData struct
-   * Difference to the above function:
+#ifndef NDEBUG
+    std::list<synchronisableVariable *>::iterator it = syncList->begin();
+    while(it!=syncList->end()){
+      assert(*it!=var);
+      it++;
+    }
+#endif
+  }
+
+  /**
+   * This function takes all SynchronisableVariables out of the Synchronisable and saves them together with the size, objectID and classID to the given memory
    * takes a pointer to already allocated memory (must have at least getSize bytes length)
    * structure of the bitstream:
-   * (var1_size,var1,var2_size,var2,...)
-   * varx_size: size = sizeof(int)
-   * varx: size = varx_size
-   * @return data containing all variables and their sizes
-   */
-  bool Synchronisable::getData(unsigned char*& mem, unsigned int id, int mode){
+   * |totalsize,objectID,classID,var1,var2,string1_length,string1,var3,...|
+   * length of varx: size saved int syncvarlist
+   * @param mem pointer to allocated memory with enough size
+   * @param id gamestateid of the gamestate to be saved (important for priorities)
+   * @param mode defines the direction in which the data will be send/received
+   *             0x1: server->client
+   *             0x2: client->server (not recommended)
+   *             0x3: bidirectional
+   * @return true: if !isMyTick or if everything was successfully saved
+   */
+  bool Synchronisable::getData(uint8_t*& mem, unsigned int id, int mode){
+    //if this tick is we dont synchronise, then abort now
+    if(!isMyTick(id))
+      return true;
     //std::cout << "inside getData" << std::endl;
     unsigned int tempsize = 0;
@@ -167,27 +240,24 @@
     if(classID==0)
       COUT(3) << "classid 0 " << this->getIdentifier()->getName() << std::endl;
-    this->classID=this->getIdentifier()->getNetworkID(); // TODO: correct this
+    assert(this->classID==this->getIdentifier()->getNetworkID());
+//     this->classID=this->getIdentifier()->getNetworkID(); // TODO: correct this
     std::list<synchronisableVariable *>::iterator i;
     unsigned int size;
-    size=getSize2(id, mode);
+    size=getSize(id, mode);
 
     // start copy header
-    memcpy(mem, &size, sizeof(unsigned int));
-    mem+=sizeof(unsigned int);
-    memcpy(mem, &(this->objectID), sizeof(unsigned int));
-    mem+=sizeof(unsigned int);
-    memcpy(mem, &(this->classID), sizeof(unsigned int));
-    mem+=sizeof(unsigned int);
-    tempsize+=12;
+    synchronisableHeader *header = (synchronisableHeader *)mem;
+    header->size = size;
+    header->objectID = this->objectID;
+    header->classID = this->classID;
+    header->dataAvailable = true;
+    tempsize+=sizeof(synchronisableHeader);
+    mem+=sizeof(synchronisableHeader);
     // end copy header
 
-    //if this tick is we dont synchronise, then abort now
-    if(!isMyTick(id))
-      return true;
 
     COUT(5) << "Synchronisable getting data from objectID: " << objectID << " classID: " << classID << " length: " << size << std::endl;
     // copy to location
     for(i=syncList->begin(); i!=syncList->end(); ++i){
-      //(std::memcpy(retVal.data+n, (const void*)(&(i->size)), sizeof(int));
       if( ((*i)->mode & mode) == 0 ){
         COUT(5) << "not getting data: " << std::endl;
@@ -217,10 +287,10 @@
 
   /**
-   * This function takes a syncData struct and takes it to update the variables
-   * @param vars data of the variables
+   * This function takes a bytestream and loads the data into the registered variables
+   * @param mem pointer to the bytestream
+   * @param mode same as in getData
    * @return true/false
    */
-  bool Synchronisable::updateData(unsigned char*& mem, int mode){
-    unsigned char *data = mem;
+  bool Synchronisable::updateData(uint8_t*& mem, int mode){
     if(mode==0x0)
       mode=state_;
@@ -231,21 +301,20 @@
     }
 
+    uint8_t *data=mem;
     // start extract header
-    unsigned int objectID, classID, size;
-    size = *(int *)mem;
-    mem+=sizeof(size);
-    objectID = *(int *)mem;
-    mem+=sizeof(objectID);
-    classID = *(int *)mem;
-    mem+=sizeof(classID);
+    synchronisableHeader *syncHeader = (synchronisableHeader *)mem;
+    assert(syncHeader->objectID==this->objectID);
+    if(syncHeader->dataAvailable==false){
+      mem+=syncHeader->size;
+      return true;
+    }
+
+    mem+=sizeof(synchronisableHeader);
     // stop extract header
-    assert(this->objectID==objectID);
-    assert(this->classID==classID);
-    if(size==3*sizeof(unsigned int)) //if true, only the header is available
-      return true;
-      //assert(0);
-
-    COUT(5) << "Synchronisable: objectID " << objectID << ", classID " << classID << " size: " << size << " synchronising data" << std::endl;
-    for(i=syncList->begin(); i!=syncList->end() && mem <= data+size; i++){
+    assert(this->objectID==syncHeader->objectID);
+//    assert(this->classID==syncHeader->classID); //TODO: fix this!!! maybe a problem with the identifier ?
+    
+    COUT(5) << "Synchronisable: objectID " << syncHeader->objectID << ", classID " << syncHeader->classID << " size: " << syncHeader->size << " synchronising data" << std::endl;
+    for(i=syncList->begin(); i!=syncList->end() && mem <= data+syncHeader->size; i++){
       if( ((*i)->mode ^ mode) == 0 ){
         COUT(5) << "synchronisable: not updating variable " << std::endl;
@@ -263,5 +332,5 @@
           break;
         case STRING:
-          (*i)->size = *(int *)mem;
+          (*i)->size = *(uint32_t *)mem;
           COUT(5) << "string size: " << (*i)->size << std::endl;
           mem+=sizeof(int);
@@ -283,10 +352,12 @@
   /**
   * This function returns the total amount of bytes needed by getData to save the whole content of the variables
+  * @param id id of the gamestate
+  * @param mode same as getData
   * @return amount of bytes
   */
-  int Synchronisable::getSize(unsigned int id, int mode){
+  uint32_t Synchronisable::getSize(unsigned int id, int mode){
     if(!isMyTick(id))
       return 0;
-    int tsize=0;
+    int tsize=sizeof(synchronisableHeader);
     if(mode==0x0)
       mode=state_;
@@ -311,35 +382,34 @@
 
   /**
-   * This function returns the total amount of bytes needed by getData to save the whole content of the variables
-   * @return amount of bytes
-   */
-  int Synchronisable::getSize2(unsigned int id, int mode){
-    return sizeof(synchronisableHeader) + getSize( id, mode );
-  }
-
-  /**
-   *
-   * @param id
-   * @return
+   * This function determines, wheter the object should be saved to the bytestream (according to its syncmode/direction)
+   * @param id gamestate id
+   * @return true/false
    */
   bool Synchronisable::isMyTick(unsigned int id){
-//     return true;
+    return ( (objectMode_&state_)!=0 );
+  }
+
+  bool Synchronisable::doSelection(unsigned int id){
     return ( id==0 || id%objectFrequency_==objectID%objectFrequency_ ) && ((objectMode_&state_)!=0);
   }
 
-  bool Synchronisable::isMyData(unsigned char* mem)
+  /**
+   * This function looks at the header located in the bytestream and checks wheter objectID and classID match with the Synchronisables ones
+   * @param mem pointer to the bytestream
+   */
+  bool Synchronisable::isMyData(uint8_t* mem)
   {
-    unsigned int objectID, classID, size;
-    size = *(int *)mem;
-    mem+=sizeof(size);
-    objectID = *(int *)mem;
-    mem+=sizeof(objectID);
-    classID = *(int *)mem;
-    mem+=sizeof(classID);
-
-    assert(classID == this->classID);
-    return (objectID == this->objectID);
-  }
-
+    synchronisableHeader *header = (synchronisableHeader *)mem;
+    assert(header->objectID==this->objectID);
+    return header->dataAvailable;
+  }
+
+  /**
+   * This function sets the synchronisation mode of the object
+   * If set to 0x1 variables will only be synchronised to the client
+   * If set to 0x2 variables will only be synchronised to the server
+   * If set to 0x3 variables will be synchronised bidirectionally (only if set so in registerVar)
+   * @param mode same as in registerVar
+   */
   void Synchronisable::setObjectMode(int mode){
     assert(mode==0x1 || mode==0x2 || mode==0x3);
Index: code/trunk/src/network/Synchronisable.h
===================================================================
--- code/trunk/src/network/Synchronisable.h	(revision 1906)
+++ code/trunk/src/network/Synchronisable.h	(revision 1907)
@@ -33,10 +33,37 @@
 
 #include <list>
+#include <map>
+#include <queue>
 #include "core/OrxonoxClass.h"
 #include "core/XMLIncludes.h"
 #include "NetworkCallback.h"
 
+#define REGISTERDATA(varname) registerVar(&varname, sizeof(varname), network::DATA)
+#define REGISTERDATA_WITHDIR(varname, mode) registerVar(&varname, sizeof(varname), network::DATA, mode)
+#define REGISTERSTRING(stringname) registerVar(&stringname, stringname.length()+1, network::STRING)
+#define REGISTERSTRING_WITHDIR(stringname, mode) registerVar(&stringname, stringname.length()+1, network::STRING, mode)
+
+//TODO: this is only a very ugly hack ...
+namespace orxonox{
+class SpaceShip;
+}
+
 namespace network
 {
+  namespace direction{
+    enum syncdirection{
+      toclient=0x1,
+      toserver=0x2,
+      bidirectional=0x3
+    };
+  }
+  
+  namespace syncmode{
+    enum mode{
+      one=0,
+      always=1
+    };
+  }
+  
   enum variableType{
     DATA,
@@ -45,7 +72,8 @@
 
   struct synchronisableHeader{
-    unsigned int size;
-    unsigned int objectID;
-    unsigned int classID;
+    uint32_t size:31;
+    bool dataAvailable:1;
+    uint32_t objectID;
+    uint32_t classID;
   };
 
@@ -58,42 +86,55 @@
   }SYNCVAR;
 
-
   /**
   * This class is the base class of all the Objects in the universe that need to be synchronised over the network
-   * Every class, t
-  int mode;hat inherits from this class has to link the DATA THAT NEEDS TO BE SYNCHRONISED into the linked list. Additionally it also has to provide a Constructor, that takes exactly the variables in this linked list.
+   * Every class, that inherits from this class has to link the DATA THAT NEEDS TO BE SYNCHRONISED into the linked list.
   * @author Oliver Scheuss
   */
   class _NetworkExport Synchronisable : virtual public orxonox::OrxonoxClass{
   public:
+    friend class packet::Gamestate;
+    friend class GamestateClient;
+    friend class Server;
+    friend class orxonox::SpaceShip;
+    virtual ~Synchronisable();
+
     
-    virtual ~Synchronisable();
-    unsigned int objectID;
-    unsigned int classID;
-
-    void registerVar(void *var, int size, variableType t, int mode=1, NetworkCallbackBase *cb=0);
-    bool getData(unsigned char*& men, unsigned int id, int mode=0x0);
-    int getSize2(unsigned int id, int mode=0x0);
-    bool updateData(unsigned char*& mem, int mode=0x0);
-    bool isMyData(unsigned char* mem);
-    void setObjectMode(int mode);
-    void setObjectFrequency(unsigned int freq){ objectFrequency_ = freq; }
-    
-    virtual void registerAllVariables()=0;
     virtual bool create();
     static void setClient(bool b);
     
-    static bool fabricate(unsigned char*& mem, int mode=0x0);
+    static Synchronisable *fabricate(uint8_t*& mem, int mode=0x0);
+    static bool deleteObject(unsigned int objectID);
+    static Synchronisable *getSynchronisable(unsigned int objectID);
+    static unsigned int getNumberOfDeletedObject(){ return deletedObjects_.size(); }
+    static unsigned int popDeletedObject(){ unsigned int i = deletedObjects_.front(); deletedObjects_.pop(); return i; }
+    
+    inline unsigned int getObjectID(){return objectID;}
+    inline unsigned int getClassID(){return classID;}
   protected:
     Synchronisable();
+    void registerVar(void *var, int size, variableType t, int mode=1, NetworkCallbackBase *cb=0);
+    void setObjectMode(int mode);
+    void setObjectFrequency(unsigned int freq){ objectFrequency_ = freq; }
+    virtual void registerAllVariables()=0;
+    
+    
   private:
-    int getSize(unsigned int id, int mode=0x0);
+    bool getData(uint8_t*& men, unsigned int id, int mode=0x0);
+    uint32_t getSize(unsigned int id, int mode=0x0);
+    bool updateData(uint8_t*& mem, int mode=0x0);
+    bool isMyData(uint8_t* mem);
+    bool doSelection(unsigned int id);
     bool isMyTick(unsigned int id);
+    
+    unsigned int objectID;
+    unsigned int classID;
+    
     std::list<synchronisableVariable *> *syncList;
-    int datasize;
     static int state_; // detemines wheter we are server (default) or client
     bool backsync_; // if true the variables with mode > 1 will be synchronised to server (client -> server)
     unsigned int objectFrequency_;
     int objectMode_;
+    static std::map<unsigned int, Synchronisable *> objectMap_;
+    static std::queue<unsigned int> deletedObjects_;
   };
 }
Index: code/trunk/src/network/packet/Acknowledgement.cc
===================================================================
--- code/trunk/src/network/packet/Acknowledgement.cc	(revision 1906)
+++ code/trunk/src/network/packet/Acknowledgement.cc	(revision 1907)
@@ -40,15 +40,15 @@
 #define _ACKID              _PACKETID + sizeof(network::packet::ENUM::Type)
   
-Acknowledgement::Acknowledgement( unsigned int id, int clientID )
+Acknowledgement::Acknowledgement( unsigned int id, unsigned int clientID )
  : Packet()
 {
   flags_ = flags_ | PACKET_FLAGS_ACK;
-  data_=new unsigned char[ getSize() ];
+  data_=new uint8_t[ getSize() ];
   *(ENUM::Type *)(data_ + _PACKETID ) = ENUM::Acknowledgement;
-  *(unsigned int *)(data_ + _ACKID ) = id;
+  *(uint32_t *)(data_ + _ACKID ) = id;
   clientID_=clientID;
 }
 
-Acknowledgement::Acknowledgement( unsigned char *data, int clientID )
+Acknowledgement::Acknowledgement( uint8_t *data, unsigned int clientID )
   : Packet(data, clientID)
 {
@@ -60,5 +60,5 @@
 
 unsigned int Acknowledgement::getSize() const{
-  return _ACKID + sizeof(unsigned int);
+  return _ACKID + sizeof(uint32_t);
 }
 
@@ -70,5 +70,5 @@
 
 unsigned int Acknowledgement::getAckID(){
-  return *(unsigned int *)(data_ + _ACKID);
+  return *(uint32_t *)(data_ + _ACKID);
 }
 
Index: code/trunk/src/network/packet/Acknowledgement.h
===================================================================
--- code/trunk/src/network/packet/Acknowledgement.h	(revision 1906)
+++ code/trunk/src/network/packet/Acknowledgement.h	(revision 1907)
@@ -40,6 +40,6 @@
 {
 public:
-  Acknowledgement( unsigned int id, int clientID );
-  Acknowledgement( unsigned char* data, int clientID );
+  Acknowledgement( unsigned int id, unsigned int clientID );
+  Acknowledgement( uint8_t* data, unsigned int clientID );
   ~Acknowledgement();
   
Index: code/trunk/src/network/packet/Chat.cc
===================================================================
--- code/trunk/src/network/packet/Chat.cc	(revision 1906)
+++ code/trunk/src/network/packet/Chat.cc	(revision 1907)
@@ -29,14 +29,16 @@
 #include "Chat.h"
 #include <assert.h>
+#include "network/Host.h"
 
 namespace network {
 namespace packet {
   
-#define PACKET_FLAGS_CHAT ENET_PACKET_FLAG_RELIABLE
-#define _PACKETID         0
-#define _MESSAGELENGTH    _PACKETID + sizeof(ENUM::Type)
-#define _MESSAGE          _MESSAGELENGTH + sizeof(unsigned int)
+#define   PACKET_FLAGS_CHAT ENET_PACKET_FLAG_RELIABLE
+#define   _PACKETID         0
+const int _PLAYERID     =   _PACKETID + sizeof(ENUM::Type);
+#define   _MESSAGELENGTH    _PLAYERID + sizeof(uint32_t)
+#define   _MESSAGE          _MESSAGELENGTH + sizeof(uint32_t)
 
-Chat::Chat( std::string& message, int clientID )
+Chat::Chat( std::string message, unsigned int playerID )
  : Packet()
 {
@@ -44,14 +46,14 @@
   messageLength_ = message.length()+1;
   data_=new unsigned char[ getSize() ];
-  *(ENUM::Type *)&data_[ _PACKETID ] = ENUM::Chat;
-  *(unsigned int *)&data_[ _MESSAGELENGTH ] = messageLength_;
-  memcpy( &data_[ _MESSAGE ], (void *)message.c_str(), messageLength_ );
-  clientID_=clientID;
+  *(ENUM::Type *)(data_ + _PACKETID ) = ENUM::Chat;
+  *(unsigned int *)(data_ + _PLAYERID ) = playerID;
+  *(unsigned int *)(data_ + _MESSAGELENGTH ) = messageLength_;
+  memcpy( data_+_MESSAGE, (void *)message.c_str(), messageLength_ );
 }
 
-Chat::Chat( unsigned char *data, int clientID )
+Chat::Chat( uint8_t* data, unsigned int clientID )
   : Packet(data, clientID)
 {
-  messageLength_ = *(unsigned int *)&data[ _MESSAGELENGTH ];
+  messageLength_ = *(uint32_t *)(data + _MESSAGELENGTH );
 }
 
@@ -65,12 +67,11 @@
 
 bool Chat::process(){
-  //TODO: change this !!!
-  assert(0);
+  bool b = Host::incomingChat(std::string((const char*)data_+_MESSAGE), *(uint32_t *)(data_+_PLAYERID));
   delete this;
-  return true;
+  return b;
 }
 
 unsigned char *Chat::getMessage(){
-  return &data_[ _MESSAGE ];
+  return data_ + _MESSAGE;
 }
 
Index: code/trunk/src/network/packet/Chat.h
===================================================================
--- code/trunk/src/network/packet/Chat.h	(revision 1906)
+++ code/trunk/src/network/packet/Chat.h	(revision 1907)
@@ -16,6 +16,6 @@
 {
 public:
-  Chat( std::string& message, int clientID );
-  Chat( unsigned char* data, int clientID );
+  Chat( std::string message, unsigned int playerID );
+  Chat( uint8_t* data, unsigned int clientID );
   ~Chat();
   
@@ -26,6 +26,6 @@
   unsigned char *getMessage();
 private:
-  unsigned int messageLength_;
-  int clientID_;
+  uint32_t messageLength_;
+  unsigned int clientID_;
 };
 
Index: code/trunk/src/network/packet/ClassID.cc
===================================================================
--- code/trunk/src/network/packet/ClassID.cc	(revision 1906)
+++ code/trunk/src/network/packet/ClassID.cc	(revision 1907)
@@ -40,5 +40,5 @@
 #define _PACKETID             0
 #define _CLASSID              _PACKETID + sizeof(ENUM::Type)
-#define _CLASSNAMELENGTH      _CLASSID + sizeof(unsigned int)
+#define _CLASSNAMELENGTH      _CLASSID + sizeof(uint32_t)
 #define _CLASSNAME            _CLASSNAMELENGTH + sizeof(classNameLength_)
 
@@ -57,5 +57,5 @@
 }
 
-ClassID::ClassID( unsigned char *data, int clientID )
+ClassID::ClassID( uint8_t* data, unsigned int clientID )
   : Packet(data, clientID)
 {
@@ -68,5 +68,5 @@
 
 unsigned int ClassID::getSize() const{
-  return sizeof(network::packet::ENUM::Type) + 2*sizeof(unsigned int) + classNameLength_;
+  return sizeof(network::packet::ENUM::Type) + 2*sizeof(uint32_t) + classNameLength_;
 }
 
@@ -82,5 +82,5 @@
 
 unsigned int ClassID::getClassID(){
-  return *(unsigned int *)&data_[ _CLASSID ];
+  return *(uint32_t *)(data_ + _CLASSID);
 }
 
Index: code/trunk/src/network/packet/ClassID.h
===================================================================
--- code/trunk/src/network/packet/ClassID.h	(revision 1906)
+++ code/trunk/src/network/packet/ClassID.h	(revision 1907)
@@ -43,5 +43,5 @@
 public:
   ClassID( unsigned int classID, std::string className );
-  ClassID( unsigned char* data, int clientID );
+  ClassID( uint8_t* data, unsigned int clientID );
   ~ClassID();
   
@@ -53,5 +53,5 @@
   unsigned char *getClassName();
 private:
-  unsigned int classNameLength_;
+  uint32_t classNameLength_;
 };
 
Index: code/trunk/src/network/packet/DeleteObjects.cc
===================================================================
--- code/trunk/src/network/packet/DeleteObjects.cc	(revision 1907)
+++ code/trunk/src/network/packet/DeleteObjects.cc	(revision 1907)
@@ -0,0 +1,97 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Oliver Scheuss, (C) 2008
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+
+#include "DeleteObjects.h"
+#include <enet/enet.h>
+#include "network/Synchronisable.h"
+#include "core/CoreIncludes.h"
+#include <assert.h>
+
+namespace network {
+namespace packet {
+
+#define PACKET_FLAG_DELETE  ENET_PACKET_FLAG_RELIABLE
+#define _PACKETID           0
+#define _QUANTITY           _PACKETID + sizeof(ENUM::Type)
+#define _OBJECTIDS          _QUANTITY + sizeof(uint32_t)
+  
+DeleteObjects::DeleteObjects()
+ : Packet()
+{
+  flags_ = flags_ | PACKET_FLAG_DELETE;
+}
+
+DeleteObjects::DeleteObjects( uint8_t *data, unsigned int clientID )
+  : Packet(data, clientID)
+{
+}
+
+DeleteObjects::~DeleteObjects()
+{
+}
+
+bool DeleteObjects::fetchIDs(){
+  unsigned int number = Synchronisable::getNumberOfDeletedObject();
+  if(number==0)
+    return false;
+  COUT(3) << "sending DeleteObjects: ";
+  unsigned int size = sizeof(ENUM::Type) + sizeof(uint32_t)*(number+1);
+  data_ = new uint8_t[size];
+  uint8_t *tdata = data_;
+  *(ENUM::Type *)(tdata) = ENUM::DeleteObjects;
+  tdata += sizeof(ENUM::Type);
+  *(uint32_t *)tdata = number;
+  tdata += sizeof(uint32_t);
+  for(unsigned int i=0; i<number; i++){
+    unsigned int temp = Synchronisable::popDeletedObject();
+//     assert(temp<10000); //ugly hack
+    *(uint32_t *)(tdata) = temp;
+    COUT(3) << temp << " ";
+    tdata += sizeof(uint32_t);
+  }
+  COUT(3) << std::endl;
+  return true;
+}
+
+unsigned int DeleteObjects::getSize() const{
+  assert(data_);
+  return _OBJECTIDS + *(uint32_t*)(data_+_QUANTITY)*sizeof(uint32_t);
+}
+
+bool DeleteObjects::process(){
+  for(unsigned int i=0; i<*(unsigned int *)(data_+_QUANTITY); i++){
+    COUT(3) << "deleting object with id: " << *(uint32_t*)(data_+_OBJECTIDS+i*sizeof(uint32_t)) << std::endl;
+    Synchronisable::deleteObject( *(uint32_t*)(data_+_OBJECTIDS+i*sizeof(uint32_t)) );
+  }
+  return true;
+}
+
+
+} //namespace packet
+} //namespace network
Index: code/trunk/src/network/packet/DeleteObjects.h
===================================================================
--- code/trunk/src/network/packet/DeleteObjects.h	(revision 1907)
+++ code/trunk/src/network/packet/DeleteObjects.h	(revision 1907)
@@ -0,0 +1,57 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Oliver Scheuss <scheusso [at] ee.ethz.ch>, (C) 2008
+ *   Co-authors:
+ *      ...
+ *
+ */
+#ifndef NETWORKPACKETDELETEOBJECTS_H
+#define NETWORKPACKETDELETEOBJECTS_H
+
+#include "Packet.h"
+
+
+namespace network {
+namespace packet {
+/**
+	@author 
+*/
+class DeleteObjects : public Packet
+{
+public:
+  DeleteObjects( );
+  DeleteObjects( uint8_t* data, unsigned int clientID );
+  ~DeleteObjects();
+  
+  bool fetchIDs();
+  
+  inline unsigned int getSize() const;
+  bool process();
+  
+private:
+};
+
+} //namespace packet
+} //namespace network
+
+#endif
Index: code/trunk/src/network/packet/Gamestate.cc
===================================================================
--- code/trunk/src/network/packet/Gamestate.cc	(revision 1906)
+++ code/trunk/src/network/packet/Gamestate.cc	(revision 1907)
@@ -46,11 +46,22 @@
 #define HEADER GAMESTATE_HEADER(data_)
 
+  
+#define PACKET_FLAG_GAMESTATE  ENET_PACKET_FLAG_RELIABLE
+  
 Gamestate::Gamestate()
 {
-}
-
-Gamestate::Gamestate(unsigned char *data, int clientID):
+  flags_ = flags_ | PACKET_FLAG_GAMESTATE;
+}
+
+Gamestate::Gamestate(uint8_t *data, unsigned int clientID):
     Packet(data, clientID)
 {
+  flags_ = flags_ | PACKET_FLAG_GAMESTATE;
+}
+
+Gamestate::Gamestate(uint8_t *data)
+{
+  flags_ = flags_ | PACKET_FLAG_GAMESTATE;
+  data_=data;
 }
 
@@ -74,11 +85,15 @@
     return false;
   }
-
+  
+#ifndef NDEBUG
+  std::list<Synchronisable*> slist;
+  std::list<Synchronisable*>::iterator iit;
+#endif
   //start collect data synchronisable by synchronisable
-  unsigned char *mem=data_;
+  uint8_t *mem=data_;
   mem+=sizeof(GamestateHeader);
   orxonox::ObjectList<Synchronisable>::iterator it;
   for(it = orxonox::ObjectList<Synchronisable>::begin(); it; ++it){
-    tempsize=it->getSize2(id, mode);
+    tempsize=it->getSize(id, mode);
 
     if(currentsize+tempsize > size){
@@ -88,6 +103,6 @@
       int addsize=tempsize;
       while(++temp)
-        addsize+=temp->getSize2(id, mode);
-      data_ = (unsigned char *)realloc(data_, sizeof(GamestateHeader) + currentsize + addsize);
+        addsize+=temp->getSize(id, mode);
+      data_ = (uint8_t *)realloc(data_, sizeof(GamestateHeader) + currentsize + addsize);
       if(!data_)
         return false;
@@ -95,4 +110,12 @@
     }// stop allocate additional memory
 
+#ifndef NDEBUG
+    for(iit=slist.begin(); iit!=slist.end(); iit++)
+      assert((*iit)!=*it);
+    slist.push_back(*it);
+#endif
+    
+    //if(it->doSelection(id))
+    dataMap_[mem-data_]=(*it);  // save the mem location of the synchronisable data
     if(!it->getData(mem, id, mode))
       return false; // mem pointer gets automatically increased because of call by reference
@@ -105,5 +128,5 @@
   HEADER->packetType = ENUM::Gamestate;
   assert( *(ENUM::Type *)(data_) == ENUM::Gamestate);
-  HEADER->normsize = currentsize;
+  HEADER->datasize = currentsize;
   HEADER->id = id;
   HEADER->diffed = false;
@@ -122,47 +145,34 @@
   assert(!HEADER->compressed);
   assert(!HEADER->diffed);
-  unsigned int size, objectID, classID;
-  unsigned char *mem=data_+sizeof(GamestateHeader);
+  uint8_t *mem=data_+sizeof(GamestateHeader);
     // get the start of the Synchronisable list
-  orxonox::ObjectList<Synchronisable>::iterator it=orxonox::ObjectList<Synchronisable>::begin();
-
-  while(mem < data_+sizeof(GamestateHeader)+HEADER->normsize){
-      // extract synchronisable header
-    size = *(unsigned int *)mem;
-    objectID = *(unsigned int*)(mem+sizeof(unsigned int));
-    classID = *(unsigned int*)(mem+2*sizeof(unsigned int));
-
-    if(!it || it->objectID!=objectID || it->classID!=classID){
-        // bad luck ;)
-        // delete the synchronisable (obviously seems to be deleted on the server)
-      while(it && it->objectID!=objectID)
-        removeObject(it);
-
-      if(!it){
-        //fabricate the new synchronisable
-        if(!Synchronisable::fabricate(mem, mode))
-          return false;
-        it=orxonox::ObjectList<Synchronisable>::end();
-      }else{
-	if(! it->updateData(mem, mode))
-        {
-          COUT(1) << "We couldn't update objectID: " \
-            << objectID << "; classID: " << classID << std::endl;
-        }
-      }
-    } else
+  //orxonox::ObjectList<Synchronisable>::iterator it=orxonox::ObjectList<Synchronisable>::begin();
+  Synchronisable *s;
+
+  // update the data of the objects we received
+  while(mem < data_+sizeof(GamestateHeader)+HEADER->datasize){
+    synchronisableHeader *objectheader = (synchronisableHeader*)mem;
+
+    s = Synchronisable::getSynchronisable( objectheader->objectID );
+    if(!s)
     {
-        // we have our object
-      if(! it->updateData(mem, mode))
-      {
-        COUT(1) << "We couldn't update objectID: " \
-            << objectID << "; classID: " << classID << std::endl;
-      }
-    }
-    ++it;
+      s = Synchronisable::fabricate(mem, mode);
+      assert(s);
+//       if(!s)
+//         return false;
+    }
+    else
+    {
+      bool b = s->updateData(mem, mode);
+      assert(b);
+      //if(!s->updateData(mem, mode))
+        //return false;
+    }
   }
 
   return true;
 }
+
+
 
 int Gamestate::getID(){
@@ -177,14 +187,14 @@
   else
   {
-    return HEADER->normsize+sizeof(GamestateHeader);
+    return HEADER->datasize+sizeof(GamestateHeader);
   }
 }
 
 bool Gamestate::operator==(packet::Gamestate gs){
-  unsigned char *d1 = data_+sizeof(GamestateHeader);
-  unsigned char *d2 = gs.data_+sizeof(GamestateHeader);
+  uint8_t *d1 = data_+sizeof(GamestateHeader);
+  uint8_t *d2 = gs.data_+sizeof(GamestateHeader);
   assert(!isCompressed());
   assert(!gs.isCompressed());
-  while(d1<data_+HEADER->normsize)
+  while(d1<data_+HEADER->datasize)
   {
     if(*d1!=*d2)
@@ -201,18 +211,20 @@
 }
 
+
+
 bool Gamestate::compressData()
 {
   assert(HEADER);
   assert(!HEADER->compressed);
-  uLongf buffer = (uLongf)(((HEADER->normsize + 12)*1.01)+1);
+  uLongf buffer = (uLongf)(((HEADER->datasize + 12)*1.01)+1);
   if(buffer==0)
     return false;
 
-  unsigned char *ndata = new unsigned char[buffer+sizeof(GamestateHeader)];
-  unsigned char *dest = GAMESTATE_START(ndata);
+  uint8_t *ndata = new uint8_t[buffer+sizeof(GamestateHeader)];
+  uint8_t *dest = GAMESTATE_START(ndata);
   //unsigned char *dest = new unsigned char[buffer];
-  unsigned char *source = GAMESTATE_START(data_);
+  uint8_t *source = GAMESTATE_START(data_);
   int retval;
-  retval = compress( dest, &buffer, source, (uLong)(HEADER->normsize) );
+  retval = compress( dest, &buffer, source, (uLong)(HEADER->datasize) );
   switch ( retval ) {
     case Z_OK: COUT(5) << "G.St.Man: compress: successfully compressed" << std::endl; break;
@@ -223,9 +235,9 @@
 #ifndef NDEBUG
   //decompress and compare the start and the decompressed data
-  unsigned char *rdata = new unsigned char[HEADER->normsize+sizeof(GamestateHeader)];
-  unsigned char *d2 = GAMESTATE_START(rdata);
-  uLongf length2 = HEADER->normsize;
+  uint8_t *rdata = new uint8_t[HEADER->datasize+sizeof(GamestateHeader)];
+  uint8_t *d2 = GAMESTATE_START(rdata);
+  uLongf length2 = HEADER->datasize;
   uncompress(d2, &length2, dest, buffer);
-  for(unsigned int i=0; i<HEADER->normsize; i++){
+  for(unsigned int i=0; i<HEADER->datasize; i++){
     assert(*(source+i)==*(d2+i));
   }
@@ -235,5 +247,5 @@
   //copy and modify header
 #ifndef NDEBUG
-  HEADER->crc32 = calcCRC(data_+sizeof(GamestateHeader), HEADER->normsize);
+  HEADER->crc32 = calcCRC(data_+sizeof(GamestateHeader), HEADER->datasize);
 #endif
   *GAMESTATE_HEADER(ndata) = *HEADER;
@@ -245,5 +257,5 @@
   HEADER->compressed = true;
   assert(HEADER->compressed);
-  COUT(3) << "gamestate compress normsize: " << HEADER->normsize << " compsize: " << HEADER->compsize << std::endl;
+  COUT(3) << "gamestate compress datasize: " << HEADER->datasize << " compsize: " << HEADER->compsize << std::endl;
   return true;
 }
@@ -252,14 +264,14 @@
   assert(HEADER);
   assert(HEADER->compressed);
-  COUT(3) << "GameStateClient: uncompressing gamestate. id: " << HEADER->id << ", baseid: " << HEADER->base_id << ", normsize: " << HEADER->normsize << ", compsize: " << HEADER->compsize << std::endl;
-  unsigned int normsize = HEADER->normsize;
+  COUT(3) << "GameStateClient: uncompressing gamestate. id: " << HEADER->id << ", baseid: " << HEADER->base_id << ", datasize: " << HEADER->datasize << ", compsize: " << HEADER->compsize << std::endl;
+  unsigned int datasize = HEADER->datasize;
   unsigned int compsize = HEADER->compsize;
   unsigned int bufsize;
-  assert(compsize<=normsize);
-  bufsize = normsize;
+  assert(compsize<=datasize);
+  bufsize = datasize;
   assert(bufsize!=0);
-  unsigned char *ndata = new unsigned char[bufsize + sizeof(GamestateHeader)];
-  unsigned char *dest = ndata + sizeof(GamestateHeader);
-  unsigned char *source = data_ + sizeof(GamestateHeader);
+  uint8_t *ndata = new uint8_t[bufsize + sizeof(GamestateHeader)];
+  uint8_t *dest = ndata + sizeof(GamestateHeader);
+  uint8_t *source = data_ + sizeof(GamestateHeader);
   int retval;
   uLongf length=bufsize;
@@ -272,5 +284,5 @@
   }
 #ifndef NDEBUG
-  assert(HEADER->crc32==calcCRC(ndata+sizeof(GamestateHeader), HEADER->normsize));
+  assert(HEADER->crc32==calcCRC(ndata+sizeof(GamestateHeader), HEADER->datasize));
 #endif
 
@@ -282,5 +294,5 @@
   data_ = ndata;
   HEADER->compressed = false;
-  assert(HEADER->normsize==normsize);
+  assert(HEADER->datasize==datasize);
   assert(HEADER->compsize==compsize);
   return true;
@@ -293,19 +305,19 @@
   assert(!HEADER->diffed);
   //unsigned char *basep = base->getGs()/*, *gs = getGs()*/;
-  unsigned char *basep = GAMESTATE_START(base->data_), *gs = GAMESTATE_START(this->data_);
+  uint8_t *basep = GAMESTATE_START(base->data_), *gs = GAMESTATE_START(this->data_);
   unsigned int of=0; // pointers offset
   unsigned int dest_length=0;
-  dest_length=HEADER->normsize;
+  dest_length=HEADER->datasize;
   if(dest_length==0)
     return NULL;
-  unsigned char *ndata = new unsigned char[dest_length*sizeof(unsigned char)+sizeof(GamestateHeader)];
-  unsigned char *dest = ndata + sizeof(GamestateHeader);
-  while(of < GAMESTATE_HEADER(base->data_)->normsize && of < HEADER->normsize){
+  uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+sizeof(GamestateHeader)];
+  uint8_t *dest = ndata + sizeof(GamestateHeader);
+  while(of < GAMESTATE_HEADER(base->data_)->datasize && of < HEADER->datasize){
     *(dest+of)=*(basep+of)^*(gs+of); // do the xor
     ++of;
   }
-  if(GAMESTATE_HEADER(base->data_)->normsize!=HEADER->normsize){
-    unsigned char n=0;
-    if(GAMESTATE_HEADER(base->data_)->normsize < HEADER->normsize){
+  if(GAMESTATE_HEADER(base->data_)->datasize!=HEADER->datasize){
+    uint8_t n=0;
+    if(GAMESTATE_HEADER(base->data_)->datasize < HEADER->datasize){
       while(of<dest_length){
         *(dest+of)=n^*(gs+of);
@@ -324,4 +336,187 @@
 }
 
+Gamestate* Gamestate::doSelection(unsigned int clientID){
+  assert(data_);
+  std::map<unsigned int, Synchronisable *>::iterator it;
+  
+  // allocate memory for new data
+  uint8_t *gdata = new uint8_t[HEADER->datasize+sizeof(GamestateHeader)];
+  // create a gamestate out of it
+  Gamestate *gs = new Gamestate(gdata);
+  uint8_t *newdata = gdata + sizeof(GamestateHeader);
+  uint8_t *origdata = GAMESTATE_START(data_);
+  
+  //copy the GamestateHeader
+  *(GamestateHeader*)gdata = *HEADER;
+  
+  synchronisableHeader *oldobjectheader, *newobjectheader;
+  unsigned int objectOffset;
+  
+  //copy in the zeros
+  for(it=dataMap_.begin(); it!=dataMap_.end(); it++){
+    oldobjectheader = (synchronisableHeader*)origdata;
+    newobjectheader = (synchronisableHeader*)newdata;
+    unsigned int objectsize = oldobjectheader->size;
+    assert(it->second->objectID==oldobjectheader->objectID);
+    *newobjectheader = *oldobjectheader;
+    objectOffset=sizeof(uint8_t)+sizeof(bool); //skip the size and the availableDate variables in the objectheader
+    if(it->second->doSelection(HEADER->id)){
+      newobjectheader->dataAvailable=true; //TODO: probably not neccessary
+      while(objectOffset<objectsize){
+        *(newdata + objectOffset)=*(origdata + objectOffset);    // copy the data
+        objectOffset++;
+      }
+    }else{
+      newobjectheader->dataAvailable=false;
+      while(objectOffset<objectsize){
+        *(newdata+objectOffset)=0;    // set to 0
+        objectOffset++;
+      }
+      assert(objectOffset==objectsize);
+    }
+    newdata += objectsize;
+    origdata += objectsize;
+  }
+  return gs;
+}
+
+
+Gamestate* Gamestate::intelligentDiff(Gamestate *base, unsigned int clientID){
+  // asserts
+  assert(data_);
+  assert(base->data_);
+  assert(!GAMESTATE_HEADER(base->data_)->diffed);
+  assert(!GAMESTATE_HEADER(base->data_)->compressed);
+  assert(!HEADER->compressed);
+  assert(!HEADER->diffed);
+  
+  //preparations
+  std::map<unsigned int, Synchronisable *>::iterator it;
+  uint8_t *origdata, *basedata, *destdata, *ndata;
+  unsigned int objectOffset, streamOffset=0;    //data offset
+  unsigned int minsize = (HEADER->datasize < GAMESTATE_HEADER(base->data_)->datasize) ? HEADER->datasize : GAMESTATE_HEADER(base->data_)->datasize; 
+  synchronisableHeader *origheader;
+  synchronisableHeader *destheader;
+  
+  origdata = GAMESTATE_START(this->data_);
+  basedata = GAMESTATE_START(base->data_);
+  ndata = new uint8_t[HEADER->datasize + sizeof(GamestateHeader)];
+  destdata = ndata + sizeof(GamestateHeader);
+  
+  // do the diff
+  for(it=dataMap_.begin(); it!=dataMap_.end(); it++){
+    assert(streamOffset<HEADER->datasize);
+    bool sendData = it->second->doSelection(HEADER->id);
+    origheader = (synchronisableHeader *)(origdata+streamOffset);
+    destheader = (synchronisableHeader *)(destdata+streamOffset);
+    
+    //copy and partially diff the object header
+    assert(sizeof(synchronisableHeader)==3*sizeof(unsigned int)+sizeof(bool));
+    *(uint32_t*)destdata = *(uint32_t*)origdata; //size (do not diff)
+    *(bool*)(destdata+sizeof(uint32_t)) = sendData;
+    if(sendData){
+      *(uint32_t*)(destdata+sizeof(uint32_t)+sizeof(bool)) = *(uint32_t*)(basedata+sizeof(uint32_t)+sizeof(bool)) ^ *(uint32_t*)(origdata+sizeof(uint32_t)+sizeof(bool)); //objectid (diff it)
+      *(uint32_t*)(destdata+2*sizeof(uint32_t)+sizeof(bool)) = *(uint32_t*)(basedata+2*sizeof(uint32_t)+sizeof(bool)) ^ *(uint32_t*)(origdata+2*sizeof(uint32_t)+sizeof(bool)); //classid (diff it)
+    }else{
+      *(uint32_t*)(destdata+sizeof(uint32_t)+sizeof(bool)) = 0;
+      *(uint32_t*)(destdata+2*sizeof(uint32_t)+sizeof(bool)) = 0; 
+    }
+    objectOffset=sizeof(synchronisableHeader);
+    streamOffset+=sizeof(synchronisableHeader);
+    
+    //now handle the object data or fill with zeros
+    while(objectOffset<origheader->size ){
+      
+      if(sendData && streamOffset<minsize)
+        *(destdata+objectOffset)=*(basedata+objectOffset)^*(origdata+objectOffset); // do the xor
+      else if(sendData)
+        *(destdata+objectOffset)=((uint8_t)0)^*(origdata+objectOffset); // xor with 0 (basestream is too short)
+      else
+        *(destdata+objectOffset)=0; // set to 0 because this object should not be transfered
+      
+      objectOffset++;
+      streamOffset++;
+    }
+    destdata+=objectOffset;
+    origdata+=objectOffset;
+    basedata+=objectOffset;
+  }
+  
+  //copy over the gamestate header and set the diffed flag
+  *(GamestateHeader *)ndata = *HEADER; //copy over the header
+  Gamestate *gs = new Gamestate(ndata);
+  GAMESTATE_HEADER(ndata)->diffed=true;
+  return gs;
+}
+
+Gamestate* Gamestate::intelligentUnDiff(Gamestate *base){
+  // asserts
+  assert(data_);
+  assert(base->data_);
+  assert(!GAMESTATE_HEADER(base->data_)->diffed);
+  assert(!GAMESTATE_HEADER(base->data_)->compressed);
+  assert(!HEADER->compressed);
+  assert(HEADER->diffed);
+  
+  //preparations
+  std::map<unsigned int, Synchronisable *>::iterator it;
+  uint8_t *origdata, *basedata, *destdata, *ndata;
+  unsigned int objectOffset, streamOffset=0;    //data offset
+  unsigned int minsize = (HEADER->datasize < GAMESTATE_HEADER(base->data_)->datasize) ? HEADER->datasize : GAMESTATE_HEADER(base->data_)->datasize; 
+  synchronisableHeader *origheader;
+  synchronisableHeader *destheader;
+  
+  origdata = GAMESTATE_START(this->data_);
+  basedata = GAMESTATE_START(base->data_);
+  ndata = new uint8_t[HEADER->datasize + sizeof(GamestateHeader)];
+  destdata = ndata + sizeof(GamestateHeader);
+  
+  // do the undiff
+  for(it=dataMap_.begin(); it!=dataMap_.end(); it++){
+    assert(streamOffset<HEADER->datasize);
+    origheader = (synchronisableHeader *)(origdata+streamOffset);
+    destheader = (synchronisableHeader *)(destdata+streamOffset);
+    bool sendData;
+    
+    //copy and partially diff the object header
+    assert(sizeof(synchronisableHeader)==3*sizeof(unsigned int)+sizeof(bool));
+    *(unsigned int*)destdata = *(unsigned int*)origdata; //size (do not diff)
+    *(bool*)(destdata+sizeof(unsigned int)) = *(bool*)(origdata+sizeof(unsigned int));
+    sendData = *(bool*)(origdata+sizeof(unsigned int));
+    if(sendData){
+      *(unsigned int*)(destdata+sizeof(unsigned int)+sizeof(bool)) = *(unsigned int*)(basedata+sizeof(unsigned int)+sizeof(bool)) ^ *(unsigned int*)(origdata+sizeof(unsigned int)+sizeof(bool)); //objectid (diff it)
+      *(unsigned int*)(destdata+2*sizeof(unsigned int)+sizeof(bool)) = *(unsigned int*)(basedata+2*sizeof(unsigned int)+sizeof(bool)) ^ *(unsigned int*)(origdata+2*sizeof(unsigned int)+sizeof(bool)); //classid (diff it)
+    }else{
+      *(unsigned int*)(destdata+sizeof(unsigned int)+sizeof(bool)) = 0;
+      *(unsigned int*)(destdata+2*sizeof(unsigned int)+sizeof(bool)) = 0; 
+    }
+    objectOffset=sizeof(synchronisableHeader);
+    streamOffset+=sizeof(synchronisableHeader);
+    
+    //now handle the object data or fill with zeros
+    while(objectOffset<origheader->size ){
+      
+      if(sendData && streamOffset<minsize)
+        *(destdata+objectOffset)=*(basedata+objectOffset)^*(origdata+objectOffset); // do the xor
+      else if(sendData)
+        *(destdata+objectOffset)=((unsigned char)0)^*(origdata+objectOffset); // xor with 0 (basestream is too short)
+      else
+        *(destdata+objectOffset)=0; // set to 0 because this object should not be transfered
+      
+      objectOffset++;
+      streamOffset++;
+    }
+    destdata+=objectOffset;
+    origdata+=objectOffset;
+    basedata+=objectOffset;
+  }
+  
+  //copy over the gamestate header and set the diffed flag
+  *(GamestateHeader *)ndata = *HEADER; //copy over the header
+  Gamestate *gs = new Gamestate(ndata);
+  GAMESTATE_HEADER(ndata)->diffed=false;
+  return gs;
+}
+
 Gamestate *Gamestate::undiff(Gamestate *base)
 {
@@ -330,20 +525,20 @@
   assert(!HEADER->compressed && !GAMESTATE_HEADER(base->data_)->compressed);
   //unsigned char *basep = base->getGs()/*, *gs = getGs()*/;
-  unsigned char *basep = GAMESTATE_START(base->data_);
-  unsigned char *gs = GAMESTATE_START(this->data_);
+  uint8_t *basep = GAMESTATE_START(base->data_);
+  uint8_t *gs = GAMESTATE_START(this->data_);
   unsigned int of=0; // pointers offset
   unsigned int dest_length=0;
-  dest_length=HEADER->normsize;
+  dest_length=HEADER->datasize;
   if(dest_length==0)
     return NULL;
-  unsigned char *ndata = new unsigned char[dest_length*sizeof(unsigned char)+sizeof(GamestateHeader)];
-  unsigned char *dest = ndata + sizeof(GamestateHeader);
-  while(of < GAMESTATE_HEADER(base->data_)->normsize && of < HEADER->normsize){
+  uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+sizeof(GamestateHeader)];
+  uint8_t *dest = ndata + sizeof(GamestateHeader);
+  while(of < GAMESTATE_HEADER(base->data_)->datasize && of < HEADER->datasize){
     *(dest+of)=*(basep+of)^*(gs+of); // do the xor
     ++of;
   }
-  if(GAMESTATE_HEADER(base->data_)->normsize!=HEADER->normsize){
-    unsigned char n=0;
-    if(GAMESTATE_HEADER(base->data_)->normsize < HEADER->normsize){
+  if(GAMESTATE_HEADER(base->data_)->datasize!=HEADER->datasize){
+    uint8_t n=0;
+    if(GAMESTATE_HEADER(base->data_)->datasize < HEADER->datasize){
       while(of < dest_length){
         *(dest+of)=n^*(gs+of);
@@ -370,5 +565,5 @@
     // get total size of gamestate
   for(it = orxonox::ObjectList<Synchronisable>::begin(); it; ++it)
-    size+=it->getSize2(id, mode); // size of the actual data of the synchronisable
+    size+=it->getSize(id, mode); // size of the actual data of the synchronisable
 //  size+=sizeof(GamestateHeader);
   return size;
Index: code/trunk/src/network/packet/Gamestate.h
===================================================================
--- code/trunk/src/network/packet/Gamestate.h	(revision 1906)
+++ code/trunk/src/network/packet/Gamestate.h	(revision 1907)
@@ -29,7 +29,9 @@
 #include "Packet.h"
 #include "network/Synchronisable.h"
+#include <map>
 #ifndef NDEBUG
 #include "util/CRC32.h"
 #endif
+
 
 #ifndef NETWORK_PACKETGAMESTATE_H
@@ -42,11 +44,11 @@
 struct GamestateHeader{
   ENUM::Type packetType;
-  int id; // id of the gamestate
-  unsigned int compsize;
-  unsigned int normsize;
-  int base_id; // id of the base-gamestate diffed from
-  bool diffed; // wheter diffed or not
-  bool complete; // wheter it is a complete gamestate or only partial
-  bool compressed;
+  int32_t id; // id of the gamestate
+  uint32_t compsize;
+  uint32_t datasize;
+  int32_t base_id; // id of the base-gamestate diffed from
+  bool diffed:1; // wheter diffed or not
+  bool complete:1; // wheter it is a complete gamestate or only partial
+  bool compressed:1;
 #ifndef NDEBUG
   uint32_t crc32;
@@ -55,10 +57,11 @@
 
 /**
-	@author
+	@author Oliver Scheuss
 */
 class Gamestate: public Packet{
   public:
     Gamestate();
-    Gamestate(unsigned char *data, int clientID);
+    Gamestate(uint8_t *data, unsigned int clientID);
+    Gamestate(uint8_t *data);
 
     ~Gamestate();
@@ -71,9 +74,13 @@
     int getBaseID();
     Gamestate *diff(Gamestate *base);
+    Gamestate* intelligentDiff(Gamestate *base, unsigned int clientID);
     Gamestate *undiff(Gamestate *base);
+    Gamestate* intelligentUnDiff(Gamestate *base);
+    Gamestate* doSelection(unsigned int clientID);
     bool compressData();
     bool decompressData();
 
     // Packet functions
+  private:
     virtual unsigned int getSize() const;
     virtual bool process();
@@ -83,8 +90,5 @@
     unsigned int calcGamestateSize(unsigned int id, int mode=0x0);
     void removeObject(orxonox::ObjectListIterator<Synchronisable> &it);
-
-
-    //Bytestream *bs_;
-    //GamestateHeader *header_;
+    std::map<unsigned int, Synchronisable*> dataMap_;
 };
 
Index: code/trunk/src/network/packet/Packet.cc
===================================================================
--- code/trunk/src/network/packet/Packet.cc	(revision 1906)
+++ code/trunk/src/network/packet/Packet.cc	(revision 1907)
@@ -42,4 +42,5 @@
 #include "Gamestate.h"
 #include "Welcome.h"
+#include "DeleteObjects.h"
 #include "network/Host.h"
 #include "core/CoreIncludes.h"
@@ -66,5 +67,5 @@
 }
 
-Packet::Packet(unsigned char *data, int clientID){
+Packet::Packet(uint8_t *data, unsigned int clientID){
   flags_ = PACKET_FLAG_DEFAULT;
   packetDirection_ = ENUM::Incoming;
@@ -74,10 +75,4 @@
 }
 
-/*Packet::Packet(ENetPacket *packet, ENetPeer *peer){
-  packetDirection_ = ENUM::Incoming;
-  enetPacket_ = packet;
-  clientID_ = ClientInformation::findClient(&peer->address)->getID();
-  data_ = packet->data;
-}*/
 
 Packet::Packet(const Packet &p){
@@ -87,5 +82,5 @@
   clientID_ = p.clientID_;
   if(p.data_){
-    data_ = new unsigned char[p.getSize()];
+    data_ = new uint8_t[p.getSize()];
     memcpy(data_, p.data_, p.getSize());
   }else
@@ -125,4 +120,5 @@
     case ENUM::Gamestate:
     case ENUM::Welcome:
+    case ENUM::DeleteObjects:
       break;
     default:
@@ -138,30 +134,34 @@
 
 Packet *Packet::createPacket(ENetPacket *packet, ENetPeer *peer){
-  unsigned char *data = packet->data;
+  uint8_t *data = packet->data;
   unsigned int clientID = ClientInformation::findClient(&peer->address)->getID();
   Packet *p;
-  COUT(3) << "packet type: " << *(ENUM::Type *)&data[_PACKETID] << std::endl;
+  COUT(5) << "packet type: " << *(ENUM::Type *)&data[_PACKETID] << std::endl;
   switch( *(ENUM::Type *)(data + _PACKETID) )
   {
     case ENUM::Acknowledgement:
-      COUT(3) << "ack" << std::endl;
+      COUT(4) << "ack" << std::endl;
       p = new Acknowledgement( data, clientID );
       break;
     case ENUM::Chat:
-      COUT(3) << "chat" << std::endl;
+      COUT(4) << "chat" << std::endl;
       p = new Chat( data, clientID );
       break;
     case ENUM::ClassID:
-      COUT(3) << "classid" << std::endl;
+      COUT(4) << "classid" << std::endl;
       p = new ClassID( data, clientID );
       break;
     case ENUM::Gamestate:
-      COUT(3) << "gamestate" << std::endl;
+      COUT(4) << "gamestate" << std::endl;
       // TODO: remove brackets
       p = new Gamestate( data, clientID );
       break;
     case ENUM::Welcome:
-      COUT(3) << "welcome" << std::endl;
+      COUT(4) << "welcome" << std::endl;
       p = new Welcome( data, clientID );
+      break;
+    case ENUM::DeleteObjects:
+      COUT(4) << "deleteobjects" << std::endl;
+      p = new DeleteObjects( data, clientID );
       break;
     default:
Index: code/trunk/src/network/packet/Packet.h
===================================================================
--- code/trunk/src/network/packet/Packet.h	(revision 1906)
+++ code/trunk/src/network/packet/Packet.h	(revision 1907)
@@ -32,4 +32,6 @@
 #include <enet/enet.h>
 
+#include "util/Integers.h"
+
 namespace network {
 
@@ -47,5 +49,6 @@
     ClassID,
     Chat,
-    Welcome
+    Welcome,
+    DeleteObjects
   };
 }
@@ -74,10 +77,10 @@
   protected:
     Packet();
-    Packet(unsigned char *data, int clientID);
+    Packet(uint8_t *data, unsigned int clientID);
 //    Packet(ENetPacket *packet, ENetPeer *peer);
     enet_uint32 flags_;
-    int clientID_;
+    unsigned int clientID_;
     ENUM::Direction packetDirection_;
-    unsigned char *data_;
+    uint8_t *data_;
   private:
     static std::map<ENetPacket *, Packet *> packetMap_;
Index: code/trunk/src/network/packet/Welcome.cc
===================================================================
--- code/trunk/src/network/packet/Welcome.cc	(revision 1906)
+++ code/trunk/src/network/packet/Welcome.cc	(revision 1907)
@@ -42,5 +42,5 @@
 #define _PACKETID             0
 #define _CLIENTID             _PACKETID + sizeof(ENUM::Type)
-#define _SHIPID               _CLIENTID + sizeof(unsigned int)
+#define _SHIPID               _CLIENTID + sizeof(uint32_t)
   
   Welcome::Welcome( unsigned int clientID, unsigned int shipID )
@@ -49,12 +49,12 @@
   flags_ = flags_ | PACKET_FLAGS_CLASSID;
   assert(getSize());
-  data_=new unsigned char[ getSize() ];
+  data_=new uint8_t[ getSize() ];
   assert(data_);
   *(packet::ENUM::Type *)(data_ + _PACKETID ) = packet::ENUM::Welcome;
-  *(unsigned int *)&data_[ _CLIENTID ] = clientID;
-  *(unsigned int *)&data_[ _SHIPID ] = shipID;
+  *(uint32_t *)&data_[ _CLIENTID ] = clientID;
+  *(uint32_t *)&data_[ _SHIPID ] = shipID;
 }
 
-Welcome::Welcome( unsigned char *data, int clientID )
+Welcome::Welcome( uint8_t* data, unsigned int clientID )
   : Packet(data, clientID)
 {
@@ -65,16 +65,16 @@
 }
 
-unsigned char *Welcome::getData(){
+uint8_t *Welcome::getData(){
   return data_;
 }
 
 unsigned int Welcome::getSize() const{
-  return sizeof(network::packet::ENUM::Type) + 2*sizeof(unsigned int);
+  return sizeof(network::packet::ENUM::Type) + 2*sizeof(uint32_t);
 }
 
 bool Welcome::process(){
   unsigned int shipID, clientID;
-  clientID = *(unsigned int *)&data_[ _CLIENTID ];
-  shipID = *(unsigned int *)&data_[ _SHIPID ];
+  clientID = *(uint32_t *)&data_[ _CLIENTID ];
+  shipID = *(uint32_t *)&data_[ _SHIPID ];
   Host::setClientID(clientID);
   Host::setShipID(shipID);
Index: code/trunk/src/network/packet/Welcome.h
===================================================================
--- code/trunk/src/network/packet/Welcome.h	(revision 1906)
+++ code/trunk/src/network/packet/Welcome.h	(revision 1907)
@@ -41,8 +41,8 @@
 public:
   Welcome( unsigned int clientID, unsigned int shipID );
-  Welcome( unsigned char* data, int clientID );
+  Welcome( uint8_t* data, unsigned int clientID );
   virtual ~Welcome();
   
-  unsigned char *getData();
+  uint8_t *getData();
   inline unsigned int getSize() const;
   bool process();
Index: code/trunk/src/orxonox/Settings.cc
===================================================================
--- code/trunk/src/orxonox/Settings.cc	(revision 1906)
+++ code/trunk/src/orxonox/Settings.cc	(revision 1907)
@@ -51,4 +51,5 @@
         : bShowsGraphics_(false)
         , bHasServer_(false)
+        , bIsClient_(false)
     {
         RegisterRootObject(Settings);
Index: code/trunk/src/orxonox/Settings.h
===================================================================
--- code/trunk/src/orxonox/Settings.h	(revision 1906)
+++ code/trunk/src/orxonox/Settings.h	(revision 1907)
@@ -52,4 +52,5 @@
         friend class GSGraphics;
         friend class GSServer;
+        friend class GSClient;
         friend class GSDedicated;
 
@@ -63,4 +64,5 @@
         static bool showsGraphics() { assert(singletonRef_s); return singletonRef_s->bShowsGraphics_; }
         static bool hasServer()     { assert(singletonRef_s); return singletonRef_s->bHasServer_; }
+        static bool isClient()      { assert(singletonRef_s); return singletonRef_s->bIsClient_; }
 
     private:
@@ -68,4 +70,5 @@
         static void setShowsGraphics(bool val) { assert(singletonRef_s); singletonRef_s->bShowsGraphics_ = val; }
         static void setHasServer    (bool val) { assert(singletonRef_s); singletonRef_s->bHasServer_     = val; }
+        static void setIsClient     (bool val) { assert(singletonRef_s); singletonRef_s->bIsClient_      = val; }
 
         Settings();
@@ -81,4 +84,5 @@
         bool bShowsGraphics_;                                  //!< global variable that tells whether to show graphics
         bool bHasServer_;                                      //!< global variable that tells whether this is a server
+        bool bIsClient_;
 
         std::string dataPath_;                                 //!< Path to the game data
Index: code/trunk/src/orxonox/gamestates/GSClient.cc
===================================================================
--- code/trunk/src/orxonox/gamestates/GSClient.cc	(revision 1906)
+++ code/trunk/src/orxonox/gamestates/GSClient.cc	(revision 1907)
@@ -33,4 +33,5 @@
 #include "core/CommandLine.h"
 #include "network/Client.h"
+#include "Settings.h"
 
 namespace orxonox
@@ -50,4 +51,6 @@
     void GSClient::enter()
     {
+        Settings::_getInstance().bIsClient_ = true;
+
         GSLevel::enter();
 
@@ -77,4 +80,6 @@
 
         GSLevel::leave();
+
+        Settings::_getInstance().bIsClient_ = false;
     }
 
Index: code/trunk/src/orxonox/gamestates/GSServer.cc
===================================================================
--- code/trunk/src/orxonox/gamestates/GSServer.cc	(revision 1906)
+++ code/trunk/src/orxonox/gamestates/GSServer.cc	(revision 1907)
@@ -83,8 +83,7 @@
         this->server_->close();
         delete this->server_;
+        Settings::_getInstance().bHasServer_ = false;
 
         GSLevel::leave();
-
-        Settings::_getInstance().bHasServer_ = false;
     }
 
Index: code/trunk/src/orxonox/objects/Backlight.cc
===================================================================
--- code/trunk/src/orxonox/objects/Backlight.cc	(revision 1906)
+++ code/trunk/src/orxonox/objects/Backlight.cc	(revision 1907)
@@ -53,21 +53,33 @@
         this->traillength_ = 1;
 
-        this->getNode()->setInheritScale(false);
+        this->configure(maxspeed, brakingtime, scale);
+    }
+    
+    bool Backlight::create(){
+      if(!WorldEntity::create())
+        return false;
+      
+      this->getNode()->setInheritScale(false);
 
-        this->billboard_.setBillboardSet("Flares/backlightflare");
-        this->attachObject(this->billboard_.getBillboardSet());
+      this->billboard_.setBillboardSet("Flares/backlightflare");
+      this->attachObject(this->billboard_.getBillboardSet());
 
-        this->ribbonTrail_ = GraphicsEngine::getInstance().getLevelSceneManager()->createRibbonTrail(this->getName() + "RibbonTrail");
-        this->ribbonTrailNode_ = GraphicsEngine::getInstance().getLevelSceneManager()->getRootSceneNode()->createChildSceneNode(this->getName() + "RibbonTrailNode");
-        this->ribbonTrailNode_->attachObject(this->ribbonTrail_);
-        this->ribbonTrail_->addNode(this->getNode());
+      this->ribbonTrail_ = GraphicsEngine::getInstance().getLevelSceneManager()->createRibbonTrail(this->getName() + "RibbonTrail");
+      this->ribbonTrailNode_ = GraphicsEngine::getInstance().getLevelSceneManager()->getRootSceneNode()->createChildSceneNode(this->getName() + "RibbonTrailNode");
+      this->ribbonTrailNode_->attachObject(this->ribbonTrail_);
+      this->ribbonTrail_->addNode(this->getNode());
 
-        this->configure(maxspeed, brakingtime, scale);
 
-        this->ribbonTrail_->setTrailLength(this->maxTraillength_);
-        this->ribbonTrail_->setMaterialName("Trail/backlighttrail");
+      this->ribbonTrail_->setTrailLength(this->maxTraillength_);
+      this->ribbonTrail_->setMaterialName("Trail/backlighttrail");
 
         //this->setTimeFactor(Orxonox::getInstance().getTimeFactor());
-        this->setTimeFactor(1.0f);
+      this->setTimeFactor(1.0f);
+      
+      this->ribbonTrail_->setMaxChainElements(this->maxTrailsegments_);
+      this->ribbonTrail_->setTrailLength(this->traillength_ = 2 * this->maxTrailsegments_);
+      this->ribbonTrail_->setInitialWidth(0, this->width_ * this->getScale());
+      this->ribbonTrail_->setWidthChange(0, this->width_ * this->getScale() / this->maxLifeTime_ * Backlight::timeFactor_s);
+      return true;
     }
 
@@ -100,4 +112,11 @@
     {
         this->ribbonTrail_->setColourChange(0, ColourValue(0, 0, 0, this->maxTraillength_ / this->traillength_ / this->maxLifeTime_ * Backlight::timeFactor_s));
+    }
+    
+    
+    void Backlight::XMLPort(Element& xmlelement, XMLPort::Mode mode){
+      SUPER(Backlight, XMLPort, xmlelement, mode);
+      
+      Backlight::create();
     }
 
@@ -136,12 +155,8 @@
         this->maxTraillength_ = this->maxLifeTime_ * maxspeed;
         this->maxTrailsegments_ = (size_t)(this->maxTraillength_ / this->trailSegmentLength_);
-        this->ribbonTrail_->setMaxChainElements(this->maxTrailsegments_);
-        this->ribbonTrail_->setTrailLength(this->traillength_ = 2 * this->maxTrailsegments_);
 
         this->brakefactor_ = this->maxLifeTime_ / brakingtime;
 
         this->scale(scale);
-        this->ribbonTrail_->setInitialWidth(0, this->width_ * scale);
-        this->ribbonTrail_->setWidthChange(0, this->width_ * scale / this->maxLifeTime_ * Backlight::timeFactor_s);
     }
 
Index: code/trunk/src/orxonox/objects/Backlight.h
===================================================================
--- code/trunk/src/orxonox/objects/Backlight.h	(revision 1906)
+++ code/trunk/src/orxonox/objects/Backlight.h	(revision 1907)
@@ -45,6 +45,8 @@
 
             void setConfigValues();
+            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
             virtual void tick(float dt);
             virtual void changedVisibility();
+            virtual bool create();
 
             void setColour(const ColourValue& colour);
Index: code/trunk/src/orxonox/objects/BillboardProjectile.cc
===================================================================
--- code/trunk/src/orxonox/objects/BillboardProjectile.cc	(revision 1906)
+++ code/trunk/src/orxonox/objects/BillboardProjectile.cc	(revision 1907)
@@ -42,10 +42,7 @@
         RegisterObject(BillboardProjectile);
 
-        if (this->owner_)
-        {
-            this->billboard_.setBillboardSet("Examples/Flare", ColourValue(1.0, 1.0, 0.5), 1);
-            this->attachObject(this->billboard_.getBillboardSet());
-            this->scale(0.5);
-        }
+        this->billboard_.setBillboardSet("Examples/Flare", ColourValue(1.0, 1.0, 0.5), 1);
+        this->attachObject(this->billboard_.getBillboardSet());
+        this->scale(0.5);
     }
 
Index: code/trunk/src/orxonox/objects/Model.cc
===================================================================
--- code/trunk/src/orxonox/objects/Model.cc	(revision 1906)
+++ code/trunk/src/orxonox/objects/Model.cc	(revision 1907)
@@ -46,5 +46,5 @@
 
     /**
-     * 
+     * @brief Constructor
      */
     Model::Model()
@@ -54,4 +54,7 @@
     }
 
+    /**
+     * @brief Destructor
+     */
     Model::~Model()
     {
@@ -86,5 +89,5 @@
       }
       if(this->isExactlyA(Class(Model)))
-        setObjectFrequency(300); //sync all 10 seconds (this only applies to asteroids and other isExactlyA(Model)
+        setObjectFrequency(300); //sync all 10 seconds (this only applies to asteroids and other isExactlyA(Model)'s
       return true;
     }
Index: code/trunk/src/orxonox/objects/ParticleProjectile.cc
===================================================================
--- code/trunk/src/orxonox/objects/ParticleProjectile.cc	(revision 1906)
+++ code/trunk/src/orxonox/objects/ParticleProjectile.cc	(revision 1907)
@@ -42,15 +42,14 @@
         RegisterObject(ParticleProjectile);
 
+        this->particles_ = new ParticleInterface("Orxonox/shot2", LODParticle::normal);
+        this->particles_->addToSceneNode(this->getNode());
+        this->particles_->setKeepParticlesInLocalSpace(true);
         if (this->owner_)
         {
-            this->particles_ = new ParticleInterface("Orxonox/shot2", LODParticle::normal);
-            this->particles_->addToSceneNode(this->getNode());
-            this->particles_->getAllEmitters()->setDirection(-this->owner_->getInitialDir());
-            this->particles_->setKeepParticlesInLocalSpace(true);
         }
-        else
-        {
-            this->particles_ = 0;
-        }
+//        else
+//        {
+//            this->particles_ = 0;
+//        }
 
         this->setConfigValues();
@@ -73,3 +72,10 @@
         this->particles_->setEnabled(this->isVisible());
     }
+    
+    bool ParticleProjectile::create(){
+      if(!Projectile::create())
+        return false;
+      this->particles_->getAllEmitters()->setDirection(-this->getOrientation()*Vector3(1,0,0));
+      return true;
+    }
 }
Index: code/trunk/src/orxonox/objects/ParticleProjectile.h
===================================================================
--- code/trunk/src/orxonox/objects/ParticleProjectile.h	(revision 1906)
+++ code/trunk/src/orxonox/objects/ParticleProjectile.h	(revision 1907)
@@ -45,4 +45,6 @@
             virtual void changedVisibility();
             void setConfigValues();
+            
+            virtual bool create();
 
         private:
Index: code/trunk/src/orxonox/objects/Projectile.cc
===================================================================
--- code/trunk/src/orxonox/objects/Projectile.cc	(revision 1906)
+++ code/trunk/src/orxonox/objects/Projectile.cc	(revision 1907)
@@ -41,4 +41,5 @@
 #include "ParticleSpawner.h"
 #include "Model.h"
+#include "Settings.h"
 
 namespace orxonox
@@ -56,13 +57,14 @@
         this->setStatic(false);
         this->translate(Vector3(55, 0, 0), Ogre::Node::TS_LOCAL);
-
+        
         if (this->owner_)
         {
+            this->setOrientation(this->owner_->getOrientation());
             this->setPosition(this->owner_->getPosition());
-            this->setOrientation(this->owner_->getOrientation());
             this->setVelocity(this->owner_->getInitialDir() * this->speed_);
         }
 
-        this->destroyTimer_.setTimer(this->lifetime_, false, this, createExecutor(createFunctor(&Projectile::destroyObject)));
+        if(!orxonox::Settings::isClient()) //only if not on client
+          this->destroyTimer_.setTimer(this->lifetime_, false, this, createExecutor(createFunctor(&Projectile::destroyObject)));
     }
 
@@ -122,3 +124,7 @@
         delete this;
     }
+    
+    bool Projectile::create(){
+      return WorldEntity::create();
+    }
 }
Index: code/trunk/src/orxonox/objects/Projectile.h
===================================================================
--- code/trunk/src/orxonox/objects/Projectile.h	(revision 1906)
+++ code/trunk/src/orxonox/objects/Projectile.h	(revision 1907)
@@ -45,4 +45,6 @@
             void destroyObject();
             virtual void tick(float dt);
+            
+            virtual bool create();
 
             static float getSpeed()
Index: code/trunk/src/orxonox/objects/SpaceShip.cc
===================================================================
--- code/trunk/src/orxonox/objects/SpaceShip.cc	(revision 1906)
+++ code/trunk/src/orxonox/objects/SpaceShip.cc	(revision 1907)
@@ -78,5 +78,5 @@
       for(it = ObjectList<SpaceShip>::begin(); it; ++it){
 	assert(it->isA(Class(SpaceShip)));
-        if( (it)->myShip_ || (network::Host::running() && network::Host::getShipID()==(it)->objectID) ){
+        if( (it)->myShip_ || (network::Host::running() && network::Host::getShipID()==(it)->getObjectID()) ){
 //	  COUT(1) << "^^^^^^^^^^ myShip_:" << *it << " classname: " << (*it)->getIdentifier()->getName() << " objectid: " << (*it)->objectID << std::endl;
           return *it;
@@ -173,18 +173,16 @@
         if (!myShip_)
         {
-            if (network::Host::running())
-                //COUT(3) << "this id: " << this->objectID << " myShipID: " << network::Host::getShipID() << std::endl;
-                if (network::Host::running() && objectID == network::Host::getShipID())
-                {
-                    if (!network::Host::isServer())
-                        setObjectMode(0x3);
-                    myShip_ = true;
-                }
-        }
-        else
-            this->setRadarObjectColour(this->getProjectileColour());
-        assert(Model::create());
-        this->init();
-        return true;
+            if (network::Host::running() && getObjectID() == network::Host::getShipID())
+            {
+                if (!network::Host::isServer())
+                    setObjectMode(0x3);
+                myShip_ = true;
+            }
+            else
+                this->setRadarObjectColour(this->getProjectileColour());
+      }
+      Model::create();
+      this->init();
+      return true;
     }
 
@@ -258,17 +256,20 @@
 
             // START CREATING ADDITIONAL EFFECTS
-            /*this->backlight_ = new Backlight(this->maxSpeed_, 0.8);
-            this->attachObject(this->backlight_);
-            this->backlight_->setPosition(-2.35, 0, 0.2);
-            this->backlight_->setColour(this->getProjectileColour());
-
-            this->smoke_ = new ParticleSpawner();
-            this->smoke_->setParticle("Orxonox/smoke5", LODParticle::normal, 0, 0, 3);
-            this->attachObject(this->smoke_);
-
-            this->fire_ = new ParticleSpawner();
-            this->fire_->setParticle("Orxonox/fire3", LODParticle::normal, 0, 0, 1);
-            this->attachObject(this->fire_);
-            */
+            if(!network::Host::running()){
+              this->backlight_ = new Backlight(this->maxSpeed_, 0.8);
+              this->backlight_->create();
+              this->attachObject(this->backlight_);
+              this->backlight_->setPosition(-2.35, 0, 0.2);
+              this->backlight_->setColour(this->getProjectileColour());
+  
+              this->smoke_ = new ParticleSpawner();
+              this->smoke_->setParticle("Orxonox/smoke5", LODParticle::normal, 0, 0, 3);
+              this->attachObject(this->smoke_);
+  
+              this->fire_ = new ParticleSpawner();
+              this->fire_->setParticle("Orxonox/fire3", LODParticle::normal, 0, 0, 1);
+              this->attachObject(this->fire_);
+            }
+            
             // END CREATING ADDITIONAL EFFECTS
 
@@ -374,13 +375,13 @@
       //if(!network::Host::running() || network::Host::getShipID()==objectID){ //TODO: check this
       if(myShip_){
-        COUT(4) << "requesting focus for camera" << std::endl;
+        COUT(5) << "requesting focus for camera" << std::endl;
         //CameraHandler::getInstance()->requestFocus(cam_);
         if(this->isExactlyA(Class(SpaceShip))){
           getFocus();
-          COUT(4) << "getting focus for obj id: " << objectID << std::endl;
+          COUT(4) << "getting focus for obj id: " << getObjectID() << std::endl;
         }else
-          COUT(4) << "not getting focus (not exactly spaceship) for obj id: " << objectID << std::endl;
+          COUT(5) << "not getting focus (not exactly spaceship) for obj id: " << getObjectID() << std::endl;
       }else
-        COUT(4) << "not getting focus (not my ship) for obj id: " << objectID << std::endl;
+        COUT(5) << "not getting focus (not my ship) for obj id: " << getObjectID() << std::endl;
     }
 
@@ -478,5 +479,5 @@
             projectile->setColour(this->getProjectileColour());
             projectile->create();
-            if (projectile->classID == 0)
+            if (projectile->getClassID() == 0)
             {
               COUT(3) << "generated projectile with classid 0" <<  std::endl; // TODO: remove this output
@@ -573,5 +574,5 @@
         }
 
-        COUT(5) << "steering our ship: " << objectID << std::endl;
+        COUT(5) << "steering our ship: " << getObjectID() << std::endl;
         this->acceleration_.x = 0;
         this->acceleration_.y = 0;
