Changeset 8623 in orxonox.OLD for trunk/src/lib/network/player_stats.cc
- Timestamp:
- Jun 20, 2006, 1:39:01 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/network/player_stats.cc
r8362 r8623 24 24 25 25 #include "debug.h" 26 #include "shell_command.h" 26 27 27 28 28 29 CREATE_FACTORY(PlayerStats, CL_PLAYER_STATS); 29 30 31 30 32 /** 31 33 * constructor … … 34 36 { 35 37 init(); 36 38 37 39 this->userId = userId; 38 40 } … … 56 58 this->playableClassId = 0; 57 59 this->modelFileName = ""; 58 60 this->nickName = "Player"; 61 this->oldNickName = "Player"; 62 59 63 userId_handle = registerVarId( new SynchronizeableInt( &userId, &userId, "userId" ) ); 60 64 teamId_handle = registerVarId( new SynchronizeableInt( &teamId, &teamId, "teamId" ) ); … … 64 68 playableUniqueId_handle = registerVarId( new SynchronizeableInt( &playableUniqueId, &playableUniqueId, "playableUniqueId" ) ); 65 69 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 67 74 PRINTF(0)("PlayerStats created\n"); 68 75 } … … 87 94 { 88 95 this->setPlayableUniqueId( this->playableUniqueId ); 89 96 90 97 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; 91 104 } 92 105 } … … 100 113 { 101 114 const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYER_STATS ); 102 115 103 116 if ( !list ) 104 117 { 105 118 return NULL; 106 119 } 107 120 108 121 for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ ) 109 122 { … … 113 126 } 114 127 } 115 128 116 129 return NULL; 117 130 } … … 123 136 { 124 137 const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYABLE ); 125 138 126 139 if ( !list ) 127 140 { … … 129 142 return; 130 143 } 131 144 132 145 this->playable = NULL; 133 146 for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ ) … … 141 154 } 142 155 } 143 156 144 157 if ( this->playable && userId == getHostID() ) 145 158 { 146 159 State::getPlayer()->setPlayable( this->playable ); 147 160 } 148 161 149 162 this->playableUniqueId = uniqueId; 150 163 } … … 158 171 if ( playable ) 159 172 return playable; 160 173 161 174 assert( playableUniqueId > 0 ); 162 175 163 176 setPlayableUniqueId( playableUniqueId ); 164 177 165 178 assert( playable ); 166 179 167 180 return playable; 168 181 } 169 182 170 183 /** 184 * client sends server a message to change nick and server changes nick directly 185 * @param nick new nickname 186 */ 187 void 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 207 bool 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 224 void PlayerStats::shellNick( const std::string& newNick ) 225 { 226 if ( getStats( SharedNetworkData::getInstance()->getHostID() ) ) 227 getStats( SharedNetworkData::getInstance()->getHostID() )->setNickName( newNick ); 228 } 229 230 231 232 void 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.