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 | ObjectListDeclaration(NetworkMonitor); |
---|
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(new NetworkNode(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(new NetworkNode(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(new NetworkNode(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(new NetworkNode(pInfo)); } |
---|
51 | |
---|
52 | void removeNode(PeerInfo* pInfo); |
---|
53 | void removeNode(NetworkNode* node, PeerInfo* pInfo); |
---|
54 | |
---|
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 | |
---|
60 | PeerInfo* getFirstChoiceProxy() const; |
---|
61 | PeerInfo* getSecondChoiceProxy() const; |
---|
62 | /** @returns the local node */ |
---|
63 | inline NetworkNode* getLocalNode() const { return this->localNode; }; |
---|
64 | |
---|
65 | /** @returns the active proxy server list of the localnode */ |
---|
66 | inline std::list<NetworkNode*> getActiveProxyServers() const { return this->localNode->getActiveProxyServers(); } |
---|
67 | |
---|
68 | /* slots admin and info interface */ |
---|
69 | /** @returns the total number of players in this game (including all proxy servers etc)*/ |
---|
70 | inline int getPlayerNumber() const { return this->playerNumber; } |
---|
71 | |
---|
72 | /** @returns true if there are still free network slots available at the local node*/ |
---|
73 | inline bool gotFreeSlots() const { return (this->localNode->getPlayerNumber() < SharedNetworkData::getInstance()->getMaxPlayer()); } |
---|
74 | /** @param node node to be checked for slots @returns true if there are still free network slots available at this node */ |
---|
75 | inline bool gotFreeSlots(NetworkNode* node) const { return (node->getPlayerNumber() < SharedNetworkData::getInstance()->getMaxPlayer()); } |
---|
76 | |
---|
77 | /** @returns true if the next client should be reconnected to some other proxy server with more connections */ |
---|
78 | inline bool isReconnectNextClient() const { return (this->localNode->getPlayerNumber() >= SharedNetworkData::getInstance()->getMaxPlayer()); } |
---|
79 | |
---|
80 | inline const std::list<NetworkNode*>& getNodeList() const { return this->nodeList; }; |
---|
81 | PeerInfo* getPeerByUserId( int userId); |
---|
82 | NetworkNode* getNodeByUserId( int userId); |
---|
83 | |
---|
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 | |
---|
90 | void toggleGUI(); |
---|
91 | |
---|
92 | void process(); |
---|
93 | void debug() const; |
---|
94 | |
---|
95 | |
---|
96 | private: |
---|
97 | NetworkStream* networkStream; //!< reference to the one networkstream of the network |
---|
98 | NetworkNode* localNode; //!< reference to the local node |
---|
99 | std::list<NetworkNode*> nodeList; //!< list of all network nodes |
---|
100 | |
---|
101 | OrxGui::GLGuiBox* box; |
---|
102 | |
---|
103 | int playerNumber; //!< total number of players in the game |
---|
104 | int connectionNumber; //!< total number of connections at this localhost |
---|
105 | |
---|
106 | IP forcedReconnection; //!< ip of a forced reconnection |
---|
107 | bool bForcedRecon; //!< true if there is a forced recon |
---|
108 | }; |
---|
109 | |
---|
110 | |
---|
111 | #endif |
---|