Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 7, 2011, 3:11:16 PM (13 years ago)
Author:
landauf
Message:

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).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/output/src/libraries/network/Host.cc

    r8827 r8829  
    3232#include <string>
    3333
     34#include "core/CoreIncludes.h"
    3435#include "core/ObjectList.h"
    3536#include "core/command/ConsoleCommand.h"
    36 #include "ChatListener.h"
     37#include "NetworkChatListener.h"
    3738
    3839namespace orxonox {
     
    4142  static const std::string __CC_printRTT_name = "printRTT";
    4243
    43   SetConsoleCommand("chat", &Host::Chat);
    4444  SetConsoleCommand(__CC_printRTT_group, __CC_printRTT_name, &Host::printRTT);
    4545
     
    8989  }
    9090
    91   void Host::Chat(const std::string& message)
     91  /**
     92   * @brief Sends a chat message through the network.
     93   * @param message message to be sent
     94   * @param sourceID the ID of the sender
     95   * @param targetID the ID of the receiver
     96   */
     97  void Host::sendChat(const std::string& message, unsigned int sourceID, unsigned int targetID)
    9298  {
    93     for (ObjectList<ChatListener>::iterator it = ObjectList<ChatListener>::begin(); it != ObjectList<ChatListener>::end(); ++it)
    94       it->incomingChat(message, 0);
    95 
    96     bool result = true;
    9799    for( std::vector<Host*>::iterator it = instances_s.begin(); it!=instances_s.end(); ++it )
    98     {
    99100      if( (*it)->isActive() )
    100       {
    101         if( !(*it)->chat(message) )
    102           result = false;
    103       }
    104     }
    105 //    return result;
     101        (*it)->doSendChat(message, sourceID, targetID);
    106102  }
    107103
    108   bool Host::Broadcast(const std::string& message)
     104  /**
     105   * @brief Gets called if a packet::Chat packet is received. Passes the message to the listeners.
     106   */
     107  void Host::doReceiveChat(const std::string& message, unsigned int sourceID, unsigned int targetID)
    109108  {
    110     for (ObjectList<ChatListener>::iterator it = ObjectList<ChatListener>::begin(); it != ObjectList<ChatListener>::end(); ++it)
    111       it->incomingChat(message, NETWORK_PEER_ID_BROADCAST);
    112 
    113     bool result = true;
    114     for( std::vector<Host*>::iterator it = instances_s.begin(); it!=instances_s.end(); ++it )
    115     {
    116       if( (*it)->isActive() )
    117       {
    118         if( !(*it)->broadcast(message) )
    119           result = false;
    120       }
    121     }
    122     return result;
     109    for (ObjectList<NetworkChatListener>::iterator it = ObjectList<NetworkChatListener>::begin(); it != ObjectList<NetworkChatListener>::end(); ++it)
     110      it->incomingChat(message, sourceID);
    123111  }
    124112
    125   bool Host::incomingChat(const std::string& message, unsigned int playerID)
    126   {
    127     for (ObjectList<ChatListener>::iterator it = ObjectList<ChatListener>::begin(); it != ObjectList<ChatListener>::end(); ++it)
    128       it->incomingChat(message, playerID);
    129 
    130     bool result = true;
    131     for( std::vector<Host*>::iterator it = instances_s.begin(); it!=instances_s.end(); ++it )
    132     {
    133       if( (*it)->isActive() )
    134       {
    135         if( !(*it)->processChat(message, playerID) )
    136           result = false;
    137       }
    138     }
    139     return result;
    140   }
    141113
    142114  bool Host::isServer()
     
    167139
    168140
     141  //////////////////////////////////////////////////////////////////////////
     142  // NetworkChatListener                                                  //
     143  //////////////////////////////////////////////////////////////////////////
     144
     145  NetworkChatListener::NetworkChatListener()
     146  {
     147      RegisterRootObject(NetworkChatListener);
     148  }
     149
    169150}//namespace orxonox
Note: See TracChangeset for help on using the changeset viewer.