Changeset 6341 in orxonox.OLD for trunk/src/lib/network/network_stream.cc
- Timestamp:
- Dec 30, 2005, 1:57:12 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/network/network_stream.cc
r6144 r6341 27 27 #include "synchronizeable.h" 28 28 #include "network_manager.h" 29 #include "network_game_manager.h" 30 29 31 #include "debug.h" 30 32 #include "class_list.h" … … 64 66 this->connectSynchronizeable(*hs); 65 67 PRINTF(0)("NetworkStream: %s\n", hs->getName()); 68 this->maxConnections = 1; 66 69 } 67 70 … … 77 80 this->handshakes.push_back( NULL ); 78 81 this->bActive = true; 82 this->networkGameManager = NetworkGameManager::getInstance(); 83 // setUniqueID( maxCon+2 ) because we need one id for every handshake 84 // and one for handshake to reject client maxCon+1 85 this->networkGameManager->setUniqueID( this->maxConnections+2 ); 86 this->connectSynchronizeable( *(this->networkGameManager) ); 79 87 80 88 this->setMaxConnections( 10 ); … … 88 96 this->bActive = false; 89 97 this->serverSocket = NULL; 98 this->networkGameManager = NULL; 90 99 myHostId = 0; 91 100 } … … 176 185 NetworkManager::getInstance()->setHostID( handshakes[i]->getHostId() ); 177 186 myHostId = NetworkManager::getInstance()->getHostID(); 178 } 179 PRINT(0)("handshake finished\n"); 187 188 this->networkGameManager = NetworkGameManager::getInstance(); 189 this->networkGameManager->setUniqueID( handshakes[i]->getNetworkGameManagerId() ); 190 this->connectSynchronizeable( *(this->networkGameManager) ); 191 } 192 else 193 { 194 //this->networkGameManager->sendEntityList( i ); 195 } 196 PRINT(0)("handshake finished id=%d\n", handshakes[i]->getNetworkGameManagerId()); 197 198 180 199 delete handshakes[i]; 181 200 handshakes[i] = NULL; 182 //TODO: replace handshake by entitymanager183 201 } 184 202 else … … 202 220 for (SynchronizeableList::iterator it = synchronizeables.begin(); it!=synchronizeables.end(); it++) 203 221 { 204 //TODO: remove items from synchronizeables if they dont exist 205 if ( (*it)!=NULL && (*it)->getOwner() == myHostId ) 222 if ( (*it)!=NULL /*&& (*it)->getOwner() == myHostId*/ ) 206 223 { 207 224 do { … … 217 234 dataLength = networkProtocol->createHeader((byte*)downBuffer, dataLength, DATA_STREAM_BUFFER_SIZE, static_cast<const Synchronizeable&>(*(*it))); 218 235 219 //FIXME: this is a hack, find a better way220 236 Header* header = (Header*)downBuffer; 221 if ( header->synchronizeableID<100 ) 237 if ( header->synchronizeableID < this->maxConnections+2 ) 238 { 239 //if ( !isServer() ) PRINTF(0)("RESET UNIQUEID FROM %d TO 0 maxCon=%d\n", header->synchronizeableID, this->maxConnections); 222 240 header->synchronizeableID = 0; 241 } 242 else 243 { 244 //if ( !isServer() ) PRINTF(0)("UNIQUEID=%d\n", header->synchronizeableID); 245 } 223 246 224 247 if ( dataLength<=0 ) … … 229 252 if ( networkSockets[reciever] != NULL ) 230 253 { 231 PRINTF( 5)("write %d bytes to socket %d\n", dataLength, reciever);254 PRINTF(0)("write %d bytes to socket %d\n", dataLength, reciever); 232 255 networkSockets[reciever]->writePacket(downBuffer, dataLength); 233 256 } … … 243 266 if ( networkSockets[i] != NULL ) 244 267 { 245 PRINTF( 5)("write %d bytes to socket %d\n", dataLength, reciever);268 PRINTF(0)("write %d bytes to socket %d\n", dataLength, reciever); 246 269 networkSockets[i]->writePacket(downBuffer, dataLength); 247 270 } … … 251 274 } while( reciever!=0 ); 252 275 } 253 else254 {255 PRINTF(0)("synchronizeables == NULL");256 }257 276 } 258 277 … … 269 288 continue; 270 289 271 PRINTF(5)("read %d bytes from socket\n", dataLength);272 290 header = networkProtocol->extractHeader(upBuffer, dataLength); 273 291 dataLength -= sizeof(header); 274 292 293 PRINTF(0)("read %d bytes from socket uniqueID = %d\n", dataLength, header.synchronizeableID); 294 275 295 if ( dataLength != header.length ) 276 296 { … … 287 307 { 288 308 if ( *it && (*it)->getUniqueID()==header.synchronizeableID ) 289 (*it)->writeBytes(upBuffer+sizeof(header), dataLength); 309 { 310 if ( (*it)->writeBytes(upBuffer+sizeof(header), dataLength, i) != header.length ) 311 { 312 PRINTF(1)("%s did not read all the data!\n", (*it)->getClassName()); 313 break; 314 } 315 continue; 316 } 290 317 } 291 318 … … 309 336 freeSocketSlots.pop_back(); 310 337 networkSockets[clientId] = tempNetworkSocket; 311 handshakes[clientId] = new Handshake(true, clientId );338 handshakes[clientId] = new Handshake(true, clientId, this->networkGameManager->getUniqueID()); 312 339 handshakes[clientId]->setUniqueID(clientId); 313 340 } else … … 315 342 clientId = networkSockets.size(); 316 343 networkSockets.push_back(tempNetworkSocket); 317 Handshake* tHs = new Handshake(true, clientId );344 Handshake* tHs = new Handshake(true, clientId, this->networkGameManager->getUniqueID()); 318 345 tHs->setUniqueID(clientId); 319 346 handshakes.push_back(tHs); … … 376 403 return; 377 404 } 405 406 if ( n > MAX_CONNECTIONS ) 407 { 408 PRINTF(1)("Cannot set maxConnectiosn to %d because of hardcoded limit %d\n", n, MAX_CONNECTIONS); 409 return; 410 } 411 378 412 this->maxConnections = n; 379 } 380 381 413 this->networkGameManager->setUniqueID( n+2 ); 414 } 415 416
Note: See TracChangeset
for help on using the changeset viewer.