Changeset 9257 in orxonox.OLD for branches/proxy/src/lib/network/player_stats.cc
- Timestamp:
- Jul 12, 2006, 5:10:09 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/proxy/src/lib/network/player_stats.cc
r9235 r9257 38 38 { 39 39 init(); 40 40 41 41 this->userId = userId; 42 42 } … … 62 62 this->nickName = "Player"; 63 63 this->oldNickName = "Player"; 64 64 65 65 userId_handle = registerVarId( new SynchronizeableInt( &userId, &userId, "userId" ) ); 66 66 teamId_handle = registerVarId( new SynchronizeableInt( &teamId, &teamId, "teamId" ) ); … … 71 71 modelFileName_handle = registerVarId( new SynchronizeableString( &modelFileName, &modelFileName, "modelFileName" ) ); 72 72 nickName_handler = registerVarId( new SynchronizeableString( &nickName, &nickName, "nickName" ) ); 73 73 74 74 MessageManager::getInstance()->registerMessageHandler( MSGID_CHANGENICKNAME, changeNickHandler, NULL ); 75 75 76 76 PRINTF(0)("PlayerStats created\n"); 77 77 } … … 96 96 { 97 97 this->setPlayableUniqueId( this->playableUniqueId ); 98 98 99 99 PRINTF(0)("uniqueID changed %d %d %d\n", userId, SharedNetworkData::getInstance()->getHostID(), getUniqueID()); 100 100 } 101 101 102 102 if ( std::find( id.begin(), id.end(), nickName_handler ) != id.end() ) 103 103 { … … 115 115 { 116 116 const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYER_STATS ); 117 117 118 118 if ( !list ) 119 119 { 120 120 return NULL; 121 121 } 122 122 123 123 for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ ) 124 124 { … … 128 128 } 129 129 } 130 130 131 131 return NULL; 132 132 } … … 138 138 { 139 139 const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYABLE ); 140 140 141 141 if ( !list ) 142 142 { … … 144 144 return; 145 145 } 146 146 147 147 this->playable = NULL; 148 148 for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ ) … … 156 156 } 157 157 } 158 158 159 159 if ( this->playable && userId == SharedNetworkData::getInstance()->getHostID() ) 160 160 { 161 161 State::getPlayer()->setPlayable( this->playable ); 162 162 } 163 163 164 164 this->playableUniqueId = uniqueId; 165 165 } … … 173 173 if ( playable ) 174 174 return playable; 175 175 176 176 assert( playableUniqueId > 0 ); 177 177 178 178 setPlayableUniqueId( playableUniqueId ); 179 179 180 180 assert( playable ); 181 181 182 182 return playable; 183 183 } … … 189 189 void PlayerStats::setNickName( std::string nick ) 190 190 { 191 if ( SharedNetworkData::getInstance()->is GameServer() )191 if ( SharedNetworkData::getInstance()->isMasterServer() ) 192 192 { 193 193 this->nickName = nick; … … 199 199 { 200 200 byte * data = new byte[nick.length()+INTSIZE]; 201 201 202 202 assert( Converter::stringToByteArray( nick, data, nick.length()+INTSIZE) == nick.length()+INTSIZE ); 203 203 204 204 MessageManager::getInstance()->sendMessage( MSGID_CHANGENICKNAME, data, nick.length()+INTSIZE, RT_SERVER, 0, MP_HIGHBANDWIDTH ); 205 205 return; … … 211 211 std::string newNick; 212 212 int res = Converter::byteArrayToString( data, newNick, dataLength ); 213 213 214 214 if ( res != dataLength ) 215 215 { … … 217 217 newNick = "invalid"; 218 218 } 219 219 220 220 if ( PlayerStats::getStats( userId ) ) 221 221 PlayerStats::getStats( userId )->setNickName( newNick ); 222 222 223 223 return true; 224 224 } … … 228 228 if ( getStats( SharedNetworkData::getInstance()->getHostID() ) ) 229 229 getStats( SharedNetworkData::getInstance()->getHostID() )->setNickName( newNick ); 230 230 231 231 Preferences::getInstance()->setString( "multiplayer", "nickname", newNick ); 232 232 } … … 237 237 { 238 238 const std::list<BaseObject*> * list; 239 239 240 240 while ( (list = ClassList::getList( CL_PLAYER_STATS )) != NULL && list->begin() != list->end() ) 241 241 delete *list->begin(); … … 247 247 { 248 248 ScoreList result; 249 249 250 250 const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYER_STATS ); 251 251 252 252 if ( !list ) 253 253 { 254 254 return result; 255 255 } 256 256 257 257 for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ ) 258 258 { 259 259 PlayerStats & stats = *dynamic_cast<PlayerStats*>(*it); 260 260 261 261 TeamScoreList::iterator it = result[stats.getTeamId()].begin(); 262 262 263 263 while ( it != result[stats.getTeamId()].end() && stats.score > it->score ) 264 264 { 265 265 it++; 266 266 } 267 267 268 268 PlayerScore score; 269 269 score.name = stats.getNickName(); 270 270 score.score = stats.getScore(); 271 271 272 272 result[stats.getTeamId()].insert(it, score); 273 273 } 274 274 275 275 return result; 276 276 }
Note: See TracChangeset
for help on using the changeset viewer.