Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Jun 20, 2006, 1:39:01 PM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the network branche back here
merged with command:
svn merge -r8230:HEAD https://svn.orxonox.net/orxonox/branches/network .
conflicts resolved in favour of the network branche (conflicts were in network)

File:
1 edited

Legend:

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

    r8362 r8623  
    2424
    2525#include "debug.h"
     26#include "shell_command.h"
    2627
    2728
    2829CREATE_FACTORY(PlayerStats, CL_PLAYER_STATS);
    2930
     31
    3032/**
    3133 * constructor
     
    3436{
    3537  init();
    36 
     38 
    3739  this->userId = userId;
    3840}
     
    5658  this->playableClassId = 0;
    5759  this->modelFileName = "";
    58 
     60  this->nickName = "Player";
     61  this->oldNickName = "Player";
     62 
    5963  userId_handle = registerVarId( new SynchronizeableInt( &userId, &userId, "userId" ) );
    6064  teamId_handle = registerVarId( new SynchronizeableInt( &teamId, &teamId, "teamId" ) );
     
    6468  playableUniqueId_handle = registerVarId( new SynchronizeableInt( &playableUniqueId, &playableUniqueId, "playableUniqueId" ) );
    6569  modelFileName_handle = registerVarId( new SynchronizeableString( &modelFileName, &modelFileName, "modelFileName" ) );
    66 
     70  nickName_handler = registerVarId( new SynchronizeableString( &nickName, &nickName, "nickName" ) );
     71 
     72  MessageManager::getInstance()->registerMessageHandler( MSGID_CHANGENICKNAME, changeNickHandler, NULL );
     73 
    6774  PRINTF(0)("PlayerStats created\n");
    6875}
     
    8794  {
    8895    this->setPlayableUniqueId( this->playableUniqueId );
    89 
     96   
    9097    PRINTF(0)("uniqueID changed %d %d %d\n", userId, getHostID(), getUniqueID());
     98  }
     99 
     100  if ( std::find( id.begin(), id.end(), nickName_handler ) != id.end() )
     101  {
     102    PRINTF(0)("user %s is now known as %s\n", oldNickName.c_str(), nickName.c_str());
     103    oldNickName = nickName;
    91104  }
    92105}
     
    100113{
    101114  const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYER_STATS );
    102 
     115 
    103116  if ( !list )
    104117  {
    105118    return NULL;
    106119  }
    107 
     120 
    108121  for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ )
    109122  {
     
    113126    }
    114127  }
    115 
     128 
    116129  return NULL;
    117130}
     
    123136{
    124137  const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYABLE );
    125 
     138 
    126139  if ( !list )
    127140  {
     
    129142    return;
    130143  }
    131 
     144 
    132145  this->playable = NULL;
    133146  for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ )
     
    141154    }
    142155  }
    143 
     156 
    144157  if ( this->playable && userId == getHostID() )
    145158  {
    146159    State::getPlayer()->setPlayable( this->playable );
    147160  }
    148 
     161 
    149162  this->playableUniqueId = uniqueId;
    150163}
     
    158171  if ( playable )
    159172    return playable;
    160 
     173 
    161174  assert( playableUniqueId > 0 );
    162 
     175 
    163176  setPlayableUniqueId( playableUniqueId );
    164 
     177 
    165178  assert( playable );
    166 
     179 
    167180  return playable;
    168181}
    169182
    170 
     183/**
     184 * client sends server a message to change nick and server changes nick directly
     185 * @param nick new nickname
     186 */
     187void PlayerStats::setNickName( std::string nick )
     188{
     189  if ( isServer() )
     190  {
     191    this->nickName = nick;
     192    PRINTF(0)("user %s is now known as %s\n", oldNickName.c_str(), nickName.c_str());
     193    oldNickName = nickName;
     194    return;
     195  }
     196  else
     197  {
     198    byte * data = new byte[nick.length()+INTSIZE];
     199   
     200    assert( Converter::stringToByteArray( nick, data, nick.length()+INTSIZE) == nick.length()+INTSIZE );
     201   
     202    MessageManager::getInstance()->sendMessage( MSGID_CHANGENICKNAME, data, nick.length()+INTSIZE, RT_SERVER, 0, MP_HIGHBANDWIDTH );
     203    return;
     204  }
     205}
     206
     207bool PlayerStats::changeNickHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId )
     208{
     209  std::string newNick;
     210  int res = Converter::byteArrayToString( data, newNick, dataLength );
     211 
     212  if ( res != dataLength )
     213  {
     214    PRINTF(2)("invalid message size from user %d\n", userId);
     215    newNick = "invalid";
     216  }
     217 
     218  if ( PlayerStats::getStats( userId ) )
     219    PlayerStats::getStats( userId )->setNickName( newNick );
     220 
     221  return true;
     222}
     223
     224void PlayerStats::shellNick( const std::string& newNick )
     225{
     226  if ( getStats( SharedNetworkData::getInstance()->getHostID() ) )
     227    getStats( SharedNetworkData::getInstance()->getHostID() )->setNickName( newNick );
     228}
     229
     230
     231
     232void PlayerStats::deleteAllPlayerStats( )
     233{
     234  const std::list<BaseObject*> * list;
     235 
     236  while ( (list  = ClassList::getList( CL_PLAYER_STATS )) != NULL && list->begin() != list->end() )
     237    delete *list->begin();
     238}
     239
Note: See TracChangeset for help on using the changeset viewer.