Index: code/branches/gui/src/orxonox/gamestates/GSClient.cc
===================================================================
--- code/branches/gui/src/orxonox/gamestates/GSClient.cc	(revision 1670)
+++ code/branches/gui/src/orxonox/gamestates/GSClient.cc	(revision 1670)
@@ -0,0 +1,87 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Reto Grieder
+ *   Co-authors:
+ *      Fabian 'x3n' Landau
+ *
+ */
+
+#include "OrxonoxStableHeaders.h"
+#include "GSClient.h"
+
+#include "core/input/InputManager.h"
+#include "core/CommandLine.h"
+#include "network/Client.h"
+
+namespace orxonox
+{
+    SetCommandLineArgument(ip, "127.0.0.0").setInformation("#.#.#.#");
+
+    GSClient::GSClient()
+        : GSLevel("client")
+        , client_(0)
+    {
+    }
+
+    GSClient::~GSClient()
+    {
+    }
+
+    void GSClient::enter()
+    {
+        GSLevel::enter();
+
+        int serverPort = CommandLine::getArgument<int>("port")->getValue();
+        std::string serverIP = CommandLine::getArgument<std::string>("ip")->getValue();
+        this->client_ = network::Client::createSingleton(serverIP, serverPort);
+
+        if(!client_->establishConnection())
+            ThrowException(InitialisationFailed, "Could not establish connection with server.");
+
+        client_->tick(0);
+
+        // level is loaded: we can start capturing the input
+        InputManager::getInstance().requestEnterState("game");
+    }
+
+    void GSClient::leave()
+    {
+        InputManager::getInstance().requestLeaveState("game");
+
+        // TODO: How do we unload the level in client mode?
+
+        client_->closeConnection();
+
+        // TODO: destroy client
+
+        GSLevel::leave();
+    }
+
+    void GSClient::ticked(float dt)
+    {
+        GSLevel::ticked(dt);
+        client_->tick(dt);
+
+        this->tickChild(dt);
+    }
+}
Index: code/branches/gui/src/orxonox/gamestates/GSClient.h
===================================================================
--- code/branches/gui/src/orxonox/gamestates/GSClient.h	(revision 1670)
+++ code/branches/gui/src/orxonox/gamestates/GSClient.h	(revision 1670)
@@ -0,0 +1,54 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Reto Grieder
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _GSClient_H__
+#define _GSClient_H__
+
+#include "OrxonoxPrereqs.h"
+#include "network/NetworkPrereqs.h"
+#include "GSLevel.h"
+
+namespace orxonox
+{
+    class _OrxonoxExport GSClient : public GSLevel
+    {
+    public:
+        GSClient();
+        ~GSClient();
+
+
+    private:
+        void enter();
+        void leave();
+        void ticked(float dt);
+
+        network::Client* client_;
+    };
+}
+
+#endif /* _GSClient_H__ */
Index: code/branches/gui/src/orxonox/gamestates/GSGUI.cc
===================================================================
--- code/branches/gui/src/orxonox/gamestates/GSGUI.cc	(revision 1664)
+++ code/branches/gui/src/orxonox/gamestates/GSGUI.cc	(revision 1670)
@@ -58,10 +58,10 @@
     }
 
-    bool GSGUI::tick(float dt)
+    void GSGUI::ticked(float dt)
     {
         // tick CEGUI
         GUIManager::getInstance().tick(dt);
 
-        return true;
+        this->tickChild(dt);
     }
 }
Index: code/branches/gui/src/orxonox/gamestates/GSGUI.h
===================================================================
--- code/branches/gui/src/orxonox/gamestates/GSGUI.h	(revision 1664)
+++ code/branches/gui/src/orxonox/gamestates/GSGUI.h	(revision 1670)
@@ -44,5 +44,5 @@
         void enter();
         void leave();
-        bool tick(float dt);
+        void ticked(float dt);
 
     };
