continued working on discord connector

This commit is contained in:
2025-03-25 14:07:51 +01:00
parent 3f6e695c77
commit ff62edb36b
11 changed files with 845 additions and 12 deletions

2
.gitmodules vendored
View File

@@ -1,4 +1,4 @@
[submodule "src/lib/godot-cpp"]
path = src/lib/godot-cpp
url = https://github.com/godotengine/godot-cpp
branch = 4.1
branch = 4.3

View File

@@ -4,7 +4,14 @@ import os
env = SConscript("src/lib/godot-cpp/SConstruct")
env.Append(CPPPATH=["src/","src/nodes/", "src/lib/discord_social_sdk/include/"])
sources = Glob("src/*.cpp") + Glob("src/nodes/*.cpp")
sources = [Glob("src/*.cpp"), Glob("src/nodes/*.cpp")]
if env["target"] in ["editor", "template_debug"]:
try:
doc_data = env.GodotCPPDocData("src/gen/doc_data.gen.cpp", source=Glob("doc_classes/*.xml"))
sources.append(doc_data)
except AttributeError:
print("Not including class reference as we're targeting a pre-4.3 baseline.")
if env["platform"] == "macos":
discord_library = "libdiscord_partner_sdk.dylib"

View File

@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="DiscordConnector" inherits="DiscordSocialSDK" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/godotengine/godot/master/doc/class.xsd">
<brief_description>
</brief_description>
<description>
</description>
<tutorials>
</tutorials>
<methods>
<method name="connect_user">
<return type="void" />
<description>
</description>
</method>
<method name="refresh_user_token">
<return type="void" />
<param index="0" name="current_refresh_token" type="String" />
<description>
</description>
</method>
<method name="update_user_token">
<return type="void" />
<param index="0" name="access_token" type="String" />
<description>
</description>
</method>
</methods>
<members>
<member name="app_id" type="int" setter="set_app_id" getter="get_app_id" default="0">
</member>
<member name="auto_connect" type="bool" setter="set_auto_connect" getter="get_auto_connect" default="false">
</member>
<member name="auto_encryption_key" type="String" setter="set_auto_encryption_key" getter="get_auto_encryption_key" default="&quot;&quot;">
</member>
<member name="auto_token_manage" type="bool" setter="set_auto_token_manage" getter="get_auto_token_manage" default="false">
</member>
</members>
<signals>
<signal name="user_connected">
<param index="0" name="access_token" type="String" />
<param index="1" name="refresh_token" type="String" />
<param index="2" name="expires_in" type="int" />
<description>
</description>
</signal>
<signal name="user_connection_failed">
<param index="0" name="error" type="String" />
<description>
</description>
</signal>
<signal name="user_token_refresh_failed">
<param index="0" name="error" type="String" />
<description>
</description>
</signal>
<signal name="user_token_refreshed">
<param index="0" name="access_token" type="String" />
<param index="1" name="refresh_token" type="String" />
<param index="2" name="expires_in" type="int" />
<description>
</description>
</signal>
<signal name="user_update_failed">
<param index="0" name="error" type="String" />
<description>
</description>
</signal>
<signal name="user_updated">
<description>
</description>
</signal>
</signals>
</class>

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="DiscordSocialSDK" inherits="Node" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/godotengine/godot/master/doc/class.xsd">
<brief_description>
</brief_description>
<description>
</description>
<tutorials>
</tutorials>
</class>

View File

@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="DiscordUtil" inherits="Object" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/godotengine/godot/master/doc/class.xsd">
<brief_description>
</brief_description>
<description>
</description>
<tutorials>
</tutorials>
<methods>
<method name="debug">
<return type="void" />
<description>
</description>
</method>
<method name="generate_auto_encryption_key">
<return type="String" />
<description>
</description>
</method>
<method name="run_callbacks">
<return type="void" />
<description>
</description>
</method>
<method name="save_tokens">
<return type="void" />
<param index="0" name="access_token" type="String" />
<param index="1" name="refresh_token" type="String" />
<param index="2" name="expires_in" type="int" />
<param index="3" name="auto_encryption_key" type="String" />
<description>
</description>
</method>
</methods>
</class>

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="EditorPresence" inherits="DiscordSocialSDK" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/godotengine/godot/master/doc/class.xsd">
<brief_description>
</brief_description>
<description>
</description>
<tutorials>
</tutorials>
</class>

