From e2c966a414b6157e94460ac0054d999a374f98fd Mon Sep 17 00:00:00 2001 From: yani9o <90964575+yani9o@users.noreply.github.com> Date: Fri, 13 Mar 2026 15:27:48 +0100 Subject: [PATCH] feat(Core/Cli): Re-Enable Console Pipe Functionality (#24963) --- .../worldserver/CommandLine/CliRunnable.cpp | 44 +++++++++++++++---- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/src/server/apps/worldserver/CommandLine/CliRunnable.cpp b/src/server/apps/worldserver/CommandLine/CliRunnable.cpp index 307bee1a5..07bb829b3 100644 --- a/src/server/apps/worldserver/CommandLine/CliRunnable.cpp +++ b/src/server/apps/worldserver/CommandLine/CliRunnable.cpp @@ -27,6 +27,7 @@ #if AC_PLATFORM == AC_PLATFORM_WINDOWS #include +#include #else #include "Chat.h" #include "ChatCommand.h" @@ -158,21 +159,48 @@ void CliThread() std::string command; #if AC_PLATFORM == AC_PLATFORM_WINDOWS - wchar_t commandbuf[256]; - DWORD charsRead = 0; - if (ReadConsoleW(hStdIn, commandbuf, sizeof(commandbuf) / sizeof(wchar_t) - 1, &charsRead, nullptr)) + static bool checkedConsole = false; + static bool isRealConsole = false; + + if (!checkedConsole) { - if (charsRead > 0) + DWORD mode = 0; + isRealConsole = GetConsoleMode(hStdIn, &mode); + checkedConsole = true; + } + + if (isRealConsole) + { + // ===== Real Windows Console ===== + wchar_t commandbuf[256]; + DWORD charsRead = 0; + + if (ReadConsoleW(hStdIn, commandbuf, + sizeof(commandbuf) / sizeof(wchar_t) - 1, + &charsRead, nullptr)) { - commandbuf[charsRead] = L'\0'; - if (!WStrToUtf8(commandbuf, charsRead, command)) + if (charsRead > 0) { - PrintCliPrefix(); - continue; + commandbuf[charsRead] = L'\0'; + if (!WStrToUtf8(commandbuf, charsRead, command)) + { + PrintCliPrefix(); + continue; + } } } } + else + { + // ===== Redirected input (pipe) ===== + if (!std::getline(std::cin, command)) + { + World::StopNow(SHUTDOWN_EXIT_CODE); + break; + } + } + #else char* command_str = readline(CLI_PREFIX); ::rl_bind_key('\t', ::rl_complete);