Changeset 7872 in orxonox.OLD for branches/network
- Timestamp:
- May 26, 2006, 2:08:51 PM (19 years ago)
- Location:
- branches/network/src
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/network/src/lib/network/connection_monitor.cc
r7851 r7872 126 126 127 127 if ( packetHistory.size() <= 1 || tick - packetHistory.begin()->first == 0 ) 128 res = 0 ;128 res = 0.0f; 129 129 else 130 130 res /= (float)((tick - packetHistory.begin()->first)*( 1 + 1/((float)(packetHistory.size()-1)) )); 131 131 132 res *= 1000 ;132 res *= 1000.0f; 133 133 134 134 return res; … … 148 148 outgoingZippedBandWidth = calculateBandWidth( outgoingZippedPacketHistory, tick ); 149 149 150 NETPRINTF(n)("UPSTREAM: user: %d bandwidth %f \n", userId, outgoingZippedBandWidth);150 NETPRINTF(n)("UPSTREAM: user: %d bandwidth %f nOutgoingPackets %d\n", userId, outgoingZippedBandWidth, nOutgoingPackets ); 151 151 152 152 } … … 163 163 incomingZippedBandWidth = calculateBandWidth( incomingZippedPacketHistory, tick ); 164 164 165 NETPRINTF(n)("DOWNSTREAM: user: %d bandwidth %f \n", userId, incomingZippedBandWidth);165 NETPRINTF(n)("DOWNSTREAM: user: %d bandwidth %f nIncomingPackets %d\n", userId, incomingZippedBandWidth, nIncomingPackets ); 166 166 167 167 } 168 168 169 170 bool ConnectionMonitor::hasTimedOut( ) 171 { 172 if ( lastPacketTick + SECS_TO_TIMEOUT*1000 < SDL_GetTicks() && nIncomingPackets > 0 ) 173 return true; 174 175 if ( nIncomingPackets == 0 && nOutgoingPackets >= NETWORK_FREQUENCY*SECS_TO_TIMEOUT ) 176 return true; 177 178 return false; 179 } 180 181 -
branches/network/src/lib/network/connection_monitor.h
r7851 r7872 30 30 void calculatePing(); 31 31 32 bool hasTimedOut() { return ( lastPacketTick + SECS_TO_TIMEOUT*1000 < SDL_GetTicks() ) && nIncomingPackets > 0; }32 bool hasTimedOut(); 33 33 34 34 private: -
branches/network/src/lib/network/handshake.cc
r7792 r7872 41 41 errorString_handler = registerVarId( new SynchronizeableString( &localState.errorString, &remoteState.errorString, "errorString", PERMISSION_ALL ) ); 42 42 43 candel_id = registerVarId( new SynchronizeableInt( &localState.canDel, &remoteState.canDel, "canDel", PERMISSION_ALL ) ); 44 43 45 localState.completed = 0; 44 46 localState.error = 0; … … 49 51 localState.orxId = _ORXONOX_ID; 50 52 localState.version = _ORXONOX_VERSION; 53 localState.canDel = 0; 51 54 52 55 remoteState.completed = 0; … … 58 61 remoteState.orxId = 0; 59 62 remoteState.version = 0; 63 remoteState.canDel = 0; 60 64 61 65 this->setSynchronized(true); … … 95 99 } 96 100 101 if ( *it == candel_id ) 102 { 103 PRINTF(0)("handshake finished candel changed\n"); 104 } 105 97 106 } 98 107 … … 101 110 remoteState.version == _ORXONOX_VERSION 102 111 ) 103 localState.completed = true;112 localState.completed = 1; 104 113 } 105 114 -
branches/network/src/lib/network/handshake.h
r7778 r7872 23 23 24 24 int completed; 25 int canDel; 25 26 26 27 int error; … … 39 40 inline int getMessageManagerId(){ return remoteState.messageManagerId; } 40 41 inline void doReject( std::string reason ){ localState.error = 1; localState.errorString = "the server rejected your connection ["+ reason +"]"; } 42 inline bool canDel(){ return localState.canDel == 1 && remoteState.canDel == 1; } 43 inline bool allowDel(){ return localState.canDel == 1; } 44 inline void del(){ localState.canDel = 1; } 41 45 42 46 virtual void varChangeHandler( std::list<int> & id ); … … 54 58 int orxId_handler; 55 59 int version_handler; 60 int candel_id; 56 61 57 62 }; -
branches/network/src/lib/network/message_manager.cc
r7697 r7872 288 288 // just do something so map creates a new entry 289 289 messageQueue[userId].toAck.clear(); 290 assert( messageQueue[userId].messages.size() == 0 );290 //assert( messageQueue[userId].messages.size() == 0 ); 291 291 } 292 292 -
branches/network/src/lib/network/message_manager.h
r7693 r7872 92 92 virtual int setStateDiff( int userId, byte* data, int length, int stateId, int fromStateId ); 93 93 virtual void cleanUpUser( int userId ); 94 virtual void handleSentState( int userId, int stateId, int fromStateId ){} 95 virtual void handleRecvState( int userId, int stateId, int fromStateId ){} 94 96 95 97 void initUser( int userId ); -
branches/network/src/lib/network/network_stream.cc
r7851 r7872 188 188 else 189 189 { 190 if ( peers[0].socket && !peers[0].socket->isOk() )190 if ( peers[0].socket && ( !peers[0].socket->isOk() || peers[0].connectionMonitor->hasTimedOut() ) ) 191 191 { 192 192 PRINTF(1)("lost connection to server\n"); … … 272 272 ) 273 273 { 274 PRINTF(0)("Client is gone: %d\n", it->second.userId); 274 std::string reason = "disconnected"; 275 if ( it->second.connectionMonitor->hasTimedOut() ) 276 reason = "timeout"; 277 PRINTF(0)("Client is gone: %d (%s)\n", it->second.userId, reason.c_str()); 278 279 assert(false); 275 280 276 281 it->second.socket->disconnectServer(); … … 340 345 if ( it->second.handshake->ok() ) 341 346 { 342 if ( type != NET_SERVER ) 343 { 344 SharedNetworkData::getInstance()->setHostID( it->second.handshake->getHostId() ); 345 myHostId = SharedNetworkData::getInstance()->getHostID(); 346 347 this->networkGameManager = NetworkGameManager::getInstance(); 348 this->networkGameManager->setUniqueID( it->second.handshake->getNetworkGameManagerId() ); 349 MessageManager::getInstance()->setUniqueID( it->second.handshake->getMessageManagerId() ); 347 if ( !it->second.handshake->allowDel() ) 348 { 349 if ( type != NET_SERVER ) 350 { 351 SharedNetworkData::getInstance()->setHostID( it->second.handshake->getHostId() ); 352 myHostId = SharedNetworkData::getInstance()->getHostID(); 353 354 this->networkGameManager = NetworkGameManager::getInstance(); 355 this->networkGameManager->setUniqueID( it->second.handshake->getNetworkGameManagerId() ); 356 MessageManager::getInstance()->setUniqueID( it->second.handshake->getMessageManagerId() ); 357 } 358 359 360 PRINT(0)("handshake finished id=%d\n", it->second.handshake->getNetworkGameManagerId()); 361 362 it->second.handshake->del(); 350 363 } 351 364 else 352 handleNewClient( it->second.userId ); 353 354 PRINT(0)("handshake finished id=%d\n", it->second.handshake->getNetworkGameManagerId()); 355 356 delete it->second.handshake; 357 it->second.handshake = NULL; 365 { 366 if ( it->second.handshake->canDel() ) 367 { 368 if ( type == NET_SERVER ) 369 { 370 handleNewClient( it->second.userId ); 371 } 372 373 PRINT(0)("handshake finished delete it\n"); 374 delete it->second.handshake; 375 it->second.handshake = NULL; 376 } 377 } 358 378 359 379 } … … 429 449 n = sync.getStateDiff( peer->second.userId, buf + offset, UDP_PACKET_SIZE-offset, currentState, peer->second.lastAckedState, -1000 ); 430 450 offset += n; 431 // PRINTF(0)("GGGGGEEEEEEETTTTTTTT: %d\n", n);451 //NETPRINTF(0)("GGGGGEEEEETTTTT: %s (%d) %d\n",sync.getClassName(), sync.getUniqueID(), n); 432 452 433 453 assert( Converter::intToByteArray( n, buf + offset - n - INTSIZE, INTSIZE ) == INTSIZE ); 434 454 455 //check if all bytes == 0 -> remove data 456 457 bool allZero = true; 458 for ( int i = 0; i < n; i++ ) 459 { 460 if ( buf[i+oldOffset+2*INTSIZE] != 0 ) 461 allZero = false; 462 } 463 464 if ( allZero ) 465 { 466 //NETPRINTF(n)("REMOVE ZERO DIFF: %s (%d)\n", sync.getClassName(), sync.getUniqueID()); 467 offset = oldOffset; 468 } 469 470 471 } 472 473 for ( SynchronizeableList::iterator it = synchronizeables.begin(); it != synchronizeables.end(); it++ ) 474 { 475 Synchronizeable & sync = **it; 476 477 if ( !sync.beSynchronized() || sync.getUniqueID() < 0 ) 478 continue; 479 480 sync.handleSentState( peer->second.userId, currentState, peer->second.lastAckedState ); 435 481 } 436 482 … … 481 527 while ( 0 < (compLength = peer->second.socket->readPacket( compBuf, UDP_PACKET_SIZE )) ) 482 528 { 529 //PRINTF(0)("GGGGGOOOOOOOOOOTTTTTTTT: %d\n", compLength); 483 530 packetLength = Zip::getInstance()->unZip( compBuf, compLength, buf, UDP_PACKET_SIZE ); 484 531 … … 523 570 524 571 assert( syncDataLength > 0 ); 525 assert( syncDataLength < 1000 );572 assert( syncDataLength < 10000 ); 526 573 527 574 Synchronizeable * sync = NULL; … … 545 592 continue; 546 593 } 547 594 548 595 if ( !peers[peer->second.userId].isServer ) 549 596 { … … 601 648 int n = sync->setStateDiff( peer->second.userId, buf+offset, syncDataLength, state, fromState ); 602 649 offset += n; 603 //PRINTF(0)("SSSSSEEEEETTTTT: %d\n", n); 650 //NETPRINTF(0)("SSSSSEEEEETTTTT: %s %d\n",sync->getClassName(), n); 651 604 652 } 605 653 … … 610 658 } 611 659 612 peer->second.connectionMonitor->processZippedIncomingPacket( compBuf, compLength, currentState, ackedState ); 613 peer->second.connectionMonitor->processUnzippedIncomingPacket( buf, offset, currentState, ackedState ); 614 660 //TODO REMOVE THIS 661 int saveOffset = offset; 662 663 for ( SynchronizeableList::iterator it = synchronizeables.begin(); it != synchronizeables.end(); it++ ) 664 { 665 Synchronizeable & sync = **it; 666 667 if ( !sync.beSynchronized() || sync.getUniqueID() < 0 ) 668 continue; 669 670 sync.handleRecvState( peer->second.userId, state, fromState ); 671 } 672 673 peer->second.connectionMonitor->processZippedIncomingPacket( compBuf, compLength, state, ackedState ); 674 peer->second.connectionMonitor->processUnzippedIncomingPacket( buf, offset, state, ackedState ); 675 676 assert( peer->second.lastAckedState <= ackedState ); 615 677 peer->second.lastAckedState = ackedState; 616 678 679 assert( peer->second.lastRecvedState < state ); 617 680 peer->second.lastRecvedState = state; 681 682 assert( saveOffset == offset ); 618 683 619 684 } -
branches/network/src/lib/network/synchronizeable.cc
r7809 r7872 20 20 #include "network_stream.h" 21 21 #include "netdefs.h" 22 #include "network_log.h" 22 23 23 24 #include "state.h" … … 179 180 if ( ( hasPermission && (*it)->getPriority() >= priorityTH ) || sizeIter == stateFrom->sizeList.end() ) 180 181 { 182 n = (*it)->writeToBuf( stateTo->data+i, stateTo->dataLength - i ); 183 //NETPRINTF(0)("getvar %s %d\n", (*it)->getName().c_str(), n); 184 stateTo->sizeList.push_back( n ); 181 185 //(*it)->debug(); 182 n = (*it)->writeToBuf( stateTo->data+i, stateTo->dataLength - i );183 stateTo->sizeList.push_back( n );184 186 i += n; 185 187 } … … 192 194 i++; 193 195 } 196 //NETPRINTF(0)("getvar %s %d\n", (*it)->getName().c_str(), *sizeIter); 194 197 stateTo->sizeList.push_back( (*sizeIter) ); 195 198 } … … 237 240 stateTo->data = new byte[ length ]; 238 241 242 243 //find state to apply diff to 244 StateHistoryEntry * stateFrom = NULL; 245 246 StateHistory::iterator it = recvStates[userId].begin(); 247 while ( it != recvStates[userId].end() && (*it)->stateId != fromStateId ) 248 it++; 249 250 251 // if ( getLeafClassID() == CL_SPACE_SHIP ) 252 // { 253 // PRINTF(0)("setStateDiff:SpaceShip from: %d stateId: %d\n", (it == recvStates[userId].end())?-1:fromStateId, stateId); 254 // } 255 256 if ( it == recvStates[userId].end() ) 257 { 258 StateHistoryEntry * initialEntry = new StateHistoryEntry(); 259 260 initialEntry->stateId = fromStateId; 261 initialEntry->dataLength = 0; 262 initialEntry->data = NULL; 263 264 stateFrom = initialEntry; 265 } 266 else 267 stateFrom = (*it); 268 269 //apply diff 270 for ( int i = 0; i<length; i++ ) 271 { 272 if ( i < stateFrom->dataLength ) 273 stateTo->data[i] = stateFrom->data[i] + data[i]; 274 else 275 stateTo->data[i] = data[i]; 276 277 } 278 279 //add state to state history 280 recvStates[userId].push_back( stateTo ); 281 282 int i = 0; 283 int n = 0; 284 std::list<int> changes; 285 286 for ( SyncVarList::iterator it = syncVarList.begin(); it != syncVarList.end(); it++ ) 287 { 288 if ( 289 (*it)->checkPermission( PERMISSION_SERVER ) && networkStream->isUserServer( userId ) || 290 (*it)->checkPermission( PERMISSION_OWNER ) && this->owner == userId || 291 (*it)->checkPermission( PERMISSION_ALL ) 292 ) 293 { 294 n = (*it)->readFromBuf( stateTo->data + i, stateTo->dataLength - i ); 295 i += n; 296 //NETPRINTF(0)("%s::setvar %s %d\n", getClassName(), (*it)->getName().c_str(), n); 297 //(*it)->debug(); 298 if ( (*it)->getHasChanged() ) 299 { 300 changes.push_back( (*it)->getVarId() ); 301 } 302 } 303 else 304 { 305 // PRINTF(0)("DONT SET VAR BECAUSE OF PERMISSION: %s %d %d %d %d %d %d\n", (*it)->getName().c_str(), (*it)->checkPermission( PERMISSION_SERVER ), (*it)->checkPermission( PERMISSION_OWNER ), (*it)->checkPermission( PERMISSION_ALL ), networkStream->isUserServer( userId ), this->owner, userId ); 306 n = (*it)->getSizeFromBuf( stateTo->data + i, stateTo->dataLength - i ); 307 //NETPRINTF(0)("%s::setvar %s %d\n", getClassName(), (*it)->getName().c_str(), n); 308 //(*it)->debug(); 309 i += n; 310 } 311 } 312 313 this->varChangeHandler( changes ); 314 315 return i; 316 } 317 318 /** 319 * override this function to be notified on change 320 * of your registred variables. 321 * @param id id's which have changed 322 */ 323 void Synchronizeable::varChangeHandler( std::list<int> & id ) 324 { 325 } 326 327 /** 328 * registers a varable to be synchronized over network 329 * @param var see src/lib/network/synchronizeable_var/ for available classes 330 */ 331 void Synchronizeable::registerVar( SynchronizeableVar * var ) 332 { 333 PRINTF(0)("ADDING VAR: %s\n", var->getName().c_str()); 334 syncVarList.push_back( var ); 335 } 336 337 /** 338 * registers a varable to be synchronized over network 339 * return value is passed to varChangeHandler on change 340 * @param var see src/lib/network/synchronizeable_var/ for available classes 341 * @return handle passed to varChangeHandler on changes 342 */ 343 int Synchronizeable::registerVarId( SynchronizeableVar * var ) 344 { 345 PRINTF(0)("ADDING VAR: %s\n", var->getName().c_str()); 346 syncVarList.push_back( var ); 347 var->setWatched( true ); 348 var->setVarId( syncVarList.size()-1 ); 349 return syncVarList.size()-1; 350 } 351 352 /** 353 * removed user's states from memory 354 * @param userId user to clean 355 */ 356 void Synchronizeable::cleanUpUser( int userId ) 357 { 358 for ( UserStateHistory::iterator it = sentStates.begin(); it != sentStates.end(); it++ ) 359 { 360 for ( StateHistory::iterator it2 = it->begin(); it2 != it->end(); it2++ ) 361 { 362 if ( (*it2)->data ) 363 delete [] (*it2)->data; 364 (*it2)->data = NULL; 365 366 delete *it2; 367 } 368 } 369 370 sentStates.clear(); 371 372 for ( UserStateHistory::iterator it = recvStates.begin(); it != recvStates.end(); it++ ) 373 { 374 for ( StateHistory::iterator it2 = it->begin(); it2 != it->end(); it2++ ) 375 { 376 if ( (*it2)->data ) 377 delete [] (*it2)->data; 378 (*it2)->data = NULL; 379 380 delete *it2; 381 } 382 } 383 384 recvStates.clear(); 385 } 386 387 /** 388 * this function is called after recieving a state. 389 * @param userId 390 * @param stateId 391 * @param fromStateId 392 */ 393 void Synchronizeable::handleRecvState( int userId, int stateId, int fromStateId ) 394 { 395 //make sure this user has his history 396 if ( recvStates.size() <= userId ) 397 recvStates.resize( userId+1 ); 398 239 399 //remove old states 240 400 StateHistory::iterator it = recvStates[userId].begin(); 241 401 402 #if 0 242 403 while ( it != recvStates[userId].end() && (*it)->stateId < fromStateId ) 243 404 it++; … … 255 416 recvStates[userId].erase( recvStates[userId].begin(), it ); 256 417 } 257 258 //find state to apply diff to 259 StateHistoryEntry * stateFrom = NULL; 260 261 it = recvStates[userId].begin(); 262 while ( it != recvStates[userId].end() && (*it)->stateId != fromStateId ) 418 #endif 419 420 for ( it = recvStates[userId].begin(); it != recvStates[userId].end(); ) 421 { 422 if ( (*it)->stateId < fromStateId ) 423 { 424 StateHistory::iterator delIt = it; 425 it ++; 426 427 if ( (*delIt)->data ) 428 delete [] (*delIt)->data; 429 recvStates[userId].erase( delIt ); 430 431 continue; 432 } 263 433 it++; 264 265 266 // if ( getLeafClassID() == CL_SPACE_SHIP ) 267 // { 268 // PRINTF(0)("setStateDiff:SpaceShip from: %d stateId: %d\n", (it == recvStates[userId].end())?-1:fromStateId, stateId); 269 // } 270 271 if ( it == recvStates[userId].end() ) 272 { 273 StateHistoryEntry * initialEntry = new StateHistoryEntry(); 274 275 initialEntry->stateId = fromStateId; 276 initialEntry->dataLength = 0; 277 initialEntry->data = NULL; 278 279 stateFrom = initialEntry; 280 } 281 else 282 stateFrom = (*it); 283 284 //apply diff 285 for ( int i = 0; i<length; i++ ) 286 { 287 if ( i < stateFrom->dataLength ) 288 stateTo->data[i] = stateFrom->data[i] + data[i]; 434 } 435 436 StateHistory::iterator fromState = recvStates[userId].end(); 437 StateHistory::iterator toState = recvStates[userId].end(); 438 439 for ( it = recvStates[userId].begin(); it != recvStates[userId].end(); it++ ) 440 { 441 if ( (*it)->stateId == stateId ) 442 toState = it; 443 if ( (*it)->stateId == fromStateId ) 444 fromState = it; 445 446 if ( fromState != recvStates[userId].end() && toState != recvStates[userId].end() ) 447 break; 448 } 449 450 // setStateDiff was not called and i know fromStateId 451 if ( fromState != recvStates[userId].end() && toState == recvStates[userId].end() ) 452 { 453 StateHistoryEntry * entry = new StateHistoryEntry; 454 455 entry->dataLength = (*fromState)->dataLength; 456 if ( entry->dataLength > 0 ) 457 { 458 entry->data = new byte[entry->dataLength]; 459 460 assert( (*fromState)->data ); 461 memcpy( entry->data, (*fromState)->data, entry->dataLength ); 462 } 289 463 else 290 stateTo->data[i] = data[i]; 291 292 } 293 294 //add state to state history 295 recvStates[userId].push_back( stateTo ); 296 297 int i = 0; 298 std::list<int> changes; 299 300 for ( SyncVarList::iterator it = syncVarList.begin(); it != syncVarList.end(); it++ ) 301 { 302 if ( 303 (*it)->checkPermission( PERMISSION_SERVER ) && networkStream->isUserServer( userId ) || 304 (*it)->checkPermission( PERMISSION_OWNER ) && this->owner == userId || 305 (*it)->checkPermission( PERMISSION_ALL ) 306 ) 307 { 308 i += (*it)->readFromBuf( stateTo->data + i, stateTo->dataLength - i ); 309 if ( (*it)->getHasChanged() ) 310 changes.push_back( (*it)->getVarId() ); 464 entry->data = NULL; 465 466 entry->sizeList = (*fromState)->sizeList; 467 entry->stateId = stateId; 468 469 recvStates[userId].push_back(entry); 470 } 471 } 472 473 /** 474 * this function is called after sending a state 475 * @param userId 476 * @param stateId 477 * @param fromStateId 478 */ 479 void Synchronizeable::handleSentState( int userId, int stateId, int fromStateId ) 480 { 481 //make sure this user has his history 482 if ( sentStates.size() <= userId ) 483 sentStates.resize( userId+1 ); 484 485 //remove old states 486 StateHistory::iterator it = sentStates[userId].begin(); 487 488 for ( it = sentStates[userId].begin(); it != sentStates[userId].end(); ) 489 { 490 if ( (*it)->stateId < fromStateId ) 491 { 492 StateHistory::iterator delIt = it; 493 it ++; 494 495 if ( (*delIt)->data ) 496 delete [] (*delIt)->data; 497 sentStates[userId].erase( delIt ); 498 499 continue; 500 } 501 it++; 502 } 503 504 505 StateHistory::iterator fromState = sentStates[userId].end(); 506 StateHistory::iterator toState = sentStates[userId].end(); 507 508 for ( it = sentStates[userId].begin(); it != sentStates[userId].end(); it++ ) 509 { 510 if ( (*it)->stateId == stateId ) 511 toState = it; 512 if ( (*it)->stateId == fromStateId ) 513 fromState = it; 514 515 if ( fromState != sentStates[userId].end() && toState != sentStates[userId].end() ) 516 break; 517 } 518 519 520 // getStateDiff was not called and i know fromStateId 521 if ( fromState != sentStates[userId].end() && toState == sentStates[userId].end() ) 522 { 523 StateHistoryEntry * entry = new StateHistoryEntry; 524 525 entry->dataLength = (*fromState)->dataLength; 526 if ( entry->dataLength > 0 ) 527 { 528 entry->data = new byte[entry->dataLength]; 529 530 assert( (*fromState)->data ); 531 memcpy( entry->data, (*fromState)->data, entry->dataLength ); 311 532 } 312 533 else 313 { 314 // PRINTF(0)("DONT SET VAR BECAUSE OF PERMISSION: %s %d %d %d %d %d %d\n", (*it)->getName().c_str(), (*it)->checkPermission( PERMISSION_SERVER ), (*it)->checkPermission( PERMISSION_OWNER ), (*it)->checkPermission( PERMISSION_ALL ), networkStream->isUserServer( userId ), this->owner, userId ); 315 i += (*it)->getSizeFromBuf( stateTo->data + i, stateTo->dataLength - i ); 316 } 317 } 318 319 this->varChangeHandler( changes ); 320 321 return i; 322 } 323 324 /** 325 * override this function to be notified on change 326 * of your registred variables. 327 * @param id id's which have changed 328 */ 329 void Synchronizeable::varChangeHandler( std::list<int> & id ) 330 { 331 } 332 333 /** 334 * registers a varable to be synchronized over network 335 * @param var see src/lib/network/synchronizeable_var/ for available classes 336 */ 337 void Synchronizeable::registerVar( SynchronizeableVar * var ) 338 { 339 syncVarList.push_back( var ); 340 } 341 342 /** 343 * registers a varable to be synchronized over network 344 * return value is passed to varChangeHandler on change 345 * @param var see src/lib/network/synchronizeable_var/ for available classes 346 * @return handle passed to varChangeHandler on changes 347 */ 348 int Synchronizeable::registerVarId( SynchronizeableVar * var ) 349 { 350 syncVarList.push_back( var ); 351 var->setWatched( true ); 352 var->setVarId( syncVarList.size()-1 ); 353 return syncVarList.size()-1; 354 } 355 356 /** 357 * removed user's states from memory 358 * @param userId user to clean 359 */ 360 void Synchronizeable::cleanUpUser( int userId ) 361 { 362 for ( UserStateHistory::iterator it = sentStates.begin(); it != sentStates.end(); it++ ) 363 { 364 for ( StateHistory::iterator it2 = it->begin(); it2 != it->end(); it2++ ) 365 { 366 if ( (*it2)->data ) 367 delete [] (*it2)->data; 368 (*it2)->data = NULL; 369 370 delete *it2; 371 } 372 } 373 374 sentStates.clear(); 375 376 for ( UserStateHistory::iterator it = recvStates.begin(); it != recvStates.end(); it++ ) 377 { 378 for ( StateHistory::iterator it2 = it->begin(); it2 != it->end(); it2++ ) 379 { 380 if ( (*it2)->data ) 381 delete [] (*it2)->data; 382 (*it2)->data = NULL; 383 384 delete *it2; 385 } 386 } 387 388 recvStates.clear(); 389 } 390 391 392 534 entry->data = NULL; 535 536 entry->sizeList = (*fromState)->sizeList; 537 entry->stateId = stateId; 538 539 sentStates[userId].push_back(entry); 540 } 541 542 } 543 544 545 -
branches/network/src/lib/network/synchronizeable.h
r7631 r7872 59 59 virtual int setStateDiff( int userId, byte* data, int length, int stateId, int fromStateId ); 60 60 virtual void cleanUpUser( int userId ); 61 virtual void handleSentState( int userId, int stateId, int fromStateId ); 62 virtual void handleRecvState( int userId, int stateId, int fromStateId ); 61 63 62 64 void registerVar( SynchronizeableVar * var ); -
branches/network/src/lib/network/synchronizeable_var/synchronizeable_string.cc
r7804 r7872 95 95 96 96 int res = Converter::byteArrayToString( buf, t, maxLength ); 97 98 97 99 98 assert( res > 0 ); -
branches/network/src/lib/network/udp_server_socket.cc
r7857 r7872 35 35 36 36 memset( packet->data, 0, UDP_PACKET_SIZE ); 37 PRINTF(0)("PACKET DATA: %x\n", packet->data);38 37 39 38 listen( port ); -
branches/network/src/lib/network/udp_socket.cc
r7778 r7872 124 124 if ( channel == -1 ) 125 125 { 126 PRINTF( 2)("SDLNet_UDP_Bind: %s\n", SDLNet_GetError());126 PRINTF(1)("SDLNet_UDP_Bind: %s\n", SDLNet_GetError()); 127 127 bOk = false; 128 128 return; -
branches/network/src/subprojects/network/network_unit_test.cc
r7860 r7872 277 277 { 278 278 MessageManager::getInstance()->sendMessage( TESTMESSAGEID, (byte*)"server to client", 18, RT_ALL, 0, MP_HIGHBANDWIDTH ); 279 netMan->synchronize( 100 0);280 SDL_Delay(100 0);279 netMan->synchronize( 100 ); 280 SDL_Delay(100); 281 281 ss->debug(); 282 282 } … … 312 312 // ss->setSynchronized( true ); 313 313 // netMan->connectSynchronizeable( *ss ); 314 315 NetworkLog::getInstance()->listen( 7777 ); 314 316 315 317 SimpleSync * ss = NULL; … … 320 322 for(;;) 321 323 { 322 netMan->synchronize( 100 0);324 netMan->synchronize( 100 ); 323 325 MessageManager::getInstance()->sendMessage( TESTMESSAGEID, (byte*)"client to server", 18, RT_ALL, 0, MP_HIGHBANDWIDTH ); 324 326 ss = dynamic_cast<SimpleSync*>(ClassList::getObject( "Server", CL_SIMPLE_SYNC ) ); 325 SDL_Delay(100 0);327 SDL_Delay(100); 326 328 if (ss) 327 329 ss->debug(); -
branches/network/src/subprojects/network/simple_sync.cc
r7631 r7872 40 40 in = 0; 41 41 out = 1; 42 syncStr = "hallo test test"; 42 43 id = this->registerVarId( new SynchronizeableInt( &in, &out, "var", PERMISSION_ALL ) ); 44 registerVar( new SynchronizeableString( &syncStr, &syncStr, "syncStr" ) ); 43 45 } 44 46 … … 54 56 { 55 57 printf("IN: %d OUT: %d\n", in, out); 58 printf("str: %s\n", syncStr.c_str()); 56 59 } 57 60 … … 62 65 in = 0; 63 66 out = 1; 67 syncStr = "hallo test test"; 64 68 id = this->registerVarId( new SynchronizeableInt( &in, &out, "var", PERMISSION_ALL ) ); 69 registerVar( new SynchronizeableString( &syncStr, &syncStr, "syncStr" ) ); 65 70 } 66 71 67 72 68 73 74 -
branches/network/src/subprojects/network/simple_sync.h
r7631 r7872 23 23 int in; 24 24 int out; 25 std::string syncStr; 25 26 int id; 26 27 };
Note: See TracChangeset
for help on using the changeset viewer.