Changeset 6503 in orxonox.OLD for branches/network
- Timestamp:
- Jan 11, 2006, 11:54:32 PM (19 years ago)
- Location:
- branches/network/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/network/src/lib/network/network_game_manager.cc
r6500 r6503 52 52 this->setClassID(CL_NETWORK_GAME_MANAGER, "NetworkGameManager"); 53 53 54 allOutBuffer.length = 0;55 56 allOutBuffer.maxLength = 10*1024;57 58 allOutBuffer.buffer = new byte[10*1024];59 60 54 newUniqueID = MAX_CONNECTIONS + 2; 61 55 … … 74 68 } 75 69 76 if ( allOutBuffer.buffer )77 delete allOutBuffer.buffer;78 70 } 79 71 … … 107 99 if ( b == CREATE_ENTITY ) 108 100 { 101 PRINTF(0)("CREATE_ENTITY\n"); 109 102 if ( !handleCreateEntity( i, data, length, sender ) ) 110 103 return i; … … 188 181 } 189 182 190 *reciever = 0; 191 int nbytes = allOutBuffer.length; 192 allOutBuffer.length = 0; 193 194 if ( nbytes <=0 ) 195 return 0; 196 197 if ( nbytes > maxLength ) 198 { 199 PRINTF(1)("OutBuffer.length (%d) > (%d) networkStreamBuffer.length\n", nbytes, maxLength); 200 return 0; 201 } 202 203 memcpy( data, allOutBuffer.buffer, nbytes ); 204 return nbytes; 183 return 0; 205 184 } 206 185 … … 221 200 int NetworkGameManager::createEntity( ClassID classID, int owner ) 222 201 { 223 224 202 if ( this->isServer() ) 225 203 { … … 254 232 return NULL; 255 233 } 256 newUniqueID++;257 234 258 235 BaseObject * b = Factory::fabricate( element ); … … 268 245 { 269 246 Synchronizeable * s = dynamic_cast<Synchronizeable*>(b); 270 s->setUniqueID( newUniqueID );247 s->setUniqueID( newUniqueID++ ); 271 248 s->setOwner( 0 ); 272 249 this->networkStream->connectSynchronizeable( *s ); … … 313 290 void NetworkGameManager::requestCreateEntity(ClassID classID) 314 291 { 315 if ( !writeToClientBuffer( allOutBuffer, (byte)REQUEST_CREATE ) ) 316 return; 317 if ( !writeToClientBuffer( allOutBuffer, (int)classID ) ) 318 return; 292 for ( int i = 0; i<outBuffer.size(); i++) 293 { 294 if ( !this->networkStream->isUserIdActive( i ) ) 295 continue; 296 297 if ( !writeToClientBuffer( outBuffer[i], (byte)REQUEST_CREATE ) ) 298 return; 299 if ( !writeToClientBuffer( outBuffer[i], (int)classID ) ) 300 return; 301 } 319 302 } 320 303 … … 325 308 void NetworkGameManager::requestRemoveEntity(int uniqueID) 326 309 { 327 if ( !writeToClientBuffer( allOutBuffer, (byte)REQUEST_REMOVE ) ) 328 return; 329 if ( !writeToClientBuffer( allOutBuffer, uniqueID ) ) 330 return; 310 for ( int i = 0; i<outBuffer.size(); i++) 311 { 312 if ( !this->networkStream->isUserIdActive( i ) ) 313 continue; 314 315 if ( !writeToClientBuffer( outBuffer[i], (byte)REQUEST_REMOVE ) ) 316 return; 317 if ( !writeToClientBuffer( outBuffer[i], uniqueID ) ) 318 return; 319 } 331 320 } 332 321 … … 338 327 int NetworkGameManager::executeCreateEntity(ClassID classID, int uniqueID, int owner) 339 328 { 340 if ( !writeToClientBuffer( allOutBuffer, (byte)CREATE_ENTITY ) ) 341 return -1; 342 if ( !writeToClientBuffer( allOutBuffer, (int)classID ) ) 343 return -1; 344 if ( !writeToClientBuffer( allOutBuffer, uniqueID ) ) 345 return -1; 346 if ( !writeToClientBuffer( allOutBuffer, owner ) ) 347 return -1; 329 for ( int i = 0; i<outBuffer.size(); i++) 330 { 331 if ( !this->networkStream->isUserIdActive( i ) ) 332 continue; 333 334 if ( !writeToClientBuffer( outBuffer[i], (byte)CREATE_ENTITY ) ) 335 return -1; 336 if ( !writeToClientBuffer( outBuffer[i], (int)classID ) ) 337 return -1; 338 if ( !writeToClientBuffer( outBuffer[i], uniqueID ) ) 339 return -1; 340 if ( !writeToClientBuffer( outBuffer[i], owner ) ) 341 return -1; 342 } 348 343 349 344 doCreateEntity( classID, uniqueID, owner ); … … 359 354 void NetworkGameManager::executeRemoveEntity(int uniqueID) 360 355 { 361 if ( !writeToClientBuffer( allOutBuffer, (byte)REMOVE_ENTITY ) ) 362 return; 363 if ( !writeToClientBuffer( allOutBuffer, uniqueID ) ) 364 return; 356 for ( int i = 0; i<outBuffer.size(); i++) 357 { 358 if ( !this->networkStream->isUserIdActive( i ) ) 359 continue; 360 361 if ( !writeToClientBuffer( outBuffer[i], (byte)REMOVE_ENTITY ) ) 362 return; 363 if ( !writeToClientBuffer( outBuffer[i], uniqueID ) ) 364 return; 365 } 365 366 366 367 doRemoveEntity(uniqueID); … … 406 407 while ( it != e ) 407 408 { 408 409 PRINTF(5)("SENDING ENTITY %s id %d\n", (*it)->getClassName(), (*it)->getUniqueID() ); 409 410 if ( !writeToClientBuffer( outBuffer[userID], (int)((*it)->getLeafClassID()) ) ) 410 411 return; … … 426 427 bool NetworkGameManager::signalNewPlayer(int userId) 427 428 { 429 if ( userId >= outBuffer.size() ) 430 resizeBufferVector( userId ); 428 431 429 432 /* create new playable for Player*/ -
branches/network/src/lib/network/network_game_manager.h
r6500 r6503 122 122 private: 123 123 std::vector<clientBuffer> outBuffer; 124 clientBuffer allOutBuffer;124 //clientBuffer allOutBuffer; 125 125 static NetworkGameManager* singletonRef; 126 126 -
branches/network/src/lib/network/network_stream.cc
r6500 r6503 78 78 this->connectionMonitor = new ConnectionMonitor(); 79 79 this->networkSockets.push_back( NULL ); 80 this->networkSockets[0] = NULL; //TODO: remove this 80 81 this->handshakes.push_back( NULL ); 81 82 this->bActive = true; … … 266 267 if ( networkSockets[i] != NULL ) 267 268 { 268 PRINTF(5)("write %d bytes to socket %d\n", dataLength, reciever);269 PRINTF(5)("write %d bytes to socket %d\n", dataLength, i); 269 270 networkSockets[i]->writePacket(downBuffer, dataLength); 270 271 } -
branches/network/src/lib/network/network_stream.h
r6341 r6503 55 55 inline int getSyncCount(){ return synchronizeables.size(); } 56 56 57 inline bool isUserIdActive( int userID ) { if (userID>=networkSockets.size()) return false; else return networkSockets[userID]!=NULL; } 58 57 59 private: 58 60 NetworkProtocol* networkProtocol; -
branches/network/src/world_entities/space_ships/space_ship.cc
r6500 r6503 539 539 } 540 540 541 return SYNCHELP_READ_N; 542 541 543 if ( b == DATA_flags && this->getHostID()!=this->getOwner() ) 542 544 { … … 591 593 } 592 594 595 return 0; 593 596 594 597 *reciever = 0;
Note: See TracChangeset
for help on using the changeset viewer.