Index: code/branches/gui/src/orxonox/gamestates/GSGraphics.cc
===================================================================
--- code/branches/gui/src/orxonox/gamestates/GSGraphics.cc	(revision 1664)
+++ code/branches/gui/src/orxonox/gamestates/GSGraphics.cc	(revision 1670)
@@ -38,5 +38,6 @@
 #include "core/ConfigValueIncludes.h"
 #include "core/input/InputManager.h"
-#include "core/Core.h"
+#include "core/TclThreadManager.h"
+//#include "core/Core.h"
 #include "overlays/console/InGameConsole.h"
 #include "gui/GUIManager.h"
@@ -48,5 +49,4 @@
         : GameState("graphics")
         , timer_(0)
-        , bAbort_(false)
         , debugRefreshTime_(0.0f)
         , inputManager_(0)
@@ -90,9 +90,4 @@
         // use the ogre timer class to measure time.
         timer_ = new Ogre::Timer();
-
-        // add console commands
-        FunctorMember<GSGraphics>* functor = createFunctor(&GSGraphics::exitGame);
-        functor->setObject(this);
-        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor, "exit"));
     }
 
@@ -123,5 +118,5 @@
         need the time. So we shouldn't run into problems.
     */
-    bool GSGraphics::tick(float dt)
+    void GSGraphics::ticked(float dt)
     {
         // note: paramter 'dt' is of no meaning
@@ -147,5 +142,5 @@
         {
             timer_->reset();
-            while (!bAbort_)
+            while (!this->hasScheduledTransition())
             {
                 // get current time
@@ -154,12 +149,8 @@
                 float dt = (timeBeforeTick - timeBeforeTickOld) / 1000000.0;
 
-
-                // tick the core (needs real time for input and tcl thread management)
-                // TODO: ticks of InputManager and tcl thread manager have to be separated.
-                Core::tick(dt);
-
-                // tick child state
-                if (this->getActiveChild())
-                    this->getActiveChild()->tick(dt);
+                this->inputManager_->tick(dt);
+                TclThreadManager::getInstance().tick(dt);
+
+                this->tickChild(dt);
 
                 // tick console
@@ -210,5 +201,5 @@
             COUT(1) << ex.what() << std::endl;
             COUT(1) << "Main loop was stopped by an unhandled exception. Shutting down." << std::endl;
-        }        return true;
+        }
     }
 }
Index: code/branches/gui/src/orxonox/gamestates/GSGraphics.h
===================================================================
--- code/branches/gui/src/orxonox/gamestates/GSGraphics.h	(revision 1664)
+++ code/branches/gui/src/orxonox/gamestates/GSGraphics.h	(revision 1670)
@@ -43,15 +43,12 @@
         ~GSGraphics();
 
-        bool tick(float dt);
         void setConfigValues();
-
-        void exitGame() { this->bAbort_ = true; }
 
     private:
         void enter();
         void leave();
+        void ticked(float dt);
 
         Ogre::Timer*          timer_;            //!< Main loop timer
-        bool                  bAbort_;           //!< aborts the render loop if true
 
         // config values
