Index: branches/network_merged/src/defs/class_id.h
===================================================================
--- branches/network_merged/src/defs/class_id.h	(revision 6339)
+++ branches/network_merged/src/defs/class_id.h	(revision 6340)
@@ -253,5 +253,5 @@
   CL_CONNECTION_MONITOR         =    0x00000b05,
   CL_HANDSHAKE                  =    0x00000b06,
-  CL_ENTITY_MANAGER             =    0x00000b07,
+  CL_NETWORK_GAME_MANAGER       =    0x00000b07,
 
 
Index: branches/network_merged/src/lib/coord/p_node.cc
===================================================================
--- branches/network_merged/src/lib/coord/p_node.cc	(revision 6339)
+++ branches/network_merged/src/lib/coord/p_node.cc	(revision 6340)
@@ -27,4 +27,6 @@
 #include "glincl.h"
 #include "color.h"
+
+#include "synchronizeable.h"
 
 using namespace std;
@@ -1007,2 +1009,134 @@
     return (PNODE_ROTATE_AND_MOVE);
 }
+
+/**
+ * Writes data from network containing information about the state
+ * @param data pointer to data
+ * @param length length of data
+ * @param sender hostID of sender
+ */
+int PNode::writeState( const byte * data, int length, int sender )
+{
+  SYNCHELP_READ_BEGIN();
+
+  SYNCHELP_READ_FKT( BaseObject::writeState );
+
+  PRINTF(0)("name = %s\n", this->getName());
+
+  char * parentName = NULL;
+  SYNCHELP_READ_STRINGM( parentName );
+
+  if ( strcmp(parentName, "")==0 )
+  {
+    setParent( (char*)NULL );
+  }
+  else
+  {
+    setParent( parentName );
+  }
+
+  delete[] parentName;
+
+  int parentMode;
+  SYNCHELP_READ_INT( parentMode );
+  this->setParentMode((PARENT_MODE)parentMode);
+
+  float f1, f2, f3, f4;
+
+  SYNCHELP_READ_FLOAT( f1 );
+  SYNCHELP_READ_FLOAT( f2 );
+  SYNCHELP_READ_FLOAT( f3 );
+  this->setRelCoor( f1, f2, f3 );
+  //this->setRelCoor( 10, 0, 0 );
+
+  SYNCHELP_READ_FLOAT( f1 );
+  SYNCHELP_READ_FLOAT( f2 );
+  SYNCHELP_READ_FLOAT( f3 );
+  //this->setAbsCoor( f1, f2, f3 );
+
+  SYNCHELP_READ_FLOAT( f1 );
+  SYNCHELP_READ_FLOAT( f2 );
+  SYNCHELP_READ_FLOAT( f3 );
+  SYNCHELP_READ_FLOAT( f4 );
+  this->setRelDir( Quaternion( Vector(f2, f3, f4), f1 ) );
+
+  SYNCHELP_READ_FLOAT( f1 );
+  SYNCHELP_READ_FLOAT( f2 );
+  SYNCHELP_READ_FLOAT( f3 );
+  SYNCHELP_READ_FLOAT( f4 );
+  //this->setAbsDir( Quaternion( Vector(f2, f3, f4), f1 ) );
+
+  int n;
+  char * childName;
+
+  SYNCHELP_READ_INT( n );
+
+  for (int i = 0; i<n; i++)
+  {
+    SYNCHELP_READ_STRINGM( childName );
+    PRINTF(0)("childname = %s\n", childName);
+    addChild( childName );
+    delete childName;
+    childName = NULL;
+  }
+
+  return SYNCHELP_READ_N;
+}
+
+/**
+ * data copied in data will bee sent to another host
+ * @param data pointer to data
+ * @param maxLength max length of data
+ * @return the number of bytes writen
+ */
+int PNode::readState( byte * data, int maxLength )
+{
+  SYNCHELP_WRITE_BEGIN();
+
+  SYNCHELP_WRITE_FKT( BaseObject::readState );
+
+  PRINTF(0)("name = %s\n", this->getName());
+
+  if ( this->parent )
+  {
+    SYNCHELP_WRITE_STRING( parent->getName() );
+  }
+  else
+  {
+    SYNCHELP_WRITE_STRING( "" );
+  }
+
+  SYNCHELP_WRITE_INT( this->parentMode );
+
+  SYNCHELP_WRITE_FLOAT( this->relCoordinate.x );
+  SYNCHELP_WRITE_FLOAT( this->relCoordinate.y );
+  SYNCHELP_WRITE_FLOAT( this->relCoordinate.z );
+
+  PRINTF(0)("%s, %f, %f, %f\n", getClassName(), relCoordinate.x, relCoordinate.y, relCoordinate.z);
+
+  SYNCHELP_WRITE_FLOAT( this->absCoordinate.x );
+  SYNCHELP_WRITE_FLOAT( this->absCoordinate.y );
+  SYNCHELP_WRITE_FLOAT( this->absCoordinate.z );
+
+  PRINTF(0)("%s, %f, %f, %f\n", getClassName(), absCoordinate.x, absCoordinate.y, absCoordinate.z);
+
+  SYNCHELP_WRITE_FLOAT( this->relDirection.w );
+  SYNCHELP_WRITE_FLOAT( this->relDirection.v.x );
+  SYNCHELP_WRITE_FLOAT( this->relDirection.v.y );
+  SYNCHELP_WRITE_FLOAT( this->relDirection.v.z );
+
+  SYNCHELP_WRITE_FLOAT( this->absDirection.w );
+  SYNCHELP_WRITE_FLOAT( this->absDirection.v.x );
+  SYNCHELP_WRITE_FLOAT( this->absDirection.v.y );
+  SYNCHELP_WRITE_FLOAT( this->absDirection.v.z );
+
+  int n = children.size();
+  SYNCHELP_WRITE_INT( n );
+
+  for (std::list<PNode*>::const_iterator it = children.begin(); it!=children.end(); it++)
+  {
+    PRINTF(0)("childname = %s\n", (*it)->getName() );
+    SYNCHELP_WRITE_STRING( (*it)->getName() );
+  }
+  return SYNCHELP_WRITE_N;
+}
Index: branches/network_merged/src/lib/coord/p_node.h
===================================================================
--- branches/network_merged/src/lib/coord/p_node.h	(revision 6339)
+++ branches/network_merged/src/lib/coord/p_node.h	(revision 6340)
@@ -20,4 +20,5 @@
 
 #include "base_object.h"
+#include "stdincl.h"
 
 #include "vector.h"
@@ -178,4 +179,6 @@
   static PARENT_MODE charToParentingMode(const char* parentingMode);
 
+  int       writeState(const byte* data, int length, int sender);
+  int       readState(byte* data, int maxLength );
 
  private:
Index: branches/network_merged/src/lib/lang/base_object.cc
===================================================================
--- branches/network_merged/src/lib/lang/base_object.cc	(revision 6339)
+++ branches/network_merged/src/lib/lang/base_object.cc	(revision 6340)
@@ -22,4 +22,6 @@
 #include "compiler.h"
 #include "class_list.h"
+
+#include "synchronizeable.h"
 
 using namespace std;
@@ -180,2 +182,37 @@
 
 }
+
+/**
+ * Writes data from network containing information about the state
+ * @param data pointer to data
+ * @param length length of data
+ * @param sender hostID of sender
+ */
+int BaseObject::writeState( const byte * data, int length, int sender )
+{
+  SYNCHELP_READ_BEGIN();
+
+  if ( objectName )
+  {
+    delete[] objectName;
+    objectName = NULL;
+  }
+  SYNCHELP_READ_STRINGM( this->objectName );
+
+  return SYNCHELP_READ_N;
+}
+
+/**
+ * data copied in data will bee sent to another host
+ * @param data pointer to data
+ * @param maxLength max length of data
+ * @return the number of bytes writen
+ */
+int BaseObject::readState( byte * data, int maxLength )
+{
+  SYNCHELP_WRITE_BEGIN();
+
+  SYNCHELP_WRITE_STRING( this->objectName );
+
+  return SYNCHELP_WRITE_N;
+}
Index: branches/network_merged/src/lib/lang/base_object.h
===================================================================
--- branches/network_merged/src/lib/lang/base_object.h	(revision 6339)
+++ branches/network_merged/src/lib/lang/base_object.h	(revision 6340)
@@ -15,4 +15,6 @@
 #define NULL     0    //!< NULL
 #endif
+
+#include "stdincl.h"
 
 class TiXmlElement;
@@ -45,4 +47,6 @@
   bool operator==(ClassID classID) { return this->isA(classID); };
 
+  int       writeState(const byte* data, int length, int sender);
+  int       readState(byte* data, int maxLength );
  protected:
   void setClassID(ClassID classID, const char* className);
Index: branches/network_merged/src/lib/network/converter.cc
===================================================================
--- branches/network_merged/src/lib/network/converter.cc	(revision 6339)
+++ branches/network_merged/src/lib/network/converter.cc	(revision 6340)
@@ -54,6 +54,6 @@
 {
   const int mod = 256; // = 2^8
-  
-  
+
+
   byte* result = new byte[INTSIZE];
   int sgn;
@@ -65,5 +65,5 @@
     x = -x;
   }
-  
+
   for (int i = 0; i < INTSIZE; i++)
   {
@@ -71,10 +71,47 @@
     x /= mod;
   }
-  
+
   if (sgn == -1)
     result[INTSIZE - 1] += sgnadd;
-  
-  
-  return result;
+
+
+  return result;
+}
+
+/*!
+ * Converts an int into a byte-array and stores the result into a given byte-array
+ * @remarks: The int is stored in big-endian
+ * @param x: The int which is to convert
+ * @return: A byte-array that accords the given int value
+ */
+int Converter::intToByteArray(int x, byte* a, int length)
+{
+  if (length < INTSIZE)
+  {
+    PRINTF(1)("byte buffer to short to store an int. Needed length %i. Avaiable length %i", INTSIZE, length);
+    return -1;
+  }
+
+  const int mod = 256; // = 2^8
+
+  int sgn;
+  if (x >= 0)
+    sgn = 1;
+  else
+  {
+    sgn = -1;
+    x = -x;
+  }
+
+  for (int i = 0; i < INTSIZE; i++)
+  {
+    a[i] = x % mod;
+    x /= mod;
+  }
+
+  if (sgn == -1)
+    a[INTSIZE - 1] += sgnadd;
+
+  return INTSIZE;
 }
 
@@ -84,72 +121,46 @@
  * @return: An int that accords the given byte-array
  */
