Index: /branches/network/src/lib/network/connection_monitor.cc
===================================================================
--- /branches/network/src/lib/network/connection_monitor.cc	(revision 7871)
+++ /branches/network/src/lib/network/connection_monitor.cc	(revision 7872)
@@ -126,9 +126,9 @@
   
   if ( packetHistory.size() <= 1 || tick - packetHistory.begin()->first == 0 )
-    res = 0;
+    res = 0.0f;
   else
     res /= (float)((tick - packetHistory.begin()->first)*( 1 + 1/((float)(packetHistory.size()-1)) ));
   
-  res *= 1000;
+  res *= 1000.0f;
   
   return res;
@@ -148,5 +148,5 @@
   outgoingZippedBandWidth = calculateBandWidth( outgoingZippedPacketHistory, tick );
   
-  NETPRINTF(n)("UPSTREAM: user: %d bandwidth %f\n", userId, outgoingZippedBandWidth );
+  NETPRINTF(n)("UPSTREAM: user: %d bandwidth %f nOutgoingPackets %d\n", userId, outgoingZippedBandWidth, nOutgoingPackets );
 
 }
@@ -163,6 +163,19 @@
   incomingZippedBandWidth = calculateBandWidth( incomingZippedPacketHistory, tick );
   
-  NETPRINTF(n)("DOWNSTREAM: user: %d bandwidth %f\n", userId, incomingZippedBandWidth );
+  NETPRINTF(n)("DOWNSTREAM: user: %d bandwidth %f nIncomingPackets %d\n", userId, incomingZippedBandWidth, nIncomingPackets );
   
 }
 
+
+bool ConnectionMonitor::hasTimedOut( )
+{
+  if ( lastPacketTick + SECS_TO_TIMEOUT*1000 < SDL_GetTicks() && nIncomingPackets > 0 )
+    return true;
+  
+  if ( nIncomingPackets == 0 && nOutgoingPackets >= NETWORK_FREQUENCY*SECS_TO_TIMEOUT )
+    return true;
+  
+  return false;
+}
+
+
Index: /branches/network/src/lib/network/connection_monitor.h
===================================================================
--- /branches/network/src/lib/network/connection_monitor.h	(revision 7871)
+++ /branches/network/src/lib/network/connection_monitor.h	(revision 7872)
@@ -30,5 +30,5 @@
     void calculatePing();
     
-    bool hasTimedOut(){ return ( lastPacketTick + SECS_TO_TIMEOUT*1000 < SDL_GetTicks() ) && nIncomingPackets > 0; }
+    bool hasTimedOut();
     
   private:
Index: /branches/network/src/lib/network/handshake.cc
===================================================================
--- /branches/network/src/lib/network/handshake.cc	(revision 7871)
+++ /branches/network/src/lib/network/handshake.cc	(revision 7872)
@@ -41,4 +41,6 @@
   errorString_handler = registerVarId( new SynchronizeableString( &localState.errorString, &remoteState.errorString, "errorString", PERMISSION_ALL ) );
   
+  candel_id = registerVarId( new SynchronizeableInt( &localState.canDel, &remoteState.canDel, "canDel", PERMISSION_ALL ) );
+  
   localState.completed = 0;
   localState.error = 0;
@@ -49,4 +51,5 @@
   localState.orxId = _ORXONOX_ID;
   localState.version = _ORXONOX_VERSION;
+  localState.canDel = 0;
   
   remoteState.completed = 0;
@@ -58,4 +61,5 @@
   remoteState.orxId = 0;
   remoteState.version = 0;
+  remoteState.canDel = 0;
 
   this->setSynchronized(true);
@@ -95,4 +99,9 @@
     }
     
+    if ( *it == candel_id )
+    {
+      PRINTF(0)("handshake finished candel changed\n");
+    }
+    
   }
   
@@ -101,5 +110,5 @@
       remoteState.version == _ORXONOX_VERSION
      )
-    localState.completed = true;
+    localState.completed = 1;
 }
 
Index: /branches/network/src/lib/network/handshake.h
===================================================================
--- /branches/network/src/lib/network/handshake.h	(revision 7871)
+++ /branches/network/src/lib/network/handshake.h	(revision 7872)
@@ -23,4 +23,5 @@
   
   int completed;
+  int canDel;
   
   int error;
