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,160 @@
|
||||
[gd_scene load_steps=2 format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://scenes/login/login_screen.gd" id="1_login"]
|
||||
|
||||
[node name="LoginScreen" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1_login")
|
||||
|
||||
[node name="Background" type="ColorRect" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
color = Color(0.094, 0.094, 0.137, 1.0)
|
||||
|
||||
[node name="Center" type="CenterContainer" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="Panel" type="PanelContainer" parent="Center"]
|
||||
layout_mode = 2
|
||||
custom_minimum_size = Vector2(360, 0)
|
||||
|
||||
[node name="Margin" type="MarginContainer" parent="Center/Panel"]
|
||||
layout_mode = 2
|
||||
theme_override_constants/margin_left = 28
|
||||
theme_override_constants/margin_top = 28
|
||||
theme_override_constants/margin_right = 28
|
||||
theme_override_constants/margin_bottom = 28
|
||||
|
||||
[node name="VBox" type="VBoxContainer" parent="Center/Panel/Margin"]
|
||||
layout_mode = 2
|
||||
theme_override_constants/separation = 14
|
||||
|
||||
[node name="Title" type="Label" parent="Center/Panel/Margin/VBox"]
|
||||
layout_mode = 2
|
||||
text = "ORIGIN"
|
||||
horizontal_alignment = 1
|
||||
theme_override_font_sizes/font_size = 30
|
||||
|
||||
[node name="Subtitle" type="Label" parent="Center/Panel/Margin/VBox"]
|
||||
layout_mode = 2
|
||||
text = "Stone of Ruin"
|
||||
horizontal_alignment = 1
|
||||
modulate = Color(0.6, 0.6, 0.65, 1.0)
|
||||
theme_override_font_sizes/font_size = 13
|
||||
|
||||
[node name="Spacer" type="Control" parent="Center/Panel/Margin/VBox"]
|
||||
layout_mode = 2
|
||||
custom_minimum_size = Vector2(0, 6)
|
||||
|
||||
[node name="Tabs" type="TabContainer" parent="Center/Panel/Margin/VBox"]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="Login" type="VBoxContainer" parent="Center/Panel/Margin/VBox/Tabs"]
|
||||
layout_mode = 2
|
||||
theme_override_constants/separation = 8
|
||||
|
||||
[node name="EmailLabel" type="Label" parent="Center/Panel/Margin/VBox/Tabs/Login"]
|
||||
layout_mode = 2
|
||||
text = "Email"
|
||||
|
||||
[node name="EmailInput" type="LineEdit" parent="Center/Panel/Margin/VBox/Tabs/Login"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
custom_minimum_size = Vector2(0, 44)
|
||||
placeholder_text = "your@email.com"
|
||||
theme_override_font_sizes/font_size = 15
|
||||
|
||||
[node name="PasswordLabel" type="Label" parent="Center/Panel/Margin/VBox/Tabs/Login"]
|
||||
layout_mode = 2
|
||||
text = "Password"
|
||||
|
||||
[node name="PasswordInput" type="LineEdit" parent="Center/Panel/Margin/VBox/Tabs/Login"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
custom_minimum_size = Vector2(0, 44)
|
||||
placeholder_text = "••••••••"
|
||||
secret = true
|
||||
theme_override_font_sizes/font_size = 15
|
||||
|
||||
[node name="LoginSpacer" type="Control" parent="Center/Panel/Margin/VBox/Tabs/Login"]
|
||||
layout_mode = 2
|
||||
custom_minimum_size = Vector2(0, 4)
|
||||
|
||||
[node name="LoginBtn" type="Button" parent="Center/Panel/Margin/VBox/Tabs/Login"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
custom_minimum_size = Vector2(0, 48)
|
||||
text = "Sign In"
|
||||
theme_override_font_sizes/font_size = 15
|
||||
|
||||
[node name="Register" type="VBoxContainer" parent="Center/Panel/Margin/VBox/Tabs"]
|
||||
layout_mode = 2
|
||||
theme_override_constants/separation = 8
|
||||
|
||||
[node name="RegEmailLabel" type="Label" parent="Center/Panel/Margin/VBox/Tabs/Register"]
|
||||
layout_mode = 2
|
||||
text = "Email"
|
||||
|
||||
[node name="RegEmailInput" type="LineEdit" parent="Center/Panel/Margin/VBox/Tabs/Register"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
custom_minimum_size = Vector2(0, 44)
|
||||
placeholder_text = "your@email.com"
|
||||
theme_override_font_sizes/font_size = 15
|
||||
|
||||
[node name="RegPasswordLabel" type="Label" parent="Center/Panel/Margin/VBox/Tabs/Register"]
|
||||
layout_mode = 2
|
||||
text = "Password"
|
||||
|
||||
[node name="RegPasswordInput" type="LineEdit" parent="Center/Panel/Margin/VBox/Tabs/Register"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
custom_minimum_size = Vector2(0, 44)
|
||||
placeholder_text = "••••••••"
|
||||
secret = true
|
||||
theme_override_font_sizes/font_size = 15
|
||||
|
||||
[node name="RegNameLabel" type="Label" parent="Center/Panel/Margin/VBox/Tabs/Register"]
|
||||
layout_mode = 2
|
||||
text = "Display Name"
|
||||
|
||||
[node name="RegNameInput" type="LineEdit" parent="Center/Panel/Margin/VBox/Tabs/Register"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
custom_minimum_size = Vector2(0, 44)
|
||||
placeholder_text = "YourName"
|
||||
theme_override_font_sizes/font_size = 15
|
||||
|
||||
[node name="RegSpacer" type="Control" parent="Center/Panel/Margin/VBox/Tabs/Register"]
|
||||
layout_mode = 2
|
||||
custom_minimum_size = Vector2(0, 4)
|
||||
|
||||
[node name="RegisterBtn" type="Button" parent="Center/Panel/Margin/VBox/Tabs/Register"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
custom_minimum_size = Vector2(0, 48)
|
||||
text = "Create Account"
|
||||
theme_override_font_sizes/font_size = 15
|
||||
|
||||
[node name="StatusLabel" type="Label" parent="Center/Panel/Margin/VBox"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
horizontal_alignment = 1
|
||||
autowrap_mode = 3
|
||||
modulate = Color(0.8, 0.8, 0.8, 1.0)
|
||||
theme_override_font_sizes/font_size = 13
|
||||
@@ -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
|
||||
@@ -0,0 +1,137 @@
|
||||
[gd_scene load_steps=2 format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://scenes/main/main_screen.gd" id="1_main"]
|
||||
|
||||
[node name="MainScreen" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1_main")
|
||||
|
||||
[node name="Background" type="ColorRect" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
color = Color(0.094, 0.094, 0.137, 1.0)
|
||||
|
||||
[node name="Layout" type="VBoxContainer" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
theme_override_constants/separation = 0
|
||||
|
||||
[node name="TopBar" type="HBoxContainer" parent="Layout"]
|
||||
layout_mode = 2
|
||||
custom_minimum_size = Vector2(0, 56)
|
||||
theme_override_constants/separation = 12
|
||||
|
||||
[node name="TopBarMargin" type="MarginContainer" parent="Layout/TopBar"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
theme_override_constants/margin_left = 16
|
||||
theme_override_constants/margin_right = 16
|
||||
|
||||
[node name="TopBarInner" type="HBoxContainer" parent="Layout/TopBar/TopBarMargin"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
theme_override_constants/separation = 0
|
||||
|
||||
[node name="BrandLabel" type="Label" parent="Layout/TopBar/TopBarMargin/TopBarInner"]
|
||||
layout_mode = 2
|
||||
text = "ORIGIN"
|
||||
theme_override_font_sizes/font_size = 18
|
||||
size_flags_vertical = 4
|
||||
|
||||
[node name="TopSpacer" type="Control" parent="Layout/TopBar/TopBarMargin/TopBarInner"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="StatusLabel" type="Label" parent="Layout/TopBar/TopBarMargin/TopBarInner"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
text = "● Online"
|
||||
modulate = Color(0.3, 0.9, 0.4, 1.0)
|
||||
size_flags_vertical = 4
|
||||
theme_override_font_sizes/font_size = 13
|
||||
|
||||
[node name="Separator" type="HSeparator" parent="Layout"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Scroll" type="ScrollContainer" parent="Layout"]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="Content" type="VBoxContainer" parent="Layout/Scroll"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
theme_override_constants/separation = 16
|
||||
|
||||
[node name="ContentMargin" type="MarginContainer" parent="Layout/Scroll/Content"]
|
||||
layout_mode = 2
|
||||
theme_override_constants/margin_left = 20
|
||||
theme_override_constants/margin_top = 20
|
||||
theme_override_constants/margin_right = 20
|
||||
theme_override_constants/margin_bottom = 20
|
||||
|
||||
[node name="ContentInner" type="VBoxContainer" parent="Layout/Scroll/Content/ContentMargin"]
|
||||
layout_mode = 2
|
||||
theme_override_constants/separation = 20
|
||||
|
||||
[node name="WelcomeLabel" type="Label" parent="Layout/Scroll/Content/ContentMargin/ContentInner"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
text = "Welcome!"
|
||||
theme_override_font_sizes/font_size = 24
|
||||
|
||||
[node name="NavSection" type="Label" parent="Layout/Scroll/Content/ContentMargin/ContentInner"]
|
||||
layout_mode = 2
|
||||
text = "PLAY"
|
||||
modulate = Color(0.6, 0.6, 0.65, 1.0)
|
||||
theme_override_font_sizes/font_size = 11
|
||||
|
||||
[node name="NavButtons" type="VBoxContainer" parent="Layout/Scroll/Content/ContentMargin/ContentInner"]
|
||||
layout_mode = 2
|
||||
theme_override_constants/separation = 10
|
||||
|
||||
[node name="CollectionBtn" type="Button" parent="Layout/Scroll/Content/ContentMargin/ContentInner/NavButtons"]
|
||||
layout_mode = 2
|
||||
custom_minimum_size = Vector2(0, 52)
|
||||
text = "My Collection"
|
||||
theme_override_font_sizes/font_size = 15
|
||||
|
||||
[node name="BazaarBtn" type="Button" parent="Layout/Scroll/Content/ContentMargin/ContentInner/NavButtons"]
|
||||
layout_mode = 2
|
||||
custom_minimum_size = Vector2(0, 52)
|
||||
text = "Bazaar"
|
||||
theme_override_font_sizes/font_size = 15
|
||||
|
||||
[node name="MatchBtn" type="Button" parent="Layout/Scroll/Content/ContentMargin/ContentInner/NavButtons"]
|
||||
layout_mode = 2
|
||||
custom_minimum_size = Vector2(0, 52)
|
||||
text = "Find Match"
|
||||
theme_override_font_sizes/font_size = 15
|
||||
|
||||
[node name="BottomBar" type="HBoxContainer" parent="Layout"]
|
||||
layout_mode = 2
|
||||
custom_minimum_size = Vector2(0, 56)
|
||||
|
||||
[node name="BottomMargin" type="MarginContainer" parent="Layout/BottomBar"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
theme_override_constants/margin_left = 16
|
||||
theme_override_constants/margin_right = 16
|
||||
|
||||
[node name="LogoutBtn" type="Button" parent="Layout/BottomBar/BottomMargin"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
text = "Sign Out"
|
||||
theme_override_font_sizes/font_size = 14
|
||||
@@ -0,0 +1,53 @@
|
||||
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
|
||||
|
||||
# ── 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)
|
||||
|
||||
_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:
|
||||
# Session expired or invalidated — return 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")
|
||||
Reference in New Issue
Block a user