Index: branches/proxy/src/lib/network/handshake.cc
===================================================================
--- branches/proxy/src/lib/network/handshake.cc	(revision 9297)
+++ branches/proxy/src/lib/network/handshake.cc	(revision 9300)
@@ -25,5 +25,5 @@
 
 
-Handshake::Handshake( int nodeType, int clientId, int networkGameManagerId, int messageManagerId )
+ Handshake::Handshake( int nodeType, int clientId, int networkGameManagerId, int messageManagerId )
   : Synchronizeable()
 {
@@ -46,4 +46,5 @@
 
   registerVar( new SynchronizeableString( &localState.preferedNickName, &remoteState.preferedNickName, "preferedNickName", PERMISSION_ALL ) );
+  // now synchronize only two of the available proxy server addresses
   registerVar( new SynchronizeableIP( &localState.proxy1, &remoteState.proxy1, "proxy server 1", PERMISSION_ALL ) );
   registerVar( new SynchronizeableIP( &localState.proxy2, &remoteState.proxy1, "proxy server 2", PERMISSION_ALL ) );
@@ -61,5 +62,11 @@
   localState.canDel = 0;
   localState.redirectProxy = 0;
+  localState.proxy1.host = 0;
+  localState.proxy1.port = 0;
+  localState.proxy2.host = 0;
+  localState.proxy2.port = 0;
 
+
+  // init the remote state
   remoteState.completed = 0;
   remoteState.error = 0;
@@ -73,4 +80,8 @@
   remoteState.canDel = 0;
   remoteState.redirectProxy = 0;
+  remoteState.proxy1.host = 0;
+  remoteState.proxy1.port = 0;
+  remoteState.proxy2.host = 0;
+  remoteState.proxy2.port = 0;
 
   // activate the synchronization process
Index: branches/proxy/src/lib/network/handshake.h
===================================================================
--- branches/proxy/src/lib/network/handshake.h	(revision 9297)
+++ branches/proxy/src/lib/network/handshake.h	(revision 9300)
@@ -1,5 +1,6 @@
 /*!
  * @file network_stream.h
- *  implementation of a network pipe
+ *  implementation of a network pipe. This node handles the handshake of two network nodes and exchanges informationas
+ * vial to the connection setup.
  */
 
@@ -10,5 +11,5 @@
 #include "synchronizeable.h"
 
-
+//!< a struct to save the handshakes to
 struct HandshakeState
 {
@@ -36,4 +37,6 @@
 };
 
+
+//!< the handshake itself with some interface functions
 class Handshake : public Synchronizeable
 {
@@ -74,5 +77,7 @@
 
     /** @returns if true the local client should reconnect to a proxy server from the proxy server list */
-    inline bool redirect() { return this->remoteState.redirectProxy;}
+    inline bool redirect() { return this->localState.redirectProxy;}
+    /** @param flag: indicating if the client should be redirected */
+    inline void setRedirect(bool flag) { this->remoteState.redirectProxy = flag; }
 
     /** @param address: the address of the proxy server 1 if any */
Index: branches/proxy/src/lib/network/monitor/network_monitor.cc
===================================================================
--- branches/proxy/src/lib/network/monitor/network_monitor.cc	(revision 9297)
+++ branches/proxy/src/lib/network/monitor/network_monitor.cc	(revision 9300)
@@ -19,7 +19,13 @@
 #include "debug.h"
 
+#include "proxy/proxy_settings.h"
+
 #include "network_monitor.h"
 #include "network_node.h"
+#include "peer_info.h"
 #include "network_stream.h"
+#include "netdefs.h"
+
+#include <vector>
 
 
@@ -45,4 +51,19 @@
 
   this->setSynchronized(false);
+
+  // assuming that the config files are already read we get the proxy servers
+  std::vector<IPaddress*>* proxyList = &ProxySettings::getInstance()->getProxyList();
+  std::vector<IPaddress*>::iterator it = proxyList->begin();
+  // create a peer info class and a network node class for each new proxy and add them to the passive list
+  for(; it < proxyList->end(); it++)
+  {
+    PeerInfo* peer = new PeerInfo();
+    peer->ip = *(*it);
+    peer->nodeType = NET_PROXY_SERVER;
+    peer->userId = -1;
+
+    NetworkNode* node = new NetworkNode(peer);
+    this->addPassiveProxyServer( this->localNode, peer);
+  }
 }
 
@@ -86,4 +107,11 @@
 }
 
