Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9250 in orxonox.OLD for branches


Ignore:
Timestamp:
Jul 12, 2006, 10:47:32 AM (18 years ago)
Author:
patrick
Message:

network: works again

Location:
branches/proxy/src/lib/network
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/proxy/src/lib/network/message_manager.cc

    r9059 r9250  
    5252      }
    5353    }
    54    
     54
    5555    it->second.messages.clear();
    5656    it->second.toAck.clear();
    5757  }
    58  
     58
    5959  messageQueue.clear();
    60  
     60
    6161  this->messageHandlerMap.clear();
    62  
     62
    6363  MessageManager::singletonRef = NULL;
    6464}
     
    8282  int i = 0;
    8383  int n;
    84  
     84
    8585  n = Converter::intToByteArray( messageQueue[userId].toAck.size(), data + i, maxLength );
    8686  i += n;
    8787  assert( n == INTSIZE );
    88  
     88
    8989  for ( std::list<int>::iterator it = messageQueue[userId].toAck.begin(); it != messageQueue[userId].toAck.end(); it++)
    9090  {
     
    9393    assert( n == INTSIZE );
    9494  }
    95  
     95
    9696  messageQueue[userId].toAck.clear();
    97  
     97
    9898  n = Converter::intToByteArray( messageQueue[userId].messages.size(), data + i, maxLength );
    9999  i += n;
    100100  assert( n == INTSIZE );
    101  
     101
    102102  for ( std::list<NetworkMessage>::iterator it = messageQueue[userId].messages.begin(); it != messageQueue[userId].messages.end(); it++ )
    103103  {
     
    105105    i += n;
    106106    assert( n == INTSIZE );
    107    
     107
    108108    n = Converter::intToByteArray( it->number, data + i, maxLength );
    109109    i += n;
    110110    assert( n == INTSIZE );
    111    
     111
    112112    n = Converter::intToByteArray( it->messageId, data + i, maxLength );
    113113    i += n;
    114114    assert( n == INTSIZE );
    115    
     115
    116116    assert( i + it->length <= maxLength );
    117117    memcpy( data + i, it->data, it->length );
    118118    i += it->length;
    119119  }
    120  
     120
    121121  return i;
    122122}
     
    136136  int i = 0;
    137137  int n;
    138  
     138
    139139  int nAcks;
    140  
     140
    141141  assert( i + INTSIZE <= length );
    142142  n = Converter::byteArrayToInt( data + i, &nAcks );
    143143  assert( n == INTSIZE );
    144144  i += n;
    145  
     145
    146146  std::list<int> acks;
    147  
     147
    148148  int number;
    149  
     149
    150150  for ( int j = 0; j < nAcks; j++ )
    151151  {
     
    154154    assert( n == INTSIZE );
    155155    i += n;
    156    
     156
    157157    acks.push_back( number );
    158158  }
    159  
     159
    160160  int nMessages;
    161  
     161
    162162  assert( i + INTSIZE <= length );
    163163  n = Converter::byteArrayToInt( data + i, &nMessages );
     
    166166
    167167  int messageLength, messageId;
    168  
     168
    169169  for ( int j = 0; j < nMessages; j++ )
    170170  {
     
    173173    assert( n == INTSIZE );
    174174    i += n;
    175    
     175
    176176    assert( i + INTSIZE <= length );
    177177    n = Converter::byteArrayToInt( data + i, &number );
    178178    assert( n == INTSIZE );
    179179    i += n;
    180  
     180
    181181    assert( i + INTSIZE <= length );
    182182    n = Converter::byteArrayToInt( data + i, &messageId );
    183183    assert( n == INTSIZE );
    184184    i += n;
    185    
     185
    186186    if ( number > 0 )
    187187      messageQueue[userId].toAck.push_back( number );
    188    
     188
    189189    assert( i + messageLength <= length );
    190190    assert( messageHandlerMap.find( (MessageId)messageId ) != messageHandlerMap.end() );
     
    194194      {
    195195        NetworkMessage msg;
    196        
     196
    197197        msg.data = new byte[messageLength];
    198198        memcpy( msg.data, data + i, messageLength );
     
    200200        msg.messageId = (MessageId)messageId;
    201201        msg.number = userId;
    202        
     202
    203203        incomingMessageBuffer.push_back( msg );
    204204      }
     
    207207    i += messageLength;
    208208  }
    209  
    210  
     209
     210
    211211  //TODO maybe handle incomingMessage in tick function. else local messages will not be handled if no clients are connected
    212212  for ( std::list<NetworkMessage>::iterator it = incomingMessageBuffer.begin(); it != incomingMessageBuffer.end();  )
     
    223223    it++;
    224224  }
    225  
     225
    226226  //walk throu message queue and remove acked messages
    227227  for ( std::list<NetworkMessage>::iterator it = messageQueue[userId].messages.begin(); it != messageQueue[userId].messages.end();  )
     
    236236    it++;
    237237  }
    238  
     238
    239239  //TODO find bether way. maybe with timestamp
    240240  if ( messageQueue[userId].recievedMessages.size() > 1000 )
     
    255255  if ( messageQueue.find( userId ) == messageQueue.end() )
    256256    return;
    257    
     257
    258258  for ( std::list<NetworkMessage>::iterator it = messageQueue[userId].messages.begin(); it != messageQueue[userId].messages.end(); it++ )
    259259  {
     
    262262    it->data = NULL;
    263263  }
    264  
     264
    265265  messageQueue[userId].toAck.clear();
    266  
     266
    267267  messageQueue.erase( userId );
    268268}
     
    270270/**
    271271 * registers function to handle messages with id messageId. someData is passed to callbackfuntion
    272  * @param messageId message id to handle 
     272 * @param messageId message id to handle
    273273 * @param cb function pointer to callback function
    274274 * @param someData this pointer is passed to callback function without modification
     
    278278{
    279279  MessageHandler messageHandler;
    280  
     280
    281281  messageHandler.cb = cb;
    282282  messageHandler.messageId = messageId;
    283283  messageHandler.someData = someData;
    284  
     284
    285285  messageHandlerMap[messageId] = messageHandler;
    286  
     286
    287287  return true;
    288288}
     
    309309 * @param data pointer to data
    310310 * @param dataLength length of data
    311  * @param recieverType 
    312  * @param reciever 
     311 * @param recieverType
     312 * @param reciever
    313313 */
    314314void MessageManager::sendMessage( MessageId messageId, byte * data, int dataLength, RecieverType recieverType, int reciever, MessagePriority messagePriority )
     
    316316  for ( MessageQueue::iterator it = messageQueue.begin(); it != messageQueue.end(); it++ )
    317317  {
    318     if ( 
     318    if (
    319319         recieverType == RT_ALL_ME ||
    320320         recieverType == RT_ALL_NOT_ME ||
    321321         recieverType == RT_USER && it->first == reciever ||
    322322         recieverType == RT_NOT_USER && it->first != reciever ||
    323          recieverType == RT_SERVER && getNetworkStream()->isUserServer( it->first )
     323         recieverType == RT_SERVER && getNetworkStream()->isUserMasterServer( it->first )
    324324       )
    325325    {
     
    336336    }
    337337  }
    338  
     338
    339339  if ( recieverType == RT_ALL_ME )
    340340  {
  • branches/proxy/src/lib/network/network_stream.h

    r9249 r9250  
    2727  public:
    2828    PeerInfo() { clear(); }
    29     void clear() { userId = 0; isMasterServer = false; socket = NULL; handshake = NULL; lastAckedState = 0; lastRecvedState = 0; connectionMonitor = NULL; }
     29
     30    void clear()
     31    {
     32      this->userId = 0;
     33      this->nodeType = NET_CLIENT;
     34      this->isMasterServer = false;
     35      this->isProxyServer = false;
     36      this->isClient = false;
     37      this->socket = NULL;
     38      this->handshake = NULL;
     39      this->lastAckedState = 0;
     40      this->lastRecvedState = 0;
     41      this->connectionMonitor = NULL;
     42    }
    3043
    3144
    3245  public:
    3346    int                 userId;
     47    int                 nodeType;
    3448    bool                isMasterServer;
    3549    bool                isProxyServer;
     
    4155    int                 lastRecvedState;
    4256};
     57
     58
    4359
    4460typedef std::list<Synchronizeable*>  SynchronizeableList;
Note: See TracChangeset for help on using the changeset viewer.