forked from seishun/SteamPP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
steam++.h
250 lines (210 loc) · 5.97 KB
/
steam++.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
#include <functional>
#include <map>
#include "steam_language/steam_language.h"
namespace Steam {
const struct {
const char* host;
std::uint16_t port;
} servers[] = {
{ "72.165.61.174", 27017 },
{ "72.165.61.174", 27018 },
{ "72.165.61.175", 27017 },
{ "72.165.61.175", 27018 },
{ "72.165.61.176", 27017 },
{ "72.165.61.176", 27018 },
{ "72.165.61.185", 27017 },
{ "72.165.61.185", 27018 },
{ "72.165.61.187", 27017 },
{ "72.165.61.187", 27018 },
{ "72.165.61.188", 27017 },
{ "72.165.61.188", 27018 },
// Inteliquent, Luxembourg, cm-[01-04].lux.valve.net
{ "146.66.152.12", 27017 },
{ "146.66.152.12", 27018 },
{ "146.66.152.12", 27019 },
{ "146.66.152.13", 27017 },
{ "146.66.152.13", 27018 },
{ "146.66.152.13", 27019 },
{ "146.66.152.14", 27017 },
{ "146.66.152.14", 27018 },
{ "146.66.152.14", 27019 },
{ "146.66.152.15", 27017 },
{ "146.66.152.15", 27018 },
{ "146.66.152.15", 27019 },
/* Highwinds, Netherlands (not live)
{ "81.171.115.5", 27017 },
{ "81.171.115.5", 27018 },
{ "81.171.115.5", 27019 },
{ "81.171.115.6", 27017 },
{ "81.171.115.6", 27018 },
{ "81.171.115.6", 27019 },
{ "81.171.115.7", 27017 },
{ "81.171.115.7", 27018 },
{ "81.171.115.7", 27019 },
{ "81.171.115.8", 27017 },
{ "81.171.115.8", 27018 },
{ "81.171.115.8", 27019 },*/
// Highwinds, Kaysville
{ "209.197.29.196", 27017 },
{ "209.197.29.197", 27017 },
/* Starhub, Singapore (non-optimal route)
{ "103.28.54.10", 27017 },
{ "103.28.54.11", 27017 }*/
};
struct SteamID {
SteamID(std::uint64_t = 0);
operator std::uint64_t() const;
union {
struct {
unsigned ID : 32;
unsigned instance : 20;
unsigned type : 4;
unsigned universe : 8;
};
std::uint64_t steamID64;
};
};
#pragma pack(push, 1)
struct ChatMember {
private:
enum Type : char {
None = 0,
String = 1,
Int32 = 2,
Float32 = 3,
Pointer = 4,
WideString = 5,
Color = 6,
UInt64 = 7,
End = 8
};
Type None_;
char MessageObject_[sizeof("MessageObject")];
Type UInt64_;
char steamid_[sizeof("steamid")];
public:
SteamID steamID;
private:
Type Int32_;
char Permissions_[sizeof("Permissions")];
public:
EChatPermission permissions;
private:
Type Int32__;
char Details_[sizeof("Details")];
public:
EClanPermission rank;
private:
Type End_;
Type End__;
};
#pragma pack(pop)
class SteamClient {
public:
/**
* @param write Called when SteamClient wants to send some data over the socket.
* Allocate a buffer of @a length bytes, then call @a fill with it, then send it.
* @param set_interval @a callback must be called every @a timeout seconds as long as the connection is alive.
*/
SteamClient(
std::function<void(std::size_t length, std::function<void(unsigned char* buffer)> fill)> write,
std::function<void(std::function<void()> callback, int timeout)> set_interval
);
~SteamClient();
/**
* Call when a connection has been established.
*
* @return The number of bytes SteamClient expects next.
*/
std::size_t connected();
/**
* Call when data has been received.
*
* @param buffer Must be of the length previously returned by #connected or #readable.
* @return The number of bytes SteamClient expects next.
*/
std::size_t readable(const unsigned char* buffer);
/**
* Encryption handshake complete – it's now safe to log on.
*/
std::function<void()> onHandshake;
/**
* @a steamID is your SteamID.
*/
std::function<void(EResult result, SteamID steamID)> onLogOn;
std::function<void(EResult result)> onLogOff;
std::function<void(const unsigned char hash[20])> onSentry;
/**
* Each parameter except @a user is optional and will equal @c nullptr if unset.
*/
std::function<void(
SteamID user,
SteamID* source,
const char* name,
EPersonaState* state,
const unsigned char avatar_hash[20],
const char* game_name
)> onUserInfo;
/**
* Should be called in response to #JoinChat.
*/
std::function<void(
SteamID room,
EChatRoomEnterResponse response,
const char* name,
std::size_t member_count,
const ChatMember members[]
)> onChatEnter;
/**
* @a member is invalid unless @a state_change == @c EChatMemberStateChange::Entered.
*/
std::function<void(
SteamID room,
SteamID acted_by,
SteamID acted_on,
EChatMemberStateChange state_change,
const ChatMember* member
)> onChatStateChange;
std::function<void(SteamID room, SteamID chatter, const char* message)> onChatMsg;
std::function<void(SteamID user, const char* message)> onPrivateMsg;
std::function<void(SteamID user)> onTyping;
std::function<void(
bool incremental,
std::map<SteamID, EFriendRelationship> &users,
std::map<SteamID, EClanRelationship> &groups
)> onRelationships;
/**
* Call this after the encryption handshake. @a steamID is only needed if you are logging into a non-default instance.
*
* @see onHandshake
*/
void LogOn(
const char* username,
const char* password,
const unsigned char sentry_hash[20] = nullptr,
const char* code = nullptr,
SteamID steamID = 0
);
void SetPersonaState(EPersonaState state);
/**
* @see onChatEnter
*/
void JoinChat(SteamID chat);
void LeaveChat(SteamID chat);
void SendChatMessage(SteamID chat, const char* message);
void SendPrivateMessage(SteamID user, const char* message);
void SendTyping(SteamID user);
/**
* @see onUserInfo
*/
void RequestUserInfo(std::size_t count, SteamID users[]);
private:
class CMClient;
CMClient* cmClient;
// some members remain here to avoid a back pointer
std::function<void(std::function<void()> callback, int timeout)> setInterval;
std::size_t packetLength;
void ReadMessage(const unsigned char* data, std::size_t length);
void HandleMessage(EMsg eMsg, const unsigned char* data, std::size_t length, std::uint64_t job_id);
};
}