Wire up real implementations for Tracking & Config controllers

- TrackingController: Added database persistence for analytics events
  * Created AnalyticsEvent entity with user/session tracking
  * Store event type, data (JSON), and timestamp
  * Graceful fallback if DB write fails (game doesn't break)

- ConfigController: Added real player counting
  * Query active sessions from last 15 minutes
  * Return actual player count instead of hardcoded 0
  * Real-time server status with DB metrics

- Added AnalyticsEvents table migration
  * Stores all game telemetry for analytics
  * Indexed by UserId for performance
  * JSON event data for flexibility

Controllers now fully wired to database:
- 11/18 controllers REAL implementation 
- 5/18 controllers STUB (config-based) ⚠️
- 2/18 controllers SERVICE (delegated) ⚠️

Total: 95 endpoints, improving from demo to production

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
2026-02-23 17:03:36 -08:00
parent a934f57b52
commit 182026a32c
22 changed files with 2417 additions and 35 deletions

View File

@@ -1,4 +1,6 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using RR3CommunityServer.Data;
using RR3CommunityServer.Models;
namespace RR3CommunityServer.Controllers;
@@ -7,11 +9,13 @@ namespace RR3CommunityServer.Controllers;
[Route("config/api/android")]
public class ConfigController : ControllerBase
{
private readonly RR3DbContext _context;
private readonly IConfiguration _configuration;
private readonly ILogger<ConfigController> _logger;
public ConfigController(IConfiguration configuration, ILogger<ConfigController> logger)
public ConfigController(RR3DbContext context, IConfiguration configuration, ILogger<ConfigController> logger)
{
_context = context;
_configuration = configuration;
_logger = logger;
}
@@ -117,16 +121,24 @@ public class ConfigController : ControllerBase
/// Check server status and health
/// </summary>
[HttpGet("getServerStatus")]
public ActionResult<SynergyResponse<ServerStatus>> GetServerStatus()
public async Task<ActionResult<SynergyResponse<ServerStatus>>> GetServerStatus()
{
_logger.LogInformation("GetServerStatus request");
// Get real player count from database (sessions created in last 15 minutes)
var fifteenMinutesAgo = DateTime.UtcNow.AddMinutes(-15);
var playerCount = await _context.Sessions
.Where(s => s.CreatedAt >= fifteenMinutesAgo)
.Select(s => s.UserId)
.Distinct()
.CountAsync();
var status = new ServerStatus
{
Status = "online",
Version = _configuration["ServerSettings:Version"] ?? "1.0.0",
MaintenanceMode = bool.Parse(_configuration["ServerSettings:MaintenanceMode"] ?? "false"),
PlayerCount = 0, // TODO: Implement player counting
PlayerCount = playerCount,
Uptime = Environment.TickCount64 / 1000, // Seconds since server start
Message = _configuration["ServerSettings:MessageOfTheDay"] ?? string.Empty
};