[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 | |
---|
[9494] | 16 | |
---|
[6678] | 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 */ |
---|
[9494] | 30 | inline int getNewUniqueID() { return ( isMasterServer())?this->newUniqueID++:-1; } |
---|
[9406] | 31 | /** sets the @param newUniqueID: the new offset for the next unique id */ |
---|
| 32 | inline void setNewUniqueID(int newUniqueID) { this->newUniqueID = newUniqueID; } |
---|
[6678] | 33 | |
---|
[9494] | 34 | /** sets the game server flag @param bGameServer true if it is a game server */ |
---|
| 35 | inline void setNodeType(int nodeType) { this->nodeType = nodeType; } |
---|
[9406] | 36 | /** @returns true is this node is a master server */ |
---|
| 37 | inline bool isMasterServer() { return this->nodeType == NET_MASTER_SERVER; } |
---|
| 38 | /** @returns true is this node is a proxy server */ |
---|
[9494] | 39 | inline bool isProxyServerActive() { return this->nodeType == NET_PROXY_SERVER_ACTIVE; } |
---|
[9406] | 40 | /** @returns true is this node is a client*/ |
---|
| 41 | inline bool isClient() { return this->nodeType == NET_CLIENT; } |
---|
[6678] | 42 | |
---|
[9494] | 43 | /** @return true if this user is connected to the local host */ |
---|
| 44 | bool isUserLocal( int userID); |
---|
| 45 | /** @returns true if this user is a master server */ |
---|
| 46 | bool isUserMasterServer( int userID ); |
---|
| 47 | /** @returns true if this user is a proxy server */ |
---|
| 48 | bool isUserProxyServerActive( int userID ); |
---|
| 49 | /** @returns true if this user is a client */ |
---|
| 50 | bool isUserClient( int userID ); |
---|
| 51 | |
---|
| 52 | |
---|
[9406] | 53 | /** @returns the maximum number of players for this server */ |
---|
| 54 | inline int getMaxPlayer() { return NetworkSettings::getInstance()->getMaxPlayer(); } |
---|
| 55 | |
---|
[6678] | 56 | /** @returns the hostID of the node */ |
---|
| 57 | inline int getHostID() { return this->hostID; } |
---|
| 58 | /** sets the hostID of this node @param hostID of the node */ |
---|
| 59 | inline void setHostID(int hostID) { this->hostID = hostID; } |
---|
| 60 | |
---|
| 61 | /** @returns the default synchronize stream */ |
---|
| 62 | inline NetworkStream* getDefaultSyncStream() { return this->defaultSyncStream; } |
---|
| 63 | /** sets the default sync stream @param defaultSyncStream the default sync stream */ |
---|
| 64 | inline void setDefaultSyncStream(NetworkStream* defaultSyncStream) { this->defaultSyncStream = defaultSyncStream; } |
---|
| 65 | |
---|
| 66 | |
---|
| 67 | private: |
---|
| 68 | SharedNetworkData(); |
---|
| 69 | |
---|
| 70 | |
---|
| 71 | private: |
---|
| 72 | int newUniqueID; //!< next uniqueID |
---|
[9406] | 73 | int nodeType; //!< saves the node type here |
---|
| 74 | |
---|
[6678] | 75 | int hostID; //!< The Host-ID of the Manager |
---|
| 76 | NetworkStream* defaultSyncStream; //!< default synchronize NetworkStream |
---|
| 77 | |
---|
| 78 | static SharedNetworkData* singletonRef; //!< Pointer to the only instance of this Class |
---|
| 79 | |
---|
| 80 | }; |
---|
| 81 | |
---|
| 82 | |
---|
| 83 | |
---|
| 84 | #endif /* _SHARED_NETWORK_DATA */ |
---|