Index: code/trunk/src/libraries/network/CMakeLists.txt
===================================================================
--- code/trunk/src/libraries/network/CMakeLists.txt	(revision 8729)
+++ code/trunk/src/libraries/network/CMakeLists.txt	(revision 8858)
@@ -19,5 +19,4 @@
 
 SET_SOURCE_FILES(NETWORK_SRC_FILES
-  ChatListener.cc
   Client.cc
   ClientConnection.cc
@@ -45,5 +44,4 @@
 
 SET_SOURCE_FILES(NETWORK_HDR_FILES
-  ChatListener.h
   Client.h
   ClientConnection.h
@@ -61,4 +59,5 @@
   WANDiscovery.h
   MasterServerComm.h
+  NetworkChatListener.h
   NetworkFunction.h
   NetworkPrecompiledHeaders.h
Index: code/trunk/src/libraries/network/ChatListener.cc
===================================================================
--- code/trunk/src/libraries/network/ChatListener.cc	(revision 8729)
+++ 	(revision )
@@ -1,50 +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:
- *      Fabian 'x3n' Landau
- *   Co-authors:
- *      ...
- *
- */
-
-#include "ChatListener.h"
-#include "core/CoreIncludes.h"
-
-namespace orxonox
-{
-    ChatListener::ChatListener()
-    {
-        RegisterRootObject(ChatListener);
-    }
-
-    //void ChatListener::incomingChat( const std::string& message,
-      //unsigned int senderID )
-    //{
-      //COUT(0) << "Chat: \"" << message << "\"\n";
-
-
-    //}
-
-
-}
-
-
Index: code/trunk/src/libraries/network/ChatListener.h
===================================================================
--- code/trunk/src/libraries/network/ChatListener.h	(revision 8729)
+++ 	(revision )
@@ -1,49 +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:
- *      Fabian 'x3n' Landau
- *   Co-authors:
- *      ...
- *
- */
-
-#ifndef _NETWORK_ChatListener__
-#define _NETWORK_ChatListener__
-
-#include "NetworkPrereqs.h"
-#include "core/OrxonoxClass.h"
-
-namespace orxonox
-{
-    class _NetworkExport ChatListener : virtual public OrxonoxClass
-    {
-        public:
-            /* constructor, destructor */
-            ChatListener();
-            virtual ~ChatListener() {}
-
-            /* What to do with incoming chat */
-            virtual void incomingChat(const std::string& message, unsigned int senderID) = 0;
-    };
-}
-
-#endif /* _NETWORK_ChatListener__ */
Index: code/trunk/src/libraries/network/Client.cc
===================================================================
--- code/trunk/src/libraries/network/Client.cc	(revision 8729)
+++ code/trunk/src/libraries/network/Client.cc	(revision 8858)
@@ -44,5 +44,5 @@
 
 #include "util/Clock.h"
-#include "util/Debug.h"
+#include "util/Output.h"
 #include "util/ScopedSingletonManager.h"
 #include "synchronisable/Synchronisable.h"
@@ -116,26 +116,30 @@
   }
 
-  bool Client::processChat(const std::string& message, unsigned int playerID)
-  {
-//    COUT(1) << "Player " << playerID << ": " << message << std::endl;
-    return true;
-  }
-
   void Client::printRTT()
   {
-    COUT(0) << "Round trip time to server is " << ClientConnection::getRTT() << " ms" << endl;
-  }
-
-  /**
-   * This function implements the method of sending a chat message to the server
+    orxout(message) << "Round trip time to server is " << ClientConnection::getRTT() << " ms" << endl;
+  }
+
+  /**
+   * @brief Sends a chat message to the server.
    * @param message message to be sent
-   * @return result(true/false)
+   * @param sourceID the ID of the sender
+   * @param targetID the ID of the receiver
    */
-  bool Client::chat(const std::string& message)
-  {
-    packet::Chat *m = new packet::Chat(message, Host::getPlayerID());
-    return m->send(static_cast<Host*>(this));
-  }
-
+  void Client::doSendChat(const std::string& message, unsigned int sourceID, unsigned int targetID)
+  {
+    // send the message to the server
+    packet::Chat* packet = new packet::Chat(message, sourceID, targetID);
+    packet->send(static_cast<Host*>(this));
+  }
+
+  /**
+   * @brief Gets called if a packet::Chat packet is received. Calls the parent function which passes the message to the listeners.
+   */
+  void Client::doReceiveChat(const std::string& message, unsigned int sourceID, unsigned int targetID)
+  {
+    // call the parent function which passes the message to the listeners
+    Host::doReceiveChat(message, sourceID, targetID);
+  }
 
   /**
@@ -150,8 +154,7 @@
     {
       timeSinceLastUpdate_ -= static_cast<unsigned int>( timeSinceLastUpdate_ / NETWORK_PERIOD ) * NETWORK_PERIOD;
-      //     COUT(3) << '.';
       if ( isConnected() && isSynched_ )
       {
-        COUT(4) << "popping partial gamestate: " << std::endl;
+        orxout(verbose, context::network) << "popping partial gamestate: " << endl;
 //         packet::Gamestate *gs = GamestateClient::getGamestate();
         if( GamestateManager::update() )
@@ -166,7 +169,7 @@
         //assert(gs); <--- there might be the case that no data has to be sent, so its commented out now
 //         if(gs){
-//           COUT(4) << "client tick: sending gs " << gs << std::endl;
+//           orxout(verbose, context::network) << "client tick: sending gs " << gs << endl;
 //           if( !gs->send() )
-//             COUT(2) << "Problem adding partial gamestate to queue" << std::endl;
+//             orxout(internal_warning, context::network) << "Problem adding partial gamestate to queue" << endl;
 //         // gs gets automatically deleted by enet callback
 //         }
@@ -204,5 +207,5 @@
     Game::getInstance().popState();
   }
-  
+
   void Client::processPacket(packet::Packet* packet)
   {
@@ -217,7 +220,3 @@
       packet->process(static_cast<Host*>(this));
   }
-
-
-
-
 }
Index: code/trunk/src/libraries/network/Client.h
===================================================================
--- code/trunk/src/libraries/network/Client.h	(revision 8729)
+++ code/trunk/src/libraries/network/Client.h	(revision 8858)
@@ -73,5 +73,5 @@
     Client();
     ~Client();
-    
+
     static Client* getInstance(){ return singletonPtr_s; } // tolua_export
 
@@ -81,7 +81,6 @@
     void queuePacket(ENetPacket* packet, int clientID, uint8_t channelID);
     virtual bool sendPacket( packet::Packet* packet ){ return packet->send( static_cast<Host*>(this) ); }
-    bool processChat(const std::string& message, unsigned int playerID);
-    virtual bool chat(const std::string& message);
-    virtual bool broadcast(const std::string& message) { return false; }
+    virtual void doSendChat(const std::string& message, unsigned int sourceID, unsigned int targetID);
+    virtual void doReceiveChat(const std::string& message, unsigned int sourceID, unsigned int targetID);
     virtual void printRTT();
 
Index: code/trunk/src/libraries/network/ClientConnection.cc
===================================================================
--- code/trunk/src/libraries/network/ClientConnection.cc	(revision 8729)
+++ code/trunk/src/libraries/network/ClientConnection.cc	(revision 8858)
@@ -32,5 +32,5 @@
 #define WIN32_LEAN_AND_MEAN
 #include <enet/enet.h>
-#include "util/Debug.h"
+#include "util/Output.h"
 
 namespace orxonox
@@ -60,5 +60,5 @@
   void ClientConnection::setServerAddress( const std::string& serverAddress ) {
     if (enet_address_set_host (this->serverAddress_, serverAddress.c_str()) < 0)
-        COUT(1) << "Error: Could not resolve \"" << serverAddress << "\"." << std::endl;
+        orxout(internal_error, context::network) << "Could not resolve \"" << serverAddress << "\"." << endl;
   }
 
@@ -76,5 +76,5 @@
     if ( this->host_ == NULL )
     {
-      COUT(1) << "ClientConnection: host_ == NULL" << std::endl;
+      orxout(internal_error, context::network) << "ClientConnection: host_ == NULL" << endl;
       // error handling
       return false;
@@ -86,14 +86,14 @@
     assert( this->host_->socket4 != ENET_SOCKET_NULL || this->host_->socket6 != ENET_SOCKET_NULL );
     if (this->host_->socket4 == ENET_SOCKET_NULL)
-        COUT(2) << "Warning: IPv4 Socket failed." << std::endl;
+        orxout(internal_warning, context::network) << "IPv4 Socket failed." << endl;
     else if (this->host_->socket6 == ENET_SOCKET_NULL)
-        COUT(2) << "Warning: IPv6 Socket failed." << std::endl;
+        orxout(internal_warning, context::network) << "IPv6 Socket failed." << endl;
     else
-        COUT(3) << "Info: Using IPv4 and IPv6 Sockets." << std::endl;
+        orxout(internal_info, context::network) << "Using IPv4 and IPv6 Sockets." << endl;
 
     this->server_ = enet_host_connect(this->host_, serverAddress_, NETWORK_CHANNEL_COUNT, 0);
     if ( this->server_==NULL )
     {
-      COUT(1) << "ClientConnection: server_ == NULL" << std::endl;
+      orxout(internal_error, context::network) << "ClientConnection: server_ == NULL" << endl;
       // error handling
       return false;
@@ -113,5 +113,5 @@
       }
     }
-    COUT(1) << "Could not connect to server" << endl;
+    orxout(user_error, context::network) << "Could not connect to server" << endl;
     return false;
   }
@@ -140,5 +140,5 @@
             break;
           case ENET_EVENT_TYPE_DISCONNECT:
-            COUT(4) << "received disconnect confirmation from server" << endl;
+            orxout(verbose, context::network) << "received disconnect confirmation from server" << endl;
             this->connectionClosed();
             return true;
@@ -167,5 +167,5 @@
   {
     this->established_=false;
-    COUT(1) << "Received disconnect Packet from Server!" << endl;
+    orxout(internal_error, context::network) << "Received disconnect Packet from Server!" << endl;
         // server closed the connection
     this->stopCommunicationThread();
Index: code/trunk/src/libraries/network/Connection.cc
===================================================================
--- code/trunk/src/libraries/network/Connection.cc	(revision 8729)
+++ code/trunk/src/libraries/network/Connection.cc	(revision 8858)
@@ -144,5 +144,5 @@
       while( outgoingEventsCount > 0 )
       {
-//         COUT(0) << "outgoing event" << endl;
+//         orxout(verbose, context::network) << "outgoing event" << endl;
         this->outgoingEventsMutex_->lock();
         outgoingEvent outEvent = this->outgoingEvents_.front();
Index: code/trunk/src/libraries/network/GamestateManager.cc
===================================================================
--- code/trunk/src/libraries/network/GamestateManager.cc	(revision 8729)
+++ code/trunk/src/libraries/network/GamestateManager.cc	(revision 8858)
@@ -52,5 +52,5 @@
 #include "core/command/Executor.h"
 #include "core/GameMode.h"
-#include "util/Debug.h"
+#include "util/Output.h"
 #include "util/Clock.h"
 #include "util/OrxAssert.h"
@@ -128,10 +128,10 @@
     if( !this->sendPacket(ack))
     {
-      COUT(3) << "could not ack gamestate: " << gamestateID << std::endl;
+      orxout(internal_warning, context::network) << "could not ack gamestate: " << gamestateID << endl;
       return false;
     }
     else
     {
-      COUT(5) << "acked a gamestate: " << gamestateID << std::endl;
+      orxout(verbose_more, context::network) << "acked a gamestate: " << gamestateID << endl;
       return true;
     }
@@ -182,9 +182,9 @@
       if( !peerIt->second.isSynched )
       {
-        COUT(5) << "Server: not sending gamestate" << std::endl;
+        orxout(verbose_more, context::network) << "Server: not sending gamestate" << endl;
         continue;
       }
-      COUT(5) << "client id: " << peerIt->first << std::endl;
-      COUT(5) << "Server: doing gamestate gamestate preparation" << std::endl;
+      orxout(verbose_more, context::network) << "client id: " << peerIt->first << endl;
+      orxout(verbose_more, context::network) << "Server: doing gamestate gamestate preparation" << endl;
       int peerID = peerIt->first; //get client id
 
@@ -256,10 +256,10 @@
 //     OrxVerify(gs->compressData(), "");
     clock.capture();
-    COUT(5) << "diff and compress time: " << clock.getDeltaTime() << endl;
-//     COUT(5) << "sending gamestate with id " << gs->getID();
+    orxout(verbose_more, context::network) << "diff and compress time: " << clock.getDeltaTime() << endl;
+//     orxout(verbose_more, context::network) << "sending gamestate with id " << gs->getID();
 //     if(gamestate->isDiffed())
-//       COUT(5) << " and baseid " << gs->getBaseID() << endl;
+//       orxout(verbose_more, context::network) << " and baseid " << gs->getBaseID() << endl;
 //     else
-//       COUT(5) << endl;
+//       orxout(verbose_more, context::network) << endl;
     gs->setPeerID(peerID);
     destgamestate = gs;
@@ -291,5 +291,5 @@
     if( gamestateID <= curid && curid != GAMESTATEID_INITIAL )
         return true;
-COUT(4) << "acking gamestate " << gamestateID << " for peerID: " << peerID << " curid: " << curid << std::endl;
+orxout(verbose, context::network) << "acking gamestate " << gamestateID << " for peerID: " << peerID << " curid: " << curid << endl;
     std::map<uint32_t, packet::Gamestate*>::iterator it2;
     for( it2=it->second.gamestates.begin(); it2!=it->second.gamestates.end(); )
Index: code/trunk/src/libraries/network/Host.cc
===================================================================
--- code/trunk/src/libraries/network/Host.cc	(revision 8729)
+++ code/trunk/src/libraries/network/Host.cc	(revision 8858)
@@ -32,7 +32,8 @@
 #include <string>
 
+#include "core/CoreIncludes.h"
 #include "core/ObjectList.h"
 #include "core/command/ConsoleCommand.h"
-#include "ChatListener.h"
+#include "NetworkChatListener.h"
 
 namespace orxonox {
@@ -41,5 +42,4 @@
   static const std::string __CC_printRTT_name = "printRTT";
 
-  SetConsoleCommand("chat", &Host::Chat);
   SetConsoleCommand(__CC_printRTT_group, __CC_printRTT_name, &Host::printRTT);
 
@@ -89,66 +89,26 @@
   }
 
-  void Host::Chat(const std::string& message)
+  /**
+   * @brief Sends a chat message through the network.
+   * @param message message to be sent
+   * @param sourceID the ID of the sender
+   * @param targetID the ID of the receiver
+   */
+  void Host::sendChat(const std::string& message, unsigned int sourceID, unsigned int targetID)
   {
-    if(instances_s.size()==0)
-    {
-      for (ObjectList<ChatListener>::iterator it = ObjectList<ChatListener>::begin(); it != ObjectList<ChatListener>::end(); ++it)
-        it->incomingChat(message, 0);
-//      return true;
-    }
-    else
-    {
-      bool result = true;
-      for( std::vector<Host*>::iterator it = instances_s.begin(); it!=instances_s.end(); ++it )
-      {
-        if( (*it)->isActive() )
-        {
-          if( !(*it)->chat(message) )
-            result = false;
-        }
-      }
-//      return result;
-    }
+    for( std::vector<Host*>::iterator it = instances_s.begin(); it!=instances_s.end(); ++it )
+      if( (*it)->isActive() )
+        (*it)->doSendChat(message, sourceID, targetID);
   }
 
-  bool Host::Broadcast(const std::string& message)
+  /**
+   * @brief Gets called if a packet::Chat packet is received. Passes the message to the listeners.
+   */
+  void Host::doReceiveChat(const std::string& message, unsigned int sourceID, unsigned int targetID)
   {
-    if(instances_s.size()==0)
-    {
-      for (ObjectList<ChatListener>::iterator it = ObjectList<ChatListener>::begin(); it != ObjectList<ChatListener>::end(); ++it)
-        it->incomingChat(message, NETWORK_PEER_ID_BROADCAST);
-      return true;
-    }
-    else
-    {
-      bool result = true;
-      for( std::vector<Host*>::iterator it = instances_s.begin(); it!=instances_s.end(); ++it )
-      {
-        if( (*it)->isActive() )
-        {
-          if( !(*it)->broadcast(message) )
-            result = false;
-        }
-      }
-      return result;
-    }
+    for (ObjectList<NetworkChatListener>::iterator it = ObjectList<NetworkChatListener>::begin(); it != ObjectList<NetworkChatListener>::end(); ++it)
+      it->incomingChat(message, sourceID);
   }
 
-  bool Host::incomingChat(const std::string& message, unsigned int playerID)
-  {
-    for (ObjectList<ChatListener>::iterator it = ObjectList<ChatListener>::begin(); it != ObjectList<ChatListener>::end(); ++it)
-      it->incomingChat(message, playerID);
-
-    bool result = true;
-    for( std::vector<Host*>::iterator it = instances_s.begin(); it!=instances_s.end(); ++it )
-    {
-      if( (*it)->isActive() )
-      {
-        if( !(*it)->processChat(message, playerID) )
-          result = false;
-      }
-    }
-    return result;
-  }
 
   bool Host::isServer()
@@ -156,10 +116,13 @@
     for (std::vector<Host*>::iterator it=instances_s.begin(); it!=instances_s.end(); ++it )
     {
-      if( (*it)->isServer_() )
-        return true;
+      if( (*it)->isActive() )
+      {
+        if( (*it)->isServer_() )
+          return true;
+      }
     }
     return false;
   }
