run clang-format

This commit is contained in:
Lucca Jiménez Könings 2024-06-26 14:06:06 +02:00
parent 3c80bcbf01
commit 29f4d0d286
19 changed files with 44 additions and 57 deletions

View File

@ -4,5 +4,5 @@
#include <string>
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);
}

View File

@ -37,8 +37,8 @@
#include <filesystem>
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<void()>;
// methods

View File

@ -17,7 +17,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#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"

View File

@ -23,8 +23,8 @@
* and write locks and read locks are mutually exclusive.
*/
#include <shared_mutex>
#include <mutex>
#include <shared_mutex>
// Use ReadLock(m) and WriteLock(m) to lock it.
using RWMutex = std::shared_mutex;

View File

@ -89,7 +89,7 @@ struct Settings {
General_AllowGuests
};
Sync<std::unordered_map<Key, SettingsTypeVariant>> SettingsMap;
Sync<std::unordered_map<Key, SettingsTypeVariant>> 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<std::unordered_map<ComposedKey, SettingsAccessControl>> InputAccessMapping;
Sync<std::unordered_map<ComposedKey, SettingsAccessControl>> 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);
};

View File

@ -27,7 +27,7 @@ class TNetwork;
class TPPSMonitor : public IThreaded {
public:
explicit TPPSMonitor(TServer& Server);
virtual ~TPPSMonitor() {}
virtual ~TPPSMonitor() { }
void operator()() override;

View File

@ -2,24 +2,21 @@
#include "Common.h"
#include <regex>
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);

View File

@ -22,13 +22,13 @@
#include "TConsole.h"
#include <array>
#include <charconv>
#include <chrono>
#include <fmt/core.h>
#include <iostream>
#include <map>
#include <regex>
#include <sstream>
#include <thread>
#include <chrono>
#include "Compat.h"
#include "CustomAssert.h"
@ -383,4 +383,3 @@ void SplitString(const std::string& str, const char delim, std::vector<std::stri
out.push_back(str.substr(start, end - start));
}
}

View File

@ -30,8 +30,8 @@
using json = nlohmann::json;
struct Connection {
std::string host{};
int port{};
std::string host {};
int port {};
Connection() = default;
Connection(std::string host, int port)
: host(host)
@ -54,13 +54,13 @@ static thread_local std::array<std::shared_ptr<httplib::SSLClient>, CONNECTION_A
write_index++;
write_index %= CONNECTION_AMOUNT;
clients[i] = std::make_shared<httplib::SSLClient>(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<httplib::SSLClient> client = getClient({host, port});
std::shared_ptr<httplib::SSLClient> 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<httplib::SSLClient> client = getClient({host, port});
std::shared_ptr<httplib::SSLClient> client = getClient({ host, port });
client->set_read_timeout(std::chrono::seconds(10));
beammp_assert(client->is_valid());
client->enable_server_certificate_verification(false);

View File

@ -20,8 +20,8 @@
#include "Client.h"
#include "Common.h"
#include "CustomAssert.h"
#include "TLuaEngine.h"
#include "Settings.h"
#include "TLuaEngine.h"
#include <nlohmann/json.hpp>

View File

@ -57,4 +57,3 @@ size_t prof::UnitExecutionTime::measurement_count() const {
std::unique_lock lock(m_mtx);
return m_total_calls;
}

View File

@ -18,9 +18,7 @@
#include "Settings.h"
Settings::Settings(){
Settings::Settings() {
SettingsMap = std::unordered_map<Key, SettingsTypeVariant> {
// 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<ComposedKey, SettingsAccessControl> {
@ -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) {

View File

@ -19,8 +19,8 @@
#include "Common.h"
#include "Env.h"
#include "TConfig.h"
#include "Settings.h"
#include "TConfig.h"
#include <cstdlib>
#include <exception>
#include <fstream>
@ -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<toml::preserve_comments>(name.data());
}

View File

@ -389,7 +389,7 @@ void TConsole::Command_Settings(const std::string&, const std::vector<std::strin
}
try {
Settings::SettingsAccessControl acl = Application::Settings.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::Settings.get(acl.first);
std::visit(
@ -421,25 +421,25 @@ void TConsole::Command_Settings(const std::string&, const std::vector<std::strin
try {
Settings::SettingsAccessControl acl = Application::Settings.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::Settings.get(acl.first);
std::visit(
overloaded {
[&args](std::string keyValue) {
Application::Settings.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))));
},
[&args](int keyValue) {
Application::Settings.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))));
},
[&args](bool keyValue) {
if (args.at(3) == "true") {
Application::Settings.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"));
} else if (args.at(3) == "false") {
Application::Settings.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"));
} else {
beammp_errorf("Error when setting key: {}::{} : Unknown literal, use either 'true', or 'false' to set boolean values.", args.at(1), args.at(2));

View File

@ -18,10 +18,10 @@
#include "THeartbeatThread.h"
#include "ChronoWrapper.h"
#include "Client.h"
#include "Http.h"
#include "ChronoWrapper.h"
//#include "SocketIO.h"
// #include "SocketIO.h"
#include <rapidjson/document.h>
#include <rapidjson/rapidjson.h>
#include <sstream>

View File

@ -1135,7 +1135,7 @@ void TLuaEngine::StateThreadData::operator()() {
case TLuaType::Bool:
LuaArgs.push_back(sol::make_object(StateView, std::get<bool>(Arg)));
break;
case TLuaType::StringStringMap: {
case TLuaType::StringStringMap: {
auto Map = std::get<std::unordered_map<std::string, std::string>>(Arg);
auto Table = StateView.create_table();
for (const auto& [k, v] : Map) {

View File

@ -292,7 +292,7 @@ std::shared_ptr<TClient> TNetwork::Authentication(TConnection&& RawConnection) {
std::string Key(reinterpret_cast<const char*>(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<TClient> 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.";
}

View File

@ -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;
});

View File

@ -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 <cstdint>
#include <iostream>