mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-02-16 10:41:01 +00:00
Compare commits
4 Commits
254-imscar
...
feature-dl
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b209e70d62 | ||
|
|
5394122d77 | ||
|
|
f48b8ff1a1 | ||
|
|
de2a3795cc |
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -31,3 +31,6 @@
|
||||
[submodule "deps/doctest"]
|
||||
path = deps/doctest
|
||||
url = https://github.com/doctest/doctest
|
||||
[submodule "deps/dlhttp"]
|
||||
path = deps/dlhttp
|
||||
url = https://github.com/lionkor/dlhttp
|
||||
|
||||
@@ -9,16 +9,20 @@ project(BeamMP-Server
|
||||
HOMEPAGE_URL https://beammp.com
|
||||
LANGUAGES CXX C)
|
||||
|
||||
find_package(Git REQUIRED)
|
||||
# Update submodules as needed
|
||||
option(GIT_SUBMODULE "Check submodules during build" ON)
|
||||
if(GIT_SUBMODULE)
|
||||
message(STATUS "Submodule update")
|
||||
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
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")
|
||||
option(BEAMMP_RUN_GIT "Run git to make sure submodules are updated (leave this on unless you know what you're doing)" ON)
|
||||
|
||||
if (BEAMMP_RUN_GIT)
|
||||
find_package(Git REQUIRED)
|
||||
# Update submodules as needed
|
||||
option(GIT_SUBMODULE "Check submodules during build" ON)
|
||||
if(GIT_SUBMODULE)
|
||||
message(STATUS "Submodule update")
|
||||
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
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()
|
||||
|
||||
@@ -52,7 +56,7 @@ elseif (WIN32)
|
||||
STRING(REPLACE "/MDd" "/MTd" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
|
||||
# ------------------------ LINUX ---------------------------------
|
||||
elseif (UNIX)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -static-libstdc++ -static-libgcc")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2 -fno-builtin")
|
||||
option(SANITIZE "Turns on thread and UB sanitizers" OFF)
|
||||
@@ -145,6 +149,7 @@ set(BeamMP_Libraries
|
||||
${LUA_LIBRARIES}
|
||||
commandline
|
||||
sentry
|
||||
dlhttp
|
||||
)
|
||||
|
||||
if (WIN32)
|
||||
|
||||
13
deps/CMakeLists.txt
vendored
13
deps/CMakeLists.txt
vendored
@@ -2,6 +2,13 @@ include_directories("${PROJECT_SOURCE_DIR}/deps")
|
||||
include_directories("${PROJECT_SOURCE_DIR}/deps/commandline")
|
||||
|
||||
add_subdirectory("${PROJECT_SOURCE_DIR}/deps/commandline")
|
||||
add_subdirectory("${PROJECT_SOURCE_DIR}/deps/fmt")
|
||||
add_subdirectory("${PROJECT_SOURCE_DIR}/deps/sol2")
|
||||
add_subdirectory("${PROJECT_SOURCE_DIR}/deps/doctest")
|
||||
if (NOT TARGET fmt)
|
||||
add_subdirectory("${PROJECT_SOURCE_DIR}/deps/fmt")
|
||||
endif()
|
||||
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")
|
||||
|
||||
1
deps/dlhttp
vendored
Submodule
1
deps/dlhttp
vendored
Submodule
Submodule deps/dlhttp added at f507c6c4e6
@@ -55,6 +55,7 @@ public:
|
||||
int MaxCars { 1 };
|
||||
bool DebugModeEnabled { false };
|
||||
int Port { 30814 };
|
||||
int DownloadThreads { 4 };
|
||||
std::string CustomIP {};
|
||||
bool LogChat { true };
|
||||
bool SendErrors { true };
|
||||
|
||||
@@ -18,6 +18,7 @@ static constexpr std::string_view StrDescription = "Description";
|
||||
static constexpr std::string_view StrResourceFolder = "ResourceFolder";
|
||||
static constexpr std::string_view StrAuthKey = "AuthKey";
|
||||
static constexpr std::string_view StrLogChat = "LogChat";
|
||||
static constexpr std::string_view StrDownloadThreads = "DownloadThreads";
|
||||
|
||||
// Misc
|
||||
static constexpr std::string_view StrSendErrors = "SendErrors";
|
||||
@@ -103,6 +104,8 @@ void TConfig::FlushToFile() {
|
||||
data["General"][StrMap.data()] = Application::Settings.MapName;
|
||||
data["General"][StrDescription.data()] = Application::Settings.ServerDesc;
|
||||
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
|
||||
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.");
|
||||
@@ -186,6 +189,7 @@ void TConfig::ParseFromFile(std::string_view name) {
|
||||
TryReadValue(data, "General", StrResourceFolder, Application::Settings.Resource);
|
||||
TryReadValue(data, "General", StrAuthKey, Application::Settings.Key);
|
||||
TryReadValue(data, "General", StrLogChat, Application::Settings.LogChat);
|
||||
TryReadValue(data, "General", StrDownloadThreads, Application::Settings.DownloadThreads);
|
||||
// Misc
|
||||
TryReadValue(data, "Misc", StrSendErrors, Application::Settings.SendErrors);
|
||||
TryReadValue(data, "Misc", StrHideUpdateMessages, Application::Settings.HideUpdateMessages);
|
||||
@@ -221,22 +225,26 @@ void TConfig::ParseFromFile(std::string_view name) {
|
||||
}
|
||||
|
||||
void TConfig::PrintDebug() {
|
||||
beammp_debug(std::string(StrDebug) + ": " + std::string(Application::Settings.DebugModeEnabled ? "true" : "false"));
|
||||
beammp_debug(std::string(StrPrivate) + ": " + std::string(Application::Settings.Private ? "true" : "false"));
|
||||
beammp_debug(std::string(StrPort) + ": " + std::to_string(Application::Settings.Port));
|
||||
beammp_debug(std::string(StrMaxCars) + ": " + std::to_string(Application::Settings.MaxCars));
|
||||
beammp_debug(std::string(StrMaxPlayers) + ": " + std::to_string(Application::Settings.MaxPlayers));
|
||||
beammp_debug(std::string(StrMap) + ": \"" + Application::Settings.MapName + "\"");
|
||||
beammp_debug(std::string(StrName) + ": \"" + Application::Settings.ServerName + "\"");
|
||||
beammp_debug(std::string(StrDescription) + ": \"" + Application::Settings.ServerDesc + "\"");
|
||||
beammp_debug(std::string(StrLogChat) + ": \"" + (Application::Settings.LogChat ? "true" : "false") + "\"");
|
||||
beammp_debug(std::string(StrResourceFolder) + ": \"" + Application::Settings.Resource + "\"");
|
||||
beammp_debug(std::string(StrSSLKeyPath) + ": \"" + Application::Settings.SSLKeyPath + "\"");
|
||||
beammp_debug(std::string(StrSSLCertPath) + ": \"" + Application::Settings.SSLCertPath + "\"");
|
||||
beammp_debug(std::string(StrHTTPServerPort) + ": \"" + std::to_string(Application::Settings.HTTPServerPort) + "\"");
|
||||
beammp_debug(std::string(StrHTTPServerIP) + ": \"" + Application::Settings.HTTPServerIP + "\"");
|
||||
beammp_debugf("{}: {}", StrDebug, Application::Settings.DebugModeEnabled ? "true" : "false");
|
||||
beammp_debugf("{}: {}", StrPrivate, Application::Settings.Private ? "true" : "false");
|
||||
beammp_debugf("{}: {}", StrPort, Application::Settings.Port);
|
||||
beammp_debugf("{}: {}", StrMaxCars, Application::Settings.MaxCars);
|
||||
beammp_debugf("{}: {}", StrMaxPlayers, Application::Settings.MaxPlayers);
|
||||
beammp_debugf("{}: '{}'", StrMap, Application::Settings.MapName);
|
||||
beammp_debugf("{}: '{}'", StrName, Application::Settings.ServerName);
|
||||
beammp_debugf("{}: '{}'", StrDescription, Application::Settings.ServerDesc);
|
||||
beammp_debugf("{}: {}", StrLogChat, Application::Settings.LogChat ? "true" : "false");
|
||||
beammp_debugf("{}: '{}'", StrResourceFolder, Application::Settings.Resource);
|
||||
beammp_debugf("{}: '{}'", StrSSLKeyPath, Application::Settings.SSLKeyPath);
|
||||
beammp_debugf("{}: '{}'", StrSSLCertPath, Application::Settings.SSLCertPath);
|
||||
beammp_debugf("{}: {}", StrHTTPServerPort, Application::Settings.HTTPServerPort);
|
||||
beammp_debugf("{}: '{}'", 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!
|
||||
beammp_debug("Key Length: " + std::to_string(Application::Settings.Key.length()) + "");
|
||||
beammp_debugf("Key Length: {}", Application::Settings.Key.length());
|
||||
}
|
||||
|
||||
void TConfig::ParseOldFormat() {
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <Http.h>
|
||||
#include <array>
|
||||
#include <cstring>
|
||||
#include <dlhttp/dlhttp.h>
|
||||
|
||||
TNetwork::TNetwork(TServer& Server, TPPSMonitor& PPSMonitor, TResourceManager& ResourceManager)
|
||||
: mServer(Server)
|
||||
@@ -148,6 +149,12 @@ void TNetwork::TCPServerMain() {
|
||||
}
|
||||
Application::SetSubsystemStatus("TCPNetwork", Application::Status::Good);
|
||||
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 {
|
||||
try {
|
||||
if (Application::IsShuttingDown()) {
|
||||
@@ -173,6 +180,15 @@ void TNetwork::TCPServerMain() {
|
||||
if (ret < 0) {
|
||||
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);
|
||||
ID.detach(); // TODO: Add to a queue and attempt to join periodically
|
||||
} catch (const std::exception& e) {
|
||||
|
||||
Reference in New Issue
Block a user