Changeset 10427 for code/branches/multiplayerFS15/src/libraries/network
- Timestamp:
- May 7, 2015, 2:22:43 PM (10 years ago)
- Location:
- code/branches/multiplayerFS15/src/libraries/network
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/multiplayerFS15/src/libraries/network/GamestateManager.h
r8402 r10427 1 /*1 /* 2 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 3 * > www.orxonox.net < … … 78 78 std::map< uint32_t, packet::Gamestate* > gamestates; 79 79 }; 80 80 81 81 public: 82 82 83 83 GamestateManager(); 84 84 ~GamestateManager(); … … 88 88 virtual uint32_t getLastReceivedGamestateID( unsigned int peerID ); 89 89 virtual uint32_t getCurrentGamestateID(){ if( currentGamestate_) return currentGamestate_->getID(); else return GAMESTATEID_INITIAL; } 90 90 91 91 bool processGamestates(); 92 92 bool sendAck(unsigned int gamestateID, uint32_t peerID); -
code/branches/multiplayerFS15/src/libraries/network/LANDiscoverable.cc
r8858 r10427 35 35 #include "util/Output.h" 36 36 #include "packet/ServerInformation.h" 37 #include "core/config/ConfigValueIncludes.h" 38 #include "core/CoreIncludes.h" 39 37 40 38 41 namespace orxonox … … 43 46 LANDiscoverable::LANDiscoverable() 44 47 { 48 /* register object in orxonox */ 49 RegisterObject(LANDiscoverable); 50 51 this->setConfigValues(); 52 // this->setActivity(true); 45 53 this->host_ = 0; 46 54 this->bActive_ = false; 47 // this->setActivity(true); 55 } 56 57 void LANDiscoverable::setConfigValues() 58 { 59 /* update msaddress string from orxonox.ini config file, if it 60 * has changed. 61 */ 62 SetConfigValueExternal(ownName, "WANDiscovery", "ownName", "tme213"); 48 63 } 49 64 … … 61 76 if( bActive == this->bActive_ ) // no change 62 77 return; 63 78 64 79 if( bActive ) 65 80 { … … 84 99 { 85 100 ENetEvent event; 86 101 87 102 if( this->bActive_==false ) 88 103 return; 89 104 assert(this->host_); 90 105 91 106 while( enet_host_service( this->host_, &event, 0 ) > 0 ) 92 107 { … … 104 119 orxout(internal_info, context::network) << "Received LAN discovery message from client " << event.peer->host->receivedAddress << endl; 105 120 packet::ServerInformation info; 106 info.setServerName( "Orxonox Server");121 info.setServerName(this->ownName); 107 122 info.send(event.peer); 108 123 // ENetPacket* packet = enet_packet_create( LAN_DISCOVERY_ACK, strlen(LAN_DISCOVERY_ACK)+1, ENET_PACKET_FLAG_RELIABLE ); -
code/branches/multiplayerFS15/src/libraries/network/LANDiscoverable.h
r8351 r10427 31 31 32 32 #include "NetworkPrereqs.h" 33 #include "core/config/Configurable.h" 33 34 34 35 namespace orxonox 35 36 { 36 37 37 class LANDiscoverable 38 class LANDiscoverable: public Configurable 38 39 { 39 40 public: … … 42 43 void setActivity( bool bActive ); 43 44 void update(); 45 /** Function used for the configuration file parameter update */ 46 void setConfigValues(); 44 47 45 48 private: 46 49 bool bActive_; 47 50 ENetHost* host_; 51 std::string ownName; 48 52 }; 49 53 -
code/branches/multiplayerFS15/src/libraries/network/MasterServer.cc
r8952 r10427 34 34 #include "util/Output.h" 35 35 36 namespace orxonox 36 namespace orxonox 37 37 { 38 38 /*** MACROS ***/ … … 49 49 50 50 /* command: list servers */ 51 void 51 void 52 52 MasterServer::listServers( void ) 53 53 { … … 59 59 60 60 /* loop through list elements */ 61 for( i = MasterServer::getInstance()->mainlist.serverlist.begin(); 62 i != MasterServer::getInstance()->mainlist.serverlist.end(); ++i ) 61 for( i = MasterServer::getInstance()->mainlist.serverlist.begin(); 62 i != MasterServer::getInstance()->mainlist.serverlist.end(); ++i ) 63 63 { 64 64 orxout(user_info) << " " << (*i).ServerInfo.getServerIP() << std::endl; … … 70 70 } 71 71 72 void 72 void 73 73 MasterServer::delServer( std::string todeladdr ) 74 74 { 75 75 /* tell the user we're now removing the entry from the server list */ 76 orxout(user_info) << "MS: Deleting server \"" << todeladdr << "\"..." 76 orxout(user_info) << "MS: Deleting server \"" << todeladdr << "\"..." 77 77 << std::endl; 78 78 79 79 /* see if we actually have that server on our list */ 80 ServerListSearchResult shandle = 80 ServerListSearchResult shandle = 81 81 MasterServer::getInstance()->mainlist.findServerByAddress(todeladdr); 82 82 … … 86 86 } 87 87 88 /* force-disconnect the server */ 88 /* force-disconnect the server */ 89 89 enet_peer_disconnect( shandle.result.peer, 0 ); 90 90 … … 98 98 99 99 /* helpers */ 100 static void 100 static void 101 101 helper_output_debug( ENetEvent *event, char *addrconv ) 102 102 { 103 103 orxout(verbose, context::master_server) 104 << "A packet of length" 104 << "A packet of length" 105 105 << event->packet->dataLength 106 106 << " containing " 107 107 << (const char*)event->packet->data 108 108 << " was received from " 109 << addrconv 109 << addrconv 110 110 << " on channel " 111 111 << event->channelID << endl; … … 122 122 123 123 /* loop through list elements */ 124 for( i = mainlist.serverlist.begin(); i 125 != mainlist.serverlist.end(); ++i ) 124 for( i = mainlist.serverlist.begin(); i 125 != mainlist.serverlist.end(); ++i ) 126 126 { 127 127 /* send this particular server */ 128 128 /* build reply string */ 129 char *tosend = (char *)calloc( (*i).ServerInfo.getServerIP().length()130 + MSPROTO_SERVERLIST_ITEM_LEN + 2,1 );131 if( !tosend ) 129 int packetlen = MSPROTO_SERVERLIST_ITEM_LEN + 1 + (*i).ServerInfo.getServerIP().length() + 1 + (*i).ServerInfo.getServerName().length() + 1; 130 char *tosend = (char *)calloc(packetlen ,1 ); 131 if( !tosend ) 132 132 { orxout(internal_warning, context::master_server) << "Masterserver.cc: Memory allocation failed." << endl; 133 133 continue; 134 } 135 sprintf( tosend, "%s %s ", MSPROTO_SERVERLIST_ITEM,136 (*i).ServerInfo.getServerIP().c_str() 134 } 135 sprintf( tosend, "%s %s %s", MSPROTO_SERVERLIST_ITEM, 136 (*i).ServerInfo.getServerIP().c_str(), (*i).ServerInfo.getServerName().c_str()); 137 137 138 138 /* create packet from it */ 139 139 reply = enet_packet_create( tosend, 140 strlen( tosend ) + 1, 140 strlen( tosend ) + 1, 141 141 ENET_PACKET_FLAG_RELIABLE); 142 142 … … 149 149 /* free the tosend buffer */ 150 150 free( tosend ); 151 } 151 } 152 152 153 153 /* create end-of-list packet */ … … 163 163 } 164 164 165 /* maybe the two methods below can be merged into one and 166 * made to use ENet's RTT functionality to check for disconnected 165 /* maybe the two methods below can be merged into one and 166 * made to use ENet's RTT functionality to check for disconnected 167 167 * servers. 168 168 */ 169 void 169 void 170 170 MasterServer::helper_cleanupServers( void ) 171 171 { 172 172 /* get an iterator */ 173 173 std::list<ServerListElem>::iterator i; 174 174 175 175 if( mainlist.serverlist.size() == 0 ) 176 176 return; 177 177 178 178 /* loop through list elements */ 179 for( i = mainlist.serverlist.begin(); i 180 != mainlist.serverlist.end(); ++i ) 179 for( i = mainlist.serverlist.begin(); i 180 != mainlist.serverlist.end(); ++i ) 181 181 { /* see if we have a disconnected peer */ 182 if( (*i).peer && 182 if( (*i).peer && 183 183 ((*i).peer->state == ENET_PEER_STATE_DISCONNECTED || 184 184 (*i).peer->state == ENET_PEER_STATE_ZOMBIE )) 185 { 185 { 186 186 /* Remove it from the list */ 187 187 orxout(internal_warning) << (char*)(*i).peer->data << " timed out.\n"; … … 190 190 /* stop iterating, we manipulated the list */ 191 191 /* TODO note: this only removes one dead server per loop 192 * iteration. not beautiful, but one iteration is ~100ms, 192 * iteration. not beautiful, but one iteration is ~100ms, 193 193 * so not really relevant for the moment. 194 194 */ … … 196 196 } 197 197 } 198 198 199 199 } 200 200 … … 204 204 /***** EVENTS *****/ 205 205 /* connect event */ 206 int 206 int 207 207 MasterServer::eventConnect( ENetEvent *event ) 208 208 { /* check for bad parameters */ … … 217 217 218 218 /* output debug info */ 219 orxout(verbose, context::master_server) << "A new client connected from " 220 << addrconv 221 << " on port " 219 orxout(verbose, context::master_server) << "A new client connected from " 220 << addrconv 221 << " on port " 222 222 << event->peer->address.port << endl; 223 223 224 224 /* store string form of address here */ 225 event->peer->data = addrconv; 225 event->peer->data = addrconv; 226 226 227 227 /* all fine. */ … … 230 230 231 231 /* disconnect event */ 232 int 232 int 233 233 MasterServer::eventDisconnect( ENetEvent *event ) 234 234 { /* check for bad parameters */ … … 255 255 256 256 /* data event */ 257 int 257 int 258 258 MasterServer::eventData( ENetEvent *event ) 259 259 { /* validate packet */ … … 262 262 return -1; 263 263 } 264 264 265 265 /* generate address in readable form */ 266 266 char *addrconv = (char *) calloc( 50, 1 ); … … 271 271 272 272 /* GAME SERVER OR CLIENT CONNECTION? */ 273 if( !strncmp( (char *)event->packet->data, MSPROTO_GAME_SERVER, 273 if( !strncmp( (char *)event->packet->data, MSPROTO_GAME_SERVER, 274 274 MSPROTO_GAME_SERVER_LEN ) ) 275 275 { /* Game server */ 276 276 277 if( !strncmp( (char *)event->packet->data 278 + MSPROTO_GAME_SERVER_LEN+1, 277 if( !strncmp( (char *)event->packet->data 278 + MSPROTO_GAME_SERVER_LEN+1, 279 279 MSPROTO_REGISTER_SERVER, MSPROTO_REGISTER_SERVER_LEN ) ) 280 280 { /* register new server */ 281 281 mainlist.addServer( packet::ServerInformation( event ), 282 282 event->peer ); 283 283 284 284 /* tell people we did so */ 285 orxout(internal_info, context::master_server) << "Added new server to list: " << 285 orxout(internal_info, context::master_server) << "Added new server to list: " << 286 286 packet::ServerInformation( event ).getServerIP() << endl; 287 287 } … … 292 292 { 293 293 /* create string from peer data */ 294 std::string name= std::string( addrconv );294 std::string ip = std::string( addrconv ); 295 295 296 296 /* remove the server from the list it belongs to */ 297 this->mainlist.delServerByAddress( name);297 this->mainlist.delServerByAddress( ip ); 298 298 299 299 /* tell the user */ 300 orxout(internal_info, context::master_server) << "Removed server " << name<< " from list." << endl;300 orxout(internal_info, context::master_server) << "Removed server " << ip << " from list." << endl; 301 301 } 302 302 303 else if( !strncmp( (char *)event->packet->data 304 + MSPROTO_GAME_SERVER_LEN+1, 305 MSPROTO_SET_NAME, MSPROTO_SET_NAME_LEN ) ) 306 { 307 /* create string from peer data */ 308 std::string ip = std::string( addrconv ); 309 std::string data (event->packet->data,event->packet->data + event->packet->dataLength ); 310 std::string name = data.substr(MSPROTO_GAME_SERVER_LEN+1 + MSPROTO_SET_NAME_LEN + 1); 311 312 /* remove the server from the list it belongs to */ 313 this->mainlist.setNameByAddress( ip, name ); 314 315 /* tell the user */ 316 orxout(internal_info, context::master_server) << "Updated server " << ip << " with new name " << name << endl; 317 } 318 303 319 /* TODO add hook for disconnect here */ 304 320 } 305 else if( !strncmp( (char *)event->packet->data, MSPROTO_CLIENT, 321 else if( !strncmp( (char *)event->packet->data, MSPROTO_CLIENT, 306 322 MSPROTO_CLIENT_LEN) ) 307 323 { /* client */ … … 312 328 } 313 329 else 314 { /* bad message, don't do anything. */ } 330 { /* bad message, don't do anything. */ } 315 331 316 332 /* delete addrconv */ … … 324 340 325 341 /**** MAIN ROUTINE *****/ 326 int 342 int 327 343 MasterServer::run() 328 344 { … … 330 346 ENetEvent *event = (ENetEvent *)calloc(sizeof(ENetEvent), sizeof(char)); 331 347 if( event == NULL ) 332 { 348 { 333 349 orxout(user_error, context::master_server) << "Could not create ENetEvent structure, exiting." << endl; 334 350 exit( EXIT_FAILURE ); … … 345 361 switch (event->type) 346 362 { /* new connection */ 347 case ENET_EVENT_TYPE_CONNECT: 363 case ENET_EVENT_TYPE_CONNECT: 348 364 eventConnect( event ); break; 349 365 350 366 /* disconnect */ 351 case ENET_EVENT_TYPE_DISCONNECT: 367 case ENET_EVENT_TYPE_DISCONNECT: 352 368 eventDisconnect( event ); break; 353 369 … … 358 374 359 375 /* done */ 376 free(event); 360 377 return 0; 361 } 378 } 362 379 363 380 /* constructor */ … … 380 397 this->address.port = ORX_MSERVER_PORT; 381 398 382 /* create a host with the above settings (the last two 0 mean: accept 399 /* create a host with the above settings (the last two 0 mean: accept 383 400 * any input/output bandwidth */ 384 this->server = enet_host_create( &this->address, ORX_MSERVER_MAXCONNS, 401 this->server = enet_host_create( &this->address, ORX_MSERVER_MAXCONNS, 385 402 ORX_MSERVER_MAXCHANS, 0, 0 ); 386 403 assert(this->server); … … 388 405 /* see if creation worked */ 389 406 if( !this->server ) 390 { orxout(user_error, context::master_server) << 407 { orxout(user_error, context::master_server) << 391 408 "An error occurred while trying to create an ENet server host." << endl; 392 409 exit( EXIT_FAILURE ); -
code/branches/multiplayerFS15/src/libraries/network/MasterServerProtocol.h
r8351 r10427 37 37 /* Client token (shows that the party sending data is a client */ 38 38 #define MSPROTO_CLIENT "CL" 39 #define MSPROTO_CLIENT_LEN 2 39 #define MSPROTO_CLIENT_LEN 2 40 40 41 41 /* Request: Serverlist (requiest made from client to master server */ … … 67 67 /* ping request from server */ 68 68 #define MSPROTO_PING_GAMESERVER "PING" 69 #define MSPROTO_PING_GAMESERVER_LEN 4 69 #define MSPROTO_PING_GAMESERVER_LEN 4 70 70 71 71 /* server disconnect */ … … 75 75 /* ping reply */ 76 76 #define MSPROTO_ACK "ACK" 77 #define MSPROTO_ACK_LEN 3 77 #define MSPROTO_ACK_LEN 3 78 78 79 #define MSPROTO_SET_NAME "NAM" 80 #define MSPROTO_SET_NAME_LEN 3 79 81 82 #define MSPROTO_SET_CLIENTS "CLI" 83 #define MSPROTO_SET_CLIENTS_LEN 3 84 85 #define SERVER_NAME_MAXLEN 7 80 86 81 87 /* default master server port */ -
code/branches/multiplayerFS15/src/libraries/network/PeerList.cc
r8858 r10427 38 38 PeerList::~PeerList() { } 39 39 40 int 40 int 41 41 PeerList::addPeer( ENetPeer *toadd ) 42 42 { /* error correction */ 43 if( toadd == NULL ) 43 if( toadd == NULL ) 44 44 { orxout(internal_error, context::master_server) << "PeerList::addPeer: empty peer given." << endl; 45 45 return -1; … … 52 52 53 53 bool sub_compAddr( ENetAddress addr1, ENetAddress addr2 ) 54 { 54 { 55 55 for( int i = 0; i < 16; ++i ) 56 56 if( addr1.host.addr[i] < addr2.host.addr[i] ) … … 61 61 return 0; 62 62 } 63 63 64 64 65 65 bool … … 69 69 70 70 /* loop through list elements */ 71 for( i = peerlist.begin(); i != peerlist.end(); ++i ) 71 for( i = peerlist.begin(); i != peerlist.end(); ++i ) 72 72 if( !sub_compAddr((*i)->address, addr ) ) 73 73 { /* found this name, remove and quit */ … … 86 86 87 87 /* loop through list elements */ 88 for( i = peerlist.begin(); i != peerlist.end(); ++i ) 88 for( i = peerlist.begin(); i != peerlist.end(); ++i ) 89 89 if( !sub_compAddr((*i)->address, addr ) ) 90 90 /* found this name, remove and quit */ … … 95 95 } 96 96 97 int 98 PeerList::count(){ 99 return this->peerlist.size(); 100 } 101 97 102 } 98 -
code/branches/multiplayerFS15/src/libraries/network/PeerList.h
r8351 r10427 35 35 36 36 /* peer list */ 37 namespace orxonox 37 namespace orxonox 38 38 { 39 /** This class keeps a list of open connections 39 /** This class keeps a list of open connections 40 40 * and some info about them. 41 41 */ 42 class PeerList 42 class PeerList 43 43 { public: 44 44 /** constructor */ … … 50 50 /** \param toadd The peer to add 51 51 * \return 0 for success, -1 for error. 52 * 53 * Add new peer to list 52 * 53 * Add new peer to list 54 54 */ 55 55 int addPeer( ENetPeer *toadd ); … … 57 57 /** \param addr Address to look for 58 58 * \return if the peer was found or not 59 * 60 * Remove peer from list by address 59 * 60 * Remove peer from list by address 61 61 */ 62 62 bool remPeerByAddr( ENetAddress addr ); 63 63 64 64 /** \param addr The address to find by 65 * 66 * Find a connection by address */ 65 * 66 * Find a connection by address 67 */ 67 68 ENetPeer *findPeerByAddr( ENetAddress addr ); 68 69 69 /* NOTE: making this list public so it can easily 70 /** 71 * Count current peers 72 */ 73 int count(); 74 75 /* NOTE: making this list public so it can easily 70 76 * be iterated. This makes sense since iterating it 71 77 * will happen all the time, and using getter methods -
code/branches/multiplayerFS15/src/libraries/network/Server.cc
r9667 r10427 77 77 this->timeSinceLastUpdate_=0; 78 78 } 79 79 /* 80 Server::Server(int port, const std::string name) 81 { 82 this->setPort( port ); 83 this->timeSinceLastUpdate_=0; 84 this->serverName_=name; 85 }*/ 80 86 /** 81 87 * Constructor -
code/branches/multiplayerFS15/src/libraries/network/Server.h
r8858 r10427 67 67 virtual void printRTT(); 68 68 float getPacketLoss(unsigned int clientID); 69 int getClientCount() { return this->clientIDs_.size();} 70 std::string getServerName() { return this->serverName_;} 71 69 72 protected: 70 73 void updateGamestate(); … … 89 92 std::deque<packet::Packet*> packetQueue_; 90 93 std::vector<uint32_t> clientIDs_; 94 std::string serverName_; 91 95 }; 92 96 -
code/branches/multiplayerFS15/src/libraries/network/ServerList.cc
r10334 r10427 145 145 } 146 146 147 bool ServerList::setNameByAddress( std::string address, std::string name ){ 148 /* get an iterator */ 149 std::list<ServerListElem>::iterator i; 150 151 /* loop through list elements */ 152 for( i = serverlist.begin(); i != serverlist.end(); ++i ) 153 if( (*i).ServerInfo.getServerIP() == address ) 154 { /* found this adress, rename and quit */ 155 (*i).ServerInfo.setServerName( name ); 156 return true; 157 } 158 return false; 159 }; 160 147 161 } -
code/branches/multiplayerFS15/src/libraries/network/ServerList.h
r8937 r10427 35 35 36 36 /* methods necessary */ 37 namespace orxonox 38 { 37 namespace orxonox 38 { 39 39 /* HELPER STRUCTURES */ 40 struct ServerListElem 40 struct ServerListElem 41 41 { 42 42 /* server information (name, IP, etc) */ … … 63 63 * and some info about them. 64 64 */ 65 class ServerList 65 class ServerList 66 66 { public: 67 67 /** constructor */ … … 74 74 /* BASIC MANIPULATION */ 75 75 /** \param toadd the server to add. 76 * 76 * 77 77 * Add server to the game server list 78 78 */ … … 81 81 82 82 /** \param name Name of the server to remove 83 * 84 * Remove server by name 83 * 84 * Remove server by name 85 85 */ 86 86 bool delServerByName( std::string name ); 87 87 88 88 /** \param address IP address of the server to remove 89 * 89 * 90 90 * Remove server by address 91 91 */ 92 92 bool delServerByAddress( std::string address ); 93 93 94 95 94 bool setNameByAddress( std::string address, std::string name ); 96 95 97 96 /* SEARCHING */ 98 /* \param address The address of the server that is to be 97 /* \param address The address of the server that is to be 99 98 * found 100 99 * \return A struct containing a result of the search and a boolean 101 100 * that is only true if the search was successful 102 * 101 * 103 102 * Find and return the list handle of a given address. 104 103 */ … … 107 106 108 107 109 /* \param name The name of the server that is to be 108 /* \param name The name of the server that is to be 110 109 * found 111 110 * \return The struct containing the list entry of the server 112 * 111 * 113 112 * Find and return the list handle of a given name. 114 113 */ … … 120 119 /** sort by name */ 121 120 void sortByName(); 122 121 123 122 /** sort by ping */ 124 123 void sortByPing(); -
code/branches/multiplayerFS15/src/libraries/network/WANDiscoverable.cc
r9667 r10427 44 44 /* debugging output */ 45 45 orxout(verbose, context::master_server) << "Creating WANDiscoverable." << endl; 46 46 47 47 /* register object in orxonox */ 48 48 RegisterObject(WANDiscoverable); … … 50 50 /* check for the masterserver address option in orxonox.ini */ 51 51 this->setConfigValues(); 52 52 53 53 } 54 54 55 55 void WANDiscoverable::setConfigValues() 56 56 { 57 /* update msaddress string from orxonox.ini config file, if it 58 * has changed. 57 /* update msaddress string from orxonox.ini config file, if it 58 * has changed. 59 59 */ 60 60 SetConfigValueExternal(msaddress, "WANDiscovery", "msaddress", "orxonox.net"); 61 SetConfigValueExternal(ownName, "WANDiscovery", "ownName", "tme213"); 61 62 // SetConfigValue( msaddress, "orxonox.net"); 62 } 63 } 63 64 64 65 WANDiscoverable::~WANDiscoverable() … … 67 68 this->disconnect(); 68 69 } 69 70 70 71 void WANDiscoverable::setActivity(bool bActive) 71 72 { 72 73 if( bActive==this->bActive_ ) 73 74 return; 74 75 75 76 if( bActive ) 76 77 { … … 84 85 } 85 86 } 86 87 87 88 bool WANDiscoverable::connect() 88 89 { … … 93 94 return false; 94 95 } 95 96 96 97 /* connect and see if it worked */ 97 98 if( msc.connect( this->msaddress.c_str(), ORX_MSERVER_PORT ) ) 98 99 { 99 orxout(internal_error, context::master_server) << "Could not connect to master server at " 100 orxout(internal_error, context::master_server) << "Could not connect to master server at " 100 101 << this->msaddress << endl; 101 102 return false; 102 103 } 103 104 104 105 /* debugging output */ 105 106 orxout(verbose, context::master_server) << "Initialization of WANDiscoverable complete." << endl; 106 107 107 108 std::string request = MSPROTO_GAME_SERVER " " MSPROTO_SET_NAME " "; 109 request += this->ownName; 110 108 111 // Now register the server at the master server 109 112 this->msc.sendRequest( MSPROTO_GAME_SERVER " " MSPROTO_REGISTER_SERVER ); 110 113 this->msc.sendRequest( request ); 114 115 111 116 return true; 112 117 } … … 120 125 121 126 122 127 123 128 } // namespace orxonox -
code/branches/multiplayerFS15/src/libraries/network/WANDiscoverable.h
r9667 r10427 46 46 47 47 /** \return Address of the master server 48 * 49 * Get the master server address 48 * 49 * Get the master server address 50 50 */ 51 51 std::string getMSAddress() … … 54 54 /** Function used for the configuration file parameter update */ 55 55 void setConfigValues(); 56 56 57 57 /** Function used to set the activity/discoverability */ 58 58 void setActivity( bool bActive ); … … 60 60 /** Master server communications object */ 61 61 MasterServerComm msc; 62 62 63 63 private: 64 64 /** Function used to connect to the master server */ 65 65 bool connect(); 66 66 67 67 /** Function used to disconnect from the master server */ 68 68 void disconnect(); 69 69 70 70 /** master server address */ 71 71 std::string msaddress; 72 std::string ownName; 72 73 bool bActive_; 73 74 -
code/branches/multiplayerFS15/src/libraries/network/WANDiscovery.cc
r8858 r10427 41 41 /* debugging output */ 42 42 orxout(verbose, context::master_server) << "Creating WANDiscovery." << endl; 43 43 44 44 /* register object in orxonox */ 45 45 RegisterObject(WANDiscovery); … … 54 54 /* connect and see if it worked */ 55 55 if( msc.connect( this->msaddress.c_str(), ORX_MSERVER_PORT ) ) 56 orxout(internal_error, context::master_server) << "Could not connect to master server at " 56 orxout(internal_error, context::master_server) << "Could not connect to master server at " 57 57 << this->msaddress << endl; 58 58 … … 63 63 void WANDiscovery::setConfigValues() 64 64 { 65 /* update msaddress string from orxonox.ini config file, if it 66 * has changed. 65 /* update msaddress string from orxonox.ini config file, if it 66 * has changed. 67 67 */ 68 68 SetConfigValue( msaddress, "master.orxonox.net"); 69 } 69 } 70 70 71 71 WANDiscovery::~WANDiscovery() 72 { 72 { 73 73 /* clear server list */ 74 this->servers_.clear(); 74 this->servers_.clear(); 75 75 } 76 76 77 77 /* callback for the network reply poller */ 78 78 int WANDiscovery::rhandler( char *addr, ENetEvent *ev ) 79 { 79 { 80 80 /* error recognition */ 81 81 if( !ev || !ev->packet || !ev->packet->data ) … … 88 88 if( !strncmp( (char*)ev->packet->data, MSPROTO_SERVERLIST_ITEM, 89 89 MSPROTO_SERVERLIST_ITEM_LEN ) ) 90 { 90 { 91 91 /* create server structure from that item */ 92 92 packet::ServerInformation toadd; 93 93 94 94 /* fill in data, -1 for the index: index should be length -1 */ 95 toadd.setServerName( std::string((char*)ev->packet->data +96 MSPROTO_SERVERLIST_ITEM_LEN+1));97 toadd.setServerIP( std::string((char*)ev->packet->data +98 MSPROTO_SERVERLIST_ITEM_LEN+1));95 std::string datastr = std::string((char*)ev->packet->data + MSPROTO_SERVERLIST_ITEM_LEN+1); 96 int separator = datastr.find(" "); 97 toadd.setServerIP(datastr.substr(0,separator)); 98 toadd.setServerName(datastr.substr(separator+1)); 99 99 100 100 /* add to list */ … … 103 103 else if( !strncmp( (char*)ev->packet->data, MSPROTO_SERVERLIST_END, 104 104 MSPROTO_SERVERLIST_END_LEN ) ) 105 { 105 { 106 106 /* this is the only case where 2 should be returned, 107 107 * as 1 is used to signal that we're done receiving 108 108 * the list 109 109 */ 110 return 2; 110 return 2; 111 111 } 112 112 … … 114 114 return 1; 115 115 } 116 116 117 117 void WANDiscovery::discover() 118 118 { … … 131 131 { case 0: /* no event occured, decrease timeout */ 132 132 --i; break; 133 case 1: /* got a list element, continue */ 133 case 1: /* got a list element, continue */ 134 134 break; 135 135 case 2: /* done. */ … … 159 159 } 160 160 161 std::string WANDiscovery::getServerListItemRTT(unsigned int index) 162 { 163 if( index >= this->servers_.size() ) 164 return BLANKSTRING; 165 else{ 166 uint32_t serverrtt = this->servers_[index].getServerRTT(); 167 return Ogre::StringConverter::toString(serverrtt); 168 } 169 170 } 161 171 162 172 } // namespace orxonox -
code/branches/multiplayerFS15/src/libraries/network/WANDiscovery.h
r9667 r10427 35 35 #include "MasterServerComm.h" 36 36 #include "MasterServerProtocol.h" 37 #include <OgreStringConverter.h> 37 38 38 39 #include <vector> … … 56 57 57 58 /** \return Address of the master server 58 * 59 * Get the master server address 59 * 60 * Get the master server address 60 61 */ 61 62 std::string getMSAddress() … … 65 66 void discover(); // tolua_export 66 67 67 /** \param index Index to get the name of 68 /** \param index Index to get the name of 68 69 * \return The name of the server 69 * 70 * Get the name of the server at index index. 70 * 71 * Get the name of the server at index index. 71 72 */ 72 73 std::string getServerListItemName( unsigned int index ); // tolua_export 73 74 74 /** \param index Index to get the IP of 75 /** \param index Index to get the IP of 75 76 * \return The IP of the server 76 * 77 * Get the IP of the server at index index. 77 * 78 * Get the IP of the server at index index. 78 79 */ 79 80 std::string getServerListItemIP( unsigned int index ); // tolua_export 80 81 82 /** \param index Index to get the RTT of 83 * \return The RTT of the server 84 * 85 * Get the RTT of the server at index index. 86 */ 87 std::string getServerListItemRTT( unsigned int index ); // tolua_export 88 81 89 /* todo: might make this private and use getter/setter methods 82 * at some later time. 90 * at some later time. 83 91 */ 84 92 /** game server list */ … … 92 100 93 101 int rhandler( char *addr, ENetEvent *ev ); 94 102 95 103 private: 96 104 /** master server address */ -
code/branches/multiplayerFS15/src/libraries/network/packet/ServerInformation.h
r10334 r10427 47 47 48 48 void send( ENetPeer* peer ); 49 void setServerName(std::string name) { this->serverName_ = name; } 50 std::string getServerName() { return this->serverName_; } 51 void setServerIP( std::string IP ) { this->serverIP_ = IP; } 49 52 std::string getServerIP() { return this->serverIP_; } 50 std::string getServerName() { return this->serverName_; }51 void setServerName(std::string name) { this->serverName_ = name; }52 void setServerIP( std::string IP ) { this->serverIP_ = IP; }53 53 uint32_t getServerRTT() { return this->serverRTT_; } 54 54
Note: See TracChangeset
for help on using the changeset viewer.