Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/masterserver2/src/libraries/network/WANDiscoverable.cc @ 8423

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

nothing actually changed.

File size: 3.3 KB
Line 
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:
23 *      Fabian 'x3n' Landau (original)
24 *   Co-authors:
25 *      Sandro 'smerkli' Merkli (adaptions to WAN)
26 *      Oliver Scheuss (various fixes and extensions)
27 *      ...
28 *
29 */
30
31#include "WANDiscoverable.h"
32
33#include <enet/enet.h>
34#include <cstring>
35
36#include "MasterServerProtocol.h"
37#include "core/ConfigValueIncludes.h"
38#include "core/CoreIncludes.h"
39
40
41namespace orxonox
42{
43
44  WANDiscoverable::WANDiscoverable(): bActive_(false)
45  {
46    /* debugging output */
47    COUT(4) << "Creating WANDiscoverable.\n";
48 
49    /* register object in orxonox */
50    RegisterObject(WANDiscoverable);
51
52    /* check for the masterserver address option in orxonox.ini */
53    this->setConfigValues();
54   
55  }
56
57  /* read the master server address from config file */
58  void WANDiscoverable::setConfigValues()
59  {
60    /* update msaddress string from orxonox.ini config file, if it
61     * has changed.
62     */
63    SetConfigValueExternal(msaddress, "WANDiscovery", "msaddress", "orxonox.net");
64//     SetConfigValue( msaddress, "orxonox.net");
65  } 
66
67  /* destructor */
68  WANDiscoverable::~WANDiscoverable()
69  {
70    if( this->bActive_ )
71      this->disconnect();
72  }
73 
74  /* set the activity of the discoverable object:
75   * active or not active
76   */
77  void WANDiscoverable::setActivity(bool bActive)
78  {
79    if( bActive==this->bActive_ )
80      return;
81   
82    if( bActive )
83    {
84      if( this->connect() )
85        this->bActive_ = true;
86    }
87    else
88    {
89      this->disconnect();
90      this->bActive_ = false;
91    }
92  }
93 
94  bool WANDiscoverable::connect()
95  {
96    /* initialize it and see if it worked */
97    if( msc.initialize() )
98    {
99      COUT(2) << "Error: could not initialize master server communications!\n";
100      return false;
101    }
102   
103    /* connect and see if it worked */
104    if( msc.connect( this->msaddress.c_str(), ORX_MSERVER_PORT ) )
105    {
106      COUT(2) << "Error: could not connect to master server at " 
107                 << this->msaddress << std::endl;
108      return false;
109    }
110                 
111    /* debugging output */
112    COUT(4) << "Initialization of WANDiscoverable complete.\n";
113   
114   
115    // Now register the server at the master server
116    this->msc.sendRequest( MSPROTO_GAME_SERVER " " MSPROTO_REGISTER_SERVER );
117   
118    return true;
119  }
120
121  void WANDiscoverable::disconnect()
122  {
123    this->msc.sendRequest( MSPROTO_GAME_SERVER " " MSPROTO_SERVERDC );
124    msc.disconnect();
125  }
126
127
128
129 
130} // namespace orxonox
Note: See TracBrowser for help on using the repository browser.