-int Converter::byteArrayToInt(byte* a)
+int Converter::byteArrayToInt(const byte* a, int* x)
 {
   int mult = 1;
   const int step = 256; // = 2 ^ 8
-  int result = 0;
+  *x = 0;
   for (int i = 0; i < INTSIZE - 1; i++)
   {
-    result += a[i] * mult;
+    *x += a[i] * mult;
     mult *= step;
   }
-  
-  printf("tara: %i", result);
-  
+
   if (a[INTSIZE - 1] >= sgnadd)
   {
-    result += (a[INTSIZE - 1] - sgnadd) * mult;
-    result *= -1;
-  }
-  else
-    result += a[INTSIZE - 1] * mult;
-  
-  return result;
-}
-
-/*char* Converter::floatToBinString(float x)
+    *x += (a[INTSIZE - 1] - sgnadd) * mult;
+    *x *= -1;
+  }
+  else
+    *x += a[INTSIZE - 1] * mult;
+
+  return INTSIZE;
+}
+
+/*!
+ * Converts a float into a string containing its binary representation
+ */
+char* Converter::floatToBinString(float x)
 {
   char* result = new char[200];
   int pos = 0;
-  
-  int h = (int)x;
-  if (h > x)
-    h--;
-  x -= h;
-  
-  
-  while (h > 0 && pos < 200)
-  {
-    //printf("%i ", pos);
-    
-    if (h % 2 == 1)
-    {
-      result[pos] = '1';
-      h -= 1;
-    }
-    else
-      result[pos] = '0';
-    pos++;
-    h /= 2;
-  }
-  
-  //printf("x = %f\n", x);
-  
-  
-  //invert
-  for (int i = 0; i < pos / 2; i++)
-  {
-    char temp = result[i];
-    result[i] = result[pos - 1 - i];
-    result[pos - 1 - i] = temp;
-  }
-  
-  
-  result[pos++] = '.';
-  float sub = 0.5;
-  while (x > 0 && pos < 200)
-  {
-    //printf("%i ", pos);
-    
+
+  if (x < 0)
+  {
+    result[pos++] = '-';
+    x = -x;
+  }
+
+  float sub = 1;
+  while (sub < x)
+    sub *= 2;
+
+  while ((x > 0 || sub >= 1) && pos < 200)
+  {
     if (x >= sub)
     {
@@ -161,54 +172,334 @@
     pos++;
     sub /= 2;
-  }
-  
-  
-  return result;
-}*/
-
-char* Converter::floatToBinString(float x)
-{
-  char* result = new char[200];
-  int pos = 0;
-  
+
+    if (sub == 0.5f)
+      result[pos++] = '.';
+  }
+
+  return result;
+}
+
+const int expmult = 8388608; //2^23
+
+/*!
+ * Converts a float value into a byte-array
+ * @param x: The float which is to convert
+ * @return: A byte-array which accords the given float
+ */
+byte* Converter::floatToByteArray(float x)
+{
+  int mantisse = 0;
+  int exponent = 128;
+
+  int sgn;
+  if (x < 0)
+  {
+    x = -x;
+    sgn = -1;
+  }
+  else
+    sgn = 1;
+
   float sub = 1;
   while (sub < x)
+  {
     sub *= 2;
-  
-  //printf("sub = %f\n", sub);
-  
-  //while (sub >= 1 && pos < 200)
-  while ((x > 0 || sub >= 1) && pos < 200)
+    exponent++;
+  }
+
+  while (x > 0)
   {
     if (x >= sub)
     {
-      result[pos] = '1';
+      mantisse += 1;
       x -= sub;
     }
-    else
-      result[pos] = '0';
-    pos++;
+
+    mantisse *= 2;
+    exponent--;
     sub /= 2;
-    
-    if (sub == 0.5f)
-      result[pos++] = '.';
-  }
-  
-  /*result[pos++] = '.';
-  sub = 0.5;
-  while (x > 0 && pos < 200)
+  }
+  exponent++;
+  mantisse /= 2;
+  while (mantisse < expmult)
+  {
+    mantisse *= 2;
+    exponent--;
+  }
+
+  //printf("mantisse = %i exponent = %i \n", mantisse, exponent);
+
+  mantisse -= expmult;
+
+  int hx = mantisse + expmult * exponent;
+  byte* result = intToByteArray(hx);
+  if (sgn == -1)
+    result[3] += sgnadd;
+
+  return result;
+}
+
+
+/*!
+ * Converts a byte-array into a float value
+ * @param a: The byte-array which is to convert
+ * @return: A float value which accords the given byte-array
+ */
+float Converter::byteArrayToFloat(byte* a)
+{
+  int hmant = a[0] + a[1] * 256 + a[2] * 65536;
+  int mantisse = hmant % expmult;
+  mantisse += expmult;
+
+  int hexp = a[2] + a[3] * 256;
+  int exponent = (hexp / 128) % 256 - 128;
+
+  int sgn;
+  if (a[3] >= sgnadd)
+    sgn = -1;
+  else
+    sgn = 1;
+
+  //printf("mantisse = %i exponent = %i \n", mantisse, exponent);
+
+  float emult = 1;
+  if (exponent > 0)
+    for (int i = 0; i < exponent; i++)
+      emult *= 2;
+  else if (exponent < 0)
+    for (int i = 0; i > exponent; i--)
+      emult /= 2;
+
+  float result = mantisse * emult;
+  if (sgn == -1)
+    result = -result;
+
+  return result;
+}
+
+/*!
+ * Converts a float value into a byte-array
+ * @param x: The float which is to convert
+ * @return: A byte-array which accords the given float
+ */
+byte* Converter::_floatToByteArray(float x)
+{
+  byte* p = (byte*)&x;
+  byte* result = new byte[4];
+  for (int i = 0; i < 4; i++)
+    result[i] = p[i];
+  return result;
+}
+
+
+/*!
+ * Converts a byte-array into a float value
+ * @param a: The byte-array which is to convert
+ * @return: A float value which accords the given byte-array
+ */
+float Converter::_byteArrayToFloat(byte* a)
+{
+  float* p = (float*)a;
+  float result = *p;
+  return result;
+}
+
+/*!
+ * Converts a float value into a byte-array and stores the result into a given byte-array
+ * @param x: The float which is to convert
+ * @return: A byte-array which accords the given float
+ */
+int Converter::floatToByteArray(float x, byte* a, int length)
+{
+  if (length < FLOATSIZE)
+  {
+    PRINTF(1)("byte buffer to short to store a float. Needed length %i. Avaiable length %i", FLOATSIZE, length);
+    return -1;
+  }
+
+  //handle 0 else function will loop for ever
+  if ( x == 0 )
+  {
+    for ( int i = 0; i<FLOATSIZE; i++)
+      a[i] = 0;
+    return FLOATSIZE;
+  }
+
+  int mantisse = 0;
+  int exponent = 128;
+
+  int sgn;
+  if (x < 0)
+  {
+    x = -x;
+    sgn = -1;
+  }
+  else
+    sgn = 1;
+
+  float sub = 1;
+  while (sub < x)
+  {
+    sub *= 2;
+    exponent++;
+  }
+
+  while (x > 0)
   {
     if (x >= sub)
     {
-      result[pos] = '1';
+      mantisse += 1;
       x -= sub;
     }
-    else
-      result[pos] = '0';
-    pos++;
+
+    mantisse *= 2;
+    exponent--;
     sub /= 2;
   }
-  */
-  
-  return result;
-}
+  exponent++;
+  mantisse /= 2;
+  while (mantisse < expmult)
+  {
+    mantisse *= 2;
+    exponent--;
+  }
+
+  //printf("mantisse = %i exponent = %i \n", mantisse, exponent);
+
+  mantisse -= expmult;
+
+  int hx = mantisse + expmult * exponent;
+  int result = intToByteArray(hx, a, length);
+  if (sgn == -1)
+    a[3] += sgnadd;
+
+  return result;
+}
+
+
+/*!
+ * Converts a byte-array into a float value
+ * @param a: The byte-array which is to convert
+ * @return: A float value which accords the given byte-array
+ */
+int Converter::byteArrayToFloat(const byte* a, float* x)
+{
+  //handle 0
+  for (int i = 0; i<FLOATSIZE; i++)
+  {
+    if (a[i]!=0)
+      break;
+    if ( i==FLOATSIZE-1 )
+    {
+      *x = 0.0f;
+      return FLOATSIZE;
+    }
+  }
+
+
+  int hmant = a[0] + a[1] * 256 + a[2] * 65536;
+  int mantisse = hmant % expmult;
+  mantisse += expmult;
+
+  int hexp = a[2] + a[3] * 256;
+  int exponent = (hexp / 128) % 256 - 128;
+
+  int sgn;
+  if (a[3] >= sgnadd)
+    sgn = -1;
+  else
+    sgn = 1;
+
+  //printf("mantisse = %i exponent = %i \n", mantisse, exponent);
+
+  float emult = 1;
+  if (exponent > 0)
+    for (int i = 0; i < exponent; i++)
+      emult *= 2;
+  else if (exponent < 0)
+    for (int i = 0; i > exponent; i--)
+      emult /= 2;
+
+  *x = mantisse * emult;
+  if (sgn == -1)
+    *x = -  *x;
+
+  return FLOATSIZE;
+}
+
+/**
+ * copies a strint to a byte array
+ * @param s: string to copy
+ * @param a: byte array
+ * @param length: string length
+ * @return: the used number of bytes in byte array
+ */
+int Converter::stringToByteArray( const char * s, byte * a, int length, int maxLength )
+{
+  if ( length+INTSIZE > maxLength )
+  {
+    PRINTF(1)("Byte array is too small (%d) to store %d bytes\n", maxLength, length+INTSIZE);
+    return -1;
+  }
+
+  int n = Converter::intToByteArray( length, a, maxLength );
+
+  memcpy( a+INTSIZE, s, length );
+
+  return length + INTSIZE;
+}
+
+/**
+ * reads a string out of a byte array
+ * @param a: byte array
+ * @param s: string
+ * @param maxLength: max bytes to copy
+ * @return: the number of read bytes in byte array
+ */
+int Converter::byteArrayToString( const byte * a, char * s, int maxLength )
+{
+  int length;
+
+  int n = Converter::byteArrayToInt( a, &length );
+
+
+  if ( length+1 > maxLength )
+  {
+    PRINTF(1)("There is not enough space in string (%d) to store %d bytes\n", maxLength, length+1 );
+    strncpy(s,"",maxLength);
+    return -1;
+  }
+
+  memcpy( s, a+n, length );
+  s[length] = '\0';
+
+  return n+length;
+}
+
+/**
+ * reads a string out of a byte array and allocates memory for string
+ * @param a: byte array
+ * @param s: string
+ * @param maxLength: max bytes to copy
+ * @return: the number of read bytes in byte array
+ */
+int Converter::byteArrayToStringM( const byte * a, char*& s )
+{
+  int length;
+
+  int n = Converter::byteArrayToInt( a, &length );
+
+  s = new char[length+1];
+
+  if ( !s )
+  {
+    PRINTF(1)("Could not allocate memory!\n" );
+    return -1;
+  }
+
+  memcpy( s, a+n, length );
+  s[length] = '\0';
+
+  return n+length;
+}
+
Index: branches/network_merged/src/lib/network/converter.h
===================================================================
--- branches/network_merged/src/lib/network/converter.h	(revision 6339)
+++ branches/network_merged/src/lib/network/converter.h	(revision 6340)
@@ -3,5 +3,5 @@
  *  Is able to convert int to byte-array and vice versa
  */
- 
+
 #ifndef _CONVERTER
 #define _CONVERTER
@@ -15,4 +15,6 @@
 /* The size of an int in byte */
 #define INTSIZE 4
+/* The size of a float in byte */
+#define FLOATSIZE 4
 
 /*!
@@ -23,12 +25,24 @@
   public:
     static byte* intToByteArray(int x);
-    static int byteArrayToInt(byte* a);
-    
-    //byte* floatToByteArray(float x);
-    //float byteArrayToFloat(byte[] a);
-    
+    static int byteArrayToInt(const byte* a);
+
+    static int intToByteArray(int x, byte* a, int length);
+    static int byteArrayToInt(const byte* a, int* x);
+
+    static int floatToByteArray(float x, byte* a, int length);
+    static int byteArrayToFloat(const byte* a, float* x);
+
+    static int stringToByteArray(const char* s, byte* a, int length, int maxLength);
+    static int byteArrayToString(const byte* a, char* s, int maxLength);
+    static int byteArrayToStringM(const byte* a, char*& s );
+
     //Test
     static char* floatToBinString(float x);
-    
+
+    static byte* floatToByteArray(float x);
+    static float byteArrayToFloat(byte* a);
+
+    static byte* _floatToByteArray(float x);
+    static float _byteArrayToFloat(byte* a);
   private:
     Converter();
Index: branches/network_merged/src/lib/network/data_stream.h
===================================================================
--- branches/network_merged/src/lib/network/data_stream.h	(revision 6339)
+++ branches/network_merged/src/lib/network/data_stream.h	(revision 6340)
@@ -13,5 +13,5 @@
 #include "netdefs.h"
 
-#define DATA_STREAM_BUFFER_SIZE 1024
+#define DATA_STREAM_BUFFER_SIZE 10240
 
 class DataStream : public BaseObject
Index: branches/network_merged/src/lib/network/handshake.cc
===================================================================
--- branches/network_merged/src/lib/network/handshake.cc	(revision 6339)
+++ branches/network_merged/src/lib/network/handshake.cc	(revision 6340)
@@ -37,10 +37,12 @@
 }
 
-void Handshake::writeBytes( const byte * data, int length )
+int 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);
 
+  SYNCHELP_READ_BEGIN();
+
   if ( hasState( HS_COMPLETED ) )
-       return;
+       return 0;
 
   if ( !hasState( HS_RECVD_INIT ) )
@@ -50,5 +52,5 @@
       PRINTF(0)("initial packet has wrong size %d instead of %d\n", length, _INITIAL_DATA_LENGTH);
       setState( HS_COMPLETED );
-      return;
+      return 0;
     }
 
@@ -57,10 +59,10 @@
       PRINTF(0)("initial packed does not match\n");
       setState( HS_COMPLETED );
-      return;
+      return length;
     }
 
     setState( HS_RECVD_INIT );
     PRINTF(0)("got valid initial packet from client %d\n", clientId);
-    return;
+    return length;
   }
 
@@ -71,5 +73,5 @@
       PRINTF(0)("version number packet has wrong size %d instead of %d\n", length, _ORXONOX_VERSION_LENGTH);
       setState( HS_COMPLETED );
-      return;
+      return 0;
     }
 
@@ -78,5 +80,5 @@
       PRINTF(0)("versions do not match\n");
       setState( HS_COMPLETED );
-      return;
+      return length;
     }
 
@@ -84,14 +86,14 @@
 
     PRINTF(0)("client %d's version does match\n", clientId);
-    return;
+    return length;
   }
 
   if ( !isServer() && hasState( HS_RECVD_VER ) && !hasState( HS_RECVD_HID ) )
   {
-    if ( length != 2 )
+    if ( length != INTSIZE+INTSIZE )
     {
       PRINTF(0)("hostID packet has wrong size %d instead of %d\n", length, 1);
       setState( HS_COMPLETED );
-      return;
+      return 0;
     }
 
@@ -99,6 +101,6 @@
     setState( HS_RECVD_HID );
     this->isOk = true;
-    this->newHostId = data[0];
-    this->newNetworkGameManagerId = data[1];
+    SYNCHELP_READ_INT( this->newHostId );
+    SYNCHELP_READ_INT( this->newNetworkGameManagerId );
 
     if ( newHostId == 0 )
@@ -112,5 +114,5 @@
       PRINTF(0)("got my hostID: %d and networkGameManagerId: %d\n", newHostId, newNetworkGameManagerId);
     }
-    return;
+    return SYNCHELP_READ_N;
   }
 
@@ -120,4 +122,6 @@
 {
   PRINTF(5)("Handshake::readBytes states = %d %d %d %d (%d)\n", hasState( HS_SENT_INIT ), hasState( HS_SENT_VER ), hasState( HS_SENT_HID ), hasState( HS_COMPLETED ), state);
+
+  SYNCHELP_WRITE_BEGIN();
 
   if ( hasState( HS_COMPLETED ) )
@@ -172,5 +176,6 @@
       isOk = false;
       //memcpy(data, (byte*)0, 4);
-      data[0] = 0;
+      SYNCHELP_WRITE_INT( 0 );
+      SYNCHELP_WRITE_INT( 0 );
     }
     else
@@ -178,9 +183,9 @@
       isOk = true;
       //memcpy(data, &clientId, 4);
-      data[0] = (byte)clientId;
-      data[1] = (byte)networkGameManagerId;
+      SYNCHELP_WRITE_INT( clientId );
+      SYNCHELP_WRITE_INT( networkGameManagerId );
     }
     *reciever = clientId;
-    return 2;
+    return SYNCHELP_WRITE_N;
   }
 
Index: branches/network_merged/src/lib/network/handshake.h
===================================================================
--- branches/network_merged/src/lib/network/handshake.h	(revision 6339)
+++ branches/network_merged/src/lib/network/handshake.h	(revision 6340)
@@ -42,5 +42,5 @@
     inline void       doReject(){ setState(HS_DO_REJECT); }
 
-    virtual void      writeBytes(const byte* data, int length);
+    virtual int       writeBytes(const byte* data, int length, int sender);
     virtual int       readBytes(byte* data, int maxLength, int * reciever);
     virtual void      writeDebug() const;
Index: branches/network_merged/src/lib/network/network_game_manager.cc
===================================================================
--- branches/network_merged/src/lib/network/network_game_manager.cc	(revision 6339)
+++ branches/network_merged/src/lib/network/network_game_manager.cc	(revision 6340)
@@ -20,4 +20,8 @@
 #define DEBUG_MODULE_NETWORK
 
+#include "factory.h"
+#include "network_stream.h"
+#include "converter.h"
+
 /* include your own header */
 #include "network_game_manager.h"
@@ -27,4 +31,6 @@
 using namespace std;
 
+NetworkGameManager* NetworkGameManager::singletonRef = NULL;
+
 /*!
  * Standard constructor
@@ -32,6 +38,18 @@
 NetworkGameManager::NetworkGameManager()
 {
+  PRINTF(0)("START\n");
+
   /* set the class id for the base object */
-  this->setClassID(CL_ENTITY_MANAGER, "EntityManager");
+  this->setClassID(CL_NETWORK_GAME_MANAGER, "NetworkGameManager");
+
+  allOutBuffer.length = 0;
+
+  allOutBuffer.maxLength = 10*1024;
+
+  allOutBuffer.buffer = new byte[10*1024];
+
+  newUniqueID = MAX_CONNECTIONS + 2;
+
+  hasRequestedWorld = false;
 }
 
