Index: /code/branches/network/src/network/packet/Acknowledgement.cc
===================================================================
--- /code/branches/network/src/network/packet/Acknowledgement.cc	(revision 1701)
+++ /code/branches/network/src/network/packet/Acknowledgement.cc	(revision 1701)
@@ -0,0 +1,49 @@
+#include "Acknowledgement.h"
+#include "Packet.h"
+#include "network/Host.h"
+
+namespace network {
+namespace packet {
+
+#define PACKET_FLAGS_ACK    0
+#define _PACKETID           0
+#define _ACKID              _PACKETID + sizeof(network::packet::ENUM::Type)
+  
+Acknowledgement::Acknowledgement( unsigned int id, int clientID )
+ : PacketContent()
+{
+  flags_ = flags_ | PACKET_FLAGS_ACK;
+  data_=new unsigned char[ getSize() ];
+  *(ENUM::Type *)&data_[ _PACKETID ] = ENUM::Acknowledgement;
+  *(unsigned int *)&data_[ _ACKID ] = id;
+  clientID_=clientID;
+}
+
+Acknowledgement::Acknowledgement( unsigned char *data, int clientID )
+  : PacketContent(data)
+{
+  clientID_=clientID;
+}
+
+Acknowledgement::~Acknowledgement()
+{
+}
+
+unsigned char *Acknowledgement::getData(){
+  return data_;
+}
+
+unsigned int Acknowledgement::getSize() const{
+  return _ACKID + sizeof(unsigned int);
+}
+
+bool Acknowledgement::process(){
+  return Host::ackGamestate(data_[_ACKID], clientID_);
+}
+
+unsigned int Acknowledgement::getAckID(){
+  return *(unsigned int *)&data_[ _ACKID ];
+}
+
+} //namespace packet
+} //namespace network
Index: /code/branches/network/src/network/packet/Acknowledgement.h
===================================================================
--- /code/branches/network/src/network/packet/Acknowledgement.h	(revision 1701)
+++ /code/branches/network/src/network/packet/Acknowledgement.h	(revision 1701)
@@ -0,0 +1,58 @@
+/*
+ *   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 NETWORKACKNOLEDGEMENT_H
+#define NETWORKACKNOLEDGEMENT_H
+
+#include "PacketContent.h"
+
+
+namespace network {
+namespace packet {
+/**
+	@author 
+*/
+class Acknowledgement : public PacketContent
+{
+public:
+  Acknowledgement( unsigned int id, int clientID );
+  Acknowledgement( unsigned char* data, int clientID );
+  ~Acknowledgement();
+  
+  unsigned char *getData();
+  inline unsigned int getSize() const;
+  bool process();
+  
+  unsigned int getAckID();
+private:
+  int clientID_;
+};
+
+} //namespace packet
+} //namespace network
+
+#endif
Index: /code/branches/network/src/network/packet/Chat.cc
===================================================================
--- /code/branches/network/src/network/packet/Chat.cc	(revision 1701)
+++ /code/branches/network/src/network/packet/Chat.cc	(revision 1701)
@@ -0,0 +1,53 @@
+#include "Chat.h"
+#include "Packet.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)
+
+Chat::Chat( std::string& message, int clientID )
+ : PacketContent()
+{
+  flags_ = flags_ | PACKET_FLAGS_CHAT;
+  messageLength_ = message.length()+1;
+  data_=new unsigned char[ getSize() ];
+  *(ENUM::Type *)&data_[ _PACKETID ] = packet::ENUM::Chat;
+  *(unsigned int *)&data_[ _MESSAGELENGTH ] = messageLength_;
+  memcpy( &data_[ _MESSAGE ], (void *)message.c_str(), messageLength_ );
+  clientID_=clientID;
+}
+
+Chat::Chat( unsigned char *data, int clientID )
+  : PacketContent(data)
+{
+  messageLength_ = *(unsigned int *)&data[ _MESSAGELENGTH ];
+  clientID_ = clientID;
+}
+
+Chat::~Chat()
+{
+}
+
+unsigned char *Chat::getData(){
+  return data_;
+}
+
+unsigned int Chat::getSize() const{
+  return _MESSAGE + messageLength_;
+}
+
+bool Chat::process(){
+  //TODO: change this !!!
+  return true;
+}
+
+unsigned char *Chat::getMessage(){
+  return &data_[ _MESSAGE ];
+}
+
+} //namespace packet
+} //namespace network
Index: /code/branches/network/src/network/packet/Chat.h
===================================================================
--- /code/branches/network/src/network/packet/Chat.h	(revision 1701)
+++ /code/branches/network/src/network/packet/Chat.h	(revision 1701)
@@ -0,0 +1,61 @@
+/*
+ *   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 NETWORKCHAT_H
+#define NETWORKCHAT_H
+
+#include <string>
+
+#include "PacketContent.h"
+
+namespace network {
+namespace packet {
+/**
+	@author 
+*/
+class Chat : public PacketContent
+{
+public:
+  Chat( std::string& message, int clientID );
+  Chat( unsigned char* data, int clientID );
+  ~Chat();
+  
+  unsigned char *getData();
+  inline unsigned int getSize() const;
+  bool process();
+  
+  unsigned int getMessageLength(){ return messageLength_; };
+  unsigned char *getMessage();
+private:
+  unsigned int messageLength_;
+  int clientID_;
+};
+
+} //namespace packet
+} //namespace network
+
+#endif
Index: /code/branches/network/src/network/packet/ClassID.cc
===================================================================
--- /code/branches/network/src/network/packet/ClassID.cc	(revision 1701)
+++ /code/branches/network/src/network/packet/ClassID.cc	(revision 1701)
@@ -0,0 +1,65 @@
+#include "ClassID.h"
+#include "Packet.h"
+#include "core/CoreIncludes.h"
+#include <string>
+
+
+namespace network {
+namespace packet {
+
+#define PACKET_FLAGS_CLASSID  ENET_PACKET_FLAG_RELIABLE
+#define _PACKETID             0
+#define _CLASSID              _PACKETID + sizeof(ENUM::Type)
+#define _CLASSNAMELENGTH      _CLASSID + sizeof(unsigned int)
+#define _CLASSNAME            _CLASSNAMELENGTH + sizeof(classNameLength_)
+  
+  ClassID::ClassID( unsigned int classID, std::string className )
+ : PacketContent()
+{
+  flags_ = flags_ | PACKET_FLAGS_CLASSID;
+  classNameLength_=className.length()+1;
+  data_=new unsigned char[ getSize() ];
+  if(!data_)
+    return;
+  *(packet::ENUM::Type *)&data_[ _PACKETID ] = packet::ENUM::ClassID;
+  *(unsigned int *)&data_[ _CLASSID ] = classID;
+  *(unsigned int *)&data_[ _CLASSNAMELENGTH ] = classNameLength_;
+  memcpy( &data_[ _CLASSNAME ], (void *)className.c_str(), classNameLength_ );
+}
+
+ClassID::ClassID( unsigned char *data )
+  : PacketContent(data)
+{
+  memcpy( (void *)&classNameLength_, &data[ sizeof(ENUM::Type) + sizeof(int) ], sizeof(classNameLength_) );
+}
+
+ClassID::~ClassID()
+{
+}
+
+unsigned char *ClassID::getData(){
+  return data_;
+}
+
+unsigned int ClassID::getSize() const{
+  return sizeof(network::packet::ENUM::Type) + sizeof(int) + classNameLength_;
+}
+
+bool ClassID::process(){
+  orxonox::Identifier *id=ID( std::string((const char*)&data_[ sizeof(network::packet::ENUM::Type) ]) );
+  if(id==NULL)
+    return false;
+  id->setNetworkID( getClassID() );
+  return true;
+}
+
+unsigned int ClassID::getClassID(){
+  return *(unsigned int *)&data_[ _CLASSID ];
+}
+
+// unsigned int ClassID::getClassNameLength(){
+//   return *(unsigned int *)&data[ _CLASSNAMELENGTH ];
+// }
+
+} //namespace packet
+}//namespace network
Index: /code/branches/network/src/network/packet/ClassID.h
===================================================================
--- /code/branches/network/src/network/packet/ClassID.h	(revision 1701)
+++ /code/branches/network/src/network/packet/ClassID.h	(revision 1701)
@@ -0,0 +1,62 @@
+/*
+ *   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 NETWORKCLASSID_H
+#define NETWORKCLASSID_H
+
+#include <string>
+
+#include "PacketContent.h"
+
+namespace network {
+namespace packet {
+
+/**
+	@author 
+*/
+class ClassID : public PacketContent
+{
+public:
+  ClassID( unsigned int classID, std::string className );
+  ClassID( unsigned char* data );
+  ~ClassID();
+  
+  unsigned char *getData();
+  inline unsigned int getSize() const;
+  bool process();
+  
+  unsigned int getClassID();
+  unsigned int getClassNameLength(){ return classNameLength_; }
+  unsigned char *getClassName();
+private:
+  unsigned int classNameLength_;
+};
+
+} //namespace packet
+} //namespace network
+
+#endif
Index: /code/branches/network/src/network/packet/Gamestate.cc
===================================================================
--- /code/branches/network/src/network/packet/Gamestate.cc	(revision 1701)
+++ /code/branches/network/src/network/packet/Gamestate.cc	(revision 1701)
@@ -0,0 +1,314 @@
+#include "Gamestate.h"
+#include "network/ClientInformation.h"
+
+
+#include <zlib.h>
+#include <assert.h>
+
+
+
+namespace network {
+
+namespace packet {
+  
+
+#define GAMESTATE_START(data) data + sizeof(GamestateHeader)
+#define GAMESTATE_HEADER(data) ((GamestateHeader *)data)
+#define HEADER GAMESTATE_HEADER(data_)
+  
+Gamestate::Gamestate()
+{
+}
+
+Gamestate::Gamestate(unsigned char *data, bool compressed):
+    PacketContent(data)
+{
+  compressed_ = compressed;
+  //GAMESTATE_HEADER = (GamestateHeader *)data;
+  //if(!compressed)
+    //bs_ = new Bytestream(data+sizeof(GamestateHeader), GAMESTATE_HEADER->compsize);
+}
+
+
+Gamestate::~Gamestate()
+{
+}
+
+bool Gamestate::collectData(int id, int mode)
+{
+  int tempsize=0, currentsize=0;
+  assert(data_==0 /*&& bs_==0*/);
+  int size = calcGamestateSize(mode);
+  
+  COUT(4) << "G.ST.Man: producing gamestate with id: " << id << std::endl;
+    //retval->data = (unsigned char*)malloc(size);
+  if(size==0)
+    return false;
+  data_ = new unsigned char[size + sizeof(GamestateHeader)];
+  //bs_ = new Bytestream(data_+sizeof(GamestateHeader), size);
+  if(!data_){
+    COUT(2) << "GameStateManager: could not allocate memory" << std::endl;
+    return false;
+  }
+
+  //start collect data synchronisable by synchronisable
+  unsigned char *mem=data_;
+  mem+=sizeof(GamestateHeader);
+  orxonox::Iterator<Synchronisable> it;
+  for(it = orxonox::ObjectList<Synchronisable>::start(); it; ++it){
+    tempsize=it->getSize2(mode);
+    
+    if(currentsize+tempsize > size){
+      // start allocate additional memory
+      COUT(3) << "G.St.Man: need additional memory" << std::endl;
+      orxonox::Iterator<Synchronisable> temp = it;
+      int addsize=tempsize;
+      while(++temp)
+        addsize+=temp->getSize2(mode);
+      data_ = (unsigned char *)realloc(data_, sizeof(GamestateHeader) + currentsize + addsize);
+      if(!data_)
+        return false;
+      size = currentsize+addsize;
+    }// stop allocate additional memory
+
+    if(!it->getData2(mem, mode))
+      return false; // mem pointer gets automatically increased because of call by reference
+    // increase size counter by size of current synchronisable
+    currentsize+=tempsize;
+  }
+  
+  
+  //start write gamestate header
+  HEADER->normsize = currentsize;
+  HEADER->id = id;
+  HEADER->diffed = false;
+  HEADER->complete = true;
+  compressed_=false;
+  //stop write gamestate header
+  
+  COUT(5) << "G.ST.Man: Gamestate size: " << currentsize << std::endl;
+  COUT(5) << "G.ST.Man: 'estimated' (and corrected) Gamestate size: " << size << std::endl;
+  return true;
+}
+
+bool Gamestate::spreadData(int mode)
+{
+  assert(data_ && !compressed_ && !HEADER->diffed);
+  unsigned int size, objectID, classID;
+  unsigned char *mem=data_+sizeof(GamestateHeader);
+    // get the start of the Synchronisable list
+  orxonox::Iterator<Synchronisable> it=orxonox::ObjectList<Synchronisable>::start();
+  
+  while(mem < data_+sizeof(GamestateHeader)+HEADER->normsize){
+      // extract synchronisable header
+    size = *(int *)mem;
+    objectID = *(int*)(mem+sizeof(int));
+    classID = *(int*)(mem+2*sizeof(int));
+
+    if(!it || it->objectID!=objectID){
+        // 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 
+    {
+        // we have our object
+      if(! it->updateData(mem, mode))
+      {
+        COUT(1) << "We couldn't update objectID: " \
+            << objectID << "; classID: " << classID << std::endl;
+      }
+    }
+    ++it;
+  }
+
+  return true;
+}
+
+unsigned char *Gamestate::getData()
+{
+  assert(data_!=0);
+  return data_;
+}
+
+unsigned int Gamestate::getSize() const
+{
+  if(compressed_)
+    return HEADER->compsize+sizeof(GamestateHeader);
+  else
+  {
+    return HEADER->normsize+sizeof(GamestateHeader);
+    //assert(bs_);
+    //return bs_->getSize();
+  }
+}
+
+bool Gamestate::process()
+{
+  //FIXME: TODO: implement this function
+  return true;
+}
+
+bool Gamestate::compressData()
+{
+  assert(HEADER);
+  uLongf buffer = (uLongf)((HEADER->normsize + 12)*1.01)+1;
+  if(buffer==0)
+    return false;
+  
+  unsigned char *ndata = new unsigned char[buffer+sizeof(GamestateHeader)];
+  unsigned char *dest = GAMESTATE_START(ndata);
+  int retval;
+  retval = compress( dest, &buffer, GAMESTATE_START(data_), (uLong)(HEADER->normsize) );
+  switch ( retval ) {
+    case Z_OK: COUT(5) << "G.St.Man: compress: successfully compressed" << std::endl; break;
+    case Z_MEM_ERROR: COUT(1) << "G.St.Man: compress: not enough memory available in gamestate.compress" << std::endl; 
+    return false;
+    case Z_BUF_ERROR: COUT(2) << "G.St.Man: compress: not enough memory available in the buffer in gamestate.compress" << std::endl;
+    return false;
+    case Z_DATA_ERROR: COUT(2) << "G.St.Man: compress: data corrupted in gamestate.compress" << std::endl;
+    return false;
+  }
+
+  //copy and modify header
+  HEADER->compsize = buffer;
+  *GAMESTATE_HEADER(ndata) = *HEADER;
+  //delete old data
+//  delete bs_;
+  delete[] data_;
+  //save new data
+  data_ = ndata;
+  compressed_ = true;
+  return true;
+}
+bool Gamestate::decompressData()
+{
+  //COUT(4) << "GameStateClient: uncompressing gamestate. id: " << a->id << ", baseid: " << a->base_id << ", normsize: " << a->normsize << ", compsize: " << a->compsize << std::endl;
+  int normsize = HEADER->normsize;
+  int compsize = HEADER->compsize;
+  int bufsize;
+  if(normsize < compsize)
+    bufsize = compsize;
+  else
+    bufsize = normsize;
+  if(bufsize==0)
+    return NULL;
+  unsigned char *ndata = new unsigned char[bufsize + sizeof(GamestateHeader)];
+  unsigned char *dest = ndata + sizeof(GamestateHeader);
+  int retval;
+  uLongf length=normsize;
+  retval = uncompress( dest, &length, data_+sizeof(GamestateHeader), (uLong)compsize );
+  switch ( retval ) {
+    case Z_OK: COUT(5) << "successfully decompressed" << std::endl; break;
+    case Z_MEM_ERROR: COUT(1) << "not enough memory available" << std::endl; return false;
+    case Z_BUF_ERROR: COUT(2) << "not enough memory available in the buffer" << std::endl; return false;
+    case Z_DATA_ERROR: COUT(2) << "data corrupted (zlib)" << std::endl; return false;
+  }
+  
+  compressed_ = false;
+  //copy over the header
+  *GAMESTATE_HEADER(ndata) = *HEADER;
+  //delete old (compressed data)
+  delete []data_;
+  //set new pointers and create bytestream
+  data_ = ndata;
+  //bs_ = new Bytestream(getGs(), GAMESTATE_HEADER->normsize);
+  
+  return true;
+}
+
+Gamestate *Gamestate::diff(Gamestate *base)
+{
+  //unsigned char *basep = base->getGs()/*, *gs = getGs()*/;
+  unsigned char *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;
+  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){
+    *(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){
+      while(of<dest_length){
+        *(dest+of)=n^*(gs+of);
+        of++;
+      }
+    }
+  }
+
+  Gamestate *g = new Gamestate(ndata, false);
+  return g;
+}
+
+Gamestate *Gamestate::undiff(Gamestate *base)
+{
+  assert(this && base);
+  assert(!this->compressed_ && !base->compressed_);
+  //unsigned char *basep = base->getGs()/*, *gs = getGs()*/;
+  unsigned char *basep = GAMESTATE_START(base->data_);
+  unsigned char *gs = GAMESTATE_START(this->data_);
+  unsigned int of=0; // pointers offset
+  unsigned int dest_length=0;
+  dest_length=HEADER->normsize;
+  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){
+    *(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){
+      while(of < dest_length){
+        *(dest+of)=n^*(gs+of);
+        of++;
+      }
+    }
+  }
+  
+  Gamestate *g = new Gamestate(ndata, false);
+  return g;
+}
+
+
+unsigned int Gamestate::calcGamestateSize(int mode)
+{
+  int size=0;
+    // get the start of the Synchronisable list
+  orxonox::Iterator<Synchronisable> it;
+    // get total size of gamestate
+  for(it = orxonox::ObjectList<Synchronisable>::start(); it; ++it)
+    size+=it->getSize2(mode); // size of the actual data of the synchronisable
+//  size+=sizeof(GamestateHeader);
+  return size;
+}
+
+/**
+ * This function removes a Synchronisable out of the universe
+ * @param it iterator of the list pointing to the object
+ * @return iterator pointing to the next object in the list
+ */
+  void Gamestate::removeObject(orxonox::Iterator<Synchronisable> &it) {
+    orxonox::Iterator<Synchronisable> temp=it;
+    ++it;
+    delete  *temp;
+  }
+
+}
+
+}
Index: /code/branches/network/src/network/packet/Gamestate.h
===================================================================
--- /code/branches/network/src/network/packet/Gamestate.h	(revision 1701)
+++ /code/branches/network/src/network/packet/Gamestate.h	(revision 1701)
@@ -0,0 +1,88 @@
+/*
+ *   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 "PacketContent.h"
+#include "network/Synchronisable.h"
+//#include "util/Bytestream.h"
+#include "core/CoreIncludes.h"
+
+#ifndef NETWORK_PACKETGAMESTATE_H
+#define NETWORK_PACKETGAMESTATE_H
+
+namespace network {
+
+namespace packet {
+  
+struct GamestateHeader{
+  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
+};
+
+/**
+	@author 
+*/
+class Gamestate: public PacketContent{
+  public:
+    Gamestate();
+    Gamestate(unsigned char *data, bool compressed);
+    
+    ~Gamestate();
+    
+    bool collectData(int id, int mode=0x0);
+    bool spreadData(int mode=0x0);
+    
+    // PacketContent functions
+    virtual unsigned char *getData();
+    virtual unsigned int getSize() const;
+    virtual bool process();
+
+    
+  private:
+    bool compressData();
+    bool decompressData();
+    Gamestate *diff(Gamestate *base);
+    Gamestate *undiff(Gamestate *base);
+    unsigned int calcGamestateSize(int mode=0x0);
+    //unsigned char *getGs(){ return bs_->getData(); }
+    void removeObject(orxonox::Iterator<Synchronisable> &it);
+
+    
+    //Bytestream *bs_;
+    //GamestateHeader *header_;
+    bool compressed_;
+};
+
+}
+
+}
+
+#endif
Index: /code/branches/network/src/network/packet/Packet.cc
===================================================================
--- /code/branches/network/src/network/packet/Packet.cc	(revision 1701)
+++ /code/branches/network/src/network/packet/Packet.cc	(revision 1701)
@@ -0,0 +1,90 @@
+
+#include <enet/enet.h>
+
+#include "Packet.h"
+#include "network/ConnectionManager.h"
+#include "network/ClientInformation.h"
+
+#include "Acknowledgement.h"
+#include "Chat.h"
+#include "ClassID.h"
+#include "network/Host.h"
+//#include "Gamestate.h"
+
+namespace network{
+
+namespace packet{
+  
+#define _PACKETID           0
+  
+
+  
+Packet::Packet(){
+  packetDirection_ = ENUM::Outgoing;
+  clientID_=0;
+  packetContent_=0;
+  enetPacket_=0;
+}
+
+Packet::Packet(PacketContent *content){
+  packetDirection_ = ENUM::Outgoing;
+  clientID_=0;
+  packetContent_=content;
+  enetPacket_=0;
+}
+
+Packet::Packet(ENetPacket *packet, ENetPeer *peer){
+  packetDirection_ = ENUM::Incoming;
+  enetPacket_ = packet;
+  clientID_ = ClientInformation::findClient(&peer->address)->getID();
+  packetContent_ = createPacketContent(packet);
+}
+
+Packet::~Packet(){
+  if(packetContent_)
+    delete packetContent_;
+  if(enetPacket_){
+    enet_packet_destroy(enetPacket_);
+  }
+}
+
+
+bool Packet::send(){
+  if(!packetDirection_ == ENUM::Outgoing || !packetDirection_ == ENUM::Bidirectional )
+    return false;
+  if(!enetPacket_){
+    if(!packetContent_)
+      return false;
+    enetPacket_ = enet_packet_create(packetContent_->getData(), packetContent_->getSize(), packetContent_->getFlags());
+  }
+  network::Host::addPacket( enetPacket_, clientID_);
+  return true;
+}
+
+PacketContent *Packet::createPacketContent(ENetPacket *packet){
+  unsigned char *data = packet->data;
+  switch( *(ENUM::Type *)&data[_PACKETID] )
+  {
+    case ENUM::Acknowledgement:
+      packetContent_ = new Acknowledgement( data, clientID_ );
+      break;
+    case ENUM::Chat:
+      packetContent_ = new Chat( data, clientID_ );
+      break;
+    case ENUM::ClassID:
+      packetContent_ = new ClassID( data );
+      break;
+    case ENUM::Gamestate:
+      // TODO: remove brackets
+      // packetContent_ = new Gamestate( data );
+      break;
+    default:
+      assert(0);
+  }
+  return packetContent_;
+}
+
+} // namespace packet
+
+} // namespace network
+
Index: /code/branches/network/src/network/packet/Packet.h
===================================================================
--- /code/branches/network/src/network/packet/Packet.h	(revision 1701)
+++ /code/branches/network/src/network/packet/Packet.h	(revision 1701)
@@ -0,0 +1,84 @@
+/*
+ *   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 NETWORKPACKET_H
+#define NETWORKPACKET_H
+
+#include "PacketContent.h"
+
+#include <enet/enet.h>
+
+namespace network {
+
+namespace packet{
+  
+namespace ENUM{
+  enum Direction{
+    Incoming,
+    Outgoing,
+    Bidirectional
+  };
+  enum Type{
+    Acknowledgement,
+    Gamestate,
+    ClassID,
+    Chat
+  };
+}
+  
+/**
+	@author Oliver Scheuss <scheusso [at] ee.ethz.ch>
+*/
+class Packet{
+  public:
+    Packet();
+    Packet(PacketContent *content);
+    Packet(ENetPacket *packet, ENetPeer *peer);
+    ~Packet();
+    
+    int getClientID(){ return clientID_; }
+    PacketContent *getPacketContent(){ return packetContent_; }
+    
+    void setClientID( int id ){ clientID_ = id; }
+    void setPacketContent(PacketContent *content){ packetContent_=content; }
+    
+    bool send();
+  protected:
+  private:
+    PacketContent *createPacketContent(ENetPacket *packet);
+    
+    int clientID_;
+    PacketContent *packetContent_;
+    ENetPacket *enetPacket_;
+    ENUM::Direction packetDirection_;
+};
+
+} //namespace packet
+
+} //namespace network
+
+#endif
Index: /code/branches/network/src/network/packet/PacketContent.h
===================================================================
--- /code/branches/network/src/network/packet/PacketContent.h	(revision 1701)
+++ /code/branches/network/src/network/packet/PacketContent.h	(revision 1701)
@@ -0,0 +1,75 @@
+/*
+ *   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 NETWORKPACKETCONTENT_H
+#define NETWORKPACKETCONTENT_H
+
+#include <enet/enet.h>
+#include <string.h>
+
+#define PACKET_FLAG_DEFAULT ENET_PACKET_FLAG_NO_ALLOCATE
+
+namespace network {
+
+namespace packet{
+  
+/**
+	@author Oliver Scheuss <scheusso [at] ee.ethz.ch>
+*/
+class PacketContent{
+  public:
+    virtual ~PacketContent()
+    { if(data_) delete[] data_; }
+    virtual unsigned char *getData()=0;
+    virtual unsigned int getSize() const =0;
+    virtual bool process()=0;
+    enet_uint32 getFlags(){ return flags_; }
+  protected:
+    PacketContent()
+        { flags_ = PACKET_FLAG_DEFAULT;
+        data_=0; }
+    PacketContent( unsigned char *data )
+        { flags_ = PACKET_FLAG_DEFAULT; data_=data; }
+    PacketContent(const PacketContent& p){
+      flags_=p.flags_;
+      if(p.data_){
+        data_ = new unsigned char[p.getSize()];
+        memcpy(data_, p.data_, p.getSize());
+      }else
+        data_=0;
+    }
+    
+    enet_uint32 flags_;
+    unsigned char *data_;
+  private:
+};
+
+} //namespace packet
+
+} //namespace network
+
+#endif
