Skip to content

Commit

Permalink
add missing access token and discord fixes
Browse files Browse the repository at this point in the history
remove godot steam module

update

update

update stuff

Update blazium_sdk

update123

update

update docs

update default stuff
  • Loading branch information
Ughuuu committed Jan 24, 2025
1 parent ed8ee3c commit af4f62c
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 1 deletion.
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)

0 comments on commit af4f62c

Please sign in to comment.