Index: code/branches/network/TODO
===================================================================
--- code/branches/network/TODO	(revision 1895)
+++ code/branches/network/TODO	(revision 1901)
@@ -2,11 +2,13 @@
 	!!! check that enet does not cause a packet traffic jam when a reliable packet gets missed !!!
 	[implemented] new gamestate concept
-	check Projectiles
-	check that we dont have to much registervar because of virtual function calls
+
+	!!! ensure that objects get synched, when newly created, even if not their tick
 
 	setvariable mode
 	objectmode
-	friend classes
-	priorities
-	static (sync once)
-	triggerSync
+	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/branches/network/src/network/Client.cc
===================================================================
--- code/branches/network/src/network/Client.cc	(revision 1895)
+++ code/branches/network/src/network/Client.cc	(revision 1901)
@@ -60,5 +60,4 @@
     isSynched_=false;
     gameStateFailure_=false;
-    isServer_ = false;
   }
 
@@ -72,5 +71,4 @@
     isSynched_=false;
     gameStateFailure_=false;
-    isServer_ = false;
   }
 
@@ -84,5 +82,4 @@
     isSynched_=false;
     gameStateFailure_=false;
-    isServer_ = false;
   }
 
@@ -155,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())
Index: code/branches/network/src/network/Client.h
===================================================================
--- code/branches/network/src/network/Client.h	(revision 1895)
+++ code/branches/network/src/network/Client.h	(revision 1901)
@@ -85,4 +85,5 @@
 
   private:
+    virtual bool isServer_(){return false;}
     
     ClientConnection client_connection;
Index: code/branches/network/src/network/ClientConnection.cc
===================================================================
--- code/branches/network/src/network/ClientConnection.cc	(revision 1895)
+++ code/branches/network/src/network/ClientConnection.cc	(revision 1901)
@@ -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/branches/network/src/network/ClientConnection.h
===================================================================
--- code/branches/network/src/network/ClientConnection.h	(revision 1895)
+++ code/branches/network/src/network/ClientConnection.h	(revision 1901)
@@ -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/branches/network/src/network/ConnectionManager.cc
===================================================================
--- code/branches/network/src/network/ConnectionManager.cc	(revision 1895)
+++ code/branches/network/src/network/ConnectionManager.cc	(revision 1901)
@@ -80,12 +80,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);
@@ -113,28 +105,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(){
@@ -163,14 +136,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) {
Index: code/branches/network/src/network/GamestateClient.cc
===================================================================
--- code/branches/network/src/network/GamestateClient.cc	(revision 1895)
+++ code/branches/network/src/network/GamestateClient.cc	(revision 1901)
@@ -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()];
Index: code/branches/network/src/network/GamestateManager.cc
===================================================================
--- code/branches/network/src/network/GamestateManager.cc	(revision 1895)
+++ code/branches/network/src/network/GamestateManager.cc	(revision 1901)
@@ -154,5 +154,6 @@
       gs = new packet::Gamestate(*gs);
     }
-    assert(gs->compressData());
+    bool b = gs->compressData();
+    assert(b);
     return gs;
   }
@@ -194,5 +195,8 @@
   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/branches/network/src/network/Host.h
===================================================================
--- code/branches/network/src/network/Host.h	(revision 1895)
+++ code/branches/network/src/network/Host.h	(revision 1901)
@@ -52,4 +52,5 @@
     virtual bool chat(std::string message)=0;
     virtual bool processChat(std::string message, unsigned int playerID)=0;
+    virtual bool isServer_()=0;
 
 
@@ -59,5 +60,4 @@
     virtual ~Host();
     static Host *instance_;
-    bool isServer_;	
     unsigned int clientID_;
     unsigned int shipID_;
@@ -72,5 +72,5 @@
     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);
Index: code/branches/network/src/network/Server.cc
===================================================================
--- code/branches/network/src/network/Server.cc	(revision 1895)
+++ code/branches/network/src/network/Server.cc	(revision 1901)
@@ -72,5 +72,4 @@
     connection = new ConnectionManager();
     gamestates_ = new GamestateManager();
-    isServer_ = true;
   }
 
@@ -79,5 +78,4 @@
     connection = new ConnectionManager(port);
     gamestates_ = new GamestateManager();
-    isServer_ = true;
   }
 
@@ -91,5 +89,4 @@
     connection = new ConnectionManager(port, bindAddress);
     gamestates_ = new GamestateManager();
