Index: branches/network/src/lib/lang/base_object.cc
===================================================================
--- branches/network/src/lib/lang/base_object.cc	(revision 6273)
+++ branches/network/src/lib/lang/base_object.cc	(revision 6275)
@@ -75,5 +75,4 @@
   this->classID |= (long)classID;
   this->className = className;
-  this->realClassID = classID;
 
   ClassList::addToClassList(this, classID, className);
Index: branches/network/src/lib/lang/base_object.h
===================================================================
--- branches/network/src/lib/lang/base_object.h	(revision 6273)
+++ branches/network/src/lib/lang/base_object.h	(revision 6275)
@@ -34,5 +34,5 @@
   /** @returns the classID of the corresponding Object */
   inline int getClassID() const { return this->classID; };
-  inline int getRealClassID() const { return this->realClassID; };
+  inline ClassID getLeafID() { return (ClassID)(this->classID & CL_MASK_LOWLEVEL_CLASS); }
 
   bool isA (ClassID classID) const;
@@ -50,5 +50,4 @@
     const char*        className;        //!< the name of the class
     long               classID;          //!< this is the id from the class_id.h enumeration
-    long               realClassID;      //!< classID which can be used with factory
     char*              objectName;       //!< The name of this object
 };
Index: branches/network/src/lib/network/converter.cc
===================================================================
--- branches/network/src/lib/network/converter.cc	(revision 6273)
+++ branches/network/src/lib/network/converter.cc	(revision 6275)
@@ -444,4 +444,5 @@
   {
     PRINTF(1)("There is not enough space in string (%d) to store %d bytes\n", maxLength, length+1 );
+    strncpy(s,"",maxLength);
     return -1;
   }
Index: branches/network/src/lib/network/data_stream.h
===================================================================
--- branches/network/src/lib/network/data_stream.h	(revision 6273)
+++ branches/network/src/lib/network/data_stream.h	(revision 6275)
@@ -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/src/lib/network/network_game_manager.cc
===================================================================
--- branches/network/src/lib/network/network_game_manager.cc	(revision 6273)
+++ branches/network/src/lib/network/network_game_manager.cc	(revision 6275)
@@ -236,4 +236,5 @@
     }
 
+
     if ( b->isA(CL_SYNCHRONIZEABLE) )
     {
@@ -372,8 +373,8 @@
   while ( it != e )
   {
-    if ( (*it)->getRealClassID() != CL_NETWORK_GAME_MANAGER && (*it)->getRealClassID() != CL_HANDSHAKE )
-    {
-
-      if ( !writeToClientBuffer( outBuffer[userID], (*it)->getRealClassID() ) )
+    if ( (*it)->getLeafID() != CL_NETWORK_GAME_MANAGER && (*it)->getLeafID() != CL_HANDSHAKE )
+    {
+
+      if ( !writeToClientBuffer( outBuffer[userID], (int)((*it)->getLeafID()) ) )
         return;
 
@@ -425,8 +426,4 @@
     PRINTF(1)("Could not fabricate Object with classID %x\n", classID);
     return;
-  }
-  else
-  {
-    //PRINTF(0)("Fabricated entity: %s\n", b->getClassName());
   }
 
@@ -439,4 +436,5 @@
     if ( !isServer() )
       s->setIsOutOfSync( true );
+    PRINTF(0)("Fabricated %s with id %d\n", s->getClassName(), s->getUniqueID());
   }
   else
Index: branches/network/src/lib/network/synchronizeable.h
===================================================================
--- branches/network/src/lib/network/synchronizeable.h	(revision 6273)
+++ branches/network/src/lib/network/synchronizeable.h	(revision 6275)
@@ -21,13 +21,103 @@
 #define STATE_REQUESTEDSYNC 4
 
+
 //macros to help writing data in byte buffer
-#define SYNCHELP_WRITE_BEGIN() {  int __synchelp_write_i = 0; \
-                                  bool __synchelp_write_err = false; \
-                                  int __synchelp_write_n; }
+/*
+ * 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!
+ *
+ *
+ * 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_RESET() { __synchelp_write_i = 0; __synchelp_write_err = false; }
-#define SYNCHELP_WRITE_INT(i) { __synchelp_write_n =  }
-#define SYNCHELP_WIRTE_FLOAT()
-#define SYNCHELP_WRITE_BYTE()
-#define SYNCHELP_WRITE_STRING()
+#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) { __synchelp_write_n = \
+                                Converter::stringToByteArray( s, data+__synchelp_write_i, strlen(s), 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_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; \
+} \
+                                    __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; \
+} \
+                                    __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; \
+} \
+}
+#define SYNCHELP_READ_BYTE(b)      { \
+                                    if ( length-__synchelp_read_i < 1 ) \
+{ \
+                                      PRINTF(1)("There is not enough data to read a byte\n");  \
+                                      return; \
+} \
+                                    b = data[__synchelp_read_i]; \
+                                    __synchelp_read_i ++;  \
+}
 
 class NetworkStream;
Index: branches/network/src/world_entities/skybox.cc
===================================================================
--- branches/network/src/world_entities/skybox.cc	(revision 6273)
+++ branches/network/src/world_entities/skybox.cc	(revision 6275)
@@ -218,8 +218,12 @@
   setIsOutOfSync( false );
 
-  int flsize = Converter::byteArrayToFloat( data, &size );
-  Converter::byteArrayToString( data+flsize, textureName, length-flsize );
-
-  PRINT(0)("GOT DATA: size=%f texture=%s\n", size, textureName);
+  /*int flsize = Converter::byteArrayToFloat( data, &size );
+  Converter::byteArrayToString( data+flsize, textureName, length-flsize );*/
+
+  SYNCHELP_READ_BEGIN();
+  SYNCHELP_READ_FLOAT(size);
+  SYNCHELP_READ_STRING( textureName, 1024 );
+
+  //PRINT(0)("GOT DATA: size=%f texture=%s\n", size, textureName);
 
   this->setSize( size );
@@ -228,9 +232,11 @@
 }
 
