Skip to content

Commit f38797a

Browse files
committed
feature: BEAMMP_PROVIDER_DISABLE_MP_SET environment variable
1 parent 9fa9974 commit f38797a

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

include/Env.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ enum class Key {
2626
// provider settings
2727
PROVIDER_UPDATE_MESSAGE,
2828
PROVIDER_DISABLE_CONFIG,
29+
PROVIDER_DISABLE_MP_SET,
2930
PROVIDER_PORT_ENV,
3031
PROVIDER_IP_ENV
3132
};

src/Env.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ std::string_view Env::ToString(Env::Key key) {
3636
case Key::PROVIDER_DISABLE_CONFIG:
3737
return "BEAMMP_PROVIDER_DISABLE_CONFIG";
3838
break;
39+
case Key::PROVIDER_DISABLE_MP_SET:
40+
return "BEAMMP_PROVIDER_DISABLE_MP_SET";
41+
break;
3942
case Key::PROVIDER_PORT_ENV:
4043
return "BEAMMP_PROVIDER_PORT_ENV";
4144
break;

src/TLuaEngine.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "CustomAssert.h"
2323
#include "Http.h"
2424
#include "LuaAPI.h"
25+
#include "Env.h"
2526
#include "Profiling.h"
2627
#include "TLuaPlugin.h"
2728
#include "sol/object.hpp"
@@ -733,6 +734,25 @@ static void AddToTable(sol::table& table, const std::string& left, const T& valu
733734
}
734735
}
735736

737+
static bool mDisableMPSet = [] {
738+
auto DisableMPSet = Env::Get(Env::Key::PROVIDER_DISABLE_MP_SET).value_or("false");
739+
return DisableMPSet == "true" || DisableMPSet == "1";
740+
}();
741+
742+
static auto GetSettingName = [](int id) -> const char* {
743+
switch (id) {
744+
case 0: return "Debug";
745+
case 1: return "Private";
746+
case 2: return "MaxCars";
747+
case 3: return "MaxPlayers";
748+
case 4: return "Map";
749+
case 5: return "Name";
750+
case 6: return "Description";
751+
case 7: return "InformationPacket";
752+
default: return "Unknown";
753+
}
754+
};
755+
736756
static void JsonDecodeRecursive(sol::state_view& StateView, sol::table& table, const std::string& left, const nlohmann::json& right) {
737757
switch (right.type()) {
738758
case nlohmann::detail::value_t::null:
@@ -925,7 +945,13 @@ TLuaEngine::StateThreadData::StateThreadData(const std::string& Name, TLuaStateI
925945
MPTable.set_function("CancelEventTimer", [&](const std::string& EventName) {
926946
mEngine->CancelEventTimers(EventName, mStateId);
927947
});
928-
MPTable.set_function("Set", &LuaAPI::MP::Set);
948+
if (mDisableMPSet) {
949+
MPTable.set_function("Set", [this](int ConfigID, sol::object NewValue) {
950+
beammp_lua_errorf("A script ({}) tried to call MP.Set to change setting '{}' but this was blocked by your server provider.", mStateId, GetSettingName(ConfigID));
951+
});
952+
} else {
953+
MPTable.set_function("Set", &LuaAPI::MP::Set);
954+
}
929955
MPTable.set_function("Get", &LuaAPI::MP::Get);
930956

931957
auto UtilTable = StateView.create_named_table("Util");

0 commit comments

Comments
 (0)