mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Fix exception during SDK shutdown
Run in a fixed interval manner within same thread instead of separate threads.
This commit is contained in:
parent
62604e8fe9
commit
0774ebf9ff
@ -92,7 +92,7 @@ void Systems_Init()
|
||||
int nError = ::WSAStartup(MAKEWORD(2, 2), &wsaData);
|
||||
if (nError != 0)
|
||||
{
|
||||
std::cerr << "Failed to start Winsock via WSAStartup: (" << NET_ErrorString(WSAGetLastError()) << ")." << std::endl;
|
||||
std::cerr << "Failed to start Winsock via WSAStartup: (" << NET_ErrorString(WSAGetLastError()) << ")" << std::endl;
|
||||
}
|
||||
|
||||
// Begin the detour transaction to hook the the process
|
||||
@ -102,7 +102,7 @@ void Systems_Init()
|
||||
// Hook functions
|
||||
IApplication_Attach();
|
||||
#ifdef DEDICATED
|
||||
PRX_Attach();
|
||||
//PRX_Attach();
|
||||
#endif // DEDICATED
|
||||
CBaseClient_Attach();
|
||||
CBaseFileSystem_Attach();
|
||||
@ -172,7 +172,7 @@ void Systems_Shutdown()
|
||||
int nError = ::WSACleanup();
|
||||
if (nError != 0)
|
||||
{
|
||||
std::cerr << "Failed to stop winsock via WSACleanup: (" << NET_ErrorString(WSAGetLastError()) << ")." << std::endl;
|
||||
std::cerr << "Failed to stop winsock via WSACleanup: (" << NET_ErrorString(WSAGetLastError()) << ")" << std::endl;
|
||||
}
|
||||
|
||||
// Begin the detour transaction to unhook the the process
|
||||
@ -182,7 +182,7 @@ void Systems_Shutdown()
|
||||
// Unhook functions
|
||||
IApplication_Detach();
|
||||
#ifdef DEDICATED
|
||||
PRX_Detach();
|
||||
//PRX_Detach();
|
||||
#endif // DEDICATED
|
||||
CBaseClient_Detach();
|
||||
CBaseFileSystem_Detach();
|
||||
|
@ -28,6 +28,9 @@
|
||||
#include "public/include/bansystem.h"
|
||||
#include "game/server/gameinterface.h"
|
||||
|
||||
std::chrono::time_point<std::chrono::steady_clock> tpPylonStartClock = std::chrono::steady_clock::now();
|
||||
std::chrono::time_point<std::chrono::steady_clock> tpBanListStartClock = std::chrono::steady_clock::now();
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: state machine's main processing loop
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -55,7 +58,6 @@ FORCEINLINE void CHostState::FrameUpdate(void* rcx, void* rdx, float time)
|
||||
else
|
||||
{
|
||||
*g_ServerAbortServer = true;
|
||||
|
||||
do
|
||||
{
|
||||
Cbuf_Execute();
|
||||
@ -82,6 +84,7 @@ FORCEINLINE void CHostState::FrameUpdate(void* rcx, void* rdx, float time)
|
||||
}
|
||||
case HostStates_t::HS_RUN:
|
||||
{
|
||||
g_pHostState->Think();
|
||||
State_RunFn(&g_pHostState->m_iCurrentState, nullptr, time);
|
||||
break;
|
||||
}
|
||||
@ -120,7 +123,6 @@ FORCEINLINE void CHostState::FrameUpdate(void* rcx, void* rdx, float time)
|
||||
} while ((oldState != HostStates_t::HS_RUN || g_pHostState->m_iNextState == HostStates_t::HS_LOAD_GAME && g_pCVar->FindVar("single_frame_shutdown_for_reload")->GetBool())
|
||||
&& oldState != HostStates_t::HS_SHUTDOWN
|
||||
&& oldState != HostStates_t::HS_RESTART);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -141,24 +143,6 @@ FORCEINLINE void CHostState::Setup(void) const
|
||||
ConCommandBase* disconnect = (ConCommandBase*)g_pCVar->FindCommand("disconnect");
|
||||
disconnect->AddFlags(FCVAR_SERVER_CAN_EXECUTE); // Make sure server is not restricted to this.
|
||||
|
||||
static std::thread PylonThread([]() // Pylon request thread.
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
KeepAliveToPylon();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(5000));
|
||||
}
|
||||
});
|
||||
|
||||
static std::thread BanlistThread([]()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
g_pBanSystem->BanListCheck();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
}
|
||||
});
|
||||
|
||||
if (net_userandomkey->GetBool())
|
||||
{
|
||||
HNET_GenerateKey();
|
||||
@ -167,6 +151,25 @@ FORCEINLINE void CHostState::Setup(void) const
|
||||
g_pCVar->FindVar("net_usesocketsforloopback")->SetValue(1);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: think
|
||||
//-----------------------------------------------------------------------------
|
||||
FORCEINLINE void CHostState::Think(void) const
|
||||
{
|
||||
std::chrono::time_point<std::chrono::steady_clock> tpCrrentClock = std::chrono::steady_clock::now();
|
||||
|
||||
if (std::chrono::duration_cast<std::chrono::seconds>(tpCrrentClock - tpBanListStartClock).count() >= 1)
|
||||
{
|
||||
g_pBanSystem->BanListCheck();
|
||||
tpBanListStartClock = std::chrono::steady_clock::now();
|
||||
}
|
||||
if (std::chrono::duration_cast<std::chrono::seconds>(tpCrrentClock - tpPylonStartClock).count() >= 5)
|
||||
{
|
||||
KeepAliveToPylon();
|
||||
tpPylonStartClock = std::chrono::steady_clock::now();
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: load and execute configuration files
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -17,9 +17,10 @@ class CHostState
|
||||
{
|
||||
public:
|
||||
FORCEINLINE static void FrameUpdate(void* rcx, void* rdx, float time);
|
||||
FORCEINLINE void LoadConfig(void) const;
|
||||
|
||||
FORCEINLINE void Setup(void) const;
|
||||
FORCEINLINE void LoadConfig(void) const;
|
||||
FORCEINLINE void Think(void) const;
|
||||
|
||||
FORCEINLINE void State_NewGame(void);
|
||||
FORCEINLINE void GameShutDown(void);
|
||||
|
Loading…
x
Reference in New Issue
Block a user