Index: trunk/src/lib/network/Makefile.am
===================================================================
--- trunk/src/lib/network/Makefile.am	(revision 6634)
+++ trunk/src/lib/network/Makefile.am	(revision 6695)
@@ -6,4 +6,5 @@
 libORXnet_a_SOURCES = synchronizeable.cc \
 		      network_manager.cc \
+		      shared_network_data.cc \
 		      network_socket.cc \
 		      connection_monitor.cc \
@@ -21,4 +22,5 @@
 noinst_HEADERS = synchronizeable.h \
                  network_manager.h \
+                 shared_network_data.h \
                  network_socket.h \
                  connection_monitor.h \
Index: trunk/src/lib/network/handshake.cc
===================================================================
--- trunk/src/lib/network/handshake.cc	(revision 6634)
+++ trunk/src/lib/network/handshake.cc	(revision 6695)
@@ -23,4 +23,5 @@
 
 Handshake::Handshake( bool server, int clientId, int networkGameManagerId )
+  : Synchronizeable()
 {
   /* set the class id for the base object */
@@ -34,4 +35,5 @@
   this->setOwner(0);
 
+  this->setSynchronized(true);
   PRINTF(5)("Handshake created clientId = %d\n", clientId);
 }
Index: trunk/src/lib/network/netdefs.h
===================================================================
--- trunk/src/lib/network/netdefs.h	(revision 6634)
+++ trunk/src/lib/network/netdefs.h	(revision 6695)
@@ -17,4 +17,7 @@
 
 
+#define MAX_CONNECTIONS 1000
+
+
 typedef unsigned char byte;
 
@@ -25,3 +28,10 @@
 } NodeType;
 
+
+typedef enum {
+  NET_UID_UNASSIGNED = -1,
+
+  NET_UID_NUMBER
+} UidType;
+
 #endif /* _NETWORK_MANAGER */
Index: trunk/src/lib/network/network_game_manager.cc
===================================================================
--- trunk/src/lib/network/network_game_manager.cc	(revision 6634)
+++ trunk/src/lib/network/network_game_manager.cc	(revision 6695)
@@ -46,4 +46,5 @@
  */
 NetworkGameManager::NetworkGameManager()
+  : Synchronizeable()
 {
   PRINTF(0)("START\n");
@@ -52,7 +53,6 @@
   this->setClassID(CL_NETWORK_GAME_MANAGER, "NetworkGameManager");
 
-  newUniqueID = MAX_CONNECTIONS + 2;
-
   hasRequestedWorld = false;
+  this->setSynchronized(true);
 }
 
@@ -80,7 +80,8 @@
     b = data[i++];
 