@@ -39,4 +40,7 @@
     inline int        getMessageManagerId(){ return remoteState.messageManagerId; }
     inline void       doReject( std::string reason ){ localState.error = 1; localState.errorString = "the server rejected your connection ["+ reason +"]"; }
+    inline bool       canDel(){ return localState.canDel == 1 && remoteState.canDel == 1; }
+    inline bool       allowDel(){ return localState.canDel == 1; }
+    inline void       del(){ localState.canDel = 1; }
     
     virtual void varChangeHandler( std::list<int> & id );
@@ -54,4 +58,5 @@
     int orxId_handler;
     int version_handler;
+    int candel_id;
 
 };
Index: /branches/network/src/lib/network/message_manager.cc
===================================================================
--- /branches/network/src/lib/network/message_manager.cc	(revision 7871)
+++ /branches/network/src/lib/network/message_manager.cc	(revision 7872)
@@ -288,5 +288,5 @@
   // just do something so map creates a new entry
   messageQueue[userId].toAck.clear();
-  assert( messageQueue[userId].messages.size() == 0 );
+  //assert( messageQueue[userId].messages.size() == 0 );
 }
 
Index: /branches/network/src/lib/network/message_manager.h
===================================================================
--- /branches/network/src/lib/network/message_manager.h	(revision 7871)
+++ /branches/network/src/lib/network/message_manager.h	(revision 7872)
@@ -92,4 +92,6 @@
    virtual int setStateDiff( int userId, byte* data, int length, int stateId, int fromStateId );
    virtual void cleanUpUser( int userId );
+   virtual void handleSentState( int userId, int stateId, int fromStateId ){}
+   virtual void handleRecvState( int userId, int stateId, int fromStateId ){}
    
    void initUser( int userId );
