using Microsoft.AspNetCore.Mvc; using RR3CommunityServer.Models; namespace RR3CommunityServer.Controllers; [ApiController] [Route("config/api/android")] public class ConfigController : ControllerBase { private readonly IConfiguration _configuration; private readonly ILogger _logger; public ConfigController(IConfiguration configuration, ILogger logger) { _configuration = configuration; _logger = logger; } /// /// Get game configuration - server time, feature flags, version info /// [HttpGet("getGameConfig")] public ActionResult> GetGameConfig() { _logger.LogInformation("GetGameConfig request"); var config = new GameConfig { ServerTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds(), ServerVersion = _configuration["ServerSettings:Version"] ?? "1.0.0", GameVersion = _configuration["ServerSettings:GameVersion"] ?? "14.0.1", MaintenanceMode = bool.Parse(_configuration["ServerSettings:MaintenanceMode"] ?? "false"), MessageOfTheDay = _configuration["ServerSettings:MessageOfTheDay"] ?? "Welcome to RR3 Community Server!", FeatureFlags = new FeatureFlags { MultiplayerEnabled = bool.Parse(_configuration["FeatureFlags:MultiplayerEnabled"] ?? "false"), LeaderboardsEnabled = bool.Parse(_configuration["FeatureFlags:LeaderboardsEnabled"] ?? "true"), DailyRewardsEnabled = bool.Parse(_configuration["FeatureFlags:DailyRewardsEnabled"] ?? "true"), TimeTrialsEnabled = bool.Parse(_configuration["FeatureFlags:TimeTrialsEnabled"] ?? "true"), CustomContentEnabled = bool.Parse(_configuration["FeatureFlags:CustomContentEnabled"] ?? "true"), SpecialEventsEnabled = bool.Parse(_configuration["FeatureFlags:SpecialEventsEnabled"] ?? "true"), AllItemsFree = bool.Parse(_configuration["FeatureFlags:AllItemsFree"] ?? "true") }, Urls = new ServerUrls { BaseUrl = _configuration["ServerSettings:BaseUrl"] ?? "http://localhost:5001", AssetsUrl = _configuration["ServerSettings:AssetsUrl"] ?? "http://localhost:5001/content/api", LeaderboardsUrl = _configuration["ServerSettings:LeaderboardsUrl"] ?? "http://localhost:5001/leaderboards/api", MultiplayerUrl = _configuration["ServerSettings:MultiplayerUrl"] ?? "http://localhost:5001/multiplayer/api" } }; var response = new SynergyResponse { resultCode = 0, message = "Success", data = config }; return Ok(response); } /// /// Get server time (Unix timestamp) /// [HttpGet("getServerTime")] public ActionResult> GetServerTime() { _logger.LogInformation("GetServerTime request"); var response = new SynergyResponse { resultCode = 0, message = "Success", data = new ServerTime { ServerTimestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds(), ServerTimeMs = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), Timezone = "UTC", IsDST = false } }; return Ok(response); } /// /// Get feature flags /// [HttpGet("getFeatureFlags")] public ActionResult> GetFeatureFlags() { _logger.LogInformation("GetFeatureFlags request"); var flags = new FeatureFlags { MultiplayerEnabled = bool.Parse(_configuration["FeatureFlags:MultiplayerEnabled"] ?? "false"), LeaderboardsEnabled = bool.Parse(_configuration["FeatureFlags:LeaderboardsEnabled"] ?? "true"), DailyRewardsEnabled = bool.Parse(_configuration["FeatureFlags:DailyRewardsEnabled"] ?? "true"), TimeTrialsEnabled = bool.Parse(_configuration["FeatureFlags:TimeTrialsEnabled"] ?? "true"), CustomContentEnabled = bool.Parse(_configuration["FeatureFlags:CustomContentEnabled"] ?? "true"), SpecialEventsEnabled = bool.Parse(_configuration["FeatureFlags:SpecialEventsEnabled"] ?? "true"), AllItemsFree = bool.Parse(_configuration["FeatureFlags:AllItemsFree"] ?? "true") }; var response = new SynergyResponse { resultCode = 0, message = "Success", data = flags }; return Ok(response); } /// /// Check server status and health /// [HttpGet("getServerStatus")] public ActionResult> GetServerStatus() { _logger.LogInformation("GetServerStatus request"); 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 Uptime = Environment.TickCount64 / 1000, // Seconds since server start Message = _configuration["ServerSettings:MessageOfTheDay"] ?? string.Empty }; var response = new SynergyResponse { resultCode = 0, message = "Success", data = status }; return Ok(response); } }