Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/proxy/src/lib/network/proxy/network_settings.cc @ 9410

Last change on this file since 9410 was 9410, checked in by patrick, 18 years ago

some better debug and function call cleanup

File size: 3.3 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11### File Specific:
12   main-programmer: Patrick Boenzli
13*/
14
15
16#define DEBUG_MODULE_NETWORK
17
18#include "network_settings.h"
19
20#include "netdefs.h"
21#include "shared_network_data.h"
22
23#include "loading/resource_manager.h"
24#include "loading/load_param.h"
25
26#include "debug.h"
27
28
29
30NetworkSettings* NetworkSettings::singletonRef = NULL;
31
32/**
33 * Standard constructor
34 */
35NetworkSettings::NetworkSettings()
36{
37  /* set the class id for the base object */
38  this->setClassID(CL_NETWORK_SETTINGS, "NetworkSettings");
39
40  // suggest a good standard max players value
41  this->maxPlayer = 10;
42
43//   this->loadData();
44}
45
46
47/**
48 * Standard destructor
49 */
50NetworkSettings::~NetworkSettings()
51{
52  NetworkSettings::singletonRef = NULL;
53
54  // remove all unused proxy data again
55  for( int i = 0; i < this->proxies.size(); i++)
56  {
57    IPaddress* ip = this->proxies.back();
58    this->proxies.pop_back();
59    delete ip;
60  }
61}
62
63
64/**
65 *  this loads the proxy settings from a configuration file
66 */
67void NetworkSettings::loadData()
68{
69  std::string fileName = ResourceManager::getInstance()->getDataDir();
70  fileName += "configs/network_settings.conf";
71
72  TiXmlDocument doc(fileName);
73  if( !doc.LoadFile(fileName))
74  {
75    PRINTF(1)("Loading file %s failed for Network Settings.\n", fileName.c_str());
76    return;
77  }
78  const TiXmlElement* root = doc.RootElement();
79
80  if( strcmp( root->Value(), "NetworkSettings"))
81  {
82    // report an error
83    PRINTF(1)("Specified XML File is not an orxonox Network Settings file (NetworkSettings element missing)\n");
84    return;
85  }
86
87  this->loadNetworkSettings( root);
88
89  // set the new unique id offset
90  // setUniqueID( maxCon+2 ) because we need one id for every handshake
91  // and one for handshake to reject client maxCon+1
92  SharedNetworkData::getInstance()->setNewUniqueID( this->maxPlayer + 2);
93}
94
95
96
97/**
98 * load the proxy settings
99 * @param root: the root element of the xml elemnts
100 */
101void NetworkSettings::loadNetworkSettings(const TiXmlElement* root)
102{
103  LoadParam(root, "master-addr", this, NetworkSettings, setMasterAddr);
104
105  LoadParam(root, "max-player", this, NetworkSettings, setMaxPlayer);
106  LoadParam(root, "max-player-saturation", this, NetworkSettings, setMaxPlayerSaturation);
107
108
109  LOAD_PARAM_START_CYCLE(root, element);
110  {
111    element->ToText();
112    LoadParam_CYCLE(element, "proxy-addr", this, NetworkSettings, setProxyAddr);
113  }
114  LOAD_PARAM_END_CYCLE(element);
115
116}
117
118
119/**
120 * sets the master server address
121 * @param masterAddr: the address of the master server
122 */
123void NetworkSettings::setMasterAddr(const std::string& masterAddr)
124{
125  IPaddress *ip = new IPaddress;
126
127  SDLNet_ResolveHost( ip, masterAddr.c_str(), 9999 );
128
129  this->masterServer = *ip;
130}
131
132
133/**
134 * sets the proxy address to
135 *  @param proxyAddr: the proxy address
136 */
137void NetworkSettings::setProxyAddr(const std::string& proxyAddr)
138{
139
140  if( !SharedNetworkData::getInstance()->isMasterServer())
141    return;
142
143  IPaddress *ip = new IPaddress;
144
145  SDLNet_ResolveHost( ip, proxyAddr.c_str(), 9999 );
146
147  this->proxies.push_back(ip);
148}
149
150
151
152
153
154
155
Note: See TracBrowser for help on using the repository browser.