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