[Orxonox-commit 4158] r8829 - in code/branches/output/src: libraries/network libraries/network/packet modules/gametypes modules/overlays/hud orxonox orxonox/chat orxonox/gametypes

landauf at orxonox.net landauf at orxonox.net
Sun Aug 7 15:11:16 CEST 2011


Author: landauf
Date: 2011-08-07 15:11:16 +0200 (Sun, 07 Aug 2011)
New Revision: 8829

Added:
   code/branches/output/src/libraries/network/NetworkChatListener.h
   code/branches/output/src/orxonox/chat/ChatListener.h
   code/branches/output/src/orxonox/chat/ChatManager.cc
   code/branches/output/src/orxonox/chat/ChatManager.h
Removed:
   code/branches/output/src/libraries/network/ChatListener.cc
   code/branches/output/src/libraries/network/ChatListener.h
Modified:
   code/branches/output/src/libraries/network/CMakeLists.txt
   code/branches/output/src/libraries/network/Client.cc
   code/branches/output/src/libraries/network/Client.h
   code/branches/output/src/libraries/network/Host.cc
   code/branches/output/src/libraries/network/Host.h
   code/branches/output/src/libraries/network/NetworkPrereqs.h
   code/branches/output/src/libraries/network/Server.cc
   code/branches/output/src/libraries/network/Server.h
   code/branches/output/src/libraries/network/packet/Chat.cc
   code/branches/output/src/libraries/network/packet/Chat.h
   code/branches/output/src/modules/gametypes/RaceCheckPoint.cc
   code/branches/output/src/modules/gametypes/SpaceRace.cc
   code/branches/output/src/modules/overlays/hud/ChatOverlay.cc
   code/branches/output/src/modules/overlays/hud/ChatOverlay.h
   code/branches/output/src/orxonox/OrxonoxPrereqs.h
   code/branches/output/src/orxonox/chat/CMakeLists.txt
   code/branches/output/src/orxonox/chat/ChatHistory.cc
   code/branches/output/src/orxonox/chat/ChatHistory.h
   code/branches/output/src/orxonox/chat/ChatInputHandler.cc
   code/branches/output/src/orxonox/chat/ChatInputHandler.h
   code/branches/output/src/orxonox/gametypes/Asteroids.cc
   code/branches/output/src/orxonox/gametypes/Deathmatch.cc
   code/branches/output/src/orxonox/gametypes/Dynamicmatch.cc
   code/branches/output/src/orxonox/gametypes/LastManStanding.cc
   code/branches/output/src/orxonox/gametypes/LastTeamStanding.cc
   code/branches/output/src/orxonox/gametypes/UnderAttack.cc
Log:
enhanced chat system. chat related code is now separated into network-side code (located in Host, Client, Server) and client-side code (located in ChatManager).
note that there are now two chat related listeners: NetworkChatListener, which is used to send chat from the network to ChatManager, and ChatListener, which is used to send online and offline chat from ChatManager to the actual chat interfaces (ChatOverlay, ChatInputHandler, ...).
the "chat" console command now supports a second argument which is the clientID of the receiver. this allows private messages (or gameplay messages directed to only one specific player).

Modified: code/branches/output/src/libraries/network/CMakeLists.txt
===================================================================
--- code/branches/output/src/libraries/network/CMakeLists.txt	2011-08-06 16:33:55 UTC (rev 8828)
+++ code/branches/output/src/libraries/network/CMakeLists.txt	2011-08-07 13:11:16 UTC (rev 8829)
@@ -18,7 +18,6 @@
  #
 
 SET_SOURCE_FILES(NETWORK_SRC_FILES
-  ChatListener.cc
   Client.cc
   ClientConnection.cc
   ClientConnectionListener.cc
@@ -44,7 +43,6 @@
 )
 
 SET_SOURCE_FILES(NETWORK_HDR_FILES
-  ChatListener.h
   Client.h
   ClientConnection.h
   ClientConnectionListener.h
@@ -60,6 +58,7 @@
   WANDiscoverable.h
   WANDiscovery.h
   MasterServerComm.h
+  NetworkChatListener.h
   NetworkFunction.h
   NetworkPrecompiledHeaders.h
   NetworkPrereqs.h

Deleted: code/branches/output/src/libraries/network/ChatListener.cc
===================================================================
--- code/branches/output/src/libraries/network/ChatListener.cc	2011-08-06 16:33:55 UTC (rev 8828)
+++ code/branches/output/src/libraries/network/ChatListener.cc	2011-08-07 13:11:16 UTC (rev 8829)
@@ -1,50 +0,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 )
-    //{
-      //orxout(message) << "Chat: \"" << message << "\"" << endl;
-
-
-    //}
-
-
-}
-
-

Deleted: code/branches/output/src/libraries/network/ChatListener.h
===================================================================
--- code/branches/output/src/libraries/network/ChatListener.h	2011-08-06 16:33:55 UTC (rev 8828)
+++ code/branches/output/src/libraries/network/ChatListener.h	2011-08-07 13:11:16 UTC (rev 8829)
@@ -1,49 +0,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__ */

Modified: code/branches/output/src/libraries/network/Client.cc
===================================================================
--- code/branches/output/src/libraries/network/Client.cc	2011-08-06 16:33:55 UTC (rev 8828)
+++ code/branches/output/src/libraries/network/Client.cc	2011-08-07 13:11:16 UTC (rev 8829)
@@ -115,28 +115,32 @@
     ClientConnection::addPacket(packet, channelID);
   }
 
