rdiscord_sdk 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
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,57 @@
1
+ #if !defined(_CRT_SECURE_NO_WARNINGS)
2
+ #define _CRT_SECURE_NO_WARNINGS
3
+ #endif
4
+
5
+ #include "image_manager.h"
6
+
7
+ #include "core.h"
8
+
9
+ #include <cstring>
10
+ #include <memory>
11
+
12
+ namespace discord {
13
+
14
+ void ImageManager::Fetch(ImageHandle handle,
15
+ bool refresh,
16
+ std::function<void(Result, ImageHandle)> callback)
17
+ {
18
+ static auto wrapper =
19
+ [](void* callbackData, EDiscordResult result, DiscordImageHandle handleResult) -> void {
20
+ std::unique_ptr<std::function<void(Result, ImageHandle)>> cb(
21
+ reinterpret_cast<std::function<void(Result, ImageHandle)>*>(callbackData));
22
+ if (!cb || !(*cb)) {
23
+ return;
24
+ }
25
+ (*cb)(static_cast<Result>(result), *reinterpret_cast<ImageHandle const*>(&handleResult));
26
+ };
27
+ std::unique_ptr<std::function<void(Result, ImageHandle)>> cb{};
28
+ cb.reset(new std::function<void(Result, ImageHandle)>(std::move(callback)));
29
+ internal_->fetch(internal_,
30
+ *reinterpret_cast<DiscordImageHandle const*>(&handle),
31
+ (refresh ? 1 : 0),
32
+ cb.release(),
33
+ wrapper);
34
+ }
35
+
36
+ Result ImageManager::GetDimensions(ImageHandle handle, ImageDimensions* dimensions)
37
+ {
38
+ if (!dimensions) {
39
+ return Result::InternalError;
40
+ }
41
+
42
+ auto result = internal_->get_dimensions(internal_,
43
+ *reinterpret_cast<DiscordImageHandle const*>(&handle),
44
+ reinterpret_cast<DiscordImageDimensions*>(dimensions));
45
+ return static_cast<Result>(result);
46
+ }
47
+
48
+ Result ImageManager::GetData(ImageHandle handle, std::uint8_t* data, std::uint32_t dataLength)
49
+ {
50
+ auto result = internal_->get_data(internal_,
51
+ *reinterpret_cast<DiscordImageHandle const*>(&handle),
52
+ reinterpret_cast<uint8_t*>(data),
53
+ dataLength);
54
+ return static_cast<Result>(result);
55
+ }
56
+
57
+ } // namespace discord
@@ -0,0 +1,28 @@
1
+ #pragma once
2
+
3
+ #include "types.h"
4
+
5
+ namespace discord {
6
+
7
+ class ImageManager final {
8
+ public:
9
+ ~ImageManager() = default;
10
+
11
+ void Fetch(ImageHandle handle, bool refresh, std::function<void(Result, ImageHandle)> callback);
12
+ Result GetDimensions(ImageHandle handle, ImageDimensions* dimensions);
13
+ Result GetData(ImageHandle handle, std::uint8_t* data, std::uint32_t dataLength);
14
+
15
+ private:
16
+ friend class Core;
17
+
18
+ ImageManager() = default;
19
+ ImageManager(ImageManager const& rhs) = delete;
20
+ ImageManager& operator=(ImageManager const& rhs) = delete;
21
+ ImageManager(ImageManager&& rhs) = delete;
22
+ ImageManager& operator=(ImageManager&& rhs) = delete;
23
+
24
+ IDiscordImageManager* internal_;
25
+ static IDiscordImageEvents events_;
26
+ };
27
+
28
+ } // namespace discord
@@ -0,0 +1,547 @@
1
+ #if !defined(_CRT_SECURE_NO_WARNINGS)
2
+ #define _CRT_SECURE_NO_WARNINGS
3
+ #endif
4
+
5
+ #include "lobby_manager.h"
6
+
7
+ #include "core.h"
8
+
9
+ #include <cstring>
10
+ #include <memory>
11
+
12
+ namespace discord {
13
+
14
+ class LobbyEvents final {
15
+ public:
16
+ static void OnLobbyUpdate(void* callbackData, int64_t lobbyId)
17
+ {
18
+ auto* core = reinterpret_cast<Core*>(callbackData);
19
+ if (!core) {
20
+ return;
21
+ }
22
+
23
+ auto& module = core->LobbyManager();
24
+ module.OnLobbyUpdate(lobbyId);
25
+ }
26
+
27
+ static void OnLobbyDelete(void* callbackData, int64_t lobbyId, uint32_t reason)
28
+ {
29
+ auto* core = reinterpret_cast<Core*>(callbackData);
30
+ if (!core) {
31
+ return;
32
+ }
33
+
34
+ auto& module = core->LobbyManager();
35
+ module.OnLobbyDelete(lobbyId, reason);
36
+ }
37
+
38
+ static void OnMemberConnect(void* callbackData, int64_t lobbyId, int64_t userId)
39
+ {
40
+ auto* core = reinterpret_cast<Core*>(callbackData);
41
+ if (!core) {
42
+ return;
43
+ }
44
+
45
+ auto& module = core->LobbyManager();
46
+ module.OnMemberConnect(lobbyId, userId);
47
+ }
48
+
49
+ static void OnMemberUpdate(void* callbackData, int64_t lobbyId, int64_t userId)
50
+ {
51
+ auto* core = reinterpret_cast<Core*>(callbackData);
52
+ if (!core) {
53
+ return;
54
+ }
55
+
56
+ auto& module = core->LobbyManager();
57
+ module.OnMemberUpdate(lobbyId, userId);
58
+ }
59
+
60
+ static void OnMemberDisconnect(void* callbackData, int64_t lobbyId, int64_t userId)
61
+ {
62
+ auto* core = reinterpret_cast<Core*>(callbackData);
63
+ if (!core) {
64
+ return;
65
+ }
66
+
67
+ auto& module = core->LobbyManager();
68
+ module.OnMemberDisconnect(lobbyId, userId);
69
+ }
70
+
71
+ static void OnLobbyMessage(void* callbackData,
72
+ int64_t lobbyId,
73
+ int64_t userId,
74
+ uint8_t* data,
75
+ uint32_t dataLength)
76
+ {
77
+ auto* core = reinterpret_cast<Core*>(callbackData);
78
+ if (!core) {
79
+ return;
80
+ }
81
+
82
+ auto& module = core->LobbyManager();
83
+ module.OnLobbyMessage(lobbyId, userId, data, dataLength);
84
+ }
85
+
86
+ static void OnSpeaking(void* callbackData, int64_t lobbyId, int64_t userId, bool speaking)
87
+ {
88
+ auto* core = reinterpret_cast<Core*>(callbackData);
89
+ if (!core) {
90
+ return;
91
+ }
92
+
93
+ auto& module = core->LobbyManager();
94
+ module.OnSpeaking(lobbyId, userId, (speaking != 0));
95
+ }
96
+
97
+ static void OnNetworkMessage(void* callbackData,
98
+ int64_t lobbyId,
99
+ int64_t userId,
100
+ uint8_t channelId,
101
+ uint8_t* data,
102
+ uint32_t dataLength)
103
+ {
104
+ auto* core = reinterpret_cast<Core*>(callbackData);
105
+ if (!core) {
106
+ return;
107
+ }
108
+
109
+ auto& module = core->LobbyManager();
110
+ module.OnNetworkMessage(lobbyId, userId, channelId, data, dataLength);
111
+ }
112
+ };
113
+
114
+ IDiscordLobbyEvents LobbyManager::events_{
115
+ &LobbyEvents::OnLobbyUpdate,
116
+ &LobbyEvents::OnLobbyDelete,
117
+ &LobbyEvents::OnMemberConnect,
118
+ &LobbyEvents::OnMemberUpdate,
119
+ &LobbyEvents::OnMemberDisconnect,
120
+ &LobbyEvents::OnLobbyMessage,
121
+ &LobbyEvents::OnSpeaking,
122
+ &LobbyEvents::OnNetworkMessage,
123
+ };
124
+
125
+ Result LobbyManager::GetLobbyCreateTransaction(LobbyTransaction* transaction)
126
+ {
127
+ if (!transaction) {
128
+ return Result::InternalError;
129
+ }
130
+
131
+ auto result = internal_->get_lobby_create_transaction(internal_, transaction->Receive());
132
+ return static_cast<Result>(result);
133
+ }
134
+
135
+ Result LobbyManager::GetLobbyUpdateTransaction(LobbyId lobbyId, LobbyTransaction* transaction)
136
+ {
137
+ if (!transaction) {
138
+ return Result::InternalError;
139
+ }
140
+
141
+ auto result =
142
+ internal_->get_lobby_update_transaction(internal_, lobbyId, transaction->Receive());
143
+ return static_cast<Result>(result);
144
+ }
145
+
146
+ Result LobbyManager::GetMemberUpdateTransaction(LobbyId lobbyId,
147
+ UserId userId,
148
+ LobbyMemberTransaction* transaction)
149
+ {
150
+ if (!transaction) {
151
+ return Result::InternalError;
152
+ }
153
+
154
+ auto result =
155
+ internal_->get_member_update_transaction(internal_, lobbyId, userId, transaction->Receive());
156
+ return static_cast<Result>(result);
157
+ }
158
+
159
+ void LobbyManager::CreateLobby(LobbyTransaction const& transaction,
160
+ std::function<void(Result, Lobby const&)> callback)
161
+ {
162
+ static auto wrapper =
163
+ [](void* callbackData, EDiscordResult result, DiscordLobby* lobby) -> void {
164
+ std::unique_ptr<std::function<void(Result, Lobby const&)>> cb(
165
+ reinterpret_cast<std::function<void(Result, Lobby const&)>*>(callbackData));
166
+ if (!cb || !(*cb)) {
167
+ return;
168
+ }
169
+ (*cb)(static_cast<Result>(result), *reinterpret_cast<Lobby const*>(lobby));
170
+ };
171
+ std::unique_ptr<std::function<void(Result, Lobby const&)>> cb{};
172
+ cb.reset(new std::function<void(Result, Lobby const&)>(std::move(callback)));
173
+ internal_->create_lobby(
174
+ internal_, const_cast<LobbyTransaction&>(transaction).Internal(), cb.release(), wrapper);
175
+ }
176
+
177
+ void LobbyManager::UpdateLobby(LobbyId lobbyId,
178
+ LobbyTransaction const& transaction,
179
+ std::function<void(Result)> callback)
180
+ {
181
+ static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
182
+ std::unique_ptr<std::function<void(Result)>> cb(
183
+ reinterpret_cast<std::function<void(Result)>*>(callbackData));
184
+ if (!cb || !(*cb)) {
185
+ return;
186
+ }
187
+ (*cb)(static_cast<Result>(result));
188
+ };
189
+ std::unique_ptr<std::function<void(Result)>> cb{};
190
+ cb.reset(new std::function<void(Result)>(std::move(callback)));
191
+ internal_->update_lobby(internal_,
192
+ lobbyId,
193
+ const_cast<LobbyTransaction&>(transaction).Internal(),
194
+ cb.release(),
195
+ wrapper);
196
+ }
197
+
198
+ void LobbyManager::DeleteLobby(LobbyId lobbyId, std::function<void(Result)> callback)
199
+ {
200
+ static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
201
+ std::unique_ptr<std::function<void(Result)>> cb(
202
+ reinterpret_cast<std::function<void(Result)>*>(callbackData));
203
+ if (!cb || !(*cb)) {
204
+ return;
205
+ }
206
+ (*cb)(static_cast<Result>(result));
207
+ };
208
+ std::unique_ptr<std::function<void(Result)>> cb{};
209
+ cb.reset(new std::function<void(Result)>(std::move(callback)));
210
+ internal_->delete_lobby(internal_, lobbyId, cb.release(), wrapper);
211
+ }
212
+
213
+ void LobbyManager::ConnectLobby(LobbyId lobbyId,
214
+ LobbySecret secret,
215
+ std::function<void(Result, Lobby const&)> callback)
216
+ {
217
+ static auto wrapper =
218
+ [](void* callbackData, EDiscordResult result, DiscordLobby* lobby) -> void {
219
+ std::unique_ptr<std::function<void(Result, Lobby const&)>> cb(
220
+ reinterpret_cast<std::function<void(Result, Lobby const&)>*>(callbackData));
221
+ if (!cb || !(*cb)) {
222
+ return;
223
+ }
224
+ (*cb)(static_cast<Result>(result), *reinterpret_cast<Lobby const*>(lobby));
225
+ };
226
+ std::unique_ptr<std::function<void(Result, Lobby const&)>> cb{};
227
+ cb.reset(new std::function<void(Result, Lobby const&)>(std::move(callback)));
228
+ internal_->connect_lobby(internal_, lobbyId, const_cast<char*>(secret), cb.release(), wrapper);
229
+ }
230
+
231
+ void LobbyManager::ConnectLobbyWithActivitySecret(
232
+ LobbySecret activitySecret,
233
+ std::function<void(Result, Lobby const&)> callback)
234
+ {
235
+ static auto wrapper =
236
+ [](void* callbackData, EDiscordResult result, DiscordLobby* lobby) -> void {
237
+ std::unique_ptr<std::function<void(Result, Lobby const&)>> cb(
238
+ reinterpret_cast<std::function<void(Result, Lobby const&)>*>(callbackData));
239
+ if (!cb || !(*cb)) {
240
+ return;
241
+ }
242
+ (*cb)(static_cast<Result>(result), *reinterpret_cast<Lobby const*>(lobby));
243
+ };
244
+ std::unique_ptr<std::function<void(Result, Lobby const&)>> cb{};
245
+ cb.reset(new std::function<void(Result, Lobby const&)>(std::move(callback)));
246
+ internal_->connect_lobby_with_activity_secret(
247
+ internal_, const_cast<char*>(activitySecret), cb.release(), wrapper);
248
+ }
249
+
250
+ void LobbyManager::DisconnectLobby(LobbyId lobbyId, std::function<void(Result)> callback)
251
+ {
252
+ static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
253
+ std::unique_ptr<std::function<void(Result)>> cb(
254
+ reinterpret_cast<std::function<void(Result)>*>(callbackData));
255
+ if (!cb || !(*cb)) {
256
+ return;
257
+ }
258
+ (*cb)(static_cast<Result>(result));
259
+ };
260
+ std::unique_ptr<std::function<void(Result)>> cb{};
261
+ cb.reset(new std::function<void(Result)>(std::move(callback)));
262
+ internal_->disconnect_lobby(internal_, lobbyId, cb.release(), wrapper);
263
+ }
264
+
265
+ Result LobbyManager::GetLobby(LobbyId lobbyId, Lobby* lobby)
266
+ {
267
+ if (!lobby) {
268
+ return Result::InternalError;
269
+ }
270
+
271
+ auto result = internal_->get_lobby(internal_, lobbyId, reinterpret_cast<DiscordLobby*>(lobby));
272
+ return static_cast<Result>(result);
273
+ }
274
+
275
+ Result LobbyManager::GetLobbyActivitySecret(LobbyId lobbyId, char secret[128])
276
+ {
277
+ if (!secret) {
278
+ return Result::InternalError;
279
+ }
280
+
281
+ auto result = internal_->get_lobby_activity_secret(
282
+ internal_, lobbyId, reinterpret_cast<DiscordLobbySecret*>(secret));
283
+ return static_cast<Result>(result);
284
+ }
285
+
286
+ Result LobbyManager::GetLobbyMetadataValue(LobbyId lobbyId, MetadataKey key, char value[4096])
287
+ {
288
+ if (!value) {
289
+ return Result::InternalError;
290
+ }
291
+
292
+ auto result = internal_->get_lobby_metadata_value(
293
+ internal_, lobbyId, const_cast<char*>(key), reinterpret_cast<DiscordMetadataValue*>(value));
294
+ return static_cast<Result>(result);
295
+ }
296
+
297
+ Result LobbyManager::GetLobbyMetadataKey(LobbyId lobbyId, std::int32_t index, char key[256])
298
+ {
299
+ if (!key) {
300
+ return Result::InternalError;
301
+ }
302
+
303
+ auto result = internal_->get_lobby_metadata_key(
304
+ internal_, lobbyId, index, reinterpret_cast<DiscordMetadataKey*>(key));
305
+ return static_cast<Result>(result);
306
+ }
307
+
308
+ Result LobbyManager::LobbyMetadataCount(LobbyId lobbyId, std::int32_t* count)
309
+ {
310
+ if (!count) {
311
+ return Result::InternalError;
312
+ }
313
+
314
+ auto result =
315
+ internal_->lobby_metadata_count(internal_, lobbyId, reinterpret_cast<int32_t*>(count));
316
+ return static_cast<Result>(result);
317
+ }
318
+
319
+ Result LobbyManager::MemberCount(LobbyId lobbyId, std::int32_t* count)
320
+ {
321
+ if (!count) {
322
+ return Result::InternalError;
323
+ }
324
+
325
+ auto result = internal_->member_count(internal_, lobbyId, reinterpret_cast<int32_t*>(count));
326
+ return static_cast<Result>(result);
327
+ }
328
+
329
+ Result LobbyManager::GetMemberUserId(LobbyId lobbyId, std::int32_t index, UserId* userId)
330
+ {
331
+ if (!userId) {
332
+ return Result::InternalError;
333
+ }
334
+
335
+ auto result =
336
+ internal_->get_member_user_id(internal_, lobbyId, index, reinterpret_cast<int64_t*>(userId));
337
+ return static_cast<Result>(result);
338
+ }
339
+
340
+ Result LobbyManager::GetMemberUser(LobbyId lobbyId, UserId userId, User* user)
341
+ {
342
+ if (!user) {
343
+ return Result::InternalError;
344
+ }
345
+
346
+ auto result =
347
+ internal_->get_member_user(internal_, lobbyId, userId, reinterpret_cast<DiscordUser*>(user));
348
+ return static_cast<Result>(result);
349
+ }
350
+
351
+ Result LobbyManager::GetMemberMetadataValue(LobbyId lobbyId,
352
+ UserId userId,
353
+ MetadataKey key,
354
+ char value[4096])
355
+ {
356
+ if (!value) {
357
+ return Result::InternalError;
358
+ }
359
+
360
+ auto result =
361
+ internal_->get_member_metadata_value(internal_,
362
+ lobbyId,
363
+ userId,
364
+ const_cast<char*>(key),
365
+ reinterpret_cast<DiscordMetadataValue*>(value));
366
+ return static_cast<Result>(result);
367
+ }
368
+
369
+ Result LobbyManager::GetMemberMetadataKey(LobbyId lobbyId,
370
+ UserId userId,
371
+ std::int32_t index,
372
+ char key[256])
373
+ {
374
+ if (!key) {
375
+ return Result::InternalError;
376
+ }
377
+
378
+ auto result = internal_->get_member_metadata_key(
379
+ internal_, lobbyId, userId, index, reinterpret_cast<DiscordMetadataKey*>(key));
380
+ return static_cast<Result>(result);
381
+ }
382
+
383
+ Result LobbyManager::MemberMetadataCount(LobbyId lobbyId, UserId userId, std::int32_t* count)
384
+ {
385
+ if (!count) {
386
+ return Result::InternalError;
387
+ }
388
+
389
+ auto result = internal_->member_metadata_count(
390
+ internal_, lobbyId, userId, reinterpret_cast<int32_t*>(count));
391
+ return static_cast<Result>(result);
392
+ }
393
+
394
+ void LobbyManager::UpdateMember(LobbyId lobbyId,
395
+ UserId userId,
396
+ LobbyMemberTransaction const& transaction,
397
+ std::function<void(Result)> callback)
398
+ {
399
+ static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
400
+ std::unique_ptr<std::function<void(Result)>> cb(
401
+ reinterpret_cast<std::function<void(Result)>*>(callbackData));
402
+ if (!cb || !(*cb)) {
403
+ return;
404
+ }
405
+ (*cb)(static_cast<Result>(result));
406
+ };
407
+ std::unique_ptr<std::function<void(Result)>> cb{};
408
+ cb.reset(new std::function<void(Result)>(std::move(callback)));
409
+ internal_->update_member(internal_,
410
+ lobbyId,
411
+ userId,
412
+ const_cast<LobbyMemberTransaction&>(transaction).Internal(),
413
+ cb.release(),
414
+ wrapper);
415
+ }
416
+
417
+ void LobbyManager::SendLobbyMessage(LobbyId lobbyId,
418
+ std::uint8_t* data,
419
+ std::uint32_t dataLength,
420
+ std::function<void(Result)> callback)
421
+ {
422
+ static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
423
+ std::unique_ptr<std::function<void(Result)>> cb(
424
+ reinterpret_cast<std::function<void(Result)>*>(callbackData));
425
+ if (!cb || !(*cb)) {
426
+ return;
427
+ }
428
+ (*cb)(static_cast<Result>(result));
429
+ };
430
+ std::unique_ptr<std::function<void(Result)>> cb{};
431
+ cb.reset(new std::function<void(Result)>(std::move(callback)));
432
+ internal_->send_lobby_message(
433
+ internal_, lobbyId, reinterpret_cast<uint8_t*>(data), dataLength, cb.release(), wrapper);
434
+ }
435
+
436
+ Result LobbyManager::GetSearchQuery(LobbySearchQuery* query)
437
+ {
438
+ if (!query) {
439
+ return Result::InternalError;
440
+ }
441
+
442
+ auto result = internal_->get_search_query(internal_, query->Receive());
443
+ return static_cast<Result>(result);
444
+ }
445
+
446
+ void LobbyManager::Search(LobbySearchQuery const& query, std::function<void(Result)> callback)
447
+ {
448
+ static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
449
+ std::unique_ptr<std::function<void(Result)>> cb(
450
+ reinterpret_cast<std::function<void(Result)>*>(callbackData));
451
+ if (!cb || !(*cb)) {
452
+ return;
453
+ }
454
+ (*cb)(static_cast<Result>(result));
455
+ };
456
+ std::unique_ptr<std::function<void(Result)>> cb{};
457
+ cb.reset(new std::function<void(Result)>(std::move(callback)));
458
+ internal_->search(
459
+ internal_, const_cast<LobbySearchQuery&>(query).Internal(), cb.release(), wrapper);
460
+ }
461
+
462
+ void LobbyManager::LobbyCount(std::int32_t* count)
463
+ {
464
+ if (!count) {
465
+ return;
466
+ }
467
+
468
+ internal_->lobby_count(internal_, reinterpret_cast<int32_t*>(count));
469
+ }
470
+
471
+ Result LobbyManager::GetLobbyId(std::int32_t index, LobbyId* lobbyId)
472
+ {
473
+ if (!lobbyId) {
474
+ return Result::InternalError;
475
+ }
476
+
477
+ auto result = internal_->get_lobby_id(internal_, index, reinterpret_cast<int64_t*>(lobbyId));
478
+ return static_cast<Result>(result);
479
+ }
480
+
481
+ void LobbyManager::ConnectVoice(LobbyId lobbyId, std::function<void(Result)> callback)
482
+ {
483
+ static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
484
+ std::unique_ptr<std::function<void(Result)>> cb(
485
+ reinterpret_cast<std::function<void(Result)>*>(callbackData));
486
+ if (!cb || !(*cb)) {
487
+ return;
488
+ }
489
+ (*cb)(static_cast<Result>(result));
490
+ };
491
+ std::unique_ptr<std::function<void(Result)>> cb{};
492
+ cb.reset(new std::function<void(Result)>(std::move(callback)));
493
+ internal_->connect_voice(internal_, lobbyId, cb.release(), wrapper);
494
+ }
495
+
496
+ void LobbyManager::DisconnectVoice(LobbyId lobbyId, std::function<void(Result)> callback)
497
+ {
498
+ static auto wrapper = [](void* callbackData, EDiscordResult result) -> void {
499
+ std::unique_ptr<std::function<void(Result)>> cb(
500
+ reinterpret_cast<std::function<void(Result)>*>(callbackData));
501
+ if (!cb || !(*cb)) {
502
+ return;
503
+ }
504
+ (*cb)(static_cast<Result>(result));
505
+ };
506
+ std::unique_ptr<std::function<void(Result)>> cb{};
507
+ cb.reset(new std::function<void(Result)>(std::move(callback)));
508
+ internal_->disconnect_voice(internal_, lobbyId, cb.release(), wrapper);
509
+ }
510
+
511
+ Result LobbyManager::ConnectNetwork(LobbyId lobbyId)
512
+ {
513
+ auto result = internal_->connect_network(internal_, lobbyId);
514
+ return static_cast<Result>(result);
515
+ }
516
+
517
+ Result LobbyManager::DisconnectNetwork(LobbyId lobbyId)
518
+ {
519
+ auto result = internal_->disconnect_network(internal_, lobbyId);
520
+ return static_cast<Result>(result);
521
+ }
522
+
523
+ Result LobbyManager::FlushNetwork()
524
+ {
525
+ auto result = internal_->flush_network(internal_);
526
+ return static_cast<Result>(result);
527
+ }
528
+
529
+ Result LobbyManager::OpenNetworkChannel(LobbyId lobbyId, std::uint8_t channelId, bool reliable)
530
+ {
531
+ auto result =
532
+ internal_->open_network_channel(internal_, lobbyId, channelId, (reliable ? 1 : 0));
533
+ return static_cast<Result>(result);
534
+ }
535
+
536
+ Result LobbyManager::SendNetworkMessage(LobbyId lobbyId,
537
+ UserId userId,
538
+ std::uint8_t channelId,
539
+ std::uint8_t* data,
540
+ std::uint32_t dataLength)
541
+ {
542
+ auto result = internal_->send_network_message(
543
+ internal_, lobbyId, userId, channelId, reinterpret_cast<uint8_t*>(data), dataLength);
544
+ return static_cast<Result>(result);
545
+ }
546
+
547
+ } // namespace discord