Index: code/branches/netp4/src/orxonox/gamestates/GSDedicated.cc
===================================================================
--- code/branches/netp4/src/orxonox/gamestates/GSDedicated.cc	(revision 3113)
+++ code/branches/netp4/src/orxonox/gamestates/GSDedicated.cc	(revision 3119)
@@ -31,4 +31,5 @@
 #include "core/Clock.h"
 #include "core/CommandLine.h"
+#include "core/CommandExecutor.h"
 #include "core/Game.h"
 #include "core/GameMode.h"
@@ -38,6 +39,13 @@
 #include "util/Sleep.h"
 
+#include <iostream>
+#include <iomanip>
+#include <boost/bind.hpp>
+
+
 namespace orxonox
 {
+    const unsigned int MAX_COMMAND_LENGTH = 255;
+    
     AddGameState(GSDedicated, "dedicated");
 
@@ -46,9 +54,21 @@
         , server_(0)
         , timeSinceLastUpdate_(0)
+        , closeThread_(false)
+        , inputIterator_(0)
+        , cleanLine_(true)
     {
+        this->inputThread_ = new boost::thread(boost::bind(&GSDedicated::inputThread, this));
+        this->commandLine_ = new unsigned char[MAX_COMMAND_LENGTH];
+//         memset( this->commandLine_, 0, MAX_COMMAND_LENGTH );
     }
 
     GSDedicated::~GSDedicated()
     {
+        closeThread_ = true;
+#ifndef ORXONOX_PLATFORM_WINDOWS
+        std::cout << "\033[0G\033[K";
+        std::cout.flush();
+#endif
+        //inputThread_->join();
     }
 
@@ -73,11 +93,7 @@
     void GSDedicated::update(const Clock& time)
     {
-//        static float startTime = time.getSecondsPrecise();
-//        static int nrOfTicks = 0;
         timeSinceLastUpdate_ += time.getDeltaTime();
         if (timeSinceLastUpdate_ >= NETWORK_PERIOD)
         {
-//            ++nrOfTicks;
-//            COUT(0) << "estimated ticks/sec: " << nrOfTicks/(time.getSecondsPrecise()-startTime) << endl;
             timeSinceLastUpdate_ -= static_cast<unsigned int>(timeSinceLastUpdate_ / NETWORK_PERIOD) * NETWORK_PERIOD;
             server_->update(time);
@@ -85,6 +101,65 @@
         else
         {
-            usleep((int)((NETWORK_PERIOD - timeSinceLastUpdate_) * 1000 * 1000));
+            usleep((unsigned int)((NETWORK_PERIOD - timeSinceLastUpdate_)*1000*1000 ));
+            usleep(NETWORK_PERIOD*1000*1000); // NOTE: this is to throttle the non-network framerate
 //            COUT(0) << "sleeping for " << (int)((NETWORK_PERIOD - timeSinceLastUpdate_) * 1000 * 1000) << " usec" << endl;
+        }
+        processQueue();
+        printLine();
+    }
+    
+    void GSDedicated::inputThread()
+    {
+        unsigned char c;
+        while(!closeThread_)
+        {
+            c = getchar();
+            {
+//                 boost::recursive_mutex::scoped_lock(this->inputLineMutex_);
+                if ( inputIterator_>=MAX_COMMAND_LENGTH-1 && c!='\n' )
+                    continue;
+                this->commandLine_[this->inputIterator_++] = c;
+                if( c == '\n' )
+                {
+                    this->cleanLine_ = true;
+                    boost::recursive_mutex::scoped_lock(this->inputQueueMutex_);
+                    this->commandQueue_.push( std::string((const char*)this->commandLine_,inputIterator_) );
+                    inputIterator_ = 0;
+                }
+            }
+        }
+    }
+    
+    void GSDedicated::printLine()
+    {
+#ifndef ORXONOX_PLATFORM_WINDOWS
+        std::cout << "\033[s\033[0G";
+//         boost::recursive_mutex::scoped_lock(this->inputLineMutex_);
+        std::cout << std::fixed << std::setprecision(2) << std::setw(5) << Game::getInstance().getAvgFPS() << " fps, " << std::setprecision(2) << std::setw(5) << Game::getInstance().getAvgTickTime() << " ms avg ticktime # ";
+        if ( this->cleanLine_ )
+            this->cleanLine_ = false;
+        else
+            std::cout <<"\033[u";
+        std::cout.flush();
+#endif
+    }
+    
+    void GSDedicated::processQueue()
+    {
+        std::string tempstr;
+        {
+            boost::recursive_mutex::scoped_lock lock1(this->inputQueueMutex_);
+            while(true)
+            {
+                if ( !this->commandQueue_.empty() )
+                {
+                    tempstr = this->commandQueue_.front();
+                    this->commandQueue_.pop();
+                    lock1.unlock();
+                }
+                else
+                    break;
+                CommandExecutor::execute(tempstr, true);
+            }
         }
     }