-  bool Client::processChat(const std::string& message, unsigned int playerID)
-  {
-//    orxout(message) << "Player " << playerID << ": " << message << endl;
-    return true;
-  }
-
   void Client::printRTT()
   {
     orxout(message) << "Round trip time to server is " << ClientConnection::getRTT() << " ms" << endl;
   }
 
   /**
-   * This function implements the method of sending a chat message to the server
+   * @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)
+  void Client::doSendChat(const std::string& message, unsigned int sourceID, unsigned int targetID)
   {
-    packet::Chat *m = new packet::Chat(message, Host::getPlayerID());
-    return m->send(static_cast<Host*>(this));
+    // 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);
+  }
 
   /**
    * Processes incoming packets, sends a gamestate to the server and does the cleanup
@@ -202,7 +206,7 @@
     Game::getInstance().popState();
     Game::getInstance().popState();
   }
-  
+
   void Client::processPacket(packet::Packet* packet)
   {
     if( packet->isReliable() )
@@ -215,8 +219,4 @@
     else
       packet->process(static_cast<Host*>(this));
   }
-
-
-
-
 }

Modified: code/branches/output/src/libraries/network/Client.h
===================================================================
--- code/branches/output/src/libraries/network/Client.h	2011-08-06 16:33:55 UTC (rev 8828)
+++ code/branches/output/src/libraries/network/Client.h	2011-08-07 13:11:16 UTC (rev 8829)
@@ -72,7 +72,7 @@
   public:
     Client();
     ~Client();
-    
+
     static Client* getInstance(){ return singletonPtr_s; } // tolua_export
 
     bool establishConnection();
@@ -80,9 +80,8 @@
     bool closeConnection();
     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();
 
     void update(const Clock& time);

Modified: code/branches/output/src/libraries/network/Host.cc
===================================================================
--- code/branches/output/src/libraries/network/Host.cc	2011-08-06 16:33:55 UTC (rev 8828)
+++ code/branches/output/src/libraries/network/Host.cc	2011-08-07 13:11:16 UTC (rev 8829)
@@ -31,16 +31,16 @@
 #include <cassert>
 #include <string>
 
+#include "core/CoreIncludes.h"
 #include "core/ObjectList.h"
 #include "core/command/ConsoleCommand.h"
-#include "ChatListener.h"
+#include "NetworkChatListener.h"
 
 namespace orxonox {
 
   static const std::string __CC_printRTT_group = "Stats";
   static const std::string __CC_printRTT_name = "printRTT";
 
-  SetConsoleCommand("chat", &Host::Chat);
   SetConsoleCommand(__CC_printRTT_group, __CC_printRTT_name, &Host::printRTT);
 
   // Host*               Host::instance_=0;
@@ -88,57 +88,29 @@
     }
   }
 
-  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)
   {
-    for (ObjectList<ChatListener>::iterator it = ObjectList<ChatListener>::begin(); it != ObjectList<ChatListener>::end(); ++it)
-      it->incomingChat(message, 0);
-
-    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;
+        (*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)
   {
-    for (ObjectList<ChatListener>::iterator it = ObjectList<ChatListener>::begin(); it != ObjectList<ChatListener>::end(); ++it)
-      it->incomingChat(message, NETWORK_PEER_ID_BROADCAST);
-
-    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()
   {
     for (std::vector<Host*>::iterator it=instances_s.begin(); it!=instances_s.end(); ++it )
@@ -166,4 +138,13 @@
   }
 
 
+  //////////////////////////////////////////////////////////////////////////
+  // NetworkChatListener                                                  //
+  //////////////////////////////////////////////////////////////////////////
+
+  NetworkChatListener::NetworkChatListener()
+  {
+      RegisterRootObject(NetworkChatListener);
+  }
+
 }//namespace orxonox

Modified: code/branches/output/src/libraries/network/Host.h
===================================================================
--- code/branches/output/src/libraries/network/Host.h	2011-08-06 16:33:55 UTC (rev 8828)
+++ code/branches/output/src/libraries/network/Host.h	2011-08-07 13:11:16 UTC (rev 8829)
@@ -51,36 +51,28 @@
 */
 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:
     Host();
     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:
     static Host* getActiveInstance();
     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_; }
   private:

Added: code/branches/output/src/libraries/network/NetworkChatListener.h
===================================================================
--- code/branches/output/src/libraries/network/NetworkChatListener.h	                        (rev 0)
+++ code/branches/output/src/libraries/network/NetworkChatListener.h	2011-08-07 13:11:16 UTC (rev 8829)
@@ -0,0 +1,61 @@
+/*
+ *   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"
+
+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__ */


Property changes on: code/branches/output/src/libraries/network/NetworkChatListener.h
___________________________________________________________________
Added: svn:eol-style
   + native

Modified: code/branches/output/src/libraries/network/NetworkPrereqs.h
===================================================================
--- code/branches/output/src/libraries/network/NetworkPrereqs.h	2011-08-06 16:33:55 UTC (rev 8828)
+++ code/branches/output/src/libraries/network/NetworkPrereqs.h	2011-08-07 13:11:16 UTC (rev 8829)
@@ -117,7 +117,6 @@
 
 namespace orxonox
 {
-  class ChatListener;
   class Client;
   class ClientConnection;
   class ClientConnectionListener;
@@ -129,6 +128,7 @@
   class GamestateHandler;
   class GamestateManager;
   class Host;
+  class NetworkChatListener;
   class NetworkFunctionBase;
   struct NetworkFunctionPointer;
   class NetworkFunctionStatic;

Modified: code/branches/output/src/libraries/network/Server.cc
===================================================================
--- code/branches/output/src/libraries/network/Server.cc	2011-08-06 16:33:55 UTC (rev 8828)
+++ code/branches/output/src/libraries/network/Server.cc	2011-08-07 13:11:16 UTC (rev 8829)
@@ -55,7 +55,6 @@
 #include "packet/FunctionIDs.h"
 #include "packet/Gamestate.h"
 #include "packet/Welcome.h"
-#include "ChatListener.h"
 // #include "ClientInformation.h"
 #include "FunctionCallManager.h"
 #include "GamestateManager.h"
@@ -103,7 +102,7 @@
   /** helper that connects to the master server */
   void Server::helper_ConnectToMasterserver()
   {
-//     WANDiscovery::getInstance().msc.sendRequest( MSPROTO_GAME_SERVER " " 
+//     WANDiscovery::getInstance().msc.sendRequest( MSPROTO_GAME_SERVER " "
 //       MSPROTO_REGISTER_SERVER );
   }
 
@@ -115,14 +114,14 @@
     Host::setActive(true);
     orxout(verbose, context::network) << "opening server" << endl;
     this->openListener();
-    
+
     /* make discoverable on LAN */
     LANDiscoverable::setActivity(true);
 
     /* make discoverable on WAN */
     WANDiscoverable::setActivity(true);
     /* TODO this needs to be optional, we need a switch from the UI to
-     * enable/disable this 
+     * enable/disable this
      */
 //     helper_ConnectToMasterserver();
 
@@ -142,38 +141,22 @@
 
     /* tell master server we're closing */
     orxout(internal_info, context::network) << "disconnecting." << endl;
-    WANDiscoverable::setActivity(false);    
+    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) );
-//         orxout(internal_warning, context::network) << "could not send Chat message to client ID: " << temp->getID() << endl;
-//       temp = temp->next();
-//     }
-//    orxout(message) << "Player " << playerID << ": " << message << endl;
-    return true;
-  }
-
-
   /* handle incoming data */
   int rephandler( char *addr, ENetEvent *ev )
