Changeset 8829 for code/branches/output/src/libraries/network/Host.cc
- Timestamp:
- Aug 7, 2011, 3:11:16 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/output/src/libraries/network/Host.cc
r8827 r8829 32 32 #include <string> 33 33 34 #include "core/CoreIncludes.h" 34 35 #include "core/ObjectList.h" 35 36 #include "core/command/ConsoleCommand.h" 36 #include " ChatListener.h"37 #include "NetworkChatListener.h" 37 38 38 39 namespace orxonox { … … 41 42 static const std::string __CC_printRTT_name = "printRTT"; 42 43 43 SetConsoleCommand("chat", &Host::Chat);44 44 SetConsoleCommand(__CC_printRTT_group, __CC_printRTT_name, &Host::printRTT); 45 45 … … 89 89 } 90 90 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) 92 98 { 93 for (ObjectList<ChatListener>::iterator it = ObjectList<ChatListener>::begin(); it != ObjectList<ChatListener>::end(); ++it)94 it->incomingChat(message, 0);95 96 bool result = true;97 99 for( std::vector<Host*>::iterator it = instances_s.begin(); it!=instances_s.end(); ++it ) 98 {99 100 if( (*it)->isActive() ) 100 { 101 if( !(*it)->chat(message) ) 102 result = false; 103 } 104 } 105 // return result; 101 (*it)->doSendChat(message, sourceID, targetID); 106 102 } 107 103 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) 109 108 { 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); 123 111 } 124 112 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 }141 113 142 114 bool Host::isServer() … … 167 139 168 140 141 ////////////////////////////////////////////////////////////////////////// 142 // NetworkChatListener // 143 ////////////////////////////////////////////////////////////////////////// 144 145 NetworkChatListener::NetworkChatListener() 146 { 147 RegisterRootObject(NetworkChatListener); 148 } 149 169 150 }//namespace orxonox
Note: See TracChangeset
for help on using the changeset viewer.