[9263] | 1 | /*! |
---|
[9264] | 2 | * @file network_monitor.h |
---|
| 3 | * a class to monitor the network: throughput, network nodes |
---|
[9263] | 4 | */ |
---|
| 5 | |
---|
| 6 | #ifndef _NETWORK_MONITOR_H |
---|
| 7 | #define _NETWORK_MONITOR_H |
---|
| 8 | |
---|
| 9 | #include "base_object.h" |
---|
| 10 | #include "synchronizeable.h" |
---|
| 11 | |
---|
[9278] | 12 | #include "network_node.h" |
---|
| 13 | |
---|
[9264] | 14 | #include <list> |
---|
| 15 | |
---|
[9263] | 16 | class NetworkStream; |
---|
[9264] | 17 | class PeerInfo; |
---|
[9263] | 18 | |
---|
[9278] | 19 | |
---|
[9269] | 20 | namespace OrxGui { class GLGuiBox; }; |
---|
[9264] | 21 | |
---|
[9273] | 22 | |
---|
| 23 | |
---|
| 24 | //!< a class that monitors the whole network. it tries to gather all informations its able to from the network |
---|
[9263] | 25 | class NetworkMonitor : public Synchronizeable |
---|
| 26 | { |
---|
| 27 | |
---|
| 28 | public: |
---|
| 29 | NetworkMonitor(NetworkStream* networkStream); |
---|
[9264] | 30 | virtual ~NetworkMonitor(); |
---|
| 31 | |
---|
[9277] | 32 | /* client/masterserver/proxyserver addition/removal interface */ |
---|
| 33 | void addNetworkNode(NetworkNode* node); |
---|
| 34 | void removeNetworkNode(NetworkNode* node); |
---|
[9264] | 35 | |
---|
[9282] | 36 | void addNode(PeerInfo* pInfo); |
---|
[9308] | 37 | void addNode(IPaddress ip, int nodeType); |
---|
[9287] | 38 | void addNode(NetworkNode* node) { this->nodeList.push_back(node); } |
---|
| 39 | void addNode(NetworkNode* node, PeerInfo* pInfo); |
---|
[9282] | 40 | |
---|
| 41 | /** adds to @param node a network node @param pInfo a new client */ |
---|
[9278] | 42 | inline void addClient(NetworkNode* node, PeerInfo* pInfo) { node->addClient(pInfo); } |
---|
[9282] | 43 | /** adds to @param node a network node @param pInfo a new proxy server */ |
---|
[9292] | 44 | inline void addActiveProxyServer(NetworkNode* node, PeerInfo* pInfo) { node->addActiveProxyServer(pInfo); } |
---|
[9300] | 45 | /** adds to @param node a network node @param pInfo a new proxy server */ |
---|
| 46 | inline void addPassiveProxyServer(NetworkNode* node, PeerInfo* pInfo) { node->addPassiveProxyServer(pInfo); } |
---|
[9282] | 47 | /** adds to @param node a network node @param pInfo a new master server*/ |
---|
[9278] | 48 | inline void addMasterServer(NetworkNode* node, PeerInfo* pInfo) { node->addMasterServer(pInfo); } |
---|
[9264] | 49 | |
---|
[9278] | 50 | inline void removeClient(NetworkNode* node, PeerInfo* pInfo) { node->removeClient(pInfo); } |
---|
[9292] | 51 | inline void removeActiveProxyServer(NetworkNode* node, PeerInfo* pInfo) { node->removeActiveProxyServer(pInfo); } |
---|
[9300] | 52 | inline void removePassiveProxyServer(NetworkNode* node, PeerInfo* pInfo) { node->removePassiveProxyServer(pInfo); } |
---|
[9278] | 53 | inline void removeMasterServer(NetworkNode* node, PeerInfo* pInfo) { node->removeMasterServer(pInfo); } |
---|
[9264] | 54 | |
---|
[9295] | 55 | /* slots admin and info interface */ |
---|
[9280] | 56 | /** @returns the total number of players in this game (including all proxy servers etc)*/ |
---|
| 57 | inline int getPlayerNumber() { return this->playerNumber; } |
---|
[9277] | 58 | |
---|
[9290] | 59 | /** @returns true if there are still free network slots available */ |
---|
[9292] | 60 | inline bool gotFreeSlots() { return (this->localNode->getPlayerNumber() < NET_MAX_CONNECTIONS)?true:false; } |
---|
| 61 | /** @param node node to be checked for slots @returns true if there are still free network slots available at this node */ |
---|
[9296] | 62 | inline bool gotFreeSlots(NetworkNode* node) { return (node->getPlayerNumber() < NET_MAX_CONNECTIONS)?true:false; } |
---|
[9300] | 63 | PeerInfo* getFirstChoiceProxy(); |
---|
| 64 | PeerInfo* getSecondChoiceProxy(); |
---|
| 65 | /** @returns true if the next client should be reconnected to some other proxy server with more connections */ |
---|
| 66 | inline bool reconnectNextClient() { return (this->localNode->getPlayerNumber() >= NET_MAX_CONNECTIONS)?true:false; } |
---|
[9280] | 67 | |
---|
[9290] | 68 | |
---|
[9265] | 69 | void showGUI(); |
---|
[9266] | 70 | void hideGUI(); |
---|
[9264] | 71 | |
---|
| 72 | void process(); |
---|
[9285] | 73 | void debug(); |
---|
[9264] | 74 | |
---|
| 75 | |
---|
| 76 | private: |
---|
[9279] | 77 | NetworkStream* networkStream; //!< reference to the one networkstream of the network |
---|
[9282] | 78 | NetworkNode* localNode; //!< reference to the local node |
---|
[9277] | 79 | std::list<NetworkNode*> nodeList; //!< list of all network nodes |
---|
[9265] | 80 | |
---|
| 81 | OrxGui::GLGuiBox* box; |
---|
[9272] | 82 | |
---|
| 83 | int playerNumber; //!< total number of players in the game |
---|
[9263] | 84 | }; |
---|
| 85 | |
---|
| 86 | |
---|
| 87 | #endif |
---|