Index: code/branches/presentation3/src/libraries/network/Client.cc
===================================================================
--- code/branches/presentation3/src/libraries/network/Client.cc	(revision 6912)
+++ code/branches/presentation3/src/libraries/network/Client.cc	(revision 7161)
@@ -50,9 +50,12 @@
 #include "FunctionCallManager.h"
 #include "core/CoreIncludes.h"
+#include "core/CommandLineParser.h"
 #include "core/Game.h"
+#include "core/ScopedSingletonManager.h"
 
 namespace orxonox
 {
 
+  ManageScopedSingleton( Client, ScopeID::Root, true );
 
   /**
@@ -61,25 +64,14 @@
   */
   Client::Client():
+      gamestate(0),
       isSynched_(false),
       gameStateFailure_(false),
       timeSinceLastUpdate_(0)
   {
-  }
-
-  /**
-  * Constructor for the Client class
-  * @param address the server address
-  * @param port port of the application on the server
-  */
-  Client::Client(const std::string& address, int port):
-      isSynched_(false),
-      gameStateFailure_(false),
-      timeSinceLastUpdate_(0)
-  {
-      setPort( port );
-      setServerAddress( address );
-  }
-
-  Client::~Client(){
+    this->setDestination( CommandLineParser::getValue("dest").getString(), CommandLineParser::getValue("port") );
+  }
+
+  Client::~Client()
+  {
     if ( ClientConnection::isConnected() )
       closeConnection();
@@ -90,7 +82,15 @@
   * @return true/false
   */
-  bool Client::establishConnection(){
+  bool Client::establishConnection()
+  {
     Synchronisable::setClient(true);
-    return ClientConnection::establishConnection();
+    this->gamestate = new GamestateClient();
+    if( ClientConnection::establishConnection() )
+    {
+      Host::setActive(true);
+      return true;
+    }
+    else
+      return false;
   }
 
@@ -99,9 +99,21 @@
   * @return true/false
   */
-  bool Client::closeConnection(){
+  bool Client::closeConnection()
+  {
+    assert(this->gamestate);
+    delete this->gamestate;
+    this->gamestate = 0;
+    Host::setActive(false);
     return ClientConnection::closeConnection();
   }
-
-  bool Client::queuePacket(ENetPacket *packet, int clientID){
+  
+  void Client::setDestination(const std::string& serverAddress, unsigned int port)
+  {
+    ClientConnection::setServerAddress(serverAddress);
+    ClientConnection::setPort(port);
+  }
+
+  bool Client::queuePacket(ENetPacket *packet, int clientID)
+  {
     bool b = ClientConnection::addPacket(packet);
     assert(b);
@@ -109,10 +121,12 @@
   }
 
-  bool Client::processChat(const std::string& message, unsigned int playerID){
+  bool Client::processChat(const std::string& message, unsigned int playerID)
+  {
 //    COUT(1) << "Player " << playerID << ": " << message << std::endl;
     return true;
   }
 
-  void Client::printRTT(){
+  void Client::printRTT()
+  {
     COUT(0) << "Round trip time to server is " << ClientConnection::getRTT() << " ms" << endl;
   }
@@ -123,5 +137,6 @@
    * @return result(true/false)
    */
-  bool Client::chat(const std::string& message){
+  bool Client::chat(const std::string& message)
+  {
     packet::Chat *m = new packet::Chat(message, Host::getPlayerID());
     return m->send();
@@ -133,5 +148,6 @@
    * @param time
    */
-  void Client::update(const Clock& time){
+  void Client::update(const Clock& time)
+  {
     //this steers our network frequency
     timeSinceLastUpdate_+=time.getDeltaTime();
@@ -143,5 +159,5 @@
       {
         COUT(4) << "popping partial gamestate: " << std::endl;
-        packet::Gamestate *gs = gamestate.getGamestate();
+        packet::Gamestate *gs = gamestate->getGamestate();
         //assert(gs); <--- there might be the case that no data has to be sent, so its commented out now
         if(gs){
@@ -157,10 +173,10 @@
 
     Connection::processQueue();
-    if(gamestate.processGamestates())
+    if(gamestate->processGamestates())
     {
       if(!isSynched_)
         isSynched_=true;
     }
-    gamestate.cleanup();
+    gamestate->cleanup();
     Connection::sendPackets();
 
@@ -184,3 +200,5 @@
   }
 
+
+
 }