+/**
+ * tihs adds the new network node
+ * @param ip ip of the new node
+ */
+void NetworkMonitor::addNode(IPaddress ip)
+{}
+
 
 /**
@@ -128,4 +156,24 @@
   else if( pInfo->isMasterServer())
     node->addMasterServer(pInfo);
+}
+
+
+/**
+ * @returns the proxy server of the first choice
+ */
+PeerInfo* NetworkMonitor::getFirstChoiceProxy()
+{
+  // return the fist proxy in the list
+  return this->localNode->getActiveProxyServer(0);
+}
+
+
+/**
+ * @returns the proxy server of second choice
+ */
+PeerInfo* NetworkMonitor::getSecondChoiceProxy()
+{
+  // return the second server in the list
+  return this->localNode->getActiveProxyServer(1);
 }
 
@@ -185,4 +233,6 @@
   }
 
+  // check if a proxy server has to activated
+
   this->debug();
 }
Index: branches/proxy/src/lib/network/monitor/network_monitor.h
===================================================================
--- branches/proxy/src/lib/network/monitor/network_monitor.h	(revision 9297)
+++ branches/proxy/src/lib/network/monitor/network_monitor.h	(revision 9300)
@@ -34,4 +34,5 @@
     void removeNetworkNode(NetworkNode* node);
 
+    void addNode(IPaddress ip);
     void addNode(PeerInfo* pInfo);
     void addNode(NetworkNode* node) { this->nodeList.push_back(node); }
@@ -42,4 +43,6 @@
     /** adds to @param node a network node @param pInfo a new proxy server */
     inline void addActiveProxyServer(NetworkNode* node, PeerInfo* pInfo) { node->addActiveProxyServer(pInfo); }
+    /** adds to @param node a network node @param pInfo a new proxy server */
+    inline void addPassiveProxyServer(NetworkNode* node, PeerInfo* pInfo) { node->addPassiveProxyServer(pInfo); }
     /** adds to @param node a network node @param pInfo a new master server*/
     inline void addMasterServer(NetworkNode* node, PeerInfo* pInfo) { node->addMasterServer(pInfo); }
@@ -47,4 +50,5 @@
     inline void removeClient(NetworkNode* node, PeerInfo* pInfo) { node->removeClient(pInfo); }
     inline void removeActiveProxyServer(NetworkNode* node, PeerInfo* pInfo) { node->removeActiveProxyServer(pInfo); }
+    inline void removePassiveProxyServer(NetworkNode* node, PeerInfo* pInfo) { node->removePassiveProxyServer(pInfo); }
     inline void removeMasterServer(NetworkNode* node, PeerInfo* pInfo) { node->removeMasterServer(pInfo); }
 
@@ -57,5 +61,8 @@
     /** @param node node to be checked for slots @returns true if there are still free network slots available at this node */
     inline bool gotFreeSlots(NetworkNode* node) { return (node->getPlayerNumber() < NET_MAX_CONNECTIONS)?true:false; }
