Changeset 8708 in orxonox.OLD for trunk/src/lib
- Timestamp:
- Jun 22, 2006, 12:48:01 PM (19 years ago)
- Location:
- trunk/src/lib/network
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/network/message_manager.cc
r8623 r8708 19 19 20 20 #include "network_stream.h" 21 #include "shared_network_data.h" 21 22 22 23 using namespace std; … … 196 197 msg.number = userId; 197 198 198 incomingMessa beBuffer.push_back( msg );199 incomingMessageBuffer.push_back( msg ); 199 200 } 200 201 messageQueue[userId].recievedMessages.push_back( number ); … … 204 205 205 206 206 for ( std::list<NetworkMessage>::iterator it = incomingMessabeBuffer.begin(); it != incomingMessabeBuffer.end(); ) 207 //TODO maybe handle incomingMessage in tick function. else local messages will not be handled if no clients are connected 208 for ( std::list<NetworkMessage>::iterator it = incomingMessageBuffer.begin(); it != incomingMessageBuffer.end(); ) 207 209 { 208 210 if ( (*(messageHandlerMap[it->messageId].cb))( it->messageId, it->data, it->length, messageHandlerMap[it->messageId].someData, it->number ) ) … … 212 214 delete it->data; 213 215 it++; 214 incomingMessa beBuffer.erase( delIt );216 incomingMessageBuffer.erase( delIt ); 215 217 continue; 216 218 } … … 328 330 329 331 it->second.messages.push_back( msg ); 330 331 332 332 } 333 333 } … … 341 341 msg.length = dataLength; 342 342 msg.messageId = messageId; 343 msg.number = newNumber++;343 msg.number = SharedNetworkData::getInstance()->getHostID(); 344 344 msg.priority = messagePriority; 345 345 346 incomingMessa beBuffer.push_back( msg );347 } 348 } 349 350 346 incomingMessageBuffer.push_back( msg ); 347 } 348 } 349 350 -
trunk/src/lib/network/message_manager.h
r8623 r8708 109 109 110 110 int newNumber; //!< used to create unique message numbers 111 std::list<NetworkMessage> incomingMessa beBuffer;111 std::list<NetworkMessage> incomingMessageBuffer; 112 112 113 113 }; -
trunk/src/lib/network/network_game_manager.cc
r8623 r8708 112 112 stats->setUniqueID( SharedNetworkData::getInstance()->getNewUniqueID() ); 113 113 stats->setSynchronized( true ); 114 stats->setOwner( getHostID() );114 stats->setOwner( SharedNetworkData::getInstance()->getHostID() ); 115 115 116 116 stats->setTeamId( team ); … … 247 247 { 248 248 if ( isServer() ) 249 setPreferedTeam( getHostID(), teamId );249 setPreferedTeam( SharedNetworkData::getInstance()->getHostID(), teamId ); 250 250 else 251 251 { … … 284 284 bool NetworkGameManager::chatMessageHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId ) 285 285 { 286 PRINTF(0)("NetworkGameManager::chatMessageHandler %d %d\n", userId, SharedNetworkData::getInstance()->getHostID() ); 287 if ( NetworkGameManager::getInstance()->isServer() && userId != SharedNetworkData::getInstance()->getHostID() ) 288 { 289 MessageManager::getInstance()->sendMessage( messageId, data, dataLength, RT_ALL_NOT_ME, 0, MP_HIGHBANDWIDTH ); 290 } 291 286 292 assert( State::getGameRules() ); 287 293 assert( State::getGameRules()->isA( CL_NETWORK_GAME_RULES ) ); … … 289 295 NetworkGameRules & rules = *(dynamic_cast<NetworkGameRules*>(State::getGameRules())); 290 296 291 if ( dataLength < 2*INTSIZE )297 if ( dataLength < 3*INTSIZE ) 292 298 { 293 299 PRINTF(2)("got too small chatmessage from client %d\n", userId); … … 298 304 int messageType = 0; 299 305 Converter::byteArrayToInt( data, &messageType ); 306 int senderUserId = 0; 307 Converter::byteArrayToInt( data+INTSIZE, &senderUserId ); 300 308 std::string message; 301 Converter::byteArrayToString( data+ INTSIZE, message, dataLength-INTSIZE );302 303 rules.handleChatMessage( userId, message, messageType );309 Converter::byteArrayToString( data+2*INTSIZE, message, dataLength-2*INTSIZE ); 310 311 rules.handleChatMessage( senderUserId, message, messageType ); 304 312 305 313 return true; … … 310 318 * @param message message text 311 319 * @param messageType some int 312 * @param userId user to send message to -1 = ALL 313 */ 314 void NetworkGameManager::sendChatMessage( const std::string & message, int messageType, int userId ) 315 { 316 byte * buf = new byte[message.length()+2*INTSIZE]; 320 */ 321 void NetworkGameManager::sendChatMessage( const std::string & message, int messageType ) 322 { 323 byte * buf = new byte[message.length()+3*INTSIZE]; 317 324 318 325 assert( Converter::intToByteArray( messageType, buf, INTSIZE ) == INTSIZE ); 319 assert( Converter::stringToByteArray(message, buf+INTSIZE, message.length()+INTSIZE) == message.length()+INTSIZE ); 320 321 if ( userId == -1 ) 322 MessageManager::getInstance()->sendMessage( MSGID_CHATMESSAGE, buf, message.length()+2*INTSIZE, RT_ALL_ME, 0, MP_HIGHBANDWIDTH ); 326 assert( Converter::intToByteArray( SharedNetworkData::getInstance()->getHostID(), buf+INTSIZE, INTSIZE ) == INTSIZE ); 327 assert( Converter::stringToByteArray(message, buf+2*INTSIZE, message.length()+INTSIZE) == message.length()+INTSIZE ); 328 329 if ( this->isServer() ) 330 MessageManager::getInstance()->sendMessage( MSGID_CHATMESSAGE, buf, message.length()+3*INTSIZE, RT_ALL_ME, 0, MP_HIGHBANDWIDTH ); 323 331 else 324 MessageManager::getInstance()->sendMessage( MSGID_CHATMESSAGE, buf, message.length()+2*INTSIZE, RT_USER, userId, MP_HIGHBANDWIDTH ); 332 MessageManager::getInstance()->sendMessage( MSGID_CHATMESSAGE, buf, message.length()+3*INTSIZE, RT_ALL_NOT_ME, 0, MP_HIGHBANDWIDTH ); 333 325 334 326 335 delete [] buf; -
trunk/src/lib/network/network_game_manager.h
r8623 r8708 65 65 void tick( float ds ); 66 66 67 void sendChatMessage( const std::string & message, int messageType , int userId = -1);67 void sendChatMessage( const std::string & message, int messageType ); 68 68 69 69 private: -
trunk/src/lib/network/network_manager.cc
r8228 r8708 144 144 this->elapsedTime = 0.0f; 145 145 146 if ( networkStream->isActive() )146 // if ( networkStream->isActive() ) 147 147 networkStream->processData(); 148 148 -
trunk/src/lib/network/player_stats.cc
r8623 r8708 95 95 this->setPlayableUniqueId( this->playableUniqueId ); 96 96 97 PRINTF(0)("uniqueID changed %d %d %d\n", userId, getHostID(), getUniqueID());97 PRINTF(0)("uniqueID changed %d %d %d\n", userId, SharedNetworkData::getInstance()->getHostID(), getUniqueID()); 98 98 } 99 99 … … 155 155 } 156 156 157 if ( this->playable && userId == getHostID() )157 if ( this->playable && userId == SharedNetworkData::getInstance()->getHostID() ) 158 158 { 159 159 State::getPlayer()->setPlayable( this->playable ); -
trunk/src/lib/network/synchronizeable.cc
r8623 r8708 38 38 this->setClassID(CL_SYNCHRONIZEABLE, "Synchronizeable"); 39 39 this->owner = 0; 40 this->hostID = SharedNetworkData::getInstance()->getHostID(); 41 this->setIsServer(this->hostID == 0); 40 this->setIsServer(SharedNetworkData::getInstance()->getHostID() == 0); 42 41 this->uniqueID = NET_UID_UNASSIGNED; 43 42 this->networkStream = NULL; … … 222 221 hasPermission = ( 223 222 this->isServer() && (*it)->checkPermission( PERMISSION_SERVER ) || 224 this->owner == this->hostID&& (*it)->checkPermission( PERMISSION_OWNER ) ||223 this->owner == SharedNetworkData::getInstance()->getHostID() && (*it)->checkPermission( PERMISSION_OWNER ) || 225 224 this->isServer() && this->owner != userId && (*it)->checkPermission( PERMISSION_OWNER ) || 226 225 (*it)->checkPermission( PERMISSION_ALL ) … … 345 344 (*it)->checkPermission( PERMISSION_SERVER ) && networkStream->isUserServer( userId ) || 346 345 (*it)->checkPermission( PERMISSION_OWNER ) && this->owner == userId || 347 networkStream->isUserServer( userId ) && this->owner != getHostID() && (*it)->checkPermission( PERMISSION_OWNER ) ||346 networkStream->isUserServer( userId ) && this->owner != SharedNetworkData::getInstance()->getHostID() && (*it)->checkPermission( PERMISSION_OWNER ) || 348 347 (*it)->checkPermission( PERMISSION_ALL ) 349 348 ) -
trunk/src/lib/network/synchronizeable.h
r8068 r8708 67 67 inline void setUniqueID( int id ){ uniqueID = id; } 68 68 inline int getUniqueID() const { return uniqueID; } 69 inline int getHostID() { return this->hostID; }70 69 71 70 inline int getOwner(){ return owner; } … … 89 88 int mLeafClassId; //!< store leafClassId to send via states 90 89 int owner; //!< hostId of owner ( 0 if none / server ) 91 int hostID; //!< my own host id92 90 bool bSynchronize; //!< do we need beeing synchronized? 93 91
Note: See TracChangeset
for help on using the changeset viewer.