@@ -41,13 +59,142 @@
 NetworkGameManager::~NetworkGameManager()
 {
-}
-
-
-void NetworkGameManager::writeBytes(const byte* data, int length)
-{
+  for ( int i = 0; i<outBuffer.size(); i++)
+  {
+    if ( outBuffer[i].buffer )
+      delete outBuffer[i].buffer;
+  }
+
+  if ( allOutBuffer.buffer )
+    delete allOutBuffer.buffer;
+}
+
+
+int NetworkGameManager::writeBytes(const byte* data, int length, int sender)
+{
+  int i = 0;
+  byte b;
+
+  while ( i<length )
+  {
+    b = data[i++];
+
+    PRINTF(0)("WriteBytes: b = %d\n", b);
+
+    if ( isServer() )
+    {
+      if ( b == REQUEST_CREATE )
+      {
+        if ( !handleRequestCreate( i, data, length, sender ) )
+          return i;
+        continue;
+      }
+      if ( b == REQUEST_REMOVE )
+      {
+        if ( !handleRequestRemove( i, data, length, sender ) )
+          return i;
+        continue;
+      }
+    }
+    else
+    {
+      if ( b == CREATE_ENTITY )
+      {
+        if ( !handleCreateEntity( i, data, length, sender ) )
+          return i;
+        continue;
+      }
+      if ( b == REMOVE_ENTITY )
+      {
+        if ( !handleRemoveEntity( i, data, length, sender ) )
+          return i;
+        continue;
+      }
+      if ( b == CREATE_ENTITY_LIST )
+      {
+        if ( !handleCreateEntityList( i, data, length, sender ) )
+          return i;
+        continue;
+      }
+      if ( b == REMOVE_ENTITY_LIST )
+      {
+        if ( !handleRemoveEntityList( i, data, length, sender ) )
+          return i;
+        continue;
+      }
+      if ( b == YOU_ARE_ENTITY )
+      {
+        if ( !handleYouAreEntity( i, data, length, sender ) )
+          return i;
+        continue;
+      }
+    }
+
+    if ( b == REQUEST_SYNC )
+    {
+      if ( !handleRequestSync( i, data, length, sender ) )
+        return i;
+      continue;
+    }
+
+    if ( b == REQUEST_ENTITY_LIST )
+    {
+      PRINTF(0)("sending THE list\n");
+      sendEntityList( sender );
+      continue;
+    }
+
+    //if we get her something with data is wrong
+    PRINTF(1)("Data is not in the right format! i=%d\n", i);
+    return i;
+  }
+
+  return i;
 }
 
 int NetworkGameManager::readBytes(byte* data, int maxLength, int * reciever)
 {
+  if ( !isServer() && !hasRequestedWorld )
+  {
+    SYNCHELP_WRITE_BEGIN();
+    byte b = REQUEST_ENTITY_LIST;
+    SYNCHELP_WRITE_BYTE( b );
+    hasRequestedWorld = true;
+    PRINTF(0)("the world is enough! id=%d\n", this->getUniqueID());
+    return SYNCHELP_WRITE_N;
+  }
+  for ( int i = 0; i<outBuffer.size(); i++ )
+  {
+    *reciever = i;
+    if ( outBuffer[i].length>0 )
+    {
+      int nbytes = outBuffer[i].length;
+      outBuffer[i].length = 0;
+
+      if ( nbytes > maxLength )
+      {
+        PRINTF(1)("OutBuffer.length (%d) > (%d) networkStreamBuffer.maxLength\n", nbytes, maxLength);
+        return 0;
+      }
+
+      memcpy(data, outBuffer[i].buffer, nbytes);
+      return nbytes;
+    }
+  }
+
+  *reciever = 0;
+  int nbytes = allOutBuffer.length;
+  allOutBuffer.length = 0;
+
+  if ( nbytes <=0 )
+    return 0;
+
+  if ( nbytes > maxLength )
+  {
+    PRINTF(1)("OutBuffer.length (%d) > (%d) networkStreamBuffer.length\n", nbytes, maxLength);
+    return 0;
+  }
+
+  memcpy( data, allOutBuffer.buffer, nbytes );
+  return nbytes;
 }
 
@@ -63,10 +210,72 @@
 /*!
  * Checks whether this is connected to a server or a client
- * and afterwards creates the needed entity if possible
+ * and afterwards creates the needed entity
  * @param classID: The ID of the class of which an entity should be created
  */
-void NetworkGameManager::createEntity(int classID)
-{
-}
+void NetworkGameManager::createEntity( ClassID classID, int owner )
+{
+  if ( this->isServer() )
+  {
+    if ( newUniqueID < 0 )
+    {
+      PRINTF(1)("Cannot create entity! There are no more uniqueIDs left!\n");
+      return;
+    }
+
+    this->executeCreateEntity( classID, newUniqueID++, owner );
+  }
+  else
+  {
+    this->requestCreateEntity( classID );
+  }
+}
+
+
+/*!
+ * Checks whether this is connected to a server or a client
+ * and afterwards creates the needed entity
+ * @param classID: The ID of the class of which an entity should be created
+ */
+BaseObject* NetworkGameManager::createEntity( TiXmlElement* element)
+{
+  if ( this->isServer() )
+  {
+    if ( newUniqueID < 0 )
+    {
+      PRINTF(1)("Cannot create entity! There are no more uniqueIDs left!\n");
+      return NULL;
+    }
+    newUniqueID++;
+
+    BaseObject * b = Factory::fabricate( element );
+
+    if ( !b )
+    {
+      PRINTF(1)("Could not fabricate Object with classID %x\n", element->Value() );
+      return NULL;
+    }
+
+
+    if ( b->isA(CL_SYNCHRONIZEABLE) )
+    {
+      Synchronizeable * s = dynamic_cast<Synchronizeable*>(b);
+      s->setUniqueID( newUniqueID );
+      s->setOwner( 0 );
+      this->networkStream->connectSynchronizeable( *s );
+      return b;
+    }
+    else
+    {
+      PRINTF(1)("Class %s is not a synchronizeable!\n", b->getClassName() );
+      delete b;
+    }
+  }
+  else
+  {
+    PRINTF(1)("This node is not a server and cannot create id %x\n", element->Value());
+  }
+  return NULL;
+}
+
 
 /*!
@@ -77,4 +286,12 @@
 void NetworkGameManager::removeEntity(int uniqueID)
 {
+  if ( this->isServer() )
+  {
+    this->executeRemoveEntity( uniqueID );
+  }
+  else
+  {
+    this->requestRemoveEntity( uniqueID );
+  }
 }
 
@@ -85,6 +302,10 @@
  * @param classID: The ID of the class of which an entity should be created
  */
