Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/masterserver/src/libraries/network/WANDiscovery.cc @ 7631

Last change on this file since 7631 was 7631, checked in by smerkli, 14 years ago

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

File size: 3.0 KB
RevLine 
[7161]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
[7631]23 *      Fabian 'x3n' Landau (original)
[7161]24 *   Co-authors:
[7631]25 *      Sandro 'smerkli' Merkli (adaptions to WAN)
[7161]26 *      ...
27 *
28 */
29
[7630]30#include "WANDiscovery.h"
[7161]31
32#include <enet/enet.h>
33#include <cstring>
34
[7284]35#include "util/ScopedSingletonManager.h"
[7161]36#include "core/CoreIncludes.h"
37
38
39namespace orxonox
[7284]40{
[7630]41  ManageScopedSingleton(WANDiscovery, ScopeID::Root, true);
[7284]42
[7630]43  WANDiscovery::WANDiscovery()
[7161]44  {
[7631]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";
[7161]55  }
56
[7630]57  WANDiscovery::~WANDiscovery()
[7631]58  { 
59    /* clear server list */
60    this->servers_.clear(); 
[7161]61  }
[7284]62
[7631]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 
[7630]76  void WANDiscovery::discover()
[7161]77  {
[7631]78    /* clear list */
[7161]79    this->servers_.clear();
[7631]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. */
[7630]89  }
[7284]90
[7630]91  std::string WANDiscovery::getServerListItemName(unsigned int index)
92  {
[7631]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();
[7161]99  }
[7284]100
[7630]101  std::string WANDiscovery::getServerListItemIP(unsigned int index)
[7161]102  {
[7631]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();
[7161]109  }
[7284]110
111
[7161]112} // namespace orxonox
Note: See TracBrowser for help on using the repository browser.