Index: /branches/network/src/lib/lang/base_object.cc
===================================================================
--- /branches/network/src/lib/lang/base_object.cc	(revision 7574)
+++ /branches/network/src/lib/lang/base_object.cc	(revision 7575)
@@ -83,4 +83,5 @@
   assert (!(this->classID & classID & !CL_MASK_SUBSUPER_CLASS_IDA ));
 
+  this->leafClassID = classID;
   this->classID |= (long)classID;
   this->className = className;
@@ -106,8 +107,7 @@
  * Factory::fabricate(Object->getLeafClassID());
  */
-ClassID BaseObject::getLeafClassID() const
+const ClassID& BaseObject::getLeafClassID() const
 {
-  assert (this->classList != NULL);
-  return this->classList->getLeafClassID();
+  return this->leafClassID;
 }
 
Index: /branches/network/src/lib/lang/base_object.h
===================================================================
--- /branches/network/src/lib/lang/base_object.h	(revision 7574)
+++ /branches/network/src/lib/lang/base_object.h	(revision 7575)
@@ -41,5 +41,5 @@
   /** @returns the classID of the corresponding Object */
   inline int getClassID() const { return this->classID; };
-  ClassID    getLeafClassID() const;
+  const ClassID& getLeafClassID() const;
 
   bool isA (ClassID classID) const;
@@ -58,4 +58,5 @@
     std::string        className;        //!< the name of the class
     long               classID;          //!< this is the id from the class_id.h enumeration
+    ClassID            leafClassID;      //!< The Leaf Class ID
 
     ClassList*         classList;        //!< Pointer to the ClassList this Object is inside of
Index: /branches/network/src/lib/network/network_stream.cc
===================================================================
--- /branches/network/src/lib/network/network_stream.cc	(revision 7574)
+++ /branches/network/src/lib/network/network_stream.cc	(revision 7575)
@@ -64,5 +64,4 @@
   this->networkProtocol = new NetworkProtocol();
   this->connectionMonitor = new ConnectionMonitor();
-  this->maxConnections = MAX_CONNECTIONS;
 }
 
@@ -131,5 +130,5 @@
   // 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->networkGameManager->setUniqueID( MAX_CONNECTIONS + 2 );
 
 }
@@ -142,6 +141,8 @@
   assert( peers[0].handshake == NULL );
   peers[0].handshake = hs;
+//   peers[0].handshake->setSynchronized( true );
+  this->connectSynchronizeable(*hs);
   //this->connectSynchronizeable(*hs);
-  PRINTF(0)("NetworkStream: %s\n", hs->getName());
+  PRINTF(0)("NetworkStream: Handshake created: %s\n", hs->getName());
 }
 
@@ -194,4 +195,7 @@
   }
 
+  handleHandshakes();
+  handleUpstream();
+  handleDownstream();
 
 
@@ -354,5 +358,5 @@
     } else
     {
-      clientId = 0;
+      clientId = 1;
       
       for ( PeerList::iterator it = peers.begin(); it != peers.end(); it++ )
@@ -366,5 +370,5 @@
     }
 
-    if ( clientId > this->maxConnections )
+    if ( clientId > MAX_CONNECTIONS )
     {
       peers[clientId].handshake->doReject( "too many connections" );
@@ -419,5 +423,5 @@
                (*it)->getUniqueID(), (*it)->beSynchronized());
   }
-  PRINT(0)(" Maximal Connections: %i\n", this->maxConnections);
+  PRINT(0)(" Maximal Connections: %i\n", MAX_CONNECTIONS );
 
 }
@@ -486,5 +490,5 @@
     offset = INTSIZE; //make already space for length 
     
-    if ( peer->second.socket )
+    if ( !peer->second.socket )
       continue;
     
@@ -504,8 +508,21 @@
     {
       Synchronizeable & sync = **it;
+
+      if ( !sync.beSynchronized() || sync.getUniqueID() < 0 )
+        continue;
+
+      //if handshake not finished only sync handshake
+      if ( peer->second.handshake && sync.getLeafClassID() != CL_HANDSHAKE )
+        continue;
+
+      PRINTF(0)("syncing: id:%d name:%s\n", sync.getUniqueID(), sync.getClassName());
       
       assert( offset + INTSIZE <= UDP_PACKET_SIZE );
       
-      n = Converter::intToByteArray( sync.getUniqueID(), buf + offset, UDP_PACKET_SIZE - offset );
+      //server fakes uniqueid=0 for handshake
+      if ( this->isServer() && sync.getUniqueID() < MAX_CONNECTIONS - 1 )
+        n = Converter::intToByteArray( 0, buf + offset, UDP_PACKET_SIZE - offset );
+      else
+        n = Converter::intToByteArray( sync.getUniqueID(), buf + offset, UDP_PACKET_SIZE - offset );
       assert( n == INTSIZE );
       offset += n;
@@ -517,4 +534,5 @@
     
     assert( peer->second.socket->writePacket( buf, offset ) );
+    PRINTF(0)("send packet: %d\n", offset);
   }
 }