-void NetworkGameManager::requestCreateEntity(int classID)
-{
+void NetworkGameManager::requestCreateEntity(ClassID classID)
+{
+  if ( !writeToClientBuffer( allOutBuffer, (byte)REQUEST_CREATE ) )
+    return;
+  if ( !writeToClientBuffer( allOutBuffer, (int)classID ) )
+    return;
 }
 
@@ -95,4 +316,8 @@
 void NetworkGameManager::requestRemoveEntity(int uniqueID)
 {
+  if ( !writeToClientBuffer( allOutBuffer, (byte)REQUEST_REMOVE ) )
+    return;
+  if ( !writeToClientBuffer( allOutBuffer, uniqueID ) )
+    return;
 }
 
@@ -102,6 +327,16 @@
  * @param classID: The ID of the class of which an entity should be created
  */
-void NetworkGameManager::executeCreateEntity(int classID)
-{
+void NetworkGameManager::executeCreateEntity(ClassID classID, int uniqueID, int owner)
+{
+  if ( !writeToClientBuffer( allOutBuffer, (byte)CREATE_ENTITY ) )
+    return;
+  if ( !writeToClientBuffer( allOutBuffer, (int)classID ) )
+    return;
+  if ( !writeToClientBuffer( allOutBuffer, uniqueID ) )
+    return;
+  if ( !writeToClientBuffer( allOutBuffer, owner ) )
+    return;
+
+  doCreateEntity( classID, uniqueID, owner );
 }
 
@@ -113,4 +348,10 @@
 void NetworkGameManager::executeRemoveEntity(int uniqueID)
 {
+  if ( !writeToClientBuffer( allOutBuffer, (byte)REMOVE_ENTITY ) )
+    return;
+  if ( !writeToClientBuffer( allOutBuffer, uniqueID ) )
+    return;
+
+  doRemoveEntity(uniqueID);
 }
 
@@ -119,5 +360,452 @@
  * @return: true if the entity can be created, false otherwise
  */
-bool NetworkGameManager::canCreateEntity(int classID)
-{
-}
+bool NetworkGameManager::canCreateEntity(ClassID classID)
+{
+  return true;
+}
+
+/*!
+ * Sends the Entities to the new connected client
+ * @param userID: The ID of the user
+ */
+void NetworkGameManager::sendEntityList( int userID )
+{
+  if ( !isServer() )
+    return;
+
+  if ( userID >= outBuffer.size() )
+    resizeBufferVector( userID );
+
+  SynchronizeableList::const_iterator it, e;
+
+  it = this->networkStream->getSyncBegin();
+  e = this->networkStream->getSyncEnd();
+
+  if ( !writeToClientBuffer( outBuffer[userID], (byte)CREATE_ENTITY_LIST ) )
+    return;
+
+  // -2 because you must not send network_game_manager and handshake
+  if ( !writeToClientBuffer( outBuffer[userID], networkStream->getSyncCount() ) )
+    return;
+
+  //PRINTF(0)("SendEntityList: n = %d\n", networkStream->getSyncCount()-2 );
+
+  while ( it != e )
+  {
+
+    if ( !writeToClientBuffer( outBuffer[userID], (int)((*it)->getLeafClassID()) ) )
+      return;
+      //PRINTF(0)("SendEntityList: ClassID = %x\n", (*it)->getRealClassID());
+
+    if ( !writeToClientBuffer( outBuffer[userID], (int)((*it)->getUniqueID()) ) )
+      return;
+
+    if ( !writeToClientBuffer( outBuffer[userID], (int)((*it)->getOwner()) ) )
+      return;
+
+    it++;
+  }
+
+
+}
+
+/**
+ * Creates a buffer for user n
+ * @param n The ID of the user
+ */
+void NetworkGameManager::resizeBufferVector( int n )
+{
+  for ( int i = outBuffer.size(); i<=n; i++)
+  {
+    clientBuffer outBuf;
+
+    outBuf.length = 0;
+
+    outBuf.maxLength = 5*1024;
+
+    outBuf.buffer = new byte[5*1014];
+
+    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 )
+  {
+    PRINTF(1)("Could not fabricate Object with classID %x\n", classID);
+    return;
+  }
+
+  if ( b->isA(CL_SYNCHRONIZEABLE) )
+  {
+    Synchronizeable * s = dynamic_cast<Synchronizeable*>(b);
+    s->setUniqueID( uniqueID );
+    s->setOwner( owner );
+    this->networkStream->connectSynchronizeable( *s );
+    if ( !isServer() )
+      s->setIsOutOfSync( true );
+    PRINTF(0)("Fabricated %s with id %d\n", s->getClassName(), s->getUniqueID());
+  }
+  else
+  {
+    PRINTF(1)("Class with ID %x 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;
+    }
+    it++;
+  }
+}
+
+/**
+ * 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;
+    }
+    it++;
+  }
+}
+
+/**
+ * Copies length bytes to the clientBuffer with error checking
+ * @param clientBuffer: the clientBuffer to write to
+ * @param data: buffer to the data
+ * @param length: length of data
+ * @return false on error true else
+ */
+bool NetworkGameManager::writeToClientBuffer( clientBuffer &cb, byte * data, int length )
+{
+  if ( length > cb.maxLength-cb.length )
+  {
+    PRINTF(1)("No space left in clientBuffer\n");
+    return false;
+  }
+
+  memcpy( cb.buffer+cb.length, data, length );
+  return true;
+}
+
+/**
+ * Reads data from clientBuffer with error checking
+ * @param clientBuffer: the clientBuffer to read from
+ * @param data: pointer to the buffer
+ * @param length:
+ * @return
+ */
+bool NetworkGameManager::readFromClientBuffer( clientBuffer &cb, byte * data, int length )
+{
+  if ( cb.length < length )
+  {
+    PRINTF(0)("There is not enough data in clientBuffer\n");
+    return 0;
+  }
+
+  memcpy( data, cb.buffer+cb.length-length, length );
+  return true;
+}
+
+/**
+ * Tells this client that he has to control this entity
+ * @param uniqueID: the entity's uniqeID
+ */
+void NetworkGameManager::doYouAre( int uniqueID )
+{
+  //TODO: what has to be done
+}
+
+/**
+ * Tells a remote client that he has to control this entity
+ * @param uniqueID: the entity's uniqeID
+ * @param userID: the users ID
+ */
+void NetworkGameManager::sendYouAre( int uniqueID, int userID )
+{
+  if ( !isServer() )
+    return;
+
+  if ( userID != 0 )
+  {
+    if ( !writeToClientBuffer( outBuffer[userID], (byte)YOU_ARE_ENTITY ) )
+      return;
+
+    if ( !writeToClientBuffer( outBuffer[userID], uniqueID ) )
+      return;
+  }
+  else
+  {
+    doYouAre(uniqueID);
+  }
+}
+
+bool NetworkGameManager::handleRequestCreate( int & i, const byte * data, int length, int sender )
+{
+  if ( INTSIZE > length-i )
+  {
+    PRINTF(1)("Cannot read classID from buffer! Not enough data left!\n");
+    return false;
+  }
+  int classID;
+  i += Converter::byteArrayToInt( &data[i], &classID );
+
+  createEntity( (ClassID)classID );
+
+  return true;
+}
+
+bool NetworkGameManager::handleRequestRemove( int & i, const byte * data, int length, int sender )
+{
+  if ( INTSIZE > length-i )
+  {
+    PRINTF(1)("Cannot read uniqueID from buffer! Not enough data left!\n");
+    return false;
+  }
+  int uniqueID;
+  i += Converter::byteArrayToInt( &data[i], &uniqueID );
+
+  removeEntity( uniqueID );
+
+  return true;
+}
+
+bool NetworkGameManager::handleCreateEntity( int & i, const byte * data, int length, int sender )
+{
+  if ( INTSIZE > length-i )
+  {
+    PRINTF(1)("Cannot read classID from buffer! Not enough data left!\n");
+    return false;
+  }
+  int classID;
+  i += Converter::byteArrayToInt( &data[i], &classID );
+
+  if ( INTSIZE > length-i )
+  {
+    PRINTF(1)("Cannot read uniqueID from buffer! Not enough data left!\n");
+    return false;
+  }
+  int uniqueID;
+  i += Converter::byteArrayToInt( &data[i], &uniqueID );
+
+  if ( INTSIZE > length-i )
+  {
+    PRINTF(1)("Cannot read owner from buffer! Not enough data left!\n");
+    return false;
+  }
+  int owner;
+  i += Converter::byteArrayToInt( &data[i], &owner );
+
+  doCreateEntity( (ClassID)classID, uniqueID, owner );
+
+  return true;
+}
+
+bool NetworkGameManager::handleRemoveEntity( int & i, const byte * data, int length, int sender )
+{
+  if ( INTSIZE > length-i )
+  {
+    PRINTF(1)("Cannot read uniqueID from buffer! Not enough data left!\n");
+    return false;
+  }
+  int uniqueID;
+  i += Converter::byteArrayToInt( &data[i], &uniqueID );
+
+  doRemoveEntity( uniqueID );
+
+  return true;
+}
+
+bool NetworkGameManager::handleCreateEntityList( 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)("HandleCreateEntityList:  data[i..i+3] = %d %d %d %d\n", data[i], data[i+1], data[i+2], data[i+3]);
+
+  int n;
+  i += Converter::byteArrayToInt( &data[i], &n );
+
+
+  PRINTF(0)("HandleCreateEntityList: n = %d\n", n);
+
+  int classID, uniqueID, owner;
+
+  for ( int j = 0; j<n; j++ )
+  {
+
+    if ( INTSIZE > length-i )
+    {
+      PRINTF(1)("Cannot read classID from buffer! Not enough data left!\n");
+      return false;
+    }
+    i += Converter::byteArrayToInt( &data[i], &classID );
+
+    if ( INTSIZE > length-i )
+    {
+      PRINTF(1)("Cannot read uniqueID from buffer! Not enough data left!\n");
+      return false;
+    }
+    i += Converter::byteArrayToInt( &data[i], &uniqueID );
+
+    if ( INTSIZE > length-i )
+    {
+      PRINTF(1)("Cannot read owner from buffer! Not enough data left!\n");
+      return false;
+    }
+    i += Converter::byteArrayToInt( &data[i], &owner );
+
+    if ( classID != CL_NETWORK_GAME_MANAGER && classID != CL_HANDSHAKE )
+      doCreateEntity( (ClassID)classID, uniqueID, owner );
+
+  }
+  return true;
+}
+
+bool NetworkGameManager::handleRemoveEntityList( 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;
+  }
+  int n;
+  i += Converter::byteArrayToInt( &data[i], &n );
+
+  int uniqueID;
+
+  for ( int j = 0; j<n; j++ )
+  {
+
+    if ( INTSIZE > length-i )
+    {
+      PRINTF(1)("Cannot read uniqueID from buffer! Not enough data left!\n");
+      return false;
+    }
+    i += Converter::byteArrayToInt( &data[i], &uniqueID );
+
+    doRemoveEntity( uniqueID );
+  }
+
+  return true;
+}
+
+bool NetworkGameManager::handleYouAreEntity( int & i, const byte * data, int length, int sender )
+{
+  if ( INTSIZE > length-i )
+  {
+    PRINTF(1)("Cannot read uniqueID from buffer! Not enough data left!\n");
+    return false;
+  }
+
+  int uniqueID;
+  i += Converter::byteArrayToInt( &data[i], &uniqueID );
+
+  doYouAre( uniqueID );
+
+  return true;
+}
+
+bool NetworkGameManager::handleRequestSync( int & i, const byte * data, int length, int sender )
+{
+  if ( INTSIZE > length-i )
+  {
+    PRINTF(1)("Cannot read uniqueID from buffer! Not enough data left!\n");
+    return false;
+  }
+  int uniqueID;
+  i += Converter::byteArrayToInt( &data[i], &uniqueID );
+
+  doRequestSync( uniqueID, sender );
+
+  return true;
+}
+
+bool NetworkGameManager::writeToClientBuffer( clientBuffer & cb, byte b )
+{
+  if ( cb.maxLength-cb.length < 1 )
+  {
+    PRINTF(1)("Cannot write to clientBuffer! Not enough space for 1 byte\n");
+    return false;
+  }
+
+  cb.buffer[cb.length++] = b;
+
+  return true;
+}
+
+bool NetworkGameManager::writeToClientBuffer( clientBuffer & cb, int i )
+{
+  int n = Converter::intToByteArray( i, cb.buffer+cb.length, cb.maxLength-cb.length );
+  cb.length += n;
+
+  if ( n <= 0 )
+  {
+    PRINTF(1)("Cannot write to clientBuffer! Not enough space for 1 int\n");
+    return false;
+  }
+
+  return true;
+}
+
+void NetworkGameManager::sync( int uniqueID, int owner )
+{
+  if ( owner==this->getHostID() )
+    return;
+
+  if ( !isServer() )
+    executeRequestSync( uniqueID, 0 );
+  else
+    executeRequestSync( uniqueID, owner );
+}
+
+void NetworkGameManager::executeRequestSync( int uniqueID, int user )
+{
+  if ( user >= outBuffer.size() )
+    resizeBufferVector( user );
+
+  if ( !writeToClientBuffer( outBuffer[user], (byte)REQUEST_SYNC ) )
+    return;
+  if ( !writeToClientBuffer( outBuffer[user], uniqueID ) )
+    return;
+}
+
Index: branches/network_merged/src/lib/network/network_game_manager.h
===================================================================
--- branches/network_merged/src/lib/network/network_game_manager.h	(revision 6339)
+++ branches/network_merged/src/lib/network/network_game_manager.h	(revision 6340)
@@ -14,31 +14,47 @@
 
 
+class TiXmlElement;
 
 /**
  * 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_ENTITY_LIST: //request the whole world :D
+ *  REQUEST_SYNC:        UNIQUE_ID
+ *  //REQUEST_SYNC_LIST:   NUMBER, [UNIQUE_ID][0..NUMBER]
+ *
+ *  YOU_ARE_ENTITY:      UNIQUE_ID
  *
  */
 
+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
+};
 
