Changeset 9300 in orxonox.OLD for branches/proxy/src/lib/network/network_stream.cc
- Timestamp:
- Jul 17, 2006, 10:15:33 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/proxy/src/lib/network/network_stream.cc
r9296 r9300 81 81 this->peers[0].nodeType = NET_MASTER_SERVER; 82 82 this->peers[0].connectionMonitor = new ConnectionMonitor( 0 ); 83 this->peers[0].ip = this->peers[0].socket->getDestAddress(); 83 84 // and set also the localhost 84 85 this->pInfo->nodeType = NET_CLIENT; 86 // get the local ip address 87 SDLNet_ResolveHost( &this->pInfo->ip, "localhost", port ); 88 85 89 } 86 90 … … 95 99 this->serverSocket = new UdpServerSocket(port); 96 100 this->pInfo->nodeType = NET_MASTER_SERVER; 101 // get the local ip address 102 SDLNet_ResolveHost( &this->pInfo->ip, "localhost", port ); 97 103 } 98 104 … … 164 170 if( this->pInfo) 165 171 delete this->pInfo; 172 173 if( this->networkMonitor) 174 delete this->networkMonitor; 166 175 } 167 176 … … 182 191 /** 183 192 * starts the network handshake 193 * handsakes are always initialized from the client side first. this starts the handshake and therefore is only 194 * executed as client 184 195 */ 185 196 void NetworkStream::startHandshake() … … 190 201 peers[0].handshake = hs; 191 202 203 // set the preferred nick name 192 204 hs->setPreferedNickName( Preferences::getInstance()->getString( "multiplayer", "nickname", "Player" ) ); 193 //hs->set194 205 195 206 // peers[0].handshake->setSynchronized( true ); … … 314 325 peers[clientId].socket = tempNetworkSocket; 315 326 peers[clientId].handshake = new Handshake(this->pInfo->nodeType, clientId, this->networkGameManager->getUniqueID(), MessageManager::getInstance()->getUniqueID() ); 327 peers[clientId].handshake->setUniqueID(clientId); 328 329 // get the proxy server informations and write them to the handshake, if any (proxy) 330 PeerInfo* pi = this->networkMonitor->getFirstChoiceProxy(); 331 if( pi != NULL) 332 peers[clientId].handshake->setProxy1Address( pi->ip); 333 pi = this->networkMonitor->getSecondChoiceProxy(); 334 if( pi != NULL) 335 peers[clientId].handshake->setProxy2Address( pi->ip); 336 337 // check if the connecting client should reconnect to a proxy server 338 peers[clientId].handshake->setRedirect(this->networkMonitor->reconnectNextClient()); 339 316 340 peers[clientId].connectionMonitor = new ConnectionMonitor( clientId ); 317 peers[clientId].handshake->setUniqueID(clientId);318 341 peers[clientId].userId = clientId; 319 342 peers[clientId].nodeType = NET_CLIENT; … … 328 351 329 352 peers[clientId].socket = tempNetworkSocket; 353 // handshake handling 330 354 peers[clientId].handshake = new Handshake(this->pInfo->nodeType, clientId, this->networkGameManager->getUniqueID(), MessageManager::getInstance()->getUniqueID()); 331 355 peers[clientId].handshake->setUniqueID(clientId); 356 // get the proxy server informations and write them to the handshake, if any (proxy) 357 PeerInfo* pi = this->networkMonitor->getFirstChoiceProxy(); 358 if( pi != NULL) 359 peers[clientId].handshake->setProxy1Address( pi->ip); 360 pi = this->networkMonitor->getSecondChoiceProxy(); 361 if( pi != NULL) 362 peers[clientId].handshake->setProxy2Address( pi->ip); 363 364 // check if the connecting client should reconnect to a proxy server 365 peers[clientId].handshake->setRedirect(this->networkMonitor->reconnectNextClient()); 366 332 367 peers[clientId].connectionMonitor = new ConnectionMonitor( clientId ); 333 368 peers[clientId].userId = clientId; … … 337 372 } 338 373 339 // check if there are too many clients connected 374 // check if there are too many clients connected (DEPRECATED: new: the masterserver sends a list of proxy servers) 340 375 if ( clientId > NET_MAX_CONNECTIONS ) 341 376 { 342 peers[clientId].handshake->doReject( "too many connections" ); 377 // peers[clientId].handshake->setRedirect(true); 378 // 379 // peers[clientId].handshake->doReject( "too many connections" ); 343 380 PRINTF(0)("Will reject client %d because there are to many connections!\n", clientId); 344 381 } … … 467 504 this->networkMonitor->addNode(&it->second); 468 505 506 // get proxy 1 address and add it 507 this->networkMonitor->addNode(it->second.handshake->getProxy1Address()); 508 // get proxy 2 address and add it 509 this->networkMonitor->addNode(it->second.handshake->getProxy2Address()); 510 511 512 // now check if there server accepted the connection 513 if( it->second.handshake->redirect()) 514 { 515 // handle the redirection 516 PRINTF(0)("===============================================\n"); 517 PRINTF(0)("Client is redirected to the other proxy servers\n"); 518 PRINTF(0)("===============================================\n"); 519 520 // disconnect from the current server and reconnect to proxy server 521 // it->second.socket->disconnectServer(); 522 523 } 524 525 // create the new network game manager and init it 469 526 this->networkGameManager = NetworkGameManager::getInstance(); 470 527 this->networkGameManager->setUniqueID( it->second.handshake->getNetworkGameManagerId() ); 528 // init the new message manager 471 529 MessageManager::getInstance()->setUniqueID( it->second.handshake->getMessageManagerId() ); 472 530 }
Note: See TracChangeset
for help on using the changeset viewer.