Changeset 9250 in orxonox.OLD for branches/proxy/src
- Timestamp:
- Jul 12, 2006, 10:47:32 AM (18 years ago)
- Location:
- branches/proxy/src/lib/network
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/proxy/src/lib/network/message_manager.cc
r9059 r9250 52 52 } 53 53 } 54 54 55 55 it->second.messages.clear(); 56 56 it->second.toAck.clear(); 57 57 } 58 58 59 59 messageQueue.clear(); 60 60 61 61 this->messageHandlerMap.clear(); 62 62 63 63 MessageManager::singletonRef = NULL; 64 64 } … … 82 82 int i = 0; 83 83 int n; 84 84 85 85 n = Converter::intToByteArray( messageQueue[userId].toAck.size(), data + i, maxLength ); 86 86 i += n; 87 87 assert( n == INTSIZE ); 88 88 89 89 for ( std::list<int>::iterator it = messageQueue[userId].toAck.begin(); it != messageQueue[userId].toAck.end(); it++) 90 90 { … … 93 93 assert( n == INTSIZE ); 94 94 } 95 95 96 96 messageQueue[userId].toAck.clear(); 97 97 98 98 n = Converter::intToByteArray( messageQueue[userId].messages.size(), data + i, maxLength ); 99 99 i += n; 100 100 assert( n == INTSIZE ); 101 101 102 102 for ( std::list<NetworkMessage>::iterator it = messageQueue[userId].messages.begin(); it != messageQueue[userId].messages.end(); it++ ) 103 103 { … … 105 105 i += n; 106 106 assert( n == INTSIZE ); 107 107 108 108 n = Converter::intToByteArray( it->number, data + i, maxLength ); 109 109 i += n; 110 110 assert( n == INTSIZE ); 111 111 112 112 n = Converter::intToByteArray( it->messageId, data + i, maxLength ); 113 113 i += n; 114 114 assert( n == INTSIZE ); 115 115 116 116 assert( i + it->length <= maxLength ); 117 117 memcpy( data + i, it->data, it->length ); 118 118 i += it->length; 119 119 } 120 120 121 121 return i; 122 122 } … … 136 136 int i = 0; 137 137 int n; 138 138 139 139 int nAcks; 140 140 141 141 assert( i + INTSIZE <= length ); 142 142 n = Converter::byteArrayToInt( data + i, &nAcks ); 143 143 assert( n == INTSIZE ); 144 144 i += n; 145 145 146 146 std::list<int> acks; 147 147 148 148 int number; 149 149 150 150 for ( int j = 0; j < nAcks; j++ ) 151 151 { … … 154 154 assert( n == INTSIZE ); 155 155 i += n; 156 156 157 157 acks.push_back( number ); 158 158 } 159 159 160 160 int nMessages; 161 161 162 162 assert( i + INTSIZE <= length ); 163 163 n = Converter::byteArrayToInt( data + i, &nMessages ); … … 166 166 167 167 int messageLength, messageId; 168 168 169 169 for ( int j = 0; j < nMessages; j++ ) 170 170 { … … 173 173 assert( n == INTSIZE ); 174 174 i += n; 175 175 176 176 assert( i + INTSIZE <= length ); 177 177 n = Converter::byteArrayToInt( data + i, &number ); 178 178 assert( n == INTSIZE ); 179 179 i += n; 180 180 181 181 assert( i + INTSIZE <= length ); 182 182 n = Converter::byteArrayToInt( data + i, &messageId ); 183 183 assert( n == INTSIZE ); 184 184 i += n; 185 185 186 186 if ( number > 0 ) 187 187 messageQueue[userId].toAck.push_back( number ); 188 188 189 189 assert( i + messageLength <= length ); 190 190 assert( messageHandlerMap.find( (MessageId)messageId ) != messageHandlerMap.end() ); … … 194 194 { 195 195 NetworkMessage msg; 196 196 197 197 msg.data = new byte[messageLength]; 198 198 memcpy( msg.data, data + i, messageLength ); … … 200 200 msg.messageId = (MessageId)messageId; 201 201 msg.number = userId; 202 202 203 203 incomingMessageBuffer.push_back( msg ); 204 204 } … … 207 207 i += messageLength; 208 208 } 209 210 209 210 211 211 //TODO maybe handle incomingMessage in tick function. else local messages will not be handled if no clients are connected 212 212 for ( std::list<NetworkMessage>::iterator it = incomingMessageBuffer.begin(); it != incomingMessageBuffer.end(); ) … … 223 223 it++; 224 224 } 225 225 226 226 //walk throu message queue and remove acked messages 227 227 for ( std::list<NetworkMessage>::iterator it = messageQueue[userId].messages.begin(); it != messageQueue[userId].messages.end(); ) … … 236 236 it++; 237 237 } 238 238 239 239 //TODO find bether way. maybe with timestamp 240 240 if ( messageQueue[userId].recievedMessages.size() > 1000 ) … … 255 255 if ( messageQueue.find( userId ) == messageQueue.end() ) 256 256 return; 257 257 258 258 for ( std::list<NetworkMessage>::iterator it = messageQueue[userId].messages.begin(); it != messageQueue[userId].messages.end(); it++ ) 259 259 { … … 262 262 it->data = NULL; 263 263 } 264 264 265 265 messageQueue[userId].toAck.clear(); 266 266 267 267 messageQueue.erase( userId ); 268 268 } … … 270 270 /** 271 271 * registers function to handle messages with id messageId. someData is passed to callbackfuntion 272 * @param messageId message id to handle 272 * @param messageId message id to handle 273 273 * @param cb function pointer to callback function 274 274 * @param someData this pointer is passed to callback function without modification … … 278 278 { 279 279 MessageHandler messageHandler; 280 280 281 281 messageHandler.cb = cb; 282 282 messageHandler.messageId = messageId; 283 283 messageHandler.someData = someData; 284 284 285 285 messageHandlerMap[messageId] = messageHandler; 286 286 287 287 return true; 288 288 } … … 309 309 * @param data pointer to data 310 310 * @param dataLength length of data 311 * @param recieverType 312 * @param reciever 311 * @param recieverType 312 * @param reciever 313 313 */ 314 314 void MessageManager::sendMessage( MessageId messageId, byte * data, int dataLength, RecieverType recieverType, int reciever, MessagePriority messagePriority ) … … 316 316 for ( MessageQueue::iterator it = messageQueue.begin(); it != messageQueue.end(); it++ ) 317 317 { 318 if ( 318 if ( 319 319 recieverType == RT_ALL_ME || 320 320 recieverType == RT_ALL_NOT_ME || 321 321 recieverType == RT_USER && it->first == reciever || 322 322 recieverType == RT_NOT_USER && it->first != reciever || 323 recieverType == RT_SERVER && getNetworkStream()->isUser Server( it->first )323 recieverType == RT_SERVER && getNetworkStream()->isUserMasterServer( it->first ) 324 324 ) 325 325 { … … 336 336 } 337 337 } 338 338 339 339 if ( recieverType == RT_ALL_ME ) 340 340 { -
branches/proxy/src/lib/network/network_stream.h
r9249 r9250 27 27 public: 28 28 PeerInfo() { clear(); } 29 void clear() { userId = 0; isMasterServer = false; socket = NULL; handshake = NULL; lastAckedState = 0; lastRecvedState = 0; connectionMonitor = NULL; } 29 30 void clear() 31 { 32 this->userId = 0; 33 this->nodeType = NET_CLIENT; 34 this->isMasterServer = false; 35 this->isProxyServer = false; 36 this->isClient = false; 37 this->socket = NULL; 38 this->handshake = NULL; 39 this->lastAckedState = 0; 40 this->lastRecvedState = 0; 41 this->connectionMonitor = NULL; 42 } 30 43 31 44 32 45 public: 33 46 int userId; 47 int nodeType; 34 48 bool isMasterServer; 35 49 bool isProxyServer; … … 41 55 int lastRecvedState; 42 56 }; 57 58 43 59 44 60 typedef std::list<Synchronizeable*> SynchronizeableList;
Note: See TracChangeset
for help on using the changeset viewer.