+    /**************** Commands only processed by servers ****************/
     if ( isServer() )
     {
-      if ( b == REQUEST_CREATE )
+      if ( b == NET_REQUEST_CREATE )
       {
         if ( !handleRequestCreate( i, data, length, sender ) )
@@ -88,5 +89,5 @@
         continue;
       }
-      if ( b == REQUEST_REMOVE )
+      else if ( b == NET_REQUEST_REMOVE )
       {
         if ( !handleRequestRemove( i, data, length, sender ) )
@@ -94,8 +95,15 @@
         continue;
       }
+      else if ( b == NET_REQUEST_PNODE_PATH )
+      {
+        if ( !handleRequestPNodePath( i, data, length, sender ) )
+          return i;
+        continue;
+      }
     }
     else
     {
-      if ( b == CREATE_ENTITY )
+      /**************** Commands only processed by clients ****************/
+      if ( b == NET_CREATE_ENTITY )
       {
         PRINTF(0)("CREATE_ENTITY\n");
@@ -104,5 +112,5 @@
         continue;
       }
-      if ( b == REMOVE_ENTITY )
+      else if ( b == NET_REMOVE_ENTITY )
       {
         if ( !handleRemoveEntity( i, data, length, sender ) )
@@ -110,5 +118,5 @@
         continue;
       }
-      if ( b == CREATE_ENTITY_LIST )
+      else if ( b == NET_CREATE_ENTITY_LIST )
       {
         if ( !handleCreateEntityList( i, data, length, sender ) )
@@ -116,5 +124,5 @@
         continue;
       }
-      if ( b == REMOVE_ENTITY_LIST )
+      else if ( b == NET_REMOVE_ENTITY_LIST )
       {
         if ( !handleRemoveEntityList( i, data, length, sender ) )
@@ -122,5 +130,5 @@
         continue;
       }
-      if ( b == YOU_ARE_ENTITY )
+      else if ( b == NET_YOU_ARE_ENTITY )
       {
         if ( !handleYouAreEntity( i, data, length, sender ) )
@@ -130,11 +138,11 @@
     }
 
-    if ( b == REQUEST_ENTITY_LIST )
+    /**************** Commands processed by servers and clients ****************/
+    if ( b == NET_REQUEST_ENTITY_LIST )
     {
       sendEntityList( sender );
       continue;
     }
-
-    if ( b == REQUEST_SYNC )
+    else if ( b == NET_REQUEST_SYNC )
     {
       if ( !handleRequestSync( i, data, length, sender ) )
@@ -143,5 +151,8 @@
     }
 
-    //if we get her something with data is wrong
+
+    PRINTF(1)("Network is asynchronous: couldn't decode the command sent by %i\n", sender);
+    PRINTF(1)("Probably this is because the network protocol has different \n");
+    PRINTF(1)("versions or there occured an error in the sending algorithm\n");
     PRINTF(1)("Data is not in the right format! i=%d\n", i);
     return i;
@@ -156,5 +167,5 @@
   {
     SYNCHELP_WRITE_BEGIN();
-    byte b = REQUEST_ENTITY_LIST;
+    byte b = NET_REQUEST_ENTITY_LIST;
     SYNCHELP_WRITE_BYTE( b );
     hasRequestedWorld = true;
@@ -200,13 +211,12 @@
 int NetworkGameManager::createEntity( ClassID classID, int owner )
 {
-  if ( this->isServer() )
-  {
-    if ( newUniqueID < 0 )
+  if ( this->isServer())
+  {
+    if ( SharedNetworkData::getInstance()->getNewUniqueID() < 0 )
     {
       PRINTF(1)("Cannot create entity! There are no more uniqueIDs left!\n");
       return -1;
     }
-
-    return this->executeCreateEntity( classID, newUniqueID++, owner );
+    return this->executeCreateEntity( classID, SharedNetworkData::getInstance()->getNewUniqueID(), owner );
   }
   else
@@ -227,5 +237,5 @@
   if ( this->isServer() )
   {
-    if ( newUniqueID < 0 )
+    if ( SharedNetworkData::getInstance()->getNewUniqueID() < 0 )
     {
       PRINTF(1)("Cannot create entity! There are no more uniqueIDs left!\n");
@@ -245,7 +255,8 @@
     {
       Synchronizeable * s = dynamic_cast<Synchronizeable*>(b);
-      s->setUniqueID( newUniqueID++ );
+      s->setUniqueID( SharedNetworkData::getInstance()->getNewUniqueID() );
       s->setOwner( 0 );
-      this->networkStream->connectSynchronizeable( *s );
+      // all entities created via this function are added automaticaly to the synchronizeable list
+      s->setSynchronized(true);
       return b;
     }
@@ -258,4 +269,5 @@
   }
   else
+
   {
     PRINTF(1)("This node is not a server and cannot create id %x\n", element->Value());
@@ -295,5 +307,5 @@
       continue;
 
-    if ( !writeToClientBuffer( outBuffer[i], (byte)REQUEST_CREATE ) )
+    if ( !writeToClientBuffer( outBuffer[i], (byte)NET_REQUEST_CREATE ) )
       return;
     if ( !writeToClientBuffer( outBuffer[i], (int)classID ) )
@@ -313,5 +325,5 @@
       continue;
 
-    if ( !writeToClientBuffer( outBuffer[i], (byte)REQUEST_REMOVE ) )
+    if ( !writeToClientBuffer( outBuffer[i], (byte)NET_REQUEST_REMOVE ) )
       return;
     if ( !writeToClientBuffer( outBuffer[i], uniqueID ) )
@@ -332,5 +344,5 @@
       continue;
 
-    if ( !writeToClientBuffer( outBuffer[i], (byte)CREATE_ENTITY ) )
+    if ( !writeToClientBuffer( outBuffer[i], (byte)NET_CREATE_ENTITY ) )
       return -1;
     if ( !writeToClientBuffer( outBuffer[i], (int)classID ) )
@@ -342,4 +354,5 @@
   }
 
+  PRINTF(0)("ExecuteCreateEntity: server side: classID: %x, uniqueID: %i, owner: %i\n", classID, uniqueID, owner);
   doCreateEntity( classID, uniqueID, owner );
 
@@ -359,5 +372,5 @@
       continue;
 
-    if ( !writeToClientBuffer( outBuffer[i], (byte)REMOVE_ENTITY ) )
+    if ( !writeToClientBuffer( outBuffer[i], (byte)NET_REMOVE_ENTITY ) )
       return;
     if ( !writeToClientBuffer( outBuffer[i], uniqueID ) )
@@ -394,8 +407,9 @@
   e = this->networkStream->getSyncEnd();
 
-  if ( !writeToClientBuffer( outBuffer[userID], (byte)CREATE_ENTITY_LIST ) )
+  // send the packet header
+  if ( !writeToClientBuffer( outBuffer[userID], (byte)NET_CREATE_ENTITY_LIST ) )
     return;
 
-  // -2 because you must not send network_game_manager and handshake
+  // send the number of entities: -2 because you must not send network_game_manager and handshake
   if ( !writeToClientBuffer( outBuffer[userID], networkStream->getSyncCount() ) )
     return;
@@ -403,18 +417,27 @@
   //PRINTF(0)("SendEntityList: n = %d\n", networkStream->getSyncCount()-2 );
 
-  int n = 0;
-
+  // first send the NullParent
+  if ( !writeToClientBuffer( outBuffer[userID], (int)PNode::getNullParent()->getLeafClassID()) )
+    return;
+  if ( !writeToClientBuffer( outBuffer[userID], (int)PNode::getNullParent()->getUniqueID()) )
+    return;
+  if ( !writeToClientBuffer( outBuffer[userID], (int)PNode::getNullParent()->getOwner()) )
+    return;
+
+  // now send the rest of the entities
   while ( it != e )
   {
-    PRINTF(5)("SENDING ENTITY %s id %d\n", (*it)->getClassName(), (*it)->getUniqueID() );
-    if ( !writeToClientBuffer( outBuffer[userID], (int)((*it)->getLeafClassID()) ) )
-      return;
-
-    if ( !writeToClientBuffer( outBuffer[userID], (int)((*it)->getUniqueID()) ) )
-      return;
-
-    if ( !writeToClientBuffer( outBuffer[userID], (int)((*it)->getOwner()) ) )
-      return;
-
+    if( (*it)->beSynchronized() && (*it) != PNode::getNullParent())
+    {
+      PRINTF(0)("SENDING ENTITY %s classid: %x, uniqueid %d\n", (*it)->getClassName(), (*it)->getLeafClassID(), (*it)->getUniqueID() );
+      if ( !writeToClientBuffer( outBuffer[userID], (int)((*it)->getLeafClassID()) ) )
+        return;
+
+      if ( !writeToClientBuffer( outBuffer[userID], (int)((*it)->getUniqueID()) ) )
+        return;
+
+      if ( !writeToClientBuffer( outBuffer[userID], (int)((*it)->getOwner()) ) )
+        return;
+    }
     it++;
   }
@@ -467,5 +490,15 @@
 BaseObject* NetworkGameManager::doCreateEntity( ClassID classID, int uniqueID, int owner )
 {
-  BaseObject * b = Factory::fabricate( classID );
+  PRINTF(0)("Creating Entity via Factory: classid: %x, uniqueID: %i, owner: %i\n", classID, uniqueID, owner);
+
+  BaseObject * b;
+  /* These are some small exeptions in creation: Not all objects can/should be created via Factory */
+  /* Exception 1: NullParent */
+  if( classID == CL_NULL_PARENT)
+  {
+    b = (BaseObject*)PNode::getNullParent();
+  }
+  else
+    b = Factory::fabricate( classID );
 
   if ( !b )
@@ -480,5 +513,6 @@
     s->setUniqueID( uniqueID );
     s->setOwner( owner );
-    this->networkStream->connectSynchronizeable( *s );
+    s->setSynchronized(true);
+    //this->networkStream->connectSynchronizeable( *s );
     if ( !isServer() )
       s->setIsOutOfSync( true );
@@ -646,5 +680,5 @@
   if ( userID != 0 )
   {
-    if ( !writeToClientBuffer( outBuffer[userID], (byte)YOU_ARE_ENTITY ) )
+    if ( !writeToClientBuffer( outBuffer[userID], (byte)NET_YOU_ARE_ENTITY ) )
       return;
 
@@ -714,4 +748,5 @@
   i += Converter::byteArrayToInt( &data[i], &owner );
 
+  PRINTF(0)("handleCreateEntity: client side: classID: %x, uniqueID: %i, owner: %i\n", classID, uniqueID, owner);
   doCreateEntity( (ClassID)classID, uniqueID, owner );
 
@@ -779,14 +814,4 @@
     {
       BaseObject* b = doCreateEntity( (ClassID)classID, uniqueID, owner );
-
-      /*if ( b != NULL )
-      {
-        if ( b->isA(CL_WORLD_ENTITY) )
-        {
-          int n = dynamic_cast<WorldEntity*>(b)->writeState( data, length, sender );
-
-          i += n;
-        }
-    }*/
     }
 
@@ -854,4 +879,44 @@
   return true;
 }
+
+
+/**
+ *  handles the network signal NET_REQUEST_PNODE_PATH
+ * @param i byte offset in the buffer
+ * @param data data array
+ * @param length length of the data arary
+ * @param sender the sender id
+ * @return true if process terminated sucessfully
+ */
+bool NetworkGameManager::handleRequestPNodePath(int& i, const byte* data, int length, int sender)
+{
+  if( INTSIZE > length-i )
+  {
+    PRINTF(1)("Cannot read n from buffer! Not enough data left!\n");
+    return false;
+  }
+  PRINTF(0)("HandleRequestPNodePath:  data[i..i+3] = %d %d %d %d\n", data[i], data[i+1], data[i+2], data[i+3]);
+
+  int uniqueID1, uniqueID2;
+  if( INTSIZE > length-i )
+  {
+    PRINTF(1)("Cannot read uniqueID from buffer! Not enough data left!\n");
+    return false;
+  }
+  i += Converter::byteArrayToInt( &data[i], &uniqueID1 );
+
+  if( INTSIZE > length-i )
+  {
+    PRINTF(1)("Cannot read uniqueID from buffer! Not enough data left!\n");
+    return false;
+  }
+  i += Converter::byteArrayToInt( &data[i], &uniqueID2 );
+
+
+  PRINTF(0)("HandleRequestPNodePath: got a request for path from uid %i to uid %i\n", uniqueID1, uniqueID2);
+
+  return true;
+}
+
 
 bool NetworkGameManager::writeToClientBuffer( clientBuffer & cb, byte b )
@@ -898,5 +963,5 @@
     resizeBufferVector( user );
 
-  if ( !writeToClientBuffer( outBuffer[user], (byte)REQUEST_SYNC ) )
+  if ( !writeToClientBuffer( outBuffer[user], (byte)NET_REQUEST_SYNC ) )
     return;
   if ( !writeToClientBuffer( outBuffer[user], uniqueID ) )
Index: trunk/src/lib/network/network_game_manager.h
===================================================================
--- trunk/src/lib/network/network_game_manager.h	(revision 6634)
+++ trunk/src/lib/network/network_game_manager.h	(revision 6695)
@@ -15,16 +15,19 @@
 
 class TiXmlElement;
+class PNode;
 
 /**
  * protocol definition
  *
- *  CREATE_ENTITY:       CLASS_ID, UNIQUE_ID, OWNER
- *  REMOVE_ENTITY:       UNIQUE_ID
+ *  CREATE_ENTITY:       >> CLASS_ID, UNIQUE_ID, OWNER
+ *  REMOVE_ENTITY:       >> UNIQUE_ID
  *
- *  CREATE_ENTITY_LIST:  NUMBER, [CLASS_ID, UNIQUE_ID, OWNER][0..NUMBER]
- *  REMOVE_ENTITY_LIST:  NUMBER, [UNIQUE_ID][0..NUMBER]
+ *  CREATE_ENTITY_LIST:  >> NUMBER, [CLASS_ID, UNIQUE_ID, OWNER][0..NUMBER]
+ *  REMOVE_ENTITY_LIST:  >> NUMBER, [UNIQUE_ID][0..NUMBER]
  *
- *  REQUEST_CREATE:      CLASS_ID
- *  REQUEST_REMOVE:      UNIQUE_ID
+ *  REQUEST_CREATE:      >> CLASS_ID
+ *                       << [Sync Info]
+ *  REQUEST_REMOVE:      >> UNIQUE_ID
+ *                       << [Sync Info]
  *
  *  //REQUEST_CREATE_LIST: NUMBER, [CLASS_ID][0..NUMBER]
@@ -32,21 +35,30 @@
  *
  *  REQUEST_ENTITY_LIST: //request the whole world :D
- *  REQUEST_SYNC:        UNIQUE_ID
+ *  REQUEST_SYNC:        >> UNIQUE_ID
+ *                       << [Sync Info]
  *  //REQUEST_SYNC_LIST:   NUMBER, [UNIQUE_ID][0..NUMBER]
  *
- *  YOU_ARE_ENTITY:      UNIQUE_ID
+ *  YOU_ARE_ENTITY:      >> UNIQUE_ID
  *
+ *  REQUEST_PNODE_PATH   >> UNIQUE_ID_START   UNIQUE_ID_STOP
+ *                       << UNIQUE_ID_1   UNIQUE_ID_2   UNIQUE_ID_3 ...   UNIQUE_ID_N
+ *
+ *  SEND_PNODE_PATH      >> UNIQUE_ID_START   UNIQUE_ID_STOP NUMBER [UNIQUE_ID][0..NUMBER]
  */
 
-typedef enum NetworkGameManagerProtocol{
-  CREATE_ENTITY = 0,
-  REMOVE_ENTITY,
-  CREATE_ENTITY_LIST,
-  REMOVE_ENTITY_LIST,
-  REQUEST_CREATE,
-  REQUEST_REMOVE,
-  REQUEST_SYNC,
-  YOU_ARE_ENTITY,
-  REQUEST_ENTITY_LIST
+typedef enum NetworkGameManagerProtocol {
+  NET_CREATE_ENTITY = 0,
+  NET_REMOVE_ENTITY,
+  NET_CREATE_ENTITY_LIST,
+  NET_REMOVE_ENTITY_LIST,
+  NET_REQUEST_CREATE,
+  NET_REQUEST_REMOVE,
+  NET_REQUEST_SYNC,
+  NET_YOU_ARE_ENTITY,
+  NET_REQUEST_ENTITY_LIST,
+  NET_REQUEST_PNODE_PATH,
+  NET_SEND_PNODE_PATH,
+
+  NET_NUMBER
 };
 
@@ -83,19 +95,39 @@
     void sendEntityList(int userID);
 
+
   private:
     NetworkGameManager();
 
+
+    /* some network signal handlers */
+    bool handleRequestCreate( int& i, const byte* data, int length, int sender );
+    bool handleRequestRemove( int& i, const byte* data, int length, int sender );
+    bool handleCreateEntity( int& i, const byte* data, int length, int sender );
+    bool handleRemoveEntity( int& i, const byte* data, int length, int sender );
+    bool handleCreateEntityList( int& i, const byte* data, int length, int sender );
+    bool handleRemoveEntityList( int& i, const byte* data, int length, int sender );
+    bool handleYouAreEntity( int& i, const byte* data, int length, int sender );
+    bool handleRequestSync( int& i, const byte* data, int length, int sender );
+    bool handleRequestPNodePath(int& i, const byte* data, int length, int sender);
+    bool handleSendPNodePath(int& i, const byte* data, int length, int sender);
+
+
+    /* some network handlers helper functions */
     void requestCreateEntity(ClassID classID);
     int executeCreateEntity(ClassID classID, int uniqueID = 0, int owner = 0);
+    BaseObject* doCreateEntity(ClassID classID, int uniqueID, int owner);
 
     void requestRemoveEntity(int uniqueID);
     void executeRemoveEntity(int uniqueID);
+    void doRemoveEntity(int uniqueID);
 
     void executeRequestSync( int uniqueID, int user );
+    void doRequestSync(int uniqueID, int userID);
 
-    BaseObject* doCreateEntity(ClassID classID, int uniqueID, int owner);
-    void doRemoveEntity(int uniqueID);
-    void doRequestSync(int uniqueID, int userID);
     void doYouAre( int uniqueID );
+
+    void requestPNodePath(const PNode* node1, const PNode* node2);
+    void executeRequestPNodePath(const PNode* node2, const PNode* node2);
+    void doRequestPNodePath(const PNode* node1, const PNode* node2);
 
     bool canCreateEntity(ClassID classID);
@@ -105,18 +137,9 @@
     void resizeBufferVector(int n);
 
-    inline bool writeToClientBuffer( clientBuffer &cb, byte*data, int length );
-    inline bool writeToClientBuffer( clientBuffer &cb, byte b );
-    inline bool writeToClientBuffer( clientBuffer &cb, int i );
-    inline bool readFromClientBuffer( clientBuffer &cb, byte*data, int length );
+    bool writeToClientBuffer( clientBuffer &cb, byte*data, int length );
+    bool writeToClientBuffer( clientBuffer &cb, byte b );
+    bool writeToClientBuffer( clientBuffer &cb, int i );
+    bool readFromClientBuffer( clientBuffer &cb, byte*data, int length );
 
-    //helper functions for writeBytes
-    inline bool handleRequestCreate( int& i, const byte* data, int length, int sender );
-    inline bool handleRequestRemove( int& i, const byte* data, int length, int sender );
-    inline bool handleCreateEntity( int& i, const byte* data, int length, int sender );
-    inline bool handleRemoveEntity( int& i, const byte* data, int length, int sender );
-    inline bool handleCreateEntityList( int& i, const byte* data, int length, int sender );
-    inline bool handleRemoveEntityList( int& i, const byte* data, int length, int sender );
-    inline bool handleYouAreEntity( int& i, const byte* data, int length, int sender );
-    inline bool handleRequestSync( int& i, const byte* data, int length, int sender );
 
   private:
@@ -124,6 +147,4 @@
     //clientBuffer                  allOutBuffer;
     static NetworkGameManager*    singletonRef;
-
-    int                           newUniqueID;
     bool                          hasRequestedWorld;
 };
Index: trunk/src/lib/network/network_manager.cc
===================================================================
--- trunk/src/lib/network/network_manager.cc	(revision 6634)
+++ trunk/src/lib/network/network_manager.cc	(revision 6695)
@@ -20,17 +20,18 @@
 #define DEBUG_MODULE_NETWORK
 
-
-#include "network_stream.h"
 #include "class_list.h"
-
 #include "debug.h"
-
+#include "shell_command.h"
 
 /* include your own header */
 #include "network_manager.h"
+#include "shared_network_data.h"
+#include "network_stream.h"
 
 
 /* using namespace std is default, this needs to be here */
 using namespace std;
+
+SHELL_COMMAND(debug, NetworkManager, debug);
 
 
@@ -49,8 +50,6 @@
   this->netStreamList = NULL;
   this->syncList = NULL;
-  this->tmpStream = NULL;
-
-  this->hostID = -1;
-  this->bGameServer = false;
+  this->defaultSyncStream = NULL;
+  this->sharedNetworkData = SharedNetworkData::getInstance();
 
   PRINTF(0)("NetworkManager created\n");
@@ -98,5 +97,7 @@
   }
 
-  this->tmpStream = new NetworkStream(ipAddress);
+  this->defaultSyncStream = new NetworkStream(ipAddress);
+  this->sharedNetworkData->setDefaultSyncStream(this->defaultSyncStream);
+  this->defaultSyncStream->startHandshake();
   return 1;
 }
@@ -109,8 +110,10 @@
 int NetworkManager::createServer(unsigned int port)
 {
-  this->hostID = 0;
-  this->bGameServer = true;
-  this->tmpStream = new NetworkStream(port);
-  this->bGameServer = true;
+  this->sharedNetworkData->setHostID(0);
+  this->sharedNetworkData->setGameServer(true);
+  this->defaultSyncStream = new NetworkStream(port);
+  this->sharedNetworkData->setDefaultSyncStream(this->defaultSyncStream);
+  this->defaultSyncStream->createNetworkGameManager();
+  PRINTF(0)("CREATE SERVER\n");
   SDL_Delay(20);
   return 1;
@@ -118,29 +121,8 @@
 
 
-/**
- *  creates a connection from one object to a host
- * @param address: the address of the destination host
- * @param synchronizeable: reference to the sync object
- */
-NetworkStream& NetworkManager::establishConnection(IPaddress& address, Synchronizeable& sync)
-{
-  /* creating a new network stream, it will register itself automaticaly to the class list */
-  this->tmpStream = new NetworkStream(address);
-  this->tmpStream->connectSynchronizeable(sync);
-}
-
-
-/**
- *  teardown a connection
- */
-void NetworkManager::shutdownConnection()
-{
-  PRINTF(0)("Shutdown connection\n");
-}
-
-
 void NetworkManager::connectSynchronizeable(Synchronizeable& sync)
 {
-  this->tmpStream->connectSynchronizeable(sync);
+  if( this->defaultSyncStream)
+    this->defaultSyncStream->connectSynchronizeable(sync);
 }
 
@@ -157,15 +139,16 @@
       if( static_cast<NetworkStream*>(*stream)->isActive())
         static_cast<NetworkStream*>(*stream)->processData();
-
   }
-
 }
 
+
+
 /**
- * Sets the hostID to a specific number
- * @param id: The new ID
+ * debug output
  */
-void NetworkManager::setHostID(int id)
+ void NetworkManager::debug()
 {
-    this->hostID = id;
+  PRINT(0)("=================Network::debug()=========\n");
+  this->defaultSyncStream->debug();
+  PRINT(0)("===========================================\n");
 }
Index: trunk/src/lib/network/network_manager.h
===================================================================
--- trunk/src/lib/network/network_manager.h	(revision 6634)
+++ trunk/src/lib/network/network_manager.h	(revision 6695)
@@ -6,9 +6,10 @@
 /* you will want to add such a a line at your header file also, since it will
    prevent c++ from including your code twice*/
-#ifndef _NETWORK_MANGER
+#ifndef _NETWORK_MANAGER
 #define _NETWORK_MANAGER
 
 /* include this file, it contains some default definitions */
 #include "netdefs.h"
+#include "shared_network_data.h"
 
 /* include base_object.h since all classes are derived from this one */
@@ -38,16 +39,14 @@
     int createServer(unsigned int port);
 
-    NetworkStream& establishConnection(IPaddress& address, Synchronizeable& sync);
-    void shutdownConnection();
-
-
-    void setHostID(int id);
     /** Returns the hostID @return The hostID of the object */
-    inline int getHostID() { return this->hostID; }
-    inline bool isGameServer() { return this->bGameServer; }
+    inline int getHostID() { return this->sharedNetworkData->getHostID(); }
+    inline bool isGameServer() { return this->sharedNetworkData->isGameServer(); }
 
 
     void connectSynchronizeable(Synchronizeable& sync);
     void synchronize();
+
+    void debug();
+
 
   private:
@@ -59,8 +58,7 @@
     const std::list<BaseObject*>*    syncList;                // list of synchronizeables
     static NetworkManager*           singletonRef;            //!< Pointer to the only instance of this Class
-    NetworkStream*                   tmpStream;               //!< FIXME: this is only for testing purposes
-    int                              hostID;                  //!< The Host-ID of the Manager
-    bool                             bGameServer;             //!< true if it is a server
+    NetworkStream*                   defaultSyncStream;       //!< FIXME: this is only for testing purposes
 
+    SharedNetworkData*               sharedNetworkData;       //!< reference to the shared data
 };
 
Index: trunk/src/lib/network/network_socket.cc
===================================================================
--- trunk/src/lib/network/network_socket.cc	(revision 6634)
+++ trunk/src/lib/network/network_socket.cc	(revision 6695)
@@ -97,4 +97,5 @@
 /**
  * Default destructor
+ * dont use this from outside: use destroy() instead!!
  */
 NetworkSocket::~NetworkSocket( )
Index: trunk/src/lib/network/network_socket.h
===================================================================
--- trunk/src/lib/network/network_socket.h	(revision 6634)
+++ trunk/src/lib/network/network_socket.h	(revision 6695)
@@ -81,10 +81,8 @@
   void init();
 
-  //dont make this public use destroy() instead
-  ~NetworkSocket();
-
 public:
 
   NetworkSocket();
+  ~NetworkSocket();
   NetworkSocket(IPaddress ip);
   NetworkSocket(TCPsocket sock);
Index: trunk/src/lib/network/network_stream.cc
===================================================================
--- trunk/src/lib/network/network_stream.cc	(revision 6634)
+++ trunk/src/lib/network/network_stream.cc	(revision 6695)
@@ -53,4 +53,5 @@
 }
 
+
 NetworkStream::NetworkStream(IPaddress& address)
 {
@@ -60,10 +61,4 @@
   this->networkProtocol = new NetworkProtocol();
   this->connectionMonitor = new ConnectionMonitor();
-
-  Handshake* hs = new Handshake(false);
-  hs->setUniqueID( 0 );
-  this->handshakes.push_back(hs);
-  this->connectSynchronizeable(*hs);
-  PRINTF(0)("NetworkStream: %s\n", hs->getName());
   this->maxConnections = 1;
 }
@@ -81,11 +76,4 @@
   this->handshakes.push_back( NULL );
   this->bActive = true;
-  this->networkGameManager = NetworkGameManager::getInstance();
-  // setUniqueID( maxCon+2 ) because we need one id for every handshake
-  // and one for handshake to reject client maxCon+1
-  this->networkGameManager->setUniqueID( this->maxConnections+2 );
-  this->connectSynchronizeable( *(this->networkGameManager) );
-
-  this->setMaxConnections( 10 );
 }
 
