rdiscord_sdk 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 59a94f08d97089f6680144bf0ce256826b3f4ea2cec5d11f1b8f911eecd87b7f
4
- data.tar.gz: 83f15af9437acd1c2723d444b50bba6fe6109929f4a7c9d27f1bbd8d9961c949
3
+ metadata.gz: 4e5d12918d76fbea01b9bb6bce5669c0546f45791aa0081f69f36c691dec7b68
4
+ data.tar.gz: bad3da53840bee73db47a0b073c46d2c5c138eb10911ec42622b063d28501c41
5
5
  SHA512:
6
- metadata.gz: afc945ab00ec2106cc0b590e2af30b6de702160af959f73cdb3dfae2c92e564963cc866b0420d2da65fb93ddecf1a5de31987597600e2de891e6bb6168bbd4bf
7
- data.tar.gz: 07ef99cda3316b89d7fa31888c4dd78c7b99eec08cf57559c1e693108bd8e26a3fb6214fdefad1a5d2afd692f3e25c463d101426ac010b24eadb8667e47409d6
6
+ metadata.gz: a60fb59f7a09136cbb3209d66a5b15a5d160047004b2f026c7f755575d4154e8869829d0172fcdd1c3c2c6d0b13a6b362ced5fb3fb4ef59607558754f86e2be7
7
+ data.tar.gz: 74c0ee7ad4b07ca3c87a28511709cc5bb2ca71cdc22fd43535dba351bf22b82c132fe888bedab6151f161fbf075701f189f00afde460117225f188fb9d60afb2
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.1.1
@@ -4,9 +4,8 @@
4
4
  "name": "Win32",
5
5
  "includePath": [
6
6
  "${workspaceFolder}/**",
7
- // "/usr/local/lib/ruby/**",
8
- // "/usr/local/include/ruby-3.0.0/**",
9
7
  "C:\\Ruby31-x64\\**",
8
+ "~/.rbenv/versions/3.1.1/**"
10
9
  ],
11
10
  "defines": [
12
11
  "_DEBUG",
@@ -17,7 +16,7 @@
17
16
  "compilerPath": "/usr/bin/gcc",
18
17
  "cStandard": "c17",
19
18
  "cppStandard": "c++17",
20
- "intelliSenseMode": "windows-msvc-x64"
19
+ "intelliSenseMode": "linux-gcc-x64"
21
20
  }
22
21
  ],
23
22
  "version": 4
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # R(uby) Discord SDK
1
+ # R(uby) Discord SDK ![Gem](https://img.shields.io/gem/v/rdiscord_sdk) ![Gem](https://img.shields.io/gem/dt/rdiscord_sdk)
2
2
 
