Skip to content

Commit b5060de

Browse files
committed
Print local server output to console on disconnect/shutdown
1 parent 86945b4 commit b5060de

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

Client/mods/deathmatch/logic/CServer.cpp

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,13 @@ void CServer::Stop(bool graceful)
225225
}
226226
}
227227

228+
// Print out the remaining server output (but not everything to avoid blocking here).
229+
for (int i = 0; i < 5; ++i)
230+
{
231+
if (!PrintServerOutputToConsole())
232+
break;
233+
}
234+
228235
if (DWORD exitCode{}; GetExitCodeProcess(m_process, &exitCode))
229236
{
230237
const char* errorText = "Unknown exit code";
@@ -256,16 +263,7 @@ void CServer::Pulse()
256263
if (!m_isRunning)
257264
return;
258265

259-
// Try to read the process standard output and then write it to the console window.
260-
if (DWORD numBytes{}; PeekNamedPipe(m_stdout, nullptr, 0, nullptr, &numBytes, nullptr) && numBytes > 0)
261-
{
262-
std::array<char, 4096> buffer{};
263-
264-
if (ReadFile(m_stdout, buffer.data(), std::min<DWORD>(buffer.size(), numBytes), &numBytes, nullptr) && numBytes > 0)
265-
{
266-
g_pCore->GetConsole()->Printf("%.*s", numBytes, buffer.data());
267-
}
268-
}
266+
PrintServerOutputToConsole();
269267

270268
// Check if the server process was terminated externally.
271269
if (!IsProcessRunning(m_process))
@@ -285,3 +283,20 @@ void CServer::Pulse()
285283
}
286284
}
287285
}
286+
287+
bool CServer::PrintServerOutputToConsole()
288+
{
289+
// Try to read the process standard output and then write it to the console window.
290+
if (DWORD numBytes{}; PeekNamedPipe(m_stdout, nullptr, 0, nullptr, &numBytes, nullptr) && numBytes > 0)
291+
{
292+
std::array<char, 4096> buffer{};
293+
294+
if (ReadFile(m_stdout, buffer.data(), std::min<DWORD>(buffer.size(), numBytes), &numBytes, nullptr) && numBytes > 0)
295+
{
296+
g_pCore->GetConsole()->Printf("%.*s", numBytes, buffer.data());
297+
return true;
298+
}
299+
}
300+
301+
return false;
302+
}

Client/mods/deathmatch/logic/CServer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ class CServer final
3030

3131
const std::string& GetPassword() const noexcept { return m_password; }
3232

33+
public:
34+
bool PrintServerOutputToConsole();
35+
3336
private:
3437
bool m_isRunning{};
3538
bool m_isAcceptingConnections{};

0 commit comments

Comments
 (0)