@@ -537,5 +555,15 @@
   for ( PeerList::iterator peer = peers.begin(); peer != peers.end(); peer++ )
   {
+    if ( !peer->second.socket )
+      continue;
+
     packetLength = peer->second.socket->readPacket( buf, UDP_PACKET_SIZE );
+
+    if ( packetLength < 4*INTSIZE )
+    {
+      if ( packetLength != 0 )
+        PRINTF(1)("got too small packet: %d\n", packetLength);
+      continue;
+    }
     
     assert( Converter::byteArrayToInt( buf, &length ) == INTSIZE );
@@ -543,4 +571,6 @@
     assert( Converter::byteArrayToInt( buf + 2*INTSIZE, &fromState ) == INTSIZE );
     assert( Converter::byteArrayToInt( buf + 3*INTSIZE, &ackedState ) == INTSIZE );
+
+    PRINTF(0)("got packet: %d, %d\n", length, packetLength);
     
     //if this is an old state drop it
@@ -565,6 +595,7 @@
       
       for ( SynchronizeableList::iterator it = synchronizeables.begin(); it != synchronizeables.end(); it++ )
-      {
-        if ( (*it)->getUniqueID() == uniqueId )
+      { 
+        //                                        client thinks his handshake has id 0!!!!!
+        if ( (*it)->getUniqueID() == uniqueId || ( uniqueId == 0 && (*it)->getUniqueID() == peer->second.userId ) )
         {
           sync = *it;
Index: /branches/network/src/lib/network/network_stream.h
===================================================================
--- /branches/network/src/lib/network/network_stream.h	(revision 7574)
+++ /branches/network/src/lib/network/network_stream.h	(revision 7575)
@@ -60,5 +60,5 @@
     inline bool isActive() const { return this->bActive; }
 
-    inline int getMaxConnections(){ return maxConnections; }
+    inline int getMaxConnections(){ return MAX_CONNECTIONS; }
 
     virtual void processData();
@@ -94,5 +94,4 @@
 
     int                        myHostId;
-    int                        maxConnections;
     
     int                        currentState;
Index: /branches/network/src/lib/network/synchronizeable.cc
===================================================================
--- /branches/network/src/lib/network/synchronizeable.cc	(revision 7574)
+++ /branches/network/src/lib/network/synchronizeable.cc	(revision 7575)
@@ -41,6 +41,5 @@
   this->networkStream = NULL;
   this->bSynchronize = false;
-  this->mLeafClassId = getLeafClassID();
-
+  
   if( State::isOnline())
   {
@@ -53,6 +52,6 @@
   /* make sure loadClassId is first synced var because this is read by networkStream */
   assert( syncVarList.size() == 0 );
-  this->registerVar( new SynchronizeableInt( &this->mLeafClassId, &this->mLeafClassId, "leafClassId" ) );
-  
+  this->registerVar( new SynchronizeableInt( (int*)&this->getLeafClassID(), (int*)&this->getLeafClassID(), "leafClassId" ) );
+    
   this->registerVar( new SynchronizeableInt( &this->owner, &this->owner, "owner" ) );
   this->registerVar( new SynchronizeableString( &this->objectName, &this->objectName, "objectName" ) );
@@ -309,5 +308,5 @@
   this->varChangeHandler( changes );
 
-  assert( i == length -1 );
+  assert( i == length );
 
   return length;
Index: /branches/network/src/lib/network/udp_server_socket.h
===================================================================
--- /branches/network/src/lib/network/udp_server_socket.h	(revision 7574)
+++ /branches/network/src/lib/network/udp_server_socket.h	(revision 7575)
@@ -20,5 +20,5 @@
 #include <vector>
 
-#define UDP_PACKET_SIZE 1024
+#define UDP_PACKET_SIZE 10240
 #define MAX_NEW_CONNECTIONS 8
 
