fixed app id type and DiscordConnector node
This commit is contained in:
@@ -1,13 +0,0 @@
|
||||
## This is a GDscript Node wich gets automatically added as Autoload while installing the addon.
|
||||
##
|
||||
## It can run in the background to comunicate with Discord.
|
||||
## You don't need to use it. If you remove it make sure to run [code]DiscordUtil.run_callbacks()[/code] in a [code]_process[/code] function.
|
||||
##
|
||||
## @tutorial: https://github.com/vaporvee/discord-rpc-godot/wiki
|
||||
extends Node
|
||||
|
||||
func _ready() -> void:
|
||||
pass
|
||||
|
||||
func _process(_delta) -> void:
|
||||
DiscordUtil.run_callbacks()
|
@@ -1 +0,0 @@
|
||||
uid://dc5abjov0ebdr
|
@@ -33,11 +33,10 @@ func _enable_plugin() -> void:
|
||||
print("IGNORE RED ERROR MESSAGES BEFORE THE SECOND RESTART!")
|
||||
|
||||
func _disable_plugin() -> void:
|
||||
remove_autoload_singleton("DiscordUtilLoader")
|
||||
FileAccess.open("res://addons/discord-rpc-gd/bin/.gdignore",FileAccess.WRITE)
|
||||
remove_custom_type("DiscordSocialSDKDebug")
|
||||
get_editor_interface().get_editor_settings().erase("DiscordSocialSDK/EditorPresence/enabled")
|
||||
push_warning("Please restart the editor to fully disable the DiscordUtil plugin")
|
||||
push_warning("Please restart the editor to fully disable the Discord Social SDK plugin")
|
||||
|
||||
func save_and_restart() -> void:
|
||||
get_editor_interface().restart_editor(true)
|
||||
|
@@ -1,64 +0,0 @@
|
||||
extends Node
|
||||
|
||||
func _ready() -> void:
|
||||
if GDExtensionManager.is_extension_loaded("res://addons/discord-rpc-gd/bin/discord-rpc-gd.gdextension"):
|
||||
set_activity()
|
||||
DiscordUtil.connect("activity_join_request",_on_activity_join_request)
|
||||
#DiscordUtil.connect("activity_join",_on_activity_join)
|
||||
DiscordUtil.connect("activity_spectate",_on_activity_spectate)
|
||||
DiscordUtil.connect("relationships_init",_on_relationship_init)
|
||||
DiscordUtil.connect("updated_relationship", _on_updated_relationship)
|
||||
|
||||
func set_activity() -> void:
|
||||
#DiscordUtil.clear(false)
|
||||
DiscordUtil.app_id = 1099618430065324082
|
||||
DiscordUtil.debug()
|
||||
#DiscordUtil.details = "A demo activity by vaporvee#1231"
|
||||
#DiscordUtil.state = "Checkpoint 23/23"
|
||||
#
|
||||
#DiscordUtil.large_image = "example_game"
|
||||
#DiscordUtil.large_image_text = "Try it now!"
|
||||
#DiscordUtil.small_image = "boss"
|
||||
#DiscordUtil.small_image_text = "Fighting the end boss! D:"
|
||||
#DiscordUtil.end_timestamp = int(Time.get_unix_time_from_system()) + 3600 # +1 hour in unix time
|
||||
|
||||
# It is NOT recommended to manage secrets locally! It's meant to be a payload wich the server understands and
|
||||
# returns the other variables like current_party_size, party_id etc. Most of the values must differ from the others.
|
||||
#var my_secret: String = str(randi_range(0,999999))
|
||||
|
||||
#DiscordUtil.party_id = "mylobbycanbeeverything_" + my_secret
|
||||
#DiscordUtil.current_party_size = 1
|
||||
#DiscordUtil.max_party_size = 4
|
||||
#DiscordUtil.match_secret = "m_" + my_secret #better use seeds with 1 to 1 range instead of just chars
|
||||
#DiscordUtil.join_secret = "j_" + my_secret
|
||||
#DiscordUtil.spectate_secret = "s_" + my_secret
|
||||
#DiscordUtil.is_public_party = true
|
||||
#DiscordUtil.instanced = true #required for spectate
|
||||
#DiscordUtil.start_timestamp = int(Time.get_unix_time_from_system())
|
||||
DiscordUtil.register_command("C:\\Users\\yanni\\Desktop\\demo\\DiscordUtil.exe")
|
||||
#DiscordUtil.register_steam(1389990)
|
||||
DiscordUtil.refresh()
|
||||
|
||||
var user_request: Dictionary;
|
||||
|
||||
func _on_activity_join_request(user_requesting: Dictionary) -> void:
|
||||
print(user_requesting)
|
||||
user_request = user_requesting
|
||||
|
||||
#func _on_activity_join(secret: String) -> void:
|
||||
#if(DiscordUtil.join_secret != secret):
|
||||
#DiscordUtil.current_party_size = clamp(int(secret) + 1, 0, DiscordUtil.max_party_size)
|
||||
#DiscordUtil.party_id = secret.replace("j_","mylobbycanbeeverything_")
|
||||
#DiscordUtil.match_secret = secret.replace("j_","m_")
|
||||
#DiscordUtil.join_secret = secret
|
||||
#DiscordUtil.spectate_secret = secret.replace("j_","s_")
|
||||
#DiscordUtil.refresh()
|
||||
|
||||
func _on_activity_spectate(secret: String) -> void:
|
||||
print(secret)
|
||||
|
||||
func _on_relationship_init() -> void:
|
||||
print("initialized")
|
||||
|
||||
func _on_updated_relationship(relationship: Dictionary) -> void:
|
||||
print(relationship)
|
@@ -1 +0,0 @@
|
||||
uid://e0nds76y78bx
|
@@ -1,11 +1,76 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://dyc3kseph4el7"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://e0nds76y78bx" path="res://main.gd" id="1_kl8ri"]
|
||||
[ext_resource type="Texture2D" uid="uid://b3qm246m7pnsx" path="res://assets/Logo_V2.png" id="2_gd222"]
|
||||
[ext_resource type="Script" uid="uid://46tue7u6crd6" path="res://addons/discord-rpc-gd/nodes/debug.gd" id="6_ujijw"]
|
||||
|
||||
[sub_resource type="GDScript" id="GDScript_0xm2m"]
|
||||
script/source = "extends Node
|
||||
|
||||
func _ready() -> void:
|
||||
if GDExtensionManager.is_extension_loaded(\"res://addons/discord-rpc-gd/bin/discord-rpc-gd.gdextension\"):
|
||||
set_activity()
|
||||
DiscordUtil.connect(\"activity_join_request\",_on_activity_join_request)
|
||||
#DiscordUtil.connect(\"activity_join\",_on_activity_join)
|
||||
DiscordUtil.connect(\"activity_spectate\",_on_activity_spectate)
|
||||
DiscordUtil.connect(\"relationships_init\",_on_relationship_init)
|
||||
DiscordUtil.connect(\"updated_relationship\", _on_updated_relationship)
|
||||
|
||||
func set_activity() -> void:
|
||||
#DiscordUtil.clear(false)
|
||||
DiscordUtil.app_id = 1099618430065324082
|
||||
#DiscordUtil.details = \"A demo activity by vaporvee#1231\"
|
||||
#DiscordUtil.state = \"Checkpoint 23/23\"
|
||||
#
|
||||
#DiscordUtil.large_image = \"example_game\"
|
||||
#DiscordUtil.large_image_text = \"Try it now!\"
|
||||
#DiscordUtil.small_image = \"boss\"
|
||||
#DiscordUtil.small_image_text = \"Fighting the end boss! D:\"
|
||||
#DiscordUtil.end_timestamp = int(Time.get_unix_time_from_system()) + 3600 # +1 hour in unix time
|
||||
|
||||
# It is NOT recommended to manage secrets locally! It's meant to be a payload wich the server understands and
|
||||
# returns the other variables like current_party_size, party_id etc. Most of the values must differ from the others.
|
||||
#var my_secret: String = str(randi_range(0,999999))
|
||||
|
||||
#DiscordUtil.party_id = \"mylobbycanbeeverything_\" + my_secret
|
||||
#DiscordUtil.current_party_size = 1
|
||||
#DiscordUtil.max_party_size = 4
|
||||
#DiscordUtil.match_secret = \"m_\" + my_secret #better use seeds with 1 to 1 range instead of just chars
|
||||
#DiscordUtil.join_secret = \"j_\" + my_secret
|
||||
#DiscordUtil.spectate_secret = \"s_\" + my_secret
|
||||
#DiscordUtil.is_public_party = true
|
||||
#DiscordUtil.instanced = true #required for spectate
|
||||
#DiscordUtil.start_timestamp = int(Time.get_unix_time_from_system())
|
||||
DiscordUtil.register_command(\"C:\\\\Users\\\\yanni\\\\Desktop\\\\demo\\\\DiscordUtil.exe\")
|
||||
#DiscordUtil.register_steam(1389990)
|
||||
DiscordUtil.refresh()
|
||||
|
||||
var user_request: Dictionary;
|
||||
|
||||
func _on_activity_join_request(user_requesting: Dictionary) -> void:
|
||||
print(user_requesting)
|
||||
user_request = user_requesting
|
||||
|
||||
#func _on_activity_join(secret: String) -> void:
|
||||
#if(DiscordUtil.join_secret != secret):
|
||||
#DiscordUtil.current_party_size = clamp(int(secret) + 1, 0, DiscordUtil.max_party_size)
|
||||
#DiscordUtil.party_id = secret.replace(\"j_\",\"mylobbycanbeeverything_\")
|
||||
#DiscordUtil.match_secret = secret.replace(\"j_\",\"m_\")
|
||||
#DiscordUtil.join_secret = secret
|
||||
#DiscordUtil.spectate_secret = secret.replace(\"j_\",\"s_\")
|
||||
#DiscordUtil.refresh()
|
||||
|
||||
func _on_activity_spectate(secret: String) -> void:
|
||||
print(secret)
|
||||
|
||||
func _on_relationship_init() -> void:
|
||||
print(\"initialized\")
|
||||
|
||||
func _on_updated_relationship(relationship: Dictionary) -> void:
|
||||
print(relationship)
|
||||
"
|
||||
|
||||
[node name="Node" type="Node"]
|
||||
script = ExtResource("1_kl8ri")
|
||||
script = SubResource("GDScript_0xm2m")
|
||||
|
||||
[node name="ColorRect" type="ColorRect" parent="."]
|
||||
anchors_preset = 15
|
||||
@@ -44,4 +109,5 @@ text = "[center][font s=60]DiscordUtil Test"
|
||||
script = ExtResource("6_ujijw")
|
||||
|
||||
[node name="DiscordConnector" type="DiscordConnector" parent="."]
|
||||
process_mode = 4
|
||||
app_id = 1099618430065324082
|
||||
auto_connect = true
|
||||
|
@@ -1 +0,0 @@
|
||||
extends Node
|
@@ -1 +0,0 @@
|
||||
uid://pi17u5foe8ti
|
@@ -19,10 +19,6 @@ boot_splash/fullsize=false
|
||||
boot_splash/image="res://assets/discordgodot_cover.png"
|
||||
config/icon="res://assets/Logo_V2.png"
|
||||
|
||||
[autoload]
|
||||
|
||||
PluginManager="*res://plugin_manager.gd"
|
||||
|
||||
[debug]
|
||||
|
||||
gdscript/warnings/untyped_declaration=1
|
||||
|
@@ -8,6 +8,6 @@
|
||||
#define SET_GET(class_name, variable, setter, ...) decltype(class_name::variable) class_name::get_##variable() { return variable; } void class_name::set_##variable(decltype(class_name::variable) value) { variable = value; setter; }
|
||||
|
||||
#define RESOLVE_TYPE(default_value) \
|
||||
typename std::conditional<std::is_same<decltype(default_value), int>::value, uint64_t, decltype(default_value)>::type
|
||||
typename std::conditional<std::is_same<decltype(default_value), int>::value, int64_t, decltype(default_value)>::type
|
||||
|
||||
#define H_SET_GET(property_name, default_value) private: RESOLVE_TYPE(default_value) property_name = default_value; public: RESOLVE_TYPE(default_value) get_##property_name(); void set_##property_name(RESOLVE_TYPE(default_value) value);
|
@@ -4,9 +4,10 @@ DiscordConnector *DiscordConnector::singleton = nullptr;
|
||||
|
||||
void DiscordConnector::_bind_methods()
|
||||
{
|
||||
BIND_SET_GET(DiscordConnector, app_id, Variant::INT, godot::PROPERTY_HINT_RANGE, "-99999,99999,or_less,or_greater,hide_slider");
|
||||
BIND_SET_GET(DiscordConnector, app_id, Variant::STRING, godot::PROPERTY_HINT_RANGE, "-99999,99999,or_less,or_greater,hide_slider");
|
||||
BIND_SET_GET(DiscordConnector, auto_connect, Variant::BOOL);
|
||||
BIND_SET_GET(DiscordConnector, token_auto_manage, Variant::BOOL);
|
||||
BIND_METHOD(DiscordConnector, connect);
|
||||
}
|
||||
DiscordConnector::DiscordConnector()
|
||||
{
|
||||
@@ -24,24 +25,29 @@ DiscordConnector *DiscordConnector::get_singleton()
|
||||
void DiscordConnector::_ready()
|
||||
{
|
||||
client = std::make_shared<discordpp::Client>();
|
||||
if (!Engine::get_singleton()->is_editor_hint() && !editor_process)
|
||||
{
|
||||
if (auto_connect)
|
||||
connect();
|
||||
}
|
||||
}
|
||||
|
||||
void DiscordConnector::_process(double delta)
|
||||
{
|
||||
if (Engine::get_singleton()->is_editor_hint() && !editor_process)
|
||||
if (!Engine::get_singleton()->is_editor_hint() && !editor_process)
|
||||
{
|
||||
discordpp::RunCallbacks();
|
||||
}
|
||||
}
|
||||
|
||||
void DiscordConnector::set_app_id(uint64_t value)
|
||||
void DiscordConnector::set_app_id(int64_t value)
|
||||
{
|
||||
app_id = value;
|
||||
app_id = static_cast<int64_t>(value);
|
||||
}
|
||||
|
||||
uint64_t DiscordConnector::get_app_id()
|
||||
int64_t DiscordConnector::get_app_id()
|
||||
{
|
||||
return app_id;
|
||||
return static_cast<int64_t>(app_id);
|
||||
}
|
||||
|
||||
void DiscordConnector::set_token_auto_manage(bool value)
|
||||
@@ -62,4 +68,39 @@ void DiscordConnector::set_auto_connect(bool value)
|
||||
bool DiscordConnector::get_auto_connect()
|
||||
{
|
||||
return auto_connect;
|
||||
}
|
||||
|
||||
void DiscordConnector::connect()
|
||||
{
|
||||
auto codeVerifier = client->CreateAuthorizationCodeVerifier();
|
||||
|
||||
discordpp::AuthorizationArgs args{};
|
||||
args.SetClientId(app_id);
|
||||
args.SetScopes(discordpp::Client::GetDefaultPresenceScopes());
|
||||
args.SetCodeChallenge(codeVerifier.Challenge());
|
||||
|
||||
// Begin authentication process // TODO: option to open browser
|
||||
client->Authorize(args, [this, codeVerifier](auto result, auto code, auto redirectUri)
|
||||
{
|
||||
if (!result.Successful()) {
|
||||
UtilityFunctions::push_error("Authentication Error: " + String(result.Error().c_str()));
|
||||
return;
|
||||
} else {
|
||||
client->GetToken(app_id, code, codeVerifier.Verifier(), redirectUri,
|
||||
[this](discordpp::ClientResult result,
|
||||
std::string accessToken, // needs to be stored securely
|
||||
std::string refreshToken, // needs to be stored securely
|
||||
discordpp::AuthorizationTokenType tokenType,
|
||||
int32_t expiresIn,
|
||||
std::string scope) {
|
||||
client->UpdateToken(discordpp::AuthorizationTokenType::Bearer, accessToken, [this](discordpp::ClientResult result) {
|
||||
if(result.Successful()) {
|
||||
client->Connect();
|
||||
UtilityFunctions::print("TODO: connection success signal");
|
||||
} else {
|
||||
UtilityFunctions::push_error("Token update error: " + String(result.Error().c_str()));
|
||||
}
|
||||
});
|
||||
});
|
||||
} });
|
||||
}
|
@@ -26,6 +26,8 @@ public:
|
||||
H_SET_GET(token_auto_manage, true)
|
||||
H_SET_GET(auto_connect, false)
|
||||
|
||||
void connect();
|
||||
|
||||
DiscordConnector();
|
||||
~DiscordConnector();
|
||||
void _ready() override;
|
||||
|
12
src/util.cpp
12
src/util.cpp
@@ -131,7 +131,7 @@ void DiscordUtil::debug()
|
||||
} });
|
||||
}
|
||||
|
||||
void DiscordUtil::set_app_id(uint64_t value)
|
||||
void DiscordUtil::set_app_id(int64_t value)
|
||||
{
|
||||
app_id = value;
|
||||
if (app_id > 0)
|
||||
@@ -167,7 +167,7 @@ void DiscordUtil::set_app_id(uint64_t value)
|
||||
*/
|
||||
}
|
||||
}
|
||||
uint64_t DiscordUtil::get_app_id()
|
||||
int64_t DiscordUtil::get_app_id()
|
||||
{
|
||||
if (app_id != 0)
|
||||
return app_id;
|
||||
@@ -261,19 +261,19 @@ void DiscordUtil::open_voice_settings()
|
||||
return;
|
||||
}
|
||||
|
||||
void DiscordUtil::accept_join_request(uint64_t user_id)
|
||||
void DiscordUtil::accept_join_request(int64_t user_id)
|
||||
{
|
||||
if (get_is_discord_working())
|
||||
// core->ActivityManager().SendRequestReply(user_id, static_cast<discordpp::ActivityJoinRequestReply>(1), {});
|
||||
return;
|
||||
}
|
||||
void DiscordUtil::send_invite(uint64_t user_id, bool is_spectate = false, String message_content = "")
|
||||
void DiscordUtil::send_invite(int64_t user_id, bool is_spectate = false, String message_content = "")
|
||||
{
|
||||
if (get_is_discord_working())
|
||||
// core->ActivityManager().SendInvite(user_id, static_cast<discordpp::ActivityActionType>(is_spectate + 1), message_content.utf8().get_data(), {});
|
||||
return;
|
||||
}
|
||||
void DiscordUtil::accept_invite(uint64_t user_id)
|
||||
void DiscordUtil::accept_invite(int64_t user_id)
|
||||
{
|
||||
if (get_is_discord_working())
|
||||
// core->ActivityManager().AcceptInvite(user_id, {});
|
||||
@@ -304,7 +304,7 @@ Dictionary DiscordUtil::get_current_user()
|
||||
return userdict;
|
||||
}
|
||||
|
||||
Dictionary DiscordUtil::get_relationship(uint64_t user_id)
|
||||
Dictionary DiscordUtil::get_relationship(int64_t user_id)
|
||||
{
|
||||
Dictionary dict;
|
||||
if (get_is_discord_working())
|
||||
|
16
src/util.h
16
src/util.h
@@ -28,13 +28,13 @@ public:
|
||||
~DiscordUtil();
|
||||
|
||||
// INTERBNAL
|
||||
uint64_t old_app_id;
|
||||
int64_t old_app_id;
|
||||
Dictionary relationship2dict(discordpp::RelationshipHandle relationship);
|
||||
Dictionary user2dict(discordpp::UserHandle user);
|
||||
///
|
||||
void set_app_id(uint64_t value);
|
||||
uint64_t get_app_id();
|
||||
uint64_t app_id = 0; // needs to be directly set to 0 or it will crash randomly
|
||||
void set_app_id(int64_t value);
|
||||
int64_t get_app_id();
|
||||
int64_t app_id = 0; // needs to be directly set to 0 or it will crash randomly
|
||||
H_SET_GET(is_overlay_locked, false)
|
||||
|
||||
void debug();
|
||||
@@ -46,13 +46,13 @@ public:
|
||||
void open_invite_overlay(bool is_spectate);
|
||||
void open_server_invite_overlay(String invite_code);
|
||||
void open_voice_settings();
|
||||
void accept_join_request(uint64_t user_id);
|
||||
void send_invite(uint64_t user_id, bool is_spectate, String message_content);
|
||||
void accept_invite(uint64_t user_id);
|
||||
void accept_join_request(int64_t user_id);
|
||||
void send_invite(int64_t user_id, bool is_spectate, String message_content);
|
||||
void accept_invite(int64_t user_id);
|
||||
void register_command(String value);
|
||||
void register_steam(int32_t value);
|
||||
Dictionary get_current_user();
|
||||
Dictionary get_relationship(uint64_t user_id);
|
||||
Dictionary get_relationship(int64_t user_id);
|
||||
Array get_all_relationships();
|
||||
bool get_is_discord_working();
|
||||
};
|
||||
|
Reference in New Issue
Block a user