diff --git a/discord_addon_export_beta.zip b/discord_addon_export_beta.zip index 7eeb0c9..4c173ee 100644 Binary files a/discord_addon_export_beta.zip and b/discord_addon_export_beta.zip differ diff --git a/project/Node b/project/Node new file mode 100644 index 0000000..7e644f0 Binary files /dev/null and b/project/Node differ diff --git a/project/addons/discord-sdk-gd/bin/windows/discord_game_sdk_binding.dll b/project/addons/discord-sdk-gd/bin/windows/discord_game_sdk_binding.dll index c9c3126..d0e7ec9 100644 Binary files a/project/addons/discord-sdk-gd/bin/windows/discord_game_sdk_binding.dll and b/project/addons/discord-sdk-gd/bin/windows/discord_game_sdk_binding.dll differ diff --git a/project/addons/discord-sdk-gd/bin/windows/discord_game_sdk_binding_debug.dll b/project/addons/discord-sdk-gd/bin/windows/discord_game_sdk_binding_debug.dll index 64de40d..56cbe35 100644 Binary files a/project/addons/discord-sdk-gd/bin/windows/discord_game_sdk_binding_debug.dll and b/project/addons/discord-sdk-gd/bin/windows/discord_game_sdk_binding_debug.dll differ diff --git a/project/assets/1.png b/project/assets/1.png new file mode 100644 index 0000000..7e644f0 Binary files /dev/null and b/project/assets/1.png differ diff --git a/project/assets/1.png.import b/project/assets/1.png.import new file mode 100644 index 0000000..c3a8114 --- /dev/null +++ b/project/assets/1.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://ht210p8vs8s7" +path="res://.godot/imported/1.png-c9a8e694d0d275633d567702fb508122.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/1.png" +dest_files=["res://.godot/imported/1.png-c9a8e694d0d275633d567702fb508122.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/project/discord_pfp_cache/invitepfp.png b/project/discord_pfp_cache/invitepfp.png new file mode 100644 index 0000000..7e644f0 Binary files /dev/null and b/project/discord_pfp_cache/invitepfp.png differ diff --git a/project/discord_pfp_cache/invitepfp.png.import b/project/discord_pfp_cache/invitepfp.png.import new file mode 100644 index 0000000..ca4cc65 --- /dev/null +++ b/project/discord_pfp_cache/invitepfp.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://lct8hsyc4bx6" +path="res://.godot/imported/invitepfp.png-a7b335dc42426751624b97336b7117a8.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://discord_pfp_cache/invitepfp.png" +dest_files=["res://.godot/imported/invitepfp.png-a7b335dc42426751624b97336b7117a8.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/project/main.gd b/project/main.gd index ad3cf15..35c1704 100644 --- a/project/main.gd +++ b/project/main.gd @@ -1,30 +1,47 @@ extends Node +var invite_pfp + func _ready(): set_activity() discord_sdk.connect("activity_join_request",_on_activity_join_request) discord_sdk.connect("activity_join",_on_activity_join) discord_sdk.connect("activity_spectate",_on_activity_spectate) + download_texture("https://cdn.discordapp.com/embed/avatars/1.png", "res://discord_pfp_cache/invitepfp.png") + debug_text_update() +func download_texture(url, file_name): + $user_request_avatar/HTTPRequest.download_file = file_name + invite_pfp = file_name + $user_request_avatar/HTTPRequest.request(url) + +func _on_http_request_request_completed(_result, _response_code, _headers, _body): + var image = Image.new() + image.load(str(invite_pfp)) + var texture = ImageTexture.create_from_image(image) + $user_request_avatar.texture = texture func set_activity(): discord_sdk.app_id = 1099618430065324082 discord_sdk.details = "A demo activity by vaporvee#1231" discord_sdk.state = "Checkpoint 23/23" - - discord_sdk.large_image = "game" + + discord_sdk.large_image = "example_game" discord_sdk.large_image_text = "Try it now!" discord_sdk.small_image = "boss" discord_sdk.small_image_text = "Fighting the end boss! D:" discord_sdk.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 = str(randi_range(0,999999)) - + discord_sdk.party_id = "mylobbycanbeeverything_" + my_secret - discord_sdk.current_party_size = 1 + discord_sdk.current_party_size = 4 discord_sdk.max_party_size = 4 discord_sdk.match_secret = "m_" + my_secret #better use seeds with 1 to 1 range instead of just chars discord_sdk.join_secret = "j_" + my_secret discord_sdk.spectate_secret = "s_" + my_secret + discord_sdk.instanced = true #required for spectate #discord_sdk.start_timestamp = int(Time.get_unix_time_from_system()) #discord_sdk.register_command("steam://rungameid/1389990") #discord_sdk.register_steam(1389990) @@ -33,8 +50,13 @@ func set_activity(): func debug_text_update(): $Info.text = $Info.text.replace("{ssecret}",discord_sdk.spectate_secret).replace("{jsecret}",discord_sdk.join_secret).replace("{msecret}",discord_sdk.match_secret).replace("{mpartysize}",str(discord_sdk.max_party_size)).replace("{cpartysize}",str(discord_sdk.current_party_size)).replace("{partyid}",discord_sdk.party_id).replace("{discordinfo}",str(discord_sdk.get_is_discord_working())).replace("{id}",str(discord_sdk.app_id)).replace("{details}",discord_sdk.details).replace("{state}",discord_sdk.state).replace("{lkey}",discord_sdk.large_image).replace("{ltext}",discord_sdk.large_image_text).replace("{skey}",discord_sdk.small_image).replace("{stext}",discord_sdk.small_image_text).replace("{stimestamp}",str(discord_sdk.start_timestamp)).replace("{etimestamp}",str(discord_sdk.end_timestamp)) +var user_request = {}; + func _on_activity_join_request(user_requesting): print(user_requesting) + user_request = user_requesting + print(user_requesting.avatar_url) + download_texture(user_requesting.avatar_url, "res://discord_pfp_cache/invitepfp.png") func _on_activity_join(secret): if(discord_sdk.join_secret != secret): @@ -45,16 +67,26 @@ func _on_activity_join(secret): discord_sdk.spectate_secret = secret.replace("j_","s_") discord_sdk.refresh() $Info.text = $Info.text.replace("{ssecret}",discord_sdk.spectate_secret).replace("{jsecret}",discord_sdk.join_secret).replace("{msecret}",discord_sdk.match_secret).replace("{mpartysize}",str(discord_sdk.max_party_size)).replace("{cpartysize}",str(discord_sdk.current_party_size)).replace("{partyid}",discord_sdk.party_id).replace("{discordinfo}",str(discord_sdk.get_is_discord_working())).replace("{id}",str(discord_sdk.app_id)).replace("{details}",discord_sdk.details).replace("{state}",discord_sdk.state).replace("{lkey}",discord_sdk.large_image).replace("{ltext}",discord_sdk.large_image_text).replace("{skey}",discord_sdk.small_image).replace("{stext}",discord_sdk.small_image_text).replace("{stimestamp}",str(discord_sdk.start_timestamp)).replace("{etimestamp}",str(discord_sdk.end_timestamp)) - print(secret) - print(discord_sdk.get_current_party_size()) - print(discord_sdk.get_join_secret()) + debug_text_update() func _on_activity_spectate(secret): print(secret) - func _on_check_button_toggled(button_pressed): if(button_pressed): set_activity() else: discord_sdk.clear() + +func _on_button_pressed(): + if(!user_request.is_empty()): + discord_sdk.accept_join_request(user_request.id) + +func _on_line_edit_text_submitted(new_text): + discord_sdk.send_invite(int(new_text),true,"this is a test invite sent from godot") + print(int(new_text)) + + +func _on_line_edit_2_text_submitted(new_text): + discord_sdk.accept_invite(int(new_text)) + print(int(new_text)) diff --git a/project/main.tscn b/project/main.tscn index 493da55..e9efa2f 100644 --- a/project/main.tscn +++ b/project/main.tscn @@ -1,9 +1,10 @@ -[gd_scene load_steps=6 format=3 uid="uid://dmx2xuigcpvt4"] +[gd_scene load_steps=7 format=3 uid="uid://dmx2xuigcpvt4"] [ext_resource type="Script" path="res://main.gd" id="1_kl8ri"] [ext_resource type="Texture2D" uid="uid://dhuttdaet6q1u" path="res://assets/Logo_V2_Clyde.png" id="2_1hv5q"] [ext_resource type="Texture2D" uid="uid://dnfq6kug4x6o2" path="res://assets/Checked.svg" id="3_ny5eu"] [ext_resource type="Texture2D" uid="uid://compmm3kviqqe" path="res://assets/Unchecked.svg" id="4_xydmq"] +[ext_resource type="Texture2D" uid="uid://ht210p8vs8s7" path="res://assets/1.png" id="5_06yyg"] [sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_1w3f4"] @@ -22,19 +23,19 @@ color = Color(0.345098, 0.396078, 0.94902, 1) [node name="Sprite2D" type="Sprite2D" parent="."] texture_filter = 4 -position = Vector2(591, 308) +position = Vector2(580, 308) scale = Vector2(0.408203, 0.408203) texture = ExtResource("2_1hv5q") [node name="DiscordSDK Test" type="RichTextLabel" parent="."] anchors_preset = -1 -anchor_left = 0.296 +anchor_left = 0.293 anchor_top = 0.59 -anchor_right = 0.742 +anchor_right = 0.736 anchor_bottom = 0.727 -offset_left = 0.00799561 -offset_top = -0.320007 -offset_right = 0.215942 +offset_left = -0.536011 +offset_top = -0.319977 +offset_right = 0.12793 offset_bottom = -0.0960388 grow_horizontal = 2 grow_vertical = 2 @@ -48,8 +49,8 @@ text = "[center][font s=60][rainbow]DiscordSDK Test[/rainbow][/font]" [node name="Info" type="RichTextLabel" parent="."] offset_left = 7.0 offset_top = 6.0 -offset_right = 514.0 -offset_bottom = 722.0 +offset_right = 424.0 +offset_bottom = 312.0 text = "Discord working: {discordinfo} Application ID : {id} @@ -70,17 +71,16 @@ Max party size: {mpartysize} Match secret: {msecret} Join secret: {jsecret} Spectate secret: {ssecret}" -scroll_active = false [node name="CheckButton" type="CheckButton" parent="."] anchors_preset = -1 -anchor_left = 0.494 +anchor_left = 0.484 anchor_top = 0.781 -anchor_right = 0.531 +anchor_right = 0.521 anchor_bottom = 0.82 -offset_left = -0.0879517 -offset_top = -0.0879822 -offset_right = 803.288 +offset_left = 0.431946 +offset_top = -0.0880127 +offset_right = 803.808 offset_bottom = 482.64 grow_horizontal = 2 grow_vertical = 0 @@ -90,4 +90,56 @@ theme_override_icons/unchecked = ExtResource("4_xydmq") theme_override_styles/focus = SubResource("StyleBoxEmpty_1w3f4") button_pressed = true +[node name="user_request_avatar" type="Sprite2D" parent="."] +position = Vector2(662, 559) +scale = Vector2(0.152344, 0.152344) +texture = ExtResource("5_06yyg") + +[node name="HTTPRequest" type="HTTPRequest" parent="user_request_avatar"] + +[node name="Button" type="Button" parent="."] +anchors_preset = -1 +anchor_left = 0.437 +anchor_top = 0.844 +anchor_right = 0.562 +anchor_bottom = 0.892 +offset_left = 0.575989 +offset_top = 0.0879517 +offset_right = -1.42395 +offset_bottom = -0.0159912 +grow_horizontal = 2 +grow_vertical = 0 +text = "ACCEPT REQUEST" + +[node name="LineEdit" type="LineEdit" parent="."] +anchors_preset = -1 +anchor_left = 0.416 +anchor_top = 0.904 +anchor_right = 0.584 +anchor_bottom = 0.952 +offset_left = 0.268005 +offset_top = 0.207947 +offset_right = -0.268066 +offset_bottom = 0.104004 +grow_horizontal = 2 +grow_vertical = 0 +placeholder_text = "Invite with user_id here" + +[node name="LineEdit2" type="LineEdit" parent="."] +anchors_preset = 7 +anchor_left = 0.5 +anchor_top = 1.0 +anchor_right = 0.5 +anchor_bottom = 1.0 +offset_left = -124.0 +offset_top = -31.0 +offset_right = 125.0 +grow_horizontal = 2 +grow_vertical = 0 +placeholder_text = "Accept Invite with user_id here" + [connection signal="toggled" from="CheckButton" to="." method="_on_check_button_toggled"] +[connection signal="request_completed" from="user_request_avatar/HTTPRequest" to="." method="_on_http_request_request_completed"] +[connection signal="pressed" from="Button" to="." method="_on_button_pressed"] +[connection signal="text_submitted" from="LineEdit" to="." method="_on_line_edit_text_submitted"] +[connection signal="text_submitted" from="LineEdit2" to="." method="_on_line_edit_2_text_submitted"] diff --git a/project/project.godot b/project/project.godot index 87150e8..94f223d 100644 --- a/project/project.godot +++ b/project/project.godot @@ -22,6 +22,10 @@ config/icon="res://assets/Logo_V2.png" updater_discordsdk="*res://addons/discord-sdk-gd/sdk_utility.gd" +[display] + +window/size/resizable=false + [dotnet] project/assembly_name="GDExtension Test Project" diff --git a/src/discordgodot.cpp b/src/discordgodot.cpp index 45d45fa..bacec0c 100644 --- a/src/discordgodot.cpp +++ b/src/discordgodot.cpp @@ -82,8 +82,12 @@ void discord_sdk::_bind_methods() ClassDB::bind_method(D_METHOD("refresh"), &discord_sdk::refresh); ClassDB::bind_method(D_METHOD("clear"), &discord_sdk::clear); - ClassDB::bind_method(D_METHOD("register_command"), &discord_sdk::register_command); - ClassDB::bind_method(D_METHOD("register_steam"), &discord_sdk::register_steam); + ClassDB::bind_method(D_METHOD("register_command", "command"), &discord_sdk::register_command); + ClassDB::bind_method(D_METHOD("register_steam", "steam_id"), &discord_sdk::register_steam); + + ClassDB::bind_method(D_METHOD("accept_join_request", "user_id"), &discord_sdk::accept_join_request); + ClassDB::bind_method(D_METHOD("send_invite", "user_id", "is_spectate", "message_content"), &discord_sdk::send_invite); + ClassDB::bind_method(D_METHOD("accept_invite", "user_id"), &discord_sdk::accept_invite); ClassDB::bind_method(D_METHOD("get_is_discord_working"), &discord_sdk::get_is_discord_working); @@ -105,6 +109,8 @@ discord_sdk::~discord_sdk() { ERR_FAIL_COND(singleton != this); singleton = nullptr; + delete core; + core = nullptr; } void discord_sdk::coreupdate() @@ -136,24 +142,31 @@ void discord_sdk::set_app_id(int64_t value) { app_id = value; result = discord::Core::Create(value, DiscordCreateFlags_NoRequireDiscord, &core); // after setting app_ID it initializes everything - // signals - core->ActivityManager().OnActivityJoin.Connect([](const char *secret) - { discord_sdk::get_singleton() - ->emit_signal("activity_join", secret); }); - core->ActivityManager().OnActivitySpectate.Connect([](const char *secret) + + if (result == discord::Result::Ok && app_id > 0) + { + // signals + core->ActivityManager().OnActivityJoin.Connect([](const char *secret) { discord_sdk::get_singleton() - ->emit_signal("activity_spectate", secret); }); - core->ActivityManager().OnActivityJoinRequest.Connect([this](discord::User const &user) - { Dictionary user_requesting; + ->emit_signal("activity_join", secret); }); + core->ActivityManager().OnActivitySpectate.Connect([](const char *secret) + { discord_sdk::get_singleton() + ->emit_signal("activity_spectate", secret); }); + core->ActivityManager().OnActivityJoinRequest.Connect([this](discord::User const &user) + { Dictionary user_requesting; user_requesting["avatar"] = user.GetAvatar(); //can be empty when user has no avatar user_requesting["is_bot"] = user.GetBot(); user_requesting["discriminator"] = user.GetDiscriminator(); user_requesting["id"] = user.GetId(); user_requesting["username"] = user.GetUsername(); + if(String(user_requesting["avatar"]).is_empty()) + user_requesting["avatar_url"] = String(std::string("https://cdn.discordapp.com/embed/avatars/" + std::to_string((user_requesting["discriminator"].INT % 5) - 1)+ ".png").c_str()); + else + user_requesting["avatar_url"] = String(std::string("https://cdn.discordapp.com/avatars/" + std::to_string(user.GetId()) + "/" + user.GetAvatar() + ".png?size=512").c_str()); user_requesting.make_read_only(); discord_sdk::get_singleton() ->emit_signal("activity_join_request",user_requesting); }); - activity.GetParty().SetPrivacy(discord::ActivityPartyPrivacy(DiscordActivityPartyPrivacy_Public)); + } } int64_t discord_sdk::get_app_id() { @@ -340,6 +353,22 @@ bool discord_sdk::get_instanced() return instanced; } +void discord_sdk::accept_join_request(int64_t user_id) +{ + if (result == discord::Result::Ok && app_id > 0) + core->ActivityManager().SendRequestReply(user_id, static_cast(1), {}); +} +void discord_sdk::send_invite(int64_t user_id, bool is_spectate = false, String message_content = "") +{ + if (result == discord::Result::Ok && app_id > 0) + core->ActivityManager().SendInvite(user_id, static_cast(is_spectate + 1), message_content.utf8().get_data(), {}); +} +void discord_sdk::accept_invite(int64_t user_id) +{ + if (result == discord::Result::Ok && app_id > 0) + core->ActivityManager().AcceptInvite(user_id, {}); +} + void discord_sdk::register_command(String value) { if (result == discord::Result::Ok && app_id > 0) diff --git a/src/discordgodot.h b/src/discordgodot.h index 3e4e471..869ab73 100644 --- a/src/discordgodot.h +++ b/src/discordgodot.h @@ -90,6 +90,10 @@ public: bool get_instanced(); void set_instanced(bool value); + 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);