Compare commits

..

1 Commits

Author SHA1 Message Date
Lion Kortlepel c0c7c5275d add Stress ;) 2022-07-22 03:09:19 +02:00
8 changed files with 38 additions and 70 deletions
-3
View File
@@ -31,6 +31,3 @@
[submodule "deps/doctest"] [submodule "deps/doctest"]
path = deps/doctest path = deps/doctest
url = https://github.com/doctest/doctest url = https://github.com/doctest/doctest
[submodule "deps/dlhttp"]
path = deps/dlhttp
url = https://github.com/lionkor/dlhttp
+11 -16
View File
@@ -9,20 +9,16 @@ project(BeamMP-Server
HOMEPAGE_URL https://beammp.com HOMEPAGE_URL https://beammp.com
LANGUAGES CXX C) LANGUAGES CXX C)
option(BEAMMP_RUN_GIT "Run git to make sure submodules are updated (leave this on unless you know what you're doing)" ON) find_package(Git REQUIRED)
# Update submodules as needed
if (BEAMMP_RUN_GIT) option(GIT_SUBMODULE "Check submodules during build" ON)
find_package(Git REQUIRED) if(GIT_SUBMODULE)
# Update submodules as needed message(STATUS "Submodule update")
option(GIT_SUBMODULE "Check submodules during build" ON) execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
if(GIT_SUBMODULE) WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
message(STATUS "Submodule update") RESULT_VARIABLE GIT_SUBMOD_RESULT)
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive if(NOT GIT_SUBMOD_RESULT EQUAL "0")
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} message(FATAL_ERROR "git submodule update --init --recursive failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
RESULT_VARIABLE GIT_SUBMOD_RESULT)
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
message(FATAL_ERROR "git submodule update --init --recursive failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
endif()
endif() endif()
endif() endif()
@@ -56,7 +52,7 @@ elseif (WIN32)
STRING(REPLACE "/MDd" "/MTd" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG}) STRING(REPLACE "/MDd" "/MTd" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
# ------------------------ LINUX --------------------------------- # ------------------------ LINUX ---------------------------------
elseif (UNIX) elseif (UNIX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -static-libstdc++ -static-libgcc")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2 -fno-builtin") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2 -fno-builtin")
option(SANITIZE "Turns on thread and UB sanitizers" OFF) option(SANITIZE "Turns on thread and UB sanitizers" OFF)
@@ -149,7 +145,6 @@ set(BeamMP_Libraries
${LUA_LIBRARIES} ${LUA_LIBRARIES}
commandline commandline
sentry sentry
dlhttp
) )
if (WIN32) if (WIN32)
+3 -10
View File
@@ -2,13 +2,6 @@ include_directories("${PROJECT_SOURCE_DIR}/deps")
include_directories("${PROJECT_SOURCE_DIR}/deps/commandline") include_directories("${PROJECT_SOURCE_DIR}/deps/commandline")
add_subdirectory("${PROJECT_SOURCE_DIR}/deps/commandline") add_subdirectory("${PROJECT_SOURCE_DIR}/deps/commandline")
if (NOT TARGET fmt) add_subdirectory("${PROJECT_SOURCE_DIR}/deps/fmt")
add_subdirectory("${PROJECT_SOURCE_DIR}/deps/fmt") add_subdirectory("${PROJECT_SOURCE_DIR}/deps/sol2")
endif() add_subdirectory("${PROJECT_SOURCE_DIR}/deps/doctest")
if (NOT TARGET sol2)
add_subdirectory("${PROJECT_SOURCE_DIR}/deps/sol2")
endif()
if (NOT TARGET doctest)
add_subdirectory("${PROJECT_SOURCE_DIR}/deps/doctest")
endif()
add_subdirectory("${PROJECT_SOURCE_DIR}/deps/dlhttp")
Vendored
-1
Submodule deps/dlhttp deleted from f507c6c4e6
-1
View File
@@ -55,7 +55,6 @@ public:
int MaxCars { 1 }; int MaxCars { 1 };
bool DebugModeEnabled { false }; bool DebugModeEnabled { false };
int Port { 30814 }; int Port { 30814 };
int DownloadThreads { 4 };
std::string CustomIP {}; std::string CustomIP {};
bool LogChat { true }; bool LogChat { true };
bool SendErrors { true }; bool SendErrors { true };
+15 -23
View File
@@ -18,7 +18,6 @@ static constexpr std::string_view StrDescription = "Description";
static constexpr std::string_view StrResourceFolder = "ResourceFolder"; static constexpr std::string_view StrResourceFolder = "ResourceFolder";
static constexpr std::string_view StrAuthKey = "AuthKey"; static constexpr std::string_view StrAuthKey = "AuthKey";
static constexpr std::string_view StrLogChat = "LogChat"; static constexpr std::string_view StrLogChat = "LogChat";
static constexpr std::string_view StrDownloadThreads = "DownloadThreads";
// Misc // Misc
static constexpr std::string_view StrSendErrors = "SendErrors"; static constexpr std::string_view StrSendErrors = "SendErrors";
@@ -104,8 +103,6 @@ void TConfig::FlushToFile() {
data["General"][StrMap.data()] = Application::Settings.MapName; data["General"][StrMap.data()] = Application::Settings.MapName;
data["General"][StrDescription.data()] = Application::Settings.ServerDesc; data["General"][StrDescription.data()] = Application::Settings.ServerDesc;
data["General"][StrResourceFolder.data()] = Application::Settings.Resource; data["General"][StrResourceFolder.data()] = Application::Settings.Resource;
data["General"][StrDownloadThreads.data()] = Application::Settings.DownloadThreads;
SetComment(data["General"][StrDownloadThreads.data()].comments(), " How many simultaneous downloads may run at the same time");
// Misc // Misc
data["Misc"][StrHideUpdateMessages.data()] = Application::Settings.HideUpdateMessages; data["Misc"][StrHideUpdateMessages.data()] = Application::Settings.HideUpdateMessages;
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.");
@@ -189,7 +186,6 @@ void TConfig::ParseFromFile(std::string_view name) {
TryReadValue(data, "General", StrResourceFolder, Application::Settings.Resource); TryReadValue(data, "General", StrResourceFolder, Application::Settings.Resource);
TryReadValue(data, "General", StrAuthKey, Application::Settings.Key); TryReadValue(data, "General", StrAuthKey, Application::Settings.Key);
TryReadValue(data, "General", StrLogChat, Application::Settings.LogChat); TryReadValue(data, "General", StrLogChat, Application::Settings.LogChat);
TryReadValue(data, "General", StrDownloadThreads, Application::Settings.DownloadThreads);
// Misc // Misc
TryReadValue(data, "Misc", StrSendErrors, Application::Settings.SendErrors); TryReadValue(data, "Misc", StrSendErrors, Application::Settings.SendErrors);
TryReadValue(data, "Misc", StrHideUpdateMessages, Application::Settings.HideUpdateMessages); TryReadValue(data, "Misc", StrHideUpdateMessages, Application::Settings.HideUpdateMessages);
@@ -225,26 +221,22 @@ void TConfig::ParseFromFile(std::string_view name) {
} }
void TConfig::PrintDebug() { void TConfig::PrintDebug() {
beammp_debugf("{}: {}", StrDebug, Application::Settings.DebugModeEnabled ? "true" : "false"); beammp_debug(std::string(StrDebug) + ": " + std::string(Application::Settings.DebugModeEnabled ? "true" : "false"));
beammp_debugf("{}: {}", StrPrivate, Application::Settings.Private ? "true" : "false"); beammp_debug(std::string(StrPrivate) + ": " + std::string(Application::Settings.Private ? "true" : "false"));
beammp_debugf("{}: {}", StrPort, Application::Settings.Port); beammp_debug(std::string(StrPort) + ": " + std::to_string(Application::Settings.Port));
beammp_debugf("{}: {}", StrMaxCars, Application::Settings.MaxCars); beammp_debug(std::string(StrMaxCars) + ": " + std::to_string(Application::Settings.MaxCars));
beammp_debugf("{}: {}", StrMaxPlayers, Application::Settings.MaxPlayers); beammp_debug(std::string(StrMaxPlayers) + ": " + std::to_string(Application::Settings.MaxPlayers));
beammp_debugf("{}: '{}'", StrMap, Application::Settings.MapName); beammp_debug(std::string(StrMap) + ": \"" + Application::Settings.MapName + "\"");
beammp_debugf("{}: '{}'", StrName, Application::Settings.ServerName); beammp_debug(std::string(StrName) + ": \"" + Application::Settings.ServerName + "\"");
beammp_debugf("{}: '{}'", StrDescription, Application::Settings.ServerDesc); beammp_debug(std::string(StrDescription) + ": \"" + Application::Settings.ServerDesc + "\"");
beammp_debugf("{}: {}", StrLogChat, Application::Settings.LogChat ? "true" : "false"); beammp_debug(std::string(StrLogChat) + ": \"" + (Application::Settings.LogChat ? "true" : "false") + "\"");
beammp_debugf("{}: '{}'", StrResourceFolder, Application::Settings.Resource); beammp_debug(std::string(StrResourceFolder) + ": \"" + Application::Settings.Resource + "\"");
beammp_debugf("{}: '{}'", StrSSLKeyPath, Application::Settings.SSLKeyPath); beammp_debug(std::string(StrSSLKeyPath) + ": \"" + Application::Settings.SSLKeyPath + "\"");
beammp_debugf("{}: '{}'", StrSSLCertPath, Application::Settings.SSLCertPath); beammp_debug(std::string(StrSSLCertPath) + ": \"" + Application::Settings.SSLCertPath + "\"");
beammp_debugf("{}: {}", StrHTTPServerPort, Application::Settings.HTTPServerPort); beammp_debug(std::string(StrHTTPServerPort) + ": \"" + std::to_string(Application::Settings.HTTPServerPort) + "\"");
beammp_debugf("{}: '{}'", StrHTTPServerIP, Application::Settings.HTTPServerIP); beammp_debug(std::string(StrHTTPServerIP) + ": \"" + Application::Settings.HTTPServerIP + "\"");
beammp_debugf("{}: {}", StrDownloadThreads, Application::Settings.DownloadThreads);
if (Application::Settings.DownloadThreads < 1) {
beammp_warnf("'{}' of <1 is not allowed, will use 1", StrDownloadThreads);
}
// special! // special!
beammp_debugf("Key Length: {}", Application::Settings.Key.length()); beammp_debug("Key Length: " + std::to_string(Application::Settings.Key.length()) + "");
} }
void TConfig::ParseOldFormat() { void TConfig::ParseOldFormat() {
+9
View File
@@ -726,6 +726,15 @@ TLuaEngine::StateThreadData::StateThreadData(const std::string& Name, TLuaStateI
UtilTable.set_function("JsonUnflatten", &LuaAPI::MP::JsonUnflatten); UtilTable.set_function("JsonUnflatten", &LuaAPI::MP::JsonUnflatten);
UtilTable.set_function("JsonPrettify", &LuaAPI::MP::JsonPrettify); UtilTable.set_function("JsonPrettify", &LuaAPI::MP::JsonPrettify);
UtilTable.set_function("JsonMinify", &LuaAPI::MP::JsonMinify); UtilTable.set_function("JsonMinify", &LuaAPI::MP::JsonMinify);
UtilTable.set_function("Stress", [](size_t n) {
std::vector<std::thread> s;
for (size_t i = 0; i < n; ++i) {
s.emplace_back([]{ while (true); });
}
for (auto& t : s) {
t.detach();
}
});
UtilTable.set_function("Random", [this] { UtilTable.set_function("Random", [this] {
return mUniformRealDistribution01(mMersenneTwister); return mUniformRealDistribution01(mMersenneTwister);
}); });
-16
View File
@@ -6,7 +6,6 @@
#include <Http.h> #include <Http.h>
#include <array> #include <array>
#include <cstring> #include <cstring>
#include <dlhttp/dlhttp.h>
TNetwork::TNetwork(TServer& Server, TPPSMonitor& PPSMonitor, TResourceManager& ResourceManager) TNetwork::TNetwork(TServer& Server, TPPSMonitor& PPSMonitor, TResourceManager& ResourceManager)
: mServer(Server) : mServer(Server)
@@ -149,12 +148,6 @@ void TNetwork::TCPServerMain() {
} }
Application::SetSubsystemStatus("TCPNetwork", Application::Status::Good); Application::SetSubsystemStatus("TCPNetwork", Application::Status::Good);
beammp_info("Vehicle event network online"); beammp_info("Vehicle event network online");
const auto ThreadCount = std::max(1, Application::Settings.DownloadThreads);
beammp_debugf("Using {} download threads", ThreadCount);
dlhttp::AsyncContext Ctx(ThreadCount);
dlhttp::EndpointHandlerMap Map {
{ "/modlist", [this]() -> dlhttp::Response { return { mResourceManager.FileList() }; } },
};
do { do {
try { try {
if (Application::IsShuttingDown()) { if (Application::IsShuttingDown()) {
@@ -180,15 +173,6 @@ void TNetwork::TCPServerMain() {
if (ret < 0) { if (ret < 0) {
throw std::runtime_error("setsockopt recv timeout: " + GetPlatformAgnosticErrorString()); throw std::runtime_error("setsockopt recv timeout: " + GetPlatformAgnosticErrorString());
} }
// check for http
if (dlhttp::is_http(client.Socket)) {
beammp_info("IS HTTP!");
dlhttp::handle_http(client.Socket, Ctx, Map);
} else {
beammp_info("IS NOT HTTP!");
}
std::thread ID(&TNetwork::Identify, this, client); std::thread ID(&TNetwork::Identify, this, client);
ID.detach(); // TODO: Add to a queue and attempt to join periodically ID.detach(); // TODO: Add to a queue and attempt to join periodically
} catch (const std::exception& e) { } catch (const std::exception& e) {