73 lines
2.5 KiB
GDScript
73 lines
2.5 KiB
GDScript
class_name SteamworksManager
|
|
extends Node
|
|
|
|
## Steamworks integration for Nakama authentication only
|
|
## Used to get Steam auth session tickets for Nakama login/registration
|
|
## Steam singleton is provided by GodotSteam GDExtension
|
|
|
|
var is_steam_initialized: bool = false
|
|
var steam_app_id: int = ProjectSettings.get_setting("steam/initialization/app_id", 480)
|
|
|
|
func _ready() -> void:
|
|
_initialize_steam()
|
|
|
|
func _initialize_steam() -> void:
|
|
# Check if GodotSteam GDExtension is loaded
|
|
if not ClassDB.class_exists("Steam"):
|
|
push_error("SteamworksManager: GodotSteam GDExtension not found. Enable it in Project Settings > Plugins.")
|
|
return
|
|
|
|
# Use steamInitEx for proper initialization with status reporting
|
|
var init_result: Dictionary = Steam.steamInitEx()
|
|
var status: int = init_result.get("status", -1)
|
|
var verbal: String = init_result.get("verbal", "Unknown error")
|
|
|
|
if status == 0:
|
|
is_steam_initialized = true
|
|
print("SteamworksManager: Steam initialized (App ID: %s)" % steam_app_id)
|
|
else:
|
|
push_warning("SteamworksManager: Steam init failed [%d] - %s" % [status, verbal])
|
|
print("SteamworksManager: Make sure Steam is running and App ID %s is valid" % steam_app_id)
|
|
|
|
func is_initialized() -> bool:
|
|
return is_steam_initialized
|
|
|
|
## Auth Methods
|
|
|
|
func get_auth_session_ticket() -> String:
|
|
if not is_steam_initialized:
|
|
push_warning("SteamworksManager: Steam not initialized, cannot get auth ticket")
|
|
return ""
|
|
|
|
# getAuthSessionTicket returns a Dictionary in GodotSteam {"id": int, "buffer": PackedByteArray}
|
|
var ticket_data = Steam.getAuthSessionTicket()
|
|
if typeof(ticket_data) == TYPE_DICTIONARY:
|
|
var buffer: PackedByteArray = ticket_data.get("buffer", PackedByteArray())
|
|
if buffer.size() > 0:
|
|
var ticket_hex = buffer.hex_encode()
|
|
print("SteamworksManager: Got Steam auth session ticket")
|
|
return ticket_hex
|
|
push_error("SteamworksManager: Auth ticket buffer is empty")
|
|
return ""
|
|
elif typeof(ticket_data) == TYPE_STRING and not ticket_data.is_empty():
|
|
print("SteamworksManager: Got Steam auth session ticket")
|
|
return ticket_data
|
|
else:
|
|
push_error("SteamworksManager: Failed to get auth session ticket")
|
|
return ""
|
|
|
|
func get_steam_user_name() -> String:
|
|
if not is_steam_initialized:
|
|
return ""
|
|
return Steam.getPersonaName()
|
|
|
|
func get_steam_user_id() -> int:
|
|
if not is_steam_initialized:
|
|
return 0
|
|
return Steam.getSteamID()
|
|
|
|
func _notification(what: int) -> void:
|
|
if what == NOTIFICATION_WM_CLOSE_REQUEST:
|
|
if is_steam_initialized:
|
|
Steam.steamShutdown()
|