Index: code/branches/gui/src/orxonox/gamestates/GSIO.cc
===================================================================
--- code/branches/gui/src/orxonox/gamestates/GSIO.cc	(revision 1670)
+++ code/branches/gui/src/orxonox/gamestates/GSIO.cc	(revision 1670)
@@ -0,0 +1,130 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Reto Grieder
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "OrxonoxStableHeaders.h"
+#include "GSIO.h"
+
+#include <OgreFrameListener.h>
+#include <OgreRoot.h>
+#include <OgreTimer.h>
+
+#include "core/ConsoleCommand.h"
+#include "core/TclThreadManager.h"
+#include "GraphicsEngine.h"
+
+namespace orxonox
+{
+    GSIO::GSIO()
+        : GameState("io")
+        //, timer_(0)
+    {
+    }
+
+    GSIO::~GSIO()
+    {
+    }
+
+    void GSIO::enter()
+    {
+    }
+
+    void GSIO::leave()
+    {
+    }
+
+    void GSIO::ticked(float dt)
+    {
+        this->tickChild(dt);
+        //Ogre::Root& ogreRoot = Ogre::Root::getSingleton();
+
+        //unsigned long frameCount = 0;
+
+        //const unsigned long refreshTime = (unsigned long)(debugRefreshTime_ * 1000000.0f);
+        //unsigned long refreshStartTime = 0;
+        //unsigned long tickTime = 0;
+        //unsigned long oldFrameCount = 0;
+
+        //unsigned long timeBeforeTick = 0;
+        //unsigned long timeBeforeTickOld = 0;
+        //unsigned long timeAfterTick = 0;
+
+        //// TODO: Update time in seconds every 7 seconds to avoid any overflow (7 secs is very tight)
+
+        //COUT(3) << "Orxonox: Starting the main loop." << std::endl;
+
+        //try
+        //{
+        //    timer_->reset();
+        //    while (!this->hasScheduledTransition())
+        //    {
+        //        // get current time
+        //        timeBeforeTickOld = timeBeforeTick;
+        //        timeBeforeTick    = timer_->getMicroseconds();
+        //        float dt = (timeBeforeTick - timeBeforeTickOld) / 1000000.0;
+
+        //        TclThreadManager::getInstance().tick(dt);
+
+        //        this->tickChild(dt);
+
+        //        // get current time once again
+        //        timeAfterTick = timer_->getMicroseconds();
+
+        //        tickTime += timeAfterTick - timeBeforeTick;
+        //        if (timeAfterTick > refreshStartTime + refreshTime)
+        //        {
+        //            GraphicsEngine::getInstance().setAverageTickTime(
+        //                (float)tickTime * 0.001 / (frameCount - oldFrameCount));
+        //            float avgFPS = (float)(frameCount - oldFrameCount) / (timeAfterTick - refreshStartTime) * 1000000.0;
+        //            GraphicsEngine::getInstance().setAverageFramesPerSecond(avgFPS);
+
+        //            oldFrameCount = frameCount;
+        //            tickTime = 0;
+        //            refreshStartTime = timeAfterTick;
+        //        }
+
+        //        // don't forget to call _fireFrameStarted in ogre to make sure
+        //        // everything goes smoothly
+        //        Ogre::FrameEvent evt;
+        //        evt.timeSinceLastFrame = dt;
+        //        evt.timeSinceLastEvent = dt; // note: same time, but shouldn't matter anyway
+        //        ogreRoot._fireFrameStarted(evt);
+
+        //        // again, just to be sure ogre works fine
+        //        ogreRoot._fireFrameEnded(evt); // note: uses the same time as _fireFrameStarted
+
+        //        ++frameCount;
+        //    }
+        //}
+        //catch (std::exception& ex)
+        //{
+        //    // something went wrong.
+        //    COUT(1) << ex.what() << std::endl;
+        //    COUT(1) << "Main loop was stopped by an unhandled exception. Shutting down." << std::endl;
+        //}
+    }
+}
Index: code/branches/gui/src/orxonox/gamestates/GSIO.h
===================================================================
--- code/branches/gui/src/orxonox/gamestates/GSIO.h	(revision 1670)
+++ code/branches/gui/src/orxonox/gamestates/GSIO.h	(revision 1670)
@@ -0,0 +1,53 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Reto Grieder
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _GSIO_H__
+#define _GSIO_H__
+
+#include "OrxonoxPrereqs.h"
+#include <OgrePrerequisites.h>
+#include "core/GameState.h"
+
+namespace orxonox
+{
+    class _OrxonoxExport GSIO : public GameState
+    {
+    public:
+        GSIO();
+        ~GSIO();
+
+    private:
+        void enter();
+        void leave();
+        void ticked(float dt);
+
+        //Ogre::Timer*          timer_;            //!< Main loop timer
+    };
+}
+
+#endif /* _GSIO_H__ */
Index: code/branches/gui/src/orxonox/gamestates/GSIOConsole.cc
===================================================================
--- code/branches/gui/src/orxonox/gamestates/GSIOConsole.cc	(revision 1670)
+++ code/branches/gui/src/orxonox/gamestates/GSIOConsole.cc	(revision 1670)
@@ -0,0 +1,69 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Reto Grieder
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "OrxonoxStableHeaders.h"
+#include "GSIOConsole.h"
+
+#include <iostream>
+#include <OgreFrameListener.h>
+#include <OgreRoot.h>
+#include <OgreTimer.h>
+
+#include "core/ConsoleCommand.h"
+#include "core/TclThreadManager.h"
+#include "GraphicsEngine.h"
+
+namespace orxonox
+{
+    GSIOConsole::GSIOConsole()
+        : GameState("ioConsole")
+    {
+    }
+
+    GSIOConsole::~GSIOConsole()
+    {
+    }
+
+    void GSIOConsole::enter()
+    {
+    }
+
+    void GSIOConsole::leave()
+    {
+    }
+
+    void GSIOConsole::ticked(float dt)
+    {
+        while (!this->hasScheduledTransition())
+        {
+            std::string command;
+            std::cin >> command;
+            CommandExecutor::execute(command, true);
+        }
+    }
+}
Index: code/branches/gui/src/orxonox/gamestates/GSIOConsole.h
===================================================================
--- code/branches/gui/src/orxonox/gamestates/GSIOConsole.h	(revision 1670)
+++ code/branches/gui/src/orxonox/gamestates/GSIOConsole.h	(revision 1670)
@@ -0,0 +1,51 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Reto Grieder
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _GSIOConsole_H__
+#define _GSIOConsole_H__
+
+#include "OrxonoxPrereqs.h"
+#include <OgrePrerequisites.h>
+#include "core/GameState.h"
+
+namespace orxonox
+{
+    class _OrxonoxExport GSIOConsole : public GameState
+    {
+    public:
+        GSIOConsole();
+        ~GSIOConsole();
+
+    private:
+        void enter();
+        void leave();
+        void ticked(float dt);
+    };
+}
+
+#endif /* _GSIOConsole_H__ */
Index: code/branches/gui/src/orxonox/gamestates/GSLevel.cc
===================================================================
--- code/branches/gui/src/orxonox/gamestates/GSLevel.cc	(revision 1664)
+++ code/branches/gui/src/orxonox/gamestates/GSLevel.cc	(revision 1670)
@@ -30,27 +30,21 @@
 #include "GSLevel.h"
 
