rdiscord_sdk 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. checksums.yaml +7 -0
  2. data/.rubocop.yml +13 -0
  3. data/.vscode/c_cpp_properties.json +24 -0
  4. data/.vscode/settings.json +102 -0
  5. data/Gemfile +11 -0
  6. data/Gemfile.lock +46 -0
  7. data/INTERNALS.md +0 -0
  8. data/LICENSE +674 -0
  9. data/README.md +187 -0
  10. data/Rakefile +17 -0
  11. data/bin/console +15 -0
  12. data/bin/setup +8 -0
  13. data/ext/rdiscord_sdk/activity.cpp +297 -0
  14. data/ext/rdiscord_sdk/activity.h +17 -0
  15. data/ext/rdiscord_sdk/common.cpp +65 -0
  16. data/ext/rdiscord_sdk/common.h +88 -0
  17. data/ext/rdiscord_sdk/extconf.rb +54 -0
  18. data/ext/rdiscord_sdk/gem_activity_manager.cpp +273 -0
  19. data/ext/rdiscord_sdk/gem_activity_manager.h +8 -0
  20. data/ext/rdiscord_sdk/gem_user_manager.cpp +114 -0
  21. data/ext/rdiscord_sdk/gem_user_manager.h +8 -0
  22. data/ext/rdiscord_sdk/rdiscord_sdk.cpp +77 -0
  23. data/ext/rdiscord_sdk/rdiscord_sdk.h +17 -0
  24. data/ext/rdiscord_sdk/user.cpp +98 -0
  25. data/ext/rdiscord_sdk/user.h +19 -0
  26. data/lib/rdiscord_sdk/enums.rb +162 -0
  27. data/lib/rdiscord_sdk/rdiscord_sdk.so +0 -0
  28. data/lib/rdiscord_sdk/version.rb +16 -0
  29. data/lib/rdiscord_sdk.rb +3 -0
  30. data/rdiscord_sdk.gemspec +34 -0
  31. data/third-party/include/achievement_manager.cpp +98 -0
  32. data/third-party/include/achievement_manager.h +34 -0
  33. data/third-party/include/activity_manager.cpp +177 -0
  34. data/third-party/include/activity_manager.h +42 -0
  35. data/third-party/include/application_manager.cpp +78 -0
  36. data/third-party/include/application_manager.h +30 -0
  37. data/third-party/include/core.cpp +182 -0
  38. data/third-party/include/core.h +64 -0
  39. data/third-party/include/discord.h +16 -0
  40. data/third-party/include/event.h +59 -0
  41. data/third-party/include/ffi.h +942 -0
  42. data/third-party/include/image_manager.cpp +57 -0
  43. data/third-party/include/image_manager.h +28 -0
  44. data/third-party/include/lobby_manager.cpp +547 -0
  45. data/third-party/include/lobby_manager.h +88 -0
  46. data/third-party/include/network_manager.cpp +103 -0
  47. data/third-party/include/network_manager.h +63 -0
  48. data/third-party/include/overlay_manager.cpp +112 -0
  49. data/third-party/include/overlay_manager.h +33 -0
  50. data/third-party/include/relationship_manager.cpp +90 -0
  51. data/third-party/include/relationship_manager.h +32 -0
  52. data/third-party/include/storage_manager.cpp +158 -0
  53. data/third-party/include/storage_manager.h +46 -0
  54. data/third-party/include/store_manager.cpp +160 -0
  55. data/third-party/include/store_manager.h +38 -0
  56. data/third-party/include/types.cpp +769 -0
  57. data/third-party/include/types.h +492 -0
  58. data/third-party/include/user_manager.cpp +80 -0
  59. data/third-party/include/user_manager.h +31 -0
  60. data/third-party/include/voice_manager.cpp +124 -0
  61. data/third-party/include/voice_manager.h +37 -0
  62. data/third-party/lib/x86/discord_game_sdk.dll +0 -0
  63. data/third-party/lib/x86/discord_game_sdk.dll.lib +0 -0
  64. data/third-party/lib/x86_64/discord_game_sdk.bundle +0 -0
  65. data/third-party/lib/x86_64/discord_game_sdk.dll +0 -0
  66. data/third-party/lib/x86_64/discord_game_sdk.dll.lib +0 -0
  67. data/third-party/lib/x86_64/discord_game_sdk.dylib +0 -0
  68. data/third-party/lib/x86_64/discord_game_sdk.so +0 -0
  69. metadata +114 -0
