Changeset 7801 for code/trunk/src/libraries/network/Server.cc
- Timestamp:
- Dec 22, 2010, 7:24:24 PM (13 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/libraries/network/Server.cc
r7284 r7801 60 60 #include "FunctionCallManager.h" 61 61 #include "GamestateManager.h" 62 #include "WANDiscovery.h" 62 63 63 64 namespace orxonox … … 99 100 } 100 101 102 103 /** helper that connects to the master server */ 104 void Server::helper_ConnectToMasterserver() 105 { 106 // WANDiscovery::getInstance().msc.sendRequest( MSPROTO_GAME_SERVER " " 107 // MSPROTO_REGISTER_SERVER ); 108 } 109 101 110 /** 102 111 * This function opens the server by creating the listener thread … … 107 116 COUT(4) << "opening server" << endl; 108 117 this->openListener(); 118 119 /* make discoverable on LAN */ 109 120 LANDiscoverable::setActivity(true); 121 122 /* make discoverable on WAN */ 123 WANDiscoverable::setActivity(true); 124 /* TODO this needs to be optional, we need a switch from the UI to 125 * enable/disable this 126 */ 127 // helper_ConnectToMasterserver(); 128 129 /* done */ 110 130 return; 111 131 } … … 120 140 this->disconnectClients(); 121 141 this->closeListener(); 142 143 /* tell master server we're closing */ 144 COUT(2) << "disconnecting." << endl; 145 WANDiscoverable::setActivity(false); 146 COUT(2) << "disconnecting done" << endl; 147 122 148 LANDiscoverable::setActivity(false); 123 149 return; … … 130 156 while(temp){ 131 157 chat = new packet::Chat(message, playerID); 132 chat->set ClientID(temp->getID());133 if(!chat->send( ))158 chat->setPeerID(temp->getID()); 159 if(!chat->send( static_cast<Host*>(this) )) 134 160 COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl; 135 161 temp = temp->next(); … … 139 165 } 140 166 167 168 /* handle incoming data */ 169 int rephandler( char *addr, ENetEvent *ev ) 170 { 171 /* reply to pings */ 172 if( !strncmp( (char *)ev->packet->data, MSPROTO_PING_GAMESERVER, 173 MSPROTO_PING_GAMESERVER_LEN ) ) 174 //this->msc.sendRequest( MSPROTO_ACK ); 175 /* NOTE implement this after pollForReply 176 * reimplementation 177 */ 178 return 0; 179 180 /* done handling, return all ok code 0 */ 181 return 0; 182 } 183 184 void Server::helper_HandleMasterServerRequests() 185 { 186 /* poll the master server for replies and see whether something 187 * has to be done or changed. 188 */ 189 //WANDiscovery::getInstance().msc.pollForReply( rhandler, 10 ); 190 } 141 191 142 192 /** … … 149 199 // receive incoming packets 150 200 Connection::processQueue(); 201 151 202 // receive and process incoming discovery packets 152 203 LANDiscoverable::update(); 204 205 // receive and process requests from master server 206 /* todo */ 207 //helper_HandleMasterServerRequests(); 153 208 154 209 if ( ClientInformation::hasClients() ) … … 156 211 // process incoming gamestates 157 212 GamestateManager::processGamestates(); 213 FunctionCallManager::processBufferedFunctionCalls(); 158 214 159 215 // send function calls to clients 160 FunctionCallManager::sendCalls( );216 FunctionCallManager::sendCalls( static_cast<Host*>(this) ); 161 217 162 218 //this steers our network frequency … … 167 223 updateGamestate(); 168 224 } 169 sendPackets(); // flush the enet queue170 } 171 } 172 173 bool Server::queuePacket(ENetPacket *packet, int clientID)174 { 175 return ServerConnection::addPacket(packet, clientID);225 // sendPackets(); // flush the enet queue 226 } 227 } 228 229 void Server::queuePacket(ENetPacket *packet, int clientID, uint8_t channelID) 230 { 231 ServerConnection::addPacket(packet, clientID, channelID); 176 232 } 177 233 … … 209 265 return; 210 266 GamestateManager::update(); 211 COUT(5) << "Server: one gamestate update complete, goig to sendGameState" << std::endl;267 // COUT(5) << "Server: one gamestate update complete, goig to sendGameState" << std::endl; 212 268 //std::cout << "updated gamestate, sending it" << std::endl; 213 269 //if(clients->getGamestateID()!=GAMESTATEID_INITIAL) 214 sendGameState ();270 sendGameStates(); 215 271 sendObjectDeletes(); 216 COUT(5) << "Server: one sendGameState turn complete, repeat in next tick" << std::endl;272 // COUT(5) << "Server: one sendGameState turn complete, repeat in next tick" << std::endl; 217 273 //std::cout << "sent gamestate" << std::endl; 218 274 } 219 275 220 bool Server::processPacket( ENetPacket *packet, ENetPeer *peer ){ 221 packet::Packet *p = packet::Packet::createPacket(packet, peer); 222 return p->process(); 223 } 224 225 /** 226 * sends the gamestate 227 */ 228 bool Server::sendGameState() 229 { 230 // COUT(5) << "Server: starting function sendGameState" << std::endl; 231 // ClientInformation *temp = ClientInformation::getBegin(); 232 // bool added=false; 233 // while(temp != NULL){ 234 // if( !(temp->getSynched()) ){ 235 // COUT(5) << "Server: not sending gamestate" << std::endl; 236 // temp=temp->next(); 237 // if(!temp) 238 // break; 239 // continue; 240 // } 241 // COUT(4) << "client id: " << temp->getID() << " RTT: " << temp->getRTT() << " loss: " << temp->getPacketLoss() << std::endl; 242 // COUT(5) << "Server: doing gamestate gamestate preparation" << std::endl; 243 // int cid = temp->getID(); //get client id 244 // packet::Gamestate *gs = GamestateManager::popGameState(cid); 245 // if(gs==NULL){ 246 // COUT(2) << "Server: could not generate gamestate (NULL from compress)" << std::endl; 247 // temp = temp->next(); 248 // continue; 249 // } 250 // //std::cout << "adding gamestate" << std::endl; 251 // gs->setClientID(cid); 252 // if ( !gs->send() ){ 253 // COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp->getFailures() << std::endl; 254 // temp->addFailure(); 255 // }else 256 // temp->resetFailures(); 257 // added=true; 258 // temp=temp->next(); 259 // // gs gets automatically deleted by enet callback 260 // } 261 GamestateManager::sendGamestates(); 276 /** 277 * sends the current gamestate to all peers 278 */ 279 bool Server::sendGameStates() 280 { 281 std::vector<packet::Gamestate*> gamestates = GamestateManager::getGamestates(); 282 std::vector<packet::Gamestate*>::iterator it; 283 for( it = gamestates.begin(); it != gamestates.end(); ++it ) 284 { 285 (*it)->send(static_cast<Host*>(this)); 286 } 262 287 return true; 263 288 } 289 264 290 265 291 bool Server::sendObjectDeletes() … … 286 312 packet::DeleteObjects *cd = new packet::DeleteObjects(*del); 287 313 assert(cd); 288 cd->set ClientID(cid);289 if ( !cd->send( ) )290 COUT(3) << "Server: packet with client id (cid): " << cid << " not sended : " << temp->getFailures()<< std::endl;314 cd->setPeerID(cid); 315 if ( !cd->send( static_cast<Host*>(this) ) ) 316 COUT(3) << "Server: packet with client id (cid): " << cid << " not sended" << std::endl; 291 317 temp=temp->next(); 292 318 // gs gets automatically deleted by enet callback … … 312 338 // inform all the listeners 313 339 ClientConnectionListener::broadcastClientConnected(newid); 340 GamestateManager::addPeer(newid); 314 341 315 342 ++newid; … … 327 354 else 328 355 { 356 GamestateManager::removePeer(client->getID()); 329 357 //ServerConnection::disconnectClient( client ); 330 358 //ClientConnectionListener::broadcastClientDisconnected( client->getID() ); //this is done in ClientInformation now … … 332 360 } 333 361 } 362 363 void Server::processPacket(packet::Packet* packet) 364 { 365 if( packet->isReliable() ) 366 { 367 if( this->getLastProcessedGamestateID(packet->getPeerID()) >= packet->getRequiredGamestateID() ) 368 packet->process(static_cast<Host*>(this)); 369 else 370 this->packetQueue_.push_back(packet); 371 } 372 else 373 packet->process(static_cast<Host*>(this)); 374 } 375 334 376 335 377 bool Server::createClient(int clientID) … … 341 383 return false; 342 384 } 343 COUT( 5) << "Con.Man: creating client id: " << temp->getID() << std::endl;385 COUT(4) << "Con.Man: creating client id: " << temp->getID() << std::endl; 344 386 345 387 // synchronise class ids … … 348 390 // now synchronise functionIDs 349 391 packet::FunctionIDs *fIDs = new packet::FunctionIDs(); 350 fIDs->set ClientID(clientID);351 bool b = fIDs->send( );392 fIDs->setPeerID(clientID); 393 bool b = fIDs->send( static_cast<Host*>(this) ); 352 394 assert(b); 353 395 354 396 temp->setSynched(true); 397 GamestateManager::setSynched(clientID); 398 355 399 COUT(4) << "sending welcome" << std::endl; 356 400 packet::Welcome *w = new packet::Welcome(temp->getID(), temp->getShipID()); 357 w->set ClientID(temp->getID());358 b = w->send( );401 w->setPeerID(temp->getID()); 402 b = w->send( static_cast<Host*>(this) ); 359 403 assert(b); 360 404 packet::Gamestate *g = new packet::Gamestate(); 361 g->setClientID(temp->getID()); 362 b = g->collectData(0,0x1); 405 g->setPeerID(temp->getID()); 406 b = g->collectData(0,packet::GAMESTATE_MODE_SERVER); 407 assert(b); 363 408 if(!b) 364 409 return false; //no data for the client 365 b = g->compressData();366 assert(b);367 b = g->send( );410 // b = g->compressData(); 411 // assert(b); 412 b = g->send( static_cast<Host*>(this) ); 368 413 assert(b); 369 414 return true; … … 373 418 { 374 419 ServerConnection::disconnectClient( client ); 375 GamestateManager::remove Client(client);420 GamestateManager::removePeer(client->getID()); 376 421 // inform all the listeners 377 422 // ClientConnectionListener::broadcastClientDisconnected(client->getID()); // this is done in ClientInformation now … … 395 440 { 396 441 chat = new packet::Chat(message, clientID); 397 chat->set ClientID(temp->getID());398 if(!chat->send( ))442 chat->setPeerID(temp->getID()); 443 if(!chat->send( static_cast<Host*>(this) )) 399 444 COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl; 400 445 temp = temp->next(); … … 411 456 int failures=0; 412 457 packet::ClassID *classid = new packet::ClassID(); 413 classid->set ClientID(clientID);414 while(!classid->send( ) && failures < 10){458 classid->setPeerID(clientID); 459 while(!classid->send( static_cast<Host*>(this) ) && failures < 10){ 415 460 failures++; 416 461 }
Note: See TracChangeset
for help on using the changeset viewer.