[9263] | 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" |
---|
[9266] | 19 | #include "debug.h" |
---|
[9263] | 20 | |
---|
| 21 | #include "network_monitor.h" |
---|
[9276] | 22 | #include "network_node.h" |
---|
[9279] | 23 | #include "network_stream.h" |
---|
[9263] | 24 | |
---|
[9276] | 25 | |
---|
[9266] | 26 | SHELL_COMMAND(showGUI, NetworkMonitor, showGUI); |
---|
| 27 | SHELL_COMMAND(hideGUI, NetworkMonitor, hideGUI); |
---|
[9263] | 28 | // SHELL_COMMAND(output, MappedWater, saveParams); |
---|
| 29 | |
---|
| 30 | |
---|
| 31 | |
---|
| 32 | /** |
---|
| 33 | * starts a network monitor |
---|
| 34 | */ |
---|
| 35 | NetworkMonitor::NetworkMonitor(NetworkStream* networkStream) |
---|
[9281] | 36 | : Synchronizeable() |
---|
[9263] | 37 | { |
---|
[9281] | 38 | this->setClassID(CL_NETWORK_MONITOR, "NetworkMonitor"); |
---|
| 39 | |
---|
[9279] | 40 | this->networkStream = networkStream; |
---|
[9272] | 41 | this->playerNumber = 0; |
---|
[9287] | 42 | // create the localnode, init it and add it to the nodes list |
---|
[9284] | 43 | this->localNode = new NetworkNode( this->networkStream->getPeerInfo()); |
---|
[9287] | 44 | this->addNode(this->localNode); |
---|
[9283] | 45 | |
---|
[9281] | 46 | this->setSynchronized(false); |
---|
[9263] | 47 | } |
---|
| 48 | |
---|
| 49 | |
---|
[9264] | 50 | /** |
---|
| 51 | * deconstructor |
---|
| 52 | */ |
---|
| 53 | NetworkMonitor::~NetworkMonitor() |
---|
[9283] | 54 | { |
---|
| 55 | if( this->localNode) |
---|
| 56 | delete this->localNode; |
---|
| 57 | } |
---|
[9263] | 58 | |
---|
| 59 | |
---|
[9266] | 60 | /** |
---|
[9277] | 61 | * add the network node |
---|
| 62 | * @param node to add |
---|
[9266] | 63 | */ |
---|
[9277] | 64 | void NetworkMonitor::addNetworkNode(NetworkNode* node) |
---|
[9266] | 65 | { |
---|
[9277] | 66 | this->nodeList.push_back(node); |
---|
[9266] | 67 | } |
---|
[9263] | 68 | |
---|
[9266] | 69 | |
---|
| 70 | /** |
---|
[9277] | 71 | * add the network node |
---|
| 72 | * @param node to add |
---|
[9266] | 73 | */ |
---|
[9277] | 74 | void NetworkMonitor::removeNetworkNode(NetworkNode* node) |
---|
[9266] | 75 | { |
---|
[9277] | 76 | std::list<NetworkNode*>::iterator it = this->nodeList.begin(); |
---|
| 77 | for(; it != this->nodeList.end(); it++) |
---|
[9266] | 78 | { |
---|
| 79 | if( *it == node) |
---|
| 80 | { |
---|
[9277] | 81 | this->nodeList.erase(it); |
---|
[9272] | 82 | this->playerNumber--; |
---|
[9266] | 83 | return; |
---|
| 84 | } |
---|
| 85 | } |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | |
---|
[9283] | 89 | /** |
---|
| 90 | * adds a network node to the local node |
---|
| 91 | * @param pInfo node information |
---|
| 92 | */ |
---|
[9282] | 93 | void NetworkMonitor::addNode(PeerInfo* pInfo) |
---|
| 94 | { |
---|
[9283] | 95 | if( this->localNode == NULL) |
---|
| 96 | return; |
---|
[9282] | 97 | |
---|
| 98 | if( pInfo->isClient()) |
---|
| 99 | this->localNode->addClient(pInfo); |
---|
| 100 | else if( pInfo->isProxyServer()) |
---|
[9290] | 101 | { |
---|
[9292] | 102 | this->localNode->addActiveProxyServer(pInfo); |
---|
[9290] | 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 | } |
---|
[9282] | 107 | else if( pInfo->isMasterServer()) |
---|
[9290] | 108 | { |
---|
[9282] | 109 | this->localNode->addMasterServer(pInfo); |
---|
[9290] | 110 | } |
---|
[9282] | 111 | } |
---|
| 112 | |
---|
[9287] | 113 | |
---|
[9266] | 114 | /** |
---|
[9287] | 115 | * adds a network node to the local node |
---|
| 116 | * @param node node to add to |
---|
| 117 | * @param pInfo node information |
---|
| 118 | */ |
---|
| 119 | void 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()) |
---|
[9292] | 127 | node->addActiveProxyServer(pInfo); |
---|
[9287] | 128 | else if( pInfo->isMasterServer()) |
---|
| 129 | node->addMasterServer(pInfo); |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | |
---|
| 133 | /** |
---|
[9265] | 134 | * this displays the network monitor gui |
---|
| 135 | */ |
---|
| 136 | void NetworkMonitor::showGUI() |
---|
| 137 | { |
---|
[9263] | 138 | if (this->box == NULL) |
---|
| 139 | { |
---|
[9265] | 140 | this->box = new OrxGui::GLGuiBox(OrxGui::Vertical); |
---|
[9263] | 141 | { |
---|
[9265] | 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); |
---|
[9263] | 149 | } |
---|
| 150 | |
---|
[9265] | 151 | this->box->showAll(); |
---|
| 152 | this->box->setAbsCoor2D(300, 40); |
---|
| 153 | OrxGui::GLGuiHandler::getInstance()->activate(); |
---|
[9266] | 154 | // OrxGui::GLGuiHandler::getInstance()->activateCursor(); |
---|
[9265] | 155 | } |
---|
| 156 | } |
---|
[9263] | 157 | |
---|
| 158 | |
---|
[9265] | 159 | /** |
---|
[9266] | 160 | * hides the network monitor gui again |
---|
| 161 | */ |
---|
| 162 | void 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 | /** |
---|
[9265] | 176 | * processes the network monitor data |
---|
| 177 | */ |
---|
| 178 | void NetworkMonitor::process() |
---|
| 179 | { |
---|
[9280] | 180 | this->playerNumber = 0; |
---|
[9279] | 181 | std::list<NetworkNode*>::iterator it = this->nodeList.begin(); |
---|
| 182 | for(; it != this->nodeList.end(); it++) |
---|
| 183 | { |
---|
[9280] | 184 | this->playerNumber += (*it)->getPlayerNumber(); |
---|
[9279] | 185 | } |
---|
[9286] | 186 | |
---|
| 187 | this->debug(); |
---|
[9265] | 188 | } |
---|
[9263] | 189 | |
---|
[9286] | 190 | /** |
---|
| 191 | * prints out the debug informations |
---|
| 192 | */ |
---|
[9285] | 193 | void NetworkMonitor::debug() |
---|
| 194 | { |
---|
[9289] | 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); |
---|
[9287] | 198 | |
---|
| 199 | std::list<NetworkNode*>::iterator it = this->nodeList.begin(); |
---|
| 200 | for(; it != this->nodeList.end(); it++) |
---|
| 201 | { |
---|
[9288] | 202 | (*it)->debug(0); |
---|
[9287] | 203 | } |
---|
| 204 | |
---|
[9289] | 205 | PRINT(0)("================================================================\n"); |
---|
[9285] | 206 | } |
---|
| 207 | |
---|