-    void getServerWithFreeSlots() { }
+    PeerInfo* getFirstChoiceProxy();
+    PeerInfo* getSecondChoiceProxy();
+    /** @returns true if the next client should be reconnected to some other proxy server with more connections */
+    inline bool reconnectNextClient() { return (this->localNode->getPlayerNumber() >= NET_MAX_CONNECTIONS)?true:false; }
 
 
Index: branches/proxy/src/lib/network/monitor/network_node.cc
===================================================================
--- branches/proxy/src/lib/network/monitor/network_node.cc	(revision 9297)
+++ branches/proxy/src/lib/network/monitor/network_node.cc	(revision 9300)
@@ -147,4 +147,83 @@
 
 
+/**
+ * @param index index to the client
+ * @return the client in the list or NULL if none
+ */
+PeerInfo* NetworkNode::getClient(int index)
+{
+  if( this->clientList.size() < index)
+    return NULL;
+
+  std::list<PeerInfo*>::iterator it = this->clientList.begin();
+  for(int i = 0; it != this->clientList.end(); it++, i++)
+  {
+  if( i == index)
+    return (*it);
+  }
+
+  return NULL;
+}
+
+
+/**
+ * @param index index to the client
+ * @return the active proxy server in the list or NULL if none
+ */
+PeerInfo* NetworkNode::getActiveProxyServer(int index)
+{
+  if( this->activeProxyServerList.size() < index)
+    return NULL;
+
+  std::list<PeerInfo*>::iterator it = this->activeProxyServerList.begin();
+  for(int i = 0; it != this->activeProxyServerList.end(); it++, i++)
+  {
+    if( i == index)
+      return (*it);
+  }
+
+  return NULL;
+}
+
+
+/**
+ * @param index index to the client
+ * @return the passive proxy server in the list or NULL if none
+ */
+PeerInfo* NetworkNode::getPassiveProxyServer(int index)
+{
+  if( this->passiveProxyServerList.size() < index)
+    return NULL;
+
+  std::list<PeerInfo*>::iterator it = this->passiveProxyServerList.begin();
+  for(int i = 0; it != this->passiveProxyServerList.end(); it++, i++)
+  {
+    if( i == index)
+      return (*it);
+  }
+
+  return NULL;
+}
+
+
+/**
+ * @param index index to the client
+ * @return the master server in the list or NULL if none
+ */
+PeerInfo* NetworkNode::getMasterServer(int index)
+{
+  if( this->masterServerList.size() < index)
+    return NULL;
+
+  std::list<PeerInfo*>::iterator it = this->masterServerList.begin();
+  for(int i = 0; it != this->masterServerList.end(); it++, i++)
+  {
+    if( i == index)
+      return (*it);
+  }
+
+  return NULL;
+}
+
 
 /**
Index: branches/proxy/src/lib/network/monitor/network_node.h
===================================================================
--- branches/proxy/src/lib/network/monitor/network_node.h	(revision 9297)
+++ branches/proxy/src/lib/network/monitor/network_node.h	(revision 9300)
@@ -32,4 +32,9 @@
     void removeMasterServer(PeerInfo* node);
 
+    PeerInfo* getClient(int index);
+    PeerInfo* getActiveProxyServer(int index);
+    PeerInfo* getPassiveProxyServer(int index);
+    PeerInfo* getMasterServer(int index);
+
     /** @returns the number of players */
     inline int getPlayerNumber() { return this->playerNumber; }
Index: branches/proxy/src/lib/network/netdefs.h
===================================================================
--- branches/proxy/src/lib/network/netdefs.h	(revision 9297)
+++ branches/proxy/src/lib/network/netdefs.h	(revision 9300)
@@ -33,13 +33,17 @@
 
 
-/* maximal connectinons for the server*/
+//!< maximal connectinons for the server
 #define NET_MAX_CONNECTIONS 5
 
-/* network polling frequency */
+//!< the amount of slots used before a proxy server is activated
+#define NET_CONNECTION_SATURATION 0.75
+
+//!< network polling frequency
 #define NETWORK_FREQUENCY 66
 
 
-/* handshake settings */
+//!< orxonox protocol id
 #define _ORXONOX_ID        0xF91337A0
+//!< orxonox network version identifier
 #define _ORXONOX_VERSION   1
 
Index: branches/proxy/src/lib/network/network_stream.cc
===================================================================
--- branches/proxy/src/lib/network/network_stream.cc	(revision 9297)
+++ branches/proxy/src/lib/network/network_stream.cc	(revision 9300)
@@ -81,6 +81,10 @@
   this->peers[0].nodeType = NET_MASTER_SERVER;
   this->peers[0].connectionMonitor = new ConnectionMonitor( 0 );
+  this->peers[0].ip = this->peers[0].socket->getDestAddress();
   // and set also the localhost
   this->pInfo->nodeType = NET_CLIENT;
+  // get the local ip address
+  SDLNet_ResolveHost( &this->pInfo->ip, "localhost", port );
+
 }
 
@@ -95,4 +99,6 @@
   this->serverSocket = new UdpServerSocket(port);
   this->pInfo->nodeType = NET_MASTER_SERVER;
+  // get the local ip address
+  SDLNet_ResolveHost( &this->pInfo->ip, "localhost", port );
 }
 
@@ -164,4 +170,7 @@
   if( this->pInfo)
     delete this->pInfo;
+
+  if( this->networkMonitor)
+    delete this->networkMonitor;
 }
 
@@ -182,4 +191,6 @@
 /**
  * starts the network handshake
+ * handsakes are always initialized from the client side first. this starts the handshake and therefore is only
+ * executed as client
  */
 void NetworkStream::startHandshake()
@@ -190,6 +201,6 @@
   peers[0].handshake = hs;
 
+  // set the preferred nick name
   hs->setPreferedNickName( Preferences::getInstance()->getString( "multiplayer", "nickname", "Player" ) );
