Changeset 9656 in orxonox.OLD for trunk/src/lib/network/player_stats.cc
- Timestamp:
- Aug 4, 2006, 11:01:28 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/network/player_stats.cc
r9494 r9656 41 41 init(); 42 42 43 this-> userId = userId;43 this->assignedUserId = userId; 44 44 } 45 45 … … 56 56 this->setClassID( CL_PLAYER_STATS, "PlayerStats" ); 57 57 58 this-> userId = 0;58 this->assignedUserId = 0; 59 59 this->teamId = TEAM_NOTEAM; 60 60 this->preferedTeamId = TEAM_NOTEAM; … … 65 65 this->oldNickName = "Player"; 66 66 67 userId_handle = registerVarId( new SynchronizeableInt( & userId, &userId, "userId") );68 teamId_handle = registerVarId( new SynchronizeableInt( &teamId, &teamId, "teamId" ) );69 preferedTeamId_handle = registerVarId( new SynchronizeableInt( &preferedTeamId, &preferedTeamId, "preferedUserId" ) );70 score_handle = registerVarId( new SynchronizeableInt( &score, &score, "score" ) );71 playableClassId_handle = registerVarId( new SynchronizeableInt( &playableClassId, &playableClassId, "playableClassId" ) );72 playableUniqueId_handle = registerVarId( new SynchronizeableInt( &playableUniqueId, &playableUniqueId, "playableUniqueId" ) );73 modelFileName_handle = registerVarId( new SynchronizeableString( &modelFileName, &modelFileName, "modelFileName" ) );74 nickName_handler = registerVarId( new SynchronizeableString( &nickName, &nickName, "nickName" ) );67 userId_handle = registerVarId( new SynchronizeableInt( &assignedUserId, &assignedUserId, "userId", PERMISSION_MASTER_SERVER ) ); 68 teamId_handle = registerVarId( new SynchronizeableInt( &teamId, &teamId, "teamId", PERMISSION_MASTER_SERVER ) ); 69 preferedTeamId_handle = registerVarId( new SynchronizeableInt( &preferedTeamId, &preferedTeamId, "preferedUserId", PERMISSION_MASTER_SERVER ) ); 70 score_handle = registerVarId( new SynchronizeableInt( &score, &score, "score", PERMISSION_MASTER_SERVER ) ); 71 playableClassId_handle = registerVarId( new SynchronizeableInt( &playableClassId, &playableClassId, "playableClassId", PERMISSION_MASTER_SERVER) ); 72 playableUniqueId_handle = registerVarId( new SynchronizeableInt( &playableUniqueId, &playableUniqueId, "playableUniqueId", PERMISSION_MASTER_SERVER ) ); 73 modelFileName_handle = registerVarId( new SynchronizeableString( &modelFileName, &modelFileName, "modelFileName", PERMISSION_MASTER_SERVER ) ); 74 nickName_handler = registerVarId( new SynchronizeableString( &nickName, &nickName, "nickName", PERMISSION_MASTER_SERVER ) ); 75 75 76 76 MessageManager::getInstance()->registerMessageHandler( MSGID_CHANGENICKNAME, changeNickHandler, NULL ); 77 77 78 PRINTF( 0)("PlayerStats created\n");78 PRINTF(5)("PlayerStats created\n"); 79 79 } 80 80 … … 84 84 */ 85 85 PlayerStats::~PlayerStats() 86 { 87 } 88 89 90 /** 91 * override this function to be notified on change 92 * of your registred variables. 93 * @param id id's which have changed 94 */ 86 {} 87 88 89 /** 90 * override this function to be notified on change 91 * of your registred variables. 92 * @param id id's which have changed 93 */ 95 94 void PlayerStats::varChangeHandler( std::list< int > & id ) 96 95 { … … 99 98 this->setPlayableUniqueId( this->playableUniqueId ); 100 99 101 PRINTF( 0)("uniqueID changed %d %d %d\n", userId, SharedNetworkData::getInstance()->getHostID(), getUniqueID());100 PRINTF(4)("uniqueID changed %d %d %d\n", assignedUserId, SharedNetworkData::getInstance()->getHostID(), getUniqueID()); 102 101 } 103 102 … … 105 104 { 106 105 PRINTF(0)("user %s is now known as %s\n", oldNickName.c_str(), nickName.c_str()); 107 oldNickName = nickName; 108 } 109 } 106 this->oldNickName = nickName; 107 } 108 109 if ( std::find( id.begin(), id.end(), preferedTeamId_handle) != id.end() ) 110 { 111 PRINTF(0)("user %s has changed team to %i\n", nickName.c_str(), this->teamId); 112 } 113 } 114 115 110 116 111 117 /** … … 123 129 } 124 130 125 for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ ) 126 { 127 if ( dynamic_cast<PlayerStats*>(*it)->getUserId() == userId ) 131 for ( std::list<BaseObject*>::const_iterator it = list-> 132 begin(); 133 it != list->end(); 134 it++ ) 135 { 136 137 138 if ( dynamic_cast<PlayerStats*>(*it)->getAssignedUserId() == userId ) 128 139 { 129 140 return dynamic_cast<PlayerStats*>(*it); … … 148 159 149 160 this->playable = NULL; 150 for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ ) 151 { 152 if ( dynamic_cast<Playable*>(*it)->getUniqueID() == uniqueId ) 161 for ( std::list<BaseObject*>::const_iterator it = list-> 162 begin(); 163 it != list->end(); 164 it++ ) 165 { 166 if ( dynamic_cast<Playable*>(*it)-> 167 getUniqueID() == uniqueId ) 153 168 { 154 169 this->playable = dynamic_cast<Playable*>(*it); … … 159 174 } 160 175 161 if ( this->playable && userId == SharedNetworkData::getInstance()->getHostID() ) 176 if ( this->playable && this->assignedUserId == SharedNetworkData::getInstance() 177 ->getHostID() ) 162 178 { 163 179 State::getPlayer()->setPlayable( this->playable ); 180 // also set the team id 164 181 } 165 182 … … 204 221 assert( Converter::stringToByteArray( nick, data, nick.length()+INTSIZE) == nick.length()+INTSIZE ); 205 222 206 MessageManager::getInstance()->sendMessage( MSGID_CHANGENICKNAME, data, nick.length()+INTSIZE, RT_SERVER, 0, MP_HIGHBANDWIDTH );223 MessageManager::getInstance()->sendMessage( MSGID_CHANGENICKNAME, data, nick.length()+INTSIZE, RT_SERVER, NET_MASTER_SERVER, MP_HIGHBANDWIDTH ); 207 224 return; 208 225 } 209 226 } 210 227 211 bool PlayerStats::changeNickHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId ) 228 /** 229 * handler for the nick name 230 * @param messageType type of the message 231 * @param data data of the message 232 * @param dataLength length of the data 233 * @param someData some additional data 234 * @param senderId userId of the sender 235 * @param destinationId userId of the rec 236 * @return true if handled correctly 237 */ 238 bool PlayerStats::changeNickHandler( MessageType messageType, byte * data, int dataLength, void * someData, int senderId, int destinationId ) 212 239 { 213 240 std::string newNick; … … 216 243 if ( res != dataLength ) 217 244 { 218 PRINTF(2)("invalid message size from user %d\n", userId);245 PRINTF(2)("invalid message size from user %d\n", senderId); 219 246 newNick = "invalid"; 220 247 } 221 248 222 if ( PlayerStats::getStats( userId) )223 PlayerStats::getStats( userId )->setNickName( newNick );249 if ( PlayerStats::getStats( senderId) ) 250 PlayerStats::getStats( senderId )->setNickName( newNick ); 224 251 225 252 return true; 226 253 } 227 254 255 /** 256 * sets the nick name from the shell 257 * @param newNick new prefered nick name 258 */ 228 259 void PlayerStats::shellNick( const std::string& newNick ) 229 260 { … … 236 267 237 268 269 /** 270 * removes and delets all player stats 271 */ 238 272 void PlayerStats::deleteAllPlayerStats( ) 239 273 { … … 246 280 247 281 282 /** 283 * @return the score list of this player stat 284 */ 248 285 ScoreList PlayerStats::getScoreList( ) 249 286 { … … 257 294 } 258 295 259 for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ ) 296 for ( std::list<BaseObject*>::const_iterator it = list-> 297 begin(); 298 it != list->end(); 299 it++ ) 260 300 { 261 301 PlayerStats & stats = *dynamic_cast<PlayerStats*>(*it);
Note: See TracChangeset
for help on using the changeset viewer.