Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/proxy/src/lib/network/proxy/proxy_settings.cc @ 9388

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

working on loading proxy config file from a seperate file

File size: 2.5 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 "proxy_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
28ProxySettings* ProxySettings::singletonRef = NULL;
29
30/**
31 * Standard constructor
32 */
33ProxySettings::ProxySettings()
34{
35  /* set the class id for the base object */
36  this->setClassID(CL_PROXY_SETTINGS, "ProxySettings");
37
38  // suggest a good standard max players value
39  this->maxPlayer = 10;
40
41  PRINTF(0)("\n\n\n\n");
42
43  std::string fileName = ResourceManager::getInstance()->getDataDir();
44  fileName += "configs/proxy_settings.conf";
45
46
47  PRINTF(0)("trying file %s\n", fileName.c_str());
48  TiXmlDocument doc(fileName);
49  if( !doc.LoadFile(fileName))
50  {
51    PRINTF(0)("Loading file %s failed for Proxy Settings.\n", fileName.c_str());
52    return;
53  }
54  const TiXmlElement* root = doc.RootElement();
55
56  if( strcmp( root->Value(), "ProxySettings"))
57  {
58    // report an error
59    PRINTF(0)("Specified XML File is not an orxonox proxy settings file (ProxySettings element missing)\n");
60    return;
61  }
62  LoadParamXML(root, "ProxySettings", this, ProxySettings, loadProxySettings);
63}
64
65
66/**
67 * Standard destructor
68 */
69ProxySettings::~ProxySettings()
70{
71  ProxySettings::singletonRef = NULL;
72
73  // remove all unused proxy data again
74  for( int i = 0; i < this->proxies.size(); i++)
75  {
76    IPaddress* ip = this->proxies.back();
77    this->proxies.pop_back();
78    delete ip;
79  }
80}
81
82
83
84/**
85 * load the proxy settings
86 * @param root: the root element of the xml elemnts
87 */
88void ProxySettings::loadProxySettings(const TiXmlElement* root)
89{
90  PRINTF(0)("lalalallalala\n\n");
91  LoadParam(root, "max-player", this, ProxySettings, setMaxPlayer);
92
93  LOAD_PARAM_START_CYCLE(root, element);
94  {
95    element->ToText();
96    LoadParam(root, "proxy-addr", this, ProxySettings, setProxyAddr);
97  }
98  LOAD_PARAM_END_CYCLE(element);
99
100}
101
102
103/**
104 * sets the proxy address to
105 *  @param proxyAddr: the proxy address
106 */
107void ProxySettings::setProxyAddr(const std::string& proxyAddr)
108{
109  IPaddress *ip = new IPaddress;
110
111  SDLNet_ResolveHost( ip, proxyAddr.c_str(), 9999 );
112
113  this->proxies.push_back(ip);
114}
115
116
117
118
119
120
121
Note: See TracBrowser for help on using the repository browser.