- Timestamp:
- Jul 12, 2006, 10:41:00 AM (18 years ago)
- Location:
- branches/proxy/src/lib/network
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/proxy/src/lib/network/network_stream.cc
r9248 r9249 75 75 this->peers[0].socket = new UdpSocket( host, port ); 76 76 this->peers[0].userId = 0; 77 this->peers[0].is Server = true;77 this->peers[0].isMasterServer = true; 78 78 this->peers[0].connectionMonitor = new ConnectionMonitor( 0 ); 79 79 } … … 222 222 currentState++; 223 223 224 if ( this->type == NET_ SERVER )224 if ( this->type == NET_MASTER_SERVER ) 225 225 { 226 226 if ( serverSocket ) … … 284 284 peers[clientId].handshake->setUniqueID(clientId); 285 285 peers[clientId].userId = clientId; 286 peers[clientId].is Server = false;286 peers[clientId].isMasterServer = false; 287 287 } 288 288 else … … 299 299 peers[clientId].connectionMonitor = new ConnectionMonitor( clientId ); 300 300 peers[clientId].userId = clientId; 301 peers[clientId].is Server = false;301 peers[clientId].isMasterServer = false; 302 302 303 303 PRINTF(0)("num sync: %d\n", synchronizeables.size()); … … 423 423 if ( !it->second.handshake->allowDel() ) 424 424 { 425 if ( type != NET_ SERVER )425 if ( type != NET_MASTER_SERVER ) 426 426 { 427 427 SharedNetworkData::getInstance()->setHostID( it->second.handshake->getHostId() ); … … 442 442 if ( it->second.handshake->canDel() ) 443 443 { 444 if ( type == NET_ SERVER )444 if ( type == NET_MASTER_SERVER ) 445 445 { 446 446 handleNewClient( it->second.userId ); … … 516 516 517 517 // if we are a server and this is not our handshake 518 if ( is Server() && sync.getLeafClassID() == CL_HANDSHAKE && sync.getUniqueID() != peer->second.userId )518 if ( isMasterServer() && sync.getLeafClassID() == CL_HANDSHAKE && sync.getUniqueID() != peer->second.userId ) 519 519 continue; 520 520 … … 576 576 // now compress the data with the zip library 577 577 int compLength = 0; 578 if ( this->is Server() )578 if ( this->isMasterServer() ) 579 579 compLength = Zip::getInstance()->zip( buf, offset, compBuf, UDP_PACKET_SIZE, dictServer ); 580 580 else … … 691 691 } 692 692 693 if ( !peers[peer->second.userId].is Server )693 if ( !peers[peer->second.userId].isMasterServer ) 694 694 { 695 695 offset += syncDataLength; -
branches/proxy/src/lib/network/network_stream.h
r9248 r9249 27 27 public: 28 28 PeerInfo() { clear(); } 29 void clear() { userId = 0; is Server = false; socket = NULL; handshake = NULL; lastAckedState = 0; lastRecvedState = 0; connectionMonitor = NULL; }29 void clear() { userId = 0; isMasterServer = false; socket = NULL; handshake = NULL; lastAckedState = 0; lastRecvedState = 0; connectionMonitor = NULL; } 30 30 31 31 32 32 public: 33 33 int userId; 34 bool isServer; 34 bool isMasterServer; 35 bool isProxyServer; 36 bool isClient; 35 37 NetworkSocket * socket; 36 38 Handshake * handshake; … … 75 77 76 78 inline bool isUserIdActive( int userID ) { return (peers.find(userID) != peers.end()); } 77 inline bool isUserServer( int userID ){ if ( !isUserIdActive(userID) ) return false; return peers[userID].isServer; } 79 inline bool isUserMasterServer( int userID ){ if ( !isUserIdActive(userID) ) return false; return peers[userID].isMasterServer; } 80 inline bool isUserProxyServer( int userID ){ if ( !isUserIdActive(userID) ) return false; return peers[userID].isProxyServer; } 81 inline bool isUserClient( int userID ){ if ( !isUserIdActive(userID) ) return false; return peers[userID].isClient; } 78 82 79 83 void debug(); -
branches/proxy/src/lib/network/synchronizeable.cc
r9110 r9249 42 42 this->networkStream = NULL; 43 43 this->bSynchronize = false; 44 44 45 45 if( State::isOnline()) 46 46 { … … 54 54 assert( syncVarList.size() == 0 ); 55 55 mLeafClassId = this->registerVarId( new SynchronizeableInt( (int*)&this->getLeafClassID(), (int*)&this->getLeafClassID(), "leafClassId" ) ); 56 56 57 57 this->registerVar( new SynchronizeableInt( &this->owner, &this->owner, "owner" ) ); 58 58 this->registerVar( new SynchronizeableString( &this->objectName, &this->objectName, "objectName" ) ); … … 69 69 { 70 70 this->networkStream->disconnectSynchronizeable(*this); 71 71 72 72 if ( this->isServer() && this->beSynchronized() && this->getUniqueID() > 0 && !this->isA( CL_MESSAGE_MANAGER ) ) 73 73 NetworkGameManager::getInstance()->removeSynchronizeable( this->getUniqueID() ); 74 74 } 75 75 76 76 for ( SyncVarList::iterator it = syncVarList.begin(); it != syncVarList.end(); it++ ) 77 77 { … … 79 79 } 80 80 syncVarList.clear(); 81 81 82 82 for ( UserStateHistory::iterator it = recvStates.begin(); it != recvStates.end(); it++ ) 83 83 { … … 93 93 94 94 } 95 95 96 96 for ( UserStateHistory::iterator it = sentStates.begin(); it != sentStates.end(); it++ ) 97 97 { … … 169 169 (*it2)->data = NULL; 170 170 } 171 171 172 172 delete *it2; 173 173 } … … 181 181 while ( it != sentStates[userId].end() && (*it)->stateId != fromStateId ) 182 182 it++; 183 183 184 184 // if ( getLeafClassID() == CL_SPACE_SHIP ) 185 185 // { … … 196 196 197 197 stateFrom = initialEntry; 198 198 199 199 sentStates[userId].push_back( stateFrom ); 200 200 } … … 205 205 206 206 sentStates[userId].push_back( stateTo ); 207 207 208 208 stateTo->stateId = stateId; 209 209 stateTo->dataLength = neededSize; … … 214 214 int i = 0; 215 215 int n; 216 216 217 217 bool hasPermission; 218 218 bool sizeChanged = false; … … 225 225 this->owner == SharedNetworkData::getInstance()->getHostID() && (*it)->checkPermission( PERMISSION_OWNER ) || 226 226 this->isServer() && this->owner != userId && (*it)->checkPermission( PERMISSION_OWNER ) || 227 (*it)->checkPermission( PERMISSION_ALL ) 227 (*it)->checkPermission( PERMISSION_ALL ) 228 228 ); 229 230 if ( sizeIter == stateFrom->sizeList.end() || *sizeIter != (*it)->getSize() ) 229 230 if ( sizeIter == stateFrom->sizeList.end() || *sizeIter != (*it)->getSize() ) 231 231 sizeChanged = true; 232 232 233 233 if ( ( hasPermission && (*it)->getPriority() >= priorityTH ) || sizeChanged ) 234 234 { … … 303 303 it++; 304 304 305 305 306 306 // if ( getLeafClassID() == CL_SPACE_SHIP ) 307 307 // { … … 318 318 319 319 stateFrom = initialEntry; 320 320 321 321 recvStates[userId].push_back( stateFrom ); 322 322 } 323 323 else 324 324 stateFrom = (*it); 325 325 326 326 //apply diff 327 327 for ( int i = 0; i<length; i++ ) … … 331 331 else 332 332 stateTo->data[i] = data[i]; 333 334 } 335 333 334 } 335 336 336 //add state to state history 337 337 recvStates[userId].push_back( stateTo ); 338 338 339 339 int i = 0; 340 340 int n = 0; 341 341 std::list<int> changes; 342 342 343 343 for ( SyncVarList::iterator it = syncVarList.begin(); it != syncVarList.end(); it++ ) 344 344 { 345 345 if ( 346 (*it)->checkPermission( PERMISSION_SERVER ) && networkStream->isUser Server( userId ) ||346 (*it)->checkPermission( PERMISSION_SERVER ) && networkStream->isUserMasterServer( userId ) || 347 347 (*it)->checkPermission( PERMISSION_OWNER ) && this->owner == userId || 348 networkStream->isUser Server( userId ) && this->owner != SharedNetworkData::getInstance()->getHostID() && (*it)->checkPermission( PERMISSION_OWNER ) ||349 (*it)->checkPermission( PERMISSION_ALL ) 348 networkStream->isUserMasterServer( userId ) && this->owner != SharedNetworkData::getInstance()->getHostID() && (*it)->checkPermission( PERMISSION_OWNER ) || 349 (*it)->checkPermission( PERMISSION_ALL ) 350 350 ) 351 351 { … … 370 370 371 371 this->varChangeHandler( changes ); 372 372 373 373 return i; 374 374 } … … 423 423 (*it)->data = NULL; 424 424 } 425 425 426 426 delete *it; 427 427 } 428 428 recvStates[userId].clear(); 429 429 } 430 430 431 431 if ( sentStates.size() > userId ) 432 432 { 433 433 434 434 for ( std::list<StateHistoryEntry*>::iterator it = sentStates[userId].begin(); it != sentStates[userId].end(); it++ ) 435 435 { … … 439 439 (*it)->data = NULL; 440 440 } 441 441 442 442 delete *it; 443 443 } … … 448 448 /** 449 449 * this function is called after recieving a state. 450 * @param userId 451 * @param stateId 452 * @param fromStateId 450 * @param userId 451 * @param stateId 452 * @param fromStateId 453 453 */ 454 454 void Synchronizeable::handleRecvState( int userId, int stateId, int fromStateId ) … … 457 457 if ( recvStates.size() <= userId ) 458 458 recvStates.resize( userId+1 ); 459 459 460 460 //remove old states 461 461 StateHistory::iterator it = recvStates[userId].begin(); … … 485 485 StateHistory::iterator delIt = it; 486 486 it ++; 487 487 488 488 if ( (*delIt)->data ) 489 489 { … … 493 493 delete *delIt; 494 494 recvStates[userId].erase( delIt ); 495 495 496 496 continue; 497 497 } 498 498 it++; 499 499 } 500 500 501 501 StateHistory::iterator fromState = recvStates[userId].end(); 502 502 StateHistory::iterator toState = recvStates[userId].end(); 503 503 504 504 for ( it = recvStates[userId].begin(); it != recvStates[userId].end(); it++ ) 505 505 { … … 508 508 if ( (*it)->stateId == fromStateId ) 509 509 fromState = it; 510 510 511 511 if ( fromState != recvStates[userId].end() && toState != recvStates[userId].end() ) 512 512 break; 513 513 } 514 514 515 515 // setStateDiff was not called and i know fromStateId 516 516 if ( fromState != recvStates[userId].end() && toState == recvStates[userId].end() ) 517 517 { 518 518 StateHistoryEntry * entry = new StateHistoryEntry; 519 519 520 520 entry->dataLength = (*fromState)->dataLength; 521 521 if ( entry->dataLength > 0 ) 522 522 { 523 523 entry->data = new byte[entry->dataLength]; 524 524 525 525 assert( (*fromState)->data ); 526 526 memcpy( entry->data, (*fromState)->data, entry->dataLength ); … … 528 528 else 529 529 entry->data = NULL; 530 530 531 531 entry->sizeList = (*fromState)->sizeList; 532 532 entry->stateId = stateId; 533 533 534 534 recvStates[userId].push_back(entry); 535 535 } … … 538 538 /** 539 539 * this function is called after sending a state 540 * @param userId 541 * @param stateId 542 * @param fromStateId 540 * @param userId 541 * @param stateId 542 * @param fromStateId 543 543 */ 544 544 void Synchronizeable::handleSentState( int userId, int stateId, int fromStateId ) … … 557 557 StateHistory::iterator delIt = it; 558 558 it ++; 559 559 560 560 if ( (*delIt)->data ) 561 561 { … … 565 565 delete *delIt; 566 566 sentStates[userId].erase( delIt ); 567 567 568 568 continue; 569 569 } … … 571 571 } 572 572 573 573 574 574 StateHistory::iterator fromState = sentStates[userId].end(); 575 575 StateHistory::iterator toState = sentStates[userId].end(); 576 576 577 577 for ( it = sentStates[userId].begin(); it != sentStates[userId].end(); it++ ) 578 578 { … … 581 581 if ( (*it)->stateId == fromStateId ) 582 582 fromState = it; 583 583 584 584 if ( fromState != sentStates[userId].end() && toState != sentStates[userId].end() ) 585 585 break; 586 586 } 587 587 588 588 589 589 // getStateDiff was not called and i know fromStateId 590 590 if ( fromState != sentStates[userId].end() && toState == sentStates[userId].end() ) 591 591 { 592 592 StateHistoryEntry * entry = new StateHistoryEntry; 593 593 594 594 entry->dataLength = (*fromState)->dataLength; 595 595 if ( entry->dataLength > 0 ) 596 596 { 597 597 entry->data = new byte[entry->dataLength]; 598 598 599 599 assert( (*fromState)->data ); 600 600 memcpy( entry->data, (*fromState)->data, entry->dataLength ); … … 602 602 else 603 603 entry->data = NULL; 604 604 605 605 entry->sizeList = (*fromState)->sizeList; 606 606 entry->stateId = stateId; 607 607 608 608 sentStates[userId].push_back(entry); 609 609 } 610 611 } 612 613 614 610 611 } 612 613 614
Note: See TracChangeset
for help on using the changeset viewer.