Index: branches/network/src/lib/network/handshake.cc
===================================================================
--- branches/network/src/lib/network/handshake.cc	(revision 6146)
+++ branches/network/src/lib/network/handshake.cc	(revision 6190)
@@ -37,5 +37,5 @@
 }
 
-void Handshake::writeBytes( const byte * data, int length )
+void Handshake::writeBytes( const byte * data, int length, int sender)
 {
   PRINTF(5)("Handshake::writeBytes states = %d %d %d %d (%d)\n", hasState( HS_RECVD_INIT ), hasState( HS_RECVD_VER ), hasState( HS_RECVD_HID ), hasState( HS_COMPLETED ), state);
Index: branches/network/src/lib/network/handshake.h
===================================================================
--- branches/network/src/lib/network/handshake.h	(revision 6146)
+++ branches/network/src/lib/network/handshake.h	(revision 6190)
@@ -42,5 +42,5 @@
     inline void       doReject(){ setState(HS_DO_REJECT); }
 
-    virtual void      writeBytes(const byte* data, int length);
+    virtual void      writeBytes(const byte* data, int length, int sender);
     virtual int       readBytes(byte* data, int maxLength, int * reciever);
     virtual void      writeDebug() const;
Index: branches/network/src/lib/network/network_game_manager.cc
===================================================================
--- branches/network/src/lib/network/network_game_manager.cc	(revision 6146)
+++ branches/network/src/lib/network/network_game_manager.cc	(revision 6190)
@@ -20,4 +20,7 @@
 #define DEBUG_MODULE_NETWORK
 
+#include "factory.h"
+#include "network_stream.h"
+
 /* include your own header */
 #include "network_game_manager.h"
@@ -41,8 +44,15 @@
 NetworkGameManager::~NetworkGameManager()
 {
-}
-
-
-void NetworkGameManager::writeBytes(const byte* data, int length)
+  for ( int i = 0; i<inBuffer.size(); i++)
+  {
+    if ( inBuffer[i].buffer )
+      delete inBuffer[i].buffer;
+    if ( outBuffer[i].buffer )
+      delete outBuffer[i].buffer;
+  }
+}
+
+
+void NetworkGameManager::writeBytes(const byte* data, int length, int sender)
 {
 }
@@ -121,3 +131,102 @@
 bool NetworkGameManager::canCreateEntity(int classID)
 {
-}
+  return true;
+}
+
+/*!
+ * Sends the Entities to the new connected client
+ * @param userID: The ID of the user
+ */
+void NetworkGameManager::sendEntityList( int userID )
+{
+}
+
+/**
+ * Creates a buffer for user n
+ * @param n The ID of the user
+ */
+void NetworkGameManager::resizeBufferVector( int n )
+{
+  for ( int i = inBuffer.size(); i<=n; i++)
+  {
+    clientBuffer inBuf;
+    clientBuffer outBuf;
+
+    inBuf.length = 0;
+    outBuf.length = 0;
+
+    inBuf.maxLength = 5*1014;
+    outBuf.maxLength = 5*1024;
+
+    inBuf.buffer = new byte[5*1014];
+    outBuf.buffer = new byte[5*1014];
+
+    inBuffer.push_back(inBuf);
+    outBuffer.push_back(outBuf);
+  }
+}
+
+/**
+ * Creates the entity on this host
+ * @param classID: ClassID of the entity to create
+ * @param uniqueID: Unique ID to assign to the synchronizeable
+ * @param owner: owner of this synchronizealbe
+ */
+void NetworkGameManager::doCreateEntity( ClassID classID, int uniqueID, int owner )
+{
+  BaseObject * b = Factory::fabricate( classID );
+
+  if ( b->isA(CL_SYNCHRONIZEABLE) )
+  {
+    Synchronizeable * s = dynamic_cast<Synchronizeable*>(b);
+    s->setUniqueID( uniqueID );
+    s->setOwner( owner );
+    this->networkStream->connectSynchronizeable( *s );
+  }
+  else
+  {
+    PRINTF(1)("Class with ID %d is not a synchronizeable!", (int)classID);
+    delete b;
+  }
+}
+
+/**
+ * Removes a entity on this host
+ * @param uniqueID: unique ID assigned with the entity to remove
+ */
+void NetworkGameManager::doRemoveEntity( int uniqueID )
+{
+  SynchronizeableList::const_iterator it,e;
+  it = this->networkStream->getSyncBegin();
+  e = this->networkStream->getSyncEnd();
+
+  while ( it != e )
+  {
+    if ( (*it)->getUniqueID() == uniqueID )
+    {
+      delete *it;
+      break;
+    }
+  }
+}
+
+/**
+ * Tell the synchronizeable that a user's synchronizeable is out of sync
+ * @param uniqueID: unique ID assigned with the entity which is out of sync
+ * @param userID: user ID who's synchronizeable is out of sync
+ */
+void NetworkGameManager::doRequestSync( int uniqueID, int userID )
+{
+  SynchronizeableList::const_iterator it,e;
+  it = this->networkStream->getSyncBegin();
+  e = this->networkStream->getSyncEnd();
+
+  while ( it != e )
+  {
+    if ( (*it)->getUniqueID() == uniqueID )
+    {
+      (*it)->requestSync( userID );
+      break;
+    }
+  }
+}
Index: branches/network/src/lib/network/network_game_manager.h
===================================================================
--- branches/network/src/lib/network/network_game_manager.h	(revision 6146)
+++ branches/network/src/lib/network/network_game_manager.h	(revision 6190)
@@ -18,27 +18,35 @@
  * 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