-
-
-
-
-
-
-
+struct clientBuffer
+{
+  int length;
+  int maxLength;
+  byte * buffer;
+};
 
 /*!
@@ -48,41 +64,65 @@
 {
   public:
-    NetworkGameManager();
     ~NetworkGameManager();
 
-    virtual void writeBytes(const byte* data, int length);
+    static NetworkGameManager* NetworkGameManager::getInstance()
+    { if (!NetworkGameManager::singletonRef) NetworkGameManager::singletonRef = new NetworkGameManager(); return NetworkGameManager::singletonRef; }
+
+    virtual int writeBytes(const byte* data, int length, int sender);
     virtual int readBytes(byte* data, int maxLength, int * reciever);
     virtual void writeDebug() const;
     virtual void readDebug() const;
 
-    void createEntity(int classID);
-    void createEntityList(int* classIDList);
-    void removeEntity(int uniqueID);
-    void removeEntityList(int* uniqueIDList);
+    void createEntity( ClassID classID, int owner = 0 );
+    BaseObject* createEntity( TiXmlElement* element);
+    void removeEntity( int uniqueID );
+    void sendYouAre( int uniqueID, int userID );
 
-    void sync(int uniqueID);
-    void syncList(int* uniqueIDList);
+    void sync(int uniqueID, int owner);
 
+    void sendEntityList(int userID);
 
   private:
-    void requestCreateEntity(int classID);
-    void executeCreateEntity(int classID);
-    void requestCreateEntityList(int* classIDList);
-    void executeCreateEntityList(int* classIDList);
+    NetworkGameManager();
+
+    void requestCreateEntity(ClassID classID);
+    void executeCreateEntity(ClassID classID, int uniqueID = 0, int owner = 0);
 
     void requestRemoveEntity(int uniqueID);
     void executeRemoveEntity(int uniqueID);
-    void requestRemoveEntityList(int* uniqueIDList);
-    void executeRemoveEntityList(int* uniqueIDList);
 
+    void executeRequestSync( int uniqueID, int user );
 
+    void doCreateEntity(ClassID classID, int uniqueID, int owner);
+    void doRemoveEntity(int uniqueID);
+    void doRequestSync(int uniqueID, int userID);
+    void doYouAre( int uniqueID );
 
-    bool canCreateEntity(int classID);
+    bool canCreateEntity(ClassID classID);
 
+    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 );
+
+    //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:
-    byte*          inBuffer;
-    byte*          outBuffer;
+    std::vector<clientBuffer>     outBuffer;
+    clientBuffer                  allOutBuffer;
+    static NetworkGameManager*    singletonRef;
+
+    int                           newUniqueID;
+    bool                          hasRequestedWorld;
 };
 
Index: branches/network_merged/src/lib/network/network_manager.cc
===================================================================
--- branches/network_merged/src/lib/network/network_manager.cc	(revision 6339)
+++ branches/network_merged/src/lib/network/network_manager.cc	(revision 6340)
@@ -44,4 +44,5 @@
   /* set the class id for the base object */
   this->setClassID(CL_NETWORK_MANAGER, "NetworkManager");
+  PRINTF(0)("START\n");
 
   /* initialize the references */
@@ -49,4 +50,5 @@
   this->syncList = NULL;
   this->tmpStream = NULL;
+
   this->hostID = -1;
   this->bGameServer = false;
@@ -107,4 +109,6 @@
 int NetworkManager::createServer(unsigned int port)
 {
+  this->hostID = 0;
+  this->bGameServer = true;
   this->tmpStream = new NetworkStream(port);
   this->bGameServer = true;
@@ -124,18 +128,4 @@
   this->tmpStream = new NetworkStream(address);
   this->tmpStream->connectSynchronizeable(sync);
-}
-
-
-/**
- *  creates a new NetworkStream of server type
- * @param sync: the listener
- */
-NetworkStream& NetworkManager::createServer(Synchronizeable& sync, unsigned int port)
-{
-  PRINTF(0)("Create a new server socket\n");
-  /* creating a new network stream, it will register itself automaticaly to the class list */
-  this->tmpStream = new NetworkStream(port);
-  this->tmpStream->connectSynchronizeable(sync);
-  this->bGameServer = true;
 }
 
@@ -178,4 +168,4 @@
 void NetworkManager::setHostID(int id)
 {
-  this->hostID = id;
+    this->hostID = id;
 }
Index: branches/network_merged/src/lib/network/network_manager.h
===================================================================
--- branches/network_merged/src/lib/network/network_manager.h	(revision 6339)
+++ branches/network_merged/src/lib/network/network_manager.h	(revision 6340)
@@ -39,5 +39,4 @@
 
     NetworkStream& establishConnection(IPaddress& address, Synchronizeable& sync);
-    NetworkStream& createServer(Synchronizeable& sync, unsigned int port);
     void shutdownConnection();
 
Index: branches/network_merged/src/lib/network/network_protocol.cc
===================================================================
--- branches/network_merged/src/lib/network/network_protocol.cc	(revision 6339)
+++ branches/network_merged/src/lib/network/network_protocol.cc	(revision 6340)
@@ -30,4 +30,6 @@
 #include "debug.h"
 
+#include "converter.h"
+
 /* using namespace std is default, this needs to be here */
 using namespace std;
@@ -41,5 +43,5 @@
   /* set the class id for the base object */
   this->setClassID(CL_NETWORK_PROTOCOL, "NetworkProtocol");
-  this->headerLength = sizeof(Header);
+  this->headerLength = INTSIZE+FLOATSIZE;
 }
 
@@ -64,5 +66,5 @@
   PRINTF(5)("create header length = %i, bufferLength = %i\n", length, bufferLength);
   //If there isn't enough space for the header return -1
-  if (length + this->headerLength > bufferLength)
+  if (length + 2*INTSIZE > bufferLength)
     return -1;
 
@@ -70,14 +72,17 @@
   // FIXME: without move Create space for the header
   for( int i = length - 1; i >= 0; i--)
-    data[i + this->headerLength] = data[i];
+    data[i + INTSIZE+INTSIZE] = data[i];
 
   //Now create the header
   /* sender ID: FIXME: there will be a better ID (for example unique:D)*/
-  data[0] = (byte)(source.getUniqueID());
+  //data[0] = (byte)(source.getUniqueID());
+  int res = Converter::intToByteArray( source.getUniqueID(), data, bufferLength );
+
   /* data length*/
-  data[1] = length;
+  //data[1] = length;
+  res += Converter::intToByteArray( length, data+res, bufferLength-res );
 
 
-  return length + this->headerLength;
+  return length + res;
 }
 
@@ -92,5 +97,5 @@
   PRINTF(5)("extract Header\n");
   //Test if received data can contain a header
-  if (length < headerLength)
+  if (length < 2*INTSIZE)
   {
     PRINTF(1)("Received data is to short; it can't contain a header!\n");
@@ -105,7 +110,9 @@
 
   /* unique ID */
-  h.synchronizeableID = data[0];
+  //h.synchronizeableID = data[0];
+  int res = Converter::byteArrayToInt( data, &(h.synchronizeableID) );
   /* data length*/
-  h.length = data[1];
+  //h.length = data[1];
+  Converter::byteArrayToInt( data+res, &(h.length) );
 
 
Index: branches/network_merged/src/lib/network/network_protocol.h
===================================================================
--- branches/network_merged/src/lib/network/network_protocol.h	(revision 6339)
+++ branches/network_merged/src/lib/network/network_protocol.h	(revision 6340)
@@ -14,6 +14,6 @@
 typedef struct Header
 {
-  byte synchronizeableID;
-  byte length;
+  int synchronizeableID;
+  int length;
 };
 
Index: branches/network_merged/src/lib/network/network_socket.cc
===================================================================
--- branches/network_merged/src/lib/network/network_socket.cc	(revision 6339)
+++ branches/network_merged/src/lib/network/network_socket.cc	(revision 6340)
@@ -21,4 +21,5 @@
 #define DEBUG_MODULE_NETWORK
 
+#include "converter.h"
 
 /* include your own header */
@@ -398,13 +399,10 @@
 {
   PRINTF(5)("NetworkSocket::writePacket()\n");
-  if (length>255)
-  {
-    PRINTF(1)("Packet length > 255!\n");
-    return false;
-  }
-
-  byte blen = length;
-
-  writeBytes(&blen, 1);
+
+  byte blen[INTSIZE];
+
+  Converter::intToByteArray( length, blen, INTSIZE );
+
+  writeBytes(blen, INTSIZE);
   writeBytes(data, length);
 }
@@ -413,10 +411,11 @@
 {
   PRINTF(5)("NetworkSocket::readPacket()\n");
-  if (incomingBufferLength<1)
-  {
-    return 0;
-  }
-
-  byte blen = incomingBuffer[0];
+  if (incomingBufferLength<INTSIZE)
+  {
+    return 0;
+  }
+
+  int blen;
+  Converter::byteArrayToInt( incomingBuffer, &blen );
 
   if (blen>maxLength)
@@ -431,5 +430,6 @@
   }
 
-  readBytes(&blen, 1);
+  byte t[INTSIZE];
+  readBytes(t, INTSIZE);
   int res = readBytes(data, blen);
 
Index: branches/network_merged/src/lib/network/network_stream.cc
===================================================================
--- branches/network_merged/src/lib/network/network_stream.cc	(revision 6339)
+++ branches/network_merged/src/lib/network/network_stream.cc	(revision 6340)
@@ -27,4 +27,6 @@
 #include "synchronizeable.h"
 #include "network_manager.h"
+#include "network_game_manager.h"
+
 #include "debug.h"
 #include "class_list.h"
@@ -64,4 +66,5 @@
   this->connectSynchronizeable(*hs);
   PRINTF(0)("NetworkStream: %s\n", hs->getName());
+  this->maxConnections = 1;
 }
 
@@ -77,4 +80,9 @@
   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 );
@@ -88,4 +96,5 @@
   this->bActive = false;
   this->serverSocket = NULL;
+  this->networkGameManager = NULL;
   myHostId = 0;
 }
@@ -176,9 +185,18 @@
             NetworkManager::getInstance()->setHostID( handshakes[i]->getHostId() );
             myHostId = NetworkManager::getInstance()->getHostID();
-          }
-          PRINT(0)("handshake finished\n");
+
+            this->networkGameManager = NetworkGameManager::getInstance();
+            this->networkGameManager->setUniqueID( handshakes[i]->getNetworkGameManagerId() );
+            this->connectSynchronizeable( *(this->networkGameManager) );
+          }
+          else
+          {
+            //this->networkGameManager->sendEntityList( i );
+          }
+          PRINT(0)("handshake finished id=%d\n", handshakes[i]->getNetworkGameManagerId());
+
+
           delete handshakes[i];
           handshakes[i] = NULL;
-          //TODO: replace handshake by entitymanager
         }
         else
@@ -202,6 +220,5 @@
   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 )
+    if ( (*it)!=NULL /*&& (*it)->getOwner() == myHostId*/ )
     {
       do {
@@ -217,8 +234,14 @@
         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+2 )
+        {
+          //if ( !isServer() ) PRINTF(0)("RESET UNIQUEID FROM %d TO 0 maxCon=%d\n", header->synchronizeableID, this->maxConnections);
           header->synchronizeableID = 0;
+        }
+        else
+        {
+          //if ( !isServer() ) PRINTF(0)("UNIQUEID=%d\n", header->synchronizeableID);
+        }
 
         if ( dataLength<=0 )
@@ -229,5 +252,5 @@
           if ( networkSockets[reciever] != NULL )
           {
-            PRINTF(5)("write %d bytes to socket %d\n", dataLength, reciever);
+            PRINTF(0)("write %d bytes to socket %d\n", dataLength, reciever);
             networkSockets[reciever]->writePacket(downBuffer, dataLength);
           }
@@ -243,5 +266,5 @@
             if ( networkSockets[i] != NULL )
             {
-              PRINTF(5)("write %d bytes to socket %d\n", dataLength, reciever);
+              PRINTF(0)("write %d bytes to socket %d\n", dataLength, reciever);
               networkSockets[i]->writePacket(downBuffer, dataLength);
             }
@@ -251,8 +274,4 @@
       } while( reciever!=0 );
     }
-    else
-    {
-      PRINTF(0)("synchronizeables == NULL");
-    }
   }
 
@@ -269,8 +288,9 @@
           continue;
 
-        PRINTF(5)("read %d bytes from socket\n", dataLength);
         header = networkProtocol->extractHeader(upBuffer, dataLength);
         dataLength -= sizeof(header);
 
