Index: code/trunk/src/network/packet/Acknowledgement.cc
===================================================================
--- code/trunk/src/network/packet/Acknowledgement.cc	(revision 2131)
+++ code/trunk/src/network/packet/Acknowledgement.cc	(revision 2171)
@@ -33,10 +33,10 @@
 #include "core/CoreIncludes.h"
 
-namespace network {
+namespace orxonox {
 namespace packet {
 
 #define PACKET_FLAGS_ACK    0
 #define _PACKETID           0
-#define _ACKID              _PACKETID + sizeof(network::packet::ENUM::Type)
+#define _ACKID              _PACKETID + sizeof(packet::ENUM::Type)
   
 Acknowledgement::Acknowledgement( unsigned int id, unsigned int clientID )
@@ -74,3 +74,3 @@
 
 } //namespace packet
-} //namespace network
+} //namespace orxonox
Index: code/trunk/src/network/packet/Acknowledgement.h
===================================================================
--- code/trunk/src/network/packet/Acknowledgement.h	(revision 2131)
+++ code/trunk/src/network/packet/Acknowledgement.h	(revision 2171)
@@ -33,5 +33,5 @@
 
 
-namespace network {
+namespace orxonox {
 namespace packet {
 /**
@@ -53,5 +53,5 @@
 
 } //namespace packet
-} //namespace network
+} //namespace orxonox
 
 #endif
Index: code/trunk/src/network/packet/Chat.cc
===================================================================
--- code/trunk/src/network/packet/Chat.cc	(revision 2131)
+++ code/trunk/src/network/packet/Chat.cc	(revision 2171)
@@ -31,5 +31,5 @@
 #include "network/Host.h"
 
-namespace network {
+namespace orxonox {
 namespace packet {
   
@@ -77,3 +77,3 @@
 
 } //namespace packet
-} //namespace network
+} //namespace orxonox
Index: code/trunk/src/network/packet/Chat.h
===================================================================
--- code/trunk/src/network/packet/Chat.h	(revision 2131)
+++ code/trunk/src/network/packet/Chat.h	(revision 2171)
@@ -10,5 +10,5 @@
 #include "Packet.h"
 
-namespace network {
+namespace orxonox {
 namespace packet {
 /**
@@ -33,5 +33,5 @@
 
 } //namespace packet
-} //namespace network
+} //namespace orxonox
 
 #endif
Index: code/trunk/src/network/packet/ClassID.cc
===================================================================
--- code/trunk/src/network/packet/ClassID.cc	(revision 2131)
+++ code/trunk/src/network/packet/ClassID.cc	(revision 2171)
@@ -34,5 +34,5 @@
 #include <assert.h>
 
-namespace network {
+namespace orxonox {
 namespace packet {
 
@@ -68,10 +68,10 @@
 
 unsigned int ClassID::getSize() const{
-  return sizeof(network::packet::ENUM::Type) + 2*sizeof(uint32_t) + classNameLength_;
+  return sizeof(packet::ENUM::Type) + 2*sizeof(uint32_t) + classNameLength_;
 }
 
 bool ClassID::process(){
   COUT(3) << "processing classid: " << getClassID() << " name: " << (const char*)(data_+_CLASSNAME) << std::endl;
-  orxonox::Identifier *id=ClassByID( std::string((const char*)(data_+_CLASSNAME) ));
+  Identifier *id=ClassByID( std::string((const char*)(data_+_CLASSNAME) ));
   if(id==NULL)
     return false;
@@ -86,3 +86,3 @@
 
 } //namespace packet
-}//namespace network
+}//namespace orxonox
Index: code/trunk/src/network/packet/ClassID.h
===================================================================
--- code/trunk/src/network/packet/ClassID.h	(revision 2131)
+++ code/trunk/src/network/packet/ClassID.h	(revision 2171)
@@ -35,5 +35,5 @@
 #include "Packet.h"
 
-namespace network {
+namespace orxonox {
 namespace packet {
 
@@ -59,5 +59,5 @@
 
 } //namespace packet
-} //namespace network
+} //namespace orxonox
 
 #endif
Index: code/trunk/src/network/packet/DeleteObjects.cc
===================================================================
--- code/trunk/src/network/packet/DeleteObjects.cc	(revision 2131)
+++ code/trunk/src/network/packet/DeleteObjects.cc	(revision 2171)
@@ -34,5 +34,5 @@
 #include <assert.h>
 
-namespace network {
+namespace orxonox {
 namespace packet {
 
@@ -95,3 +95,3 @@
 
 } //namespace packet
-} //namespace network
+} //namespace orxonox
Index: code/trunk/src/network/packet/DeleteObjects.h
===================================================================
--- code/trunk/src/network/packet/DeleteObjects.h	(revision 2131)
+++ code/trunk/src/network/packet/DeleteObjects.h	(revision 2171)
@@ -34,5 +34,5 @@
 
 
-namespace network {
+namespace orxonox {
 namespace packet {
 /**
@@ -55,5 +55,5 @@
 
 } //namespace packet
-} //namespace network
+} //namespace orxonox
 
 #endif
Index: code/trunk/src/network/packet/Gamestate.cc
===================================================================
--- code/trunk/src/network/packet/Gamestate.cc	(revision 2131)
+++ code/trunk/src/network/packet/Gamestate.cc	(revision 2171)
@@ -38,5 +38,5 @@
 
 
-namespace network {
+namespace orxonox {
 
 namespace packet {
@@ -71,9 +71,9 @@
 }
 
-bool Gamestate::collectData(int id, int mode)
-{
-  int tempsize=0, currentsize=0;
+bool Gamestate::collectData(int id, uint8_t mode)
+{
+  unsigned int tempsize=0, currentsize=0;
   assert(data_==0);
-  int size = calcGamestateSize(id, mode);
+  unsigned int size = calcGamestateSize(id, mode);
 
   COUT(4) << "G.ST.Man: producing gamestate with id: " << id << std::endl;
@@ -86,19 +86,16 @@
   }
 
-#ifndef NDEBUG
-  std::list<Synchronisable*> slist;
-  std::list<Synchronisable*>::iterator iit;
-#endif
   //start collect data synchronisable by synchronisable
   uint8_t *mem=data_;
   mem+=sizeof(GamestateHeader);
-  orxonox::ObjectList<Synchronisable>::iterator it;
-  for(it = orxonox::ObjectList<Synchronisable>::begin(); it; ++it){
+  ObjectList<Synchronisable>::iterator it;
+  for(it = ObjectList<Synchronisable>::begin(); it; ++it){
     tempsize=it->getSize(id, mode);
 
     if(currentsize+tempsize > size){
+      assert(0); // if we don't use multithreading this part shouldn't be neccessary
       // start allocate additional memory
       COUT(3) << "G.St.Man: need additional memory" << std::endl;
-      orxonox::ObjectList<Synchronisable>::iterator temp = it;
+      ObjectList<Synchronisable>::iterator temp = it;
       int addsize=tempsize;
       while(++temp)
@@ -110,9 +107,4 @@
     }// 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))
@@ -127,5 +119,4 @@
   //start write gamestate header
   HEADER->packetType = ENUM::Gamestate;
-  assert( *(ENUM::Type *)(data_) == ENUM::Gamestate);
   HEADER->datasize = currentsize;
   HEADER->id = id;
@@ -140,5 +131,5 @@
 }
 
-bool Gamestate::spreadData(int mode)
+bool Gamestate::spreadData(uint8_t mode)
 {
   assert(data_);
@@ -147,5 +138,5 @@
   uint8_t *mem=data_+sizeof(GamestateHeader);
     // get the start of the Synchronisable list
-  //orxonox::ObjectList<Synchronisable>::iterator it=orxonox::ObjectList<Synchronisable>::begin();
+  //ObjectList<Synchronisable>::iterator it=ObjectList<Synchronisable>::begin();
   Synchronisable *s;
 
@@ -163,6 +154,4 @@
       bool b = s->updateData(mem, mode);
       assert(b);
-      //if(!s->updateData(mem, mode))
-        //return false;
     }
   }
@@ -367,17 +356,11 @@
     assert(it->second->objectID==oldobjectheader->objectID);
     *newobjectheader = *oldobjectheader;
-    objectOffset=sizeof(uint8_t)+sizeof(bool); //skip the size and the availableData variables in the objectheader
+    objectOffset=sizeof(synchronisableHeader); //skip the size and the availableData 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++;
-      }
+      assert(newobjectheader->dataAvailable==true);
+      memcpy(newdata+objectOffset, origdata+objectOffset, objectsize-objectOffset);
     }else{
       newobjectheader->dataAvailable=false;
-      while(objectOffset<objectsize){
-        *(newdata+objectOffset)=0;    // set to 0
-        objectOffset++;
-      }
+      memset(newdata+objectOffset, 0, objectsize-objectOffset);
       assert(objectOffset==objectsize);
     }
@@ -565,11 +548,11 @@
 
 
-unsigned int Gamestate::calcGamestateSize(unsigned int id, int mode)
-{
-  int size=0;
+unsigned int Gamestate::calcGamestateSize(unsigned int id, uint8_t mode)
+{
+  unsigned int size=0;
     // get the start of the Synchronisable list
-  orxonox::ObjectList<Synchronisable>::iterator it;
+  ObjectList<Synchronisable>::iterator it;
     // get total size of gamestate
-  for(it = orxonox::ObjectList<Synchronisable>::begin(); it; ++it)
+  for(it = ObjectList<Synchronisable>::begin(); it; ++it)
     size+=it->getSize(id, mode); // size of the actual data of the synchronisable
 //  size+=sizeof(GamestateHeader);
@@ -582,6 +565,6 @@
  * @return iterator pointing to the next object in the list
  */
-  void Gamestate::removeObject(orxonox::ObjectList<Synchronisable>::iterator &it) {
-    orxonox::ObjectList<Synchronisable>::iterator temp=it;
+  void Gamestate::removeObject(ObjectList<Synchronisable>::iterator &it) {
+    ObjectList<Synchronisable>::iterator temp=it;
     ++it;
     delete  *temp;
Index: code/trunk/src/network/packet/Gamestate.h
===================================================================
--- code/trunk/src/network/packet/Gamestate.h	(revision 2131)
+++ code/trunk/src/network/packet/Gamestate.h	(revision 2171)
@@ -40,5 +40,5 @@
 #endif
 
-namespace network {
+namespace orxonox {
 
 namespace packet {
@@ -69,6 +69,6 @@
     ~Gamestate();
 
-    bool collectData(int id, int mode=0x0);
-    bool spreadData(int mode=0x0);
+    bool collectData(int id, uint8_t mode=0x0);
+    bool spreadData( uint8_t mode=0x0);
     int getID();
     bool isDiffed();
@@ -90,6 +90,6 @@
     bool operator ==(packet::Gamestate gs);
   private:
-    unsigned int calcGamestateSize(unsigned int id, int mode=0x0);
-    void removeObject(orxonox::ObjectListIterator<Synchronisable> &it);
+    unsigned int calcGamestateSize(unsigned int id, uint8_t mode=0x0);
+    void removeObject(ObjectListIterator<Synchronisable> &it);
     std::map<unsigned int, Synchronisable*> dataMap_;
 };
Index: code/trunk/src/network/packet/Packet.cc
===================================================================
--- code/trunk/src/network/packet/Packet.cc	(revision 2131)
+++ code/trunk/src/network/packet/Packet.cc	(revision 2171)
@@ -46,5 +46,5 @@
 #include "core/CoreIncludes.h"
 
-namespace network{
+namespace orxonox{
 
 namespace packet{
@@ -53,5 +53,6 @@
 #define _PACKETID           0
 
-std::map<ENetPacket *, Packet *> Packet::packetMap_;
+std::map<size_t, Packet *> Packet::packetMap_;
+boost::recursive_mutex Packet::packetMap_mutex;
 
 Packet::Packet(){
@@ -128,4 +129,7 @@
       return false;
     }
+    // Assures we don't create a packet and destroy it right after in another thread
+    // without having a reference in the packetMap_
+    boost::recursive_mutex::scoped_lock lock(Packet::packetMap_mutex);
     // We deliver ENet the data address so that it doesn't memcpy everything again.
     // --> We have to delete data_ ourselves!
@@ -134,5 +138,5 @@
     // Add the packet to a global list so we can access it again once enet calls our
     // deletePacket method. We can of course only give a one argument function to the ENet C library.
-    packetMap_[enetPacket_] = this;
+    packetMap_[(size_t)(void*)enetPacket_] = this;
   }
 #ifndef NDEBUG
@@ -153,5 +157,5 @@
 //  ENetPacket *temp = enetPacket_;
 //  enetPacket_ = 0; // otherwise we have a double free because enet already handles the deallocation of the packet
-  network::Host::addPacket( enetPacket_, clientID_);
+  Host::addPacket( enetPacket_, clientID_);
   return true;
 }
@@ -207,11 +211,12 @@
 */
 void Packet::deletePacket(ENetPacket *enetPacket){
+  boost::recursive_mutex::scoped_lock lock(Packet::packetMap_mutex);
   // Get our Packet from a gloabal map with all Packets created in the send() method of Packet.
-  std::map<ENetPacket*, Packet*>::iterator it = packetMap_.find(enetPacket);
+  std::map<size_t, Packet*>::iterator it = packetMap_.find((size_t)enetPacket);
   assert(it != packetMap_.end());
   // Make sure we don't delete it again in the destructor
   it->second->enetPacket_ = 0;
   delete it->second;
-  //packetMap_.erase(it);
+  packetMap_.erase(it);
   COUT(4) << "PacketMap size: " << packetMap_.size() << std::endl;
 }
@@ -219,4 +224,4 @@
 } // namespace packet
 
-} // namespace network
-
+} // namespace orxonox
+
Index: code/trunk/src/network/packet/Packet.h
===================================================================
--- code/trunk/src/network/packet/Packet.h	(revision 2131)
+++ code/trunk/src/network/packet/Packet.h	(revision 2171)
@@ -29,12 +29,13 @@
 #define NETWORKPACKET_H
 
-#include "../NetworkPrereqs.h"
+#include "network/NetworkPrereqs.h"
 
 #include <map>
 #include <enet/enet.h>
+#include <boost/thread/recursive_mutex.hpp>
 
 #include "util/Integers.h"
 
-namespace network {
+namespace orxonox {
 
 namespace packet{
@@ -92,5 +93,7 @@
     bool bDataENetAllocated_;
   private:
-    static std::map<ENetPacket *, Packet *> packetMap_;
+    static std::map<size_t, Packet *> packetMap_;
+    //! Static mutex for any packetMap_ access
+    static boost::recursive_mutex packetMap_mutex;
     ENetPacket *enetPacket_;
 };
@@ -98,5 +101,5 @@
 } //namespace packet
 
-} //namespace network
+} //namespace orxonox
 
 #endif
Index: code/trunk/src/network/packet/Welcome.cc
===================================================================
--- code/trunk/src/network/packet/Welcome.cc	(revision 2131)
+++ code/trunk/src/network/packet/Welcome.cc	(revision 2171)
@@ -36,5 +36,5 @@
 #include <assert.h>
 
-namespace network {
+namespace orxonox {
 namespace packet {
 
@@ -70,5 +70,5 @@
 
 unsigned int Welcome::getSize() const{
-  return sizeof(network::packet::ENUM::Type) + 2*sizeof(uint32_t);
+  return sizeof(packet::ENUM::Type) + 2*sizeof(uint32_t);
 }
 
@@ -87,3 +87,3 @@
 
 } //namespace packet
-}//namespace network
+}//namespace orxonox
Index: code/trunk/src/network/packet/Welcome.h
===================================================================
--- code/trunk/src/network/packet/Welcome.h	(revision 2131)
+++ code/trunk/src/network/packet/Welcome.h	(revision 2171)
@@ -33,5 +33,5 @@
 #include "Packet.h"
 
-namespace network {
+namespace orxonox {
 namespace packet {
 
@@ -54,5 +54,5 @@
 
 } //namespace packet
-} //namespace network
+} //namespace orxonox
 
 #endif