-    isServer_ = true;
   }
 
@@ -103,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_;
   }
 
@@ -198,6 +204,6 @@
     //std::cout << "updated gamestate, sending it" << std::endl;
     //if(clients->getGamestateID()!=GAMESTATEID_INITIAL)
+    sendGameState();
     sendObjectDeletes();
-    sendGameState();
     COUT(5) << "Server: one sendGameState turn complete, repeat in next tick" << std::endl;
     //std::cout << "sent gamestate" << std::endl;
@@ -254,4 +260,5 @@
     if(!del->fetchIDs())
       return true;  //everything ok (no deletes this tick)
+//     COUT(3) << "sending DeleteObjects" << std::endl;
     while(temp != NULL){
       if( !(temp->getSynched()) ){
@@ -307,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;
   }
Index: code/branches/network/src/network/Server.h
===================================================================
--- code/branches/network/src/network/Server.h	(revision 1895)
+++ code/branches/network/src/network/Server.h	(revision 1901)
@@ -63,4 +63,5 @@
     Server(int port, std::string bindAddress);
     Server(int port, const char *bindAddress);
+    ~Server();
     
     void open();
@@ -73,4 +74,5 @@
     void updateGamestate();
   private:
+    virtual bool isServer_(){return true;}
     unsigned int shipID(){return 0;}
     unsigned int playerID(){return 0;}
Index: code/branches/network/src/network/Synchronisable.cc
===================================================================
--- code/branches/network/src/network/Synchronisable.cc	(revision 1895)
+++ code/branches/network/src/network/Synchronisable.cc	(revision 1901)
@@ -64,9 +64,8 @@
   Synchronisable::Synchronisable(){
     RegisterRootObject(Synchronisable);
-    static unsigned int idCounter=0;
+    static uint32_t idCounter=0;
     objectFrequency_=1;
     objectMode_=0x1; // by default do not send data to server
     objectID=idCounter++;
-//     COUT(3) << " bump +++" << objectID << " | " << &objectMap_ << std::endl;
     syncList = new std::list<synchronisableVariable *>;
   }
@@ -81,4 +80,6 @@
       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);
@@ -94,6 +95,7 @@
   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);
@@ -121,7 +123,9 @@
    * @return pointer to the newly created synchronisable
    */
-  Synchronisable *Synchronisable::fabricate(unsigned char*& mem, int mode)
+  Synchronisable *Synchronisable::fabricate(uint8_t*& mem, int mode)
   {
     synchronisableHeader *header = (synchronisableHeader *)mem;
+    
+    COUT(3) << "fabricating object with id: " << header->objectID << std::endl;
     
     orxonox::Identifier* id = GetIdentifier(header->classID);
@@ -134,6 +138,8 @@
     COUT(3) << "fabricate objectID: " << no->objectID << " classID: " << no->classID << std::endl;
           // update data and create object/entity...
-    assert(no->updateData(mem, mode));
-    assert( no->create() );
+    bool b = no->updateData(mem, mode);
+    assert(b);
+    b = no->create();
+    assert(b);
     return no;
   }
