diff options
Diffstat (limited to 'src/server/worldserver/Main.cpp')
-rw-r--r-- | src/server/worldserver/Main.cpp | 59 |
1 files changed, 50 insertions, 9 deletions
diff --git a/src/server/worldserver/Main.cpp b/src/server/worldserver/Main.cpp index bd028069c62..6c93343b8de 100644 --- a/src/server/worldserver/Main.cpp +++ b/src/server/worldserver/Main.cpp @@ -88,6 +88,7 @@ bool StartDB(); void StopDB(); void WorldUpdateLoop(); void ClearOnlineAccounts(); +void ShutdownCLIThread(std::thread* cliThread); void ShutdownThreadPool(std::vector<std::thread>& threadPool); variables_map GetConsoleArguments(int argc, char** argv, std::string& cfg_file, std::string& cfg_service); @@ -277,11 +278,26 @@ extern int main(int argc, char** argv) TC_LOG_INFO("server.worldserver", "Halting process..."); + ShutdownCLIThread(cliThread); + + OpenSSLCrypto::threadsCleanup(); + + // 0 - normal shutdown + // 1 - shutdown at error + // 2 - restart command used, this code can be used by restarter for restart Trinityd + + return World::GetExitCode(); +} + +void ShutdownCLIThread(std::thread* cliThread) +{ if (cliThread != nullptr) { #ifdef _WIN32 + // First try to cancel any I/O in the CLI thread if (!CancelSynchronousIo(cliThread->native_handle())) { + // if CancelSynchronousIo() fails, print the error and try with old way DWORD errorCode = GetLastError(); LPSTR errorBuffer; @@ -290,22 +306,47 @@ extern int main(int argc, char** argv) if (!formatReturnCode) errorBuffer = "Unknown error"; - TC_LOG_ERROR("server.worldserver", "Error cancelling I/O of CliThread, error code %u, detail: %s", + TC_LOG_DEBUG("server.worldserver", "Error cancelling I/O of CliThread, error code %u, detail: %s", errorCode, errorBuffer); LocalFree(errorBuffer); + + // send keyboard input to safely unblock the CLI thread + INPUT_RECORD b[4]; + HANDLE hStdIn = GetStdHandle(STD_INPUT_HANDLE); + b[0].EventType = KEY_EVENT; + b[0].Event.KeyEvent.bKeyDown = TRUE; + b[0].Event.KeyEvent.uChar.AsciiChar = 'X'; + b[0].Event.KeyEvent.wVirtualKeyCode = 'X'; + b[0].Event.KeyEvent.wRepeatCount = 1; + + b[1].EventType = KEY_EVENT; + b[1].Event.KeyEvent.bKeyDown = FALSE; + b[1].Event.KeyEvent.uChar.AsciiChar = 'X'; + b[1].Event.KeyEvent.wVirtualKeyCode = 'X'; + b[1].Event.KeyEvent.wRepeatCount = 1; + + b[2].EventType = KEY_EVENT; + b[2].Event.KeyEvent.bKeyDown = TRUE; + b[2].Event.KeyEvent.dwControlKeyState = 0; + b[2].Event.KeyEvent.uChar.AsciiChar = '\r'; + b[2].Event.KeyEvent.wVirtualKeyCode = VK_RETURN; + b[2].Event.KeyEvent.wRepeatCount = 1; + b[2].Event.KeyEvent.wVirtualScanCode = 0x1c; + + b[3].EventType = KEY_EVENT; + b[3].Event.KeyEvent.bKeyDown = FALSE; + b[3].Event.KeyEvent.dwControlKeyState = 0; + b[3].Event.KeyEvent.uChar.AsciiChar = '\r'; + b[3].Event.KeyEvent.wVirtualKeyCode = VK_RETURN; + b[3].Event.KeyEvent.wVirtualScanCode = 0x1c; + b[3].Event.KeyEvent.wRepeatCount = 1; + DWORD numb; + WriteConsoleInput(hStdIn, b, 4, &numb); } #endif cliThread->join(); delete cliThread; } - - OpenSSLCrypto::threadsCleanup(); - - // 0 - normal shutdown - // 1 - shutdown at error - // 2 - restart command used, this code can be used by restarter for restart Trinityd - - return World::GetExitCode(); } void ShutdownThreadPool(std::vector<std::thread>& threadPool) |