Changeset 9656 in orxonox.OLD for trunk/src/lib/network
- Timestamp:
- Aug 4, 2006, 11:01:28 PM (18 years ago)
- Location:
- trunk/src/lib/network
- Files:
-
- 36 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/network/Makefile.am
r9494 r9656 27 27 \ 28 28 proxy/network_settings.cc \ 29 proxy/proxy_control.cc \ 29 30 \ 30 31 monitor/connection_monitor.cc \ … … 76 77 udp_broadcast.h \ 77 78 \ 78 proxy/network_settings.cc \ 79 proxy/network_settings.h \ 80 proxy/proxy_control.h \ 79 81 \ 80 82 monitor/connection_monitor.h \ -
trunk/src/lib/network/README.NETWORK
r9494 r9656 1 1 2 3 4 5 WORD OF WARNING: 6 ================ 7 - Allways keep the network_settings.conf file from the data repos up-to-date!! Its very important, that the user numbers are synchronized! 2 8 3 9 4 10 WORKING_STACK: 5 11 ============== 6 - it works to connecto to a master server which is connected to a proxy itself 7 12 - removed compiler warnings in some modules 13 - totaly rework of the permission system 14 - introduced a new PERMISSION layer: PERMISSION_SERVER which gives the nearest server the authority to handle 8 15 9 16 10 17 UNSOLVED: 11 18 ========= 12 - what if the proxy server gets a new client and wants to add it to the game? There are some problems waiting in the network game manager 13 - actualy the whole message sending system won't work in this network topic. proxys have to relay messages to clients 14 - the clients cant get its ip in the handleHandshakes without throuwing sigseg 19 - the clients cant get its ip in the handleHandshakes without throwing sigseg 20 - MessageManager: proxy/server forward the messages always. Perhaps there is a case, where messages get forwarded forever if there is a loop in the network. think about it again. 21 - Permissions: Proxy Servers shouldn't be able to create new eneitites on the server 22 - the nick name must be handled new 15 23 16 24 … … 48 56 49 57 58 The ids are created by the master/proxy servers. Each server receives an address space of 1000 nodes where it is able to assign nodes to. This address space could be extended quite easely, since we got plenty of numbers in 4bytes (integer) 59 60 The handshake sync has always the uniqueId == userId. This is why there are some reserved uniqueIds 61 50 62 51 63 uniqueId: 52 64 ========= 53 65 uniqueId is an id (unique :D) for each synchronizeable to be identified in a network. the number space for uniqueIds goes from 0 to maxplayers - 1 66 67 The handshake sync has always the uniqueId == userId. This is why there are some reserved uniqueIds 54 68 55 69 … … 62 76 PERMISSION_ALL : all clients can write this variable 63 77 78 Only the master server should have the permission to create new WorldEntities and to add them to the game 64 79 65 80 … … 72 87 73 88 89 MessageManager: 90 =============== 91 The message manager has special handling if its a master/proxy: the messages will simply be forwarded to the other server 92 93 94 Proxy Control: 95 ============== 96 The ProxyControl class manages the state of the network by exchanging state messages. -
trunk/src/lib/network/handshake.cc
r9494 r9656 71 71 remoteState.error = 0; 72 72 remoteState.errorString = ""; 73 remoteState.hostId = -1;73 remoteState.hostId = NET_ID_UNASSIGNED; 74 74 remoteState.networkManagerId = -1; 75 75 remoteState.messageManagerId = -1; -
trunk/src/lib/network/message_manager.cc
r9494 r9656 11 11 ### File Specific: 12 12 main-programmer: Christoph Renner 13 co-programmer: ... 13 co-programmer: Patrick Boenzli (patrick@orxonox.ethz.ch) 14 15 June 2006: finishing work on the network stream for pps presentation (rennerc@ee.ethz.ch) 16 July 2006: some code rearangement and integration of the proxy server mechanism (boenzlip@ee.ethz.ch) 17 July 2006: message forwarding algorithms 14 18 */ 15 19 … … 44 48 MessageManager::~MessageManager () 45 49 { 46 for ( MessageQueue::iterator it = messageQueue.begin(); it != messageQueue.end(); it++ )50 for ( MessageQueue::iterator it = outgoingMessageQueue.begin(); it != outgoingMessageQueue.end(); it++ ) 47 51 { 48 52 for ( std::list<NetworkMessage>::iterator it2 = it->second.messages.begin(); it2 != it->second.messages.end(); it2++ ) … … 59 63 } 60 64 61 messageQueue.clear();65 outgoingMessageQueue.clear(); 62 66 63 67 this->messageHandlerMap.clear(); … … 85 89 int n; 86 90 87 n = Converter::intToByteArray( messageQueue[userId].toAck.size(), data + i, maxLength );91 n = Converter::intToByteArray( outgoingMessageQueue[userId].toAck.size(), data + i, maxLength ); 88 92 i += n; 89 93 assert( n == INTSIZE ); 90 94 91 for ( std::list<int>::iterator it = messageQueue[userId].toAck.begin(); it != messageQueue[userId].toAck.end(); it++)95 for ( std::list<int>::iterator it = outgoingMessageQueue[userId].toAck.begin(); it != outgoingMessageQueue[userId].toAck.end(); it++) 92 96 { 93 97 n = Converter::intToByteArray( *it, data + i, maxLength ); … … 96 100 } 97 101 98 messageQueue[userId].toAck.clear();99 100 n = Converter::intToByteArray( messageQueue[userId].messages.size(), data + i, maxLength );102 outgoingMessageQueue[userId].toAck.clear(); 103 104 n = Converter::intToByteArray( outgoingMessageQueue[userId].messages.size(), data + i, maxLength ); 101 105 i += n; 102 106 assert( n == INTSIZE ); 103 107 104 for ( std::list<NetworkMessage>::iterator it = messageQueue[userId].messages.begin(); it != messageQueue[userId].messages.end(); it++ ) 105 { 108 // write the message down, a message has this structure: 109 // | data_length | serial_number | message_type | source_id | dest_id | ...data... | 110 // 4byte 4byte 4byte 4byte 4byte data_length 111 for ( std::list<NetworkMessage>::iterator it = outgoingMessageQueue[userId].messages.begin(); it != outgoingMessageQueue[userId].messages.end(); it++ ) 112 { 113 // send data length 106 114 n = Converter::intToByteArray( it->length, data + i, maxLength ); 107 115 i += n; 108 116 assert( n == INTSIZE ); 109 117 118 // send serial number 110 119 n = Converter::intToByteArray( it->number, data + i, maxLength ); 111 120 i += n; 112 121 assert( n == INTSIZE ); 113 122 114 n = Converter::intToByteArray( it->messageId, data + i, maxLength ); 115 i += n; 116 assert( n == INTSIZE ); 117 123 // send message type 124 n = Converter::intToByteArray( it->messageType, data + i, maxLength ); 125 i += n; 126 assert( n == INTSIZE ); 127 128 // send sender id 129 n = Converter::intToByteArray( it->senderId, data + i, maxLength ); 130 i += n; 131 assert( n == INTSIZE ); 132 133 // send destination id 134 n = Converter::intToByteArray( it->destinationId, data + i, maxLength ); 135 i += n; 136 assert( n == INTSIZE ); 137 138 // send receiver type 139 n = Converter::intToByteArray( it->recieverType, data + i, maxLength ); 140 i += n; 141 assert( n == INTSIZE ); 142 143 // and copy the data 118 144 assert( i + it->length <= maxLength ); 119 145 memcpy( data + i, it->data, it->length ); … … 141 167 int nAcks; 142 168 169 143 170 assert( i + INTSIZE <= length ); 144 171 n = Converter::byteArrayToInt( data + i, &nAcks ); … … 167 194 i += n; 168 195 169 int messageLength, messageId; 170 196 int messageLength, messageType; 197 int senderId, destinationId, recieverType; 198 199 // now go through all newly received messages and assemble them 171 200 for ( int j = 0; j < nMessages; j++ ) 172 201 { 202 // read the length 173 203 assert( i + INTSIZE <= length ); 174 204 n = Converter::byteArrayToInt( data + i, &messageLength ); … … 176 206 i += n; 177 207 208 // read the serial number 178 209 assert( i + INTSIZE <= length ); 179 210 n = Converter::byteArrayToInt( data + i, &number ); … … 181 212 i += n; 182 213 183 assert( i + INTSIZE <= length ); 184 n = Converter::byteArrayToInt( data + i, &messageId ); 214 // read the message type 215 assert( i + INTSIZE <= length ); 216 n = Converter::byteArrayToInt( data + i, &messageType ); 217 assert( n == INTSIZE ); 218 i += n; 219 220 // read the sender id 221 assert( i + INTSIZE <= length ); 222 n = Converter::byteArrayToInt( data + i, &senderId ); 223 assert( n == INTSIZE ); 224 i += n; 225 226 //read the destination id 227 assert( i + INTSIZE <= length ); 228 n = Converter::byteArrayToInt( data + i, &destinationId); 229 assert( n == INTSIZE ); 230 i += n; 231 232 // read the receiver type 233 assert( i + INTSIZE <= length ); 234 n = Converter::byteArrayToInt( data + i, &recieverType); 185 235 assert( n == INTSIZE ); 186 236 i += n; 187 237 188 238 if ( number > 0 ) 189 messageQueue[userId].toAck.push_back( number ); 190 239 outgoingMessageQueue[userId].toAck.push_back( number ); 240 241 // PRINTF(0)("got message with type: %i\n", messageType); 191 242 assert( i + messageLength <= length ); 192 assert( messageHandlerMap.find( (MessageId)messageId ) != messageHandlerMap.end() ); 193 if ( std::find( messageQueue[userId].recievedMessages.begin(), messageQueue[userId].recievedMessages.end(), number )== messageQueue[userId].recievedMessages.end() ) 243 // make sure there is a message handler for this message type 244 assert( messageHandlerMap.find( (MessageType)messageType ) != messageHandlerMap.end()); 245 246 247 if ( std::find( outgoingMessageQueue[userId].recievedMessages.begin(), outgoingMessageQueue[userId].recievedMessages.end(), number ) == 248 outgoingMessageQueue[userId].recievedMessages.end() ) 194 249 { 195 if ( !(*(messageHandlerMap[(MessageId)messageId].cb))( (MessageId)messageId, data + i, messageLength, messageHandlerMap[(MessageId)messageId].someData, userId ) ) 250 251 // find out if this message is addressed for this client too 252 if( recieverType == RT_ALL_BUT_ME && SharedNetworkData::getInstance()->getHostID() != senderId || 253 recieverType == RT_ALL_ME || 254 recieverType == RT_NOT_USER && SharedNetworkData::getInstance()->getHostID() != destinationId || 255 recieverType == RT_USER && SharedNetworkData::getInstance()->getHostID() == destinationId || 256 recieverType == RT_SERVER && SharedNetworkData::getInstance()->isMasterServer() || 257 recieverType == RT_SERVER && SharedNetworkData::getInstance()->isProxyServerActive()) 196 258 { 197 NetworkMessage msg; 198 199 msg.data = new byte[messageLength]; 200 memcpy( msg.data, data + i, messageLength ); 201 msg.length = messageLength; 202 msg.messageId = (MessageId)messageId; 203 msg.number = userId; 204 205 incomingMessageBuffer.push_back( msg ); 259 260 PRINTF(0)("<<< MessageManager: got msg with type: %i, from sender %i, to rec: %i\n", messageType, senderId, destinationId); 261 // call the handler function and handle errors 262 if ( !(*(messageHandlerMap[(MessageType)messageType].cb))( (MessageType)messageType, data + i, messageLength, 263 messageHandlerMap[(MessageType)messageType].someData, senderId, destinationId ) ) 264 { 265 // if the message is not handled correctly, bush it back to the incoming packets therefore trying it later 266 NetworkMessage msg; 267 268 msg.data = new byte[messageLength]; 269 memcpy( msg.data, data + i, messageLength ); 270 msg.length = messageLength; 271 msg.messageType = (MessageType)messageType; 272 msg.number = userId; 273 msg.senderId = senderId; 274 msg.recieverType = (RecieverType)recieverType; 275 msg.destinationId = destinationId; 276 277 incomingMessageQueue.push_back( msg ); 278 } 206 279 } 207 messageQueue[userId].recievedMessages.push_back( number ); 280 281 282 // check if the message needs to be forwarded 283 if( recieverType == RT_ALL_BUT_ME || 284 recieverType == RT_ALL_ME || 285 recieverType == RT_NOT_USER || 286 recieverType == RT_USER && SharedNetworkData::getInstance()->getHostID() != destinationId || 287 recieverType == RT_SERVER && SharedNetworkData::getInstance()->isProxyServerActive() ) 288 { 289 // forwarding the messages but only if its a proxy 290 if( SharedNetworkData::getInstance()->isProxyServerActive()) 291 { 292 PRINTF(0)("===========>> Forwarding Message msg with type: %i, from sender %i, to rec: %i\n", messageType, senderId, destinationId); 293 NetworkMessage msg; 294 295 msg.data = new byte[messageLength]; 296 memcpy( msg.data, data + i, messageLength ); 297 msg.length = messageLength; 298 msg.messageType = (MessageType)messageType; 299 msg.number = userId; 300 msg.senderId = senderId; 301 msg.destinationId = destinationId; 302 msg.recieverType = (RecieverType)recieverType; 303 304 this->sendMessage(msg.messageType, msg.data, msg.length, msg.recieverType, msg.senderId = senderId, msg.destinationId, MP_HIGHBANDWIDTH); 305 } 306 } 307 308 // save the serial number for ack signaling 309 outgoingMessageQueue[userId].recievedMessages.push_back( number ); 208 310 } 311 209 312 i += messageLength; 210 313 } 211 314 212 315 213 //TODO maybe handle incomingMessage in tick function. else local messages will not be handled if no clients are connected 214 for ( std::list<NetworkMessage>::iterator it = incomingMessageBuffer.begin(); it != incomingMessageBuffer.end(); ) 215 { 216 if ( (*(messageHandlerMap[it->messageId].cb))( it->messageId, it->data, it->length, messageHandlerMap[it->messageId].someData, it->number ) ) 316 //walk throu message queue and remove acked messages 317 for ( std::list<NetworkMessage>::iterator it = outgoingMessageQueue[userId].messages.begin(); it != outgoingMessageQueue[userId].messages.end(); ) 318 { 319 if ( std::find( acks.begin(), acks.end(), it->number) != acks.end() ) 320 { 321 std::list<NetworkMessage>::iterator delIt = it; 322 it++; 323 outgoingMessageQueue[userId].messages.erase( delIt ); 324 continue; 325 } 326 it++; 327 } 328 329 //TODO find bether way. maybe with timestamp 330 if ( outgoingMessageQueue[userId].recievedMessages.size() > 1000 ) 331 { 332 for ( int j = 0; j < (int)outgoingMessageQueue[userId].recievedMessages.size() - 1000; j++ ) 333 outgoingMessageQueue[userId].recievedMessages.erase( outgoingMessageQueue[userId].recievedMessages.begin() ); 334 } 335 336 return i; 337 } 338 339 340 341 342 /** 343 * processes the message manager data, specialy check for localy generated messages 344 */ 345 void MessageManager::processData() 346 { 347 // now call the message handlers with the new message 348 for ( std::list<NetworkMessage>::iterator it = incomingMessageQueue.begin(); it != incomingMessageQueue.end(); ) 349 { 350 PRINTF(0)("<<< MessageManager: got local msg with type: %i, from sender %i, to rec: %i\n", (*it).messageType, (*it).senderId, (*it).destinationId); 351 352 if ( (*(messageHandlerMap[it->messageType].cb))( it->messageType, it->data, it->length, messageHandlerMap[it->messageType].someData, 353 /*it->number, */it->senderId, it->destinationId ) ) 217 354 { 218 355 std::list<NetworkMessage>::iterator delIt = it; … … 220 357 delete it->data; 221 358 it++; 222 incomingMessage Buffer.erase( delIt );359 incomingMessageQueue.erase( delIt ); 223 360 continue; 224 361 } … … 226 363 } 227 364 228 //walk throu message queue and remove acked messages 229 for ( std::list<NetworkMessage>::iterator it = messageQueue[userId].messages.begin(); it != messageQueue[userId].messages.end(); ) 230 { 231 if ( std::find( acks.begin(), acks.end(), it->number) != acks.end() ) 232 { 233 std::list<NetworkMessage>::iterator delIt = it; 234 it++; 235 messageQueue[userId].messages.erase( delIt ); 236 continue; 237 } 238 it++; 239 } 240 241 //TODO find bether way. maybe with timestamp 242 if ( messageQueue[userId].recievedMessages.size() > 1000 ) 243 { 244 for ( int j = 0; j < messageQueue[userId].recievedMessages.size() - 1000; j++ ) 245 messageQueue[userId].recievedMessages.erase( messageQueue[userId].recievedMessages.begin() ); 246 } 247 248 return i; 249 } 365 } 366 367 368 250 369 251 370 /** … … 255 374 void MessageManager::cleanUpUser( int userId ) 256 375 { 257 if ( messageQueue.find( userId ) == messageQueue.end() )376 if ( outgoingMessageQueue.find( userId ) == outgoingMessageQueue.end() ) 258 377 return; 259 378 260 for ( std::list<NetworkMessage>::iterator it = messageQueue[userId].messages.begin(); it != messageQueue[userId].messages.end(); it++ )379 for ( std::list<NetworkMessage>::iterator it = outgoingMessageQueue[userId].messages.begin(); it != outgoingMessageQueue[userId].messages.end(); it++ ) 261 380 { 262 381 if ( it->data ) … … 265 384 } 266 385 267 messageQueue[userId].toAck.clear();268 269 messageQueue.erase( userId );270 } 271 272 /** 273 * registers function to handle messages with id message Id. someData is passed to callbackfuntion274 * @param message Idmessage id to handle386 outgoingMessageQueue[userId].toAck.clear(); 387 388 outgoingMessageQueue.erase( userId ); 389 } 390 391 /** 392 * registers function to handle messages with id messageType. someData is passed to callbackfuntion 393 * @param messageType message id to handle 275 394 * @param cb function pointer to callback function 276 395 * @param someData this pointer is passed to callback function without modification 277 396 * @return true on success 278 397 */ 279 bool MessageManager::registerMessageHandler( Message Id messageId, MessageCallback cb, void * someData )398 bool MessageManager::registerMessageHandler( MessageType messageType, MessageCallback cb, void * someData ) 280 399 { 281 400 MessageHandler messageHandler; 282 401 283 402 messageHandler.cb = cb; 284 messageHandler.message Id = messageId;403 messageHandler.messageType = messageType; 285 404 messageHandler.someData = someData; 286 405 287 messageHandlerMap[message Id] = messageHandler;406 messageHandlerMap[messageType] = messageHandler; 288 407 289 408 return true; … … 297 416 { 298 417 // just do something so map creates a new entry 299 messageQueue[userId].toAck.clear(); 300 //assert( messageQueue[userId].messages.size() == 0 ); 301 } 418 outgoingMessageQueue[userId].toAck.clear(); 419 //assert( outgoingMessageQueue[userId].messages.size() == 0 ); 420 } 421 422 302 423 303 424 /** … … 308 429 * RT_NOT_USER send to all but reciever 309 430 * 310 * @param message Idmessage id431 * @param messageType message id 311 432 * @param data pointer to data 312 433 * @param dataLength length of data 313 * @param recieverType 314 * @param reciever 315 */ 316 void MessageManager::sendMessage( MessageId messageId, byte * data, int dataLength, RecieverType recieverType, int reciever, MessagePriority messagePriority ) 317 { 318 for ( MessageQueue::iterator it = messageQueue.begin(); it != messageQueue.end(); it++ ) 319 { 434 * @param recieverType type of the receiver 435 * @param reciever the userId of the receiver if needed (depends on the ReceiverType) 436 */ 437 void MessageManager::sendMessage( MessageType messageType, byte * data, int dataLength, RecieverType recieverType, int reciever, MessagePriority messagePriority ) 438 { 439 this->sendMessage(messageType, data, dataLength, recieverType, SharedNetworkData::getInstance()->getHostID(), reciever, messagePriority); 440 } 441 442 443 /** 444 * send a message to one or more clients as a special client 445 * recieverType: 446 * RT_ALL send to all users. reciever is ignored 447 * RT_USER send only to reciever 448 * RT_NOT_USER send to all but reciever 449 * 450 * @param messageType message id 451 * @param data pointer to data 452 * @param dataLength length of data 453 * @param recieverType type of the receiver 454 * @param sender the userId of the sender if there is need for shadowing it (eg. for msg forwarding) 455 * @param reciever the userId of the receiver if needed (depends on the ReceiverType) 456 */ 457 void MessageManager::sendMessage( MessageType messageType, byte * data, int dataLength, RecieverType recieverType, int sender, int reciever, MessagePriority messagePriority ) 458 { 459 PRINTF(0)(" >>> MessageManager: sending msg with type: %i, recieverType: %i, reciever %i\n", messageType, recieverType, reciever); 460 461 // go through all outgoing message queues and add the message if its appropriate 462 for ( MessageQueue::iterator it = this->outgoingMessageQueue.begin(); it != this->outgoingMessageQueue.end(); it++ ) 463 { 464 320 465 if ( 321 recieverType == RT_ALL_ME || 322 recieverType == RT_ALL_BUT_ME || 323 recieverType == RT_USER && it->first == reciever || 324 recieverType == RT_NOT_USER && it->first != reciever || 325 recieverType == RT_SERVER && getNetworkStream()->isUserMasterServer( it->first ) || 326 recieverType == RT_SERVER && getNetworkStream()->isUserProxyServerActive( it->first ) 327 ) 466 recieverType == RT_ALL_ME || 467 recieverType == RT_ALL_BUT_ME || 468 recieverType == RT_USER && it->first == reciever || 469 recieverType == RT_USER && reciever == NET_ID_MASTER_SERVER && !getNetworkStream()->isUserMasterServer( it->first ) || //(*) 470 recieverType == RT_NOT_USER && it->first != reciever || 471 recieverType == RT_SERVER && getNetworkStream()->isUserMasterServer( it->first ) || 472 recieverType == RT_SERVER && getNetworkStream()->isUserProxyServerActive( it->first ) 473 )// (*) special case: forward 328 474 { 329 475 NetworkMessage msg; … … 332 478 memcpy( msg.data, data, dataLength ); 333 479 msg.length = dataLength; 334 msg.messageId = messageId; 335 msg.number = newNumber++; 480 msg.messageType = messageType; 481 msg.number = this->newNumber++; 482 msg.senderId = sender; 483 msg.destinationId = reciever; 484 msg.recieverType = recieverType; 336 485 msg.priority = messagePriority; 337 486 338 487 it->second.messages.push_back( msg ); 339 488 } 340 } 341 342 if ( recieverType == RT_ALL_ME ) 489 490 491 } 492 493 494 // if the message is also for myself, handle it here 495 if ( recieverType == RT_ALL_ME || 496 recieverType == RT_USER && reciever == SharedNetworkData::getInstance()->getHostID() 497 ) 343 498 { 344 499 NetworkMessage msg; … … 347 502 memcpy( msg.data, data, dataLength ); 348 503 msg.length = dataLength; 349 msg.message Id = messageId;504 msg.messageType = messageType; 350 505 msg.number = SharedNetworkData::getInstance()->getHostID(); 506 msg.senderId = sender; 507 msg.destinationId = reciever; 508 msg.recieverType = recieverType; 351 509 msg.priority = messagePriority; 352 510 353 incomingMessageBuffer.push_back( msg );354 } 355 } 356 357 511 this->incomingMessageQueue.push_back( msg ); 512 } 513 } 514 515 -
trunk/src/lib/network/message_manager.h
r9494 r9656 20 20 int length 21 21 int number 22 int Message Id22 int MessageType 23 23 byte * data 24 24 )[1..nmsg] … … 26 26 27 27 28 enum MessageId 28 //!< different message ids 29 enum MessageType 29 30 { 30 TESTMESSAGEID = 1, 31 MSGID_DELETESYNCHRONIZEABLE, 32 MSGID_PREFEREDTEAM, 33 MSGID_CHANGENICKNAME, 34 MSGID_CHATMESSAGE, 35 MSGID_RESPAWN 31 TESTMESSAGEID = 1, //!< for testing purposes 32 MSGID_DELETESYNCHRONIZEABLE, //!< message for sync deletion 33 MSGID_PREFEREDTEAM, //!< change prefered team 34 MSGID_CHANGENICKNAME, //!< change nicknames 35 MSGID_CHATMESSAGE, //!< chat message 36 MSGID_RESPAWN, //!< respawn message 37 38 MSGID_PROXY_NEWCLIENT, //!< informs the master server about a new client 39 MSGID_PROXY_LEAVECLIENT, //!< informs the master and other proxy servers about a leaving client 40 MSGID_PROXY_COMMAND, //!< command handler: delivers commands from and to proxies/clients 36 41 }; 37 42 38 typedef bool (*MessageCallback)( MessageId messageId, byte * data, int dataLength, void * someData, int userId );39 43 40 enum RecieverType 44 typedef bool (*MessageCallback)( MessageType messageType, byte * data, int dataLength, void * someData, int senderId, int destinationId ); 45 46 typedef enum RecieverType 41 47 { 42 48 RT_ALL_BUT_ME = 1, //!< message is sent to all users but myself … … 57 63 struct NetworkMessage 58 64 { 59 MessageId messageId; 60 byte * data; 61 int length; 62 int number; 63 MessagePriority priority; 65 MessageType messageType; //!< type of the message 66 byte * data; //!< data 67 int length; //!< length of the data 68 int number; //!< serial number 69 int senderId; //!< userId of the sender 70 int destinationId; //!< userId of the destination 71 RecieverType recieverType; //!< type of the receiver 72 MessagePriority priority; //!< priority of the messages 64 73 }; 65 74 … … 73 82 typedef std::map<int,MessageUserQueue> MessageQueue; 74 83 84 85 75 86 struct MessageHandler 76 87 { 77 MessageCallback cb;78 Message Id messageId;79 void * someData;88 MessageCallback cb; 89 MessageType messageType; 90 void * someData; 80 91 }; 81 92 82 typedef std::map<Message Id,MessageHandler> MessageHandlerMap;93 typedef std::map<MessageType,MessageHandler> MessageHandlerMap; 83 94 84 95 //! A class for sending messages over network 85 96 class MessageManager : public Synchronizeable { 86 protected: 87 MessageManager(); 97 98 88 99 public: 89 100 inline static MessageManager * getInstance(){ if (!singletonRef) singletonRef = new MessageManager(); return singletonRef; } … … 91 102 virtual ~MessageManager(); 92 103 93 bool registerMessageHandler( Message Id messageId, MessageCallback cb, void * someData );104 bool registerMessageHandler( MessageType messageType, MessageCallback cb, void * someData ); 94 105 95 void sendMessage( MessageId messageId, byte * data, int dataLength, RecieverType recieverType, int reciever, MessagePriority messagePriority ); 106 void sendMessage( MessageType messageType, byte * data, int dataLength, RecieverType recieverType, int reciever, MessagePriority messagePriority ); 107 void sendMessage( MessageType messageType, byte * data, int dataLength, RecieverType recieverType, int sender, int reciever, MessagePriority messagePriority ); 96 108 109 void initUser( int userId ); 110 111 void processData(); 112 113 114 protected: 115 MessageManager(); 116 117 118 private: 97 119 virtual int getStateDiff( int userId, byte* data, int maxLength, int stateId, int fromStateId, int priorityTH ); 98 120 virtual int setStateDiff( int userId, byte* data, int length, int stateId, int fromStateId ); … … 101 123 virtual void handleRecvState( int userId, int stateId, int fromStateId ){} 102 124 103 void initUser( int userId );104 105 125 106 126 private: 107 static MessageManager * singletonRef; 108 MessageQueue messageQueue; //!< stores messages to send 127 static MessageManager * singletonRef; //!< the singleton reference 128 129 std::list<NetworkMessage> incomingMessageQueue; //!< the incoming message buffer 130 MessageQueue outgoingMessageQueue; //!< stores messages to send 109 131 MessageHandlerMap messageHandlerMap; //!< contains handlers for messages 110 132 111 133 int newNumber; //!< used to create unique message numbers 112 std::list<NetworkMessage> incomingMessageBuffer; 134 113 135 114 136 }; 115 137 116 #endif /* _ PROTO_CLASS_H */138 #endif /* _MESSAGE_MANAGER_H */ -
trunk/src/lib/network/monitor/network_monitor.cc
r9494 r9656 10 10 11 11 ### File Specific: 12 main-programmer: Patrick Boenzli 12 main-programmer: Patrick Boenzli (patrick@orxonox.ethz.ch) 13 13 */ 14 14 … … 49 49 this->networkStream = networkStream; 50 50 this->playerNumber = 0; 51 this->connectionNumber = 0; 51 52 // create the localnode, init it and add it to the nodes list 52 53 this->localNode = new NetworkNode( this->networkStream->getPeerInfo()); … … 66 67 PeerInfo* peer = new PeerInfo(); 67 68 peer->ip = (*it); 68 peer->nodeType = NET_PROXY_SERVER_ ACTIVE;69 peer->nodeType = NET_PROXY_SERVER_PASSIVE; 69 70 peer->userId = -1; 70 71 71 NetworkNode* node = new NetworkNode(peer);72 this->addNode( node);73 72 this->addActiveProxyServer( this->localNode, peer); 74 73 } … … 141 140 return; 142 141 142 PRINTF(0)("^^^^^^^^^^^^^^^^^^^^^^^^^^ adding node: %i with type: %s\n\n", pInfo->userId, pInfo->getNodeTypeString().c_str()); 143 143 144 if( pInfo->isClient()) 144 this->localNode->addClient(pInfo); 145 { 146 this->localNode->addClient(new NetworkNode(pInfo)); 147 } 145 148 else if( pInfo->isProxyServerActive()) 146 149 { 147 this->localNode->addActiveProxyServer(pInfo); 148 // create a new node, since a proxy can connect clients again 149 NetworkNode* node = new NetworkNode(pInfo); 150 this->nodeList.push_back(node); 150 this->localNode->addActiveProxyServer(new NetworkNode(pInfo)); 151 } 152 else if( pInfo->isProxyServerActivePassive()) 153 { 154 this->localNode->addPassiveProxyServer(new NetworkNode(pInfo)); 151 155 } 152 156 else if( pInfo->isMasterServer()) 153 157 { 154 this->localNode->addMasterServer(pInfo); 155 } 158 this->localNode->addMasterServer(new NetworkNode(pInfo)); 159 } 160 else 161 assert(false); 156 162 } 157 163 … … 168 174 169 175 if( pInfo->isClient()) 170 node->addClient( pInfo);176 node->addClient(new NetworkNode(pInfo)); 171 177 else if( pInfo->isProxyServerActive()) 172 node->addActiveProxyServer( pInfo);178 node->addActiveProxyServer(new NetworkNode(pInfo)); 173 179 else if( pInfo->isMasterServer()) 174 node->addMasterServer(pInfo); 180 node->addMasterServer(new NetworkNode(pInfo)); 181 } 182 183 184 185 /** 186 * removes a node from the network monitor 187 * @param pInfo the node to remove 188 */ 189 void NetworkMonitor::removeNode(PeerInfo* pInfo) 190 { 191 this->removeNode(this->localNode, pInfo); 192 } 193 194 195 /** 196 * removes the network node 197 * @param node the network node where the PeerInfo node is connected to 198 * @param pInfo the PeerInfo to remove 199 */ 200 void NetworkMonitor::removeNode(NetworkNode* node, PeerInfo* pInfo) 201 { 202 if( node == NULL || pInfo == NULL) 203 return; 204 205 if( pInfo->isClient()) 206 node->removeClient(pInfo->userId); 207 else if( pInfo->isProxyServerActive()) 208 node->removeActiveProxyServer(pInfo->userId); 209 else if( pInfo->isMasterServer()) 210 node->removeMasterServer(pInfo->userId); 175 211 } 176 212 … … 197 233 198 234 /** 235 * @param userId of the searched node 236 * @returns the PeerInfo of the userId peer 237 */ 238 PeerInfo* NetworkMonitor::getPeerByUserId( int userId) 239 { 240 NetworkNode* node = this->getNodeByUserId(userId); 241 if( node != NULL) 242 return node->getPeerInfo(); 243 244 return NULL; 245 } 246 247 /** 248 * searches for a given NetworkNode 249 * @param userId of the searched node 250 * @returns the PeerInfo of the userId peer 251 */ 252 NetworkNode* NetworkMonitor::getNodeByUserId( int userId) 253 { 254 std::list<NetworkNode*>::iterator it = this->nodeList.begin(); 255 NetworkNode* node = NULL; 256 for(; it != this->nodeList.end(); it++) 257 { 258 node = (*it)->getNodeByUserId(userId); 259 if( node != NULL) 260 return node; 261 } 262 263 return NULL; 264 } 265 266 267 /** 199 268 * this displays the network monitor gui 200 269 */ … … 203 272 if (this->box == NULL) 204 273 { 205 this->box = new OrxGui::GLGuiBox(OrxGui::Vertical); 206 { 207 NetworkStatsWidget* netStats = new NetworkStatsWidget(this); 208 this->box->pack(netStats); 209 210 } 211 274 this->box = new NetworkStatsWidget(this); 212 275 this->box->showAll(); 213 this->box->setAbsCoor2D(300, 40);214 276 } 215 277 else … … 251 313 for(; it != this->nodeList.end(); it++) 252 314 { 253 (*it)->debug( 0);315 (*it)->debug(1); 254 316 } 255 317 -
trunk/src/lib/network/monitor/network_monitor.h
r9494 r9656 42 42 43 43 /** adds to @param node a network node @param pInfo a new client */ 44 inline void addClient(NetworkNode* node, PeerInfo* pInfo) { node->addClient( pInfo); }44 inline void addClient(NetworkNode* node, PeerInfo* pInfo) { node->addClient(new NetworkNode(pInfo)); } 45 45 /** adds to @param node a network node @param pInfo a new proxy server */ 46 inline void addActiveProxyServer(NetworkNode* node, PeerInfo* pInfo) { node->addActiveProxyServer( pInfo); }46 inline void addActiveProxyServer(NetworkNode* node, PeerInfo* pInfo) { node->addActiveProxyServer(new NetworkNode(pInfo)); } 47 47 /** adds to @param node a network node @param pInfo a new proxy server */ 48 inline void addPassiveProxyServer(NetworkNode* node, PeerInfo* pInfo) { node->addPassiveProxyServer( pInfo); }48 inline void addPassiveProxyServer(NetworkNode* node, PeerInfo* pInfo) { node->addPassiveProxyServer(new NetworkNode(pInfo)); } 49 49 /** adds to @param node a network node @param pInfo a new master server*/ 50 inline void addMasterServer(NetworkNode* node, PeerInfo* pInfo) { node->addMasterServer( pInfo); }50 inline void addMasterServer(NetworkNode* node, PeerInfo* pInfo) { node->addMasterServer(new NetworkNode(pInfo)); } 51 51 52 inline void removeClient(NetworkNode* node, PeerInfo* pInfo) { node->removeClient(pInfo); } 53 inline void removeActiveProxyServer(NetworkNode* node, PeerInfo* pInfo) { node->removeActiveProxyServer(pInfo); } 54 inline void removePassiveProxyServer(NetworkNode* node, PeerInfo* pInfo) { node->removePassiveProxyServer(pInfo); } 55 inline void removeMasterServer(NetworkNode* node, PeerInfo* pInfo) { node->removeMasterServer(pInfo); } 52 void removeNode(PeerInfo* pInfo); 53 void removeNode(NetworkNode* node, PeerInfo* pInfo); 54 55 inline void removeClient(NetworkNode* node, int userId) { node->removeClient(userId); } 56 inline void removeActiveProxyServer(NetworkNode* node, int userId) { node->removeActiveProxyServer(userId); } 57 inline void removePassiveProxyServer(NetworkNode* node, int userId) { node->removePassiveProxyServer(userId); } 58 inline void removeMasterServer(NetworkNode* node, int userId) { node->removeMasterServer(userId); } 56 59 57 60 PeerInfo* getFirstChoiceProxy() const; … … 61 64 62 65 /** @returns the active proxy server list of the localnode */ 63 inline std::list< PeerInfo*> getActiveProxyServer() const { return this->localNode->getActiveProxyServer(); }66 inline std::list<NetworkNode*> getActiveProxyServers() const { return this->localNode->getActiveProxyServers(); } 64 67 65 68 /* slots admin and info interface */ … … 76 79 77 80 inline const std::list<NetworkNode*>& getNodeList() const { return this->nodeList; }; 81 PeerInfo* getPeerByUserId( int userId); 82 NetworkNode* getNodeByUserId( int userId); 83 84 /* forced reconnection interface */ 85 inline void setForcedReconnection(IP address) { this->bForcedRecon = true; this->forcedReconnection = address;} 86 inline bool isForcedReconnection() const { return this->bForcedRecon; } 87 inline IP getForcedReconnectionIP() { this->bForcedRecon = false; return this->forcedReconnection; } 88 78 89 79 90 void toggleGUI(); … … 92 103 int playerNumber; //!< total number of players in the game 93 104 int connectionNumber; //!< total number of connections at this localhost 105 106 IP forcedReconnection; //!< ip of a forced reconnection 107 bool bForcedRecon; //!< true if there is a forced recon 94 108 }; 95 109 -
trunk/src/lib/network/monitor/network_node.cc
r9494 r9656 18 18 #include "debug.h" 19 19 20 21 20 /** 22 21 * constructor … … 39 38 * adds a client 40 39 */ 41 void NetworkNode::addClient( PeerInfo* node)40 void NetworkNode::addClient(NetworkNode* node) 42 41 { 43 42 this->clientList.push_back(node); … … 49 48 * adds a proxy server 50 49 */ 51 void NetworkNode::addActiveProxyServer( PeerInfo* node)50 void NetworkNode::addActiveProxyServer(NetworkNode* node) 52 51 { 53 52 this->activeProxyServerList.push_back(node); … … 58 57 * adds a proxy server 59 58 */ 60 void NetworkNode::addPassiveProxyServer( PeerInfo* node)59 void NetworkNode::addPassiveProxyServer(NetworkNode* node) 61 60 { 62 61 this->passiveProxyServerList.push_back(node); … … 66 65 * adds a master server 67 66 */ 68 void NetworkNode::addMasterServer( PeerInfo* node)67 void NetworkNode::addMasterServer(NetworkNode* node) 69 68 { 70 69 this->masterServerList.push_back(node); … … 75 74 * removes a client 76 75 */ 77 void NetworkNode::removeClient( PeerInfo* node)78 { 79 std::list< PeerInfo*>::iterator it = this->clientList.begin();76 void NetworkNode::removeClient(NetworkNode* node) 77 { 78 std::list<NetworkNode*>::iterator it = this->clientList.begin(); 80 79 for(; it != this->clientList.end(); it++) 81 80 { … … 94 93 * removes a proxy server 95 94 */ 96 void NetworkNode::removeActiveProxyServer( PeerInfo* node)97 { 98 std::list< PeerInfo*>::iterator it = this->activeProxyServerList.begin();95 void NetworkNode::removeActiveProxyServer(NetworkNode* node) 96 { 97 std::list<NetworkNode*>::iterator it = this->activeProxyServerList.begin(); 99 98 for(; it != this->activeProxyServerList.end(); it++) 100 99 { … … 113 112 * removes a proxy server 114 113 */ 115 void NetworkNode::removePassiveProxyServer( PeerInfo* node)116 { 117 std::list< PeerInfo*>::iterator it = this->passiveProxyServerList.begin();114 void NetworkNode::removePassiveProxyServer(NetworkNode* node) 115 { 116 std::list<NetworkNode*>::iterator it = this->passiveProxyServerList.begin(); 118 117 for(; it != this->passiveProxyServerList.end(); it++) 119 118 { … … 131 130 * removes a master server 132 131 */ 133 void NetworkNode::removeMasterServer( PeerInfo* node)134 { 135 std::list< PeerInfo*>::iterator it = this->masterServerList.begin();132 void NetworkNode::removeMasterServer(NetworkNode* node) 133 { 134 std::list<NetworkNode*>::iterator it = this->masterServerList.begin(); 136 135 for(; it != this->masterServerList.end(); it++) 137 136 { … … 145 144 146 145 PRINTF(2)("Could not remove client from the list, very strange..."); 146 } 147 148 149 150 151 /** 152 * removes a client 153 */ 154 void NetworkNode::removeClient(int userId) 155 { 156 std::list<NetworkNode*>::iterator it = this->clientList.begin(); 157 for(; it != this->clientList.end(); it++) 158 { 159 if( (*it)->getPeerInfo()->userId == userId) 160 { 161 this->clientList.erase(it); 162 this->playerNumber--; 163 return; 164 } 165 } 166 167 PRINTF(2)("Could not remove client from the list, very strange..."); 168 } 169 170 /** 171 * removes a proxy server 172 */ 173 void NetworkNode::removeActiveProxyServer(int userId) 174 { 175 std::list<NetworkNode*>::iterator it = this->activeProxyServerList.begin(); 176 for(; it != this->activeProxyServerList.end(); it++) 177 { 178 if( (*it)->getPeerInfo()->userId == userId) 179 { 180 this->activeProxyServerList.erase(it); 181 this->playerNumber--; 182 return; 183 } 184 } 185 186 PRINTF(2)("Could not remove proxy server from the list, very strange..."); 187 } 188 189 /** 190 * removes a proxy server 191 */ 192 void NetworkNode::removePassiveProxyServer(int userId) 193 { 194 std::list<NetworkNode*>::iterator it = this->passiveProxyServerList.begin(); 195 for(; it != this->passiveProxyServerList.end(); it++) 196 { 197 if( (*it)->getPeerInfo()->userId == userId) 198 { 199 this->passiveProxyServerList.erase(it); 200 return; 201 } 202 } 203 204 PRINTF(2)("Could not remove proxy server from the list, very strange..."); 205 } 206 207 /** 208 * removes a master server 209 */ 210 void NetworkNode::removeMasterServer(int userId) 211 { 212 std::list<NetworkNode*>::iterator it = this->masterServerList.begin(); 213 for(; it != this->masterServerList.end(); it++) 214 { 215 if( (*it)->getPeerInfo()->userId == userId) 216 { 217 this->masterServerList.erase(it); 218 this->playerNumber--; 219 return; 220 } 221 } 222 223 PRINTF(2)("Could not remove client from the list, very strange..."); 224 } 225 226 227 228 229 230 /** 231 * gets the peer info by user id 232 * @param userId the user id of the node to look up 233 * @return the peer info of this node NULL if nothing found 234 */ 235 PeerInfo* NetworkNode::getPeerByUserId( int userId) 236 { 237 // look through the master server lists 238 std::list<NetworkNode*>::const_iterator it = this->masterServerList.begin(); 239 for( ;it != this->masterServerList.end(); it++) 240 { 241 if( (*it)->getPeerInfo()->userId == userId) 242 return (*it)->getPeerInfo(); 243 } 244 245 // look through the active proxy server list 246 it = this->activeProxyServerList.begin(); 247 for( ; it != this->activeProxyServerList.end(); it++) 248 { 249 if( (*it)->getPeerInfo()->userId == userId) 250 return (*it)->getPeerInfo(); 251 } 252 253 // look through the passive server list 254 it = this->passiveProxyServerList.begin(); 255 for( ; it != this->passiveProxyServerList.end(); it++) 256 { 257 if( (*it)->getPeerInfo()->userId == userId) 258 return (*it)->getPeerInfo(); 259 } 260 261 // look through the client list 262 it = this->clientList.begin(); 263 for( ; it != this->clientList.end(); it++) 264 { 265 if( (*it)->getPeerInfo()->userId == userId) 266 return (*it)->getPeerInfo(); 267 } 268 269 return NULL; 147 270 } 148 271 … … 154 277 PeerInfo* NetworkNode::getClient(int index) const 155 278 { 156 if( this->clientList.size() < index)279 if( (int)this->clientList.size() < index) 157 280 return NULL; 158 281 159 std::list< PeerInfo*>::const_iterator it = this->clientList.begin();282 std::list<NetworkNode*>::const_iterator it = this->clientList.begin(); 160 283 for(int i = 0; it != this->clientList.end(); it++, i++) 161 284 { 162 285 if( i == index) 163 return (*it) ;286 return (*it)->getPeerInfo(); 164 287 } 165 288 … … 174 297 PeerInfo* NetworkNode::getActiveProxyServer(int index) const 175 298 { 176 if( this->activeProxyServerList.size() < index)299 if( (int)this->activeProxyServerList.size() < index) 177 300 return NULL; 178 301 179 std::list< PeerInfo*>::const_iterator it = this->activeProxyServerList.begin();302 std::list<NetworkNode*>::const_iterator it = this->activeProxyServerList.begin(); 180 303 for(int i = 0; it != this->activeProxyServerList.end(); it++, i++) 181 304 { 182 305 if( i == index) 183 return (*it) ;306 return (*it)->getPeerInfo(); 184 307 } 185 308 … … 194 317 PeerInfo* NetworkNode::getPassiveProxyServer(int index) const 195 318 { 196 if( this->passiveProxyServerList.size() < index)319 if( (int)this->passiveProxyServerList.size() < index) 197 320 return NULL; 198 321 199 std::list< PeerInfo*>::const_iterator it = this->passiveProxyServerList.begin();322 std::list<NetworkNode*>::const_iterator it = this->passiveProxyServerList.begin(); 200 323 for(int i = 0; it != this->passiveProxyServerList.end(); it++, i++) 201 324 { 202 325 if( i == index) 203 return (*it) ;326 return (*it)->getPeerInfo(); 204 327 } 205 328 … … 214 337 PeerInfo* NetworkNode::getMasterServer(int index) const 215 338 { 216 if( this->masterServerList.size() < index)339 if( (int)this->masterServerList.size() < index) 217 340 return NULL; 218 341 219 std::list< PeerInfo*>::const_iterator it = this->masterServerList.begin();342 std::list<NetworkNode*>::const_iterator it = this->masterServerList.begin(); 220 343 for(int i = 0; it != this->masterServerList.end(); it++, i++) 221 344 { 222 345 if( i == index) 223 return (*it); 346 return (*it)->getPeerInfo(); 347 } 348 349 return NULL; 350 } 351 352 353 354 /** 355 * searches for a given NetworkNode 356 * @param userId of the searched node 357 * @returns the PeerInfo of the userId peer 358 */ 359 NetworkNode* NetworkNode::getNodeByUserId( int userId) 360 { 361 if( this->peerInfo->userId == userId) 362 return this; 363 364 365 NetworkNode* node = NULL; 366 std::list<NetworkNode*>::const_iterator it = this->masterServerList.begin(); 367 368 for(; it != this->masterServerList.end(); it++) 369 { 370 node = (*it)->getNodeByUserId(userId); 371 if( node != NULL) 372 return node; 373 } 374 375 it = this->activeProxyServerList.begin(); 376 for(; it != this->activeProxyServerList.end(); it++) 377 { 378 node = (*it)->getNodeByUserId(userId); 379 if( node != NULL) 380 return node; 381 } 382 383 it = this->passiveProxyServerList.begin(); 384 for(; it != this->passiveProxyServerList.end(); it++) 385 { 386 node = (*it)->getNodeByUserId(userId); 387 if( node != NULL) 388 return node; 389 } 390 391 it = this->clientList.begin(); 392 for(; it != this->clientList.end(); it++) 393 { 394 node = (*it)->getNodeByUserId(userId); 395 if( node != NULL) 396 return node; 224 397 } 225 398 … … 234 407 void NetworkNode::debug(int depth) const 235 408 { 236 PRINT(0)(" = %s\n", this->peerInfo->getNodeTypeString().c_str()); 237 238 PRINT(0)(" master servers: %i\n", this->masterServerList.size()); 239 std::list<PeerInfo*>::const_iterator it = this->masterServerList.begin(); 240 for(; it != this->masterServerList.end(); it++) 241 { 242 IP* ip = &(*it)->ip; 243 PRINT(0)(" - ms, id: %i (%s)\n", (*it)->userId, ip->ipString().c_str()); 244 } 245 246 PRINT(0)(" proxy servers active: %i\n", this->activeProxyServerList.size()); 247 it = this->activeProxyServerList.begin(); 248 for(; it != this->activeProxyServerList.end(); it++) 249 { 250 IP* ip = &(*it)->ip; 251 PRINT(0)(" - ps-a, id: %i (%s)\n", (*it)->userId, ip->ipString().c_str()); 252 } 253 254 PRINT(0)(" proxy servers passive: %i\n", this->passiveProxyServerList.size()); 255 it = this->passiveProxyServerList.begin(); 256 for(; it != this->passiveProxyServerList.end(); it++) 257 { 258 IP* ip = &(*it)->ip; 259 PRINT(0)(" - ps-p, id: %i (%s)\n", (*it)->userId, ip->ipString().c_str()); 260 } 261 262 PRINT(0)(" clients: %i\n", this->clientList.size()); 263 it = this->clientList.begin(); 264 for(; it != this->clientList.end(); it++) 265 { 266 IP* ip = &(*it)->ip; 267 PRINT(0)(" - client, id: %i (%s)\n", (*it)->userId, ip->ipString().c_str()); 268 } 269 } 270 409 char indent[depth +1]; 410 for( int i = 0; i < depth; i++) { indent[i] = ' '; } 411 indent[depth] = '\0'; 412 413 PRINT(0)("%s + %s, with id %i and ip: %s\n", indent, this->peerInfo->getNodeTypeString().c_str(), this->peerInfo->userId, this->peerInfo->ip.ipString().c_str()); 414 415 416 417 std::list<NetworkNode*>::const_iterator it; 418 if( !this->masterServerList.empty()) 419 { 420 it = this->masterServerList.begin(); 421 422 for(; it != this->masterServerList.end(); it++) 423 { 424 (*it)->debug(depth+1); 425 } 426 } 427 428 if( !this->activeProxyServerList.empty()) 429 { 430 it = this->activeProxyServerList.begin(); 431 432 for(; it != this->activeProxyServerList.end(); it++) 433 { 434 (*it)->debug(depth+1); 435 } 436 } 437 438 439 if( !this->passiveProxyServerList.empty()) 440 { 441 it = this->passiveProxyServerList.begin(); 442 443 for(; it != this->passiveProxyServerList.end(); it++) 444 { 445 (*it)->debug(depth+1); 446 } 447 } 448 449 if( !this->clientList.empty()) 450 { 451 it = this->clientList.begin(); 452 453 for(; it != this->clientList.end(); it++) 454 { 455 (*it)->debug(depth+1); 456 } 457 } 458 } 459 -
trunk/src/lib/network/monitor/network_node.h
r9494 r9656 13 13 #include <list> 14 14 15 16 15 //!< a class representing a node in the network (this can be a MASTER_SERVER, PROXY_SERVER or a CLIENT 17 16 class NetworkNode … … 22 21 23 22 24 void addClient( PeerInfo* node);25 void addActiveProxyServer( PeerInfo* node);26 void addPassiveProxyServer( PeerInfo* node);27 void addMasterServer( PeerInfo* node);23 void addClient(NetworkNode* node); 24 void addActiveProxyServer(NetworkNode* node); 25 void addPassiveProxyServer(NetworkNode* node); 26 void addMasterServer(NetworkNode* node); 28 27 29 void removeClient(PeerInfo* node); 30 void removeActiveProxyServer(PeerInfo* node); 31 void removePassiveProxyServer(PeerInfo* node); 32 void removeMasterServer(PeerInfo* node); 28 void removeClient(NetworkNode* node); 29 void removeActiveProxyServer(NetworkNode* node); 30 void removePassiveProxyServer(NetworkNode* node); 31 void removeMasterServer(NetworkNode* node); 32 33 void removeClient(int userId); 34 void removeActiveProxyServer(int userId); 35 void removePassiveProxyServer(int userId); 36 void removeMasterServer(int userId); 37 33 38 34 39 PeerInfo* getClient(int index) const; … … 38 43 39 44 /** @returns the master server list */ 40 inline std::list< PeerInfo*> getMasterServer() const { return this->masterServerList; }45 inline std::list<NetworkNode*> getMasterServers() const { return this->masterServerList; } 41 46 /** @returns the active proxy server list */ 42 inline std::list< PeerInfo*> getActiveProxyServer() const { return this->activeProxyServerList; }47 inline std::list<NetworkNode*> getActiveProxyServers() const { return this->activeProxyServerList; } 43 48 /** @returns the passive proxy server list */ 44 inline std::list< PeerInfo*> getPassiveProxyServer() const { return this->passiveProxyServerList; }49 inline std::list<NetworkNode*> getPassiveProxyServers() const { return this->passiveProxyServerList; } 45 50 /** @returns the client list */ 46 inline std::list< PeerInfo*> getClient() const { return this->clientList; }51 inline std::list<NetworkNode*> getClients() const { return this->clientList; } 47 52 53 PeerInfo* getPeerByUserId( int userId); 48 54 49 55 /** @returns the number of players */ … … 53 59 /** @returns the peer info of this node */ 54 60 inline PeerInfo* getPeerInfo() const { return this->peerInfo; } 61 62 NetworkNode* getNodeByUserId( int userId); 55 63 56 64 void debug(int depth) const; … … 63 71 64 72 /* network nodes directly connected to this node */ 65 std::list< PeerInfo*> clientList; //!< list of all clients in the network66 std::list< PeerInfo*> activeProxyServerList; //!< list of all proxy servers in the network67 std::list< PeerInfo*> passiveProxyServerList; //!< list of all proxy servers in the network68 std::list< PeerInfo*> masterServerList; //!< list of all master servers in the network (should be 1!! :D)73 std::list<NetworkNode*> clientList; //!< list of all clients in the network 74 std::list<NetworkNode*> activeProxyServerList; //!< list of all proxy servers in the network 75 std::list<NetworkNode*> passiveProxyServerList; //!< list of all proxy servers in the network 76 std::list<NetworkNode*> masterServerList; //!< list of all master servers in the network (should be 1!! :D) 69 77 70 78 }; -
trunk/src/lib/network/monitor/network_stats_widget.cc
r9494 r9656 18 18 #include "network_stats_widget.h" 19 19 #include "network_monitor.h" 20 #include "peer_info.h" 20 21 21 22 #include "multi_type.h" … … 23 24 #include "shell_command.h" 24 25 25 // SHELL_COMMAND(gui, NetworkMonitor, toggleGUI) 26 // ->setAlias("ProxyGui"); 26 #include "loading/resource_manager.h" 27 28 // this fcuk does not work! 29 // SHELL_COMMAND(gui, NetworkStatsWidget, toggleGUI) 30 // ->setAlias("ProxyGui"); 27 31 28 32 … … 30 34 : GLGuiBox(OrxGui::Horizontal) 31 35 { 36 this->init(); 37 32 38 this->setName(name); 33 39 this->setIP(ip); 34 40 41 } 42 43 HostWidget::HostWidget(const PeerInfo* peerInfo) 44 : GLGuiBox(OrxGui::Horizontal) 45 { 46 this->init(); 47 if (peerInfo == NULL) 48 { 49 this->setName("INVALID"); 50 return; 51 } 52 this->setName(peerInfo->getNodeTypeString() + "ID: " + MultiType(peerInfo->userId).getString()); 53 this->setIP(peerInfo->ip); 54 } 55 56 void HostWidget::init() 57 { 58 if(_font == NULL) 59 _font = new Font(ResourceManager::getInstance()->getDataDir() + "/fonts/arial.ttf", 20); 60 61 //this->_name.setFont(*_font); 62 this->_name.setTextSize(15); 63 //this->_ip.setFont(*_font); 64 this->_ip.setTextSize(15); 65 35 66 this->pack(&this->_name); 36 67 this->pack(&this->_ip); … … 49 80 } 50 81 82 Font* HostWidget::_font = NULL; 83 84 51 85 52 86 … … 54 88 55 89 56 ProxyWidget::ProxyWidget(const std::string& proxyName, const IP& ip)90 NodeWidget::NodeWidget(const std::string& proxyName, const IP& ip) 57 91 : _proxyWidget(proxyName, ip) 58 92 { 59 this->_ clientNameWidth = 100.0f;93 this->_nodeNameWidth = 100.0f; 60 94 this->pack(&_proxyWidget); 61 95 } 62 96 63 void ProxyWidget::addClient(const std::string& name, const IP& ip) 97 NodeWidget::NodeWidget(const NetworkNode* node) 98 : _proxyWidget(node->getPeerInfo())// "node", node->getPeerInfo()->ip) 99 { 100 this->_nodeNameWidth = 100.0f; 101 this->pack(&_proxyWidget); 102 103 std::list<NetworkNode*> list = node->getMasterServers(); 104 std::list<NetworkNode*>::const_iterator it; 105 106 for(it = list.begin(); it != list.end(); it++) 107 this->addNode(*it); 108 109 list = node->getActiveProxyServers(); 110 for(it = list.begin(); it != list.end(); it++) 111 this->addNode(*it); 112 113 list = node->getPassiveProxyServers(); 114 for(it = list.begin(); it != list.end(); it++) 115 this->addNode(*it); 116 117 list = node->getClients(); 118 for(it = list.begin(); it != list.end(); it++) 119 this->addNode(*it); 120 } 121 122 123 void NodeWidget::addNode(const NetworkNode* node) 124 { 125 this->_nodes.push_back(new NodeWidget(node)); 126 this->pack(this->_nodes.back()); 127 this->_nodes.back()->show(); 128 } 129 130 131 void NodeWidget::addNode(const std::string& name, const IP& ip) 64 132 { 65 133 HostWidget* newClient = new HostWidget(name, ip); 66 newClient->setNameWidth(this->_ clientNameWidth);134 newClient->setNameWidth(this->_nodeNameWidth); 67 135 68 136 this->pack(newClient); … … 72 140 } 73 141 74 bool ProxyWidget::removeClient(const IP& ip)75 { 76 std::vector<HostWidget*>::iterator rmIt;77 for(rmIt = this->_clients.begin(); rmIt != this->_clients.end(); ++rmIt)78 {79 if (*(*rmIt) == ip)80 {81 delete (*rmIt);82 this->_clients.erase(rmIt);83 return true;84 }85 }86 return false;87 } 88 89 bool ProxyWidget::removeClient(const std::string& name)90 { 91 std::vector<HostWidget*>::iterator rmIt;92 for(rmIt = this->_clients.begin(); rmIt != this->_clients.end(); ++rmIt)93 {94 if (*(*rmIt) == name)95 {96 delete (*rmIt);97 this->_clients.erase(rmIt);98 return true;99 }100 }101 return false;102 103 } 104 105 bool ProxyWidget::removeClient(const std::string& name, const IP& ip)106 { 107 std::vector<HostWidget*>::iterator rmIt;108 for(rmIt = this->_clients.begin(); rmIt != this->_clients.end(); ++rmIt)109 {110 if (*(*rmIt) == ip && *(*rmIt) == name)111 {112 delete (*rmIt);113 this->_clients.erase(rmIt);114 return true;115 }116 }117 return false;118 } 119 120 121 void ProxyWidget::setClientNameWidths(float width)122 { 123 this->_clientNameWidth = width;124 for (unsigned int i = 0; i < this->_ clients.size(); ++i)125 this->_ clients[i]->setNameWidth(width);126 } 127 128 void ProxyWidget::hiding()142 bool NodeWidget::removeNode(const IP& ip) 143 { 144 // std::vector<HostWidget*>::iterator rmIt; 145 // for(rmIt = this->_nodes.begin(); rmIt != this->_nodes.end(); ++rmIt) 146 // { 147 // if (*(*rmIt) == ip) 148 // { 149 // delete (*rmIt); 150 // this->_nodes.erase(rmIt); 151 // return true; 152 // } 153 // } 154 // return false; 155 } 156 157 bool NodeWidget::removeNode(const std::string& name) 158 { 159 // std::vector<HostWidget*>::iterator rmIt; 160 // for(rmIt = this->_nodes.begin(); rmIt != this->_nodes.end(); ++rmIt) 161 // { 162 // if (*(*rmIt) == name) 163 // { 164 // delete (*rmIt); 165 // this->_nodes.erase(rmIt); 166 // return true; 167 // } 168 // } 169 // return false; 170 171 } 172 173 bool NodeWidget::removeNode(const std::string& name, const IP& ip) 174 { 175 // std::vector<HostWidget*>::iterator rmIt; 176 // for(rmIt = this->_nodes.begin(); rmIt != this->_nodes.end(); ++rmIt) 177 // { 178 // if (*(*rmIt) == ip && *(*rmIt) == name) 179 // { 180 // delete (*rmIt); 181 // this->_nodes.erase(rmIt); 182 // return true; 183 // } 184 // } 185 // return false; 186 } 187 188 189 void NodeWidget::setNodeNameWidths(float width) 190 { 191 /* this->_nodeNameWidth = width; 192 for (unsigned int i = 0; i < this->_nodes.size(); ++i) 193 this->_nodes[i]->setNameWidth(width);*/ 194 } 195 196 void NodeWidget::hiding() 129 197 { 130 198 this->_proxyWidget.hide(); 131 for (unsigned int i = 0; i < this->_ clients.size(); ++i)132 this->_ clients[i]->hide();133 } 134 135 void ProxyWidget::showing()199 for (unsigned int i = 0; i < this->_nodes.size(); ++i) 200 this->_nodes[i]->hide(); 201 } 202 203 void NodeWidget::showing() 136 204 { 137 205 this->_proxyWidget.show(); 138 for (unsigned int i = 0; i < this->_ clients.size(); ++i)139 this->_ clients[i]->show();206 for (unsigned int i = 0; i < this->_nodes.size(); ++i) 207 this->_nodes[i]->show(); 140 208 } 141 209 … … 147 215 */ 148 216 NetworkStatsWidget::NetworkStatsWidget(const NetworkMonitor* monitor) 149 : GLGuiBox(OrxGui::Vertical), _thisHost("myName", IP(127, 0, 0 , 1))217 : OrxGui::GLGuiFixedpositionBox(OrxGui::Center, OrxGui::Vertical), _thisHost("myName", IP(127, 0, 0 , 1)) 150 218 { 151 219 this->_monitor = monitor; 220 this->_passedTime = 0.0f; 152 221 153 222 /* … … 169 238 this->_bar.setChangedValueColor(Color::black); 170 239 */ 240 this->_thisHostIs.setText(std::string("I am ") + _monitor->getLocalNode()->getPeerInfo()->getNodeTypeString()); 241 242 this->pack(&this->_thisHostIs); 243 171 244 this->pack(&this->_thisHost); 245 246 this->pack(&this->_serverBox); 172 247 173 248 this->pack(&this->_upstreamText); 174 249 this->pack(&this->_downstreamText); 175 250 176 this->pack(&this->_serverIP); 251 252 this->rebuild(); 177 253 } 178 254 … … 183 259 NetworkStatsWidget::~NetworkStatsWidget () 184 260 {} 261 262 263 void NetworkStatsWidget::addNode(const NetworkNode* node) 264 { 265 this->_proxies.push_back(new NodeWidget(node)); 266 this->_serverBox.pack(this->_proxies.back()); 267 this->_proxies.back()->show(); 268 } 269 270 271 272 273 NetworkStatsWidget* NetworkStatsWidget::_statsWidget = NULL; 274 275 #include "class_list.h" 276 277 void NetworkStatsWidget::toggleGUI() 278 { 279 BaseObject* bo = NULL; 280 const std::list<BaseObject*>* ls = ClassList::getList(CL_NETWORK_MONITOR); 281 if (ls != NULL && !ls->empty()) 282 bo = ls->front(); 283 284 if (bo != NULL && NetworkStatsWidget::_statsWidget == NULL) 285 { 286 NetworkStatsWidget::_statsWidget = new NetworkStatsWidget(dynamic_cast<NetworkMonitor*> (bo)); 287 NetworkStatsWidget::_statsWidget->showAll(); 288 } 289 else 290 { 291 delete NetworkStatsWidget::_statsWidget; 292 NetworkStatsWidget::_statsWidget = NULL; 293 } 294 } 185 295 186 296 … … 204 314 205 315 316 void NetworkStatsWidget::addProxy(const std::string& name, const IP& proxy) 317 {} 318 319 void NetworkStatsWidget::clearProxies() 320 {} 321 322 323 void NetworkStatsWidget::rebuild() 324 { 325 while (!this->_proxies.empty()) 326 { 327 delete this->_proxies.back(); 328 this->_proxies.pop_back(); 329 } 330 331 const NetworkNode* node = this->_monitor->getLocalNode(); 332 if (node == NULL) 333 { 334 printf("NO NODE\n"); 335 return; 336 } 337 338 this->addNode(node); 339 } 340 341 342 206 343 void NetworkStatsWidget::tick(float dt) 207 344 { 345 346 if ((_passedTime+= dt) > 1.0f) 347 { 348 this->_passedTime = 0.0f; 349 this->rebuild(); 350 } 351 208 352 assert (this->_monitor->getLocalNode() != NULL); 209 353 assert(this->_monitor->getLocalNode()->getPeerInfo() != NULL); … … 220 364 void NetworkStatsWidget::resize() 221 365 { 222 GLGui Box::resize();366 GLGuiFixedpositionBox::resize(); 223 367 } 224 368 -
trunk/src/lib/network/monitor/network_stats_widget.h
r9494 r9656 2 2 * @file network_stats_widget.h 3 3 * @brief Definition of an EnergyWidget, that displays a bar and a Text 4 */4 */ 5 5 6 6 #ifndef _NETWORK_STATS_WIDGET_H 7 7 #define _NETWORK_STATS_WIDGET_H 8 8 9 #include "glgui_ box.h"9 #include "glgui_fixedposition_box.h" 10 10 #include "glgui_bar.h" 11 11 #include "glgui_text.h" 12 #include "glgui_pushbutton.h" 12 13 13 14 #include "network/ip.h" 14 15 15 16 class NetworkMonitor; 16 17 class NetworkNode; 18 class PeerInfo; 17 19 18 20 class HostWidget : public OrxGui::GLGuiBox … … 20 22 public: 21 23 HostWidget(const std::string& name, const IP& ip); 22 ~HostWidget() {};24 HostWidget(const PeerInfo* peerInfo); 23 25 24 26 void setName(const std::string& name) { this->_name.setText(name); }; 25 void setIP(const IP& ip) { this->_ip.setText( ip.ipString()); this->_storedIP = ip; };27 void setIP(const IP& ip) { this->_ip.setText(std::string("at ") + ip.ipString()); this->_storedIP = ip; }; 26 28 27 29 void setNameWidth(float width) { this->_name.setLineWidth(width); }; … … 35 37 36 38 private: 39 void init(); 40 private: 37 41 OrxGui::GLGuiText _name; //!< The Name of the Proxy server to be displayed. 38 42 OrxGui::GLGuiText _ip; //!< The IP of the proxy server. 39 43 IP _storedIP; //!< The ip to compare. 44 45 static Font* _font; 40 46 }; 41 47 42 48 43 class ProxyWidget : public OrxGui::GLGuiBox49 class NodeWidget : public OrxGui::GLGuiBox 44 50 { 45 51 public: 46 ProxyWidget(const std::string& proxyName, const IP& ip); 52 NodeWidget(const std::string& proxyName, const IP& ip); 53 NodeWidget(const NetworkNode* node); 47 54 48 void addClient(const std::string& name, const IP& ip); 55 void addNode(const NetworkNode* node); 56 void addNode(const std::string& name, const IP& ip); 49 57 50 bool remove Client(const IP& ip);51 bool remove Client(const std::string& name);52 bool remove Client(const std::string& name, const IP& ip);58 bool removeNode(const IP& ip); 59 bool removeNode(const std::string& name); 60 bool removeNode(const std::string& name, const IP& ip); 53 61 54 void set ClientNameWidths(float width);62 void setNodeNameWidths(float width); 55 63 56 64 … … 63 71 HostWidget _proxyWidget; 64 72 65 std::vector< HostWidget*> _clients;66 float _ clientNameWidth;73 std::vector<NodeWidget*> _nodes; 74 float _nodeNameWidth; 67 75 }; 68 76 … … 71 79 72 80 //! A class to display network Statistics. 73 class NetworkStatsWidget : public OrxGui::GLGui Box81 class NetworkStatsWidget : public OrxGui::GLGuiFixedpositionBox 74 82 { 75 83 public: 84 static void toggleGUI(); 85 76 86 NetworkStatsWidget(const NetworkMonitor* monitor); 77 87 virtual ~NetworkStatsWidget(); … … 84 94 85 95 void addProxy(const std::string& name, const IP& proxy); 96 void addNode(const NetworkNode* node); 86 97 98 void clearProxies(); 99 100 void rebuild(); 87 101 88 102 //void rebuildConnectedHosts(std::vector<hosts> hosts); … … 101 115 const NetworkMonitor* _monitor; 102 116 117 OrxGui::GLGuiText _thisHostIs; 103 118 HostWidget _thisHost; 104 119 … … 106 121 OrxGui::GLGuiText _downstreamText; 107 122 108 std::vector<HostWidget*>_connectedProxies;123 OrxGui::GLGuiBox _serverBox; 109 124 110 OrxGui::GLGuiText _serverIP;125 std::vector<NodeWidget*> _proxies; 111 126 112 127 128 static NetworkStatsWidget* _statsWidget; 129 130 131 float _passedTime; 113 132 //OrxGui::GLGuiText _valueText; 114 133 //OrxGui::GLGuiBar _bar; -
trunk/src/lib/network/nettypes.h
r9494 r9656 10 10 PERMISSION_MASTER_SERVER = 1, 11 11 PERMISSION_PROXY_SERVER = 2, 12 PERMISSION_OWNER = 4, 13 PERMISSION_ALL = 8 12 PERMISSION_SERVER = 4, 13 PERMISSION_OWNER = 8, 14 PERMISSION_ALL = 16 14 15 }; 15 16 -
trunk/src/lib/network/network_game_manager.cc
r9494 r9656 68 68 69 69 this->gameState = 0; 70 registerVar( new SynchronizeableInt( &gameState, &gameState, "gameState" ) );70 registerVar( new SynchronizeableInt( &gameState, &gameState, "gameState", PERMISSION_MASTER_SERVER ) ); 71 71 } 72 72 … … 91 91 bool NetworkGameManager::signalNewPlayer( int userId ) 92 92 { 93 assert( SharedNetworkData::getInstance()->isMasterServer() || SharedNetworkData::getInstance()->isProxyServerActive());93 assert( SharedNetworkData::getInstance()->isMasterServer()); 94 94 assert( State::getGameRules() ); 95 95 assert( State::getGameRules()->isA( CL_NETWORK_GAME_RULES ) ); … … 97 97 NetworkGameRules & rules = *(dynamic_cast<NetworkGameRules*>(State::getGameRules())); 98 98 99 int team = rules.getTeamForNewUser();100 ClassID playableClassId = rules.getPlayableClassId( userId, team );101 std::string playableModel = rules.getPlayableModelFileName( userId, team, playableClassId );102 std::string playableTexture = rules.getPlayableModelFileName( userId, team, playableClassId );103 float playableScale = rules.getPlayableScale( userId, team, playableClassId );99 int team = rules.getTeamForNewUser(); 100 ClassID playableClassId = rules.getPlayableClassId( userId, team ); 101 std::string playableModel = rules.getPlayableModelFileName( userId, team, playableClassId ); 102 std::string playableTexture = rules.getPlayableModelFileName( userId, team, playableClassId ); 103 float playableScale = rules.getPlayableScale( userId, team, playableClassId ); 104 104 105 105 BaseObject * bo = Factory::fabricate( playableClassId ); … … 111 111 112 112 playable.loadMD2Texture( playableTexture ); 113 113 playable.setTeam(team); 114 114 playable.loadModel( playableModel, 100.0f ); 115 115 playable.setOwner( userId ); … … 159 159 /** 160 160 * handler for remove synchronizeable messages 161 * @param message Id161 * @param messageType 162 162 * @param data 163 163 * @param dataLength … … 166 166 * @return true on successfull handling else handler will be called again 167 167 */ 168 bool NetworkGameManager::delSynchronizeableHandler( Message Id messageId, byte * data, int dataLength, void * someData, int userId)168 bool NetworkGameManager::delSynchronizeableHandler( MessageType messageType, byte * data, int dataLength, void * someData, int senderId, int destinationId ) 169 169 { 170 170 … … 172 172 173 173 if ( SharedNetworkData::getInstance()->isMasterServer() || 174 SharedNetworkData::getInstance()->isProxyServerActive() && SharedNetworkData::getInstance()->isUserClient( userId))175 { 176 PRINTF(0)("Recieved DeleteSynchronizeable message from client %d!\n", userId);174 SharedNetworkData::getInstance()->isProxyServerActive() && SharedNetworkData::getInstance()->isUserClient(senderId)) 175 { 176 PRINTF(0)("Recieved DeleteSynchronizeable message from client %d!\n", senderId); 177 177 return true; 178 178 } … … 183 183 if ( len != dataLength ) 184 184 { 185 PRINTF(2)("Recieved DeleteSynchronizeable message with incorrect size (%d) from client %d!\n", dataLength, userId);185 PRINTF(2)("Recieved DeleteSynchronizeable message with incorrect size (%d) from client %d!\n", dataLength, senderId); 186 186 return true; 187 187 } … … 217 217 assert( Converter::intToByteArray( uniqueId, buf, INTSIZE ) == INTSIZE ); 218 218 219 MessageManager::getInstance()->sendMessage( MSGID_DELETESYNCHRONIZEABLE, buf, INTSIZE, RT_ALL_BUT_ME, 0, MP_HIGHBANDWIDTH );219 MessageManager::getInstance()->sendMessage( MSGID_DELETESYNCHRONIZEABLE, buf, INTSIZE, RT_ALL_BUT_ME, NET_UNASSIGNED, MP_HIGHBANDWIDTH ); 220 220 } 221 221 … … 224 224 /** 225 225 * handler for MSGID_PREFEREDTEAM message 226 * @param message Id226 * @param messageType 227 227 * @param data 228 228 * @param dataLength … … 231 231 * @return 232 232 */ 233 bool NetworkGameManager::preferedTeamHandler( Message Id messageId, byte * data, int dataLength, void * someData, int userId)234 { 235 assert( SharedNetworkData::getInstance()->isMasterServer() || SharedNetworkData::getInstance()->isProxyServerActive());233 bool NetworkGameManager::preferedTeamHandler( MessageType messageType, byte * data, int dataLength, void * someData, int senderId, int destinationId ) 234 { 235 assert( SharedNetworkData::getInstance()->isMasterServer() ); 236 236 237 237 int teamId = 0; … … 240 240 if ( len != dataLength ) 241 241 { 242 PRINTF(2)("Recieved DeleteSynchronizeable message with incorrect size (%d) from client %d!\n", dataLength, userId);242 PRINTF(2)("Recieved DeleteSynchronizeable message with incorrect size (%d) from client %d!\n", dataLength, senderId); 243 243 return true; 244 244 } 245 245 246 NetworkGameManager::getInstance()->setPreferedTeam( userId, teamId ); 247 248 return true; 249 } 250 246 PRINTF(0)("Client %i wishes to play in team %i\n", senderId, teamId); 247 NetworkGameManager::getInstance()->setPreferedTeam( senderId, teamId ); 248 249 return true; 250 } 251 252 253 /** 254 * this actualy sets the new prefered team id 255 * @param userId: the user that changes team 256 * @param teamId: the new team id for the user 257 */ 251 258 void NetworkGameManager::setPreferedTeam( int userId, int teamId ) 252 259 { … … 259 266 } 260 267 268 261 269 /** 262 270 * set prefered team for this host … … 265 273 void NetworkGameManager::prefereTeam( int teamId ) 266 274 { 267 if ( SharedNetworkData::getInstance()->isMasterServer() /*|| SharedNetworkData::getInstance()->isProxyServerActive()*/)268 setPreferedTeam( SharedNetworkData::getInstance()->getHostID(), teamId );275 if ( SharedNetworkData::getInstance()->isMasterServer() ) 276 this->setPreferedTeam( SharedNetworkData::getInstance()->getHostID(), teamId ); 269 277 else 270 278 { … … 273 281 assert( Converter::intToByteArray( teamId, buf, INTSIZE) == INTSIZE ); 274 282 275 MessageManager::getInstance()->sendMessage( MSGID_PREFEREDTEAM, buf, INTSIZE, RT_USER, 0, MP_HIGHBANDWIDTH ); 283 // send this message to the master server 284 MessageManager::getInstance()->sendMessage( MSGID_PREFEREDTEAM, buf, INTSIZE, RT_USER, NET_ID_MASTER_SERVER, MP_HIGHBANDWIDTH ); 276 285 } 277 286 } … … 306 315 307 316 308 bool NetworkGameManager::chatMessageHandler( Message Id messageId, byte * data, int dataLength, void * someData, int userId)309 { 310 PRINTF(0)("NetworkGameManager::chatMessageHandler %d %d\n", userId, SharedNetworkData::getInstance()->getHostID() );311 if ( (SharedNetworkData::getInstance()->isMasterServer() /*|| SharedNetworkData::getInstance()->isProxyServerActive()*/) && userId != SharedNetworkData::getInstance()->getHostID() )312 { 313 MessageManager::getInstance()->sendMessage( message Id, data, dataLength, RT_ALL_BUT_ME, 0, MP_HIGHBANDWIDTH );317 bool NetworkGameManager::chatMessageHandler( MessageType messageType, byte * data, int dataLength, void * someData, int senderId, int destinationId ) 318 { 319 PRINTF(0)("NetworkGameManager::chatMessageHandler %d %d\n", senderId, SharedNetworkData::getInstance()->getHostID() ); 320 if ( (SharedNetworkData::getInstance()->isMasterServer() /*|| SharedNetworkData::getInstance()->isProxyServerActive()*/) && senderId != SharedNetworkData::getInstance()->getHostID() ) 321 { 322 MessageManager::getInstance()->sendMessage( messageType, data, dataLength, RT_ALL_BUT_ME, NET_UNASSIGNED, MP_HIGHBANDWIDTH ); 314 323 } 315 324 … … 321 330 if ( dataLength < 3*INTSIZE ) 322 331 { 323 PRINTF(2)("got too small chatmessage from client %d\n", userId);332 PRINTF(2)("got too small chatmessage from client %d\n", senderId); 324 333 325 334 return true; 326 335 } 327 336 328 int messageType = 0;329 Converter::byteArrayToInt( data, & messageType);337 int chatType = 0; 338 Converter::byteArrayToInt( data, &chatType); 330 339 int senderUserId = 0; 331 340 Converter::byteArrayToInt( data+INTSIZE, &senderUserId ); … … 333 342 Converter::byteArrayToString( data+2*INTSIZE, message, dataLength-2*INTSIZE ); 334 343 335 rules.handleChatMessage( senderUserId, message, messageType);344 rules.handleChatMessage( senderUserId, message, chatType); 336 345 337 346 return true; … … 352 361 353 362 if ( SharedNetworkData::getInstance()->isMasterServer() /*|| SharedNetworkData::getInstance()->isProxyServerActive()*/) 354 MessageManager::getInstance()->sendMessage( MSGID_CHATMESSAGE, buf, message.length()+3*INTSIZE, RT_ALL_ME, 0, MP_HIGHBANDWIDTH );363 MessageManager::getInstance()->sendMessage( MSGID_CHATMESSAGE, buf, message.length()+3*INTSIZE, RT_ALL_ME, NET_UNASSIGNED, MP_HIGHBANDWIDTH ); 355 364 else 356 MessageManager::getInstance()->sendMessage( MSGID_CHATMESSAGE, buf, message.length()+3*INTSIZE, RT_ALL_BUT_ME, 0, MP_HIGHBANDWIDTH );365 MessageManager::getInstance()->sendMessage( MSGID_CHATMESSAGE, buf, message.length()+3*INTSIZE, RT_ALL_BUT_ME, NET_UNASSIGNED, MP_HIGHBANDWIDTH ); 357 366 358 367 -
trunk/src/lib/network/network_game_manager.h
r9406 r9656 19 19 class PNode; 20 20 21 typedef enum NetworkGameManagerProtocol {22 NET_CREATE_ENTITY = 0,23 NET_REMOVE_ENTITY,24 NET_CREATE_ENTITY_LIST,25 NET_REMOVE_ENTITY_LIST,26 NET_REQUEST_CREATE,27 NET_REQUEST_REMOVE,28 NET_YOU_ARE_ENTITY,29 NET_REQUEST_ENTITY_LIST,30 21 31 NET_NUMBER32 };33 22 34 23 struct clientBuffer … … 70 59 NetworkGameManager(); 71 60 72 static bool delSynchronizeableHandler( Message Id messageId, byte * data, int dataLength, void * someData, int userId);73 static bool preferedTeamHandler( Message Id messageId, byte * data, int dataLength, void * someData, int userId);74 static bool chatMessageHandler( Message Id messageId, byte * data, int dataLength, void * someData, int userId);61 static bool delSynchronizeableHandler( MessageType messageType, byte * data, int dataLength, void * someData, int senderId, int destinationId ); 62 static bool preferedTeamHandler( MessageType messageType, byte * data, int dataLength, void * someData, int senderId, int destinationId ); 63 static bool chatMessageHandler( MessageType messageType, byte * data, int dataLength, void * someData, int senderId, int destinationId ); 75 64 76 65 void setPreferedTeam( int userId, int teamId ); -
trunk/src/lib/network/network_manager.cc
r9494 r9656 31 31 #include "network_log.h" 32 32 #include "network_game_manager.h" 33 #include "proxy/proxy_control.h" 33 34 34 35 … … 37 38 38 39 SHELL_COMMAND(debug, NetworkManager, debug); 40 SHELL_COMMAND(redirTest, NetworkManager, setRedirectionTest); 41 39 42 40 43 … … 111 114 // create the network stream 112 115 this->networkStream = new NetworkStream(NET_MASTER_SERVER); 113 this->networkStream->createServer( port, port + 1 );116 this->networkStream->createServer( port, port + 1, port + 2); 114 117 115 118 // start the network game manager 116 119 this->networkStream->createNetworkGameManager(); 120 121 // init the proxy control center 122 ProxyControl::getInstance(); 117 123 118 124 PRINTF(0)("Created Network Master Server\n"); … … 138 144 139 145 // then start the server 140 this->networkStream->createServer( port, port +1); 141 146 this->networkStream->createServer( port, port + 1, port + 2); 142 147 143 148 // and to the other proxy servers also, this would be very nice if its works 144 145 146 // start the network game manager 147 //this->networkStream->createNetworkGameManager(); 148 149 /* put it here....*/ 150 151 // init the proxy control center 152 ProxyControl::getInstance(); 149 153 150 154 PRINTF(0)("Created Network Proxy Server\n"); … … 168 172 this->networkStream->connectToMasterServer( name, port); 169 173 174 170 175 // and start the handshake 171 176 this->networkStream->startHandshake(); 177 // create the proxy control 178 ProxyControl::getInstance(); 172 179 173 180 PRINTF(0)("Created Network Client\n"); 174 181 return 1; 182 } 183 184 185 /** 186 * reconnects this client to another server 187 * @param address new server address 188 */ 189 void NetworkManager::reconnectToServer(IP address) 190 { 191 PRINTF(0)("Rec. reconnection command\n"); 192 this->networkStream->reconnectToServer(address); 175 193 } 176 194 … … 216 234 PRINT(0)("===========================================\n"); 217 235 } 236 237 238 void NetworkManager::setRedirectionTest() 239 { 240 this->networkStream->setRedirectionTest(); 241 } 242 -
trunk/src/lib/network/network_manager.h
r9494 r9656 39 39 int createProxyServer( unsigned int port); 40 40 41 void reconnectToServer(IP address); 42 41 43 void connectSynchronizeable(Synchronizeable& sync); 42 44 void synchronize(float dtS); 43 45 44 46 void debug(); 47 48 void setRedirectionTest(); 49 45 50 46 51 -
trunk/src/lib/network/network_stream.cc
r9494 r9656 11 11 ### File Specific: 12 12 main-programmer: Christoph Renner rennerc@ee.ethz.ch 13 co-programmer: Patrick Boenzli boenzlip@orxonox.ethz.ch13 co-programmer: Patrick Boenzli patrick@orxonox.ethz.ch 14 14 15 15 June 2006: finishing work on the network stream for pps presentation (rennerc@ee.ethz.ch) 16 July 2006: some code rearangement and integration of the proxy server mechanism ( boenzlip@ee.ethz.ch)16 July 2006: some code rearangement and integration of the proxy server mechanism (patrick@orxonox.ethz.ch) 17 17 */ 18 18 … … 20 20 #define DEBUG_MODULE_NETWORK 21 21 22 #include "proxy/proxy_control.h" 22 23 23 24 #include "base_object.h" … … 80 81 // init the shared network data 81 82 SharedNetworkData::getInstance()->setHostID(NET_ID_MASTER_SERVER); 83 this->pInfo->userId = NET_ID_MASTER_SERVER; 84 this->pInfo->nodeType = NET_MASTER_SERVER; 85 82 86 break; 83 87 case NET_PROXY_SERVER_ACTIVE: 84 88 // init the shared network data 85 89 SharedNetworkData::getInstance()->setHostID(NET_ID_PROXY_SERVER_01); 90 this->pInfo->nodeType = NET_PROXY_SERVER_ACTIVE; 91 86 92 break; 87 93 case NET_PROXY_SERVER_PASSIVE: 88 94 // init the shared network data 89 95 SharedNetworkData::getInstance()->setHostID(NET_ID_PROXY_SERVER_01); 96 this->pInfo->nodeType = NET_PROXY_SERVER_PASSIVE; 97 90 98 break; 91 99 case NET_CLIENT: 92 100 SharedNetworkData::getInstance()->setHostID(NET_ID_UNASSIGNED); 101 this->pInfo->nodeType = NET_CLIENT; 93 102 break; 94 103 } … … 97 106 98 107 // get the local ip address 99 IPaddress ip; 100 SDLNet_ResolveHost( &ip, NULL, 0); 108 IP ip("localhost", 0); 101 109 this->pInfo->ip = ip; 102 110 } … … 112 120 this->setClassID(CL_NETWORK_STREAM, "NetworkStream"); 113 121 this->clientSocket = NULL; 122 this->clientSoftSocket = NULL; 114 123 this->proxySocket = NULL; 115 124 this->networkGameManager = NULL; … … 117 126 118 127 this->pInfo = new PeerInfo(); 119 this->pInfo->userId = 0;128 this->pInfo->userId = NET_UID_UNASSIGNED; 120 129 this->pInfo->lastAckedState = 0; 121 130 this->pInfo->lastRecvedState = 0; 131 this->pInfo->bLocal = true; 122 132 123 133 this->bRedirect = false; 124 134 125 135 this->currentState = 0; 136 this->redirectionUID = NET_ID_MASTER_SERVER; 126 137 127 138 remainingBytesToWriteToDict = Preferences::getInstance()->getInt( "compression", "writedict", 0 ); … … 142 153 if ( this->clientSocket ) 143 154 { 144 clientSocket->close(); 145 delete clientSocket; 146 clientSocket = NULL; 155 this->clientSocket->close(); 156 delete this->clientSocket; 157 this->clientSocket = NULL; 158 } 159 if ( this->clientSoftSocket ) 160 { 161 this->clientSoftSocket->close(); 162 delete this->clientSoftSocket; 163 this->clientSoftSocket = NULL; 147 164 } 148 165 if ( this->proxySocket) … … 199 216 this->peers[node].connectionMonitor = new ConnectionMonitor( NET_ID_MASTER_SERVER ); 200 217 this->peers[node].ip = this->peers[node].socket->getRemoteAddress(); 218 this->peers[node].bLocal = true; 201 219 } 202 220 … … 218 236 this->peers[proxyId].connectionMonitor = new ConnectionMonitor( proxyId ); 219 237 this->peers[proxyId].ip = this->peers[proxyId].socket->getRemoteAddress(); 238 this->peers[proxyId].bLocal = true; 220 239 } 221 240 … … 225 244 * @param port: interface port for all clients 226 245 */ 227 void NetworkStream::createServer(int clientPort, int proxyPort )246 void NetworkStream::createServer(int clientPort, int proxyPort, int clientSoftPort) 228 247 { 229 248 PRINTF(0)(" Creating new Server: listening for clients on port %i and for proxies on port %i", clientPort, proxyPort); 230 249 this->clientSocket= new UdpServerSocket(clientPort); 250 this->clientSoftSocket= new UdpServerSocket(clientSoftPort); 231 251 this->proxySocket = new UdpServerSocket(proxyPort); 232 252 } … … 255 275 Handshake* hs = new Handshake(this->pInfo->nodeType); 256 276 // fake the unique id 257 hs->setUniqueID( NET_UID_HANDSHAKE ); 258 assert( peers[userId].handshake == NULL ); 259 peers[userId].handshake = hs; 277 hs->setUniqueID( userId); 278 assert( this->peers[userId].handshake == NULL ); 279 this->peers[userId].handshake = hs; 280 this->peers[userId].bLocal = true; 260 281 261 282 // set the preferred nick name … … 301 322 // create the network monitor after all the init work and before there is any connection handlings 302 323 if( this->networkMonitor == NULL) 324 { 303 325 this->networkMonitor = new NetworkMonitor(this); 326 SharedNetworkData::getInstance()->setNetworkMonitor( this->networkMonitor); 327 } 304 328 305 329 … … 318 342 if ( this->clientSocket ) 319 343 this->clientSocket->update(); 344 if ( this->clientSoftSocket) 345 this->clientSoftSocket->update(); 320 346 if( this->proxySocket) 321 347 this->proxySocket->update(); … … 328 354 if ( this->clientSocket ) 329 355 this->clientSocket->update(); 356 if ( this->clientSoftSocket) 357 this->clientSoftSocket->update(); 330 358 if( this->proxySocket) 331 359 this->proxySocket->update(); … … 348 376 if( this->bRedirect) 349 377 { 350 this->handleReconnect( NET_ID_MASTER_SERVER);378 this->handleReconnect( this->redirectionUID); 351 379 } 352 380 } … … 362 390 this->handleDownstream( tick ); 363 391 this->handleUpstream( tick ); 392 393 // process the local data of the message manager 394 MessageManager::getInstance()->processData(); 395 396 if( this->bSoftRedirect) 397 this->softReconnectToServer(0, IP("localhost", 10001)); 364 398 } 365 399 … … 385 419 if ( tempNetworkSocket ) 386 420 { 387 // determine the network node id 388 if ( freeSocketSlots.size() > 0 ) 421 // get a userId 422 // if ( freeSocketSlots.size() > 0 ) 423 // { 424 // // this should never be called 425 // userId = freeSocketSlots.back(); 426 // freeSocketSlots.pop_back(); 427 // } 428 // else 389 429 { 390 userId = freeSocketSlots.back(); 391 freeSocketSlots.pop_back(); 392 } 393 else 394 { 395 userId = 1; 430 // each server (proxy and master) have an address space for new network nodes of 1000 nodes 431 // the first NET_ID_PROXY_MAX are always reserved for proxy servers 432 userId = SharedNetworkData::getInstance()->getHostID() * 1000 + NET_ID_PROXY_MAX + 1; 396 433 397 434 for ( PeerList::iterator it = peers.begin(); it != peers.end(); it++ ) 398 435 if ( it->first >= userId ) 399 436 userId = it->first + 1; 437 438 // make sure that this server only uses an address space of 1000 439 assert( userId < (SharedNetworkData::getInstance()->getHostID() + 1) * 1000); 400 440 } 401 441 // this creates a new entry in the peers list … … 410 450 } 411 451 452 if( this->clientSoftSocket != NULL) 453 { 454 tempNetworkSocket = this->clientSoftSocket->getNewSocket(); 455 456 // we got new NET_CLIENT connecting 457 if ( tempNetworkSocket ) 458 { 459 460 // this creates a new entry in the peers list 461 peers[userId].socket = tempNetworkSocket; 462 peers[userId].nodeType = NET_CLIENT; 463 464 // handle the newly connected client 465 this->handleSoftConnect(userId); 466 467 PRINTF(0)("New Client softly connected: %d :D\n", userId); 468 } 469 } 470 412 471 413 472 if( this->proxySocket != NULL) … … 419 478 { 420 479 // determine the network node id 421 if ( freeSocketSlots.size() > 0 )422 {423 userId = freeSocketSlots.back();424 freeSocketSlots.pop_back();425 }426 else480 // if ( freeSocketSlots.size() > 0 ) 481 // { 482 // userId = freeSocketSlots.back(); 483 // freeSocketSlots.pop_back(); 484 // } 485 // else 427 486 { 428 487 userId = 1; 429 488 430 for ( PeerList::iterator it = peers.begin(); it != peers.end(); it++ ) 431 if ( it->first >= userId ) 432 userId = it->first + 1; 489 // find an empty slot within the range 490 for( int i = 0; i < NET_ID_PROXY_MAX; i++) 491 { 492 if( this->peers.find( i) == this->peers.end()) 493 { 494 userId = i; 495 break; 496 } 497 } 498 499 // for ( PeerList::iterator it = peers.begin(); it != peers.end(); it++ ) 500 // if ( it->first >= userId ) 501 // userId = it->first + 1; 433 502 } 434 503 … … 443 512 } 444 513 } 514 445 515 446 516 … … 461 531 PRINTF(0)("Client is gone: %d (%s)\n", it->second.userId, reason.c_str()); 462 532 533 463 534 this->handleDisconnect( it->second.userId); 535 536 if( SharedNetworkData::getInstance()->isProxyServerActive()) 537 ProxyControl::getInstance()->signalLeaveClient(it->second.userId); 464 538 465 539 it++; … … 469 543 it++; 470 544 } 471 472 473 545 } 474 546 … … 481 553 { 482 554 // create new handshake and init its variables 483 peers[userId].handshake = new Handshake(this->pInfo->nodeType, userId, this->networkGameManager->getUniqueID(), MessageManager::getInstance()->getUniqueID()); 484 peers[userId].handshake->setUniqueID(userId); 485 486 peers[userId].connectionMonitor = new ConnectionMonitor( userId ); 487 peers[userId].userId = userId; 555 this->peers[userId].handshake = new Handshake(this->pInfo->nodeType, userId, this->networkGameManager->getUniqueID(), MessageManager::getInstance()->getUniqueID()); 556 this->peers[userId].handshake->setUniqueID(userId); 557 558 this->peers[userId].connectionMonitor = new ConnectionMonitor( userId ); 559 this->peers[userId].userId = userId; 560 this->peers[userId].bLocal = true; 488 561 489 562 PRINTF(0)("num sync: %d\n", synchronizeables.size()); … … 494 567 if( pi != NULL) 495 568 { 496 peers[userId].handshake->setProxy1Address( pi->ip);569 this->peers[userId].handshake->setProxy1Address( pi->ip); 497 570 } 498 571 pi = this->networkMonitor->getSecondChoiceProxy(); 499 572 if( pi != NULL) 500 peers[userId].handshake->setProxy2Address( pi->ip);573 this->peers[userId].handshake->setProxy2Address( pi->ip); 501 574 502 575 // check if the connecting client should reconnect to a proxy server 503 576 if( SharedNetworkData::getInstance()->isMasterServer()) 504 peers[userId].handshake->setRedirect(/*this->networkMonitor->isReconnectNextClient()*/false); 577 { 578 if( this->networkMonitor->isReconnectNextClient()) 579 { 580 this->peers[userId].handshake->setRedirect(true); 581 PRINTF(0)("forwarding client to proxy server because this server is saturated\n"); 582 } 583 } 505 584 506 585 // the connecting node of course is a client 507 peers[userId].ip = peers[userId].socket->getRemoteAddress(); 508 } 586 this->peers[userId].ip = this->peers[userId].socket->getRemoteAddress(); 587 } 588 589 590 /** 591 * this handles new soft connections 592 * @param userId: the id of the new user node 593 * 594 * soft connections are connections from clients that are already in the network and don't need a new handshake etc. 595 * the state of all entitites owned by userId are not deleted and stay 596 * soft connections can not be redirected therefore they are negotiated between the to parties 597 */ 598 void NetworkStream::handleSoftConnect( int userId) 599 { 600 // create new handshake and init its variables 601 this->peers[userId].handshake = NULL; 602 this->peers[userId].handshake->setUniqueID(userId); 603 604 this->peers[userId].connectionMonitor = new ConnectionMonitor( userId ); 605 this->peers[userId].userId = userId; 606 this->peers[userId].bLocal = true; 607 608 PRINTF(0)("num sync: %d\n", synchronizeables.size()); 609 610 // the connecting node of course is a client 611 this->peers[userId].ip = this->peers[userId].socket->getRemoteAddress(); 612 } 613 509 614 510 615 … … 524 629 PRINT(0)(" Host ist Client with ID: %i\n", this->pInfo->userId); 525 630 } 631 632 PRINT(0)(" Current number of connections is: %i\n", this->peers.size()); 633 for ( PeerList::iterator it = peers.begin(); it != peers.end(); it++ ) 634 { 635 PRINT(0)(" peers[%i] with uniqueId %i and address: %s\n", it->first, it->second.userId, it->second.ip.ipString().c_str()); 636 } 637 PRINT(0)("\n\n"); 638 526 639 527 640 PRINT(0)(" Got %i connected Synchronizeables, showing active Syncs:\n", this->synchronizeables.size()); … … 576 689 // - client <==> master server 577 690 // - proxy server <==> master server 578 if( SharedNetworkData::getInstance()->isClient() || SharedNetworkData::getInstance()->isProxyServerActive() && it->second.isMasterServer()) 691 if( SharedNetworkData::getInstance()->isClient() || 692 SharedNetworkData::getInstance()->isProxyServerActive() && 693 SharedNetworkData::getInstance()->isUserMasterServer(it->second.userId)) 579 694 { 580 PRINTF( 0)("Handshake: i am in client role\n");695 PRINTF(4)("Handshake: i am in client role\n"); 581 696 582 697 SharedNetworkData::getInstance()->setHostID( it->second.handshake->getHostId() ); 583 698 this->pInfo->userId = SharedNetworkData::getInstance()->getHostID(); 584 699 585 #warning the ip address is not set here because it results in a segfault when connecting to a proxy server => trace this later586 700 // it->second.ip = it->second.socket->getRemoteAddress(); 587 701 588 //it->second.nodeType = it->second.handshake->getRemoteNodeType();702 it->second.nodeType = it->second.handshake->getRemoteNodeType(); 589 703 // it->second.ip = it->second.socket->getRemoteAddress(); 590 704 // add the new server to the nodes list (it can be a NET_MASTER_SERVER or NET_PROXY_SERVER) … … 633 747 else if ( SharedNetworkData::getInstance()->isProxyServerActive() && it->second.isClient() ) 634 748 { 635 PRINTF( 0)("Handshake: i am in server role\n");749 PRINTF(4)("Handshake: Proxy in server role: connecting %i\n", it->second.userId); 636 750 637 751 it->second.ip = it->second.socket->getRemoteAddress(); … … 639 753 this->networkMonitor->addNode(&it->second); 640 754 641 this->handleNewClient( it->second.userId ); 755 // work with the ProxyControl to init the new client 756 ProxyControl::getInstance()->signalNewClient( it->second.userId); 642 757 643 758 if ( PlayerStats::getStats( it->second.userId ) && it->second.handshake->getPreferedNickName() != "" ) … … 667 782 /** 668 783 * this functions handles a reconnect event received from the a NET_MASTER_SERVER or NET_PROXY_SERVER 784 * @param userId 669 785 */ 670 786 void NetworkStream::handleReconnect(int userId) 671 787 { 672 788 this->bRedirect = false; 789 #warning this peer will be created if it does not yet exist: dangerous 673 790 PeerInfo* pInfo = &this->peers[userId]; 791 792 IP proxyIP; 793 if( this->networkMonitor->isForcedReconnection()) 794 proxyIP = this->networkMonitor->getForcedReconnectionIP(); 795 else 796 proxyIP = pInfo->handshake->getProxy1Address(); 674 797 675 798 PRINTF(0)("===============================================\n"); 676 799 PRINTF(0)("Client is redirected to the other proxy servers\n"); 677 800 PRINTF(0)(" user id: %i\n", userId); 678 PRINTF(0)(" connecting to: %s\n", this->networkMonitor->getFirstChoiceProxy()->ip.ipString().c_str());801 PRINTF(0)(" connecting to: %s\n", proxyIP.ipString().c_str()); 679 802 PRINTF(0)("===============================================\n"); 680 803 … … 683 806 pInfo->lastRecvedState = 0; 684 807 685 // temp save the ip address here686 IP proxyIP = pInfo->handshake->getProxy1Address();687 688 808 // disconnect from the current server and reconnect to proxy server 689 809 this->handleDisconnect( userId); 690 810 this->connectToProxyServer(NET_ID_PROXY_SERVER_01, proxyIP.ipString(), 9999); 811 // this->connectToMasterServer(proxyIP.ipString(), 9999); 691 812 #warning the ports are not yet integrated correctly in the ip class 692 813 … … 696 817 697 818 819 820 /** 821 * reconnects to another server, with full handshake 822 * @param address of the new server 823 */ 824 void NetworkStream::reconnectToServer(IP address) 825 { 826 ///TODO make a redirection struct and push it to the network monitor 827 this->networkMonitor->setForcedReconnection(address); 828 829 // reconnect (depending on how we are connected at the moment) 830 if ( peers.find( NET_ID_MASTER_SERVER) != peers.end() ) 831 this->redirectionUID = NET_ID_MASTER_SERVER; 832 else if( peers.find( NET_ID_PROXY_SERVER_01) != peers.end() ) 833 this->redirectionUID = NET_ID_PROXY_SERVER_01; 834 835 this->bRedirect = true; 836 } 837 838 839 840 /** 841 * softly reconnecting to another server 842 * @param serverUserId the id of the client 843 * @param address of the new server 844 */ 845 void NetworkStream::softReconnectToServer(int serverUserId, IP address) 846 { 847 // this->networkMonitor->setForcedReconnection(address); 848 // this->handleReconnect( NET_ID_MASTER_SERVER); 849 850 // create the new udp socket and open the connection to the soft connection port 851 NetworkSocket* newSocket = new UdpSocket(address.ipString(), 10001); 852 853 // delete the synchronization state of this client for all syncs 854 for ( SynchronizeableList::iterator it2 = synchronizeables.begin(); it2 != synchronizeables.end(); it2++ ) { 855 (*it2)->cleanUpUser( serverUserId ); 856 } 857 858 // temp save the old socket 859 NetworkSocket* oldSocket = this->peers[serverUserId].socket; 860 861 // now integrate the new socket 862 this->peers[serverUserId].socket = newSocket; 863 864 this->bSoftRedirect = false; 865 return; 866 867 // now remove the old socket 868 oldSocket->disconnectServer(); 869 delete oldSocket; 870 871 // replace the old connection monitor 872 if ( this->peers[serverUserId].connectionMonitor ) 873 delete this->peers[serverUserId].connectionMonitor; 874 this->peers[serverUserId].connectionMonitor = new ConnectionMonitor(serverUserId); 875 876 // remove old node from the network monitor 877 this->networkMonitor->removeNode(&this->peers[serverUserId]); 878 879 } 880 881 882 883 /** 884 * prepares a soft connection for a client to connect to 885 * @param userId that will connect to this server 886 */ 887 void NetworkStream::prepareSoftConnection(int userId) 888 { 889 PRINTF(0)("prepare soft connection for userId %i\n"); 890 } 891 892 893 698 894 /** 699 895 * handles the disconnect event … … 702 898 void NetworkStream::handleDisconnect( int userId ) 703 899 { 704 peers[userId].socket->disconnectServer();705 delete peers[userId].socket;706 peers[userId].socket = NULL;707 708 if ( peers[userId].handshake )709 delete peers[userId].handshake;710 peers[userId].handshake = NULL;711 712 if ( peers[userId].connectionMonitor )713 delete peers[userId].connectionMonitor;714 peers[userId].connectionMonitor = NULL;715 716 900 this->peers[userId].socket->disconnectServer(); 901 delete this->peers[userId].socket; 902 this->peers[userId].socket = NULL; 903 904 if ( this->peers[userId].handshake ) 905 delete this->peers[userId].handshake; 906 this->peers[userId].handshake = NULL; 907 908 if ( this->peers[userId].connectionMonitor ) 909 delete this->peers[userId].connectionMonitor; 910 this->peers[userId].connectionMonitor = NULL; 911 912 // delete the synchronization state of this client for all syncs 717 913 for ( SynchronizeableList::iterator it2 = synchronizeables.begin(); it2 != synchronizeables.end(); it2++ ) { 718 914 (*it2)->cleanUpUser( userId ); … … 724 920 this->freeSocketSlots.push_back( userId ); 725 921 726 peers.erase( userId);727 } 728 922 this->networkMonitor->removeNode(&this->peers[userId]); 923 this->peers.erase( userId); 924 } 729 925 730 926 … … 793 989 assert( offset + INTSIZE <= UDP_PACKET_SIZE ); 794 990 795 // server fakes uniqueid == 0 for handshake 991 // server fakes uniqueid == 0 for handshake synchronizeable 796 992 if ( ( SharedNetworkData::getInstance()->isMasterServer() || 797 993 SharedNetworkData::getInstance()->isProxyServerActive() && peer->second.isClient() ) && 798 sync.getUniqueID() <= SharedNetworkData::getInstance()->getMaxPlayer() + 1) // plus one to handle one client more than the max to redirect it994 ( sync.getUniqueID() >= 1000 || sync.getUniqueID() <= SharedNetworkData::getInstance()->getMaxPlayer() + 1 + NET_ID_PROXY_MAX)) 799 995 n = Converter::intToByteArray( 0, buf + offset, UDP_PACKET_SIZE - offset ); 800 996 else … … 930 1126 while ( offset + 2 * INTSIZE < length ) 931 1127 { 1128 // read the unique id of the sync 932 1129 assert( offset > 0 ); 933 1130 assert( Converter::byteArrayToInt( buf + offset, &uniqueId ) == INTSIZE ); 934 1131 offset += INTSIZE; 935 1132 1133 // read the data length 936 1134 assert( Converter::byteArrayToInt( buf + offset, &syncDataLength ) == INTSIZE ); 937 1135 offset += INTSIZE; … … 945 1143 for ( SynchronizeableList::iterator it = synchronizeables.begin(); it != synchronizeables.end(); it++ ) 946 1144 { 947 // client thinks his handshake has id 0!!!!! 948 if ( (*it)->getUniqueID() == uniqueId || ( uniqueId == 0 && (*it)->getUniqueID() == peer->second.userId ) ) 1145 // client thinks his handshake has a special id: hostId * 1000 (host id of this server) 1146 if ( (*it)->getUniqueID() == uniqueId || // so this client exists already go to sync work 1147 ( uniqueId == 0 && (*it)->getUniqueID() == peer->second.userId ) ) // so this is a Handshake! 949 1148 { 950 1149 sync = *it; -
trunk/src/lib/network/network_stream.h
r9494 r9656 41 41 void init(); 42 42 43 /* network interface controls */ 43 44 void connectToMasterServer(std::string host, int port); 44 45 void connectToProxyServer(int proxyId, std::string host, int port); 45 void createServer(int clientPort, int proxyPort );46 void createServer(int clientPort, int proxyPort, int clientSoftPort); 46 47 47 48 void createNetworkGameManager(); 48 49 void startHandshake(int userId = NET_ID_MASTER_SERVER); 50 51 void reconnectToServer(IP address); 52 void softReconnectToServer(int serverUserId, IP address); 53 void prepareSoftConnection(int userId); 54 49 55 50 56 /* synchronizeable interface */ … … 70 76 inline PeerInfo* getPeerInfo() { return this->pInfo; } 71 77 inline PeerList getPeerInfoList() { return this->peers; } 78 79 inline void setRedirectionTest() { this->bSoftRedirect = true; } 72 80 73 81 /* data processing*/ … … 96 104 97 105 void handleConnect( int userId); 106 void handleSoftConnect( int userId); 98 107 void handleReconnect( int userId ); 99 108 void handleDisconnect( int userId ); 109 void handleSoftDisconnect( int userId); 100 110 101 111 void writeToNewDict( byte * data, int length, bool upstream ); … … 112 122 NetworkMonitor* networkMonitor; //!< the network monitor 113 123 NetworkGameManager* networkGameManager; //!< reference to the network game manager 114 ServerSocket* clientSocket; //!< the listening socket of the server 124 ServerSocket* clientSocket; //!< the listening socket for clients of the server 125 ServerSocket* clientSoftSocket; //!< the listening socket for soft connections to the server 115 126 ServerSocket* proxySocket; //!< socket for proxy connections 116 127 … … 126 137 127 138 bool bRedirect; //!< true if the master server sent a redirect command 139 int redirectionUID; //!< uid of the redir host 140 bool bSoftRedirect; //!< tsting 128 141 }; 129 142 #endif /* _NETWORK_STREAM */ -
trunk/src/lib/network/peer_info.cc
r9494 r9656 42 42 void PeerInfo::clear() 43 43 { 44 this->userId = 0;45 this->nodeType = NET_ CLIENT;44 this->userId = NET_ID_UNASSIGNED; 45 this->nodeType = NET_UNASSIGNED; 46 46 this->socket = NULL; 47 47 this->handshake = NULL; … … 49 49 this->lastRecvedState = 0; 50 50 this->connectionMonitor = NULL; 51 this->bLocal = false; 51 52 52 53 this->ip = IP(0,0); … … 68 69 const std::string PeerInfo::nodeNames[] = 69 70 { 70 71 "maser server", 71 "master server", 72 72 "proxy server active", 73 73 "proxy server passive", -
trunk/src/lib/network/peer_info.h
r9494 r9656 30 30 static const std::string& nodeTypeToString(unsigned int type); 31 31 32 inline bool isLocal() { return this->bLocal; } 32 33 33 34 … … 44 45 int lastRecvedState; //!< last received state 45 46 47 bool bLocal; //!< true if this node is localy connected to this node 48 46 49 static const std::string nodeNames[]; 47 50 -
trunk/src/lib/network/player_stats.cc
r9494 r9656 41 41 init(); 42 42 43 this-> userId = userId;43 this->assignedUserId = userId; 44 44 } 45 45 … … 56 56 this->setClassID( CL_PLAYER_STATS, "PlayerStats" ); 57 57 58 this-> userId = 0;58 this->assignedUserId = 0; 59 59 this->teamId = TEAM_NOTEAM; 60 60 this->preferedTeamId = TEAM_NOTEAM; … … 65 65 this->oldNickName = "Player"; 66 66 67 userId_handle = registerVarId( new SynchronizeableInt( & userId, &userId, "userId") );68 teamId_handle = registerVarId( new SynchronizeableInt( &teamId, &teamId, "teamId" ) );69 preferedTeamId_handle = registerVarId( new SynchronizeableInt( &preferedTeamId, &preferedTeamId, "preferedUserId" ) );70 score_handle = registerVarId( new SynchronizeableInt( &score, &score, "score" ) );71 playableClassId_handle = registerVarId( new SynchronizeableInt( &playableClassId, &playableClassId, "playableClassId" ) );72 playableUniqueId_handle = registerVarId( new SynchronizeableInt( &playableUniqueId, &playableUniqueId, "playableUniqueId" ) );73 modelFileName_handle = registerVarId( new SynchronizeableString( &modelFileName, &modelFileName, "modelFileName" ) );74 nickName_handler = registerVarId( new SynchronizeableString( &nickName, &nickName, "nickName" ) );67 userId_handle = registerVarId( new SynchronizeableInt( &assignedUserId, &assignedUserId, "userId", PERMISSION_MASTER_SERVER ) ); 68 teamId_handle = registerVarId( new SynchronizeableInt( &teamId, &teamId, "teamId", PERMISSION_MASTER_SERVER ) ); 69 preferedTeamId_handle = registerVarId( new SynchronizeableInt( &preferedTeamId, &preferedTeamId, "preferedUserId", PERMISSION_MASTER_SERVER ) ); 70 score_handle = registerVarId( new SynchronizeableInt( &score, &score, "score", PERMISSION_MASTER_SERVER ) ); 71 playableClassId_handle = registerVarId( new SynchronizeableInt( &playableClassId, &playableClassId, "playableClassId", PERMISSION_MASTER_SERVER) ); 72 playableUniqueId_handle = registerVarId( new SynchronizeableInt( &playableUniqueId, &playableUniqueId, "playableUniqueId", PERMISSION_MASTER_SERVER ) ); 73 modelFileName_handle = registerVarId( new SynchronizeableString( &modelFileName, &modelFileName, "modelFileName", PERMISSION_MASTER_SERVER ) ); 74 nickName_handler = registerVarId( new SynchronizeableString( &nickName, &nickName, "nickName", PERMISSION_MASTER_SERVER ) ); 75 75 76 76 MessageManager::getInstance()->registerMessageHandler( MSGID_CHANGENICKNAME, changeNickHandler, NULL ); 77 77 78 PRINTF( 0)("PlayerStats created\n");78 PRINTF(5)("PlayerStats created\n"); 79 79 } 80 80 … … 84 84 */ 85 85 PlayerStats::~PlayerStats() 86 { 87 } 88 89 90 /** 91 * override this function to be notified on change 92 * of your registred variables. 93 * @param id id's which have changed 94 */ 86 {} 87 88 89 /** 90 * override this function to be notified on change 91 * of your registred variables. 92 * @param id id's which have changed 93 */ 95 94 void PlayerStats::varChangeHandler( std::list< int > & id ) 96 95 { … … 99 98 this->setPlayableUniqueId( this->playableUniqueId ); 100 99 101 PRINTF( 0)("uniqueID changed %d %d %d\n", userId, SharedNetworkData::getInstance()->getHostID(), getUniqueID());100 PRINTF(4)("uniqueID changed %d %d %d\n", assignedUserId, SharedNetworkData::getInstance()->getHostID(), getUniqueID()); 102 101 } 103 102 … … 105 104 { 106 105 PRINTF(0)("user %s is now known as %s\n", oldNickName.c_str(), nickName.c_str()); 107 oldNickName = nickName; 108 } 109 } 106 this->oldNickName = nickName; 107 } 108 109 if ( std::find( id.begin(), id.end(), preferedTeamId_handle) != id.end() ) 110 { 111 PRINTF(0)("user %s has changed team to %i\n", nickName.c_str(), this->teamId); 112 } 113 } 114 115 110 116 111 117 /** … … 123 129 } 124 130 125 for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ ) 126 { 127 if ( dynamic_cast<PlayerStats*>(*it)->getUserId() == userId ) 131 for ( std::list<BaseObject*>::const_iterator it = list-> 132 begin(); 133 it != list->end(); 134 it++ ) 135 { 136 137 138 if ( dynamic_cast<PlayerStats*>(*it)->getAssignedUserId() == userId ) 128 139 { 129 140 return dynamic_cast<PlayerStats*>(*it); … … 148 159 149 160 this->playable = NULL; 150 for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ ) 151 { 152 if ( dynamic_cast<Playable*>(*it)->getUniqueID() == uniqueId ) 161 for ( std::list<BaseObject*>::const_iterator it = list-> 162 begin(); 163 it != list->end(); 164 it++ ) 165 { 166 if ( dynamic_cast<Playable*>(*it)-> 167 getUniqueID() == uniqueId ) 153 168 { 154 169 this->playable = dynamic_cast<Playable*>(*it); … … 159 174 } 160 175 161 if ( this->playable && userId == SharedNetworkData::getInstance()->getHostID() ) 176 if ( this->playable && this->assignedUserId == SharedNetworkData::getInstance() 177 ->getHostID() ) 162 178 { 163 179 State::getPlayer()->setPlayable( this->playable ); 180 // also set the team id 164 181 } 165 182 … … 204 221 assert( Converter::stringToByteArray( nick, data, nick.length()+INTSIZE) == nick.length()+INTSIZE ); 205 222 206 MessageManager::getInstance()->sendMessage( MSGID_CHANGENICKNAME, data, nick.length()+INTSIZE, RT_SERVER, 0, MP_HIGHBANDWIDTH );223 MessageManager::getInstance()->sendMessage( MSGID_CHANGENICKNAME, data, nick.length()+INTSIZE, RT_SERVER, NET_MASTER_SERVER, MP_HIGHBANDWIDTH ); 207 224 return; 208 225 } 209 226 } 210 227 211 bool PlayerStats::changeNickHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId ) 228 /** 229 * handler for the nick name 230 * @param messageType type of the message 231 * @param data data of the message 232 * @param dataLength length of the data 233 * @param someData some additional data 234 * @param senderId userId of the sender 235 * @param destinationId userId of the rec 236 * @return true if handled correctly 237 */ 238 bool PlayerStats::changeNickHandler( MessageType messageType, byte * data, int dataLength, void * someData, int senderId, int destinationId ) 212 239 { 213 240 std::string newNick; … … 216 243 if ( res != dataLength ) 217 244 { 218 PRINTF(2)("invalid message size from user %d\n", userId);245 PRINTF(2)("invalid message size from user %d\n", senderId); 219 246 newNick = "invalid"; 220 247 } 221 248 222 if ( PlayerStats::getStats( userId) )223 PlayerStats::getStats( userId )->setNickName( newNick );249 if ( PlayerStats::getStats( senderId) ) 250 PlayerStats::getStats( senderId )->setNickName( newNick ); 224 251 225 252 return true; 226 253 } 227 254 255 /** 256 * sets the nick name from the shell 257 * @param newNick new prefered nick name 258 */ 228 259 void PlayerStats::shellNick( const std::string& newNick ) 229 260 { … … 236 267 237 268 269 /** 270 * removes and delets all player stats 271 */ 238 272 void PlayerStats::deleteAllPlayerStats( ) 239 273 { … … 246 280 247 281 282 /** 283 * @return the score list of this player stat 284 */ 248 285 ScoreList PlayerStats::getScoreList( ) 249 286 { … … 257 294 } 258 295 259 for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ ) 296 for ( std::list<BaseObject*>::const_iterator it = list-> 297 begin(); 298 it != list->end(); 299 it++ ) 260 300 { 261 301 PlayerStats & stats = *dynamic_cast<PlayerStats*>(*it); -
trunk/src/lib/network/player_stats.h
r9110 r9656 16 16 enum 17 17 { 18 TEAM_NOTEAM = -3,19 TEAM_RANDOM = -2,20 TEAM_SPECTATOR = -118 TEAM_NOTEAM = -3, 19 TEAM_RANDOM = -2, 20 TEAM_SPECTATOR = -1 21 21 }; 22 22 23 23 24 struct PlayerScore … … 26 27 int score; 27 28 }; 29 30 28 31 typedef std::list<PlayerScore> TeamScoreList; 29 32 typedef std::map<int,TeamScoreList> ScoreList; 30 33 34 31 35 //! A class for storing player information 32 class PlayerStats : public Synchronizeable 36 class PlayerStats : public Synchronizeable 33 37 { 34 38 … … 37 41 PlayerStats( int userId ); 38 42 virtual ~PlayerStats(); 39 43 40 44 virtual void varChangeHandler( std::list<int> & id ); 41 45 42 46 static PlayerStats * getStats( int userId ); 43 44 inline int getUserId(){ return userId; } 45 47 inline int getAssignedUserId(){ return this->assignedUserId; } 48 49 46 50 inline int getTeamId(){ return teamId; } 47 51 inline void setTeamId( int teamId ){ this->teamId = teamId; } 48 52 49 53 inline int getPreferedTeamId(){ return preferedTeamId; } 50 inline void setPreferedTeamId( int preferedTeamId ) { this->preferedTeamId = preferedTeamId; }51 54 inline void setPreferedTeamId( int preferedTeamId ) { this->preferedTeamId = preferedTeamId; } 55 52 56 inline int getScore(){ return score; } 53 57 inline void setScore( int score ){ this->score = score; } 54 58 55 59 inline int getPlayableClassId(){ return playableClassId; } 56 60 void setPlayableClassId( int classId ){ this->playableClassId = classId; }; 57 61 58 62 inline int getPlayableUniqueId(){ return playableUniqueId; } 59 63 void setPlayableUniqueId( int uniqueId ); 60 64 61 65 inline std::string getModelFileName(){ return modelFileName; } 62 66 inline void setModelFileName( std::string filename ){ modelFileName = filename; } 63 67 64 68 Playable * getPlayable(); 65 69 66 70 inline std::string getNickName(){ return this->nickName; } 67 71 void setNickName( std::string nick ); 68 static bool changeNickHandler( Message Id messageId, byte * data, int dataLength, void * someData, int userId);72 static bool changeNickHandler( MessageType messageType, byte * data, int dataLength, void * someData, int senderId, int destinationId ); 69 73 void shellNick( const std::string& newNick ); 70 74 71 75 static void deleteAllPlayerStats(); 72 76 73 77 static ScoreList getScoreList(); 74 78 79 75 80 private: 76 int userId; //!< userId 77 int teamId; //!< teamId 78 int preferedTeamId; //!< preferedTeamId 81 void init(); 79 82 80 std::string nickName; //!< players nickname81 std::string oldNickName; //!< nickname player had before82 83 83 int score; //!< users score points 84 int playableClassId; //!< players playable class id 85 int playableUniqueId; //!< playable's uniqueId 86 std::string modelFileName; //!< model filename 84 private: 85 // handles for SynchronizeableVars 86 int userId_handle; 87 int teamId_handle; 88 int preferedTeamId_handle; 89 int score_handle; 90 int playableClassId_handle; 91 int playableUniqueId_handle; 92 int modelFileName_handle; 93 int nickName_handler; 87 94 88 Playable * playable; //!< pointer to players playable 95 int assignedUserId; //!< userId 96 int teamId; //!< teamId 97 int preferedTeamId; //!< preferedTeamId 89 98 90 // handles for SynchronizeableVars 91 int userId_handle; 92 int teamId_handle; 93 int preferedTeamId_handle; 94 int score_handle; 95 int playableClassId_handle; 96 int playableUniqueId_handle; 97 int modelFileName_handle; 98 int nickName_handler; 99 100 void init(); 99 std::string nickName; //!< players nickname 100 std::string oldNickName; //!< nickname player had before 101 102 int score; //!< users score points 103 int playableClassId; //!< players playable class id 104 int playableUniqueId; //!< playable's uniqueId 105 std::string modelFileName; //!< model filename 106 107 Playable * playable; //!< pointer to players playable 101 108 }; 102 109 -
trunk/src/lib/network/proxy/network_settings.cc
r9494 r9656 87 87 // setUniqueID( maxCon+2 ) because we need one id for every handshake 88 88 // and one for handshake to reject client maxCon+1 89 SharedNetworkData::getInstance()->setNewUniqueID( this->maxPlayer + 2); 89 // NEW: at most there will be 90 SharedNetworkData::getInstance()->setNewUniqueID( this->maxPlayer + NET_ID_PROXY_MAX + 2); 90 91 } 91 92 -
trunk/src/lib/network/server_socket.h
r7954 r9656 1 1 /*! 2 2 * @file server_socket.h 3 * waits for incoming connections4 3 * waits for incoming connections and handles them. 4 * 5 5 */ 6 6 -
trunk/src/lib/network/shared_network_data.h
r9494 r9656 16 16 17 17 class Synchronizeable; 18 class NetworkMonitor; 18 19 19 20 … … 64 65 inline void setDefaultSyncStream(NetworkStream* defaultSyncStream) { this->defaultSyncStream = defaultSyncStream; } 65 66 67 /** @returns the network monitor reference */ 68 inline NetworkMonitor* getNetworkMonitor() { return this->networkMonitor; } 69 /** @param networkMonitor sets the NetworkMonitor reference */ 70 inline void setNetworkMonitor( NetworkMonitor* networkMonitor) { this->networkMonitor = networkMonitor; } 71 66 72 67 73 private: … … 75 81 int hostID; //!< The Host-ID of the Manager 76 82 NetworkStream* defaultSyncStream; //!< default synchronize NetworkStream 83 NetworkMonitor* networkMonitor; //!< reference to the NetworkMonitor 77 84 78 85 static SharedNetworkData* singletonRef; //!< Pointer to the only instance of this Class -
trunk/src/lib/network/synchronizeable.cc
r9494 r9656 55 55 /* make sure loadClassId is first synced var because this is read by networkStream */ 56 56 assert( syncVarList.size() == 0 ); 57 mLeafClassId = this->registerVarId( new SynchronizeableInt( (int*)&this->getLeafClassID(), (int*)&this->getLeafClassID(), "leafClassId" 58 59 this->registerVar( new SynchronizeableInt( &this->owner, &this->owner, "owner" ) );60 this->registerVar( new SynchronizeableString( &this->objectName, &this->objectName, "objectName" ) );57 mLeafClassId = this->registerVarId( new SynchronizeableInt( (int*)&this->getLeafClassID(), (int*)&this->getLeafClassID(), "leafClassId", PERMISSION_MASTER_SERVER) ); 58 59 this->registerVar( new SynchronizeableInt( &this->owner, &this->owner, "owner", PERMISSION_MASTER_SERVER ) ); 60 this->registerVar( new SynchronizeableString( &this->objectName, &this->objectName, "objectName", PERMISSION_MASTER_SERVER ) ); 61 61 } 62 62 … … 126 126 int Synchronizeable::getStateDiff( int userId, byte* data, int maxLength, int stateId, int fromStateId, int priorityTH ) 127 127 { 128 // make sure this user has his history129 if ( sentStates.size() <= userId )128 // make sure this user has his history or resize for new clients 129 if ( (int)sentStates.size() <= userId ) 130 130 sentStates.resize( userId+1 ); 131 131 … … 133 133 int neededSize = 0; 134 134 135 // calculate the needed space for network packet by summing up 135 136 for ( SyncVarList::iterator it = syncVarList.begin(); it != syncVarList.end(); it++ ) 136 137 { … … 201 202 int n; 202 203 203 bool hasPermission = false;204 204 bool sizeChanged = false; 205 205 … … 207 207 for ( SyncVarList::iterator it = syncVarList.begin(); it != syncVarList.end(); it++ ) 208 208 { 209 // DATA PERMISSIONS 210 // check if this synchronizeable has the permissions to write the data 211 212 // first check MASTER_SERVER permissions 213 if( SharedNetworkData::getInstance()->isMasterServer() && (*it)->checkPermission( PERMISSION_MASTER_SERVER )) 214 hasPermission = true; 215 // now check PROXY_SERVER permissions 216 else if( SharedNetworkData::getInstance()->isProxyServerActive() && (*it)->checkPermission( PERMISSION_PROXY_SERVER )) 217 hasPermission = true; 218 // now check OWNER permissions 219 else if( this->owner == SharedNetworkData::getInstance()->getHostID() && (*it)->checkPermission( PERMISSION_OWNER )) 220 hasPermission = true; 221 // now check ALL permissions 222 else if( (*it)->checkPermission( PERMISSION_ALL )) 223 hasPermission = true; 224 // SPECIAL: get write permissions if i am master server and i am able to overwrite the client stuff 225 #warning this could probably override also clients that are connected to another proxy: the master server overwrites it 226 else if( SharedNetworkData::getInstance()->isMasterServer() && this->owner != userId && (*it)->checkPermission( PERMISSION_OWNER )) 227 hasPermission = true; 228 // SPECIAL: get write permissions if i am proxy server and i am able to overwrite the client stuff 229 else if( SharedNetworkData::getInstance()->isProxyServerActive() && this->networkStream->isUserClient(userId) 230 && this->owner != userId && (*it)->checkPermission( PERMISSION_OWNER ) ) 231 hasPermission = true; 209 210 //////////////////////////////// 211 // Data SENDING Permissions 212 //////////////////////////////// 213 bool hasPermission = false; 214 bool b1, b2, b3, b4, b5, b6, b7, b8, b9; 215 b1 = b2 = b3 = b4 = b5 = b6 = b7 = b8 = b9 = false; 216 217 218 // Permission OWNER accept if: 219 // I am the owner 220 if( (*it)->checkPermission( PERMISSION_OWNER ) && this->owner == SharedNetworkData::getInstance()->getHostID()) { 221 hasPermission = true; b1 = true; } 222 // reciever != owner && owner is local 223 else if( (*it)->checkPermission( PERMISSION_OWNER ) && userId != this->owner && 224 (SharedNetworkData::getInstance()->isUserLocal(this->owner) || this->owner == SharedNetworkData::getInstance()->getHostID())) { 225 hasPermission = true; b2 = true; } 226 227 228 // Permission MASTER_SERVER accept if: 229 // im MASTER_SERVER 230 else if( (*it)->checkPermission( PERMISSION_MASTER_SERVER ) && SharedNetworkData::getInstance()->isMasterServer()) { 231 hasPermission = true; b3 = true; } 232 // im PROXY_SERVER && reciever == CLIENT 233 else if( (*it)->checkPermission( PERMISSION_MASTER_SERVER ) && SharedNetworkData::getInstance()->isProxyServerActive() && 234 SharedNetworkData::getInstance()->isUserClient( userId)) { 235 hasPermission = true; b4 = true; } 236 237 238 // Pemission SERVER accept if: 239 // i am server && reciever == CLIENT 240 else if( (*it)->checkPermission( PERMISSION_SERVER ) && !SharedNetworkData::getInstance()->isClient() && 241 SharedNetworkData::getInstance()->isUserClient( userId)) { 242 hasPermission = true; b5 = true; } 243 // i am SERVER && reciever == SERVER && reciever != owner && ( owner is local || i am owner) 244 else if( (*it)->checkPermission( PERMISSION_SERVER ) && !SharedNetworkData::getInstance()->isClient() && 245 userId != this->owner && 246 ( SharedNetworkData::getInstance()->isUserLocal( this->owner) || this->owner == SharedNetworkData::getInstance()->getHostID())) { 247 hasPermission = true; b6 = true; } 248 249 250 // Permission ALL accept if: 251 else if( (*it)->checkPermission( PERMISSION_ALL )) { 252 hasPermission = true; b7 = true; } 253 // or else refuse sending data 232 254 else 233 255 hasPermission = false; 234 256 235 257 258 236 259 if ( sizeIter == stateFrom->sizeList.end() || *sizeIter != (*it)->getSize() ) 237 260 sizeChanged = true; … … 241 264 n = (*it)->writeToBuf( stateTo->data+i, stateTo->dataLength - i ); 242 265 //NETPRINTF(0)("getvar %s %d\n", (*it)->getName().c_str(), n); 243 //PRINTF(0)("getvar %s %d\n", (*it)->getName().c_str(), n); 266 // PRINTF(0)("sending %s %d\n", (*it)->getName().c_str(), n); 267 268 // if( this->isA(CL_PLAYABLE)) 269 // { 270 // PRINTF(0)("ms: %i, ps: %i, c: %i, sender: %i, reciever: %i, owner: %i, perm: (ow %i, ms %i, s %i, a %i)\n", 271 // SharedNetworkData::getInstance()->isMasterServer(), SharedNetworkData::getInstance()->isProxyServerActive(), SharedNetworkData::getInstance()->isClient(), 272 // SharedNetworkData::getInstance()->getHostID(), userId, this->owner, 273 // (*it)->checkPermission( PERMISSION_OWNER ), (*it)->checkPermission( PERMISSION_MASTER_SERVER ), 274 // (*it)->checkPermission( PERMISSION_SERVER ), (*it)->checkPermission( PERMISSION_ALL )); 275 // PRINTF(0)("hasPermission: %i, sizeChanged: %i, eval: %i, %i, %i, %i, %i, %i, %i\n", hasPermission, sizeChanged, b1, b2, b3, b4, b5, b6, b7); 276 // PRINTF(0)("sending %s %s %d\n", this->getClassCName(), (*it)->getName().c_str(), n); 277 // } 278 279 244 280 stateTo->sizeList.push_back( n ); 245 281 // this is only for very hardcore debug sessions … … 282 318 283 319 /** 284 * sets a new state out of a diff created on another host 320 * sets a new state out of a diff created on another host (recieving data) 285 321 * @param userId hostId of user who send me that diff 286 322 * @param data pointer to diff … … 295 331 { 296 332 //make sure this user has his history 297 if ( recvStates.size() <= userId )333 if ( (int)recvStates.size() <= userId ) 298 334 recvStates.resize( userId+1 ); 299 335 … … 345 381 int n = 0; 346 382 std::list<int> changes; 347 bool hasPermission = false;348 383 349 384 // extract the new state for every client … … 353 388 // check if this synchronizeable has the permissions to write the data 354 389 355 // first check MASTER_SERVER permissions 356 if( this->networkStream->isUserMasterServer( userId ) && (*it)->checkPermission( PERMISSION_MASTER_SERVER )) 357 hasPermission = true; 358 // now check PROXY_SERVER permissions 359 else if( this->networkStream->isUserProxyServerActive( userId ) && (*it)->checkPermission( PERMISSION_MASTER_SERVER ) 360 && SharedNetworkData::getInstance()->isClient()) 361 hasPermission = true; 362 // now check OWNER permissions 363 else if( this->owner == userId && (*it)->checkPermission( PERMISSION_OWNER )) 364 hasPermission = true; 365 // now check ALL permissions 366 else if( (*it)->checkPermission( PERMISSION_ALL )) 367 hasPermission = true; 368 // SPECIAL: get write permissions if im sending to a master server that does not own this sync 369 else if( this->networkStream->isUserMasterServer( userId ) && this->owner != SharedNetworkData::getInstance()->getHostID() && (*it)->checkPermission( PERMISSION_OWNER )) 370 hasPermission = true; 371 // SPECIAL: get write permissions if im sending to a proxy server that does not own this sync 372 else if( this->networkStream->isUserProxyServerActive( userId ) && SharedNetworkData::getInstance()->isClient() 373 && this->owner != SharedNetworkData::getInstance()->getHostID() && (*it)->checkPermission( PERMISSION_OWNER )) 374 hasPermission = true; 390 bool hasPermission = false; 391 bool b1, b2, b3, b4, b5, b6, b7, b8, b9; 392 b1 = b2 = b3 = b4 = b5 = b6 = b7 = b8 = b9 = false; 393 394 //////////////////////////////// 395 // Data RECIEVING Permissions 396 //////////////////////////////// 397 398 // i should never ever receive a state update from a synchronizeable, that belongs to me! If it does somethings wrong with the send rules 399 // assert( !((*it)->checkPermission( PERMISSION_OWNER ) && this->owner == SharedNetworkData::getInstance()->getHostID())); 400 401 402 // Permission OWNER accept if: 403 // sender == owner 404 if( (*it)->checkPermission( PERMISSION_OWNER ) && this->owner == userId) { 405 hasPermission = true; b1 = true; } 406 // sender == MASTER_SERVER 407 else if( (*it)->checkPermission( PERMISSION_OWNER ) && SharedNetworkData::getInstance()->isUserMasterServer( userId) 408 && this->owner != SharedNetworkData::getInstance()->getHostID()) { 409 hasPermission = true; b2 = true; } 410 // sender == PROXY_SERVER 411 else if( (*it)->checkPermission( PERMISSION_OWNER ) && SharedNetworkData::getInstance()->isUserProxyServerActive( userId) && 412 this->owner != SharedNetworkData::getInstance()->getHostID()) { 413 hasPermission = true; b3 = true; } 414 415 416 417 // Permission MASTER_SERVER accept if: 418 // sender == MASTER_SERVER 419 else if( (*it)->checkPermission( PERMISSION_MASTER_SERVER) && SharedNetworkData::getInstance()->isUserMasterServer( userId)) { 420 hasPermission = true; b4 = true; } 421 // sender == PROXY_SERVER && im not MASTER_SERVER && im not PROXY_SERVER 422 else if( (*it)->checkPermission( PERMISSION_MASTER_SERVER) && SharedNetworkData::getInstance()->isClient() && 423 SharedNetworkData::getInstance()->isUserProxyServerActive( userId)) { 424 hasPermission = true; b5 = true; } 425 426 // Permission SERVER accept if: 427 // sender == SERVER 428 else if( (*it)->checkPermission( PERMISSION_SERVER ) && !SharedNetworkData::getInstance()->isUserClient( userId) /*&& 429 SharedNetworkData::getInstance()->isClient()*/) { 430 hasPermission = true; b6 = true; } 431 432 433 434 // Pemission ALL accept if: 435 else if( (*it)->checkPermission( PERMISSION_ALL )) { 436 hasPermission = true; b8 = true; } 437 438 439 // no rights to over-write local data 375 440 else 376 441 hasPermission = false; … … 384 449 i += n; 385 450 //NETPRINTF(0)("%s::setvar %s %d\n", getClassCName(), (*it)->getName().c_str(), n); 386 //PRINTF(0)("%s::setvar %s %d\n", getClassCName(),(*it)->getName().c_str(), n);451 // PRINTF(0)("recieving: %s %d\n", (*it)->getName().c_str(), n); 387 452 //(*it)->debug(); 453 454 // if( this->isA(CL_PLAYABLE)) 455 // { 456 // PRINTF(0)("ms: %i, ps: %i, c: %i, sender: %i, reciever: %i, owner: %i, perm: (ow %i, ms %i, s %i, a %i)\n", 457 // SharedNetworkData::getInstance()->isMasterServer(), SharedNetworkData::getInstance()->isProxyServerActive(), SharedNetworkData::getInstance()->isClient(), 458 // userId, SharedNetworkData::getInstance()->getHostID(), this->owner, 459 // (*it)->checkPermission( PERMISSION_OWNER ), (*it)->checkPermission( PERMISSION_MASTER_SERVER ), 460 // (*it)->checkPermission( PERMISSION_SERVER ), (*it)->checkPermission( PERMISSION_ALL )); 461 // PRINTF(0)("hasPermission: %i, eval: %i, %i, %i, %i, %i, %i, %i, %i\n", hasPermission, b1, b2, b3, b4, b5, b6, b7, b8); 462 // PRINTF(0)("rec %s %s %d\n", this->getClassCName(), (*it)->getName().c_str(), n); 463 // } 464 465 388 466 if ( (*it)->getHasChanged() ) 389 467 { … … 444 522 void Synchronizeable::cleanUpUser( int userId ) 445 523 { 446 if ( recvStates.size() > userId )524 if ( (int)recvStates.size() > userId ) 447 525 { 448 526 for ( std::list<StateHistoryEntry*>::iterator it = recvStates[userId].begin(); it != recvStates[userId].end(); it++ ) … … 459 537 } 460 538 461 if ( sentStates.size() > userId )539 if ( (int)sentStates.size() > userId ) 462 540 { 463 541 … … 485 563 { 486 564 //make sure this user has his history 487 if ( recvStates.size() <= userId )565 if ( (int)recvStates.size() <= userId ) 488 566 recvStates.resize( userId+1 ); 489 567 … … 575 653 { 576 654 //make sure this user has his history 577 if ( sentStates.size() <= userId )655 if ( (int)sentStates.size() <= userId ) 578 656 sentStates.resize( userId+1 ); 579 657 -
trunk/src/lib/network/synchronizeable_var/synchronizeable_bool.h
r9406 r9656 12 12 13 13 public: 14 SynchronizeableBool( bool * ptrIn, bool * ptrOut, std::string name, int permission = PERMISSION_MASTER_SERVER, int priority = 0 );14 SynchronizeableBool( bool * ptrIn, bool * ptrOut, std::string name, int permission, int priority = 0 ); 15 15 virtual ~SynchronizeableBool(); 16 16 -
trunk/src/lib/network/synchronizeable_var/synchronizeable_float.h
r9406 r9656 13 13 14 14 public: 15 SynchronizeableFloat( float * ptrIn, float * ptrOut, std::string name, int permission = PERMISSION_MASTER_SERVER, int priority = 0 );15 SynchronizeableFloat( float * ptrIn, float * ptrOut, std::string name, int permission, int priority = 0 ); 16 16 virtual ~SynchronizeableFloat(); 17 17 -
trunk/src/lib/network/synchronizeable_var/synchronizeable_int.h
r9406 r9656 13 13 14 14 public: 15 SynchronizeableInt( int * ptrIn, int * ptrOut, std::string name, int permission = PERMISSION_MASTER_SERVER, int priority = 0 );15 SynchronizeableInt( int * ptrIn, int * ptrOut, std::string name, int permission, int priority = 0 ); 16 16 virtual ~SynchronizeableInt(); 17 17 -
trunk/src/lib/network/synchronizeable_var/synchronizeable_ip.h
r9406 r9656 15 15 16 16 public: 17 SynchronizeableIP( IP *ptrIn, IP * ptrOut, std::string name, int permission = PERMISSION_MASTER_SERVER, int priority = 0 );17 SynchronizeableIP( IP *ptrIn, IP * ptrOut, std::string name, int permission, int priority = 0 ); 18 18 virtual ~SynchronizeableIP(); 19 19 -
trunk/src/lib/network/synchronizeable_var/synchronizeable_quaternion.h
r9406 r9656 14 14 15 15 public: 16 SynchronizeableQuaternion( Quaternion * ptrIn, Quaternion * ptrOut, std::string name, int permission = PERMISSION_MASTER_SERVER, int priority = 0 );16 SynchronizeableQuaternion( Quaternion * ptrIn, Quaternion * ptrOut, std::string name, int permission, int priority = 0 ); 17 17 virtual ~SynchronizeableQuaternion(); 18 18 -
trunk/src/lib/network/synchronizeable_var/synchronizeable_string.h
r9406 r9656 14 14 15 15 public: 16 SynchronizeableString( std::string * ptrIn, std::string * ptrOut, std::string name, int permission = PERMISSION_MASTER_SERVER, int priority = 0 );16 SynchronizeableString( std::string * ptrIn, std::string * ptrOut, std::string name, int permission, int priority = 0 ); 17 17 virtual ~SynchronizeableString(); 18 18 -
trunk/src/lib/network/synchronizeable_var/synchronizeable_uint.h
r9406 r9656 13 13 14 14 public: 15 SynchronizeableUInt( unsigned int * ptrIn, unsigned int * ptrOut, std::string name, int permission = PERMISSION_MASTER_SERVER, int priority = 0 );15 SynchronizeableUInt( unsigned int * ptrIn, unsigned int * ptrOut, std::string name, int permission, int priority = 0 ); 16 16 virtual ~SynchronizeableUInt(); 17 17 -
trunk/src/lib/network/synchronizeable_var/synchronizeable_var.h
r9494 r9656 15 15 16 16 public: 17 SynchronizeableVar( void * ptrIn, void * ptrOut, std::string name, int length, int permission = PERMISSION_MASTER_SERVER, int priority = 0 );17 SynchronizeableVar( void * ptrIn, void * ptrOut, std::string name, int length, int permission, int priority = 0 ); 18 18 virtual ~SynchronizeableVar(); 19 19 -
trunk/src/lib/network/synchronizeable_var/synchronizeable_vector.h
r9406 r9656 14 14 15 15 public: 16 SynchronizeableVector( Vector * ptrIn, Vector * ptrOut, std::string name, int permission = PERMISSION_MASTER_SERVER, int priority = 0 );16 SynchronizeableVector( Vector * ptrIn, Vector * ptrOut, std::string name, int permission, int priority = 0 ); 17 17 virtual ~SynchronizeableVector(); 18 18 -
trunk/src/lib/network/udp_socket.h
r9406 r9656 41 41 42 42 private: 43 void init(); 44 45 bool writeRawPacket( byte * data, int length ); 46 bool checkUdpCmd( byte udpCmd ); 47 bool checkRandomByte( byte rndByte ); 48 byte generateNewRandomByte(); 49 50 51 private: 43 52 UdpServerSocket * serverSocket; //!< will get packets here 44 53 int userId; //!< user id used by serverSocket … … 47 56 48 57 byte randomByte; //!< contains random bytes & 0xFC 49 50 bool writeRawPacket( byte * data, int length );51 bool checkUdpCmd( byte udpCmd );52 bool checkRandomByte( byte rndByte );53 byte generateNewRandomByte();54 55 void init();56 57 58 }; 58 59
Note: See TracChangeset
for help on using the changeset viewer.