|
22 | 22 | #include "CustomAssert.h" |
23 | 23 | #include "Http.h" |
24 | 24 | #include "LuaAPI.h" |
| 25 | +#include "Env.h" |
25 | 26 | #include "Profiling.h" |
26 | 27 | #include "TLuaPlugin.h" |
27 | 28 | #include "sol/object.hpp" |
@@ -733,6 +734,25 @@ static void AddToTable(sol::table& table, const std::string& left, const T& valu |
733 | 734 | } |
734 | 735 | } |
735 | 736 |
|
| 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 | + |
736 | 756 | static void JsonDecodeRecursive(sol::state_view& StateView, sol::table& table, const std::string& left, const nlohmann::json& right) { |
737 | 757 | switch (right.type()) { |
738 | 758 | case nlohmann::detail::value_t::null: |
@@ -925,7 +945,13 @@ TLuaEngine::StateThreadData::StateThreadData(const std::string& Name, TLuaStateI |
925 | 945 | MPTable.set_function("CancelEventTimer", [&](const std::string& EventName) { |
926 | 946 | mEngine->CancelEventTimers(EventName, mStateId); |
927 | 947 | }); |
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 | + } |
929 | 955 | MPTable.set_function("Get", &LuaAPI::MP::Get); |
930 | 956 |
|
931 | 957 | auto UtilTable = StateView.create_named_table("Util"); |
|
0 commit comments