Network.gd — drain packets before handling close (main bug fix):
When the server rejects auth.hello it sends an error frame then closes
the connection. Godot's WebSocketPeer.poll() can transition directly to
STATE_CLOSED while the error packet sits unread in the buffer. The old
code returned early on STATE_CLOSED without calling _poll_packets(), so
_on_ws_closed() fired DISCONNECTED for the pending auth.hello instead of
the real AUTH_FAILED. Auth kept the session token and retried forever.
Fix: drain any buffered packets before _on_ws_closed().
Network.gd — fail request() immediately when not connected:
Previously request() silently dropped the send but left a dangling
pending entry that was never resolved until the next disconnect. Now
on_error("DISCONNECTED") is called immediately, giving the caller
consistent feedback and keeping _pending clean.
main_screen.gd — stay on screen for DISCONNECTED auth errors:
A transient network drop during auth.hello was sending the user back
to the login screen unnecessarily. Only navigate to login when the
session is explicitly rejected (AUTH_FAILED, ACCOUNT_LOCKED, etc.).
The "● Reconnecting…" status label already handles the transient case.
login_screen.gd — add missing friendly error translations:
INVALID_PASSWORD / USER_NOT_FOUND → "Wrong email or password."
DISPLAY_NAME_TAKEN, ACCOUNT_LOCKED, AUTH_REQUIRED,
AUTH_SERVICE_UNAVAILABLE all now map to clear human-readable strings
instead of falling through to the raw server message or error code.
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>
62 lines
2.5 KiB
GDScript
62 lines
2.5 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.
|
|
##
|
|
## If auth.hello re-validation fails after a reconnect (expired session),
|
|
## Auth.auth_failed fires and we redirect back to the login screen.
|
|
|
|
@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)
|
|
Auth.auth_failed.connect(_on_auth_failed)
|
|
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)
|
|
if Auth.auth_failed.is_connected(_on_auth_failed):
|
|
Auth.auth_failed.disconnect(_on_auth_failed)
|
|
|
|
# ── 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_auth_failed(error_code: String, _message: String) -> void:
|
|
if error_code == "DISCONNECTED":
|
|
# Transient drop during auth.hello retry — stay on screen.
|
|
# _update_status() already shows "● Reconnecting…" via the disconnected signal.
|
|
return
|
|
# Session explicitly rejected (expired, revoked, locked out) — go to login.
|
|
get_tree().change_scene_to_file("res://scenes/login/LoginScreen.tscn")
|
|
|
|
|
|
func _on_logout_pressed() -> void:
|
|
Auth.logout()
|
|
get_tree().change_scene_to_file("res://scenes/login/LoginScreen.tscn")
|