@@ -146,5 +152,7 @@
    */
   bool Synchronisable::deleteObject(unsigned int objectID){
-    assert(getSynchronisable(objectID));
+//     assert(getSynchronisable(objectID));
+    if(!getSynchronisable(objectID))
+      return false;
     assert(getSynchronisable(objectID)->objectID==objectID);
 //     delete objectMap_[objectID];
@@ -222,5 +230,5 @@
    * @return true: if !isMyTick or if everything was successfully saved
    */
-  bool Synchronisable::getData(unsigned char*& mem, unsigned int id, int mode){
+  bool Synchronisable::getData(uint8_t*& mem, unsigned int id, int mode){
     //if this tick is we dont synchronise, then abort now
     if(!isMyTick(id))
@@ -232,5 +240,6 @@
     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;
@@ -283,5 +292,5 @@
    * @return true/false
    */
-  bool Synchronisable::updateData(unsigned char*& mem, int mode){
+  bool Synchronisable::updateData(uint8_t*& mem, int mode){
     if(mode==0x0)
       mode=state_;
@@ -291,5 +300,5 @@
       return false;
     }
-    unsigned char *data=mem;
+    uint8_t *data=mem;
     // start extract header
     synchronisableHeader *syncHeader = (synchronisableHeader *)mem;
@@ -322,5 +331,5 @@
           break;
         case STRING:
-          (*i)->size = *(int *)mem;
+          (*i)->size = *(uint32_t *)mem;
           COUT(5) << "string size: " << (*i)->size << std::endl;
           mem+=sizeof(int);
@@ -346,5 +355,5 @@
   * @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;
@@ -388,5 +397,5 @@
    * @param mem pointer to the bytestream
    */
-  bool Synchronisable::isMyData(unsigned char* mem)
+  bool Synchronisable::isMyData(uint8_t* mem)
   {
     synchronisableHeader *header = (synchronisableHeader *)mem;
Index: code/branches/network/src/network/Synchronisable.h
===================================================================
--- code/branches/network/src/network/Synchronisable.h	(revision 1895)
+++ code/branches/network/src/network/Synchronisable.h	(revision 1901)
@@ -57,5 +57,11 @@
       bidirectional=0x3
     };
-    
+  }
+  
+  namespace syncmode{
+    enum mode{
+      one=0,
+      always=1
+    };
   }
   
@@ -66,8 +72,8 @@
 
   struct synchronisableHeader{
-    unsigned int size;
-    bool dataAvailable;
-    unsigned int objectID;
-    unsigned int classID;
+    uint32_t size:31;
+    bool dataAvailable:1;
+    uint32_t objectID;
+    uint32_t classID;
   };
 
@@ -97,5 +103,5 @@
     static void setClient(bool b);
     
-    static Synchronisable *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);
@@ -114,8 +120,8 @@
     
   private:
-    bool getData(unsigned char*& men, unsigned int id, int mode=0x0);
-    int getSize(unsigned int id, int mode=0x0);
-    bool updateData(unsigned char*& mem, int mode=0x0);
-    bool isMyData(unsigned char* mem);
+    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);
Index: code/branches/network/src/network/packet/DeleteObjects.cc
===================================================================
--- code/branches/network/src/network/packet/DeleteObjects.cc	(revision 1895)
+++ code/branches/network/src/network/packet/DeleteObjects.cc	(revision 1901)
@@ -37,5 +37,5 @@
 namespace packet {
 
-#define PACKET_FLAGS_DELETE    ENET_PACKET_FLAG_RELIABLE
+#define PACKET_FLAG_DELETE  ENET_PACKET_FLAG_RELIABLE
 #define _PACKETID           0
 #define _QUANTITY           _PACKETID + sizeof(ENUM::Type)
@@ -45,5 +45,5 @@
  : Packet()
 {
-  flags_ = flags_ | PACKET_FLAGS_DELETE;
+  flags_ = flags_ | PACKET_FLAG_DELETE;
 }
 
@@ -61,11 +61,20 @@
   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];
-  *(ENUM::Type *)(data_ + _PACKETID ) = ENUM::DeleteObjects;
-  *(uint32_t *)(data_ + _QUANTITY) = number;
+  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++){
-    *(uint32_t *)(data_ + sizeof(ENUM::Type) + (i+1)*sizeof(uint32_t)) = Synchronisable::popDeletedObject();
+    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;
 }
Index: code/branches/network/src/network/packet/Gamestate.cc
===================================================================
--- code/branches/network/src/network/packet/Gamestate.cc	(revision 1895)
+++ code/branches/network/src/network/packet/Gamestate.cc	(revision 1901)
@@ -47,15 +47,20 @@
 
   
+#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)
 {
-}
-
-Gamestate::Gamestate(unsigned char *data)
-{
+  flags_ = flags_ | PACKET_FLAG_GAMESTATE;
+}
+
+Gamestate::Gamestate(uint8_t *data)
+{
+  flags_ = flags_ | PACKET_FLAG_GAMESTATE;
   data_=data;
 }
@@ -86,5 +91,5 @@
 #endif
   //start collect data synchronisable by synchronisable
-  unsigned char *mem=data_;
+  uint8_t *mem=data_;
   mem+=sizeof(GamestateHeader);
   orxonox::ObjectList<Synchronisable>::iterator it;
@@ -99,5 +104,5 @@
       while(++temp)
         addsize+=temp->getSize(id, mode);
-      data_ = (unsigned char *)realloc(data_, sizeof(GamestateHeader) + currentsize + addsize);
+      data_ = (uint8_t *)realloc(data_, sizeof(GamestateHeader) + currentsize + addsize);
       if(!data_)
         return false;
