Changeset 8362 in orxonox.OLD for trunk/src/lib/network/network_game_manager.cc
- Timestamp:
- Jun 14, 2006, 10:08:41 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/network/network_game_manager.cc
r8228 r8362 39 39 #include "network_game_manager.h" 40 40 41 #include "debug.h" 42 41 43 42 44 /* using namespace std is default, this needs to be here */ … … 57 59 58 60 this->setSynchronized(true); 59 61 60 62 MessageManager::getInstance()->registerMessageHandler( MSGID_DELETESYNCHRONIZEABLE, delSynchronizeableHandler, NULL ); 61 63 MessageManager::getInstance()->registerMessageHandler( MSGID_PREFEREDTEAM, preferedTeamHandler, NULL ); 62 64 63 65 this->gameState = 0; 64 66 registerVar( new SynchronizeableInt( &gameState, &gameState, "gameState" ) ); … … 75 77 /** 76 78 * insert new player into game 77 * @param userId 78 * @return 79 * @param userId 80 * @return 79 81 */ 80 82 bool NetworkGameManager::signalNewPlayer( int userId ) … … 83 85 assert( State::getGameRules() ); 84 86 assert( State::getGameRules()->isA( CL_NETWORK_GAME_RULES ) ); 85 87 86 88 NetworkGameRules & rules = *(dynamic_cast<NetworkGameRules*>(State::getGameRules())); 87 89 88 90 int team = rules.getTeamForNewUser(); 89 91 ClassID playableClassId = rules.getPlayableClassId( userId, team ); 90 92 std::string playableModel = rules.getPlayableModelFileName( userId, team, playableClassId ); 91 93 92 94 BaseObject * bo = Factory::fabricate( playableClassId ); 93 95 94 96 assert( bo != NULL ); 95 97 assert( bo->isA( CL_PLAYABLE ) ); 96 98 97 99 Playable & playable = *(dynamic_cast<Playable*>(bo)); 98 100 99 101 playable.loadModel( playableModel ); 100 102 playable.setOwner( userId ); 101 103 playable.setUniqueID( SharedNetworkData::getInstance()->getNewUniqueID() ); 102 104 playable.setSynchronized( true ); 103 105 104 106 PlayerStats * stats = rules.getNewPlayerStats( userId ); 105 107 106 108 stats->setUniqueID( SharedNetworkData::getInstance()->getNewUniqueID() ); 107 109 stats->setSynchronized( true ); 108 110 stats->setOwner( getHostID() ); 109 111 110 112 stats->setTeamId( team ); 111 113 stats->setPlayableClassId( playableClassId ); 112 114 stats->setPlayableUniqueId( playable.getUniqueID() ); 113 115 stats->setModelFileName( playableModel ); 114 116 115 117 return true; 116 118 } … … 119 121 /** 120 122 * remove player from game 121 * @param userID 122 * @return 123 * @param userID 124 * @return 123 125 */ 124 126 bool NetworkGameManager::signalLeftPlayer(int userID) … … 130 132 delete PlayerStats::getStats( userID ); 131 133 } 132 134 133 135 return true; 134 136 } … … 138 140 /** 139 141 * handler for remove synchronizeable messages 140 * @param messageId 141 * @param data 142 * @param dataLength 143 * @param someData 144 * @param userId 142 * @param messageId 143 * @param data 144 * @param dataLength 145 * @param someData 146 * @param userId 145 147 * @return true on successfull handling else handler will be called again 146 148 */ … … 152 154 return true; 153 155 } 154 156 155 157 int uniqueId = 0; 156 158 int len = Converter::byteArrayToInt( data, &uniqueId ); 157 159 158 160 if ( len != dataLength ) 159 161 { … … 161 163 return true; 162 164 } 163 165 164 166 const std::list<BaseObject*> * list = ClassList::getList( CL_SYNCHRONIZEABLE ); 165 167 166 168 for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ ) 167 169 { … … 173 175 return true; 174 176 } 175 177 176 178 delete dynamic_cast<Synchronizeable*>(*it); 177 179 return true; 178 180 } 179 181 } 180 182 181 183 return true; 182 184 } … … 189 191 { 190 192 byte buf[INTSIZE]; 191 193 192 194 assert( Converter::intToByteArray( uniqueId, buf, INTSIZE ) == INTSIZE ); 193 195 194 196 MessageManager::getInstance()->sendMessage( MSGID_DELETESYNCHRONIZEABLE, buf, INTSIZE, RT_ALL_NOT_ME, 0, MP_HIGHBANDWIDTH ); 195 197 } … … 199 201 /** 200 202 * handler for MSGID_PREFEREDTEAM message 201 * @param messageId 202 * @param data 203 * @param dataLength 204 * @param someData 205 * @param userId 206 * @return 203 * @param messageId 204 * @param data 205 * @param dataLength 206 * @param someData 207 * @param userId 208 * @return 207 209 */ 208 210 bool NetworkGameManager::preferedTeamHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId ) 209 211 { 210 212 assert( NetworkGameManager::getInstance()->isServer() ); 211 213 212 214 int teamId = 0; 213 215 int len = Converter::byteArrayToInt( data, &teamId ); 214 216 215 217 if ( len != dataLength ) 216 218 { … … 218 220 return true; 219 221 } 220 222 221 223 NetworkGameManager::getInstance()->setPreferedTeam( userId, teamId ); 222 224 223 225 return true; 224 226 } … … 228 230 if ( !PlayerStats::getStats( userId ) ) 229 231 return; 230 232 231 233 PlayerStats & stats = *(PlayerStats::getStats( userId )); 232 234 233 235 stats.setPreferedTeamId( teamId ); 234 236 } … … 236 238 /** 237 239 * set prefered team for this host 238 * @param teamId 240 * @param teamId 239 241 */ 240 242 void NetworkGameManager::prefereTeam( int teamId ) … … 245 247 { 246 248 byte buf[INTSIZE]; 247 249 248 250 assert( Converter::intToByteArray( teamId, buf, INTSIZE) == INTSIZE ); 249 251 250 252 MessageManager::getInstance()->sendMessage( MSGID_PREFEREDTEAM, buf, INTSIZE, RT_USER, 0, MP_HIGHBANDWIDTH ); 251 253 }
Note: See TracChangeset
for help on using the changeset viewer.