-  
+
   Host* Host::getActiveInstance()
   {
@@ -176,3 +139,12 @@
 
 
+  //////////////////////////////////////////////////////////////////////////
+  // NetworkChatListener                                                  //
+  //////////////////////////////////////////////////////////////////////////
+
+  NetworkChatListener::NetworkChatListener()
+  {
+      RegisterRootObject(NetworkChatListener);
+  }
+
 }//namespace orxonox
Index: code/trunk/src/libraries/network/Host.h
===================================================================
--- code/trunk/src/libraries/network/Host.h	(revision 8729)
+++ code/trunk/src/libraries/network/Host.h	(revision 8858)
@@ -52,15 +52,9 @@
 class _NetworkExport Host: public GamestateManager
 {
+  friend class packet::Chat;
+
   private:
-    //TODO add these functions or adequate
-    //virtual bool processChat(packet::Chat *message, unsigned int clientID)=0;
-    //virtual bool sendChat(packet::Chat *chat)=0;
     virtual void queuePacket(ENetPacket *packet, int clientID, uint8_t channelID)=0;
-    virtual bool chat(const std::string& message)=0;
-    virtual bool broadcast(const std::string& message)=0;
-    virtual bool processChat(const std::string& message, unsigned int playerID)=0;
     virtual bool isServer_()=0;
-
-
 
   protected:
@@ -68,5 +62,7 @@
     virtual ~Host();
     void setActive( bool bActive ){ bIsActive_ = bActive; }
-//     static Host *instance_;
+
+    virtual void doSendChat(const std::string& message, unsigned int sourceID, unsigned int targetID)=0;
+    virtual void doReceiveChat(const std::string& message, unsigned int sourceID, unsigned int targetID)=0;
 
   public:
@@ -74,12 +70,8 @@
     static bool running(){ return instances_s.size(); }
     static void addPacket(ENetPacket* packet, int clientID = NETWORK_PEER_ID_SERVER, uint8_t channelID = 0);
-    //static bool chat(std::string& message);
-//     static bool receiveChat(packet::Chat *message, unsigned int clientID);
     static unsigned int getPlayerID(){ return clientID_s; }
     static void setClientID(unsigned int id){ clientID_s = id; }
     static bool isServer();
-    static void Chat(const std::string& message);
-    static bool Broadcast(const std::string& message);
-    static bool incomingChat(const std::string& message, unsigned int playerID);
+    static void sendChat(const std::string& message, unsigned int sourceID, unsigned int targetID);
     virtual void printRTT()=0;
     bool isActive(){ return bIsActive_; }
Index: code/trunk/src/libraries/network/LANDiscoverable.cc
===================================================================
--- code/trunk/src/libraries/network/LANDiscoverable.cc	(revision 8729)
+++ code/trunk/src/libraries/network/LANDiscoverable.cc	(revision 8858)
@@ -33,5 +33,5 @@
 #include <cstring>
 
-#include "util/Debug.h"
+#include "util/Output.h"
 #include "packet/ServerInformation.h"
 
@@ -71,5 +71,5 @@
       this->host_ = enet_host_create( &bindAddress, 10, 0, 0, 0 );
       if ( this->host_ == NULL )
-          COUT(1) << "LANDiscoverable: host_ == NULL" << std::endl;
+          orxout(internal_error, context::network) << "LANDiscoverable: host_ == NULL" << endl;
     }
     else
