When auth.hello is rejected (session expired/revoked), Auth.gd now calls logout() to wipe all auth state (including auth.cfg) and drives the scene change to LoginScreen directly, instead of relying on each scene's own auth_failed handler. This covers all screens (main, collection, etc.) without each needing a handler, and eliminates the race where the auth.hello reply arrived as DISCONNECTED (STATE_CLOSING path, token kept) → reconnect → resend token. main_screen.gd no longer subscribes to auth_failed; session expiry redirect is fully owned by Auth.gd. Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
50 lines
2.0 KiB
GDScript
50 lines
2.0 KiB
GDScript
extends Control
|
|
## Main hub screen — shown after successful authentication.
|
|
##
|
|
## Displays the player's display name and live connection status.
|
|
## Placeholder navigation buttons for future game features.
|
|
##
|
|
## Session expiry is handled centrally by Auth.gd, which calls logout() and
|
|
## navigates to LoginScreen when auth.hello is rejected on reconnect.
|
|
|
|
@onready var welcome_label : Label = %WelcomeLabel
|
|
@onready var status_label : Label = %StatusLabel
|
|
@onready var logout_btn : Button = %LogoutBtn
|
|
@onready var collection_btn : Button = %CollectionBtn
|
|
@onready var bazaar_btn : Button = %BazaarBtn
|
|
|
|
# ── Lifecycle ─────────────────────────────────────────────────────────────────
|
|
|
|
func _ready() -> void:
|
|
welcome_label.text = "Welcome, %s!" % Auth.display_name
|
|
|
|
Network.connected.connect(_update_status)
|
|
Network.disconnected.connect(_update_status)
|
|
logout_btn.pressed.connect(_on_logout_pressed)
|
|
collection_btn.pressed.connect(func():
|
|
get_tree().change_scene_to_file("res://scenes/collection/CollectionScreen.tscn"))
|
|
|
|
_update_status()
|
|
|
|
|
|
func _exit_tree() -> void:
|
|
if Network.connected.is_connected(_update_status):
|
|
Network.connected.disconnect(_update_status)
|
|
if Network.disconnected.is_connected(_update_status):
|
|
Network.disconnected.disconnect(_update_status)
|
|
|
|
# ── Signal handlers ───────────────────────────────────────────────────────────
|
|
|
|
func _update_status() -> void:
|
|
if Network.is_online():
|
|
status_label.text = "● Online"
|
|
status_label.modulate = Color(0.3, 0.9, 0.4)
|
|
else:
|
|
status_label.text = "● Reconnecting…"
|
|
status_label.modulate = Color(1.0, 0.8, 0.2)
|
|
|
|
|
|
func _on_logout_pressed() -> void:
|
|
Auth.logout()
|
|
get_tree().change_scene_to_file("res://scenes/login/LoginScreen.tscn")
|