Index: code/branches/output/src/orxonox/CMakeLists.txt
===================================================================
--- code/branches/output/src/orxonox/CMakeLists.txt	(revision 8826)
+++ code/branches/output/src/orxonox/CMakeLists.txt	(revision 8828)
@@ -32,6 +32,4 @@
   PlayerManager.cc
   Radar.cc
-  ChatHistory.cc
-  ChatInputHandler.cc
 #  Test.cc
 
@@ -42,4 +40,5 @@
 )
 
+ADD_SUBDIRECTORY(chat)
 ADD_SUBDIRECTORY(collisionshapes)
 ADD_SUBDIRECTORY(controllers)
@@ -59,5 +58,5 @@
   FIND_HEADER_FILES
   TOLUA_FILES
-    ChatInputHandler.h
+    chat/ChatInputHandler.h
     LevelInfo.h
     LevelManager.h
Index: code/branches/output/src/orxonox/ChatHistory.cc
===================================================================
--- code/branches/output/src/orxonox/ChatHistory.cc	(revision 8826)
+++ 	(revision )
@@ -1,186 +1,0 @@
-/*
- *   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:
- *      Sandro 'smerkli' Merkli
- *   Co-authors:
- *      ...
- *
- */
-
-#include "ChatHistory.h"
-#include "util/ScopedSingletonManager.h"
-
-#ifndef CHATTEST
-namespace orxonox
-{
-  /* singleton */
-  ManageScopedSingleton( ChatHistory, ScopeID::Root, false );
-#endif
-
-  /* constructor */
-#ifndef CHATTEST
-  //ChatHistory::ChatHistory( BaseObject* creator ) : BaseObject(creator)
-  ChatHistory::ChatHistory()
-#else
-  ChatHistory::ChatHistory()
-#endif
-  {
-    /* register the object */
-#ifndef CHATTEST
-    RegisterObject(ChatHistory);
-#endif
-
-    this->hist_log_enabled = true;
-
-    /* Read setting for logfiles */
-    if( hist_log_enabled ) /* NOTE Make this a check for the logfile setting */
-    { this->chat_hist_openlog();
-
-      /* push starting line */
-      this->chat_hist_logline( "--- Logfile opened ---" );
-    }
-
-    /* Read setting for maximum number of lines and set limit */
-    this->hist_maxlines = 200; /* NOTE to be changed, 200 is just for testing */
-  }
-
-  /* destructor */
-  ChatHistory::~ChatHistory()
-  {
-    chat_hist_closelog();
-
-    /* clear list */
-    this->hist_buffer.clear();
-  }
-
-  /* react to incoming chat */
-  void ChatHistory::incomingChat(const std::string& message,
-    unsigned int senderID)
-  {
-    /* --> a) look up the actual name of the sender */
-    std::string text = message;
-
-#ifndef CHATTEST
-    /* get sender ID and prepend it to the message */
-    if (senderID != NETWORK_PEER_ID_UNKNOWN)
-    {
-      PlayerInfo* player = PlayerManager::getInstance().getClient(senderID);
-      if (player)
-        text = player->getName() + ": " + message;
-    }
-#endif
-
-    /* add the line to the history */
-    this->chat_hist_addline( text );
-
-    /* add the line to the log */
-    this->chat_hist_logline( text );
-  }
-
-  /* Synchronize logfile onto the hard drive */ /* MARK MARK */
-  int ChatHistory::syncLog()
-  {
-    //if( this->hist_logfile )
-      //this->hist_logfile.sync();
-    return 0;
-  }
-
-  /* add a line to this history */
-  int ChatHistory::chat_hist_addline( const std::string& toadd )
-  {
-    /* crop history at the end if it's too large */
-    while( this->hist_buffer.size() > this->hist_maxlines+1 )
-      this->hist_buffer.pop_front();
-
-    /* push to the front of the history */
-    this->hist_buffer.push_back( toadd );
-    return 0;
-  }
-
-  /* log a line to a logfile */
-  int ChatHistory::chat_hist_logline( const std::string& toadd )
-  {
-    /* output the line to the file if logging is enabled */
-    if( this->hist_log_enabled )
-      this->hist_logfile << toadd << endl;
-    return 0;
-  }
-
-  /* open logfile */
-  int ChatHistory::chat_hist_openlog()
-  {
-    /* TODO: find out the name of the file to log to via settings
-     *       and set the this->hist_logfile_path variable to it
-     */
-#ifndef CHATTEST
-    this->hist_logfile.open( (PathConfig::getInstance().getLogPathString() +
-      "chatlog.log").c_str(),
-      std::fstream::out | std::fstream::app );
-#else
-    this->hist_logfile.open( "/tmp/chatlog.log",
-      std::fstream::out | std::fstream::app );
-#endif
-
-    /* TODO check whether this works (not sure how you'd like it?) */
-    if( !this->hist_logfile )
-    { this->hist_log_enabled = false;
-#ifndef CHATTEST
-      orxout(internal_warning) << "Could not open logfile." << endl;
-#endif
-    }
-
-    /* if it worked */
-    return 0;
-  }
-
-  /* close logfile */
-  void ChatHistory::chat_hist_closelog()
-  {
-    /* see if we've actually got a logfile */
-    if( this->hist_logfile )
-    {
-      /* yes, we've got one, add a line that shows we're closing it */
-      this->chat_hist_logline( "--- Logfile closed ---" );
-
-      /* actually close down the file */
-      this->hist_logfile.close();
-    }
-  }
-
-  /* output history for debugging */
-  void ChatHistory::debug_printhist()
-  {
-    /* create deque iterator */
-    std::deque<std::string>::iterator it;
-
-    /* output all the strings */
-    for( it = this->hist_buffer.begin(); it != this->hist_buffer.end();
-      ++it )
-      orxout(debug_output) << *it << endl;
-
-    /* output size */
-    orxout(debug_output) << "Size: " << hist_buffer.size() << endl;
-  }
-
-#ifndef CHATTEST
-}
-#endif
Index: code/branches/output/src/orxonox/ChatHistory.h
===================================================================
--- code/branches/output/src/orxonox/ChatHistory.h	(revision 8826)
+++ 	(revision )
@@ -1,149 +1,0 @@
-/*
- *   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:
- *      Sandro 'smerkli' Merkli
- *   Co-authors:
- *      ...
- *
- */
-
-#include <deque>
-#include <string>
-#include <fstream>
-#include <iostream>
-#include <cassert>
-
-/* define this if you're unit testing */
-//#define CHATTEST
-
-#ifndef CHATTEST
-#include <OrxonoxPrereqs.h>
-#include <PlayerManager.h>
-#include <infos/PlayerInfo.h>
-#include <core/BaseObject.h>
-#include <network/ChatListener.h>
-#include <core/PathConfig.h>
-#include <util/Singleton.h>
-#endif
-
-#ifndef _ChatHistory_H__
-#define _ChatHistory_H__
-
-
-/* Class to implement chat history */
-#ifndef CHATTEST
-namespace orxonox
-{
-#endif
-
-  /* constructor */
-#ifndef CHATTEST
-  class _OrxonoxExport ChatHistory : public ChatListener,
-    public Singleton<ChatHistory>
-
-#else
-  class ChatHistory
-#endif
-  {
-    public:
-      /* constructors, destructors */
-#ifndef CHATTEST
-      ChatHistory();
-      friend class Singleton<ChatHistory>;
-#else
-      ChatHistory();
-#endif
-      virtual ~ChatHistory();
-
-
-    //protected:
-      /** what to do with incoming chat
-       *
-       * \param message The incoming message
-       * \param senderID Identification number of the sender
-       */
-      virtual void incomingChat(const std::string& message,
-        unsigned int senderID);
-
-      /** Synchronize logfile onto the hard drive
-       *
-       * \return 0 for success, other for error
-       */
-      int syncLog();
-
-      /** debug-print: output the whole history to stdout */
-      void debug_printhist();
-
-    private:
-      /* FIELDS */
-      /** Vector to store the history in */
-      std::deque<std::string> hist_buffer;
-
-      /** Maximum number of lines stored in this history */
-      unsigned int hist_maxlines;
-
-      /** is logging enabled? */
-      bool hist_log_enabled;
-
-      /** path of logfile on the file system */
-      std::string hist_logfile_path;
-
-      /** Output file stream for logfile */
-      std::ofstream hist_logfile;
-
-#ifndef CHATTEST
-      static ChatHistory* singletonPtr_s;
-#endif
-
-
-
-      /* METHODS */
-      /** Append line to chat history
-       *
-       * \param toadd The line to add to the history
-       * \return 0 for success, other for error TODO: Throw exception
-       */
-      int chat_hist_addline( const std::string& toadd );
-
-      /** Append line to logfile
-       *
-       * \param toadd The line to add to the logfile
-       * \return 0 for success, other for error TODO: Throw exception
-       */
-      int chat_hist_logline( const std::string& toadd );
-
-      /** open logfile to log to
-       *
-       * \return 0 for success,s other for error
-       */
-      int chat_hist_openlog();
-
-
-      /** close logfile */
-      void chat_hist_closelog();
-  };
-
-#ifndef CHATTEST
-}
-#endif
-
-#endif /* _ChatHistory_H__ */
Index: code/branches/output/src/orxonox/ChatInputHandler.cc
===================================================================
--- code/branches/output/src/orxonox/ChatInputHandler.cc	(revision 8826)
+++ 	(revision )
@@ -1,358 +1,0 @@
-/*
- *   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:
- *      Sandro 'smerkli' Merkli
- *   Co-authors:
- *      ...
- *
- */
-
-#include "ChatInputHandler.h"
-
-#include <cassert>
-#include <string>
-#include <CEGUIWindow.h>
-#include <CEGUIWindowManager.h>
-#include <elements/CEGUIListbox.h>
-#include <elements/CEGUIListboxItem.h>
-#include <elements/CEGUIListboxTextItem.h>
-
-#include "util/ScopedSingletonManager.h"
-#include "core/CoreIncludes.h"
-#include "core/GUIManager.h"
-#include "core/command/ConsoleCommand.h"
-#include "core/input/InputBuffer.h"
-#include "core/input/InputManager.h"
-#include "core/input/InputState.h"
-#include "network/Host.h"
-
-#include "PlayerManager.h"
-#include "infos/PlayerInfo.h"
-
-namespace orxonox
-{
-  /* singleton */
-  ManageScopedSingleton( ChatInputHandler, ScopeID::Graphics, false );
-
-  /* add commands to console */
-  SetConsoleCommand( "startchat", &ChatInputHandler::activate_static );
-  SetConsoleCommand( "startchat_small", &ChatInputHandler::activate_small_static );
-
-  /* constructor */
-  ChatInputHandler::ChatInputHandler()
-  {
-    /* register the object  */
-    RegisterObject(ChatInputHandler);
-
-    /* create necessary objects */
-    this->inpbuf = new InputBuffer();
-    this->disp_offset = 0;
-    assert( this->inpbuf != NULL );
-
-    /* generate chatbox ui and chatbox-inputonly ui */
-    GUIManager::getInstance().loadGUI( "ChatBox" );
-    GUIManager::getInstance().loadGUI( "ChatBox-inputonly" );
-
-    /* setup colors */
-    setupColors();
-
-    /* configure the input buffer */
-    configureInputBuffer();
-
-    this->inputState = InputManager::getInstance().createInputState( "chatinput", false, false, InputStatePriority::Dynamic );
-    this->inputState->setKeyHandler(this->inpbuf);
-  }
-
-  ChatInputHandler::~ChatInputHandler()
-  {
-    /* Clean up */
-    InputManager::getInstance().destroyState("chatinput");
-    delete this->inpbuf;
-  }
-
-  /* configure input buffer, sub for the constructor */
-  void ChatInputHandler::configureInputBuffer()
-  {
-    /* INSTALL CALLBACKS */
-    /* input has changed */
-    this->inpbuf->registerListener(this, &ChatInputHandler::inputChanged, true);
-
-    /* add a line */
-    this->inpbuf->registerListener(this, &ChatInputHandler::addline,         '\r',   false);
-    this->inpbuf->registerListener(this, &ChatInputHandler::addline,         '\n',   false);
-
-    /* backspace */
-    this->inpbuf->registerListener(this, &ChatInputHandler::backspace,       '\b',   true);
-    //this->inpbuf->registerListener(this, &ChatInputHandler::backspace,       '\177', true);
-
-    /* exit the chatinputhandler thingy (tbd) */
-    this->inpbuf->registerListener(this, &ChatInputHandler::exit,            '\033', true); // escape
-
-    /* delete character */
-    this->inpbuf->registerListener(this, &ChatInputHandler::deleteChar,      KeyCode::Delete);
-
-    /* cursor movement */
-    this->inpbuf->registerListener(this, &ChatInputHandler::cursorRight,     KeyCode::Right);
-    this->inpbuf->registerListener(this, &ChatInputHandler::cursorLeft,      KeyCode::Left);
-    this->inpbuf->registerListener(this, &ChatInputHandler::cursorEnd,       KeyCode::End);
-    this->inpbuf->registerListener(this, &ChatInputHandler::cursorHome,      KeyCode::Home);
-
-    /* GET WINDOW POINTERS */
-    input = CEGUI::WindowManager::getSingleton().getWindow( "orxonox/ChatBox/input" );
-    inputonly = CEGUI::WindowManager::getSingleton().getWindow( "orxonox/ChatBox-inputonly/input" );
-
-    /* get pointer to the history window */
-    CEGUI::Window *history = CEGUI::WindowManager::getSingleton().getWindow( "orxonox/ChatBox/history" );
-
-    /* cast it to a listbox */
-    lb_history = dynamic_cast<CEGUI::Listbox*>(history);
-
-    /* assert wee */
-    assert( lb_history );
-  }
-
-  /* setup the colors, sub for the constructor */
-  void ChatInputHandler::setupColors()
-  {
-    /* auto variables */
-    float red = 1.0, green = 0.5, blue = 0.5;
-    int i = 0;
-
-    // three loops: red tones, blue tones and green tones
-    // reds
-    for( i = 0; i < NumberOfColors/3; ++i )
-    { this->text_colors[ i ] = CEGUI::colour( red, green, blue );
-      green += 0.2f, blue += 0.2f;
-    }
-
-    // greens
-    red = 0.5, green = 1, blue = 0.5;
-    for( ; i < NumberOfColors*2/3; ++i )
-    { this->text_colors[ i ] = CEGUI::colour( red, green, blue );
-      red += 0.2f, blue += 0.2f;
-    }
-
-    // blues
-    red = 0.5, green = 0.5, blue = 1;
-    for( ; i < NumberOfColors; ++i )
-    { this->text_colors[ i ] = CEGUI::colour( red, green, blue );
-      red += 0.2f, green += 0.2f;
-    }
-  }
-
-
-  /* activate, deactivate */
-  void ChatInputHandler::activate_static()
-  { ChatInputHandler::getInstance().activate( true ); }
-
-  void ChatInputHandler::activate_small_static()
-  { ChatInputHandler::getInstance().activate( false ); }
-
-  void ChatInputHandler::activate( bool full )
-  {
-    /* start listening */
-    InputManager::getInstance().enterState("chatinput");
-
-    /* MARK add spawning of chat widget stuff here.*/
-    if( full )
-      GUIManager::getInstance().showGUI( "ChatBox" );
-    else
-      GUIManager::getInstance().showGUI( "ChatBox-inputonly" );
-
-    this->fullchat = full;
-  }
-
-  void ChatInputHandler::deactivate()
-  {
-    /* stop listening */
-    InputManager::getInstance().leaveState("chatinput");
-
-    /* un-spawning of chat widget stuff */
-    GUIManager::getInstance().hideGUI( "ChatBox" );
-    GUIManager::getInstance().hideGUI( "ChatBox-inputonly" );
-  }
-
-
-  /* subs for incomingChat */
-  void ChatInputHandler::sub_setcolor( CEGUI::ListboxTextItem *tocolor,
-    std::string name )
-  {
-    /* sanity checks */
-    if( !tocolor )
-      orxout(internal_warning) << "Empty ListBoxTextItem given to "
-        "ChatInputhandler::sub_setcolor()." << endl;
-
-    /* "hash" the name */
-    int hash = 0;
-    for( int i = name.length(); i > 0; --i )
-      hash += name[i-1];
-    hash = hash % this->NumberOfColors;
-
-    /* set the color according to the hash */
-    tocolor->setTextColours( this->text_colors[ hash ] );
-  }
-
-  /* handle incoming chat */
-  void ChatInputHandler::incomingChat(const std::string& message,
-    unsigned int senderID)
-  {
-    /* look up the actual name of the sender */
-    std::string text = message;
-    std::string name = "";
-
-    /* setup player name info */
-    if (senderID != NETWORK_PEER_ID_UNKNOWN)
-    {
-       PlayerInfo* player = PlayerManager::getInstance().getClient(senderID);
-       if (player)
-       {
-         name = player->getName();
-         text = name + ": " + message;
-       }
-    }
-
-    /* create item */
-    CEGUI::ListboxTextItem *toadd = new CEGUI::ListboxTextItem( text );
-
-    /* setup colors */
-    if (name != "")
-      sub_setcolor( toadd, name );
-
-    /* now add */
-    this->lb_history->addItem( dynamic_cast<CEGUI::ListboxItem*>(toadd) );
-    this->lb_history->ensureItemIsVisible(
-      dynamic_cast<CEGUI::ListboxItem*>(toadd) );
-
-    /* make sure the history handles it */
-    this->lb_history->handleUpdatedItemData();
-  }
-
-
-  /* sub for inputchanged */
-  void ChatInputHandler::sub_adjust_dispoffset( int maxlen,
-    int cursorpos,
-    int inplen )
-  {
-    /* already start offsetting 5 characters before end */
-    if( cursorpos+5 > maxlen )
-    {
-      /* always stay 5 characters ahead of end, looks better */
-      ((disp_offset = cursorpos-maxlen+5) >= 0) ? 1 : disp_offset = 0;
-
-      /* enforce visibility of cursor */
-      (disp_offset > cursorpos ) ? disp_offset = 0 : 1;
-    }
-
-    /* make sure we don't die at substr */
-    if( inplen <= disp_offset ) disp_offset = 0;
-  }
-
-  /* callbacks for InputBuffer */
-  void ChatInputHandler::inputChanged()
-  {
-    /* update the cursor and the window */
-    std::string raw = this->inpbuf->get();
-    int cursorpos = this->inpbuf->getCursorPosition();
-
-    /* get string before cursor */
-    std::string left = raw.substr( 0, cursorpos );
-
-    /* see if there's a string after the cursor */
-    std::string right = "";
-    if( raw.length() >= left.length()+1 )
-      right = raw.substr( cursorpos );
-
-    /* set the text */
-    std::string assembled = "$ " + left + "|" + right;
-
-    if( this->fullchat )
-    {
-      /* adjust curser position - magic number 5 for font width */
-      sub_adjust_dispoffset( (int)(this->input->getUnclippedInnerRect().getWidth()/6),
-        cursorpos, assembled.length() );
-      this->input->setProperty( "Text", assembled.substr( disp_offset ) );
-    }
-    else
-    {
-      /* adjust curser position - magic number 5 for font width */
-      sub_adjust_dispoffset( (int)(this->inputonly->getUnclippedInnerRect().getWidth()/6),
-        cursorpos, assembled.length() );
-      this->inputonly->setProperty( "Text", assembled.substr( disp_offset) );
-    }
-
-    /* reset display offset */
-    disp_offset = 0;
-  }
-
-  void ChatInputHandler::addline()
-  {
-    /* actually do send what was input */
-    /* a) get the string out of the inputbuffer */
-    std::string msgtosend = this->inpbuf->get();
-
-    if( msgtosend.length() == 0 )
-    { this->deactivate();
-      return;
-    }
-
-    /* b) clear the input buffer */
-    if (this->inpbuf->getSize() > 0)
-      this->inpbuf->clear();
-
-    /* c) send the chat via some call */
-    Host::Chat( msgtosend );
-
-    /* d) stop listening to input - only if this is not fullchat */
-    if( !this->fullchat )
-      this->deactivate();
-
-  }
-
-  void ChatInputHandler::backspace()
-  { this->inpbuf->removeBehindCursor(); }
-
-  void ChatInputHandler::deleteChar()
-  { this->inpbuf->removeAtCursor(); }
-
-  void ChatInputHandler::cursorRight()
-  { this->inpbuf->increaseCursor(); }
-
-  void ChatInputHandler::cursorLeft()
-  { this->inpbuf->decreaseCursor(); }
-
-  void ChatInputHandler::cursorEnd()
-  { this->inpbuf->setCursorToEnd(); }
-
-  void ChatInputHandler::cursorHome()
-  { this->inpbuf->setCursorToBegin(); }
-
-  void ChatInputHandler::exit()
-  {
-    /* b) clear the input buffer */
-    if (this->inpbuf->getSize() > 0)
-      this->inpbuf->clear();
-
-    /* d) stop listening to input  */
-    this->deactivate();
-  }
-
-}
Index: code/branches/output/src/orxonox/ChatInputHandler.h
===================================================================
--- code/branches/output/src/orxonox/ChatInputHandler.h	(revision 8826)
+++ 	(revision )
@@ -1,134 +1,0 @@
-/*
- *   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:
- *      Sandro 'smerkli' Merkli
- *   Co-authors:
- *      ...
- *
- */
-
-#ifndef _ChatInputHandler_H__
-#define _ChatInputHandler_H__
-
-#include <OrxonoxPrereqs.h>
-
-#include <string>
-#include <CEGUIForwardRefs.h>
-#include <CEGUIcolour.h>
-
-#include "util/Singleton.h"
-#include "network/ChatListener.h"
-
-namespace orxonox // tolua_export
-{ // tolua_export
-  /* class to handle chat using an InputBuffer */
-  class _OrxonoxExport ChatInputHandler  // tolua_export
-    : public Singleton<ChatInputHandler>, public ChatListener
-  { // tolua_export
-    private:
-      /** Input buffer, to be used to catch input from the
-       * keyboard
-       */
-      InputBuffer *inpbuf;
-      int disp_offset, width;
-      bool fullchat;
-
-      /* colors for nickname coloring */
-      static const int NumberOfColors = 10;
-      CEGUI::colour text_colors[ NumberOfColors ];
-
-      /** input state */
-      InputState *inputState;
-
-      /** setup input buffer, the constructor calls this */
-      void configureInputBuffer();
-
-      /** adjust display offset depending on cursor position */
-      void sub_adjust_dispoffset( int maxlen, int cursorpos, int inplen );
-
-      /** singleton pointer */
-      static ChatInputHandler* singletonPtr_s;
-
-      /** cegui window handles */
-      CEGUI::Window *input, *inputonly;
-
-      /** cegui handle for the history window */
-      CEGUI::Listbox *lb_history;
-
-      /* methods to deal with colors */
-      void sub_setcolor( CEGUI::ListboxTextItem *tocolor,
-        std::string name );
-
-      void setupColors();
-
-      /* callbacks for input handler */
-      void inputChanged();
-      void addline();
-      void backspace();
-      void deleteChar();
-      void cursorRight();
-      void cursorLeft();
-      void cursorEnd();
-      void cursorHome();
-      void exit();
-
-    public:
-      /** constructor */
-      ChatInputHandler();
-      ~ChatInputHandler();
-      friend class Singleton<ChatInputHandler>;
-
-      static ChatInputHandler& getInstance(void) { return Singleton<ChatInputHandler>::getInstance(); }  // tolua_export
-
-      /** start listening */
-      static void activate_static();
-
-      /** stop listening */
-      static void activate_small_static();
-
-      /** \param message the message text
-       * \param senderID ID of the player who sent the message
-       *
-       * Deal with incoming chat (which means in our case: Add it to the
-       * history window of the full chat window)
-       */
-      void incomingChat( const std::string& message,
-        unsigned int senderID );
-
-      /** \param full true means show full chat window with history,
-            false means show only an input line
-       *
-       * Show the chat window and redirect the game's keyboard input
-       * into it.
-       */
-      void activate( bool full );
-
-      /** Deactivate the chat window, meaning: hide it. */
-      void deactivate();  // tolua_export
-
-  };  // tolua_export
-
-
-}  // tolua_export
-
-
-#endif /*_ChatInputHandler_H__*/
Index: code/branches/output/src/orxonox/chat/CMakeLists.txt
===================================================================
--- code/branches/output/src/orxonox/chat/CMakeLists.txt	(revision 8828)
+++ code/branches/output/src/orxonox/chat/CMakeLists.txt	(revision 8828)
@@ -0,0 +1,4 @@
+ADD_SOURCE_FILES(ORXONOX_SRC_FILES
+  ChatHistory.cc
+  ChatInputHandler.cc
+)
Index: code/branches/output/src/orxonox/chat/ChatHistory.cc
===================================================================
--- code/branches/output/src/orxonox/chat/ChatHistory.cc	(revision 8828)
+++ code/branches/output/src/orxonox/chat/ChatHistory.cc	(revision 8828)
@@ -0,0 +1,186 @@
+/*
+ *   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:
+ *      Sandro 'smerkli' Merkli
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "ChatHistory.h"
+#include "util/ScopedSingletonManager.h"
+
+#ifndef CHATTEST
+namespace orxonox
+{
+  /* singleton */
+  ManageScopedSingleton( ChatHistory, ScopeID::Root, false );
+#endif
+
+  /* constructor */
+#ifndef CHATTEST
+  //ChatHistory::ChatHistory( BaseObject* creator ) : BaseObject(creator)
+  ChatHistory::ChatHistory()
+#else
+  ChatHistory::ChatHistory()
+#endif
+  {
+    /* register the object */
+#ifndef CHATTEST
+    RegisterObject(ChatHistory);
+#endif
+
+    this->hist_log_enabled = true;
+
+    /* Read setting for logfiles */
+    if( hist_log_enabled ) /* NOTE Make this a check for the logfile setting */
+    { this->chat_hist_openlog();
+
+      /* push starting line */
+      this->chat_hist_logline( "--- Logfile opened ---" );
+    }
+
+    /* Read setting for maximum number of lines and set limit */
+    this->hist_maxlines = 200; /* NOTE to be changed, 200 is just for testing */
+  }
+
+  /* destructor */
+  ChatHistory::~ChatHistory()
+  {
+    chat_hist_closelog();
+
+    /* clear list */
+    this->hist_buffer.clear();
+  }
+
+  /* react to incoming chat */
+  void ChatHistory::incomingChat(const std::string& message,
+    unsigned int senderID)
+  {
+    /* --> a) look up the actual name of the sender */
+    std::string text = message;
+
+#ifndef CHATTEST
+    /* get sender ID and prepend it to the message */
+    if (senderID != NETWORK_PEER_ID_UNKNOWN)
+    {
+      PlayerInfo* player = PlayerManager::getInstance().getClient(senderID);
+      if (player)
+        text = player->getName() + ": " + message;
+    }
+#endif
+
+    /* add the line to the history */
+    this->chat_hist_addline( text );
+
+    /* add the line to the log */
+    this->chat_hist_logline( text );
+  }
+
+  /* Synchronize logfile onto the hard drive */ /* MARK MARK */
+  int ChatHistory::syncLog()
+  {
+    //if( this->hist_logfile )
+      //this->hist_logfile.sync();
+    return 0;
+  }
+
+  /* add a line to this history */
+  int ChatHistory::chat_hist_addline( const std::string& toadd )
+  {
+    /* crop history at the end if it's too large */
+    while( this->hist_buffer.size() > this->hist_maxlines+1 )
+      this->hist_buffer.pop_front();
+
+    /* push to the front of the history */
+    this->hist_buffer.push_back( toadd );
+    return 0;
+  }
+
+  /* log a line to a logfile */
+  int ChatHistory::chat_hist_logline( const std::string& toadd )
+  {
+    /* output the line to the file if logging is enabled */
+    if( this->hist_log_enabled )
+      this->hist_logfile << toadd << endl;
+    return 0;
+  }
+
+  /* open logfile */
+  int ChatHistory::chat_hist_openlog()
+  {
+    /* TODO: find out the name of the file to log to via settings
+     *       and set the this->hist_logfile_path variable to it
+     */
+#ifndef CHATTEST
+    this->hist_logfile.open( (PathConfig::getInstance().getLogPathString() +
+      "chatlog.log").c_str(),
+      std::fstream::out | std::fstream::app );
+#else
+    this->hist_logfile.open( "/tmp/chatlog.log",
+      std::fstream::out | std::fstream::app );
+#endif
+
+    /* TODO check whether this works (not sure how you'd like it?) */
+    if( !this->hist_logfile )
+    { this->hist_log_enabled = false;
+#ifndef CHATTEST
+      orxout(internal_warning) << "Could not open logfile." << endl;
+#endif
+    }
+
+    /* if it worked */
+    return 0;
+  }
+
+  /* close logfile */
+  void ChatHistory::chat_hist_closelog()
+  {
+    /* see if we've actually got a logfile */
+    if( this->hist_logfile )
+    {
+      /* yes, we've got one, add a line that shows we're closing it */
+      this->chat_hist_logline( "--- Logfile closed ---" );
+
+      /* actually close down the file */
+      this->hist_logfile.close();
+    }
+  }
+
+  /* output history for debugging */
+  void ChatHistory::debug_printhist()
+  {
+    /* create deque iterator */
+    std::deque<std::string>::iterator it;
+
+    /* output all the strings */
+    for( it = this->hist_buffer.begin(); it != this->hist_buffer.end();
+      ++it )
+      orxout(debug_output) << *it << endl;
+
+    /* output size */
+    orxout(debug_output) << "Size: " << hist_buffer.size() << endl;
+  }
+
+#ifndef CHATTEST
+}
+#endif
Index: code/branches/output/src/orxonox/chat/ChatHistory.h
===================================================================
--- code/branches/output/src/orxonox/chat/ChatHistory.h	(revision 8828)
+++ code/branches/output/src/orxonox/chat/ChatHistory.h	(revision 8828)
@@ -0,0 +1,149 @@
+/*
+ *   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:
+ *      Sandro 'smerkli' Merkli
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include <deque>
+#include <string>
+#include <fstream>
+#include <iostream>
+#include <cassert>
+
+/* define this if you're unit testing */
+//#define CHATTEST
+
+#ifndef CHATTEST
+#include <OrxonoxPrereqs.h>
+#include <PlayerManager.h>
+#include <infos/PlayerInfo.h>
+#include <core/BaseObject.h>
+#include <network/ChatListener.h>
+#include <core/PathConfig.h>
+#include <util/Singleton.h>
+#endif
+
+#ifndef _ChatHistory_H__
+#define _ChatHistory_H__
+
+
+/* Class to implement chat history */
+#ifndef CHATTEST
+namespace orxonox
+{
+#endif
+
+  /* constructor */
+#ifndef CHATTEST
+  class _OrxonoxExport ChatHistory : public ChatListener,
+    public Singleton<ChatHistory>
+
+#else
+  class ChatHistory
+#endif
+  {
+    public:
+      /* constructors, destructors */
+#ifndef CHATTEST
+      ChatHistory();
+      friend class Singleton<ChatHistory>;
+#else
+      ChatHistory();
+#endif
+      virtual ~ChatHistory();
+
+
+    //protected:
+      /** what to do with incoming chat
+       *
+       * \param message The incoming message
+       * \param senderID Identification number of the sender
+       */
+      virtual void incomingChat(const std::string& message,
+        unsigned int senderID);
+
+      /** Synchronize logfile onto the hard drive
+       *
+       * \return 0 for success, other for error
+       */
+      int syncLog();
+
+      /** debug-print: output the whole history to stdout */
+      void debug_printhist();
+
+    private:
+      /* FIELDS */
+      /** Vector to store the history in */
+      std::deque<std::string> hist_buffer;
+
+      /** Maximum number of lines stored in this history */
+      unsigned int hist_maxlines;
+
+      /** is logging enabled? */
+      bool hist_log_enabled;
+
+      /** path of logfile on the file system */
+      std::string hist_logfile_path;
+
+      /** Output file stream for logfile */
+      std::ofstream hist_logfile;
+
+#ifndef CHATTEST
+      static ChatHistory* singletonPtr_s;
+#endif
+
+
+
+      /* METHODS */
+      /** Append line to chat history
+       *
+       * \param toadd The line to add to the history
+       * \return 0 for success, other for error TODO: Throw exception
+       */
+      int chat_hist_addline( const std::string& toadd );
+
+      /** Append line to logfile
+       *
+       * \param toadd The line to add to the logfile
+       * \return 0 for success, other for error TODO: Throw exception
+       */
+      int chat_hist_logline( const std::string& toadd );
+
+      /** open logfile to log to
+       *
+       * \return 0 for success,s other for error
+       */
+      int chat_hist_openlog();
+
+
+      /** close logfile */
+      void chat_hist_closelog();
+  };
+
+#ifndef CHATTEST
+}
+#endif
+
+#endif /* _ChatHistory_H__ */
Index: code/branches/output/src/orxonox/chat/ChatInputHandler.cc
===================================================================
--- code/branches/output/src/orxonox/chat/ChatInputHandler.cc	(revision 8828)
+++ code/branches/output/src/orxonox/chat/ChatInputHandler.cc	(revision 8828)
@@ -0,0 +1,358 @@
+/*
+ *   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:
+ *      Sandro 'smerkli' Merkli
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "ChatInputHandler.h"
+
+#include <cassert>
+#include <string>
+#include <CEGUIWindow.h>
+#include <CEGUIWindowManager.h>
+#include <elements/CEGUIListbox.h>
+#include <elements/CEGUIListboxItem.h>
+#include <elements/CEGUIListboxTextItem.h>
+
+#include "util/ScopedSingletonManager.h"
+#include "core/CoreIncludes.h"
+#include "core/GUIManager.h"
+#include "core/command/ConsoleCommand.h"
+#include "core/input/InputBuffer.h"
+#include "core/input/InputManager.h"
+#include "core/input/InputState.h"
+#include "network/Host.h"
+
+#include "PlayerManager.h"
+#include "infos/PlayerInfo.h"
+
+namespace orxonox
+{
+  /* singleton */
+  ManageScopedSingleton( ChatInputHandler, ScopeID::Graphics, false );
+
+  /* add commands to console */
+  SetConsoleCommand( "startchat", &ChatInputHandler::activate_static );
+  SetConsoleCommand( "startchat_small", &ChatInputHandler::activate_small_static );
+
+  /* constructor */
+  ChatInputHandler::ChatInputHandler()
+  {
+    /* register the object  */
+    RegisterObject(ChatInputHandler);
+
+    /* create necessary objects */
+    this->inpbuf = new InputBuffer();
+    this->disp_offset = 0;
+    assert( this->inpbuf != NULL );
+
+    /* generate chatbox ui and chatbox-inputonly ui */
+    GUIManager::getInstance().loadGUI( "ChatBox" );
+    GUIManager::getInstance().loadGUI( "ChatBox-inputonly" );
+
+    /* setup colors */
+    setupColors();
+
+    /* configure the input buffer */
+    configureInputBuffer();
+
+    this->inputState = InputManager::getInstance().createInputState( "chatinput", false, false, InputStatePriority::Dynamic );
+    this->inputState->setKeyHandler(this->inpbuf);
+  }
+
+  ChatInputHandler::~ChatInputHandler()
+  {
+    /* Clean up */
+    InputManager::getInstance().destroyState("chatinput");
+    delete this->inpbuf;
+  }
+
+  /* configure input buffer, sub for the constructor */
+  void ChatInputHandler::configureInputBuffer()
+  {
+    /* INSTALL CALLBACKS */
+    /* input has changed */
+    this->inpbuf->registerListener(this, &ChatInputHandler::inputChanged, true);
+
+    /* add a line */
+    this->inpbuf->registerListener(this, &ChatInputHandler::addline,         '\r',   false);
+    this->inpbuf->registerListener(this, &ChatInputHandler::addline,         '\n',   false);
+
+    /* backspace */
+    this->inpbuf->registerListener(this, &ChatInputHandler::backspace,       '\b',   true);
+    //this->inpbuf->registerListener(this, &ChatInputHandler::backspace,       '\177', true);
+
+    /* exit the chatinputhandler thingy (tbd) */
+    this->inpbuf->registerListener(this, &ChatInputHandler::exit,            '\033', true); // escape
+
+    /* delete character */
+    this->inpbuf->registerListener(this, &ChatInputHandler::deleteChar,      KeyCode::Delete);
+
+    /* cursor movement */
+    this->inpbuf->registerListener(this, &ChatInputHandler::cursorRight,     KeyCode::Right);
+    this->inpbuf->registerListener(this, &ChatInputHandler::cursorLeft,      KeyCode::Left);
+    this->inpbuf->registerListener(this, &ChatInputHandler::cursorEnd,       KeyCode::End);
+    this->inpbuf->registerListener(this, &ChatInputHandler::cursorHome,      KeyCode::Home);
+
+    /* GET WINDOW POINTERS */
+    input = CEGUI::WindowManager::getSingleton().getWindow( "orxonox/ChatBox/input" );
+    inputonly = CEGUI::WindowManager::getSingleton().getWindow( "orxonox/ChatBox-inputonly/input" );
+
+    /* get pointer to the history window */
+    CEGUI::Window *history = CEGUI::WindowManager::getSingleton().getWindow( "orxonox/ChatBox/history" );
+
+    /* cast it to a listbox */
+    lb_history = dynamic_cast<CEGUI::Listbox*>(history);
+
+    /* assert wee */
+    assert( lb_history );
+  }
+
+  /* setup the colors, sub for the constructor */
+  void ChatInputHandler::setupColors()
+  {
+    /* auto variables */
+    float red = 1.0, green = 0.5, blue = 0.5;
+    int i = 0;
+
+    // three loops: red tones, blue tones and green tones
+    // reds
+    for( i = 0; i < NumberOfColors/3; ++i )
+    { this->text_colors[ i ] = CEGUI::colour( red, green, blue );
+      green += 0.2f, blue += 0.2f;
+    }
+
+    // greens
+    red = 0.5, green = 1, blue = 0.5;
+    for( ; i < NumberOfColors*2/3; ++i )
+    { this->text_colors[ i ] = CEGUI::colour( red, green, blue );
+      red += 0.2f, blue += 0.2f;
+    }
+
+    // blues
+    red = 0.5, green = 0.5, blue = 1;
+    for( ; i < NumberOfColors; ++i )
+    { this->text_colors[ i ] = CEGUI::colour( red, green, blue );
+      red += 0.2f, green += 0.2f;
+    }
+  }
+
+
+  /* activate, deactivate */
+  void ChatInputHandler::activate_static()
+  { ChatInputHandler::getInstance().activate( true ); }
+
+  void ChatInputHandler::activate_small_static()
+  { ChatInputHandler::getInstance().activate( false ); }
+
+  void ChatInputHandler::activate( bool full )
+  {
+    /* start listening */
+    InputManager::getInstance().enterState("chatinput");
+
+    /* MARK add spawning of chat widget stuff here.*/
+    if( full )
+      GUIManager::getInstance().showGUI( "ChatBox" );
+    else
+      GUIManager::getInstance().showGUI( "ChatBox-inputonly" );
+
+    this->fullchat = full;
+  }
+
+  void ChatInputHandler::deactivate()
+  {
+    /* stop listening */
+    InputManager::getInstance().leaveState("chatinput");
+
+    /* un-spawning of chat widget stuff */
+    GUIManager::getInstance().hideGUI( "ChatBox" );
+    GUIManager::getInstance().hideGUI( "ChatBox-inputonly" );
+  }
+
+
+  /* subs for incomingChat */
+  void ChatInputHandler::sub_setcolor( CEGUI::ListboxTextItem *tocolor,
+    std::string name )
+  {
+    /* sanity checks */
+    if( !tocolor )
+      orxout(internal_warning) << "Empty ListBoxTextItem given to "
+        "ChatInputhandler::sub_setcolor()." << endl;
+
+    /* "hash" the name */
+    int hash = 0;
+    for( int i = name.length(); i > 0; --i )
+      hash += name[i-1];
+    hash = hash % this->NumberOfColors;
+
+    /* set the color according to the hash */
+    tocolor->setTextColours( this->text_colors[ hash ] );
+  }
+
+  /* handle incoming chat */
+  void ChatInputHandler::incomingChat(const std::string& message,
+    unsigned int senderID)
+  {
+    /* look up the actual name of the sender */
+    std::string text = message;
+    std::string name = "";
+
+    /* setup player name info */
+    if (senderID != NETWORK_PEER_ID_UNKNOWN)
+    {
+       PlayerInfo* player = PlayerManager::getInstance().getClient(senderID);
+       if (player)
+       {
+         name = player->getName();
+         text = name + ": " + message;
+       }
+    }
+
+    /* create item */
+    CEGUI::ListboxTextItem *toadd = new CEGUI::ListboxTextItem( text );
+
+    /* setup colors */
+    if (name != "")
+      sub_setcolor( toadd, name );
+
+    /* now add */
+    this->lb_history->addItem( dynamic_cast<CEGUI::ListboxItem*>(toadd) );
+    this->lb_history->ensureItemIsVisible(
+      dynamic_cast<CEGUI::ListboxItem*>(toadd) );
+
+    /* make sure the history handles it */
+    this->lb_history->handleUpdatedItemData();
+  }
+
+
+  /* sub for inputchanged */
+  void ChatInputHandler::sub_adjust_dispoffset( int maxlen,
+    int cursorpos,
+    int inplen )
+  {
+    /* already start offsetting 5 characters before end */
+    if( cursorpos+5 > maxlen )
+    {
+      /* always stay 5 characters ahead of end, looks better */
+      ((disp_offset = cursorpos-maxlen+5) >= 0) ? 1 : disp_offset = 0;
+
+      /* enforce visibility of cursor */
+      (disp_offset > cursorpos ) ? disp_offset = 0 : 1;
+    }
+
+    /* make sure we don't die at substr */
+    if( inplen <= disp_offset ) disp_offset = 0;
+  }
+
+  /* callbacks for InputBuffer */
+  void ChatInputHandler::inputChanged()
+  {
+    /* update the cursor and the window */
+    std::string raw = this->inpbuf->get();
+    int cursorpos = this->inpbuf->getCursorPosition();
+
+    /* get string before cursor */
+    std::string left = raw.substr( 0, cursorpos );
+
+    /* see if there's a string after the cursor */
+    std::string right = "";
+    if( raw.length() >= left.length()+1 )
+      right = raw.substr( cursorpos );
+
+    /* set the text */
+    std::string assembled = "$ " + left + "|" + right;
+
+    if( this->fullchat )
+    {
+      /* adjust curser position - magic number 5 for font width */
+      sub_adjust_dispoffset( (int)(this->input->getUnclippedInnerRect().getWidth()/6),
+        cursorpos, assembled.length() );
+      this->input->setProperty( "Text", assembled.substr( disp_offset ) );
+    }
+    else
+    {
+      /* adjust curser position - magic number 5 for font width */
+      sub_adjust_dispoffset( (int)(this->inputonly->getUnclippedInnerRect().getWidth()/6),
+        cursorpos, assembled.length() );
+      this->inputonly->setProperty( "Text", assembled.substr( disp_offset) );
+    }
+
+    /* reset display offset */
+    disp_offset = 0;
+  }
+
+  void ChatInputHandler::addline()
+  {
+    /* actually do send what was input */
+    /* a) get the string out of the inputbuffer */
+    std::string msgtosend = this->inpbuf->get();
+
+    if( msgtosend.length() == 0 )
+    { this->deactivate();
+      return;
+    }
+
+    /* b) clear the input buffer */
+    if (this->inpbuf->getSize() > 0)
+      this->inpbuf->clear();
+
+    /* c) send the chat via some call */
+    Host::Chat( msgtosend );
+
+    /* d) stop listening to input - only if this is not fullchat */
+    if( !this->fullchat )
+      this->deactivate();
+
+  }
+
+  void ChatInputHandler::backspace()
+  { this->inpbuf->removeBehindCursor(); }
+
+  void ChatInputHandler::deleteChar()
+  { this->inpbuf->removeAtCursor(); }
+
+  void ChatInputHandler::cursorRight()
+  { this->inpbuf->increaseCursor(); }
+
+  void ChatInputHandler::cursorLeft()
+  { this->inpbuf->decreaseCursor(); }
+
+  void ChatInputHandler::cursorEnd()
+  { this->inpbuf->setCursorToEnd(); }
+
+  void ChatInputHandler::cursorHome()
+  { this->inpbuf->setCursorToBegin(); }
+
+  void ChatInputHandler::exit()
+  {
+    /* b) clear the input buffer */
+    if (this->inpbuf->getSize() > 0)
+      this->inpbuf->clear();
+
+    /* d) stop listening to input  */
+    this->deactivate();
+  }
+
+}
Index: code/branches/output/src/orxonox/chat/ChatInputHandler.h
===================================================================
--- code/branches/output/src/orxonox/chat/ChatInputHandler.h	(revision 8828)
+++ code/branches/output/src/orxonox/chat/ChatInputHandler.h	(revision 8828)
@@ -0,0 +1,134 @@
+/*
+ *   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:
+ *      Sandro 'smerkli' Merkli
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _ChatInputHandler_H__
+#define _ChatInputHandler_H__
+
+#include <OrxonoxPrereqs.h>
+
+#include <string>
+#include <CEGUIForwardRefs.h>
+#include <CEGUIcolour.h>
+
+#include "util/Singleton.h"
+#include "network/ChatListener.h"
+
+namespace orxonox // tolua_export
+{ // tolua_export
+  /* class to handle chat using an InputBuffer */
+  class _OrxonoxExport ChatInputHandler  // tolua_export
+    : public Singleton<ChatInputHandler>, public ChatListener
+  { // tolua_export
+    private:
+      /** Input buffer, to be used to catch input from the
+       * keyboard
+       */
+      InputBuffer *inpbuf;
+      int disp_offset, width;
+      bool fullchat;
+
+      /* colors for nickname coloring */
+      static const int NumberOfColors = 10;
+      CEGUI::colour text_colors[ NumberOfColors ];
+
+      /** input state */
+      InputState *inputState;
+
+      /** setup input buffer, the constructor calls this */
+      void configureInputBuffer();
+
+      /** adjust display offset depending on cursor position */
+      void sub_adjust_dispoffset( int maxlen, int cursorpos, int inplen );
+
+      /** singleton pointer */
+      static ChatInputHandler* singletonPtr_s;
+
+      /** cegui window handles */
+      CEGUI::Window *input, *inputonly;
+
+      /** cegui handle for the history window */
+      CEGUI::Listbox *lb_history;
+
+      /* methods to deal with colors */
+      void sub_setcolor( CEGUI::ListboxTextItem *tocolor,
+        std::string name );
+
+      void setupColors();
+
+      /* callbacks for input handler */
+      void inputChanged();
+      void addline();
+      void backspace();
+      void deleteChar();
+      void cursorRight();
+      void cursorLeft();
+      void cursorEnd();
+      void cursorHome();
+      void exit();
+
+    public:
+      /** constructor */
+      ChatInputHandler();
+      ~ChatInputHandler();
+      friend class Singleton<ChatInputHandler>;
+
+      static ChatInputHandler& getInstance(void) { return Singleton<ChatInputHandler>::getInstance(); }  // tolua_export
+
+      /** start listening */
+      static void activate_static();
+
+      /** stop listening */
+      static void activate_small_static();
+
+      /** \param message the message text
+       * \param senderID ID of the player who sent the message
+       *
+       * Deal with incoming chat (which means in our case: Add it to the
+       * history window of the full chat window)
+       */
+      void incomingChat( const std::string& message,
+        unsigned int senderID );
+
+      /** \param full true means show full chat window with history,
+            false means show only an input line
+       *
+       * Show the chat window and redirect the game's keyboard input
+       * into it.
+       */
+      void activate( bool full );
+
+      /** Deactivate the chat window, meaning: hide it. */
+      void deactivate();  // tolua_export
+
+  };  // tolua_export
+
+
+}  // tolua_export
+
+
+#endif /*_ChatInputHandler_H__*/