-  { 
+  {
     /* reply to pings */
-    if( !strncmp( (char *)ev->packet->data, MSPROTO_PING_GAMESERVER, 
+    if( !strncmp( (char *)ev->packet->data, MSPROTO_PING_GAMESERVER,
       MSPROTO_PING_GAMESERVER_LEN ) )
       //this->msc.sendRequest( MSPROTO_ACK );
       /* NOTE implement this after pollForReply
-       * reimplementation 
+       * reimplementation
        */
       return 0;
 
@@ -182,8 +165,8 @@
   }
 
   void Server::helper_HandleMasterServerRequests()
-  { 
-    /* poll the master server for replies and see whether something 
+  {
+    /* poll the master server for replies and see whether something
      * has to be done or changed.
      */
     //WANDiscovery::getInstance().msc.pollForReply( rhandler, 10 );
@@ -201,7 +184,7 @@
 
     // receive and process incoming discovery packets
     LANDiscoverable::update();
-    
+
     // receive and process requests from master server
     /* todo */
     //helper_HandleMasterServerRequests();
@@ -329,7 +312,7 @@
   void Server::addPeer(uint32_t peerID)
   {
 //     static unsigned int newid=1;
-// 
+//
 //     orxout(internal_info, context::network) << "Server: adding client" << endl;
 //     ClientInformation *temp = ClientInformation::insertBack(new ClientInformation);
 //     if(!temp)
@@ -374,7 +357,7 @@
 //       delete client;
 //     }
   }
-  
+
   void Server::processPacket(packet::Packet* packet)
   {
     if( packet->isReliable() )
@@ -410,7 +393,7 @@
 
 //     temp->setSynched(true);
     GamestateManager::setSynched(clientID);
-    
+
     orxout(verbose, context::network) << "sending welcome" << endl;
     packet::Welcome *w = new packet::Welcome(clientID);
     w->setPeerID(clientID);
@@ -437,33 +420,52 @@
     // ClientConnectionListener::broadcastClientDisconnected(client->getID()); // this is done in ClientInformation now
   }
 
-  bool Server::chat(const std::string& message)
+  /**
+   * @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)
   {
-      return this->sendChat(message, Host::getPlayerID());
+    // 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);
   }
 
-  bool Server::broadcast(const std::string& message)
+  /**
+   * @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)
   {
-      return this->sendChat(message, NETWORK_PEER_ID_BROADCAST);
+      this->doSendChat(message, sourceID, targetID);
   }
 
-  bool Server::sendChat(const std::string& message, unsigned int clientID)
+  /**
+   * @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)
   {
-//     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) );
-//         orxout(internal_warning, context::network) << "could not send Chat message to client ID: " << temp->getID() << endl;
-//       temp = temp->next();
-    }
-//    orxout(message) << "Player " << Host::getPlayerID() << ": " << message << endl;
-    for (ObjectList<ChatListener>::iterator it = ObjectList<ChatListener>::begin(); it != ObjectList<ChatListener>::end(); ++it)
-      it->incomingChat(message, clientID);
+    if (targetID == NETWORK_PEER_ID_BROADCAST || targetID == NETWORK_PEER_ID_SERVER)
+      return true;
 
-    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;
   }
 
   void Server::syncClassid(unsigned int clientID)

Modified: code/branches/output/src/libraries/network/Server.h
===================================================================
--- code/branches/output/src/libraries/network/Server.h	2011-08-06 16:33:55 UTC (rev 8828)
+++ code/branches/output/src/libraries/network/Server.h	2011-08-07 13:11:16 UTC (rev 8829)
@@ -67,7 +67,6 @@
 
     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) ); }
     void update(const Clock& time);
@@ -88,9 +87,9 @@
     void disconnectClient( uint32_t clientID );
     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);
 
     float timeSinceLastUpdate_;

Modified: code/branches/output/src/libraries/network/packet/Chat.cc
===================================================================
--- code/branches/output/src/libraries/network/packet/Chat.cc	2011-08-06 16:33:55 UTC (rev 8828)
+++ code/branches/output/src/libraries/network/packet/Chat.cc	2011-08-07 13:11:16 UTC (rev 8829)
@@ -38,12 +38,13 @@
 #define   PACKET_FLAGS_CHAT PacketFlag::Reliable
 
 /* 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()
 {
   /* Add chat flag to packet flags */
@@ -56,7 +57,8 @@
   data_=new unsigned char[ getSize() ];
 
   *(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_;
 
   /* cast the hell out of the message string, and copy it into the
@@ -80,9 +82,9 @@
 }
 
 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;
 }
 
 unsigned char *Chat::getMessage(){

Modified: code/branches/output/src/libraries/network/packet/Chat.h
===================================================================
--- code/branches/output/src/libraries/network/packet/Chat.h	2011-08-06 16:33:55 UTC (rev 8828)
+++ code/branches/output/src/libraries/network/packet/Chat.h	2011-08-07 13:11:16 UTC (rev 8829)
@@ -41,7 +41,7 @@
 {
 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 );
 
   /* destructor */

Modified: code/branches/output/src/modules/gametypes/RaceCheckPoint.cc
===================================================================
--- code/branches/output/src/modules/gametypes/RaceCheckPoint.cc	2011-08-06 16:33:55 UTC (rev 8828)
+++ code/branches/output/src/modules/gametypes/RaceCheckPoint.cc	2011-08-07 13:11:16 UTC (rev 8829)
@@ -31,7 +31,7 @@
 #include "util/Convert.h"
 #include "core/CoreIncludes.h"
 #include "core/XMLPort.h"
-#include "network/Host.h"
+#include "chat/ChatManager.h"
 #include "SpaceRace.h"
 
 namespace orxonox
@@ -111,7 +111,7 @@
                 const std::string& message =  "You have " + multi_cast<std::string>(this->bTimeLimit_)
                             + " seconds to reach the check point " + multi_cast<std::string>(this->bCheckpointIndex_+1);
                 const_cast<GametypeInfo*>(gametype->getGametypeInfo())->sendAnnounceMessage(message);
-                Host::Broadcast(message);
+                ChatManager::message(message);
             }
         }
     }

Modified: code/branches/output/src/modules/gametypes/SpaceRace.cc
===================================================================
--- code/branches/output/src/modules/gametypes/SpaceRace.cc	2011-08-06 16:33:55 UTC (rev 8828)
+++ code/branches/output/src/modules/gametypes/SpaceRace.cc	2011-08-07 13:11:16 UTC (rev 8829)
@@ -29,9 +29,9 @@
 #include "SpaceRace.h"
 
 #include "core/CoreIncludes.h"
-#include "network/Host.h"
-#include <util/Clock.h>
-#include <util/Math.h>
+#include "chat/ChatManager.h"
+#include "util/Clock.h"
+#include "util/Math.h"
 #include "util/Convert.h"
 
 namespace orxonox
@@ -59,7 +59,7 @@
                         + "You didn't reach the check point " + multi_cast<std::string>(this->bCheckpointsReached_+1)
                         + " before the time limit. You lose!";
             const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
-            Host::Broadcast(message);
+            ChatManager::message(message);
         }
         else
         {
@@ -69,7 +69,7 @@
             const std::string& message = "You win!! You have reached the last check point after "+ multi_cast<std::string>(s)
                         + "." + multi_cast<std::string>(ms) + " seconds.";
             const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
-            Host::Broadcast(message);
+            ChatManager::message(message);
 /*
             float time = this->clock_.getSecondsPrecise();
             this->scores_.insert(time);
@@ -85,7 +85,7 @@
         Gametype::start();
 
         std::string message("The match has started! Reach the check points as quickly as possible!");
-        Host::Broadcast(message);
+        ChatManager::message(message);
     }
 
     void SpaceRace::newCheckpointReached()
@@ -98,7 +98,7 @@
                         + " reached after " + multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms)
                         + " seconds.";
         const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
-        Host::Broadcast(message);
+        ChatManager::message(message);
     }
 
 }

Modified: code/branches/output/src/modules/overlays/hud/ChatOverlay.cc
===================================================================
--- code/branches/output/src/modules/overlays/hud/ChatOverlay.cc	2011-08-06 16:33:55 UTC (rev 8828)
+++ code/branches/output/src/modules/overlays/hud/ChatOverlay.cc	2011-08-07 13:11:16 UTC (rev 8829)
@@ -66,19 +66,10 @@
         SetConfigValue(displayTime_, 6.0f);
     }
 
-    void ChatOverlay::incomingChat(const std::string& message, unsigned int senderID)
+    void ChatOverlay::incomingChat(const std::string& message, const std::string& /*name*/)
     {
-        std::string text = message;
+        this->messages_.push_back(multi_cast<Ogre::DisplayString>(message));
 
-        if (senderID != NETWORK_PEER_ID_UNKNOWN)
-        {
-            PlayerInfo* player = PlayerManager::getInstance().getClient(senderID);
-            if (player)
-                text = player->getName() + ": " + message;
-        }
-
-        this->messages_.push_back(multi_cast<Ogre::DisplayString>(text));
-
         Timer* timer = new Timer();
         this->timers_.insert(timer); // store the timer in a set to destroy it in the destructor
         const ExecutorPtr& executor = createExecutor(createFunctor(&ChatOverlay::dropMessage, this));

Modified: code/branches/output/src/modules/overlays/hud/ChatOverlay.h
===================================================================
--- code/branches/output/src/modules/overlays/hud/ChatOverlay.h	2011-08-06 16:33:55 UTC (rev 8828)
+++ code/branches/output/src/modules/overlays/hud/ChatOverlay.h	2011-08-07 13:11:16 UTC (rev 8829)
@@ -34,7 +34,7 @@
 #include <list>
 #include <OgreOverlayElement.h>
 
-#include "network/ChatListener.h"
+#include "chat/ChatListener.h"
 #include "overlays/OverlayText.h"
 
 namespace orxonox
@@ -48,7 +48,7 @@
             void setConfigValues();
 
         protected:
-            virtual void incomingChat(const std::string& message, unsigned int senderID);
+            virtual void incomingChat(const std::string& message, const std::string& name);
 
             std::list<Ogre::DisplayString> messages_;
 

Modified: code/branches/output/src/orxonox/OrxonoxPrereqs.h
===================================================================
--- code/branches/output/src/orxonox/OrxonoxPrereqs.h	2011-08-06 16:33:55 UTC (rev 8828)
+++ code/branches/output/src/orxonox/OrxonoxPrereqs.h	2011-08-07 13:11:16 UTC (rev 8829)
@@ -77,6 +77,12 @@
     class Radar;
     class Scene;
 
+    // chat
+    class ChatHistory;
+    class ChatInputHandler;
+    class ChatListener;
+    class ChatManager;
+
     // collisionshapes
     class CollisionShape;
     class CompoundCollisionShape;

Modified: code/branches/output/src/orxonox/chat/CMakeLists.txt
===================================================================
--- code/branches/output/src/orxonox/chat/CMakeLists.txt	2011-08-06 16:33:55 UTC (rev 8828)
+++ code/branches/output/src/orxonox/chat/CMakeLists.txt	2011-08-07 13:11:16 UTC (rev 8829)
@@ -1,4 +1,5 @@
 ADD_SOURCE_FILES(ORXONOX_SRC_FILES
   ChatHistory.cc
   ChatInputHandler.cc
+  ChatManager.cc
 )

Modified: code/branches/output/src/orxonox/chat/ChatHistory.cc
===================================================================
--- code/branches/output/src/orxonox/chat/ChatHistory.cc	2011-08-06 16:33:55 UTC (rev 8828)
+++ code/branches/output/src/orxonox/chat/ChatHistory.cc	2011-08-07 13:11:16 UTC (rev 8829)
@@ -73,27 +73,13 @@
   }
 
   /* react to incoming chat */
-  void ChatHistory::incomingChat(const std::string& message,
-    unsigned int senderID)
+  void ChatHistory::incomingChat(const std::string& message, const std::string& /*name*/)
   {
-    /* --> a) look up the actual name of the sender */
-    std::string text = message;
-
-#ifndef CHATTEST
-    /* get sender ID and prepend it to the message */
-    if (senderID != NETWORK_PEER_ID_UNKNOWN)
-    {
-      PlayerInfo* player = PlayerManager::getInstance().getClient(senderID);
-      if (player)
-        text = player->getName() + ": " + message;
-    }
-#endif
-
     /* add the line to the history */
-    this->chat_hist_addline( text );
+    this->chat_hist_addline( message );
 
     /* add the line to the log */
-    this->chat_hist_logline( text );
+    this->chat_hist_logline( message );
   }
 
   /* Synchronize logfile onto the hard drive */ /* MARK MARK */

Modified: code/branches/output/src/orxonox/chat/ChatHistory.h
===================================================================
--- code/branches/output/src/orxonox/chat/ChatHistory.h	2011-08-06 16:33:55 UTC (rev 8828)
+++ code/branches/output/src/orxonox/chat/ChatHistory.h	2011-08-07 13:11:16 UTC (rev 8829)
@@ -36,13 +36,14 @@
 //#define CHATTEST
 
 #ifndef CHATTEST
-#include <OrxonoxPrereqs.h>
-#include <PlayerManager.h>
-#include <infos/PlayerInfo.h>
-#include <core/BaseObject.h>
-#include <network/ChatListener.h>
-#include <core/PathConfig.h>
-#include <util/Singleton.h>
+#include "OrxonoxPrereqs.h"
+
+#include "util/Singleton.h"
+#include "core/BaseObject.h"
+#include "core/PathConfig.h"
+#include "chat/ChatListener.h"
+#include "infos/PlayerInfo.h"
+#include "PlayerManager.h"
 #endif
 
 #ifndef _ChatHistory_H__
@@ -81,8 +82,7 @@
        * \param message The incoming message
        * \param senderID Identification number of the sender
        */
-      virtual void incomingChat(const std::string& message,
-        unsigned int senderID);
+      virtual void incomingChat(const std::string& message, const std::string& name);
 
       /** Synchronize logfile onto the hard drive
        *

Modified: code/branches/output/src/orxonox/chat/ChatInputHandler.cc
===================================================================
--- code/branches/output/src/orxonox/chat/ChatInputHandler.cc	2011-08-06 16:33:55 UTC (rev 8828)
+++ code/branches/output/src/orxonox/chat/ChatInputHandler.cc	2011-08-07 13:11:16 UTC (rev 8829)
@@ -43,8 +43,8 @@
 #include "core/input/InputBuffer.h"
 #include "core/input/InputManager.h"
 #include "core/input/InputState.h"
-#include "network/Host.h"
 
+#include "chat/ChatManager.h"
 #include "PlayerManager.h"
 #include "infos/PlayerInfo.h"
 
@@ -212,26 +212,10 @@
   }
 
   /* handle incoming chat */
-  void ChatInputHandler::incomingChat(const std::string& message,
-    unsigned int senderID)
+  void ChatInputHandler::incomingChat(const std::string& message, const std::string& name)
   {
-    /* look up the actual name of the sender */
-    std::string text = message;
-    std::string name = "";
-
-    /* setup player name info */
-    if (senderID != NETWORK_PEER_ID_UNKNOWN)
-    {
-       PlayerInfo* player = PlayerManager::getInstance().getClient(senderID);
-       if (player)
-       {
-         name = player->getName();
-         text = name + ": " + message;
-       }
-    }
-
     /* create item */
-    CEGUI::ListboxTextItem *toadd = new CEGUI::ListboxTextItem( text );
+    CEGUI::ListboxTextItem *toadd = new CEGUI::ListboxTextItem( message );
 
     /* setup colors */
     if (name != "")
@@ -319,7 +303,7 @@
       this->inpbuf->clear();
 
     /* c) send the chat via some call */
-    Host::Chat( msgtosend );
+    ChatManager::chat( msgtosend );
 
     /* d) stop listening to input - only if this is not fullchat */
     if( !this->fullchat )

Modified: code/branches/output/src/orxonox/chat/ChatInputHandler.h
===================================================================
--- code/branches/output/src/orxonox/chat/ChatInputHandler.h	2011-08-06 16:33:55 UTC (rev 8828)
+++ code/branches/output/src/orxonox/chat/ChatInputHandler.h	2011-08-07 13:11:16 UTC (rev 8829)
@@ -29,14 +29,14 @@
 #ifndef _ChatInputHandler_H__
 #define _ChatInputHandler_H__
 
-#include <OrxonoxPrereqs.h>
+#include "OrxonoxPrereqs.h"
 
 #include <string>
 #include <CEGUIForwardRefs.h>
 #include <CEGUIcolour.h>
 
 #include "util/Singleton.h"
-#include "network/ChatListener.h"
+#include "chat/ChatListener.h"
 
 namespace orxonox // tolua_export
 { // tolua_export
@@ -111,8 +111,7 @@
        * Deal with incoming chat (which means in our case: Add it to the
        * history window of the full chat window)
        */
-      void incomingChat( const std::string& message,
-        unsigned int senderID );
+      void incomingChat(const std::string& message, const std::string& name);
 
       /** \param full true means show full chat window with history,
             false means show only an input line

Added: code/branches/output/src/orxonox/chat/ChatListener.h
===================================================================
--- code/branches/output/src/orxonox/chat/ChatListener.h	                        (rev 0)
+++ code/branches/output/src/orxonox/chat/ChatListener.h	2011-08-07 13:11:16 UTC (rev 8829)
@@ -0,0 +1,58 @@
+/*
+ *   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 _ChatListener_H__
+#define _ChatListener_H__
+
+#include "OrxonoxPrereqs.h"
+
+namespace orxonox
+{
+    /**
+        @brief Classes inheriting from this interface get a notification whenever a chat
+        message was sent through ChatManager.
+    */
+    class _OrxonoxExport ChatListener : virtual public OrxonoxClass
+    {
+        friend class ChatManager;
+
+        public:
+            ChatListener(); // implemented in ChatManager.cc
+            virtual ~ChatListener() {}
+
+        protected:
+            /**
+                @brief Gets called whenever a chat message was sent through ChatManager.
+                @param message The whole message (including name of the sender if available)
+                @param name The name of the sender (if available, otherwise "")
+            */
+            virtual void incomingChat(const std::string& message, const std::string& name) = 0;
+    };
+}
+
+#endif /* _ChatListener_H__ */


Property changes on: code/branches/output/src/orxonox/chat/ChatListener.h
___________________________________________________________________
Added: svn:eol-style
   + native

Added: code/branches/output/src/orxonox/chat/ChatManager.cc
===================================================================
--- code/branches/output/src/orxonox/chat/ChatManager.cc	                        (rev 0)
+++ code/branches/output/src/orxonox/chat/ChatManager.cc	2011-08-07 13:11:16 UTC (rev 8829)
@@ -0,0 +1,120 @@
+/*
+ *   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 "ChatManager.h"
+#include "ChatListener.h"
+
+#include "util/ScopedSingletonManager.h"
+#include "core/CoreIncludes.h"
+#include "core/command/ConsoleCommand.h"
+#include "network/Host.h"
+
+#include "PlayerManager.h"
+#include "infos/PlayerInfo.h"
+
+namespace orxonox
+{
+    ManageScopedSingleton(ChatManager, ScopeID::Root, false);
+
+    SetConsoleCommand("chat", &ChatManager::chat).defaultValue(1, NETWORK_PEER_ID_BROADCAST);
+
+    ChatManager::ChatManager()
+    {
+        RegisterObject(ChatManager);
+    }
+
+    /**
+        @brief Sends a message (usually gameplay related) without explicit sender to the chat.
+        @param message The message
+        @param targetID The client ID (network) of the receiver. Usually the broadcast ID
+    */
+    /*static*/ void ChatManager::message(const std::string& message, unsigned int targetID)
+    {
+        unsigned int sourceID = NETWORK_PEER_ID_UNKNOWN;
+
+        // only the server should send gameplay messages through the network. otherwise display the message locally
+        if (GameMode::isServer())
+            Host::sendChat(message, sourceID, targetID);
+        else
+            ChatManager::getInstance().incomingChat(message, sourceID);
+    }
+
+    /**
+        @brief Sends a chat message with the client as its sender to the chat.
+        @param message The message
+        @param targetID The client ID (network) of the receiver. Usually the broadcast ID
+    */
+    /*static*/ void ChatManager::chat(const std::string& message, unsigned int targetID)
+    {
+        unsigned int sourceID = Host::getPlayerID();
+
+        // if connected to the network, send chat messages online. otherwise display chat locally
+        if (GameMode::isServer() || GameMode::isClient())
+            Host::sendChat(message, sourceID, targetID);
+        else
+            ChatManager::getInstance().incomingChat(message, sourceID);
+    }
+
+    /**
+        @brief Inherited callback from NetworkChatListener, but gets also called directly
+        by ChatManager itself if the client is offline. Distributes an incoming chat message
+        to all ChatListeners.
+        @param message The message
+        @param sourceID The client ID (network) of the sender
+    */
+    void ChatManager::incomingChat(const std::string& message, unsigned int sourceID)
+    {
+        std::string text = message;
+        std::string name;
+
+        // get the name of the sender and prepend it to the text message
+        if (sourceID != NETWORK_PEER_ID_UNKNOWN)
+        {
+            PlayerInfo* player = PlayerManager::getInstance().getClient(sourceID);
+            if (player)
+            {
+                name = player->getName();
+                text = name + ": " + message;
+            }
+        }
+
+        // notify all listeners
+        for (ObjectList<ChatListener>::iterator it = ObjectList<ChatListener>::begin(); it != ObjectList<ChatListener>::end(); ++it)
+            it->incomingChat(text, name);
+    }
+
+
+    //////////////////////////////////////////////////////////////////////////
+    // ChatListener                                                         //
+    //////////////////////////////////////////////////////////////////////////
+
+    ChatListener::ChatListener()
+    {
+        RegisterRootObject(ChatListener);
+    }
+}


Property changes on: code/branches/output/src/orxonox/chat/ChatManager.cc
___________________________________________________________________
Added: svn:eol-style
   + native

Added: code/branches/output/src/orxonox/chat/ChatManager.h
===================================================================
--- code/branches/output/src/orxonox/chat/ChatManager.h	                        (rev 0)
+++ code/branches/output/src/orxonox/chat/ChatManager.h	2011-08-07 13:11:16 UTC (rev 8829)
@@ -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 _ChatManager_H__
+#define _ChatManager_H__
+
+#include "OrxonoxPrereqs.h"
+#include "util/Singleton.h"
+#include "network/NetworkChatListener.h"
+
+namespace orxonox
+{
+    /**
+        @brief This class collects and distributes chat messages. If the client is online,
+        all chat messages are sent and received through the network. Otherwise chat is handled
+        directly by this class.
+    */
+    class _OrxonoxExport ChatManager : public Singleton<ChatManager>, public NetworkChatListener
+    {
+        friend class Singleton<ChatManager>;
+
+        public:
+            ChatManager();
+            virtual ~ChatManager() {}
+
+            static void message(const std::string& message, unsigned int targetID = NETWORK_PEER_ID_BROADCAST);
+            static void chat(const std::string& message, unsigned int targetID = NETWORK_PEER_ID_BROADCAST);
+
+        protected:
+            ChatManager(const ChatManager&);
+
+            virtual void incomingChat(const std::string& message, unsigned int sourceID);
+
+            static ChatManager* singletonPtr_s;
+    };
+}
+
+#endif /* _ChatManager_H__ */


Property changes on: code/branches/output/src/orxonox/chat/ChatManager.h
___________________________________________________________________
Added: svn:eol-style
   + native

Modified: code/branches/output/src/orxonox/gametypes/Asteroids.cc
===================================================================
--- code/branches/output/src/orxonox/gametypes/Asteroids.cc	2011-08-06 16:33:55 UTC (rev 8828)
+++ code/branches/output/src/orxonox/gametypes/Asteroids.cc	2011-08-07 13:11:16 UTC (rev 8829)
@@ -29,7 +29,7 @@
 #include "Asteroids.h"
 
 #include "core/CoreIncludes.h"
-#include "network/Host.h"
+#include "chat/ChatManager.h"
 #include "worldentities/pawns/Pawn.h"
 
 namespace orxonox
@@ -73,7 +73,7 @@
         Gametype::start();
 
         std::string message("The match has started! Reach the first chekpoint within 15 seconds! But be aware, there may be pirates around...");
-        Host::Broadcast(message);
+        ChatManager::message(message);
 
     }
 