View File

@@ -45,7 +45,7 @@ script = ExtResource("6_ujijw")
[node name="DiscordConnector" type="DiscordConnector" parent="."]
app_id = 1099618430065324082
auto_connect = true
auto_encryption_key = "nS\"#&bOk4?bFAD0h(h,5=dIp&7o#r#TGKAywD%Gd2IKa%gk0qf"
auto_token_manage = true
script = ExtResource("3_h2yge")
[connection signal="user_connected" from="DiscordConnector" to="DiscordConnector" method="_on_user_connected"]

696
src/gen/doc_data.gen.cpp Normal file
View File

@@ -0,0 +1,696 @@
/* THIS FILE IS GENERATED DO NOT EDIT */
#include <godot_cpp/godot.hpp>
static const char *_doc_data_hash = "-3920927385899744258";
static const int _doc_data_uncompressed_size = 4148;
static const int _doc_data_compressed_size = 684;
static const unsigned char _doc_data_compressed[] = {
120,
218,
237,
87,
193,
114,
218,
48,
16,
61,
39,
95,
225,
209,
161,
183,
96,
146,
92,
58,
20,
146,
67,
211,
94,
154,
166,
157,
161,
153,
233,
205,
35,
75,
139,
81,
99,
75,
174,
36,
7,
248,
251,
174,
44,
139,
98,
195,
0,
45,
208,
118,
166,
185,
192,
90,
171,
221,
247,
118,
181,
43,
175,
135,
183,
243,
34,
143,
158,
65,
27,
161,
228,
136,
92,
246,
250,
36,
2,
201,
20,
23,
50,
27,
145,
199,
47,
239,
47,
94,
147,
232,
246,
230,
124,
200,
114,
106,
76,
36,
105,
1,
35,
114,
39,
12,
83,
154,
191,
85,
82,
2,
179,
74,
147,
72,
200,
41,
104,
97,
205,
82,
55,
86,
76,
208,
124,
124,
247,
129,
68,
8,
32,
205,
96,
110,
196,
136,
76,
173,
45,
7,
113,
60,
155,
205,
122,
179,
235,
158,
210,
89,
124,
213,
239,
95,
198,
95,
63,
222,
143,
217,
20,
10,
122,
33,
164,
177,
84,
50,
64,
43,
35,
6,
82,
61,
32,
158,
41,
41,
3,
175,
191,
87,
140,
218,
154,
168,
243,
100,
208,
149,
166,
179,
94,
38,
236,
180,
74,
43,
3,
154,
41,
105,
65,
218,
30,
83,
69,
156,
41,
174,
240,
33,
19,
18,
188,
28,
23,
212,
88,
208,
49,
87,
44,
174,
163,
233,
205,
13,
39,
55,
231,
103,
195,
84,
11,
152,
36,
28,
12,
211,
162,
116,
254,
221,
98,
188,
113,
181,
187,
169,
243,
108,
43,
76,
7,
6,
110,
106,
101,
235,
169,
0,
59,
85,
220,
137,
65,
110,
178,
201,
124,
26,
19,
23,
128,
163,
131,
122,
13,
182,
210,
50,
178,
139,
18,
245,
207,
74,
112,
18,
197,
94,
211,
198,
59,
91,
99,
128,
11,
222,
249,
58,
142,
134,
137,
6,
51,
173,
113,
18,
171,
158,
64,
238,
68,
43,
169,
166,
5,
30,
46,
135,
249,
136,
96,
101,
52,
132,
43,
173,
49,
203,
73,
112,
232,
125,
53,
246,
99,
171,
177,
116,
142,
193,
183,
42,
57,
181,
112,
56,
93,
202,
24,
24,
115,
52,
150,
65,
108,
14,
181,
72,
177,
119,
26,
242,
78,
14,
160,
101,
153,
56,
102,
30,
78,
72,
75,
34,
3,
22,
203,
111,
68,
240,
63,
9,
234,
172,
89,
203,
86,
214,
56,
76,
104,
149,
91,
23,
65,
128,
118,
142,
55,
96,
96,
121,
37,
77,
245,
4,
164,
84,
169,
188,
3,
213,
218,
213,
2,
108,
105,
150,
176,
19,
44,
88,
216,
7,
26,
239,
9,
189,
168,
83,
148,
60,
193,
162,
155,
218,
53,
14,
221,
237,
107,
84,
186,
27,
150,
140,
94,
125,
175,
148,
125,
227,
127,
247,
33,
86,
31,
117,
82,
80,
73,
51,
216,
145,
152,
246,
214,
53,
74,
109,
245,
246,
20,
5,
177,
46,
12,
35,
50,
233,
27,
63,
200,
161,
170,
93,
57,
55,
73,
7,
78,
14,
44,
220,
150,
225,
37,
233,
116,
250,
222,
150,
87,
193,
18,
230,
165,
64,
211,
68,
200,
86,
233,
238,
223,
38,
62,
214,
237,
97,
187,
3,
158,
80,
145,
239,
8,
31,
180,
118,
175,
150,
223,
109,
216,
173,
76,
252,
185,
134,
60,
253,
75,
100,
254,
183,
154,
104,
110,
249,
191,
124,
4,
158,
69,
192,
255,
21,
111,
65,
196,
86,
31,
250,
177,
2,
133,
3,
134,
170,
149,
193,
233,
231,
80,
245,
160,
56,
188,
12,
82,
199,
75,
242,
163,
21,
249,
106,
126,
63,
165,
223,
234,
119,
224,
75,
134,
183,
143,
170,
28,
210,
42,
59,
229,
140,
154,
129,
4,
237,
238,
131,
77,
3,
193,
6,
220,
227,
77,
155,
186,
146,
9,
163,
121,
158,
82,
246,
100,
78,
25,
162,
161,
207,
224,
111,
97,
115,
186,
129,
246,
207,
190,
3,
90,
54,
215,
100,
255,
25,
241,
176,
241,
251,
176,
171,
224,
29,
23,
88,
242,
159,
49,
42,
168,
187,
248,
229,
19,
118,
223,
155,
247,
7,
100,
41,
93,
61,
};
static godot::internal::DocDataRegistration _doc_data_registration(_doc_data_hash, _doc_data_uncompressed_size, _doc_data_compressed_size, _doc_data_compressed);