-  //hs->set
 
 //   peers[0].handshake->setSynchronized( true );
@@ -314,6 +325,18 @@
       peers[clientId].socket = tempNetworkSocket;
       peers[clientId].handshake = new Handshake(this->pInfo->nodeType, clientId, this->networkGameManager->getUniqueID(), MessageManager::getInstance()->getUniqueID() );
+      peers[clientId].handshake->setUniqueID(clientId);
+
+      // get the proxy server informations and write them to the handshake, if any (proxy)
+      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->reconnectNextClient());
+
       peers[clientId].connectionMonitor = new ConnectionMonitor( clientId );
-      peers[clientId].handshake->setUniqueID(clientId);
       peers[clientId].userId = clientId;
       peers[clientId].nodeType = NET_CLIENT;
@@ -328,6 +351,18 @@
 
       peers[clientId].socket = tempNetworkSocket;
+      // handshake handling
       peers[clientId].handshake = new Handshake(this->pInfo->nodeType, clientId, this->networkGameManager->getUniqueID(), MessageManager::getInstance()->getUniqueID());
       peers[clientId].handshake->setUniqueID(clientId);
+      // get the proxy server informations and write them to the handshake, if any (proxy)
+      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->reconnectNextClient());
+
       peers[clientId].connectionMonitor = new ConnectionMonitor( clientId );
       peers[clientId].userId = clientId;
@@ -337,8 +372,10 @@
     }
 
-    // check if there are too many clients connected
+    // check if there are too many clients connected (DEPRECATED: new: the masterserver sends a list of proxy servers)
     if ( clientId > NET_MAX_CONNECTIONS )
     {
-      peers[clientId].handshake->doReject( "too many connections" );
+//       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);
     }
@@ -467,6 +504,27 @@
               this->networkMonitor->addNode(&it->second);
 
+              // get proxy 1 address and add it
+              this->networkMonitor->addNode(it->second.handshake->getProxy1Address());
+              // get proxy 2 address and add it
+              this->networkMonitor->addNode(it->second.handshake->getProxy2Address());
+
+
+              // now check if there server accepted the connection
+              if( it->second.handshake->redirect())
+              {
+                // handle the redirection
+                PRINTF(0)("===============================================\n");
+                PRINTF(0)("Client is redirected to the other proxy servers\n");
+                PRINTF(0)("===============================================\n");
+
+                // disconnect from the current server and reconnect to proxy server
+//                 it->second.socket->disconnectServer();
+
+              }
+
+              // 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() );
             }
Index: branches/proxy/src/lib/network/proxy/proxy_settings.cc
===================================================================
--- branches/proxy/src/lib/network/proxy/proxy_settings.cc	(revision 9297)
+++ branches/proxy/src/lib/network/proxy/proxy_settings.cc	(revision 9300)
@@ -43,4 +43,12 @@
 {
   ProxySettings::singletonRef = NULL;
+
+  // remove all unused proxy data again
+  for( int i = 0; i < this->proxies.size(); i++)
+  {
+    IPaddress* ip = this->proxies.back();
+    this->proxies.pop_back();
+    delete ip;
+  }
 }
 
Index: branches/proxy/src/lib/network/proxy/proxy_settings.h
===================================================================
--- branches/proxy/src/lib/network/proxy/proxy_settings.h	(revision 9297)
+++ branches/proxy/src/lib/network/proxy/proxy_settings.h	(revision 9300)
@@ -29,6 +29,10 @@
     void loadProxySettings(const TiXmlElement* root);
 
+    /** @returns the max number of players */
     inline void setMaxPlayer(int number) { this->maxPlayer = number; }
     void setProxyAddr(const std::string& proxyAddr);
+
+    /** @returns the list of proxy servers from the init file */
+    inline std::vector<IPaddress*> getProxyList() { return this->proxies; }
 
 
Index: branches/proxy/src/story_entities/multi_player_world_data.cc
===================================================================
--- branches/proxy/src/story_entities/multi_player_world_data.cc	(revision 9297)
+++ branches/proxy/src/story_entities/multi_player_world_data.cc	(revision 9300)
@@ -299,4 +299,7 @@
 ErrorMessage MultiPlayerWorldData::unloadScene()
 {
+  // delete the proxy settings
+  delete ProxySettings::getInstance();
+
   /* call underlying function */
   return GameWorldData::unloadScene();
