Index: /branches/proxy/src/lib/network/network_stream.cc
===================================================================
--- /branches/proxy/src/lib/network/network_stream.cc	(revision 9463)
+++ /branches/proxy/src/lib/network/network_stream.cc	(revision 9464)
@@ -316,6 +316,8 @@
   {
     // execute everytthing the master server shoudl do
-    if ( clientSocket )
-      clientSocket->update();
+    if ( this->clientSocket )
+      this->clientSocket->update();
+    if( this->proxySocket)
+      this->proxySocket->update();
 
     this->updateConnectionList();
@@ -326,4 +328,6 @@
     if ( clientSocket )
       clientSocket->update();
+    if( this->proxySocket)
+      this->proxySocket->update();
 
     this->updateConnectionList();
@@ -368,71 +372,56 @@
   //check for new connections
 
-  NetworkSocket* tempNetworkSocket = clientSocket->getNewSocket();
-
-  // we got new network node
+  NetworkSocket* tempNetworkSocket = this->clientSocket->getNewSocket();
+  int userId;
+
+  // we got new NET_CLIENT connecting
   if ( tempNetworkSocket )
   {
-    int clientId;
     // determine the network node id
     if ( freeSocketSlots.size() > 0 )
     {
-      clientId = freeSocketSlots.back();
+      userId = freeSocketSlots.back();
       freeSocketSlots.pop_back();
     }
     else
     {
-      clientId = 1;
+      userId = 1;
 
       for ( PeerList::iterator it = peers.begin(); it != peers.end(); it++ )
-        if ( it->first >= clientId )
-          clientId = it->first + 1;
+        if ( it->first >= userId )
+          userId = it->first + 1;
     }
     // this creates a new entry in the peers list
-    peers[clientId].socket = tempNetworkSocket;
-
-
-    // create new handshake and init its variables
-    peers[clientId].handshake = new Handshake(this->pInfo->nodeType, clientId, this->networkGameManager->getUniqueID(), MessageManager::getInstance()->getUniqueID());
-    peers[clientId].handshake->setUniqueID(clientId);
-
-    peers[clientId].connectionMonitor = new ConnectionMonitor( clientId );
-    peers[clientId].userId = clientId;
-
-    PRINTF(0)("num sync: %d\n", synchronizeables.size());
-
-    // get the proxy server informations and write them to the handshake, if any (proxy)
-    assert( this->networkMonitor != NULL);
-    PeerInfo* pi = this->networkMonitor->getFirstChoiceProxy();
-    if( pi != NULL)
-    {
-      peers[clientId].handshake->setProxy1Address( pi->ip);
-    }
-    pi = this->networkMonitor->getSecondChoiceProxy();
-    if( pi != NULL)
-      peers[clientId].handshake->setProxy2Address( pi->ip);
-
-    // check if the connecting client should reconnect to a proxy server
-    peers[clientId].handshake->setRedirect(this->networkMonitor->isReconnectNextClient());
-
-    // the connecting node of course is a client
-    peers[clientId].nodeType = NET_CLIENT;
-    peers[clientId].ip = peers[clientId].socket->getRemoteAddress();
-
-
-    // check if there are too many clients connected (DEPRECATED: new: the masterserver sends a list of proxy servers)
-//     if ( clientId > SharedNetworkData::getInstance()->getMaxPlayer() )
-//     {
-// //       peers[clientId].handshake->setRedirect(true);
-// //
-// //       peers[clientId].handshake->doReject( "too many connections" );
-//       PRINTF(0)("Will reject client %d because there are to many connections!\n", clientId);
-//     }
-//     else
-//     {
-//       PRINTF(0)("New Client: %d\n", clientId);
-//     }
-    PRINTF(0)("New Client: %d\n", clientId);
-
-
+    peers[userId].socket = tempNetworkSocket;
+    this->handleConnect(userId);
+
+    PRINTF(0)("New Client: %d\n", userId);
+  }
+
+  tempNetworkSocket = this->proxySocket->getNewSocket();
+
+  // we got new NET_PROXY_SERVER_ACTIVE connecting
+  if ( tempNetworkSocket )
+  {
+    // determine the network node id
+    if ( freeSocketSlots.size() > 0 )
+    {
+      userId = freeSocketSlots.back();
+      freeSocketSlots.pop_back();
+    }
+    else
+    {
+      userId = 1;
+
+      for ( PeerList::iterator it = peers.begin(); it != peers.end(); it++ )
+        if ( it->first >= userId )
+          userId = it->first + 1;
+    }
+
+    // this creates a new entry in the peers list
+    peers[userId].socket = tempNetworkSocket;
+    this->handleConnect(userId);
+
+    PRINTF(0)("New Proxy: %d\n", userId);
   }
 
@@ -465,4 +454,35 @@
 
 
+}
+
+
+void NetworkStream::handleConnect( int userId)
+{
+  // create new handshake and init its variables
+  peers[userId].handshake = new Handshake(this->pInfo->nodeType, userId, this->networkGameManager->getUniqueID(), MessageManager::getInstance()->getUniqueID());
+  peers[userId].handshake->setUniqueID(userId);
+
+  peers[userId].connectionMonitor = new ConnectionMonitor( userId );
+  peers[userId].userId = userId;
+
+  PRINTF(0)("num sync: %d\n", synchronizeables.size());
+
+    // get the proxy server informations and write them to the handshake, if any (proxy)
+  assert( this->networkMonitor != NULL);
+  PeerInfo* pi = this->networkMonitor->getFirstChoiceProxy();
+  if( pi != NULL)
+  {
+    peers[userId].handshake->setProxy1Address( pi->ip);
+  }
+  pi = this->networkMonitor->getSecondChoiceProxy();
+  if( pi != NULL)
+    peers[userId].handshake->setProxy2Address( pi->ip);
+
+    // check if the connecting client should reconnect to a proxy server
+  peers[userId].handshake->setRedirect(this->networkMonitor->isReconnectNextClient());
+
+    // the connecting node of course is a client
+  peers[userId].nodeType = NET_CLIENT;
+  peers[userId].ip = peers[userId].socket->getRemoteAddress();
 }
 
Index: /branches/proxy/src/lib/network/network_stream.h
===================================================================
--- /branches/proxy/src/lib/network/network_stream.h	(revision 9463)
+++ /branches/proxy/src/lib/network/network_stream.h	(revision 9464)
@@ -94,4 +94,6 @@
     /* handle events*/
     void handleNewClient( int userId );
+
+    void handleConnect( int userId);
     void handleReconnect( int userId );
     void handleDisconnect( int userId );
