Changeset 7777 for code/branches/network5/src/libraries/network/Server.cc
- Timestamp:
- Dec 19, 2010, 2:27:06 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network5/src/libraries/network/Server.cc
r7773 r7777 162 162 while(temp){ 163 163 chat = new packet::Chat(message, playerID); 164 chat->set ClientID(temp->getID());165 if(!chat->send( ))164 chat->setPeerID(temp->getID()); 165 if(!chat->send( static_cast<Host*>(this) )) 166 166 COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl; 167 167 temp = temp->next(); … … 220 220 221 221 // send function calls to clients 222 FunctionCallManager::sendCalls( );222 FunctionCallManager::sendCalls( static_cast<Host*>(this) ); 223 223 224 224 //this steers our network frequency … … 271 271 return; 272 272 GamestateManager::update(); 273 COUT(5) << "Server: one gamestate update complete, goig to sendGameState" << std::endl;273 // COUT(5) << "Server: one gamestate update complete, goig to sendGameState" << std::endl; 274 274 //std::cout << "updated gamestate, sending it" << std::endl; 275 275 //if(clients->getGamestateID()!=GAMESTATEID_INITIAL) 276 sendGameState ();276 sendGameStates(); 277 277 sendObjectDeletes(); 278 COUT(5) << "Server: one sendGameState turn complete, repeat in next tick" << std::endl;278 // COUT(5) << "Server: one sendGameState turn complete, repeat in next tick" << std::endl; 279 279 //std::cout << "sent gamestate" << std::endl; 280 280 } 281 281 282 bool Server::processPacket( ENetPacket *packet, ENetPeer *peer ){ 283 packet::Packet *p = packet::Packet::createPacket(packet, peer); 284 return p->process(); 285 } 286 287 /** 288 * sends the gamestate 289 */ 290 bool Server::sendGameState() 291 { 292 // COUT(5) << "Server: starting function sendGameState" << std::endl; 293 // ClientInformation *temp = ClientInformation::getBegin(); 294 // bool added=false; 295 // while(temp != NULL){ 296 // if( !(temp->getSynched()) ){ 297 // COUT(5) << "Server: not sending gamestate" << std::endl; 298 // temp=temp->next(); 299 // if(!temp) 300 // break; 301 // continue; 302 // } 303 // COUT(4) << "client id: " << temp->getID() << " RTT: " << temp->getRTT() << " loss: " << temp->getPacketLoss() << std::endl; 304 // COUT(5) << "Server: doing gamestate gamestate preparation" << std::endl; 305 // int cid = temp->getID(); //get client id 306 // packet::Gamestate *gs = GamestateManager::popGameState(cid); 307 // if(gs==NULL){ 308 // COUT(2) << "Server: could not generate gamestate (NULL from compress)" << std::endl; 309 // temp = temp->next(); 310 // continue; 311 // } 312 // //std::cout << "adding gamestate" << std::endl; 313 // gs->setClientID(cid); 314 // if ( !gs->send() ){ 315 // COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp->getFailures() << std::endl; 316 // temp->addFailure(); 317 // }else 318 // temp->resetFailures(); 319 // added=true; 320 // temp=temp->next(); 321 // // gs gets automatically deleted by enet callback 322 // } 323 GamestateManager::sendGamestates(); 282 /** 283 * sends the current gamestate to all peers 284 */ 285 bool Server::sendGameStates() 286 { 287 std::vector<packet::Gamestate*> gamestates = GamestateManager::getGamestates(); 288 std::vector<packet::Gamestate*>::iterator it; 289 for( it = gamestates.begin(); it != gamestates.end(); ++it ) 290 { 291 (*it)->send(static_cast<Host*>(this)); 292 } 324 293 return true; 325 294 } 295 326 296 327 297 bool Server::sendObjectDeletes() … … 348 318 packet::DeleteObjects *cd = new packet::DeleteObjects(*del); 349 319 assert(cd); 350 cd->set ClientID(cid);351 if ( !cd->send( ) )352 COUT(3) << "Server: packet with client id (cid): " << cid << " not sended : " << temp->getFailures()<< std::endl;320 cd->setPeerID(cid); 321 if ( !cd->send( static_cast<Host*>(this) ) ) 322 COUT(3) << "Server: packet with client id (cid): " << cid << " not sended" << std::endl; 353 323 temp=temp->next(); 354 324 // gs gets automatically deleted by enet callback … … 374 344 // inform all the listeners 375 345 ClientConnectionListener::broadcastClientConnected(newid); 346 GamestateManager::addPeer(newid); 376 347 377 348 ++newid; … … 394 365 } 395 366 } 367 368 void Server::processPacket(packet::Packet* packet) 369 { 370 if( packet->isReliable() ) 371 { 372 if( this->getLastProcessedGamestateID(packet->getPeerID()) >= packet->getRequiredGamestateID() ) 373 packet->process(static_cast<Host*>(this)); 374 else 375 this->packetQueue_.push_back(packet); 376 } 377 else 378 packet->process(static_cast<Host*>(this)); 379 } 380 396 381 397 382 bool Server::createClient(int clientID) … … 403 388 return false; 404 389 } 405 COUT( 5) << "Con.Man: creating client id: " << temp->getID() << std::endl;390 COUT(4) << "Con.Man: creating client id: " << temp->getID() << std::endl; 406 391 407 392 // synchronise class ids … … 410 395 // now synchronise functionIDs 411 396 packet::FunctionIDs *fIDs = new packet::FunctionIDs(); 412 fIDs->set ClientID(clientID);413 bool b = fIDs->send( );397 fIDs->setPeerID(clientID); 398 bool b = fIDs->send( static_cast<Host*>(this) ); 414 399 assert(b); 415 400 416 401 temp->setSynched(true); 402 GamestateManager::setSynched(clientID); 403 417 404 COUT(4) << "sending welcome" << std::endl; 418 405 packet::Welcome *w = new packet::Welcome(temp->getID(), temp->getShipID()); 419 w->set ClientID(temp->getID());420 b = w->send( );406 w->setPeerID(temp->getID()); 407 b = w->send( static_cast<Host*>(this) ); 421 408 assert(b); 422 409 packet::Gamestate *g = new packet::Gamestate(); 423 g->setClientID(temp->getID()); 424 b = g->collectData(0,0x1); 410 g->setPeerID(temp->getID()); 411 b = g->collectData(0,packet::GAMESTATE_MODE_SERVER); 412 assert(b); 425 413 if(!b) 426 414 return false; //no data for the client 427 415 // b = g->compressData(); 428 416 // assert(b); 429 b = g->send( );417 b = g->send( static_cast<Host*>(this) ); 430 418 assert(b); 431 419 return true; … … 435 423 { 436 424 ServerConnection::disconnectClient( client ); 437 GamestateManager::remove Client(client);425 GamestateManager::removePeer(client->getID()); 438 426 // inform all the listeners 439 427 // ClientConnectionListener::broadcastClientDisconnected(client->getID()); // this is done in ClientInformation now … … 457 445 { 458 446 chat = new packet::Chat(message, clientID); 459 chat->set ClientID(temp->getID());460 if(!chat->send( ))447 chat->setPeerID(temp->getID()); 448 if(!chat->send( static_cast<Host*>(this) )) 461 449 COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl; 462 450 temp = temp->next(); … … 473 461 int failures=0; 474 462 packet::ClassID *classid = new packet::ClassID(); 475 classid->set ClientID(clientID);476 while(!classid->send( ) && failures < 10){463 classid->setPeerID(clientID); 464 while(!classid->send( static_cast<Host*>(this) ) && failures < 10){ 477 465 failures++; 478 466 }
Note: See TracChangeset
for help on using the changeset viewer.