Index: trunk/src/lib/network/synchronizeable.cc
===================================================================
--- trunk/src/lib/network/synchronizeable.cc	(revision 9406)
+++ trunk/src/lib/network/synchronizeable.cc	(revision 9494)
@@ -72,5 +72,6 @@
     this->networkStream->disconnectSynchronizeable(*this);
 
-    if ( (SharedNetworkData::getInstance()->isMasterServer() || SharedNetworkData::getInstance()->isProxyServer() )
+    // remove the message manager only by the server
+    if ( (SharedNetworkData::getInstance()->isMasterServer() )
            && this->beSynchronized() && this->getUniqueID() > 0 && !this->isA( CL_MESSAGE_MANAGER ) )
       NetworkGameManager::getInstance()->removeSynchronizeable( this->getUniqueID() );
@@ -213,5 +214,5 @@
       hasPermission = true;
     // now check PROXY_SERVER permissions
-    else if( SharedNetworkData::getInstance()->isProxyServer() && (*it)->checkPermission( PERMISSION_MASTER_SERVER ))
+    else if( SharedNetworkData::getInstance()->isProxyServerActive() && (*it)->checkPermission( PERMISSION_PROXY_SERVER ))
       hasPermission = true;
     // now check OWNER permissions
@@ -222,8 +223,10 @@
       hasPermission = true;
     // SPECIAL: get write permissions if i am master server and i am able to overwrite the client stuff
+#warning this could probably override also clients that are connected to another proxy: the master server overwrites it
     else if( SharedNetworkData::getInstance()->isMasterServer() && this->owner != userId && (*it)->checkPermission( PERMISSION_OWNER ))
       hasPermission = true;
     // SPECIAL: get write permissions if i am proxy server and i am able to overwrite the client stuff
-    else if( SharedNetworkData::getInstance()->isProxyServer()  && this->owner != userId && (*it)->checkPermission( PERMISSION_OWNER ))
+    else if( SharedNetworkData::getInstance()->isProxyServerActive() && this->networkStream->isUserClient(userId)
+             && this->owner != userId && (*it)->checkPermission( PERMISSION_OWNER ) )
       hasPermission = true;
     else
@@ -354,5 +357,6 @@
       hasPermission = true;
     // now check PROXY_SERVER permissions
-    else if( this->networkStream->isUserProxyServer( userId )  && (*it)->checkPermission( PERMISSION_MASTER_SERVER ))
+    else if( this->networkStream->isUserProxyServerActive( userId )  && (*it)->checkPermission( PERMISSION_MASTER_SERVER )
+             && SharedNetworkData::getInstance()->isClient())
       hasPermission = true;
     // now check OWNER permissions
@@ -366,5 +370,6 @@
       hasPermission = true;
     // SPECIAL: get write permissions if im sending to a proxy server that does not own this sync
-    else if( this->networkStream->isUserProxyServer( userId )  && this->owner != SharedNetworkData::getInstance()->getHostID() && (*it)->checkPermission( PERMISSION_OWNER ))
+    else if( this->networkStream->isUserProxyServerActive( userId ) && SharedNetworkData::getInstance()->isClient()
+              && this->owner != SharedNetworkData::getInstance()->getHostID() && (*it)->checkPermission( PERMISSION_OWNER ))
       hasPermission = true;
     else
@@ -388,5 +393,5 @@
     else
     {
-//      PRINTF(0)("DONT SET VAR BECAUSE OF PERMISSION: %s %d %d %d %d %d %d\n", (*it)->getName().c_str(), (*it)->checkPermission( PERMISSION_MASTER_SERVER ), (*it)->checkPermission( PERMISSION_OWNER ), (*it)->checkPermission( PERMISSION_ALL ), networkStream->isUserServer( userId ), this->owner, userId );
+//       PRINTF(0)("DONT SET VAR BECAUSE OF PERMISSION: %s perm: %d %d %d - %d %d %d\n", (*it)->getName().c_str(), (*it)->checkPermission( PERMISSION_MASTER_SERVER ), (*it)->checkPermission( PERMISSION_OWNER ), (*it)->checkPermission( PERMISSION_ALL ), networkStream->isUserMasterServer( userId ), this->owner, userId );
       n = (*it)->getSizeFromBuf( stateTo->data + i, stateTo->dataLength - i );
       //NETPRINTF(0)("%s::setvar %s %d\n", getClassCName(), (*it)->getName().c_str(), n);
@@ -416,5 +421,4 @@
 void Synchronizeable::registerVar( SynchronizeableVar * var )
 {
-  //PRINTF(0)("ADDING VAR: %s\n", var->getName().c_str());
   syncVarList.push_back( var );
 }
@@ -428,5 +432,4 @@
 int Synchronizeable::registerVarId( SynchronizeableVar * var )
 {
-  //PRINTF(0)("ADDING VAR: %s\n", var->getName().c_str());
   syncVarList.push_back( var );
   var->setWatched( true );