Index: /branches/network/src/lib/network/network_stream.cc
===================================================================
--- /branches/network/src/lib/network/network_stream.cc	(revision 7871)
+++ /branches/network/src/lib/network/network_stream.cc	(revision 7872)
@@ -188,5 +188,5 @@
   else
   {
-    if ( peers[0].socket && !peers[0].socket->isOk() )
+    if ( peers[0].socket && ( !peers[0].socket->isOk() || peers[0].connectionMonitor->hasTimedOut() ) )
     {
       PRINTF(1)("lost connection to server\n");
@@ -272,5 +272,10 @@
        )
     {
-      PRINTF(0)("Client is gone: %d\n", it->second.userId);
+      std::string reason = "disconnected";
+      if ( it->second.connectionMonitor->hasTimedOut() )
+        reason = "timeout";
+      PRINTF(0)("Client is gone: %d (%s)\n", it->second.userId, reason.c_str());
+      
+      assert(false);
 
       it->second.socket->disconnectServer();
@@ -340,20 +345,35 @@
         if ( it->second.handshake->ok() )
         {
-          if ( type != NET_SERVER )
-          {
-            SharedNetworkData::getInstance()->setHostID( it->second.handshake->getHostId() );
-            myHostId = SharedNetworkData::getInstance()->getHostID();
-
-            this->networkGameManager = NetworkGameManager::getInstance();
-            this->networkGameManager->setUniqueID( it->second.handshake->getNetworkGameManagerId() );
-            MessageManager::getInstance()->setUniqueID( it->second.handshake->getMessageManagerId() );
+          if ( !it->second.handshake->allowDel() )
+          {
+            if ( type != NET_SERVER )
+            {
+              SharedNetworkData::getInstance()->setHostID( it->second.handshake->getHostId() );
+              myHostId = SharedNetworkData::getInstance()->getHostID();
+
+              this->networkGameManager = NetworkGameManager::getInstance();
+              this->networkGameManager->setUniqueID( it->second.handshake->getNetworkGameManagerId() );
+              MessageManager::getInstance()->setUniqueID( it->second.handshake->getMessageManagerId() );
+            }
+              
+
+            PRINT(0)("handshake finished id=%d\n", it->second.handshake->getNetworkGameManagerId());
+
+            it->second.handshake->del();
           }
           else
-            handleNewClient( it->second.userId );
-
-          PRINT(0)("handshake finished id=%d\n", it->second.handshake->getNetworkGameManagerId());
-
-          delete it->second.handshake;
-          it->second.handshake = NULL;
+          {
+            if ( it->second.handshake->canDel() )
+            {
+              if ( type == NET_SERVER )
+              {
+                handleNewClient( it->second.userId );
+              }
+              
+              PRINT(0)("handshake finished delete it\n");
+              delete it->second.handshake;
+              it->second.handshake = NULL;
+            }
+          }
 
         }
@@ -429,8 +449,34 @@
       n = sync.getStateDiff( peer->second.userId, buf + offset, UDP_PACKET_SIZE-offset, currentState, peer->second.lastAckedState, -1000 );
       offset += n;
-      //PRINTF(0)("GGGGGEEEEEEETTTTTTTT: %d\n", n);
+      //NETPRINTF(0)("GGGGGEEEEETTTTT: %s (%d) %d\n",sync.getClassName(), sync.getUniqueID(), n);
       
       assert( Converter::intToByteArray( n, buf + offset - n - INTSIZE, INTSIZE ) == INTSIZE );
       
+      //check if all bytes == 0 -> remove data 
+
+      bool allZero = true; 
+      for ( int i = 0; i < n; i++ ) 
+      { 
+         if ( buf[i+oldOffset+2*INTSIZE] != 0 ) 
+           allZero = false; 
+      } 
+
+      if ( allZero ) 
+      { 
+        //NETPRINTF(n)("REMOVE ZERO DIFF: %s (%d)\n", sync.getClassName(), sync.getUniqueID()); 
+        offset = oldOffset; 
+      } 
+
+      
+    }
+    
+    for ( SynchronizeableList::iterator it = synchronizeables.begin(); it != synchronizeables.end(); it++ )
+    {
+      Synchronizeable & sync = **it;
+      
+      if ( !sync.beSynchronized() || sync.getUniqueID() < 0 )
+        continue;
+      
+      sync.handleSentState( peer->second.userId, currentState, peer->second.lastAckedState );
     }
     
@@ -481,4 +527,5 @@
     while ( 0 < (compLength = peer->second.socket->readPacket( compBuf, UDP_PACKET_SIZE )) )
     {
+      //PRINTF(0)("GGGGGOOOOOOOOOOTTTTTTTT: %d\n", compLength);
       packetLength = Zip::getInstance()->unZip( compBuf, compLength, buf, UDP_PACKET_SIZE );
       
@@ -523,5 +570,5 @@
         
         assert( syncDataLength > 0 );
-        assert( syncDataLength < 1000 );
+        assert( syncDataLength < 10000 );
       
         Synchronizeable * sync = NULL;
@@ -545,5 +592,5 @@
             continue;
           }
-
+          
           if ( !peers[peer->second.userId].isServer )
           {
@@ -601,5 +648,6 @@
         int n = sync->setStateDiff( peer->second.userId, buf+offset, syncDataLength, state, fromState ); 
         offset += n;
-        //PRINTF(0)("SSSSSEEEEETTTTT: %d\n", n);
+        //NETPRINTF(0)("SSSSSEEEEETTTTT: %s %d\n",sync->getClassName(), n);
+
       }
       
@@ -610,10 +658,27 @@
       }
       
-      peer->second.connectionMonitor->processZippedIncomingPacket( compBuf, compLength, currentState, ackedState );
-      peer->second.connectionMonitor->processUnzippedIncomingPacket( buf, offset, currentState, ackedState );
-    
+      //TODO REMOVE THIS
+      int saveOffset = offset;
+      
+      for ( SynchronizeableList::iterator it = synchronizeables.begin(); it != synchronizeables.end(); it++ )
+      {
+        Synchronizeable & sync = **it;
+      
+        if ( !sync.beSynchronized() || sync.getUniqueID() < 0 )
+          continue;
+      
+        sync.handleRecvState( peer->second.userId, state, fromState );
+      }
+      
+      peer->second.connectionMonitor->processZippedIncomingPacket( compBuf, compLength, state, ackedState );
+      peer->second.connectionMonitor->processUnzippedIncomingPacket( buf, offset, state, ackedState );
+    
+      assert( peer->second.lastAckedState <= ackedState );
       peer->second.lastAckedState = ackedState;
       
+      assert( peer->second.lastRecvedState < state );
       peer->second.lastRecvedState = state;
+      
+      assert( saveOffset == offset );
       
     }
