00001 00002 00003 00004 00005 00006 00007 00008 #ifndef __NETWORK_ID_MANAGER_H 00009 #define __NETWORK_ID_MANAGER_H 00010 00011 #include "DS_BinarySearchTree.h" 00012 #include "RakNetTypes.h" 00013 #include "Export.h" 00014 #include "RakMemoryOverride.h" 00015 #include "NetworkIDObject.h" 00016 00019 struct RAK_DLL_EXPORT NetworkIDNode 00020 { 00021 NetworkID networkID; 00022 NetworkIDObject *object; 00023 NetworkIDNode(); 00024 NetworkIDNode( NetworkID _networkID, NetworkIDObject *_object ); 00025 bool operator==( const NetworkIDNode& right ) const; 00026 bool operator > ( const NetworkIDNode& right ) const; 00027 bool operator < ( const NetworkIDNode& right ) const; 00028 }; 00029 00034 class RAK_DLL_EXPORT NetworkIDManager 00035 { 00036 public: 00037 NetworkIDManager(void); 00038 virtual ~NetworkIDManager(void); 00039 00045 void SetIsNetworkIDAuthority(bool isAuthority); 00046 00048 bool IsNetworkIDAuthority(void) const; 00049 00056 void SetExternalSystemAddress(SystemAddress systemAddress); 00057 SystemAddress GetExternalSystemAddress(void); 00058 00063 void SetGuid(RakNetGUID g); 00064 RakNetGUID GetGuid(void); 00065 00071 unsigned short GetSharedNetworkID( void ); 00072 00077 void SetSharedNetworkID( unsigned short i ); 00078 00081 NetworkIDObject* GET_BASE_OBJECT_FROM_ID( NetworkID x ); 00082 00086 void* GET_OBJECT_FROM_ID( NetworkID x ); 00087 00091 template <class returnType> 00092 returnType GET_OBJECT_FROM_ID(NetworkID x) { 00093 NetworkIDObject *nio = GET_BASE_OBJECT_FROM_ID(x); 00094 if (nio==0) 00095 return 0; 00096 if (nio->GetParent()) 00097 return (returnType) nio->GetParent(); 00098 return (returnType) nio; 00099 } 00100 00101 protected: 00102 RakNetGUID guid; 00103 // deprecated - use guid instead. This has the problem that it can be different between the LAN and the internet, or duplicated on different LANs 00104 SystemAddress externalSystemAddress; 00105 unsigned short sharedNetworkID; 00106 bool isNetworkIDAuthority; 00107 bool calledSetIsNetworkIDAuthority; 00108 friend class NetworkIDObject; 00109 00110 00111 #if ! defined(NETWORK_ID_USE_PTR_TABLE) || defined(NETWORK_ID_USE_HASH) 00112 00113 DataStructures::AVLBalancedBinarySearchTree<NetworkIDNode> IDTree; 00114 #else 00115 NetworkIDObject **IDArray; 00116 #endif 00117 }; 00118 00119 #endif