Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 10, 2010, 3:35:39 PM (13 years ago)
Author:
smerkli
Message:

added comments, lua function (to be tested) and various implementation bits

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/masterserver/src/libraries/network/WANDiscovery.cc

    r7630 r7631  
    2121 *
    2222 *   Author:
    23  *      Fabian 'x3n' Landau
     23 *      Fabian 'x3n' Landau (original)
    2424 *   Co-authors:
     25 *      Sandro 'smerkli' Merkli (adaptions to WAN)
    2526 *      ...
    2627 *
     
    4243  WANDiscovery::WANDiscovery()
    4344  {
     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";
    4455  }
    4556
    4657  WANDiscovery::~WANDiscovery()
    47   {
     58  {
     59    /* clear server list */
     60    this->servers_.clear(); 
    4861  }
    4962
     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 
    5076  void WANDiscovery::discover()
    5177  {
     78    /* clear list */
    5279    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. */
    5389  }
    5490
    5591  std::string WANDiscovery::getServerListItemName(unsigned int index)
    5692  {
    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();
    5899  }
    59100
    60101  std::string WANDiscovery::getServerListItemIP(unsigned int index)
    61102  {
    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();
    63109  }
    64110
Note: See TracChangeset for help on using the changeset viewer.