Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

found a bug in the server settings reading

File size: 2.8 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#include "netdefs.h"
20
21#include "loading/resource_manager.h"
22#include "loading/load_param.h"
23
24#include "debug.h"
25
26
27
28NetworkSettings* NetworkSettings::singletonRef = NULL;
29
30/**
31 * Standard constructor
32 */
33NetworkSettings::NetworkSettings()
34{
35  /* set the class id for the base object */
36  this->setClassID(CL_NETWORK_SETTINGS, "NetworkSettings");
37
38  // suggest a good standard max players value
39  this->maxPlayer = 10;
40}
41
42
43/**
44 * Standard destructor
45 */
46NetworkSettings::~NetworkSettings()
47{
48  NetworkSettings::singletonRef = NULL;
49
50  // remove all unused proxy data again
51  for( int i = 0; i < this->proxies.size(); i++)
52  {
53    IPaddress* ip = this->proxies.back();
54    this->proxies.pop_back();
55    delete ip;
56  }
57}
58
59
60/**
61 *  this loads the proxy settings from a configuration file
62 */
63void NetworkSettings::loadData()
64{
65  std::string fileName = ResourceManager::getInstance()->getDataDir();
66  fileName += "configs/network_settings.conf";
67
68  TiXmlDocument doc(fileName);
69  if( !doc.LoadFile(fileName))
70  {
71    PRINTF(1)("Loading file %s failed for Network Settings.\n", fileName.c_str());
72    return;
73  }
74  const TiXmlElement* root = doc.RootElement();
75
76  if( strcmp( root->Value(), "NetworkSettings"))
77  {
78    // report an error
79    PRINTF(1)("Specified XML File is not an orxonox Network Settings file (NetworkSettings element missing)\n");
80    return;
81  }
82
83  this->loadNetworkSettings( root);
84}
85
86
87
88/**
89 * load the proxy settings
90 * @param root: the root element of the xml elemnts
91 */
92void NetworkSettings::loadNetworkSettings(const TiXmlElement* root)
93{
94  LoadParam(root, "master-addr", this, NetworkSettings, setMasterAddr);
95
96  LoadParam(root, "max-player", this, NetworkSettings, setMaxPlayer);
97
98
99  LOAD_PARAM_START_CYCLE(root, element);
100  {
101    element->ToText();
102    LoadParam_CYCLE(element, "proxy-addr", this, NetworkSettings, setProxyAddr);
103  }
104  LOAD_PARAM_END_CYCLE(element);
105
106}
107
108
109/**
110 * sets the master server address
111 * @param masterAddr: the address of the master server
112 */
113void NetworkSettings::setMasterAddr(const std::string& masterAddr)
114{
115  IPaddress *ip = new IPaddress;
116
117  SDLNet_ResolveHost( ip, masterAddr.c_str(), 9999 );
118
119  this->masterServer = *ip;
120}
121
122/**
123 * sets the proxy address to
124 *  @param proxyAddr: the proxy address
125 */
126void NetworkSettings::setProxyAddr(const std::string& proxyAddr)
127{
128  IPaddress *ip = new IPaddress;
129
130  SDLNet_ResolveHost( ip, proxyAddr.c_str(), 9999 );
131
132  this->proxies.push_back(ip);
133}
134
135
136
137
138
139
140
Note: See TracBrowser for help on using the repository browser.