- Timestamp:
- Nov 10, 2010, 3:35:39 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/masterserver/src/libraries/network/WANDiscovery.cc
r7630 r7631 21 21 * 22 22 * Author: 23 * Fabian 'x3n' Landau 23 * Fabian 'x3n' Landau (original) 24 24 * Co-authors: 25 * Sandro 'smerkli' Merkli (adaptions to WAN) 25 26 * ... 26 27 * … … 42 43 WANDiscovery::WANDiscovery() 43 44 { 45 /* create master server communications object */ 46 this->msc = MasterServerComm(); 47 48 /* initialize it and see if it worked */ 49 if( msc.initialize() ) 50 COUT(1) << "Error: could not initialize master server communications!\n"; 51 52 /* connect and see if it worked */ 53 if( msc.connect( MS_ADDRESS, 1234 ) ) 54 COUT(1) << "Error: could not connect to master server!\n"; 44 55 } 45 56 46 57 WANDiscovery::~WANDiscovery() 47 { 58 { 59 /* clear server list */ 60 this->servers_.clear(); 48 61 } 49 62 63 /* callback for the network reply poller */ 64 /* NOTE implement protocol-specific part here. */ 65 int replyhandler( char *addr, ENetEvent *ev ) 66 { 67 /* handle incoming data 68 * if a list entry arrives add to list 69 * if a done entry arrives set done to true 70 */ 71 72 /* done handling, return all ok code 0 */ 73 return 0; 74 } 75 50 76 void WANDiscovery::discover() 51 77 { 78 /* clear list */ 52 79 this->servers_.clear(); 80 81 /* send request to server */ 82 msc.sendRequest( MSPROTO_CLIENT MSPROTO_REQ_LIST ); 83 84 /* deal with replies */ 85 while( msc.pollForReply( replyhandler ) ) 86 /* nothing */; 87 88 /* done receiving. */ 53 89 } 54 90 55 91 std::string WANDiscovery::getServerListItemName(unsigned int index) 56 92 { 57 93 /* if the index is out of range, return empty */ 94 if( index >= this->servers_.size() ) 95 return BLANKSTRING; 96 else 97 /* else return the name of the server */ 98 return this->servers_[index].getServerName(); 58 99 } 59 100 60 101 std::string WANDiscovery::getServerListItemIP(unsigned int index) 61 102 { 62 103 /* if the index is out of range, return empty */ 104 if( index >= this->servers_.size() ) 105 return BLANKSTRING; 106 else 107 /* else return the IP of the server */ 108 return this->servers_[index].getServerIP(); 63 109 } 64 110
Note: See TracChangeset
for help on using the changeset viewer.