@@ -140,5 +145,5 @@
   assert(!HEADER->compressed);
   assert(!HEADER->diffed);
-  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();
@@ -159,5 +164,6 @@
     else
     {
-      assert(s->updateData(mem, mode));
+      bool b = s->updateData(mem, mode);
+      assert(b);
       //if(!s->updateData(mem, mode))
         //return false;
@@ -186,6 +192,6 @@
 
 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());
@@ -215,8 +221,8 @@
     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->datasize) );
@@ -229,6 +235,6 @@
 #ifndef NDEBUG
   //decompress and compare the start and the decompressed data
-  unsigned char *rdata = new unsigned char[HEADER->datasize+sizeof(GamestateHeader)];
-  unsigned char *d2 = GAMESTATE_START(rdata);
+  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);
@@ -265,7 +271,7 @@
   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;
@@ -299,5 +305,5 @@
   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;
@@ -305,6 +311,6 @@
   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);
+  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
@@ -312,5 +318,5 @@
   }
   if(GAMESTATE_HEADER(base->data_)->datasize!=HEADER->datasize){
-    unsigned char n=0;
+    uint8_t n=0;
     if(GAMESTATE_HEADER(base->data_)->datasize < HEADER->datasize){
       while(of<dest_length){
@@ -335,5 +341,5 @@
   
   Gamestate *gs = new Gamestate(*this);
-  unsigned char *ndata = gs->data_ + sizeof(GamestateHeader);
+  uint8_t *ndata = gs->data_ + sizeof(GamestateHeader);
   synchronisableHeader *objectheader;
   unsigned int objectOffset;
@@ -344,5 +350,5 @@
     unsigned int objectsize = objectheader->size;
     assert(it->second->objectID==objectheader->objectID);
-    objectOffset=sizeof(unsigned int)+sizeof(bool); //skip the size and the availableDate variables in the objectheader
+    objectOffset=sizeof(uint8_t)+sizeof(bool); //skip the size and the availableDate variables in the objectheader
     if(!it->second->doSelection(HEADER->id)){
       while(objectOffset<objectsize){
@@ -370,5 +376,5 @@
   //preparations
   std::map<unsigned int, Synchronisable *>::iterator it;
-  unsigned char *origdata, *basedata, *destdata, *ndata;
+  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; 
@@ -378,5 +384,5 @@
   origdata = GAMESTATE_START(this->data_);
   basedata = GAMESTATE_START(base->data_);
-  ndata = new unsigned char[HEADER->datasize + sizeof(GamestateHeader)];
+  ndata = new uint8_t[HEADER->datasize + sizeof(GamestateHeader)];
   destdata = ndata + sizeof(GamestateHeader);
   
@@ -390,12 +396,12 @@
     //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)) = sendData;
+    *(uint32_t*)destdata = *(uint32_t*)origdata; //size (do not diff)
+    *(bool*)(destdata+sizeof(uint32_t)) = sendData;
     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)
+      *(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{
-      *(unsigned int*)(destdata+sizeof(unsigned int)+sizeof(bool)) = 0;
-      *(unsigned int*)(destdata+2*sizeof(unsigned int)+sizeof(bool)) = 0; 
+      *(uint32_t*)(destdata+sizeof(uint32_t)+sizeof(bool)) = 0;
+      *(uint32_t*)(destdata+2*sizeof(uint32_t)+sizeof(bool)) = 0; 
     }
     objectOffset=sizeof(synchronisableHeader);
@@ -408,5 +414,5 @@
         *(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)
+        *(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
@@ -438,5 +444,5 @@
   //preparations
   std::map<unsigned int, Synchronisable *>::iterator it;
-  unsigned char *origdata, *basedata, *destdata, *ndata;
+  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; 
@@ -446,5 +452,5 @@
   origdata = GAMESTATE_START(this->data_);
   basedata = GAMESTATE_START(base->data_);
-  ndata = new unsigned char[HEADER->datasize + sizeof(GamestateHeader)];
+  ndata = new uint8_t[HEADER->datasize + sizeof(GamestateHeader)];
   destdata = ndata + sizeof(GamestateHeader);
   
@@ -502,6 +508,6 @@
   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;
@@ -509,6 +515,6 @@
   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);
+  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
@@ -516,5 +522,5 @@
   }
   if(GAMESTATE_HEADER(base->data_)->datasize!=HEADER->datasize){
-    unsigned char n=0;
+    uint8_t n=0;
     if(GAMESTATE_HEADER(base->data_)->datasize < HEADER->datasize){
       while(of < dest_length){
Index: code/branches/network/src/network/packet/Gamestate.h
===================================================================
--- code/branches/network/src/network/packet/Gamestate.h	(revision 1895)
+++ code/branches/network/src/network/packet/Gamestate.h	(revision 1901)
@@ -44,11 +44,11 @@
 struct GamestateHeader{
   ENUM::Type packetType;
-  int id; // id of the gamestate
-  unsigned int compsize;
-  unsigned int datasize;
-  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;
@@ -62,6 +62,6 @@
   public:
     Gamestate();
-    Gamestate(unsigned char *data, int clientID);
-    Gamestate(unsigned char *data);
+    Gamestate(uint8_t *data, unsigned int clientID);
+    Gamestate(uint8_t *data);
 
     ~Gamestate();
Index: code/branches/network/src/network/packet/Packet.cc
===================================================================
--- code/branches/network/src/network/packet/Packet.cc	(revision 1895)
+++ code/branches/network/src/network/packet/Packet.cc	(revision 1901)
@@ -120,4 +120,5 @@
     case ENUM::Gamestate:
     case ENUM::Welcome:
+    case ENUM::DeleteObjects:
       break;
     default:
Index: code/branches/network/src/orxonox/Settings.h
===================================================================
--- code/branches/network/src/orxonox/Settings.h	(revision 1895)
+++ code/branches/network/src/orxonox/Settings.h	(revision 1901)
@@ -53,6 +53,6 @@
         friend class GSGraphics;
         friend class GSServer;
+        friend class GSClient;
         friend class GSDedicated;
-        friend class GSClient;
 
     public:
Index: code/branches/network/src/orxonox/gamestates/GSServer.cc
===================================================================
--- code/branches/network/src/orxonox/gamestates/GSServer.cc	(revision 1895)
+++ code/branches/network/src/orxonox/gamestates/GSServer.cc	(revision 1901)
@@ -78,4 +78,5 @@
 
         // TODO: Remove and destroy console command
+        Settings::_getInstance().bHasServer_ = false;
 
         this->unloadLevel();
Index: code/branches/network/src/orxonox/objects/Backlight.cc
===================================================================
--- code/branches/network/src/orxonox/objects/Backlight.cc	(revision 1895)
+++ code/branches/network/src/orxonox/objects/Backlight.cc	(revision 1901)
@@ -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/branches/network/src/orxonox/objects/Backlight.h
===================================================================
--- code/branches/network/src/orxonox/objects/Backlight.h	(revision 1895)
+++ code/branches/network/src/orxonox/objects/Backlight.h	(revision 1901)
@@ -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/branches/network/src/orxonox/objects/Model.cc
===================================================================
--- code/branches/network/src/orxonox/objects/Model.cc	(revision 1895)
+++ code/branches/network/src/orxonox/objects/Model.cc	(revision 1901)
@@ -46,5 +46,5 @@
 
     /**
-     * 
+     * @brief Constructor
      */
     Model::Model()
@@ -54,4 +54,7 @@
     }
 
+    /**
+     * @brief Destructor
+     */
     Model::~Model()
     {
Index: code/branches/network/src/orxonox/objects/Projectile.cc
===================================================================
--- code/branches/network/src/orxonox/objects/Projectile.cc	(revision 1895)
+++ code/branches/network/src/orxonox/objects/Projectile.cc	(revision 1901)
@@ -41,4 +41,5 @@
 #include "ParticleSpawner.h"
 #include "Model.h"
+#include "Settings.h"
 
 namespace orxonox
@@ -64,5 +65,6 @@
         }
 
-        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)));
     }
 
Index: code/branches/network/src/orxonox/objects/SpaceShip.cc
===================================================================
--- code/branches/network/src/orxonox/objects/SpaceShip.cc	(revision 1895)
+++ code/branches/network/src/orxonox/objects/SpaceShip.cc	(revision 1901)
@@ -181,5 +181,5 @@
           this->setRadarObjectColour(this->getProjectileColour());
       }
-      assert(Model::create());
+      Model::create();
       this->init();
       return true;
@@ -255,17 +255,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
 