@@ -94,5 +94,5 @@
       {
         case ENET_EVENT_TYPE_CONNECT:
-            COUT(4) << "Received LAN discovery connect from client " << event.peer->host->receivedAddress << std::endl;
+            orxout(verbose, context::network) << "Received LAN discovery connect from client " << event.peer->host->receivedAddress << endl;
             break;
         case ENET_EVENT_TYPE_DISCONNECT:
@@ -102,5 +102,5 @@
           if( strcmp( LAN_DISCOVERY_MESSAGE, (char*)event.packet->data ) == 0 )      // check for a suitable orxonox client
           {
-            COUT(3) << "Received LAN discovery message from client " << event.peer->host->receivedAddress << std::endl;
+            orxout(internal_info, context::network) << "Received LAN discovery message from client " << event.peer->host->receivedAddress << endl;
             packet::ServerInformation info;
             info.setServerName("Orxonox Server");
Index: code/trunk/src/libraries/network/LANDiscovery.cc
===================================================================
--- code/trunk/src/libraries/network/LANDiscovery.cc	(revision 8729)
+++ code/trunk/src/libraries/network/LANDiscovery.cc	(revision 8858)
@@ -21,5 +21,5 @@
  *
  *   Author:
- *      Fabian 'x3n' Landau
+ *      Oliver Scheuss
  *   Co-authors:
  *      ...
@@ -44,5 +44,5 @@
     this->host_ = enet_host_create(NULL, 10, 0, 0, 0 );
     if ( this->host_ == NULL )
-        COUT(1) << "LANDiscovery: host_ == NULL" << std::endl;
+        orxout(internal_error, context::network) << "LANDiscovery: host_ == NULL" << endl;
   }
 
@@ -66,5 +66,5 @@
     peer = enet_host_connect(this->host_, &address, 0, 0);
     if (peer == NULL)
-        COUT(1) << "Error: Could not send LAN discovery to IPv4 Broadcast." << std::endl;
+        orxout(internal_error, context::network) << "Could not send LAN discovery to IPv4 Broadcast." << endl;
 
     /* IPv6 */
@@ -72,5 +72,5 @@
     peer = enet_host_connect(this->host_, &address, 0, 0);
     if (peer == NULL)
-        COUT(1) << "Error: Could not send LAN discovery to IPv6 Multicast." << std::endl;
+        orxout(internal_error, context::network) << "Could not send LAN discovery to IPv6 Multicast." << endl;
 
     ENetEvent event;
@@ -81,5 +81,5 @@
         case ENET_EVENT_TYPE_CONNECT:
         {
-          COUT(4) << "Received LAN discovery connect from server " << event.peer->host->receivedAddress << std::endl;
+          orxout(verbose, context::network) << "Received LAN discovery connect from server " << event.peer->host->receivedAddress << endl;
           ENetPacket* packet = enet_packet_create(LAN_DISCOVERY_MESSAGE, strlen(LAN_DISCOVERY_MESSAGE)+1, ENET_PACKET_FLAG_RELIABLE);
           enet_peer_send(event.peer, 0, packet);
@@ -89,5 +89,5 @@
           {
             packet::ServerInformation info(&event);
-            COUT(3) << "Received LAN discovery server information; Name: " << info.getServerName() << ", Address: " << info.getServerIP() << ", RTT: " << info.getServerRTT() << endl;
+            orxout(internal_info, context::network) << "Received LAN discovery server information; Name: " << info.getServerName() << ", Address: " << info.getServerIP() << ", RTT: " << info.getServerRTT() << endl;
             std::vector<packet::ServerInformation>::iterator it;
             for( it=this->servers_.begin(); it!=this->servers_.end(); ++it )
Index: code/trunk/src/libraries/network/LANDiscovery.h
===================================================================
--- code/trunk/src/libraries/network/LANDiscovery.h	(revision 8729)
+++ code/trunk/src/libraries/network/LANDiscovery.h	(revision 8858)
@@ -21,5 +21,5 @@
  *
  *   Author:
- *      Fabian 'x3n' Landau
+ *      Oliver Scheuss
  *   Co-authors:
  *      ...
Index: code/trunk/src/libraries/network/MasterServer.cc
===================================================================
--- code/trunk/src/libraries/network/MasterServer.cc	(revision 8729)
+++ code/trunk/src/libraries/network/MasterServer.cc	(revision 8858)
@@ -38,5 +38,6 @@
   helper_output_debug( ENetEvent *event, char *addrconv )
   {
-    COUT(4) << "A packet of length" 
+    orxout(verbose, context::master_server)
+      << "A packet of length" 
       << event->packet->dataLength
       << " containing "
@@ -45,5 +46,5 @@
       << addrconv 
       << " on channel "
-      << event->channelID << "\n";
+      << event->channelID << endl;
   }
 
@@ -66,5 +67,5 @@
           + MSPROTO_SERVERLIST_ITEM_LEN + 2,1 );
       if( !tosend ) 
-      { COUT(2) << "Masterserver.cc: Memory allocation failed.\n";
+      { orxout(internal_warning, context::master_server) << "Masterserver.cc: Memory allocation failed." << endl;
         continue;
       } 
@@ -108,5 +109,5 @@
   { /* check for bad parameters */
     if( !event )
-    { COUT(2) << "MasterServer::eventConnect: No event given.\n" ;
+    { orxout(internal_warning, context::master_server) << "MasterServer::eventConnect: No event given." << endl;
       return -1;
     }
@@ -117,8 +118,8 @@
 
     /* output debug info */
-    COUT(4) << "A new client connected from " 
+    orxout(verbose, context::master_server) << "A new client connected from " 
       << addrconv 
       << " on port " 
-      << event->peer->address.port << "\n";
+      << event->peer->address.port << endl;
 
     /* store string form of address here */
@@ -134,10 +135,10 @@
   { /* check for bad parameters */
     if( !event )
-    { COUT(2) << "No event given.\n";
+    { orxout(internal_warning, context::master_server) << "No event given." << endl;
       return -1;
     }
 
     /* output that the disconnect happened */
-    COUT(4) << (char*)event->peer->data << " disconnected.\n";
+    orxout(verbose, context::master_server) << (char*)event->peer->data << " disconnected." << endl;
 
     /* create string from peer data */
@@ -159,5 +160,5 @@
   { /* validate packet */
     if( !event || !(event->packet) || !(event->peer) )
-    { COUT(2) << "No complete event given.\n";
+    { orxout(internal_warning, context::master_server) << "No complete event given." << endl;
       return -1;
     }
@@ -182,6 +183,6 @@
         
         /* tell people we did so */
-        COUT(2) << "Added new server to list: " << 
-          packet::ServerInformation( event ).getServerIP() << "\n";
+        orxout(internal_info, context::master_server) << "Added new server to list: " << 
+          packet::ServerInformation( event ).getServerIP() << endl;
       }
 
@@ -197,5 +198,5 @@
 
         /* tell the user */
-        COUT(2) << "Removed server " << name << " from list.\n";
+        orxout(internal_info, context::master_server) << "Removed server " << name << " from list." << endl;
       }
 
@@ -230,5 +231,5 @@
     if( event == NULL )
     { 
-      COUT(1) << "Could not create ENetEvent structure, exiting.\n";
+      orxout(user_error, context::master_server) << "Could not create ENetEvent structure, exiting." << endl;
       exit( EXIT_FAILURE );
     }
@@ -263,5 +264,5 @@
     /***** INITIALIZE NETWORKING *****/
     if( enet_initialize () != 0)
-    { COUT(1) << "An error occurred while initializing ENet.\n";
+    { orxout(user_error, context::master_server) << "An error occurred while initializing ENet." << endl;
       exit( EXIT_FAILURE );
     }
@@ -285,6 +286,6 @@
     /* see if creation worked */
     if( !this->server )
-    { COUT(1) << 
-        "An error occurred while trying to create an ENet server host.\n";
+    { orxout(user_error, context::master_server) << 
+        "An error occurred while trying to create an ENet server host." << endl;
       exit( EXIT_FAILURE );
     }
@@ -294,5 +295,5 @@
 
     /* tell people we're now initialized */
-    COUT(0) << "MasterServer initialized, waiting for connections.\n";
+    orxout(internal_status, context::master_server) << "MasterServer initialized, waiting for connections." << endl;
   }
 
Index: code/trunk/src/libraries/network/MasterServerComm.cc
===================================================================
--- code/trunk/src/libraries/network/MasterServerComm.cc	(revision 8729)
+++ code/trunk/src/libraries/network/MasterServerComm.cc	(revision 8858)
@@ -28,5 +28,6 @@
 
 #include "MasterServerComm.h"
-#include "util/Debug.h"
+#include "util/Output.h"
+#include "WANDiscovery.h"
 
 namespace orxonox
@@ -44,5 +45,5 @@
     /* initialize Enet */
     if( enet_initialize () != 0 )
-    { COUT(1) << "An error occurred while initializing ENet.\n";
+    { orxout(internal_error, context::master_server) << "An error occurred while initializing ENet." << endl;
       return 1;
     }
@@ -61,6 +62,6 @@
     /* see if it worked */
     if (this->client == NULL)
-    { COUT(1) << "An error occurred while trying to create an " 
-        << "ENet client host.\n";
+    { orxout(internal_error, context::master_server) << "An error occurred while trying to create an " 
+        << "ENet client host." << endl;
       return 1;
     }
@@ -85,6 +86,6 @@
 
     if( this->peer == NULL )
-    { COUT(2) << "ERROR: No available peers for initiating an ENet"
-        << " connection.\n";
+    { orxout(internal_error, context::master_server) << "No available peers for initiating an ENet"
+        << " connection." << endl;
       return -1;
     }
@@ -93,9 +94,9 @@
     if (enet_host_service (this->client, &this->event, 500) > 0 &&
         this->event.type == ENET_EVENT_TYPE_CONNECT )
-      COUT(3) << "Connection to master server succeeded.\n";
+      orxout(internal_info, context::master_server) << "Connection to master server succeeded." << endl;
     else
     {
       enet_peer_reset (this->peer);
-      COUT(2) << "ERROR: connection to " << address << " failed.\n";
+      orxout(internal_warning, context::master_server) << "Connection to " << address << " failed." << endl;
       return -1;
     }
@@ -128,5 +129,5 @@
 
         case ENET_EVENT_TYPE_DISCONNECT:
-          COUT(4) << "Disconnect from master server successful.\n"; 
+          orxout(verbose, context::master_server) << "Disconnect from master server successful." << endl; 
           return 0;
         default: break;
@@ -149,10 +150,9 @@
    * so we can also make callbacks from objects
    */
-  int MasterServerComm::pollForReply( int (*callback)( char*, ENetEvent* ),
-    int delayms )
+  int MasterServerComm::pollForReply( WANDiscovery* listener, int delayms )
   { 
     /* see whether anything happened */
     /* WORK MARK REMOVE THIS OUTPUT */
-    COUT(2) << "polling masterserver...\n";
+    orxout(verbose, context::master_server) << "polling masterserver..." << endl;
 
     /* address buffer */
@@ -176,5 +176,5 @@
           addrconv = (char *) calloc( 50, 1 );
           if( !addrconv ) 
-          { COUT(2) << "MasterServerComm.cc: Could not allocate memory!\n";
+          { orxout(internal_warning, context::master_server) << "MasterServerComm.cc: Could not allocate memory!" << endl;
             break;
           }
@@ -185,5 +185,5 @@
 
           /* DEBUG */
-          COUT(3) << "MasterServer Debug: A packet of length " 
+          orxout(verbose, context::master_server) << "MasterServer Debug: A packet of length " 
             << this->event.packet->dataLength 
             << " containing " << this->event.packet->data
@@ -193,6 +193,6 @@
 
           /* call the supplied callback, if any. */
-          if( (*callback) != NULL )
-            retval = (*callback)( addrconv, &(this->event) );
+          if( listener != NULL )
+            retval = listener->rhandler( addrconv, &(this->event) );
 
           /* clean up */
Index: code/trunk/src/libraries/network/MasterServerComm.h
===================================================================
--- code/trunk/src/libraries/network/MasterServerComm.h	(revision 8729)
+++ code/trunk/src/libraries/network/MasterServerComm.h	(revision 8858)
@@ -93,5 +93,5 @@
        * 
        * Poll the master server for new data and act accordingly */
-      int pollForReply( int (*callback)( char*, ENetEvent* ), int delayms );
+      int pollForReply( WANDiscovery* listener, int delayms );
 
     private:
Index: code/trunk/src/libraries/network/NetworkChatListener.h
===================================================================
--- code/trunk/src/libraries/network/NetworkChatListener.h	(revision 8858)
+++ code/trunk/src/libraries/network/NetworkChatListener.h	(revision 8858)
@@ -0,0 +1,63 @@
+/*
+ *   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:
+ *      Fabian 'x3n' Landau
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _NetworkChatListener_H__
+#define _NetworkChatListener_H__
+
+#include "NetworkPrereqs.h"
+
+#include "core/OrxonoxClass.h"
+
+namespace orxonox
+{
+    /**
+        @brief The only function of this interface, incomingChat(), gets called whenever a chat
+        message was received through the network.
+
+        This interface exists mostly to resolve circular dependencies between the chat functions
+        in Host and ChatManager. ChatManager is the main derivative of this interface.
+    */
+    class _NetworkExport NetworkChatListener : virtual public OrxonoxClass
+    {
+        friend class Host;
+
+        public:
+            NetworkChatListener(); // implemented in Host.cc
+            virtual ~NetworkChatListener() {}
+
+        protected:
+            /**
+                @brief Gets called when a chat message was received through the network.
+                @param message The message
+                @param sourceID The (network) client ID of the sender
+            */
+            virtual void incomingChat(const std::string& message, unsigned int sourceID) = 0;
+    };
+}
+
+#endif /* _NetworkChatListener_H__ */
Index: code/trunk/src/libraries/network/NetworkPrecompiledHeaders.h
===================================================================
--- code/trunk/src/libraries/network/NetworkPrecompiledHeaders.h	(revision 8729)
+++ code/trunk/src/libraries/network/NetworkPrecompiledHeaders.h	(revision 8858)
@@ -52,5 +52,5 @@
 #include <set>      // 20
 
-#include "util/Debug.h"      // 20
+#include "util/Output.h"      // 20
 #include <loki/TypeTraits.h> // 18
 
Index: code/trunk/src/libraries/network/NetworkPrereqs.h
===================================================================
--- code/trunk/src/libraries/network/NetworkPrereqs.h	(revision 8729)
+++ code/trunk/src/libraries/network/NetworkPrereqs.h	(revision 8858)
@@ -118,5 +118,4 @@
 namespace orxonox
 {
-  class ChatListener;
   class Client;
   class ClientConnection;
@@ -130,4 +129,7 @@
   class GamestateManager;
   class Host;
+  class MasterServer;
+  class MasterServerComm;
+  class NetworkChatListener;
   class NetworkFunctionBase;
   struct NetworkFunctionPointer;
@@ -136,7 +138,10 @@
   class NetworkMemberFunction;
   class NetworkMemberFunctionBase;
+  class PeerList;
   class Server;
   class ServerConnection;
   class TrafficControl;
+  class WANDiscoverable;
+  class WANDiscovery;
 
   // packet
Index: code/trunk/src/libraries/network/PeerList.cc
===================================================================
--- code/trunk/src/libraries/network/PeerList.cc	(revision 8729)
+++ code/trunk/src/libraries/network/PeerList.cc	(revision 8858)
@@ -28,6 +28,8 @@
 
 #include "PeerList.h"
-#include <network/packet/ServerInformation.h>
+
 #include <cstdio>
+#include "util/Output.h"
+#include "network/packet/ServerInformation.h"
 
 namespace orxonox
@@ -40,5 +42,5 @@
   { /* error correction */
     if( toadd == NULL ) 
-    { fprintf( stderr, "PeerList::addPeer: empty peer given.\n" );
+    { orxout(internal_error, context::master_server) << "PeerList::addPeer: empty peer given." << endl;
       return -1;
     }
Index: code/trunk/src/libraries/network/Server.cc
===================================================================
--- code/trunk/src/libraries/network/Server.cc	(revision 8729)
+++ code/trunk/src/libraries/network/Server.cc	(revision 8858)
@@ -47,5 +47,5 @@
 
 #include "util/Clock.h"
-#include "util/Debug.h"
+#include "util/Output.h"
 #include "core/ObjectList.h"
 #include "core/command/Executor.h"
@@ -56,9 +56,7 @@
 #include "packet/Gamestate.h"
 #include "packet/Welcome.h"
-#include "ChatListener.h"
 // #include "ClientInformation.h"
 #include "FunctionCallManager.h"
 #include "GamestateManager.h"
-#include "WANDiscovery.h"
 
 namespace orxonox
@@ -100,12 +98,4 @@
   }
 
-
-  /** helper that connects to the master server */
-  void Server::helper_ConnectToMasterserver()
-  {
-//     WANDiscovery::getInstance().msc.sendRequest( MSPROTO_GAME_SERVER " " 
-//       MSPROTO_REGISTER_SERVER );
-  }
-
   /**
   * This function opens the server by creating the listener thread
@@ -114,7 +104,7 @@
   {
     Host::setActive(true);
-    COUT(4) << "opening server" << endl;
+    orxout(verbose, context::network) << "opening server" << endl;
     this->openListener();
-    
+
     /* make discoverable on LAN */
     LANDiscoverable::setActivity(true);
@@ -122,8 +112,4 @@
     /* make discoverable on WAN */
     WANDiscoverable::setActivity(true);
-    /* TODO this needs to be optional, we need a switch from the UI to
-     * enable/disable this 
-     */
-//     helper_ConnectToMasterserver();
 
     /* done */
@@ -137,55 +123,15 @@
   {
     Host::setActive(false);
-    COUT(4) << "closing server" << endl;
+    orxout(verbose, context::network) << "closing server" << endl;
     this->disconnectClients();
     this->closeListener();
 
     /* tell master server we're closing */
-    COUT(2) << "disconnecting." << endl;
-    WANDiscoverable::setActivity(false);    
-    COUT(2) << "disconnecting done" << endl;
+    orxout(internal_info, context::network) << "disconnecting." << endl;
+    WANDiscoverable::setActivity(false);
+    orxout(internal_info, context::network) << "disconnecting done" << endl;
 
     LANDiscoverable::setActivity(false);
     return;
-  }
-
-  bool Server::processChat(const std::string& message, unsigned int playerID)
-  {
-//     ClientInformation *temp = ClientInformation::getBegin();
-    packet::Chat *chat;
-//     while(temp){
-    chat = new packet::Chat(message, playerID);
-    chat->setPeerID(NETWORK_PEER_ID_BROADCAST);
-    chat->send( static_cast<Host*>(this) );
-//         COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl;
-//       temp = temp->next();
-//     }
-//    COUT(1) << "Player " << playerID << ": " << message << std::endl;
-    return true;
-  }
-
-
-  /* handle incoming data */
-  int rephandler( char *addr, ENetEvent *ev )
-  { 
-    /* reply to pings */
-    if( !strncmp( (char *)ev->packet->data, MSPROTO_PING_GAMESERVER, 
-      MSPROTO_PING_GAMESERVER_LEN ) )
-      //this->msc.sendRequest( MSPROTO_ACK );
-      /* NOTE implement this after pollForReply
-       * reimplementation 
-       */
-      return 0;
-
-    /* done handling, return all ok code 0 */
-    return 0;
-  }
-
-  void Server::helper_HandleMasterServerRequests()
-  { 
-    /* poll the master server for replies and see whether something 
-     * has to be done or changed.
-     */
-    //WANDiscovery::getInstance().msc.pollForReply( rhandler, 10 );
   }
 
@@ -202,8 +148,4 @@
     // receive and process incoming discovery packets
     LANDiscoverable::update();
-    
-    // receive and process requests from master server
-    /* todo */
-    //helper_HandleMasterServerRequests();
 
     if ( GamestateManager::hasPeers() )
@@ -246,5 +188,5 @@
   {
 //     for( ClientInformation* temp=ClientInformation::getBegin(); temp!=0; temp=temp->next() )
-//       COUT(0) << "Round trip time to client with ID: " << temp->getID() << " is " << temp->getRTT() << " ms" << endl;
+//       orxout(message) << "Round trip time to client with ID: " << temp->getID() << " is " << temp->getRTT() << " ms" << endl;
   }
 
@@ -268,11 +210,11 @@
       return;
     GamestateManager::update();
-//     COUT(5) << "Server: one gamestate update complete, goig to sendGameState" << std::endl;
-    //std::cout << "updated gamestate, sending it" << std::endl;
+//     orxout(verbose_more, context::network) << "Server: one gamestate update complete, goig to sendGameState" << endl;
+    //orxout(verbose_more, context::network) << "updated gamestate, sending it" << endl;
     //if(clients->getGamestateID()!=GAMESTATEID_INITIAL)
     sendGameStates();
     sendObjectDeletes();
-//     COUT(5) << "Server: one sendGameState turn complete, repeat in next tick" << std::endl;
-    //std::cout << "sent gamestate" << std::endl;
+//     orxout(verbose_more, context::network) << "Server: one sendGameState turn complete, repeat in next tick" << endl;
+    //orxout(verbose_more, context::network) << "sent gamestate" << endl;
   }
 
@@ -305,9 +247,9 @@
       return true;  //everything ok (no deletes this tick)
     }
-//     COUT(3) << "sending DeleteObjects" << std::endl;
+//     orxout(verbose, context::network) << "sending DeleteObjects" << endl;
 //     while(temp != NULL){
 //       if( !(temp->getSynched()) )
 //       {
-//         COUT(5) << "Server: not sending gamestate" << std::endl;
+//         orxout(verbose_more, context::network) << "Server: not sending gamestate" << endl;
 //         temp=temp->next();
 //         continue;
@@ -318,5 +260,5 @@
     del->setPeerID(NETWORK_PEER_ID_BROADCAST);
     if ( !del->send( static_cast<Host*>(this) ) )
-      COUT(3) << "Server: could not broadcast deleteObjects packet" << std::endl;
+      orxout(internal_warning, context::network) << "Server: could not broadcast deleteObjects packet" << endl;
 //       temp=temp->next();
       // gs gets automatically deleted by enet callback
@@ -330,10 +272,10 @@
   {
 //     static unsigned int newid=1;
-// 
-//     COUT(2) << "Server: adding client" << std::endl;
+//
+//     orxout(internal_info, context::network) << "Server: adding client" << endl;
 //     ClientInformation *temp = ClientInformation::insertBack(new ClientInformation);
 //     if(!temp)
 //     {
-//       COUT(2) << "Server: could not add client" << std::endl;
+//       orxout(internal_warning, context::network) << "Server: could not add client" << endl;
 //     }
 //     temp->setID(newid);
@@ -347,5 +289,5 @@
 //     ++newid;
 
-    COUT(3) << "Server: added client id: " << peerID << std::endl;
+    orxout(internal_info, context::network) << "Server: added client id: " << peerID << endl;
     createClient(peerID);
 }
@@ -353,5 +295,5 @@
   void Server::removePeer(uint32_t peerID)
   {
-    COUT(4) << "removing client from list" << std::endl;
+    orxout(verbose, context::network) << "removing client from list" << endl;
 //     ClientInformation *client = ClientInformation::findClient(&event->peer->address);
 //     if(!client)
@@ -375,5 +317,5 @@
 //     }
   }
-  
+
   void Server::processPacket(packet::Packet* packet)
   {
@@ -395,8 +337,8 @@
 //     if(!temp)
 //     {
-//       COUT(2) << "Server. could not create client with id: " << clientID << std::endl;
+//       orxout(internal_error, context::network) << "Server. could not create client with id: " << clientID << endl;
 //       return false;
 //     }
-//     COUT(4) << "Con.Man: creating client id: " << temp->getID() << std::endl;
+//     orxout(verbose, context::network) << "Con.Man: creating client id: " << temp->getID() << endl;
 
     // synchronise class ids
@@ -411,6 +353,6 @@
 //     temp->setSynched(true);
     GamestateManager::setSynched(clientID);
-    
-    COUT(4) << "sending welcome" << std::endl;
+
+    orxout(verbose, context::network) << "sending welcome" << endl;
     packet::Welcome *w = new packet::Welcome(clientID);
     w->setPeerID(clientID);
@@ -438,31 +380,50 @@
   }
 
-  bool Server::chat(const std::string& message)
-  {
-      return this->sendChat(message, Host::getPlayerID());
-  }
-
-  bool Server::broadcast(const std::string& message)
-  {
-      return this->sendChat(message, NETWORK_PEER_ID_BROADCAST);
-  }
-
-  bool Server::sendChat(const std::string& message, unsigned int clientID)
-  {
-//     ClientInformation *temp = ClientInformation::getBegin();
-    packet::Chat *chat;
-//     while(temp)
-    {
-      chat = new packet::Chat(message, clientID);
-      chat->setPeerID(NETWORK_PEER_ID_BROADCAST);
-      chat->send( static_cast<Host*>(this) );
-//         COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl;
-//       temp = temp->next();
-    }
-//    COUT(1) << "Player " << Host::getPlayerID() << ": " << message << std::endl;
-    for (ObjectList<ChatListener>::iterator it = ObjectList<ChatListener>::begin(); it != ObjectList<ChatListener>::end(); ++it)
-      it->incomingChat(message, clientID);
-
-    return true;
+  /**
+   * @brief Sends a chat message to the given target ID.
+   * @param message message to be sent
+   * @param sourceID the ID of the sender
+   * @param targetID the ID of the receiver
+   */
+  void Server::doSendChat(const std::string& message, unsigned int sourceID, unsigned int targetID)
+  {
+    // check if the target exists. just ignore the message otherwise
+    if (!this->isValidTarget(targetID)) // TODO: remove this if an invalid clientIDs don't trigger assertions anymore
+      return;
+
+    // send the message to the target
+    packet::Chat* packet = new packet::Chat(message, sourceID, targetID);
+    packet->setPeerID(targetID);
+    packet->send( static_cast<Host*>(this) );
+
+    // if the target is (or includes) this host as well, call the parent function which passes the message to the listeners
+    if (targetID == NETWORK_PEER_ID_BROADCAST || targetID == Host::getPlayerID())
+      Host::doReceiveChat(message, sourceID, targetID);
+  }
+
+  /**
+   * @brief Gets called if a packet::Chat packet is received. Forwards the packet to the target
+   * and calls the parent function if necessary.
+   */
+  void Server::doReceiveChat(const std::string& message, unsigned int sourceID, unsigned int targetID)
+  {
+      this->doSendChat(message, sourceID, targetID);
+  }
+
+  /**
+   * @brief Returns true if the target ID is in the list of clients (or if it
+   * corresponds to the broadcast or the server ID).
+   */
+  bool Server::isValidTarget(unsigned int targetID)
+  {
+    if (targetID == NETWORK_PEER_ID_BROADCAST || targetID == NETWORK_PEER_ID_SERVER)
+      return true;
+
+    std::vector<uint32_t>::iterator it;
+    for( it=this->clientIDs_.begin(); it!=this->clientIDs_.end(); ++it )
+      if( *it == targetID )
+        return true;
+
+    return false;
   }
 
@@ -476,5 +437,5 @@
     }
     assert(failures<10);
-    COUT(4) << "syncClassid:\tall synchClassID packets have been sent" << std::endl;
+    orxout(verbose, context::network) << "syncClassid:\tall synchClassID packets have been sent" << endl;
   }
 
Index: code/trunk/src/libraries/network/Server.h
===================================================================
--- code/trunk/src/libraries/network/Server.h	(revision 8729)
+++ code/trunk/src/libraries/network/Server.h	(revision 8858)
@@ -42,6 +42,4 @@
 #include "LANDiscoverable.h"
 #include "WANDiscoverable.h"
-// #include "MasterServerComm.h"
-// #include "MasterServerProtocol.h"
 
 
@@ -61,12 +59,6 @@
     ~Server();
 
-    /* helpers */
-    void helper_ConnectToMasterserver();
-    void helper_HandleMasterServerRequests();
-    int replyhandler( char *addr, ENetEvent *ev );
-
     void open();
     void close();
-    bool processChat(const std::string& message, unsigned int playerID);
     void queuePacket(ENetPacket *packet, int clientID, uint8_t channelID);
     virtual bool sendPacket( packet::Packet* packet ){ return packet->send( static_cast<Host*>(this) ); }
@@ -89,7 +81,7 @@
     bool sendGameStates();
     bool sendObjectDeletes();
-    virtual bool chat(const std::string& message);
-    virtual bool broadcast(const std::string& message);
-    bool sendChat(const std::string& message, unsigned int clientID);
+    bool isValidTarget(unsigned int targetID);
+    virtual void doSendChat(const std::string& message, unsigned int sourceID, unsigned int targetID);
+    virtual void doReceiveChat(const std::string& message, unsigned int sourceID, unsigned int targetID);
     void syncClassid(unsigned int clientID);
 
Index: code/trunk/src/libraries/network/ServerConnection.cc
===================================================================
--- code/trunk/src/libraries/network/ServerConnection.cc	(revision 8729)
+++ code/trunk/src/libraries/network/ServerConnection.cc	(revision 8858)
@@ -34,5 +34,5 @@
 #include <enet/enet.h>
 
-#include "util/Debug.h"
+#include "util/Output.h"
 #include <util/Sleep.h>
 // #include "ClientInformation.h"
@@ -61,5 +61,5 @@
   {
     if (enet_address_set_host (this->bindAddress_, bindAddress.c_str()) < 0)
-        COUT(1) << "Error: Could not resolve \"" << bindAddress << "\"." << std::endl;
+        orxout(internal_error, context::network) << "Could not resolve \"" << bindAddress << "\"." << endl;
   }
 
@@ -75,5 +75,5 @@
     if ( this->host_ == NULL )
     {
-        COUT(1) << "ServerConnection: host_ == NULL" << std::endl;
+        orxout(internal_error, context::network) << "ServerConnection: host_ == NULL" << endl;
         return false;
     }
@@ -83,9 +83,9 @@
     assert( this->host_->socket4 != ENET_SOCKET_NULL || this->host_->socket6 != ENET_SOCKET_NULL );
     if (this->host_->socket4 == ENET_SOCKET_NULL)
-        COUT(2) << "Warning: IPv4 Socket failed." << std::endl;
+        orxout(internal_warning, context::network) << "IPv4 Socket failed." << endl;
     else if (this->host_->socket6 == ENET_SOCKET_NULL)
-        COUT(2) << "Warning: IPv6 Socket failed." << std::endl;
+        orxout(internal_warning, context::network) << "IPv6 Socket failed." << endl;
     else
-        COUT(3) << "Info: Using IPv4 and IPv6 Sockets." << std::endl;
+        orxout(internal_info, context::network) << "Using IPv4 and IPv6 Sockets." << endl;
     
     // start communication thread
@@ -114,5 +114,5 @@
 //       ClientInformation *temp = ClientInformation::findClient(clientID);
 //       if(!temp){
-//         COUT(3) << "C.Man: addPacket findClient failed" << std::endl;
+//         orxout(internal_warning, context::network) << "C.Man: addPacket findClient failed" << endl;
 //       }
       Connection::addPacket(packet, clientID, channelID);
Index: code/trunk/src/libraries/network/TrafficControl.cc
===================================================================
--- code/trunk/src/libraries/network/TrafficControl.cc	(revision 8729)
+++ code/trunk/src/libraries/network/TrafficControl.cc	(revision 8858)
@@ -287,7 +287,7 @@
   {
     std::list<obj>::iterator it;
-    COUT(0) << "=========== Objectlist ===========" << endl;
+    orxout(debug_output, context::network) << "=========== Objectlist ===========" << endl;
     for( it=list.begin(); it!=list.end(); it++)
-      COUT(0) << "ObjectID: " << it->objID << " creatorID: " << it->objCreatorID << " Priority: " << clientListPerm_[clientID][it->objID].objValuePerm + clientListPerm_[clientID][it->objID].objValueSched << " size: " << it->objSize << endl;
+      orxout(debug_output, context::network) << "ObjectID: " << it->objID << " creatorID: " << it->objCreatorID << " Priority: " << clientListPerm_[clientID][it->objID].objValuePerm + clientListPerm_[clientID][it->objID].objValueSched << " size: " << it->objSize << endl;
   }
 
Index: code/trunk/src/libraries/network/WANDiscoverable.cc
===================================================================
--- code/trunk/src/libraries/network/WANDiscoverable.cc	(revision 8729)
+++ code/trunk/src/libraries/network/WANDiscoverable.cc	(revision 8858)
@@ -21,8 +21,7 @@
  *
  *   Author:
- *      Fabian 'x3n' Landau (original)
+ *      Sandro 'smerkli' Merkli
  *   Co-authors:
- *      Sandro 'smerkli' Merkli (adaptions to WAN)
- *      ...
+ *      Oliver Scheuss (original)
  *
  */
@@ -44,5 +43,5 @@
   {
     /* debugging output */
-    COUT(4) << "Creating WANDiscoverable.\n";
+    orxout(verbose, context::master_server) << "Creating WANDiscoverable." << endl;
   
     /* register object in orxonox */
@@ -91,5 +90,5 @@
     if( msc.initialize() )
     {
-      COUT(2) << "Error: could not initialize master server communications!\n";
+      orxout(internal_error, context::master_server) << "Could not initialize master server communications!" << endl;
       return false;
     }
@@ -98,11 +97,11 @@
     if( msc.connect( this->msaddress.c_str(), ORX_MSERVER_PORT ) )
     {
-      COUT(2) << "Error: could not connect to master server at " 
-                 << this->msaddress << std::endl;
+      orxout(internal_error, context::master_server) << "Could not connect to master server at " 
+                 << this->msaddress << endl;
       return false;
     }
                  
     /* debugging output */
-    COUT(4) << "Initialization of WANDiscoverable complete.\n";
+    orxout(verbose, context::master_server) << "Initialization of WANDiscoverable complete." << endl;
     
     
Index: code/trunk/src/libraries/network/WANDiscoverable.h
===================================================================
--- code/trunk/src/libraries/network/WANDiscoverable.h	(revision 8729)
+++ code/trunk/src/libraries/network/WANDiscoverable.h	(revision 8858)
@@ -19,6 +19,8 @@
  *   Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  *
- *   Author: Fabian 'x3n' Landau (original) Co-authors: Sandro 'smerkli' Merkli
- *   (copied and adapted to WAN)
+ *   Author:
+ *      Sandro 'smerkli' Merkli
+ *   Co-authors:
+ *      Oliver Scheuss (original)
  *
  */
Index: code/trunk/src/libraries/network/WANDiscovery.cc
===================================================================
--- code/trunk/src/libraries/network/WANDiscovery.cc	(revision 8729)
+++ code/trunk/src/libraries/network/WANDiscovery.cc	(revision 8858)
@@ -21,8 +21,7 @@
  *
  *   Author:
- *      Fabian 'x3n' Landau (original)
+ *      Sandro 'smerkli' Merkli
  *   Co-authors:
- *      Sandro 'smerkli' Merkli (adaptions to WAN)
- *      ...
+ *      Oliver Scheuss (original)
  *
  */
@@ -33,5 +32,4 @@
 #include <cstring>
 
-#include "util/ScopedSingletonManager.h"
 #include "core/CoreIncludes.h"
 
@@ -39,11 +37,8 @@
 namespace orxonox
 {
-  ManageScopedSingleton(WANDiscovery, ScopeID::Graphics, true);
-
-
   WANDiscovery::WANDiscovery()
   {
     /* debugging output */
-    COUT(4) << "Creating WANDiscovery.\n";
+    orxout(verbose, context::master_server) << "Creating WANDiscovery." << endl;
   
     /* register object in orxonox */
@@ -55,13 +50,13 @@
     /* initialize it and see if it worked */
     if( msc.initialize() )
-      COUT(2) << "Error: could not initialize master server communications!\n";
+      orxout(internal_error, context::master_server) << "Could not initialize master server communications!" << endl;
 
     /* connect and see if it worked */
     if( msc.connect( this->msaddress.c_str(), ORX_MSERVER_PORT ) )
-      COUT(2) << "Error: could not connect to master server at " 
-        << this->msaddress << std::endl;
+      orxout(internal_error, context::master_server) << "Could not connect to master server at " 
+        << this->msaddress << endl;
 
     /* debugging output */
-    COUT(4) << "Initialization of WANDiscovery complete.\n";
+    orxout(verbose, context::master_server) << "Initialization of WANDiscovery complete." << endl;
   }
 
@@ -81,9 +76,9 @@
 
   /* callback for the network reply poller */
-  int rhandler( char *addr, ENetEvent *ev )
+  int WANDiscovery::rhandler( char *addr, ENetEvent *ev )
   { 
     /* error recognition */
     if( !ev || !ev->packet || !ev->packet->data )
-    { COUT(2) << "Bad arguments received in WANDiscovery's reply handler.\n";
+    { orxout(internal_warning, context::master_server) << "Bad arguments received in WANDiscovery's reply handler." << endl;
       return 0;
     }
@@ -104,5 +99,5 @@
 
       /* add to list */
-      WANDiscovery::getInstance().servers_.push_back( toadd );
+      this->servers_.push_back( toadd );
     }
     else if( !strncmp( (char*)ev->packet->data, MSPROTO_SERVERLIST_END,
@@ -133,5 +128,5 @@
     {
       /* poll for reply and act according to what was received */
-      switch( this->msc.pollForReply( rhandler, 500 ) )
+      switch( this->msc.pollForReply( this, 500 ) )
       { case 0: /* no event occured, decrease timeout */
           --i; break;
Index: code/trunk/src/libraries/network/WANDiscovery.h
===================================================================
--- code/trunk/src/libraries/network/WANDiscovery.h	(revision 8729)
+++ code/trunk/src/libraries/network/WANDiscovery.h	(revision 8858)
@@ -19,6 +19,8 @@
  *   Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  *
- *   Author: Fabian 'x3n' Landau (original) Co-authors: Sandro 'smerkli' Merkli
- *   (copied and adapted to WAN)
+ *   Author:
+ *      Sandro 'smerkli' Merkli
+ *   Co-authors:
+ *      Oliver Scheuss (original)
  *
  */
@@ -30,5 +32,4 @@
 #include "packet/ServerInformation.h"
 #include "core/ConfigFileManager.h"
-#include "util/Singleton.h"
 #include "core/OrxonoxClass.h"
 #include "core/ConfigValueIncludes.h"
@@ -47,10 +48,9 @@
   class _NetworkExport WANDiscovery
 // tolua_end
-    : public Singleton<WANDiscovery>, public OrxonoxClass
+    : public OrxonoxClass
   { // tolua_export
-    friend class Singleton<WANDiscovery>;
     public:
       /** constructor */
-      WANDiscovery();
+      WANDiscovery(); // tolua_export
 
       /** destructor */
@@ -81,10 +81,4 @@
       std::string getServerListItemIP( unsigned int index ); // tolua_export
 
-      /** \return an instance of WANDiscovery
-       * 
-       * Create and return an instance of WANDiscovery.
-       */
-      static WANDiscovery& getInstance() { return Singleton<WANDiscovery>::getInstance(); } // tolua_export
-    
       /* todo: might make this private and use getter/setter methods
        * at some later time. 
@@ -98,9 +92,8 @@
       /** Master server communications object */
       MasterServerComm msc;
+
+      int rhandler( char *addr, ENetEvent *ev );
       
     private:
-      /** Singleton pointer */
-      static WANDiscovery* singletonPtr_s;
-
       /** master server address */
       std::string msaddress;
Index: code/trunk/src/libraries/network/packet/Acknowledgement.cc
===================================================================
--- code/trunk/src/libraries/network/packet/Acknowledgement.cc	(revision 8729)
+++ code/trunk/src/libraries/network/packet/Acknowledgement.cc	(revision 8858)
@@ -29,5 +29,5 @@
 #include "Acknowledgement.h"
 
-#include "util/Debug.h"
+#include "util/Output.h"
 #include "network/GamestateHandler.h"
 #include "network/Host.h"
@@ -64,5 +64,5 @@
 
 bool Acknowledgement::process(orxonox::Host* host){
-  COUT(5) << "processing ACK with ID: " << getAckID() << endl;
+  orxout(verbose_more, context::packets) << "processing ACK with ID: " << getAckID() << endl;
   bool b = host->ackGamestate(getAckID(), peerID_);
   delete this;
Index: code/trunk/src/libraries/network/packet/Chat.cc
===================================================================
--- code/trunk/src/libraries/network/packet/Chat.cc	(revision 8729)
+++ code/trunk/src/libraries/network/packet/Chat.cc	(revision 8858)
@@ -39,10 +39,11 @@
 
 /* Some lengths */
-#define   _PACKETID         0
-const int _PLAYERID     =   _PACKETID + sizeof(Type::Value);
-#define   _MESSAGELENGTH    _PLAYERID + sizeof(uint32_t)
-#define   _MESSAGE          _MESSAGELENGTH + sizeof(uint32_t)
+#define _PACKETID         0
+#define _SOURCEID         _PACKETID + sizeof(Type::Value)
+#define _TARGETID         _SOURCEID + sizeof(uint32_t)
+#define _MESSAGELENGTH    _TARGETID + sizeof(uint32_t)
+#define _MESSAGE          _MESSAGELENGTH + sizeof(uint32_t)
 
-Chat::Chat( const std::string& message, unsigned int playerID )
+Chat::Chat( const std::string& message, unsigned int sourceID, unsigned int targetID )
  : Packet()
 {
@@ -57,5 +58,6 @@
 
   *(Type::Value *)(data_ + _PACKETID ) = Type::Chat;
-  *(unsigned int *)(data_ + _PLAYERID ) = playerID;
+  *(unsigned int *)(data_ + _SOURCEID ) = sourceID;
+  *(unsigned int *)(data_ + _TARGETID ) = targetID;
   *(unsigned int *)(data_ + _MESSAGELENGTH ) = messageLength_;
 
@@ -81,7 +83,7 @@
 
 bool Chat::process(orxonox::Host* host){
-  bool b = host->incomingChat(std::string((const char*)data_+_MESSAGE), *(uint32_t *)(data_+_PLAYERID));
+  host->doReceiveChat(std::string((const char*)data_+_MESSAGE), *(uint32_t *)(data_+_SOURCEID), *(uint32_t *)(data_+_TARGETID));
   delete this;
-  return b;
+  return true;
 }
 
Index: code/trunk/src/libraries/network/packet/Chat.h
===================================================================
--- code/trunk/src/libraries/network/packet/Chat.h	(revision 8729)
+++ code/trunk/src/libraries/network/packet/Chat.h	(revision 8858)
@@ -42,5 +42,5 @@
 public:
   /* constructors */
-  Chat( const std::string& message, unsigned int playerID );
+  Chat( const std::string& message, unsigned int sourceID, unsigned int targetID );
   Chat( uint8_t* data, unsigned int clientID );
 
Index: code/trunk/src/libraries/network/packet/ClassID.cc
===================================================================
--- code/trunk/src/libraries/network/packet/ClassID.cc	(revision 8729)
+++ code/trunk/src/libraries/network/packet/ClassID.cc	(revision 8858)
@@ -92,5 +92,5 @@
   assert(tempsize==packetSize);
 
-  COUT(5) << "classid packetSize is " << packetSize << endl;
+  orxout(verbose_more, context::packets) << "classid packetSize is " << packetSize << endl;
 
 }
@@ -131,5 +131,5 @@
   Identifier::clearNetworkIDs();
 
-  COUT(4) << "=== processing classids: " << endl;
+  orxout(verbose, context::packets) << "=== processing classids: " << endl;
   std::pair<uint32_t, std::string> tempPair;
   Identifier *id;
@@ -143,7 +143,7 @@
     classname = temp+2*sizeof(uint32_t);
     id=ClassByString( std::string((const char*)classname) );
-    COUT(3) << "processing classid: " << networkID << " name: " << classname << " id: " << id << std::endl;
+    orxout(internal_info, context::packets) << "processing classid: " << networkID << " name: " << classname << " id: " << id << endl;
     if(id==NULL){
-      COUT(0) << "Received a bad classname" << endl;
+      orxout(user_error, context::packets) << "Received a bad classname" << endl;
       abort();
     }
Index: code/trunk/src/libraries/network/packet/DeleteObjects.cc
===================================================================
--- code/trunk/src/libraries/network/packet/DeleteObjects.cc	(revision 8729)
+++ code/trunk/src/libraries/network/packet/DeleteObjects.cc	(revision 8858)
@@ -31,5 +31,5 @@
 
 #include <cassert>
-#include "util/Debug.h"
+#include "util/Output.h"
 #include "network/synchronisable/Synchronisable.h"
 
@@ -62,5 +62,5 @@
   if(number==0)
     return false;
-  COUT(4) << "sending DeleteObjects: ";
+  orxout(verbose, context::packets) << "sending DeleteObjects: ";
   unsigned int size = sizeof(Type::Value) + sizeof(uint32_t)*(number+1);
   data_ = new uint8_t[size];
@@ -73,8 +73,8 @@
     unsigned int temp = Synchronisable::popDeletedObject();
     *reinterpret_cast<uint32_t*>(tdata) = temp;
-    COUT(4) << temp << ' ';
+    orxout(verbose, context::packets) << temp << ' ';
     tdata += sizeof(uint32_t);
   }
-  COUT(4) << std::endl;
+  orxout(verbose, context::packets) << endl;
   return true;
 }
@@ -90,5 +90,5 @@
   for(unsigned int i=0; i<*(unsigned int *)(data_+_QUANTITY); i++)
   {
-    COUT(4) << "deleting object with id: " << *(uint32_t*)(data_+_OBJECTIDS+i*sizeof(uint32_t)) << std::endl;
+    orxout(verbose, context::packets) << "deleting object with id: " << *(uint32_t*)(data_+_OBJECTIDS+i*sizeof(uint32_t)) << endl;
     Synchronisable::deleteObject( *(uint32_t*)(data_+_OBJECTIDS+i*sizeof(uint32_t)) );
   }
Index: code/trunk/src/libraries/network/packet/FunctionIDs.cc
===================================================================
--- code/trunk/src/libraries/network/packet/FunctionIDs.cc	(revision 8729)
+++ code/trunk/src/libraries/network/packet/FunctionIDs.cc	(revision 8858)
@@ -34,5 +34,5 @@
 #include <string>
 
-#include "util/Debug.h"
+#include "util/Output.h"
 #include "core/ObjectList.h"
 #include "network/NetworkFunction.h"
@@ -88,5 +88,5 @@
   }
 
-  COUT(5) << "FunctionIDs packetSize is " << packetSize << endl;
+  orxout(verbose_more, context::packets) << "FunctionIDs packetSize is " << packetSize << endl;
 
 }
@@ -126,5 +126,5 @@
   unsigned char *functionname;
 
-  COUT(4) << "=== processing functionids: " << endl;
+  orxout(verbose, context::packets) << "=== processing functionids: " << endl;
   std::pair<uint32_t, std::string> tempPair;
   // read the total number of classes
@@ -137,5 +137,5 @@
     stringsize = *(uint32_t*)(temp+sizeof(uint32_t));
     functionname = temp+2*sizeof(uint32_t);
-    COUT(3) << "processing functionid: " << networkID << " name: " << functionname << std::endl;
+    orxout(internal_info, context::packets) << "processing functionid: " << networkID << " name: " << functionname << endl;
     NetworkFunctionBase::setNetworkID((const char*)functionname, networkID);
     temp += 2*sizeof(uint32_t) + stringsize;
Index: code/trunk/src/libraries/network/packet/Gamestate.cc
===================================================================
--- code/trunk/src/libraries/network/packet/Gamestate.cc	(revision 8729)
+++ code/trunk/src/libraries/network/packet/Gamestate.cc	(revision 8858)
@@ -31,5 +31,5 @@
 #include <zlib.h>
 
-#include "util/Debug.h"
+#include "util/Output.h"
 #include "util/OrxAssert.h"
 #include "core/GameMode.h"
@@ -108,5 +108,5 @@
   uint32_t size = calcGamestateSize(id, mode);
 
-  COUT(5) << "G.ST.Man: producing gamestate with id: " << id << std::endl;
+  orxout(verbose_more, context::packets) << "G.ST.Man: producing gamestate with id: " << id << endl;
   if(size==0)
     return false;
@@ -114,5 +114,5 @@
   if(!data_)
   {
-    COUT(2) << "GameStateManager: could not allocate memory" << std::endl;
+    orxout(internal_warning, context::packets) << "GameStateManager: could not allocate memory" << endl;
     return false;
   }
@@ -139,5 +139,5 @@
       assert(0); // if we don't use multithreading this part shouldn't be neccessary
       // start allocate additional memory
-      COUT(3) << "Gamestate: need additional memory" << std::endl;
+      orxout(internal_info, context::packets) << "Gamestate: need additional memory" << endl;
       ObjectList<Synchronisable>::iterator temp = it;
       uint32_t addsize=tempsize;
@@ -167,6 +167,6 @@
   //stop write gamestate header
 
-  COUT(5) << "Gamestate: Gamestate size: " << currentsize << std::endl;
-  COUT(5) << "Gamestate: 'estimated' (and corrected) Gamestate size: " << size << std::endl;
+  orxout(verbose_more, context::packets) << "Gamestate: Gamestate size: " << currentsize << endl;
+  orxout(verbose_more, context::packets) << "Gamestate: 'estimated' (and corrected) Gamestate size: " << size << endl;
   return true;
 }
@@ -175,5 +175,5 @@
 bool Gamestate::spreadData(uint8_t mode)
 {
-  COUT(5) << "processing gamestate with id " << header_.getID() << endl;
+  orxout(verbose_more, context::packets) << "processing gamestate with id " << header_.getID() << endl;
   assert(data_);
   assert(!header_.isCompressed());
@@ -195,5 +195,5 @@
       else
       {
-//         COUT(4) << "not creating object of classid " << objectheader.getClassID() << endl;
+//         orxout(verbose, context::packets) << "not creating object of classid " << objectheader.getClassID() << endl;
         mem += objectheader.getDataSize() + ( objectheader.isDiffed() ? SynchronisableHeaderLight::getSize() : SynchronisableHeader::getSize() );
       }
@@ -201,5 +201,5 @@
     else
     {
-//       COUT(4) << "updating object of classid " << objectheader.getClassID() << endl;
+//       orxout(verbose, context::packets) << "updating object of classid " << objectheader.getClassID() << endl;
       OrxVerify(s->updateData(mem, mode), "ERROR: could not update Synchronisable with Gamestate data");
     }
@@ -219,7 +219,7 @@
         if (it->objectMode_ != 0x0)
         {
-          COUT(0) << "Found object with OBJECTID_UNKNOWN on the client with objectMode != 0x0!" << std::endl;
-          COUT(0) << "Possible reason for this error: Client created a synchronized object without the Server's approval." << std::endl;
-          COUT(0) << "Objects class: " << it->getIdentifier()->getName() << std::endl;
+          orxout(user_error, context::packets) << "Found object with OBJECTID_UNKNOWN on the client with objectMode != 0x0!" << endl;
+          orxout(user_error, context::packets) << "Possible reason for this error: Client created a synchronized object without the Server's approval." << endl;
+          orxout(user_error, context::packets) << "Objects class: " << it->getIdentifier()->getName() << endl;
           assert(false);
         }
@@ -232,7 +232,7 @@
           if (it->getObjectID() == *it2)
           {
-            COUT(0) << "Found duplicate objectIDs on the client!" << std::endl
-                    << "Are you sure you don't create a Sychnronisable objcect with 'new' \
-                        that doesn't have objectMode = 0x0?" << std::endl;
+            orxout(user_error, context::packets) << "Found duplicate objectIDs on the client!" << endl
+                                                 << "Are you sure you don't create a Sychnronisable objcect with 'new' \
+                                                     that doesn't have objectMode = 0x0?" << endl;
             assert(false);
           }
@@ -293,8 +293,8 @@
   switch ( retval )
   {
-    case Z_OK: COUT(5) << "G.St.Man: compress: successfully compressed" << std::endl; break;
-    case Z_MEM_ERROR: COUT(1) << "G.St.Man: compress: not enough memory available in gamestate.compress" << std::endl; return false;
-    case Z_BUF_ERROR: COUT(2) << "G.St.Man: compress: not enough memory available in the buffer in gamestate.compress" << std::endl; return false;
-    case Z_DATA_ERROR: COUT(2) << "G.St.Man: compress: data corrupted in gamestate.compress" << std::endl; return false;
+    case Z_OK: orxout(verbose_more, context::packets) << "G.St.Man: compress: successfully compressed" << endl; break;
+    case Z_MEM_ERROR: orxout(internal_error, context::packets) << "G.St.Man: compress: not enough memory available in gamestate.compress" << endl; return false;
+    case Z_BUF_ERROR: orxout(internal_warning, context::packets) << "G.St.Man: compress: not enough memory available in the buffer in gamestate.compress" << endl; return false;
+    case Z_DATA_ERROR: orxout(internal_warning, context::packets) << "G.St.Man: compress: data corrupted in gamestate.compress" << endl; return false;
   }
 
@@ -310,5 +310,5 @@
   header_.setCompSize( buffer );
   header_.setCompressed( true );
-  COUT(4) << "gamestate compress datasize: " << header_.getDataSize() << " compsize: " << header_.getCompSize() << std::endl;
+  orxout(verbose, context::packets) << "gamestate compress datasize: " << header_.getDataSize() << " compsize: " << header_.getCompSize() << endl;
   return true;
 }
@@ -319,5 +319,5 @@
   assert(data_);
   assert(header_.isCompressed());
-  COUT(4) << "GameStateClient: uncompressing gamestate. id: " << header_.getID() << ", baseid: " << header_.getBaseID() << ", datasize: " << header_.getDataSize() << ", compsize: " << header_.getCompSize() << std::endl;
+  orxout(verbose, context::packets) << "GameStateClient: uncompressing gamestate. id: " << header_.getID() << ", baseid: " << header_.getBaseID() << ", datasize: " << header_.getDataSize() << ", compsize: " << header_.getCompSize() << endl;
   uint32_t datasize = header_.getDataSize();
   uint32_t compsize = header_.getCompSize();
@@ -333,8 +333,8 @@
   switch ( retval )
   {
-    case Z_OK: COUT(5) << "successfully decompressed" << std::endl; break;
-    case Z_MEM_ERROR: COUT(1) << "not enough memory available" << std::endl; return false;
-    case Z_BUF_ERROR: COUT(2) << "not enough memory available in the buffer" << std::endl; return false;
-    case Z_DATA_ERROR: COUT(2) << "data corrupted (zlib)" << std::endl; return false;
+    case Z_OK: orxout(verbose_more, context::packets) << "successfully decompressed" << endl; break;
+    case Z_MEM_ERROR: orxout(internal_error, context::packets) << "not enough memory available" << endl; return false;
+    case Z_BUF_ERROR: orxout(internal_warning, context::packets) << "not enough memory available in the buffer" << endl; return false;
+    case Z_DATA_ERROR: orxout(internal_warning, context::packets) << "data corrupted (zlib)" << endl; return false;
   }
 
@@ -375,5 +375,5 @@
   if( memcmp( origDataPtr+objectOffset, baseDataPtr+objectOffset, objectHeader.getDataSize()) == 0 )
   {
-//     COUT(4) << "skip object " << Synchronisable::getSynchronisable(objectHeader.getObjectID())->getIdentifier()->getName() << endl;
+//     orxout(verbose, context::packets) << "skip object " << Synchronisable::getSynchronisable(objectHeader.getObjectID())->getIdentifier()->getName() << endl;
     origDataPtr += objectOffset + objectHeader.getDataSize(); // skip the whole object
     baseDataPtr += objectOffset + objectHeader.getDataSize();
@@ -431,5 +431,5 @@
 inline void /*Gamestate::*/copyObject( uint8_t*& newData, uint8_t*& origData, uint8_t*& baseData, SynchronisableHeader& objectHeader, std::vector<uint32_t>::iterator& sizes )
 {
-  //       COUT(4) << "docopy" << endl;
+  //       orxout(verbose, context::packets) << "docopy" << endl;
   // Just copy over the whole Object
   memcpy( newData, origData, objectHeader.getDataSize()+SynchronisableHeader::getSize() );
@@ -440,13 +440,13 @@
 //   SynchronisableHeader baseHeader( baseData );
 //   baseData += baseHeader.getDataSize()+SynchronisableHeader::getSize();
-  //       COUT(4) << "copy " << h.getObjectID() << endl;
-  //       COUT(4) << "copy " << h.getObjectID() << ":";
+  //       orxout(verbose, context::packets) << "copy " << h.getObjectID() << endl;
+  //       orxout(verbose, context::packets) << "copy " << h.getObjectID() << ":";
   sizes += Synchronisable::getSynchronisable(objectHeader.getObjectID())->getNrOfVariables();
 //   for( unsigned int i = 0; i < Synchronisable::getSynchronisable(objectHeader.getObjectID())->getNrOfVariables(); ++i )
 //   {
-//     //         COUT(4) << " " << *sizes;
+//     //         orxout(verbose, context::packets) << " " << *sizes;
 //     ++sizes;
 //   }
-    //       COUT(4) << endl;
+    //       orxout(verbose, context::packets) << endl;
 }
 
@@ -541,5 +541,5 @@
       if( SynchronisableHeader(baseDataPtr).getDataSize()==origHeader.getDataSize() )
       {
-//         COUT(4) << "diffing object in order: " << Synchronisable::getSynchronisable(origHeader.getObjectID())->getIdentifier()->getName() << endl;
+//         orxout(verbose, context::packets) << "diffing object in order: " << Synchronisable::getSynchronisable(origHeader.getObjectID())->getIdentifier()->getName() << endl;
         diffObject(destDataPtr, origDataPtr, baseDataPtr, origHeader, sizesIt);
         diffedObject = true;
@@ -547,5 +547,5 @@
       else
       {
-//         COUT(4) << "copy object because of different data sizes (1): " << Synchronisable::getSynchronisable(origHeader.getObjectID())->getIdentifier()->getName() << endl;
+//         orxout(verbose, context::packets) << "copy object because of different data sizes (1): " << Synchronisable::getSynchronisable(origHeader.getObjectID())->getIdentifier()->getName() << endl;
         copyObject(destDataPtr, origDataPtr, baseDataPtr, origHeader, sizesIt);
         assert(sizesIt != this->sizes_.end() || origDataPtr==origDataEnd);
@@ -565,5 +565,5 @@
         if( SynchronisableHeader(baseDataPtr).getDataSize()==origHeader.getDataSize() )
         {
-//           COUT(4) << "diffing object out of order: " << Synchronisable::getSynchronisable(origHeader.getObjectID())->getIdentifier()->getName() << endl;
+//           orxout(verbose, context::packets) << "diffing object out of order: " << Synchronisable::getSynchronisable(origHeader.getObjectID())->getIdentifier()->getName() << endl;
           diffObject(destDataPtr, origDataPtr, baseDataPtr, origHeader, sizesIt);
           diffedObject = true;
@@ -571,5 +571,5 @@
         else
         {
-//           COUT(4) << "copy object because of different data sizes (2): " << Synchronisable::getSynchronisable(origHeader.getObjectID())->getIdentifier()->getName() << endl;
+//           orxout(verbose, context::packets) << "copy object because of different data sizes (2): " << Synchronisable::getSynchronisable(origHeader.getObjectID())->getIdentifier()->getName() << endl;
           copyObject(destDataPtr, origDataPtr, baseDataPtr, origHeader, sizesIt);
           assert(sizesIt != this->sizes_.end() || origDataPtr==origDataEnd);
@@ -578,5 +578,5 @@
       else
       {
-//         COUT(4) << "copy object: " << Synchronisable::getSynchronisable(origHeader.getObjectID())->getIdentifier()->getName() << endl;
+//         orxout(verbose, context::packets) << "copy object: " << Synchronisable::getSynchronisable(origHeader.getObjectID())->getIdentifier()->getName() << endl;
         assert(baseDataPtr == oldBaseDataPtr);
         copyObject(destDataPtr, origDataPtr, baseDataPtr, origHeader, sizesIt);
@@ -718,8 +718,8 @@
   //copy in the zeros
 //   std::list<obj>::iterator itt;
-//   COUT(0) << "myvector contains:";
+//   orxout() << "myvector contains:";
 //   for ( itt=dataVector_.begin() ; itt!=dataVector_.end(); itt++ )
-//     COUT(0) << " " << (*itt).objID;
-//   COUT(0) << endl;
+//     orxout() << " " << (*itt).objID;
+//   orxout() << endl;
   for(it=dataVector_.begin(); it!=dataVector_.end();){
     SynchronisableHeader oldobjectheader(origdata);
@@ -771,5 +771,5 @@
     nrOfVariables += it->getNrOfVariables();
   }
-//   COUT(0) << "allocating " << nrOfVariables << " ints" << endl;
+//   orxout() << "allocating " << nrOfVariables << " ints" << endl;
   this->sizes_.reserve(nrOfVariables);
   return size;
Index: code/trunk/src/libraries/network/packet/Packet.cc
===================================================================
--- code/trunk/src/libraries/network/packet/Packet.cc	(revision 8729)
+++ code/trunk/src/libraries/network/packet/Packet.cc	(revision 8858)
@@ -37,5 +37,5 @@
 #include <boost/thread/mutex.hpp>
 
-#include "util/Debug.h"
+#include "util/Output.h"
 #include "Acknowledgement.h"
 #include "Chat.h"
@@ -192,37 +192,37 @@
 //     peerID = NETWORK_PEER_ID_SERVER;
   Packet *p = 0;
-//   COUT(6) << "packet type: " << *(Type::Value *)&data[_PACKETID] << std::endl;
+//   orxout(verbose_ultra, context::packets) << "packet type: " << *(Type::Value *)&data[_PACKETID] << endl;
   switch( *(Type::Value *)(data + _PACKETID) )
   {
     case Type::Acknowledgement:
-//       COUT(5) << "ack" << std::endl;
+//       orxout(verbose_more, context::packets) << "ack" << endl;
     p = new Acknowledgement( data, peerID );
       break;
     case Type::Chat:
-//       COUT(5) << "chat" << std::endl;
+//       orxout(verbose_more, context::packets) << "chat" << endl;
       p = new Chat( data, peerID );
       break;
     case Type::ClassID:
-//       COUT(5) << "classid" << std::endl;
+//       orxout(verbose_more, context::packets) << "classid" << endl;
       p = new ClassID( data, peerID );
       break;
     case Type::Gamestate:
-//       COUT(5) << "gamestate" << std::endl;
+//       orxout(verbose_more, context::packets) << "gamestate" << endl;
       p = new Gamestate( data, peerID );
       break;
     case Type::Welcome:
-//       COUT(5) << "welcome" << std::endl;
+//       orxout(verbose_more, context::packets) << "welcome" << endl;
       p = new Welcome( data, peerID );
       break;
     case Type::DeleteObjects:
-//       COUT(5) << "deleteobjects" << std::endl;
+//       orxout(verbose_more, context::packets) << "deleteobjects" << endl;
       p = new DeleteObjects( data, peerID );
       break;
     case Type::FunctionCalls:
-//       COUT(5) << "functionCalls" << std::endl;
+//       orxout(verbose_more, context::packets) << "functionCalls" << endl;
       p = new FunctionCalls( data, peerID );
       break;
     case Type::FunctionIDs:
-//       COUT(5) << "functionIDs" << std::endl;
+//       orxout(verbose_more, context::packets) << "functionIDs" << endl;
       p = new FunctionIDs( data, peerID );
       break;
@@ -255,5 +255,5 @@
   packetMap_.erase(it);
   Packet::packetMapMutex_.unlock();
-//   COUT(6) << "PacketMap size: " << packetMap_.size() << std::endl;
+//   orxout(verbose_ultra, context::packets) << "PacketMap size: " << packetMap_.size() << endl;
 }
 
Index: code/trunk/src/libraries/network/packet/Welcome.cc
===================================================================
--- code/trunk/src/libraries/network/packet/Welcome.cc	(revision 8729)
+++ code/trunk/src/libraries/network/packet/Welcome.cc	(revision 8858)
@@ -32,5 +32,5 @@
 
 #include <cassert>
-#include "util/Debug.h"
+#include "util/Output.h"
 #include "network/Host.h"
 #include "network/synchronisable/Synchronisable.h"
@@ -78,5 +78,5 @@
   assert(*(uint32_t *)(data_ + _ENDIANTEST ) == 0xFEDC4321);
   host->setClientID(clientID);
-  COUT(3) << "Welcome set clientId: " << clientID << endl;
+  orxout(internal_info, context::packets) << "Welcome set clientId: " << clientID << endl;
   Synchronisable::setClient(true);
   delete this;
Index: code/trunk/src/libraries/network/synchronisable/Synchronisable.cc
===================================================================
--- code/trunk/src/libraries/network/synchronisable/Synchronisable.cc	(revision 8729)
+++ code/trunk/src/libraries/network/synchronisable/Synchronisable.cc	(revision 8858)
@@ -130,5 +130,5 @@
 //     assert( !header.isDiffed() );
 
-    COUT(4) << "fabricating object with id: " << header.getObjectID() << std::endl;
+    orxout(verbose, context::network) << "fabricating object with id: " << header.getObjectID() << endl;
 
     Identifier* id = ClassByID(header.getClassID());
@@ -136,7 +136,7 @@
     {
         for(int i = 0; i<160; i++)
-            COUT(0) << "classid: " << i << " identifier: " << ClassByID(i) << endl;
-        COUT(0) << "Assertion failed: id" << std::endl;
-        COUT(0) << "Possible reason for this error: Client received a synchronizable object whose class has no factory." << std::endl;
+            orxout(user_error, context::network) << "classid: " << i << " identifier: " << ClassByID(i) << endl;
+        orxout(user_error, context::network) << "Assertion failed: id" << endl;
+        orxout(user_error, context::network) << "Possible reason for this error: Client received a synchronizable object whose class has no factory." << endl;
         abort();
     }
@@ -168,5 +168,5 @@
       bo->setLevel(creator->getLevel());          // Note: this ensures that the level is known on the client for child objects of the scene (and the scene itself)
     //assert(no->classID_ == header.getClassID());
-    COUT(4) << "fabricate objectID_: " << no->objectID_ << " classID_: " << no->classID_ << std::endl;
+    orxout(verbose, context::network) << "fabricate objectID_: " << no->objectID_ << " classID_: " << no->classID_ << endl;
           // update data and create object/entity...
     bool b = no->updateData(mem, mode, true);
@@ -242,5 +242,5 @@
     uint8_t* oldmem = mem;
     if (this->classID_==0)
-      COUT(3) << "classid 0 " << this->getIdentifier()->getName() << std::endl;
+      orxout(internal_info, context::network) << "classid 0 " << this->getIdentifier()->getName() << endl;
 #endif
 
@@ -258,11 +258,11 @@
     // end copy header
 
-    CCOUT(5) << "getting data from objectID_: " << objectID_ << ", classID_: " << classID_ << std::endl;
-//     COUT(4) << "objectid: " << this->objectID_ << ":";
+    orxout(verbose_more, context::network) << "getting data from objectID_: " << objectID_ << ", classID_: " << classID_ << endl;
+//     orxout(verbose, context::network) << "objectid: " << this->objectID_ << ":";
     // copy to location
     for(i=syncList_.begin(); i!=syncList_.end(); ++i)
     {
       uint32_t varsize = (*i)->getData( mem, mode );
-//       COUT(4) << " " << varsize;
+//       orxout(verbose, context::network) << " " << varsize;
       tempsize += varsize;
       sizes.push_back(varsize);
@@ -271,5 +271,5 @@
     }
     assert(tempsize!=0);  // if this happens an empty object (with no variables) would be transmitted
-//     COUT(4) << endl;
+//     orxout(verbose, context::network) << endl;
 
     header.setObjectID( this->objectID_ );
@@ -305,6 +305,6 @@
     if(syncList_.empty())
     {
+      orxout(internal_warning, context::network) << "Synchronisable::updateData syncList_ is empty" << endl;
       assert(0);
-      COUT(2) << "Synchronisable::updateData syncList_ is empty" << std::endl;
       return false;
     }
@@ -326,5 +326,5 @@
     }
 
-    //COUT(5) << "Synchronisable: objectID_ " << syncHeader.getObjectID() << ", classID_ " << syncHeader.getClassID() << " size: " << syncHeader.getDataSize() << " synchronising data" << std::endl;
+    //orxout(verbose_more, context::network) << "Synchronisable: objectID_ " << syncHeader.getObjectID() << ", classID_ " << syncHeader.getClassID() << " size: " << syncHeader.getDataSize() << " synchronising data" << endl;
     if( !syncHeaderLight.isDiffed() )
     {
@@ -344,9 +344,9 @@
     {
       mem += SynchronisableHeaderLight::getSize();
-//       COUT(0) << "objectID: " << this->objectID_ << endl;
+//       orxout(debug_output, context::network) << "objectID: " << this->objectID_ << endl;
       while( mem < data+syncHeaderLight.getDataSize()+SynchronisableHeaderLight::getSize() )
       {
         VariableID varID = *(VariableID*)mem;
-//         COUT(0) << "varID: " << varID << endl;
+//         orxout(debug_output, context::network) << "varID: " << varID << endl;
         assert( varID < syncList_.size() );
         mem += sizeof(VariableID);
Index: code/trunk/src/libraries/network/synchronisable/Synchronisable.h
===================================================================
--- code/trunk/src/libraries/network/synchronisable/Synchronisable.h	(revision 8729)
+++ code/trunk/src/libraries/network/synchronisable/Synchronisable.h	(revision 8858)
@@ -232,5 +232,5 @@
         it++;
     }
-    COUT(1) << "Tried to unregister not registered variable" << endl;
+    orxout(internal_error, context::network) << "Tried to unregister not registered variable" << endl;
     assert(false); //if we reach this point something went wrong:
     // the variable has not been registered before
Index: code/trunk/src/libraries/network/synchronisable/SynchronisableVariable.h
===================================================================
--- code/trunk/src/libraries/network/synchronisable/SynchronisableVariable.h	(revision 8729)
+++ code/trunk/src/libraries/network/synchronisable/SynchronisableVariable.h	(revision 8858)
@@ -202,5 +202,5 @@
         if ( *static_cast<uint8_t*>(mem) != this->varReference_ )
         { // wrong reference number, so discard the data
-//           COUT(0) << "discharding data" << endl;
+//           orxout(debug_output, context::network) << "discharding data" << endl;
           mem += getSize( mode ); // SynchronisableVariableBidirectional::getSize returns size of variable + reference
           return;
