Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Aug 4, 2006, 11:01:28 PM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the proxy bache back with no conflicts

File:
1 edited

Legend:

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

    r9494 r9656  
    4141  init();
    4242
    43   this->userId = userId;
     43  this->assignedUserId = userId;
    4444}
    4545
     
    5656  this->setClassID( CL_PLAYER_STATS, "PlayerStats" );
    5757
    58   this->userId = 0;
     58  this->assignedUserId = 0;
    5959  this->teamId = TEAM_NOTEAM;
    6060  this->preferedTeamId = TEAM_NOTEAM;
     
    6565  this->oldNickName = "Player";
    6666
    67   userId_handle = registerVarId( new SynchronizeableInt( &userId, &userId, "userId" ) );
    68   teamId_handle = registerVarId( new SynchronizeableInt( &teamId, &teamId, "teamId" ) );
    69   preferedTeamId_handle = registerVarId( new SynchronizeableInt( &preferedTeamId, &preferedTeamId, "preferedUserId" ) );
    70   score_handle = registerVarId( new SynchronizeableInt( &score, &score, "score" ) );
    71   playableClassId_handle = registerVarId( new SynchronizeableInt( &playableClassId, &playableClassId, "playableClassId") );
    72   playableUniqueId_handle = registerVarId( new SynchronizeableInt( &playableUniqueId, &playableUniqueId, "playableUniqueId" ) );
    73   modelFileName_handle = registerVarId( new SynchronizeableString( &modelFileName, &modelFileName, "modelFileName" ) );
    74   nickName_handler = registerVarId( new SynchronizeableString( &nickName, &nickName, "nickName" ) );
     67  userId_handle = registerVarId( new SynchronizeableInt( &assignedUserId, &assignedUserId, "userId", PERMISSION_MASTER_SERVER ) );
     68  teamId_handle = registerVarId( new SynchronizeableInt( &teamId, &teamId, "teamId", PERMISSION_MASTER_SERVER ) );
     69  preferedTeamId_handle = registerVarId( new SynchronizeableInt( &preferedTeamId, &preferedTeamId, "preferedUserId", PERMISSION_MASTER_SERVER ) );
     70  score_handle = registerVarId( new SynchronizeableInt( &score, &score, "score", PERMISSION_MASTER_SERVER ) );
     71  playableClassId_handle = registerVarId( new SynchronizeableInt( &playableClassId, &playableClassId, "playableClassId", PERMISSION_MASTER_SERVER) );
     72  playableUniqueId_handle = registerVarId( new SynchronizeableInt( &playableUniqueId, &playableUniqueId, "playableUniqueId", PERMISSION_MASTER_SERVER ) );
     73  modelFileName_handle = registerVarId( new SynchronizeableString( &modelFileName, &modelFileName, "modelFileName", PERMISSION_MASTER_SERVER ) );
     74  nickName_handler = registerVarId( new SynchronizeableString( &nickName, &nickName, "nickName", PERMISSION_MASTER_SERVER ) );
    7575
    7676  MessageManager::getInstance()->registerMessageHandler( MSGID_CHANGENICKNAME, changeNickHandler, NULL );
    7777
    78   PRINTF(0)("PlayerStats created\n");
     78  PRINTF(5)("PlayerStats created\n");
    7979}
    8080
     
    8484 */
    8585PlayerStats::~PlayerStats()
    86 {
    87 }
    88 
    89 
    90  /**
    91  * override this function to be notified on change
    92  * of your registred variables.
    93  * @param id id's which have changed
    94   */
     86{}
     87
     88
     89/**
     90* override this function to be notified on change
     91* of your registred variables.
     92* @param id id's which have changed
     93 */
    9594void PlayerStats::varChangeHandler( std::list< int > & id )
    9695{
     
    9998    this->setPlayableUniqueId( this->playableUniqueId );
    10099
    101     PRINTF(0)("uniqueID changed %d %d %d\n", userId, SharedNetworkData::getInstance()->getHostID(), getUniqueID());
     100    PRINTF(4)("uniqueID changed %d %d %d\n", assignedUserId, SharedNetworkData::getInstance()->getHostID(), getUniqueID());
    102101  }
    103102
     
    105104  {
    106105    PRINTF(0)("user %s is now known as %s\n", oldNickName.c_str(), nickName.c_str());
    107     oldNickName = nickName;
    108   }
    109 }
     106    this->oldNickName = nickName;
     107  }
     108
     109  if ( std::find( id.begin(), id.end(), preferedTeamId_handle) != id.end() )
     110  {
     111    PRINTF(0)("user %s has changed team to %i\n", nickName.c_str(), this->teamId);
     112  }
     113}
     114
     115
    110116
    111117/**
     
    123129  }
    124130
    125   for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ )
    126   {
    127     if ( dynamic_cast<PlayerStats*>(*it)->getUserId() == userId )
     131  for ( std::list<BaseObject*>::const_iterator it = list->
     132        begin();
     133        it != list->end();
     134        it++ )
     135  {
     136
     137
     138    if ( dynamic_cast<PlayerStats*>(*it)->getAssignedUserId() == userId )
    128139    {
    129140      return dynamic_cast<PlayerStats*>(*it);
     
    148159
    149160  this->playable = NULL;
    150   for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ )
    151   {
    152     if ( dynamic_cast<Playable*>(*it)->getUniqueID() == uniqueId )
     161  for ( std::list<BaseObject*>::const_iterator it = list->
     162        begin();
     163        it != list->end();
     164        it++ )
     165  {
     166    if ( dynamic_cast<Playable*>(*it)->
     167         getUniqueID() == uniqueId )
    153168    {
    154169      this->playable = dynamic_cast<Playable*>(*it);
     
    159174  }
    160175
    161   if ( this->playable && userId == SharedNetworkData::getInstance()->getHostID() )
     176  if ( this->playable && this->assignedUserId == SharedNetworkData::getInstance()
     177       ->getHostID() )
    162178  {
    163179    State::getPlayer()->setPlayable( this->playable );
     180    // also set the team id
    164181  }
    165182
     
    204221    assert( Converter::stringToByteArray( nick, data, nick.length()+INTSIZE) == nick.length()+INTSIZE );
    205222
    206     MessageManager::getInstance()->sendMessage( MSGID_CHANGENICKNAME, data, nick.length()+INTSIZE, RT_SERVER, 0, MP_HIGHBANDWIDTH );
     223    MessageManager::getInstance()->sendMessage( MSGID_CHANGENICKNAME, data, nick.length()+INTSIZE, RT_SERVER, NET_MASTER_SERVER, MP_HIGHBANDWIDTH );
    207224    return;
    208225  }
    209226}
    210227
    211 bool PlayerStats::changeNickHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId )
     228/**
     229 * handler for the nick name
     230 * @param messageType type of the message
     231 * @param data  data of the message
     232 * @param dataLength length of the data
     233 * @param someData some additional data
     234 * @param senderId userId of the sender
     235 * @param destinationId userId of the rec
     236 * @return true if handled correctly
     237 */
     238bool PlayerStats::changeNickHandler( MessageType messageType, byte * data, int dataLength, void * someData, int senderId, int destinationId  )
    212239{
    213240  std::string newNick;
     
    216243  if ( res != dataLength )
    217244  {
    218     PRINTF(2)("invalid message size from user %d\n", userId);
     245    PRINTF(2)("invalid message size from user %d\n", senderId);
    219246    newNick = "invalid";
    220247  }
    221248
    222   if ( PlayerStats::getStats( userId ) )
    223     PlayerStats::getStats( userId )->setNickName( newNick );
     249  if ( PlayerStats::getStats( senderId) )
     250    PlayerStats::getStats( senderId )->setNickName( newNick );
    224251
    225252  return true;
    226253}
    227254
     255/**
     256 * sets the nick name from the shell
     257 * @param newNick new prefered nick name
     258 */
    228259void PlayerStats::shellNick( const std::string& newNick )
    229260{
     
    236267
    237268
     269/**
     270 * removes and delets all player stats
     271 */
    238272void PlayerStats::deleteAllPlayerStats( )
    239273{
     
    246280
    247281
     282/**
     283 * @return the score list of this player stat
     284 */
    248285ScoreList PlayerStats::getScoreList( )
    249286{
     
    257294  }
    258295
    259   for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ )
     296  for ( std::list<BaseObject*>::const_iterator it = list->
     297        begin();
     298        it != list->end();
     299        it++ )
    260300  {
    261301    PlayerStats & stats = *dynamic_cast<PlayerStats*>(*it);
Note: See TracChangeset for help on using the changeset viewer.