+        PRINTF(0)("read %d bytes from socket uniqueID = %d\n", dataLength, header.synchronizeableID);
+
         if ( dataLength != header.length )
         {
@@ -287,5 +307,12 @@
         {
           if ( *it && (*it)->getUniqueID()==header.synchronizeableID )
-            (*it)->writeBytes(upBuffer+sizeof(header), dataLength);
+          {
+            if ( (*it)->writeBytes(upBuffer+sizeof(header), dataLength, i) != header.length )
+            {
+              PRINTF(1)("%s did not read all the data!\n", (*it)->getClassName());
+              break;
+            }
+            continue;
+          }
         }
 
@@ -309,5 +336,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
@@ -315,5 +342,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);
@@ -376,6 +403,14 @@
     return;
   }
+
+  if ( n > MAX_CONNECTIONS )
+  {
+    PRINTF(1)("Cannot set maxConnectiosn to %d because of hardcoded limit %d\n", n, MAX_CONNECTIONS);
+    return;
+  }
+
   this->maxConnections = n;
-}
-
-
+  this->networkGameManager->setUniqueID( n+2 );
+}
+
+
Index: branches/network_merged/src/lib/network/network_stream.h
===================================================================
--- branches/network_merged/src/lib/network/network_stream.h	(revision 6339)
+++ branches/network_merged/src/lib/network/network_stream.h	(revision 6340)
@@ -15,4 +15,6 @@
 #include "handshake.h"
 
+#define MAX_CONNECTIONS 1000
+
 class Synchronizeable;
 class NetworkSocket;
@@ -20,4 +22,5 @@
 class ConnectionMonitor;
 class NetworkProtocol;
+class NetworkGameManager;
 
 typedef std::list<Synchronizeable*>  SynchronizeableList;
@@ -48,4 +51,8 @@
     virtual void processData();
 
+    inline SynchronizeableList::const_iterator getSyncBegin(){ return synchronizeables.begin(); }
+    inline SynchronizeableList::const_iterator getSyncEnd(){ return synchronizeables.end(); }
+    inline int getSyncCount(){ return synchronizeables.size(); }
+
   private:
     NetworkProtocol*       networkProtocol;
@@ -63,4 +70,6 @@
     int                    maxConnections;
 
+    NetworkGameManager*   networkGameManager;
+
     void updateConnectionList();
 };
Index: branches/network_merged/src/lib/network/synchronizeable.cc
===================================================================
--- branches/network_merged/src/lib/network/synchronizeable.cc	(revision 6339)
+++ branches/network_merged/src/lib/network/synchronizeable.cc	(revision 6340)
@@ -28,21 +28,14 @@
 Synchronizeable::Synchronizeable()
 {
-
+  this->setClassID(CL_SYNCHRONIZEABLE, "Synchronizeable");
   owner = 0;
+  state = 0;
   hostID = NetworkManager::getInstance()->getHostID();
+  this->setIsServer(this->hostID == 0);
   uniqueID = -1;
   this->networkStream = NULL;
-  //state = ?;
-
+  this->setRequestedSync( false );
 }
 
-/**
- *  default constructor
- */
-Synchronizeable::Synchronizeable(const char* name)
-{
-  this->setName(name);
-  this->networkStream = NULL;
-}
 
 
@@ -59,7 +52,7 @@
  *  write data to NetworkStream
  */
-void Synchronizeable::writeBytes(const byte* data, int length)
+int Synchronizeable::writeBytes(const byte* data, int length, int sender)
 {
-  PRINTF(1)("Synchronizeable::writeBytes was called\n");
+  PRINTF(5)("Synchronizeable::writeBytes was called\n");
 }
 
@@ -69,5 +62,5 @@
 int Synchronizeable::readBytes(byte* data, int maxLength, int * reciever)
 {
-  PRINTF(1)("Synchronizeable::readBytes was called\n");
+  PRINTF(5)("Synchronizeable::readBytes was called\n");
 }
 
@@ -103,4 +96,5 @@
   else
     this->state = this->state & (~STATE_OUTOFSYNC);
+  //PRINTF(0)("isoutofsync %s %d\n", this->getClassName(), state);
 }
 
@@ -111,5 +105,5 @@
 bool Synchronizeable::isServer()
 {
-  return this->state & STATE_SERVER == STATE_SERVER;
+  return (this->state & STATE_SERVER) >0;
 }
 
@@ -120,5 +114,26 @@
 bool Synchronizeable::isOutOfSync()
 {
-  return this->state & STATE_OUTOFSYNC == STATE_OUTOFSYNC;
+  return (this->state & STATE_OUTOFSYNC) >0;
+}
+
+/**
+ * Determines if the requestedSync flag is set
+ * @return true, if the requestedSync flag is true, false else
+ */
+bool Synchronizeable::requestedSync()
+{
+  return (this->state & STATE_REQUESTEDSYNC) >0;
+}
+
+/**
+ * Sets the requestedsync flag to a given value
+ * @param requestedSync: the boolean value which the requestedsync flag is to set to
+ */
+void Synchronizeable::setRequestedSync( bool requestedSync )
+{
+  if( requestedSync )
+    this->state = this->state | STATE_REQUESTEDSYNC;
+  else
+    this->state = this->state & (~STATE_REQUESTEDSYNC);
 }
 
Index: branches/network_merged/src/lib/network/synchronizeable.h
===================================================================
--- branches/network_merged/src/lib/network/synchronizeable.h	(revision 6339)
+++ branches/network_merged/src/lib/network/synchronizeable.h	(revision 6340)
@@ -9,4 +9,5 @@
 #include "base_object.h"
 #include "netdefs.h"
+#include "converter.h"
 
 
@@ -18,4 +19,143 @@
 #define STATE_SERVER 1
 #define STATE_OUTOFSYNC 2
+#define STATE_REQUESTEDSYNC 4
+
+
+//macros to help writing data in byte buffer
+/*
+ * Important: these macros must be used in
+ *     SYNCHELP_READ_*:  virtual void      writeBytes(const byte* data, int length, int sender);
+ *     SYNCHELP_WRITE_*: virtual int       readBytes(byte* data, int maxLength, int * reciever);
+ * with the same argument names!
+ *
+ * SYNCHELP_WRITE_BEGIN()
+ * SYNCHELP_WRITE_INT(i)
+ * SYNCHELP_WRITE_FLOAT(f)
+ * SYNCHELP_WRITE_BYTE(b)
+ * SYNCHELP_WRITE_STRING(s)
+ * SYNCHELP_WRITE_N
+ *
+ * SYNCHELP_READ_BEGIN()
+ * SYNCHELP_READ_INT(i)
+ * SYNCHELP_READ_FLOAT(f)
+ * SYNCHELP_READ_STRING(s,l) l = size of buffer s
+ * SYNCHELP_READ_STRINGM(s)  allocates memory for string! you have to free this after
+ * SYNCHELP_READ_BYTE(b)
+ * SYNCHELP_READ_N
+ *
+ *
+ *
+ * Example 1:
+ *  SYNCHELP_READ_BEGIN();
+ *  SYNCHELP_READ_FLOAT(size);
+ *  SYNCHELP_READ_STRING( textureName, 1024 ); //1024 is the length of textureName
+ *
+ * Example 2:
+ *  SYNCHELP_WRITE_BEGIN();
+ *  SYNCHELP_WRITE_FLOAT(this->size);
+ *  SYNCHELP_WRITE_STRING(this->textureName);
+ *  return SYNCHELP_WRITE_N;
+ *
+ */
+#define SYNCHELP_WRITE_BEGIN()    int __synchelp_write_i = 0; \
+                                  int __synchelp_write_n
+#define SYNCHELP_WRITE_INT(i) { __synchelp_write_n = \
+                                Converter::intToByteArray( i, data+__synchelp_write_i, maxLength-__synchelp_write_i ); \
+                                if ( __synchelp_write_n <= 0) \
+{ \
+                                  PRINTF(1)("Buffer is too small to store a int\n"); \
+                                  return 0; \
+} \
+                                __synchelp_write_i += __synchelp_write_n; \
+}
+#define SYNCHELP_WRITE_FLOAT(f) { __synchelp_write_n = \
+                                Converter::floatToByteArray( f, data+__synchelp_write_i, maxLength-__synchelp_write_i ); \
+                                if ( __synchelp_write_n <= 0) \
+{ \
+                                  PRINTF(1)("Buffer is too small to store a float\n"); \
+                                  return 0; \
+} \
+                                __synchelp_write_i += __synchelp_write_n; \
+}
+#define SYNCHELP_WRITE_BYTE(b) { \
+                                if (maxLength - __synchelp_write_i < 1) \
+{ \
+                                  PRINTF(1)("Buffer is too small to store string\n"); \
+                                  return 0; \
+} \
+                                data[__synchelp_write_i] = b; \
+                                __synchelp_write_i++; \
+}
+#define SYNCHELP_WRITE_STRING(s) { if (s!=NULL) \
+                                __synchelp_write_n = \
+                                Converter::stringToByteArray( s, data+__synchelp_write_i, strlen(s), maxLength-__synchelp_write_i ); \
+                                else \
+                                __synchelp_write_n = \
+                                Converter::stringToByteArray( "", data+__synchelp_write_i, strlen(""), maxLength-__synchelp_write_i ); \
+                                if ( __synchelp_write_n <= 0) \
+{ \
+                                  PRINTF(1)("Buffer is too small to store string\n"); \
+                                  return 0; \
+} \
+                                __synchelp_write_i += __synchelp_write_n; \
+}
+#define SYNCHELP_WRITE_N        __synchelp_write_i
+#define SYNCHELP_WRITE_FKT(f)   { \
+                                  __synchelp_write_i += \
+                                  f( data+__synchelp_write_i, maxLength-__synchelp_write_i ); \
+                                }
+
+
+#define SYNCHELP_READ_BEGIN()     int __synchelp_read_i = 0; \
+                                  int __synchelp_read_n
+
+#define SYNCHELP_READ_INT(i)       { \
+                                    if ( length-__synchelp_read_i < INTSIZE ) \
+{ \
+                                      PRINTF(1)("There is not enough data to read an int\n");  \
+                                      return 0; \
+} \
+                                    __synchelp_read_i += Converter::byteArrayToInt( data+__synchelp_read_i, &i );  \
+}
+#define SYNCHELP_READ_FLOAT(f)    { \
+                                    if ( length-__synchelp_read_i < FLOATSIZE ) \
+{ \
+                                      PRINTF(1)("There is not enough data to read a flaot\n");  \
+                                      return 0; \
+} \
+                                    __synchelp_read_i += Converter::byteArrayToFloat( data+__synchelp_read_i, &f );  \
+}
+#define SYNCHELP_READ_STRING(s,l)    { \
+                                    __synchelp_read_n = Converter::byteArrayToString( data+__synchelp_read_i, s, l );  \
+                                    if ( __synchelp_read_n <0 )  \
+{ \
+                                      PRINTF(1)("There is not enough data to read string\n");  \
+                                      return 0; \
+} \
+                                    __synchelp_read_i += __synchelp_read_n; \
+}
+#define SYNCHELP_READ_STRINGM(s)    { \
+                                    __synchelp_read_n = Converter::byteArrayToStringM( data+__synchelp_read_i, s );  \
+                                    if ( __synchelp_read_n <0 )  \
+{ \
+                                      PRINTF(1)("There is not enough data to read string\n");  \
+                                      return 0; \
+} \
+                                    __synchelp_read_i += __synchelp_read_n; \
+}
+#define SYNCHELP_READ_BYTE(b)      { \
+                                    if ( length-__synchelp_read_i < 1 ) \
+{ \
+                                      PRINTF(1)("There is not enough data to read a byte\n");  \
+                                      return 0; \
+} \
+                                    b = data[__synchelp_read_i]; \
+                                    __synchelp_read_i ++;  \
+}
+#define SYNCHELP_READ_FKT(f)   { \
+                                  __synchelp_read_i += \
+                                  f( data+__synchelp_read_i, length-__synchelp_read_i, sender); \
+                                  }
+#define SYNCHELP_READ_N           __synchelp_read_i
 
 class NetworkStream;
@@ -25,10 +165,8 @@
   {
   public:
-
-    Synchronizeable(const char* name);
     Synchronizeable();
     ~Synchronizeable();
 
-    virtual void      writeBytes(const byte* data, int length);
+    virtual int       writeBytes(const byte* data, int length, int sender);
     virtual int       readBytes(byte* data, int maxLength, int * reciever);
     virtual void      writeDebug() const;
@@ -37,9 +175,13 @@
     void setIsServer( bool isServer );
     void setIsOutOfSync( bool outOfSync );
+    void setRequestedSync( bool requestedSync );
     bool isServer();
     bool isOutOfSync();
-    void setUniqueID( int id ){ uniqueID = id; }
-    int  getUniqueID() const { return uniqueID; };
-    void requestSync( int hostID ){ this->synchronizeRequests.push_back( hostID ); }
+    bool requestedSync();
+    inline void setUniqueID( int id ){ uniqueID = id; }
+    inline int  getUniqueID() const { return uniqueID; };
+    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; }
@@ -57,8 +199,10 @@
     int owner;
     int hostID;