+ *  REQUEST_REMOVE:      UNIQUE_ID
  *
- *  REQUEST_SYNC:       UNIQUE_ID
- *  REQUEST_SYNC_LIST:  NUMBER, [UNIQUE_ID][0..NUMBER]
+ *  REQUEST_CREATE_LIST: NUMBER, [CLASS_ID][0..NUMBER]
+ *  REQUEST_CREATE_LIST: NUMBER, [UNIQUE_ID][0..NUMBER]
+ *
+ *  REQUEST_SYNC:        UNIQUE_ID
+ *  REQUEST_SYNC_LIST:   NUMBER, [UNIQUE_ID][0..NUMBER]
  *
  *
  */
 
+typedef enum NetworkGameManagerProtocol{
+  CREATE_ENTITY = 0,
+  REMOVE_ENTITY,
+  REQUEST_CREATE,
+  REQUEST_SYNC
+};
 
-
-
-
-
-
-
-
+struct clientBuffer
+{
+  int length;
+  int maxLength;
+  byte * buffer;
+};
 
 /*!
@@ -51,5 +59,5 @@
     ~NetworkGameManager();
 
-    virtual void writeBytes(const byte* data, int length);
+    virtual void writeBytes(const byte* data, int length, int sender);
     virtual int readBytes(byte* data, int maxLength, int * reciever);
     virtual void writeDebug() const;
@@ -57,32 +65,28 @@
 
     void createEntity(int classID);
-    void createEntityList(int* classIDList);
     void removeEntity(int uniqueID);
-    void removeEntityList(int* uniqueIDList);
 
     void sync(int uniqueID);
-    void syncList(int* uniqueIDList);
 
+    void sendEntityList(int userID);
 
   private:
     void requestCreateEntity(int classID);
     void executeCreateEntity(int classID);
-    void requestCreateEntityList(int* classIDList);
-    void executeCreateEntityList(int* classIDList);
 
     void requestRemoveEntity(int uniqueID);
     void executeRemoveEntity(int uniqueID);
-    void requestRemoveEntityList(int* uniqueIDList);
-    void executeRemoveEntityList(int* uniqueIDList);
 
-
+    void doCreateEntity(ClassID classID, int uniqueID, int owner);
+    void doRemoveEntity(int uniqueID);
+    void doRequestSync(int uniqueID, int userID);
 
     bool canCreateEntity(int classID);
 
-
+    void resizeBufferVector(int n);
 
   private:
-    byte*          inBuffer;
-    byte*          outBuffer;
+    std::vector<clientBuffer>     inBuffer;
+    std::vector<clientBuffer>     outBuffer;
 };
 
Index: branches/network/src/lib/network/network_stream.cc
===================================================================
--- branches/network/src/lib/network/network_stream.cc	(revision 6146)
+++ branches/network/src/lib/network/network_stream.cc	(revision 6190)
@@ -27,4 +27,5 @@
 #include "synchronizeable.h"
 #include "network_manager.h"
+#include "network_game_manager.h"
 #include "list.h"
 #include "debug.h"
@@ -77,4 +78,9 @@
   this->handshakes.push_back( NULL );
   this->bActive = true;
+  this->networkGameManager = new NetworkGameManager();
+  // 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 );
@@ -88,4 +94,5 @@
   this->bActive = false;
   this->serverSocket = NULL;
+  this->networkGameManager = NULL;
   myHostId = 0;
 }
@@ -175,7 +182,11 @@
           }
           PRINT(0)("handshake finished\n");
+
+          this->networkGameManager = new NetworkGameManager();
+          this->networkGameManager->setUniqueID( handshakes[i]->getNetworkGameManagerId() );
+          this->connectSynchronizeable( *(this->networkGameManager) );
+
           delete handshakes[i];
           handshakes[i] = NULL;
-          //TODO: replace handshake by entitymanager
         }
         else
@@ -199,5 +210,4 @@
   for (SynchronizeableList::iterator it = synchronizeables.begin(); it!=synchronizeables.end(); it++)
   {
-    //TODO: remove items from synchronizeables if they dont exist
     if ( (*it)!=NULL && (*it)->getOwner() == myHostId )
     {
@@ -214,7 +224,6 @@
         dataLength = networkProtocol->createHeader((byte*)downBuffer, dataLength, DATA_STREAM_BUFFER_SIZE, static_cast<const Synchronizeable&>(*(*it)));
 
-        //FIXME: this is a hack, find a better way
         Header* header = (Header*)downBuffer;
-        if ( header->synchronizeableID<100 )
+        if ( header->synchronizeableID < this->maxConnections )
           header->synchronizeableID = 0;
 
@@ -284,5 +293,5 @@
         {
           if ( *it && (*it)->getUniqueID()==header.synchronizeableID )
-            (*it)->writeBytes(upBuffer+sizeof(header), dataLength);
+            (*it)->writeBytes(upBuffer+sizeof(header), dataLength, i);
         }
 
@@ -306,5 +315,5 @@
       freeSocketSlots.pop_back();
       networkSockets[clientId] = tempNetworkSocket;
-      handshakes[clientId] = new Handshake(true, clientId);
+      handshakes[clientId] = new Handshake(true, clientId, this->networkGameManager->getUniqueID());
       handshakes[clientId]->setUniqueID(clientId);
     } else
@@ -312,5 +321,5 @@
       clientId = networkSockets.size();
       networkSockets.push_back(tempNetworkSocket);
-      Handshake* tHs = new Handshake(true, clientId);
+      Handshake* tHs = new Handshake(true, clientId, this->networkGameManager->getUniqueID());
       tHs->setUniqueID(clientId);
       handshakes.push_back(tHs);
@@ -374,5 +383,6 @@
   }
   this->maxConnections = n;
-}
-
-
+  this->networkGameManager->setUniqueID( n+2 );
+}
+
+
Index: branches/network/src/lib/network/network_stream.h
===================================================================
--- branches/network/src/lib/network/network_stream.h	(revision 6146)
+++ branches/network/src/lib/network/network_stream.h	(revision 6190)
@@ -20,4 +20,5 @@
 class ConnectionMonitor;
 class NetworkProtocol;
+class NetworkGameManager;
 
 typedef std::list<Synchronizeable*>  SynchronizeableList;
@@ -48,4 +49,7 @@
     virtual void processData();
 
+    inline SynchronizeableList::const_iterator getSyncBegin(){ return synchronizeables.begin(); }
+    inline SynchronizeableList::const_iterator getSyncEnd(){ return synchronizeables.end(); }
+
   private:
     NetworkProtocol*       networkProtocol;
@@ -63,4 +67,6 @@
     int                    maxConnections;
 
+    NetworkGameManager*   networkGameManager;
+
     void updateConnectionList();
 };
Index: branches/network/src/lib/network/synchronizeable.cc
===================================================================
--- branches/network/src/lib/network/synchronizeable.cc	(revision 6146)
+++ branches/network/src/lib/network/synchronizeable.cc	(revision 6190)
@@ -59,5 +59,5 @@
  *  write data to NetworkStream
  */
-void Synchronizeable::writeBytes(const byte* data, int length)
+void Synchronizeable::writeBytes(const byte* data, int length, int sender)
 {
   PRINTF(1)("Synchronizeable::writeBytes was called\n");
Index: branches/network/src/lib/network/synchronizeable.h
===================================================================
--- branches/network/src/lib/network/synchronizeable.h	(revision 6146)
+++ branches/network/src/lib/network/synchronizeable.h	(revision 6190)
@@ -30,5 +30,5 @@
     ~Synchronizeable();
 
-    virtual void      writeBytes(const byte* data, int length);
+    virtual void      writeBytes(const byte* data, int length, int sender);
     virtual int       readBytes(byte* data, int maxLength, int * reciever);
     virtual void      writeDebug() const;
@@ -60,4 +60,5 @@
     std::list<int> synchronizeRequests;
 
+  protected:
     NetworkStream* networkStream;
 
