/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004 orx This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. ### File Specific: main-programmer: Patrick Boenzli */ #include "glgui.h" #include "shell_command.h" #include "network_stream.h" #include "debug.h" #include "network_monitor.h" #include "network_node.h" #include "network_stream.h" SHELL_COMMAND(showGUI, NetworkMonitor, showGUI); SHELL_COMMAND(hideGUI, NetworkMonitor, hideGUI); // SHELL_COMMAND(output, MappedWater, saveParams); /** * starts a network monitor */ NetworkMonitor::NetworkMonitor(NetworkStream* networkStream) : Synchronizeable() { this->setClassID(CL_NETWORK_MONITOR, "NetworkMonitor"); this->networkStream = networkStream; this->playerNumber = 0; this->localNode = new NetworkNode( this->networkStream->getPeerInfo()); this->setSynchronized(false); } /** * deconstructor */ NetworkMonitor::~NetworkMonitor() { if( this->localNode) delete this->localNode; } /** * add the network node * @param node to add */ void NetworkMonitor::addNetworkNode(NetworkNode* node) { this->nodeList.push_back(node); } /** * add the network node * @param node to add */ void NetworkMonitor::removeNetworkNode(NetworkNode* node) { std::list::iterator it = this->nodeList.begin(); for(; it != this->nodeList.end(); it++) { if( *it == node) { this->nodeList.erase(it); this->playerNumber--; return; } } } /** * adds a network node to the local node * @param pInfo node information */ void NetworkMonitor::addNode(PeerInfo* pInfo) { if( this->localNode == NULL) return; if( pInfo->isClient()) this->localNode->addClient(pInfo); else if( pInfo->isProxyServer()) this->localNode->addProxyServer(pInfo); else if( pInfo->isMasterServer()) this->localNode->addMasterServer(pInfo); } /** * this displays the network monitor gui */ void NetworkMonitor::showGUI() { if (this->box == NULL) { this->box = new OrxGui::GLGuiBox(OrxGui::Vertical); { OrxGui::GLGuiBox* waterColorBox = new OrxGui::GLGuiBox(OrxGui::Horizontal); { OrxGui::GLGuiText* waterColorText = new OrxGui::GLGuiText(); waterColorText->setText("NetworkMonitor"); waterColorBox->pack(waterColorText); } this->box->pack(waterColorBox); } this->box->showAll(); this->box->setAbsCoor2D(300, 40); OrxGui::GLGuiHandler::getInstance()->activate(); // OrxGui::GLGuiHandler::getInstance()->activateCursor(); } } /** * hides the network monitor gui again */ void NetworkMonitor::hideGUI() { if( this->box == NULL) return; OrxGui::GLGuiHandler::getInstance()->deactivate(); // OrxGui::GLGuiHandler::getInstance()->deactivateCursor(); delete this->box; this->box = NULL; } /** * processes the network monitor data */ void NetworkMonitor::process() { this->playerNumber = 0; std::list::iterator it = this->nodeList.begin(); for(; it != this->nodeList.end(); it++) { this->playerNumber += (*it)->getPlayerNumber(); } this->debug(); } /** * prints out the debug informations */ void NetworkMonitor::debug() { PRINTF(0)("================================= Network Monitor ========\n"); PRINTF(0)(" I am: %s\n", this->localNode->getPeerInfo()->getNodeTypeString().c_str()); PRINTF(0)(" Total count of network nodes: %i\n", this->playerNumber); PRINTF(0)("==========================================================\n"); // PRINTF(0)(" Currently got %i"); }