Add Settings, Account, Bug Reports, and Leaderboard
Server: - New SOR.Support project: SubmitBugReport, GetLeaderboard, GetAccountProfile handlers - New SOR.Database support schema: BugReport + BugReportResponse entities + SupportDbContext - EF migration: Migrations/Support/AddSupport - Admin panel: Bug Reports list + detail pages with reply-to-submitter flow - Admin NavMenu: Support section with Bug Reports link - Reply creates chat.Notification (type "admin_response") for in-game mailbox Client: - Settings autoload (Settings.gd): music/sfx volume+mute, persisted to user://settings.cfg - SettingsScreen: sliders + mute CheckButtons wired to Settings autoload - AccountScreen: profile (display name, OP, rank score) + mailbox (admin_response notifications) - LeaderboardScreen: paginated ranked player list, caller highlighted in blue - BugReportDialog: category/title/description/steps form, submits via support.submit_bug_report - MainScreen: new Leaderboard, Account, Settings, Report a Bug navigation buttons 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,46 @@
|
||||
namespace SOR.Support.Handlers;
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SOR.Database.Contexts;
|
||||
using SOR.Networking.Abstractions.Messaging;
|
||||
using SOR.Networking.Abstractions.Transport;
|
||||
using SOR.Shared.Networking;
|
||||
|
||||
/// <summary>
|
||||
/// account.get_profile — returns the caller's own account profile.
|
||||
/// Used by the Account Management screen: display name, OP balance, rank score.
|
||||
/// </summary>
|
||||
internal sealed class GetAccountProfileHandler : IMessageHandler
|
||||
{
|
||||
private readonly SorIdentityDbContext _identityDb;
|
||||
|
||||
public GetAccountProfileHandler(SorIdentityDbContext identityDb)
|
||||
{
|
||||
_identityDb = identityDb;
|
||||
}
|
||||
|
||||
public string MessageType => "account.get_profile";
|
||||
|
||||
public async Task<IServerMessage?> HandleAsync(
|
||||
IClientMessage message,
|
||||
AuthenticatedConnection connection,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var accountId = Guid.Parse(connection.UserId);
|
||||
|
||||
var account = await _identityDb.Users
|
||||
.Where(a => a.Id == accountId)
|
||||
.Select(a => new { a.Id, a.DisplayName, a.OriginPoints, a.RankScore })
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
|
||||
if (account is null)
|
||||
return ServerMessage.Error(message.Seq, "NOT_FOUND", "Account not found.");
|
||||
|
||||
return ServerMessage.Reply("account.get_profile.ack", message.Seq,
|
||||
new GetAccountProfileResponse(
|
||||
AccountId: account.Id,
|
||||
DisplayName: account.DisplayName ?? connection.DisplayName,
|
||||
OriginPoints: account.OriginPoints,
|
||||
RankScore: account.RankScore));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
namespace SOR.Support.Handlers;
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SOR.Database.Contexts;
|
||||
using SOR.Networking.Abstractions.Messaging;
|
||||
using SOR.Networking.Abstractions.Transport;
|
||||
using SOR.Shared.Networking;
|
||||
|
||||
/// <summary>
|
||||
/// leaderboard.get — returns paginated ranked leaderboard entries.
|
||||
/// Ranked by RankScore descending. Includes the caller's own entry
|
||||
/// so the client can highlight their position.
|
||||
/// </summary>
|
||||
internal sealed class GetLeaderboardHandler : IMessageHandler
|
||||
{
|
||||
private readonly IMessageSerializer _serializer;
|
||||
private readonly SorIdentityDbContext _identityDb;
|
||||
|
||||
private const int MaxPageSize = 100;
|
||||
|
||||
public GetLeaderboardHandler(
|
||||
IMessageSerializer serializer,
|
||||
SorIdentityDbContext identityDb)
|
||||
{
|
||||
_serializer = serializer;
|
||||
_identityDb = identityDb;
|
||||
}
|
||||
|
||||
public string MessageType => "leaderboard.get";
|
||||
|
||||
public async Task<IServerMessage?> HandleAsync(
|
||||
IClientMessage message,
|
||||
AuthenticatedConnection connection,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var req = _serializer.DeserializePayload<GetLeaderboardRequest>(message.Payload);
|
||||
var page = Math.Max(0, req.Page);
|
||||
var pageSize = Math.Clamp(req.PageSize, 1, MaxPageSize);
|
||||
var skip = page * pageSize;
|
||||
|
||||
var total = await _identityDb.Users.CountAsync(cancellationToken);
|
||||
|
||||
var entries = await _identityDb.Users
|
||||
.OrderByDescending(a => a.RankScore)
|
||||
.Skip(skip)
|
||||
.Take(pageSize)
|
||||
.Select(a => new { a.Id, a.DisplayName, a.RankScore })
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
var dtos = entries
|
||||
.Select((e, i) => new LeaderboardEntryDto(
|
||||
Rank: skip + i + 1,
|
||||
AccountId: e.Id,
|
||||
DisplayName: e.DisplayName ?? e.Id.ToString(),
|
||||
RankScore: e.RankScore))
|
||||
.ToList();
|
||||
|
||||
return ServerMessage.Reply("leaderboard.get.ack", message.Seq,
|
||||
new GetLeaderboardResponse(dtos, total, page, pageSize));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
namespace SOR.Support.Handlers;
|
||||
|
||||
using SOR.Database.Contexts;
|
||||
using SOR.Database.Entities.Support;
|
||||
using SOR.Networking.Abstractions.Messaging;
|
||||
using SOR.Networking.Abstractions.Transport;
|
||||
using SOR.Shared.Networking;
|
||||
|
||||
/// <summary>
|
||||
/// support.submit_bug_report — persists a player bug report.
|
||||
/// The player's display name is snapshotted from the connection.
|
||||
/// </summary>
|
||||
internal sealed class SubmitBugReportHandler : IMessageHandler
|
||||
{
|
||||
private readonly IMessageSerializer _serializer;
|
||||
private readonly SupportDbContext _supportDb;
|
||||
|
||||
public SubmitBugReportHandler(
|
||||
IMessageSerializer serializer,
|
||||
SupportDbContext supportDb)
|
||||
{
|
||||
_serializer = serializer;
|
||||
_supportDb = supportDb;
|
||||
}
|
||||
|
||||
public string MessageType => "support.submit_bug_report";
|
||||
|
||||
public async Task<IServerMessage?> HandleAsync(
|
||||
IClientMessage message,
|
||||
AuthenticatedConnection connection,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var req = _serializer.DeserializePayload<SubmitBugReportRequest>(message.Payload);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(req.Title) || string.IsNullOrWhiteSpace(req.Description))
|
||||
return ServerMessage.Error(message.Seq, "INVALID_PAYLOAD", "Title and description are required.");
|
||||
|
||||
var accountId = Guid.Parse(connection.UserId);
|
||||
|
||||
var report = new BugReport
|
||||
{
|
||||
SubmitterAccountId = accountId,
|
||||
SubmitterDisplayName = connection.DisplayName,
|
||||
Category = string.IsNullOrWhiteSpace(req.Category) ? "other" : req.Category,
|
||||
Title = req.Title.Trim()[..Math.Min(req.Title.Trim().Length, 200)],
|
||||
Description = req.Description.Trim()[..Math.Min(req.Description.Trim().Length, 5000)],
|
||||
StepsToReproduce = req.StepsToReproduce?.Trim(),
|
||||
Status = "Open",
|
||||
CreatedAt = DateTimeOffset.UtcNow,
|
||||
};
|
||||
|
||||
_supportDb.BugReports.Add(report);
|
||||
await _supportDb.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return ServerMessage.Reply("support.submit_bug_report.ack", message.Seq,
|
||||
new SubmitBugReportResponse(report.Id));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<AssemblyName>SOR.Support</AssemblyName>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<FrameworkReference Include="Microsoft.AspNetCore.App" />
|
||||
<ProjectReference Include="..\SOR.Database\SOR.Database.csproj" />
|
||||
<ProjectReference Include="..\SOR.Networking.Abstractions\SOR.Networking.Abstractions.csproj" />
|
||||
<ProjectReference Include="..\SOR.Shared\SOR.Shared.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,30 @@
|
||||
namespace SOR.Support;
|
||||
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using SOR.Database;
|
||||
using SOR.Networking.Abstractions.Messaging;
|
||||
using SOR.Support.Handlers;
|
||||
|
||||
/// <summary>
|
||||
/// Registers all Support service components into the DI container.
|
||||
/// Called from SOR.Host/Program.cs when ENABLED_SERVICES includes "support".
|
||||
/// </summary>
|
||||
public static class ServiceRegistration
|
||||
{
|
||||
public static IServiceCollection AddSupportService(
|
||||
this IServiceCollection services,
|
||||
IConfiguration configuration)
|
||||
{
|
||||
// Database contexts the support service needs.
|
||||
services.AddSupportDatabase(configuration);
|
||||
services.AddIdentityDatabase(configuration);
|
||||
|
||||
// Message handlers — one per message type, Transient lifetime.
|
||||
services.AddTransient<IMessageHandler, SubmitBugReportHandler>();
|
||||
services.AddTransient<IMessageHandler, GetLeaderboardHandler>();
|
||||
services.AddTransient<IMessageHandler, GetAccountProfileHandler>();
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
namespace SOR.Support;
|
||||
|
||||
// ── Request types (client → server) ──────────────────────────────────────────
|
||||
|
||||
/// <summary>Submit a bug report from in-game.</summary>
|
||||
public sealed record SubmitBugReportRequest(
|
||||
string Category,
|
||||
string Title,
|
||||
string Description,
|
||||
string? StepsToReproduce = null);
|
||||
|
||||
/// <summary>Fetch the ranked leaderboard (paginated).</summary>
|
||||
public sealed record GetLeaderboardRequest(
|
||||
int Page = 0,
|
||||
int PageSize = 50);
|
||||
|
||||
/// <summary>Fetch the caller's own account profile.</summary>
|
||||
public sealed record GetAccountProfileRequest; // identity from connection
|
||||
|
||||
// ── Response types (server → client) ─────────────────────────────────────────
|
||||
|
||||
public sealed record SubmitBugReportResponse(Guid ReportId);
|
||||
|
||||
public sealed record GetLeaderboardResponse(
|
||||
IEnumerable<LeaderboardEntryDto> Entries,
|
||||
int TotalCount,
|
||||
int Page,
|
||||
int PageSize);
|
||||
|
||||
public sealed record GetAccountProfileResponse(
|
||||
Guid AccountId,
|
||||
string DisplayName,
|
||||
int OriginPoints,
|
||||
int RankScore);
|
||||
|
||||
// ── DTOs ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
public sealed record LeaderboardEntryDto(
|
||||
int Rank,
|
||||
Guid AccountId,
|
||||
string DisplayName,
|
||||
int RankScore);
|
||||
Reference in New Issue
Block a user