Index: trunk/src/lib/coord/p_node.cc
===================================================================
--- trunk/src/lib/coord/p_node.cc	(revision 6956)
+++ trunk/src/lib/coord/p_node.cc	(revision 6959)
@@ -1253,5 +1253,5 @@
   SYNCHELP_WRITE_BEGIN();
 
-  if ( this->getHostID()!=this->getOwner() )
+  if ( this->getHostID()!=0 && this->getHostID()!=this->getOwner() )
   {
     return SYNCHELP_WRITE_N;
@@ -1259,7 +1259,7 @@
 
   byte flags = 0;
-  if ( fabs( coorx - relCoordinate.x ) > __OFFSET_POS ||
-       fabs( coory - relCoordinate.y ) > __OFFSET_POS ||
-       fabs( coorz - relCoordinate.z ) > __OFFSET_POS )
+  if ( fabs( coorx - relCoordinate.x ) > __OFFSET_POS*0.05*this->velocity.len() ||
+       fabs( coory - relCoordinate.y ) > __OFFSET_POS*0.05*this->velocity.len() ||
+       fabs( coorz - relCoordinate.z ) > __OFFSET_POS*0.05*this->velocity.len() )
     flags |= __FLAG_COOR;
 
@@ -1272,10 +1272,10 @@
 
   SYNCHELP_WRITE_BYTE( flags, NWT_PN_FLAGS );
-  //PRINTF(0)("FLAGS = %d\n", flags);
+  PRINTF(0)("FLAGS = %d\n", flags);
 
   if ( flags & __FLAG_COOR )
   {
 
-    //PRINTF(0)("SEND COOR: %f %f %f\n", this->relCoordinate.x, this->relCoordinate.y, this->relCoordinate.z);
+    PRINTF(0)("SEND COOR: %f %f %f\n", this->relCoordinate.x, this->relCoordinate.y, this->relCoordinate.z);
 
     SYNCHELP_WRITE_FLOAT( this->relCoordinate.x, NWT_PN_SCOORX );
@@ -1291,5 +1291,5 @@
   {
 
-    //PRINTF(0)("SEND QUAT: %f %f %f %f\n", this->absDirection.w, this->absDirection.v.x, this->absDirection.v.y, this->absDirection.v.z);
+    PRINTF(0)("SEND QUAT: %f %f %f %f\n", this->absDirection.w, this->absDirection.v.x, this->absDirection.v.y, this->absDirection.v.z);
 
     SYNCHELP_WRITE_FLOAT( this->absDirection.w, NWT_PN_SROTV );
@@ -1309,7 +1309,7 @@
 bool PNode::needsReadSync( )
 {
-  if ( fabs( coorx - relCoordinate.x ) > __OFFSET_POS ||
-       fabs( coory - relCoordinate.y ) > __OFFSET_POS ||
-       fabs( coorz - relCoordinate.z ) > __OFFSET_POS )
+  if ( fabs( coorx - relCoordinate.x ) > __OFFSET_POS*0.05*this->velocity.len() ||
+       fabs( coory - relCoordinate.y ) > __OFFSET_POS*0.05*this->velocity.len() ||
+       fabs( coorz - relCoordinate.z ) > __OFFSET_POS*0.05*this->velocity.len() )
     return true;
 
Index: trunk/src/lib/network/converter.cc
===================================================================
--- trunk/src/lib/network/converter.cc	(revision 6956)
+++ trunk/src/lib/network/converter.cc	(revision 6959)
@@ -90,5 +90,5 @@
  * @return: The number of written bytes
  */
-int Converter::intToByteArray(int x, byte* a, int length)
+int Converter::_intToByteArray(int x, byte* a, int length)
 {
   if (length < INTSIZE)
@@ -127,5 +127,5 @@
  * @return: The number of read bytes
  */
-int Converter::byteArrayToInt(const byte* a, int* x)
+int Converter::_byteArrayToInt(const byte* a, int* x)
 {
   int mult = 1;
@@ -146,4 +146,21 @@
     *x += a[INTSIZE - 1] * mult;
 
+  return INTSIZE;
+}
+
+int Converter::byteArrayToInt(const byte* a, int* x)
+{
+  memcpy( x, a, INTSIZE );
+  return INTSIZE;
+}
+
+int Converter::intToByteArray(int x, byte* a, int length)
+{
+  if ( length< INTSIZE )
+  {
+    PRINTF(1)("Byte Array to small\n");
+    return 0;
+  }
+  memcpy(a, &x, INTSIZE);
   return INTSIZE;
 }
Index: trunk/src/lib/network/converter.h
===================================================================
--- trunk/src/lib/network/converter.h	(revision 6956)
+++ trunk/src/lib/network/converter.h	(revision 6959)
@@ -30,4 +30,7 @@
     static int intToByteArray(int x, byte* a, int length);
     static int byteArrayToInt(const byte* a, int* x);
+    
+    static int _intToByteArray(int x, byte* a, int length);
+    static int _byteArrayToInt(const byte* a, int* x);
 
     static int stringToByteArray(const char* s, byte* a, int length, int maxLength);
Index: trunk/src/lib/network/network_game_manager.cc
===================================================================
--- trunk/src/lib/network/network_game_manager.cc	(revision 6956)
+++ trunk/src/lib/network/network_game_manager.cc	(revision 6959)
@@ -29,6 +29,7 @@
 #include "world_entity.h"
 #include "playable.h"
+#include "space_ships/space_ship.h"
 #include "player.h"
-#include "network_manager.h"
+#include "shared_network_data.h"
 
 #include "class_list.h"
@@ -541,5 +542,5 @@
     if ( b->isA(CL_WORLD_ENTITY) && !b->isA(CL_PLAYABLE) )
     {
-      if ( NetworkManager::getInstance()->getHostID()!=0 )
+      if ( SharedNetworkData::getInstance()->getHostID()!=0 )
       {
         static Vector pos = Vector(1000.0, 1000.0, 1000.0);
@@ -550,4 +551,20 @@
       }
     }
+    ///HACK this is only for network multiplayer games.
+    if( b->isA(CL_SPACE_SHIP))
+    {
+      SpaceShip* ss = dynamic_cast<SpaceShip*>(b);
+      if( owner%2 == 0)
+      {
+
+        ss->loadModel("models/ships/reap_#.obj");
+        ss->toList(OM_GROUP_00);
+      }
+      else
+      {
+        ss->loadModel( "models/ships/fighter.obj" );
+        ss->toList(OM_GROUP_01);
+      }
+    }
 
     return b;
@@ -576,4 +593,5 @@
     {
       assert((*it)->isA(CL_WORLD_ENTITY));
+      dynamic_cast<WorldEntity*>(*it)->leaveWorld();
       dynamic_cast<WorldEntity*>(*it)->toList(OM_DEAD);
       break;
@@ -895,4 +913,5 @@
   i += Converter::byteArrayToInt( &data[i], &uniqueID );
 
+  PRINTF(0)("handleRequestSync %d %d\n", uniqueID, sender);
   doRequestSync( uniqueID, sender );
 
@@ -980,4 +999,5 @@
 void NetworkGameManager::executeRequestSync( int uniqueID, int user )
 {
+  PRINTF(0)("executeRequestSync %d %d\n", uniqueID, user);
   if ( user >= outBuffer.size() )
     resizeBufferVector( user );
Index: trunk/src/lib/network/network_socket.cc
===================================================================
--- trunk/src/lib/network/network_socket.cc	(revision 6956)
+++ trunk/src/lib/network/network_socket.cc	(revision 6959)
@@ -172,5 +172,8 @@
 
   if (!tcpSocket || data==NULL || nbytes<=0)
-    return 0;
+  {
+    assert(_OUTGOING_BUFFER_SIZE - outgoingBufferLength > 0);
+    return 0;
+  }
 
   SDL_mutexP(outgoingBufferMutex);
@@ -324,5 +327,13 @@
 
 
+#ifdef DONTEXITTHREADS
+  while ( true )
+  {
+    SDL_Delay(1000);
+  }
+#endif
+  
   PRINTF(0)("QUIT READ THREAD\n");
+  
   return 0;
 }
@@ -392,7 +403,15 @@
   }
 
+#ifdef DONTEXITTHREADS
+  while ( true )
+  {
+  SDL_Delay(1000);
+  }
+#endif
 
   PRINTF(0)("QUIT WRITE THREAD\n");
+
   return 0;
+  
 }
 
@@ -426,4 +445,5 @@
   {
     PRINTF(1)("Buffersize is too small (%d) for packet (%d)\n", maxLength, blen);
+    assert(false);
     return 0;
   }
Index: trunk/src/lib/network/network_socket.h
===================================================================
--- trunk/src/lib/network/network_socket.h	(revision 6956)
+++ trunk/src/lib/network/network_socket.h	(revision 6959)
@@ -8,8 +8,11 @@
 #define _NETWORK_SOCKET
 
+//HACK else gdb will not work on server
+#define DONTEXITTHREADS
+
 //if you want to use outgoing buffer define _USE_OUTGOING_BUFFER
 #define _USE_OUTGOING_BUFFER
 
-#define _INCOMING_BUFFER_SIZE 10240
+#define _INCOMING_BUFFER_SIZE 2024000
 #define _OUTGOING_BUFFER_SIZE 2024000
 #define _LOCAL_BUFFER_SIZE 1024
Index: trunk/src/lib/network/network_stream.cc
===================================================================
--- trunk/src/lib/network/network_stream.cc	(revision 6956)
+++ trunk/src/lib/network/network_stream.cc	(revision 6959)
@@ -26,6 +26,6 @@
 #include "connection_monitor.h"
 #include "synchronizeable.h"
-#include "network_manager.h"
 #include "network_game_manager.h"
+#include "shared_network_data.h"
 
 #include "debug.h"
@@ -195,5 +195,5 @@
           {
             SharedNetworkData::getInstance()->setHostID( handshakes[i]->getHostId() );
-            myHostId = NetworkManager::getInstance()->getHostID();
+            myHostId = SharedNetworkData::getInstance()->getHostID();
 
             this->networkGameManager = NetworkGameManager::getInstance();
@@ -231,12 +231,24 @@
   int reciever;
   Header header;
+  int counter;
+
   for (SynchronizeableList::iterator it = synchronizeables.begin(); it!=synchronizeables.end(); it++)
   {
+    counter = 0;
+
     if ( (*it)!=NULL && (*it)->beSynchronized() /*&& (*it)->getOwner() == myHostId*/ )
     {
       do {
+        counter++;
+
+        //check for endless loop
+        if ( counter > 50 )
+        {
+          PRINTF(1)("there seems to be an error in readBytes of %s\n", (*it)->getClassName());
+          assert(false);
+        }
+
         reciever = 0;
         dataLength = (*it)->readBytes(downBuffer, DATA_STREAM_BUFFER_SIZE, &reciever);
-
 
         if ( dataLength<=0 ){
@@ -267,7 +279,7 @@
             for ( int i = 0; i<networkSockets.size(); i++)
             {
-              if ( i!=-reciever && networkSockets[i] != NULL )
+              if ( i!=abs(reciever) && networkSockets[i] != NULL )
               {
-                PRINTF(5)("write %d bytes to socket %d\n", dataLength, i);
+                PRINTF(0)("write %d bytes to socket %d uniqueid %d reciever %d\n", dataLength, i, (*it)->getUniqueID(), reciever);
                 networkSockets[i]->writePacket(downBuffer, dataLength);
               }
Index: trunk/src/lib/network/synchronizeable.h
===================================================================
--- trunk/src/lib/network/synchronizeable.h	(revision 6956)
+++ trunk/src/lib/network/synchronizeable.h	(revision 6959)
@@ -34,10 +34,14 @@
   NWT_SS_VELZ,
   NWT_SS_PL_SYNC,
-  
+  NWT_SS_CO_N,
+  NWT_SS_CO_CLID,
+
   NWT_HS_HOST_ID,
   NWT_HS_NGM_ID,
-  
+
+  NWT_PL_B,
   NWT_PL_FLAGS,
-  
+  NWT_PL_SCORE,
+
   NWT_PN_BO_WRITESTATE,
   NWT_PN_PARENTMODE,
@@ -49,5 +53,5 @@
   NWT_PN_ROTZ,
   NWT_PN_ROTV,
-  
+
   NWT_PN_FLAGS,
   NWT_PN_SCOORX,
@@ -58,27 +62,27 @@
   NWT_PN_SROTZ,
   NWT_PN_SROTV,
-  
+
   NWT_BO_NAME,
-  
+
   NWT_WE_PN_WRITESTATE,
   NWT_WE_PN_MODELFILENAME,
   NWT_WE_PN_SCALING,
-  
+
   NWT_GT_WE_STATE,
-  
+
   NWT_SB_WE_STATE,
   NWT_SB_SIZE,
   NWT_SB_TEXTURENAME,
-  
+
   NWT_TER_WE_STATE,
-  
+
   NWT_PU_WE_STATE,
-  
+
   NWT_TPU_WE_STATE,
-  
+
   NWT_LPU_WE_STATE,
-  
+
   NWT_WPU_WE_STATE,
-  
+
   NWT_PPU_WE_STATE,
   NWT_PPU_TYPE,
@@ -133,5 +137,5 @@
  *  delete[] textureName;
  *  textureName = NULL;
- *  SYNCHELP_READ_STRINGM( texturename );      //this will call new char[strlen()+1] 
+ *  SYNCHELP_READ_STRINGM( texturename );      //this will call new char[strlen()+1]
  *
  * Example 2:
@@ -142,5 +146,5 @@
  *
  */
- 
+
 #define SYNCHELP_WRITE_DEBUG(n) {\
   __synchelp_write_n = Converter::intToByteArray( n, data+__synchelp_write_i, maxLength-__synchelp_write_i ); \
