forked from mirror/openmw-tes3mp
[Server] Add experimental option for not crashing from Lua script errors
Additionally, fix return type of GetPluginEnforcementState()
This commit is contained in:
parent
b39e3f518b
commit
b7090b2550
5 changed files with 58 additions and 6 deletions
|
@ -31,6 +31,7 @@ Networking *Networking::sThis = 0;
|
|||
|
||||
static int currentMpNum = 0;
|
||||
static bool pluginEnforcementState = true;
|
||||
static bool scriptErrorIgnoringState = false;
|
||||
|
||||
Networking::Networking(RakNet::RakPeerInterface *peer) : mclient(nullptr)
|
||||
{
|
||||
|
@ -430,6 +431,16 @@ void Networking::setPluginEnforcementState(bool state)
|
|||
pluginEnforcementState = state;
|
||||
}
|
||||
|
||||
bool Networking::getScriptErrorIgnoringState()
|
||||
{
|
||||
return scriptErrorIgnoringState;
|
||||
}
|
||||
|
||||
void Networking::setScriptErrorIgnoringState(bool state)
|
||||
{
|
||||
scriptErrorIgnoringState = state;
|
||||
}
|
||||
|
||||
const Networking &Networking::get()
|
||||
{
|
||||
return *sThis;
|
||||
|
|
|
@ -56,6 +56,9 @@ namespace mwmp
|
|||
bool getPluginEnforcementState();
|
||||
void setPluginEnforcementState(bool state);
|
||||
|
||||
bool getScriptErrorIgnoringState();
|
||||
void setScriptErrorIgnoringState(bool state);
|
||||
|
||||
MasterClient *getMasterClient();
|
||||
void InitQuery(std::string queryAddr, unsigned short queryPort);
|
||||
void setServerPassword(std::string passw) noexcept;
|
||||
|
|
|
@ -75,11 +75,16 @@ bool ServerFunctions::HasPassword() noexcept
|
|||
return mwmp::Networking::get().isPassworded();
|
||||
}
|
||||
|
||||
int ServerFunctions::GetPluginEnforcementState() noexcept
|
||||
bool ServerFunctions::GetPluginEnforcementState() noexcept
|
||||
{
|
||||
return mwmp::Networking::getPtr()->getPluginEnforcementState();
|
||||
}
|
||||
|
||||
bool ServerFunctions::GetScriptErrorIgnoringState() noexcept
|
||||
{
|
||||
return mwmp::Networking::getPtr()->getScriptErrorIgnoringState();
|
||||
}
|
||||
|
||||
void ServerFunctions::SetGameMode(const char *gameMode) noexcept
|
||||
{
|
||||
if (mwmp::Networking::getPtr()->getMasterClient())
|
||||
|
@ -102,6 +107,11 @@ void ServerFunctions::SetPluginEnforcementState(bool state) noexcept
|
|||
mwmp::Networking::getPtr()->setPluginEnforcementState(state);
|
||||
}
|
||||
|
||||
void ServerFunctions::SetScriptErrorIgnoringState(bool state) noexcept
|
||||
{
|
||||
mwmp::Networking::getPtr()->setScriptErrorIgnoringState(state);
|
||||
}
|
||||
|
||||
void ServerFunctions::SetRuleString(const char *key, const char *value) noexcept
|
||||
{
|
||||
auto mc = mwmp::Networking::getPtr()->getMasterClient();
|
||||
|
|
|
@ -18,11 +18,13 @@
|
|||
{"GetPort", ServerFunctions::GetPort},\
|
||||
{"HasPassword", ServerFunctions::HasPassword},\
|
||||
{"GetPluginEnforcementState", ServerFunctions::GetPluginEnforcementState},\
|
||||
{"GetScriptErrorIgnoringState", ServerFunctions::GetScriptErrorIgnoringState},\
|
||||
\
|
||||
{"SetGameMode", ServerFunctions::SetGameMode},\
|
||||
{"SetHostname", ServerFunctions::SetHostname},\
|
||||
{"SetServerPassword", ServerFunctions::SetServerPassword},\
|
||||
{"SetPluginEnforcementState", ServerFunctions::SetPluginEnforcementState},\
|
||||
{"SetScriptErrorIgnoringState", ServerFunctions::SetScriptErrorIgnoringState},\
|
||||
{"SetRuleString", ServerFunctions::SetRuleString},\
|
||||
{"SetRuleValue", ServerFunctions::SetRuleValue},\
|
||||
{"AddPluginHash", ServerFunctions::AddPluginHash}
|
||||
|
@ -121,7 +123,16 @@ public:
|
|||
*
|
||||
* \return The enforcement state.
|
||||
*/
|
||||
static int GetPluginEnforcementState() noexcept;
|
||||
static bool GetPluginEnforcementState() noexcept;
|
||||
|
||||
/**
|
||||
* \brief Get the script error ignoring state of the server.
|
||||
*
|
||||
* If true, script errors will not crash the server.
|
||||
*
|
||||
* \return The script error ignoring state.
|
||||
*/
|
||||
static bool GetScriptErrorIgnoringState() noexcept;
|
||||
|
||||
/**
|
||||
* \brief Set the game mode of the server, as displayed in the server browser.
|
||||
|
@ -157,6 +168,18 @@ public:
|
|||
*/
|
||||
static void SetPluginEnforcementState(bool state) noexcept;
|
||||
|
||||
/**
|
||||
* \brief Set whether script errors should be ignored or not.
|
||||
*
|
||||
* If true, script errors will not crash the server, but could have any number
|
||||
* of unforeseen consequences, which is why this is a highly experimental
|
||||
* setting.
|
||||
*
|
||||
* \param state The new script error ignoring state.
|
||||
* \return void
|
||||
*/
|
||||
static void SetScriptErrorIgnoringState(bool state) noexcept;
|
||||
|
||||
/**
|
||||
* \brief Set a rule string for the server details displayed in the server browser.
|
||||
*
|
||||
|
|
|
@ -4,15 +4,18 @@
|
|||
|
||||
#ifndef PLUGINSYSTEM3_SCRIPT_HPP
|
||||
#define PLUGINSYSTEM3_SCRIPT_HPP
|
||||
|
||||
#include <boost/any.hpp>
|
||||
#include <unordered_map>
|
||||
#include <memory>
|
||||
|
||||
#include "Types.hpp"
|
||||
#include "SystemInterface.hpp"
|
||||
#include "ScriptFunction.hpp"
|
||||
#include "ScriptFunctions.hpp"
|
||||
#include "Language.hpp"
|
||||
|
||||
#include <boost/any.hpp>
|
||||
#include <unordered_map>
|
||||
#include <memory>
|
||||
#include "Networking.hpp"
|
||||
|
||||
class Script : private ScriptFunctions
|
||||
{
|
||||
|
@ -98,6 +101,8 @@ public:
|
|||
catch (std::exception &e)
|
||||
{
|
||||
LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, e.what());
|
||||
|
||||
if (!mwmp::Networking::getPtr()->getScriptErrorIgnoringState())
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue