From 956d6f50e1a188b719b7dcf7b5ff83a7b578152c Mon Sep 17 00:00:00 2001 From: Tixx <83774803+WiserTixx@users.noreply.github.com> Date: Sun, 13 Oct 2024 23:32:15 +0200 Subject: [PATCH] Add setting for the information packet --- include/Settings.h | 3 ++- src/LuaAPI.cpp | 10 ++++++++++ src/Settings.cpp | 2 ++ src/TLuaEngine.cpp | 3 ++- src/TNetwork.cpp | 2 +- 5 files changed, 17 insertions(+), 3 deletions(-) diff --git a/include/Settings.h b/include/Settings.h index 1ef8ea1..3034c1c 100644 --- a/include/Settings.h +++ b/include/Settings.h @@ -86,7 +86,8 @@ struct Settings { General_LogChat, General_ResourceFolder, General_Debug, - General_AllowGuests + General_AllowGuests, + General_InformationPacket, }; Sync> SettingsMap; diff --git a/src/LuaAPI.cpp b/src/LuaAPI.cpp index 582da46..4da07b3 100644 --- a/src/LuaAPI.cpp +++ b/src/LuaAPI.cpp @@ -317,6 +317,14 @@ void LuaAPI::MP::Set(int ConfigID, sol::object NewValue) { beammp_lua_error("set invalid argument [2] expected string"); } break; + case 7: // Information packet + if (NewValue.is()) { + Application::Settings.set(Settings::Key::General_InformationPacket, NewValue.as()); + beammp_info(std::string("Set `InformationPacket` to ") + (Application::Settings.getAsBool(Settings::Key::General_InformationPacket) ? "true" : "false")); + } else { + beammp_lua_error("set invalid argument [2] expected boolean"); + } + break; default: beammp_warn("Invalid config ID \"" + std::to_string(ConfigID) + "\". Use `MP.Settings.*` enum for this."); break; @@ -339,6 +347,8 @@ TLuaValue LuaAPI::MP::Get(int ConfigID) { return Application::Settings.getAsString(Settings::Key::General_Name); case 6: // Desc return Application::Settings.getAsString(Settings::Key::General_Description); + case 7: // Information packet + return Application::Settings.getAsBool(Settings::Key::General_InformationPacket); default: beammp_warn("Invalid config ID \"" + std::to_string(ConfigID) + "\". Use `MP.Settings.*` enum for this."); return 0; diff --git a/src/Settings.cpp b/src/Settings.cpp index a82a66b..d2393cd 100644 --- a/src/Settings.cpp +++ b/src/Settings.cpp @@ -34,6 +34,7 @@ Settings::Settings() { { General_ResourceFolder, std::string("Resources") }, { General_Debug, false }, { General_AllowGuests, true }, + { General_InformationPacket, true }, { Misc_SendErrorsShowMessage, true }, { Misc_SendErrors, true }, { Misc_ImScaredOfUpdates, true }, @@ -54,6 +55,7 @@ Settings::Settings() { { { "General", "ResourceFolder" }, { General_ResourceFolder, READ_ONLY } }, { { "General", "Debug" }, { General_Debug, READ_WRITE } }, { { "General", "AllowGuests" }, { General_AllowGuests, READ_WRITE } }, + { { "General", "InformationPacket" }, { General_InformationPacket, READ_WRITE } }, { { "Misc", "SendErrorsShowMessage" }, { Misc_SendErrorsShowMessage, READ_WRITE } }, { { "Misc", "SendErrors" }, { Misc_SendErrors, READ_WRITE } }, { { "Misc", "ImScaredOfUpdates" }, { Misc_ImScaredOfUpdates, READ_WRITE } }, diff --git a/src/TLuaEngine.cpp b/src/TLuaEngine.cpp index 42440b1..fb3f4c6 100644 --- a/src/TLuaEngine.cpp +++ b/src/TLuaEngine.cpp @@ -1024,7 +1024,8 @@ TLuaEngine::StateThreadData::StateThreadData(const std::string& Name, TLuaStateI "MaxPlayers", 3, "Map", 4, "Name", 5, - "Description", 6); + "Description", 6, + "InformationPacket", 7); MPTable.create_named("CallStrategy", "BestEffort", CallStrategy::BestEffort, diff --git a/src/TNetwork.cpp b/src/TNetwork.cpp index 6ef9a15..6fc0b87 100644 --- a/src/TNetwork.cpp +++ b/src/TNetwork.cpp @@ -249,7 +249,7 @@ void TNetwork::Identify(TConnection&& RawConnection) { return; } else if (Code == 'I') { boost::system::error_code ec; - write(RawConnection.Socket, buffer(THeartbeatThread::lastCall), ec); + write(RawConnection.Socket, buffer(Application::Settings.getAsBool(Settings::Key::General_InformationPacket) ? THeartbeatThread::lastCall : ""), ec); } else { beammp_errorf("Invalid code got in Identify: '{}'", Code); }