Index: /branches/network/src/lib/network/synchronizeable.cc
===================================================================
--- /branches/network/src/lib/network/synchronizeable.cc	(revision 7871)
+++ /branches/network/src/lib/network/synchronizeable.cc	(revision 7872)
@@ -20,4 +20,5 @@
 #include "network_stream.h"
 #include "netdefs.h"
+#include "network_log.h"
 
 #include "state.h"
@@ -179,7 +180,8 @@
     if ( ( hasPermission && (*it)->getPriority() >= priorityTH ) || sizeIter == stateFrom->sizeList.end() )
     {
+      n = (*it)->writeToBuf( stateTo->data+i, stateTo->dataLength - i );
+      //NETPRINTF(0)("getvar %s %d\n", (*it)->getName().c_str(), n);
+      stateTo->sizeList.push_back( n );
       //(*it)->debug();
-      n = (*it)->writeToBuf( stateTo->data+i, stateTo->dataLength - i );
-      stateTo->sizeList.push_back( n );
       i += n;
     }
@@ -192,4 +194,5 @@
         i++;
       }
+      //NETPRINTF(0)("getvar %s %d\n", (*it)->getName().c_str(), *sizeIter);
       stateTo->sizeList.push_back( (*sizeIter) );
     }
@@ -237,7 +240,165 @@
   stateTo->data = new byte[ length ];
 
+
+  //find state to apply diff to
+  StateHistoryEntry * stateFrom = NULL;
+
+  StateHistory::iterator it = recvStates[userId].begin();
+  while ( it != recvStates[userId].end() && (*it)->stateId != fromStateId )
+    it++;
+
+  
+//  if ( getLeafClassID() == CL_SPACE_SHIP )
+//  {
+//    PRINTF(0)("setStateDiff:SpaceShip from: %d stateId: %d\n", (it == recvStates[userId].end())?-1:fromStateId, stateId);
+//  }
+
+  if ( it == recvStates[userId].end() )
+  {
+    StateHistoryEntry * initialEntry = new StateHistoryEntry();
+
+    initialEntry->stateId = fromStateId;
+    initialEntry->dataLength = 0;
+    initialEntry->data = NULL;
+
+    stateFrom = initialEntry;
+  }
+  else
+    stateFrom = (*it);
+  
+  //apply diff
+  for ( int i = 0; i<length; i++ )
+  {
+    if ( i < stateFrom->dataLength )
+      stateTo->data[i] = stateFrom->data[i] + data[i];
+    else
+      stateTo->data[i] = data[i];
+    
+  }
+  
+  //add state to state history
+  recvStates[userId].push_back( stateTo );
+  
+  int i = 0;
+  int n = 0;
+  std::list<int> changes;
+  
+  for ( SyncVarList::iterator it = syncVarList.begin(); it != syncVarList.end(); it++ )
+  {
+    if (
+        (*it)->checkPermission( PERMISSION_SERVER ) && networkStream->isUserServer( userId ) ||
+        (*it)->checkPermission( PERMISSION_OWNER ) && this->owner == userId ||
+        (*it)->checkPermission( PERMISSION_ALL ) 
+       )
+    {
+      n = (*it)->readFromBuf( stateTo->data + i, stateTo->dataLength - i );
+      i += n;
+      //NETPRINTF(0)("%s::setvar %s %d\n", getClassName(), (*it)->getName().c_str(), n);
+      //(*it)->debug();
+      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 );
+      n = (*it)->getSizeFromBuf( stateTo->data + i, stateTo->dataLength - i );
+      //NETPRINTF(0)("%s::setvar %s %d\n", getClassName(), (*it)->getName().c_str(), n);
+      //(*it)->debug();
+      i += n;
+    }
+  }
+
+  this->varChangeHandler( changes );
+  
+  return i;
+}
+
+ /**
+ * override this function to be notified on change
+ * of your registred variables.
+ * @param id id's which have changed
+ */
+void Synchronizeable::varChangeHandler( std::list<int> & id )
+{
+}
+
+/**
+ * registers a varable to be synchronized over network
+ * @param var see src/lib/network/synchronizeable_var/ for available classes
+ */
+void Synchronizeable::registerVar( SynchronizeableVar * var )
+{
+  PRINTF(0)("ADDING VAR: %s\n", var->getName().c_str());
+  syncVarList.push_back( var );
+}
+
+/**
+ * registers a varable to be synchronized over network
+ * return value is passed to varChangeHandler on change
+ * @param var see src/lib/network/synchronizeable_var/ for available classes
+ * @return handle passed to varChangeHandler on changes
+ */
+int Synchronizeable::registerVarId( SynchronizeableVar * var )
+{
+  PRINTF(0)("ADDING VAR: %s\n", var->getName().c_str());
+  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(); it2++ )
+    {
+      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(); it2++ )
+    {
+      if ( (*it2)->data )
+        delete [] (*it2)->data;
+      (*it2)->data = NULL;
+      
+      delete *it2;
+    }
+  }
+  
+  recvStates.clear();
+}
+
+/**
+ * this function is called after recieving a state.
+ * @param userId 
+ * @param stateId 
+ * @param fromStateId 
+ */
+void Synchronizeable::handleRecvState( int userId, int stateId, int fromStateId )
+{
+   //make sure this user has his history
+  if ( recvStates.size() <= userId )
+    recvStates.resize( userId+1 );
+  
   //remove old states
   StateHistory::iterator it = recvStates[userId].begin();
 
+#if 0
   while ( it != recvStates[userId].end() && (*it)->stateId < fromStateId )
     it++;
@@ -255,138 +416,130 @@
     recvStates[userId].erase( recvStates[userId].begin(), it );
   }