@@ -132,4 +120,25 @@
 
 
+void NetworkStream::createNetworkGameManager()
+{
+  this->networkGameManager = NetworkGameManager::getInstance();
+  // setUniqueID( maxCon+2 ) because we need one id for every handshake
+  // and one for handshake to reject client maxCon+1
+  this->networkGameManager->setUniqueID( this->maxConnections + 2 );
+  //this->connectSynchronizeable( *(this->networkGameManager) );
+  this->setMaxConnections( 10 );
+}
+
+
+void NetworkStream::startHandshake()
+{
+  Handshake* hs = new Handshake(false);
+  hs->setUniqueID( 0 );
+  this->handshakes.push_back(hs);
+  //this->connectSynchronizeable(*hs);
+  PRINTF(0)("NetworkStream: %s\n", hs->getName());
+}
+
+
 void NetworkStream::connectSynchronizeable(Synchronizeable& sync)
 {
@@ -140,4 +149,5 @@
     this->bActive = true;
 }
+
 
 void NetworkStream::disconnectSynchronizeable(Synchronizeable& sync)
@@ -184,10 +194,10 @@
           if ( type != NET_SERVER )
           {
-            NetworkManager::getInstance()->setHostID( handshakes[i]->getHostId() );
+            SharedNetworkData::getInstance()->setHostID( handshakes[i]->getHostId() );
             myHostId = NetworkManager::getInstance()->getHostID();
 
             this->networkGameManager = NetworkGameManager::getInstance();
             this->networkGameManager->setUniqueID( handshakes[i]->getNetworkGameManagerId() );
-            this->connectSynchronizeable( *(this->networkGameManager) );
+            //this->connectSynchronizeable( *(this->networkGameManager) );
           }
           else