@@ -0,0 +1,162 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Discord
4
+ module Result
5
+ Ok = 0
6
+ ServiceUnavailable = 1
7
+ InvalidVersion = 2
8
+ LockFailed = 3
9
+ InternalError = 4
10
+ InvalidPayload = 5
11
+ InvalidCommand = 6
12
+ InvalidPermissions = 7
13
+ NotFetched = 8
14
+ NotFound = 9
15
+ Conflict = 10
16
+ InvalidSecret = 11
17
+ InvalidJoinSecret = 12
18
+ NoEligibleActivity = 13
19
+ InvalidInvite = 14
20
+ NotAuthenticated = 15
21
+ InvalidAccessToken = 16
22
+ ApplicationMismatch = 17
23
+ InvalidDataUrl = 18
24
+ InvalidBase64 = 19
25
+ NotFiltered = 20
26
+ LobbyFull = 21
27
+ InvalidLobbySecret = 22
28
+ InvalidFilename = 23
29
+ InvalidFileSize = 24
30
+ InvalidEntitlement = 25
31
+ NotInstalled = 26
32
+ NotRunning = 27
33
+ InsufficientBuffer = 28
34
+ PurchaseCanceled = 29
35
+ InvalidGuild = 30
36
+ InvalidEvent = 31
37
+ InvalidChannel = 32
38
+ InvalidOrigin = 33
39
+ RateLimited = 34
40
+ OAuth2Error = 35
41
+ SelectChannelTimeout = 36
42
+ GetGuildTimeout = 37
43
+ SelectVoiceForceRequired = 38
44
+ CaptureShortcutAlreadyListening = 39
45
+ UnauthorizedForAchievement = 40
46
+ InvalidGiftCode = 41
47
+ PurchaseError = 42
48
+ TransactionAborted = 43
49
+ end
50
+
51
+ module CreateFlags
52
+ Default = 0
53
+ NoRequireDiscord = 1
54
+ end
55
+
56
+ module LogLevel
57
+ Error = 1
58
+ Warn = 2
59
+ Info = 3
60
+ Debug = 4
61
+ end
62
+
63
+ module UserFlag
64
+ Partner = 2
65
+ HypeSquadEvents = 4
66
+ HypeSquadHouse1 = 64
67
+ HypeSquadHouse2 = 128
68
+ HypeSquadHouse3 = 256
69
+ end
70
+
71
+ module PremiumType
72
+ None = 0
73
+ Tier1 = 1
74
+ Tier2 = 2
75
+ end
76
+
77
+ module ImageType
78
+ User = 0
79
+ end
80
+
81
+ module ActivityType
82
+ Playing = 0
83
+ Streaming = 1
84
+ Listening = 2
85
+ Watching = 3
86
+ end
87
+
88
+ module ActivityActionType
89
+ Join = 1
90
+ Spectate = 2
91
+ end
92
+
93
+ module ActivityJoinRequestReply
94
+ No = 0
95
+ Yes = 1
96
+ Ignore = 2
97
+ end
98
+
99
+ module Status
100
+ Offline = 0
101
+ Online = 1
102
+ Idle = 2
103
+ DoNotDisturb = 3
104
+ end
105
+
106
+ module RelationshipType
107
+ None = 0
108
+ Friend = 1
109
+ Blocked = 2
110
+ PendingIncoming = 3
111
+ PendingOutgoing = 4
112
+ Implicit = 5
113
+ end
114
+
115
+ module LobbyType
116
+ Private = 1
117
+ Public = 2
118
+ end
119
+
120
+ module LobbySearchComparison
121
+ LessThanOrEqual = -2
122
+ LessThan = -1
123
+ Equal = 0
124
+ GreaterThan = 1
125
+ GreaterThanOrEqual = 2
126
+ NotEqual = 3
127
+ end
128
+
129
+ module LobbySearchCast
130
+ String = 1
131
+ Number = 2
132
+ end
133
+
134
+ module LobbySearchDistance
135
+ Local = 1
136
+ Default = 2
137
+ Extended = 3
138
+ Global = 4
139
+ end
140
+
141
+ module EntitlementType
142
+ Purchase = 1
143
+ PremiumSubscription = 2
144
+ DeveloperGift = 3
145
+ TestModePurchase = 4
146
+ FreePurchase = 5
147
+ UserGift = 6
148
+ PremiumPurchase = 7
149
+ end
150
+
151
+ module SkuType
152
+ Application = 1
153
+ DLC = 2
154
+ Consumable = 3
155
+ Bundle = 4
156
+ end
157
+
158
+ module InputModeType
159
+ VoiceActivity = 0
160
+ PushToTalk = 1
161
+ end
162
+ end
Binary file
@@ -0,0 +1,16 @@
1
+ module Discord
2
+ VERSION = "0.1.1"
3
+ DISCORD_VERSION = "2"
4
+ DISCORD_APPLICATION_MANAGER_VERSION = "1"
5
+ DISCORD_USER_MANAGER_VERSION = "1"
6
+ DISCORD_IMAGE_MANAGER_VERSION = "1"
7
+ DISCORD_ACTIVITY_MANAGER_VERSION = "1"
8
+ DISCORD_RELATIONSHIP_MANAGER_VERSION = "1"
9
+ DISCORD_LOBBY_MANAGER_VERSION = "1"
10
+ DISCORD_NETWORK_MANAGER_VERSION = "1"
11
+ DISCORD_OVERLAY_MANAGER_VERSION = "1"
12
+ DISCORD_STORAGE_MANAGER_VERSION = "1"
13
+ DISCORD_STORE_MANAGER_VERSION = "1"
14
+ DISCORD_VOICE_MANAGER_VERSION = "1"
15
+ DISCORD_ACHIEVEMENT_MANAGER_VERSION = "1"
16
+ end
@@ -0,0 +1,3 @@
1
+ require "rdiscord_sdk.so"
2
+ require_relative "rdiscord_sdk/version"
3
+ require_relative "rdiscord_sdk/enums"
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "rdiscord_sdk"
5
+ spec.version = "1.1.0"
6
+ spec.authors = ["Matthew Lyons"]
7
+ spec.email = ["matthew@nowaffles.com"]
8
+
9
+ spec.summary = "Ruby bindings for the Discord Game SDK"
10
+ spec.homepage = "https://github.com/Speak2Erase/rdiscord_sdk"
11
+ spec.required_ruby_version = ">= 2.6.0"
12
+
13
+ spec.metadata["homepage_uri"] = spec.homepage
14
+ spec.metadata["source_code_uri"] = spec.homepage
15
+ spec.metadata["changelog_uri"] = spec.homepage
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
20
+ `git ls-files -z`.split("\x0").reject do |f|
21
+ (f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
22
+ end
23
+ end
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib", "ext"]
27
+ spec.extensions = ["ext/rdiscord_sdk/extconf.rb"]
28
+
29
+ # Uncomment to register a new dependency of your gem
30
+ # spec.add_dependency "example-gem", "~> 1.0"
31
+
32
+ # For more information and examples about making a new gem, checkout our
33
+ # guide at: https://bundler.io/guides/creating_gem.html
34
+ end
@@ -0,0 +1,98 @@
1
+ #if !defined(_CRT_SECURE_NO_WARNINGS)
2
+ #define _CRT_SECURE_NO_WARNINGS
3
+ #endif
4
+
5
+ #include "achievement_manager.h"
6
+
7
+ #include "core.h"
8
+
9
+ #include <cstring>
10
+ #include <memory>
11
+
12
+ namespace discord {
13
+
14
+ class AchievementEvents final {
15
+ public:
16
+ static void OnUserAchievementUpdate(void* callbackData, DiscordUserAchievement* userAchievement)
17
+ {
18
+ auto* core = reinterpret_cast<Core*>(callbackData);
19
+ if (!core) {
20
+ return;
21
+ }
22
+
23
+ auto& module = core->AchievementManager();
24
+ module.OnUserAchievementUpdate(*reinterpret_cast<UserAchievement const*>(userAchievement));
25
+ }
26
+ };
27
+
28
+ IDiscordAchievementEvents AchievementManager::events_{
29
+ &AchievementEvents::OnUserAchievementUpdate,
30
+ };
31
+
32
+ void AchievementManager::SetUserAchievement(Snowflake achievementId,
33
+ std::uint8_t percentComplete,
34
+ std::function<void(Result)> callback)
35
+ {
36
+ static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
37
+ std::unique_ptr<std::function<void(Result)>> cb(
38
+ reinterpret_cast<std::function<void(Result)>*>(callbackData));
39
+ if (!cb || !(*cb)) {
40
+ return;
41
+ }
42
+ (*cb)(static_cast<Result>(result));
43
+ };
44
+ std::unique_ptr<std::function<void(Result)>> cb{};
45
+ cb.reset(new std::function<void(Result)>(std::move(callback)));
46
+ internal_->set_user_achievement(
47
+ internal_, achievementId, percentComplete, cb.release(), wrapper);
48
+ }
49
+
50
+ void AchievementManager::FetchUserAchievements(std::function<void(Result)> callback)
51
+ {
52
+ static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
53
+ std::unique_ptr<std::function<void(Result)>> cb(
54
+ reinterpret_cast<std::function<void(Result)>*>(callbackData));
55
+ if (!cb || !(*cb)) {
56
+ return;
57
+ }
58
+ (*cb)(static_cast<Result>(result));
59
+ };
60
+ std::unique_ptr<std::function<void(Result)>> cb{};
61
+ cb.reset(new std::function<void(Result)>(std::move(callback)));
62
+ internal_->fetch_user_achievements(internal_, cb.release(), wrapper);
63
+ }
64
+
65
+ void AchievementManager::CountUserAchievements(std::int32_t* count)
66
+ {
67
+ if (!count) {
68
+ return;
69
+ }
70
+
71
+ internal_->count_user_achievements(internal_, reinterpret_cast<int32_t*>(count));
72
+ }
73
+
74
+ Result AchievementManager::GetUserAchievement(Snowflake userAchievementId,
75
+ UserAchievement* userAchievement)
76
+ {
77
+ if (!userAchievement) {
78
+ return Result::InternalError;
79
+ }
80
+
81
+ auto result = internal_->get_user_achievement(
82
+ internal_, userAchievementId, reinterpret_cast<DiscordUserAchievement*>(userAchievement));
83
+ return static_cast<Result>(result);
84
+ }
85
+
86
+ Result AchievementManager::GetUserAchievementAt(std::int32_t index,
87
+ UserAchievement* userAchievement)
88
+ {
89
+ if (!userAchievement) {
90
+ return Result::InternalError;
91
+ }
92
+
93
+ auto result = internal_->get_user_achievement_at(
94
+ internal_, index, reinterpret_cast<DiscordUserAchievement*>(userAchievement));
95
+ return static_cast<Result>(result);
96
+ }
97
+
98
+ } // namespace discord
@@ -0,0 +1,34 @@
1
+ #pragma once
2
+
3
+ #include "types.h"
4
+
5
+ namespace discord {
6
+
7
+ class AchievementManager final {
8
+ public:
9
+ ~AchievementManager() = default;
10
+
11
+ void SetUserAchievement(Snowflake achievementId,
12
+ std::uint8_t percentComplete,
13
+ std::function<void(Result)> callback);
14
+ void FetchUserAchievements(std::function<void(Result)> callback);
15
+ void CountUserAchievements(std::int32_t* count);
16
+ Result GetUserAchievement(Snowflake userAchievementId, UserAchievement* userAchievement);
17
+ Result GetUserAchievementAt(std::int32_t index, UserAchievement* userAchievement);
18
+
19
+ Event<UserAchievement const&> OnUserAchievementUpdate;
20
+
21
+ private:
22
+ friend class Core;
23
+
24
+ AchievementManager() = default;
25
+ AchievementManager(AchievementManager const& rhs) = delete;
26
+ AchievementManager& operator=(AchievementManager const& rhs) = delete;
27
+ AchievementManager(AchievementManager&& rhs) = delete;
28
+ AchievementManager& operator=(AchievementManager&& rhs) = delete;
29
+
30
+ IDiscordAchievementManager* internal_;
31
+ static IDiscordAchievementEvents events_;
32
+ };
33
+
34
+ } // namespace discord
@@ -0,0 +1,177 @@
1
+ #if !defined(_CRT_SECURE_NO_WARNINGS)
2
+ #define _CRT_SECURE_NO_WARNINGS
3
+ #endif
4
+
5
+ #include "activity_manager.h"
6
+
7
+ #include "core.h"
8
+
9
+ #include <cstring>
10
+ #include <memory>
11
+
12
+ namespace discord {
13
+
14
+ class ActivityEvents final {
15
+ public:
16
+ static void OnActivityJoin(void* callbackData, char const* secret)
17
+ {
18
+ auto* core = reinterpret_cast<Core*>(callbackData);
19
+ if (!core) {
20
+ return;
21
+ }
22
+
23
+ auto& module = core->ActivityManager();
24
+ module.OnActivityJoin(static_cast<const char*>(secret));
25
+ }
26
+
27
+ static void OnActivitySpectate(void* callbackData, char const* secret)
28
+ {
29
+ auto* core = reinterpret_cast<Core*>(callbackData);
30
+ if (!core) {
31
+ return;
32
+ }
33
+
34
+ auto& module = core->ActivityManager();
35
+ module.OnActivitySpectate(static_cast<const char*>(secret));
36
+ }
37
+
38
+ static void OnActivityJoinRequest(void* callbackData, DiscordUser* user)
39
+ {
40
+ auto* core = reinterpret_cast<Core*>(callbackData);
41
+ if (!core) {
42
+ return;
43
+ }
44
+
45
+ auto& module = core->ActivityManager();
46
+ module.OnActivityJoinRequest(*reinterpret_cast<User const*>(user));
47
+ }
48
+
49
+ static void OnActivityInvite(void* callbackData,
50
+ EDiscordActivityActionType type,
51
+ DiscordUser* user,
52
+ DiscordActivity* activity)
53
+ {
54
+ auto* core = reinterpret_cast<Core*>(callbackData);
55
+ if (!core) {
56
+ return;
57
+ }
58
+
59
+ auto& module = core->ActivityManager();
60
+ module.OnActivityInvite(static_cast<ActivityActionType>(type),
61
+ *reinterpret_cast<User const*>(user),
62
+ *reinterpret_cast<Activity const*>(activity));
63
+ }
64
+ };
65
+
66
+ IDiscordActivityEvents ActivityManager::events_{
67
+ &ActivityEvents::OnActivityJoin,
68
+ &ActivityEvents::OnActivitySpectate,
69
+ &ActivityEvents::OnActivityJoinRequest,
70
+ &ActivityEvents::OnActivityInvite,
71
+ };
72
+
73
+ Result ActivityManager::RegisterCommand(char const* command)
74
+ {
75
+ auto result = internal_->register_command(internal_, const_cast<char*>(command));
76
+ return static_cast<Result>(result);
77
+ }
78
+
79
+ Result ActivityManager::RegisterSteam(std::uint32_t steamId)
80
+ {
81
+ auto result = internal_->register_steam(internal_, steamId);
82
+ return static_cast<Result>(result);
83
+ }
84
+
85
+ void ActivityManager::UpdateActivity(Activity const& activity, std::function<void(Result)> callback)
86
+ {
87
+ static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
88
+ std::unique_ptr<std::function<void(Result)>> cb(
89
+ reinterpret_cast<std::function<void(Result)>*>(callbackData));
90
+ if (!cb || !(*cb)) {
91
+ return;
92
+ }
93
+ (*cb)(static_cast<Result>(result));
94
+ };
95
+ std::unique_ptr<std::function<void(Result)>> cb{};
96
+ cb.reset(new std::function<void(Result)>(std::move(callback)));
97
+ internal_->update_activity(internal_,
98
+ reinterpret_cast<DiscordActivity*>(const_cast<Activity*>(&activity)),
99
+ cb.release(),
100
+ wrapper);
101
+ }
102
+
103
+ void ActivityManager::ClearActivity(std::function<void(Result)> callback)
104
+ {
105
+ static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
106
+ std::unique_ptr<std::function<void(Result)>> cb(
107
+ reinterpret_cast<std::function<void(Result)>*>(callbackData));
108
+ if (!cb || !(*cb)) {
109
+ return;
110
+ }
111
+ (*cb)(static_cast<Result>(result));
112
+ };
113
+ std::unique_ptr<std::function<void(Result)>> cb{};
114
+ cb.reset(new std::function<void(Result)>(std::move(callback)));
115
+ internal_->clear_activity(internal_, cb.release(), wrapper);
116
+ }
117
+
118
+ void ActivityManager::SendRequestReply(UserId userId,
119
+ ActivityJoinRequestReply reply,
120
+ std::function<void(Result)> callback)
121
+ {
122
+ static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
123
+ std::unique_ptr<std::function<void(Result)>> cb(
124
+ reinterpret_cast<std::function<void(Result)>*>(callbackData));
125
+ if (!cb || !(*cb)) {
126
+ return;
127
+ }
128
+ (*cb)(static_cast<Result>(result));
129
+ };
130
+ std::unique_ptr<std::function<void(Result)>> cb{};
131
+ cb.reset(new std::function<void(Result)>(std::move(callback)));
132
+ internal_->send_request_reply(internal_,
133
+ userId,
134
+ static_cast<EDiscordActivityJoinRequestReply>(reply),
135
+ cb.release(),
136
+ wrapper);
137
+ }
138
+
139
+ void ActivityManager::SendInvite(UserId userId,
140
+ ActivityActionType type,
141
+ char const* content,
142
+ std::function<void(Result)> callback)
143
+ {
144
+ static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
145
+ std::unique_ptr<std::function<void(Result)>> cb(
146
+ reinterpret_cast<std::function<void(Result)>*>(callbackData));
147
+ if (!cb || !(*cb)) {
148
+ return;
149
+ }
150
+ (*cb)(static_cast<Result>(result));
151
+ };
152
+ std::unique_ptr<std::function<void(Result)>> cb{};
153
+ cb.reset(new std::function<void(Result)>(std::move(callback)));
154
+ internal_->send_invite(internal_,
155
+ userId,
156
+ static_cast<EDiscordActivityActionType>(type),
157
+ const_cast<char*>(content),
158
+ cb.release(),
159
+ wrapper);
160
+ }
161
+
162
+ void ActivityManager::AcceptInvite(UserId userId, std::function<void(Result)> callback)
163
+ {
164
+ static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
165
+ std::unique_ptr<std::function<void(Result)>> cb(
166
+ reinterpret_cast<std::function<void(Result)>*>(callbackData));
167
+ if (!cb || !(*cb)) {
168
+ return;
169
+ }
170
+ (*cb)(static_cast<Result>(result));
171
+ };
172
+ std::unique_ptr<std::function<void(Result)>> cb{};
173
+ cb.reset(new std::function<void(Result)>(std::move(callback)));
174
+ internal_->accept_invite(internal_, userId, cb.release(), wrapper);
175
+ }
176
+
177
+ } // namespace discord
@@ -0,0 +1,42 @@
1
+ #pragma once
2
+
3
+ #include "types.h"
4
+
5
+ namespace discord {
6
+
7
+ class ActivityManager final {
8
+ public:
9
+ ~ActivityManager() = default;
10
+
11
+ Result RegisterCommand(char const* command);
12
+ Result RegisterSteam(std::uint32_t steamId);
13
+ void UpdateActivity(Activity const& activity, std::function<void(Result)> callback);
14
+ void ClearActivity(std::function<void(Result)> callback);
15
+ void SendRequestReply(UserId userId,
16
+ ActivityJoinRequestReply reply,
17
+ std::function<void(Result)> callback);
18
+ void SendInvite(UserId userId,
19
+ ActivityActionType type,
20
+ char const* content,
21
+ std::function<void(Result)> callback);
22
+ void AcceptInvite(UserId userId, std::function<void(Result)> callback);
23
+
24
+ Event<char const*> OnActivityJoin;
25
+ Event<char const*> OnActivitySpectate;
26
+ Event<User const&> OnActivityJoinRequest;
27
+ Event<ActivityActionType, User const&, Activity const&> OnActivityInvite;
28
+
29
+ private:
30
+ friend class Core;
31
+
32
+ ActivityManager() = default;
33
+ ActivityManager(ActivityManager const& rhs) = delete;
34
+ ActivityManager& operator=(ActivityManager const& rhs) = delete;
35
+ ActivityManager(ActivityManager&& rhs) = delete;
36
+ ActivityManager& operator=(ActivityManager&& rhs) = delete;
37
+
38
+ IDiscordActivityManager* internal_;
39
+ static IDiscordActivityEvents events_;
40
+ };
41
+
42
+ } // namespace discord
@@ -0,0 +1,78 @@
1
+ #if !defined(_CRT_SECURE_NO_WARNINGS)
2
+ #define _CRT_SECURE_NO_WARNINGS
3
+ #endif
4
+
5
+ #include "application_manager.h"
6
+
7
+ #include "core.h"
8
+
9
+ #include <cstring>
10
+ #include <memory>
11
+
12
+ namespace discord {
13
+
14
+ void ApplicationManager::ValidateOrExit(std::function<void(Result)> callback)
15
+ {
16
+ static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
17
+ std::unique_ptr<std::function<void(Result)>> cb(
18
+ reinterpret_cast<std::function<void(Result)>*>(callbackData));
19
+ if (!cb || !(*cb)) {
20
+ return;
21
+ }
22
+ (*cb)(static_cast<Result>(result));
23
+ };
24
+ std::unique_ptr<std::function<void(Result)>> cb{};
25
+ cb.reset(new std::function<void(Result)>(std::move(callback)));
26
+ internal_->validate_or_exit(internal_, cb.release(), wrapper);
27
+ }
28
+
29
+ void ApplicationManager::GetCurrentLocale(char locale[128])
30
+ {
31
+ if (!locale) {
32
+ return;
33
+ }
34
+
35
+ internal_->get_current_locale(internal_, reinterpret_cast<DiscordLocale*>(locale));
36
+ }
37
+
38
+ void ApplicationManager::GetCurrentBranch(char branch[4096])
39
+ {
40
+ if (!branch) {
41
+ return;
42
+ }
43
+
44
+ internal_->get_current_branch(internal_, reinterpret_cast<DiscordBranch*>(branch));
45
+ }
46
+
47
+ void ApplicationManager::GetOAuth2Token(std::function<void(Result, OAuth2Token const&)> callback)
48
+ {
49
+ static auto wrapper =
50
+ [](void* callbackData, EDiscordResult result, DiscordOAuth2Token* oauth2Token) -> void {
51
+ std::unique_ptr<std::function<void(Result, OAuth2Token const&)>> cb(
52
+ reinterpret_cast<std::function<void(Result, OAuth2Token const&)>*>(callbackData));
53
+ if (!cb || !(*cb)) {
54
+ return;
55
+ }
56
+ (*cb)(static_cast<Result>(result), *reinterpret_cast<OAuth2Token const*>(oauth2Token));
57
+ };
58
+ std::unique_ptr<std::function<void(Result, OAuth2Token const&)>> cb{};
59
+ cb.reset(new std::function<void(Result, OAuth2Token const&)>(std::move(callback)));
60
+ internal_->get_oauth2_token(internal_, cb.release(), wrapper);
61
+ }
62
+
63
+ void ApplicationManager::GetTicket(std::function<void(Result, char const*)> callback)
64
+ {
65
+ static auto wrapper = [](void* callbackData, EDiscordResult result, char const* data) -> void {
66
+ std::unique_ptr<std::function<void(Result, char const*)>> cb(
67
+ reinterpret_cast<std::function<void(Result, char const*)>*>(callbackData));
68
+ if (!cb || !(*cb)) {
69
+ return;
70
+ }
71
+ (*cb)(static_cast<Result>(result), static_cast<const char*>(data));
72
+ };
73
+ std::unique_ptr<std::function<void(Result, char const*)>> cb{};
74
+ cb.reset(new std::function<void(Result, char const*)>(std::move(callback)));
75
+ internal_->get_ticket(internal_, cb.release(), wrapper);
76
+ }
77
+
78
+ } // namespace discord
@@ -0,0 +1,30 @@
1
+ #pragma once
2
+
3
+ #include "types.h"
4
+
5
+ namespace discord {
6
+
7
+ class ApplicationManager final {
8
+ public:
9
+ ~ApplicationManager() = default;
10
+
11
+ void ValidateOrExit(std::function<void(Result)> callback);
12
+ void GetCurrentLocale(char locale[128]);
13
+ void GetCurrentBranch(char branch[4096]);
14
+ void GetOAuth2Token(std::function<void(Result, OAuth2Token const&)> callback);
15
+ void GetTicket(std::function<void(Result, char const*)> callback);
16
+
17
+ private:
18
+ friend class Core;
19
+
20
+ ApplicationManager() = default;
21
+ ApplicationManager(ApplicationManager const& rhs) = delete;
22
+ ApplicationManager& operator=(ApplicationManager const& rhs) = delete;
23
+ ApplicationManager(ApplicationManager&& rhs) = delete;
24
+ ApplicationManager& operator=(ApplicationManager&& rhs) = delete;
25
+
26
+ IDiscordApplicationManager* internal_;
27
+ static IDiscordApplicationEvents events_;
28
+ };
29
+
30
+ } // namespace discord