Skip to content

RCON GetDvar: normalize CoD4x responses for unknown-cvar and color-coded values#981

Merged
frasermolyneux merged 6 commits into
mainfrom
copilot/agent-normalize-rcon-responses
May 31, 2026
Merged

RCON GetDvar: normalize CoD4x responses for unknown-cvar and color-coded values#981
frasermolyneux merged 6 commits into
mainfrom
copilot/agent-normalize-rcon-responses

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 30, 2026

GetDvar could return raw RCON output when the quoted dvar format did not match, which breaks CoD4x behavior. This change normalizes CoD4x response text so unknown cvars map to not-found and returned values are stripped of Quake-style color tokens.

  • Response normalization in RconController.GetDvar

    • Added color-code stripping before parsing (^0-^9, ^a-^z, ^A-^Z).
    • Parsing now runs on normalized text, avoiding leakage of raw formatted RCON output.
    • Uses compiled regex fields for consistent and efficient match/replace behavior.
  • Unknown-cvar mapping

    • Detects normalized responses starting with Bad command or cvar:.
    • Returns API not-found for missing dvars instead of treating the raw text as a value.
  • Error contract extension

    • Added DVAR_NOT_FOUND to ErrorCodes for explicit not-found semantics on dvar lookups.
  • Focused unit coverage

    • Added RconControllerTests for:
      • unknown-cvar CoD4x response -> not found
      • numeric color code normalization
      • alphabetic color code normalization
var normalizedResponse = QuakeColorCodeRegex.Replace(response ?? string.Empty, string.Empty).Trim();

if (normalizedResponse.StartsWith("Bad command or cvar:", StringComparison.OrdinalIgnoreCase))
    return new ApiResponse<DvarValueDto>(
        new ApiError(ErrorCodes.DVAR_NOT_FOUND, $"The dvar '{dvarName}' was not found on the game server."))
        .ToNotFoundResult();

Copilot AI requested review from Copilot and removed request for Copilot May 30, 2026 13:43
Copilot AI linked an issue May 30, 2026 that may be closed by this pull request
7 tasks
Co-authored-by: frasermolyneux <34033625+frasermolyneux@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot May 30, 2026 13:54
Co-authored-by: frasermolyneux <34033625+frasermolyneux@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot May 30, 2026 13:58
Copilot AI changed the title [WIP] Fix RCON GetDvar to handle unknown cvars and color codes RCON GetDvar: normalize CoD4x responses for unknown-cvar and color-coded values May 30, 2026
Copilot AI requested a review from frasermolyneux May 30, 2026 13:59
@frasermolyneux frasermolyneux marked this pull request as ready for review May 30, 2026 15:19
Copilot AI review requested due to automatic review settings May 30, 2026 15:19
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 30, 2026

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 30, 2026

Superseded — A newer run has replaced this result.
Superseded — A newer run has replaced this result.

🏗️ Terraform Plan

🌍 Environment: dev

✅ Validate — Passed

✅ Plan

No changes. Your infrastructure matches the configuration.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR normalizes GetDvar RCON responses so CoD/Quake-style color-coded output is parsed consistently and unknown dvars are returned as not found.

Changes:

  • Adds compiled regex-based response normalization in RconController.GetDvar.
  • Maps Bad command or cvar: responses to DVAR_NOT_FOUND.
  • Adds focused unit tests for unknown dvars and numeric/alphabetic color-code stripping.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/XtremeIdiots.Portal.Integrations.Servers.Api.V1/Controllers/V1/RconController.cs Normalizes GetDvar responses, strips Quake color codes, and returns not-found for unknown cvars.
src/XtremeIdiots.Portal.Integrations.Servers.Api.V1/Constants/ErrorCodes.cs Adds DVAR_NOT_FOUND error code.
src/XtremeIdiots.Portal.Integrations.Servers.Api.Tests.V1/Controllers/RconControllerTests.cs Adds unit tests covering CoD4x unknown-cvar and color-code normalization behavior.

@frasermolyneux
Copy link
Copy Markdown
Owner

@copilot - you need to pass a timeout in for the regex to fix the sonarcloud failures on the sonarcloud code analysis quality gate

Co-authored-by: frasermolyneux <34033625+frasermolyneux@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 30, 2026

@copilot - you need to pass a timeout in for the regex to fix the sonarcloud failures on the sonarcloud code analysis quality gate

Implemented in 8354431: both new RconController compiled regexes now include TimeSpan.FromSeconds(1) timeouts to satisfy SonarCloud’s bounded-regex requirement.

Copilot AI review requested due to automatic review settings May 30, 2026 20:49
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 30, 2026

Superseded — A newer run has replaced this result.

🏗️ Terraform Plan

🌍 Environment: dev

✅ Validate — Passed

✅ Plan

No changes. Your infrastructure matches the configuration.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

@github-actions
Copy link
Copy Markdown
Contributor

🏗️ Terraform Plan

🌍 Environment: dev

✅ Validate — Passed

✅ Plan

Count
➕ Add 6
📋 Resource Details
Action Resource
➕ Create azurerm_api_management_api_version_set.api_version_set
➕ Create azurerm_api_management_product.api_product
➕ Create azurerm_api_management_product_policy.api_product_policy
➕ Create azurerm_linux_web_app.app_v1
➕ Create azurerm_monitor_activity_log_alert.rg_resource_health
➕ Create random_id.environment_id

@sonarqubecloud
Copy link
Copy Markdown

@frasermolyneux frasermolyneux enabled auto-merge (squash) May 31, 2026 07:19
@frasermolyneux frasermolyneux merged commit 855577f into main May 31, 2026
17 checks passed
@frasermolyneux frasermolyneux deleted the copilot/agent-normalize-rcon-responses branch May 31, 2026 07:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Agent] RCON GetDvar: normalize CoD4x responses (unknown cvar + color codes)

3 participants