-
-  //find state to apply diff to
-  StateHistoryEntry * stateFrom = NULL;
-
-  it = recvStates[userId].begin();
-  while ( it != recvStates[userId].end() && (*it)->stateId != fromStateId )
+#endif
+
+  for ( it = recvStates[userId].begin(); it != recvStates[userId].end();  )
+  {
+    if ( (*it)->stateId < fromStateId )
+    {
+      StateHistory::iterator delIt = it;
+      it ++;
+      
+      if ( (*delIt)->data )
+        delete [] (*delIt)->data;
+      recvStates[userId].erase( delIt );
+      
+      continue;
+    }
     it++;
-
-  
-//  if ( getLeafClassID() == CL_SPACE_SHIP )
-//  {
-//    PRINTF(0)("setStateDiff:SpaceShip from: %d stateId: %d\n", (it == recvStates[userId].end())?-1:fromStateId, stateId);
-//  }
-
-  if ( it == recvStates[userId].end() )
-  {
-    StateHistoryEntry * initialEntry = new StateHistoryEntry();
-
-    initialEntry->stateId = fromStateId;
-    initialEntry->dataLength = 0;
-    initialEntry->data = NULL;
-
-    stateFrom = initialEntry;
-  }
-  else
-    stateFrom = (*it);
-  
-  //apply diff
-  for ( int i = 0; i<length; i++ )
-  {
-    if ( i < stateFrom->dataLength )
-      stateTo->data[i] = stateFrom->data[i] + data[i];
+  }
+  
+  StateHistory::iterator fromState = recvStates[userId].end();
+  StateHistory::iterator toState = recvStates[userId].end();
+  
+  for ( it = recvStates[userId].begin(); it != recvStates[userId].end(); it++ )
+  {
+    if ( (*it)->stateId == stateId )
+      toState = it;
+    if ( (*it)->stateId == fromStateId )
+      fromState = it;
+    
+    if ( fromState != recvStates[userId].end() && toState != recvStates[userId].end() )
+      break;
+  }
+  
+  // setStateDiff was not called and i know fromStateId
+  if ( fromState != recvStates[userId].end() && toState == recvStates[userId].end() )
+  {
+    StateHistoryEntry * entry = new StateHistoryEntry;
+    
+    entry->dataLength = (*fromState)->dataLength;
+    if ( entry->dataLength > 0 )
+    {
+      entry->data = new byte[entry->dataLength];
+          
+      assert( (*fromState)->data );
+      memcpy( entry->data, (*fromState)->data, entry->dataLength );
+    }
     else
-      stateTo->data[i] = data[i];
-    
-  }
-  
-  //add state to state history
-  recvStates[userId].push_back( stateTo );
-  
-  int i = 0;
-  std::list<int> changes;
-  
-  for ( SyncVarList::iterator it = syncVarList.begin(); it != syncVarList.end(); it++ )
-  {
-    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() );
+      entry->data = NULL;
+    
+    entry->sizeList = (*fromState)->sizeList;
+    entry->stateId = stateId;
+    
+    recvStates[userId].push_back(entry);
+  }
+}
+
+/**
+ * this function is called after sending a state
+ * @param userId 
+ * @param stateId 
+ * @param fromStateId 
+ */
+void Synchronizeable::handleSentState( int userId, int stateId, int fromStateId )
+{
+   //make sure this user has his history
+  if ( sentStates.size() <= userId )
+    sentStates.resize( userId+1 );
+
+   //remove old states
+  StateHistory::iterator it = sentStates[userId].begin();
+
+  for ( it = sentStates[userId].begin(); it != sentStates[userId].end();  )
+  {
+    if ( (*it)->stateId < fromStateId )
+    {
+      StateHistory::iterator delIt = it;
+      it ++;
+      
+      if ( (*delIt)->data )
+        delete [] (*delIt)->data;
+      sentStates[userId].erase( delIt );
+      
+      continue;
+    }
+    it++;
+  }
+
+  
+  StateHistory::iterator fromState = sentStates[userId].end();
+  StateHistory::iterator toState = sentStates[userId].end();
+  
+  for ( it = sentStates[userId].begin(); it != sentStates[userId].end(); it++ )
+  {
+    if ( (*it)->stateId == stateId )
+      toState = it;
+    if ( (*it)->stateId == fromStateId )
+      fromState = it;
+    
+    if ( fromState != sentStates[userId].end() && toState != sentStates[userId].end() )
+      break;
+  }
+
+  
+  // getStateDiff was not called and i know fromStateId
+  if ( fromState != sentStates[userId].end() && toState == sentStates[userId].end() )
+  {
+    StateHistoryEntry * entry = new StateHistoryEntry;
+    
+    entry->dataLength = (*fromState)->dataLength;
+    if ( entry->dataLength > 0 )
+    {
+      entry->data = new byte[entry->dataLength];
+      
+      assert( (*fromState)->data );
+      memcpy( entry->data, (*fromState)->data, entry->dataLength );
     }
     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 );
-    }
-  }
-
-  this->varChangeHandler( changes );
-  
-  return i;
-}
-
- /**
- * override this function to be notified on change
- * of your registred variables.
- * @param id id's which have changed
- */
-void Synchronizeable::varChangeHandler( std::list<int> & id )
-{
-}
-
-/**
- * registers a varable to be synchronized over network
- * @param var see src/lib/network/synchronizeable_var/ for available classes
- */
-void Synchronizeable::registerVar( SynchronizeableVar * var )
-{
-  syncVarList.push_back( var );
-}
-
-/**
- * registers a varable to be synchronized over network
- * return value is passed to varChangeHandler on change
- * @param var see src/lib/network/synchronizeable_var/ for available classes
- * @return handle passed to varChangeHandler on changes
- */
-int Synchronizeable::registerVarId( SynchronizeableVar * var )
-{
-  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(); it2++ )
-    {
-      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(); it2++ )
-    {
-      if ( (*it2)->data )
-        delete [] (*it2)->data;
-      (*it2)->data = NULL;
-      
-      delete *it2;
-    }
-  }
-  
-  recvStates.clear();
-}
-
-
-
+      entry->data = NULL;
+    
+    entry->sizeList = (*fromState)->sizeList;
+    entry->stateId = stateId;
+    
+    sentStates[userId].push_back(entry);
+  }
+  
+}
+
+
+
Index: /branches/network/src/lib/network/synchronizeable.h
===================================================================
--- /branches/network/src/lib/network/synchronizeable.h	(revision 7871)
+++ /branches/network/src/lib/network/synchronizeable.h	(revision 7872)
@@ -59,4 +59,6 @@
     virtual int setStateDiff( int userId, byte* data, int length, int stateId, int fromStateId );
     virtual void cleanUpUser( int userId );
