-
-
Notifications
You must be signed in to change notification settings - Fork 113
/
Copy pathsteam_friends.cpp
67 lines (56 loc) · 1.75 KB
/
steam_friends.cpp
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
#include "steam_internal.h"
#include "steam_friends.h"
#include "steamworks/public/steam/isteamfriends.h"
#include <map>
#define FUNC(name, ...) SteamAPI_ISteamFriends_##name
namespace steam {
struct Friends::Impl {
ISteamFriends* ptr;
std::map<CSteamID, string> userNames;
optional<string> updateUserName(uint64_steamid userID) {
string name = FUNC(GetFriendPersonaName)(ptr, userID);
if (name.empty() || name == "[unknown]")
return none;
userNames[userID] = name;
return name;
}
};
Friends::Friends(ISteamFriends* ptr) : ptr(ptr) {
impl->ptr = ptr;
}
Friends::~Friends() = default;
int Friends::count(unsigned flags) const {
return FUNC(GetFriendCount)(ptr, flags);
}
vector<UserId> Friends::ids(unsigned flags) const {
int count = this->count(flags);
vector<UserId> out;
out.reserve(count);
for (int n = 0; n < count; n++)
out.emplace_back(UserId(FUNC(GetFriendByIndex)(ptr, n, flags)));
return out;
}
void Friends::requestUserInfo(UserId userId, bool nameOnly) {
FUNC(RequestUserInformation)(ptr, userId, nameOnly);
}
optional<string> Friends::retrieveUserName(UserId userId) {
auto it = impl->userNames.find(CSteamID(userId));
if (it != impl->userNames.end())
return it->second;
return impl->updateUserName(userId);
}
string Friends::name() const {
return FUNC(GetPersonaName)(ptr);
}
optional<int> Friends::retrieveUserAvatar(UserId steamId, AvatarSize size) {
int value = 0;
if (size == AvatarSize::small)
value = FUNC(GetSmallFriendAvatar)(ptr, steamId);
else if (size == AvatarSize::medium)
value = FUNC(GetMediumFriendAvatar)(ptr, steamId);
else if (size == AvatarSize::large)
value = FUNC(GetLargeFriendAvatar)(ptr, steamId);
return value ? value : optional<int>();
}
}
#undef FUNC