-#include "core/ConsoleCommand.h"
 #include "core/input/InputManager.h"
 #include "core/input/SimpleInputState.h"
 #include "core/input/KeyBinder.h"
 #include "core/Loader.h"
-#include "core/CommandLine.h"
-#include "overlays/console/InGameConsole.h"
-#include "gui/GUIManager.h"
 #include "objects/Backlight.h"
 #include "tools/ParticleInterface.h"
+#include "Settings.h"
 #include "Radar.h"
-#include "Settings.h"
 #include "GraphicsEngine.h"
 
 namespace orxonox
 {
-    SetCommandLineArgument(port, 55556).setShortcut("p").setInformation("PORT");
-    SetCommandLineArgument(ip, "127.0.0.0").setInformation("#.#.#.#");
-
-    GSLevel::GSLevel()
-        : GameState("level")
+    GSLevel::GSLevel(const std::string& name)
+        : GameState(name)
         , timefactor_(1.0f)
         , keyBinder_(0)
+        , inputState_(0)
         , radar_(0)
         , startLevel_(0)
@@ -65,7 +59,8 @@
     void GSLevel::enter()
     {
+        inputState_ = InputManager::getInstance().createInputState<SimpleInputState>("game", 20);
         keyBinder_ = new KeyBinder();
         keyBinder_->loadBindings();
-        InputManager::getInstance().createInputState<SimpleInputState>("game", 20)->setHandler(keyBinder_);
+        inputState_->setHandler(keyBinder_);
 
         // create Ogre SceneManager for the level
@@ -79,28 +74,8 @@
         hud_ = new Level(Settings::getDataPath() + "overlay/hud.oxo");
         Loader::load(hud_);
-
-        // call the loader
-        COUT(0) << "Loading level..." << std::endl;
-        startLevel_ = new Level(Settings::getDataPath() + "levels/sample.oxw");
-        Loader::open(startLevel_);
-
-        // add console commands
-        FunctorMember<GSLevel>* functor = createFunctor(&GSLevel::setTimeFactor);
-        functor->setObject(this);
-        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor, "setTimeFactor"));
-
-        // level is loaded: we can start capturing the input
-        InputManager::getInstance().requestEnterState("game");
     }
 
     void GSLevel::leave()
     {
-        InputManager::getInstance().requestLeaveState("game");
-
-        // TODO: Remove and destroy console command
-
-        Loader::unload(startLevel_);
-        delete this->startLevel_;
-
         Loader::unload(hud_);
         delete this->hud_;
@@ -116,9 +91,10 @@
         // TODO: delete SceneManager
 
-        InputManager::getInstance().destroyState("game");
+        inputState_->setHandler(0);
+        InputManager::getInstance().requestDestroyState("game");
         delete this->keyBinder_;
     }
 
