Skip to content

Replace environment variable port ranges with config-based solution#51

Merged
pardeike merged 2 commits intomainfrom
copilot/fix-104ab506-f559-4fd7-8d7f-ac7e807f65fa
Sep 15, 2025
Merged

Replace environment variable port ranges with config-based solution#51
pardeike merged 2 commits intomainfrom
copilot/fix-104ab506-f559-4fd7-8d7f-ac7e807f65fa

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Sep 15, 2025

Problem

The previous implementation used GABS_PORT_RANGES environment variable to configure custom port ranges, which was problematic because:

  1. AI Agent Workflow: GABS is typically started by AI agents, making manual environment variable setup impractical
  2. User Experience: Users had to set environment variables before starting GABS manually
  3. Configuration Inconsistency: Port configuration was separated from the main config file

Users reported getting "no available ports in range 49152-65535" errors even with DirectPath launch mode, because the environment variable wasn't set.

Solution

This PR replaces the environment variable approach with a config-based solution that integrates port range configuration directly into the main config.json file.

Key Changes

Configuration Structure

{
  "version": "1.0",
  "portRanges": {
    "customRanges": [
      {"min": 8000, "max": 8999},
      {"min": 9000, "max": 9999}
    ]
  },
  "games": {
    "rimworld": {
      "id": "rimworld", 
      "name": "RimWorld",
      "launchMode": "DirectPath",
      "target": "C:\\Program Files (x86)\\Steam\\steamapps\\common\\RimWorld\\RimWorldWin64.exe"
    }
  }
}

Implementation Details

  • Added PortRange and PortRangeConfig structs with JSON serialization
  • Extended GamesConfig with optional portRanges field
  • Created WriteBridgeJSONWithConfig() that accepts games configuration
  • Updated startGame() to pass configuration to bridge creation
  • Replaced findAvailablePortWithFallback() with findAvailablePortWithConfig()
  • Removed getCustomPortRanges() environment variable parsing
  • Updated error messages to suggest config file instead of environment variables

DirectPath Clarification

The user's confusion about DirectPath mode was addressed - all launch modes require GABP bridge configuration for game communication, regardless of how the game is launched. The port allocation happens for Steam, Epic, DirectPath, and CustomCommand modes because they all need the bridge for AI-game communication.

Benefits

  1. Simplified Setup: No environment variables needed
  2. AI-Friendly: AI agents can start GABS without additional configuration steps
  3. Centralized Config: All configuration in one place
  4. Backward Compatible: Existing configs work (falls back to default ranges)
  5. Better Error Messages: Users directed to config file instead of environment variables

Testing

  • All existing tests updated and passing
  • New tests added for config-based port range functionality
  • Comprehensive test coverage for serialization/deserialization
  • Manual testing confirms custom port ranges work correctly
  • Build and integration tests verify no regressions

This change makes GABS much more user-friendly for both manual and automated deployment scenarios.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…pendency

Co-authored-by: pardeike <853584+pardeike@users.noreply.github.com>
Copilot AI changed the title [WIP] The last change was kind of problematic. The gabs server usually is started by an AI so giving people instructions on how to set env variables for port ranges before starting it manually makes little sense. Revert the change that gets the custom port r... Replace environment variable port ranges with config-based solution Sep 15, 2025
Copilot AI requested a review from pardeike September 15, 2025 19:04
@pardeike pardeike marked this pull request as ready for review September 15, 2025 19:07
@pardeike pardeike merged commit 0f54c2d into main Sep 15, 2025
5 of 6 checks passed
@pardeike pardeike deleted the copilot/fix-104ab506-f559-4fd7-8d7f-ac7e807f65fa branch September 15, 2025 19:07
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.

2 participants