Changeset 8236 in orxonox.OLD for branches/network/src/lib
- Timestamp:
- Jun 8, 2006, 1:42:53 PM (18 years ago)
- Location:
- branches/network/src/lib/network
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/network/src/lib/network/message_manager.h
r8228 r8236 31 31 MSGID_DELETESYNCHRONIZEABLE, 32 32 MSGID_PREFEREDTEAM, 33 MSGID_CHANGE PLAYERNAME33 MSGID_CHANGENICKNAME 34 34 }; 35 35 -
branches/network/src/lib/network/player_stats.cc
r8228 r8236 23 23 #include "shared_network_data.h" 24 24 25 #include "shell_command.h" 26 25 27 26 28 CREATE_FACTORY(PlayerStats, CL_PLAYER_STATS); 29 SHELL_COMMAND(nick, PlayerStats, shellNick); 27 30 28 31 /** … … 62 65 playableUniqueId_handle = registerVarId( new SynchronizeableInt( &playableUniqueId, &playableUniqueId, "playableUniqueId" ) ); 63 66 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 ); 64 70 65 71 PRINTF(0)("PlayerStats created\n"); … … 87 93 88 94 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); 89 100 } 90 101 } … … 166 177 } 167 178 168 179 /** 180 * client sends server a message to change nick and server changes nick directly 181 * @param nick new nickname 182 */ 183 void 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 201 bool 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 216 void 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 9 9 #include "synchronizeable.h" 10 10 #include "playable.h" 11 #include "message_manager.h" 11 12 12 13 #include <string> … … 54 55 55 56 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 ); 56 62 57 63 private: … … 59 65 int teamId; //!< teamId 60 66 int preferedTeamId; //!< preferedTeamId 67 68 std::string nickName; //!< players nickname 61 69 62 70 int score; //!< users score points … … 75 83 int playableUniqueId_handle; 76 84 int modelFileName_handle; 85 int nickName_handler; 77 86 78 87 void init();
Note: See TracChangeset
for help on using the changeset viewer.