Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9406 in orxonox.OLD for trunk/src/lib/network/player_stats.cc


Ignore:
Timestamp:
Jul 24, 2006, 11:09:47 AM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the proxy back

merged with commandsvn merge -r9346:HEAD https://svn.orxonox.net/orxonox/branches/proxy .

no conflicts

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/network/player_stats.cc

    r9235 r9406  
    2323#include "shared_network_data.h"
    2424
     25#include "converter.h"
     26
    2527#include "preferences.h"
    2628
     
    3840{
    3941  init();
    40  
     42
    4143  this->userId = userId;
    4244}
     
    6264  this->nickName = "Player";
    6365  this->oldNickName = "Player";
    64  
     66
    6567  userId_handle = registerVarId( new SynchronizeableInt( &userId, &userId, "userId" ) );
    6668  teamId_handle = registerVarId( new SynchronizeableInt( &teamId, &teamId, "teamId" ) );
     
    7173  modelFileName_handle = registerVarId( new SynchronizeableString( &modelFileName, &modelFileName, "modelFileName" ) );
    7274  nickName_handler = registerVarId( new SynchronizeableString( &nickName, &nickName, "nickName" ) );
    73  
     75
    7476  MessageManager::getInstance()->registerMessageHandler( MSGID_CHANGENICKNAME, changeNickHandler, NULL );
    75  
     77
    7678  PRINTF(0)("PlayerStats created\n");
    7779}
     
    9698  {
    9799    this->setPlayableUniqueId( this->playableUniqueId );
    98    
     100
    99101    PRINTF(0)("uniqueID changed %d %d %d\n", userId, SharedNetworkData::getInstance()->getHostID(), getUniqueID());
    100102  }
    101  
     103
    102104  if ( std::find( id.begin(), id.end(), nickName_handler ) != id.end() )
    103105  {
     
    115117{
    116118  const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYER_STATS );
    117  
     119
    118120  if ( !list )
    119121  {
    120122    return NULL;
    121123  }
    122  
     124
    123125  for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ )
    124126  {
     
    128130    }
    129131  }
    130  
     132
    131133  return NULL;
    132134}
     
    138140{
    139141  const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYABLE );
    140  
     142
    141143  if ( !list )
    142144  {
     
    144146    return;
    145147  }
    146  
     148
    147149  this->playable = NULL;
    148150  for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ )
     
    156158    }
    157159  }
    158  
     160
    159161  if ( this->playable && userId == SharedNetworkData::getInstance()->getHostID() )
    160162  {
    161163    State::getPlayer()->setPlayable( this->playable );
    162164  }
    163  
     165
    164166  this->playableUniqueId = uniqueId;
    165167}
     
    173175  if ( playable )
    174176    return playable;
    175  
     177
    176178  assert( playableUniqueId > 0 );
    177  
     179
    178180  setPlayableUniqueId( playableUniqueId );
    179  
     181
    180182  assert( playable );
    181  
     183
    182184  return playable;
    183185}
     
    189191void PlayerStats::setNickName( std::string nick )
    190192{
    191   if ( SharedNetworkData::getInstance()->isGameServer() )
     193  if ( SharedNetworkData::getInstance()->isMasterServer() || SharedNetworkData::getInstance()->isProxyServer() )
    192194  {
    193195    this->nickName = nick;
     
    199201  {
    200202    byte * data = new byte[nick.length()+INTSIZE];
    201    
     203
    202204    assert( Converter::stringToByteArray( nick, data, nick.length()+INTSIZE) == nick.length()+INTSIZE );
    203    
     205
    204206    MessageManager::getInstance()->sendMessage( MSGID_CHANGENICKNAME, data, nick.length()+INTSIZE, RT_SERVER, 0, MP_HIGHBANDWIDTH );
    205207    return;
     
    211213  std::string newNick;
    212214  int res = Converter::byteArrayToString( data, newNick, dataLength );
    213  
     215
    214216  if ( res != dataLength )
    215217  {
     
    217219    newNick = "invalid";
    218220  }
    219  
     221
    220222  if ( PlayerStats::getStats( userId ) )
    221223    PlayerStats::getStats( userId )->setNickName( newNick );
    222  
     224
    223225  return true;
    224226}
     
    228230  if ( getStats( SharedNetworkData::getInstance()->getHostID() ) )
    229231    getStats( SharedNetworkData::getInstance()->getHostID() )->setNickName( newNick );
    230    
     232
    231233  Preferences::getInstance()->setString( "multiplayer", "nickname", newNick );
    232234}
     
    237239{
    238240  const std::list<BaseObject*> * list;
    239  
     241
    240242  while ( (list  = ClassList::getList( CL_PLAYER_STATS )) != NULL && list->begin() != list->end() )
    241243    delete *list->begin();
     
    247249{
    248250  ScoreList result;
    249  
     251
    250252  const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYER_STATS );
    251  
     253
    252254  if ( !list )
    253255  {
    254256    return result;
    255257  }
    256  
     258
    257259  for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ )
    258260  {
    259261    PlayerStats & stats = *dynamic_cast<PlayerStats*>(*it);
    260    
     262
    261263    TeamScoreList::iterator it = result[stats.getTeamId()].begin();
    262    
     264
    263265    while (  it != result[stats.getTeamId()].end() && stats.score > it->score )
    264266    {
    265267      it++;
    266268    }
    267    
     269
    268270    PlayerScore score;
    269271    score.name = stats.getNickName();
    270272    score.score = stats.getScore();
    271    
     273
    272274    result[stats.getTeamId()].insert(it, score);
    273275  }
    274  
     276
    275277  return result;
    276278}
Note: See TracChangeset for help on using the changeset viewer.