+
+
 int SkyBox::readBytes( byte * data, int maxLength, int * reciever )
 {
   if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() )
   {
-    PRINTF(0)("Requesting sync! %d\n", this->getUniqueID());
+    //PRINTF(0)("Requesting sync! %d\n", this->getUniqueID());
     (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() );
     setRequestedSync( true );
@@ -240,23 +246,12 @@
   if ( rec > 0 )
   {
-    PRINTF(0)("Serving client %d which requested sync %d size=%f texture=%s\n", rec, this->getUniqueID(), this->size, this->textureName);
+    //PRINTF(0)("Serving client %d which requested sync %d size=%f texture=%s\n", rec, this->getUniqueID(), this->size, this->textureName);
     *reciever = rec;
 
-    int flsize = Converter::floatToByteArray( this->size, data, maxLength );
-
-    if ( flsize <= 0 )
-    {
-      PRINTF(1)("Byte array is too small (%d) to store float\n", maxLength );
-      return 0;
-    }
-
-    if ( strlen(textureName)+INTSIZE+flsize > maxLength )
-    {
-      PRINTF(1)("Byte array is too small (%d) to store data\n", maxLength );
-      return 0;
-    }
-
-    return flsize + Converter::stringToByteArray( textureName, data+flsize, strlen(textureName), maxLength-flsize );
-
+    SYNCHELP_WRITE_BEGIN();
+    SYNCHELP_WRITE_FLOAT(this->size);
+    SYNCHELP_WRITE_STRING(this->textureName);
+
+    return SYNCHELP_WRITE_N;
   }
 
Index: branches/network/src/world_entities/terrain.cc
===================================================================
--- branches/network/src/world_entities/terrain.cc	(revision 6273)
+++ branches/network/src/world_entities/terrain.cc	(revision 6275)
@@ -24,4 +24,6 @@
 #include "resource_manager.h"
 #include "model.h"
+#include "network_game_manager.h"
+
 
 #include "glincl.h"
@@ -57,4 +59,5 @@
     {
       this->loadModel(fileName);
+      strncpy( terrainFile, fileName, 1024 );
     }
   else
@@ -98,4 +101,6 @@
   this->ssp = NULL;
   this->vegetation = NULL;
+  strncpy( this->vegetationFile, "", 1024 );
+  strncpy( this->terrainFile, "", 1024 );
 }
 
@@ -111,4 +116,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 +122,6 @@
   {
     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);
+    strncpy( this->vegetationFile, vegetationFile, 1024);
   }
   else
@@ -315,2 +322,58 @@
     }
 }
+
+void Terrain::writeBytes( const byte * data, int length, int sender )
+{
+  setRequestedSync( false );
+  setIsOutOfSync( false );
+
+  int n = Converter::byteArrayToString( data, vegetationFile, length );
+  Converter::byteArrayToString( data+n, terrainFile, length-n );
+
+  //PRINT(0)("GOT DATA: size=%f texture=%s\n", size, textureName);
+
+  if ( strcmp(vegetationFile, "") )
+    this->loadVegetation( vegetationFile );
+  if ( strcmp(terrainFile, "") )
+    this->loadModel( terrainFile );
+
+}
+
+int Terrain::readBytes( byte * data, int maxLength, int * reciever )
+{
+  if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() )
+  {
+    //PRINTF(0)("Requesting sync! %d\n", this->getUniqueID());
+    (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() );
+    setRequestedSync( true );
+  }
+
+  int rec = this->getRequestSync();
+  if ( rec > 0 )
+  {
+    //PRINTF(0)("Serving client %d which requested sync %d size=%f texture=%s\n", rec, this->getUniqueID(), this->size, this->textureName);
+    *reciever = rec;
+
+    if ( strlen(vegetationFile)+INTSIZE > maxLength )
+    {
+      PRINTF(1)("Byte array is too small (%d) to store data\n", maxLength );
+      return 0;
+    }
+
+    int n = Converter::stringToByteArray( vegetationFile, data, strlen(vegetationFile), maxLength );
+
+    return n + Converter::stringToByteArray( terrainFile, data+n, strlen(terrainFile), maxLength-n );
+
+  }
+
+  *reciever = 0;
+  return 0;
+}
+
+void Terrain::writeDebug( ) const
+{
+}
+
+void Terrain::readDebug( ) const
+{
+}
Index: branches/network/src/world_entities/terrain.h
===================================================================
--- branches/network/src/world_entities/terrain.h	(revision 6273)
+++ branches/network/src/world_entities/terrain.h	(revision 6275)
@@ -30,4 +30,9 @@
   virtual ~Terrain();
 
+  virtual void      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,6 @@
    Model*              vegetation;
    int                 objectList;
+   char                vegetationFile[1024];
+   char                terrainFile[1024];
 };
 