+
+    std::list<int> synchronizeRequests;
+
+  protected:
+    NetworkStream* networkStream;
     int state;
-    std::list<int> synchronizeRequests;
-
-    NetworkStream* networkStream;
 
   };
Index: branches/network_merged/src/story_entities/network_world.cc
===================================================================
--- branches/network_merged/src/story_entities/network_world.cc	(revision 6339)
+++ branches/network_merged/src/story_entities/network_world.cc	(revision 6340)
@@ -69,4 +69,5 @@
 #include "playable.h"
 #include "network_manager.h"
+#include "network_game_manager.h"
 #include "playable.h"
 
@@ -167,4 +168,5 @@
 {
   this->setClassID(CL_WORLD, "NetworkWorld");
+  PRINTF(0)("START\n");
 
   this->setName(name);
@@ -337,7 +339,4 @@
   // find WorldEntities //
   ////////////////////////
-  if( NetworkManager::getInstance()->isGameServer())
-  {}
-
   element = root->FirstChildElement("WorldEntities");
   if( element == NULL)
@@ -352,6 +351,31 @@
     while( element != NULL)
     {
-      if( NetworkManager::getInstance()->isGameServer() || !strcmp( element->Value(), "SkyBox") || !strcmp( element->Value(), "Terrain")
-          || !strcmp( element->Value(), "SpaceShip"))
+      if( NetworkManager::getInstance()->isGameServer())
+      {
+
+        BaseObject* created = NetworkGameManager::getInstance()->createEntity(element);
+        if( created != NULL )
+        {
+          if(created->isA(CL_WORLD_ENTITY))
+            this->spawn(dynamic_cast<WorldEntity*>(created));
+          printf("Created a %s: %s\n", created->getClassName(), created->getName());
+        }
+        else
+          PRINTF(1)("NetworkWorld: could not create this entity\n");
+
+          // if we load a 'Player' we use it as localPlayer
+
+
+          //todo do this more elegant
+        if( element->Value() != NULL && !strcmp( element->Value(), "SkyBox"))
+          sky = dynamic_cast<SkyBox*>(created);
+        if( element->Value() != NULL && !strcmp( element->Value(), "Terrain"))
+        {
+          terrain = dynamic_cast<Terrain*>(created);
+          CDEngine::getInstance()->setTerrain(terrain);
+        }
+
+      }
+      else if( /* !strcmp( element->Value(), "SkyBox") || */ /* !strcmp( element->Value(), "Terrain") || */ !strcmp( element->Value(), "SpaceShip"))
       {
         BaseObject* created = Factory::fabricate(element);
@@ -362,4 +386,6 @@
           printf("Created a %s: %s\n", created->getClassName(), created->getName());
         }
+        else
+          PRINTF(1)("NetworkWorld: could not create this entity\n");
 
           // if we load a 'Player' we use it as localPlayer
@@ -374,5 +400,4 @@
           CDEngine::getInstance()->setTerrain(terrain);
         }
-
       }
       element = element->NextSiblingElement();
@@ -443,13 +468,13 @@
 //   this->spawn(testEntity);
 
-  for(int i = 0; i < 100; i++)
-  {
-    WorldEntity* tmp = new NPCTest1();
-    char npcChar[10];
-    sprintf (npcChar, "NPC_%d", i);
-        tmp->setName(npcChar);
-    tmp->setAbsCoor(((float)rand()/RAND_MAX) * 5000, 50/*+ (float)rand()/RAND_MAX*20*/, ((float)rand()/RAND_MAX -.5) *30);
-    this->spawn(tmp);
-  }
+//   for(int i = 0; i < 100; i++)
+//   {
+//     WorldEntity* tmp = NetworkGameManager::;
+//     char npcChar[10];
+//     sprintf (npcChar, "NPC_%d", i);
+//         tmp->setName(npcChar);
+//     tmp->setAbsCoor(((float)rand()/RAND_MAX) * 5000, 50/*+ (float)rand()/RAND_MAX*20*/, ((float)rand()/RAND_MAX -.5) *30);
+//     this->spawn(tmp);
+//   }
 
   this->music = NULL;
@@ -865,4 +890,5 @@
 //   this->entities->add (entity);
   entity->postSpawn ();
+
 }
 
Index: branches/network_merged/src/subprojects/network/Makefile.am
===================================================================
--- branches/network_merged/src/subprojects/network/Makefile.am	(revision 6339)
+++ branches/network_merged/src/subprojects/network/Makefile.am	(revision 6340)
@@ -22,4 +22,5 @@
                   $(MAINSRCDIR)/lib/lang/class_list.cc \
                   $(MAINSRCDIR)/util/loading/load_param.cc \
+                  $(MAINSRCDIR)/util/loading/factory.cc \
                   $(MAINSRCDIR)/lib/util/substring.cc \
                   $(MAINSRCDIR)/util/loading/load_param_description.cc \
Index: branches/network_merged/src/subprojects/network/network_unit_test.cc
===================================================================
--- branches/network_merged/src/subprojects/network/network_unit_test.cc	(revision 6339)
+++ branches/network_merged/src/subprojects/network/network_unit_test.cc	(revision 6340)
@@ -284,7 +284,38 @@
 }
 
-
+void testFloatConverter(float f)
+{
+  char* s = Converter::floatToBinString(f);
+  printf("%f = ", f);
+  printf(s); printf("\n");
+  
+  byte* res = Converter::floatToByteArray(f);
+  printf("Byte Array: ");
+  for (int i = 0; i < 4; i++)
+    printf("%i  ", res[i]);
+  printf("\n");
+  
+  float b = Converter::byteArrayToFloat(res);
+  printf("ReConvert: %f \n", b);
+}
+
+void testFloatConverter2(float f)
+{
+  char* s = Converter::floatToBinString(f);
+  printf("### %f = ", f);
+  printf(s); printf("\n");
+  
+  byte* res = Converter::_floatToByteArray(f);
+  printf("Byte Array: ");
+  for (int i = 0; i < 4; i++)
+    printf("%i  ", res[i]);
+  printf("\n");
+  
+  float b = Converter::_byteArrayToFloat(res);
+  printf("ReConvert: %f \n", b);
+}
 int converter(int argc, char** argv)
 {
+  /*
   int x = 200564786;
   printf("To convert: %i\n", x);
@@ -305,4 +336,6 @@
   printf("\n");
   
+  */
+  /*
   float y;
   char* s;
@@ -328,5 +361,39 @@
   printf(s); printf("\n");
   
-  
+  y = -4.7824f;
+  s = Converter::floatToBinString(y);
+  printf("%f = ", y);
+  printf(s); printf("\n");
+  
+  y = -14.35e14f;
+  s = Converter::floatToBinString(y);
+  printf("%f = ", y);
+  printf(s); printf("\n");
+                                                            */
+  
+  
+  /*
+  float a = 12.3f;
+  
+  char* s = Converter::floatToBinString(a);
+  printf("%f = ", a);
+  printf(s); printf("\n");
+  
+  byte* res = Converter::floatToByteArray(a);
+  printf("Byte Array: \n");
+  for (int i = 0; i < 4; i++)
+    printf("%i  ", res[i]);
+  printf("\n");
+  
+  float b = Converter::byteArrayToFloat(res);
+  printf("ReConvert: %f \n", b);
+  */
+//  testFloatConverter(12.3e-53f); printf("\n");
+//  testFloatConverter(134.26455646546548741661675165f); printf("\n");
+ // testFloatConverter(35.67e14f); printf("\n");
+  
+  testFloatConverter(12.3e-7f); printf("\n");
+  testFloatConverter(134.26455646546548741661675165f); printf("\n");
+  testFloatConverter(35.67e14f); printf("\n");
   
   return 0;
Index: branches/network_merged/src/subprojects/network/read_sync.cc
===================================================================
--- branches/network_merged/src/subprojects/network/read_sync.cc	(revision 6339)
+++ branches/network_merged/src/subprojects/network/read_sync.cc	(revision 6340)
@@ -60,5 +60,5 @@
  *  write data to Synchronizeable
  */
-void ReadSync::writeBytes(const byte* data, int length)
+int ReadSync::writeBytes(const byte* data, int length, int sender)
 {
   PRINTF(0)("ReadSync: got %i bytes of data\n", length);
Index: branches/network_merged/src/subprojects/network/read_sync.h
===================================================================
--- branches/network_merged/src/subprojects/network/read_sync.h	(revision 6339)
+++ branches/network_merged/src/subprojects/network/read_sync.h	(revision 6340)
@@ -16,5 +16,5 @@
     ~ReadSync();
 
-    virtual void writeBytes(const byte* data, int length);
+    virtual int writeBytes(const byte* data, int length, int sender);
     virtual int readBytes(byte* data, int maxLength, int * reciever);
 
Index: branches/network_merged/src/subprojects/network/simple_sync.cc
===================================================================
--- branches/network_merged/src/subprojects/network/simple_sync.cc	(revision 6339)
+++ branches/network_merged/src/subprojects/network/simple_sync.cc	(revision 6340)
@@ -66,5 +66,5 @@
  *  write data to Synchronizeable
  */
-void SimpleSync::writeBytes(const byte* data, int length)
+int SimpleSync::writeBytes(const byte* data, int length, int sender)
 {
   PRINTF(0)("SimpleSync: got %i bytes of data\n", length);
Index: branches/network_merged/src/subprojects/network/simple_sync.h
===================================================================
--- branches/network_merged/src/subprojects/network/simple_sync.h	(revision 6339)
+++ branches/network_merged/src/subprojects/network/simple_sync.h	(revision 6340)
@@ -16,5 +16,5 @@
     ~SimpleSync();
 
-    virtual void writeBytes(const byte* data, int length);
+    virtual int writeBytes(const byte* data, int length, int sender);
     virtual int readBytes(byte* data, int maxLength, int * reciever);
 
Index: branches/network_merged/src/subprojects/network/write_sync.cc
===================================================================
--- branches/network_merged/src/subprojects/network/write_sync.cc	(revision 6339)
+++ branches/network_merged/src/subprojects/network/write_sync.cc	(revision 6340)
@@ -66,5 +66,5 @@
  *  write data to Synchronizeable
  */
-void WriteSync::writeBytes(const byte* data, int length)
+int WriteSync::writeBytes(const byte* data, int length, int sender)
 {
   PRINTF(0)("WriteSync: got %i bytes of data\n", length);
Index: branches/network_merged/src/subprojects/network/write_sync.h
===================================================================
--- branches/network_merged/src/subprojects/network/write_sync.h	(revision 6339)
+++ branches/network_merged/src/subprojects/network/write_sync.h	(revision 6340)
@@ -16,5 +16,5 @@
     ~WriteSync();
 
-    virtual void writeBytes(const byte* data, int length);
+    virtual int writeBytes(const byte* data, int length, int sender);
     virtual int readBytes(byte* data, int maxLength, int * reciever);
 
Index: branches/network_merged/src/util/loading/factory.cc
===================================================================
--- branches/network_merged/src/util/loading/factory.cc	(revision 6339)
+++ branches/network_merged/src/util/loading/factory.cc	(revision 6340)
@@ -155,4 +155,5 @@
 }
 
+
 /**
  * Creates a new Object of type classID
Index: branches/network_merged/src/util/loading/factory.h
===================================================================
--- branches/network_merged/src/util/loading/factory.h	(revision 6339)
+++ branches/network_merged/src/util/loading/factory.h	(revision 6340)
@@ -29,4 +29,5 @@
 #include "debug.h"
 #include <vector>
+#include <list>
 
 /**
Index: branches/network_merged/src/world_entities/npcs/npc.cc
===================================================================
--- branches/network_merged/src/world_entities/npcs/npc.cc	(revision 6339)
+++ branches/network_merged/src/world_entities/npcs/npc.cc	(revision 6340)
@@ -62,6 +62,6 @@
       this->collider = entity;
   }
-  else if (entity->isA(CL_PLAYER))
-    this->applyForce(Vector(0,0,0)-location*100);
+  //  else if (entity->isA(CL_PLAYER))
+  //    this->applyForce(Vector(0,0,0)-location*100);
   else if (entity->isA(CL_NPC))
   {
Index: branches/network_merged/src/world_entities/npcs/npc.h
===================================================================
--- branches/network_merged/src/world_entities/npcs/npc.h	(revision 6339)
+++ branches/network_merged/src/world_entities/npcs/npc.h	(revision 6340)
@@ -8,5 +8,5 @@
 class AI;
 
-class NPC : public WorldEntity, public PhysicsInterface {
+class NPC : public WorldEntity {
 
  public:
Index: branches/network_merged/src/world_entities/skybox.cc
===================================================================
--- branches/network_merged/src/world_entities/skybox.cc	(revision 6339)
+++ branches/network_merged/src/world_entities/skybox.cc	(revision 6340)
@@ -22,4 +22,6 @@
 #include "static_model.h"
 #include "material.h"
+#include "network_game_manager.h"
+#include "converter.h"
 
 using namespace std;
@@ -77,4 +79,6 @@
     }
   this->setParentMode(PNODE_MOVEMENT);
+
+  this->textureName = NULL;
 }
 
@@ -208,2 +212,66 @@
   this->setModel(model);
 }
+
+int SkyBox::writeBytes( const byte * data, int length, int sender )
+{
+  setRequestedSync( false );
+  setIsOutOfSync( false );
+
+  SYNCHELP_READ_BEGIN();
+
+  SYNCHELP_READ_FKT( WorldEntity::writeState );
+
+  SYNCHELP_READ_FLOAT( size );
+  if ( textureName )
+  {
+    delete[] textureName;
+    textureName = NULL;
+  }
+  SYNCHELP_READ_STRINGM( textureName );
+
+  PRINT(0)("GOT DATA: size=%f texture='%s'\n", size, textureName);
+
+  this->setSize( size );
+  this->setTextureAndType( textureName, "jpg" );
+  this->rebuild();
+
+  return SYNCHELP_READ_N;
+}
+
+
+
+int SkyBox::readBytes( byte * data, int maxLength, int * reciever )
+{
+  if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() )
+  {
+    (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() );
+    setRequestedSync( true );
+  }
+
+  int rec = this->getRequestSync();
+  if ( rec > 0 )
+  {
+    PRINT(0)("SEND DATA: size=%f texture='%s'\n", size, textureName);
+    *reciever = rec;
+
+    SYNCHELP_WRITE_BEGIN();
+
+    SYNCHELP_WRITE_FKT( WorldEntity::readState );
+
+    SYNCHELP_WRITE_FLOAT(this->size);
+    SYNCHELP_WRITE_STRING(this->textureName);
+
+    return SYNCHELP_WRITE_N;
+  }
+
+  *reciever = 0;
+  return 0;
+}
+
+void SkyBox::writeDebug( ) const
+{
+}
+
+void SkyBox::readDebug( ) const
+{
+}
Index: branches/network_merged/src/world_entities/skybox.h
===================================================================
--- branches/network_merged/src/world_entities/skybox.h	(revision 6339)
+++ branches/network_merged/src/world_entities/skybox.h	(revision 6340)
@@ -35,9 +35,14 @@
   void setSize(float size);
   /** assumes jpg as input-format */
-  void setTexture(const char* name) { this->setTextureAndType (name, "jpg"); };
+  void setTexture(const char* name) { if (textureName) delete[] textureName; textureName = new char[strlen(name)+1]; strcpy(textureName, name); this->setTextureAndType (name, "jpg"); };
 
   void setTextureAndType(const char* name, const char* extension);
   void setTextures(const char* top, const char* bottom, const char* left,
                    const char* right, const char* front, const char* back);
+
+  virtual int       writeBytes(const byte* data, int length, int sender);
+  virtual int       readBytes(byte* data, int maxLength, int * reciever);
+  virtual void      writeDebug() const;
+  virtual void      readDebug() const;
 
  private:
@@ -46,4 +51,5 @@
   Material*       material[6];     //!< Materials for the SkyBox. sorted by number (0-5) top, bottom, left, right, front, back
   float           size;            //!< Size of the SkyBox. This should match the frustum maximum range.
+  char*           textureName;     //!< Name of the Texture
 
 };
Index: branches/network_merged/src/world_entities/space_ships/space_ship.cc
===================================================================
--- branches/network_merged/src/world_entities/space_ships/space_ship.cc	(revision 6339)
+++ branches/network_merged/src/world_entities/space_ships/space_ship.cc	(revision 6340)
@@ -121,5 +121,5 @@
   PRINTF(4)("SPACESHIP INIT\n");
 
-  EventHandler::getInstance()->grabEvents(true);
+  //  EventHandler::getInstance()->grabEvents(true);
 
   bUp = bDown = bLeft = bRight = bAscend = bDescend = bRollL = bRollR = false;
Index: branches/network_merged/src/world_entities/terrain.cc
===================================================================
--- branches/network_merged/src/world_entities/terrain.cc	(revision 6339)
+++ branches/network_merged/src/world_entities/terrain.cc	(revision 6340)
@@ -24,4 +24,6 @@
 #include "resource_manager.h"
 #include "model.h"
+#include "network_game_manager.h"
+
 
 #include "glincl.h"
@@ -111,4 +113,5 @@
 void Terrain::loadVegetation(const char* vegetationFile)
 {
+  PRINTF(0)("loadVegetation: %s\n", vegetationFile);
   if (this->vegetation)
     ResourceManager::getInstance()->unload(this->vegetation, RP_LEVEL);
@@ -116,5 +119,5 @@
   {
     PRINTF(4)("fetching %s\n", vegetationFile);
-      this->vegetation = (Model*)ResourceManager::getInstance()->load(vegetationFile, OBJ, RP_CAMPAIGN);
+    this->vegetation = (Model*)ResourceManager::getInstance()->load(vegetationFile, OBJ, RP_CAMPAIGN);
   }
   else
@@ -315,2 +318,42 @@
     }
 }
+
+int Terrain::writeBytes( const byte * data, int length, int sender )
+{
+  setRequestedSync( false );
+  setIsOutOfSync( false );
+
+  SYNCHELP_READ_BEGIN();
+  SYNCHELP_READ_FKT( WorldEntity::writeState );
+
+  return SYNCHELP_READ_N;
+}
+
+int Terrain::readBytes( byte * data, int maxLength, int * reciever )
+{
+  if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() )
+  {
+    (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() );
+    setRequestedSync( true );
+  }
+
+  int rec = this->getRequestSync();
+  if ( rec > 0 )
+  {
+    *reciever = rec;
+
+    return WorldEntity::readState( data, maxLength );
+
+  }
+
+  *reciever = 0;
+  return 0;
+}
+
+void Terrain::writeDebug( ) const
+{
+}
+
+void Terrain::readDebug( ) const
+{
+}
Index: branches/network_merged/src/world_entities/terrain.h
===================================================================
--- branches/network_merged/src/world_entities/terrain.h	(revision 6339)
+++ branches/network_merged/src/world_entities/terrain.h	(revision 6340)
@@ -30,4 +30,9 @@
   virtual ~Terrain();
 
