From 58e2383b2ede2d580d7f6b0d468c8568c5c75255 Mon Sep 17 00:00:00 2001 From: Mackenzie <41524393+Mack29446@users.noreply.github.com> Date: Wed, 13 Apr 2022 19:48:12 +0100 Subject: [PATCH 01/14] update version number in git checkout command --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ab685da..c1156de 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,7 @@ On windows, use git-bash for these commands. On Linux, these should work in your 1. Make sure you have all [prerequisites](#prerequisites) installed 2. Clone the repository in a location of your choice with `git clone --recurse-submodules https://github.com/BeamMP/BeamMP-Server`. 3. Ensure that all submodules are initialized by running `git submodule update --init --recursive`. Then change into the cloned directory by running `cd BeamMP-Server`. -4. Checkout the branch of the release you want to compile (`master` is often unstable), for example `git checkout tags/v2.3.3` for version 2.3.3. You can find the latest version [here](https://github.com/BeamMP/BeamMP-Server/tags). +4. Checkout the branch of the release you want to compile (`master` is often unstable), for example `git checkout tags/v3.0.1` for version 3.0.1. You can find the latest version [here](https://github.com/BeamMP/BeamMP-Server/tags). 5. Run `cmake . -DCMAKE_BUILD_TYPE=Release` (with `.`) 6. Run `make` 7. You will now have a `BeamMP-Server` file in your directory, which is executable with `./BeamMP-Server` (`.\BeamMP-Server.exe` for windows). Follow the (windows or linux, doesnt matter) instructions on the [wiki](https://wiki.beammp.com/en/home/Server_Mod) for further setup after installation (which we just did), such as port-forwarding and getting a key to actually run the server. From 3b2016d09f818864cfb7b3007e4fcd2757315913 Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Thu, 28 Apr 2022 14:58:07 +0200 Subject: [PATCH 02/14] Windows moment Windows deprecated when --- src/TConsole.cpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/TConsole.cpp b/src/TConsole.cpp index 13e8f2d..f6eb1fa 100644 --- a/src/TConsole.cpp +++ b/src/TConsole.cpp @@ -97,14 +97,6 @@ void TConsole::BackupOldLog() { } } -enum EscState { - None, - Escape, - FeSeqStart, - FeSeqMid, - SeqEnd -}; - void TConsole::StartLoggingToFile() { mLogFileStream.open("Server.log"); Application::Console().Internal().on_write = [this](const std::string& ToWrite) { From 8d7505956d86fbbd5b1f7496af2b413b360afa09 Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Thu, 28 Apr 2022 16:26:30 +0200 Subject: [PATCH 03/14] let's try vcpkg --- CMakeLists.txt | 132 +++++++++++++++++-------------------------- deps/CMakeLists.txt | 7 +-- include/TConfig.h | 2 +- include/TLuaEngine.h | 2 +- src/TSentry.cpp | 2 +- vcpkg.cmake | 18 ++++++ vcpkg.json | 17 ++++++ 7 files changed, 91 insertions(+), 89 deletions(-) create mode 100644 vcpkg.cmake create mode 100644 vcpkg.json diff --git a/CMakeLists.txt b/CMakeLists.txt index f6a813f..680cd8b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,17 @@ cmake_minimum_required(VERSION 3.0) +if (WIN32) + set(VCPKG_TARGET_TRIPLET "x64-windows-static") +elseif(UNIX) + set(VCPKG_TARGET_TRIPLET "x64-linux") +endif() + +option(USE_VCPKG "USE_VCPKG" ON) + +if(USE_VCPKG) + include(vcpkg.cmake) +endif() + message(STATUS "You can find build instructions and a list of dependencies in the README at \ https://github.com/BeamMP/BeamMP-Server") @@ -10,15 +22,6 @@ project(BeamMP-Server set(HTTPLIB_REQUIRE_OPENSSL ON) -include_directories("${PROJECT_SOURCE_DIR}/deps/asio/asio/include") -include_directories("${PROJECT_SOURCE_DIR}/deps/rapidjson/include") -include_directories("${PROJECT_SOURCE_DIR}/deps/websocketpp") -include_directories("${PROJECT_SOURCE_DIR}/deps/commandline") -include_directories("${PROJECT_SOURCE_DIR}/deps/sol2/include") -include_directories("${PROJECT_SOURCE_DIR}/deps/cpp-httplib") -include_directories("${PROJECT_SOURCE_DIR}/deps/json/single_include") -include_directories("${PROJECT_SOURCE_DIR}/deps") - add_compile_definitions(CPPHTTPLIB_OPENSSL_SUPPORT) if(APPLE) @@ -36,26 +39,6 @@ if (WIN32) STRING(REPLACE "/MDd" "/MTd" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG}) endif() -include_directories("include/sentry-native/include") -set(SENTRY_BUILD_SHARED_LIBS OFF) -if (MSVC) - set(SENTRY_BUILD_RUNTIMESTATIC ON) -endif() -message(STATUS "Checking for Sentry URL") -# this is set by the build system. -# IMPORTANT: if you're building from source, just leave this empty -if (NOT DEFINED BEAMMP_SECRET_SENTRY_URL) - message(WARNING "No sentry URL configured. Sentry logging is disabled for this build. \ - This is not an error, and if you're building the BeamMP-Server yourself, this is expected and can be ignored.") - set(BEAMMP_SECRET_SENTRY_URL "") - set(SENTRY_BACKEND none) -else() - string(LENGTH ${BEAMMP_SECRET_SENTRY_URL} URL_LEN) - message(STATUS "Sentry URL is length ${URL_LEN}") - set(SENTRY_BACKEND breakpad) -endif() -add_subdirectory("deps/sentry-native") - if (MSVC) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj") endif () @@ -81,7 +64,19 @@ elseif (UNIX) endif (SANITIZE) endif () - +message(STATUS "Checking for Sentry URL") +# this is set by the build system. +# IMPORTANT: if you're building from source, just leave this empty +if (NOT DEFINED BEAMMP_SECRET_SENTRY_URL) + message(WARNING "No sentry URL configured. Sentry logging is disabled for this build. \ + This is not an error, and if you're building the BeamMP-Server yourself, this is expected and can be ignored.") + set(BEAMMP_SECRET_SENTRY_URL "") + set(SENTRY_BACKEND none) +else() + string(LENGTH ${BEAMMP_SECRET_SENTRY_URL} URL_LEN) + message(STATUS "Sentry URL is length ${URL_LEN}") + set(SENTRY_BACKEND breakpad) +endif() set(CMAKE_CXX_STANDARD 17) @@ -113,57 +108,34 @@ add_executable(BeamMP-Server target_compile_definitions(BeamMP-Server PRIVATE SECRET_SENTRY_URL="${BEAMMP_SECRET_SENTRY_URL}") include_directories(BeamMP-Server PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) -target_include_directories(BeamMP-Server PUBLIC - "${CMAKE_CURRENT_SOURCE_DIR}/include" - "${CMAKE_CURRENT_SOURCE_DIR}/commandline") +include(FindThreads) -if (APPLE) - message(STATUS "NOT looking for Lua on APPLE") -else() - message(STATUS "Looking for Lua") - find_package(Lua REQUIRED VERSION 5.3) -endif() +find_package(OpenSSL REQUIRED) +find_package(ZLIB REQUIRED) +find_package(CURL CONFIG REQUIRED) +find_package(Lua REQUIRED 5.3) +find_package(nlohmann_json CONFIG REQUIRED) +find_package(RapidJSON CONFIG REQUIRED) +find_package(sentry CONFIG REQUIRED) +find_package(sol2 CONFIG REQUIRED) +find_package(toml11 CONFIG REQUIRED) +find_path(CPP_HTTPLIB_INCLUDE_DIRS "httplib.h") -target_include_directories(BeamMP-Server PUBLIC - ${LUA_INCLUDE_DIR} - ${CURL_INCLUDE_DIRS} - "include/tomlplusplus" - "include/sentry-native/include" - "include/curl/include") +target_include_directories(BeamMP-Server PRIVATE + ${CPP_HTTPLIB_INCLUDE_DIRS} + ${LUA_INCLUDE_DIR} +) -message(STATUS "Looking for SSL") +target_link_libraries(BeamMP-Server PRIVATE OpenSSL::SSL OpenSSL::Crypto + ZLIB::ZLIB + CURL::libcurl + ${LUA_LIBRARIES} + Threads::Threads + commandline + nlohmann_json::nlohmann_json + rapidjson + sentry::sentry + sol2::sol2 + toml11::toml11 +) -if (APPLE) - set(OPENSSL_LIBRARIES ssl crypto) -else() - find_package(OpenSSL REQUIRED) -endif() - -target_link_libraries(BeamMP-Server sol2::sol2 ${LUA_LIBRARIES}) -message(STATUS "CURL IS ${CURL_LIBRARIES}") - -if (UNIX) - target_link_libraries(BeamMP-Server - z - pthread - ${LUA_LIBRARIES} - crypto - ${OPENSSL_LIBRARIES} - commandline - sentry - ssl) -elseif (WIN32) - include(FindLua) - message(STATUS "Looking for libz") - find_package(ZLIB REQUIRED) - message(STATUS "Looking for RapidJSON") - find_package(RapidJSON CONFIG REQUIRED) - target_include_directories(BeamMP-Server PRIVATE ${RAPIDJSON_INCLUDE_DIRS}) - target_link_libraries(BeamMP-Server - ws2_32 - ZLIB::ZLIB - ${LUA_LIBRARIES} - ${OPENSSL_LIBRARIES} - commandline - sentry) -endif () diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt index 4e556b0..6f87000 100644 --- a/deps/CMakeLists.txt +++ b/deps/CMakeLists.txt @@ -1,9 +1,4 @@ -include_directories("${PROJECT_SOURCE_DIR}/deps/asio/asio/include") -include_directories("${PROJECT_SOURCE_DIR}/deps/rapidjson/include") -include_directories("${PROJECT_SOURCE_DIR}/deps/websocketpp") -include_directories("${PROJECT_SOURCE_DIR}/deps/commandline") -include_directories("${PROJECT_SOURCE_DIR}/deps/sol2/include") 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/sol2") diff --git a/include/TConfig.h b/include/TConfig.h index 3fcc597..b05f422 100644 --- a/include/TConfig.h +++ b/include/TConfig.h @@ -5,7 +5,7 @@ #include #define TOML11_PRESERVE_COMMENTS_BY_DEFAULT -#include // header-only version of TOML++ +#include // header-only version of TOML++ namespace fs = std::filesystem; diff --git a/include/TLuaEngine.h b/include/TLuaEngine.h index 5ca2222..876d910 100644 --- a/include/TLuaEngine.h +++ b/include/TLuaEngine.h @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/TSentry.cpp b/src/TSentry.cpp index da05c10..7f2b416 100644 --- a/src/TSentry.cpp +++ b/src/TSentry.cpp @@ -72,7 +72,7 @@ void TSentry::Log(SentryLevel level, const std::string& logger, const std::strin SetContext("threads", { { "thread-name", ThreadName(true) } }); auto Msg = sentry_value_new_message_event(sentry_level_t(level), logger.c_str(), text.c_str()); sentry_capture_event(Msg); - sentry_remove_transaction(); + sentry_set_transaction(nullptr); } void TSentry::LogError(const std::string& text, const std::string& file, const std::string& line) { diff --git a/vcpkg.cmake b/vcpkg.cmake new file mode 100644 index 0000000..56b51e5 --- /dev/null +++ b/vcpkg.cmake @@ -0,0 +1,18 @@ +include(FetchContent) + +message(STATUS "Getting, checking and running vcpkg, this may take a while") + +FetchContent_Declare( + vcpkg + GIT_REPOSITORY https://github.com/microsoft/vcpkg.git +) + +FetchContent_GetProperties(vcpkg) + +if(NOT vcpkg_POPULATED) + FetchContent_Populate(vcpkg) + execute_process(COMMAND ./${vcpkg_SOURCE_DIR}/bootstrap-vcpkg.sh) +endif() + +set(CMAKE_TOOLCHAIN_FILE ${vcpkg_SOURCE_DIR}/scripts/buildsystems/vcpkg.cmake +CACHE STRING "Vcpkg toolchain file") diff --git a/vcpkg.json b/vcpkg.json new file mode 100644 index 0000000..f28fa5b --- /dev/null +++ b/vcpkg.json @@ -0,0 +1,17 @@ +{ + "name": "beammp-server", + "version-string": "3.0.2", + "homepage": "https://beammp.com", + "dependencies": [ + "sentry-native", + "lua", + "zlib", + "rapidjson", + "nlohmann-json", + "openssl", + "curl", + "sol2", + "cpp-httplib", + "toml11" + ] +} From a5153e4bc111d5b08acc4504277ae555af7225e9 Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Thu, 28 Apr 2022 16:28:23 +0200 Subject: [PATCH 04/14] Remove unneeded submodules --- .gitmodules | 24 ------------------------ deps/asio | 1 - deps/cpp-httplib | 1 - deps/json | 1 - deps/libzip | 1 - deps/rapidjson | 1 - deps/sentry-native | 1 - deps/sol2 | 1 - deps/toml11 | 1 - 9 files changed, 32 deletions(-) delete mode 160000 deps/asio delete mode 160000 deps/cpp-httplib delete mode 160000 deps/json delete mode 160000 deps/libzip delete mode 160000 deps/rapidjson delete mode 160000 deps/sentry-native delete mode 160000 deps/sol2 delete mode 160000 deps/toml11 diff --git a/.gitmodules b/.gitmodules index b54a97b..5cfa6fa 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,27 +1,3 @@ [submodule "deps/commandline"] path = deps/commandline url = https://github.com/lionkor/commandline -[submodule "deps/asio"] - path = deps/asio - url = https://github.com/chriskohlhoff/asio -[submodule "deps/rapidjson"] - path = deps/rapidjson - url = https://github.com/Tencent/rapidjson -[submodule "deps/toml11"] - path = deps/toml11 - url = https://github.com/ToruNiina/toml11 -[submodule "deps/sentry-native"] - path = deps/sentry-native - url = https://github.com/getsentry/sentry-native -[submodule "deps/sol2"] - path = deps/sol2 - url = https://github.com/ThePhD/sol2 -[submodule "deps/libzip"] - path = deps/libzip - url = https://github.com/nih-at/libzip -[submodule "deps/cpp-httplib"] - path = deps/cpp-httplib - url = https://github.com/yhirose/cpp-httplib -[submodule "deps/json"] - path = deps/json - url = https://github.com/nlohmann/json diff --git a/deps/asio b/deps/asio deleted file mode 160000 index d038fb3..0000000 --- a/deps/asio +++ /dev/null @@ -1 +0,0 @@ -Subproject commit d038fb3c2fb56fb91ff1d17b0715cff7887aa09e diff --git a/deps/cpp-httplib b/deps/cpp-httplib deleted file mode 160000 index b324921..0000000 --- a/deps/cpp-httplib +++ /dev/null @@ -1 +0,0 @@ -Subproject commit b324921c1aeff2976544128e4bb2a0979a4aa595 diff --git a/deps/json b/deps/json deleted file mode 160000 index eb21824..0000000 --- a/deps/json +++ /dev/null @@ -1 +0,0 @@ -Subproject commit eb2182414749825be086c825edb5229e5c28503d diff --git a/deps/libzip b/deps/libzip deleted file mode 160000 index 76df02f..0000000 --- a/deps/libzip +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 76df02f86b9746e139fd9fc934a70e3a21bbc557 diff --git a/deps/rapidjson b/deps/rapidjson deleted file mode 160000 index 00dbcf2..0000000 --- a/deps/rapidjson +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 00dbcf2c6e03c47d6c399338b6de060c71356464 diff --git a/deps/sentry-native b/deps/sentry-native deleted file mode 160000 index 90966cc..0000000 --- a/deps/sentry-native +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 90966cc1022b8155681b6899539b35466baccf2c diff --git a/deps/sol2 b/deps/sol2 deleted file mode 160000 index c068aef..0000000 --- a/deps/sol2 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit c068aefbeddb3dd1f1fd38d42843ecb49a3b4cdb diff --git a/deps/toml11 b/deps/toml11 deleted file mode 160000 index fda0a2b..0000000 --- a/deps/toml11 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit fda0a2b9abd16e356f777c40a675131821c71b00 From d8526f06495b4685e02a96b62d23a62eb0cd11a1 Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Sun, 29 May 2022 14:30:57 +0200 Subject: [PATCH 05/14] TNetwork::SplitLoad: Use managed memory --- src/TNetwork.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/TNetwork.cpp b/src/TNetwork.cpp index 03c90f1..d9edc81 100644 --- a/src/TNetwork.cpp +++ b/src/TNetwork.cpp @@ -756,11 +756,11 @@ void TNetwork::SendFile(TClient& c, const std::string& UnsafeName) { void TNetwork::SplitLoad(TClient& c, size_t Sent, size_t Size, bool D, const std::string& Name) { std::ifstream f(Name.c_str(), std::ios::binary); uint32_t Split = 0x7735940; // 125MB - char* Data; + std::vector Data; if (Size > Split) - Data = new char[Split]; + Data.resize(Split); else - Data = new char[Size]; + Data.resize(Size); SOCKET TCPSock; if (D) TCPSock = c.GetDownSock(); @@ -771,8 +771,8 @@ void TNetwork::SplitLoad(TClient& c, size_t Sent, size_t Size, bool D, const std size_t Diff = Size - Sent; if (Diff > Split) { f.seekg(Sent, std::ios_base::beg); - f.read(Data, Split); - if (!TCPSendRaw(c, TCPSock, Data, Split)) { + f.read(Data.data(), Split); + if (!TCPSendRaw(c, TCPSock, Data.data(), Split)) { if (c.GetStatus() > -1) c.SetStatus(-1); break; @@ -780,8 +780,8 @@ void TNetwork::SplitLoad(TClient& c, size_t Sent, size_t Size, bool D, const std Sent += Split; } else { f.seekg(Sent, std::ios_base::beg); - f.read(Data, Diff); - if (!TCPSendRaw(c, TCPSock, Data, int32_t(Diff))) { + f.read(Data.data(), Diff); + if (!TCPSendRaw(c, TCPSock, Data.data(), int32_t(Diff))) { if (c.GetStatus() > -1) c.SetStatus(-1); break; @@ -789,8 +789,6 @@ void TNetwork::SplitLoad(TClient& c, size_t Sent, size_t Size, bool D, const std Sent += Diff; } } - delete[] Data; - f.close(); } bool TNetwork::TCPSendRaw(TClient& C, SOCKET socket, char* Data, int32_t Size) { From 1970d97ea415a43a9d1d97f4a704fd0656a57d4f Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Sun, 29 May 2022 14:37:41 +0200 Subject: [PATCH 06/14] Revert "Remove unneeded submodules" This reverts commit a5153e4bc111d5b08acc4504277ae555af7225e9. --- .gitmodules | 24 ++++++++++++++++++++++++ deps/asio | 1 + deps/cpp-httplib | 1 + deps/json | 1 + deps/libzip | 1 + deps/rapidjson | 1 + deps/sentry-native | 1 + deps/sol2 | 1 + deps/toml11 | 1 + 9 files changed, 32 insertions(+) create mode 160000 deps/asio create mode 160000 deps/cpp-httplib create mode 160000 deps/json create mode 160000 deps/libzip create mode 160000 deps/rapidjson create mode 160000 deps/sentry-native create mode 160000 deps/sol2 create mode 160000 deps/toml11 diff --git a/.gitmodules b/.gitmodules index 5cfa6fa..b54a97b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,27 @@ [submodule "deps/commandline"] path = deps/commandline url = https://github.com/lionkor/commandline +[submodule "deps/asio"] + path = deps/asio + url = https://github.com/chriskohlhoff/asio +[submodule "deps/rapidjson"] + path = deps/rapidjson + url = https://github.com/Tencent/rapidjson +[submodule "deps/toml11"] + path = deps/toml11 + url = https://github.com/ToruNiina/toml11 +[submodule "deps/sentry-native"] + path = deps/sentry-native + url = https://github.com/getsentry/sentry-native +[submodule "deps/sol2"] + path = deps/sol2 + url = https://github.com/ThePhD/sol2 +[submodule "deps/libzip"] + path = deps/libzip + url = https://github.com/nih-at/libzip +[submodule "deps/cpp-httplib"] + path = deps/cpp-httplib + url = https://github.com/yhirose/cpp-httplib +[submodule "deps/json"] + path = deps/json + url = https://github.com/nlohmann/json diff --git a/deps/asio b/deps/asio new file mode 160000 index 0000000..d038fb3 --- /dev/null +++ b/deps/asio @@ -0,0 +1 @@ +Subproject commit d038fb3c2fb56fb91ff1d17b0715cff7887aa09e diff --git a/deps/cpp-httplib b/deps/cpp-httplib new file mode 160000 index 0000000..b324921 --- /dev/null +++ b/deps/cpp-httplib @@ -0,0 +1 @@ +Subproject commit b324921c1aeff2976544128e4bb2a0979a4aa595 diff --git a/deps/json b/deps/json new file mode 160000 index 0000000..eb21824 --- /dev/null +++ b/deps/json @@ -0,0 +1 @@ +Subproject commit eb2182414749825be086c825edb5229e5c28503d diff --git a/deps/libzip b/deps/libzip new file mode 160000 index 0000000..76df02f --- /dev/null +++ b/deps/libzip @@ -0,0 +1 @@ +Subproject commit 76df02f86b9746e139fd9fc934a70e3a21bbc557 diff --git a/deps/rapidjson b/deps/rapidjson new file mode 160000 index 0000000..00dbcf2 --- /dev/null +++ b/deps/rapidjson @@ -0,0 +1 @@ +Subproject commit 00dbcf2c6e03c47d6c399338b6de060c71356464 diff --git a/deps/sentry-native b/deps/sentry-native new file mode 160000 index 0000000..90966cc --- /dev/null +++ b/deps/sentry-native @@ -0,0 +1 @@ +Subproject commit 90966cc1022b8155681b6899539b35466baccf2c diff --git a/deps/sol2 b/deps/sol2 new file mode 160000 index 0000000..c068aef --- /dev/null +++ b/deps/sol2 @@ -0,0 +1 @@ +Subproject commit c068aefbeddb3dd1f1fd38d42843ecb49a3b4cdb diff --git a/deps/toml11 b/deps/toml11 new file mode 160000 index 0000000..fda0a2b --- /dev/null +++ b/deps/toml11 @@ -0,0 +1 @@ +Subproject commit fda0a2b9abd16e356f777c40a675131821c71b00 From 758d5b2c968d0301d01fe3fb1e573e547bedfd03 Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Sun, 29 May 2022 14:37:50 +0200 Subject: [PATCH 07/14] Revert "let's try vcpkg" This reverts commit 8d7505956d86fbbd5b1f7496af2b413b360afa09. --- CMakeLists.txt | 132 ++++++++++++++++++++++++++----------------- deps/CMakeLists.txt | 7 ++- include/TConfig.h | 2 +- include/TLuaEngine.h | 2 +- src/TSentry.cpp | 2 +- vcpkg.cmake | 18 ------ vcpkg.json | 17 ------ 7 files changed, 89 insertions(+), 91 deletions(-) delete mode 100644 vcpkg.cmake delete mode 100644 vcpkg.json diff --git a/CMakeLists.txt b/CMakeLists.txt index 680cd8b..f6a813f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,17 +1,5 @@ cmake_minimum_required(VERSION 3.0) -if (WIN32) - set(VCPKG_TARGET_TRIPLET "x64-windows-static") -elseif(UNIX) - set(VCPKG_TARGET_TRIPLET "x64-linux") -endif() - -option(USE_VCPKG "USE_VCPKG" ON) - -if(USE_VCPKG) - include(vcpkg.cmake) -endif() - message(STATUS "You can find build instructions and a list of dependencies in the README at \ https://github.com/BeamMP/BeamMP-Server") @@ -22,6 +10,15 @@ project(BeamMP-Server set(HTTPLIB_REQUIRE_OPENSSL ON) +include_directories("${PROJECT_SOURCE_DIR}/deps/asio/asio/include") +include_directories("${PROJECT_SOURCE_DIR}/deps/rapidjson/include") +include_directories("${PROJECT_SOURCE_DIR}/deps/websocketpp") +include_directories("${PROJECT_SOURCE_DIR}/deps/commandline") +include_directories("${PROJECT_SOURCE_DIR}/deps/sol2/include") +include_directories("${PROJECT_SOURCE_DIR}/deps/cpp-httplib") +include_directories("${PROJECT_SOURCE_DIR}/deps/json/single_include") +include_directories("${PROJECT_SOURCE_DIR}/deps") + add_compile_definitions(CPPHTTPLIB_OPENSSL_SUPPORT) if(APPLE) @@ -39,6 +36,26 @@ if (WIN32) STRING(REPLACE "/MDd" "/MTd" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG}) endif() +include_directories("include/sentry-native/include") +set(SENTRY_BUILD_SHARED_LIBS OFF) +if (MSVC) + set(SENTRY_BUILD_RUNTIMESTATIC ON) +endif() +message(STATUS "Checking for Sentry URL") +# this is set by the build system. +# IMPORTANT: if you're building from source, just leave this empty +if (NOT DEFINED BEAMMP_SECRET_SENTRY_URL) + message(WARNING "No sentry URL configured. Sentry logging is disabled for this build. \ + This is not an error, and if you're building the BeamMP-Server yourself, this is expected and can be ignored.") + set(BEAMMP_SECRET_SENTRY_URL "") + set(SENTRY_BACKEND none) +else() + string(LENGTH ${BEAMMP_SECRET_SENTRY_URL} URL_LEN) + message(STATUS "Sentry URL is length ${URL_LEN}") + set(SENTRY_BACKEND breakpad) +endif() +add_subdirectory("deps/sentry-native") + if (MSVC) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj") endif () @@ -64,19 +81,7 @@ elseif (UNIX) endif (SANITIZE) endif () -message(STATUS "Checking for Sentry URL") -# this is set by the build system. -# IMPORTANT: if you're building from source, just leave this empty -if (NOT DEFINED BEAMMP_SECRET_SENTRY_URL) - message(WARNING "No sentry URL configured. Sentry logging is disabled for this build. \ - This is not an error, and if you're building the BeamMP-Server yourself, this is expected and can be ignored.") - set(BEAMMP_SECRET_SENTRY_URL "") - set(SENTRY_BACKEND none) -else() - string(LENGTH ${BEAMMP_SECRET_SENTRY_URL} URL_LEN) - message(STATUS "Sentry URL is length ${URL_LEN}") - set(SENTRY_BACKEND breakpad) -endif() + set(CMAKE_CXX_STANDARD 17) @@ -108,34 +113,57 @@ add_executable(BeamMP-Server target_compile_definitions(BeamMP-Server PRIVATE SECRET_SENTRY_URL="${BEAMMP_SECRET_SENTRY_URL}") include_directories(BeamMP-Server PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) -include(FindThreads) +target_include_directories(BeamMP-Server PUBLIC + "${CMAKE_CURRENT_SOURCE_DIR}/include" + "${CMAKE_CURRENT_SOURCE_DIR}/commandline") -find_package(OpenSSL REQUIRED) -find_package(ZLIB REQUIRED) -find_package(CURL CONFIG REQUIRED) -find_package(Lua REQUIRED 5.3) -find_package(nlohmann_json CONFIG REQUIRED) -find_package(RapidJSON CONFIG REQUIRED) -find_package(sentry CONFIG REQUIRED) -find_package(sol2 CONFIG REQUIRED) -find_package(toml11 CONFIG REQUIRED) -find_path(CPP_HTTPLIB_INCLUDE_DIRS "httplib.h") +if (APPLE) + message(STATUS "NOT looking for Lua on APPLE") +else() + message(STATUS "Looking for Lua") + find_package(Lua REQUIRED VERSION 5.3) +endif() -target_include_directories(BeamMP-Server PRIVATE - ${CPP_HTTPLIB_INCLUDE_DIRS} - ${LUA_INCLUDE_DIR} -) +target_include_directories(BeamMP-Server PUBLIC + ${LUA_INCLUDE_DIR} + ${CURL_INCLUDE_DIRS} + "include/tomlplusplus" + "include/sentry-native/include" + "include/curl/include") -target_link_libraries(BeamMP-Server PRIVATE OpenSSL::SSL OpenSSL::Crypto - ZLIB::ZLIB - CURL::libcurl - ${LUA_LIBRARIES} - Threads::Threads - commandline - nlohmann_json::nlohmann_json - rapidjson - sentry::sentry - sol2::sol2 - toml11::toml11 -) +message(STATUS "Looking for SSL") +if (APPLE) + set(OPENSSL_LIBRARIES ssl crypto) +else() + find_package(OpenSSL REQUIRED) +endif() + +target_link_libraries(BeamMP-Server sol2::sol2 ${LUA_LIBRARIES}) +message(STATUS "CURL IS ${CURL_LIBRARIES}") + +if (UNIX) + target_link_libraries(BeamMP-Server + z + pthread + ${LUA_LIBRARIES} + crypto + ${OPENSSL_LIBRARIES} + commandline + sentry + ssl) +elseif (WIN32) + include(FindLua) + message(STATUS "Looking for libz") + find_package(ZLIB REQUIRED) + message(STATUS "Looking for RapidJSON") + find_package(RapidJSON CONFIG REQUIRED) + target_include_directories(BeamMP-Server PRIVATE ${RAPIDJSON_INCLUDE_DIRS}) + target_link_libraries(BeamMP-Server + ws2_32 + ZLIB::ZLIB + ${LUA_LIBRARIES} + ${OPENSSL_LIBRARIES} + commandline + sentry) +endif () diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt index 6f87000..4e556b0 100644 --- a/deps/CMakeLists.txt +++ b/deps/CMakeLists.txt @@ -1,4 +1,9 @@ -include_directories("${PROJECT_SOURCE_DIR}/deps") +include_directories("${PROJECT_SOURCE_DIR}/deps/asio/asio/include") +include_directories("${PROJECT_SOURCE_DIR}/deps/rapidjson/include") +include_directories("${PROJECT_SOURCE_DIR}/deps/websocketpp") include_directories("${PROJECT_SOURCE_DIR}/deps/commandline") +include_directories("${PROJECT_SOURCE_DIR}/deps/sol2/include") +include_directories("${PROJECT_SOURCE_DIR}/deps") add_subdirectory("${PROJECT_SOURCE_DIR}/deps/commandline") +add_subdirectory("${PROJECT_SOURCE_DIR}/deps/sol2") diff --git a/include/TConfig.h b/include/TConfig.h index b05f422..3fcc597 100644 --- a/include/TConfig.h +++ b/include/TConfig.h @@ -5,7 +5,7 @@ #include #define TOML11_PRESERVE_COMMENTS_BY_DEFAULT -#include // header-only version of TOML++ +#include // header-only version of TOML++ namespace fs = std::filesystem; diff --git a/include/TLuaEngine.h b/include/TLuaEngine.h index 876d910..5ca2222 100644 --- a/include/TLuaEngine.h +++ b/include/TLuaEngine.h @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/TSentry.cpp b/src/TSentry.cpp index 7f2b416..da05c10 100644 --- a/src/TSentry.cpp +++ b/src/TSentry.cpp @@ -72,7 +72,7 @@ void TSentry::Log(SentryLevel level, const std::string& logger, const std::strin SetContext("threads", { { "thread-name", ThreadName(true) } }); auto Msg = sentry_value_new_message_event(sentry_level_t(level), logger.c_str(), text.c_str()); sentry_capture_event(Msg); - sentry_set_transaction(nullptr); + sentry_remove_transaction(); } void TSentry::LogError(const std::string& text, const std::string& file, const std::string& line) { diff --git a/vcpkg.cmake b/vcpkg.cmake deleted file mode 100644 index 56b51e5..0000000 --- a/vcpkg.cmake +++ /dev/null @@ -1,18 +0,0 @@ -include(FetchContent) - -message(STATUS "Getting, checking and running vcpkg, this may take a while") - -FetchContent_Declare( - vcpkg - GIT_REPOSITORY https://github.com/microsoft/vcpkg.git -) - -FetchContent_GetProperties(vcpkg) - -if(NOT vcpkg_POPULATED) - FetchContent_Populate(vcpkg) - execute_process(COMMAND ./${vcpkg_SOURCE_DIR}/bootstrap-vcpkg.sh) -endif() - -set(CMAKE_TOOLCHAIN_FILE ${vcpkg_SOURCE_DIR}/scripts/buildsystems/vcpkg.cmake -CACHE STRING "Vcpkg toolchain file") diff --git a/vcpkg.json b/vcpkg.json deleted file mode 100644 index f28fa5b..0000000 --- a/vcpkg.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "name": "beammp-server", - "version-string": "3.0.2", - "homepage": "https://beammp.com", - "dependencies": [ - "sentry-native", - "lua", - "zlib", - "rapidjson", - "nlohmann-json", - "openssl", - "curl", - "sol2", - "cpp-httplib", - "toml11" - ] -} From 06f8ba5a0eae98d35cd8b7d27973cadb99d9d3e1 Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Sat, 9 Jul 2022 21:11:34 +0200 Subject: [PATCH 08/14] update sentry-native to 0.4.18 --- deps/sentry-native | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps/sentry-native b/deps/sentry-native index 90966cc..ff5bfcf 160000 --- a/deps/sentry-native +++ b/deps/sentry-native @@ -1 +1 @@ -Subproject commit 90966cc1022b8155681b6899539b35466baccf2c +Subproject commit ff5bfcf0eb2c47d03eb57a51bdf2e6ad4b8ece10 From 420e6c353376260542e387c87e636d49dc7dbc2f Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Sat, 9 Jul 2022 21:40:19 +0200 Subject: [PATCH 09/14] roll back to an ancient version of sentry sentry-native deprecated compiling without error somewhere around one of the next version --- CMakeLists.txt | 2 +- deps/sentry-native | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f6a813f..7ada026 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,7 +37,7 @@ if (WIN32) endif() include_directories("include/sentry-native/include") -set(SENTRY_BUILD_SHARED_LIBS OFF) +set(BUILD_SHARED_LIBS OFF) if (MSVC) set(SENTRY_BUILD_RUNTIMESTATIC ON) endif() diff --git a/deps/sentry-native b/deps/sentry-native index ff5bfcf..90966cc 160000 --- a/deps/sentry-native +++ b/deps/sentry-native @@ -1 +1 @@ -Subproject commit ff5bfcf0eb2c47d03eb57a51bdf2e6ad4b8ece10 +Subproject commit 90966cc1022b8155681b6899539b35466baccf2c From 98681254e63211b45e576dde55ac17be363cf801 Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Sat, 9 Jul 2022 21:50:23 +0200 Subject: [PATCH 10/14] update toml11 --- deps/toml11 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps/toml11 b/deps/toml11 index fda0a2b..1400dd2 160000 --- a/deps/toml11 +++ b/deps/toml11 @@ -1 +1 @@ -Subproject commit fda0a2b9abd16e356f777c40a675131821c71b00 +Subproject commit 1400dd223fb4297337266fcb5d04b700338aea71 From 696e080e1c20ab99f9afc081870974891a436b01 Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Sat, 9 Jul 2022 21:57:24 +0200 Subject: [PATCH 11/14] fix #105 --- src/TConfig.cpp | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/src/TConfig.cpp b/src/TConfig.cpp index f21954e..4a414da 100644 --- a/src/TConfig.cpp +++ b/src/TConfig.cpp @@ -91,8 +91,14 @@ void TConfig::FlushToFile() { SetComment(data["HTTP"][StrHTTPServerUseSSL.data()].comments(), " Recommended to have enabled for servers which face the internet. With SSL the server will serve https and requires valid key and cert files"); data["HTTP"][StrHTTPServerEnabled.data()] = Application::Settings.HTTPServerEnabled; SetComment(data["HTTP"][StrHTTPServerEnabled.data()].comments(), " Enables the internal HTTP server"); + std::stringstream Ss; + Ss << data; std::ofstream Stream(mConfigFileName, std::ios::trunc | std::ios::out); - Stream << data << std::flush; + Stream << "# This is the BeamMP-Server config file.\n" + "# Help & Documentation: `https://wiki.beammp.com/en/home/server-maintenance`\n" + "# IMPORTANT: Fill in the AuthKey with the key you got from `https://beammp.com/k/dashboard` on the left under \"Keys\"\n" + << Ss.str(); + Stream.flush(); } void TConfig::CreateConfigFile(std::string_view name) { @@ -112,27 +118,6 @@ void TConfig::CreateConfigFile(std::string_view name) { } FlushToFile(); - - size_t FileSize = fs::file_size(name); - std::fstream ofs { std::string(name), std::ios::in | std::ios::out }; - if (ofs.good()) { - std::string Contents {}; - Contents.resize(FileSize); - ofs.readsome(Contents.data(), FileSize); - ofs.seekp(0); - ofs << "# This is the BeamMP-Server config file.\n" - "# Help & Documentation: `https://wiki.beammp.com/en/home/server-maintenance`\n" - "# IMPORTANT: Fill in the AuthKey with the key you got from `https://beammp.com/k/dashboard` on the left under \"Keys\"\n" - << '\n' - << Contents; - beammp_error("There was no \"" + std::string(mConfigFileName) + "\" file (this is normal for the first time running the server), so one was generated for you. It was automatically filled with the settings from your Server.cfg, if you have one. Please open ServerConfig.toml and ensure your AuthKey and other settings are filled in and correct, then restart the server. The old Server.cfg file will no longer be used and causes a warning if it exists from now on."); - mFailed = true; - ofs.close(); - } else { - beammp_error("Couldn't create " + std::string(name) + ". Check permissions, try again, and contact support if it continues not to work."); - Application::SetSubsystemStatus("Config", Application::Status::Bad); - mFailed = true; - } } void TConfig::TryReadValue(toml::value& Table, const std::string& Category, const std::string_view& Key, std::string& OutValue) { From 38eeec39b49872d0d79ebd49f98d0e65d2ab25cb Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Sat, 9 Jul 2022 22:27:05 +0200 Subject: [PATCH 12/14] another attempt to fix #105 --- Changelog.md | 1 + src/TConfig.cpp | 25 ++++++++++++++----------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/Changelog.md b/Changelog.md index 7ff6d04..0486505 100644 --- a/Changelog.md +++ b/Changelog.md @@ -7,6 +7,7 @@ - FIXED `MP.CreateEventTimer` filling up the queue (see ) - FIXED `MP.TriggerClientEvent` not kicking the client if it failed - FIXED Lua result queue handling not checking all results +- FIXED bug which caused ServerConfig.toml to generate incorrectly # v3.0.1 diff --git a/src/TConfig.cpp b/src/TConfig.cpp index 4a414da..65c7ba0 100644 --- a/src/TConfig.cpp +++ b/src/TConfig.cpp @@ -92,13 +92,20 @@ void TConfig::FlushToFile() { data["HTTP"][StrHTTPServerEnabled.data()] = Application::Settings.HTTPServerEnabled; SetComment(data["HTTP"][StrHTTPServerEnabled.data()].comments(), " Enables the internal HTTP server"); std::stringstream Ss; - Ss << data; - std::ofstream Stream(mConfigFileName, std::ios::trunc | std::ios::out); - Stream << "# This is the BeamMP-Server config file.\n" - "# Help & Documentation: `https://wiki.beammp.com/en/home/server-maintenance`\n" - "# IMPORTANT: Fill in the AuthKey with the key you got from `https://beammp.com/k/dashboard` on the left under \"Keys\"\n" - << Ss.str(); - Stream.flush(); + Ss << "# This is the BeamMP-Server config file.\n" + "# Help & Documentation: `https://wiki.beammp.com/en/home/server-maintenance`\n" + "# IMPORTANT: Fill in the AuthKey with the key you got from `https://beammp.com/k/dashboard` on the left under \"Keys\"\n" + << data; + auto File = std::fopen(mConfigFileName.c_str(), "w+"); + if (!File) { + beammp_error("Failed to create/write to config file: " + GetPlatformAgnosticErrorString()); + throw std::runtime_error("Failed to create/write to config file"); + } + auto Str = Ss.str(); + auto N = std::fwrite(Str.data(), sizeof(char), Str.size(), File); + if (N != Str.size()) { + beammp_error("Failed to write to config file properly, config file might be misshapen"); + } } void TConfig::CreateConfigFile(std::string_view name) { @@ -113,10 +120,6 @@ void TConfig::CreateConfigFile(std::string_view name) { beammp_error("an error occurred and was ignored during config transfer: " + std::string(e.what())); } - { // create file context - std::ofstream ofs(name.data()); - } - FlushToFile(); } From 6c1d02a425037122bc6140b3c85ca8b21c126ca8 Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Sat, 9 Jul 2022 22:29:12 +0200 Subject: [PATCH 13/14] add fclose --- src/TConfig.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/TConfig.cpp b/src/TConfig.cpp index 65c7ba0..8d445c9 100644 --- a/src/TConfig.cpp +++ b/src/TConfig.cpp @@ -106,6 +106,7 @@ void TConfig::FlushToFile() { if (N != Str.size()) { beammp_error("Failed to write to config file properly, config file might be misshapen"); } + std::fclose(File); } void TConfig::CreateConfigFile(std::string_view name) { From f8d622352f4e4ebcee73400c499deeefd0f76d30 Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Sat, 9 Jul 2022 22:42:38 +0200 Subject: [PATCH 14/14] generate toml from scratch --- src/TConfig.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/TConfig.cpp b/src/TConfig.cpp index 8d445c9..531fd59 100644 --- a/src/TConfig.cpp +++ b/src/TConfig.cpp @@ -62,7 +62,8 @@ void SetComment(CommentsT& Comments, const std::string& Comment) { * whether it is in TConfig.cpp or the configuration file. */ void TConfig::FlushToFile() { - auto data = toml::parse(mConfigFileName); + // auto data = toml::parse(mConfigFileName); + auto data = toml::value {}; data["General"][StrAuthKey.data()] = Application::Settings.Key; SetComment(data["General"][StrAuthKey.data()].comments(), " AuthKey has to be filled out in order to run the server"); data["General"][StrDebug.data()] = Application::Settings.DebugModeEnabled;