Index: branches/network/src/lib/network/converter.cc
===================================================================
--- branches/network/src/lib/network/converter.cc	(revision 6258)
+++ branches/network/src/lib/network/converter.cc	(revision 6273)
@@ -92,5 +92,5 @@
     return -1;
   }
-  
+
   const int mod = 256; // = 2^8
 
@@ -405,2 +405,49 @@
   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 );
+    return -1;
+  }
+
+  memcpy( s, a+n, length );
+  s[length] = '\0';
+
+  return n+length;
+}
Index: branches/network/src/lib/network/converter.h
===================================================================
--- branches/network/src/lib/network/converter.h	(revision 6258)
+++ branches/network/src/lib/network/converter.h	(revision 6273)
@@ -32,5 +32,8 @@
     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);
+
     //Test
     static char* floatToBinString(float x);
Index: branches/network/src/lib/network/network_game_manager.cc
===================================================================
--- branches/network/src/lib/network/network_game_manager.cc	(revision 6258)
+++ branches/network/src/lib/network/network_game_manager.cc	(revision 6273)
@@ -353,5 +353,5 @@
     return;
 
-  if ( userID > outBuffer.size() )
+  if ( userID >= outBuffer.size() )
     resizeBufferVector( userID );
 
@@ -368,5 +368,5 @@
     return;
 
-  PRINTF(0)("SendEntityList: n = %d\n", networkStream->getSyncCount()-2 );
+  //PRINTF(0)("SendEntityList: n = %d\n", networkStream->getSyncCount()-2 );
 
   while ( it != e )
@@ -378,5 +378,5 @@
         return;
 
-      PRINTF(0)("SendEntityList: ClassID = %x\n", (*it)->getRealClassID());
+      //PRINTF(0)("SendEntityList: ClassID = %x\n", (*it)->getRealClassID());
 
       if ( !writeToClientBuffer( outBuffer[userID], (*it)->getUniqueID() ) )
@@ -428,5 +428,5 @@
   else
   {
-    PRINTF(0)("Fabricated entity: %s\n", b->getClassName());
+    //PRINTF(0)("Fabricated entity: %s\n", b->getClassName());
   }
 
@@ -437,4 +437,6 @@
     s->setOwner( owner );
     this->networkStream->connectSynchronizeable( *s );
+    if ( !isServer() )
+      s->setIsOutOfSync( true );
   }
   else
@@ -769,2 +771,24 @@
 }
 
+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/src/lib/network/network_game_manager.h
===================================================================
--- branches/network/src/lib/network/network_game_manager.h	(revision 6258)
+++ branches/network/src/lib/network/network_game_manager.h	(revision 6273)
@@ -77,5 +77,5 @@
     void sendYouAre( int uniqueID, int userID );
 
-    void sync(int uniqueID);
+    void sync(int uniqueID, int owner);
 
     void sendEntityList(int userID);
@@ -89,4 +89,6 @@
     void requestRemoveEntity(int uniqueID);
     void executeRemoveEntity(int uniqueID);
+
+    void executeRequestSync( int uniqueID, int user );
 
     void doCreateEntity(ClassID classID, int uniqueID, int owner);
Index: branches/network/src/lib/network/network_protocol.cc
===================================================================
--- branches/network/src/lib/network/network_protocol.cc	(revision 6258)
+++ branches/network/src/lib/network/network_protocol.cc	(revision 6273)
@@ -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;
 }
 
@@ -74,7 +76,10 @@
   //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 );
 
 
@@ -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/src/lib/network/network_protocol.h
===================================================================
--- branches/network/src/lib/network/network_protocol.h	(revision 6258)
+++ branches/network/src/lib/network/network_protocol.h	(revision 6273)
@@ -14,6 +14,6 @@
 typedef struct Header
 {
-  byte synchronizeableID;
-  byte length;
+  int synchronizeableID;
+  int length;
 };
 
