[6678] | 1 | /*! |
---|
| 2 | * @file shared_network_data.h |
---|
| 3 | * some shared data from the NetworkManager |
---|
| 4 | */ |
---|
| 5 | |
---|
| 6 | #ifndef _SHARED_NETWORK_DATA |
---|
| 7 | #define _SHARED_NETWORK_DATA |
---|
| 8 | |
---|
| 9 | #include "base_object.h" |
---|
[9406] | 10 | #include "netdefs.h" |
---|
| 11 | #include "proxy/network_settings.h" |
---|
[6678] | 12 | |
---|
[9406] | 13 | //!< maximal connectinons for the server |
---|
| 14 | #define NET_MAX_CONNECTIONS 2 |
---|
[6678] | 15 | |
---|
| 16 | class NetworkStream; |
---|
| 17 | class Synchronizeable; |
---|
| 18 | |
---|
[9406] | 19 | |
---|
[6678] | 20 | /* and here is the class itsself*/ |
---|
| 21 | class SharedNetworkData : public BaseObject |
---|
| 22 | { |
---|
| 23 | |
---|
| 24 | public: |
---|
| 25 | inline static SharedNetworkData* getInstance() { if (!SharedNetworkData::singletonRef) SharedNetworkData::singletonRef = new SharedNetworkData(); |
---|
| 26 | return SharedNetworkData::singletonRef; } |
---|
| 27 | virtual ~SharedNetworkData(); |
---|
| 28 | |
---|
| 29 | /** @returns the next uniqueID free for an object */ |
---|
[9406] | 30 | inline int getNewUniqueID() { return ( this->nodeType != NET_CLIENT)?this->newUniqueID++:-1; } |
---|
| 31 | /** sets the @param newUniqueID: the new offset for the next unique id */ |
---|
| 32 | inline void setNewUniqueID(int newUniqueID) { this->newUniqueID = newUniqueID; } |
---|
[6678] | 33 | |
---|
[9406] | 34 | /** @returns true is this node is a master server */ |
---|
| 35 | inline bool isMasterServer() { return this->nodeType == NET_MASTER_SERVER; } |
---|
| 36 | /** @returns true is this node is a proxy server */ |
---|
[9452] | 37 | inline bool isProxyServerActive() { return this->nodeType == NET_PROXY_SERVER_ACTIVE; } |
---|
[9406] | 38 | /** @returns true is this node is a client*/ |
---|
| 39 | inline bool isClient() { return this->nodeType == NET_CLIENT; } |
---|
[6678] | 40 | /** sets the game server flag @param bGameServer true if it is a game server */ |
---|
[9406] | 41 | inline void setNodeType(int nodeType) { this->nodeType = nodeType; } |
---|
[6678] | 42 | |
---|
[9406] | 43 | /** @returns the maximum number of players for this server */ |
---|
| 44 | inline int getMaxPlayer() { return NetworkSettings::getInstance()->getMaxPlayer(); } |
---|
| 45 | |
---|
[6678] | 46 | /** @returns the hostID of the node */ |
---|
| 47 | inline int getHostID() { return this->hostID; } |
---|
| 48 | /** sets the hostID of this node @param hostID of the node */ |
---|
| 49 | inline void setHostID(int hostID) { this->hostID = hostID; } |
---|
| 50 | |
---|
| 51 | /** @returns the default synchronize stream */ |
---|
| 52 | inline NetworkStream* getDefaultSyncStream() { return this->defaultSyncStream; } |
---|
| 53 | /** sets the default sync stream @param defaultSyncStream the default sync stream */ |
---|
| 54 | inline void setDefaultSyncStream(NetworkStream* defaultSyncStream) { this->defaultSyncStream = defaultSyncStream; } |
---|
| 55 | |
---|
| 56 | |
---|
| 57 | private: |
---|
| 58 | SharedNetworkData(); |
---|
| 59 | |
---|
| 60 | |
---|
| 61 | private: |
---|
| 62 | int newUniqueID; //!< next uniqueID |
---|
[9406] | 63 | int nodeType; //!< saves the node type here |
---|
| 64 | |
---|
[6678] | 65 | int hostID; //!< The Host-ID of the Manager |
---|
| 66 | NetworkStream* defaultSyncStream; //!< default synchronize NetworkStream |
---|
| 67 | |
---|
| 68 | static SharedNetworkData* singletonRef; //!< Pointer to the only instance of this Class |
---|
| 69 | |
---|
| 70 | }; |
---|
| 71 | |
---|
| 72 | |
---|
| 73 | |
---|
| 74 | #endif /* _SHARED_NETWORK_DATA */ |
---|