Skip to content

Commit 626f01e

Browse files
committed
add: better feedback messages for DisableMPSet
1 parent 4d357d8 commit 626f01e

File tree

2 files changed

+29
-26
lines changed

2 files changed

+29
-26
lines changed

src/LuaAPI.cpp

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include "CustomAssert.h"
2323
#include "Settings.h"
2424
#include "TLuaEngine.h"
25-
#include "Env.h"
2625

2726
#include <nlohmann/json.hpp>
2827

@@ -307,31 +306,7 @@ std::pair<bool, std::string> LuaAPI::MP::RemoveVehicle(int PID, int VID) {
307306
return Result;
308307
}
309308

310-
static bool mDisableMPSet = [] {
311-
auto DisableMPSet = Env::Get(Env::Key::PROVIDER_DISABLE_MP_SET).value_or("false");
312-
return DisableMPSet == "true" || DisableMPSet == "1";
313-
}();
314-
315-
static auto GetSettingName = [](int id) -> const char* {
316-
switch (id) {
317-
case 0: return "Debug";
318-
case 1: return "Private";
319-
case 2: return "MaxCars";
320-
case 3: return "MaxPlayers";
321-
case 4: return "Map";
322-
case 5: return "Name";
323-
case 6: return "Description";
324-
case 7: return "InformationPacket";
325-
default: return "Unknown";
326-
}
327-
};
328-
329309
void LuaAPI::MP::Set(int ConfigID, sol::object NewValue) {
330-
if (mDisableMPSet) {
331-
beammp_lua_errorf("A script tried to call MP.Set to change setting '{}' but this was blocked by your server provider.", GetSettingName(ConfigID));
332-
return;
333-
}
334-
335310
switch (ConfigID) {
336311
case 0: // debug
337312
if (NewValue.is<bool>()) {

src/TLuaEngine.cpp

Lines changed: 29 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,15 @@ 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+
949+
if (mDisableMPSet) {
950+
MPTable.set_function("Set", [this](int ConfigID, sol::object NewValue){
951+
beammp_lua_errorf("A script ({}) tried to call MP.Set to change setting '{}' but this was blocked by your server provider.", mStateId, GetSettingName(ConfigID));
952+
});
953+
} else {
954+
MPTable.set_function("Set", &LuaAPI::MP::Set);
955+
}
956+
929957
MPTable.set_function("Get", &LuaAPI::MP::Get);
930958

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

0 commit comments

Comments
 (0)