3
3
  This is a Ruby gem that implements bindings to the [Discord Game SDK](https://discord.com/developers/docs/game-sdk/discord).
4
4
  It is intended to be used in [ModShot](https://github.com/Astrabit-ST/Modshot-Core), although will work in any ruby application.
@@ -26,6 +26,8 @@ There are a couple of minor differences, such as the lack of a need to initializ
26
26
  - Events are also method blocks
27
27
  - Pending callbacks and events are accessible
28
28
  - Some functions return an array, usually the result being at [0] and an object at [1] (such as Discord::UserManager.get_current_user)
29
+ - Images will likely not be supported on many platforms aside from mkxp-z, as mkxp-z has the ability to create bitmaps from strings
30
+ - Some network manager events and methods return/take in an array of bytes (integers from 0-255, similar to a byte array in C#) rather than how you'd expect in C++
29
31
 
30
32
  As mentioned above, some functions return arrays. An easy way to deal with these would be to:
31
33
  ```rb
@@ -159,17 +161,16 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/Speak2
159
161
  - [x] ActivityManager
160
162
  - [ ] RelationshipManager
161
163
  - [ ] LobbyManager
162
- - [ ] NetworkManager
163
- - [ ] OverlayManager
164
+ - [x] NetworkManager
165
+ - [x] OverlayManager
164
166
  - [ ] StorageManager
165
167
  - [ ] StoreManager
166
168
  - [ ] VoiceManager
167
169
  - [ ] AchievementManager
168
170
 
169
171
  ### Others
170
- - [ ] Core functionality
172
+ - [x] Core functionality
171
173
  - [x] Initialization
172
- - [ ] Teardown
173
174
  - [x] Run callbacks
174
175
  - [x] Log hooks
175
176
  - [x] All enums
@@ -180,8 +181,8 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/Speak2
180
181
  - [x] ActivityEvents
181
182
  - [ ] RelationshipEvents
182
183
  - [ ] LobbyEvents
183
- - [ ] NetworkEvents
184
- - [ ] OverlayEvents
184
+ - [x] NetworkEvents
185
+ - [x] OverlayEvents
185
186
  - [ ] StoreEvents
186
187
  - [ ] VoiceEvents
187
- - [ ] AchievementEvents
188
+ - [ ] AchievementEvents
@@ -0,0 +1,163 @@
1
+ #include "gem_network_manager.h"
2
+ #include <rice/rice.hpp>
3
+ #include "common.h"
4
+ #include "discord.h"
5
+ #include <cstdint>
6
+ #include <iostream>
7
+
8
+ Module rb_mNetworkManager;
9
+
10
+ std::uint64_t rb_network_manager_get_peer_id() {
11
+ CHECK_CORE_INITIALIZED;
12
+
13
+ std::uint64_t peerId;
14
+
15
+ DiscordSDK.core->NetworkManager().GetPeerId(&peerId);
16
+
17
+ return peerId;
18
+ }
19
+
20
+ int rb_network_manager_flush() {
21
+ CHECK_CORE_INITIALIZED;
22
+
23
+ return (int) DiscordSDK.core->NetworkManager().Flush();
24
+ }
25
+
26
+ int rb_network_manager_open_peer(std::uint64_t peer_id, const char* route_data) {
27
+ CHECK_CORE_INITIALIZED;
28
+
29
+ return (int) DiscordSDK.core->NetworkManager().OpenPeer(peer_id, route_data);
30
+ }
31
+
32
+ int rb_network_manager_update_peer(std::uint64_t peer_id, const char* route_data) {
33
+ CHECK_CORE_INITIALIZED;
34
+
35
+ return (int) DiscordSDK.core->NetworkManager().UpdatePeer(peer_id, route_data);
36
+ }
37
+
38
+ int rb_network_manager_close_peer(std::uint64_t peer_id) {
39
+ CHECK_CORE_INITIALIZED;
40
+
41
+ return (int) DiscordSDK.core->NetworkManager().ClosePeer(peer_id);
42
+ }
43
+
44
+ int rb_network_manager_open_channel(std::uint64_t peer_id, std::uint8_t channel_id, bool reliable) {
45
+ CHECK_CORE_INITIALIZED;
46
+
47
+ return (int) DiscordSDK.core->NetworkManager().OpenChannel(peer_id, channel_id, reliable);
48
+ }
49
+
50
+ int rb_network_manager_close_channel(std::uint64_t peer_id, std::uint8_t channel_id) {
51
+ CHECK_CORE_INITIALIZED;
52
+
53
+ return (int) DiscordSDK.core->NetworkManager().CloseChannel(peer_id, channel_id);
54
+ }
55
+
56
+ int rb_network_manager_send_message(std::uint64_t peer_id, std::uint8_t channel_id, Array rb_data) {
57
+ CHECK_CORE_INITIALIZED;
58
+
59
+ std::uint32_t data_length = rb_array_len(rb_data);
60
+ std::uint8_t data[data_length];
61
+
62
+ int value;
63
+ for (std::uint32_t i = 0; i < data_length; i++) {
64
+ value = NUM2INT(
65
+ rb_ary_entry(rb_data, i)
66
+ );
67
+ if (value > 255 || value < 0) {
68
+ rb_raise(rb_eRangeError, "Expected Integer between 0 and 255, encountered %d at index %d", value, i);
69
+ return 4;
70
+ }
71
+ data[i] = (std::uint8_t) value;
72
+ }
73
+
74
+ return (int) DiscordSDK.core->NetworkManager().SendMessage(peer_id, channel_id, data, data_length);
75
+ }
76
+
77
+
78
+ int rb_network_manager_on_message_connect() {
79
+ CHECK_CORE_INITIALIZED;
80
+
81
+ VALUE event_proc = rb_common_get_event_proc(4);
82
+ int token = DiscordSDK.core->NetworkManager().OnMessage.Connect(
83
+ [event_proc](std::uint64_t peer_id, std::uint8_t channel_id, std::uint8_t* data, std::uint32_t data_length) {
84
+ if (event_proc == Qnil)
85
+ return;
86
+
87
+ if (!rb_obj_is_kind_of(event_proc, rb_cProc))
88
+ rb_raise(rb_eTypeError, "Proc expected in callback, got %d instead", rb_obj_classname(event_proc));
89
+
90
+ VALUE rb_data = rb_ary_new();
91
+ for (int i = 0; i < data_length; i++) {
92
+ rb_ary_push(rb_data, INT2NUM(data[i]));
93
+ }
94
+
95
+ VALUE array = rb_ary_new_from_args(4, event_proc, INT2NUM(peer_id), INT2NUM(channel_id), rb_data);
96
+
97
+ int state;
98
+ state = rb_discord_call_proc(array);
99
+
100
+ LOG_ERROR_IF_STATE;
101
+ }
102
+ );
103
+ rb_common_add_proc_to_hash(Symbol("on_message" + token), event_proc);
104
+
105
+ return token;
106
+ }
107
+
108
+ Object rb_network_manager_on_message_disconnect(int token) {
109
+ CHECK_CORE_INITIALIZED;
110
+
111
+ DiscordSDK.core->NetworkManager().OnMessage.Disconnect(token);
112
+ rb_hash_delete(rb_oProcEvents, Symbol("on_message" + token));
113
+
114
+ return Qnil;
115
+ }
116
+
117
+ int rb_network_manager_on_route_update_connect() {
118
+ CHECK_CORE_INITIALIZED;
119
+
120
+ VALUE event_proc = rb_common_get_event_proc(1);
121
+ int token = DiscordSDK.core->NetworkManager().OnRouteUpdate.Connect(
122
+ [event_proc](const char* route_data) {
123
+ if (event_proc == Qnil)
124
+ return;
125
+
126
+ if (!rb_obj_is_kind_of(event_proc, rb_cProc))
127
+ rb_raise(rb_eTypeError, "Proc expected in callback, got %d instead", rb_obj_classname(event_proc));
128
+
129
+ VALUE array = rb_ary_new_from_args(2, event_proc, rb_str_new_cstr(route_data));
130
+
131
+ int state;
132
+ state = rb_discord_call_proc(array);
133
+
134
+ LOG_ERROR_IF_STATE;
135
+ }
136
+ );
137
+ rb_common_add_proc_to_hash(Symbol("on_route_update" + token), event_proc);
138
+
139
+ return token;
140
+ }
141
+
142
+ Object rb_network_manager_on_route_update_disconnect(int token) {
143
+ CHECK_CORE_INITIALIZED;
144
+
145
+ DiscordSDK.core->NetworkManager().OnRouteUpdate.Disconnect(token);
146
+ rb_hash_delete(rb_oProcEvents, Symbol("on_route_update" + token));
147
+
148
+ return Qnil;
149
+ }
150
+
151
+ void rb_network_init_manager(Module module) {
152
+ rb_mNetworkManager = define_module_under(module, "NetworkManager");
153
+ rb_mNetworkManager.define_module_function("get_peer_id", &rb_network_manager_get_peer_id);
154
+ rb_mNetworkManager.define_module_function("flush", &rb_network_manager_flush);
155
+ rb_mNetworkManager.define_module_function("open_peer", &rb_network_manager_open_peer);
156
+ rb_mNetworkManager.define_module_function("update_peer", &rb_network_manager_update_peer);
157
+ rb_mNetworkManager.define_module_function("close_peer", &rb_network_manager_close_peer);
158
+ rb_mNetworkManager.define_module_function("open_channel", &rb_network_manager_open_channel);
159
+ rb_mNetworkManager.define_module_function("close_channel", &rb_network_manager_close_channel);
160
+ rb_mNetworkManager.define_module_function("send_message", &rb_network_manager_send_message);
161
+ DEF_METHOD_EVENT(rb_mNetworkManager, message, network_manager);
162
+ DEF_METHOD_EVENT(rb_mNetworkManager, route_update, network_manager);
163
+ }
@@ -0,0 +1,8 @@
1
+ #pragma once
2
+
3
+ #include "rdiscord_sdk.h"
4
+
5
+ using namespace Rice;
6
+
7
+ extern Module rb_NetworkManager;
8
+ void rb_network_init_manager(Module module);
@@ -0,0 +1,112 @@
1
+ #include "gem_overlay_manager.h"
2
+ #include <rice/rice.hpp>
3
+ #include "common.h"
4
+ #include "discord.h"
5
+
6
+ using namespace Rice;
7
+
8
+ Module rb_mOverlayManager;
9
+
10
+ bool rb_overlay_manager_is_enabled() {
11
+ CHECK_CORE_INITIALIZED;
12
+
13
+ bool enabled;
14
+
15
+ DiscordSDK.core->OverlayManager().IsEnabled(&enabled);
16
+
17
+ return enabled;
18
+ }
19
+
20
+ bool rb_overlay_manager_is_locked() {
21
+ CHECK_CORE_INITIALIZED;
22
+
23
+ bool locked;
24
+
25
+ DiscordSDK.core->OverlayManager().IsLocked(&locked);
26
+
27
+ return locked;
28
+ }
29
+
30
+ void rb_overlay_manager_set_locked(bool locked) {
31
+ CHECK_CORE_INITIALIZED;
32
+
33
+ VALUE callback_proc = rb_common_get_callback_proc(1);
34
+ DiscordSDK.core->OverlayManager().SetLocked(
35
+ locked,
36
+ rb_discord_callback_wrapper_basic(callback_proc)
37
+ );
38
+ }
39
+
40
+ void rb_overlay_manager_open_activity_invite(int type) {
41
+ CHECK_CORE_INITIALIZED;
42
+
43
+ VALUE callback_proc = rb_common_get_callback_proc(1);
44
+ DiscordSDK.core->OverlayManager().OpenActivityInvite(
45
+ (discord::ActivityActionType) type,
46
+ rb_discord_callback_wrapper_basic(callback_proc)
47
+ );
48
+ }
49
+
50
+ void rb_activity_open_guild_invite(const char* code) {
51
+ CHECK_CORE_INITIALIZED;
52
+
53
+ VALUE callback_proc = rb_common_get_callback_proc(1);
54
+ DiscordSDK.core->OverlayManager().OpenGuildInvite(
55
+ code,
56
+ rb_discord_callback_wrapper_basic(callback_proc)
57
+ );
58
+ }
59
+
60
+ void rb_overlay_manager_open_voice_settings() {
61
+ CHECK_CORE_INITIALIZED;
62
+
63
+ VALUE callback_proc = rb_common_get_callback_proc(1);
64
+ DiscordSDK.core->OverlayManager().OpenVoiceSettings(
65
+ rb_discord_callback_wrapper_basic(callback_proc)
66
+ );
67
+ }
68
+
69
+ int rb_overlay_manager_on_toggle_connect() {
70
+ CHECK_CORE_INITIALIZED;
71
+
72
+ VALUE event_proc = rb_common_get_event_proc(1);
73
+ int token = DiscordSDK.core->OverlayManager().OnToggle.Connect(
74
+ [event_proc](bool locked) {
75
+ if (event_proc == Qnil)
76
+ return;
77
+
78
+ if (!rb_obj_is_kind_of(event_proc, rb_cProc))
79
+ rb_raise(rb_eTypeError, "Proc expected in callback, got %d instead", rb_obj_classname(event_proc));
80
+
81
+
82
+ VALUE array = rb_ary_new_from_args(2, event_proc, BOOL2RB(locked));
83
+ int state;
84
+ rb_protect(rb_discord_call_proc, array, &state);
85
+
86
+ LOG_ERROR_IF_STATE;
87
+ }
88
+ );
89
+ rb_common_add_proc_to_hash(Symbol("on_toggle" + token), event_proc);
90
+
91
+ return token;
92
+ }
93
+
94
+ Object rb_overlay_manager_on_toggle_disconnect(int token) {
95
+ CHECK_CORE_INITIALIZED;
96
+
97
+ DiscordSDK.core->OverlayManager().OnToggle.Disconnect(token);
98
+ rb_hash_delete(rb_oProcEvents, Symbol("on_toggle" + token));
99
+
100
+ return Qnil;
101
+ }
102
+
103
+ void rb_overlay_init_manager(Module module) {
104
+ rb_mOverlayManager = define_module_under(module, "OverlayManager");
105
+ rb_mOverlayManager.define_module_function("is_enabled", &rb_overlay_manager_is_enabled);
106
+ rb_mOverlayManager.define_module_function("is_locked", &rb_overlay_manager_is_locked);
107
+ rb_mOverlayManager.define_module_function("set_locked", &rb_overlay_manager_set_locked);
108
+ rb_mOverlayManager.define_module_function("open_activity_invite", &rb_overlay_manager_open_activity_invite);
109
+ rb_mOverlayManager.define_module_function("open_guild_invite", &rb_activity_open_guild_invite);
110
+ rb_mOverlayManager.define_module_function("open_voice_settings", &rb_overlay_manager_open_voice_settings);
111
+ DEF_METHOD_EVENT(rb_mOverlayManager, toggle, overlay_manager);
112
+ }
@@ -0,0 +1,8 @@
1
+ #pragma once
2
+
3
+ #include "rdiscord_sdk.h"
4
+
5
+ using namespace Rice;
6
+
7
+ extern Module rb_mOverlayManager;
8
+ void rb_overlay_init_manager(Module module);
@@ -4,6 +4,8 @@
4
4
  #include "activity.h"
5
5
  #include "user.h"
6
6
  #include "gem_user_manager.h"
7
+ #include "gem_overlay_manager.h"
8
+ #include "gem_network_manager.h"
7
9
 
8
10
  using namespace Rice;
9
11
 
@@ -74,4 +76,6 @@ void Init_rdiscord_sdk()
74
76
  rb_activity_init_class(rb_mDiscord);
75
77
  rb_user_init_class(rb_mDiscord);
76
78
  rb_user_init_manager(rb_mDiscord);
79
+ rb_overlay_init_manager(rb_mDiscord);
80
+ rb_network_init_manager(rb_mDiscord);
77
81
  }
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdiscord_sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Lyons
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-03-29 00:00:00.000000000 Z
11
+ date: 2022-03-30 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -19,6 +19,7 @@ extensions:
19
19
  extra_rdoc_files: []
20
20
  files:
21
21
  - ".rubocop.yml"
22
+ - ".ruby-version"
22
23
  - ".vscode/c_cpp_properties.json"
23
24
  - ".vscode/settings.json"
24
25
  - Gemfile
@@ -36,6 +37,10 @@ files:
36
37
  - ext/rdiscord_sdk/extconf.rb
37
38
  - ext/rdiscord_sdk/gem_activity_manager.cpp
38
39
  - ext/rdiscord_sdk/gem_activity_manager.h
40
+ - ext/rdiscord_sdk/gem_network_manager.cpp
41
+ - ext/rdiscord_sdk/gem_network_manager.h
42
+ - ext/rdiscord_sdk/gem_overlay_manager.cpp
43
+ - ext/rdiscord_sdk/gem_overlay_manager.h
39
44
  - ext/rdiscord_sdk/gem_user_manager.cpp
40
45
  - ext/rdiscord_sdk/gem_user_manager.h
41
46
  - ext/rdiscord_sdk/rdiscord_sdk.cpp
@@ -46,7 +51,6 @@ files:
46
51
  - lib/rdiscord_sdk/enums.rb
47
52
  - lib/rdiscord_sdk/rdiscord_sdk.so
48
53
  - lib/rdiscord_sdk/version.rb
49
- - rdiscord_sdk.gemspec
50
54
  - third-party/include/achievement_manager.cpp
51
55
  - third-party/include/achievement_manager.h
52
56
  - third-party/include/activity_manager.cpp
@@ -86,7 +90,8 @@ files:
86
90
  - third-party/lib/x86_64/discord_game_sdk.dylib
87
91
  - third-party/lib/x86_64/discord_game_sdk.so
88
92
  homepage: https://github.com/Speak2Erase/rdiscord_sdk
89
- licenses: []
93
+ licenses:
94
+ - GPL-3.0
90
95
  metadata:
91
96
  homepage_uri: https://github.com/Speak2Erase/rdiscord_sdk
92
97
  source_code_uri: https://github.com/Speak2Erase/rdiscord_sdk
data/rdiscord_sdk.gemspec DELETED
@@ -1,34 +0,0 @@
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