Changeset 7693 in orxonox.OLD for branches/network
- Timestamp:
- May 18, 2006, 3:52:44 PM (19 years ago)
- Location:
- branches/network/src/lib/network
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/network/src/lib/network/message_manager.cc
r7681 r7693 184 184 if ( std::find( messageQueue[userId].recievedMessages.begin(), messageQueue[userId].recievedMessages.end(), number )== messageQueue[userId].recievedMessages.end() ) 185 185 { 186 (*(messageHandlerMap[(MessageId)messageId].cb))( (MessageId)messageId, data + i, messageLength, messageHandlerMap[(MessageId)messageId].someData, userId ); 186 if ( !(*(messageHandlerMap[(MessageId)messageId].cb))( (MessageId)messageId, data + i, messageLength, messageHandlerMap[(MessageId)messageId].someData, userId ) ) 187 { 188 NetworkMessage msg; 189 190 msg.data = new byte[messageLength]; 191 memcpy( msg.data, data + i, messageLength ); 192 msg.length = messageLength; 193 msg.messageId = (MessageId)messageId; 194 msg.number = userId; 195 196 incomingMessabeBuffer.push_back( msg ); 197 } 187 198 messageQueue[userId].recievedMessages.push_back( number ); 188 199 } … … 190 201 } 191 202 203 204 for ( std::list<NetworkMessage>::iterator it = incomingMessabeBuffer.begin(); it != incomingMessabeBuffer.end(); it++ ) 205 { 206 if ( (*(messageHandlerMap[it->messageId].cb))( it->messageId, data + i, it->length, messageHandlerMap[it->messageId].someData, it->number ) ) 207 { 208 std::list<NetworkMessage>::iterator delIt = it; 209 it++; 210 incomingMessabeBuffer.erase( delIt ); 211 continue; 212 } 213 it++; 214 } 192 215 193 216 //walk throu message queue and remove acked messages -
branches/network/src/lib/network/message_manager.h
r7681 r7693 28 28 enum MessageId 29 29 { 30 TESTMESSAGEID = 1 30 TESTMESSAGEID = 1, 31 MSGID_YOU_ARE 31 32 }; 32 33 33 typedef void(*MessageCallback)( MessageId messageId, byte * data, int dataLength, void * someData, int userId );34 typedef bool (*MessageCallback)( MessageId messageId, byte * data, int dataLength, void * someData, int userId ); 34 35 35 36 enum RecieverType … … 96 97 97 98 private: 98 static MessageManager * singletonRef;99 MessageQueue messageQueue;//!< stores messages to send100 MessageHandlerMap messageHandlerMap;//!< contains handlers for messages99 static MessageManager * singletonRef; 100 MessageQueue messageQueue; //!< stores messages to send 101 MessageHandlerMap messageHandlerMap; //!< contains handlers for messages 101 102 102 int newNumber; //!< used to create unique message numbers 103 int newNumber; //!< used to create unique message numbers 104 std::list<NetworkMessage> incomingMessabeBuffer; 103 105 104 106 }; -
branches/network/src/lib/network/network_game_manager.cc
r7567 r7693 27 27 #include "shared_network_data.h" 28 28 #include "converter.h" 29 #include "message_manager.h" 29 30 30 31 #include "playable.h" … … 212 213 if ( this->isServer()) 213 214 { 214 if ( SharedNetworkData::getInstance()->getNewUniqueID() < 0 ) 215 int res = this->executeCreateEntity( classID, SharedNetworkData::getInstance()->getNewUniqueID(), owner ); 216 217 if ( res < 0 ) 215 218 { 216 219 PRINTF(1)("Cannot create entity! There are no more uniqueIDs left!\n"); 217 220 return -1; 218 221 } 219 return this->executeCreateEntity( classID, SharedNetworkData::getInstance()->getNewUniqueID(), owner ); 222 223 return res; 220 224 } 221 225 else … … 461 465 bool NetworkGameManager::signalNewPlayer(int userId) 462 466 { 463 #if 0464 if ( userId >= outBuffer.size() )465 resizeBufferVector( userId );466 467 467 /* create new playable for Player*/ 468 468 PRINTF(0)("Request for creation: %i\n", userId); … … 470 470 PRINTF(0)("Request for creation: userid: %i, uniqueid: %i\n", userId, uniqueId); 471 471 this->sendYouAre(uniqueId, userId); 472 #endif473 472 } 474 473 … … 709 708 if ( !isServer() ) 710 709 return; 711 #if 0 712 if ( userID != 0 ) 713 { 714 if ( !writeToClientBuffer( outBuffer[userID], (byte)NET_YOU_ARE_ENTITY ) ) 715 return; 716 717 if ( !writeToClientBuffer( outBuffer[userID], uniqueID ) ) 718 return; 719 } 720 else 721 { 722 #endif 723 doYouAre(uniqueID); 724 #if 0 725 } 726 #endif 727 710 711 byte buf[INTSIZE]; 712 713 Converter::intToByteArray( uniqueID, buf, INTSIZE ); 714 715 MessageManager::getInstance()->sendMessage( MSGID_YOU_ARE, buf, INTSIZE, RT_USER, userID, MP_HIGHBANDWIDTH); 728 716 } 729 717 … … 939 927 } 940 928 929 bool NetworkGameManager::youAreHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId ) 930 { 931 assert( dataLength == INTSIZE ); 932 int uniqueId; 933 934 Converter::byteArrayToInt( data, &uniqueId ); 935 936 NetworkGameManager::getInstance()->doYouAre( uniqueId ); 937 } 938 941 939 #if 0 942 940 bool NetworkGameManager::writeToClientBuffer( clientBuffer & cb, byte b ) -
branches/network/src/lib/network/network_game_manager.h
r7567 r7693 12 12 /* include base_object.h since all classes are derived from this one */ 13 13 #include "synchronizeable.h" 14 #include "message_manager.h" 14 15 15 16 16 17 class TiXmlElement; 17 18 class PNode; 18 19 /**20 * protocol definition21 *22 * CREATE_ENTITY: >> CLASS_ID, UNIQUE_ID, OWNER23 * REMOVE_ENTITY: >> UNIQUE_ID24 *25 * CREATE_ENTITY_LIST: >> NUMBER, [CLASS_ID, UNIQUE_ID, OWNER][0..NUMBER]26 * REMOVE_ENTITY_LIST: >> NUMBER, [UNIQUE_ID][0..NUMBER]27 *28 * REQUEST_CREATE: >> CLASS_ID29 * << [Sync Info]30 * REQUEST_REMOVE: >> UNIQUE_ID31 * << [Sync Info]32 *33 * //REQUEST_CREATE_LIST: NUMBER, [CLASS_ID][0..NUMBER]34 * //REQUEST_CREATE_LIST: NUMBER, [UNIQUE_ID][0..NUMBER]35 *36 * REQUEST_ENTITY_LIST: //request the whole world :D37 * YOU_ARE_ENTITY: >> UNIQUE_ID38 *39 * REQUEST_PNODE_PATH >> UNIQUE_ID_START UNIQUE_ID_STOP40 * << UNIQUE_ID_1 UNIQUE_ID_2 UNIQUE_ID_3 ... UNIQUE_ID_N41 *42 * SEND_PNODE_PATH >> UNIQUE_ID_START UNIQUE_ID_STOP NUMBER [UNIQUE_ID][0..NUMBER]43 */44 19 45 20 typedef enum NetworkGameManagerProtocol { … … 98 73 private: 99 74 NetworkGameManager(); 75 76 static bool youAreHandler(MessageId messageId, byte * data, int dataLength, void * someData, int userId ); 100 77 101 78 -
branches/network/src/lib/network/network_stream.cc
r7684 r7693 569 569 * @todo create playable for new user 570 570 */ 571 #include "world_entities/space_ships/space_ship.h" 571 572 void NetworkStream::handleNewClient( int userId ) 572 573 { 573 574 MessageManager::getInstance()->initUser( userId ); 574 } 575 576 577 578 579 580 575 576 networkGameManager->signalNewPlayer( userId ); 577 } 578 579 580 581 582 583
Note: See TracChangeset
for help on using the changeset viewer.