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