-    bool GSLevel::tick(float dt)
+    void GSLevel::ticked(float dt)
     {
         // Call those objects that need the real time
@@ -128,13 +104,4 @@
         for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; ++it)
             it->tick(dt * this->timefactor_);
-
-        // TODO: split file into server/client/standalone
-        // call server/client with normal dt
-        //if (client_g)
-        //    client_g->tick(dt * this->timefactor_);
-        //if (server_g)
-        //    server_g->tick(dt * this->timefactor_);
-
-        return true;
     }
 
@@ -153,3 +120,17 @@
             it->setTimeFactor(timefactor_);
     }
+
+    void GSLevel::loadLevel()
+    {
+        // call the loader
+        COUT(0) << "Loading level..." << std::endl;
+        startLevel_ = new Level(Settings::getDataPath() + "levels/sample.oxw");
+        Loader::open(startLevel_);
+    }
+
+    void GSLevel::unloadLevel()
+    {
+        Loader::unload(startLevel_);
+        delete this->startLevel_;
+    }
 }
Index: code/branches/gui/src/orxonox/gamestates/GSLevel.h
===================================================================
--- code/branches/gui/src/orxonox/gamestates/GSLevel.h	(revision 1664)
+++ code/branches/gui/src/orxonox/gamestates/GSLevel.h	(revision 1670)
@@ -38,18 +38,26 @@
     {
     public:
-        GSLevel();
-        ~GSLevel();
+        GSLevel(const std::string& name);
+        virtual ~GSLevel();
 
-        bool tick(float dt);
+        // this has to be public because proteced triggers a bug in msvc
+        // when taking the function address.
+        void setTimeFactor(float factor);
+        float getTimeFactor() { return this->timefactor_; }
+
+    protected:
+        virtual void enter();
+        virtual void leave();
+        virtual void ticked(float dt);
+
+        void loadLevel();
+        void unloadLevel();
 
     private:
-        void enter();
-        void leave();
-
-        void setTimeFactor(float factor);
 
         float timefactor_;       //!< A factor to change the gamespeed
 
         KeyBinder*            keyBinder_;        //!< tool that loads and manages the input bindings
+        SimpleInputState*     inputState_;
         Radar*                radar_;            //!< represents the Radar (not the HUD part)
         Level*                startLevel_;       //!< current hard coded default level
Index: code/branches/gui/src/orxonox/gamestates/GSRoot.cc
===================================================================
--- code/branches/gui/src/orxonox/gamestates/GSRoot.cc	(revision 1664)
+++ code/branches/gui/src/orxonox/gamestates/GSRoot.cc	(revision 1670)
@@ -52,4 +52,5 @@
         , settings_(0)
         , graphicsEngine_(0)
+        , bExit_(false)
     {
     }
@@ -101,5 +102,5 @@
 
         std::string dataPath;
-        CommandLine::getCommandLineValue("dataPath", &dataPath);
+        CommandLine::getValue("dataPath", &dataPath);
         if (dataPath != "")
         {
@@ -122,5 +123,8 @@
         CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor, "loadGame"));
 
