1 /// Transcription of steamtypes.h to D.
2 ///
3 /// Copyright: Valve Corporation, all rights reserved
4 module steam_gns.stypes;
5 
6 @nogc nothrow extern (C++) align(4):
7 
8 // probably unnecessary, i confused this with steamnetworkingtypes.h
9 
10 alias intp = ptrdiff_t;
11 alias uintp = size_t;
12 
13 alias AppId_t = uint;
14 enum AppId_t k_uAppIdInvalid = 0x0;
15 
16 // AppIds and DepotIDs also presently share the same namespace
17 alias DepotId_t = uint;
18 enum DepotId_t k_uDepotIdInvalid = 0x0;
19 
20 // RTime32.  Seconds elapsed since Jan 1 1970, i.e. unix timestamp.
21 // It's the same as time_t, but it is always 32-bit and unsigned.
22 alias RTime32 = uint;
23 
24 // handle to a Steam API call
25 alias SteamAPICall_t = ulong;
26 enum SteamAPICall_t k_uAPICallInvalid = 0x0;
27 
28 alias AccountID_t = uint;
29 
30 // Party Beacon ID
31 alias PartyBeaconID_t = ulong;
32 enum PartyBeaconID_t k_ulPartyBeaconIdInvalid = 0;
33 
34 enum ESteamIPType {
35     k_ESteamIPTypeIPv4 = 0,
36     k_ESteamIPTypeIPv6 = 1,
37 }
38 
39 struct SteamIPAddress_t {
40 
41     align(1):
42 
43     union {
44 
45         uint          m_unIPv4;       // Host order
46         ubyte[16]     m_rgubIPv6;     // Network order! Same as inaddr_in6.  (0011:2233:4455:6677:8899:aabb:ccdd:eeff)
47 
48         // Internal use only
49         ulong[2]         m_ipv6Qword; // big endian
50     };
51 
52     ESteamIPType m_eType;
53 
54     bool IsSet() const {
55         if (ESteamIPType.k_ESteamIPTypeIPv4 == m_eType) {
56             return m_unIPv4 != 0;
57         }
58         else {
59             return m_ipv6Qword[0] != 0 || m_ipv6Qword[1] != 0;
60         }
61     }
62 
63     static SteamIPAddress_t IPv4Any() {
64         SteamIPAddress_t ipOut;
65         ipOut.m_eType = ESteamIPType.k_ESteamIPTypeIPv4;
66         ipOut.m_unIPv4 = 0;
67 
68         return ipOut;
69     }
70 
71     static SteamIPAddress_t IPv6Any() {
72         SteamIPAddress_t ipOut;
73         ipOut.m_eType = ESteamIPType.k_ESteamIPTypeIPv6;
74         ipOut.m_ipv6Qword[0] = 0;
75         ipOut.m_ipv6Qword[1] = 0;
76 
77         return ipOut;
78     }
79 
80     static SteamIPAddress_t IPv4Loopback() {
81         SteamIPAddress_t ipOut;
82         ipOut.m_eType = ESteamIPType.k_ESteamIPTypeIPv4;
83         ipOut.m_unIPv4 = 0x7f000001;
84 
85         return ipOut;
86     }
87 
88     static SteamIPAddress_t IPv6Loopback() {
89         SteamIPAddress_t ipOut;
90         ipOut.m_eType = ESteamIPType.k_ESteamIPTypeIPv6;
91         ipOut.m_ipv6Qword[0] = 0;
92         ipOut.m_ipv6Qword[1] = 0;
93         ipOut.m_rgubIPv6[15] = 1;
94 
95         return ipOut;
96     }
97 }