[Server] Add experimental option for not crashing from Lua script errors

Additionally, fix return type of GetPluginEnforcementState()
pull/492/head
David Cernat 6 years ago
parent b39e3f518b
commit b7090b2550

@ -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,7 +101,9 @@ public:
catch (std::exception &e)
{
LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, e.what());
throw;
if (!mwmp::Networking::getPtr()->getScriptErrorIgnoringState())
throw;
}
}
#endif

Loading…
Cancel
Save