Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8236 in orxonox.OLD for branches/network/src/lib


Ignore:
Timestamp:
Jun 8, 2006, 1:42:53 PM (18 years ago)
Author:
rennerc
Message:

added nickname to playerstats

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

Legend:

Unmodified
Added
Removed
  • branches/network/src/lib/network/message_manager.h

    r8228 r8236  
    3131  MSGID_DELETESYNCHRONIZEABLE,
    3232  MSGID_PREFEREDTEAM,
    33   MSGID_CHANGEPLAYERNAME
     33  MSGID_CHANGENICKNAME
    3434};
    3535
  • branches/network/src/lib/network/player_stats.cc

    r8228 r8236  
    2323#include "shared_network_data.h"
    2424
     25#include "shell_command.h"
     26
    2527
    2628CREATE_FACTORY(PlayerStats, CL_PLAYER_STATS);
     29SHELL_COMMAND(nick, PlayerStats, shellNick);
    2730
    2831/**
     
    6265  playableUniqueId_handle = registerVarId( new SynchronizeableInt( &playableUniqueId, &playableUniqueId, "playableUniqueId" ) );
    6366  modelFileName_handle = registerVarId( new SynchronizeableString( &modelFileName, &modelFileName, "modelFileName" ) );
     67  nickName_handler = registerVarId( new SynchronizeableString( &nickName, &nickName, "nickName" ) );
     68 
     69  MessageManager::getInstance()->registerMessageHandler( MSGID_CHANGENICKNAME, changeNickHandler, NULL );
    6470 
    6571  PRINTF(0)("PlayerStats created\n");
     
    8793   
    8894    PRINTF(0)("uniqueID changed %d %d %d\n", userId, getHostID(), getUniqueID());
     95  }
     96 
     97  if ( std::find( id.begin(), id.end(), nickName_handler ) != id.end() )
     98  {
     99    PRINTF(0)("user %d is now known as %s\n", userId, nickName);
    89100  }
    90101}
     
    166177}
    167178
    168 
     179/**
     180 * client sends server a message to change nick and server changes nick directly
     181 * @param nick new nickname
     182 */
     183void PlayerStats::setNickName( std::string nick )
     184{
     185  if ( isServer() )
     186  {
     187    this->nickName = nick;
     188    return;
     189  }
     190  else
     191  {
     192    byte * data = new byte[nick.length()+INTSIZE];
     193   
     194    assert( Converter::stringToByteArray( nick, data, nick.length()+INTSIZE) == nick.length()+INTSIZE );
     195   
     196    MessageManager::getInstance()->sendMessage( MSGID_CHANGENICKNAME, data, nick.length()+INTSIZE, RT_SERVER, 0, MP_HIGHBANDWIDTH );
     197    return;
     198  }
     199}
     200
     201bool PlayerStats::changeNickHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId )
     202{
     203  std::string newNick;
     204  int res = Converter::byteArrayToString( data, newNick, dataLength );
     205 
     206  if ( res != dataLength )
     207  {
     208    PRINTF(2)("invalid message size from user %d\n", userId);
     209    newNick = "invalid";
     210  }
     211 
     212  if ( PlayerStats::getStats( userId ) )
     213    PlayerStats::getStats( userId )->setNickName( newNick );
     214}
     215
     216void PlayerStats::shellNick( const std::string& newNick )
     217{
     218  //if ( getStats( SharedNetworkData::getInstance()->getHostID() ) )
     219  //  getStats( SharedNetworkData::getInstance()->getHostID() )->setNickName( newNick );
     220}
     221
     222
  • branches/network/src/lib/network/player_stats.h

    r8068 r8236  
    99#include "synchronizeable.h"
    1010#include "playable.h"
     11#include "message_manager.h"
    1112
    1213#include <string>
     
    5455   
    5556    Playable * getPlayable();
     57   
     58    inline std::string getNickName(){ return this->nickName; }
     59    void setNickName( std::string nick );
     60    static bool changeNickHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId );
     61    void shellNick( const std::string&  newNick );
    5662
    5763  private:
     
    5965    int teamId;                //!< teamId
    6066    int preferedTeamId;        //!< preferedTeamId
     67
     68    std::string nickName;      //!< players nickname
    6169
    6270    int score;                 //!< users score points
     
    7583    int playableUniqueId_handle;
    7684    int modelFileName_handle;
     85    int nickName_handler;
    7786   
    7887    void init();
Note: See TracChangeset for help on using the changeset viewer.