@@ -82,6 +82,6 @@
         Gametype::end();
 
         std::string message("The match has ended.");
-        Host::Broadcast(message);
+        ChatManager::message(message);
     }
 }

Modified: code/branches/output/src/orxonox/gametypes/Deathmatch.cc
===================================================================
--- code/branches/output/src/orxonox/gametypes/Deathmatch.cc	2011-08-06 16:33:55 UTC (rev 8828)
+++ code/branches/output/src/orxonox/gametypes/Deathmatch.cc	2011-08-07 13:11:16 UTC (rev 8829)
@@ -29,7 +29,7 @@
 #include "Deathmatch.h"
 
 #include "core/CoreIncludes.h"
-#include "network/Host.h"
+#include "chat/ChatManager.h"
 #include "infos/PlayerInfo.h"
 #include "worldentities/pawns/Pawn.h"
 
@@ -47,7 +47,7 @@
         Gametype::start();
 
         std::string message("The match has started!");
-        Host::Broadcast(message);
+        ChatManager::message(message);
     }
 
     void Deathmatch::end()
@@ -55,7 +55,7 @@
         Gametype::end();
 
         std::string message("The match has ended.");
-        Host::Broadcast(message);
+        ChatManager::message(message);
     }
 
     void Deathmatch::playerEntered(PlayerInfo* player)
