Skip to content

Commit 4d1ba12

Browse files
authored
Add exit code to shutdown function (Fixes #2293) (PR #2298)
1 parent 7963997 commit 4d1ba12

23 files changed

+187
-259
lines changed

Server/core/CModManagerImpl.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ void CModManagerImpl::Unload(bool bKeyPressBeforeTerm)
127127
Print("Press Q to shut down the server!\n");
128128
WaitForKey('q');
129129
}
130-
TerminateProcess(GetCurrentProcess(), 0);
130+
TerminateProcess(GetCurrentProcess(), GetExitCode());
131131
}
132132
#endif
133133
// Unload the library
@@ -179,6 +179,16 @@ bool CModManagerImpl::GetSleepIntervals(int& iSleepBusyMs, int& iSleepIdleMs, in
179179
return false;
180180
}
181181

182+
void CModManagerImpl::SetExitCode(int exitCode)
183+
{
184+
m_pServer->SetExitCode(exitCode);
185+
}
186+
187+
int CModManagerImpl::GetExitCode() const
188+
{
189+
return m_pServer->GetExitCode();
190+
}
191+
182192
void CModManagerImpl::GetTag(char* szInfoTag, int iInfoTag)
183193
{
184194
if (m_pBase)

Server/core/CModManagerImpl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ class CModManagerImpl : public CModManager
5252
bool GetSleepIntervals(int& iSleepBusyMs, int& iSleepIdleMs, int& iLogicFpsLimit);
5353
CDynamicLibrary& GetDynamicLibrary() { return m_Library; };
5454

55+
void SetExitCode(int exitCode) override;
56+
int GetExitCode() const override;
57+
5558
private:
5659
CServerImpl* m_pServer;
5760

Server/core/CServerImpl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ CServerImpl::CServerImpl()
6464
m_pNetwork = NULL;
6565
m_bRequestedQuit = false;
6666
m_bRequestedReset = false;
67+
m_exitCode = ERROR_NO_ERROR;
6768
memset(&m_szInputBuffer, 0, sizeof(m_szInputBuffer));
6869
memset(&m_szTag, 0, sizeof(m_szTag) * sizeof(char));
6970
m_uiInputCount = 0;

Server/core/CServerImpl.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ class CServerImpl : public CServerInterface
6767
bool HasConsole();
6868
#endif
6969

70+
void SetExitCode(int exitCode) { m_exitCode = exitCode; }
71+
int GetExitCode() const { return m_exitCode; }
72+
7073
private:
7174
void MainLoop();
7275

@@ -104,6 +107,8 @@ class CServerImpl : public CServerInterface
104107
double m_dLastTimeMs;
105108
double m_dPrevOverrun;
106109

110+
int m_exitCode;
111+
107112
std::vector<std::vector<SString>> m_vecCommandHistory = {{"", ""}};
108113
uint m_uiSelectedCommandHistoryEntry = 0;
109114

Server/core/Server.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "CServerImpl.h"
1414
#define ALLOC_STATS_MODULE_NAME "core"
1515
#include "SharedUtil.hpp"
16+
#include "ErrorCodes.h"
1617
#ifdef WIN_x86
1718
// TODO - 64 bit file hooks
1819
#include "SharedUtil.Win32Utf8FileHooks.hpp"
@@ -66,6 +67,10 @@ MTAEXPORT int Run(int iArgumentCount, char* szArguments[])
6667
RemoveUtf8FileHooks();
6768
#endif
6869

70+
// Overwrite the exit code, if we are stopping gracefully without errors
71+
if (iReturn == ERROR_NO_ERROR)
72+
iReturn = Server.GetExitCode();
73+
6974
return iReturn;
7075
}
7176

Server/mods/deathmatch/StdInc.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ struct SAclRequest;
157157
#include "lua/CLuaManager.h"
158158
#include "lua/CLuaTimerManager.h"
159159
#include "lua/CLuaTimer.h"
160-
#include "lua/CLuaFunctionDefs.h"
161160
#include "lua/CLuaModuleManager.h"
162161
#include "lua/CLuaArgument.h"
163162
#include "lua/CLuaCFunctions.h"

Server/mods/deathmatch/logic/CGame.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,6 @@ bool CGame::Start(int iArgumentCount, char* szArguments[])
800800
m_pZoneNames = new CZoneNames;
801801

802802
CStaticFunctionDefinitions(this);
803-
CLuaFunctionDefs::Initialize(m_pLuaManager, this);
804803
CLuaDefs::Initialize(this);
805804

806805
m_pPlayerManager->SetScriptDebugging(m_pScriptDebugging);

Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
#include "StdInc.h"
1313

14-
extern CGame* g_pGame;
14+
extern CGame* g_pGame;
15+
extern CTimeUsMarker<20> markerLatentEvent;
1516

1617
static CLuaManager* m_pLuaManager;
1718
static CColManager* m_pColManager;

Server/mods/deathmatch/logic/lua/CLuaFunctionDefs.cpp

Lines changed: 0 additions & 55 deletions
This file was deleted.

Server/mods/deathmatch/logic/lua/CLuaMain.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
*****************************************************************************/
1111

1212
#include "StdInc.h"
13-
14-
#include "CLuaFunctionDefs.h"
13+
#include "luadefs/CLuaFunctionDefs.h"
1514
#include <clocale>
1615

1716
static CLuaManager* m_pLuaManager;

0 commit comments

Comments
 (0)