Skip to content

Fix command argument parsing bug when token substring matches earlier token#626

Merged
Bishbash777 merged 6 commits intoTorchAPI:masterfrom
buttheadbob:master
Jan 28, 2026
Merged

Fix command argument parsing bug when token substring matches earlier token#626
Bishbash777 merged 6 commits intoTorchAPI:masterfrom
buttheadbob:master

Conversation

@buttheadbob
Copy link
Copy Markdown
Contributor

Fix command argument parsing bug when token substring matches earlier token

Changes

  • Bug Fix: Revised CommandTree.GetCommand method to correctly extract arguments from command strings.
  • Minor Formatting: Updated array initializer syntax for consistency.

Bug Description

The previous implementation used IndexOf(split[skip]) to locate the start of the arguments within the original command text. This approach fails when an earlier command token contains the argument token as a substring. For example, given the command "qs storegrid ore 10000", the token "ore" appears inside the preceding token "storegrid". IndexOf would then return the position inside "storegrid", causing argText to incorrectly start at "oregrid ore 10000" rather than at the actual argument "ore 10000".

Solution

The fix tracks the position of each preceding token by iterating over the command tokens up to the argument start. For each token, we locate it in the original string using a case‑sensitive ordinal search, advance the position past the token and any trailing spaces, and finally take the substring from that position. This ensures the argument text begins exactly after the full command name.

Code Changes

  1. Line 99: Changed new []{' '} to new[] { ' ' } (cosmetic).
  2. Lines 106–145: Replaced the faulty substring logic with a robust token‑position tracking algorithm. Added detailed inline comments explaining the bug and the fix.
  3. Line 147: Added a blank line for readability.

Impact

  • Commands with overlapping token substrings will now parse arguments correctly.
  • No breaking changes; the method signature and overall behavior remain unchanged.
  • Improves reliability of command‑line parsing in Torch's command system.
… token

## Fix command argument parsing bug when token substring matches earlier token

### Changes
- **Bug Fix**: Revised `CommandTree.GetCommand` method to correctly extract arguments from command strings.
- **Minor Formatting**: Updated array initializer syntax for consistency.

### Bug Description
The previous implementation used `IndexOf(split[skip])` to locate the start of the arguments within the original command text. This approach fails when an earlier command token contains the argument token as a substring. For example, given the command `"qs storegrid ore 10000"`, the token `"ore"` appears inside the preceding token `"storegrid"`. `IndexOf` would then return the position inside `"storegrid"`, causing `argText` to incorrectly start at `"oregrid ore 10000"` rather than at the actual argument `"ore 10000"`.

### Solution
The fix tracks the position of each preceding token by iterating over the command tokens up to the argument start. For each token, we locate it in the original string using a case‑sensitive ordinal search, advance the position past the token and any trailing spaces, and finally take the substring from that position. This ensures the argument text begins exactly after the full command name.

### Code Changes
1. **Line 99**: Changed `new []{' '}` to `new[] { ' ' }` (cosmetic).
2. **Lines 106–145**: Replaced the faulty substring logic with a robust token‑position tracking algorithm. Added detailed inline comments explaining the bug and the fix.
3. **Line 147**: Added a blank line for readability.

### Impact
- Commands with overlapping token substrings will now parse arguments correctly.
- No breaking changes; the method signature and overall behavior remain unchanged.
- Improves reliability of command‑line parsing in Torch's command system.
…ry structure

Move dedicated server files to 'game' subdirectory

Add retry logic and error handling for SteamCMD updates

Remove unused using statements

Centralize path calculation with GetDedicatedServer64Path method
…evelopers

- Added EnsureDedicatedServer64Symlink method that creates a directory junction from ./DedicatedServer64 to ./game/DedicatedServer64 for backward compatibility with plugin development workflows.
- Ensure world list refreshes after new world creation by calling RefreshModel in InstanceManager.SelectWorld
@Bishbash777 Bishbash777 merged commit 4fd5dfa into TorchAPI:master Jan 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants