From 29f4d0d286503906766e7467f4995ca4a1d27c00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucca=20Jim=C3=A9nez=20K=C3=B6nings?= Date: Wed, 26 Jun 2024 14:06:06 +0200 Subject: [PATCH] run clang-format --- include/ChronoWrapper.h | 2 +- include/Common.h | 4 +--- include/Json.h | 4 ++-- include/RWMutex.h | 2 +- include/Settings.h | 6 ++---- include/TPPSMonitor.h | 2 +- src/ChronoWrapper.cpp | 21 +++++++++------------ src/Common.cpp | 3 +-- src/Http.cpp | 10 +++++----- src/LuaAPI.cpp | 2 +- src/Profiling.cpp | 1 - src/Settings.cpp | 12 ++++-------- src/TConfig.cpp | 4 ++-- src/TConsole.cpp | 12 ++++++------ src/THeartbeatThread.cpp | 4 ++-- src/TLuaEngine.cpp | 2 +- src/TNetwork.cpp | 4 ++-- src/TPPSMonitor.cpp | 4 ++-- src/main.cpp | 2 +- 19 files changed, 44 insertions(+), 57 deletions(-) diff --git a/include/ChronoWrapper.h b/include/ChronoWrapper.h index 009e911..906ba26 100644 --- a/include/ChronoWrapper.h +++ b/include/ChronoWrapper.h @@ -4,5 +4,5 @@ #include namespace ChronoWrapper { - std::chrono::high_resolution_clock::duration TimeFromStringWithLiteral(const std::string& time_str); +std::chrono::high_resolution_clock::duration TimeFromStringWithLiteral(const std::string& time_str); } diff --git a/include/Common.h b/include/Common.h index 64d7194..4960077 100644 --- a/include/Common.h +++ b/include/Common.h @@ -37,8 +37,8 @@ #include namespace fs = std::filesystem; -#include "TConsole.h" #include "Settings.h" +#include "TConsole.h" struct Version { uint8_t major; @@ -61,8 +61,6 @@ class Application final { public: // types - - using TShutdownHandler = std::function; // methods diff --git a/include/Json.h b/include/Json.h index 4034ad0..fbb90eb 100644 --- a/include/Json.h +++ b/include/Json.h @@ -17,7 +17,7 @@ // along with this program. If not, see . #pragma once -#include "rapidjson/stringbuffer.h" -#include "rapidjson/prettywriter.h" #include "rapidjson/document.h" +#include "rapidjson/prettywriter.h" +#include "rapidjson/stringbuffer.h" #include "rapidjson/writer.h" diff --git a/include/RWMutex.h b/include/RWMutex.h index f18e69d..82d0504 100644 --- a/include/RWMutex.h +++ b/include/RWMutex.h @@ -23,8 +23,8 @@ * and write locks and read locks are mutually exclusive. */ -#include #include +#include // Use ReadLock(m) and WriteLock(m) to lock it. using RWMutex = std::shared_mutex; diff --git a/include/Settings.h b/include/Settings.h index 8ee3ffc..1ef8ea1 100644 --- a/include/Settings.h +++ b/include/Settings.h @@ -89,7 +89,7 @@ struct Settings { General_AllowGuests }; - Sync> SettingsMap; + Sync> SettingsMap; enum SettingsAccessMask { READ_ONLY, // Value can be read from console READ_WRITE, // Value can be read and written to from console @@ -101,7 +101,7 @@ struct Settings { SettingsAccessMask // Console read/write permissions >; - Sync> InputAccessMapping; + Sync> InputAccessMapping; std::string getAsString(Key key); int getAsInt(Key key); @@ -142,5 +142,3 @@ struct Settings { void setConsoleInputAccessMapping(const ComposedKey& keyName, int value); void setConsoleInputAccessMapping(const ComposedKey& keyName, bool value); }; - - diff --git a/include/TPPSMonitor.h b/include/TPPSMonitor.h index bb5e802..aaeb417 100644 --- a/include/TPPSMonitor.h +++ b/include/TPPSMonitor.h @@ -27,7 +27,7 @@ class TNetwork; class TPPSMonitor : public IThreaded { public: explicit TPPSMonitor(TServer& Server); - virtual ~TPPSMonitor() {} + virtual ~TPPSMonitor() { } void operator()() override; diff --git a/src/ChronoWrapper.cpp b/src/ChronoWrapper.cpp index 9a2c50b..99ad5cc 100644 --- a/src/ChronoWrapper.cpp +++ b/src/ChronoWrapper.cpp @@ -2,24 +2,21 @@ #include "Common.h" #include -std::chrono::high_resolution_clock::duration ChronoWrapper::TimeFromStringWithLiteral(const std::string& time_str) -{ +std::chrono::high_resolution_clock::duration ChronoWrapper::TimeFromStringWithLiteral(const std::string& time_str) { // const std::regex time_regex(R"((\d+\.{0,1}\d*)(min|ms|us|ns|[dhs]))"); //i.e one of: "25ns, 6us, 256ms, 2s, 13min, 69h, 356d" will get matched (only available in newer C++ versions) - const std::regex time_regex(R"((\d+\.{0,1}\d*)(min|[dhs]))"); //i.e one of: "2.01s, 13min, 69h, 356.69d" will get matched + const std::regex time_regex(R"((\d+\.{0,1}\d*)(min|[dhs]))"); // i.e one of: "2.01s, 13min, 69h, 356.69d" will get matched std::smatch match; float time_value; - if (!std::regex_search(time_str, match, time_regex)) return std::chrono::nanoseconds(0); + if (!std::regex_search(time_str, match, time_regex)) + return std::chrono::nanoseconds(0); time_value = stof(match.str(1)); if (match.str(2) == "d") { - return std::chrono::seconds((uint64_t)(time_value * 86400)); //86400 seconds in a day - } - else if (match.str(2) == "h") { - return std::chrono::seconds((uint64_t)(time_value * 3600)); //3600 seconds in an hour - } - else if (match.str(2) == "min") { + return std::chrono::seconds((uint64_t)(time_value * 86400)); // 86400 seconds in a day + } else if (match.str(2) == "h") { + return std::chrono::seconds((uint64_t)(time_value * 3600)); // 3600 seconds in an hour + } else if (match.str(2) == "min") { return std::chrono::seconds((uint64_t)(time_value * 60)); - } - else if (match.str(2) == "s") { + } else if (match.str(2) == "s") { return std::chrono::seconds((uint64_t)time_value); } return std::chrono::nanoseconds(0); diff --git a/src/Common.cpp b/src/Common.cpp index e412a6f..4988fc4 100644 --- a/src/Common.cpp +++ b/src/Common.cpp @@ -22,13 +22,13 @@ #include "TConsole.h" #include #include +#include #include #include #include #include #include #include -#include #include "Compat.h" #include "CustomAssert.h" @@ -383,4 +383,3 @@ void SplitString(const std::string& str, const char delim, std::vector, CONNECTION_A write_index++; write_index %= CONNECTION_AMOUNT; clients[i] = std::make_shared(connectionInfo.host, connectionInfo.port); - connections[i] = {connectionInfo.host, connectionInfo.port}; + connections[i] = { connectionInfo.host, connectionInfo.port }; beammp_tracef("New client connected, with ip {} and port {}", connectionInfo.host, connectionInfo.port); return clients[i]; } std::string Http::GET(const std::string& host, int port, const std::string& target, unsigned int* status) { - std::shared_ptr client = getClient({host, port}); + std::shared_ptr client = getClient({ host, port }); client->enable_server_certificate_verification(false); client->set_address_family(AF_INET); auto res = client->Get(target.c_str()); @@ -75,7 +75,7 @@ std::string Http::GET(const std::string& host, int port, const std::string& targ } std::string Http::POST(const std::string& host, int port, const std::string& target, const std::string& body, const std::string& ContentType, unsigned int* status, const httplib::Headers& headers) { - std::shared_ptr client = getClient({host, port}); + std::shared_ptr client = getClient({ host, port }); client->set_read_timeout(std::chrono::seconds(10)); beammp_assert(client->is_valid()); client->enable_server_certificate_verification(false); diff --git a/src/LuaAPI.cpp b/src/LuaAPI.cpp index 8ec0ec8..2189080 100644 --- a/src/LuaAPI.cpp +++ b/src/LuaAPI.cpp @@ -20,8 +20,8 @@ #include "Client.h" #include "Common.h" #include "CustomAssert.h" -#include "TLuaEngine.h" #include "Settings.h" +#include "TLuaEngine.h" #include diff --git a/src/Profiling.cpp b/src/Profiling.cpp index f6a41d8..ef8c405 100644 --- a/src/Profiling.cpp +++ b/src/Profiling.cpp @@ -57,4 +57,3 @@ size_t prof::UnitExecutionTime::measurement_count() const { std::unique_lock lock(m_mtx); return m_total_calls; } - diff --git a/src/Settings.cpp b/src/Settings.cpp index b5692a7..a82a66b 100644 --- a/src/Settings.cpp +++ b/src/Settings.cpp @@ -18,9 +18,7 @@ #include "Settings.h" - - -Settings::Settings(){ +Settings::Settings() { SettingsMap = std::unordered_map { // All entries which contain std::strings must be explicitly constructed, otherwise they become 'bool' { General_Description, std::string("BeamMP Default Description") }, @@ -39,7 +37,7 @@ Settings::Settings(){ { Misc_SendErrorsShowMessage, true }, { Misc_SendErrors, true }, { Misc_ImScaredOfUpdates, true }, - { Misc_UpdateReminderTime, "30s"} + { Misc_UpdateReminderTime, "30s" } }; InputAccessMapping = std::unordered_map { @@ -55,14 +53,12 @@ Settings::Settings(){ { { "General", "LogChat" }, { General_LogChat, READ_ONLY } }, { { "General", "ResourceFolder" }, { General_ResourceFolder, READ_ONLY } }, { { "General", "Debug" }, { General_Debug, READ_WRITE } }, - { { "General", "AllowGuests"}, { General_AllowGuests, READ_WRITE } }, + { { "General", "AllowGuests" }, { General_AllowGuests, READ_WRITE } }, { { "Misc", "SendErrorsShowMessage" }, { Misc_SendErrorsShowMessage, READ_WRITE } }, { { "Misc", "SendErrors" }, { Misc_SendErrors, READ_WRITE } }, { { "Misc", "ImScaredOfUpdates" }, { Misc_ImScaredOfUpdates, READ_WRITE } }, - { { "Misc", "UpdateReminderTime" }, {Misc_UpdateReminderTime, READ_WRITE} } + { { "Misc", "UpdateReminderTime" }, { Misc_UpdateReminderTime, READ_WRITE } } }; - - } std::string Settings::getAsString(Key key) { diff --git a/src/TConfig.cpp b/src/TConfig.cpp index c3a0a8d..95044a7 100644 --- a/src/TConfig.cpp +++ b/src/TConfig.cpp @@ -19,8 +19,8 @@ #include "Common.h" #include "Env.h" -#include "TConfig.h" #include "Settings.h" +#include "TConfig.h" #include #include #include @@ -239,7 +239,7 @@ void TConfig::TryReadValue(toml::value& Table, const std::string& Category, cons void TConfig::ParseFromFile(std::string_view name) { try { toml::value data {}; - if (!mDisableConfig) { + if (!mDisableConfig) { data = toml::parse(name.data()); } diff --git a/src/TConsole.cpp b/src/TConsole.cpp index b9ae153..9882c12 100644 --- a/src/TConsole.cpp +++ b/src/TConsole.cpp @@ -389,7 +389,7 @@ void TConsole::Command_Settings(const std::string&, const std::vector #include #include diff --git a/src/TLuaEngine.cpp b/src/TLuaEngine.cpp index 32ad0e5..a48c848 100644 --- a/src/TLuaEngine.cpp +++ b/src/TLuaEngine.cpp @@ -1135,7 +1135,7 @@ void TLuaEngine::StateThreadData::operator()() { case TLuaType::Bool: LuaArgs.push_back(sol::make_object(StateView, std::get(Arg))); break; - case TLuaType::StringStringMap: { + case TLuaType::StringStringMap: { auto Map = std::get>(Arg); auto Table = StateView.create_table(); for (const auto& [k, v] : Map) { diff --git a/src/TNetwork.cpp b/src/TNetwork.cpp index 65f0c97..ddecf69 100644 --- a/src/TNetwork.cpp +++ b/src/TNetwork.cpp @@ -292,7 +292,7 @@ std::shared_ptr TNetwork::Authentication(TConnection&& RawConnection) { std::string Key(reinterpret_cast(Data.data()), Data.size()); std::string AuthKey = Application::Settings.getAsString(Settings::Key::General_AuthKey); std::string ClientIp = Client->GetIdentifiers().at("ip"); - + nlohmann::json AuthReq {}; std::string AuthResStr {}; try { @@ -373,7 +373,7 @@ std::shared_ptr TNetwork::Authentication(TConnection&& RawConnection) { return false; }); - if (!NotAllowedWithReason && !Application::Settings.getAsBool(Settings::Key::General_AllowGuests) && Client->IsGuest()) { //!NotAllowedWithReason because this message has the lowest priority + if (!NotAllowedWithReason && !Application::Settings.getAsBool(Settings::Key::General_AllowGuests) && Client->IsGuest()) { //! NotAllowedWithReason because this message has the lowest priority NotAllowedWithReason = true; Reason = "No guests are allowed on this server! To join, sign up at: forum.beammp.com."; } diff --git a/src/TPPSMonitor.cpp b/src/TPPSMonitor.cpp index 461dfbf..ccababf 100644 --- a/src/TPPSMonitor.cpp +++ b/src/TPPSMonitor.cpp @@ -65,13 +65,13 @@ void TPPSMonitor::operator()() { V += c->GetCarCount(); } // kick on "no ping" - if (c->SecondsSinceLastPing() > (20 * 60) ){ + if (c->SecondsSinceLastPing() > (20 * 60)) { beammp_debugf("client {} ({}) timing out: {}", c->GetID(), c->GetName(), c->SecondsSinceLastPing()); TimedOutClients.push_back(c); } else if (c->IsSynced() && c->SecondsSinceLastPing() > (1 * 60)) { beammp_debugf("client {} ({}) timing out: {}", c->GetName(), c->GetID(), c->SecondsSinceLastPing()); TimedOutClients.push_back(c); - } + } return true; }); diff --git a/src/main.cpp b/src/main.cpp index 59c1469..2b36e5a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -20,6 +20,7 @@ #include "Common.h" #include "Http.h" #include "LuaAPI.h" +#include "Settings.h" #include "SignalHandling.h" #include "TConfig.h" #include "THeartbeatThread.h" @@ -29,7 +30,6 @@ #include "TPluginMonitor.h" #include "TResourceManager.h" #include "TServer.h" -#include "Settings.h" #include #include