Index: /branches/network/src/defs/class_id.h
===================================================================
--- /branches/network/src/defs/class_id.h	(revision 7630)
+++ /branches/network/src/defs/class_id.h	(revision 7631)
@@ -330,4 +330,6 @@
   CL_HANDSHAKE                  =    0x00000d06,
   CL_NETWORK_GAME_MANAGER       =    0x00000d07,
+  CL_MESSAGE_MANAGER            =    0x00000d08,
+  CL_SIMPLE_SYNC                =    0x00000d09,
 
 
Index: /branches/network/src/lib/network/Makefile.am
===================================================================
--- /branches/network/src/lib/network/Makefile.am	(revision 7630)
+++ /branches/network/src/lib/network/Makefile.am	(revision 7631)
@@ -20,4 +20,5 @@
 		      network_game_manager.cc \
 		      converter.cc \
+		      message_manager.cc \
 		      \
 		      synchronizeable_var/synchronizeable_var.cc \
@@ -50,4 +51,5 @@
 		 converter.h \
 		 netdefs.h \
+		 message_manager.h \
 		 \
 		 synchronizeable_var/synchronizeable_var.h \
Index: /branches/network/src/lib/network/converter.cc
===================================================================
--- /branches/network/src/lib/network/converter.cc	(revision 7630)
+++ /branches/network/src/lib/network/converter.cc	(revision 7631)
@@ -493,5 +493,5 @@
   }
 
-  s[0] = '\0';
+  s = "";
   s.append( (char*)a+n, length );
 
Index: /branches/network/src/lib/network/message_manager.cc
===================================================================
--- /branches/network/src/lib/network/message_manager.cc	(revision 7631)
+++ /branches/network/src/lib/network/message_manager.cc	(revision 7631)
@@ -0,0 +1,78 @@
+/*
+   orxonox - the future of 3D-vertical-scrollers
+
+   Copyright (C) 2004 orx
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   ### File Specific:
+   main-programmer: Christoph Renner
+   co-programmer: ...
+*/
+
+//#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_
+
+#include "message_manager.h"
+
+using namespace std;
+
+
+/**
+ * standard constructor
+*/
+MessageManager::MessageManager ()
+{
+  this->setClassID( CL_MESSAGE_MANAGER, "MessageManager" );
+}
+
+
+/**
+ * standard deconstructor
+*/
+MessageManager::~MessageManager ()
+{
+}
+
+/**
+ * get the diff to last acked state of userId
+ *
+ * each synchrinizeable defines its own stack of states received and sent over the network. The stack contains
+ * a per user entry for the last sent/received state This function returns a delta compressed state of the
+ * synchronizeable. This state will be transmitted over the network to the other participants
+ *
+ * @param userId user to create diff for
+ * @param data buffer to copy diff in
+ * @param maxLength max bytes to copy into data
+ * @param stateId id of current state
+ * @param fromStateId the reference state for the delta state
+ * @param priorityTH tells getStateDiff to not send element with priority \< priorityTH
+ * @return n bytes copied into data
+ */
+int MessageManager::getStateDiff( int userId, byte * data, int maxLength, int stateId, int fromStateId, int priorityTH )
+{
+}
+
+/**
+ * sets a new state out of a diff created on another host
+ * @param userId hostId of user who send me that diff
+ * @param data pointer to diff
+ * @param length length of diff
+ * @param stateId id of current state
+ * @param fromStateId id of the base state id
+ * @return number bytes read
+ * @todo check for permissions
+ */
+int MessageManager::setStateDiff( int userId, byte * data, int length, int stateId, int fromStateId )
+{
+}
+
+/**
+ * clean up memory reserved for user
+ * @param userId userid
+ */
+void MessageManager::cleanUpUser( int userId )
+{
+}
Index: /branches/network/src/lib/network/message_manager.h
===================================================================
--- /branches/network/src/lib/network/message_manager.h	(revision 7631)
+++ /branches/network/src/lib/network/message_manager.h	(revision 7631)
@@ -0,0 +1,29 @@
+/*!
+ * @file message_manager.h
+ * @brief Definition of MessageManager
+*/
+
+#ifndef _MESSAGE_MANAGER_H
+#define _MESSAGE_MANAGER_H
+
+#include "synchronizeable.h"
+
+// FORWARD DECLARATION
+
+//! A class for sending messages over network
+class MessageManager : public Synchronizeable {
+
+ public:
+   MessageManager();
+   virtual ~MessageManager();
+
+   virtual int getStateDiff( int userId, byte* data, int maxLength, int stateId, int fromStateId, int priorityTH );
+   virtual int setStateDiff( int userId, byte* data, int length, int stateId, int fromStateId );
+   virtual void cleanUpUser( int userId );
+
+
+ private:
+
+};
+
+#endif /* _PROTO_CLASS_H */
Index: /branches/network/src/lib/network/network_stream.cc
===================================================================
--- /branches/network/src/lib/network/network_stream.cc	(revision 7630)
+++ /branches/network/src/lib/network/network_stream.cc	(revision 7631)
@@ -62,4 +62,6 @@
   this->init();
   this->peers[0].socket = new UdpSocket( host, port );
