diff --git a/Client/origin-client/autoloads/Auth.gd b/Client/origin-client/autoloads/Auth.gd new file mode 100644 index 0000000..3d3908a --- /dev/null +++ b/Client/origin-client/autoloads/Auth.gd @@ -0,0 +1,107 @@ +extends Node +## Authentication autoload. +## +## Drives the auth handshake (auth.hello / auth.login / auth.register) as the +## first WebSocket message on every connection. Persists the session token to +## disk so the next session can reconnect silently. +## +## Scenes interact with this node via signals and the three public methods. +## +## Signals: +## auth_success(user_id, display_name) — auth succeeded; switch to main screen +## auth_failed(error_code, message) — auth rejected; show error to user + +const SAVE_PATH := "user://auth.cfg" +const SECTION := "auth" + +signal auth_success(user_id: String, display_name: String) +signal auth_failed(error_code: String, message: String) + +## Set after a successful auth. Empty while unauthenticated. +var user_id: String = "" +var display_name: String = "" +var session_token: String = "" + +# ── Lifecycle ───────────────────────────────────────────────────────────────── + +func _ready() -> void: + _load_session() + Network.connected.connect(_on_network_connected) + +# ── Public API ──────────────────────────────────────────────────────────────── + +## Attempt to sign in with email and password. +## Call from the login form. +func login(email: String, password: String) -> void: + Network.request( + "auth.login", + { "email": email, "password": password }, + func(_type: String, p: Variant): _on_auth_ok(p), + func(code: String, msg: String): auth_failed.emit(code, msg) + ) + + +## Attempt to create a new account. +## Call from the register form. +func register(email: String, password: String, disp_name: String) -> void: + Network.request( + "auth.register", + { "email": email, "password": password, "displayName": disp_name }, + func(_type: String, p: Variant): _on_auth_ok(p), + func(code: String, msg: String): auth_failed.emit(code, msg) + ) + + +## Clear the saved session and reset auth state (e.g. logout button). +func logout() -> void: + user_id = "" + display_name = "" + session_token = "" + _save_session() + +# ── Private ─────────────────────────────────────────────────────────────────── + +## Called every time the WebSocket connects (including after reconnects). +## If a session token is saved, send auth.hello to resume silently. +func _on_network_connected() -> void: + if session_token.is_empty(): + return # No token — LoginScreen will drive login/register. + + Network.request( + "auth.hello", + { "sessionToken": session_token }, + func(_type: String, p: Variant): _on_auth_ok(p), + func(code: String, msg: String): + # Keep the token on network errors — we'll retry on the next + # reconnect. Only clear it on explicit auth rejections. + if code != "DISCONNECTED": + session_token = "" + _save_session() + auth_failed.emit(code, msg) + ) + + +func _on_auth_ok(payload: Variant) -> void: + var p := payload as Dictionary + user_id = p.get("userId", "") + display_name = p.get("displayName", "") + session_token = p.get("sessionToken", "") + _save_session() + auth_success.emit(user_id, display_name) + + +func _load_session() -> void: + var cfg := ConfigFile.new() + if cfg.load(SAVE_PATH) != OK: + return + session_token = cfg.get_value(SECTION, "session_token", "") + user_id = cfg.get_value(SECTION, "user_id", "") + display_name = cfg.get_value(SECTION, "display_name", "") + + +func _save_session() -> void: + var cfg := ConfigFile.new() + cfg.set_value(SECTION, "session_token", session_token) + cfg.set_value(SECTION, "user_id", user_id) + cfg.set_value(SECTION, "display_name", display_name) + cfg.save(SAVE_PATH) diff --git a/Client/origin-client/autoloads/Network.gd b/Client/origin-client/autoloads/Network.gd new file mode 100644 index 0000000..932d057 --- /dev/null +++ b/Client/origin-client/autoloads/Network.gd @@ -0,0 +1,260 @@ +extends Node +## Singleton WebSocket connection manager. +## +## Handles connection lifecycle, reconnection with exponential backoff, +## request/reply correlation via sequence numbers, and application-level +## keepalive (sends a network.ping every 30 s of idle; expects any reply +## within 30 s or forces a reconnect). +## +## Usage: +## Network.request("chat.send", payload, on_reply_callable, on_error_callable) +## Network.send("game.move", payload) +## Network.debug_log_packets = true # dump all sent/received JSON + +# ── Configuration ───────────────────────────────────────────────────────────── + +const SERVER_URL := "wss://hub.aeternalisgames.com/ws" + +## Print every sent/received packet as JSON to stdout. +@export var debug_log_packets: bool = false + +const KEEPALIVE_INTERVAL_SEC := 30.0 ## Idle seconds before sending an app-level ping. +const KEEPALIVE_TIMEOUT_SEC := 30.0 ## Seconds with no reply before forcing a reconnect. +const MAX_RECONNECT_DELAY := 30.0 ## Cap on exponential backoff (seconds). + +# ── Signals ─────────────────────────────────────────────────────────────────── + +## Emitted once the WebSocket handshake completes. Auth will send its +## first message (auth.hello / auth.login / auth.register) in response. +signal connected + +## Emitted when the connection is lost. Reconnect loop starts automatically. +signal disconnected + +## Emitted for server-pushed messages that don't match a pending request. +signal message_received(type: String, payload: Variant) + +# ── State machine ───────────────────────────────────────────────────────────── + +enum _State { DISCONNECTED, CONNECTING, CONNECTED, RECONNECTING } + +var _state: _State = _State.DISCONNECTED +var _ws: WebSocketPeer + +var _seq: int = 0 +var _pending: Dictionary = {} ## int(seq) → { on_reply: Callable, on_error: Callable } +var _ping_seq: int = -1 ## seq of the in-flight keepalive ping, or -1 + +var _reconnect_delay: float = 1.0 +var _reconnect_timer: float = 0.0 + +var _last_rx_time: float = 0.0 ## Epoch-seconds of last received packet. +var _ping_sent_at: float = -1.0 ## Epoch-seconds when keepalive ping was sent, or -1. + +# ── Lifecycle ───────────────────────────────────────────────────────────────── + +func _ready() -> void: + _connect_now() + + +func _process(delta: float) -> void: + # ── DISCONNECTED: nothing to do ──────────────────────────────────────────── + if _state == _State.DISCONNECTED: + return + + # ── RECONNECTING: count down and retry ──────────────────────────────────── + if _state == _State.RECONNECTING: + _reconnect_timer -= delta + if _reconnect_timer <= 0.0: + _connect_now() + return + + # ── CONNECTING / CONNECTED: drive the WebSocket ─────────────────────────── + _ws.poll() + var ws_ready := _ws.get_ready_state() + + match ws_ready: + WebSocketPeer.STATE_OPEN: + if _state == _State.CONNECTING: + _on_ws_opened() + # Fall through to packet/keepalive processing below. + + WebSocketPeer.STATE_CLOSED: + if _state == _State.CONNECTED: + _on_ws_closed() + else: # STATE_CONNECTING → connection attempt failed + _schedule_reconnect() + return + + WebSocketPeer.STATE_CLOSING: + return # Wait for STATE_CLOSED on the next poll. + + # Only run packet/keepalive while fully connected. + if _state == _State.CONNECTED: + _poll_packets() + _tick_keepalive() + +# ── Public API ──────────────────────────────────────────────────────────────── + +## Send [param type] with [param payload] and register callbacks. +## [param on_reply] is called as (type: String, payload: Variant). +## [param on_error] is called as (error_code: String, message: String). +## Returns the sequence number used (useful for cancellation). +func request( + type: String, + payload: Variant, + on_reply: Callable, + on_error: Callable = Callable()) -> int: + _seq += 1 + var seq := _seq + _pending[seq] = { &"on_reply": on_reply, &"on_error": on_error } + _send_raw({ "type": type, "seq": seq, "payload": payload }) + return seq + + +## Fire-and-forget send. No reply tracking. +func send(type: String, payload: Variant = {}) -> void: + _seq += 1 + _send_raw({ "type": type, "seq": _seq, "payload": payload }) + + +## True when the WebSocket is fully open. +func is_online() -> bool: + return _state == _State.CONNECTED + +# ── Connection helpers ──────────────────────────────────────────────────────── + +func _connect_now() -> void: + _ws = WebSocketPeer.new() + _state = _State.CONNECTING + var err := _ws.connect_to_url(SERVER_URL) + if err != OK: + push_warning("Network: connect_to_url failed — %s" % error_string(err)) + _schedule_reconnect() + return + if debug_log_packets: + print("[Net] Connecting → %s" % SERVER_URL) + + +func _on_ws_opened() -> void: + _state = _State.CONNECTED + _reconnect_delay = 1.0 + _last_rx_time = _now() + _ping_sent_at = -1.0 + if debug_log_packets: + print("[Net] Connected") + connected.emit() + + +func _on_ws_closed() -> void: + var code := _ws.get_close_code() + var reason := _ws.get_close_reason() + if debug_log_packets: + print("[Net] Closed code=%d reason=%s" % [code, reason]) + + # Fail all pending requests immediately. + for seq in _pending.keys(): + var cb: Dictionary = _pending[seq] + if cb[&"on_error"].is_valid(): + cb[&"on_error"].call("DISCONNECTED", "Connection lost.") + _pending.clear() + _ping_seq = -1 + _ping_sent_at = -1.0 + + _schedule_reconnect() + disconnected.emit() + + +func _schedule_reconnect() -> void: + _state = _State.RECONNECTING + _reconnect_timer = _reconnect_delay + _reconnect_delay = minf(_reconnect_delay * 2.0, MAX_RECONNECT_DELAY) + if debug_log_packets: + print("[Net] Reconnecting in %.1f s (next backoff=%.1f s)" + % [_reconnect_timer, _reconnect_delay]) + +# ── Packet I/O ──────────────────────────────────────────────────────────────── + +func _poll_packets() -> void: + while _ws.get_available_packet_count() > 0: + var raw := _ws.get_packet() + var text := raw.get_string_from_utf8() + + _last_rx_time = _now() + _ping_sent_at = -1.0 # Any received packet resets the ping watchdog. + + if debug_log_packets: + print("[Net] << %s" % text) + + var parsed: Variant = JSON.parse_string(text) + if typeof(parsed) != TYPE_DICTIONARY: + push_warning("Network: non-object packet — %s" % text) + continue + _dispatch(parsed as Dictionary) + + +func _dispatch(packet: Dictionary) -> void: + var ref : int = packet.get("ref", -1) + var type : String = packet.get("type", "") + var payload: Variant = packet.get("payload", {}) + + if ref >= 0 and _pending.has(ref): + var cb: Dictionary = _pending[ref] + _pending.erase(ref) + + if type == "error": + var error_code: String = (payload as Dictionary).get("errorCode", "UNKNOWN") + var message: String = (payload as Dictionary).get("message", "") + # UNKNOWN_TYPE for our own keepalive ping is expected — swallow it. + if ref == _ping_seq and error_code == "UNKNOWN_TYPE": + return + if cb[&"on_error"].is_valid(): + cb[&"on_error"].call(error_code, message) + else: + if cb[&"on_reply"].is_valid(): + cb[&"on_reply"].call(type, payload) + return + + # Not a reply to a known request — broadcast/push to listeners. + message_received.emit(type, payload) + + +func _send_raw(msg: Dictionary) -> void: + if _ws == null or _ws.get_ready_state() != WebSocketPeer.STATE_OPEN: + push_warning("Network: dropped send (not connected) type=%s" + % msg.get("type", "?")) + return + var text := JSON.stringify(msg) + if debug_log_packets: + print("[Net] >> %s" % text) + _ws.send_text(text) + +# ── Keepalive ───────────────────────────────────────────────────────────────── + +func _tick_keepalive() -> void: + var now := _now() + + if _ping_sent_at >= 0.0: + # Ping already in flight — check for timeout. + if now - _ping_sent_at > KEEPALIVE_TIMEOUT_SEC: + push_warning("Network: keepalive timeout — forcing reconnect") + _ws.close(1001, "keepalive_timeout") + _on_ws_closed() + return + + if now - _last_rx_time >= KEEPALIVE_INTERVAL_SEC: + # Send application-level ping. The server has no handler so it will + # reply with error UNKNOWN_TYPE, which is silently swallowed in + # _dispatch(). The reply itself resets _ping_sent_at and counts as + # proof the round-trip works. + _seq += 1 + _ping_seq = _seq + _pending[_ping_seq] = { &"on_reply": Callable(), &"on_error": Callable() } + _send_raw({ "type": "network.ping", "seq": _ping_seq, "payload": {} }) + _ping_sent_at = now + if debug_log_packets: + print("[Net] Keepalive ping seq=%d" % _ping_seq) + + +func _now() -> float: + return Time.get_ticks_msec() / 1000.0 diff --git a/Client/origin-client/project.godot b/Client/origin-client/project.godot index e91ed7b..814ca4e 100644 --- a/Client/origin-client/project.godot +++ b/Client/origin-client/project.godot @@ -13,6 +13,12 @@ config_version=5 config/name="Origin-Client" config/features=PackedStringArray("4.5", "Mobile") config/icon="res://icon.svg" +run/main_scene="res://scenes/login/LoginScreen.tscn" + +[autoload] + +Network="*res://autoloads/Network.gd" +Auth="*res://autoloads/Auth.gd" [rendering] diff --git a/Client/origin-client/scenes/login/LoginScreen.tscn b/Client/origin-client/scenes/login/LoginScreen.tscn new file mode 100644 index 0000000..be0ef07 --- /dev/null +++ b/Client/origin-client/scenes/login/LoginScreen.tscn @@ -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 diff --git a/Client/origin-client/scenes/login/login_screen.gd b/Client/origin-client/scenes/login/login_screen.gd new file mode 100644 index 0000000..0b0f439 --- /dev/null +++ b/Client/origin-client/scenes/login/login_screen.gd @@ -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 diff --git a/Client/origin-client/scenes/main/MainScreen.tscn b/Client/origin-client/scenes/main/MainScreen.tscn new file mode 100644 index 0000000..3a586d9 --- /dev/null +++ b/Client/origin-client/scenes/main/MainScreen.tscn @@ -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 diff --git a/Client/origin-client/scenes/main/main_screen.gd b/Client/origin-client/scenes/main/main_screen.gd new file mode 100644 index 0000000..fe0bdc2 --- /dev/null +++ b/Client/origin-client/scenes/main/main_screen.gd @@ -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") diff --git a/Server/src/SOR.Admin/Components/Layout/MainLayout.razor b/Server/src/SOR.Admin/Components/Layout/MainLayout.razor index c39f163..0d7e156 100644 --- a/Server/src/SOR.Admin/Components/Layout/MainLayout.razor +++ b/Server/src/SOR.Admin/Components/Layout/MainLayout.razor @@ -8,7 +8,7 @@ @* Mobile topbar: hamburger + brand. Hidden on desktop via CSS. *@
-