- Timestamp:
- May 7, 2015, 2:22:43 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note: See TracChangeset
for help on using the changeset viewer.