Index: branches/proxy/src/lib/network/network_stream.cc
===================================================================
--- branches/proxy/src/lib/network/network_stream.cc	(revision 9427)
+++ branches/proxy/src/lib/network/network_stream.cc	(revision 9430)
@@ -203,4 +203,7 @@
   PRINTF(0)("connect to proxy %s, this is node %i\n", host.c_str(), node);
 
+  if( this->peers[node].socket != NULL)
+    delete this->peers[node].socket;
+
   this->peers[node].socket = new UdpSocket( host, port );
   this->peers[node].userId = 0;
@@ -437,18 +440,18 @@
 
 #warning this is some more disconnct handling, consider doing it in the handleDisconnect() funciton
-//       // and cleanup the user infos
-//       for ( SynchronizeableList::iterator it2 = synchronizeables.begin(); it2 != synchronizeables.end(); it2++ )
-//       {
-//         (*it2)->cleanUpUser( it->second.userId );
-//       }
-//
-//       NetworkGameManager::getInstance()->signalLeftPlayer(it->second.userId);
-//
-//       freeSocketSlots.push_back( it->second.userId );
-//
-//       PeerList::iterator delit = it;
-//       it++;
-//
-//       peers.erase( delit );
+      // and cleanup the user infos
+      for ( SynchronizeableList::iterator it2 = synchronizeables.begin(); it2 != synchronizeables.end(); it2++ )
+      {
+        (*it2)->cleanUpUser( it->second.userId );
+      }
+
+      NetworkGameManager::getInstance()->signalLeftPlayer(it->second.userId);
+
+      freeSocketSlots.push_back( it->second.userId );
+
+      PeerList::iterator delit = it;
+      it++;
+
+      peers.erase( delit );
 
       continue;
@@ -520,32 +523,29 @@
           {
             // make sure this is a client
-            assert( this->pInfo->isClient());
-
-            SharedNetworkData::getInstance()->setHostID( it->second.handshake->getHostId() );
-            this->pInfo->userId = SharedNetworkData::getInstance()->getHostID();
-
-            it->second.nodeType = it->second.handshake->getRemoteNodeType();
-            it->second.ip = it->second.socket->getRemoteAddress();
+            if( this->pInfo->isClient())
+            {
+              SharedNetworkData::getInstance()->setHostID( it->second.handshake->getHostId() );
+              this->pInfo->userId = SharedNetworkData::getInstance()->getHostID();
+
+              it->second.nodeType = it->second.handshake->getRemoteNodeType();
+              it->second.ip = it->second.socket->getRemoteAddress();
               // add the new server to the nodes list (it can be a NET_MASTER_SERVER or NET_PROXY_SERVER)
-            this->networkMonitor->addNode(&it->second);
+              this->networkMonitor->addNode(&it->second);
               // get proxy 1 address and add it
-            this->networkMonitor->addNode(it->second.handshake->getProxy1Address(), NET_PROXY_SERVER_ACTIVE);
+              this->networkMonitor->addNode(it->second.handshake->getProxy1Address(), NET_PROXY_SERVER_ACTIVE);
               // get proxy 2 address and add it
-            this->networkMonitor->addNode(it->second.handshake->getProxy2Address(), NET_PROXY_SERVER_ACTIVE);
+              this->networkMonitor->addNode(it->second.handshake->getProxy2Address(), NET_PROXY_SERVER_ACTIVE);
 
               // now check if the server accepted the connection
-            if( !it->second.handshake->redirect())
-            {
-                // create the new network game manager and init it
+
+              // create the new network game manager and init it
               this->networkGameManager = NetworkGameManager::getInstance();
               this->networkGameManager->setUniqueID( it->second.handshake->getNetworkGameManagerId() );
               // init the new message manager
               MessageManager::getInstance()->setUniqueID( it->second.handshake->getMessageManagerId() );
-
-              PRINT(0)("handshake finished id=%d\n", it->second.handshake->getNetworkGameManagerId());
-              it->second.handshake->del();
             }
-            else
-              this->handleReconnect( it->second.userId);
+
+            PRINT(0)("handshake finished id=%d\n", it->second.handshake->getNetworkGameManagerId());
+            it->second.handshake->del();
 
           }
@@ -600,4 +600,17 @@
     }
   }
+
+
+//   for ( PeerList::iterator it = peers.begin(); it != peers.end(); it++ )
+//   {
+//     if( !it->second.handshake->redirect())
+//     {
+//       if( SharedNetworkData::getInstance()->isClient())
+//       {
+//         this->handleReconnect( it->second.userId);
+//         return;
+//       }
+//     }
+//   }
 }
 
@@ -618,6 +631,6 @@
 
   // reject the server
-  pInfo->handshake->doReject( "redirected to different server");
-  pInfo->handshake->del();
+//   pInfo->handshake->doReject( "redirected to different server");
+//   pInfo->handshake->del();
 
   // flush the old synchronization states, since the numbering could be completely different
@@ -631,9 +644,9 @@
 //   pInfo->socket->reconnectToServer( proxyIP.ipString(), proxyIP.port());
   this->handleDisconnect( userId);
-  this->connectToProxyServer(proxyIP.ipString(), 9999);
+//   this->connectToProxyServer(proxyIP.ipString(), 9999);
 #warning the ports are not yet integrated correctly in the ip class
 
   // and restart the handshake
-  this->startHandshake( userId);
+//   this->startHandshake( userId);
 }
 
@@ -658,13 +671,21 @@
 
 
-  for ( SynchronizeableList::iterator it2 = synchronizeables.begin(); it2 != synchronizeables.end(); it2++ )  {
-    (*it2)->cleanUpUser( userId );
-  }
-
-//   NetworkGameManager::getInstance()->signalLeftPlayer(userId);
-
-  this->freeSocketSlots.push_back( userId );
-
-  peers.erase( userId );
+//   for ( SynchronizeableList::iterator it2 = synchronizeables.begin(); it2 != synchronizeables.end(); it2++ )  {
+//     (*it2)->cleanUpUser( userId );
+//   }
+//
+// //   NetworkGameManager::getInstance()->signalLeftPlayer(userId);
+//
+//   this->freeSocketSlots.push_back( userId );
+//
+//   peers.erase( userId );
+
+//   this->pInfo->userId = 0;
+//   this->pInfo->lastAckedState = 0;
+//   this->pInfo->lastRecvedState = 0;
+//   this->pInfo->connectionMonitor = NULL;
+//   this->pInfo->handshake = NULL;
+//   this->pInfo->socket = NULL;
+//   this->pInfo->nodeType = NET_CLIENT;
 }
 
