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:
@@ -17,8 +17,6 @@ using SOR.Shared.Proto;
|
||||
/// </summary>
|
||||
public sealed class GatewayAuthValidator : IGatewayAuthValidator
|
||||
{
|
||||
// AuthService.AuthServiceClient is the generated client stub from auth.proto.
|
||||
// It wraps a gRPC channel and provides typed RPC methods (ValidateTokenAsync, etc.).
|
||||
private readonly AuthService.AuthServiceClient _grpcClient;
|
||||
private readonly ILogger<GatewayAuthValidator> _logger;
|
||||
|
||||
@@ -37,8 +35,6 @@ public sealed class GatewayAuthValidator : IGatewayAuthValidator
|
||||
{
|
||||
try
|
||||
{
|
||||
// Call the Auth service's ValidateToken RPC.
|
||||
// This is a synchronous RPC (request → response) over gRPC.
|
||||
var response = await _grpcClient.ValidateTokenAsync(
|
||||
new ValidateTokenRequest { SessionToken = sessionToken },
|
||||
cancellationToken: cancellationToken);
|
||||
@@ -53,11 +49,56 @@ public sealed class GatewayAuthValidator : IGatewayAuthValidator
|
||||
}
|
||||
catch (Grpc.Core.RpcException ex)
|
||||
{
|
||||
// gRPC exception: Auth service is unreachable, overloaded, or returned an error.
|
||||
// Treat as invalid — never accept a connection that cannot be validated.
|
||||
_logger.LogWarning(ex,
|
||||
"Auth gRPC call failed during token validation: {Status}", ex.Status.StatusCode);
|
||||
return (false, string.Empty, string.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async Task<(bool Success, string ErrorCode, string SessionToken, string UserId, string DisplayName)>
|
||||
LoginAsync(string email, string password, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
var response = await _grpcClient.LoginAsync(
|
||||
new LoginRequest { Email = email, Password = password },
|
||||
cancellationToken: cancellationToken);
|
||||
|
||||
if (!response.Success)
|
||||
return (false, response.ErrorCode, string.Empty, string.Empty, string.Empty);
|
||||
|
||||
// Token is returned; fetch display name via ValidateToken (it includes it).
|
||||
var validate = await ValidateAsync(response.SessionToken, cancellationToken);
|
||||
return (true, string.Empty, response.SessionToken, validate.UserId, validate.DisplayName);
|
||||
}
|
||||
catch (Grpc.Core.RpcException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "Auth gRPC call failed during login: {Status}", ex.Status.StatusCode);
|
||||
return (false, "AUTH_SERVICE_UNAVAILABLE", string.Empty, string.Empty, string.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async Task<(bool Success, string ErrorCode, string SessionToken, string UserId, string DisplayName)>
|
||||
RegisterAsync(string email, string password, string displayName, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
var response = await _grpcClient.RegisterAsync(
|
||||
new RegisterRequest { Email = email, Password = password, DisplayName = displayName },
|
||||
cancellationToken: cancellationToken);
|
||||
|
||||
if (!response.Success)
|
||||
return (false, response.ErrorCode, string.Empty, string.Empty, string.Empty);
|
||||
|
||||
var validate = await ValidateAsync(response.SessionToken, cancellationToken);
|
||||
return (true, string.Empty, response.SessionToken, validate.UserId, validate.DisplayName);
|
||||
}
|
||||
catch (Grpc.Core.RpcException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "Auth gRPC call failed during register: {Status}", ex.Status.StatusCode);
|
||||
return (false, "AUTH_SERVICE_UNAVAILABLE", string.Empty, string.Empty, string.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user