@@ -63,7 +63,7 @@
         Gametype::playerEntered(player);
 
         const std::string& message = player->getName() + " entered the game";
-        Host::Broadcast(message);
+        ChatManager::message(message);
     }
 
     bool Deathmatch::playerLeft(PlayerInfo* player)
@@ -73,7 +73,7 @@
         if (valid_player)
         {
             const std::string& message = player->getName() + " left the game";
-            Host::Broadcast(message);
+            ChatManager::message(message);
         }
 
         return valid_player;
@@ -86,7 +86,7 @@
         if (valid_player)
         {
             const std::string& message = player->getOldName() + " changed name to " + player->getName();
-            Host::Broadcast(message);
+            ChatManager::message(message);
         }
 
         return valid_player;
@@ -107,7 +107,7 @@
             else
                 message = victim->getPlayer()->getName() + " died";
 
-            Host::Broadcast(message);
+            ChatManager::message(message);
         }
 
         Gametype::pawnKilled(victim, killer);
@@ -120,7 +120,7 @@
         if (player)
         {
             const std::string& message = player->getName() + " scores!";
-            Host::Broadcast(message);
+            ChatManager::message(message);
         }
     }
 }

Modified: code/branches/output/src/orxonox/gametypes/Dynamicmatch.cc
===================================================================
--- code/branches/output/src/orxonox/gametypes/Dynamicmatch.cc	2011-08-06 16:33:55 UTC (rev 8828)
+++ code/branches/output/src/orxonox/gametypes/Dynamicmatch.cc	2011-08-07 13:11:16 UTC (rev 8829)
@@ -48,7 +48,7 @@
 #include "util/Convert.h"
 #include "core/CoreIncludes.h"
 #include "core/command/Executor.h"
