mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-02-16 02:30:54 +00:00
Add logic for new Settings type
Signed-off-by: Lucca Jiménez Könings <development@jimkoen.com>
This commit is contained in:
@@ -103,7 +103,7 @@ public:
|
||||
static void SetPPS(const std::string& NewPPS) { mPPS = NewPPS; }
|
||||
|
||||
static TSettings Settings;
|
||||
static struct Settings SettingsSingleton;
|
||||
static inline struct Settings SettingsSingleton { };
|
||||
|
||||
static std::vector<std::string> GetBackendUrlsInOrder() {
|
||||
return {
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "Common.h"
|
||||
#include "TSettings.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <filesystem>
|
||||
@@ -43,6 +44,7 @@ private:
|
||||
void TryReadValue(toml::value& Table, const std::string& Category, const std::string_view& Key, const std::string_view& Env, std::string& OutValue);
|
||||
void TryReadValue(toml::value& Table, const std::string& Category, const std::string_view& Key, const std::string_view& Env, bool& OutValue);
|
||||
void TryReadValue(toml::value& Table, const std::string& Category, const std::string_view& Key, const std::string_view& Env, int& OutValue);
|
||||
void TryReadValue(toml::value& Table, const std::string& Category, const std::string_view& Key, const std::string_view& Env, Settings::Key key);
|
||||
|
||||
void ParseOldFormat();
|
||||
std::string TagsAsPrettyArray() const;
|
||||
|
||||
@@ -49,7 +49,21 @@ struct Settings {
|
||||
General_Debug
|
||||
};
|
||||
|
||||
std::unordered_map<Key, SettingsTypeVariant> SettingsMap {};
|
||||
std::unordered_map<Key, SettingsTypeVariant> SettingsMap {
|
||||
{ General_Description, "BeamMP Default Description" },
|
||||
{ General_Tags, "Freeroam" },
|
||||
{ General_MaxPlayers, 8 },
|
||||
{ General_Name, "BeamMP Server" },
|
||||
{ General_Map, "/levels/gridmap_v2/info.json" },
|
||||
{ General_AuthKey, "" },
|
||||
{ General_Private, true },
|
||||
{ General_Port, 30814 },
|
||||
{ General_MaxCars, 1 },
|
||||
{ General_LogChat, true },
|
||||
{ General_ResourceFolder, "Resources" },
|
||||
{ General_Debug, false }
|
||||
|
||||
};
|
||||
|
||||
std::string getAsString(Key key) {
|
||||
if (!SettingsMap.contains(key)) {
|
||||
@@ -72,6 +86,13 @@ struct Settings {
|
||||
return std::get<bool>(SettingsMap.at(key));
|
||||
}
|
||||
|
||||
SettingsTypeVariant get(Key key) {
|
||||
if (!SettingsMap.contains(key)) {
|
||||
throw std::logic_error { "Undefined setting key accessed in Settings::get" };
|
||||
}
|
||||
return SettingsMap.at(key);
|
||||
}
|
||||
|
||||
void set(Key key, std::string value) {
|
||||
if (!SettingsMap.contains(key)) {
|
||||
throw std::logic_error { "Undefined setting key accessed in Settings::getAsString" };
|
||||
|
||||
Reference in New Issue
Block a user