![]() |
Shadowrun: Awakened 29 September 2011 - Build 871
|
00001 00002 00003 00004 00005 00006 00007 00008 00009 #ifndef __NETWORK_TYPES_H 00010 #define __NETWORK_TYPES_H 00011 00012 #include "RakNetDefines.h" 00013 #include "NativeTypes.h" 00014 #include "RakNetTime.h" 00015 #include "Export.h" 00016 #include "SocketIncludes.h" 00017 #include "WindowsIncludes.h" 00018 #include "XBox360Includes.h" 00019 00020 00021 00022 00023 00024 namespace RakNet { 00026 class RakPeerInterface; 00027 class BitStream; 00028 struct Packet; 00029 00030 enum StartupResult 00031 { 00032 RAKNET_STARTED, 00033 RAKNET_ALREADY_STARTED, 00034 INVALID_SOCKET_DESCRIPTORS, 00035 INVALID_MAX_CONNECTIONS, 00036 SOCKET_FAMILY_NOT_SUPPORTED, 00037 SOCKET_PORT_ALREADY_IN_USE, 00038 SOCKET_FAILED_TO_BIND, 00039 SOCKET_FAILED_TEST_SEND, 00040 PORT_CANNOT_BE_ZERO, 00041 FAILED_TO_CREATE_NETWORK_THREAD, 00042 STARTUP_OTHER_FAILURE, 00043 }; 00044 00045 00046 enum ConnectionAttemptResult 00047 { 00048 CONNECTION_ATTEMPT_STARTED, 00049 INVALID_PARAMETER, 00050 CANNOT_RESOLVE_DOMAIN_NAME, 00051 ALREADY_CONNECTED_TO_ENDPOINT, 00052 CONNECTION_ATTEMPT_ALREADY_IN_PROGRESS, 00053 SECURITY_INITIALIZATION_FAILED 00054 }; 00055 00057 enum ConnectionState 00058 { 00060 IS_PENDING, 00062 IS_CONNECTING, 00064 IS_CONNECTED, 00066 IS_DISCONNECTING, 00068 IS_SILENTLY_DISCONNECTING, 00070 IS_DISCONNECTED, 00072 IS_NOT_CONNECTED, 00073 }; 00074 00076 #define BITS_TO_BYTES(x) (((x)+7)>>3) 00077 #define BYTES_TO_BITS(x) ((x)<<3) 00078 00080 typedef unsigned char UniqueIDType; 00081 typedef unsigned short SystemIndex; 00082 typedef unsigned char RPCIndex; 00083 const int MAX_RPC_MAP_SIZE=((RPCIndex)-1)-1; 00084 const int UNDEFINED_RPC_INDEX=((RPCIndex)-1); 00085 00087 typedef unsigned char MessageID; 00088 00089 typedef uint32_t BitSize_t; 00090 00091 #if defined(_MSC_VER) && _MSC_VER > 0 00092 #define PRINTF_64_BIT_MODIFIER "I64" 00093 #else 00094 #define PRINTF_64_BIT_MODIFIER "ll" 00095 #endif 00096 00098 enum PublicKeyMode 00099 { 00101 PKM_INSECURE_CONNECTION, 00102 00105 PKM_ACCEPT_ANY_PUBLIC_KEY, 00106 00109 PKM_USE_KNOWN_PUBLIC_KEY, 00110 00116 PKM_USE_TWO_WAY_AUTHENTICATION 00117 }; 00118 00120 struct RAK_DLL_EXPORT PublicKey 00121 { 00123 PublicKeyMode publicKeyMode; 00124 00126 char *remoteServerPublicKey; 00127 00129 char *myPublicKey; 00130 00132 char *myPrivateKey; 00133 }; 00134 00136 struct RAK_DLL_EXPORT SocketDescriptor 00137 { 00138 SocketDescriptor(); 00139 SocketDescriptor(unsigned short _port, const char *_hostAddress); 00140 00142 unsigned short port; 00143 00145 char hostAddress[32]; 00146 00153 short socketFamily; 00154 00155 00156 00157 00158 00159 00160 00161 00162 00163 unsigned short remotePortRakNetWasStartedOn_PS3_PSP2; 00164 00166 unsigned int extraSocketOptions; 00167 }; 00168 00169 extern bool NonNumericHostString( const char *host ); 00170 00176 struct RAK_DLL_EXPORT SystemAddress 00177 { 00179 SystemAddress(); 00180 SystemAddress(const char *str); 00181 SystemAddress(const char *str, unsigned short port); 00182 00183 00184 00185 00186 00187 00188 00190 union// In6OrIn4 00191 { 00192 #if RAKNET_SUPPORT_IPV6==1 00193 struct sockaddr_in6 addr6; 00194 #endif 00195 00196 struct sockaddr_in addr4; 00197 } address; 00198 00200 unsigned short debugPort; 00201 00203 static int size(void); 00204 00206 static unsigned long ToInteger( const SystemAddress &sa ); 00207 00210 unsigned char GetIPVersion(void) const; 00211 00214 unsigned int GetIPPROTO(void) const; 00215 00217 void SetToLoopback(void); 00218 00221 void SetToLoopback(unsigned char ipVersion); 00222 00224 bool IsLoopback(void) const; 00225 00226 // Return the systemAddress as a string in the format <IP>|<Port> 00227 // Returns a static string 00228 // NOT THREADSAFE 00229 // portDelineator should not be '.', ':', '%', '-', '/', a number, or a-f 00230 const char *ToString(bool writePort=true, char portDelineator='|') const; 00231 00232 // Return the systemAddress as a string in the format <IP>|<Port> 00233 // dest must be large enough to hold the output 00234 // portDelineator should not be '.', ':', '%', '-', '/', a number, or a-f 00235 // THREADSAFE 00236 void ToString(bool writePort, char *dest, char portDelineator='|') const; 00237 00245 bool FromString(const char *str, char portDelineator='|', int ipVersion=0); 00246 00248 bool FromStringExplicitPort(const char *str, unsigned short port, int ipVersion=0); 00249 00251 void CopyPort( const SystemAddress& right ); 00252 00254 bool EqualsExcludingPort( const SystemAddress& right ) const; 00255 00257 unsigned short GetPort(void) const; 00258 00260 unsigned short GetPortNetworkOrder(void) const; 00261 00263 void SetPort(unsigned short s); 00264 00266 void SetPortNetworkOrder(unsigned short s); 00267 00269 void SetBinaryAddress(const char *str, char portDelineator=':'); 00271 void ToString_Old(bool writePort, char *dest, char portDelineator=':') const; 00272 00274 void FixForIPVersion(const SystemAddress &boundAddressToSocket); 00275 00276 SystemAddress& operator = ( const SystemAddress& input ); 00277 bool operator==( const SystemAddress& right ) const; 00278 bool operator!=( const SystemAddress& right ) const; 00279 bool operator > ( const SystemAddress& right ) const; 00280 bool operator < ( const SystemAddress& right ) const; 00281 00283 SystemIndex systemIndex; 00284 00285 private: 00286 00287 #if RAKNET_SUPPORT_IPV6==1 00288 void ToString_New(bool writePort, char *dest, char portDelineator) const; 00289 #endif 00290 }; 00291 00294 struct RAK_DLL_EXPORT RakNetGUID 00295 { 00296 RakNetGUID(); 00297 explicit RakNetGUID(uint64_t _g) {g=_g; systemIndex=(SystemIndex)-1;} 00298 // uint32_t g[6]; 00299 uint64_t g; 00300 00301 // Return the GUID as a string 00302 // Returns a static string 00303 // NOT THREADSAFE 00304 const char *ToString(void) const; 00305 00306 // Return the GUID as a string 00307 // dest must be large enough to hold the output 00308 // THREADSAFE 00309 void ToString(char *dest) const; 00310 00311 bool FromString(const char *source); 00312 00313 static unsigned long ToUint32( const RakNetGUID &g ); 00314 00315 RakNetGUID& operator = ( const RakNetGUID& input ) 00316 { 00317 g=input.g; 00318 systemIndex=input.systemIndex; 00319 return *this; 00320 } 00321 00322 // Used internally for fast lookup. Optional (use -1 to do regular lookup). Don't transmit this. 00323 SystemIndex systemIndex; 00324 static int size() {return (int) sizeof(uint64_t);} 00325 00326 bool operator==( const RakNetGUID& right ) const; 00327 bool operator!=( const RakNetGUID& right ) const; 00328 bool operator > ( const RakNetGUID& right ) const; 00329 bool operator < ( const RakNetGUID& right ) const; 00330 }; 00331 00333 //const SystemAddress UNASSIGNED_SYSTEM_ADDRESS = 00334 //{ 00335 // 0xFFFFFFFF, 0xFFFF 00336 //}; 00337 #ifndef SWIG 00338 const SystemAddress UNASSIGNED_SYSTEM_ADDRESS; 00339 const RakNetGUID UNASSIGNED_RAKNET_GUID((uint64_t)-1); 00340 #endif 00341 //{ 00342 // {0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF} 00343 // 0xFFFFFFFFFFFFFFFF 00344 //}; 00345 00346 00347 struct RAK_DLL_EXPORT AddressOrGUID 00348 { 00349 RakNetGUID rakNetGuid; 00350 SystemAddress systemAddress; 00351 00352 SystemIndex GetSystemIndex(void) const {if (rakNetGuid!=UNASSIGNED_RAKNET_GUID) return rakNetGuid.systemIndex; else return systemAddress.systemIndex;} 00353 bool IsUndefined(void) const {return rakNetGuid==UNASSIGNED_RAKNET_GUID && systemAddress==UNASSIGNED_SYSTEM_ADDRESS;} 00354 void SetUndefined(void) {rakNetGuid=UNASSIGNED_RAKNET_GUID; systemAddress=UNASSIGNED_SYSTEM_ADDRESS;} 00355 static unsigned long ToInteger( const AddressOrGUID &aog ); 00356 const char *ToString(bool writePort=true) const; 00357 void ToString(bool writePort, char *dest) const; 00358 00359 AddressOrGUID() {} 00360 AddressOrGUID( const AddressOrGUID& input ) 00361 { 00362 rakNetGuid=input.rakNetGuid; 00363 systemAddress=input.systemAddress; 00364 } 00365 AddressOrGUID( const SystemAddress& input ) 00366 { 00367 rakNetGuid=UNASSIGNED_RAKNET_GUID; 00368 systemAddress=input; 00369 } 00370 AddressOrGUID( Packet *packet ); 00371 AddressOrGUID( const RakNetGUID& input ) 00372 { 00373 rakNetGuid=input; 00374 systemAddress=UNASSIGNED_SYSTEM_ADDRESS; 00375 } 00376 AddressOrGUID& operator = ( const AddressOrGUID& input ) 00377 { 00378 rakNetGuid=input.rakNetGuid; 00379 systemAddress=input.systemAddress; 00380 return *this; 00381 } 00382 00383 AddressOrGUID& operator = ( const SystemAddress& input ) 00384 { 00385 rakNetGuid=UNASSIGNED_RAKNET_GUID; 00386 systemAddress=input; 00387 return *this; 00388 } 00389 00390 AddressOrGUID& operator = ( const RakNetGUID& input ) 00391 { 00392 rakNetGuid=input; 00393 systemAddress=UNASSIGNED_SYSTEM_ADDRESS; 00394 return *this; 00395 } 00396 00397 inline bool operator==( const AddressOrGUID& right ) const {return (rakNetGuid!=UNASSIGNED_RAKNET_GUID && rakNetGuid==right.rakNetGuid) || (systemAddress!=UNASSIGNED_SYSTEM_ADDRESS && systemAddress==right.systemAddress);} 00398 }; 00399 00400 typedef uint64_t NetworkID; 00401 00403 struct Packet 00404 { 00406 SystemAddress systemAddress; 00407 00411 RakNetGUID guid; 00412 00414 unsigned int length; 00415 00417 BitSize_t bitSize; 00418 00420 unsigned char* data; 00421 00424 bool deleteData; 00425 00428 bool wasGeneratedLocally; 00429 }; 00430 00432 const SystemIndex UNASSIGNED_PLAYER_INDEX = 65535; 00433 00435 const NetworkID UNASSIGNED_NETWORK_ID = (uint64_t) -1; 00436 00437 const int PING_TIMES_ARRAY_SIZE = 5; 00438 00439 struct RAK_DLL_EXPORT uint24_t 00440 { 00441 uint32_t val; 00442 00443 uint24_t() {} 00444 inline operator uint32_t() { return val; } 00445 inline operator uint32_t() const { return val; } 00446 00447 inline uint24_t(const uint24_t& a) {val=a.val;} 00448 inline uint24_t operator++() {++val; val&=0x00FFFFFF; return *this;} 00449 inline uint24_t operator--() {--val; val&=0x00FFFFFF; return *this;} 00450 inline uint24_t operator++(int) {uint24_t temp(val); ++val; val&=0x00FFFFFF; return temp;} 00451 inline uint24_t operator--(int) {uint24_t temp(val); --val; val&=0x00FFFFFF; return temp;} 00452 inline uint24_t operator&(const uint24_t& a) {return uint24_t(val&a.val);} 00453 inline uint24_t& operator=(const uint24_t& a) { val=a.val; return *this; } 00454 inline uint24_t& operator+=(const uint24_t& a) { val+=a.val; val&=0x00FFFFFF; return *this; } 00455 inline uint24_t& operator-=(const uint24_t& a) { val-=a.val; val&=0x00FFFFFF; return *this; } 00456 inline bool operator==( const uint24_t& right ) const {return val==right.val;} 00457 inline bool operator!=( const uint24_t& right ) const {return val!=right.val;} 00458 inline bool operator > ( const uint24_t& right ) const {return val>right.val;} 00459 inline bool operator < ( const uint24_t& right ) const {return val<right.val;} 00460 inline const uint24_t operator+( const uint24_t &other ) const { return uint24_t(val+other.val); } 00461 inline const uint24_t operator-( const uint24_t &other ) const { return uint24_t(val-other.val); } 00462 inline const uint24_t operator/( const uint24_t &other ) const { return uint24_t(val/other.val); } 00463 inline const uint24_t operator*( const uint24_t &other ) const { return uint24_t(val*other.val); } 00464 00465 inline uint24_t(const uint32_t& a) {val=a; val&=0x00FFFFFF;} 00466 inline uint24_t operator&(const uint32_t& a) {return uint24_t(val&a);} 00467 inline uint24_t& operator=(const uint32_t& a) { val=a; val&=0x00FFFFFF; return *this; } 00468 inline uint24_t& operator+=(const uint32_t& a) { val+=a; val&=0x00FFFFFF; return *this; } 00469 inline uint24_t& operator-=(const uint32_t& a) { val-=a; val&=0x00FFFFFF; return *this; } 00470 inline bool operator==( const uint32_t& right ) const {return val==(right&0x00FFFFFF);} 00471 inline bool operator!=( const uint32_t& right ) const {return val!=(right&0x00FFFFFF);} 00472 inline bool operator > ( const uint32_t& right ) const {return val>(right&0x00FFFFFF);} 00473 inline bool operator < ( const uint32_t& right ) const {return val<(right&0x00FFFFFF);} 00474 inline const uint24_t operator+( const uint32_t &other ) const { return uint24_t(val+other); } 00475 inline const uint24_t operator-( const uint32_t &other ) const { return uint24_t(val-other); } 00476 inline const uint24_t operator/( const uint32_t &other ) const { return uint24_t(val/other); } 00477 inline const uint24_t operator*( const uint32_t &other ) const { return uint24_t(val*other); } 00478 }; 00479 00480 } // namespace RakNet 00481 00482 #endif
Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.