From 1a2409c02a85be765893dbfee98d9621eb2220b0 Mon Sep 17 00:00:00 2001 From: OZAWA Sakuro <10973+sakuro@users.noreply.github.com> Date: Thu, 23 Apr 2026 20:11:07 +0900 Subject: [PATCH 1/2] :sparkles: Add rcon exec and rcon eval commands (#87) - Add `factorix rcon exec` to send a Factorio console command via RCon - Add `factorix rcon eval` to evaluate a Lua script; reads from stdin when script argument is omitted - sentinel_command: "/c" required for Factorio compatibility --- .rubocop.yml | 4 + CHANGELOG.md | 5 ++ README.md | 1 + doc/components/cli.md | 52 +++++++++++++ doc/factorix.1 | 43 +++++++++++ factorix.gemspec | 1 + lib/factorix.rb | 8 ++ lib/factorix/cli.rb | 2 + lib/factorix/cli/commands/rcon/eval.rb | 43 +++++++++++ lib/factorix/cli/commands/rcon/exec.rb | 42 ++++++++++ lib/factorix/errors.rb | 5 ++ spec/factorix/cli/commands/rcon/eval_spec.rb | 80 ++++++++++++++++++++ spec/factorix/cli/commands/rcon/exec_spec.rb | 63 +++++++++++++++ 13 files changed, 349 insertions(+) create mode 100644 lib/factorix/cli/commands/rcon/eval.rb create mode 100644 lib/factorix/cli/commands/rcon/exec.rb create mode 100644 spec/factorix/cli/commands/rcon/eval_spec.rb create mode 100644 spec/factorix/cli/commands/rcon/exec_spec.rb diff --git a/.rubocop.yml b/.rubocop.yml index 03a3013..b02e5cc 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -76,6 +76,10 @@ RSpec/IndexedLet: - '^error\d+$' # Allow error1, error2, etc. - '^suggestion\d+$' # Allow suggestion1, suggestion2, etc. +RSpec/SpecFilePathFormat: + CustomTransform: + RCon: rcon + Style/HashEachMethods: Exclude: - lib/factorix/cli/commands/cache/stat.rb # cache.each is not Hash#each, it's Cache::Base#each diff --git a/CHANGELOG.md b/CHANGELOG.md index 04647e1..830025f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ ## [Unreleased] +### Added + +- Add `rcon exec` command to execute a Factorio console command via RCon (#87) +- Add `rcon eval` command to evaluate a Lua script in a running Factorio server via RCon (#87) + ## [0.12.0] - 2026-04-21 ### Added diff --git a/README.md b/README.md index ff6bc0f..b8a4113 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ Factorix simplifies Factorio MOD management by providing: - **Blueprint Conversion**: Decode/encode Factorio blueprint strings to/from JSON - **MOD Portal Integration**: Upload new MODs or update existing ones, edit metadata - **Game Control**: Launch Factorio from the command line +- **RCon**: Execute console commands and Lua scripts on a running Factorio server via RCon - **Game Download**: Download Factorio game files (alpha, expansion, demo, headless) - **Cross-platform Support**: Works on Windows, Linux, macOS, and WSL diff --git a/doc/components/cli.md b/doc/components/cli.md index 2366d4f..dbad239 100644 --- a/doc/components/cli.md +++ b/doc/components/cli.md @@ -571,6 +571,58 @@ Validate the structure of a MOD changelog.txt file. **Use case**: CI validation of changelog structure before release +### RCon::Exec + +Execute a Factorio console command via RCon. + +**Requirements**: Factorio server must be running with RCon enabled. + +**Arguments**: +- `command` (required) - Console command to execute (e.g. `/server-save`) + +**Options**: +- `--host` - RCon host (default: from config, fallback `localhost`) +- `--port` - RCon port (default: from config, fallback `27015`) +- `--password` - RCon password (default: from config) + +**Configuration**: Connection settings can be set in the config file: +```ruby +config.rcon.host = "192.168.1.10" +config.rcon.port = 25575 +config.rcon.password = "secret" +``` + +**Output**: Server response, if any. Empty responses are suppressed. + +**Errors**: +- `RConConnectionError` - server unreachable +- `RConAuthenticationError` - wrong password + +**Examples**: +```bash +factorix rcon exec /server-save +factorix rcon exec --host 192.168.1.10 --port 25575 --password secret /server-save +``` + +### RCon::Eval + +Evaluate a Lua script in a running Factorio server via RCon. Wraps the script in `/c