+  virtual int       writeBytes(const byte* data, int length, int sender);
+  virtual int       readBytes(byte* data, int maxLength, int * reciever);
+  virtual void      writeDebug() const;
+  virtual void      readDebug() const;
+
   void init();
   void loadParams(const TiXmlElement* root);
@@ -44,4 +49,5 @@
    Model*              vegetation;
    int                 objectList;
+
 };
 
Index: branches/network_merged/src/world_entities/weapons/ground_turret.cc
===================================================================
--- branches/network_merged/src/world_entities/weapons/ground_turret.cc	(revision 6339)
+++ branches/network_merged/src/world_entities/weapons/ground_turret.cc	(revision 6340)
@@ -19,4 +19,5 @@
 
 #include "factory.h"
+#include "network_game_manager.h"
 #include "load_param.h"
 
@@ -168,2 +169,49 @@
 
 }
+
+/**
+ * Writes data from network containing information about the state
+ * @param data pointer to data
+ * @param length length of data
+ * @param sender hostID of sender
+ */
+int GroundTurret::writeBytes( const byte * data, int length, int sender )
+{
+  setRequestedSync( false );
+  setIsOutOfSync( false );
+
+  SYNCHELP_READ_BEGIN();
+
+  SYNCHELP_READ_FKT( WorldEntity::writeState );
+
+  return SYNCHELP_READ_N;
+}
+
+/**
+ * data copied in data will bee sent to another host
+ * @param data pointer to data
+ * @param maxLength max length of data
+ * @return the number of bytes writen
+ */
+int GroundTurret::readBytes( byte * data, int maxLength, int * reciever )
+{
+  SYNCHELP_WRITE_BEGIN();
+
+  if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() )
+  {
+    (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() );
+    setRequestedSync( true );
+  }
+
+  int rec = this->getRequestSync();
+  if ( rec > 0 )
+  {
+    *reciever = rec;
+
+    SYNCHELP_WRITE_FKT( WorldEntity::readState );
+
+  }
+
+  *reciever = 0;
+  return SYNCHELP_WRITE_N;
+}
Index: branches/network_merged/src/world_entities/weapons/ground_turret.h
===================================================================
--- branches/network_merged/src/world_entities/weapons/ground_turret.h	(revision 6339)
+++ branches/network_merged/src/world_entities/weapons/ground_turret.h	(revision 6340)
@@ -30,4 +30,7 @@
   virtual void collidesWith (WorldEntity* entity, const Vector& location);
 
+  virtual int writeBytes(const byte* data, int length, int sender);
+  virtual int readBytes(byte* data, int maxLength, int * reciever);
+
  private:
    Weapon *left, *right;
Index: branches/network_merged/src/world_entities/world_entity.cc
===================================================================
--- branches/network_merged/src/world_entities/world_entity.cc	(revision 6339)
+++ branches/network_merged/src/world_entities/world_entity.cc	(revision 6340)
@@ -105,5 +105,5 @@
 void WorldEntity::loadModel(const char* fileName, float scaling, unsigned int modelNumber)
 {
-  if (fileName != NULL)
+  if ( fileName != NULL && strcmp(fileName, "") )
   {
    // search for the special character # in the LoadParam
@@ -144,5 +144,7 @@
   }
   else
+  {
     this->setModel(NULL);
+  }
 }
 
@@ -340,2 +342,48 @@
   glPopMatrix();
 }
+
+/**
+ * Writes data from network containing information about the state
+ * @param data pointer to data
+ * @param length length of data
+ * @param sender hostID of sender
+ */
+int WorldEntity::writeState( const byte * data, int length, int sender )
+{
+  char* modelFileName;
+  SYNCHELP_READ_BEGIN();
+
+  SYNCHELP_READ_FKT( PNode::writeState );
+
+  SYNCHELP_READ_STRINGM( modelFileName );
+  SYNCHELP_READ_FLOAT( scaling );
+  //check if modelFileName is relative to datadir or absolute
+  if ( strstr(modelFileName, ResourceManager::getInstance()->getDataDir()) )
+  {
+    loadModel( modelFileName+strlen(ResourceManager::getInstance()->getDataDir()), scaling );
+  }
+  else
+  {
+    loadModel( modelFileName, scaling );
+  }
+  delete[] modelFileName;
+
+  return SYNCHELP_READ_N;
+}
+
+/**
+ * data copied in data will bee sent to another host
+ * @param data pointer to data
+ * @param maxLength max length of data
+ * @return the number of bytes writen
+ */
+int WorldEntity::readState( byte * data, int maxLength )
+{
+  SYNCHELP_WRITE_BEGIN();
+
+  SYNCHELP_WRITE_FKT( PNode::readState );
+
+  SYNCHELP_WRITE_STRING( getModel( 0 )->getName() );
+  SYNCHELP_WRITE_FLOAT( scaling );
+  return SYNCHELP_WRITE_N;
+}
Index: branches/network_merged/src/world_entities/world_entity.h
===================================================================
--- branches/network_merged/src/world_entities/world_entity.h	(revision 6339)
+++ branches/network_merged/src/world_entities/world_entity.h	(revision 6340)
@@ -74,7 +74,10 @@
   std::list<WorldEntity*>::iterator& getEntityIterator() { return this->objectListIterator; }
 
+  int       writeState(const byte* data, int length, int sender);
+  int       readState(byte* data, int maxLength );
 
  protected:
   //  CharacterAttributes*    charAttr;         //!< the character attributes of a world_entity
+
 
  private:
@@ -89,4 +92,7 @@
   std::list<WorldEntity*>::iterator objectListIterator; //!< The iterator position of this Entity in the given list of the ObjectManager.
 
+  float                   scaling;
+
+
 };
 
