mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-10-26 05:50:14 +00:00
Refactor all references to settings to use new Settings type
Signed-off-by: Lucca Jiménez Könings <development@jimkoen.com>
This commit is contained in:
13 files changed
+168
-243
No files matched your search
+4
-5
@@ -102,8 +102,7 @@ public:
|
|||||||
static std::string PPS() { return mPPS; }
|
static std::string PPS() { return mPPS; }
|
||||||
static void SetPPS(const std::string& NewPPS) { mPPS = NewPPS; }
|
static void SetPPS(const std::string& NewPPS) { mPPS = NewPPS; }
|
||||||
|
|
||||||
static TSettings Settings;
|
static inline struct Settings Settings { };
|
||||||
static inline struct Settings SettingsSingleton { };
|
|
||||||
|
|
||||||
static std::vector<std::string> GetBackendUrlsInOrder() {
|
static std::vector<std::string> GetBackendUrlsInOrder() {
|
||||||
return {
|
return {
|
||||||
@@ -225,13 +224,13 @@ void RegisterThread(const std::string& str);
|
|||||||
#define luaprint(x) Application::Console().Write(_this_location + std::string("[LUA] ") + (x))
|
#define luaprint(x) Application::Console().Write(_this_location + std::string("[LUA] ") + (x))
|
||||||
#define beammp_debug(x) \
|
#define beammp_debug(x) \
|
||||||
do { \
|
do { \
|
||||||
if (Application::Settings.DebugModeEnabled) { \
|
if (Application::Settings.getAsBool(Settings::Key::General_Debug)) { \
|
||||||
Application::Console().Write(_this_location + std::string("[DEBUG] ") + (x)); \
|
Application::Console().Write(_this_location + std::string("[DEBUG] ") + (x)); \
|
||||||
} \
|
} \
|
||||||
} while (false)
|
} while (false)
|
||||||
#define beammp_event(x) \
|
#define beammp_event(x) \
|
||||||
do { \
|
do { \
|
||||||
if (Application::Settings.DebugModeEnabled) { \
|
if (Application::Settings.getAsBool(Settings::Key::General_Debug)) { \
|
||||||
Application::Console().Write(_this_location + std::string("[EVENT] ") + (x)); \
|
Application::Console().Write(_this_location + std::string("[EVENT] ") + (x)); \
|
||||||
} \
|
} \
|
||||||
} while (false)
|
} while (false)
|
||||||
@@ -239,7 +238,7 @@ void RegisterThread(const std::string& str);
|
|||||||
#if defined(DEBUG)
|
#if defined(DEBUG)
|
||||||
#define beammp_trace(x) \
|
#define beammp_trace(x) \
|
||||||
do { \
|
do { \
|
||||||
if (Application::Settings.DebugModeEnabled) { \
|
if (Application::Settings.getAsBool(Settings::Key::General_Debug)) { \
|
||||||
Application::Console().Write(_this_location + std::string("[TRACE] ") + (x)); \
|
Application::Console().Write(_this_location + std::string("[TRACE] ") + (x)); \
|
||||||
} \
|
} \
|
||||||
} while (false)
|
} while (false)
|
||||||
|
|||||||
+5
-5
@@ -17,6 +17,7 @@
|
|||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include "Sync.h"
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <fmt/core.h>
|
#include <fmt/core.h>
|
||||||
#include <fmt/format.h>
|
#include <fmt/format.h>
|
||||||
@@ -24,7 +25,6 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
#include "Sync.h"
|
|
||||||
|
|
||||||
struct ComposedKey {
|
struct ComposedKey {
|
||||||
std::string Category;
|
std::string Category;
|
||||||
@@ -83,9 +83,9 @@ struct Settings {
|
|||||||
General_Debug
|
General_Debug
|
||||||
};
|
};
|
||||||
|
|
||||||
Sync<std::unordered_map<Key, SettingsTypeVariant>> SettingsMap = std::unordered_map<Key, SettingsTypeVariant>{
|
Sync<std::unordered_map<Key, SettingsTypeVariant>> SettingsMap = std::unordered_map<Key, SettingsTypeVariant> {
|
||||||
{ General_Description, "BeamMP Default Description" },
|
{ General_Description, std::string("BeamMP Default Description") },
|
||||||
{ General_Tags, "Freeroam" },
|
{ General_Tags, std::string("Freeroam") },
|
||||||
{ General_MaxPlayers, 8 },
|
{ General_MaxPlayers, 8 },
|
||||||
{ General_Name, "BeamMP Server" },
|
{ General_Name, "BeamMP Server" },
|
||||||
{ General_Map, "/levels/gridmap_v2/info.json" },
|
{ General_Map, "/levels/gridmap_v2/info.json" },
|
||||||
@@ -112,7 +112,7 @@ struct Settings {
|
|||||||
SettingsAccessMask // Console read/write permissions
|
SettingsAccessMask // Console read/write permissions
|
||||||
>;
|
>;
|
||||||
|
|
||||||
Sync<std::unordered_map<ComposedKey, SettingsAccessControl>> InputAccessMapping = std::unordered_map<ComposedKey, SettingsAccessControl>{
|
Sync<std::unordered_map<ComposedKey, SettingsAccessControl>> InputAccessMapping = std::unordered_map<ComposedKey, SettingsAccessControl> {
|
||||||
{ { "General", "Description" }, { General_Description, write } },
|
{ { "General", "Description" }, { General_Description, write } },
|
||||||
{ { "General", "Tags" }, { General_Tags, write } },
|
{ { "General", "Tags" }, { General_Tags, write } },
|
||||||
{ { "General", "MaxPlayers" }, { General_MaxPlayers, write } },
|
{ { "General", "MaxPlayers" }, { General_MaxPlayers, write } },
|
||||||
|
|||||||
+7
-9
@@ -33,8 +33,6 @@
|
|||||||
#include "CustomAssert.h"
|
#include "CustomAssert.h"
|
||||||
#include "Http.h"
|
#include "Http.h"
|
||||||
|
|
||||||
Application::TSettings Application::Settings = {};
|
|
||||||
|
|
||||||
void Application::RegisterShutdownHandler(const TShutdownHandler& Handler) {
|
void Application::RegisterShutdownHandler(const TShutdownHandler& Handler) {
|
||||||
std::unique_lock Lock(mShutdownHandlersMutex);
|
std::unique_lock Lock(mShutdownHandlersMutex);
|
||||||
if (Handler) {
|
if (Handler) {
|
||||||
@@ -256,7 +254,7 @@ static std::mutex ThreadNameMapMutex {};
|
|||||||
|
|
||||||
std::string ThreadName(bool DebugModeOverride) {
|
std::string ThreadName(bool DebugModeOverride) {
|
||||||
auto Lock = std::unique_lock(ThreadNameMapMutex);
|
auto Lock = std::unique_lock(ThreadNameMapMutex);
|
||||||
if (DebugModeOverride || Application::Settings.DebugModeEnabled) {
|
if (DebugModeOverride || Application::Settings.getAsBool(Settings::Key::General_Debug)) {
|
||||||
auto id = std::this_thread::get_id();
|
auto id = std::this_thread::get_id();
|
||||||
if (threadNameMap.find(id) != threadNameMap.end()) {
|
if (threadNameMap.find(id) != threadNameMap.end()) {
|
||||||
// found
|
// found
|
||||||
@@ -268,21 +266,21 @@ std::string ThreadName(bool DebugModeOverride) {
|
|||||||
|
|
||||||
TEST_CASE("ThreadName") {
|
TEST_CASE("ThreadName") {
|
||||||
RegisterThread("MyThread");
|
RegisterThread("MyThread");
|
||||||
auto OrigDebug = Application::Settings.DebugModeEnabled;
|
auto OrigDebug = Application::Settings.getAsBool(Settings::Key::General_Debug);
|
||||||
|
|
||||||
// ThreadName adds a space at the end, legacy but we need it still
|
// ThreadName adds a space at the end, legacy but we need it still
|
||||||
SUBCASE("Debug mode enabled") {
|
SUBCASE("Debug mode enabled") {
|
||||||
Application::Settings.DebugModeEnabled = true;
|
Application::Settings.set(Settings::Key::General_Debug, true);
|
||||||
CHECK(ThreadName(true) == "MyThread ");
|
CHECK(ThreadName(true) == "MyThread ");
|
||||||
CHECK(ThreadName(false) == "MyThread ");
|
CHECK(ThreadName(false) == "MyThread ");
|
||||||
}
|
}
|
||||||
SUBCASE("Debug mode disabled") {
|
SUBCASE("Debug mode disabled") {
|
||||||
Application::Settings.DebugModeEnabled = false;
|
Application::Settings.set(Settings::Key::General_Debug, false);
|
||||||
CHECK(ThreadName(true) == "MyThread ");
|
CHECK(ThreadName(true) == "MyThread ");
|
||||||
CHECK(ThreadName(false) == "");
|
CHECK(ThreadName(false) == "");
|
||||||
}
|
}
|
||||||
// cleanup
|
// cleanup
|
||||||
Application::Settings.DebugModeEnabled = OrigDebug;
|
Application::Settings.set(Settings::Key::General_Debug, OrigDebug);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegisterThread(const std::string& str) {
|
void RegisterThread(const std::string& str) {
|
||||||
@@ -296,7 +294,7 @@ void RegisterThread(const std::string& str) {
|
|||||||
#elif defined(BEAMMP_FREEBSD)
|
#elif defined(BEAMMP_FREEBSD)
|
||||||
ThreadId = std::to_string(getpid());
|
ThreadId = std::to_string(getpid());
|
||||||
#endif
|
#endif
|
||||||
if (Application::Settings.DebugModeEnabled) {
|
if (Application::Settings.getAsBool(Settings::Key::General_Debug)) {
|
||||||
std::ofstream ThreadFile(".Threads.log", std::ios::app);
|
std::ofstream ThreadFile(".Threads.log", std::ios::app);
|
||||||
ThreadFile << ("Thread \"" + str + "\" is TID " + ThreadId) << std::endl;
|
ThreadFile << ("Thread \"" + str + "\" is TID " + ThreadId) << std::endl;
|
||||||
}
|
}
|
||||||
@@ -329,7 +327,7 @@ TEST_CASE("Version::AsString") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void LogChatMessage(const std::string& name, int id, const std::string& msg) {
|
void LogChatMessage(const std::string& name, int id, const std::string& msg) {
|
||||||
if (Application::Settings.LogChat) {
|
if (Application::Settings.getAsBool(Settings::Key::General_LogChat)) {
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << ThreadName();
|
ss << ThreadName();
|
||||||
ss << "[CHAT] ";
|
ss << "[CHAT] ";
|
||||||
|
|||||||
+1
-1
@@ -61,7 +61,7 @@ TEST_CASE("init and reset termios") {
|
|||||||
CHECK_EQ(current.c_lflag, original.c_lflag);
|
CHECK_EQ(current.c_lflag, original.c_lflag);
|
||||||
#ifndef BEAMMP_FREEBSD // The 'c_line' attribute seems to only exist on Linux, so we need to omit it on other platforms
|
#ifndef BEAMMP_FREEBSD // The 'c_line' attribute seems to only exist on Linux, so we need to omit it on other platforms
|
||||||
CHECK_EQ(current.c_line, original.c_line);
|
CHECK_EQ(current.c_line, original.c_line);
|
||||||
#endif
|
#endif
|
||||||
CHECK_EQ(current.c_oflag, original.c_oflag);
|
CHECK_EQ(current.c_oflag, original.c_oflag);
|
||||||
CHECK_EQ(current.c_ospeed, original.c_ospeed);
|
CHECK_EQ(current.c_ospeed, original.c_ospeed);
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-14
@@ -21,6 +21,7 @@
|
|||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
#include "CustomAssert.h"
|
#include "CustomAssert.h"
|
||||||
#include "TLuaEngine.h"
|
#include "TLuaEngine.h"
|
||||||
|
#include "TSettings.h"
|
||||||
|
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
@@ -226,56 +227,56 @@ void LuaAPI::MP::Set(int ConfigID, sol::object NewValue) {
|
|||||||
switch (ConfigID) {
|
switch (ConfigID) {
|
||||||
case 0: // debug
|
case 0: // debug
|
||||||
if (NewValue.is<bool>()) {
|
if (NewValue.is<bool>()) {
|
||||||
Application::Settings.DebugModeEnabled = NewValue.as<bool>();
|
Application::Settings.set(Settings::Key::General_Debug, NewValue.as<bool>());
|
||||||
beammp_info(std::string("Set `Debug` to ") + (Application::Settings.DebugModeEnabled ? "true" : "false"));
|
beammp_info(std::string("Set `Debug` to ") + (Application::Settings.getAsBool(Settings::Key::General_Debug) ? "true" : "false"));
|
||||||
} else {
|
} else {
|
||||||
beammp_lua_error("set invalid argument [2] expected boolean");
|
beammp_lua_error("set invalid argument [2] expected boolean");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 1: // private
|
case 1: // private
|
||||||
if (NewValue.is<bool>()) {
|
if (NewValue.is<bool>()) {
|
||||||
Application::Settings.Private = NewValue.as<bool>();
|
Application::Settings.set(Settings::Key::General_Private, NewValue.as<bool>());
|
||||||
beammp_info(std::string("Set `Private` to ") + (Application::Settings.Private ? "true" : "false"));
|
beammp_info(std::string("Set `Private` to ") + (Application::Settings.getAsBool(Settings::Key::General_Private) ? "true" : "false"));
|
||||||
} else {
|
} else {
|
||||||
beammp_lua_error("set invalid argument [2] expected boolean");
|
beammp_lua_error("set invalid argument [2] expected boolean");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 2: // max cars
|
case 2: // max cars
|
||||||
if (NewValue.is<int>()) {
|
if (NewValue.is<int>()) {
|
||||||
Application::Settings.MaxCars = NewValue.as<int>();
|
Application::Settings.set(Settings::Key::General_MaxCars, NewValue.as<int>());
|
||||||
beammp_info(std::string("Set `MaxCars` to ") + std::to_string(Application::Settings.MaxCars));
|
beammp_info(std::string("Set `MaxCars` to ") + std::to_string(Application::Settings.getAsInt(Settings::Key::General_MaxCars)));
|
||||||
} else {
|
} else {
|
||||||
beammp_lua_error("set invalid argument [2] expected integer");
|
beammp_lua_error("set invalid argument [2] expected integer");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 3: // max players
|
case 3: // max players
|
||||||
if (NewValue.is<int>()) {
|
if (NewValue.is<int>()) {
|
||||||
Application::Settings.MaxPlayers = NewValue.as<int>();
|
Application::Settings.set(Settings::Key::General_MaxPlayers, NewValue.as<int>());
|
||||||
beammp_info(std::string("Set `MaxPlayers` to ") + std::to_string(Application::Settings.MaxPlayers));
|
beammp_info(std::string("Set `MaxPlayers` to ") + std::to_string(Application::Settings.getAsInt(Settings::Key::General_MaxPlayers)));
|
||||||
} else {
|
} else {
|
||||||
beammp_lua_error("set invalid argument [2] expected integer");
|
beammp_lua_error("set invalid argument [2] expected integer");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 4: // Map
|
case 4: // Map
|
||||||
if (NewValue.is<std::string>()) {
|
if (NewValue.is<std::string>()) {
|
||||||
Application::Settings.MapName = NewValue.as<std::string>();
|
Application::Settings.set(Settings::Key::General_Map, NewValue.as<std::string>());
|
||||||
beammp_info(std::string("Set `Map` to ") + Application::Settings.MapName);
|
beammp_info(std::string("Set `Map` to ") + Application::Settings.getAsString(Settings::Key::General_Map));
|
||||||
} else {
|
} else {
|
||||||
beammp_lua_error("set invalid argument [2] expected string");
|
beammp_lua_error("set invalid argument [2] expected string");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 5: // Name
|
case 5: // Name
|
||||||
if (NewValue.is<std::string>()) {
|
if (NewValue.is<std::string>()) {
|
||||||
Application::Settings.ServerName = NewValue.as<std::string>();
|
Application::Settings.set(Settings::Key::General_Name, NewValue.as<std::string>());
|
||||||
beammp_info(std::string("Set `Name` to ") + Application::Settings.ServerName);
|
beammp_info(std::string("Set `Name` to ") + Application::Settings.getAsString(Settings::Key::General_Name));
|
||||||
} else {
|
} else {
|
||||||
beammp_lua_error("set invalid argument [2] expected string");
|
beammp_lua_error("set invalid argument [2] expected string");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 6: // Desc
|
case 6: // Desc
|
||||||
if (NewValue.is<std::string>()) {
|
if (NewValue.is<std::string>()) {
|
||||||
Application::Settings.ServerDesc = NewValue.as<std::string>();
|
Application::Settings.set(Settings::Key::General_Description, NewValue.as<std::string>());
|
||||||
beammp_info(std::string("Set `Description` to ") + Application::Settings.ServerDesc);
|
beammp_info(std::string("Set `Description` to ") + Application::Settings.getAsString(Settings::Key::General_Description));
|
||||||
} else {
|
} else {
|
||||||
beammp_lua_error("set invalid argument [2] expected string");
|
beammp_lua_error("set invalid argument [2] expected string");
|
||||||
}
|
}
|
||||||
|
|||||||
+65
-132
@@ -20,11 +20,14 @@
|
|||||||
|
|
||||||
#include "Env.h"
|
#include "Env.h"
|
||||||
#include "TConfig.h"
|
#include "TConfig.h"
|
||||||
|
#include "TSettings.h"
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <exception>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <istream>
|
#include <istream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
// General
|
// General
|
||||||
static constexpr std::string_view StrDebug = "Debug";
|
static constexpr std::string_view StrDebug = "Debug";
|
||||||
@@ -120,29 +123,29 @@ void SetComment(CommentsT& Comments, const std::string& Comment) {
|
|||||||
void TConfig::FlushToFile() {
|
void TConfig::FlushToFile() {
|
||||||
// auto data = toml::parse<toml::preserve_comments>(mConfigFileName);
|
// auto data = toml::parse<toml::preserve_comments>(mConfigFileName);
|
||||||
auto data = toml::value {};
|
auto data = toml::value {};
|
||||||
data["General"][StrAuthKey.data()] = Application::Settings.Key;
|
data["General"][StrAuthKey.data()] = Application::Settings.getAsString(Settings::Key::General_AuthKey);
|
||||||
SetComment(data["General"][StrAuthKey.data()].comments(), " AuthKey has to be filled out in order to run the server");
|
SetComment(data["General"][StrAuthKey.data()].comments(), " AuthKey has to be filled out in order to run the server");
|
||||||
data["General"][StrLogChat.data()] = Application::Settings.LogChat;
|
data["General"][StrLogChat.data()] = Application::Settings.getAsBool(Settings::Key::General_LogChat);
|
||||||
SetComment(data["General"][StrLogChat.data()].comments(), " Whether to log chat messages in the console / log");
|
SetComment(data["General"][StrLogChat.data()].comments(), " Whether to log chat messages in the console / log");
|
||||||
data["General"][StrDebug.data()] = Application::Settings.DebugModeEnabled;
|
data["General"][StrDebug.data()] = Application::Settings.getAsBool(Settings::Key::General_Debug);
|
||||||
data["General"][StrPrivate.data()] = Application::Settings.Private;
|
data["General"][StrPrivate.data()] = Application::Settings.getAsBool(Settings::Key::General_Private);
|
||||||
data["General"][StrPort.data()] = Application::Settings.Port;
|
data["General"][StrPort.data()] = Application::Settings.getAsInt(Settings::Key::General_Port);
|
||||||
data["General"][StrName.data()] = Application::Settings.ServerName;
|
data["General"][StrName.data()] = Application::Settings.getAsString(Settings::Key::General_Name);
|
||||||
SetComment(data["General"][StrTags.data()].comments(), " Add custom identifying tags to your server to make it easier to find. Format should be TagA,TagB,TagC. Note the comma seperation.");
|
SetComment(data["General"][StrTags.data()].comments(), " Add custom identifying tags to your server to make it easier to find. Format should be TagA,TagB,TagC. Note the comma seperation.");
|
||||||
data["General"][StrTags.data()] = Application::Settings.ServerTags;
|
data["General"][StrTags.data()] = Application::Settings.getAsString(Settings::Key::General_Tags);
|
||||||
data["General"][StrMaxCars.data()] = Application::Settings.MaxCars;
|
data["General"][StrMaxCars.data()] = Application::Settings.getAsInt(Settings::Key::General_MaxCars);
|
||||||
data["General"][StrMaxPlayers.data()] = Application::Settings.MaxPlayers;
|
data["General"][StrMaxPlayers.data()] = Application::Settings.getAsInt(Settings::Key::General_MaxCars);
|
||||||
data["General"][StrMap.data()] = Application::Settings.MapName;
|
data["General"][StrMap.data()] = Application::Settings.getAsString(Settings::Key::General_Map);
|
||||||
data["General"][StrDescription.data()] = Application::Settings.ServerDesc;
|
data["General"][StrDescription.data()] = Application::Settings.getAsString(Settings::Key::General_Description);
|
||||||
data["General"][StrResourceFolder.data()] = Application::Settings.Resource;
|
data["General"][StrResourceFolder.data()] = Application::Settings.getAsString(Settings::Key::General_ResourceFolder);
|
||||||
// data["General"][StrPassword.data()] = Application::Settings.Password;
|
// data["General"][StrPassword.data()] = Application::Settings.Password;
|
||||||
// SetComment(data["General"][StrPassword.data()].comments(), " Sets a password on this server, which restricts people from joining. To join, a player must enter this exact password. Leave empty ("") to disable the password.");
|
// SetComment(data["General"][StrPassword.data()].comments(), " Sets a password on this server, which restricts people from joining. To join, a player must enter this exact password. Leave empty ("") to disable the password.");
|
||||||
// Misc
|
// Misc
|
||||||
data["Misc"][StrHideUpdateMessages.data()] = Application::Settings.HideUpdateMessages;
|
data["Misc"][StrHideUpdateMessages.data()] = Application::Settings.getAsBool(Settings::Key::Misc_ImScaredOfUpdates);
|
||||||
SetComment(data["Misc"][StrHideUpdateMessages.data()].comments(), " Hides the periodic update message which notifies you of a new server version. You should really keep this on and always update as soon as possible. For more information visit https://wiki.beammp.com/en/home/server-maintenance#updating-the-server. An update message will always appear at startup regardless.");
|
SetComment(data["Misc"][StrHideUpdateMessages.data()].comments(), " Hides the periodic update message which notifies you of a new server version. You should really keep this on and always update as soon as possible. For more information visit https://wiki.beammp.com/en/home/server-maintenance#updating-the-server. An update message will always appear at startup regardless.");
|
||||||
data["Misc"][StrSendErrors.data()] = Application::Settings.SendErrors;
|
data["Misc"][StrSendErrors.data()] = Application::Settings.getAsBool(Settings::Key::Misc_SendErrors);
|
||||||
SetComment(data["Misc"][StrSendErrors.data()].comments(), " If SendErrors is `true`, the server will send helpful info about crashes and other issues back to the BeamMP developers. This info may include your config, who is on your server at the time of the error, and similar general information. This kind of data is vital in helping us diagnose and fix issues faster. This has no impact on server performance. You can opt-out of this system by setting this to `false`");
|
SetComment(data["Misc"][StrSendErrors.data()].comments(), " If SendErrors is `true`, the server will send helpful info about crashes and other issues back to the BeamMP developers. This info may include your config, who is on your server at the time of the error, and similar general information. This kind of data is vital in helping us diagnose and fix issues faster. This has no impact on server performance. You can opt-out of this system by setting this to `false`");
|
||||||
data["Misc"][StrSendErrorsMessageEnabled.data()] = Application::Settings.SendErrorsMessageEnabled;
|
data["Misc"][StrSendErrorsMessageEnabled.data()] = Application::Settings.getAsBool(Settings::Key::Misc_SendErrorsShowMessage);
|
||||||
SetComment(data["Misc"][StrSendErrorsMessageEnabled.data()].comments(), " You can turn on/off the SendErrors message you get on startup here");
|
SetComment(data["Misc"][StrSendErrorsMessageEnabled.data()].comments(), " You can turn on/off the SendErrors message you get on startup here");
|
||||||
std::stringstream Ss;
|
std::stringstream Ss;
|
||||||
Ss << "# This is the BeamMP-Server config file.\n"
|
Ss << "# This is the BeamMP-Server config file.\n"
|
||||||
@@ -190,76 +193,59 @@ overloaded(Ts...) -> overloaded<Ts...>;
|
|||||||
|
|
||||||
void TConfig::TryReadValue(toml::value& Table, const std::string& Category, const std::string_view& Key, const std::string_view& Env, Settings::Key key) {
|
void TConfig::TryReadValue(toml::value& Table, const std::string& Category, const std::string_view& Key, const std::string_view& Env, Settings::Key key) {
|
||||||
if (!Env.empty()) {
|
if (!Env.empty()) {
|
||||||
if (const char* envp = std::getenv(Env.data()); envp != nullptr && std::strcmp(envp, "") != 0) {
|
if (const char* envp = std::getenv(Env.data());
|
||||||
|
envp != nullptr && std::strcmp(envp, "") != 0) {
|
||||||
|
|
||||||
std::visit(
|
std::visit(
|
||||||
overloaded {
|
overloaded {
|
||||||
[&envp, &key](std::string) {
|
[&envp, &key](std::string) {
|
||||||
Application::SettingsSingleton.set(key, std::string(envp));
|
Application::Settings.set(key, std::string(envp));
|
||||||
},
|
},
|
||||||
[&envp, &key](int) {
|
[&envp, &key](int) {
|
||||||
Application::SettingsSingleton.set(key, int(std::strtol(envp, nullptr, 10)));
|
Application::Settings.set(key, int(std::strtol(envp, nullptr, 10)));
|
||||||
},
|
},
|
||||||
[&envp, &key](bool) {
|
[&envp, &key](bool) {
|
||||||
auto Str = std::string(envp);
|
auto Str = std::string(envp);
|
||||||
Application::SettingsSingleton.set(key, bool(Str == "1" || Str == "true"));
|
Application::Settings.set(key, bool(Str == "1" || Str == "true"));
|
||||||
} },
|
} },
|
||||||
Application::SettingsSingleton.get(key));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
|
|
||||||
std::visit(
|
Application::Settings.get(key));
|
||||||
overloaded {
|
return;
|
||||||
[&Table, &Category, &Key, &key](std::string) {
|
}
|
||||||
if (Table[Category.c_str()][Key.data()].is_string())
|
|
||||||
Application::SettingsSingleton.set(key, Table[Category.c_str()][Key.data()].as_string());
|
|
||||||
else
|
|
||||||
beammp_warnf("Value '{}.{}' has unexpected type, expected type 'string'", Category, Key);
|
|
||||||
},
|
|
||||||
[&Table, &Category, &Key, &key](int) {
|
|
||||||
if (Table[Category.c_str()][Key.data()].is_integer())
|
|
||||||
Application::SettingsSingleton.set(key, int(Table[Category.c_str()][Key.data()].as_integer()));
|
|
||||||
else
|
|
||||||
beammp_warnf("Value '{}.{}' has unexpected type, expected type 'integer'", Category, Key);
|
|
||||||
},
|
|
||||||
[&Table, &Category, &Key, &key](bool) {
|
|
||||||
if (Table[Category.c_str()][Key.data()].is_boolean())
|
|
||||||
Application::SettingsSingleton.set(key, Table[Category.c_str()][Key.data()].as_boolean());
|
|
||||||
else
|
|
||||||
beammp_warnf("Value '{}.{}' has unexpected type, expected type 'boolean'", Category, Key);
|
|
||||||
} },
|
|
||||||
Application::SettingsSingleton.get(key));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::visit([&Table, &Category, &Key, &key](auto&& arg) {
|
||||||
|
using T = std::decay_t<decltype(arg)>;
|
||||||
|
if constexpr (std::is_same_v<T, std::string>) {
|
||||||
|
if (Table[Category.c_str()][Key.data()].is_string())
|
||||||
|
Application::Settings.set(key, Table[Category.c_str()][Key.data()].as_string());
|
||||||
|
else
|
||||||
|
beammp_warnf("Value '{}.{}' has unexpected type, expected type 'string'", Category, Key);
|
||||||
|
} else if constexpr (std::is_same_v<T, int>) {
|
||||||
|
if (Table[Category.c_str()][Key.data()].is_integer())
|
||||||
|
Application::Settings.set(key, int(Table[Category.c_str()][Key.data()].as_integer()));
|
||||||
|
else
|
||||||
|
beammp_warnf("Value '{}.{}' has unexpected type, expected type 'integer'", Category, Key);
|
||||||
|
} else if constexpr (std::is_same_v<T, bool>) {
|
||||||
|
if (Table[Category.c_str()][Key.data()].is_boolean())
|
||||||
|
Application::Settings.set(key, Table[Category.c_str()][Key.data()].as_boolean());
|
||||||
|
else
|
||||||
|
beammp_warnf("Value '{}.{}' has unexpected type, expected type 'boolean'", Category, Key);
|
||||||
|
} else {
|
||||||
|
throw std::logic_error { "Invalid type for config value during read attempt" };
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Application::Settings.get(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TConfig::ParseFromFile(std::string_view name) {
|
void TConfig::ParseFromFile(std::string_view name) {
|
||||||
try {
|
try {
|
||||||
toml::value data {};
|
toml::value data {};
|
||||||
if (!mDisableConfig) {
|
if (!mDisableConfig) { // todo: rename mDisableCofig to configEnabled
|
||||||
data = toml::parse<toml::preserve_comments>(name.data());
|
data = toml::parse<toml::preserve_comments>(name.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
// GENERAL
|
// GENERAL
|
||||||
TryReadValue(data, "General", StrDebug, EnvStrDebug, Application::Settings.DebugModeEnabled);
|
|
||||||
TryReadValue(data, "General", StrPrivate, EnvStrPrivate, Application::Settings.Private);
|
|
||||||
if (Env::Get(Env::Key::PROVIDER_PORT_ENV).has_value()) {
|
|
||||||
TryReadValue(data, "General", StrPort, Env::Get(Env::Key::PROVIDER_PORT_ENV).value(), Application::Settings.Port);
|
|
||||||
} else {
|
|
||||||
TryReadValue(data, "General", StrPort, EnvStrPort, Application::Settings.Port);
|
|
||||||
}
|
|
||||||
TryReadValue(data, "General", StrMaxCars, EnvStrMaxCars, Application::Settings.MaxCars);
|
|
||||||
TryReadValue(data, "General", StrMaxPlayers, EnvStrMaxPlayers, Application::Settings.MaxPlayers);
|
|
||||||
TryReadValue(data, "General", StrMap, EnvStrMap, Application::Settings.MapName);
|
|
||||||
TryReadValue(data, "General", StrName, EnvStrName, Application::Settings.ServerName);
|
|
||||||
TryReadValue(data, "General", StrDescription, EnvStrDescription, Application::Settings.ServerDesc);
|
|
||||||
TryReadValue(data, "General", StrTags, EnvStrTags, Application::Settings.ServerTags);
|
|
||||||
TryReadValue(data, "General", StrResourceFolder, EnvStrResourceFolder, Application::Settings.Resource);
|
|
||||||
TryReadValue(data, "General", StrAuthKey, EnvStrAuthKey, Application::Settings.Key);
|
|
||||||
TryReadValue(data, "General", StrLogChat, EnvStrLogChat, Application::Settings.LogChat);
|
|
||||||
TryReadValue(data, "General", StrPassword, "", Application::Settings.Password);
|
|
||||||
// Misc
|
|
||||||
TryReadValue(data, "Misc", StrSendErrors, "", Application::Settings.SendErrors);
|
|
||||||
TryReadValue(data, "Misc", StrHideUpdateMessages, "", Application::Settings.HideUpdateMessages);
|
|
||||||
TryReadValue(data, "Misc", StrSendErrorsMessageEnabled, "", Application::Settings.SendErrorsMessageEnabled);
|
|
||||||
|
|
||||||
// Read into new Settings Singleton
|
// Read into new Settings Singleton
|
||||||
TryReadValue(data, "General", StrDebug, EnvStrDebug, Settings::Key::General_Debug);
|
TryReadValue(data, "General", StrDebug, EnvStrDebug, Settings::Key::General_Debug);
|
||||||
@@ -291,7 +277,7 @@ void TConfig::ParseFromFile(std::string_view name) {
|
|||||||
FlushToFile();
|
FlushToFile();
|
||||||
}
|
}
|
||||||
// all good so far, let's check if there's a key
|
// all good so far, let's check if there's a key
|
||||||
if (Application::Settings.Key.empty()) {
|
if (Application::Settings.getAsString(Settings::Key::General_AuthKey).empty()) {
|
||||||
if (mDisableConfig) {
|
if (mDisableConfig) {
|
||||||
beammp_error("No AuthKey specified in the environment.");
|
beammp_error("No AuthKey specified in the environment.");
|
||||||
} else {
|
} else {
|
||||||
@@ -302,7 +288,7 @@ void TConfig::ParseFromFile(std::string_view name) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Application::SetSubsystemStatus("Config", Application::Status::Good);
|
Application::SetSubsystemStatus("Config", Application::Status::Good);
|
||||||
if (Application::Settings.Key.size() != 36) {
|
if (Application::Settings.getAsString(Settings::Key::General_AuthKey).size() != 36) {
|
||||||
beammp_warn("AuthKey specified is the wrong length and likely isn't valid.");
|
beammp_warn("AuthKey specified is the wrong length and likely isn't valid.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -311,77 +297,24 @@ void TConfig::PrintDebug() {
|
|||||||
if (mDisableConfig) {
|
if (mDisableConfig) {
|
||||||
beammp_debug("Provider turned off the generation and parsing of the ServerConfig.toml");
|
beammp_debug("Provider turned off the generation and parsing of the ServerConfig.toml");
|
||||||
}
|
}
|
||||||
beammp_debug(std::string(StrDebug) + ": " + std::string(Application::Settings.DebugModeEnabled ? "true" : "false"));
|
beammp_debug(std::string(StrDebug) + ": " + std::string(Application::Settings.getAsBool(Settings::Key::General_Debug) ? "true" : "false"));
|
||||||
beammp_debug(std::string(StrPrivate) + ": " + std::string(Application::Settings.Private ? "true" : "false"));
|
beammp_debug(std::string(StrPrivate) + ": " + std::string(Application::Settings.getAsBool(Settings::Key::General_Private) ? "true" : "false"));
|
||||||
beammp_debug(std::string(StrPort) + ": " + std::to_string(Application::Settings.Port));
|
beammp_debug(std::string(StrPort) + ": " + std::to_string(Application::Settings.getAsInt(Settings::Key::General_Port)));
|
||||||
beammp_debug(std::string(StrMaxCars) + ": " + std::to_string(Application::Settings.MaxCars));
|
beammp_debug(std::string(StrMaxCars) + ": " + std::to_string(Application::Settings.getAsInt(Settings::Key::General_MaxCars)));
|
||||||
beammp_debug(std::string(StrMaxPlayers) + ": " + std::to_string(Application::Settings.MaxPlayers));
|
beammp_debug(std::string(StrMaxPlayers) + ": " + std::to_string(Application::Settings.getAsInt(Settings::Key::General_MaxPlayers)));
|
||||||
beammp_debug(std::string(StrMap) + ": \"" + Application::Settings.MapName + "\"");
|
beammp_debug(std::string(StrMap) + ": \"" + Application::Settings.getAsString(Settings::Key::General_Map) + "\"");
|
||||||
beammp_debug(std::string(StrName) + ": \"" + Application::Settings.ServerName + "\"");
|
beammp_debug(std::string(StrName) + ": \"" + Application::Settings.getAsString(Settings::Key::General_Name) + "\"");
|
||||||
beammp_debug(std::string(StrDescription) + ": \"" + Application::Settings.ServerDesc + "\"");
|
beammp_debug(std::string(StrDescription) + ": \"" + Application::Settings.getAsString(Settings::Key::General_Description) + "\"");
|
||||||
beammp_debug(std::string(StrTags) + ": " + TagsAsPrettyArray());
|
beammp_debug(std::string(StrTags) + ": " + TagsAsPrettyArray());
|
||||||
beammp_debug(std::string(StrLogChat) + ": \"" + (Application::Settings.LogChat ? "true" : "false") + "\"");
|
beammp_debug(std::string(StrLogChat) + ": \"" + (Application::Settings.getAsBool(Settings::Key::General_LogChat) ? "true" : "false") + "\"");
|
||||||
beammp_debug(std::string(StrResourceFolder) + ": \"" + Application::Settings.Resource + "\"");
|
beammp_debug(std::string(StrResourceFolder) + ": \"" + Application::Settings.getAsString(Settings::Key::General_ResourceFolder) + "\"");
|
||||||
// special!
|
// special!
|
||||||
beammp_debug("Key Length: " + std::to_string(Application::Settings.Key.length()) + "");
|
beammp_debug("Key Length: " + std::to_string(Application::Settings.getAsString(Settings::Key::General_AuthKey).length()) + "");
|
||||||
beammp_debug("Password Protected: " + std::string(Application::Settings.Password.empty() ? "false" : "true"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TConfig::ParseOldFormat() {
|
|
||||||
std::ifstream File("Server.cfg");
|
|
||||||
// read all, strip comments
|
|
||||||
std::string Content;
|
|
||||||
for (;;) {
|
|
||||||
std::string Line;
|
|
||||||
std::getline(File, Line);
|
|
||||||
if (!Line.empty() && Line.at(0) != '#') {
|
|
||||||
Line = Line.substr(0, Line.find_first_of('#'));
|
|
||||||
Content += Line + "\n";
|
|
||||||
}
|
|
||||||
if (!File.good()) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
std::stringstream Str(Content);
|
|
||||||
std::string Key, Ignore, Value;
|
|
||||||
for (;;) {
|
|
||||||
Str >> Key >> std::ws >> Ignore >> std::ws;
|
|
||||||
std::getline(Str, Value);
|
|
||||||
if (Str.eof()) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
std::stringstream ValueStream(Value);
|
|
||||||
ValueStream >> std::ws; // strip leading whitespace if any
|
|
||||||
Value = ValueStream.str();
|
|
||||||
if (Key == "Debug") {
|
|
||||||
Application::Settings.DebugModeEnabled = Value.find("true") != std::string::npos;
|
|
||||||
} else if (Key == "Private") {
|
|
||||||
Application::Settings.Private = Value.find("true") != std::string::npos;
|
|
||||||
} else if (Key == "Port") {
|
|
||||||
ValueStream >> Application::Settings.Port;
|
|
||||||
} else if (Key == "Cars") {
|
|
||||||
ValueStream >> Application::Settings.MaxCars;
|
|
||||||
} else if (Key == "MaxPlayers") {
|
|
||||||
ValueStream >> Application::Settings.MaxPlayers;
|
|
||||||
} else if (Key == "Map") {
|
|
||||||
Application::Settings.MapName = Value.substr(1, Value.size() - 3);
|
|
||||||
} else if (Key == "Name") {
|
|
||||||
Application::Settings.ServerName = Value.substr(1, Value.size() - 3);
|
|
||||||
} else if (Key == "Desc") {
|
|
||||||
Application::Settings.ServerDesc = Value.substr(1, Value.size() - 3);
|
|
||||||
} else if (Key == "use") {
|
|
||||||
Application::Settings.Resource = Value.substr(1, Value.size() - 3);
|
|
||||||
} else if (Key == "AuthKey") {
|
|
||||||
Application::Settings.Key = Value.substr(1, Value.size() - 3);
|
|
||||||
} else {
|
|
||||||
beammp_warn("unknown key in old auth file (ignored): " + Key);
|
|
||||||
}
|
|
||||||
Str >> std::ws;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
std::string TConfig::TagsAsPrettyArray() const {
|
std::string TConfig::TagsAsPrettyArray() const {
|
||||||
std::vector<std::string> TagsArray = {};
|
std::vector<std::string> TagsArray = {};
|
||||||
SplitString(Application::Settings.ServerTags, ',', TagsArray);
|
SplitString(Application::Settings.getAsString(Settings::General_Tags), ',', TagsArray);
|
||||||
std::string Pretty = {};
|
std::string Pretty = {};
|
||||||
for (size_t i = 0; i < TagsArray.size() - 1; ++i) {
|
for (size_t i = 0; i < TagsArray.size() - 1; ++i) {
|
||||||
Pretty += '\"' + TagsArray[i] + "\", ";
|
Pretty += '\"' + TagsArray[i] + "\", ";
|
||||||
|
|||||||
+41
-42
@@ -78,7 +78,7 @@ static std::string GetDate() {
|
|||||||
auto local_tm = std::localtime(&tt);
|
auto local_tm = std::localtime(&tt);
|
||||||
char buf[30];
|
char buf[30];
|
||||||
std::string date;
|
std::string date;
|
||||||
if (Application::Settings.DebugModeEnabled) {
|
if (Application::Settings.getAsBool(Settings::Key::General_Debug)) {
|
||||||
std::strftime(buf, sizeof(buf), "[%d/%m/%y %T.", local_tm);
|
std::strftime(buf, sizeof(buf), "[%d/%m/%y %T.", local_tm);
|
||||||
date += buf;
|
date += buf;
|
||||||
auto seconds = std::chrono::time_point_cast<std::chrono::seconds>(now);
|
auto seconds = std::chrono::time_point_cast<std::chrono::seconds>(now);
|
||||||
@@ -402,11 +402,10 @@ void TConsole::Command_Settings(const std::string&, const std::vector<std::strin
|
|||||||
Application::Console().WriteRaw("BeamMP-Server Console: " + std::string(sHelpString));
|
Application::Console().WriteRaw("BeamMP-Server Console: " + std::string(sHelpString));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Settings::SettingsAccessControl acl = Application::SettingsSingleton.getConsoleInputAccessMapping(ComposedKey(args.at(1), args.at(2)));
|
Settings::SettingsAccessControl acl = Application::Settings.getConsoleInputAccessMapping(ComposedKey(args.at(1), args.at(2)));
|
||||||
Settings::SettingsTypeVariant keyType = Application::SettingsSingleton.get(acl.first);
|
Settings::SettingsTypeVariant keyType = Application::Settings.get(acl.first);
|
||||||
|
|
||||||
std::visit(
|
std::visit(
|
||||||
overloaded {
|
overloaded {
|
||||||
@@ -437,28 +436,28 @@ void TConsole::Command_Settings(const std::string&, const std::vector<std::strin
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
Settings::SettingsAccessControl acl = Application::SettingsSingleton.getConsoleInputAccessMapping(ComposedKey(args.at(1), args.at(2)));
|
Settings::SettingsAccessControl acl = Application::Settings.getConsoleInputAccessMapping(ComposedKey(args.at(1), args.at(2)));
|
||||||
Settings::SettingsTypeVariant keyType = Application::SettingsSingleton.get(acl.first);
|
Settings::SettingsTypeVariant keyType = Application::Settings.get(acl.first);
|
||||||
|
|
||||||
std::visit(
|
std::visit(
|
||||||
overloaded {
|
overloaded {
|
||||||
[&args](std::string keyValue) {
|
[&args](std::string keyValue) {
|
||||||
Application::SettingsSingleton.setConsoleInputAccessMapping(ComposedKey(args.at(1), args.at(2)), std::string(args.at(3)));
|
Application::Settings.setConsoleInputAccessMapping(ComposedKey(args.at(1), args.at(2)), std::string(args.at(3)));
|
||||||
Application::Console().WriteRaw(fmt::format("{}::{} := {}", args.at(1), args.at(2), std::string(args.at(3))));
|
Application::Console().WriteRaw(fmt::format("{}::{} := {}", args.at(1), args.at(2), std::string(args.at(3))));
|
||||||
},
|
},
|
||||||
[&args](int keyValue) {
|
[&args](int keyValue) {
|
||||||
Application::SettingsSingleton.setConsoleInputAccessMapping(ComposedKey(args.at(1), args.at(2)), std::stoi(args.at(3)));
|
Application::Settings.setConsoleInputAccessMapping(ComposedKey(args.at(1), args.at(2)), std::stoi(args.at(3)));
|
||||||
Application::Console().WriteRaw(fmt::format("{}::{} := {}", args.at(1),args.at(2), std::stoi(args.at(3))));
|
Application::Console().WriteRaw(fmt::format("{}::{} := {}", args.at(1), args.at(2), std::stoi(args.at(3))));
|
||||||
},
|
},
|
||||||
[&args](bool keyValue) {
|
[&args](bool keyValue) {
|
||||||
// todo: implement other way to convert from string to bool
|
// todo: implement other way to convert from string to bool
|
||||||
if(args.at(3) == "true"){
|
if (args.at(3) == "true") {
|
||||||
Application::SettingsSingleton.setConsoleInputAccessMapping(ComposedKey(args.at(1), args.at(2)), true);
|
Application::Settings.setConsoleInputAccessMapping(ComposedKey(args.at(1), args.at(2)), true);
|
||||||
Application::Console().WriteRaw(fmt::format("{}::{} := {}", args.at(1), args.at(2), "true"));
|
Application::Console().WriteRaw(fmt::format("{}::{} := {}", args.at(1), args.at(2), "true"));
|
||||||
}else if(args.at(3) == "false"){
|
} else if (args.at(3) == "false") {
|
||||||
Application::SettingsSingleton.setConsoleInputAccessMapping(ComposedKey(args.at(1), args.at(2)), false);
|
Application::Settings.setConsoleInputAccessMapping(ComposedKey(args.at(1), args.at(2)), false);
|
||||||
Application::Console().WriteRaw(fmt::format("{}::{} := {}", args.at(1), args.at(2), "false"));
|
Application::Console().WriteRaw(fmt::format("{}::{} := {}", args.at(1), args.at(2), "false"));
|
||||||
}else{
|
} else {
|
||||||
beammp_errorf("Error when setting key: {}::{} : Unknown literal, use either 'true', or 'false' to set boolean values.", args.at(1), args.at(2));
|
beammp_errorf("Error when setting key: {}::{} : Unknown literal, use either 'true', or 'false' to set boolean values.", args.at(1), args.at(2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -471,39 +470,39 @@ void TConsole::Command_Settings(const std::string&, const std::vector<std::strin
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
}else if(args.front() == "list"){
|
} else if (args.front() == "list") {
|
||||||
//std::unordered_map<std::string, Settings::SettingsAccessControl>
|
// std::unordered_map<std::string, Settings::SettingsAccessControl>
|
||||||
for(const auto& [composedKey, keyACL] : Application::SettingsSingleton.getACLMap()){
|
for (const auto& [composedKey, keyACL] : Application::Settings.getACLMap()) {
|
||||||
// even though we have the value, we want to ignore it in order to make use of access
|
// even though we have the value, we want to ignore it in order to make use of access
|
||||||
// control checks
|
// control checks
|
||||||
|
|
||||||
if(keyACL.second != Settings::SettingsAccessMask::noaccess){
|
|
||||||
|
|
||||||
try{
|
|
||||||
|
|
||||||
Settings::SettingsAccessControl acl = Application::SettingsSingleton.getConsoleInputAccessMapping(composedKey);
|
|
||||||
Settings::SettingsTypeVariant keyType = Application::SettingsSingleton.get(acl.first);
|
|
||||||
|
|
||||||
std::visit(
|
if (keyACL.second != Settings::SettingsAccessMask::noaccess) {
|
||||||
overloaded {
|
|
||||||
[&composedKey](std::string keyValue) {
|
|
||||||
Application::Console().WriteRaw(fmt::format("{} = {}", composedKey, keyValue));
|
|
||||||
},
|
|
||||||
[&composedKey](int keyValue) {
|
|
||||||
Application::Console().WriteRaw(fmt::format("{} = {}", composedKey, keyValue));
|
|
||||||
},
|
|
||||||
[&composedKey](bool keyValue) {
|
|
||||||
Application::Console().WriteRaw(fmt::format("{} = {}", composedKey, keyValue));
|
|
||||||
}
|
|
||||||
|
|
||||||
},
|
try {
|
||||||
keyType);
|
|
||||||
}catch(std::logic_error& e){
|
Settings::SettingsAccessControl acl = Application::Settings.getConsoleInputAccessMapping(composedKey);
|
||||||
beammp_errorf("Error when getting key: {}", e.what());
|
Settings::SettingsTypeVariant keyType = Application::Settings.get(acl.first);
|
||||||
}
|
|
||||||
|
std::visit(
|
||||||
|
overloaded {
|
||||||
|
[&composedKey](std::string keyValue) {
|
||||||
|
Application::Console().WriteRaw(fmt::format("{} = {}", composedKey, keyValue));
|
||||||
|
},
|
||||||
|
[&composedKey](int keyValue) {
|
||||||
|
Application::Console().WriteRaw(fmt::format("{} = {}", composedKey, keyValue));
|
||||||
|
},
|
||||||
|
[&composedKey](bool keyValue) {
|
||||||
|
Application::Console().WriteRaw(fmt::format("{} = {}", composedKey, keyValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
keyType);
|
||||||
|
} catch (std::logic_error& e) {
|
||||||
|
beammp_errorf("Error when getting key: {}", e.what());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else {
|
} else {
|
||||||
beammp_errorf("Unknown argument for cammand 'settings': {}", args.front());
|
beammp_errorf("Unknown argument for cammand 'settings': {}", args.front());
|
||||||
|
|
||||||
Application::Console().WriteRaw("BeamMP-Server Console: " + std::string(sHelpString));
|
Application::Console().WriteRaw("BeamMP-Server Console: " + std::string(sHelpString));
|
||||||
@@ -515,7 +514,7 @@ void TConsole::Command_Say(const std::string& FullCmd) {
|
|||||||
if (FullCmd.size() > 3) {
|
if (FullCmd.size() > 3) {
|
||||||
auto Message = FullCmd.substr(4);
|
auto Message = FullCmd.substr(4);
|
||||||
LuaAPI::MP::SendChatMessage(-1, Message);
|
LuaAPI::MP::SendChatMessage(-1, Message);
|
||||||
if (!Application::Settings.LogChat) {
|
if (!Application::Settings.getAsBool(Settings::Key::General_LogChat)) {
|
||||||
Application::Console().WriteRaw("Chat message sent!");
|
Application::Console().WriteRaw("Chat message sent!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-14
@@ -64,7 +64,7 @@ void THeartbeatThread::operator()() {
|
|||||||
T = Http::POST(Url, 443, Target, Body, "application/x-www-form-urlencoded", &ResponseCode, { { "api-v", "2" } });
|
T = Http::POST(Url, 443, Target, Body, "application/x-www-form-urlencoded", &ResponseCode, { { "api-v", "2" } });
|
||||||
Doc.Parse(T.data(), T.size());
|
Doc.Parse(T.data(), T.size());
|
||||||
if (Doc.HasParseError() || !Doc.IsObject()) {
|
if (Doc.HasParseError() || !Doc.IsObject()) {
|
||||||
if (!Application::Settings.Private) {
|
if (!Application::Settings.getAsBool(Settings::Key::General_Private)) {
|
||||||
beammp_trace("Backend response failed to parse as valid json");
|
beammp_trace("Backend response failed to parse as valid json");
|
||||||
beammp_trace("Response was: `" + T + "`");
|
beammp_trace("Response was: `" + T + "`");
|
||||||
}
|
}
|
||||||
@@ -104,12 +104,12 @@ void THeartbeatThread::operator()() {
|
|||||||
beammp_error("Missing/invalid json members in backend response");
|
beammp_error("Missing/invalid json members in backend response");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!Application::Settings.Private) {
|
if (!Application::Settings.getAsBool(Settings::Key::General_Private)) {
|
||||||
beammp_warn("Backend failed to respond to a heartbeat. Your server may temporarily disappear from the server list. This is not an error, and will likely resolve itself soon. Direct connect will still work.");
|
beammp_warn("Backend failed to respond to a heartbeat. Your server may temporarily disappear from the server list. This is not an error, and will likely resolve itself soon. Direct connect will still work.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Ok && !isAuth && !Application::Settings.Private) {
|
if (Ok && !isAuth && !Application::Settings.getAsBool(Settings::Key::General_Private)) {
|
||||||
if (Status == "2000") {
|
if (Status == "2000") {
|
||||||
beammp_info(("Authenticated! " + Message));
|
beammp_info(("Authenticated! " + Message));
|
||||||
isAuth = true;
|
isAuth = true;
|
||||||
@@ -123,10 +123,10 @@ void THeartbeatThread::operator()() {
|
|||||||
beammp_error("Backend REFUSED the auth key. Reason: " + Message);
|
beammp_error("Backend REFUSED the auth key. Reason: " + Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isAuth || Application::Settings.Private) {
|
if (isAuth || Application::Settings.getAsBool(Settings::Key::General_Private)) {
|
||||||
Application::SetSubsystemStatus("Heartbeat", Application::Status::Good);
|
Application::SetSubsystemStatus("Heartbeat", Application::Status::Good);
|
||||||
}
|
}
|
||||||
if (!Application::Settings.HideUpdateMessages && UpdateReminderCounter % 5) {
|
if (!Application::Settings.getAsBool(Settings::Key::Misc_ImScaredOfUpdates) && UpdateReminderCounter % 5) {
|
||||||
Application::CheckForUpdates();
|
Application::CheckForUpdates();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -135,22 +135,21 @@ void THeartbeatThread::operator()() {
|
|||||||
std::string THeartbeatThread::GenerateCall() {
|
std::string THeartbeatThread::GenerateCall() {
|
||||||
std::stringstream Ret;
|
std::stringstream Ret;
|
||||||
|
|
||||||
Ret << "uuid=" << Application::Settings.Key
|
Ret << "uuid=" << Application::Settings.getAsString(Settings::Key::General_AuthKey)
|
||||||
<< "&players=" << mServer.ClientCount()
|
<< "&players=" << mServer.ClientCount()
|
||||||
<< "&maxplayers=" << Application::Settings.MaxPlayers
|
<< "&maxplayers=" << Application::Settings.getAsInt(Settings::Key::General_MaxPlayers)
|
||||||
<< "&port=" << Application::Settings.Port
|
<< "&port=" << Application::Settings.getAsInt(Settings::Key::General_Port)
|
||||||
<< "&map=" << Application::Settings.MapName
|
<< "&map=" << Application::Settings.getAsString(Settings::Key::General_Map)
|
||||||
<< "&private=" << (Application::Settings.Private ? "true" : "false")
|
<< "&private=" << (Application::Settings.getAsBool(Settings::Key::General_Private) ? "true" : "false")
|
||||||
<< "&version=" << Application::ServerVersionString()
|
<< "&version=" << Application::ServerVersionString()
|
||||||
<< "&clientversion=" << std::to_string(Application::ClientMajorVersion()) + ".0" // FIXME: Wtf.
|
<< "&clientversion=" << std::to_string(Application::ClientMajorVersion()) + ".0" // FIXME: Wtf.
|
||||||
<< "&name=" << Application::Settings.ServerName
|
<< "&name=" << Application::Settings.getAsString(Settings::Key::General_Name)
|
||||||
<< "&tags=" << Application::Settings.ServerTags
|
<< "&tags=" << Application::Settings.getAsString(Settings::Key::General_Tags)
|
||||||
<< "&modlist=" << mResourceManager.TrimmedList()
|
<< "&modlist=" << mResourceManager.TrimmedList()
|
||||||
<< "&modstotalsize=" << mResourceManager.MaxModSize()
|
<< "&modstotalsize=" << mResourceManager.MaxModSize()
|
||||||
<< "&modstotal=" << mResourceManager.ModsLoaded()
|
<< "&modstotal=" << mResourceManager.ModsLoaded()
|
||||||
<< "&playerslist=" << GetPlayers()
|
<< "&playerslist=" << GetPlayers()
|
||||||
<< "&desc=" << Application::Settings.ServerDesc
|
<< "&desc=" << Application::Settings.getAsString(Settings::Key::General_Description);
|
||||||
<< "&pass=" << (Application::Settings.Password.empty() ? "false" : "true");
|
|
||||||
return Ret.str();
|
return Ret.str();
|
||||||
}
|
}
|
||||||
THeartbeatThread::THeartbeatThread(TResourceManager& ResourceManager, TServer& Server)
|
THeartbeatThread::THeartbeatThread(TResourceManager& ResourceManager, TServer& Server)
|
||||||
|
|||||||
+5
-5
@@ -35,11 +35,11 @@
|
|||||||
TLuaEngine* LuaAPI::MP::Engine;
|
TLuaEngine* LuaAPI::MP::Engine;
|
||||||
|
|
||||||
TLuaEngine::TLuaEngine()
|
TLuaEngine::TLuaEngine()
|
||||||
: mResourceServerPath(fs::path(Application::Settings.Resource) / "Server") {
|
: mResourceServerPath(fs::path(Application::Settings.getAsString(Settings::Key::General_ResourceFolder)) / "Server") {
|
||||||
Application::SetSubsystemStatus("LuaEngine", Application::Status::Starting);
|
Application::SetSubsystemStatus("LuaEngine", Application::Status::Starting);
|
||||||
LuaAPI::MP::Engine = this;
|
LuaAPI::MP::Engine = this;
|
||||||
if (!fs::exists(Application::Settings.Resource)) {
|
if (!fs::exists(Application::Settings.getAsString(Settings::Key::General_ResourceFolder))) {
|
||||||
fs::create_directory(Application::Settings.Resource);
|
fs::create_directory(Application::Settings.getAsString(Settings::Key::General_ResourceFolder));
|
||||||
}
|
}
|
||||||
if (!fs::exists(mResourceServerPath)) {
|
if (!fs::exists(mResourceServerPath)) {
|
||||||
fs::create_directory(mResourceServerPath);
|
fs::create_directory(mResourceServerPath);
|
||||||
@@ -55,7 +55,7 @@ TLuaEngine::TLuaEngine()
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("TLuaEngine ctor & dtor") {
|
TEST_CASE("TLuaEngine ctor & dtor") {
|
||||||
Application::Settings.Resource = "beammp_server_test_resources";
|
Application::Settings.set(Settings::Key::General_ResourceFolder, "beammp_server_test_resources");
|
||||||
TLuaEngine engine;
|
TLuaEngine engine;
|
||||||
Application::GracefullyShutdown();
|
Application::GracefullyShutdown();
|
||||||
}
|
}
|
||||||
@@ -836,7 +836,7 @@ TLuaEngine::StateThreadData::StateThreadData(const std::string& Name, TLuaStateI
|
|||||||
ToPrint += LuaAPI::LuaToString(static_cast<const sol::object>(arg));
|
ToPrint += LuaAPI::LuaToString(static_cast<const sol::object>(arg));
|
||||||
ToPrint += "\t";
|
ToPrint += "\t";
|
||||||
}
|
}
|
||||||
if (Application::Settings.DebugModeEnabled) {
|
if (Application::Settings.getAsBool(Settings::Key::General_Debug)) {
|
||||||
beammp_lua_log("DEBUG", mStateId, ToPrint);
|
beammp_lua_log("DEBUG", mStateId, ToPrint);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
+8
-8
@@ -80,7 +80,7 @@ TNetwork::TNetwork(TServer& Server, TPPSMonitor& PPSMonitor, TResourceManager& R
|
|||||||
|
|
||||||
void TNetwork::UDPServerMain() {
|
void TNetwork::UDPServerMain() {
|
||||||
RegisterThread("UDPServer");
|
RegisterThread("UDPServer");
|
||||||
ip::udp::endpoint UdpListenEndpoint(ip::address::from_string("0.0.0.0"), Application::Settings.Port);
|
ip::udp::endpoint UdpListenEndpoint(ip::address::from_string("0.0.0.0"), Application::Settings.getAsInt(Settings::Key::General_Port));
|
||||||
boost::system::error_code ec;
|
boost::system::error_code ec;
|
||||||
mUDPSock.open(UdpListenEndpoint.protocol(), ec);
|
mUDPSock.open(UdpListenEndpoint.protocol(), ec);
|
||||||
if (ec) {
|
if (ec) {
|
||||||
@@ -95,8 +95,8 @@ void TNetwork::UDPServerMain() {
|
|||||||
Application::GracefullyShutdown();
|
Application::GracefullyShutdown();
|
||||||
}
|
}
|
||||||
Application::SetSubsystemStatus("UDPNetwork", Application::Status::Good);
|
Application::SetSubsystemStatus("UDPNetwork", Application::Status::Good);
|
||||||
beammp_info(("Vehicle data network online on port ") + std::to_string(Application::Settings.Port) + (" with a Max of ")
|
beammp_info(("Vehicle data network online on port ") + std::to_string(Application::Settings.getAsInt(Settings::Key::General_Port)) + (" with a Max of ")
|
||||||
+ std::to_string(Application::Settings.MaxPlayers) + (" Clients"));
|
+ std::to_string(Application::Settings.getAsInt(Settings::Key::General_MaxPlayers)) + (" Clients"));
|
||||||
while (!Application::IsShuttingDown()) {
|
while (!Application::IsShuttingDown()) {
|
||||||
try {
|
try {
|
||||||
ip::udp::endpoint client {};
|
ip::udp::endpoint client {};
|
||||||
@@ -133,7 +133,7 @@ void TNetwork::UDPServerMain() {
|
|||||||
void TNetwork::TCPServerMain() {
|
void TNetwork::TCPServerMain() {
|
||||||
RegisterThread("TCPServer");
|
RegisterThread("TCPServer");
|
||||||
|
|
||||||
ip::tcp::endpoint ListenEp(ip::address::from_string("0.0.0.0"), Application::Settings.Port);
|
ip::tcp::endpoint ListenEp(ip::address::from_string("0.0.0.0"), Application::Settings.getAsInt(Settings::Key::General_Port));
|
||||||
ip::tcp::socket Listener(mServer.IoCtx());
|
ip::tcp::socket Listener(mServer.IoCtx());
|
||||||
boost::system::error_code ec;
|
boost::system::error_code ec;
|
||||||
Listener.open(ListenEp.protocol(), ec);
|
Listener.open(ListenEp.protocol(), ec);
|
||||||
@@ -376,7 +376,7 @@ std::shared_ptr<TClient> TNetwork::Authentication(TConnection&& RawConnection) {
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mServer.ClientCount() < size_t(Application::Settings.MaxPlayers)) {
|
if (mServer.ClientCount() < size_t(Application::Settings.getAsInt(Settings::Key::General_MaxPlayers))) {
|
||||||
beammp_info("Identification success");
|
beammp_info("Identification success");
|
||||||
mServer.InsertClient(Client);
|
mServer.InsertClient(Client);
|
||||||
TCPClient(Client);
|
TCPClient(Client);
|
||||||
@@ -569,7 +569,7 @@ void TNetwork::TCPClient(const std::weak_ptr<TClient>& c) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TNetwork::UpdatePlayer(TClient& Client) {
|
void TNetwork::UpdatePlayer(TClient& Client) {
|
||||||
std::string Packet = ("Ss") + std::to_string(mServer.ClientCount()) + "/" + std::to_string(Application::Settings.MaxPlayers) + ":";
|
std::string Packet = ("Ss") + std::to_string(mServer.ClientCount()) + "/" + std::to_string(Application::Settings.getAsInt(Settings::Key::General_MaxPlayers)) + ":";
|
||||||
mServer.ForEachClient([&](const std::weak_ptr<TClient>& ClientPtr) -> bool {
|
mServer.ForEachClient([&](const std::weak_ptr<TClient>& ClientPtr) -> bool {
|
||||||
ReadLock Lock(mServer.GetClientMutex());
|
ReadLock Lock(mServer.GetClientMutex());
|
||||||
if (!ClientPtr.expired()) {
|
if (!ClientPtr.expired()) {
|
||||||
@@ -644,7 +644,7 @@ void TNetwork::OnConnect(const std::weak_ptr<TClient>& c) {
|
|||||||
SyncResources(*LockedClient);
|
SyncResources(*LockedClient);
|
||||||
if (LockedClient->IsDisconnected())
|
if (LockedClient->IsDisconnected())
|
||||||
return;
|
return;
|
||||||
(void)Respond(*LockedClient, StringToVector("M" + Application::Settings.MapName), true); // Send the Map on connect
|
(void)Respond(*LockedClient, StringToVector("M" + Application::Settings.getAsString(Settings::Key::General_Map)), true); // Send the Map on connect
|
||||||
beammp_info(LockedClient->GetName() + " : Connected");
|
beammp_info(LockedClient->GetName() + " : Connected");
|
||||||
LuaAPI::MP::Engine->ReportErrors(LuaAPI::MP::Engine->TriggerEvent("onPlayerJoining", "", LockedClient->GetID()));
|
LuaAPI::MP::Engine->ReportErrors(LuaAPI::MP::Engine->TriggerEvent("onPlayerJoining", "", LockedClient->GetID()));
|
||||||
}
|
}
|
||||||
@@ -703,7 +703,7 @@ void TNetwork::SendFile(TClient& c, const std::string& UnsafeName) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto FileName = fs::path(UnsafeName).filename().string();
|
auto FileName = fs::path(UnsafeName).filename().string();
|
||||||
FileName = Application::Settings.Resource + "/Client/" + FileName;
|
FileName = Application::Settings.getAsString(Settings::Key::General_ResourceFolder) + "/Client/" + FileName;
|
||||||
|
|
||||||
if (!std::filesystem::exists(FileName)) {
|
if (!std::filesystem::exists(FileName)) {
|
||||||
if (!TCPSend(c, StringToVector("CO"))) {
|
if (!TCPSend(c, StringToVector("CO"))) {
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ namespace fs = std::filesystem;
|
|||||||
|
|
||||||
TResourceManager::TResourceManager() {
|
TResourceManager::TResourceManager() {
|
||||||
Application::SetSubsystemStatus("ResourceManager", Application::Status::Starting);
|
Application::SetSubsystemStatus("ResourceManager", Application::Status::Starting);
|
||||||
std::string Path = Application::Settings.Resource + "/Client";
|
std::string Path = Application::Settings.getAsString(Settings::Key::General_ResourceFolder) + "/Client";
|
||||||
if (!fs::exists(Path))
|
if (!fs::exists(Path))
|
||||||
fs::create_directories(Path);
|
fs::create_directories(Path);
|
||||||
for (const auto& entry : fs::directory_iterator(Path)) {
|
for (const auto& entry : fs::directory_iterator(Path)) {
|
||||||
|
|||||||
+1
-1
@@ -286,7 +286,7 @@ bool TServer::ShouldSpawn(TClient& c, const std::string& CarJson, int ID) {
|
|||||||
c.SetUnicycleID(ID);
|
c.SetUnicycleID(ID);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return c.GetCarCount() < Application::Settings.MaxCars;
|
return c.GetCarCount() < Application::Settings.getAsInt(Settings::Key::General_MaxCars);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-6
@@ -151,7 +151,7 @@ int BeamMPServerMain(MainArguments Arguments) {
|
|||||||
beammp_errorf("Custom port requested via --port is invalid: '{}'", Port.value());
|
beammp_errorf("Custom port requested via --port is invalid: '{}'", Port.value());
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
Application::Settings.Port = P;
|
Application::Settings.set(Settings::Key::General_Port, P);
|
||||||
beammp_info("Custom port requested via commandline arguments: " + Port.value());
|
beammp_info("Custom port requested via commandline arguments: " + Port.value());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -197,11 +197,7 @@ int BeamMPServerMain(MainArguments Arguments) {
|
|||||||
PPSMonitor.SetNetwork(Network);
|
PPSMonitor.SetNetwork(Network);
|
||||||
Application::CheckForUpdates();
|
Application::CheckForUpdates();
|
||||||
|
|
||||||
TPluginMonitor PluginMonitor(fs::path(Application::Settings.Resource) / "Server", LuaEngine);
|
TPluginMonitor PluginMonitor(fs::path(Application::Settings.getAsString(Settings::Key::General_ResourceFolder)) / "Server", LuaEngine);
|
||||||
|
|
||||||
if (Application::Settings.HTTPServerEnabled) {
|
|
||||||
Http::Server::THttpServerInstance HttpServerInstance {};
|
|
||||||
}
|
|
||||||
|
|
||||||
Application::SetSubsystemStatus("Main", Application::Status::Good);
|
Application::SetSubsystemStatus("Main", Application::Status::Good);
|
||||||
RegisterThread("Main(Waiting)");
|
RegisterThread("Main(Waiting)");
|
||||||
|
|||||||
Reference in new issue
Block a user