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>
62 lines
2.1 KiB
C#
62 lines
2.1 KiB
C#
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));
|
|
}
|
|
}
|