Godot client networking + auth + login/main screens; fix admin hamburger
Server: - ConnectionLoop: accept auth.login and auth.register as valid first messages (not just auth.hello); all ack payloads now include sessionToken for client persistence - IGatewayAuthValidator: add LoginAsync and RegisterAsync - GatewayAuthValidator: implement both via auth gRPC; fetch displayName from ValidateAsync after login/register succeeds - Admin hamburger: custom .sor-admin-hamburger CSS (hardcoded white, no Bootstrap btn-link theme fighting); topbar z-index 1050 with position:sticky Client (Godot 4.5, GDScript): - autoloads/Network.gd: WebSocketPeer state machine (CONNECTING / CONNECTED / RECONNECTING), exponential backoff (1→30s), app-level keepalive ping every 30s of idle, 30s ping timeout → reconnect, request/reply correlation by sequence number, debug_log_packets export flag for full packet dumps - autoloads/Auth.gd: drives auth.hello / auth.login / auth.register as first WS message; persists sessionToken + userId + displayName to user://auth.cfg; auto-resumes saved session on reconnect; auth_success / auth_failed signals - scenes/login/LoginScreen.tscn + login_screen.gd: Login + Register tabs, touch-friendly inputs (44px height), status label, Enter key submits, handles reconnect/resume states - scenes/main/MainScreen.tscn + main_screen.gd: top bar with live connection dot, welcome label, placeholder nav buttons, sign-out, redirects to login on session expiry - project.godot: Network and Auth autoloads registered; LoginScreen as main scene 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>
This commit is contained in:
@@ -0,0 +1,119 @@
|
||||
extends Control
|
||||
## Login / Register screen.
|
||||
##
|
||||
## Shown as the entry point before authentication. Uses two tabs:
|
||||
## "Login" — email + password → auth.login
|
||||
## "Register" — email + password + display name → auth.register
|
||||
##
|
||||
## Listens to Auth.auth_success and Auth.auth_failed.
|
||||
## On success: transitions to MainScreen.
|
||||
## On failure: shows an error message and re-enables the form.
|
||||
|
||||
# ── Node references (unique names set in the .tscn) ──────────────────────────
|
||||
|
||||
@onready var email_input : LineEdit = %EmailInput
|
||||
@onready var password_input : LineEdit = %PasswordInput
|
||||
@onready var login_btn : Button = %LoginBtn
|
||||
|
||||
@onready var reg_email_input : LineEdit = %RegEmailInput
|
||||
@onready var reg_password_input : LineEdit = %RegPasswordInput
|
||||
@onready var reg_name_input : LineEdit = %RegNameInput
|
||||
@onready var register_btn : Button = %RegisterBtn
|
||||
|
||||
@onready var status_label : Label = %StatusLabel
|
||||
|
||||
# ── Lifecycle ─────────────────────────────────────────────────────────────────
|
||||
|
||||
func _ready() -> void:
|
||||
# If already authenticated (e.g. scene reloaded), skip straight to main.
|
||||
if not Auth.user_id.is_empty():
|
||||
_go_to_main()
|
||||
return
|
||||
|
||||
Auth.auth_success.connect(_on_auth_success)
|
||||
Auth.auth_failed.connect(_on_auth_failed)
|
||||
|
||||
login_btn.pressed.connect(_on_login_pressed)
|
||||
register_btn.pressed.connect(_on_register_pressed)
|
||||
|
||||
# Allow pressing Enter to submit the login form.
|
||||
password_input.text_submitted.connect(func(_t): _on_login_pressed())
|
||||
reg_name_input.text_submitted.connect(func(_t): _on_register_pressed())
|
||||
|
||||
# Show connection / session-resume status on first open.
|
||||
if not Auth.session_token.is_empty():
|
||||
_set_status("Resuming session…", false)
|
||||
_set_enabled(false)
|
||||
elif not Network.is_online():
|
||||
_set_status("Connecting…", false)
|
||||
|
||||
|
||||
func _exit_tree() -> void:
|
||||
if Auth.auth_success.is_connected(_on_auth_success):
|
||||
Auth.auth_success.disconnect(_on_auth_success)
|
||||
if Auth.auth_failed.is_connected(_on_auth_failed):
|
||||
Auth.auth_failed.disconnect(_on_auth_failed)
|
||||
|
||||
# ── Button handlers ───────────────────────────────────────────────────────────
|
||||
|
||||
func _on_login_pressed() -> void:
|
||||
var email := email_input.text.strip_edges()
|
||||
var pass_ := password_input.text
|
||||
if email.is_empty() or pass_.is_empty():
|
||||
_set_status("Please enter your email and password.", true)
|
||||
return
|
||||
_set_status("Signing in…", false)
|
||||
_set_enabled(false)
|
||||
Auth.login(email, pass_)
|
||||
|
||||
|
||||
func _on_register_pressed() -> void:
|
||||
var email := reg_email_input.text.strip_edges()
|
||||
var pass_ := reg_password_input.text
|
||||
var name_ := reg_name_input.text.strip_edges()
|
||||
if email.is_empty() or pass_.is_empty() or name_.is_empty():
|
||||
_set_status("Please fill in all fields.", true)
|
||||
return
|
||||
_set_status("Creating account…", false)
|
||||
_set_enabled(false)
|
||||
Auth.register(email, pass_, name_)
|
||||
|
||||
# ── Auth signal handlers ──────────────────────────────────────────────────────
|
||||
|
||||
func _on_auth_success(_user_id: String, _display_name: String) -> void:
|
||||
_go_to_main()
|
||||
|
||||
|
||||
func _on_auth_failed(error_code: String, message: String) -> void:
|
||||
if error_code == "DISCONNECTED":
|
||||
_set_status("Connection lost. Retrying…", false)
|
||||
else:
|
||||
_set_status(_friendly_error(error_code, message), true)
|
||||
_set_enabled(true)
|
||||
|
||||
# ── Helpers ───────────────────────────────────────────────────────────────────
|
||||
|
||||
func _go_to_main() -> void:
|
||||
get_tree().change_scene_to_file("res://scenes/main/MainScreen.tscn")
|
||||
|
||||
|
||||
func _set_status(text: String, is_error: bool) -> void:
|
||||
status_label.text = text
|
||||
status_label.modulate = Color(1.0, 0.4, 0.4) if is_error else Color(0.8, 0.8, 0.8)
|
||||
|
||||
|
||||
func _set_enabled(enabled: bool) -> void:
|
||||
login_btn.disabled = not enabled
|
||||
register_btn.disabled = not enabled
|
||||
|
||||
|
||||
func _friendly_error(code: String, message: String) -> String:
|
||||
match code:
|
||||
"INVALID_CREDENTIALS": return "Wrong email or password."
|
||||
"EMAIL_TAKEN": return "That email is already in use."
|
||||
"WEAK_PASSWORD": return "Password must be at least 8 characters."
|
||||
"INVALID_EMAIL": return "Please enter a valid email address."
|
||||
"AUTH_FAILED": return "Authentication failed. Please try again."
|
||||
_:
|
||||
return message if not message.is_empty() \
|
||||
else "Something went wrong (%s)." % code
|
||||
Reference in New Issue
Block a user