Changeset 8858 for code/trunk/src/libraries/network/Server.cc
- Timestamp:
- Aug 23, 2011, 12:45:53 AM (13 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:ignore
-
old new 1 1 build 2 2 codeblocks 3 vs 3 4 dependencies
-
- Property svn:mergeinfo changed
/code/branches/output (added) merged: 8739-8740,8765,8771-8772,8774-8780,8787-8789,8794-8799,8801,8803-8812,8814,8816-8817,8820,8822,8825-8837,8840,8844,8846,8848-8850,8853-8854
- Property svn:ignore
-
code/trunk/src/libraries/network/Server.cc
r8706 r8858 47 47 48 48 #include "util/Clock.h" 49 #include "util/ Debug.h"49 #include "util/Output.h" 50 50 #include "core/ObjectList.h" 51 51 #include "core/command/Executor.h" … … 56 56 #include "packet/Gamestate.h" 57 57 #include "packet/Welcome.h" 58 #include "ChatListener.h"59 58 // #include "ClientInformation.h" 60 59 #include "FunctionCallManager.h" 61 60 #include "GamestateManager.h" 62 #include "WANDiscovery.h"63 61 64 62 namespace orxonox … … 100 98 } 101 99 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 110 100 /** 111 101 * This function opens the server by creating the listener thread … … 114 104 { 115 105 Host::setActive(true); 116 COUT(4) << "opening server" << endl;106 orxout(verbose, context::network) << "opening server" << endl; 117 107 this->openListener(); 118 108 119 109 /* make discoverable on LAN */ 120 110 LANDiscoverable::setActivity(true); … … 122 112 /* make discoverable on WAN */ 123 113 WANDiscoverable::setActivity(true); 124 /* TODO this needs to be optional, we need a switch from the UI to125 * enable/disable this126 */127 // helper_ConnectToMasterserver();128 114 129 115 /* done */ … … 137 123 { 138 124 Host::setActive(false); 139 COUT(4) << "closing server" << endl;125 orxout(verbose, context::network) << "closing server" << endl; 140 126 this->disconnectClients(); 141 127 this->closeListener(); 142 128 143 129 /* tell master server we're closing */ 144 COUT(2) << "disconnecting." << endl;145 WANDiscoverable::setActivity(false); 146 COUT(2) << "disconnecting done" << endl;130 orxout(internal_info, context::network) << "disconnecting." << endl; 131 WANDiscoverable::setActivity(false); 132 orxout(internal_info, context::network) << "disconnecting done" << endl; 147 133 148 134 LANDiscoverable::setActivity(false); 149 135 return; 150 }151 152 bool Server::processChat(const std::string& message, unsigned int playerID)153 {154 // ClientInformation *temp = ClientInformation::getBegin();155 packet::Chat *chat;156 // while(temp){157 chat = new packet::Chat(message, playerID);158 chat->setPeerID(NETWORK_PEER_ID_BROADCAST);159 chat->send( static_cast<Host*>(this) );160 // COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl;161 // temp = temp->next();162 // }163 // COUT(1) << "Player " << playerID << ": " << message << std::endl;164 return true;165 }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 pollForReply176 * reimplementation177 */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 something187 * has to be done or changed.188 */189 //WANDiscovery::getInstance().msc.pollForReply( rhandler, 10 );190 136 } 191 137 … … 202 148 // receive and process incoming discovery packets 203 149 LANDiscoverable::update(); 204 205 // receive and process requests from master server206 /* todo */207 //helper_HandleMasterServerRequests();208 150 209 151 if ( GamestateManager::hasPeers() ) … … 246 188 { 247 189 // for( ClientInformation* temp=ClientInformation::getBegin(); temp!=0; temp=temp->next() ) 248 // COUT(0) << "Round trip time to client with ID: " << temp->getID() << " is " << temp->getRTT() << " ms" << endl;190 // orxout(message) << "Round trip time to client with ID: " << temp->getID() << " is " << temp->getRTT() << " ms" << endl; 249 191 } 250 192 … … 268 210 return; 269 211 GamestateManager::update(); 270 // COUT(5) << "Server: one gamestate update complete, goig to sendGameState" << std::endl;271 // std::cout << "updated gamestate, sending it" << std::endl;212 // orxout(verbose_more, context::network) << "Server: one gamestate update complete, goig to sendGameState" << endl; 213 //orxout(verbose_more, context::network) << "updated gamestate, sending it" << endl; 272 214 //if(clients->getGamestateID()!=GAMESTATEID_INITIAL) 273 215 sendGameStates(); 274 216 sendObjectDeletes(); 275 // COUT(5) << "Server: one sendGameState turn complete, repeat in next tick" << std::endl;276 // std::cout << "sent gamestate" << std::endl;217 // orxout(verbose_more, context::network) << "Server: one sendGameState turn complete, repeat in next tick" << endl; 218 //orxout(verbose_more, context::network) << "sent gamestate" << endl; 277 219 } 278 220 … … 305 247 return true; //everything ok (no deletes this tick) 306 248 } 307 // COUT(3) << "sending DeleteObjects" << std::endl;249 // orxout(verbose, context::network) << "sending DeleteObjects" << endl; 308 250 // while(temp != NULL){ 309 251 // if( !(temp->getSynched()) ) 310 252 // { 311 // COUT(5) << "Server: not sending gamestate" << std::endl;253 // orxout(verbose_more, context::network) << "Server: not sending gamestate" << endl; 312 254 // temp=temp->next(); 313 255 // continue; … … 318 260 del->setPeerID(NETWORK_PEER_ID_BROADCAST); 319 261 if ( !del->send( static_cast<Host*>(this) ) ) 320 COUT(3) << "Server: could not broadcast deleteObjects packet" << std::endl;262 orxout(internal_warning, context::network) << "Server: could not broadcast deleteObjects packet" << endl; 321 263 // temp=temp->next(); 322 264 // gs gets automatically deleted by enet callback … … 330 272 { 331 273 // static unsigned int newid=1; 332 // 333 // COUT(2) << "Server: adding client" << std::endl;274 // 275 // orxout(internal_info, context::network) << "Server: adding client" << endl; 334 276 // ClientInformation *temp = ClientInformation::insertBack(new ClientInformation); 335 277 // if(!temp) 336 278 // { 337 // COUT(2) << "Server: could not add client" << std::endl;279 // orxout(internal_warning, context::network) << "Server: could not add client" << endl; 338 280 // } 339 281 // temp->setID(newid); … … 347 289 // ++newid; 348 290 349 COUT(3) << "Server: added client id: " << peerID << std::endl;291 orxout(internal_info, context::network) << "Server: added client id: " << peerID << endl; 350 292 createClient(peerID); 351 293 } … … 353 295 void Server::removePeer(uint32_t peerID) 354 296 { 355 COUT(4) << "removing client from list" << std::endl;297 orxout(verbose, context::network) << "removing client from list" << endl; 356 298 // ClientInformation *client = ClientInformation::findClient(&event->peer->address); 357 299 // if(!client) … … 375 317 // } 376 318 } 377 319 378 320 void Server::processPacket(packet::Packet* packet) 379 321 { … … 395 337 // if(!temp) 396 338 // { 397 // COUT(2) << "Server. could not create client with id: " << clientID << std::endl;339 // orxout(internal_error, context::network) << "Server. could not create client with id: " << clientID << endl; 398 340 // return false; 399 341 // } 400 // COUT(4) << "Con.Man: creating client id: " << temp->getID() << std::endl;342 // orxout(verbose, context::network) << "Con.Man: creating client id: " << temp->getID() << endl; 401 343 402 344 // synchronise class ids … … 411 353 // temp->setSynched(true); 412 354 GamestateManager::setSynched(clientID); 413 414 COUT(4) << "sending welcome" << std::endl;355 356 orxout(verbose, context::network) << "sending welcome" << endl; 415 357 packet::Welcome *w = new packet::Welcome(clientID); 416 358 w->setPeerID(clientID); … … 438 380 } 439 381 440 bool Server::chat(const std::string& message) 441 { 442 return this->sendChat(message, Host::getPlayerID()); 443 } 444 445 bool Server::broadcast(const std::string& message) 446 { 447 return this->sendChat(message, NETWORK_PEER_ID_BROADCAST); 448 } 449 450 bool Server::sendChat(const std::string& message, unsigned int clientID) 451 { 452 // ClientInformation *temp = ClientInformation::getBegin(); 453 packet::Chat *chat; 454 // while(temp) 455 { 456 chat = new packet::Chat(message, clientID); 457 chat->setPeerID(NETWORK_PEER_ID_BROADCAST); 458 chat->send( static_cast<Host*>(this) ); 459 // COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl; 460 // temp = temp->next(); 461 } 462 // COUT(1) << "Player " << Host::getPlayerID() << ": " << message << std::endl; 463 for (ObjectList<ChatListener>::iterator it = ObjectList<ChatListener>::begin(); it != ObjectList<ChatListener>::end(); ++it) 464 it->incomingChat(message, clientID); 465 466 return true; 382 /** 383 * @brief Sends a chat message to the given target ID. 384 * @param message message to be sent 385 * @param sourceID the ID of the sender 386 * @param targetID the ID of the receiver 387 */ 388 void Server::doSendChat(const std::string& message, unsigned int sourceID, unsigned int targetID) 389 { 390 // check if the target exists. just ignore the message otherwise 391 if (!this->isValidTarget(targetID)) // TODO: remove this if an invalid clientIDs don't trigger assertions anymore 392 return; 393 394 // send the message to the target 395 packet::Chat* packet = new packet::Chat(message, sourceID, targetID); 396 packet->setPeerID(targetID); 397 packet->send( static_cast<Host*>(this) ); 398 399 // if the target is (or includes) this host as well, call the parent function which passes the message to the listeners 400 if (targetID == NETWORK_PEER_ID_BROADCAST || targetID == Host::getPlayerID()) 401 Host::doReceiveChat(message, sourceID, targetID); 402 } 403 404 /** 405 * @brief Gets called if a packet::Chat packet is received. Forwards the packet to the target 406 * and calls the parent function if necessary. 407 */ 408 void Server::doReceiveChat(const std::string& message, unsigned int sourceID, unsigned int targetID) 409 { 410 this->doSendChat(message, sourceID, targetID); 411 } 412 413 /** 414 * @brief Returns true if the target ID is in the list of clients (or if it 415 * corresponds to the broadcast or the server ID). 416 */ 417 bool Server::isValidTarget(unsigned int targetID) 418 { 419 if (targetID == NETWORK_PEER_ID_BROADCAST || targetID == NETWORK_PEER_ID_SERVER) 420 return true; 421 422 std::vector<uint32_t>::iterator it; 423 for( it=this->clientIDs_.begin(); it!=this->clientIDs_.end(); ++it ) 424 if( *it == targetID ) 425 return true; 426 427 return false; 467 428 } 468 429 … … 476 437 } 477 438 assert(failures<10); 478 COUT(4) << "syncClassid:\tall synchClassID packets have been sent" << std::endl;439 orxout(verbose, context::network) << "syncClassid:\tall synchClassID packets have been sent" << endl; 479 440 } 480 441
Note: See TracChangeset
for help on using the changeset viewer.