Index: code/trunk/src/network/packet/Acknowledgement.cc
===================================================================
--- code/trunk/src/network/packet/Acknowledgement.cc	(revision 1856)
+++ 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 1856)
+++ 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 1856)
+++ 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 1856)
+++ 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 1856)
+++ 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 1856)
+++ 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 1856)
+++ 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 1856)
+++ 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 1856)
+++ 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 1856)
+++ 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 1856)
+++ 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 1856)
+++ 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();
