Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6231 in orxonox.OLD for branches


Ignore:
Timestamp:
Dec 21, 2005, 3:00:35 PM (19 years ago)
Author:
rennerc
Message:

network_game_manager now works with new converter

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

Legend:

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

    r6230 r6231  
    229229void NetworkGameManager::requestCreateEntity(ClassID classID)
    230230{
    231   byte* bp;
    232   byte b = REQUEST_CREATE;
    233   bp = Converter::intToByteArray( classID );
    234 
    235   if ( !writeToClientBuffer( allOutBuffer, &b, 1 ) )
    236   {
    237     PRINTF(1)("Could not write to clientBuffer\n");
    238     return;
    239   }
    240 
    241   if ( !writeToClientBuffer( allOutBuffer, bp, INTSIZE ) )
    242   {
    243     PRINTF(1)("Could not write to clientBuffer\n");
    244     delete bp;
    245     return;
    246   }
    247   delete bp;
     231  if ( !writeToClientBuffer( allOutBuffer, (byte)REQUEST_CREATE ) )
     232    return;
     233  if ( !writeToClientBuffer( allOutBuffer, (int)classID ) )
     234    return;
    248235}
    249236
     
    254241void NetworkGameManager::requestRemoveEntity(int uniqueID)
    255242{
    256   byte* bp;
    257   byte b = REQUEST_REMOVE;
    258   bp = Converter::intToByteArray( uniqueID );
    259 
    260   if ( !writeToClientBuffer( allOutBuffer, &b, 1 ) )
    261   {
    262     PRINTF(1)("Could not write to clientBuffer\n");
    263     return;
    264   }
    265 
    266   if ( !writeToClientBuffer( allOutBuffer, bp, INTSIZE ) )
    267   {
    268     PRINTF(1)("Could not write to clientBuffer\n");
    269     delete bp;
    270     return;
    271   }
    272   delete bp;
     243  if ( !writeToClientBuffer( allOutBuffer, (byte)REQUEST_REMOVE ) )
     244    return;
     245  if ( !writeToClientBuffer( allOutBuffer, uniqueID ) )
     246    return;
    273247}
    274248
     
    280254void NetworkGameManager::executeCreateEntity(ClassID classID, int uniqueID, int owner)
    281255{
    282   byte* bp;
    283   byte b = CREATE_ENTITY;
    284 
    285   if ( !writeToClientBuffer( allOutBuffer, &b, 1 ) )
    286   {
    287     PRINTF(1)("Could not write to clientBuffer\n");
    288     return;
    289   }
    290 
    291   bp = Converter::intToByteArray( uniqueID );
    292   if ( !writeToClientBuffer( allOutBuffer, bp, INTSIZE ) )
    293   {
    294     PRINTF(1)("Could not write to clientBuffer\n");
    295     delete bp;
    296     return;
    297   }
    298   delete bp;
    299 
    300   bp = Converter::intToByteArray( uniqueID );
    301   if ( !writeToClientBuffer( allOutBuffer, bp, INTSIZE ) )
    302   {
    303     PRINTF(1)("Could not write to clientBuffer\n");
    304     delete bp;
    305     return;
    306   }
    307   delete bp;
    308 
    309   bp = Converter::intToByteArray( owner );
    310   if ( !writeToClientBuffer( allOutBuffer, bp, INTSIZE ) )
    311   {
    312     PRINTF(1)("Could not write to clientBuffer\n");
    313     delete bp;
    314     return;
    315   }
    316   delete bp;
     256  if ( !writeToClientBuffer( allOutBuffer, (byte)CREATE_ENTITY ) )
     257    return;
     258  if ( !writeToClientBuffer( allOutBuffer, (int)classID ) )
     259    return;
     260  if ( !writeToClientBuffer( allOutBuffer, uniqueID ) )
     261    return;
     262  if ( !writeToClientBuffer( allOutBuffer, owner ) )
     263    return;
    317264
    318265  doCreateEntity( classID, uniqueID, owner );
     
    326273void NetworkGameManager::executeRemoveEntity(int uniqueID)
    327274{
    328   byte* bp;
    329   byte b = REMOVE_ENTITY;
    330 
    331   if ( !writeToClientBuffer( allOutBuffer, &b, 1 ) )
    332   {
    333     PRINTF(1)("Could not write to clientBuffer\n");
    334     return;
    335   }
    336 
    337   bp = Converter::intToByteArray( uniqueID );
    338   if ( !writeToClientBuffer( allOutBuffer, bp, INTSIZE ) )
    339   {
    340     PRINTF(1)("Could not write to clientBuffer\n");
    341     delete bp;
    342     return;
    343   }
    344   delete bp;
     275  if ( !writeToClientBuffer( allOutBuffer, (byte)REMOVE_ENTITY ) )
     276    return;
     277  if ( !writeToClientBuffer( allOutBuffer, uniqueID ) )
     278    return;
    345279
    346280  doRemoveEntity(uniqueID);
     
    373307  e = this->networkStream->getSyncEnd();
    374308
    375   byte b = CREATE_ENTITY_LIST;
    376   byte* ib;
    377 
    378   if ( !writeToClientBuffer( outBuffer[userID], &b, 1 ) )
    379   {
    380     PRINTF(1)("Could not write to clientBuffer\n");
    381     return;
    382   }
    383 
    384   ib = Converter::intToByteArray( networkStream->getSyncCount() );
    385   if ( !writeToClientBuffer( outBuffer[userID], ib, INTSIZE ) )
    386   {
    387     PRINTF(1)("Could not write to clientBuffer\n");
    388     delete ib;
    389     return;
    390   }
    391   delete ib;
     309  if ( !writeToClientBuffer( outBuffer[userID], (byte)CREATE_ENTITY_LIST ) )
     310    return;
     311
     312  if ( !writeToClientBuffer( outBuffer[userID], networkStream->getSyncCount() ) )
     313    return;
    392314
    393315  while ( it != e )
    394316  {
    395     ib = Converter::intToByteArray( (*it)->getClassID() );
    396     if ( !writeToClientBuffer( outBuffer[userID], ib, INTSIZE ) )
    397     {
    398       PRINTF(1)("Could not write to clientBuffer\n");
    399       delete ib;
     317    if ( !writeToClientBuffer( outBuffer[userID], (*it)->getClassID() ) )
    400318      return;
    401     }
    402     delete ib;
    403 
    404     ib = Converter::intToByteArray( (*it)->getUniqueID() );
    405     if ( !writeToClientBuffer( outBuffer[userID], ib, INTSIZE ) )
    406     {
    407       PRINTF(1)("Could not write to clientBuffer\n");
    408       delete ib;
     319
     320    if ( !writeToClientBuffer( outBuffer[userID], (*it)->getUniqueID() ) )
    409321      return;
    410     }
    411     delete ib;
    412 
    413     ib = Converter::intToByteArray( (*it)->getOwner() );
    414     if ( !writeToClientBuffer( outBuffer[userID], ib, INTSIZE ) )
    415     {
    416       PRINTF(1)("Could not write to clientBuffer\n");
    417       delete ib;
     322
     323    if ( !writeToClientBuffer( outBuffer[userID], (*it)->getOwner() ) )
    418324      return;
    419     }
    420     delete ib;
    421325
    422326    it++;
     
    574478    return;
    575479
    576   byte* bp;
    577   byte b = YOU_ARE_ENTITY;
    578 
    579480  if ( userID != 0 )
    580481  {
    581     if ( !writeToClientBuffer( allOutBuffer, &b, 1 ) )
    582     {
    583       PRINTF(1)("Could not write to clientBuffer\n");
     482    if ( !writeToClientBuffer( outBuffer[userID], (byte)YOU_ARE_ENTITY ) )
    584483      return;
    585     }
    586 
    587     bp = Converter::intToByteArray( uniqueID );
    588     if ( !writeToClientBuffer( allOutBuffer, bp, INTSIZE ) )
    589     {
    590       PRINTF(1)("Could not write to clientBuffer\n");
    591       delete bp;
     484
     485    if ( !writeToClientBuffer( outBuffer[userID], uniqueID ) )
    592486      return;
    593     }
    594     delete bp;
    595487  }
    596488  else
     
    607499    return false;
    608500  }
    609   int classID = Converter::byteArrayToInt( data );
    610   i += INTSIZE;
     501  int classID;
     502  i += Converter::byteArrayToInt( data, &classID );
    611503
    612504  createEntity( (ClassID)classID );
     
    622514    return false;
    623515  }
    624   int uniqueID = Converter::byteArrayToInt( data );
    625   i += INTSIZE;
     516  int uniqueID;
     517  i += Converter::byteArrayToInt( data, &uniqueID );
    626518
    627519  removeEntity( uniqueID );
     
    637529    return false;
    638530  }
    639   int classID = Converter::byteArrayToInt( data );
    640   i += INTSIZE;
     531  int classID;
     532  i += Converter::byteArrayToInt( data, &classID );
    641533
    642534  if ( INTSIZE > length-i )
     
    645537    return false;
    646538  }
    647   int uniqueID = Converter::byteArrayToInt( data );
    648   i += INTSIZE;
     539  int uniqueID;
     540  i += Converter::byteArrayToInt( data, &uniqueID );
    649541
    650542  if ( INTSIZE > length-i )
     
    653545    return false;
    654546  }
    655   int owner = Converter::byteArrayToInt( data );
    656   i += INTSIZE;
     547  int owner;
     548  i += Converter::byteArrayToInt( data, &owner );
    657549
    658550  doCreateEntity( (ClassID)classID, uniqueID, owner );
     
    668560    return false;
    669561  }
    670   int uniqueID = Converter::byteArrayToInt( data );
    671   i += INTSIZE;
     562  int uniqueID;
     563  i += Converter::byteArrayToInt( data, &uniqueID );
    672564
    673565  doRemoveEntity( uniqueID );
     
    683575    return false;
    684576  }
    685   int n = Converter::byteArrayToInt( data );
    686   i += INTSIZE;
     577  int n;
     578  i += Converter::byteArrayToInt( data, &n );
    687579
    688580  int classID, uniqueID, owner;
     
    696588      return false;
    697589    }
    698     classID = Converter::byteArrayToInt( data );
    699     i += INTSIZE;
     590    i += Converter::byteArrayToInt( data, &classID );
    700591
    701592    if ( INTSIZE > length-i )
     
    704595      return false;
    705596    }
    706     uniqueID = Converter::byteArrayToInt( data );
    707     i += INTSIZE;
     597    i += Converter::byteArrayToInt( data, &uniqueID );
    708598
    709599    if ( INTSIZE > length-i )
     
    712602      return false;
    713603    }
    714     owner = Converter::byteArrayToInt( data );
    715     i += INTSIZE;
     604    i += Converter::byteArrayToInt( data, &owner );
    716605
    717606    doCreateEntity( (ClassID)classID, uniqueID, owner );
     
    728617    return false;
    729618  }
    730   int n = Converter::byteArrayToInt( data );
    731   i += INTSIZE;
     619  int n;
     620  i += Converter::byteArrayToInt( data, &n );
    732621
    733622  int uniqueID;
     
    741630      return false;
    742631    }
    743     uniqueID = Converter::byteArrayToInt( data );
    744     i += INTSIZE;
     632    i += Converter::byteArrayToInt( data, &uniqueID );
    745633
    746634    doRemoveEntity( uniqueID );
     
    757645    return false;
    758646  }
    759   int uniqueID = Converter::byteArrayToInt( data );
    760   i += INTSIZE;
     647
     648  int uniqueID;
     649  i += Converter::byteArrayToInt( data, &uniqueID );
    761650
    762651  doYouAre( uniqueID );
     
    772661    return false;
    773662  }
    774   int uniqueID = Converter::byteArrayToInt( data );
    775   i += INTSIZE;
     663  int uniqueID;
     664  i += Converter::byteArrayToInt( data, &uniqueID );
    776665
    777666  doRequestSync( uniqueID, sender );
     
    780669}
    781670
     671bool NetworkGameManager::writeToClientBuffer( clientBuffer & cb, byte b )
     672{
     673  if ( cb.maxLength-cb.length < 1 )
     674  {
     675    PRINTF(1)("Cannot write to clientBuffer! Not enough space for 1 byte\n");
     676    return false;
     677  }
     678
     679  cb.buffer[cb.length++] = b;
     680
     681  return true;
     682}
     683
     684bool NetworkGameManager::writeToClientBuffer( clientBuffer & cb, int i )
     685{
     686  int n = Converter::intToByteArray( i, cb.buffer, cb.maxLength-cb.length );
     687  cb.length += n;
     688
     689  if ( n <= 0 )
     690  {
     691    PRINTF(1)("Cannot write to clientBuffer! Not enough space for 1 int\n");
     692    return false;
     693  }
     694
     695  return true;
     696}
     697
  • branches/network/src/lib/network/network_game_manager.h

    r6230 r6231  
    9797
    9898    inline bool writeToClientBuffer( clientBuffer &cb, byte*data, int length );
     99    inline bool writeToClientBuffer( clientBuffer &cb, byte b );
     100    inline bool writeToClientBuffer( clientBuffer &cb, int i );
    99101    inline bool readFromClientBuffer( clientBuffer &cb, byte*data, int length );
    100102
Note: See TracChangeset for help on using the changeset viewer.