View File

@@ -7,8 +7,8 @@ void DiscordConnector::_bind_methods()
BIND_SET_GET(DiscordConnector, app_id, Variant::STRING, godot::PROPERTY_HINT_RANGE, "-99999,99999,or_less,or_greater,hide_slider");
ADD_GROUP("Automatic", "auto_");
BIND_SET_GET(DiscordConnector, auto_connect, Variant::BOOL);
BIND_SET_GET(DiscordConnector, auto_encryption_key, Variant::STRING, godot::PROPERTY_HINT_PASSWORD);
BIND_SET_GET(DiscordConnector, auto_token_manage, Variant::BOOL);
BIND_SET_GET(DiscordConnector, auto_encryption_key, Variant::STRING, godot::PROPERTY_HINT_NONE, "", godot::PROPERTY_USAGE_NO_EDITOR);
BIND_METHOD(DiscordConnector, connect_user);
BIND_METHOD(DiscordConnector, update_user_token, "access_token");
BIND_METHOD(DiscordConnector, refresh_user_token, "current_refresh_token");
@@ -55,14 +55,21 @@ void DiscordConnector::_ready()
}
else
{
if (!Engine::get_singleton()->is_editor_hint() && !editor_process)
if (!Engine::get_singleton()->is_editor_hint())
{
if (auto_encryption_key.is_empty() && auto_token_manage)
{
DiscordUtil::get_singleton()->delete_tokens();
auto_encryption_key = DiscordUtil::get_singleton()->generate_auto_encryption_key();
}
if (auto_connect && !editor_process)
{
if (auto_connect)
connect_user();
}
}
}
}
}
void DiscordConnector::_process(double delta)
{
@@ -70,11 +77,6 @@ void DiscordConnector::_process(double delta)
{
discordpp::RunCallbacks();
}
if (auto_encryption_key == "" && auto_token_manage)
{
DiscordUtil::get_singleton()->delete_tokens();
auto_encryption_key = DiscordUtil::get_singleton()->generate_auto_encryption_key();
}
}
void DiscordConnector::set_auto_connect(bool value)

View File

@@ -36,6 +36,8 @@ public:
void update_user_token(String access_token);
void refresh_user_token(String refresh_token);
void refresh_auto_encryption_key();
DiscordConnector();
~DiscordConnector();
void _ready() override;