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