- Timestamp:
- Oct 4, 2015, 12:13:42 PM (9 years ago)
- Location:
- code/branches/presentationFS15merge
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentationFS15merge
- Property svn:mergeinfo changed
/code/branches/multiplayerFS15 (added) merged: 10324,10334,10427,10434,10446-10447,10456-10457
- Property svn:mergeinfo changed
-
code/branches/presentationFS15merge/src/libraries/network/WANDiscovery.cc
r8858 r10612 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 int secondsep = datastr.find(" ", separator + 1); 99 toadd.setServerName(datastr.substr(separator + 1, secondsep - separator - 1)); 100 toadd.setClientNumber(Ogre::StringConverter::parseInt(datastr.substr(secondsep+1))); 101 102 orxout(internal_info, context::network) << "Received WAN discovery server information; Name: " << toadd.getServerName() << ", Address: " << toadd.getServerIP() << ", Players: " << toadd.getClientNumber() << ", RTT: " << toadd.getServerRTT() << endl; 99 103 100 104 /* add to list */ … … 103 107 else if( !strncmp( (char*)ev->packet->data, MSPROTO_SERVERLIST_END, 104 108 MSPROTO_SERVERLIST_END_LEN ) ) 105 { 109 { 106 110 /* this is the only case where 2 should be returned, 107 111 * as 1 is used to signal that we're done receiving 108 112 * the list 109 113 */ 110 return 2; 114 return 2; 111 115 } 112 116 … … 114 118 return 1; 115 119 } 116 120 117 121 void WANDiscovery::discover() 118 122 { … … 131 135 { case 0: /* no event occured, decrease timeout */ 132 136 --i; break; 133 case 1: /* got a list element, continue */ 137 case 1: /* got a list element, continue */ 134 138 break; 135 139 case 2: /* done. */ … … 159 163 } 160 164 165 std::string WANDiscovery::getServerListItemRTT(unsigned int index) 166 { 167 if( index >= this->servers_.size() ) 168 return BLANKSTRING; 169 else{ 170 uint32_t serverrtt = this->servers_[index].getServerRTT(); 171 return Ogre::StringConverter::toString(serverrtt); 172 } 173 174 } 175 std::string WANDiscovery::getServerListItemPlayerNumber(unsigned int index) 176 { 177 if( index >= this->servers_.size() ) 178 return BLANKSTRING; 179 else{ 180 int playerNumber = this->servers_[index].getClientNumber(); 181 return Ogre::StringConverter::toString(playerNumber); 182 } 183 } 161 184 162 185 } // namespace orxonox
Note: See TracChangeset
for help on using the changeset viewer.