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 | |
---|
26 | SHELL_COMMAND(showGUI, NetworkMonitor, showGUI); |
---|
27 | SHELL_COMMAND(hideGUI, NetworkMonitor, hideGUI); |
---|
28 | // SHELL_COMMAND(output, MappedWater, saveParams); |
---|
29 | |
---|
30 | |
---|
31 | |
---|
32 | /** |
---|
33 | * starts a network monitor |
---|
34 | */ |
---|
35 | NetworkMonitor::NetworkMonitor(NetworkStream* networkStream) |
---|
36 | : Synchronizeable() |
---|
37 | { |
---|
38 | this->setClassID(CL_NETWORK_MONITOR, "NetworkMonitor"); |
---|
39 | |
---|
40 | this->networkStream = networkStream; |
---|
41 | this->playerNumber = 0; |
---|
42 | this->localNode = new NetworkNode( this->networkStream->getPeerInfo()); |
---|
43 | |
---|
44 | this->setSynchronized(false); |
---|
45 | } |
---|
46 | |
---|
47 | |
---|
48 | /** |
---|
49 | * deconstructor |
---|
50 | */ |
---|
51 | NetworkMonitor::~NetworkMonitor() |
---|
52 | { |
---|
53 | if( this->localNode) |
---|
54 | delete this->localNode; |
---|
55 | } |
---|
56 | |
---|
57 | |
---|
58 | /** |
---|
59 | * add the network node |
---|
60 | * @param node to add |
---|
61 | */ |
---|
62 | void NetworkMonitor::addNetworkNode(NetworkNode* node) |
---|
63 | { |
---|
64 | this->nodeList.push_back(node); |
---|
65 | } |
---|
66 | |
---|
67 | |
---|
68 | /** |
---|
69 | * add the network node |
---|
70 | * @param node to add |
---|
71 | */ |
---|
72 | void NetworkMonitor::removeNetworkNode(NetworkNode* node) |
---|
73 | { |
---|
74 | std::list<NetworkNode*>::iterator it = this->nodeList.begin(); |
---|
75 | for(; it != this->nodeList.end(); it++) |
---|
76 | { |
---|
77 | if( *it == node) |
---|
78 | { |
---|
79 | this->nodeList.erase(it); |
---|
80 | this->playerNumber--; |
---|
81 | return; |
---|
82 | } |
---|
83 | } |
---|
84 | } |
---|
85 | |
---|
86 | |
---|
87 | /** |
---|
88 | * adds a network node to the local node |
---|
89 | * @param pInfo node information |
---|
90 | */ |
---|
91 | void NetworkMonitor::addNode(PeerInfo* pInfo) |
---|
92 | { |
---|
93 | if( this->localNode == NULL) |
---|
94 | return; |
---|
95 | |
---|
96 | if( pInfo->isClient()) |
---|
97 | this->localNode->addClient(pInfo); |
---|
98 | else if( pInfo->isProxyServer()) |
---|
99 | this->localNode->addProxyServer(pInfo); |
---|
100 | else if( pInfo->isMasterServer()) |
---|
101 | this->localNode->addMasterServer(pInfo); |
---|
102 | } |
---|
103 | |
---|
104 | /** |
---|
105 | * this displays the network monitor gui |
---|
106 | */ |
---|
107 | void NetworkMonitor::showGUI() |
---|
108 | { |
---|
109 | if (this->box == NULL) |
---|
110 | { |
---|
111 | this->box = new OrxGui::GLGuiBox(OrxGui::Vertical); |
---|
112 | { |
---|
113 | OrxGui::GLGuiBox* waterColorBox = new OrxGui::GLGuiBox(OrxGui::Horizontal); |
---|
114 | { |
---|
115 | OrxGui::GLGuiText* waterColorText = new OrxGui::GLGuiText(); |
---|
116 | waterColorText->setText("NetworkMonitor"); |
---|
117 | waterColorBox->pack(waterColorText); |
---|
118 | } |
---|
119 | this->box->pack(waterColorBox); |
---|
120 | } |
---|
121 | |
---|
122 | this->box->showAll(); |
---|
123 | this->box->setAbsCoor2D(300, 40); |
---|
124 | OrxGui::GLGuiHandler::getInstance()->activate(); |
---|
125 | // OrxGui::GLGuiHandler::getInstance()->activateCursor(); |
---|
126 | } |
---|
127 | } |
---|
128 | |
---|
129 | |
---|
130 | /** |
---|
131 | * hides the network monitor gui again |
---|
132 | */ |
---|
133 | void NetworkMonitor::hideGUI() |
---|
134 | { |
---|
135 | if( this->box == NULL) |
---|
136 | return; |
---|
137 | |
---|
138 | OrxGui::GLGuiHandler::getInstance()->deactivate(); |
---|
139 | // OrxGui::GLGuiHandler::getInstance()->deactivateCursor(); |
---|
140 | |
---|
141 | delete this->box; |
---|
142 | this->box = NULL; |
---|
143 | } |
---|
144 | |
---|
145 | |
---|
146 | /** |
---|
147 | * processes the network monitor data |
---|
148 | */ |
---|
149 | void NetworkMonitor::process() |
---|
150 | { |
---|
151 | this->playerNumber = 0; |
---|
152 | std::list<NetworkNode*>::iterator it = this->nodeList.begin(); |
---|
153 | for(; it != this->nodeList.end(); it++) |
---|
154 | { |
---|
155 | this->playerNumber += (*it)->getPlayerNumber(); |
---|
156 | } |
---|
157 | |
---|
158 | this->debug(); |
---|
159 | } |
---|
160 | |
---|
161 | /** |
---|
162 | * prints out the debug informations |
---|
163 | */ |
---|
164 | void NetworkMonitor::debug() |
---|
165 | { |
---|
166 | PRINTF(0)("================================= Network Monitor ========\n"); |
---|
167 | PRINTF(0)(" I am: %s\n", this->localNode->getPeerInfo()->getNodeTypeString().c_str()); |
---|
168 | PRINTF(0)(" Total count of network nodes: %i\n", this->playerNumber); |
---|
169 | PRINTF(0)("==========================================================\n"); |
---|
170 | // PRINTF(0)(" Currently got %i"); |
---|
171 | } |
---|
172 | |
---|