Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add missing access token and discord fixes #261

Merged
merged 1 commit into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
extends DiscordEmbeddedAppClient

func _init() -> void:
log_updated.connect(_log_updated)

# Only run this on discord embedded app environment
if is_discord_environment():
var result:DiscordEmbeddedAppResult = await is_ready().finished
if result.has_error():
push_error(result.error)
return

func do_authorize() -> void:
var result = await authorize("code", "", "none", ["identify"]).finished
if result.data.has("code"):
print(result.data)
else:
push_error("Cannot authorize ", result.data)

func _log_updated(command: String, message: String):
print("DiscordEmbeddedAppClient: ", command, ": ", message)
39 changes: 39 additions & 0 deletions modules/gdscript/editor/script_templates/LobbyClient/default.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
extends LobbyClient

@export var reconnects = 0
var config: ConfigFile

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
config = ConfigFile.new()
config.load("user://blazium.cfg")

reconnection_token = config.get_value("LobbyClient", "reconnection_token", "")

disconnected_from_lobby.connect(_disconnected_from_lobby)
log_updated.connect(_log_updated)
connected_to_lobby.connect(_connected_to_lobby)

connect_to_lobby()

func _log_updated(command: String, message: String):
print("LobbyClient: ", command, ": ", message)

func _connected_to_lobby(_peer: LobbyPeer, new_reconnection_token: String):
reconnects = 0
config.set_value("LobbyClient", "reconnection_token", new_reconnection_token)
var err = config.save("user://blazium.cfg")
if err != OK:
push_error(error_string(err))

func _disconnected_from_lobby(reason: String):
if reason == "Reconnect Close":
reconnection_token = ""
print("Disconnected. ", reason)
if reconnects > 10:
push_error("Cannot connect")
return
reconnects += 1
if is_inside_tree():
await get_tree().create_timer(0.5 * reconnects).timeout
connect_to_lobby()
28 changes: 28 additions & 0 deletions modules/gdscript/editor/script_templates/LoginClient/default.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
extends LoginClient

func _init() -> void:
received_jwt.connect(_received_jwt)
log_updated.connect(_log_updated)

# Connect to the server
var result = await connect_to_server().finished
if result.has_error():
push_error(result.error)

func request_login_and_open() -> void:
# Get Login URL
var login_result :LoginResult = await request_login_info("discord").finished
if login_result.has_error():
push_error(login_result.error)
return

# Open Login URL and wait for received_jwt signal
var error := OS.shell_open(login_result.login_url)
if error != OK:
push_error(error)

func _log_updated(command: String, message: String):
print("LoginClient: ", command, ": ", message)

func _received_jwt(jwt: String, type: String, access_token: String):
print("Got jwt and access_token", jwt, " ", type, " ", access_token)
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
extends LoginClient

func _init() -> void:
received_jwt.connect(_received_jwt)
log_updated.connect(_log_updated)

# Connect to the server
var result = await connect_to_server().finished
if result.has_error():
push_error(result.error)

func request_login_and_open() -> void:
# Get Login URL
var login_result :LoginResult = await request_login_info("discord").finished
if login_result.has_error():
push_error(login_result.error)

# Open Login URL and wait for received_jwt signal
var error := OS.shell_open(login_result.login_url)
if error != OK:
push_error(error)

func _log_updated(command: String, message: String):
print("LoginClient: ", command, ": ", message)

func _received_jwt(jwt: String, type: String, access_token: String):
print("Godt jwt and access_token", jwt, " ", type, " ", access_token)
Loading