Add 'ShutdownHostGame()' to all VM's

Calling this before connecting to a different (remote or local) server avoids crashing in the VM's during shutdown.
This commit is contained in:
Kawe Mazidjatari 2022-05-28 17:27:52 +02:00
parent 6b6ee089f6
commit 5adaf48d33
3 changed files with 22 additions and 0 deletions

View File

@ -16,6 +16,7 @@
#include "engine/server/server.h"
#endif // CLIENT_DLL
#include "engine/cmodel_bsp.h"
#include "engine/host_state.h"
#include "squirrel/sqtype.h"
#include "squirrel/sqapi.h"
#include "squirrel/sqinit.h"
@ -82,6 +83,17 @@ namespace VSquirrel
return SQ_OK;
}
//-----------------------------------------------------------------------------
// Purpose: shutdown local game (host only)
//-----------------------------------------------------------------------------
SQRESULT ShutdownHostGame(HSQUIRRELVM v)
{
if (g_pHostState->m_bActiveGame)
g_pHostState->m_iNextState = HostStates_t::HS_GAME_SHUTDOWN;
return SQ_OK;
}
}
#ifndef CLIENT_DLL
namespace SERVER

View File

@ -23,6 +23,7 @@ namespace VSquirrel
SQRESULT GetSDKVersion(HSQUIRRELVM v);
SQRESULT GetAvailableMaps(HSQUIRRELVM v);
SQRESULT GetAvailablePlaylists(HSQUIRRELVM v);
SQRESULT ShutdownHostGame(HSQUIRRELVM v);
}
#ifndef CLIENT_DLL
namespace SERVER

View File

@ -338,10 +338,14 @@ void SQVM_RegisterServerScriptFunctions(HSQUIRRELVM v)
{
SQVM_RegisterFunction(v, "SDKNativeTest", "Native SERVER test function", "void", "", &VSquirrel::SHARED::SDKNativeTest);
SQVM_RegisterFunction(v, "GetSDKVersion", "Gets the SDK version as a string", "string", "", &VSquirrel::SHARED::GetSDKVersion);
SQVM_RegisterFunction(v, "GetNumHumanPlayers", "Gets the number of human players on the server", "int", "", &VSquirrel::SERVER::GetNumHumanPlayers);
SQVM_RegisterFunction(v, "GetNumFakeClients", "Gets the number of bot players on the server", "int", "", &VSquirrel::SERVER::GetNumFakeClients);
SQVM_RegisterFunction(v, "GetAvailableMaps", "Gets an array of all available maps", "array<string>", "", &VSquirrel::SHARED::GetAvailableMaps);
SQVM_RegisterFunction(v, "GetAvailablePlaylists", "Gets an array of all available playlists", "array<string>", "", &VSquirrel::SHARED::GetAvailablePlaylists);
SQVM_RegisterFunction(v, "ShutdownHostGame", "Shuts down the local host game", "void", "", &VSquirrel::SHARED::ShutdownHostGame);
}
#endif // !CLIENT_DLL
@ -354,8 +358,11 @@ void SQVM_RegisterClientScriptFunctions(HSQUIRRELVM v)
{
SQVM_RegisterFunction(v, "SDKNativeTest", "Native CLIENT test function", "void", "", &VSquirrel::SHARED::SDKNativeTest);
SQVM_RegisterFunction(v, "GetSDKVersion", "Gets the SDK version as a string", "string", "", &VSquirrel::SHARED::GetSDKVersion);
SQVM_RegisterFunction(v, "GetAvailableMaps", "Gets an array of all available maps", "array<string>", "", &VSquirrel::SHARED::GetAvailableMaps);
SQVM_RegisterFunction(v, "GetAvailablePlaylists", "Gets an array of all available playlists", "array<string>", "", &VSquirrel::SHARED::GetAvailablePlaylists);
SQVM_RegisterFunction(v, "ShutdownHostGame", "Shuts down the local host game", "void", "", &VSquirrel::SHARED::ShutdownHostGame);
}
//---------------------------------------------------------------------------------
@ -385,6 +392,8 @@ void SQVM_RegisterUIScriptFunctions(HSQUIRRELVM v)
SQVM_RegisterFunction(v, "GetAvailableMaps", "Gets an array of all available maps", "array<string>", "", &VSquirrel::SHARED::GetAvailableMaps);
SQVM_RegisterFunction(v, "GetAvailablePlaylists", "Gets an array of all available playlists", "array<string>", "", &VSquirrel::SHARED::GetAvailablePlaylists);
SQVM_RegisterFunction(v, "ShutdownHostGame", "Shuts down the local host game", "void", "", &VSquirrel::SHARED::ShutdownHostGame);
}
//---------------------------------------------------------------------------------