Changeset 9253 in orxonox.OLD for branches/proxy/src
- Timestamp:
- Jul 12, 2006, 11:28:38 AM (18 years ago)
- Location:
- branches/proxy/src/lib/network
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/proxy/src/lib/network/netdefs.h
r9248 r9253 1 /* 2 orxonox - the future of 3D-vertical-scrollers 1 3 4 Copyright (C) 2004 orx 5 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2, or (at your option) 9 any later version. 10 11 ### File Specific: 12 main-programmer: Christoph Renner rennerc@ee.ethz.ch 13 co-programmer: Patrick Boenzli boenzlip@orxonox.ethz.ch 14 15 June 2006: finishing work on the network stream for pps presentation (rennerc@ee.ethz.ch) 16 July 2006: some code rearangement and integration of the proxy server mechanism (boenzlip@ee.ethz.ch) 17 */ 2 18 3 19 /*! -
branches/proxy/src/lib/network/network_game_manager.cc
r9235 r9253 10 10 11 11 ### File Specific: 12 main-programmer: Benjamin Wuest 13 co-programmer: ... 12 main-programmer: Christoph Renner rennerc@ee.ethz.ch 13 co-programmer: Patrick Boenzli boenzlip@orxonox.ethz.ch 14 15 June 2006: finishing work on the network stream for pps presentation (rennerc@ee.ethz.ch) 16 July 2006: some code rearangement and integration of the proxy server mechanism (boenzlip@ee.ethz.ch) 14 17 */ 15 18 16 19 17 /* this is for debug output. It just says, that all calls to PRINT() belong to the DEBUG_MODULE_NETWORK module 18 For more information refere to https://www.orxonox.net/cgi-bin/trac.cgi/wiki/DebugOutput 19 */ 20 20 21 #define DEBUG_MODULE_NETWORK 21 22 … … 45 46 46 47 47 /* using namespace std is default, this needs to be here */48 48 using namespace std; 49 49 … … 62 62 63 63 this->setSynchronized(true); 64 64 65 65 MessageManager::getInstance()->registerMessageHandler( MSGID_DELETESYNCHRONIZEABLE, delSynchronizeableHandler, NULL ); 66 66 MessageManager::getInstance()->registerMessageHandler( MSGID_PREFEREDTEAM, preferedTeamHandler, NULL ); 67 67 MessageManager::getInstance()->registerMessageHandler( MSGID_CHATMESSAGE, chatMessageHandler, NULL ); 68 68 69 69 this->gameState = 0; 70 70 registerVar( new SynchronizeableInt( &gameState, &gameState, "gameState" ) ); … … 77 77 { 78 78 delete MessageManager::getInstance(); 79 79 80 80 PlayerStats::deleteAllPlayerStats(); 81 81 82 82 NetworkGameManager::singletonRef = NULL; 83 83 } … … 86 86 /** 87 87 * insert new player into game 88 * @param userId 89 * @return 88 * @param userId 89 * @return 90 90 */ 91 91 bool NetworkGameManager::signalNewPlayer( int userId ) … … 94 94 assert( State::getGameRules() ); 95 95 assert( State::getGameRules()->isA( CL_NETWORK_GAME_RULES ) ); 96 96 97 97 NetworkGameRules & rules = *(dynamic_cast<NetworkGameRules*>(State::getGameRules())); 98 98 99 99 int team = rules.getTeamForNewUser(); 100 100 ClassID playableClassId = rules.getPlayableClassId( userId, team ); … … 102 102 std::string playableTexture = rules.getPlayableModelFileName( userId, team, playableClassId ); 103 103 float playableScale = rules.getPlayableScale( userId, team, playableClassId ); 104 104 105 105 BaseObject * bo = Factory::fabricate( playableClassId ); 106 106 107 107 assert( bo != NULL ); 108 108 assert( bo->isA( CL_PLAYABLE ) ); 109 109 110 110 Playable & playable = *(dynamic_cast<Playable*>(bo)); 111 111 112 112 playable.loadMD2Texture( playableTexture ); 113 113 114 114 playable.loadModel( playableModel, 100.0f ); 115 115 playable.setOwner( userId ); 116 116 playable.setUniqueID( SharedNetworkData::getInstance()->getNewUniqueID() ); 117 117 playable.setSynchronized( true ); 118 118 119 119 PlayerStats * stats = rules.getNewPlayerStats( userId ); 120 120 121 121 stats->setUniqueID( SharedNetworkData::getInstance()->getNewUniqueID() ); 122 122 stats->setSynchronized( true ); 123 123 stats->setOwner( SharedNetworkData::getInstance()->getHostID() ); 124 124 125 125 stats->setTeamId( team ); 126 126 stats->setPlayableClassId( playableClassId ); 127 127 stats->setPlayableUniqueId( playable.getUniqueID() ); 128 128 stats->setModelFileName( playableModel ); 129 129 130 130 if ( userId == 0 ) 131 131 stats->setNickName( Preferences::getInstance()->getString( "multiplayer", "nickname", "Server" ) ); 132 132 133 133 if ( rules.isA( CL_MULTIPLAYER_TEAM_DEATHMATCH ) ) 134 134 dynamic_cast<MultiplayerTeamDeathmatch*>(&rules)->respawnPlayable( &playable, team, 0.0f ); 135 135 136 136 return true; 137 137 } … … 140 140 /** 141 141 * remove player from game 142 * @param userID 143 * @return 142 * @param userID 143 * @return 144 144 */ 145 145 bool NetworkGameManager::signalLeftPlayer(int userID) … … 151 151 delete PlayerStats::getStats( userID ); 152 152 } 153 153 154 154 return true; 155 155 } … … 159 159 /** 160 160 * handler for remove synchronizeable messages 161 * @param messageId 162 * @param data 163 * @param dataLength 164 * @param someData 165 * @param userId 161 * @param messageId 162 * @param data 163 * @param dataLength 164 * @param someData 165 * @param userId 166 166 * @return true on successfull handling else handler will be called again 167 167 */ … … 173 173 return true; 174 174 } 175 175 176 176 int uniqueId = 0; 177 177 int len = Converter::byteArrayToInt( data, &uniqueId ); 178 178 179 179 if ( len != dataLength ) 180 180 { … … 182 182 return true; 183 183 } 184 184 185 185 const std::list<BaseObject*> * list = ClassList::getList( CL_SYNCHRONIZEABLE ); 186 186 187 187 for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ ) 188 188 { … … 194 194 return true; 195 195 } 196 196 197 197 delete dynamic_cast<Synchronizeable*>(*it); 198 198 return true; 199 199 } 200 200 } 201 201 202 202 return true; 203 203 } … … 210 210 { 211 211 byte buf[INTSIZE]; 212 212 213 213 assert( Converter::intToByteArray( uniqueId, buf, INTSIZE ) == INTSIZE ); 214 214 … … 220 220 /** 221 221 * handler for MSGID_PREFEREDTEAM message 222 * @param messageId 223 * @param data 224 * @param dataLength 225 * @param someData 226 * @param userId 227 * @return 222 * @param messageId 223 * @param data 224 * @param dataLength 225 * @param someData 226 * @param userId 227 * @return 228 228 */ 229 229 bool NetworkGameManager::preferedTeamHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId ) 230 230 { 231 231 assert( NetworkGameManager::getInstance()->isServer() ); 232 232 233 233 int teamId = 0; 234 234 int len = Converter::byteArrayToInt( data, &teamId ); 235 235 236 236 if ( len != dataLength ) 237 237 { … … 239 239 return true; 240 240 } 241 241 242 242 NetworkGameManager::getInstance()->setPreferedTeam( userId, teamId ); 243 243 244 244 return true; 245 245 } … … 249 249 if ( !PlayerStats::getStats( userId ) ) 250 250 return; 251 251 252 252 PlayerStats & stats = *(PlayerStats::getStats( userId )); 253 253 254 254 stats.setPreferedTeamId( teamId ); 255 255 } … … 257 257 /** 258 258 * set prefered team for this host 259 * @param teamId 259 * @param teamId 260 260 */ 261 261 void NetworkGameManager::prefereTeam( int teamId ) … … 266 266 { 267 267 byte buf[INTSIZE]; 268 268 269 269 assert( Converter::intToByteArray( teamId, buf, INTSIZE) == INTSIZE ); 270 270 271 271 MessageManager::getInstance()->sendMessage( MSGID_PREFEREDTEAM, buf, INTSIZE, RT_USER, 0, MP_HIGHBANDWIDTH ); 272 272 } … … 285 285 { 286 286 const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYABLE ); 287 287 288 288 if ( list && std::find( list->begin(), list->end(), *it ) != list->end() ) 289 { 289 { 290 290 PRINTF(0)("Delete unused playable: %s owner: %d\n", (*it)->getClassName(), (*it)->getOwner() ); 291 291 std::list<Playable*>::iterator delit = it; … … 309 309 MessageManager::getInstance()->sendMessage( messageId, data, dataLength, RT_ALL_NOT_ME, 0, MP_HIGHBANDWIDTH ); 310 310 } 311 311 312 312 assert( State::getGameRules() ); 313 313 assert( State::getGameRules()->isA( CL_NETWORK_GAME_RULES ) ); 314 314 315 315 NetworkGameRules & rules = *(dynamic_cast<NetworkGameRules*>(State::getGameRules())); 316 316 317 317 if ( dataLength < 3*INTSIZE ) 318 318 { 319 319 PRINTF(2)("got too small chatmessage from client %d\n", userId); 320 320 321 321 return true; 322 322 } 323 323 324 324 int messageType = 0; 325 325 Converter::byteArrayToInt( data, &messageType ); … … 328 328 std::string message; 329 329 Converter::byteArrayToString( data+2*INTSIZE, message, dataLength-2*INTSIZE ); 330 330 331 331 rules.handleChatMessage( senderUserId, message, messageType ); 332 332 … … 346 346 assert( Converter::intToByteArray( SharedNetworkData::getInstance()->getHostID(), buf+INTSIZE, INTSIZE ) == INTSIZE ); 347 347 assert( Converter::stringToByteArray(message, buf+2*INTSIZE, message.length()+INTSIZE) == message.length()+INTSIZE ); 348 348 349 349 if ( this->isServer() ) 350 350 MessageManager::getInstance()->sendMessage( MSGID_CHATMESSAGE, buf, message.length()+3*INTSIZE, RT_ALL_ME, 0, MP_HIGHBANDWIDTH ); … … 352 352 MessageManager::getInstance()->sendMessage( MSGID_CHATMESSAGE, buf, message.length()+3*INTSIZE, RT_ALL_NOT_ME, 0, MP_HIGHBANDWIDTH ); 353 353 354 354 355 355 delete [] buf; 356 356 } -
branches/proxy/src/lib/network/network_game_manager.h
r9248 r9253 28 28 NET_YOU_ARE_ENTITY, 29 29 NET_REQUEST_ENTITY_LIST, 30 NET_REQUEST_PNODE_PATH,31 NET_SEND_PNODE_PATH,32 30 33 31 NET_NUMBER
Note: See TracChangeset
for help on using the changeset viewer.