Index: code/trunk/src/libraries/network/Host.cc
===================================================================
--- code/trunk/src/libraries/network/Host.cc	(revision 8408)
+++ 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