+  this->peers[0].userId = 0;
+  this->peers[0].isServer = true;
   this->networkProtocol = new NetworkProtocol();
   this->connectionMonitor = new ConnectionMonitor();
@@ -357,4 +359,5 @@
       peers[clientId].handshake->setUniqueID(clientId);
       peers[clientId].userId = clientId;
+      peers[clientId].isServer = false;
     } else
     {
@@ -369,4 +372,5 @@
       peers[clientId].handshake->setUniqueID(clientId);
       peers[clientId].userId = clientId;
+      peers[clientId].isServer = false;
       
       PRINTF(0)("num sync: %d\n", synchronizeables.size());
@@ -400,5 +404,9 @@
         delete it->second.handshake;
       it->second.handshake = NULL;
-
+      
+      for ( SynchronizeableList::iterator it2 = synchronizeables.begin(); it2 != synchronizeables.end(); it2++ )
+      {
+        (*it2)->cleanUpUser( it->second.userId );
+      }
 
       NetworkGameManager::getInstance()->signalLeftPlayer(it->second.userId);
@@ -632,5 +640,8 @@
         int leafClassId;
         if ( INTSIZE > length - offset )
-          break;
+        {
+          offset += syncDataLength;
+          continue;
+        }
         
         Converter::byteArrayToInt( buf + offset, &leafClassId );
@@ -639,8 +650,9 @@
         /* These are some small exeptions in creation: Not all objects can/should be created via Factory */
         /* Exception 1: NullParent */
-        if( leafClassId == CL_NULL_PARENT)
-        {
-          PRINTF(1)("Can not create Class with ID %x!", (int)leafClassId);
-          break;
+        if( leafClassId == CL_NULL_PARENT || leafClassId == CL_SYNCHRONIZEABLE )
+        {
+          PRINTF(1)("Can not create Class with ID %x!\n", (int)leafClassId);
+          offset += syncDataLength;
+          continue;
         }
         else
@@ -650,5 +662,6 @@
         {
           PRINTF(1)("Could not fabricate Object with classID %x\n", leafClassId);
-          break;
+          offset += syncDataLength;
+          continue;
         }
         
@@ -663,7 +676,8 @@
         else
         {
-          PRINTF(1)("Class with ID %x is not a synchronizeable!", (int)leafClassId);
+          PRINTF(1)("Class with ID %x is not a synchronizeable!\n", (int)leafClassId);
           delete b;
-          break;
+          offset += syncDataLength;
+          continue;
         }
       }
Index: /branches/network/src/lib/network/network_stream.h
===================================================================
--- /branches/network/src/lib/network/network_stream.h	(revision 7630)
+++ /branches/network/src/lib/network/network_stream.h	(revision 7631)
@@ -69,4 +69,5 @@
 
     inline bool isUserIdActive( int userID ) { return (peers.find(userID) != peers.end()); }
+    inline bool isUserServer( int userID ){ if ( !isUserIdActive(userID) ) return false; return peers[userID].isServer; }
 
     void debug();
Index: /branches/network/src/lib/network/synchronizeable.cc
===================================================================
--- /branches/network/src/lib/network/synchronizeable.cc	(revision 7630)
+++ /branches/network/src/lib/network/synchronizeable.cc	(revision 7631)
@@ -92,19 +92,5 @@
 
 
-/**
- * get the diff to last acked state of userId
- *
- * each synchrinizeable defines its own stack of states received and sent over the network. The stack contains
- * a per user entry for the last sent/received state This function returns a delta compressed state of the
- * synchronizeable. This state will be transmitted over the network to the other participants
- *
- * @param userId user to create diff for
- * @param data buffer to copy diff in
- * @param maxLength max bytes to copy into data
- * @param stateId id of current state
- * @param fromStateId the reference state for the delta state
- * @param priorityTH tells getStateDiff to not send element with priority \< priorityTH
- * @return n bytes copied into data
- */
+
 int Synchronizeable::getStateDiff( int userId, byte* data, int maxLength, int stateId, int fromStateId, int priorityTH )
 {
@@ -119,5 +105,9 @@
     neededSize += (*it)->getSize();
 
-  assert( neededSize <= maxLength );
+  if ( !( neededSize <= maxLength ) )
+  {
+    PRINTF(0)( "%d > %d\n", neededSize, maxLength );
+    assert(false);
+  }
 
   //remove older states from history than fromStateId
@@ -170,10 +160,17 @@
   int i = 0;
   int n;
+  
+  bool hasPermission;
 
   // now do the actual synchronization: kick all variables to write into a common buffer
   for ( SyncVarList::iterator it = syncVarList.begin(); it != syncVarList.end(); it++ )
   {
-    PRINTF(0)("SIZE: %d\n", syncVarList.size());
-    if ( (*it)->getPriority() >= priorityTH || sizeIter == stateFrom->sizeList.end() )
+    hasPermission = (
+            this->isServer() && (*it)->checkPermission( PERMISSION_SERVER ) ||
+            this->owner == this->hostID && (*it)->checkPermission( PERMISSION_OWNER ) ||
+            (*it)->checkPermission( PERMISSION_ALL ) 
+                    );
+    
+    if ( ( hasPermission && (*it)->getPriority() >= priorityTH ) || sizeIter == stateFrom->sizeList.end() )
     {
       (*it)->debug();
@@ -182,11 +179,7 @@
       i += n;
     }
-    else if ( ! (
-                 this->isServer() && (*it)->checkPremission( PERMISSION_SERVER ) ||
-                 this->owner == this->hostID && (*it)->checkPremission( PERMISSION_OWNER ) ||
-                 (*it)->checkPremission( PERMISSION_ALL ) 
-                ) )
-    {
-      for ( int j = 0; j < (*it)->getSize(); it++ )
+    else if ( ! hasPermission )
+    {
+      for ( int j = 0; j < (*it)->getSize(); j++ )
       {
         assert(false);
@@ -287,6 +280,4 @@
     stateFrom = (*it);
   
-  std::list<int> changes;
-  
   //apply diff
   for ( int i = 0; i<length; i++ )
@@ -297,6 +288,4 @@
       stateTo->data[i] = data[i];
     
-    if ( data[i] != 0 )
-      changes.push_back(i);
   }
 
@@ -305,8 +294,23 @@
   
   int i = 0;
-
+  std::list<int> changes;
+  
   for ( SyncVarList::iterator it = syncVarList.begin(); it != syncVarList.end(); it++ )
   {
-    i += (*it)->readFromBuf( stateTo->data + i, stateTo->dataLength - i );
+    if (
+        (*it)->checkPermission( PERMISSION_SERVER ) && networkStream->isUserServer( userId ) ||
+        (*it)->checkPermission( PERMISSION_OWNER ) && this->owner == userId ||
+        (*it)->checkPermission( PERMISSION_ALL ) 
+       )
+    {
+      i += (*it)->readFromBuf( stateTo->data + i, stateTo->dataLength - i );
+      if ( (*it)->getHasChanged() )
+        changes.push_back( (*it)->getVarId() );
+    }
+    else
+    {
+      PRINTF(0)("DONT SET VAR BECAUSE OF PERMISSION: %s %d %d %d %d %d %d\n", (*it)->getName().c_str(), (*it)->checkPermission( PERMISSION_SERVER ), (*it)->checkPermission( PERMISSION_OWNER ), (*it)->checkPermission( PERMISSION_ALL ), networkStream->isUserServer( userId ), this->owner, userId );
+      i += (*it)->getSizeFromBuf( stateTo->data + i, stateTo->dataLength - i );
+    }
   }
 
@@ -331,4 +335,5 @@
 void Synchronizeable::registerVar( SynchronizeableVar * var )
 {
+  PRINTF(0)("ADDING var: %s (%s)\n", var->getName().c_str(), this->getName() );
   syncVarList.push_back( var );
 }
@@ -342,8 +347,46 @@
 int Synchronizeable::registerVarId( SynchronizeableVar * var )
 {
+  PRINTF(0)("ADDING var: %s (%s)\n", var->getName().c_str(), this->getName() );
   syncVarList.push_back( var );
+  var->setWatched( true );
+  var->setVarId( syncVarList.size()-1 );
   return syncVarList.size()-1;
 }
 
-
-
+/**
+ * removed user's states from memory
+ * @param userId user to clean
+ */
+void Synchronizeable::cleanUpUser( int userId )
+{
+  for ( UserStateHistory::iterator it = sentStates.begin(); it != sentStates.end(); it++ )
+  {
+    for ( StateHistory::iterator it2 = it->begin(); it2 != it->end(); it++ )
+    {
+      if ( (*it2)->data )
+        delete (*it2)->data;
+      (*it2)->data = NULL;
+      
+      delete *it2;
+    }
+  }
+  
+  sentStates.clear();
+  
+  for ( UserStateHistory::iterator it = recvStates.begin(); it != recvStates.end(); it++ )
+  {
+    for ( StateHistory::iterator it2 = it->begin(); it2 != it->end(); it++ )
+    {
+      if ( (*it2)->data )
+        delete (*it2)->data;
+      (*it2)->data = NULL;
+      
+      delete *it2;
+    }
+  }
+  
+  recvStates.clear();
+}
+
+
+
Index: /branches/network/src/lib/network/synchronizeable.h
===================================================================
--- /branches/network/src/lib/network/synchronizeable.h	(revision 7630)
+++ /branches/network/src/lib/network/synchronizeable.h	(revision 7631)
@@ -40,10 +40,4 @@
 typedef std::vector<StateHistory> UserStateHistory;
 
-enum {
-  PERMISSION_SERVER = 1,
-  PERMISSION_OWNER  = 2,
-  PERMISSION_ALL    = 4
-};
-
 typedef std::vector<SynchronizeableVar*> SyncVarList;
 
@@ -62,6 +56,7 @@
     virtual void varChangeHandler( std::list<int> & id );
 
-    int getStateDiff( int userId, byte* data, int maxLength, int stateId, int fromStateId, int priorityTH );
-    int setStateDiff( int userId, byte* data, int length, int stateId, int fromStateId );
+    virtual int getStateDiff( int userId, byte* data, int maxLength, int stateId, int fromStateId, int priorityTH );
+    virtual int setStateDiff( int userId, byte* data, int length, int stateId, int fromStateId );
+    virtual void cleanUpUser( int userId );
 
     void registerVar( SynchronizeableVar * var );
Index: /branches/network/src/lib/network/synchronizeable_var/synchronizeable_bool.cc
===================================================================
--- /branches/network/src/lib/network/synchronizeable_var/synchronizeable_bool.cc	(revision 7630)
+++ /branches/network/src/lib/network/synchronizeable_var/synchronizeable_bool.cc	(revision 7631)
@@ -60,5 +60,9 @@
   assert( maxLength >= 1 );
   
+  bool oldVal = *vPtrOut;
+  
   *vPtrOut = buf[0] != 0;
+  
+  setHasChanged( oldVal != *vPtrOut );
   
   return 1;
Index: /branches/network/src/lib/network/synchronizeable_var/synchronizeable_bool.h
===================================================================
--- /branches/network/src/lib/network/synchronizeable_var/synchronizeable_bool.h	(revision 7630)
+++ /branches/network/src/lib/network/synchronizeable_var/synchronizeable_bool.h	(revision 7631)
@@ -12,5 +12,5 @@
 
   public:
-    SynchronizeableBool( bool * ptrIn, bool * ptrOut, std::string name, int permission = 0, int priority = 0 );
+    SynchronizeableBool( bool * ptrIn, bool * ptrOut, std::string name, int permission = PERMISSION_SERVER, int priority = 0 );
     virtual ~SynchronizeableBool();
     
Index: /branches/network/src/lib/network/synchronizeable_var/synchronizeable_float.cc
===================================================================
--- /branches/network/src/lib/network/synchronizeable_var/synchronizeable_float.cc	(revision 7630)
+++ /branches/network/src/lib/network/synchronizeable_var/synchronizeable_float.cc	(revision 7631)
@@ -62,5 +62,9 @@
   assert( maxLength >= FLOATSIZE );
   
+  float oldVal = *vPtrOut;
+  
   int res = Converter::byteArrayToFloat( buf, vPtrOut );
+  
+  setHasChanged( oldVal != *vPtrOut );
   
   assert( res == FLOATSIZE );
Index: /branches/network/src/lib/network/synchronizeable_var/synchronizeable_float.h
===================================================================
--- /branches/network/src/lib/network/synchronizeable_var/synchronizeable_float.h	(revision 7630)
+++ /branches/network/src/lib/network/synchronizeable_var/synchronizeable_float.h	(revision 7631)
@@ -12,5 +12,5 @@
 
   public:
-    SynchronizeableFloat( float * ptrIn, float * ptrOut, std::string name, int permission = 0, int priority = 0 );
+    SynchronizeableFloat( float * ptrIn, float * ptrOut, std::string name, int permission = PERMISSION_SERVER, int priority = 0 );
     virtual ~SynchronizeableFloat();
     
Index: /branches/network/src/lib/network/synchronizeable_var/synchronizeable_int.cc
===================================================================
--- /branches/network/src/lib/network/synchronizeable_var/synchronizeable_int.cc	(revision 7630)
+++ /branches/network/src/lib/network/synchronizeable_var/synchronizeable_int.cc	(revision 7631)
@@ -62,5 +62,9 @@
   assert( maxLength >= INTSIZE );
   
+  int oldVal = *vPtrOut;
+  
   int res = Converter::byteArrayToInt( buf, vPtrOut );
+  
+  setHasChanged( oldVal != *vPtrOut );
   
   assert( res == INTSIZE );
Index: /branches/network/src/lib/network/synchronizeable_var/synchronizeable_int.h
===================================================================
--- /branches/network/src/lib/network/synchronizeable_var/synchronizeable_int.h	(revision 7630)
+++ /branches/network/src/lib/network/synchronizeable_var/synchronizeable_int.h	(revision 7631)
@@ -12,5 +12,5 @@
 
   public:
-    SynchronizeableInt( int * ptrIn, int * ptrOut, std::string name, int permission = 0, int priority = 0 );
+    SynchronizeableInt( int * ptrIn, int * ptrOut, std::string name, int permission = PERMISSION_SERVER, int priority = 0 );
     virtual ~SynchronizeableInt();
     
Index: /branches/network/src/lib/network/synchronizeable_var/synchronizeable_quaternion.cc
===================================================================
--- /branches/network/src/lib/network/synchronizeable_var/synchronizeable_quaternion.cc	(revision 7630)
+++ /branches/network/src/lib/network/synchronizeable_var/synchronizeable_quaternion.cc	(revision 7631)
@@ -98,6 +98,10 @@
   assert( res > 0 );
   n += res;
+  
+  Quaternion oldVal = *vPtrOut;
 
   *vPtrOut = Quaternion( Vector(x, y, z), w );
+  
+  setHasChanged( ! ( oldVal == *vPtrOut ) );
 
   assert( n == 4*FLOATSIZE );
Index: /branches/network/src/lib/network/synchronizeable_var/synchronizeable_quaternion.h
===================================================================
--- /branches/network/src/lib/network/synchronizeable_var/synchronizeable_quaternion.h	(revision 7630)
+++ /branches/network/src/lib/network/synchronizeable_var/synchronizeable_quaternion.h	(revision 7631)
@@ -14,5 +14,5 @@
 
   public:
-    SynchronizeableQuaternion( Quaternion * ptrIn, Quaternion * ptrOut, std::string name, int permission = 0, int priority = 0 );
+    SynchronizeableQuaternion( Quaternion * ptrIn, Quaternion * ptrOut, std::string name, int permission = PERMISSION_SERVER, int priority = 0 );
     virtual ~SynchronizeableQuaternion();
     
Index: /branches/network/src/lib/network/synchronizeable_var/synchronizeable_string.cc
===================================================================
--- /branches/network/src/lib/network/synchronizeable_var/synchronizeable_string.cc	(revision 7630)
+++ /branches/network/src/lib/network/synchronizeable_var/synchronizeable_string.cc	(revision 7631)
@@ -60,5 +60,9 @@
 int SynchronizeableString::readFromBuf( byte * buf, int maxLength )
 {
+  std::string oldVal = *vPtrOut;
+      
   int res = Converter::byteArrayToString( buf, *vPtrOut, maxLength );
+  
+  setHasChanged( oldVal != *vPtrOut );
   
   assert( res > 0 );
@@ -76,2 +80,21 @@
 
 
+/**
+ * reads actual size from buffer. this is used when size is not constant
+ * @param buf pointer to data
+ * @param maxLength maximal size of data
+ * @return same as readFromBuf would return
+ */
+int SynchronizeableString::getSizeFromBuf( byte * buf, int maxLength )
+{
+  std::string t;
+  
+  int res = Converter::byteArrayToString( buf, t, maxLength );
+
+  
+  assert( res > 0 );
+  
+  return res;
+}
+
+
Index: /branches/network/src/lib/network/synchronizeable_var/synchronizeable_string.h
===================================================================
--- /branches/network/src/lib/network/synchronizeable_var/synchronizeable_string.h	(revision 7630)
+++ /branches/network/src/lib/network/synchronizeable_var/synchronizeable_string.h	(revision 7631)
@@ -15,5 +15,5 @@
 
   public:
-    SynchronizeableString( std::string * ptrIn, std::string * ptrOut, std::string name, int permission = 0, int priority = 0 );
+    SynchronizeableString( std::string * ptrIn, std::string * ptrOut, std::string name, int permission = PERMISSION_SERVER, int priority = 0 );
     virtual ~SynchronizeableString();
     
@@ -30,4 +30,6 @@
     virtual int getSize(){ return vPtrIn->length()+INTSIZE; }
     
+    virtual int getSizeFromBuf( byte * buf, int maxLength );
+    
     virtual void debug();
     
Index: /branches/network/src/lib/network/synchronizeable_var/synchronizeable_uint.h
===================================================================
--- /branches/network/src/lib/network/synchronizeable_var/synchronizeable_uint.h	(revision 7630)
+++ /branches/network/src/lib/network/synchronizeable_var/synchronizeable_uint.h	(revision 7631)
@@ -12,5 +12,5 @@
 
   public:
-    SynchronizeableUInt( unsigned int * ptrIn, unsigned int * ptrOut, std::string name, int permission = 0, int priority = 0 );
+    SynchronizeableUInt( unsigned int * ptrIn, unsigned int * ptrOut, std::string name, int permission = PERMISSION_SERVER, int priority = 0 );
     virtual ~SynchronizeableUInt();
     
Index: /branches/network/src/lib/network/synchronizeable_var/synchronizeable_var.cc
===================================================================
--- /branches/network/src/lib/network/synchronizeable_var/synchronizeable_var.cc	(revision 7630)
+++ /branches/network/src/lib/network/synchronizeable_var/synchronizeable_var.cc	(revision 7631)
@@ -35,4 +35,5 @@
   this->realPriority = priority;
   this->name = name;
+  this->bWatched = false;
 }
 
Index: /branches/network/src/lib/network/synchronizeable_var/synchronizeable_var.h
===================================================================
--- /branches/network/src/lib/network/synchronizeable_var/synchronizeable_var.h	(revision 7630)
+++ /branches/network/src/lib/network/synchronizeable_var/synchronizeable_var.h	(revision 7631)
@@ -11,8 +11,14 @@
 #include <assert.h>
 
+enum {
+  PERMISSION_SERVER = 1,
+  PERMISSION_OWNER  = 2,
+  PERMISSION_ALL    = 4
+};
+
 class SynchronizeableVar {
 
   public:
-    SynchronizeableVar( void * ptrIn, void * ptrOut, std::string name, int length, int permission = 0, int priority = 0 );
+    SynchronizeableVar( void * ptrIn, void * ptrOut, std::string name, int length, int permission = PERMISSION_SERVER, int priority = 0 );
     virtual ~SynchronizeableVar();
 
@@ -22,4 +28,9 @@
      */
     inline bool beWatched(){ return this->bWatched; }
+    
+    /** 
+     * set flag if synchronizeable wants to be informed on changes
+     */
+    inline void setWatched( bool watched ){ this->bWatched = watched; }
 
     /**
@@ -55,5 +66,5 @@
      * @return true if you can write
      */
-    inline bool checkPremission( int permission ){ return (permission & this->permission) != 0; }
+    inline bool checkPermission( int permission ){ return (permission & this->permission) != 0; }
 
     /**
@@ -87,4 +98,36 @@
     
     /**
+     * reads actual size from buffer. this is used when size is not constant
+     * @param buf pointer to data
+     * @param maxLength maximal size of data
+     * @return same as readFromBuf would return
+     */
+    virtual inline int getSizeFromBuf( byte * buf, int maxLength ){ return this->getSize(); }
+    
+    /**
+     * set variable id
+     * @param id
+     */
+    inline void setVarId( int id ){ this->varId = id; }
+    
+    /** 
+     * get variable id
+     * @return variable id
+     */
+    inline int getVarId(){ return varId; }
+    
+    /**
+     * set hasChanged
+     * @param changed
+     */
+    inline void setHasChanged( bool changed ){ this->changed = changed; }
+    
+    /** 
+     * get hasChanged
+     * @return variable id
+     */
+    inline bool getHasChanged(){ return changed; }
+    
+    /**
      * print out variable value
      */
@@ -94,4 +137,11 @@
   private:
     bool bWatched;      //!< true if synchronizeable wants to be informed on changes
+    
+    int permission;     //!< who is allowed to change this var
+    int priority;       //!< priority assigned to var
+    int realPriority;   //!< priority assigned to var, increased every time not sent
+    int varId;          //!< id to identify varables
+    
+    bool changed;       //!< true if last readFromBuf changed anything
 
   protected:
@@ -99,7 +149,4 @@
     void * ptrOut;      //!< pointer to data (write)
     int length;         //!< data length
-    int permission;     //!< who is allowed to change this var
-    int priority;       //!< priority assigned to var
-    int realPriority;  //!< priority assigned to var, increased every time not sent
 
 
Index: /branches/network/src/lib/network/synchronizeable_var/synchronizeable_vector.h
===================================================================
--- /branches/network/src/lib/network/synchronizeable_var/synchronizeable_vector.h	(revision 7630)
+++ /branches/network/src/lib/network/synchronizeable_var/synchronizeable_vector.h	(revision 7631)
@@ -14,5 +14,5 @@
 
   public:
-    SynchronizeableVector( Vector * ptrIn, Vector * ptrOut, std::string name, int permission = 0, int priority = 0 );
+    SynchronizeableVector( Vector * ptrIn, Vector * ptrOut, std::string name, int permission = PERMISSION_SERVER, int priority = 0 );
     virtual ~SynchronizeableVector();
     
Index: /branches/network/src/subprojects/network/network_unit_test.cc
===================================================================
--- /branches/network/src/subprojects/network/network_unit_test.cc	(revision 7630)
+++ /branches/network/src/subprojects/network/network_unit_test.cc	(revision 7631)
@@ -259,4 +259,5 @@
   
   SimpleSync* ss = new SimpleSync("Server");
+  ss->setSynchronized( true );
 
   
@@ -292,12 +293,17 @@
   netMan->establishConnection("localhost", 9999);
   
-  SimpleSync* ss = new SimpleSync("SimpleSync");
-  netMan->connectSynchronizeable( *ss );
-
+//  SimpleSync* ss = new SimpleSync("SimpleSync");
+//  ss->setSynchronized( true );
+//  netMan->connectSynchronizeable( *ss );
+
+  SimpleSync * ss = NULL;
+  
   for(;;)
   {
     netMan->synchronize();
+    ss = dynamic_cast<SimpleSync*>(ClassList::getObject( "Server", CL_SIMPLE_SYNC ) );
     SDL_Delay(1000);
-    ss->debug();
+    if (ss)
+      ss->debug();
   }
 
Index: /branches/network/src/subprojects/network/simple_sync.cc
===================================================================
--- /branches/network/src/subprojects/network/simple_sync.cc	(revision 7630)
+++ /branches/network/src/subprojects/network/simple_sync.cc	(revision 7631)
@@ -22,5 +22,11 @@
 #include "simple_sync.h"
 
+#include "class_id.h"
+#include "fast_factory.h"
+#include "lib/util/loading/factory.h"
+
 #include "debug.h"
+
+CREATE_FACTORY(SimpleSync, CL_SIMPLE_SYNC);
 
 
@@ -31,4 +37,5 @@
 {
   setName( name );
+  this->setClassID( CL_SIMPLE_SYNC, "SimpleSync" );
   in = 0;
   out = 1;
@@ -49,4 +56,13 @@
 }
 
+SimpleSync::SimpleSync( const TiXmlElement * root )
+{
+  setName( "" );
+  this->setClassID( CL_SIMPLE_SYNC, "SimpleSync" );
+  in = 0;
+  out = 1;
+  id = this->registerVarId( new SynchronizeableInt( &in, &out, "var", PERMISSION_ALL ) );
+}
 
 
+
Index: /branches/network/src/subprojects/network/simple_sync.h
===================================================================
--- /branches/network/src/subprojects/network/simple_sync.h	(revision 7630)
+++ /branches/network/src/subprojects/network/simple_sync.h	(revision 7631)
@@ -14,4 +14,5 @@
   public:
     SimpleSync( std::string name);
+    SimpleSync(const TiXmlElement* root = NULL);
     virtual ~SimpleSync();
     
