Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/proxy/src/lib/network/monitor/network_monitor.cc @ 9292

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

seperating the proxy servers in passive and active

File size: 4.4 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#include "glgui.h"
16#include "shell_command.h"
17
18#include "network_stream.h"
19#include "debug.h"
20
21#include "network_monitor.h"
22#include "network_node.h"
23#include "network_stream.h"
24
25
26SHELL_COMMAND(showGUI, NetworkMonitor, showGUI);
27SHELL_COMMAND(hideGUI, NetworkMonitor, hideGUI);
28// SHELL_COMMAND(output, MappedWater, saveParams);
29
30
31
32/**
33 * starts a network monitor
34 */
35NetworkMonitor::NetworkMonitor(NetworkStream* networkStream)
36  : Synchronizeable()
37{
38  this->setClassID(CL_NETWORK_MONITOR, "NetworkMonitor");
39
40  this->networkStream = networkStream;
41  this->playerNumber = 0;
42  // create the localnode, init it and add it to the nodes list
43  this->localNode = new NetworkNode( this->networkStream->getPeerInfo());
44  this->addNode(this->localNode);
45
46  this->setSynchronized(false);
47}
48
49
50/**
51 * deconstructor
52 */
53NetworkMonitor::~NetworkMonitor()
54{
55  if( this->localNode)
56    delete this->localNode;
57}
58
59
60/**
61 * add the network node
62 * @param node to add
63 */
64void NetworkMonitor::addNetworkNode(NetworkNode* node)
65{
66  this->nodeList.push_back(node);
67}
68
69
70/**
71 * add the network node
72 * @param node to add
73 */
74void NetworkMonitor::removeNetworkNode(NetworkNode* node)
75{
76  std::list<NetworkNode*>::iterator it = this->nodeList.begin();
77  for(; it != this->nodeList.end(); it++)
78  {
79    if( *it == node)
80    {
81      this->nodeList.erase(it);
82      this->playerNumber--;
83      return;
84    }
85  }
86}
87
88
89/**
90 * adds a network node to the local node
91 *  @param pInfo node information
92 */
93void NetworkMonitor::addNode(PeerInfo* pInfo)
94{
95  if( this->localNode == NULL)
96    return;
97
98  if( pInfo->isClient())
99    this->localNode->addClient(pInfo);
100  else if( pInfo->isProxyServer())
101  {
102    this->localNode->addActiveProxyServer(pInfo);
103    // create a new node, since a proxy can connect clients again
104    NetworkNode* node = new NetworkNode(pInfo);
105    this->nodeList.push_back(node);
106  }
107  else if( pInfo->isMasterServer())
108  {
109    this->localNode->addMasterServer(pInfo);
110  }
111}
112
113
114/**
115 * adds a network node to the local node
116 *  @param node node to add to
117 *  @param pInfo node information
118 */
119void NetworkMonitor::addNode(NetworkNode* node, PeerInfo* pInfo)
120{
121  if( node == NULL)
122    return;
123
124  if( pInfo->isClient())
125    node->addClient(pInfo);
126  else if( pInfo->isProxyServer())
127    node->addActiveProxyServer(pInfo);
128  else if( pInfo->isMasterServer())
129    node->addMasterServer(pInfo);
130}
131
132
133/**
134 * this displays the network monitor gui
135 */
136void NetworkMonitor::showGUI()
137{
138  if (this->box == NULL)
139  {
140    this->box = new OrxGui::GLGuiBox(OrxGui::Vertical);
141    {
142      OrxGui::GLGuiBox* waterColorBox = new OrxGui::GLGuiBox(OrxGui::Horizontal);
143      {
144        OrxGui::GLGuiText* waterColorText = new OrxGui::GLGuiText();
145        waterColorText->setText("NetworkMonitor");
146        waterColorBox->pack(waterColorText);
147      }
148      this->box->pack(waterColorBox);
149    }
150
151    this->box->showAll();
152    this->box->setAbsCoor2D(300, 40);
153    OrxGui::GLGuiHandler::getInstance()->activate();
154//     OrxGui::GLGuiHandler::getInstance()->activateCursor();
155  }
156}
157
158
159/**
160 * hides the network monitor gui again
161 */
162void NetworkMonitor::hideGUI()
163{
164  if( this->box == NULL)
165    return;
166
167  OrxGui::GLGuiHandler::getInstance()->deactivate();
168//   OrxGui::GLGuiHandler::getInstance()->deactivateCursor();
169
170  delete this->box;
171  this->box = NULL;
172}
173
174
175/**
176 * processes the network monitor data
177 */
178void NetworkMonitor::process()
179{
180  this->playerNumber = 0;
181  std::list<NetworkNode*>::iterator it = this->nodeList.begin();
182  for(; it != this->nodeList.end(); it++)
183  {
184    this->playerNumber += (*it)->getPlayerNumber();
185  }
186
187  this->debug();
188}
189
190/**
191 * prints out the debug informations
192 */
193void NetworkMonitor::debug()
194{
195  PRINT(0)("================================= Network Monitor::debug() =====\n");
196  PRINT(0)(" I am: %s\n", this->localNode->getPeerInfo()->getNodeTypeString().c_str());
197  PRINT(0)(" Total count of network connections: %i\n", this->playerNumber);
198
199  std::list<NetworkNode*>::iterator it = this->nodeList.begin();
200  for(; it != this->nodeList.end(); it++)
201  {
202    (*it)->debug(0);
203  }
204
205  PRINT(0)("================================================================\n");
206}
207
Note: See TracBrowser for help on using the repository browser.