-        requestState("gui");
+        // add console commands
+        functor = createFunctor(&GSRoot::exitGame);
+        functor->setObject(this);
+        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor, "exit"));
     }
 
@@ -128,13 +132,12 @@
     {
         delete graphicsEngine_;
+        delete settings_;
 
-        delete settings_;
+        // TODO: remove and destroy console commands
     }
 
-    bool GSRoot::tick(float dt)
+    void GSRoot::ticked(float dt)
     {
-        if (this->getActiveChild())
-            this->getActiveChild()->tick(dt);
-        return true;
+        this->tickChild(dt);
     }
 
Index: code/branches/gui/src/orxonox/gamestates/GSRoot.h
===================================================================
--- code/branches/gui/src/orxonox/gamestates/GSRoot.h	(revision 1664)
+++ code/branches/gui/src/orxonox/gamestates/GSRoot.h	(revision 1670)
@@ -42,13 +42,18 @@
 
         void feedCommandLine(int argc, char** argv);
-        bool tick(float dt);
         void loadGame(const std::string& name);
+
+        void exitGame()
+        { requestState("root"); }
+        bool isGameFinished() { return (this->getActiveChild() == 0); }
 
     private:
         void enter();
         void leave();
+        void ticked(float dt);
 
         Settings*             settings_;
         GraphicsEngine*       graphicsEngine_;   //!< our dearest graphics engine <3
+        bool                  bExit_;
     };
 }
