From bb93442db8b1e450adf08a8305335020c436d358 Mon Sep 17 00:00:00 2001 From: HappyDOGE <28511119+HappyDOGE@users.noreply.github.com> Date: Tue, 28 Dec 2021 12:56:08 +0300 Subject: dedicated console command input --- NorthstarDedicatedTest/dedicated.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'NorthstarDedicatedTest/dedicated.cpp') diff --git a/NorthstarDedicatedTest/dedicated.cpp b/NorthstarDedicatedTest/dedicated.cpp index 83a9950a..26dcc9ae 100644 --- a/NorthstarDedicatedTest/dedicated.cpp +++ b/NorthstarDedicatedTest/dedicated.cpp @@ -76,6 +76,32 @@ bool IsGameActiveWindowHook() return true; } +HANDLE consoleInputThreadHandle = NULL; + +DWORD WINAPI ConsoleInputThread(PVOID pThreadParameter) +{ + while (!g_pEngine || !g_pHostState || g_pHostState->m_iCurrentState != HostState_t::HS_RUN) + Sleep(1000); + + // Bind stdin to receive console input. + FILE* fp = nullptr; + freopen_s(&fp, "CONIN$", "r", stdin); + + spdlog::info("Ready to receive console commands."); + + { + // Process console input + std::string input; + while (g_pEngine && g_pEngine->m_nQuitting == EngineQuitState::QUIT_NOTQUITTING && std::getline(std::cin, input)) + { + input += "\n"; + Cbuf_AddText(Cbuf_GetCurrentPlayer(), input.c_str(), cmd_source_t::kCommandSrcCode); + } + } + + return 0; +} + void InitialiseDedicated(HMODULE engineAddress) { if (!IsDedicated()) @@ -380,6 +406,9 @@ void InitialiseDedicated(HMODULE engineAddress) CommandLine()->AppendParm("+host_preload_shaders", "0"); CommandLine()->AppendParm("+net_usesocketsforloopback", "1"); CommandLine()->AppendParm("+exec", "autoexec_ns_server"); + + // create console input thread + consoleInputThreadHandle = CreateThread(0, 0, ConsoleInputThread, 0, 0, NULL); } typedef void(*Tier0_InitOriginType)(); -- cgit v1.2.3 From 8179de9831dd415794269015a40de44baa4c29d1 Mon Sep 17 00:00:00 2001 From: HappyDOGE <28511119+HappyDOGE@users.noreply.github.com> Date: Tue, 28 Dec 2021 13:17:55 +0300 Subject: add parm checks for dedicated input + disable quick edit --- NorthstarDedicatedTest/dedicated.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'NorthstarDedicatedTest/dedicated.cpp') diff --git a/NorthstarDedicatedTest/dedicated.cpp b/NorthstarDedicatedTest/dedicated.cpp index 26dcc9ae..91e9cef6 100644 --- a/NorthstarDedicatedTest/dedicated.cpp +++ b/NorthstarDedicatedTest/dedicated.cpp @@ -407,8 +407,30 @@ void InitialiseDedicated(HMODULE engineAddress) CommandLine()->AppendParm("+net_usesocketsforloopback", "1"); CommandLine()->AppendParm("+exec", "autoexec_ns_server"); + // Disable Quick Edit mode to reduce chance of user unintentionally hanging their server by selecting something. + if (!CommandLine()->CheckParm("-bringbackquickedit")) + { + spdlog::info("Quick Edit enabled by user request"); + + HANDLE stdIn = GetStdHandle(STD_INPUT_HANDLE); + DWORD mode = 0; + + if (GetConsoleMode(stdIn, &mode)) { + if (mode & ENABLE_QUICK_EDIT_MODE) { + mode &= ~ENABLE_QUICK_EDIT_MODE; + mode &= ~ENABLE_MOUSE_INPUT; + + mode |= ENABLE_PROCESSED_INPUT; + + SetConsoleMode(stdIn, mode); + } + } + } + // create console input thread - consoleInputThreadHandle = CreateThread(0, 0, ConsoleInputThread, 0, 0, NULL); + if (!CommandLine()->CheckParm("-noconsoleinput")) + consoleInputThreadHandle = CreateThread(0, 0, ConsoleInputThread, 0, 0, NULL); + else spdlog::info("Console input disabled by user request"); } typedef void(*Tier0_InitOriginType)(); -- cgit v1.2.3 From 4e9e9d9766663c39e21fcdd33e865cdc8cbf7e6a Mon Sep 17 00:00:00 2001 From: HappyDOGE <28511119+HappyDOGE@users.noreply.github.com> Date: Tue, 28 Dec 2021 13:34:09 +0300 Subject: fix quick edit enabled message --- NorthstarDedicatedTest/dedicated.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'NorthstarDedicatedTest/dedicated.cpp') diff --git a/NorthstarDedicatedTest/dedicated.cpp b/NorthstarDedicatedTest/dedicated.cpp index 91e9cef6..f77567ec 100644 --- a/NorthstarDedicatedTest/dedicated.cpp +++ b/NorthstarDedicatedTest/dedicated.cpp @@ -410,8 +410,6 @@ void InitialiseDedicated(HMODULE engineAddress) // Disable Quick Edit mode to reduce chance of user unintentionally hanging their server by selecting something. if (!CommandLine()->CheckParm("-bringbackquickedit")) { - spdlog::info("Quick Edit enabled by user request"); - HANDLE stdIn = GetStdHandle(STD_INPUT_HANDLE); DWORD mode = 0; @@ -425,7 +423,7 @@ void InitialiseDedicated(HMODULE engineAddress) SetConsoleMode(stdIn, mode); } } - } + } else spdlog::info("Quick Edit enabled by user request"); // create console input thread if (!CommandLine()->CheckParm("-noconsoleinput")) -- cgit v1.2.3