-#include "network/Host.h"
+#include "chat/ChatManager.h"
 #include "infos/PlayerInfo.h"
 #include "worldentities/pawns/Pawn.h"
 #include "worldentities/pawns/SpaceShip.h"
@@ -342,7 +342,7 @@
         numberOf[chaser]++;
         Gametype::playerEntered(player);
         const std::string& message = player->getName() + " entered the game";
-        Host::Broadcast(message);
+        ChatManager::message(message);
     }
 
     bool Dynamicmatch::playerLeft(PlayerInfo* player) //standardfunction
@@ -357,7 +357,7 @@
             case 2: numberOf[killer]--; break;
             }
             const std::string& message = player->getName() + " left the game";
-            Host::Broadcast(message);
+            ChatManager::message(message);
             //remove player from map
             playerParty_.erase (player);
             //adjust player parties
@@ -614,7 +614,7 @@
         if (valid_player)
         {
             const std::string& message = player->getOldName() + " changed name to " + player->getName();
-            Host::Broadcast(message);
+            ChatManager::message(message);
         }
 
         return valid_player;
@@ -626,7 +626,7 @@
         if(!tutorial)
         {
             std::string message("Dynamicmatch started!");
-            Host::Broadcast(message);
+            ChatManager::message(message);
         }
         else if(tutorial) // Announce selectionphase
         {
@@ -642,21 +642,21 @@
     /*void Dynamicmatch::instructions()
     {
         std::string message("Earn points:\n\n\n\tIf you're red: Chase the blue player!\n\n\tIf you're blue shoot at a red player or hide.\n\n\tIf you're green: You've got the licence to kill red players!");
-        Host::Broadcast(message);
+        ChatManager::message(message);
         callInstructions_.setTimer(10, false, createExecutor(createFunctor(&Dynamicmatch::furtherInstructions, this)));
     }
 
     void Dynamicmatch::furtherInstructions()
     {
         std::string message("After 3 Minutes the game is over.");
-        Host::Broadcast(message);
+        ChatManager::message(message);
     }*/
     void Dynamicmatch::end()
     {
         Gametype::end();
 
         std::string message("Time out. Press F2 to see the points you scored.");
-        Host::Broadcast(message);
+        ChatManager::message(message);
     }
     SpawnPoint* Dynamicmatch::getBestSpawnPoint(PlayerInfo* player) const
     {

Modified: code/branches/output/src/orxonox/gametypes/LastManStanding.cc
===================================================================
--- code/branches/output/src/orxonox/gametypes/LastManStanding.cc	2011-08-06 16:33:55 UTC (rev 8828)
+++ code/branches/output/src/orxonox/gametypes/LastManStanding.cc	2011-08-07 13:11:16 UTC (rev 8829)
@@ -29,7 +29,7 @@
 #include "LastManStanding.h"
 
 #include "core/CoreIncludes.h"
-#include "network/Host.h"
+#include "chat/ChatManager.h"
 #include "infos/PlayerInfo.h"
 #include "worldentities/pawns/Pawn.h"
 #include "core/ConfigValueIncludes.h"
@@ -104,7 +104,7 @@
         {
             this->playersAlive--;
             const std::string& message = victim->getPlayer()->getName() + " has lost all lives";
-            Host::Broadcast(message);
+            ChatManager::message(message);
         }
 
         return true;

Modified: code/branches/output/src/orxonox/gametypes/LastTeamStanding.cc
===================================================================
--- code/branches/output/src/orxonox/gametypes/LastTeamStanding.cc	2011-08-06 16:33:55 UTC (rev 8828)
+++ code/branches/output/src/orxonox/gametypes/LastTeamStanding.cc	2011-08-07 13:11:16 UTC (rev 8829)
@@ -29,8 +29,7 @@
 #include "LastTeamStanding.h"
 
 #include "core/CoreIncludes.h"
-#include "network/NetworkPrereqs.h"
-#include "network/Host.h"
+#include "chat/ChatManager.h"
 #include "infos/PlayerInfo.h"
 #include "worldentities/pawns/Pawn.h"
 #include "core/ConfigValueIncludes.h"
@@ -118,7 +117,7 @@
             if(eachTeamsPlayers[team] == 0) //last team member died
                 this->teamsAlive--;
             const std::string& message = victim->getPlayer()->getName() + " has lost all lives";
-            Host::Broadcast(message);
+            ChatManager::message(message);
         }
         return allow;
     }

