Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7872 in orxonox.OLD for branches/network/src/lib


Ignore:
Timestamp:
May 26, 2006, 2:08:51 PM (18 years ago)
Author:
rennerc
Message:

removing zerobytes should work now

Location:
branches/network/src/lib/network
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • branches/network/src/lib/network/connection_monitor.cc

    r7851 r7872  
    126126 
    127127  if ( packetHistory.size() <= 1 || tick - packetHistory.begin()->first == 0 )
    128     res = 0;
     128    res = 0.0f;
    129129  else
    130130    res /= (float)((tick - packetHistory.begin()->first)*( 1 + 1/((float)(packetHistory.size()-1)) ));
    131131 
    132   res *= 1000;
     132  res *= 1000.0f;
    133133 
    134134  return res;
     
    148148  outgoingZippedBandWidth = calculateBandWidth( outgoingZippedPacketHistory, tick );
    149149 
    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 );
    151151
    152152}
     
    163163  incomingZippedBandWidth = calculateBandWidth( incomingZippedPacketHistory, tick );
    164164 
    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 );
    166166 
    167167}
    168168
     169
     170bool 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  
    3030    void calculatePing();
    3131   
    32     bool hasTimedOut(){ return ( lastPacketTick + SECS_TO_TIMEOUT*1000 < SDL_GetTicks() ) && nIncomingPackets > 0; }
     32    bool hasTimedOut();
    3333   
    3434  private:
  • branches/network/src/lib/network/handshake.cc

    r7792 r7872  
    4141  errorString_handler = registerVarId( new SynchronizeableString( &localState.errorString, &remoteState.errorString, "errorString", PERMISSION_ALL ) );
    4242 
     43  candel_id = registerVarId( new SynchronizeableInt( &localState.canDel, &remoteState.canDel, "canDel", PERMISSION_ALL ) );
     44 
    4345  localState.completed = 0;
    4446  localState.error = 0;
     
    4951  localState.orxId = _ORXONOX_ID;
    5052  localState.version = _ORXONOX_VERSION;
     53  localState.canDel = 0;
    5154 
    5255  remoteState.completed = 0;
     
    5861  remoteState.orxId = 0;
    5962  remoteState.version = 0;
     63  remoteState.canDel = 0;
    6064
    6165  this->setSynchronized(true);
     
    9599    }
    96100   
     101    if ( *it == candel_id )
     102    {
     103      PRINTF(0)("handshake finished candel changed\n");
     104    }
     105   
    97106  }
    98107 
     
    101110      remoteState.version == _ORXONOX_VERSION
    102111     )
    103     localState.completed = true;
     112    localState.completed = 1;
    104113}
    105114
  • branches/network/src/lib/network/handshake.h

    r7778 r7872  
    2323 
    2424  int completed;
     25  int canDel;
    2526 
    2627  int error;
     
    3940    inline int        getMessageManagerId(){ return remoteState.messageManagerId; }
    4041    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; }
    4145   
    4246    virtual void varChangeHandler( std::list<int> & id );
     
    5458    int orxId_handler;
    5559    int version_handler;
     60    int candel_id;
    5661
    5762};
  • branches/network/src/lib/network/message_manager.cc

    r7697 r7872  
    288288  // just do something so map creates a new entry
    289289  messageQueue[userId].toAck.clear();
    290   assert( messageQueue[userId].messages.size() == 0 );
     290  //assert( messageQueue[userId].messages.size() == 0 );
    291291}
    292292
  • branches/network/src/lib/network/message_manager.h

    r7693 r7872  
    9292   virtual int setStateDiff( int userId, byte* data, int length, int stateId, int fromStateId );
    9393   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 ){}
    9496   
    9597   void initUser( int userId );
  • branches/network/src/lib/network/network_stream.cc

    r7851 r7872  
    188188  else
    189189  {
    190     if ( peers[0].socket && !peers[0].socket->isOk() )
     190    if ( peers[0].socket && ( !peers[0].socket->isOk() || peers[0].connectionMonitor->hasTimedOut() ) )
    191191    {
    192192      PRINTF(1)("lost connection to server\n");
     
    272272       )
    273273    {
    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);
    275280
    276281      it->second.socket->disconnectServer();
     
    340345        if ( it->second.handshake->ok() )
    341346        {
    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();
    350363          }
    351364          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          }
    358378
    359379        }
     
    429449      n = sync.getStateDiff( peer->second.userId, buf + offset, UDP_PACKET_SIZE-offset, currentState, peer->second.lastAckedState, -1000 );
    430450      offset += n;
    431       //PRINTF(0)("GGGGGEEEEEEETTTTTTTT: %d\n", n);
     451      //NETPRINTF(0)("GGGGGEEEEETTTTT: %s (%d) %d\n",sync.getClassName(), sync.getUniqueID(), n);
    432452     
    433453      assert( Converter::intToByteArray( n, buf + offset - n - INTSIZE, INTSIZE ) == INTSIZE );
    434454     
     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 );
    435481    }
    436482   
     
    481527    while ( 0 < (compLength = peer->second.socket->readPacket( compBuf, UDP_PACKET_SIZE )) )
    482528    {
     529      //PRINTF(0)("GGGGGOOOOOOOOOOTTTTTTTT: %d\n", compLength);
    483530      packetLength = Zip::getInstance()->unZip( compBuf, compLength, buf, UDP_PACKET_SIZE );
    484531     
     
    523570       
    524571        assert( syncDataLength > 0 );
    525         assert( syncDataLength < 1000 );
     572        assert( syncDataLength < 10000 );
    526573     
    527574        Synchronizeable * sync = NULL;
     
    545592            continue;
    546593          }
    547 
     594         
    548595          if ( !peers[peer->second.userId].isServer )
    549596          {
     
    601648        int n = sync->setStateDiff( peer->second.userId, buf+offset, syncDataLength, state, fromState );
    602649        offset += n;
    603         //PRINTF(0)("SSSSSEEEEETTTTT: %d\n", n);
     650        //NETPRINTF(0)("SSSSSEEEEETTTTT: %s %d\n",sync->getClassName(), n);
     651
    604652      }
    605653     
     
    610658      }
    611659     
    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 );
    615677      peer->second.lastAckedState = ackedState;
    616678     
     679      assert( peer->second.lastRecvedState < state );
    617680      peer->second.lastRecvedState = state;
     681     
     682      assert( saveOffset == offset );
    618683     
    619684    }
  • branches/network/src/lib/network/synchronizeable.cc

    r7809 r7872  
    2020#include "network_stream.h"
    2121#include "netdefs.h"
     22#include "network_log.h"
    2223
    2324#include "state.h"
     
    179180    if ( ( hasPermission && (*it)->getPriority() >= priorityTH ) || sizeIter == stateFrom->sizeList.end() )
    180181    {
     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 );
    181185      //(*it)->debug();
    182       n = (*it)->writeToBuf( stateTo->data+i, stateTo->dataLength - i );
    183       stateTo->sizeList.push_back( n );
    184186      i += n;
    185187    }
     
    192194        i++;
    193195      }
     196      //NETPRINTF(0)("getvar %s %d\n", (*it)->getName().c_str(), *sizeIter);
    194197      stateTo->sizeList.push_back( (*sizeIter) );
    195198    }
     
    237240  stateTo->data = new byte[ length ];
    238241
     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 */
     323void 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 */
     331void 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 */
     343int 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 */
     356void 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 */
     393void 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 
    239399  //remove old states
    240400  StateHistory::iterator it = recvStates[userId].begin();
    241401
     402#if 0
    242403  while ( it != recvStates[userId].end() && (*it)->stateId < fromStateId )
    243404    it++;
     
    255416    recvStates[userId].erase( recvStates[userId].begin(), it );
    256417  }
    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    }
    263433    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    }
    289463    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 */
     479void 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 );
    311532    }
    312533    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  
    5959    virtual int setStateDiff( int userId, byte* data, int length, int stateId, int fromStateId );
    6060    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 );
    6163
    6264    void registerVar( SynchronizeableVar * var );
  • branches/network/src/lib/network/synchronizeable_var/synchronizeable_string.cc

    r7804 r7872  
    9595 
    9696  int res = Converter::byteArrayToString( buf, t, maxLength );
    97 
    9897 
    9998  assert( res > 0 );
  • branches/network/src/lib/network/udp_server_socket.cc

    r7857 r7872  
    3535 
    3636  memset( packet->data, 0, UDP_PACKET_SIZE );
    37   PRINTF(0)("PACKET DATA: %x\n", packet->data);
    3837 
    3938  listen( port );
  • branches/network/src/lib/network/udp_socket.cc

    r7778 r7872  
    124124  if ( channel == -1 )
    125125  {
    126     PRINTF(2)("SDLNet_UDP_Bind: %s\n", SDLNet_GetError());
     126    PRINTF(1)("SDLNet_UDP_Bind: %s\n", SDLNet_GetError());
    127127    bOk = false;
    128128    return;
Note: See TracChangeset for help on using the changeset viewer.