From 46d7f1fe82d3c6e84881c72ea6765a1375660324 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Bosc=C3=A1?= Date: Wed, 15 Apr 2026 16:35:49 -0300 Subject: [PATCH 01/25] Add one-command Windows startup script for OpenKore remote stack --- docs/guia-acesso-remoto-pt-br.md | 6 + docs/guia-acesso-remoto-windows-nativo.md | 56 +++++++++- src/Interface/Socket.pm | 73 ++++++++---- tools/start-gateway.ps1 | 32 +++++- tools/start-openkore-socket-tcp.ps1 | 128 ++++++++++++++++++++++ 5 files changed, 269 insertions(+), 26 deletions(-) create mode 100644 tools/start-openkore-socket-tcp.ps1 diff --git a/docs/guia-acesso-remoto-pt-br.md b/docs/guia-acesso-remoto-pt-br.md index 53232b5685..3b1984862d 100644 --- a/docs/guia-acesso-remoto-pt-br.md +++ b/docs/guia-acesso-remoto-pt-br.md @@ -21,6 +21,10 @@ Por quê: - O gateway conecta no OpenKore via socket Unix (`--socket`) **ou** via TCP (`--kore-host` + `--kore-port`). - O fluxo padrão do projeto usa caminhos Unix (`/etc/...`) e serviço `systemd`. +> Importante: para funcionar, o endpoint precisa falar o protocolo de console do OpenKore (`set active/input`). Nem toda porta TCP do OpenKore (ex.: `XKore_port`) é compatível com esse protocolo. +> No Windows nativo, você pode expor endpoint compatível iniciando com `OPENKORE_SOCKET_TCP_PORT` e `--interface=Socket`. +> Atalho no Windows: `tools/start-openkore-socket-tcp.ps1` sobe OpenKore + gateway com um comando. + Isso significa: - **Linux nativo**: cenário recomendado e documentado. @@ -250,6 +254,8 @@ perl tools/remote_gateway.pl \ ``` > Nesse modo, use `--kore-host` + `--kore-port` juntos. +> Importante: `XKore_port` no `config.txt` não garante compatibilidade com o protocolo de console (`set active/input`) usado pelo gateway. +> Se a porta não for compatível, o `/health` ficará com `connected=false` e `/commands` retornará `503 core_unavailable`. --- diff --git a/docs/guia-acesso-remoto-windows-nativo.md b/docs/guia-acesso-remoto-windows-nativo.md index e6c652ce85..0d788a556d 100644 --- a/docs/guia-acesso-remoto-windows-nativo.md +++ b/docs/guia-acesso-remoto-windows-nativo.md @@ -99,11 +99,53 @@ python -m json.tool .\config\gateway-users.json | Out-Null; Write-Host "JSON OK" Você precisa saber host/porta do endpoint TCP. -Exemplo deste guia: +### Pré-requisito crítico + +O `remote_gateway.pl` só consegue falar com um endpoint que implemente o protocolo de console do OpenKore (`set active` / `input`). +Esse endpoint é nativo da **Interface Socket** (arquivo `console.socket`). + +Em outras palavras: deixar apenas `XKore_port` configurado não abre automaticamente esse protocolo para o gateway. + +⚠️ **Importante:** no OpenKore padrão, `XKore_port` (ex.: `2350`) **não é automaticamente** o endpoint de console remoto esperado pelo `remote_gateway.pl` (`set active/input`). + +### Como abrir endpoint TCP compatível no Windows nativo + +No mesmo PowerShell em que você vai rodar o OpenKore: + +```powershell +$env:OPENKORE_SOCKET_TCP_HOST = "127.0.0.1" +$env:OPENKORE_SOCKET_TCP_PORT = "2350" +perl .\openkore.pl --interface=Socket +``` + +Esse comando inicia o OpenKore já com endpoint TCP compatível para o gateway. + +### Jeito curto (sem comandos longos): script pronto + +Você pode subir OpenKore + gateway com **um único comando**: + +```powershell +powershell -NoProfile -ExecutionPolicy Bypass -File .\tools\start-openkore-socket-tcp.ps1 -CommandToken "UM_TOKEN_LONGO_E_ALEATORIO" +``` + +Esse script: +- inicia OpenKore com `--interface=Socket`; +- habilita endpoint TCP compatível na `127.0.0.1:2350`; +- inicia o gateway na `127.0.0.1:18085`. + +Exemplo deste guia (somente se você tiver um endpoint TCP compatível já ativo): - host: `127.0.0.1` - porta: `2350` +Valide antes de subir o gateway: + +```powershell +Test-NetConnection 127.0.0.1 -Port 2350 +``` + +Se `TcpTestSucceeded` for `False`, o gateway vai subir com `/health`, mas ficará com `connected=false` e retornará `503 core_unavailable` em `/commands`. + --- ## 6) Subir gateway no Windows (modo TCP) @@ -114,6 +156,8 @@ No PowerShell, dentro de `C:\openkore`: perl .\tools\remote_gateway.pl --kore-host 127.0.0.1 --kore-port 2350 --listen-host 127.0.0.1 --listen-port 18085 --command-token "UM_TOKEN_LONGO_E_ALEATORIO" --audit-file ".\\logs\\gateway_audit.jsonl" --command-rate-limit 30 --command-rate-window 60 --auth-enabled --users-file ".\\config\\gateway-users.json" --token-ttl 900 --session-file ".\\data\\gateway_sessions.json" ``` +> Se quiser manter nativo no Windows, prefira abrir o endpoint com `OPENKORE_SOCKET_TCP_PORT` + `--interface=Socket` (bloco acima). + --- ## 7) Testar pelo Windows (browser + PowerShell) @@ -180,6 +224,14 @@ powershell -NoProfile -ExecutionPolicy Bypass -File C:\openkore\scripts\start-ga ## 10) Troubleshooting comum (Windows nativo) - **Gateway não inicia com erro de conexão**: host/porta TCP do OpenKore incorretos. +- **`Status conectado ao OpenKore: False` + erro `core_unavailable (503)` na UI**: + - O gateway está de pé, mas **não conseguiu abrir sessão com o endpoint do OpenKore**. + - Confira no PowerShell se a porta realmente aceita TCP: + ```powershell + Test-NetConnection 127.0.0.1 -Port 2350 + ``` + - Se `TcpTestSucceeded` vier `False`, a porta configurada em `--kore-port` está incorreta/inativa. + - Atenção: `XKore_port` pode existir no `config.txt` e **mesmo assim não ser** o endpoint que fala o protocolo de console (`set active/input`) esperado pelo `remote_gateway.pl`. - **porta 18085 não abre no Windows**: confirme que gateway está rodando e bound em `127.0.0.1`. - **401/403**: revisar usuário/senha/token/header. - **sem eventos**: OpenKore não está acessível no endpoint TCP configurado. @@ -191,4 +243,4 @@ powershell -NoProfile -ExecutionPolicy Bypass -File C:\openkore\scripts\start-ga ```powershell perl .\src\test\unittests.pl RemoteGatewaySmokeTest bash .\tools\check_gateway_release.sh -``` \ No newline at end of file +``` diff --git a/src/Interface/Socket.pm b/src/Interface/Socket.pm index 41b84e4914..354d846816 100644 --- a/src/Interface/Socket.pm +++ b/src/Interface/Socket.pm @@ -169,6 +169,8 @@ package Interface::Socket::Server; use strict; use IO::Socket::UNIX; +use IO::Socket::INET; +use Errno qw(EADDRINUSE); use Base::Server; use base qw(Base::Server); use Settings; @@ -184,31 +186,54 @@ sub new { my ($class) = @_; my $socket_file = "$Settings::logs_folder/console.socket"; my $pid_file = "$Settings::logs_folder/openkore.pid"; - my $socket = new IO::Socket::UNIX( - Local => $socket_file, - Type => SOCK_STREAM, - Listen => 5 - ); - if (!$socket && $! == 98) { - $socket = new IO::Socket::UNIX( - Peer => $socket_file, - Type => SOCK_STREAM + my $tcp_host = $ENV{OPENKORE_SOCKET_TCP_HOST} || '127.0.0.1'; + my $tcp_port = $ENV{OPENKORE_SOCKET_TCP_PORT} || 0; + my $use_tcp = ($tcp_port =~ /^\d+$/ && $tcp_port > 0); + my ($socket, $endpoint_desc); + + if ($use_tcp) { + $socket = new IO::Socket::INET( + LocalAddr => $tcp_host, + LocalPort => $tcp_port, + Proto => 'tcp', + Type => SOCK_STREAM, + Listen => 5, + ReuseAddr => 1 ); if (!$socket) { - unlink($socket_file); + print STDERR "Cannot listen at '$tcp_host:$tcp_port': $!\n"; + exit 1; + } + $endpoint_desc = "$tcp_host:" . $socket->sockport; + print "Interface::Socket TCP endpoint listening at $endpoint_desc\n"; + } else { + $socket = new IO::Socket::UNIX( + Local => $socket_file, + Type => SOCK_STREAM, + Listen => 5 + ); + if (!$socket && $! == EADDRINUSE) { $socket = new IO::Socket::UNIX( - Local => $socket_file, - Type => SOCK_STREAM, - Listen => 5 + Peer => $socket_file, + Type => SOCK_STREAM ); - } else { - print STDERR "There is already an OpenKore instance listening at '$socket_file'.\n"; + if (!$socket) { + unlink($socket_file); + $socket = new IO::Socket::UNIX( + Local => $socket_file, + Type => SOCK_STREAM, + Listen => 5 + ); + } else { + print STDERR "There is already an OpenKore instance listening at '$socket_file'.\n"; + exit 1; + } + } + if (!$socket) { + print STDERR "Cannot listen at '$socket_file': $!\n"; exit 1; } - } - if (!$socket) { - print STDERR "Cannot listen at '$socket_file': $!\n"; - exit 1; + $endpoint_desc = $socket_file; } my $f; @@ -216,7 +241,7 @@ sub new { print $f $$; close($f); } else { - unlink $socket_file; + unlink $socket_file if !$use_tcp; print STDERR "Cannot write to PID file '$pid_file'.\n"; exit 1; } @@ -228,11 +253,13 @@ sub new { $self->{messages} = []; $self->{inputs} = []; $self->{socket_file} = $socket_file; + $self->{use_tcp} = $use_tcp; + $self->{endpoint_desc} = $endpoint_desc; $self->{pid_file} = $pid_file; $self->{waitingForInput} = 0; $SIG{INT} = $SIG{TERM} = $SIG{QUIT} = sub { - unlink $socket_file; + unlink $socket_file if !$use_tcp; unlink $pid_file; exit 2; }; @@ -242,7 +269,7 @@ sub new { sub DESTROY { my ($self) = @_; - unlink $self->{socket_file}; + unlink $self->{socket_file} if !$self->{use_tcp}; unlink $self->{pid_file}; $self->SUPER::DESTROY(); } @@ -362,4 +389,4 @@ sub onClientData { } } -1; \ No newline at end of file +1; diff --git a/tools/start-gateway.ps1 b/tools/start-gateway.ps1 index a78963bf15..ccedc497c3 100644 --- a/tools/start-gateway.ps1 +++ b/tools/start-gateway.ps1 @@ -57,6 +57,30 @@ function Ensure-Dir { } } +function Test-TcpEndpoint { + param( + [string]$Host, + [int]$Port, + [int]$TimeoutMs = 800 + ) + + $client = New-Object System.Net.Sockets.TcpClient + try { + $iar = $client.BeginConnect($Host, $Port, $null, $null) + if (-not $iar.AsyncWaitHandle.WaitOne($TimeoutMs, $false)) { + return $false + } + $client.EndConnect($iar) + return $true + } + catch { + return $false + } + finally { + try { $client.Close() } catch {} + } +} + $OpenKoreRoot = Resolve-OpenKoreRoot -UserPath $OpenKoreRoot $gatewayScript = Join-Path $OpenKoreRoot "tools\remote_gateway.pl" $configDir = Join-Path $OpenKoreRoot "config" @@ -106,6 +130,12 @@ if ($CommandToken -eq "CHANGE_ME") { Write-Warning "Você ainda está usando token padrão CHANGE_ME. Troque antes de produção." } +$koreEndpointReachable = Test-TcpEndpoint -Host $KoreHost -Port $KorePort +if (-not $koreEndpointReachable) { + Write-Warning "Não foi possível conectar em $KoreHost`:$KorePort antes de iniciar o gateway." + Write-Warning "Se o /health mostrar connected=false, inicie o OpenKore com endpoint compatível: `$env:OPENKORE_SOCKET_TCP_PORT=`"$KorePort`"` + `--interface=Socket`." +} + $existingPid = $null if (Test-Path -LiteralPath $pidFile) { $existingPid = (Get-Content -LiteralPath $pidFile -ErrorAction SilentlyContinue | Select-Object -First 1) @@ -160,4 +190,4 @@ try { } finally { Pop-Location -} \ No newline at end of file +} diff --git a/tools/start-openkore-socket-tcp.ps1 b/tools/start-openkore-socket-tcp.ps1 new file mode 100644 index 0000000000..095ed6ca5e --- /dev/null +++ b/tools/start-openkore-socket-tcp.ps1 @@ -0,0 +1,128 @@ +param( + [string]$OpenKoreRoot = "", + [string]$SocketHost = "127.0.0.1", + [int]$SocketPort = 2350, + [switch]$StartGateway = $true, + [string]$GatewayListenHost = "127.0.0.1", + [int]$GatewayListenPort = 18085, + [string]$CommandToken = "CHANGE_ME" +) + +$ErrorActionPreference = "Stop" + +function Resolve-OpenKoreRoot { + param([string]$UserPath) + + if ($UserPath -and $UserPath.Trim() -ne "") { + if (Test-Path -LiteralPath $UserPath) { + return (Resolve-Path -LiteralPath $UserPath).Path + } + throw "OpenKoreRoot inválido (não encontrado): $UserPath" + } + + $scriptPath = $PSCommandPath + if (-not $scriptPath) { $scriptPath = $MyInvocation.PSCommandPath } + if (-not $scriptPath) { $scriptPath = $MyInvocation.MyCommand.Path } + if (-not $scriptPath) { $scriptPath = (Join-Path (Get-Location).Path "tools\start-openkore-socket-tcp.ps1") } + $scriptDir = Split-Path -Parent $scriptPath + $candidates = @() + $candidates += $scriptDir + try { $candidates += (Resolve-Path (Join-Path $scriptDir "..")).Path } catch {} + try { $candidates += (Resolve-Path (Join-Path $scriptDir "..\..")).Path } catch {} + $candidates += (Get-Location).Path + + foreach ($cand in ($candidates | Select-Object -Unique)) { + if (Test-Path -LiteralPath (Join-Path $cand "openkore.pl")) { + return $cand + } + } + + throw "Não foi possível detectar a raiz do OpenKore automaticamente. Use -OpenKoreRoot `"C:\caminho\openkore`"." +} + +function Ensure-Dir { + param([string]$Path) + if (-not (Test-Path -LiteralPath $Path)) { + New-Item -ItemType Directory -Path $Path -Force | Out-Null + } +} + +function Wait-TcpOpen { + param( + [string]$Host, + [int]$Port, + [int]$TimeoutMs = 8000 + ) + + $start = Get-Date + while (((Get-Date) - $start).TotalMilliseconds -lt $TimeoutMs) { + $client = New-Object System.Net.Sockets.TcpClient + try { + $iar = $client.BeginConnect($Host, $Port, $null, $null) + if ($iar.AsyncWaitHandle.WaitOne(250, $false)) { + $client.EndConnect($iar) + return $true + } + } + catch {} + finally { + try { $client.Close() } catch {} + } + Start-Sleep -Milliseconds 200 + } + return $false +} + +if ($SocketPort -le 0 -or $SocketPort -gt 65535) { + throw "SocketPort inválida: $SocketPort" +} + +$OpenKoreRoot = Resolve-OpenKoreRoot -UserPath $OpenKoreRoot + +$logsDir = Join-Path $OpenKoreRoot "logs" +$dataDir = Join-Path $OpenKoreRoot "data" +$openkorePidFile = Join-Path $dataDir "openkore_socket_tcp.pid" +$openkoreOut = Join-Path $logsDir "openkore_socket_tcp_stdout.log" +$openkoreErr = Join-Path $logsDir "openkore_socket_tcp_stderr.log" +$gatewayScript = Join-Path $OpenKoreRoot "tools\start-gateway.ps1" + +Ensure-Dir -Path $logsDir +Ensure-Dir -Path $dataDir + +if (Test-Path -LiteralPath $openkorePidFile) { + $existingPid = (Get-Content -LiteralPath $openkorePidFile -ErrorAction SilentlyContinue | Select-Object -First 1) + if ($existingPid) { + $existingProc = Get-Process -Id $existingPid -ErrorAction SilentlyContinue + if ($existingProc) { + Write-Host "OpenKore já está em execução (PID=$existingPid)." + } + } +} + +Push-Location $OpenKoreRoot +try { + $env:OPENKORE_SOCKET_TCP_HOST = $SocketHost + $env:OPENKORE_SOCKET_TCP_PORT = "$SocketPort" + + $openkoreProc = Start-Process -FilePath "perl" -ArgumentList @(".\openkore.pl", "--interface=Socket") -WorkingDirectory $OpenKoreRoot -RedirectStandardOutput $openkoreOut -RedirectStandardError $openkoreErr -PassThru + Set-Content -LiteralPath $openkorePidFile -Value $openkoreProc.Id -Encoding ASCII + + if (Wait-TcpOpen -Host $SocketHost -Port $SocketPort -TimeoutMs 10000) { + Write-Host "OpenKore iniciado com endpoint TCP de console em $SocketHost`:$SocketPort (PID=$($openkoreProc.Id))." + } else { + Write-Warning "OpenKore iniciou (PID=$($openkoreProc.Id)), mas a porta $SocketHost`:$SocketPort não abriu a tempo." + Write-Warning "Confira logs: $openkoreOut e $openkoreErr" + } + + if ($StartGateway) { + if (-not (Test-Path -LiteralPath $gatewayScript)) { + throw "Script do gateway não encontrado: $gatewayScript" + } + & $gatewayScript -OpenKoreRoot $OpenKoreRoot -KoreHost $SocketHost -KorePort $SocketPort -ListenHost $GatewayListenHost -ListenPort $GatewayListenPort -CommandToken $CommandToken + } else { + Write-Host "Gateway não iniciado (-StartGateway:`$false)." + } +} +finally { + Pop-Location +} From c68d5f2f74f911bfe2aba9fdd6b8e620e29ba646 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Bosc=C3=A1?= Date: Wed, 15 Apr 2026 16:54:16 -0300 Subject: [PATCH 02/25] Support launcher exe and double-click startup for Windows remote stack --- docs/guia-acesso-remoto-pt-br.md | 1 + docs/guia-acesso-remoto-windows-nativo.md | 10 ++++- tools/start-openkore-socket-tcp.cmd | 9 +++++ tools/start-openkore-socket-tcp.ps1 | 45 ++++++++++++++++++++++- 4 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 tools/start-openkore-socket-tcp.cmd diff --git a/docs/guia-acesso-remoto-pt-br.md b/docs/guia-acesso-remoto-pt-br.md index 3b1984862d..42166b0772 100644 --- a/docs/guia-acesso-remoto-pt-br.md +++ b/docs/guia-acesso-remoto-pt-br.md @@ -24,6 +24,7 @@ Por quê: > Importante: para funcionar, o endpoint precisa falar o protocolo de console do OpenKore (`set active/input`). Nem toda porta TCP do OpenKore (ex.: `XKore_port`) é compatível com esse protocolo. > No Windows nativo, você pode expor endpoint compatível iniciando com `OPENKORE_SOCKET_TCP_PORT` e `--interface=Socket`. > Atalho no Windows: `tools/start-openkore-socket-tcp.ps1` sobe OpenKore + gateway com um comando. +> Se preferir duplo clique, use `tools/start-openkore-socket-tcp.cmd`. Isso significa: diff --git a/docs/guia-acesso-remoto-windows-nativo.md b/docs/guia-acesso-remoto-windows-nativo.md index 0d788a556d..d708a8eb0f 100644 --- a/docs/guia-acesso-remoto-windows-nativo.md +++ b/docs/guia-acesso-remoto-windows-nativo.md @@ -110,7 +110,7 @@ Em outras palavras: deixar apenas `XKore_port` configurado não abre automaticam ### Como abrir endpoint TCP compatível no Windows nativo -No mesmo PowerShell em que você vai rodar o OpenKore: +Se você iniciar pelo `openkore.pl`: ```powershell $env:OPENKORE_SOCKET_TCP_HOST = "127.0.0.1" @@ -120,6 +120,8 @@ perl .\openkore.pl --interface=Socket Esse comando inicia o OpenKore já com endpoint TCP compatível para o gateway. +Se você iniciar por executável (`start.exe`, `tkstart.exe`, etc.), use o helper script que detecta launcher automaticamente e aplica as variáveis para o processo criado. + ### Jeito curto (sem comandos longos): script pronto Você pode subir OpenKore + gateway com **um único comando**: @@ -133,6 +135,12 @@ Esse script: - habilita endpoint TCP compatível na `127.0.0.1:2350`; - inicia o gateway na `127.0.0.1:18085`. +Se preferir **duplo clique** (sem digitar nada), execute: + +```text +tools\start-openkore-socket-tcp.cmd +``` + Exemplo deste guia (somente se você tiver um endpoint TCP compatível já ativo): - host: `127.0.0.1` diff --git a/tools/start-openkore-socket-tcp.cmd b/tools/start-openkore-socket-tcp.cmd new file mode 100644 index 0000000000..7cece73e7b --- /dev/null +++ b/tools/start-openkore-socket-tcp.cmd @@ -0,0 +1,9 @@ +@echo off +setlocal +set "SCRIPT_DIR=%~dp0" +powershell -NoProfile -ExecutionPolicy Bypass -File "%SCRIPT_DIR%start-openkore-socket-tcp.ps1" %* +if errorlevel 1 ( + echo. + echo Falha ao iniciar stack remoto do OpenKore. + pause +) diff --git a/tools/start-openkore-socket-tcp.ps1 b/tools/start-openkore-socket-tcp.ps1 index 095ed6ca5e..e158b6e426 100644 --- a/tools/start-openkore-socket-tcp.ps1 +++ b/tools/start-openkore-socket-tcp.ps1 @@ -1,5 +1,6 @@ param( [string]$OpenKoreRoot = "", + [string]$LauncherPath = "", [string]$SocketHost = "127.0.0.1", [int]$SocketPort = 2350, [switch]$StartGateway = $true, @@ -73,6 +74,37 @@ function Wait-TcpOpen { return $false } +function Resolve-Launcher { + param( + [string]$Root, + [string]$UserLauncherPath + ) + + if ($UserLauncherPath -and $UserLauncherPath.Trim() -ne "") { + if (-not (Test-Path -LiteralPath $UserLauncherPath)) { + throw "LauncherPath não encontrado: $UserLauncherPath" + } + return (Resolve-Path -LiteralPath $UserLauncherPath).Path + } + + $candidates = @( + (Join-Path $Root "start.exe"), + (Join-Path $Root "wxstart.exe"), + (Join-Path $Root "winguistart.exe"), + (Join-Path $Root "tkstart.exe"), + (Join-Path $Root "vxstart.exe"), + (Join-Path $Root "openkore.pl") + ) + + foreach ($candidate in $candidates) { + if (Test-Path -LiteralPath $candidate) { + return (Resolve-Path -LiteralPath $candidate).Path + } + } + + throw "Nenhum launcher encontrado (start.exe/wxstart.exe/winguistart.exe/tkstart.exe/vxstart.exe/openkore.pl)." +} + if ($SocketPort -le 0 -or $SocketPort -gt 65535) { throw "SocketPort inválida: $SocketPort" } @@ -85,6 +117,7 @@ $openkorePidFile = Join-Path $dataDir "openkore_socket_tcp.pid" $openkoreOut = Join-Path $logsDir "openkore_socket_tcp_stdout.log" $openkoreErr = Join-Path $logsDir "openkore_socket_tcp_stderr.log" $gatewayScript = Join-Path $OpenKoreRoot "tools\start-gateway.ps1" +$launcher = Resolve-Launcher -Root $OpenKoreRoot -UserLauncherPath $LauncherPath Ensure-Dir -Path $logsDir Ensure-Dir -Path $dataDir @@ -103,12 +136,20 @@ Push-Location $OpenKoreRoot try { $env:OPENKORE_SOCKET_TCP_HOST = $SocketHost $env:OPENKORE_SOCKET_TCP_PORT = "$SocketPort" + $launcherName = [System.IO.Path]::GetFileName($launcher).ToLowerInvariant() + $openkoreArgs = @("--interface=Socket") + $openkoreFile = $launcher + + if ($launcherName -eq "openkore.pl") { + $openkoreFile = "perl" + $openkoreArgs = @(".\openkore.pl", "--interface=Socket") + } - $openkoreProc = Start-Process -FilePath "perl" -ArgumentList @(".\openkore.pl", "--interface=Socket") -WorkingDirectory $OpenKoreRoot -RedirectStandardOutput $openkoreOut -RedirectStandardError $openkoreErr -PassThru + $openkoreProc = Start-Process -FilePath $openkoreFile -ArgumentList $openkoreArgs -WorkingDirectory $OpenKoreRoot -RedirectStandardOutput $openkoreOut -RedirectStandardError $openkoreErr -PassThru Set-Content -LiteralPath $openkorePidFile -Value $openkoreProc.Id -Encoding ASCII if (Wait-TcpOpen -Host $SocketHost -Port $SocketPort -TimeoutMs 10000) { - Write-Host "OpenKore iniciado com endpoint TCP de console em $SocketHost`:$SocketPort (PID=$($openkoreProc.Id))." + Write-Host "OpenKore iniciado com '$launcherName' e endpoint TCP de console em $SocketHost`:$SocketPort (PID=$($openkoreProc.Id))." } else { Write-Warning "OpenKore iniciou (PID=$($openkoreProc.Id)), mas a porta $SocketHost`:$SocketPort não abriu a tempo." Write-Warning "Confira logs: $openkoreOut e $openkoreErr" From bbc2e4af8158f3ec94c67dd750c52684e98895e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Bosc=C3=A1?= Date: Wed, 15 Apr 2026 17:07:33 -0300 Subject: [PATCH 03/25] Clarify auto-detection behavior and existing OpenKore reuse in Windows helper --- docs/guia-acesso-remoto-pt-br.md | 1 + docs/guia-acesso-remoto-windows-nativo.md | 8 +++++ tools/start-openkore-socket-tcp.ps1 | 39 +++++++++++++++-------- 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/docs/guia-acesso-remoto-pt-br.md b/docs/guia-acesso-remoto-pt-br.md index 42166b0772..00dd936fc9 100644 --- a/docs/guia-acesso-remoto-pt-br.md +++ b/docs/guia-acesso-remoto-pt-br.md @@ -25,6 +25,7 @@ Por quê: > No Windows nativo, você pode expor endpoint compatível iniciando com `OPENKORE_SOCKET_TCP_PORT` e `--interface=Socket`. > Atalho no Windows: `tools/start-openkore-socket-tcp.ps1` sobe OpenKore + gateway com um comando. > Se preferir duplo clique, use `tools/start-openkore-socket-tcp.cmd`. +> A porta só existe enquanto o processo do OpenKore estiver rodando nesse modo. Isso significa: diff --git a/docs/guia-acesso-remoto-windows-nativo.md b/docs/guia-acesso-remoto-windows-nativo.md index d708a8eb0f..e8885bf5b6 100644 --- a/docs/guia-acesso-remoto-windows-nativo.md +++ b/docs/guia-acesso-remoto-windows-nativo.md @@ -141,6 +141,14 @@ Se preferir **duplo clique** (sem digitar nada), execute: tools\start-openkore-socket-tcp.cmd ``` +### Dúvida comum + +- **“Detecção automática” de quê?** + Do executável de inicialização (`start.exe`, `tkstart.exe`, etc.) dentro da pasta do OpenKore. +- **OpenKore precisa já estar aberto para a porta existir?** + Sim: a porta só abre quando o processo do OpenKore sobe com `--interface=Socket` + `OPENKORE_SOCKET_TCP_*`. + O script já faz isso para você. Se encontrar OpenKore já rodando, ele tenta reutilizar; se a porta não estiver ativa, avisa para reiniciar pelo script. + Exemplo deste guia (somente se você tiver um endpoint TCP compatível já ativo): - host: `127.0.0.1` diff --git a/tools/start-openkore-socket-tcp.ps1 b/tools/start-openkore-socket-tcp.ps1 index e158b6e426..e85ebe3bb2 100644 --- a/tools/start-openkore-socket-tcp.ps1 +++ b/tools/start-openkore-socket-tcp.ps1 @@ -118,6 +118,7 @@ $openkoreOut = Join-Path $logsDir "openkore_socket_tcp_stdout.log" $openkoreErr = Join-Path $logsDir "openkore_socket_tcp_stderr.log" $gatewayScript = Join-Path $OpenKoreRoot "tools\start-gateway.ps1" $launcher = Resolve-Launcher -Root $OpenKoreRoot -UserLauncherPath $LauncherPath +$alreadyRunning = $false Ensure-Dir -Path $logsDir Ensure-Dir -Path $dataDir @@ -128,6 +129,7 @@ if (Test-Path -LiteralPath $openkorePidFile) { $existingProc = Get-Process -Id $existingPid -ErrorAction SilentlyContinue if ($existingProc) { Write-Host "OpenKore já está em execução (PID=$existingPid)." + $alreadyRunning = $true } } } @@ -136,23 +138,32 @@ Push-Location $OpenKoreRoot try { $env:OPENKORE_SOCKET_TCP_HOST = $SocketHost $env:OPENKORE_SOCKET_TCP_PORT = "$SocketPort" - $launcherName = [System.IO.Path]::GetFileName($launcher).ToLowerInvariant() - $openkoreArgs = @("--interface=Socket") - $openkoreFile = $launcher - - if ($launcherName -eq "openkore.pl") { - $openkoreFile = "perl" - $openkoreArgs = @(".\openkore.pl", "--interface=Socket") - } + if (-not $alreadyRunning) { + $launcherName = [System.IO.Path]::GetFileName($launcher).ToLowerInvariant() + $openkoreArgs = @("--interface=Socket") + $openkoreFile = $launcher + + if ($launcherName -eq "openkore.pl") { + $openkoreFile = "perl" + $openkoreArgs = @(".\openkore.pl", "--interface=Socket") + } - $openkoreProc = Start-Process -FilePath $openkoreFile -ArgumentList $openkoreArgs -WorkingDirectory $OpenKoreRoot -RedirectStandardOutput $openkoreOut -RedirectStandardError $openkoreErr -PassThru - Set-Content -LiteralPath $openkorePidFile -Value $openkoreProc.Id -Encoding ASCII + $openkoreProc = Start-Process -FilePath $openkoreFile -ArgumentList $openkoreArgs -WorkingDirectory $OpenKoreRoot -RedirectStandardOutput $openkoreOut -RedirectStandardError $openkoreErr -PassThru + Set-Content -LiteralPath $openkorePidFile -Value $openkoreProc.Id -Encoding ASCII - if (Wait-TcpOpen -Host $SocketHost -Port $SocketPort -TimeoutMs 10000) { - Write-Host "OpenKore iniciado com '$launcherName' e endpoint TCP de console em $SocketHost`:$SocketPort (PID=$($openkoreProc.Id))." + if (Wait-TcpOpen -Host $SocketHost -Port $SocketPort -TimeoutMs 10000) { + Write-Host "OpenKore iniciado com '$launcherName' e endpoint TCP de console em $SocketHost`:$SocketPort (PID=$($openkoreProc.Id))." + } else { + Write-Warning "OpenKore iniciou (PID=$($openkoreProc.Id)), mas a porta $SocketHost`:$SocketPort não abriu a tempo." + Write-Warning "Confira logs: $openkoreOut e $openkoreErr" + } } else { - Write-Warning "OpenKore iniciou (PID=$($openkoreProc.Id)), mas a porta $SocketHost`:$SocketPort não abriu a tempo." - Write-Warning "Confira logs: $openkoreOut e $openkoreErr" + if (Wait-TcpOpen -Host $SocketHost -Port $SocketPort -TimeoutMs 2000) { + Write-Host "Endpoint TCP já estava ativo em $SocketHost`:$SocketPort. Reutilizando instância existente." + } else { + Write-Warning "OpenKore já estava aberto, mas a porta $SocketHost`:$SocketPort não está ativa." + Write-Warning "Feche e inicie pelo script para aplicar OPENKORE_SOCKET_TCP_* e --interface=Socket." + } } if ($StartGateway) { From d53b4b442e1ce11081b5799a8652401fecd9a311 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Bosc=C3=A1?= Date: Wed, 15 Apr 2026 17:12:47 -0300 Subject: [PATCH 04/25] Make Windows helper configure-only by default and document launcher usage --- docs/guia-acesso-remoto-pt-br.md | 3 +- docs/guia-acesso-remoto-windows-nativo.md | 27 ++++++++++++---- tools/start-openkore-socket-tcp.ps1 | 39 +++++++++++++++++++++-- 3 files changed, 60 insertions(+), 9 deletions(-) diff --git a/docs/guia-acesso-remoto-pt-br.md b/docs/guia-acesso-remoto-pt-br.md index 00dd936fc9..0072441824 100644 --- a/docs/guia-acesso-remoto-pt-br.md +++ b/docs/guia-acesso-remoto-pt-br.md @@ -23,9 +23,10 @@ Por quê: > Importante: para funcionar, o endpoint precisa falar o protocolo de console do OpenKore (`set active/input`). Nem toda porta TCP do OpenKore (ex.: `XKore_port`) é compatível com esse protocolo. > No Windows nativo, você pode expor endpoint compatível iniciando com `OPENKORE_SOCKET_TCP_PORT` e `--interface=Socket`. -> Atalho no Windows: `tools/start-openkore-socket-tcp.ps1` sobe OpenKore + gateway com um comando. +> Atalho no Windows: `tools/start-openkore-socket-tcp.ps1` prepara o ambiente TCP do socket de console com um comando. > Se preferir duplo clique, use `tools/start-openkore-socket-tcp.cmd`. > A porta só existe enquanto o processo do OpenKore estiver rodando nesse modo. +> O helper PS1 agora, por padrão, só prepara o arquivo `tools/openkore-socket-env.cmd`; iniciar OpenKore/gateway é opcional. Isso significa: diff --git a/docs/guia-acesso-remoto-windows-nativo.md b/docs/guia-acesso-remoto-windows-nativo.md index e8885bf5b6..73b3c23503 100644 --- a/docs/guia-acesso-remoto-windows-nativo.md +++ b/docs/guia-acesso-remoto-windows-nativo.md @@ -124,16 +124,28 @@ Se você iniciar por executável (`start.exe`, `tkstart.exe`, etc.), use o helpe ### Jeito curto (sem comandos longos): script pronto -Você pode subir OpenKore + gateway com **um único comando**: +Você pode só preparar o ambiente (sem iniciar nada automaticamente): ```powershell -powershell -NoProfile -ExecutionPolicy Bypass -File .\tools\start-openkore-socket-tcp.ps1 -CommandToken "UM_TOKEN_LONGO_E_ALEATORIO" +powershell -NoProfile -ExecutionPolicy Bypass -File .\tools\start-openkore-socket-tcp.ps1 ``` Esse script: -- inicia OpenKore com `--interface=Socket`; -- habilita endpoint TCP compatível na `127.0.0.1:2350`; -- inicia o gateway na `127.0.0.1:18085`. +- grava `tools\openkore-socket-env.cmd` com `OPENKORE_SOCKET_TCP_HOST/PORT`; +- **não** inicia OpenKore nem gateway por padrão; +- deixa você escolher como iniciar (`start.exe`, `tkstart.exe`, etc). + +Depois, inicie do jeito que quiser: + +```text +tools\openkore-socket-env.cmd start.exe --interface=Socket +``` + +Se quiser que o PS1 inicie OpenKore (opcional): + +```powershell +powershell -NoProfile -ExecutionPolicy Bypass -File .\tools\start-openkore-socket-tcp.ps1 -LaunchOpenKore +``` Se preferir **duplo clique** (sem digitar nada), execute: @@ -147,7 +159,10 @@ tools\start-openkore-socket-tcp.cmd Do executável de inicialização (`start.exe`, `tkstart.exe`, etc.) dentro da pasta do OpenKore. - **OpenKore precisa já estar aberto para a porta existir?** Sim: a porta só abre quando o processo do OpenKore sobe com `--interface=Socket` + `OPENKORE_SOCKET_TCP_*`. - O script já faz isso para você. Se encontrar OpenKore já rodando, ele tenta reutilizar; se a porta não estiver ativa, avisa para reiniciar pelo script. + O script prepara o ambiente; você escolhe como abrir o OpenKore. Opcionalmente ele também pode iniciar OpenKore com `-LaunchOpenKore`. + +- **Erro `XSTools.dll is not found` ao usar `perl .\openkore.pl` no Windows** + Use os launchers compilados (`start.exe`, `tkstart.exe`, `wxstart.exe`, etc.) em vez do `perl openkore.pl` puro no Windows. Exemplo deste guia (somente se você tiver um endpoint TCP compatível já ativo): diff --git a/tools/start-openkore-socket-tcp.ps1 b/tools/start-openkore-socket-tcp.ps1 index e85ebe3bb2..895395d6d8 100644 --- a/tools/start-openkore-socket-tcp.ps1 +++ b/tools/start-openkore-socket-tcp.ps1 @@ -3,7 +3,8 @@ param( [string]$LauncherPath = "", [string]$SocketHost = "127.0.0.1", [int]$SocketPort = 2350, - [switch]$StartGateway = $true, + [switch]$LaunchOpenKore = $false, + [switch]$StartGateway = $false, [string]$GatewayListenHost = "127.0.0.1", [int]$GatewayListenPort = 18085, [string]$CommandToken = "CHANGE_ME" @@ -105,6 +106,27 @@ function Resolve-Launcher { throw "Nenhum launcher encontrado (start.exe/wxstart.exe/winguistart.exe/tkstart.exe/vxstart.exe/openkore.pl)." } +function Write-EnvLauncherCmd { + param( + [string]$Root, + [string]$Host, + [int]$Port + ) + + $cmdPath = Join-Path $Root "tools\openkore-socket-env.cmd" + @( + "@echo off", + "setlocal", + "set `"OPENKORE_SOCKET_TCP_HOST=$Host`"", + "set `"OPENKORE_SOCKET_TCP_PORT=$Port`"", + "if `"%~1`"==`"`" goto :done", + "%*", + ":done" + ) | Set-Content -LiteralPath $cmdPath -Encoding ASCII + + return $cmdPath +} + if ($SocketPort -le 0 -or $SocketPort -gt 65535) { throw "SocketPort inválida: $SocketPort" } @@ -117,12 +139,15 @@ $openkorePidFile = Join-Path $dataDir "openkore_socket_tcp.pid" $openkoreOut = Join-Path $logsDir "openkore_socket_tcp_stdout.log" $openkoreErr = Join-Path $logsDir "openkore_socket_tcp_stderr.log" $gatewayScript = Join-Path $OpenKoreRoot "tools\start-gateway.ps1" -$launcher = Resolve-Launcher -Root $OpenKoreRoot -UserLauncherPath $LauncherPath $alreadyRunning = $false Ensure-Dir -Path $logsDir Ensure-Dir -Path $dataDir +$envCmdPath = Write-EnvLauncherCmd -Root $OpenKoreRoot -Host $SocketHost -Port $SocketPort +Write-Host "Arquivo atualizado: $envCmdPath" +Write-Host "Use assim: tools\\openkore-socket-env.cmd start.exe --interface=Socket" + if (Test-Path -LiteralPath $openkorePidFile) { $existingPid = (Get-Content -LiteralPath $openkorePidFile -ErrorAction SilentlyContinue | Select-Object -First 1) if ($existingPid) { @@ -134,6 +159,16 @@ if (Test-Path -LiteralPath $openkorePidFile) { } } +if (-not $LaunchOpenKore) { + if ($StartGateway) { + Write-Warning "-StartGateway foi ignorado porque -LaunchOpenKore não foi usado." + } + Write-Host "Configuração pronta. O script não iniciou OpenKore automaticamente." + return +} + +$launcher = Resolve-Launcher -Root $OpenKoreRoot -UserLauncherPath $LauncherPath + Push-Location $OpenKoreRoot try { $env:OPENKORE_SOCKET_TCP_HOST = $SocketHost From 760347182de254ca2c42101daf14e00aa3dad55f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Bosc=C3=A1?= Date: Wed, 15 Apr 2026 17:19:57 -0300 Subject: [PATCH 05/25] Fix PowerShell automatic variable collisions in TCP checks --- tools/start-gateway.ps1 | 6 +++--- tools/start-openkore-socket-tcp.ps1 | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/start-gateway.ps1 b/tools/start-gateway.ps1 index ccedc497c3..ba77f29769 100644 --- a/tools/start-gateway.ps1 +++ b/tools/start-gateway.ps1 @@ -59,14 +59,14 @@ function Ensure-Dir { function Test-TcpEndpoint { param( - [string]$Host, + [string]$TargetHost, [int]$Port, [int]$TimeoutMs = 800 ) $client = New-Object System.Net.Sockets.TcpClient try { - $iar = $client.BeginConnect($Host, $Port, $null, $null) + $iar = $client.BeginConnect($TargetHost, $Port, $null, $null) if (-not $iar.AsyncWaitHandle.WaitOne($TimeoutMs, $false)) { return $false } @@ -130,7 +130,7 @@ if ($CommandToken -eq "CHANGE_ME") { Write-Warning "Você ainda está usando token padrão CHANGE_ME. Troque antes de produção." } -$koreEndpointReachable = Test-TcpEndpoint -Host $KoreHost -Port $KorePort +$koreEndpointReachable = Test-TcpEndpoint -TargetHost $KoreHost -Port $KorePort if (-not $koreEndpointReachable) { Write-Warning "Não foi possível conectar em $KoreHost`:$KorePort antes de iniciar o gateway." Write-Warning "Se o /health mostrar connected=false, inicie o OpenKore com endpoint compatível: `$env:OPENKORE_SOCKET_TCP_PORT=`"$KorePort`"` + `--interface=Socket`." diff --git a/tools/start-openkore-socket-tcp.ps1 b/tools/start-openkore-socket-tcp.ps1 index 895395d6d8..d75bc006f1 100644 --- a/tools/start-openkore-socket-tcp.ps1 +++ b/tools/start-openkore-socket-tcp.ps1 @@ -51,7 +51,7 @@ function Ensure-Dir { function Wait-TcpOpen { param( - [string]$Host, + [string]$TargetHost, [int]$Port, [int]$TimeoutMs = 8000 ) @@ -60,7 +60,7 @@ function Wait-TcpOpen { while (((Get-Date) - $start).TotalMilliseconds -lt $TimeoutMs) { $client = New-Object System.Net.Sockets.TcpClient try { - $iar = $client.BeginConnect($Host, $Port, $null, $null) + $iar = $client.BeginConnect($TargetHost, $Port, $null, $null) if ($iar.AsyncWaitHandle.WaitOne(250, $false)) { $client.EndConnect($iar) return $true @@ -186,14 +186,14 @@ try { $openkoreProc = Start-Process -FilePath $openkoreFile -ArgumentList $openkoreArgs -WorkingDirectory $OpenKoreRoot -RedirectStandardOutput $openkoreOut -RedirectStandardError $openkoreErr -PassThru Set-Content -LiteralPath $openkorePidFile -Value $openkoreProc.Id -Encoding ASCII - if (Wait-TcpOpen -Host $SocketHost -Port $SocketPort -TimeoutMs 10000) { + if (Wait-TcpOpen -TargetHost $SocketHost -Port $SocketPort -TimeoutMs 10000) { Write-Host "OpenKore iniciado com '$launcherName' e endpoint TCP de console em $SocketHost`:$SocketPort (PID=$($openkoreProc.Id))." } else { Write-Warning "OpenKore iniciou (PID=$($openkoreProc.Id)), mas a porta $SocketHost`:$SocketPort não abriu a tempo." Write-Warning "Confira logs: $openkoreOut e $openkoreErr" } } else { - if (Wait-TcpOpen -Host $SocketHost -Port $SocketPort -TimeoutMs 2000) { + if (Wait-TcpOpen -TargetHost $SocketHost -Port $SocketPort -TimeoutMs 2000) { Write-Host "Endpoint TCP já estava ativo em $SocketHost`:$SocketPort. Reutilizando instância existente." } else { Write-Warning "OpenKore já estava aberto, mas a porta $SocketHost`:$SocketPort não está ativa." From de6521673ddc61a15ae22bcd8bdc0c1f17ee9d9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Bosc=C3=A1?= Date: Wed, 15 Apr 2026 17:25:49 -0300 Subject: [PATCH 06/25] Fix remaining PowerShell Host automatic variable collision --- tools/start-openkore-socket-tcp.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/start-openkore-socket-tcp.ps1 b/tools/start-openkore-socket-tcp.ps1 index d75bc006f1..a0f4b11977 100644 --- a/tools/start-openkore-socket-tcp.ps1 +++ b/tools/start-openkore-socket-tcp.ps1 @@ -109,7 +109,7 @@ function Resolve-Launcher { function Write-EnvLauncherCmd { param( [string]$Root, - [string]$Host, + [string]$TargetHost, [int]$Port ) @@ -117,7 +117,7 @@ function Write-EnvLauncherCmd { @( "@echo off", "setlocal", - "set `"OPENKORE_SOCKET_TCP_HOST=$Host`"", + "set `"OPENKORE_SOCKET_TCP_HOST=$TargetHost`"", "set `"OPENKORE_SOCKET_TCP_PORT=$Port`"", "if `"%~1`"==`"`" goto :done", "%*", @@ -144,7 +144,7 @@ $alreadyRunning = $false Ensure-Dir -Path $logsDir Ensure-Dir -Path $dataDir -$envCmdPath = Write-EnvLauncherCmd -Root $OpenKoreRoot -Host $SocketHost -Port $SocketPort +$envCmdPath = Write-EnvLauncherCmd -Root $OpenKoreRoot -TargetHost $SocketHost -Port $SocketPort Write-Host "Arquivo atualizado: $envCmdPath" Write-Host "Use assim: tools\\openkore-socket-env.cmd start.exe --interface=Socket" From f233e5058ab87132f322641b7638417f7d0cebb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Bosc=C3=A1?= Date: Wed, 15 Apr 2026 17:53:18 -0300 Subject: [PATCH 07/25] Use platform console loader in Socket interface to avoid Utils::Unix failure on Windows --- src/Interface/Socket.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Interface/Socket.pm b/src/Interface/Socket.pm index 354d846816..6684aee215 100644 --- a/src/Interface/Socket.pm +++ b/src/Interface/Socket.pm @@ -56,7 +56,7 @@ use Interface; use Translation; use base qw(Interface); use Utils qw(timeOut); -use Interface::Console::Simple; +use Interface::Console; use constant MAX_LOG_ENTRIES => 5000; @@ -66,7 +66,7 @@ sub new { my (%self, $f); $self{server} = new Interface::Socket::Server(); - $self{console} = new Interface::Console::Simple(); + $self{console} = new Interface::Console(); open($f, ">:utf8", "$Settings::logs_folder/console.log"); $self{consoleLogFile} = $f; $self{logEntryCount} = 0; From dba46ce80244562334b999078dda5df6022ea910 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Bosc=C3=A1?= Date: Wed, 15 Apr 2026 18:03:33 -0300 Subject: [PATCH 08/25] Launch OpenKore in a new window from generated env helper --- docs/guia-acesso-remoto-windows-nativo.md | 2 ++ tools/start-openkore-socket-tcp.ps1 | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/guia-acesso-remoto-windows-nativo.md b/docs/guia-acesso-remoto-windows-nativo.md index 73b3c23503..e5875f1895 100644 --- a/docs/guia-acesso-remoto-windows-nativo.md +++ b/docs/guia-acesso-remoto-windows-nativo.md @@ -141,6 +141,8 @@ Depois, inicie do jeito que quiser: tools\openkore-socket-env.cmd start.exe --interface=Socket ``` +Esse launcher abre o OpenKore em nova janela (não “preso” ao PowerShell atual). + Se quiser que o PS1 inicie OpenKore (opcional): ```powershell diff --git a/tools/start-openkore-socket-tcp.ps1 b/tools/start-openkore-socket-tcp.ps1 index a0f4b11977..ff9735f266 100644 --- a/tools/start-openkore-socket-tcp.ps1 +++ b/tools/start-openkore-socket-tcp.ps1 @@ -120,7 +120,7 @@ function Write-EnvLauncherCmd { "set `"OPENKORE_SOCKET_TCP_HOST=$TargetHost`"", "set `"OPENKORE_SOCKET_TCP_PORT=$Port`"", "if `"%~1`"==`"`" goto :done", - "%*", + "start `"`" %*", ":done" ) | Set-Content -LiteralPath $cmdPath -Encoding ASCII @@ -146,7 +146,7 @@ Ensure-Dir -Path $dataDir $envCmdPath = Write-EnvLauncherCmd -Root $OpenKoreRoot -TargetHost $SocketHost -Port $SocketPort Write-Host "Arquivo atualizado: $envCmdPath" -Write-Host "Use assim: tools\\openkore-socket-env.cmd start.exe --interface=Socket" +Write-Host "Use assim: tools\\openkore-socket-env.cmd start.exe --interface=Socket (abre em nova janela)" if (Test-Path -LiteralPath $openkorePidFile) { $existingPid = (Get-Content -LiteralPath $openkorePidFile -ErrorAction SilentlyContinue | Select-Object -First 1) From 5497c8bdc2316842fd853ab5545a8d3c0019b0f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Bosc=C3=A1?= Date: Wed, 15 Apr 2026 18:08:59 -0300 Subject: [PATCH 09/25] Open TCP env launcher in interactive cmd window for local typing --- docs/guia-acesso-remoto-windows-nativo.md | 2 +- tools/start-openkore-socket-tcp.ps1 | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/guia-acesso-remoto-windows-nativo.md b/docs/guia-acesso-remoto-windows-nativo.md index e5875f1895..636ce22a9c 100644 --- a/docs/guia-acesso-remoto-windows-nativo.md +++ b/docs/guia-acesso-remoto-windows-nativo.md @@ -141,7 +141,7 @@ Depois, inicie do jeito que quiser: tools\openkore-socket-env.cmd start.exe --interface=Socket ``` -Esse launcher abre o OpenKore em nova janela (não “preso” ao PowerShell atual). +Esse launcher abre o OpenKore em nova janela **interativa** (não “preso” ao PowerShell atual), mantendo digitação no console. Se quiser que o PS1 inicie OpenKore (opcional): diff --git a/tools/start-openkore-socket-tcp.ps1 b/tools/start-openkore-socket-tcp.ps1 index ff9735f266..e490bd1da5 100644 --- a/tools/start-openkore-socket-tcp.ps1 +++ b/tools/start-openkore-socket-tcp.ps1 @@ -120,7 +120,7 @@ function Write-EnvLauncherCmd { "set `"OPENKORE_SOCKET_TCP_HOST=$TargetHost`"", "set `"OPENKORE_SOCKET_TCP_PORT=$Port`"", "if `"%~1`"==`"`" goto :done", - "start `"`" %*", + "start `"`" cmd /k %*", ":done" ) | Set-Content -LiteralPath $cmdPath -Encoding ASCII @@ -146,7 +146,7 @@ Ensure-Dir -Path $dataDir $envCmdPath = Write-EnvLauncherCmd -Root $OpenKoreRoot -TargetHost $SocketHost -Port $SocketPort Write-Host "Arquivo atualizado: $envCmdPath" -Write-Host "Use assim: tools\\openkore-socket-env.cmd start.exe --interface=Socket (abre em nova janela)" +Write-Host "Use assim: tools\\openkore-socket-env.cmd start.exe --interface=Socket (abre em nova janela interativa)" if (Test-Path -LiteralPath $openkorePidFile) { $existingPid = (Get-Content -LiteralPath $openkorePidFile -ErrorAction SilentlyContinue | Select-Object -First 1) From b487f5f022579b01b001ffb76f6f6a4c95c8134f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Bosc=C3=A1?= Date: Wed, 15 Apr 2026 18:37:48 -0300 Subject: [PATCH 10/25] Use Console::Simple safely on Windows for Socket interface input loop --- src/Interface/Console/Simple.pm | 15 +++++++++------ src/Interface/Socket.pm | 4 ++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Interface/Console/Simple.pm b/src/Interface/Console/Simple.pm index 07330b2d02..2ecf53a573 100644 --- a/src/Interface/Console/Simple.pm +++ b/src/Interface/Console/Simple.pm @@ -31,7 +31,7 @@ use Globals qw(%consoleColors); use Interface; use base qw(Interface); use I18N qw(UTF8ToString); -use Utils::Unix; +use if $^O ne 'MSWin32', 'Utils::Unix'; sub new { my $class = shift; @@ -41,7 +41,7 @@ sub new { } sub DESTROY { - print STDOUT Utils::Unix::getColor('default'); + print STDOUT Utils::Unix::getColor('default') if $^O ne 'MSWin32'; STDOUT->flush; } @@ -79,10 +79,13 @@ sub getInput { sub writeOutput { my ($self, $type, $message, $domain) = @_; - my ($code, $reset) = ( - Utils::Unix::getColorForMessage(\%consoleColors, $type, $domain), - Utils::Unix::getColor('reset'), - ); + my ($code, $reset) = ('', ''); + if ($^O ne 'MSWin32') { + ($code, $reset) = ( + Utils::Unix::getColorForMessage(\%consoleColors, $type, $domain), + Utils::Unix::getColor('reset'), + ); + } $message =~ s/\n/$reset\n$code/sg; $message = $code.$message.$reset; diff --git a/src/Interface/Socket.pm b/src/Interface/Socket.pm index 6684aee215..354d846816 100644 --- a/src/Interface/Socket.pm +++ b/src/Interface/Socket.pm @@ -56,7 +56,7 @@ use Interface; use Translation; use base qw(Interface); use Utils qw(timeOut); -use Interface::Console; +use Interface::Console::Simple; use constant MAX_LOG_ENTRIES => 5000; @@ -66,7 +66,7 @@ sub new { my (%self, $f); $self{server} = new Interface::Socket::Server(); - $self{console} = new Interface::Console(); + $self{console} = new Interface::Console::Simple(); open($f, ">:utf8", "$Settings::logs_folder/console.log"); $self{consoleLogFile} = $f; $self{logEntryCount} = 0; From 6d6eb003f68dd608e30dd93491d35968c02e4af9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Bosc=C3=A1?= Date: Wed, 15 Apr 2026 18:37:52 -0300 Subject: [PATCH 11/25] Add one-shot Windows launcher to start OpenKore socket endpoint and gateway --- docs/guia-acesso-remoto-pt-br.md | 1 + docs/guia-acesso-remoto-windows-nativo.md | 13 ++++++++ tools/run-remote.cmd | 39 +++++++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 tools/run-remote.cmd diff --git a/docs/guia-acesso-remoto-pt-br.md b/docs/guia-acesso-remoto-pt-br.md index 0072441824..313be09beb 100644 --- a/docs/guia-acesso-remoto-pt-br.md +++ b/docs/guia-acesso-remoto-pt-br.md @@ -27,6 +27,7 @@ Por quê: > Se preferir duplo clique, use `tools/start-openkore-socket-tcp.cmd`. > A porta só existe enquanto o processo do OpenKore estiver rodando nesse modo. > O helper PS1 agora, por padrão, só prepara o arquivo `tools/openkore-socket-env.cmd`; iniciar OpenKore/gateway é opcional. +> Se quiser zero fricção, use `tools/run-remote.cmd SEU_TOKEN` (one-shot para abrir OpenKore + gateway). Isso significa: diff --git a/docs/guia-acesso-remoto-windows-nativo.md b/docs/guia-acesso-remoto-windows-nativo.md index 636ce22a9c..affc9977d4 100644 --- a/docs/guia-acesso-remoto-windows-nativo.md +++ b/docs/guia-acesso-remoto-windows-nativo.md @@ -191,6 +191,19 @@ perl .\tools\remote_gateway.pl --kore-host 127.0.0.1 --kore-port 2350 --listen-h > Se quiser manter nativo no Windows, prefira abrir o endpoint com `OPENKORE_SOCKET_TCP_PORT` + `--interface=Socket` (bloco acima). +### Modo ultra simples (recomendado) + +Sem digitar vários comandos: execute **um arquivo**: + +```text +tools\run-remote.cmd UM_TOKEN_LONGO_E_ALEATORIO +``` + +Esse `.cmd`: +- abre OpenKore (launcher detectado automaticamente) com `--interface=Socket`; +- configura `OPENKORE_SOCKET_TCP_HOST=127.0.0.1` e `OPENKORE_SOCKET_TCP_PORT=2350`; +- inicia o gateway em `127.0.0.1:18085`. + --- ## 7) Testar pelo Windows (browser + PowerShell) diff --git a/tools/run-remote.cmd b/tools/run-remote.cmd new file mode 100644 index 0000000000..b9ebb34651 --- /dev/null +++ b/tools/run-remote.cmd @@ -0,0 +1,39 @@ +@echo off +setlocal + +REM One-shot launcher: opens OpenKore console TCP endpoint + starts gateway. +REM Usage: +REM tools\run-remote.cmd YOUR_LONG_RANDOM_TOKEN + +cd /d "%~dp0.." +set "ROOT=%CD%" + +set "OPENKORE_SOCKET_TCP_HOST=127.0.0.1" +set "OPENKORE_SOCKET_TCP_PORT=2350" + +set "COMMAND_TOKEN=%~1" +if "%COMMAND_TOKEN%"=="" set "COMMAND_TOKEN=CHANGE_ME" + +set "LAUNCHER=" +if exist "%ROOT%\start.exe" set "LAUNCHER=%ROOT%\start.exe" +if "%LAUNCHER%"=="" if exist "%ROOT%\tkstart.exe" set "LAUNCHER=%ROOT%\tkstart.exe" +if "%LAUNCHER%"=="" if exist "%ROOT%\wxstart.exe" set "LAUNCHER=%ROOT%\wxstart.exe" +if "%LAUNCHER%"=="" if exist "%ROOT%\winguistart.exe" set "LAUNCHER=%ROOT%\winguistart.exe" +if "%LAUNCHER%"=="" if exist "%ROOT%\vxstart.exe" set "LAUNCHER=%ROOT%\vxstart.exe" + +if "%LAUNCHER%"=="" ( + echo [ERRO] Nenhum launcher encontrado (start.exe/tkstart.exe/wxstart.exe/winguistart.exe/vxstart.exe). + exit /b 1 +) + +echo [1/3] Iniciando OpenKore com interface Socket em nova janela... +start "OpenKore Socket" "%LAUNCHER%" --interface=Socket + +echo [2/3] Aguardando 3s... +timeout /t 3 /nobreak >nul + +echo [3/3] Iniciando gateway... +powershell -NoProfile -ExecutionPolicy Bypass -File "%ROOT%\tools\start-gateway.ps1" -OpenKoreRoot "%ROOT%" -KoreHost "127.0.0.1" -KorePort 2350 -ListenHost "127.0.0.1" -ListenPort 18085 -CommandToken "%COMMAND_TOKEN%" + +echo. +echo Pronto. Abra: http://127.0.0.1:18085/ From 090b88f1041e06842f4cb2fd27e4a484c9f198f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Bosc=C3=A1?= Date: Wed, 15 Apr 2026 18:46:11 -0300 Subject: [PATCH 12/25] Make run-remote.cmd fully standalone and mark as primary simple flow --- docs/guia-acesso-remoto-pt-br.md | 1 + docs/guia-acesso-remoto-windows-nativo.md | 4 +++- tools/run-remote.cmd | 11 ++++++++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/docs/guia-acesso-remoto-pt-br.md b/docs/guia-acesso-remoto-pt-br.md index 313be09beb..11beafc4ad 100644 --- a/docs/guia-acesso-remoto-pt-br.md +++ b/docs/guia-acesso-remoto-pt-br.md @@ -28,6 +28,7 @@ Por quê: > A porta só existe enquanto o processo do OpenKore estiver rodando nesse modo. > O helper PS1 agora, por padrão, só prepara o arquivo `tools/openkore-socket-env.cmd`; iniciar OpenKore/gateway é opcional. > Se quiser zero fricção, use `tools/run-remote.cmd SEU_TOKEN` (one-shot para abrir OpenKore + gateway). +> Para fluxo simples, use só `run-remote.cmd` e ignore os scripts auxiliares. Isso significa: diff --git a/docs/guia-acesso-remoto-windows-nativo.md b/docs/guia-acesso-remoto-windows-nativo.md index affc9977d4..424bd9175a 100644 --- a/docs/guia-acesso-remoto-windows-nativo.md +++ b/docs/guia-acesso-remoto-windows-nativo.md @@ -202,7 +202,9 @@ tools\run-remote.cmd UM_TOKEN_LONGO_E_ALEATORIO Esse `.cmd`: - abre OpenKore (launcher detectado automaticamente) com `--interface=Socket`; - configura `OPENKORE_SOCKET_TCP_HOST=127.0.0.1` e `OPENKORE_SOCKET_TCP_PORT=2350`; -- inicia o gateway em `127.0.0.1:18085`. +- inicia o gateway em `127.0.0.1:18085` **sem depender** de `start-gateway.ps1`. + +> Se seu objetivo é simplicidade, use somente `tools\run-remote.cmd` e ignore os outros scripts auxiliares. --- diff --git a/tools/run-remote.cmd b/tools/run-remote.cmd index b9ebb34651..14c45384fd 100644 --- a/tools/run-remote.cmd +++ b/tools/run-remote.cmd @@ -14,6 +14,15 @@ set "OPENKORE_SOCKET_TCP_PORT=2350" set "COMMAND_TOKEN=%~1" if "%COMMAND_TOKEN%"=="" set "COMMAND_TOKEN=CHANGE_ME" +if not exist "%ROOT%\logs" mkdir "%ROOT%\logs" >nul 2>&1 +if not exist "%ROOT%\data" mkdir "%ROOT%\data" >nul 2>&1 +if not exist "%ROOT%\config" mkdir "%ROOT%\config" >nul 2>&1 +if not exist "%ROOT%\config\gateway-users.json" ( + if exist "%ROOT%\tools\gateway-users.example.json" ( + copy /Y "%ROOT%\tools\gateway-users.example.json" "%ROOT%\config\gateway-users.json" >nul + ) +) + set "LAUNCHER=" if exist "%ROOT%\start.exe" set "LAUNCHER=%ROOT%\start.exe" if "%LAUNCHER%"=="" if exist "%ROOT%\tkstart.exe" set "LAUNCHER=%ROOT%\tkstart.exe" @@ -33,7 +42,7 @@ echo [2/3] Aguardando 3s... timeout /t 3 /nobreak >nul echo [3/3] Iniciando gateway... -powershell -NoProfile -ExecutionPolicy Bypass -File "%ROOT%\tools\start-gateway.ps1" -OpenKoreRoot "%ROOT%" -KoreHost "127.0.0.1" -KorePort 2350 -ListenHost "127.0.0.1" -ListenPort 18085 -CommandToken "%COMMAND_TOKEN%" +start "OpenKore Remote Gateway" perl "%ROOT%\tools\remote_gateway.pl" --kore-host 127.0.0.1 --kore-port 2350 --listen-host 127.0.0.1 --listen-port 18085 --command-token "%COMMAND_TOKEN%" --audit-file "%ROOT%\logs\gateway_audit.jsonl" --command-rate-limit 30 --command-rate-window 60 --auth-enabled --users-file "%ROOT%\config\gateway-users.json" --token-ttl 900 --session-file "%ROOT%\data\gateway_sessions.json" echo. echo Pronto. Abra: http://127.0.0.1:18085/ From ff3df63c5dd67919ed8f206f048798a579bd2d2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Bosc=C3=A1?= Date: Wed, 15 Apr 2026 19:14:32 -0300 Subject: [PATCH 13/25] Rewrite run-remote.cmd with robust batch conditionals to avoid parser errors --- tools/run-remote.cmd | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/tools/run-remote.cmd b/tools/run-remote.cmd index 14c45384fd..12216791a6 100644 --- a/tools/run-remote.cmd +++ b/tools/run-remote.cmd @@ -1,22 +1,22 @@ @echo off -setlocal +setlocal ENABLEEXTENSIONS -REM One-shot launcher: opens OpenKore console TCP endpoint + starts gateway. +REM One-shot launcher: OpenKore Socket TCP + Remote Gateway (Windows). REM Usage: REM tools\run-remote.cmd YOUR_LONG_RANDOM_TOKEN cd /d "%~dp0.." set "ROOT=%CD%" +set "COMMAND_TOKEN=%~1" +if "%COMMAND_TOKEN%"=="" set "COMMAND_TOKEN=CHANGE_ME" set "OPENKORE_SOCKET_TCP_HOST=127.0.0.1" set "OPENKORE_SOCKET_TCP_PORT=2350" -set "COMMAND_TOKEN=%~1" -if "%COMMAND_TOKEN%"=="" set "COMMAND_TOKEN=CHANGE_ME" - if not exist "%ROOT%\logs" mkdir "%ROOT%\logs" >nul 2>&1 if not exist "%ROOT%\data" mkdir "%ROOT%\data" >nul 2>&1 if not exist "%ROOT%\config" mkdir "%ROOT%\config" >nul 2>&1 + if not exist "%ROOT%\config\gateway-users.json" ( if exist "%ROOT%\tools\gateway-users.example.json" ( copy /Y "%ROOT%\tools\gateway-users.example.json" "%ROOT%\config\gateway-users.json" >nul @@ -25,15 +25,12 @@ if not exist "%ROOT%\config\gateway-users.json" ( set "LAUNCHER=" if exist "%ROOT%\start.exe" set "LAUNCHER=%ROOT%\start.exe" -if "%LAUNCHER%"=="" if exist "%ROOT%\tkstart.exe" set "LAUNCHER=%ROOT%\tkstart.exe" -if "%LAUNCHER%"=="" if exist "%ROOT%\wxstart.exe" set "LAUNCHER=%ROOT%\wxstart.exe" -if "%LAUNCHER%"=="" if exist "%ROOT%\winguistart.exe" set "LAUNCHER=%ROOT%\winguistart.exe" -if "%LAUNCHER%"=="" if exist "%ROOT%\vxstart.exe" set "LAUNCHER=%ROOT%\vxstart.exe" - -if "%LAUNCHER%"=="" ( - echo [ERRO] Nenhum launcher encontrado (start.exe/tkstart.exe/wxstart.exe/winguistart.exe/vxstart.exe). - exit /b 1 -) +if not defined LAUNCHER if exist "%ROOT%\tkstart.exe" set "LAUNCHER=%ROOT%\tkstart.exe" +if not defined LAUNCHER if exist "%ROOT%\wxstart.exe" set "LAUNCHER=%ROOT%\wxstart.exe" +if not defined LAUNCHER if exist "%ROOT%\winguistart.exe" set "LAUNCHER=%ROOT%\winguistart.exe" +if not defined LAUNCHER if exist "%ROOT%\vxstart.exe" set "LAUNCHER=%ROOT%\vxstart.exe" + +if not defined LAUNCHER goto :launcher_missing echo [1/3] Iniciando OpenKore com interface Socket em nova janela... start "OpenKore Socket" "%LAUNCHER%" --interface=Socket @@ -41,8 +38,14 @@ start "OpenKore Socket" "%LAUNCHER%" --interface=Socket echo [2/3] Aguardando 3s... timeout /t 3 /nobreak >nul -echo [3/3] Iniciando gateway... +echo [3/3] Iniciando gateway em nova janela... start "OpenKore Remote Gateway" perl "%ROOT%\tools\remote_gateway.pl" --kore-host 127.0.0.1 --kore-port 2350 --listen-host 127.0.0.1 --listen-port 18085 --command-token "%COMMAND_TOKEN%" --audit-file "%ROOT%\logs\gateway_audit.jsonl" --command-rate-limit 30 --command-rate-window 60 --auth-enabled --users-file "%ROOT%\config\gateway-users.json" --token-ttl 900 --session-file "%ROOT%\data\gateway_sessions.json" echo. echo Pronto. Abra: http://127.0.0.1:18085/ +exit /b 0 + +:launcher_missing +echo [ERRO] Nenhum launcher encontrado. +echo Esperado: start.exe, tkstart.exe, wxstart.exe, winguistart.exe ou vxstart.exe na raiz. +exit /b 1 From 58e3154db10fc4a0a9ce0a28b7c55ec91b42bd93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Bosc=C3=A1?= Date: Wed, 15 Apr 2026 19:19:53 -0300 Subject: [PATCH 14/25] Remove dependency on if.pm for Windows compatibility in Console::Simple --- src/Interface/Console/Simple.pm | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Interface/Console/Simple.pm b/src/Interface/Console/Simple.pm index 2ecf53a573..92e36c88b6 100644 --- a/src/Interface/Console/Simple.pm +++ b/src/Interface/Console/Simple.pm @@ -31,7 +31,13 @@ use Globals qw(%consoleColors); use Interface; use base qw(Interface); use I18N qw(UTF8ToString); -use if $^O ne 'MSWin32', 'Utils::Unix'; + +BEGIN { + if ($^O ne 'MSWin32') { + require Utils::Unix; + Utils::Unix->import(); + } +} sub new { my $class = shift; From 81f6eb7251a15e066d42b98c73a90d1c87451364 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Bosc=C3=A1?= Date: Wed, 15 Apr 2026 19:23:33 -0300 Subject: [PATCH 15/25] Use platform console backend in Socket interface to restore Windows input handling --- src/Interface/Socket.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Interface/Socket.pm b/src/Interface/Socket.pm index 354d846816..6684aee215 100644 --- a/src/Interface/Socket.pm +++ b/src/Interface/Socket.pm @@ -56,7 +56,7 @@ use Interface; use Translation; use base qw(Interface); use Utils qw(timeOut); -use Interface::Console::Simple; +use Interface::Console; use constant MAX_LOG_ENTRIES => 5000; @@ -66,7 +66,7 @@ sub new { my (%self, $f); $self{server} = new Interface::Socket::Server(); - $self{console} = new Interface::Console::Simple(); + $self{console} = new Interface::Console(); open($f, ">:utf8", "$Settings::logs_folder/console.log"); $self{consoleLogFile} = $f; $self{logEntryCount} = 0; From 7ce94ee975ddd8c74213c4f7c7ad0ba9a390b2af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Bosc=C3=A1?= Date: Wed, 15 Apr 2026 19:30:01 -0300 Subject: [PATCH 16/25] Launch OpenKore via cmd /k in run-remote to preserve interactive typing --- docs/guia-acesso-remoto-windows-nativo.md | 1 + tools/run-remote.cmd | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/guia-acesso-remoto-windows-nativo.md b/docs/guia-acesso-remoto-windows-nativo.md index 424bd9175a..e9f799c18b 100644 --- a/docs/guia-acesso-remoto-windows-nativo.md +++ b/docs/guia-acesso-remoto-windows-nativo.md @@ -203,6 +203,7 @@ Esse `.cmd`: - abre OpenKore (launcher detectado automaticamente) com `--interface=Socket`; - configura `OPENKORE_SOCKET_TCP_HOST=127.0.0.1` e `OPENKORE_SOCKET_TCP_PORT=2350`; - inicia o gateway em `127.0.0.1:18085` **sem depender** de `start-gateway.ps1`. +- o OpenKore é aberto via `cmd /k` para manter console interativo para digitação local. > Se seu objetivo é simplicidade, use somente `tools\run-remote.cmd` e ignore os outros scripts auxiliares. diff --git a/tools/run-remote.cmd b/tools/run-remote.cmd index 12216791a6..dfafeff825 100644 --- a/tools/run-remote.cmd +++ b/tools/run-remote.cmd @@ -33,7 +33,7 @@ if not defined LAUNCHER if exist "%ROOT%\vxstart.exe" set "LAUNCHER=%ROOT%\vxsta if not defined LAUNCHER goto :launcher_missing echo [1/3] Iniciando OpenKore com interface Socket em nova janela... -start "OpenKore Socket" "%LAUNCHER%" --interface=Socket +start "OpenKore Socket" cmd /k ""%LAUNCHER%" --interface=Socket" echo [2/3] Aguardando 3s... timeout /t 3 /nobreak >nul From 883f775656387e819a835bbd8f25409e84d69bc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Bosc=C3=A1?= Date: Thu, 16 Apr 2026 16:35:42 -0300 Subject: [PATCH 17/25] Launch OpenKore with normal launcher flow in run-remote --- docs/guia-acesso-remoto-windows-nativo.md | 2 +- tools/run-remote.cmd | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/guia-acesso-remoto-windows-nativo.md b/docs/guia-acesso-remoto-windows-nativo.md index e9f799c18b..e79ac01da1 100644 --- a/docs/guia-acesso-remoto-windows-nativo.md +++ b/docs/guia-acesso-remoto-windows-nativo.md @@ -203,7 +203,7 @@ Esse `.cmd`: - abre OpenKore (launcher detectado automaticamente) com `--interface=Socket`; - configura `OPENKORE_SOCKET_TCP_HOST=127.0.0.1` e `OPENKORE_SOCKET_TCP_PORT=2350`; - inicia o gateway em `127.0.0.1:18085` **sem depender** de `start-gateway.ps1`. -- o OpenKore é aberto via `cmd /k` para manter console interativo para digitação local. +- o OpenKore é aberto pelo launcher normal (`start.exe`/`tkstart.exe`/etc), como no fluxo de duplo clique. > Se seu objetivo é simplicidade, use somente `tools\run-remote.cmd` e ignore os outros scripts auxiliares. diff --git a/tools/run-remote.cmd b/tools/run-remote.cmd index dfafeff825..361328a59f 100644 --- a/tools/run-remote.cmd +++ b/tools/run-remote.cmd @@ -32,8 +32,8 @@ if not defined LAUNCHER if exist "%ROOT%\vxstart.exe" set "LAUNCHER=%ROOT%\vxsta if not defined LAUNCHER goto :launcher_missing -echo [1/3] Iniciando OpenKore com interface Socket em nova janela... -start "OpenKore Socket" cmd /k ""%LAUNCHER%" --interface=Socket" +echo [1/3] Iniciando OpenKore com interface Socket (launcher normal)... +start "OpenKore Socket" "%LAUNCHER%" --interface=Socket echo [2/3] Aguardando 3s... timeout /t 3 /nobreak >nul From 9b8dee401b19f891605b5729b49fff0b36c01c4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Bosc=C3=A1?= Date: Thu, 16 Apr 2026 16:58:19 -0300 Subject: [PATCH 18/25] Simplify PT-BR docs to single run-remote.cmd flow --- docs/guia-acesso-remoto-pt-br.md | 9 +-- docs/guia-acesso-remoto-windows-nativo.md | 77 ++++------------------- 2 files changed, 13 insertions(+), 73 deletions(-) diff --git a/docs/guia-acesso-remoto-pt-br.md b/docs/guia-acesso-remoto-pt-br.md index 11beafc4ad..757d72ef1c 100644 --- a/docs/guia-acesso-remoto-pt-br.md +++ b/docs/guia-acesso-remoto-pt-br.md @@ -22,13 +22,8 @@ Por quê: - O fluxo padrão do projeto usa caminhos Unix (`/etc/...`) e serviço `systemd`. > Importante: para funcionar, o endpoint precisa falar o protocolo de console do OpenKore (`set active/input`). Nem toda porta TCP do OpenKore (ex.: `XKore_port`) é compatível com esse protocolo. -> No Windows nativo, você pode expor endpoint compatível iniciando com `OPENKORE_SOCKET_TCP_PORT` e `--interface=Socket`. -> Atalho no Windows: `tools/start-openkore-socket-tcp.ps1` prepara o ambiente TCP do socket de console com um comando. -> Se preferir duplo clique, use `tools/start-openkore-socket-tcp.cmd`. -> A porta só existe enquanto o processo do OpenKore estiver rodando nesse modo. -> O helper PS1 agora, por padrão, só prepara o arquivo `tools/openkore-socket-env.cmd`; iniciar OpenKore/gateway é opcional. -> Se quiser zero fricção, use `tools/run-remote.cmd SEU_TOKEN` (one-shot para abrir OpenKore + gateway). -> Para fluxo simples, use só `run-remote.cmd` e ignore os scripts auxiliares. +> No Windows nativo, para fluxo simples, use só `tools/run-remote.cmd SEU_TOKEN`. +> Esse comando único abre OpenKore + gateway e expõe o endpoint TCP compatível. Isso significa: diff --git a/docs/guia-acesso-remoto-windows-nativo.md b/docs/guia-acesso-remoto-windows-nativo.md index e79ac01da1..2e4c35b202 100644 --- a/docs/guia-acesso-remoto-windows-nativo.md +++ b/docs/guia-acesso-remoto-windows-nativo.md @@ -108,70 +108,20 @@ Em outras palavras: deixar apenas `XKore_port` configurado não abre automaticam ⚠️ **Importante:** no OpenKore padrão, `XKore_port` (ex.: `2350`) **não é automaticamente** o endpoint de console remoto esperado pelo `remote_gateway.pl` (`set active/input`). -### Como abrir endpoint TCP compatível no Windows nativo +### Fluxo único (simples, recomendado) -Se você iniciar pelo `openkore.pl`: - -```powershell -$env:OPENKORE_SOCKET_TCP_HOST = "127.0.0.1" -$env:OPENKORE_SOCKET_TCP_PORT = "2350" -perl .\openkore.pl --interface=Socket -``` - -Esse comando inicia o OpenKore já com endpoint TCP compatível para o gateway. - -Se você iniciar por executável (`start.exe`, `tkstart.exe`, etc.), use o helper script que detecta launcher automaticamente e aplica as variáveis para o processo criado. - -### Jeito curto (sem comandos longos): script pronto - -Você pode só preparar o ambiente (sem iniciar nada automaticamente): - -```powershell -powershell -NoProfile -ExecutionPolicy Bypass -File .\tools\start-openkore-socket-tcp.ps1 -``` - -Esse script: -- grava `tools\openkore-socket-env.cmd` com `OPENKORE_SOCKET_TCP_HOST/PORT`; -- **não** inicia OpenKore nem gateway por padrão; -- deixa você escolher como iniciar (`start.exe`, `tkstart.exe`, etc). - -Depois, inicie do jeito que quiser: - -```text -tools\openkore-socket-env.cmd start.exe --interface=Socket -``` - -Esse launcher abre o OpenKore em nova janela **interativa** (não “preso” ao PowerShell atual), mantendo digitação no console. - -Se quiser que o PS1 inicie OpenKore (opcional): - -```powershell -powershell -NoProfile -ExecutionPolicy Bypass -File .\tools\start-openkore-socket-tcp.ps1 -LaunchOpenKore -``` - -Se preferir **duplo clique** (sem digitar nada), execute: +Use **só** este arquivo: ```text -tools\start-openkore-socket-tcp.cmd +tools\run-remote.cmd UM_TOKEN_LONGO_E_ALEATORIO ``` -### Dúvida comum - -- **“Detecção automática” de quê?** - Do executável de inicialização (`start.exe`, `tkstart.exe`, etc.) dentro da pasta do OpenKore. -- **OpenKore precisa já estar aberto para a porta existir?** - Sim: a porta só abre quando o processo do OpenKore sobe com `--interface=Socket` + `OPENKORE_SOCKET_TCP_*`. - O script prepara o ambiente; você escolhe como abrir o OpenKore. Opcionalmente ele também pode iniciar OpenKore com `-LaunchOpenKore`. - -- **Erro `XSTools.dll is not found` ao usar `perl .\openkore.pl` no Windows** - Use os launchers compilados (`start.exe`, `tkstart.exe`, `wxstart.exe`, etc.) em vez do `perl openkore.pl` puro no Windows. - -Exemplo deste guia (somente se você tiver um endpoint TCP compatível já ativo): +Ele já: +- abre OpenKore com `--interface=Socket` usando launcher normal (`start.exe`, `tkstart.exe`, etc.); +- configura endpoint TCP de console em `127.0.0.1:2350`; +- inicia o gateway em `127.0.0.1:18085`. -- host: `127.0.0.1` -- porta: `2350` - -Valide antes de subir o gateway: +Valide: ```powershell Test-NetConnection 127.0.0.1 -Port 2350 @@ -251,21 +201,16 @@ Se seu Windows não aceita SSH inbound, use VPN/Tailscale/ZeroTier e exponha ape ## 9) Inicialização automática no Windows -Use o script pronto: `scripts/start-gateway.ps1`. - -Ele detecta automaticamente a raiz do OpenKore quando executado de dentro do repositório. -Também existe atalho em `tools/start-gateway.ps1`. - -Exemplo manual (PowerShell): +Para manter simples, agende **um comando só**: ```powershell -powershell -NoProfile -ExecutionPolicy Bypass -File .\scripts\start-gateway.ps1 -KoreHost "127.0.0.1" -KorePort 2350 -ListenHost "127.0.0.1" -ListenPort 18085 -CommandToken "UM_TOKEN_LONGO_E_ALEATORIO" +powershell -NoProfile -ExecutionPolicy Bypass -Command "& { cd 'C:\openkore'; .\tools\run-remote.cmd UM_TOKEN_LONGO_E_ALEATORIO }" ``` Depois crie uma tarefa no **Task Scheduler** chamando: ```powershell -powershell -NoProfile -ExecutionPolicy Bypass -File C:\openkore\scripts\start-gateway.ps1 +powershell -NoProfile -ExecutionPolicy Bypass -Command "& { cd 'C:\openkore'; .\tools\run-remote.cmd UM_TOKEN_LONGO_E_ALEATORIO }" ``` --- From 07df042b91d36925ac58451a4ebcabc5bf133495 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Bosc=C3=A1?= Date: Thu, 16 Apr 2026 16:58:43 -0300 Subject: [PATCH 19/25] Remove launcher auto-detection from run-remote and require explicit user choice --- docs/guia-acesso-remoto-pt-br.md | 2 +- docs/guia-acesso-remoto-windows-nativo.md | 4 ++-- tools/run-remote.cmd | 21 ++++++++++----------- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/docs/guia-acesso-remoto-pt-br.md b/docs/guia-acesso-remoto-pt-br.md index 757d72ef1c..f903c9bdf3 100644 --- a/docs/guia-acesso-remoto-pt-br.md +++ b/docs/guia-acesso-remoto-pt-br.md @@ -22,7 +22,7 @@ Por quê: - O fluxo padrão do projeto usa caminhos Unix (`/etc/...`) e serviço `systemd`. > Importante: para funcionar, o endpoint precisa falar o protocolo de console do OpenKore (`set active/input`). Nem toda porta TCP do OpenKore (ex.: `XKore_port`) é compatível com esse protocolo. -> No Windows nativo, para fluxo simples, use só `tools/run-remote.cmd SEU_TOKEN`. +> No Windows nativo, para fluxo simples, use só `tools/run-remote.cmd SEU_TOKEN start.exe` (ou `tkstart.exe`, etc.). > Esse comando único abre OpenKore + gateway e expõe o endpoint TCP compatível. Isso significa: diff --git a/docs/guia-acesso-remoto-windows-nativo.md b/docs/guia-acesso-remoto-windows-nativo.md index 2e4c35b202..72dba0dee3 100644 --- a/docs/guia-acesso-remoto-windows-nativo.md +++ b/docs/guia-acesso-remoto-windows-nativo.md @@ -113,11 +113,11 @@ Em outras palavras: deixar apenas `XKore_port` configurado não abre automaticam Use **só** este arquivo: ```text -tools\run-remote.cmd UM_TOKEN_LONGO_E_ALEATORIO +tools\run-remote.cmd UM_TOKEN_LONGO_E_ALEATORIO start.exe ``` Ele já: -- abre OpenKore com `--interface=Socket` usando launcher normal (`start.exe`, `tkstart.exe`, etc.); +- abre OpenKore com `--interface=Socket` usando o launcher que **você** informar (`start.exe`, `tkstart.exe`, etc.); - configura endpoint TCP de console em `127.0.0.1:2350`; - inicia o gateway em `127.0.0.1:18085`. diff --git a/tools/run-remote.cmd b/tools/run-remote.cmd index 361328a59f..3cbaef184a 100644 --- a/tools/run-remote.cmd +++ b/tools/run-remote.cmd @@ -3,12 +3,15 @@ setlocal ENABLEEXTENSIONS REM One-shot launcher: OpenKore Socket TCP + Remote Gateway (Windows). REM Usage: -REM tools\run-remote.cmd YOUR_LONG_RANDOM_TOKEN +REM tools\run-remote.cmd YOUR_LONG_RANDOM_TOKEN start.exe +REM If launcher is omitted, defaults to start.exe. cd /d "%~dp0.." set "ROOT=%CD%" set "COMMAND_TOKEN=%~1" if "%COMMAND_TOKEN%"=="" set "COMMAND_TOKEN=CHANGE_ME" +set "LAUNCHER_NAME=%~2" +if "%LAUNCHER_NAME%"=="" set "LAUNCHER_NAME=start.exe" set "OPENKORE_SOCKET_TCP_HOST=127.0.0.1" set "OPENKORE_SOCKET_TCP_PORT=2350" @@ -23,14 +26,8 @@ if not exist "%ROOT%\config\gateway-users.json" ( ) ) -set "LAUNCHER=" -if exist "%ROOT%\start.exe" set "LAUNCHER=%ROOT%\start.exe" -if not defined LAUNCHER if exist "%ROOT%\tkstart.exe" set "LAUNCHER=%ROOT%\tkstart.exe" -if not defined LAUNCHER if exist "%ROOT%\wxstart.exe" set "LAUNCHER=%ROOT%\wxstart.exe" -if not defined LAUNCHER if exist "%ROOT%\winguistart.exe" set "LAUNCHER=%ROOT%\winguistart.exe" -if not defined LAUNCHER if exist "%ROOT%\vxstart.exe" set "LAUNCHER=%ROOT%\vxstart.exe" - -if not defined LAUNCHER goto :launcher_missing +set "LAUNCHER=%ROOT%\%LAUNCHER_NAME%" +if not exist "%LAUNCHER%" goto :launcher_missing echo [1/3] Iniciando OpenKore com interface Socket (launcher normal)... start "OpenKore Socket" "%LAUNCHER%" --interface=Socket @@ -46,6 +43,8 @@ echo Pronto. Abra: http://127.0.0.1:18085/ exit /b 0 :launcher_missing -echo [ERRO] Nenhum launcher encontrado. -echo Esperado: start.exe, tkstart.exe, wxstart.exe, winguistart.exe ou vxstart.exe na raiz. +echo [ERRO] Launcher nao encontrado: %LAUNCHER_NAME% +echo Informe explicitamente no comando, por exemplo: +echo tools\run-remote.cmd SEU_TOKEN start.exe +echo tools\run-remote.cmd SEU_TOKEN tkstart.exe exit /b 1 From 979394fbae62c571cc7af5227b5e2bc4db450cbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Bosc=C3=A1?= Date: Thu, 16 Apr 2026 17:44:30 -0300 Subject: [PATCH 20/25] Fix Windows console input by reading from CONIN$ --- src/Interface/Console/Simple.pm | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Interface/Console/Simple.pm b/src/Interface/Console/Simple.pm index 92e36c88b6..c922cf1f99 100644 --- a/src/Interface/Console/Simple.pm +++ b/src/Interface/Console/Simple.pm @@ -43,7 +43,13 @@ sub new { my $class = shift; binmode STDOUT; STDOUT->autoflush(0); - return bless {}, $class; + my $self = bless {}, $class; + if ($^O eq 'MSWin32') { + if (open(my $conin, '<', 'CONIN$')) { + $self->{conin} = $conin; + } + } + return $self; } sub DESTROY { @@ -55,23 +61,26 @@ sub getInput { my ($self, $timeout) = @_; my $line; my $bits; + my $in = $self->{conin} || \*STDIN; + my $fd = fileno($in); + return undef if !defined $fd; if ($timeout < 0) { my $done; while (!$done) { $bits = ''; - vec($bits, fileno(STDIN), 1) = 1; + vec($bits, $fd, 1) = 1; if (select($bits, undef, undef, 1) > 0) { - $line = ; + $line = <$in>; $done = 1; } } } else { $bits = ''; - vec($bits, fileno(STDIN), 1) = 1; + vec($bits, $fd, 1) = 1; if (select($bits, undef, undef, $timeout) > 0) { - $line = ; + $line = <$in>; } } From bcad671805685de7e0ee5745a12b596db171d74f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Bosc=C3=A1?= Date: Thu, 16 Apr 2026 17:44:54 -0300 Subject: [PATCH 21/25] Fix run-remote.cmd to open separate Windows consoles --- docs/guia-acesso-remoto-windows-nativo.md | 4 ++-- tools/run-remote.cmd | 13 ++++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/docs/guia-acesso-remoto-windows-nativo.md b/docs/guia-acesso-remoto-windows-nativo.md index 72dba0dee3..d5c2ffb27d 100644 --- a/docs/guia-acesso-remoto-windows-nativo.md +++ b/docs/guia-acesso-remoto-windows-nativo.md @@ -117,9 +117,9 @@ tools\run-remote.cmd UM_TOKEN_LONGO_E_ALEATORIO start.exe ``` Ele já: -- abre OpenKore com `--interface=Socket` usando o launcher que **você** informar (`start.exe`, `tkstart.exe`, etc.); +- abre **uma janela separada** para OpenKore com `--interface=Socket` usando o launcher que **você** informar (`start.exe`, `tkstart.exe`, etc.); - configura endpoint TCP de console em `127.0.0.1:2350`; -- inicia o gateway em `127.0.0.1:18085`. +- abre **outra janela separada** para o gateway em `127.0.0.1:18085`. Valide: diff --git a/tools/run-remote.cmd b/tools/run-remote.cmd index 3cbaef184a..18d4609c42 100644 --- a/tools/run-remote.cmd +++ b/tools/run-remote.cmd @@ -29,17 +29,20 @@ if not exist "%ROOT%\config\gateway-users.json" ( set "LAUNCHER=%ROOT%\%LAUNCHER_NAME%" if not exist "%LAUNCHER%" goto :launcher_missing -echo [1/3] Iniciando OpenKore com interface Socket (launcher normal)... -start "OpenKore Socket" "%LAUNCHER%" --interface=Socket +echo [1/3] Abrindo OpenKore em janela separada (interface do launcher)... +start "OpenKore Socket" cmd /k "cd /d \"%ROOT%\" && set OPENKORE_SOCKET_TCP_HOST=%OPENKORE_SOCKET_TCP_HOST% && set OPENKORE_SOCKET_TCP_PORT=%OPENKORE_SOCKET_TCP_PORT% && \"%LAUNCHER%\" --interface=Socket" echo [2/3] Aguardando 3s... timeout /t 3 /nobreak >nul -echo [3/3] Iniciando gateway em nova janela... -start "OpenKore Remote Gateway" perl "%ROOT%\tools\remote_gateway.pl" --kore-host 127.0.0.1 --kore-port 2350 --listen-host 127.0.0.1 --listen-port 18085 --command-token "%COMMAND_TOKEN%" --audit-file "%ROOT%\logs\gateway_audit.jsonl" --command-rate-limit 30 --command-rate-window 60 --auth-enabled --users-file "%ROOT%\config\gateway-users.json" --token-ttl 900 --session-file "%ROOT%\data\gateway_sessions.json" +echo [3/3] Abrindo gateway em outra janela separada... +start "OpenKore Remote Gateway" cmd /k "cd /d \"%ROOT%\" && perl \"%ROOT%\tools\remote_gateway.pl\" --kore-host 127.0.0.1 --kore-port 2350 --listen-host 127.0.0.1 --listen-port 18085 --command-token \"%COMMAND_TOKEN%\" --audit-file \"%ROOT%\logs\gateway_audit.jsonl\" --command-rate-limit 30 --command-rate-window 60 --auth-enabled --users-file \"%ROOT%\config\gateway-users.json\" --token-ttl 900 --session-file \"%ROOT%\data\gateway_sessions.json\"" echo. -echo Pronto. Abra: http://127.0.0.1:18085/ +echo Pronto. Janelas abertas separadamente: +echo - OpenKore (launcher/interface) +echo - Remote Gateway +echo UI Web: http://127.0.0.1:18085/ exit /b 0 :launcher_missing From 37e776ff5d9aad8c69624a2f16119423e7a1df73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Bosc=C3=A1?= Date: Thu, 16 Apr 2026 17:56:55 -0300 Subject: [PATCH 22/25] Fix run-remote.cmd Windows quoting for start/cmd invocations --- tools/run-remote.cmd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/run-remote.cmd b/tools/run-remote.cmd index 18d4609c42..23bd4e1909 100644 --- a/tools/run-remote.cmd +++ b/tools/run-remote.cmd @@ -30,13 +30,13 @@ set "LAUNCHER=%ROOT%\%LAUNCHER_NAME%" if not exist "%LAUNCHER%" goto :launcher_missing echo [1/3] Abrindo OpenKore em janela separada (interface do launcher)... -start "OpenKore Socket" cmd /k "cd /d \"%ROOT%\" && set OPENKORE_SOCKET_TCP_HOST=%OPENKORE_SOCKET_TCP_HOST% && set OPENKORE_SOCKET_TCP_PORT=%OPENKORE_SOCKET_TCP_PORT% && \"%LAUNCHER%\" --interface=Socket" +start "OpenKore Socket" cmd /k "cd /d ""%ROOT%"" && set OPENKORE_SOCKET_TCP_HOST=%OPENKORE_SOCKET_TCP_HOST% && set OPENKORE_SOCKET_TCP_PORT=%OPENKORE_SOCKET_TCP_PORT% && ""%LAUNCHER%"" --interface=Socket" echo [2/3] Aguardando 3s... timeout /t 3 /nobreak >nul echo [3/3] Abrindo gateway em outra janela separada... -start "OpenKore Remote Gateway" cmd /k "cd /d \"%ROOT%\" && perl \"%ROOT%\tools\remote_gateway.pl\" --kore-host 127.0.0.1 --kore-port 2350 --listen-host 127.0.0.1 --listen-port 18085 --command-token \"%COMMAND_TOKEN%\" --audit-file \"%ROOT%\logs\gateway_audit.jsonl\" --command-rate-limit 30 --command-rate-window 60 --auth-enabled --users-file \"%ROOT%\config\gateway-users.json\" --token-ttl 900 --session-file \"%ROOT%\data\gateway_sessions.json\"" +start "OpenKore Remote Gateway" cmd /k "cd /d ""%ROOT%"" && perl ""%ROOT%\tools\remote_gateway.pl"" --kore-host 127.0.0.1 --kore-port 2350 --listen-host 127.0.0.1 --listen-port 18085 --command-token ""%COMMAND_TOKEN%"" --audit-file ""%ROOT%\logs\gateway_audit.jsonl"" --command-rate-limit 30 --command-rate-window 60 --auth-enabled --users-file ""%ROOT%\config\gateway-users.json"" --token-ttl 900 --session-file ""%ROOT%\data\gateway_sessions.json""" echo. echo Pronto. Janelas abertas separadamente: From 983adb59d9bd598334249c808a0b93c04111b12d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Bosc=C3=A1?= Date: Thu, 16 Apr 2026 18:17:07 -0300 Subject: [PATCH 23/25] Default Windows Socket interface to TCP endpoint --- docs/guia-acesso-remoto-windows-nativo.md | 2 ++ src/Interface/Socket.pm | 11 +++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/docs/guia-acesso-remoto-windows-nativo.md b/docs/guia-acesso-remoto-windows-nativo.md index d5c2ffb27d..96f7b2cb71 100644 --- a/docs/guia-acesso-remoto-windows-nativo.md +++ b/docs/guia-acesso-remoto-windows-nativo.md @@ -110,6 +110,8 @@ Em outras palavras: deixar apenas `XKore_port` configurado não abre automaticam ### Fluxo único (simples, recomendado) +> No Windows, ao usar `--interface=Socket`, o OpenKore agora usa TCP por padrão em `127.0.0.1:2350` se `OPENKORE_SOCKET_TCP_PORT` não estiver definido. + Use **só** este arquivo: ```text diff --git a/src/Interface/Socket.pm b/src/Interface/Socket.pm index 6684aee215..4ea7c4e3ac 100644 --- a/src/Interface/Socket.pm +++ b/src/Interface/Socket.pm @@ -187,7 +187,9 @@ sub new { my $socket_file = "$Settings::logs_folder/console.socket"; my $pid_file = "$Settings::logs_folder/openkore.pid"; my $tcp_host = $ENV{OPENKORE_SOCKET_TCP_HOST} || '127.0.0.1'; - my $tcp_port = $ENV{OPENKORE_SOCKET_TCP_PORT} || 0; + my $tcp_port = defined $ENV{OPENKORE_SOCKET_TCP_PORT} + ? $ENV{OPENKORE_SOCKET_TCP_PORT} + : (($^O eq 'MSWin32') ? 2350 : 0); my $use_tcp = ($tcp_port =~ /^\d+$/ && $tcp_port > 0); my ($socket, $endpoint_desc); @@ -230,7 +232,12 @@ sub new { } } if (!$socket) { - print STDERR "Cannot listen at '$socket_file': $!\n"; + if ($^O eq 'MSWin32') { + print STDERR "Cannot listen at UNIX socket '$socket_file' on Windows: $!\n"; + print STDERR "Set OPENKORE_SOCKET_TCP_PORT (example: 2350) to use TCP console endpoint.\n"; + } else { + print STDERR "Cannot listen at '$socket_file': $!\n"; + } exit 1; } $endpoint_desc = $socket_file; From a5ff5d27e51b5bb0e23d826b2121de74a32c3ab6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Bosc=C3=A1?= Date: Thu, 16 Apr 2026 18:25:46 -0300 Subject: [PATCH 24/25] Avoid UNIX socket path on Perl builds without sockaddr_un --- src/Interface/Socket.pm | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Interface/Socket.pm b/src/Interface/Socket.pm index 4ea7c4e3ac..52d4b87096 100644 --- a/src/Interface/Socket.pm +++ b/src/Interface/Socket.pm @@ -170,6 +170,7 @@ package Interface::Socket::Server; use strict; use IO::Socket::UNIX; use IO::Socket::INET; +use Socket (); use Errno qw(EADDRINUSE); use Base::Server; use base qw(Base::Server); @@ -187,9 +188,10 @@ sub new { my $socket_file = "$Settings::logs_folder/console.socket"; my $pid_file = "$Settings::logs_folder/openkore.pid"; my $tcp_host = $ENV{OPENKORE_SOCKET_TCP_HOST} || '127.0.0.1'; + my $unix_socket_supported = eval { Socket::pack_sockaddr_un($socket_file); 1 }; my $tcp_port = defined $ENV{OPENKORE_SOCKET_TCP_PORT} ? $ENV{OPENKORE_SOCKET_TCP_PORT} - : (($^O eq 'MSWin32') ? 2350 : 0); + : ((!$unix_socket_supported || $^O eq 'MSWin32') ? 2350 : 0); my $use_tcp = ($tcp_port =~ /^\d+$/ && $tcp_port > 0); my ($socket, $endpoint_desc); @@ -209,6 +211,11 @@ sub new { $endpoint_desc = "$tcp_host:" . $socket->sockport; print "Interface::Socket TCP endpoint listening at $endpoint_desc\n"; } else { + if (!$unix_socket_supported) { + print STDERR "UNIX sockets are not supported by this Perl build.\n"; + print STDERR "Set OPENKORE_SOCKET_TCP_PORT (example: 2350) or run with Windows TCP defaults.\n"; + exit 1; + } $socket = new IO::Socket::UNIX( Local => $socket_file, Type => SOCK_STREAM, From 442d41e316517f9e03ef4111f9ceda7ae5b42f01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Bosc=C3=A1?= Date: Thu, 16 Apr 2026 18:29:39 -0300 Subject: [PATCH 25/25] Fallback to TCP when OPENKORE_SOCKET_TCP_PORT is empty/invalid --- src/Interface/Socket.pm | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/Interface/Socket.pm b/src/Interface/Socket.pm index 52d4b87096..3d403a9be6 100644 --- a/src/Interface/Socket.pm +++ b/src/Interface/Socket.pm @@ -189,9 +189,11 @@ sub new { my $pid_file = "$Settings::logs_folder/openkore.pid"; my $tcp_host = $ENV{OPENKORE_SOCKET_TCP_HOST} || '127.0.0.1'; my $unix_socket_supported = eval { Socket::pack_sockaddr_un($socket_file); 1 }; - my $tcp_port = defined $ENV{OPENKORE_SOCKET_TCP_PORT} - ? $ENV{OPENKORE_SOCKET_TCP_PORT} - : ((!$unix_socket_supported || $^O eq 'MSWin32') ? 2350 : 0); + my $tcp_port_env = $ENV{OPENKORE_SOCKET_TCP_PORT}; + my $default_tcp_port = (!$unix_socket_supported || $^O eq 'MSWin32') ? 2350 : 0; + my $tcp_port = ($tcp_port_env && $tcp_port_env =~ /^\d+$/ && $tcp_port_env > 0) + ? $tcp_port_env + : $default_tcp_port; my $use_tcp = ($tcp_port =~ /^\d+$/ && $tcp_port > 0); my ($socket, $endpoint_desc); @@ -211,11 +213,6 @@ sub new { $endpoint_desc = "$tcp_host:" . $socket->sockport; print "Interface::Socket TCP endpoint listening at $endpoint_desc\n"; } else { - if (!$unix_socket_supported) { - print STDERR "UNIX sockets are not supported by this Perl build.\n"; - print STDERR "Set OPENKORE_SOCKET_TCP_PORT (example: 2350) or run with Windows TCP defaults.\n"; - exit 1; - } $socket = new IO::Socket::UNIX( Local => $socket_file, Type => SOCK_STREAM,