Modified: code/branches/output/src/orxonox/gametypes/UnderAttack.cc
===================================================================
--- code/branches/output/src/orxonox/gametypes/UnderAttack.cc	2011-08-06 16:33:55 UTC (rev 8828)
+++ code/branches/output/src/orxonox/gametypes/UnderAttack.cc	2011-08-07 13:11:16 UTC (rev 8829)
@@ -31,7 +31,7 @@
 #include "util/Convert.h"
 #include "core/CoreIncludes.h"
 #include "core/ConfigValueIncludes.h"
-#include "network/Host.h"
+#include "chat/ChatManager.h"
 #include "worldentities/pawns/Destroyer.h"
 #include "infos/PlayerInfo.h"
 
@@ -69,7 +69,7 @@
     {
         this->end(); //end gametype
         std::string message("Ship destroyed! Team 0 has won!");
-        Host::Broadcast(message);
+        ChatManager::message(message);
         this->gameEnded_ = true;
 
         for (std::map<PlayerInfo*, int>::iterator it = this->teamnumbers_.begin(); it != this->teamnumbers_.end(); ++it)
@@ -151,7 +151,7 @@
                 this->gameEnded_ = true;
                 this->end();
                 std::string message("Time is up! Team 1 has won!");
-                Host::Broadcast(message);
+                ChatManager::message(message);
 
                 for (std::map<PlayerInfo*, int>::iterator it = this->teamnumbers_.begin(); it != this->teamnumbers_.end(); ++it)
                 {
@@ -170,7 +170,7 @@
             {
                 const std::string& message = multi_cast<std::string>(timesequence_) + " seconds left!";
 /*
-                Host::Broadcast(message);
+                ChatManager::message(message);
 */
                 this->gtinfo_->sendAnnounceMessage(message);
 




More information about the Orxonox-commit mailing list