SLikeNet 0.1.3

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
types.h
Go to the documentation of this file.
1 /*
2 * Original work: Copyright (c) 2014, Oculus VR, Inc.
3 * All rights reserved.
4 *
5 * This source code is licensed under the BSD-style license found in the
6 * RakNet License.txt file in the licenses directory of this source tree. An additional grant
7 * of patent rights can be found in the RakNet Patents.txt file in the same directory.
8 *
9 *
10 * Modified work: Copyright (c) 2016-2018, SLikeSoft UG (haftungsbeschränkt)
11 *
12 * This source code was modified by SLikeSoft. Modifications are licensed under the MIT-style
13 * license found in the license.txt file in the root directory of this source tree.
14 */
15
19
20
21 #ifndef __NETWORK_TYPES_H
22 #define __NETWORK_TYPES_H
23
24
25
26
27
28 #include "defines.h"
29 #include "NativeTypes.h"
30 #include "time.h"
31 #include "Export.h"
32 #include "WindowsIncludes.h"
33 #include "XBox360Includes.h"
34 #include "SocketIncludes.h"
35
36
37
38
39
40 namespace SLNet {
42 class RakPeerInterface;
43 class BitStream;
44 struct Packet;
45
46 enum StartupResult
47 {
48 RAKNET_STARTED,
49 RAKNET_ALREADY_STARTED,
50 INVALID_SOCKET_DESCRIPTORS,
51 INVALID_MAX_CONNECTIONS,
52 SOCKET_FAMILY_NOT_SUPPORTED,
53 SOCKET_PORT_ALREADY_IN_USE,
54 SOCKET_FAILED_TO_BIND,
55 SOCKET_FAILED_TEST_SEND,
56 PORT_CANNOT_BE_ZERO,
57 FAILED_TO_CREATE_NETWORK_THREAD,
58 COULD_NOT_GENERATE_GUID,
59 STARTUP_OTHER_FAILURE
60 };
61
62
63 enum ConnectionAttemptResult
64 {
65 CONNECTION_ATTEMPT_STARTED,
66 INVALID_PARAMETER,
67 CANNOT_RESOLVE_DOMAIN_NAME,
68 ALREADY_CONNECTED_TO_ENDPOINT,
69 CONNECTION_ATTEMPT_ALREADY_IN_PROGRESS,
70 SECURITY_INITIALIZATION_FAILED
71 };
72
74 enum ConnectionState
75 {
77 IS_PENDING,
79 IS_CONNECTING,
81 IS_CONNECTED,
83 IS_DISCONNECTING,
85 IS_SILENTLY_DISCONNECTING,
87 IS_DISCONNECTED,
89 IS_NOT_CONNECTED
90 };
91
93 #define BITS_TO_BYTES(x) (((x)+7)>>3)
94 #define BYTES_TO_BITS(x) ((x)<<3)
95
97 typedef unsigned char UniqueIDType;
98 typedef unsigned short SystemIndex;
99 typedef unsigned char RPCIndex;
100 const int MAX_RPC_MAP_SIZE=((RPCIndex)-1)-1;
101 const int UNDEFINED_RPC_INDEX=((RPCIndex)-1);
102
104 typedef unsigned char MessageID;
105
106 typedef uint32_t BitSize_t;
107
108 #define PRINTF_64_BIT_MODIFIER "ll"
109
111 enum PublicKeyMode
112 {
114 PKM_INSECURE_CONNECTION,
115
118 PKM_ACCEPT_ANY_PUBLIC_KEY,
119
122 PKM_USE_KNOWN_PUBLIC_KEY,
123
129 PKM_USE_TWO_WAY_AUTHENTICATION
130 };
131
133 struct RAK_DLL_EXPORT PublicKey
134 {
136 PublicKeyMode publicKeyMode;
137
139 char *remoteServerPublicKey;
140
142 char *myPublicKey;
143
145 char *myPrivateKey;
146 };
147
149 struct RAK_DLL_EXPORT SocketDescriptor
150 {
151 SocketDescriptor();
152 SocketDescriptor(unsigned short _port, const char *_hostAddress);
153
155 unsigned short port;
156
158 char hostAddress[32];
159
166 short socketFamily;
167
168
169
170
171
172
173
174
175
176 unsigned short remotePortRakNetWasStartedOn_PS3_PSP2;
177
178 // Required for Google chrome
179 _PP_Instance_ chromeInstance;
180
181 // Set to true to use a blocking socket (default, do not change unless you have a reason to)
182 bool blockingSocket;
183
185 unsigned int extraSocketOptions;
186 };
187
188 extern bool NonNumericHostString( const char *host );
189
195 struct RAK_DLL_EXPORT SystemAddress
196 {
198 SystemAddress();
199 SystemAddress(const char *str);
200 SystemAddress(const char *str, unsigned short port);
201
202
203
204
205
206
207
208
209
210
212 union// In6OrIn4
213 {
214 #if RAKNET_SUPPORT_IPV6==1
215 struct sockaddr_storage sa_stor;
216 sockaddr_in6 addr6;
217 #endif
218
219 sockaddr_in addr4;
220 } address;
221
223 unsigned short debugPort;
224
226 static int size(void);
227
229 static unsigned long ToInteger( const SystemAddress &sa );
230
233 unsigned char GetIPVersion(void) const;
234
237 unsigned int GetIPPROTO(void) const;
238
240 void SetToLoopback(void);
241
244 void SetToLoopback(unsigned char ipVersion);
245
247 bool IsLoopback(void) const;
248
249 // Return the systemAddress as a string in the format <IP>|<Port>
250 // Returns a static string
251 // NOT THREADSAFE
252 // portDelineator should not be '.', ':', '%', '-', '/', a number, or a-f
253 const char *ToString(bool writePort=true, char portDelineator='|') const;
254
255 // Return the systemAddress as a string in the format <IP>|<Port>
256 // dest must be large enough to hold the output
257 // portDelineator should not be '.', ':', '%', '-', '/', a number, or a-f
258 // THREADSAFE
259 void ToString(bool writePort, char *dest, char portDelineator = '|') const;
260 void ToString(bool writePort, char *dest, size_t destLength, char portDelineator='|') const;
261
269 bool FromString(const char *str, char portDelineator='|', int ipVersion=0);
270
272 bool FromStringExplicitPort(const char *str, unsigned short port, int ipVersion=0);
273
275 void CopyPort( const SystemAddress& right );
276
278 bool EqualsExcludingPort( const SystemAddress& right ) const;
279
281 unsigned short GetPort(void) const;
282
284 unsigned short GetPortNetworkOrder(void) const;
285
288 void SetPortHostOrder(unsigned short s);
289
291 void SetPortNetworkOrder(unsigned short s);
292
294 bool SetBinaryAddress(const char *str, char portDelineator=':');
296 void ToString_Old(bool writePort, char *dest, char portDelineator = ':') const;
297 void ToString_Old(bool writePort, char *dest, size_t destLength, char portDelineator = ':') const;
298
300 void FixForIPVersion(const SystemAddress &boundAddressToSocket);
301
302 bool IsLANAddress(void);
303
304 SystemAddress& operator = ( const SystemAddress& input );
305 bool operator==( const SystemAddress& right ) const;
306 bool operator!=( const SystemAddress& right ) const;
307 bool operator > ( const SystemAddress& right ) const;
308 bool operator < ( const SystemAddress& right ) const;
309
311 SystemIndex systemIndex;
312
313 private:
314
315 #if RAKNET_SUPPORT_IPV6==1
316 void ToString_New(bool writePort, char *dest, char portDelineator) const;
317 void ToString_New(bool writePort, char *dest, size_t destLength, char portDelineator) const;
318 #endif
319 };
320
323 struct RAK_DLL_EXPORT RakNetGUID
324 {
325 RakNetGUID();
326 explicit RakNetGUID(uint64_t _g) {g=_g; systemIndex=(SystemIndex)-1;}
327 // uint32_t g[6];
328 uint64_t g;
329
330 // Return the GUID as a string
331 // Returns a static string
332 // NOT THREADSAFE
333 const char *ToString(void) const;
334
335 // Return the GUID as a string
336 // dest must be large enough to hold the output
337 // THREADSAFE
338 void ToString(char *dest) const;
339 void ToString(char *dest, size_t destSize) const;
340
341 bool FromString(const char *source);
342
343 static unsigned long ToUint32( const RakNetGUID &g );
344
345 RakNetGUID& operator = ( const RakNetGUID& input )
346 {
347 g=input.g;
348 systemIndex=input.systemIndex;
349 return *this;
350 }
351
352 // Used internally for fast lookup. Optional (use -1 to do regular lookup). Don't transmit this.
353 SystemIndex systemIndex;
354 static int size() {return (int) sizeof(uint64_t);}
355
356 bool operator==( const RakNetGUID& right ) const;
357 bool operator!=( const RakNetGUID& right ) const;
358 bool operator > ( const RakNetGUID& right ) const;
359 bool operator < ( const RakNetGUID& right ) const;
360 };
361
363 //const SystemAddress UNASSIGNED_SYSTEM_ADDRESS =
364 //{
365 // 0xFFFFFFFF, 0xFFFF
366 //};
367 #ifndef SWIG
368 const SystemAddress UNASSIGNED_SYSTEM_ADDRESS;
369 const RakNetGUID UNASSIGNED_RAKNET_GUID((uint64_t)-1);
370 #endif
371 //{
372 // {0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF}
373 // 0xFFFFFFFFFFFFFFFF
374 //};
375
376
377 struct RAK_DLL_EXPORT AddressOrGUID
378 {
379 RakNetGUID rakNetGuid;
380 SystemAddress systemAddress;
381
382 SystemIndex GetSystemIndex(void) const {if (rakNetGuid!=UNASSIGNED_RAKNET_GUID) return rakNetGuid.systemIndex; else return systemAddress.systemIndex;}
383 bool IsUndefined(void) const {return rakNetGuid==UNASSIGNED_RAKNET_GUID && systemAddress==UNASSIGNED_SYSTEM_ADDRESS;}
384 void SetUndefined(void) {rakNetGuid=UNASSIGNED_RAKNET_GUID; systemAddress=UNASSIGNED_SYSTEM_ADDRESS;}
385 static unsigned long ToInteger( const AddressOrGUID &aog );
386 const char *ToString(bool writePort=true) const;
387 void ToString(bool writePort, char *dest) const;
388 void ToString(bool writePort, char *dest, size_t destLength) const;
389
390 AddressOrGUID() {}
391 AddressOrGUID( const AddressOrGUID& input )
392 {
393 rakNetGuid=input.rakNetGuid;
394 systemAddress=input.systemAddress;
395 }
396 AddressOrGUID( const SystemAddress& input )
397 {
398 rakNetGuid=UNASSIGNED_RAKNET_GUID;
399 systemAddress=input;
400 }
401 AddressOrGUID( Packet *packet );
402 AddressOrGUID( const RakNetGUID& input )
403 {
404 rakNetGuid=input;
405 systemAddress=UNASSIGNED_SYSTEM_ADDRESS;
406 }
407 AddressOrGUID& operator = ( const AddressOrGUID& input )
408 {
409 rakNetGuid=input.rakNetGuid;
410 systemAddress=input.systemAddress;
411 return *this;
412 }
413
414 AddressOrGUID& operator = ( const SystemAddress& input )
415 {
416 rakNetGuid=UNASSIGNED_RAKNET_GUID;
417 systemAddress=input;
418 return *this;
419 }
420
421 AddressOrGUID& operator = ( const RakNetGUID& input )
422 {
423 rakNetGuid=input;
424 systemAddress=UNASSIGNED_SYSTEM_ADDRESS;
425 return *this;
426 }
427
428 inline bool operator==( const AddressOrGUID& right ) const {return (rakNetGuid!=UNASSIGNED_RAKNET_GUID && rakNetGuid==right.rakNetGuid) || (systemAddress!=UNASSIGNED_SYSTEM_ADDRESS && systemAddress==right.systemAddress);}
429 };
430
431 typedef uint64_t NetworkID;
432
434 struct Packet
435 {
437 SystemAddress systemAddress;
438
442 RakNetGUID guid;
443
445 unsigned int length;
446
448 BitSize_t bitSize;
449
451 unsigned char* data;
452
455 bool deleteData;
456
459 bool wasGeneratedLocally;
460 };
461
463 const SystemIndex UNASSIGNED_PLAYER_INDEX = 65535;
464
466 const NetworkID UNASSIGNED_NETWORK_ID = (uint64_t) -1;
467
468 const int PING_TIMES_ARRAY_SIZE = 5;
469
470 struct RAK_DLL_EXPORT uint24_t
471 {
472 uint32_t val;
473
474 uint24_t() {}
475 inline operator uint32_t() { return val; }
476 inline operator uint32_t() const { return val; }
477
478 inline uint24_t(const uint24_t& a) {val=a.val;}
479 inline uint24_t operator++() {++val; val&=0x00FFFFFF; return *this;}
480 inline uint24_t operator--() {--val; val&=0x00FFFFFF; return *this;}
481 inline uint24_t operator++(int) {uint24_t temp(val); ++val; val&=0x00FFFFFF; return temp;}
482 inline uint24_t operator--(int) {uint24_t temp(val); --val; val&=0x00FFFFFF; return temp;}
483 inline uint24_t operator&(const uint24_t& a) {return uint24_t(val&a.val);}
484 inline uint24_t& operator=(const uint24_t& a) { val=a.val; return *this; }
485 inline uint24_t& operator+=(const uint24_t& a) { val+=a.val; val&=0x00FFFFFF; return *this; }
486 inline uint24_t& operator-=(const uint24_t& a) { val-=a.val; val&=0x00FFFFFF; return *this; }
487 inline bool operator==( const uint24_t& right ) const {return val==right.val;}
488 inline bool operator!=( const uint24_t& right ) const {return val!=right.val;}
489 inline bool operator > ( const uint24_t& right ) const {return val>right.val;}
490 inline bool operator < ( const uint24_t& right ) const {return val<right.val;}
491 inline const uint24_t operator+( const uint24_t &other ) const { return uint24_t(val+other.val); }
492 inline const uint24_t operator-( const uint24_t &other ) const { return uint24_t(val-other.val); }
493 inline const uint24_t operator/( const uint24_t &other ) const { return uint24_t(val/other.val); }
494 inline const uint24_t operator*( const uint24_t &other ) const { return uint24_t(val*other.val); }
495
496 inline uint24_t(const uint32_t& a) {val=a; val&=0x00FFFFFF;}
497 inline uint24_t operator&(const uint32_t& a) {return uint24_t(val&a);}
498 inline uint24_t& operator=(const uint32_t& a) { val=a; val&=0x00FFFFFF; return *this; }
499 inline uint24_t& operator+=(const uint32_t& a) { val+=a; val&=0x00FFFFFF; return *this; }
500 inline uint24_t& operator-=(const uint32_t& a) { val-=a; val&=0x00FFFFFF; return *this; }
501 inline bool operator==( const uint32_t& right ) const {return val==(right&0x00FFFFFF);}
502 inline bool operator!=( const uint32_t& right ) const {return val!=(right&0x00FFFFFF);}
503 inline bool operator > ( const uint32_t& right ) const {return val>(right&0x00FFFFFF);}
504 inline bool operator < ( const uint32_t& right ) const {return val<(right&0x00FFFFFF);}
505 inline const uint24_t operator+( const uint32_t &other ) const { return uint24_t(val+other); }
506 inline const uint24_t operator-( const uint32_t &other ) const { return uint24_t(val-other); }
507 inline const uint24_t operator/( const uint32_t &other ) const { return uint24_t(val/other); }
508 inline const uint24_t operator*( const uint32_t &other ) const { return uint24_t(val*other); }
509 };
510
511 } // namespace SLNet
512
513 #endif