1 | /*! |
---|
2 | * @file network_node.h |
---|
3 | * a class representing a node in the network (this can be a MASTER_SERVER, PROXY_SERVER or a CLIENT |
---|
4 | */ |
---|
5 | |
---|
6 | #ifndef _NETWORK_NODE_H |
---|
7 | #define _NETWORK_NODE_H |
---|
8 | |
---|
9 | #include "base_object.h" |
---|
10 | #include "synchronizeable.h" |
---|
11 | #include "peer_info.h" |
---|
12 | |
---|
13 | #include <list> |
---|
14 | |
---|
15 | //!< a class representing a node in the network (this can be a MASTER_SERVER, PROXY_SERVER or a CLIENT |
---|
16 | class NetworkNode |
---|
17 | { |
---|
18 | public: |
---|
19 | NetworkNode(PeerInfo* pInfo); |
---|
20 | ~NetworkNode(); |
---|
21 | |
---|
22 | |
---|
23 | void addClient(NetworkNode* node); |
---|
24 | void addActiveProxyServer(NetworkNode* node); |
---|
25 | void addPassiveProxyServer(NetworkNode* node); |
---|
26 | void addMasterServer(NetworkNode* node); |
---|
27 | |
---|
28 | void removeClient(NetworkNode* node); |
---|
29 | void removeActiveProxyServer(NetworkNode* node); |
---|
30 | void removePassiveProxyServer(NetworkNode* node); |
---|
31 | void removeMasterServer(NetworkNode* node); |
---|
32 | |
---|
33 | void removeClient(int userId); |
---|
34 | void removeActiveProxyServer(int userId); |
---|
35 | void removePassiveProxyServer(int userId); |
---|
36 | void removeMasterServer(int userId); |
---|
37 | |
---|
38 | |
---|
39 | PeerInfo* getClient(int index) const; |
---|
40 | PeerInfo* getActiveProxyServer(int index) const; |
---|
41 | PeerInfo* getPassiveProxyServer(int index) const; |
---|
42 | PeerInfo* getMasterServer(int index) const; |
---|
43 | |
---|
44 | /** @returns the master server list */ |
---|
45 | inline std::list<NetworkNode*> getMasterServers() const { return this->masterServerList; } |
---|
46 | /** @returns the active proxy server list */ |
---|
47 | inline std::list<NetworkNode*> getActiveProxyServers() const { return this->activeProxyServerList; } |
---|
48 | /** @returns the passive proxy server list */ |
---|
49 | inline std::list<NetworkNode*> getPassiveProxyServers() const { return this->passiveProxyServerList; } |
---|
50 | /** @returns the client list */ |
---|
51 | inline std::list<NetworkNode*> getClients() const { return this->clientList; } |
---|
52 | |
---|
53 | PeerInfo* getPeerByUserId( int userId); |
---|
54 | |
---|
55 | /** @returns the number of players */ |
---|
56 | inline int getPlayerNumber() const { return this->playerNumber; } |
---|
57 | /** @returns the node type of this node */ |
---|
58 | inline int getNodeType() const { return this->peerInfo->nodeType; } |
---|
59 | /** @returns the peer info of this node */ |
---|
60 | inline PeerInfo* getPeerInfo() const { return this->peerInfo; } |
---|
61 | |
---|
62 | NetworkNode* getNodeByUserId( int userId); |
---|
63 | |
---|
64 | void debug(int depth) const; |
---|
65 | |
---|
66 | |
---|
67 | private: |
---|
68 | int playerNumber; //!< localy direct connected player number |
---|
69 | int connectionNumber; //!< number of connections ( can but musn't be equal players) |
---|
70 | PeerInfo* peerInfo; //!< the peer information about this node |
---|
71 | |
---|
72 | /* network nodes directly connected to this node */ |
---|
73 | std::list<NetworkNode*> clientList; //!< list of all clients in the network |
---|
74 | std::list<NetworkNode*> activeProxyServerList; //!< list of all proxy servers in the network |
---|
75 | std::list<NetworkNode*> passiveProxyServerList; //!< list of all proxy servers in the network |
---|
76 | std::list<NetworkNode*> masterServerList; //!< list of all master servers in the network (should be 1!! :D) |
---|
77 | |
---|
78 | }; |
---|
79 | |
---|
80 | #endif /* _NETWORK_NODE_H */ |
---|