Skip to content

Commit 86945b4

Browse files
committed
Improve graceful server shutdown
1 parent 2c3932c commit 86945b4

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

Server/core/CModManagerImpl.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ void CModManagerImpl::Unload(bool bKeyPressBeforeTerm)
130130
Print("Press Q to shut down the server!\n");
131131
WaitForKey('q');
132132
}
133-
TerminateProcess(GetCurrentProcess(), GetExitCode());
134133
}
135134
#endif
136135
// Unload the library

Server/core/CServerImpl.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,21 +351,26 @@ int CServerImpl::Run(int iArgumentCount, char* szArguments[])
351351

352352
if (m_XMLLibrary.Load(PathJoin(m_strServerPath, SERVER_BIN_PATH, szXMLLibName)))
353353
{
354-
// Grab the network interface
355-
InitNetServerInterface pfnInitNetServerInterface = (InitNetServerInterface)(m_NetworkLibrary.GetProcedureAddress("InitNetServerInterface"));
356-
InitXMLInterface pfnInitXMLInterface = (InitXMLInterface)(m_XMLLibrary.GetProcedureAddress("InitXMLInterface"));
354+
auto pfnInitNetServerInterface = (InitNetServerInterface)(m_NetworkLibrary.GetProcedureAddress("InitNetServerInterface"));
355+
auto pfnReleaseNetServerInterface = (ReleaseNetServerInterface)(m_NetworkLibrary.GetProcedureAddress("ReleaseNetServerInterface"));
356+
auto pfnInitXMLInterface = (InitXMLInterface)(m_XMLLibrary.GetProcedureAddress("InitXMLInterface"));
357+
357358
if (pfnInitNetServerInterface && pfnInitXMLInterface)
358359
{
359360
// Call it to grab the network interface class
360361
m_pNetwork = pfnInitNetServerInterface();
361362
m_pXML = pfnInitXMLInterface(*m_strServerModPath);
363+
362364
if (m_pNetwork && m_pXML)
363365
{
364366
// Make the modmanager load our mod
365367
if (m_pModManager->Load("deathmatch", iArgumentCount, szArguments)) // Hardcoded for now
366368
{
367369
// Enter our mainloop
368370
MainLoop();
371+
372+
if (pfnReleaseNetServerInterface)
373+
pfnReleaseNetServerInterface();
369374
}
370375
else
371376
{

Server/core/CServerImpl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class CServerImpl;
2828

2929
typedef CXML* (*InitXMLInterface)(const char* szSaveFlagDirectory);
3030
typedef CNetServer* (*InitNetServerInterface)();
31+
typedef void (*ReleaseNetServerInterface)();
3132

3233
#ifdef WIN32
3334
constexpr SHORT SCREEN_BUFFER_SIZE = 256;

0 commit comments

Comments
 (0)