@@ -216,4 +226,6 @@
   /* DOWNSTREAM */
 
+
+
   int dataLength;
   int reciever;
@@ -221,5 +233,5 @@
   for (SynchronizeableList::iterator it = synchronizeables.begin(); it!=synchronizeables.end(); it++)
   {
-    if ( (*it)!=NULL /*&& (*it)->getOwner() == myHostId*/ )
+    if ( (*it)!=NULL && (*it)->beSynchronized() /*&& (*it)->getOwner() == myHostId*/ )
     {
       do {
@@ -357,5 +369,5 @@
     PRINTF(0)("New Client: %d\n", clientId);
 
-    this->connectSynchronizeable(*handshakes[clientId]);
+    //this->connectSynchronizeable(*handshakes[clientId]);
   }
 
@@ -416,2 +428,38 @@
 
 
+
+void NetworkStream::debug()
+{
+  if( this->isServer())
+    PRINT(0)(" Host ist Server with ID: %i\n", this->myHostId);
+  else
+    PRINT(0)(" Host ist Client with ID: %i\n", this->myHostId);
+
+  PRINT(0)(" Got %i connected Synchronizeables, showing active Syncs:\n", this->synchronizeables.size());
+  for (SynchronizeableList::iterator it = synchronizeables.begin(); it!=synchronizeables.end(); it++)
+  {
+    if( (*it)->beSynchronized() == true)
+      PRINT(0)("  Synchronizeable of class: %s::%s, with unique ID: %i, Synchronize: %i\n", (*it)->getClassName(), (*it)->getName(),
+               (*it)->getUniqueID(), (*it)->beSynchronized());
+  }
+  PRINT(0)(" Maximal Connections: %i\n", this->maxConnections);
+
+}
+
+
+int NetworkStream::getSyncCount()
+{
+  int n = 0;
+  for (SynchronizeableList::iterator it = synchronizeables.begin(); it!=synchronizeables.end(); it++)
+    if( (*it)->beSynchronized() == true)
+      ++n;
+
+  //return synchronizeables.size();
+  return n;
+}
+
+
+
+
+
+
Index: trunk/src/lib/network/network_stream.h
===================================================================
--- trunk/src/lib/network/network_stream.h	(revision 6634)
+++ trunk/src/lib/network/network_stream.h	(revision 6695)
@@ -14,6 +14,4 @@
 #include "server_socket.h"
 #include "handshake.h"
-
-#define MAX_CONNECTIONS 1000
 
 class Synchronizeable;
@@ -40,4 +38,7 @@
     void init();
 
+    void createNetworkGameManager();
+    void startHandshake();
+
     void connectSynchronizeable(Synchronizeable& sync);
     void disconnectSynchronizeable(Synchronizeable& sync);
@@ -53,26 +54,31 @@
     inline SynchronizeableList::const_iterator getSyncBegin(){ return synchronizeables.begin(); }
     inline SynchronizeableList::const_iterator getSyncEnd(){ return synchronizeables.end(); }
-    inline int getSyncCount(){ return synchronizeables.size(); }
+    int getSyncCount();
 
     inline bool isUserIdActive( int userID ) { if (userID>=networkSockets.size()) return false; else return networkSockets[userID]!=NULL; }
 
+    void debug();
+
+
   private:
-    NetworkProtocol*       networkProtocol;
-    ConnectionMonitor*     connectionMonitor;
-    SynchronizeableList    synchronizeables;
-    NetworkSocketVector    networkSockets;
-    HandshakeVector        handshakes;
-    ServerSocket*          serverSocket;
-    int                    type;
-    Header                 packetHeader;
-    bool                   bActive;
-    std::list<int>         freeSocketSlots;
+    void updateConnectionList();
 
-    int                    myHostId;
-    int                    maxConnections;
 
-    NetworkGameManager*   networkGameManager;
+  private:
+    NetworkProtocol*           networkProtocol;
+    ConnectionMonitor*         connectionMonitor;
+    SynchronizeableList        synchronizeables;
+    NetworkSocketVector        networkSockets;
+    HandshakeVector            handshakes;
+    ServerSocket*              serverSocket;
+    int                        type;
+    Header                     packetHeader;
+    bool                       bActive;
+    std::list<int>             freeSocketSlots;
 
-    void updateConnectionList();
+    int                        myHostId;
+    int                        maxConnections;
+
+    NetworkGameManager*        networkGameManager;
 };
 #endif /* _NETWORK_STREAM */
Index: trunk/src/lib/network/shared_network_data.cc
===================================================================
--- trunk/src/lib/network/shared_network_data.cc	(revision 6695)
+++ trunk/src/lib/network/shared_network_data.cc	(revision 6695)
@@ -0,0 +1,46 @@
+/*
+   orxonox - the future of 3D-vertical-scrollers
+
+   Copyright (C) 2004 orx
+
+   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, or (at your option)
+   any later version.
+
+### File Specific:
+   main-programmer: Patrick Boenzli
+*/
+
+
+#define DEBUG_MODULE_NETWORK
+
+#include "shared_network_data.h"
+#include "netdefs.h"
+
+
+using namespace std;
+
+
+SharedNetworkData* SharedNetworkData::singletonRef = NULL;
+
+/**
+ * Standard constructor
+ */
+SharedNetworkData::SharedNetworkData()
+{
+  /* set the class id for the base object */
+  this->setClassID(CL_SHARED_NETWORK_DATA, "SharedNetworkData");
+
+  this->hostID = -1;
+  this->defaultSyncStream = NULL;
+  this->newUniqueID = MAX_CONNECTIONS + 2;
+  this->bGameServer = false;
+}
+
+
+/**
+ * Standard destructor
+ */
+SharedNetworkData::~SharedNetworkData()
+{}
Index: trunk/src/lib/network/shared_network_data.h
===================================================================
--- trunk/src/lib/network/shared_network_data.h	(revision 6695)
+++ trunk/src/lib/network/shared_network_data.h	(revision 6695)
@@ -0,0 +1,61 @@
+/*!
+ * @file shared_network_data.h
+ *  some shared data from the NetworkManager
+ */
+
+#ifndef _SHARED_NETWORK_DATA
+#define _SHARED_NETWORK_DATA
+
+#include "base_object.h"
+
+
+class NetworkStream;
+class Synchronizeable;
+template<typename>
+    class tList;
+
+/* and here is the class itsself*/
+class SharedNetworkData : public BaseObject
+{
+
+  public:
+    inline static SharedNetworkData* getInstance() { if (!SharedNetworkData::singletonRef) SharedNetworkData::singletonRef = new SharedNetworkData();
+      return SharedNetworkData::singletonRef; }
+    virtual ~SharedNetworkData();
+
+    /** @returns the next uniqueID free for an object */
+    inline int getNewUniqueID() { return ( this->bGameServer)?this->newUniqueID++:-1; }
+
+    /** @returns true is this node is a game server */
+    inline bool isGameServer() { return this->bGameServer; }
+    /** sets the game server flag @param bGameServer true if it is a game server */
+    inline void setGameServer(bool bGameServer) { this->bGameServer = bGameServer; }
+
+    /** @returns the hostID of the node */
+    inline int getHostID() { return this->hostID; }
+    /** sets the hostID of this node @param hostID of the node */
+    inline void setHostID(int hostID) { this->hostID = hostID; }
+
+    /** @returns the default synchronize stream */
+    inline NetworkStream* getDefaultSyncStream() { return this->defaultSyncStream; }
+    /** sets the default sync stream @param defaultSyncStream the default sync stream */
+    inline void setDefaultSyncStream(NetworkStream* defaultSyncStream) { this->defaultSyncStream = defaultSyncStream; }
+
+
+  private:
+    SharedNetworkData();
+
+
+  private:
+    int                             newUniqueID;             //!< next uniqueID
+    bool                            bGameServer;             //!< true if it is a server
+    int                             hostID;                  //!< The Host-ID of the Manager
+    NetworkStream*                  defaultSyncStream;       //!< default synchronize NetworkStream
+
+    static SharedNetworkData*       singletonRef;            //!< Pointer to the only instance of this Class
+
+};
+
+
+
+#endif /* _SHARED_NETWORK_DATA */
Index: trunk/src/lib/network/synchronizeable.cc
===================================================================
--- trunk/src/lib/network/synchronizeable.cc	(revision 6634)
+++ trunk/src/lib/network/synchronizeable.cc	(revision 6695)
@@ -17,8 +17,14 @@
 #define DEBUG_MODULE_NETWORK
 
+#include "shared_network_data.h"
+#include "network_stream.h"
+#include "netdefs.h"
+
+#include "state.h"
+
+#include "assert.h"
+
 #include "synchronizeable.h"
-#include "netdefs.h"
-#include "network_manager.h"
-#include "network_stream.h"
+
 
 
@@ -29,12 +35,21 @@
 {
   this->setClassID(CL_SYNCHRONIZEABLE, "Synchronizeable");
-  owner = 0;
-  state = 0;
-  hostID = NetworkManager::getInstance()->getHostID();
+  this->owner = 0;
+  this->state = 0;
+  this->hostID = SharedNetworkData::getInstance()->getHostID();
   this->setIsServer(this->hostID == 0);
-  uniqueID = -1;
+  this->uniqueID = NET_UID_UNASSIGNED;
   this->networkStream = NULL;
   this->setRequestedSync( false );
   this->setIsOutOfSync( !(this->isServer()) );
+  this->bSynchronize = false;
+
+  if( State::isOnline())
+  {
+    NetworkStream* nd = SharedNetworkData::getInstance()->getDefaultSyncStream();
+    assert(nd != NULL);
+    nd->connectSynchronizeable(*this);
+    this->setUniqueID(SharedNetworkData::getInstance()->getNewUniqueID());
+  }
 }
 
@@ -50,4 +65,5 @@
 }
 
