Core: allow launching dedicated server without terminal window

The terminal window isn't always necessary, especially on Linux systems. In fact, it causes issues on some Wine environments. Allow user to disable it with -noconsole. This option only exists on the dedicated server. The client builds have the console disabled by default, and can enable them with -wconsole.
This commit is contained in:
Kawe Mazidjatari 2024-04-14 19:39:52 +02:00
parent 5d38b3762b
commit cb72778a25
4 changed files with 27 additions and 10 deletions

View File

@ -30,7 +30,9 @@ bool g_bSdkInitCallInitiated = false;
bool g_bSdkShutdownCallInitiated = false;
bool g_bSdkShutdownInitiatedFromConsoleHandler = false;
HMODULE s_hModuleHandle = NULL;
static bool s_bConsoleInitialized = false;
static HMODULE s_hModuleHandle = NULL;
//#############################################################################
// UTILITY
@ -116,9 +118,11 @@ void SDK_Init()
#ifndef DEDICATED
if (CommandLine()->CheckParm("-wconsole"))
#endif // !DEDICATED
#else
if (!CommandLine()->CheckParm("-noconsole"))
#endif // !DEDICATED
{
Console_Init(bAnsiColor);
s_bConsoleInitialized = Console_Init(bAnsiColor);
}
SpdLog_Init(bAnsiColor);
@ -186,7 +190,7 @@ void SDK_Shutdown()
// If the shutdown was initiated from the console window itself, don't
// shutdown the console as it would otherwise deadlock in FreeConsole!
if (!g_bSdkShutdownInitiatedFromConsoleHandler)
if (s_bConsoleInitialized && !g_bSdkShutdownInitiatedFromConsoleHandler)
Console_Shutdown();
g_bSdkInitialized = false;

View File

@ -109,6 +109,11 @@ void CSurface::Init()
this->m_ConsoleToggle->SetSize({ 110, 18 });
this->m_ConsoleToggle->SetLocation({ 290, 7 });
this->m_ConsoleToggle->SetTabIndex(0);
#ifdef DEDI_LAUNCHER
this->m_ConsoleToggle->SetChecked(true);
#else // For client builds, don't show the console by default
this->m_ConsoleToggle->SetChecked(false);
#endif // DEDI_LAUNCHER
this->m_ConsoleToggle->SetText("Show console");
this->m_ConsoleToggle->SetAnchor(Forms::AnchorStyles::Top | Forms::AnchorStyles::Left);
this->m_GameGroupExt->AddControl(this->m_ConsoleToggle);
@ -968,6 +973,8 @@ void CSurface::AppendConsoleParameters(string& svParameters)
{
if (this->m_ConsoleToggle->Checked())
AppendParameterInternal(svParameters, "-wconsole");
else
AppendParameterInternal(svParameters, "-noconsole");
if (this->m_ColorConsoleToggle->Checked())
AppendParameterInternal(svParameters, "-ansicolor");

View File

@ -77,8 +77,9 @@ void FlashConsoleBackground(int nFlashCount, int nFlashInterval, COLORREF color)
//-----------------------------------------------------------------------------
// Purpose: terminal window setup
// Input : bAnsiColor -
// Output : true on success, false otherwise
//-----------------------------------------------------------------------------
void Console_Init(const bool bAnsiColor)
bool Console_Init(const bool bAnsiColor)
{
#ifndef _TOOLS
///////////////////////////////////////////////////////////////////////////
@ -89,7 +90,7 @@ void Console_Init(const bool bAnsiColor)
snprintf(szBuf, sizeof(szBuf), "Failed to create console window! [%s]\n", std::system_category().message(static_cast<int>(::GetLastError())).c_str());
OutputDebugStringA(szBuf);
return;
return false;
}
//-- Set the window title
@ -133,12 +134,15 @@ void Console_Init(const bool bAnsiColor)
#ifndef _TOOLS
SetConsoleCtrlHandler(ConsoleHandlerRoutine, true);
#endif // !_TOOLS
return true;
}
//-----------------------------------------------------------------------------
// Purpose: terminal window shutdown
// Output : true on success, false otherwise
//-----------------------------------------------------------------------------
void Console_Shutdown()
bool Console_Shutdown()
{
///////////////////////////////////////////////////////////////////////////
// Destroy the console window
@ -148,8 +152,10 @@ void Console_Shutdown()
snprintf(szBuf, sizeof(szBuf), "Failed to destroy console window! [%s]\n", std::system_category().message(static_cast<int>(::GetLastError())).c_str());
OutputDebugStringA(szBuf);
return;
return false;
}
return true;
}
#ifndef _TOOLS

View File

@ -3,5 +3,5 @@
void SetConsoleBackgroundColor(COLORREF color);
void FlashConsoleBackground(int nFlashCount, int nFlashInterval, COLORREF color);
void Console_Init(const bool bAnsiColor);
void Console_Shutdown();
bool Console_Init(const bool bAnsiColor);
bool Console_Shutdown();