+    virtual void handleSentState( int userId, int stateId, int fromStateId );
+    virtual void handleRecvState( int userId, int stateId, int fromStateId );
 
     void registerVar( SynchronizeableVar * var );
Index: /branches/network/src/lib/network/synchronizeable_var/synchronizeable_string.cc
===================================================================
--- /branches/network/src/lib/network/synchronizeable_var/synchronizeable_string.cc	(revision 7871)
+++ /branches/network/src/lib/network/synchronizeable_var/synchronizeable_string.cc	(revision 7872)
@@ -95,5 +95,4 @@
   
   int res = Converter::byteArrayToString( buf, t, maxLength );
-
   
   assert( res > 0 );
Index: /branches/network/src/lib/network/udp_server_socket.cc
===================================================================
--- /branches/network/src/lib/network/udp_server_socket.cc	(revision 7871)
+++ /branches/network/src/lib/network/udp_server_socket.cc	(revision 7872)
@@ -35,5 +35,4 @@
   
   memset( packet->data, 0, UDP_PACKET_SIZE );
-  PRINTF(0)("PACKET DATA: %x\n", packet->data);
   
   listen( port );
Index: /branches/network/src/lib/network/udp_socket.cc
===================================================================
--- /branches/network/src/lib/network/udp_socket.cc	(revision 7871)
+++ /branches/network/src/lib/network/udp_socket.cc	(revision 7872)
@@ -124,5 +124,5 @@
   if ( channel == -1 ) 
   {
-    PRINTF(2)("SDLNet_UDP_Bind: %s\n", SDLNet_GetError());
+    PRINTF(1)("SDLNet_UDP_Bind: %s\n", SDLNet_GetError());
     bOk = false;
     return;
Index: /branches/network/src/subprojects/network/network_unit_test.cc
===================================================================
--- /branches/network/src/subprojects/network/network_unit_test.cc	(revision 7871)
+++ /branches/network/src/subprojects/network/network_unit_test.cc	(revision 7872)
@@ -277,6 +277,6 @@
   {
     MessageManager::getInstance()->sendMessage( TESTMESSAGEID, (byte*)"server to client", 18, RT_ALL, 0, MP_HIGHBANDWIDTH );
-    netMan->synchronize( 1000 );
-    SDL_Delay(1000);
+    netMan->synchronize( 100 );
+    SDL_Delay(100);
     ss->debug();
   }
@@ -312,4 +312,6 @@
 //  ss->setSynchronized( true );
 //  netMan->connectSynchronizeable( *ss );
+  
+  NetworkLog::getInstance()->listen( 7777 );
 
   SimpleSync * ss = NULL;
@@ -320,8 +322,8 @@
   for(;;)
   {
-    netMan->synchronize( 1000 );
+    netMan->synchronize( 100 );
     MessageManager::getInstance()->sendMessage( TESTMESSAGEID, (byte*)"client to server", 18, RT_ALL, 0, MP_HIGHBANDWIDTH );
     ss = dynamic_cast<SimpleSync*>(ClassList::getObject( "Server", CL_SIMPLE_SYNC ) );
-    SDL_Delay(1000);
+    SDL_Delay(100);
     if (ss)
       ss->debug();
Index: /branches/network/src/subprojects/network/simple_sync.cc
===================================================================
--- /branches/network/src/subprojects/network/simple_sync.cc	(revision 7871)
+++ /branches/network/src/subprojects/network/simple_sync.cc	(revision 7872)
@@ -40,5 +40,7 @@
   in = 0;
   out = 1;
+  syncStr = "hallo test test";
   id = this->registerVarId( new SynchronizeableInt( &in, &out, "var", PERMISSION_ALL ) );
+  registerVar( new SynchronizeableString( &syncStr, &syncStr, "syncStr" ) );
 }
 
@@ -54,4 +56,5 @@
 {
   printf("IN: %d OUT: %d\n", in, out);
+  printf("str: %s\n", syncStr.c_str());
 }
 
@@ -62,7 +65,10 @@
   in = 0;
   out = 1;
+  syncStr = "hallo test test";
   id = this->registerVarId( new SynchronizeableInt( &in, &out, "var", PERMISSION_ALL ) );
+  registerVar( new SynchronizeableString( &syncStr, &syncStr, "syncStr" ) );
 }
 
 
 
+
Index: /branches/network/src/subprojects/network/simple_sync.h
===================================================================
--- /branches/network/src/subprojects/network/simple_sync.h	(revision 7871)
+++ /branches/network/src/subprojects/network/simple_sync.h	(revision 7872)
@@ -23,4 +23,5 @@
     int in;
     int out;
+    std::string syncStr;
     int id;
   };