Index: branches/network/src/lib/network/network_stream.cc
===================================================================
--- branches/network/src/lib/network/network_stream.cc	(revision 6258)
+++ branches/network/src/lib/network/network_stream.cc	(revision 6273)
@@ -215,5 +215,5 @@
   for (SynchronizeableList::iterator it = synchronizeables.begin(); it!=synchronizeables.end(); it++)
   {
-    if ( (*it)!=NULL && (*it)->getOwner() == myHostId )
+    if ( (*it)!=NULL /*&& (*it)->getOwner() == myHostId*/ )
     {
       do {
@@ -276,7 +276,8 @@
           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 )
Index: branches/network/src/lib/network/synchronizeable.cc
===================================================================
--- branches/network/src/lib/network/synchronizeable.cc	(revision 6258)
+++ branches/network/src/lib/network/synchronizeable.cc	(revision 6273)
@@ -30,8 +30,10 @@
   this->setClassID(CL_SYNCHRONIZEABLE, "Synchronizeable");
   owner = 0;
+  state = 0;
   hostID = NetworkManager::getInstance()->getHostID();
   this->setIsServer(this->hostID == 0);
   uniqueID = -1;
   this->networkStream = NULL;
+  this->setRequestedSync( false );
 }
 
@@ -94,4 +96,5 @@
   else
     this->state = this->state & (~STATE_OUTOFSYNC);
+  //PRINTF(0)("isoutofsync %s %d\n", this->getClassName(), state);
 }
 
@@ -102,5 +105,5 @@
 bool Synchronizeable::isServer()
 {
-  return this->state & STATE_SERVER == STATE_SERVER;
+  return (this->state & STATE_SERVER) >0;
 }
 
@@ -111,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/src/lib/network/synchronizeable.h
===================================================================
--- branches/network/src/lib/network/synchronizeable.h	(revision 6258)
+++ branches/network/src/lib/network/synchronizeable.h	(revision 6273)
@@ -9,4 +9,5 @@
 #include "base_object.h"
 #include "netdefs.h"
+#include "converter.h"
 
 
@@ -18,4 +19,15 @@
 #define STATE_SERVER 1
 #define STATE_OUTOFSYNC 2
+#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; }
+#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()
 
 class NetworkStream;
@@ -35,9 +47,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; }
@@ -55,9 +71,10 @@
     int owner;
     int hostID;
-    int state;
+
     std::list<int> synchronizeRequests;
 
   protected:
     NetworkStream* networkStream;
+    int state;
 
   };
Index: branches/network/src/world_entities/skybox.cc
===================================================================
--- branches/network/src/world_entities/skybox.cc	(revision 6258)
+++ branches/network/src/world_entities/skybox.cc	(revision 6273)
@@ -22,4 +22,6 @@
 #include "static_model.h"
 #include "material.h"
+#include "network_game_manager.h"
+#include "converter.h"
 
 using namespace std;
@@ -210,2 +212,62 @@
   this->setModel(model);
 }
+
+void SkyBox::writeBytes( const byte * data, int length, int sender )
+{
+  setRequestedSync( false );
+  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);
+
+  this->setSize( size );
+  this->setTexture( textureName );
+  this->rebuild();
+}
+
+int SkyBox::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;
+
+    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 );
+
+  }
+
+  *reciever = 0;
+  return 0;
+}
+
+void SkyBox::writeDebug( ) const
+{
+}
+
+void SkyBox::readDebug( ) const
+{
+}
Index: branches/network/src/world_entities/skybox.h
===================================================================
--- branches/network/src/world_entities/skybox.h	(revision 6258)
+++ branches/network/src/world_entities/skybox.h	(revision 6273)
@@ -35,5 +35,5 @@
   void setSize(float size);
   /** assumes jpg as input-format */
-  void setTexture(const char* name) { this->setTextureAndType (name, "jpg"); };
+  void setTexture(const char* name) { strncpy(textureName, name, 1024); this->setTextureAndType (name, "jpg"); };
 
   void setTextureAndType(const char* name, const char* extension);
@@ -41,9 +41,15 @@
                    const char* right, const char* front, const char* back);
 
+  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;
+
  private:
   void rebuild();
 
-  Material**      material;        //!< 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.
+  Material**      material;          //!< 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[1024]; //!< Name of the Texture
 
 };
