Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 9715 was 9715, checked in by bensch, 18 years ago

renamed newclassid to classid and newobjectlist to objectlist

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