mirror of
https://github.com/smartcmd/MinecraftConsoles.git
synced 2026-08-20 09:57:09 +00:00
fix #397 server console
This commit is contained in:
parent
0e9d8629f1
commit
5f170b68eb
|
|
@ -58,7 +58,11 @@ target_compile_definitions(MinecraftClient PRIVATE
|
||||||
)
|
)
|
||||||
if(MSVC)
|
if(MSVC)
|
||||||
configure_msvc_target(MinecraftClient)
|
configure_msvc_target(MinecraftClient)
|
||||||
|
# Use CONSOLE subsystem so the shell waits for the process (important for
|
||||||
|
# Docker and piped output in server mode). WinMainCRTStartup keeps the
|
||||||
|
# WinMain entry point. Client mode calls FreeConsole() to detach.
|
||||||
target_link_options(MinecraftClient PRIVATE
|
target_link_options(MinecraftClient PRIVATE
|
||||||
|
/SUBSYSTEM:CONSOLE /ENTRY:WinMainCRTStartup
|
||||||
$<$<CONFIG:Release>:/LTCG /INCREMENTAL:NO>
|
$<$<CONFIG:Release>:/LTCG /INCREMENTAL:NO>
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
|
||||||
|
|
@ -228,14 +228,14 @@ static BOOL WINAPI HeadlessServerCtrlHandler(DWORD ctrlType)
|
||||||
|
|
||||||
static void SetupHeadlessServerConsole()
|
static void SetupHeadlessServerConsole()
|
||||||
{
|
{
|
||||||
if (AllocConsole())
|
// The exe is now linked as /SUBSYSTEM:CONSOLE, so it inherits the parent's
|
||||||
{
|
// console automatically. We just need to re-open the CRT streams so that
|
||||||
|
// printf/scanf go through the console and set up our Ctrl handler.
|
||||||
FILE* stream = NULL;
|
FILE* stream = NULL;
|
||||||
freopen_s(&stream, "CONIN$", "r", stdin);
|
freopen_s(&stream, "CONIN$", "r", stdin);
|
||||||
freopen_s(&stream, "CONOUT$", "w", stdout);
|
freopen_s(&stream, "CONOUT$", "w", stdout);
|
||||||
freopen_s(&stream, "CONOUT$", "w", stderr);
|
freopen_s(&stream, "CONOUT$", "w", stderr);
|
||||||
SetConsoleTitleA("Minecraft Server");
|
SetConsoleTitleA("Minecraft Server");
|
||||||
}
|
|
||||||
|
|
||||||
SetConsoleCtrlHandler(HeadlessServerCtrlHandler, TRUE);
|
SetConsoleCtrlHandler(HeadlessServerCtrlHandler, TRUE);
|
||||||
}
|
}
|
||||||
|
|
@ -1141,6 +1141,15 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
|
||||||
|
|
||||||
// Load stuff from launch options, including username
|
// Load stuff from launch options, including username
|
||||||
Win64LaunchOptions launchOptions = ParseLaunchOptions();
|
Win64LaunchOptions launchOptions = ParseLaunchOptions();
|
||||||
|
|
||||||
|
// The exe is linked as /SUBSYSTEM:CONSOLE so that the shell waits for it
|
||||||
|
// (required for Docker / piped output in server mode). In client mode we
|
||||||
|
// don't need the console, so detach from it immediately.
|
||||||
|
if (!launchOptions.serverMode)
|
||||||
|
{
|
||||||
|
FreeConsole();
|
||||||
|
}
|
||||||
|
|
||||||
ApplyScreenMode(launchOptions.screenMode);
|
ApplyScreenMode(launchOptions.screenMode);
|
||||||
|
|
||||||
// If no username, let's fall back
|
// If no username, let's fall back
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue