[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" |
---|
[9327] | 11 | #include "shared_network_data.h" |
---|
[9334] | 12 | #include "ip.h" |
---|
[9263] | 13 | |
---|
[9278] | 14 | #include "network_node.h" |
---|
| 15 | |
---|
[9264] | 16 | #include <list> |
---|
| 17 | |
---|
[9263] | 18 | class NetworkStream; |
---|
[9264] | 19 | class PeerInfo; |
---|
[9263] | 20 | |
---|
[9278] | 21 | |
---|
[9269] | 22 | namespace OrxGui { class GLGuiBox; }; |
---|
[9264] | 23 | |
---|
[9273] | 24 | |
---|
| 25 | |
---|
| 26 | //!< a class that monitors the whole network. it tries to gather all informations its able to from the network |
---|
[9263] | 27 | class NetworkMonitor : public Synchronizeable |
---|
| 28 | { |
---|
[9869] | 29 | ObjectListDeclaration(NetworkMonitor); |
---|
[9263] | 30 | public: |
---|
| 31 | NetworkMonitor(NetworkStream* networkStream); |
---|
[9264] | 32 | virtual ~NetworkMonitor(); |
---|
| 33 | |
---|
[9277] | 34 | /* client/masterserver/proxyserver addition/removal interface */ |
---|
| 35 | void addNetworkNode(NetworkNode* node); |
---|
| 36 | void removeNetworkNode(NetworkNode* node); |
---|
[9264] | 37 | |
---|
[9282] | 38 | void addNode(PeerInfo* pInfo); |
---|
[9494] | 39 | void addNode(const IP& ip, int nodeType); |
---|
[9287] | 40 | void addNode(NetworkNode* node) { this->nodeList.push_back(node); } |
---|
| 41 | void addNode(NetworkNode* node, PeerInfo* pInfo); |
---|
[9282] | 42 | |
---|
| 43 | /** adds to @param node a network node @param pInfo a new client */ |
---|
[9656] | 44 | inline void addClient(NetworkNode* node, PeerInfo* pInfo) { node->addClient(new NetworkNode(pInfo)); } |
---|
[9282] | 45 | /** adds to @param node a network node @param pInfo a new proxy server */ |
---|
[9656] | 46 | inline void addActiveProxyServer(NetworkNode* node, PeerInfo* pInfo) { node->addActiveProxyServer(new NetworkNode(pInfo)); } |
---|
[9300] | 47 | /** adds to @param node a network node @param pInfo a new proxy server */ |
---|
[9656] | 48 | inline void addPassiveProxyServer(NetworkNode* node, PeerInfo* pInfo) { node->addPassiveProxyServer(new NetworkNode(pInfo)); } |
---|
[9282] | 49 | /** adds to @param node a network node @param pInfo a new master server*/ |
---|
[9656] | 50 | inline void addMasterServer(NetworkNode* node, PeerInfo* pInfo) { node->addMasterServer(new NetworkNode(pInfo)); } |
---|
[9264] | 51 | |
---|
[9656] | 52 | void removeNode(PeerInfo* pInfo); |
---|
| 53 | void removeNode(NetworkNode* node, PeerInfo* pInfo); |
---|
[9264] | 54 | |
---|
[9656] | 55 | inline void removeClient(NetworkNode* node, int userId) { node->removeClient(userId); } |
---|
| 56 | inline void removeActiveProxyServer(NetworkNode* node, int userId) { node->removeActiveProxyServer(userId); } |
---|
| 57 | inline void removePassiveProxyServer(NetworkNode* node, int userId) { node->removePassiveProxyServer(userId); } |
---|
| 58 | inline void removeMasterServer(NetworkNode* node, int userId) { node->removeMasterServer(userId); } |
---|
| 59 | |
---|
[9494] | 60 | PeerInfo* getFirstChoiceProxy() const; |
---|
| 61 | PeerInfo* getSecondChoiceProxy() const; |
---|
| 62 | /** @returns the local node */ |
---|
| 63 | inline NetworkNode* getLocalNode() const { return this->localNode; }; |
---|
[9396] | 64 | |
---|
| 65 | /** @returns the active proxy server list of the localnode */ |
---|
[9656] | 66 | inline std::list<NetworkNode*> getActiveProxyServers() const { return this->localNode->getActiveProxyServers(); } |
---|
[9396] | 67 | |
---|
[9295] | 68 | /* slots admin and info interface */ |
---|
[9280] | 69 | /** @returns the total number of players in this game (including all proxy servers etc)*/ |
---|
[9494] | 70 | inline int getPlayerNumber() const { return this->playerNumber; } |
---|
[9277] | 71 | |
---|
[9404] | 72 | /** @returns true if there are still free network slots available at the local node*/ |
---|
[9494] | 73 | inline bool gotFreeSlots() const { return (this->localNode->getPlayerNumber() < SharedNetworkData::getInstance()->getMaxPlayer()); } |
---|
[9292] | 74 | /** @param node node to be checked for slots @returns true if there are still free network slots available at this node */ |
---|
[9494] | 75 | inline bool gotFreeSlots(NetworkNode* node) const { return (node->getPlayerNumber() < SharedNetworkData::getInstance()->getMaxPlayer()); } |
---|
[9396] | 76 | |
---|
[9300] | 77 | /** @returns true if the next client should be reconnected to some other proxy server with more connections */ |
---|
[9494] | 78 | inline bool isReconnectNextClient() const { return (this->localNode->getPlayerNumber() >= SharedNetworkData::getInstance()->getMaxPlayer()); } |
---|
[9280] | 79 | |
---|
[9494] | 80 | inline const std::list<NetworkNode*>& getNodeList() const { return this->nodeList; }; |
---|
[9656] | 81 | PeerInfo* getPeerByUserId( int userId); |
---|
| 82 | NetworkNode* getNodeByUserId( int userId); |
---|
[9290] | 83 | |
---|
[9656] | 84 | /* forced reconnection interface */ |
---|
| 85 | inline void setForcedReconnection(IP address) { this->bForcedRecon = true; this->forcedReconnection = address;} |
---|
| 86 | inline bool isForcedReconnection() const { return this->bForcedRecon; } |
---|
| 87 | inline IP getForcedReconnectionIP() { this->bForcedRecon = false; return this->forcedReconnection; } |
---|
| 88 | |
---|
| 89 | |
---|
[9494] | 90 | void toggleGUI(); |
---|
[9264] | 91 | |
---|
| 92 | void process(); |
---|
[9494] | 93 | void debug() const; |
---|
[9264] | 94 | |
---|
| 95 | |
---|
| 96 | private: |
---|
[9279] | 97 | NetworkStream* networkStream; //!< reference to the one networkstream of the network |
---|
[9282] | 98 | NetworkNode* localNode; //!< reference to the local node |
---|
[9277] | 99 | std::list<NetworkNode*> nodeList; //!< list of all network nodes |
---|
[9265] | 100 | |
---|
| 101 | OrxGui::GLGuiBox* box; |
---|
[9272] | 102 | |
---|
| 103 | int playerNumber; //!< total number of players in the game |
---|
[9404] | 104 | int connectionNumber; //!< total number of connections at this localhost |
---|
[9656] | 105 | |
---|
| 106 | IP forcedReconnection; //!< ip of a forced reconnection |
---|
| 107 | bool bForcedRecon; //!< true if there is a forced recon |
---|
[9263] | 108 | }; |
---|
| 109 | |
---|
| 110 | |
---|
| 111 | #endif |
---|