+
 /**
  *  write data to NetworkStream
@@ -57,4 +73,5 @@
   PRINTF(5)("Synchronizeable::writeBytes was called\n");
 }
+
 
 /**
@@ -87,4 +104,5 @@
 }
 
+
 /**
  * Sets the outofsync flag to a given value
@@ -100,4 +118,5 @@
 }
 
+
 /**
  * Determines if the server flag is set
@@ -108,4 +127,5 @@
   return (this->state & STATE_SERVER) >0;
 }
+
 
 /**
@@ -118,4 +138,5 @@
 }
 
+
 /**
  * Determines if the requestedSync flag is set
@@ -126,4 +147,5 @@
   return (this->state & STATE_REQUESTEDSYNC) >0;
 }
+
 
 /**
Index: trunk/src/lib/network/synchronizeable.h
===================================================================
--- trunk/src/lib/network/synchronizeable.h	(revision 6634)
+++ trunk/src/lib/network/synchronizeable.h	(revision 6695)
@@ -163,8 +163,9 @@
 
 class Synchronizeable : virtual public BaseObject
-  {
+{
+
   public:
     Synchronizeable();
-    ~Synchronizeable();
+    virtual ~Synchronizeable();
 
     virtual int       writeBytes(const byte* data, int length, int sender);
@@ -179,31 +180,37 @@
     bool isOutOfSync();
     bool requestedSync();
+
     inline void setUniqueID( int id ){ uniqueID = id; }
-    inline int  getUniqueID() const { return uniqueID; };
+    inline int  getUniqueID() const { return uniqueID; }
+    inline int getHostID() { return this->hostID; }
+
+    inline int getOwner(){ return owner; }
+    inline void setOwner(int owner){ this->owner = owner; }
+
+    /** @returns true if this Synchronizeable has to be synchronized over network */
+    inline bool beSynchronized() { return this->bSynchronize; }
+    /** @param bSynchronize sets the Synchronizeable to be sunchronized or not */
+    inline void setSynchronized(bool bSynchronize) { this->bSynchronize = bSynchronize; }
+
     inline void requestSync( int hostID ){ this->synchronizeRequests.push_back( hostID ); }
     inline int getRequestSync( void ){ if ( this->synchronizeRequests.size()>0 ){ int n = *(synchronizeRequests.begin()); synchronizeRequests.pop_front(); return n; } else { return -1; } };
-    inline int getHostID() { return this->hostID; }
-
-    inline int getOwner(){ return owner; }
-    inline void setOwner(int owner){ this->owner = owner; }
 
     inline void setNetworkStream(NetworkStream* stream) { this->networkStream = stream; }
+    inline NetworkStream* getNetworkStream() { return this->networkStream; }
+
+
+  protected:
+    NetworkStream*    networkStream;
+    int               state;
+
 
   private:
-
     int               uniqueID;
-
-
-
-    //static std::vector<Synchronizeable*> classList;
-    int owner;
-    int hostID;
-
-    std::list<int> synchronizeRequests;
-
-  protected:
-    NetworkStream* networkStream;
-    int state;
-
-  };
+    int               owner;
+    int               hostID;
+    bool              bSynchronize;
+
+    std::list<int>    synchronizeRequests;
+
+};
 #endif /* _SYNCHRONIZEABLE_H */