Index: code/branches/gui/src/orxonox/gamestates/GSServer.cc
===================================================================
--- code/branches/gui/src/orxonox/gamestates/GSServer.cc	(revision 1670)
+++ code/branches/gui/src/orxonox/gamestates/GSServer.cc	(revision 1670)
@@ -0,0 +1,91 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Reto Grieder
+ *   Co-authors:
+ *      Fabian 'x3n' Landau
+ *
+ */
+
+#include "OrxonoxStableHeaders.h"
+#include "GSServer.h"
+
+#include "core/ConsoleCommand.h"
+#include "core/input/InputManager.h"
+#include "core/CommandLine.h"
+#include "network/Server.h"
+
+namespace orxonox
+{
+    SetCommandLineArgument(port, 55556).setShortcut("p").setInformation("0-65535");
+
+    GSServer::GSServer()
+        : GSLevel("server")
+        , server_(0)
+    {
+    }
+
+    GSServer::~GSServer()
+    {
+    }
+
+    void GSServer::enter()
+    {
+        GSLevel::enter();
+
+        int serverPort = CommandLine::getArgument<int>("port")->getValue();
+        this->server_ = network::Server::createSingleton(serverPort);
+
+        this->loadLevel();
+
+        server_->open();
+
+        // add console commands
+        FunctorMember<GSLevel>* functor = createFunctor(&GSLevel::setTimeFactor);
+        functor->setObject(this);
+        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor, "setTimeFactor"));
+
+        // level is loaded: we can start capturing the input
+        InputManager::getInstance().requestEnterState("game");
+    }
+
+    void GSServer::leave()
+    {
+        InputManager::getInstance().requestLeaveState("game");
+
+        // TODO: Remove and destroy console command
+
+        this->unloadLevel();
+
+        this->server_->close();
+        // TODO: destroy server
+
+        GSLevel::leave();
+    }
+
+    void GSServer::ticked(float dt)
+    {
+        GSLevel::ticked(dt);
+        server_->tick(dt);
+        this->tickChild(dt);
+    }
+}
Index: code/branches/gui/src/orxonox/gamestates/GSServer.h
===================================================================
--- code/branches/gui/src/orxonox/gamestates/GSServer.h	(revision 1670)
+++ code/branches/gui/src/orxonox/gamestates/GSServer.h	(revision 1670)
@@ -0,0 +1,54 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Reto Grieder
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _GSServer_H__
+#define _GSServer_H__
+
+#include "OrxonoxPrereqs.h"
+#include "network/NetworkPrereqs.h"
+#include "GSLevel.h"
+
+namespace orxonox
+{
+    class _OrxonoxExport GSServer : public GSLevel
+    {
+    public:
+        GSServer();
+        ~GSServer();
+
+
+    private:
+        void enter();
+        void leave();
+        void ticked(float dt);
+
+        network::Server*      server_;
+    };
+}
+
+#endif /* _GSServer_H__ */
Index: code/branches/gui/src/orxonox/gamestates/GSStandalone.cc
===================================================================
--- code/branches/gui/src/orxonox/gamestates/GSStandalone.cc	(revision 1670)
+++ code/branches/gui/src/orxonox/gamestates/GSStandalone.cc	(revision 1670)
@@ -0,0 +1,78 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Reto Grieder
+ *   Co-authors:
+ *      Fabian 'x3n' Landau
+ *
+ */
+
+#include "OrxonoxStableHeaders.h"
+#include "GSStandalone.h"
+
+#include "core/input/InputManager.h"
+#include "core/ConsoleCommand.h"
+
+namespace orxonox
+{
+    GSStandalone::GSStandalone()
+        : GSLevel("standalone")
+    {
+    }
+
+    GSStandalone::~GSStandalone()
+    {
+    }
+
+    void GSStandalone::enter()
+    {
+        GSLevel::enter();
+
+        this->loadLevel();
+
+        // add console commands
+        FunctorMember<GSLevel>* functor = createFunctor(&GSLevel::setTimeFactor);
+        functor->setObject(this);
+        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor, "setTimeFactor"));
+
+        // level is loaded: we can start capturing the input
+        InputManager::getInstance().requestEnterState("game");
+    }
+
+    void GSStandalone::leave()
+    {
+        InputManager::getInstance().requestLeaveState("game");
+
+        // TODO: Remove and destroy console command
+
+        this->unloadLevel();
+
+        GSLevel::leave();
+    }
+
+    void GSStandalone::ticked(float dt)
+    {
+        GSLevel::ticked(dt);
+
+        this->tickChild(dt);
+    }
+}
Index: code/branches/gui/src/orxonox/gamestates/GSStandalone.h
===================================================================
--- code/branches/gui/src/orxonox/gamestates/GSStandalone.h	(revision 1670)
+++ code/branches/gui/src/orxonox/gamestates/GSStandalone.h	(revision 1670)
@@ -0,0 +1,51 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Reto Grieder
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _GSStandalone_H__
+#define _GSStandalone_H__
+
+#include "OrxonoxPrereqs.h"
+#include "GSLevel.h"
+
+namespace orxonox
+{
+    class _OrxonoxExport GSStandalone : public GSLevel
+    {
+    public:
+        GSStandalone();
+        ~GSStandalone();
+
+
+    private:
+        void enter();
+        void leave();
+        void ticked(float dt);
+    };
+}
+
+#endif /* _GSStandalone_H__ */
