Index: code/trunk/src/network/ChatListener.cc
===================================================================
--- code/trunk/src/network/ChatListener.cc	(revision 2131)
+++ code/trunk/src/network/ChatListener.cc	(revision 2171)
@@ -32,5 +32,5 @@
 #include "core/Core.h"
 
-namespace network
+namespace orxonox
 {
     ChatListener::ChatListener()
Index: code/trunk/src/network/ChatListener.h
===================================================================
--- code/trunk/src/network/ChatListener.h	(revision 2131)
+++ code/trunk/src/network/ChatListener.h	(revision 2171)
@@ -35,7 +35,7 @@
 #include "core/OrxonoxClass.h"
 
-namespace network
+namespace orxonox
 {
-    class _NetworkExport ChatListener : virtual public orxonox::OrxonoxClass
+    class _NetworkExport ChatListener : virtual public OrxonoxClass
     {
         public:
Index: code/trunk/src/network/Client.cc
===================================================================
--- code/trunk/src/network/Client.cc	(revision 2131)
+++ code/trunk/src/network/Client.cc	(revision 2171)
@@ -49,5 +49,5 @@
 // #include "packet/Acknowledgement.h"
 
-namespace network
+namespace orxonox
 {
 //   SetConsoleCommandShortcut(Client, chat);
Index: code/trunk/src/network/Client.h
===================================================================
--- code/trunk/src/network/Client.h	(revision 2131)
+++ code/trunk/src/network/Client.h	(revision 2171)
@@ -54,8 +54,8 @@
 
 
-namespace network
+namespace orxonox
 {
   /**
-  network::Client *client;
+  Client *client;
   * The network/Client class
   * This class implements all necessary function for the network communication
Index: code/trunk/src/network/ClientConnection.cc
===================================================================
--- code/trunk/src/network/ClientConnection.cc	(revision 2131)
+++ code/trunk/src/network/ClientConnection.cc	(revision 2171)
@@ -48,5 +48,5 @@
 #include "util/Debug.h"
 
-namespace network
+namespace orxonox
 {
   //static boost::thread_group network_threads;
Index: code/trunk/src/network/ClientConnection.h
===================================================================
--- code/trunk/src/network/ClientConnection.h	(revision 2131)
+++ code/trunk/src/network/ClientConnection.h	(revision 2171)
@@ -50,5 +50,5 @@
 namespace boost { class thread; }
 
-namespace network
+namespace orxonox
 {
 
Index: code/trunk/src/network/ClientConnectionListener.cc
===================================================================
--- code/trunk/src/network/ClientConnectionListener.cc	(revision 2131)
+++ code/trunk/src/network/ClientConnectionListener.cc	(revision 2171)
@@ -3,5 +3,5 @@
 #include "core/Core.h"
 
-namespace network{
+namespace orxonox{
 
   ClientConnectionListener::ClientConnectionListener()
@@ -11,5 +11,5 @@
 
   void ClientConnectionListener::getConnectedClients(){
-    if(orxonox::Core::showsGraphics())
+    if(Core::showsGraphics())
       this->clientConnected(0); //server client id
     ClientInformation *client = ClientInformation::getBegin();
Index: code/trunk/src/network/ClientConnectionListener.h
===================================================================
--- code/trunk/src/network/ClientConnectionListener.h	(revision 2131)
+++ code/trunk/src/network/ClientConnectionListener.h	(revision 2171)
@@ -6,7 +6,7 @@
 #include "core/OrxonoxClass.h"
 
-namespace network{
+namespace orxonox{
 
-  class _NetworkExport ClientConnectionListener : virtual public orxonox::OrxonoxClass
+  class _NetworkExport ClientConnectionListener : virtual public OrxonoxClass
   {
     friend class Server;
Index: code/trunk/src/network/ClientInformation.cc
===================================================================
--- code/trunk/src/network/ClientInformation.cc	(revision 2131)
+++ code/trunk/src/network/ClientInformation.cc	(revision 2171)
@@ -43,5 +43,5 @@
 #include <iostream> //debug
 
-namespace network
+namespace orxonox
 {
 
Index: code/trunk/src/network/ClientInformation.h
===================================================================
--- code/trunk/src/network/ClientInformation.h	(revision 2131)
+++ code/trunk/src/network/ClientInformation.h	(revision 2171)
@@ -48,5 +48,5 @@
 // WATCH OUT: THE CLIENTINFORMATION LIST IS NOT THREADSAFE ANYMORE
 
-namespace network
+namespace orxonox
 {
   static const unsigned int GAMESTATEID_INITIAL = (unsigned int)-1;
Index: code/trunk/src/network/ConnectionManager.cc
===================================================================
--- code/trunk/src/network/ConnectionManager.cc	(revision 2131)
+++ code/trunk/src/network/ConnectionManager.cc	(revision 2171)
@@ -65,5 +65,5 @@
 }
 
-namespace network
+namespace orxonox
 {
   //boost::thread_group network_threads;
@@ -138,5 +138,5 @@
 
   bool ConnectionManager::addPacket(ENetPacket *packet, ENetPeer *peer) {
-    boost::recursive_mutex::scoped_lock lock(instance_->enet_mutex);
+    boost::recursive_mutex::scoped_lock lock(ConnectionManager::enet_mutex);
     if(enet_peer_send(peer, NETWORK_DEFAULT_CHANNEL, packet)!=0)
       return false;
@@ -156,5 +156,5 @@
     if(!instance_)
       return false;
-    boost::recursive_mutex::scoped_lock lock(instance_->enet_mutex);
+    boost::recursive_mutex::scoped_lock lock(ConnectionManager::enet_mutex);
     for(ClientInformation *i=ClientInformation::getBegin()->next(); i!=0; i=i->next()){
       COUT(3) << "adding broadcast packet for client: " << i->getID() << std::endl;
@@ -169,5 +169,5 @@
     if(server==NULL || !instance_)
       return false;
-    boost::recursive_mutex::scoped_lock lock(enet_mutex);
+    boost::recursive_mutex::scoped_lock lock(ConnectionManager::enet_mutex);
     enet_host_flush(server);
     lock.unlock();
@@ -180,5 +180,5 @@
     atexit(enet_deinitialize);
     { //scope of the mutex
-      boost::recursive_mutex::scoped_lock lock(enet_mutex);
+      boost::recursive_mutex::scoped_lock lock(ConnectionManager::enet_mutex);
       enet_initialize();
       server = enet_host_create(&bindAddress, NETWORK_MAX_CONNECTIONS, 0, 0);
@@ -194,5 +194,5 @@
     while(!quit){
       { //mutex scope
-        boost::recursive_mutex::scoped_lock lock(enet_mutex);
+        boost::recursive_mutex::scoped_lock lock(ConnectionManager::enet_mutex);
         if(enet_host_service(server, event, NETWORK_WAIT_TIMEOUT)<0){
           // we should never reach this point
@@ -236,5 +236,5 @@
     // if we're finishied, destroy server
     {
-      boost::recursive_mutex::scoped_lock lock(enet_mutex);
+      boost::recursive_mutex::scoped_lock lock(ConnectionManager::enet_mutex);
       enet_host_destroy(server);
       lock.unlock();
@@ -250,5 +250,5 @@
     while(temp!=0){
       {
-        boost::recursive_mutex::scoped_lock lock(enet_mutex);
+        boost::recursive_mutex::scoped_lock lock(ConnectionManager::enet_mutex);
         enet_peer_disconnect(temp->getPeer(), 0);
         lock.unlock();
@@ -258,5 +258,5 @@
     //bugfix: might be the reason why server crashes when clients disconnects
     temp = ClientInformation::getBegin()->next();
-    boost::recursive_mutex::scoped_lock lock(enet_mutex);
+    boost::recursive_mutex::scoped_lock lock(ConnectionManager::enet_mutex);
     while( temp!=0 && enet_host_service(server, &event, NETWORK_WAIT_TIMEOUT) >= 0){
       switch (event.type)
@@ -306,7 +306,7 @@
     unsigned int network_id=0, failures=0;
     std::string classname;
-    orxonox::Identifier *id;
-    std::map<std::string, orxonox::Identifier*>::const_iterator it = orxonox::Factory::getFactoryMapBegin();
-    while(it != orxonox::Factory::getFactoryMapEnd()){
+    Identifier *id;
+    std::map<std::string, Identifier*>::const_iterator it = Factory::getFactoryMapBegin();
+    while(it != Factory::getFactoryMapEnd()){
       id = (*it).second;
       if(id == NULL)
@@ -332,5 +332,5 @@
   void ConnectionManager::disconnectClient(ClientInformation *client){
     {
-      boost::recursive_mutex::scoped_lock lock(enet_mutex);
+      boost::recursive_mutex::scoped_lock lock(ConnectionManager::enet_mutex);
       enet_peer_disconnect(client->getPeer(), 0);
       lock.unlock();
Index: code/trunk/src/network/ConnectionManager.h
===================================================================
--- code/trunk/src/network/ConnectionManager.h	(revision 2131)
+++ code/trunk/src/network/ConnectionManager.h	(revision 2171)
@@ -59,5 +59,5 @@
 }
 
-namespace network
+namespace orxonox
 {
     const int NETWORK_PORT = 55556;
Index: code/trunk/src/network/GamestateClient.cc
===================================================================
--- code/trunk/src/network/GamestateClient.cc	(revision 2131)
+++ code/trunk/src/network/GamestateClient.cc	(revision 2171)
@@ -39,5 +39,5 @@
 
 
-namespace network
+namespace orxonox
 {
   struct _NetworkExport GameStateItem{
@@ -94,6 +94,6 @@
   * @return iterator pointing to the next object in the list
   */
-  void GamestateClient::removeObject(orxonox::ObjectList<Synchronisable>::iterator &it) {
-    orxonox::ObjectList<Synchronisable>::iterator temp=it;
+  void GamestateClient::removeObject(ObjectList<Synchronisable>::iterator &it) {
+    ObjectList<Synchronisable>::iterator temp=it;
     ++it;
     delete  *temp;
Index: code/trunk/src/network/GamestateClient.h
===================================================================
--- code/trunk/src/network/GamestateClient.h	(revision 2131)
+++ code/trunk/src/network/GamestateClient.h	(revision 2171)
@@ -50,5 +50,5 @@
 const unsigned int GAMESTATEID_INITIAL = (unsigned int)-1;
 
-namespace network
+namespace orxonox
 {
   class _NetworkExport GamestateClient: public GamestateHandler
@@ -66,5 +66,5 @@
   private:
     packet::Gamestate *processGamestate(packet::Gamestate *gs);
-    void removeObject(orxonox::ObjectListIterator<Synchronisable> &it);
+    void removeObject(ObjectListIterator<Synchronisable> &it);
     void printGamestateMap();
     bool sendAck(unsigned int gamestateID);
Index: code/trunk/src/network/GamestateHandler.cc
===================================================================
--- code/trunk/src/network/GamestateHandler.cc	(revision 2131)
+++ code/trunk/src/network/GamestateHandler.cc	(revision 2171)
@@ -4,5 +4,5 @@
 #include "packet/Packet.h"
 
-namespace network {
+namespace orxonox {
 
 GamestateHandler *GamestateHandler::instance_=0;
@@ -22,3 +22,3 @@
 
 
-}//namespace network
+}//namespace orxonox
Index: code/trunk/src/network/GamestateHandler.h
===================================================================
--- code/trunk/src/network/GamestateHandler.h	(revision 2131)
+++ code/trunk/src/network/GamestateHandler.h	(revision 2171)
@@ -34,5 +34,5 @@
 #include "packet/Chat.h"
 
-namespace network {
+namespace orxonox {
 
 /**
Index: code/trunk/src/network/GamestateManager.cc
===================================================================
--- code/trunk/src/network/GamestateManager.cc	(revision 2131)
+++ code/trunk/src/network/GamestateManager.cc	(revision 2171)
@@ -51,5 +51,5 @@
 #include "Synchronisable.h"
 
-namespace network
+namespace orxonox
 {
   GamestateManager::GamestateManager() {
Index: code/trunk/src/network/GamestateManager.h
===================================================================
--- code/trunk/src/network/GamestateManager.h	(revision 2131)
+++ code/trunk/src/network/GamestateManager.h	(revision 2171)
@@ -47,5 +47,5 @@
 #include "packet/Gamestate.h"
 
-namespace network
+namespace orxonox
 {
 
Index: code/trunk/src/network/Host.cc
===================================================================
--- code/trunk/src/network/Host.cc	(revision 2131)
+++ code/trunk/src/network/Host.cc	(revision 2171)
@@ -34,5 +34,5 @@
 #include "ChatListener.h"
 
-namespace network {
+namespace orxonox {
 
 SetConsoleCommandShortcut(Host, Chat);
@@ -80,5 +80,5 @@
 // }
 
-// bool Host::receiveChat(network::packet::Chat *message, unsigned int clientID){
+// bool Host::receiveChat(packet::Chat *message, unsigned int clientID){
 //   if(instance_)
 //     return instance_->processChat(message, clientID);
@@ -110,5 +110,5 @@
 
 bool Host::incomingChat(const std::string& message, unsigned int playerID){
-  for (orxonox::ObjectList<ChatListener>::iterator it = orxonox::ObjectList<ChatListener>::begin(); it != orxonox::ObjectList<ChatListener>::end(); ++it)
+  for (ObjectList<ChatListener>::iterator it = ObjectList<ChatListener>::begin(); it != ObjectList<ChatListener>::end(); ++it)
     it->incomingChat(message, playerID);
 
@@ -116,3 +116,3 @@
 }
 
-}//namespace network
+}//namespace orxonox
Index: code/trunk/src/network/Host.h
===================================================================
--- code/trunk/src/network/Host.h	(revision 2131)
+++ code/trunk/src/network/Host.h	(revision 2171)
@@ -34,5 +34,5 @@
 #include "packet/Chat.h"
 
-namespace network {
+namespace orxonox {
 
 /**
Index: code/trunk/src/network/NetworkCallback.h
===================================================================
--- code/trunk/src/network/NetworkCallback.h	(revision 2131)
+++ code/trunk/src/network/NetworkCallback.h	(revision 2171)
@@ -4,5 +4,5 @@
 #include "NetworkPrereqs.h"
 
-namespace network{
+namespace orxonox{
   class _NetworkExport NetworkCallbackBase
   {
Index: code/trunk/src/network/NetworkPrereqs.h
===================================================================
--- code/trunk/src/network/NetworkPrereqs.h	(revision 2131)
+++ code/trunk/src/network/NetworkPrereqs.h	(revision 2171)
@@ -59,5 +59,5 @@
 // Forward declarations
 //-----------------------------------------------------------------------
-namespace network
+namespace orxonox
 {
   class Client;
Index: code/trunk/src/network/PacketBuffer.cc
===================================================================
--- code/trunk/src/network/PacketBuffer.cc	(revision 2131)
+++ code/trunk/src/network/PacketBuffer.cc	(revision 2171)
@@ -39,5 +39,5 @@
 #include <boost/thread/mutex.hpp>
 
-namespace network
+namespace orxonox
 {
    boost::recursive_mutex PacketBuffer::mutex_;
@@ -147,3 +147,3 @@
   }
 
-} // namespace network
+} // namespace orxonox
Index: code/trunk/src/network/PacketBuffer.h
===================================================================
--- code/trunk/src/network/PacketBuffer.h	(revision 2131)
+++ code/trunk/src/network/PacketBuffer.h	(revision 2171)
@@ -47,5 +47,5 @@
 #include <boost/thread/recursive_mutex.hpp>
 
-namespace network
+namespace orxonox
 {
   struct _NetworkExport PacketEnvelope{
Index: code/trunk/src/network/Server.cc
===================================================================
--- code/trunk/src/network/Server.cc	(revision 2131)
+++ code/trunk/src/network/Server.cc	(revision 2171)
@@ -60,5 +60,5 @@
 #include "ChatListener.h"
 
-namespace network
+namespace orxonox
 {
   const unsigned int MAX_FAILURES = 20;
@@ -317,5 +317,5 @@
 
     // inform all the listeners
-    orxonox::ObjectList<ClientConnectionListener>::iterator listener = orxonox::ObjectList<ClientConnectionListener>::begin();
+    ObjectList<ClientConnectionListener>::iterator listener = ObjectList<ClientConnectionListener>::begin();
     while(listener){
       listener->clientConnected(newid);
@@ -366,5 +366,5 @@
 
 // inform all the listeners
-    orxonox::ObjectList<ClientConnectionListener>::iterator listener = orxonox::ObjectList<ClientConnectionListener>::begin();
+    ObjectList<ClientConnectionListener>::iterator listener = ObjectList<ClientConnectionListener>::begin();
     while(listener){
       listener->clientDisconnected(client->getID());
@@ -404,5 +404,5 @@
     }
 //    COUT(1) << "Player " << Host::getPlayerID() << ": " << message << std::endl;
-    for (orxonox::ObjectList<ChatListener>::iterator it = orxonox::ObjectList<ChatListener>::begin(); it != orxonox::ObjectList<ChatListener>::end(); ++it)
+    for (ObjectList<ChatListener>::iterator it = ObjectList<ChatListener>::begin(); it != ObjectList<ChatListener>::end(); ++it)
       it->incomingChat(message, clientID);
 
Index: code/trunk/src/network/Server.h
===================================================================
--- code/trunk/src/network/Server.h	(revision 2131)
+++ code/trunk/src/network/Server.h	(revision 2171)
@@ -49,5 +49,5 @@
 #include "GamestateManager.h"
 
-namespace network
+namespace orxonox
 {
   const int CLIENTID_SERVER = 0;
Index: code/trunk/src/network/Synchronisable.cc
===================================================================
--- code/trunk/src/network/Synchronisable.cc	(revision 2131)
+++ code/trunk/src/network/Synchronisable.cc	(revision 2171)
@@ -50,5 +50,6 @@
 // #include "core/Identifier.h"
 
-namespace network
+#include "Host.h"
+namespace orxonox
 {
 
@@ -57,5 +58,5 @@
   std::queue<unsigned int> Synchronisable::deletedObjects_;
 
-  int Synchronisable::state_=0x1; // detemines wheter we are server (default) or client
+  uint8_t Synchronisable::state_=0x1; // detemines wheter we are server (default) or client
 
   /**
@@ -63,12 +64,28 @@
   * Initializes all Variables and sets the right objectID
   */
-  Synchronisable::Synchronisable(orxonox::BaseObject* creator){
+  Synchronisable::Synchronisable(BaseObject* creator){
     RegisterRootObject(Synchronisable);
     static uint32_t idCounter=0;
     objectFrequency_=1;
     objectMode_=0x1; // by default do not send data to server
-    objectID=idCounter++;
+    if ( !Host::running() || ( Host::running() && Host::isServer() ) )
+    {
+      this->objectID = idCounter++; //this is only needed when running a server
+    //add synchronisable to the objectMap
+      objectMap_[this->objectID] = this;
+    }
+    else
+      objectID=OBJECTID_UNKNOWN;
     classID = (unsigned int)-1;
     syncList = new std::list<synchronisableVariable *>;
+
+
+#ifndef NDEBUG
+    ObjectList<Synchronisable>::iterator it;
+    for(it = ObjectList<Synchronisable>::begin(); it!=ObjectList<Synchronisable>::end(); ++it){
+      if( it->getObjectID()==this->objectID )
+        assert(*it==this || (it->objectID==OBJECTID_UNKNOWN && it->objectMode_==0x0));
+    }
+#endif
 
     this->creatorID = OBJECTID_UNKNOWN;
@@ -96,8 +113,8 @@
   Synchronisable::~Synchronisable(){
     // delete callback function objects
-    if(!orxonox::Identifier::isCreatingHierarchy()){
+    if(!Identifier::isCreatingHierarchy()){
       for(std::list<synchronisableVariable *>::iterator it = syncList->begin(); it!=syncList->end(); it++)
         delete (*it)->callback;
-      if (this->objectMode_ != 0x0)
+      if (this->objectMode_ != 0x0 && (Host::running() && Host::isServer()))
         deletedObjects_.push(objectID);
 //       COUT(3) << "destruct synchronisable +++" << objectID << " | " << classID << std::endl;
@@ -106,4 +123,8 @@
 //       objectMap_.erase(objectID);
     }
+    std::map<unsigned int, Synchronisable*>::iterator it;
+    it = objectMap_.find(objectID);
+    if (it != objectMap_.end())
+      objectMap_.erase(it);
   }
 
@@ -143,5 +164,5 @@
    * @return pointer to the newly created synchronisable
    */
-  Synchronisable *Synchronisable::fabricate(uint8_t*& mem, int mode)
+  Synchronisable *Synchronisable::fabricate(uint8_t*& mem, uint8_t mode)
   {
     synchronisableHeader *header = (synchronisableHeader *)mem;
@@ -152,10 +173,10 @@
       return 0;
     }
-    
+
     COUT(4) << "fabricating object with id: " << header->objectID << std::endl;
 
-    orxonox::Identifier* id = ClassByID(header->classID);
+    Identifier* id = ClassByID(header->classID);
     assert(id);
-    orxonox::BaseObject* creator = 0;
+    BaseObject* creator = 0;
     if (header->creatorID != OBJECTID_UNKNOWN)
     {
@@ -167,7 +188,8 @@
       }
       else
-        creator = dynamic_cast<orxonox::BaseObject*>(synchronisable_creator);
-    }
-    orxonox::BaseObject *bo = id->fabricate(creator);
+        creator = dynamic_cast<BaseObject*>(synchronisable_creator);
+    }
+    assert(getSynchronisable(header->objectID)==0);   //make sure no object with this id exists
+    BaseObject *bo = id->fabricate(creator);
     assert(bo);
     Synchronisable *no = dynamic_cast<Synchronisable *>(bo);
@@ -214,16 +236,17 @@
    */
   Synchronisable* Synchronisable::getSynchronisable(unsigned int objectID){
-    orxonox::ObjectList<Synchronisable>::iterator it;
-    for(it = orxonox::ObjectList<Synchronisable>::begin(); it; ++it){
-      if( it->getObjectID()==objectID )
-           return *it;
+    std::map<unsigned int, Synchronisable*>::iterator it1;
+    it1 = objectMap_.find(objectID);
+    if (it1 != objectMap_.end())
+      return it1->second;
+
+    ObjectList<Synchronisable>::iterator it;
+    for(it = ObjectList<Synchronisable>::begin(); it; ++it){
+      if( it->getObjectID()==objectID ){
+        objectMap_[objectID] = *it;
+        return *it;
+      }
     }
     return NULL;
-
-//     std::map<unsigned int, Synchronisable *>::iterator i = objectMap_.find(objectID);
-//     if(i==objectMap_.end())
-//       return NULL;
-//     assert(i->second->objectID==objectID);
-//     return (*i).second;
   }
 
@@ -234,9 +257,9 @@
   * @param var pointer to the variable
   * @param size size of the datatype the variable consists of
-  * @param t the type of the variable (network::DATA or network::STRING
+  * @param t the type of the variable (DATA or STRING
   * @param mode same as in getData
   * @param cb callback object that should get called, if the value of the variable changes
   */
-  void Synchronisable::registerVar(void *var, int size, variableType t, int mode, NetworkCallbackBase *cb){
+  void Synchronisable::registerVariable(void *var, int size, variableType t, uint8_t mode, NetworkCallbackBase *cb){
     assert( mode==direction::toclient || mode==direction::toserver || mode==direction::serverMaster || mode==direction::clientMaster);
     // create temporary synch.Var struct
@@ -249,6 +272,13 @@
     if( ( mode & direction::bidirectional ) )
     {
-      temp->varBuffer = new uint8_t[size];
-      memcpy(temp->varBuffer, temp->var, size); //now fill the buffer for the first time
+      if(t!=STRING)
+      {
+        temp->varBuffer = new uint8_t[size];
+        memcpy(temp->varBuffer, temp->var, size); //now fill the buffer for the first time
+      }
+      else
+      {
+        temp->varBuffer=new std::string( *static_cast<std::string*>(var) );
+      }
       temp->varReference = 0;
     }
@@ -265,4 +295,21 @@
 #endif
   }
+
+  void Synchronisable::unregisterVariable(void *var){
+    std::list<synchronisableVariable *>::iterator it = syncList->begin();
+    while(it!=syncList->end()){
+      if( (*it)->var == var ){
+        delete *it;
+        syncList->erase(it);
+        return;
+      }
+      else
+        it++;
+    }
+    bool unregistered_nonexistent_variable = false;
+    assert(unregistered_nonexistent_variable); //if we reach this point something went wrong:
+    // the variable has not been registered before
+  }
+
 
   /**
@@ -280,12 +327,12 @@
    * @return true: if !doSync or if everything was successfully saved
    */
-  bool Synchronisable::getData(uint8_t*& mem, unsigned int id, int mode){
+  bool Synchronisable::getData(uint8_t*& mem, unsigned int id, uint8_t mode){
+    if(mode==0x0)
+      mode=state_;
     //if this tick is we dont synchronise, then abort now
-    if(!doSync(id))
+    if(!doSync(id, mode))
       return true;
     //std::cout << "inside getData" << std::endl;
     unsigned int tempsize = 0;
-    if(mode==0x0)
-      mode=state_;
     if(classID==0)
       COUT(3) << "classid 0 " << this->getIdentifier()->getName() << std::endl;
@@ -307,6 +354,6 @@
     header->classID = this->classID;
     header->dataAvailable = true;
-    tempsize+=sizeof(synchronisableHeader);
-    mem+=sizeof(synchronisableHeader);
+    tempsize += sizeof(synchronisableHeader);
+    mem += sizeof(synchronisableHeader);
     // end copy header
 
@@ -319,25 +366,50 @@
         continue;  // this variable should only be received
       }
+
+      // =========== start bidirectional stuff =============
       // if the variable gets synchronised bidirectional, then add the reference to the bytestream
       if( ( (*i)->mode & direction::bidirectional ) == direction::bidirectional )
       {
+        if( ( ((*i)->mode == direction::serverMaster) && (mode == 0x1) ) || \
+            ( ((*i)->mode == direction::clientMaster) && (mode == 0x2) ) )
+        {
+          // MASTER
+          if((*i)->type==DATA){
+            if( memcmp((*i)->var,(*i)->varBuffer,(*i)->size) != 0 ) //check whether the variable changed during the last tick
+            {
+              ((*i)->varReference)++;   //the variable changed so increase the refnr
+              memcpy((*i)->varBuffer, (*i)->var, (*i)->size); //set the buffer to the new value
+            }
+          }
+          else //STRING
+          {
+            if( *static_cast<std::string*>((*i)->var) != *static_cast<std::string*>((*i)->varBuffer) ) //the string changed
+            {
+              ((*i)->varReference)++;   //the variable changed
+              *static_cast<std::string*>((*i)->varBuffer) = *static_cast<std::string*>((*i)->var);  //now set the buffer to the new value
+            }
+          }
+        }
+        // copy the reference number to the stream
         *(uint8_t*)mem = (*i)->varReference;
         mem += sizeof( (*i)->varReference );
         tempsize += sizeof( (*i)->varReference );
       }
+      // ================== end bidirectional stuff
+
       switch((*i)->type){
         case DATA:
           memcpy( (void *)(mem), (void*)((*i)->var), (*i)->size);
-          mem+=(*i)->size;
-          tempsize+=(*i)->size;
+          mem += (*i)->size;
+          tempsize += (*i)->size;
           break;
         case STRING:
           memcpy( (void *)(mem), (void *)&((*i)->size), sizeof(size_t) );
-          mem+=sizeof(size_t);
+          mem += sizeof(size_t);
           const char *data = ( ( *(std::string *) (*i)->var).c_str());
           memcpy( mem, (void*)data, (*i)->size);
           COUT(5) << "synchronisable: char: " << (const char *)(mem) << " data: " << data << " string: " << *(std::string *)((*i)->var) << std::endl;
-          mem+=(*i)->size;
-          tempsize+=(*i)->size + sizeof(size_t);
+          mem += (*i)->size;
+          tempsize += (*i)->size + sizeof(size_t);
           break;
       }
@@ -354,8 +426,10 @@
    * @return true/false
    */
-  bool Synchronisable::updateData(uint8_t*& mem, int mode, bool forceCallback){
+  bool Synchronisable::updateData(uint8_t*& mem, uint8_t mode, bool forceCallback){
     if(mode==0x0)
       mode=state_;
     std::list<synchronisableVariable *>::iterator i;
+    //assert(objectMode_!=0x0);
+    //assert( (mode ^ objectMode_) != 0);
     if(syncList->empty()){
       COUT(4) << "Synchronisable::updateData syncList is empty" << std::endl;
@@ -367,14 +441,13 @@
     synchronisableHeader *syncHeader = (synchronisableHeader *)mem;
     assert(syncHeader->objectID==this->objectID);
-//    assert(syncHeader->creatorID==this->creatorID);
+    assert(syncHeader->creatorID==this->creatorID);
+    assert(this->classID==syncHeader->classID); //TODO: fix this!!! maybe a problem with the identifier ?
     if(syncHeader->dataAvailable==false){
-      mem+=syncHeader->size;
+      mem += syncHeader->size;
       return true;
     }
 
-    mem+=sizeof(synchronisableHeader);
+    mem += sizeof(synchronisableHeader);
     // stop extract header
-    assert(this->objectID==syncHeader->objectID);
-//    assert(this->classID==syncHeader->classID); //TODO: fix this!!! maybe a problem with the identifier ?
 
     COUT(5) << "Synchronisable: objectID " << syncHeader->objectID << ", classID " << syncHeader->classID << " size: " << syncHeader->size << " synchronising data" << std::endl;
@@ -382,59 +455,85 @@
       if( ((*i)->mode ^ mode) == 0 ){
         COUT(5) << "synchronisable: not updating variable " << std::endl;
+        // if we have a forcecallback then do the callback
         continue;  // this variable should only be set
       }
       COUT(5) << "Synchronisable: element size: " << (*i)->size << " type: " << (*i)->type << std::endl;
       bool callback=false;
+      bool master=false;
+
+      if( ( (*i)->mode & direction::bidirectional ) == direction::bidirectional )
+      {
+        uint8_t refNr = *(uint8_t *)mem;
+        if( ( ((*i)->mode == direction::serverMaster) && (mode == 0x1) ) || \
+            ( ((*i)->mode == direction::clientMaster) && (mode == 0x2) ) )
+        { // MASTER
+          master=true;
+          if( refNr != (*i)->varReference || ( memcmp((*i)->var, (*i)->varBuffer, (*i)->size) != 0 ) )
+          { // DISCARD data
+            if( (*i)->type == DATA )
+            {
+              mem += sizeof((*i)->varReference) + (*i)->size;
+            }
+            else //STRING
+            {
+              mem += sizeof(size_t) + *(size_t *)mem;
+            }
+            if( forceCallback && (*i)->callback)
+              (*i)->callback->call();
+            continue;
+          }//otherwise everything is ok and we update the value
+        }
+        else // SLAVE
+        {
+          if( (*i)->varReference == refNr ){
+            //discard data because it's outdated or not different to what we've got
+            if( (*i)->type == DATA )
+            {
+              mem += sizeof((*i)->varReference) + (*i)->size;
+            }
+            else //STRING
+            {
+              mem += sizeof(size_t) + *(size_t *)mem;
+            }
+            if( forceCallback && (*i)->callback)
+              (*i)->callback->call();
+            continue;
+          }
+          else
+            (*i)->varReference = refNr; //copy the reference value for this variable
+        }
+        mem += sizeof((*i)->varReference);
+      }
+
       switch((*i)->type){
         case DATA:
-          if( ( (*i)->mode & direction::bidirectional ) == direction::bidirectional )
+          if((*i)->callback) // check whether this variable changed (but only if callback was set)
           {
-            if( ( mode == 0x1 && (*i)->mode == direction::serverMaster ) || \
-                  ( mode == 0x2 && (*i)->mode == direction::clientMaster ) )    // if true we are master on this variable
-            {
-              uint8_t refNr = *(uint8_t *)mem;
-              if( refNr != (*i)->varReference )
-              {
-                mem += sizeof((*i)->varReference) + (*i)->size; // the reference for this variable is not recent, discard data
-                break;
-              }
-            }
-            else //we are slave for this variable
-            {
-              (*i)->varReference = *(uint8_t *)mem; //copy the reference value for this variable
-            }
-            mem += sizeof((*i)->varReference);
+            if(memcmp((*i)->var, mem, (*i)->size) != 0)
+              callback=true;
           }
-          if((*i)->callback) // check whether this variable changed (but only if callback was set)
-            if(strncmp((char *)(*i)->var, (char *)mem, (*i)->size)!=0)
-              callback=true;
-          memcpy((void*)(*i)->var, mem, (*i)->size);
-          mem+=(*i)->size;
+          if( master )
+          {
+            if( callback || memcmp((*i)->var, mem, (*i)->size) != 0 )
+              //value changed, so set the buffer to the new value
+              memcpy((*i)->varBuffer, mem, (*i)->size);
+          }
+          memcpy((*i)->var, mem, (*i)->size);
+          mem += (*i)->size;
           break;
         case STRING:
-          if( ( (*i)->mode & direction::bidirectional ) == direction::bidirectional )
+          (*i)->size = *(size_t *)mem;
+          mem += sizeof(size_t);
+
+          if( (*i)->callback) // check whether this string changed
+            if( *static_cast<std::string*>((*i)->var) != std::string((char *)mem) )
+              callback=true;
+          if( master )
           {
-            if( ( mode == 0x1 && (*i)->mode == direction::serverMaster ) || \
-                  ( mode == 0x2 && (*i)->mode == direction::clientMaster ) )    // if true we are master for this variable
-            {
-              uint8_t refNr = *(uint8_t *)mem;
-              mem += sizeof( (*i)->varReference );
-              if( refNr != (*i)->varReference ){
-                mem += sizeof(size_t) + *(size_t *)mem; // the reference for this variable is not recent, discard data
-                break;
-              }
-            }
-            else //we are slave for this variable
-            {
-              (*i)->varReference = *(uint8_t *)mem; //copy the reference value for this variable
-            }
-            mem += sizeof( (*i)->varReference );
+            if( callback || *static_cast<std::string*>((*i)->var) != std::string((char *)mem) )
+              //string changed. set the buffer to the new one
+              *static_cast<std::string*>((*i)->varBuffer)=*static_cast<std::string*>( (void*)(mem+sizeof(size_t)) );
           }
-          (*i)->size = *(size_t *)mem;
-          COUT(5) << "string size: " << (*i)->size << std::endl;
-          mem += sizeof(size_t);
-          if((*i)->callback) // check whether this string changed
-            if( *(std::string *)((*i)->var) != std::string((char *)mem) )
-              callback=true;
+
           *((std::string *)((*i)->var)) = std::string((const char*)mem);
           COUT(5) << "synchronisable: char: " << (const char*)mem << " string: " << std::string((const char*)mem) << std::endl;
@@ -446,4 +545,5 @@
         (*i)->callback->call();
     }
+    assert(mem == data+syncHeader->size);
     return true;
   }
@@ -455,10 +555,10 @@
   * @return amount of bytes
   */
-  uint32_t Synchronisable::getSize(unsigned int id, int mode){
-    if(!doSync(id))
-      return 0;
+  uint32_t Synchronisable::getSize(unsigned int id, uint8_t mode){
     int tsize=sizeof(synchronisableHeader);
     if(mode==0x0)
       mode=state_;
+    if(!doSync(id, mode))
+      return 0;
     std::list<synchronisableVariable *>::iterator i;
     for(i=syncList->begin(); i!=syncList->end(); i++){
@@ -489,10 +589,13 @@
    * @return true/false
    */
-  bool Synchronisable::doSync(unsigned int id){
-    return ( (objectMode_&state_)!=0 && (!syncList->empty() ) );
+  bool Synchronisable::doSync(unsigned int id, uint8_t mode){
+    if(mode==0x0)
+      mode=state_;
+    return ( (objectMode_&mode)!=0 && (!syncList->empty() ) );
   }
 
   bool Synchronisable::doSelection(unsigned int id){
-    return ( id==0 || id%objectFrequency_==objectID%objectFrequency_ ) && ((objectMode_&state_)!=0);
+    return true; //TODO: change this
+    //return ( id==0 || id%objectFrequency_==objectID%objectFrequency_ ) && ((objectMode_&state_)!=0);
   }
 
@@ -510,4 +613,5 @@
   /**
    * This function sets the synchronisation mode of the object
+   * If set to 0x0 variables will not be synchronised at all
    * If set to 0x1 variables will only be synchronised to the client
    * If set to 0x2 variables will only be synchronised to the server
@@ -515,5 +619,5 @@
    * @param mode same as in registerVar
    */
-  void Synchronisable::setObjectMode(int mode){
+  void Synchronisable::setObjectMode(uint8_t mode){
     assert(mode==0x0 || mode==0x1 || mode==0x2 || mode==0x3);
     objectMode_=mode;
Index: code/trunk/src/network/Synchronisable.h
===================================================================
--- code/trunk/src/network/Synchronisable.h	(revision 2131)
+++ code/trunk/src/network/Synchronisable.h	(revision 2171)
@@ -42,9 +42,9 @@
 
 #define REGISTERDATA(varname, ...) \
-    registerVar((void*)&varname, sizeof(varname), network::DATA, __VA_ARGS__)
+    registerVariable((void*)&varname, sizeof(varname), DATA, __VA_ARGS__)
 #define REGISTERSTRING(stringname, ...) \
-    registerVar(&stringname, stringname.length()+1, network::STRING, __VA_ARGS__)
+    registerVariable(&stringname, stringname.length()+1, STRING, __VA_ARGS__)
 
-namespace network
+namespace orxonox
 {
   static const unsigned int OBJECTID_UNKNOWN = (unsigned int)-1;
@@ -62,5 +62,5 @@
   namespace syncmode{
     enum mode{
-      one=0,
+      once=0,
       always=1
     };
@@ -81,6 +81,6 @@
 
   struct _NetworkExport synchronisableVariable{
-    unsigned int size;
-    int mode; // this determines in which direction the variable gets synchronised
+    size_t size;
+    uint8_t mode; // this determines in which direction the variable gets synchronised
     void *var;
     variableType type;
@@ -95,9 +95,8 @@
   * @author Oliver Scheuss
   */
-  class _NetworkExport Synchronisable : virtual public orxonox::OrxonoxClass{
+  class _NetworkExport Synchronisable : virtual public OrxonoxClass{
   public:
     friend class packet::Gamestate;
-    friend class GamestateClient;
-    friend class Server;
+//     friend class Server;
     virtual ~Synchronisable();
 
@@ -106,5 +105,5 @@
     static void setClient(bool b);
 
-    static Synchronisable *fabricate(uint8_t*& mem, int mode=0x0);
+    static Synchronisable *fabricate(uint8_t*& mem, uint8_t mode=0x0);
     static bool deleteObject(unsigned int objectID);
     static Synchronisable *getSynchronisable(unsigned int objectID);
@@ -115,17 +114,18 @@
     inline unsigned int getClassID(){return classID;}
   protected:
-    Synchronisable(orxonox::BaseObject* creator);
-    void registerVar(void *var, int size, variableType t, int mode=1, NetworkCallbackBase *cb=0);
-    void setObjectMode(int mode);
+    Synchronisable(BaseObject* creator);
+    void registerVariable(void *var, int size, variableType t, uint8_t mode=0x1, NetworkCallbackBase *cb=0);
+    void unregisterVariable(void *var);
+    void setObjectMode(uint8_t mode);
     void setObjectFrequency(unsigned int freq){ objectFrequency_ = freq; }
 
 
   private:
-    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 forceCallback=false);
+    bool getData(uint8_t*& men, unsigned int id, uint8_t mode=0x0);
+    uint32_t getSize(unsigned int id, uint8_t mode=0x0);
+    bool updateData(uint8_t*& mem, uint8_t mode=0x0, bool forceCallback=false);
     bool isMyData(uint8_t* mem);
     bool doSelection(unsigned int id);
-    bool doSync(unsigned int id);
+    bool doSync(unsigned int id, uint8_t mode=0x0);
 
     unsigned int objectID;
@@ -134,5 +134,5 @@
 
     std::list<synchronisableVariable *> *syncList;
-    static int state_; // detemines wheter we are server (default) or client
+    static uint8_t state_; // detemines wheter we are server (default) or client
     bool backsync_; // if true the variables with mode > 1 will be synchronised to server (client -> server)
     unsigned int objectFrequency_;
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
