mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-07-17 12:13:57 +00:00
Compare commits
71 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3f7cf7a258 | |||
| f0141e4fd3 | |||
| 00560f7646 | |||
| 27d50fc2b5 | |||
| 6014536f52 | |||
| fbce8a946e | |||
| bd9b6212e2 | |||
| b112ee20d8 | |||
| 8593aeb21d | |||
| 840f9b9f9d | |||
| ec21cbbe86 | |||
| e90f1af109 | |||
| c78775bfd8 | |||
| 9c3042280d | |||
| 4f2ef3c3a7 | |||
| 6a2ee052ba | |||
| 2658d0f785 | |||
| a7eeda0569 | |||
| cd29f25435 | |||
| 7c864d94b3 | |||
| 26f1be0a51 | |||
| d7e75ae0c7 | |||
| 1d90f53527 | |||
| 7dd6b41642 | |||
| d7f3bc8b9f | |||
| 687a988701 | |||
| 9046b5a4d3 | |||
| b4d4967529 | |||
| 51c24b82fe | |||
| 5e13f9dd2d | |||
| f8d66c4336 | |||
| 9875defe86 | |||
| fc208770dd | |||
| 99a51808a0 | |||
| 1c07cf83b2 | |||
| 99136f133a | |||
| 6c9d58582b | |||
| 4edae00998 | |||
| 17e9c05f46 | |||
| 71e3cb83ae | |||
| fb2e26bd28 | |||
| 976ab68ca3 | |||
| 58a76e1df2 | |||
| c696276fc3 | |||
| 6ce0608bb3 | |||
| 52ad237419 | |||
| 71038dc617 | |||
| dc3bb517a3 | |||
| 7b2c48c8d4 | |||
| ef557ebfc4 | |||
| b2e953b92a | |||
| 576d765557 | |||
| e3416804e4 | |||
| 9ad4f61209 | |||
| aed6311146 | |||
| 5e41cefa87 | |||
| b1710ee826 | |||
| 03b0bd4d2c | |||
| 5179ac1fdc | |||
| 54e31ce2ec | |||
| 4abe9b8636 | |||
| 956d6f50e1 | |||
| 6aeb2eb736 | |||
| f40d4c1ddd | |||
| 4f052a3e0a | |||
| 2bf9e7d916 | |||
| 89c906232d | |||
| c39beb5b72 | |||
| 7dd2d89ad9 | |||
| 3403c8acba | |||
| 0a6eecee69 |
@@ -0,0 +1,6 @@
|
|||||||
|
Please replace this text <-> with your PR description and leave the below declarations intact.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
By creating this pull request, I understand that code that is AI generated or otherwise automatically generated may be rejected without further discussion.
|
||||||
|
I declare that I fully understand all code I pushed into this PR, and wrote all this code myself and own the rights to this code.
|
||||||
@@ -84,7 +84,7 @@ jobs:
|
|||||||
run: ./bin/BeamMP-Server-tests
|
run: ./bin/BeamMP-Server-tests
|
||||||
|
|
||||||
arm64-matrix:
|
arm64-matrix:
|
||||||
runs-on: [Linux, ARM64]
|
runs-on: ubuntu-22.04-arm
|
||||||
env:
|
env:
|
||||||
VCPKG_DEFAULT_TRIPLET: "arm64-linux"
|
VCPKG_DEFAULT_TRIPLET: "arm64-linux"
|
||||||
strategy:
|
strategy:
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ jobs:
|
|||||||
asset_content_type: application/x-elf
|
asset_content_type: application/x-elf
|
||||||
|
|
||||||
arm64-matrix:
|
arm64-matrix:
|
||||||
runs-on: [Linux, ARM64]
|
runs-on: ubuntu-22.04-arm
|
||||||
needs: create-release
|
needs: create-release
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
.idea/
|
.idea/
|
||||||
.sentry-native/
|
|
||||||
*.orig
|
*.orig
|
||||||
*.toml
|
*.toml
|
||||||
boost_*
|
boost_*
|
||||||
|
|||||||
@@ -104,6 +104,7 @@ set(PRJ_LIBRARIES
|
|||||||
httplib::httplib
|
httplib::httplib
|
||||||
libzip::zip
|
libzip::zip
|
||||||
OpenSSL::SSL OpenSSL::Crypto
|
OpenSSL::SSL OpenSSL::Crypto
|
||||||
|
CURL::libcurl
|
||||||
${LUA_LIBRARIES}
|
${LUA_LIBRARIES}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -116,6 +117,7 @@ find_package(httplib CONFIG REQUIRED)
|
|||||||
find_package(libzip CONFIG REQUIRED)
|
find_package(libzip CONFIG REQUIRED)
|
||||||
find_package(RapidJSON CONFIG REQUIRED)
|
find_package(RapidJSON CONFIG REQUIRED)
|
||||||
find_package(sol2 CONFIG REQUIRED)
|
find_package(sol2 CONFIG REQUIRED)
|
||||||
|
find_package(CURL CONFIG REQUIRED)
|
||||||
add_subdirectory("deps/toml11")
|
add_subdirectory("deps/toml11")
|
||||||
|
|
||||||
include_directories(include)
|
include_directories(include)
|
||||||
|
|||||||
+2
-2
@@ -108,8 +108,8 @@ A BeamMP-Developer must review your code in detail, and leave a review. If this
|
|||||||
5. Run `git submodule update --init --recursive`.
|
5. Run `git submodule update --init --recursive`.
|
||||||
6. Make a new branch for your feature or fix from the branch you are on. You can do this via `git checkout -b <branch name>`. See [this section on branches](#branches) for more info on branch naming.
|
6. Make a new branch for your feature or fix from the branch you are on. You can do this via `git checkout -b <branch name>`. See [this section on branches](#branches) for more info on branch naming.
|
||||||
7. Install all dependencies. Those are usually listed in the `README.md` in the branch you're in, or, more reliably, in one of the files in `.github/workflows` (if you can read `yaml`).
|
7. Install all dependencies. Those are usually listed in the `README.md` in the branch you're in, or, more reliably, in one of the files in `.github/workflows` (if you can read `yaml`).
|
||||||
8. Run CMake to configure the project. You can find tutorials on this online. You will want to tell CMake to build with `CMAKE_BUILD_TYPE=Debug`, for example by passing it to CMake via the commandline switch `-DCMAKE_BUILD_TYPE=Debug`. You may also want to turn off sentry by setting `SENTRY_BACKEND=none` (for example via commandline switch `-DSENTRY_BACKEND=none`). An example invocation on Linux with GNU make would be
|
8. Run CMake to configure the project. You can find tutorials on this online. You will want to tell CMake to build with `CMAKE_BUILD_TYPE=Debug`, for example by passing it to CMake via the commandline switch `-DCMAKE_BUILD_TYPE=Debug`. An example invocation on Linux with GNU make would be
|
||||||
`cmake . -DCMAKE_BUILD_TYPE=Debug -DSENTRY_BACKEND=none` .
|
`cmake . -DCMAKE_BUILD_TYPE=Debug` .
|
||||||
9. Build the `BeamMP-Server` target to build the BeamMP-Server, or the `BeamMP-Server-tests` target to build the unit-tests (does not include a working server). In the example from 8. (on Linux), you could build with `make BeamMP-Server`, `make -j BeamMP-Server` or `cmake --build . --parallel --target BeamMP-Server` . Or, on Windows, (in Visual Studio), you would just press some big green "run" or "debug" button.
|
9. Build the `BeamMP-Server` target to build the BeamMP-Server, or the `BeamMP-Server-tests` target to build the unit-tests (does not include a working server). In the example from 8. (on Linux), you could build with `make BeamMP-Server`, `make -j BeamMP-Server` or `cmake --build . --parallel --target BeamMP-Server` . Or, on Windows, (in Visual Studio), you would just press some big green "run" or "debug" button.
|
||||||
10. When making changes, refer to [this section on how to commit properly](#how-to-commit). Not following those guidelines will result in your changes being rejected, so please take a look.
|
10. When making changes, refer to [this section on how to commit properly](#how-to-commit). Not following those guidelines will result in your changes being rejected, so please take a look.
|
||||||
11. Make sure to add Unit-tests with `doctest` if you build new stuff. You can find examples all over the latest version of the codebase (search for `TEST_CASE`).
|
11. Make sure to add Unit-tests with `doctest` if you build new stuff. You can find examples all over the latest version of the codebase (search for `TEST_CASE`).
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ If you need support with understanding the codebase, please write us in the Disc
|
|||||||
|
|
||||||
## About Building from Source
|
## About Building from Source
|
||||||
|
|
||||||
We only allow building unmodified (original) source code for public use. `master` is considered **unstable** and we will not provide technical support if such a build doesn't work, so always build from a tag. You can checkout a tag with `git checkout tags/TAGNAME`, where `TAGNAME` is the tag, for example `v3.1.0`.
|
We only allow building unmodified (original) source code for public use. `master` is considered **unstable** and we will not provide technical support if such a build doesn't work, so always build from a tag. You can checkout a tag with `git checkout tags/TAGNAME`, where `TAGNAME` is the tag, for example `v3.4.1`. See [the tags](https://github.com/BeamMP/BeamMP-Server/tags) for possible versions/tags, as well as [the releases](https://github.com/BeamMP/BeamMP-Server/releases) to check which version is marked as a release/prerelease. We recommend using the [latest release](https://github.com/BeamMP/BeamMP-Server/releases/latest).
|
||||||
|
|
||||||
## Supported Operating Systems
|
## Supported Operating Systems
|
||||||
|
|
||||||
@@ -66,9 +66,10 @@ You can build on **Windows, Linux** or other platforms by following these steps:
|
|||||||
|
|
||||||
1. Check out the repository with git: `git clone --recursive https://github.com/BeamMP/BeamMP-Server`.
|
1. Check out the repository with git: `git clone --recursive https://github.com/BeamMP/BeamMP-Server`.
|
||||||
2. Go into the directory `cd BeamMP-Server`.
|
2. Go into the directory `cd BeamMP-Server`.
|
||||||
3. Run CMake `cmake -S . -B bin -DCMAKE_BUILD_TYPE=Release` - this can take a few minutes and may take a lot of disk space and bandwidth.
|
3. Specify the server version to build by checking out a tag: `git checkout tags/v3.4.1` - [Possible versions/tags](https://github.com/BeamMP/BeamMP-Server/tags)
|
||||||
4. Build via `cmake --build bin --parallel --config Release -t BeamMP-Server`.
|
4. Run CMake `cmake -S . -B bin -DCMAKE_BUILD_TYPE=Release` - this can take a few minutes and may take a lot of disk space and bandwidth.
|
||||||
5. Your executable can be found in `bin/`.
|
5. Build via `cmake --build bin --parallel --config Release -t BeamMP-Server`.
|
||||||
|
6. Your executable can be found in `bin/`.
|
||||||
|
|
||||||
When you make changes to the code, you only have to run step 4 again.
|
When you make changes to the code, you only have to run step 4 again.
|
||||||
### Building for FreeBSD
|
### Building for FreeBSD
|
||||||
|
|||||||
+9
-10
@@ -74,7 +74,7 @@ public:
|
|||||||
static TConsole& Console() { return mConsole; }
|
static TConsole& Console() { return mConsole; }
|
||||||
static std::string ServerVersionString();
|
static std::string ServerVersionString();
|
||||||
static const Version& ServerVersion() { return mVersion; }
|
static const Version& ServerVersion() { return mVersion; }
|
||||||
static uint8_t ClientMajorVersion() { return 2; }
|
static Version ClientMinimumVersion() { return Version { 2, 2, 0 }; }
|
||||||
static std::string PPS() { return mPPS; }
|
static std::string PPS() { return mPPS; }
|
||||||
static void SetPPS(const std::string& NewPPS) { mPPS = NewPPS; }
|
static void SetPPS(const std::string& NewPPS) { mPPS = NewPPS; }
|
||||||
|
|
||||||
@@ -82,11 +82,11 @@ public:
|
|||||||
|
|
||||||
static std::vector<std::string> GetBackendUrlsInOrder() {
|
static std::vector<std::string> GetBackendUrlsInOrder() {
|
||||||
return {
|
return {
|
||||||
"backend.beammp.com",
|
"https://backend.beammp.com",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string GetBackendUrlForAuth() { return "auth.beammp.com"; }
|
static std::string GetBackendUrlForAuth() { return "https://auth.beammp.com"; }
|
||||||
static std::string GetBackendUrlForSocketIO() { return "https://backend.beammp.com"; }
|
static std::string GetBackendUrlForSocketIO() { return "https://backend.beammp.com"; }
|
||||||
static void CheckForUpdates();
|
static void CheckForUpdates();
|
||||||
static std::array<uint8_t, 3> VersionStrToInts(const std::string& str);
|
static std::array<uint8_t, 3> VersionStrToInts(const std::string& str);
|
||||||
@@ -127,7 +127,7 @@ private:
|
|||||||
static inline std::mutex mShutdownHandlersMutex {};
|
static inline std::mutex mShutdownHandlersMutex {};
|
||||||
static inline std::deque<TShutdownHandler> mShutdownHandlers {};
|
static inline std::deque<TShutdownHandler> mShutdownHandlers {};
|
||||||
|
|
||||||
static inline Version mVersion { 3, 6, 0 };
|
static inline Version mVersion { 3, 8, 2 };
|
||||||
};
|
};
|
||||||
|
|
||||||
void SplitString(std::string const& str, const char delim, std::vector<std::string>& out);
|
void SplitString(std::string const& str, const char delim, std::vector<std::string>& out);
|
||||||
@@ -139,7 +139,6 @@ void RegisterThread(const std::string& str);
|
|||||||
#define KB 1024llu
|
#define KB 1024llu
|
||||||
#define MB (KB * 1024llu)
|
#define MB (KB * 1024llu)
|
||||||
#define GB (MB * 1024llu)
|
#define GB (MB * 1024llu)
|
||||||
#define SSU_UNRAW SECRET_SENTRY_URL
|
|
||||||
|
|
||||||
#define _file_basename std::filesystem::path(__FILE__).filename().string()
|
#define _file_basename std::filesystem::path(__FILE__).filename().string()
|
||||||
#define _line std::to_string(__LINE__)
|
#define _line std::to_string(__LINE__)
|
||||||
@@ -162,13 +161,13 @@ void RegisterThread(const std::string& str);
|
|||||||
#else
|
#else
|
||||||
#define _function_name std::string(__func__)
|
#define _function_name std::string(__func__)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
#define DEBUG
|
#define DEBUG
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(DEBUG)
|
#if defined(DEBUG)
|
||||||
|
|
||||||
// if this is defined, we will show the full function signature infront of
|
// if this is defined, we will show the full function signature infront of
|
||||||
// each info/debug/warn... call instead of the 'filename:line' format.
|
// each info/debug/warn... call instead of the 'filename:line' format.
|
||||||
#if defined(BMP_FULL_FUNCTION_NAMES)
|
#if defined(BMP_FULL_FUNCTION_NAMES)
|
||||||
@@ -178,7 +177,7 @@ void RegisterThread(const std::string& str);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // defined(DEBUG)
|
#endif // defined(DEBUG)
|
||||||
|
|
||||||
#define beammp_warn(x) Application::Console().Write(_this_location + std::string("[WARN] ") + (x))
|
#define beammp_warn(x) Application::Console().Write(_this_location + std::string("[WARN] ") + (x))
|
||||||
#define beammp_info(x) Application::Console().Write(_this_location + std::string("[INFO] ") + (x))
|
#define beammp_info(x) Application::Console().Write(_this_location + std::string("[INFO] ") + (x))
|
||||||
#define beammp_error(x) \
|
#define beammp_error(x) \
|
||||||
@@ -221,7 +220,7 @@ void RegisterThread(const std::string& str);
|
|||||||
#else
|
#else
|
||||||
#define beammp_trace(x)
|
#define beammp_trace(x)
|
||||||
#endif // defined(DEBUG)
|
#endif // defined(DEBUG)
|
||||||
|
|
||||||
#define beammp_errorf(...) beammp_error(fmt::format(__VA_ARGS__))
|
#define beammp_errorf(...) beammp_error(fmt::format(__VA_ARGS__))
|
||||||
#define beammp_infof(...) beammp_info(fmt::format(__VA_ARGS__))
|
#define beammp_infof(...) beammp_info(fmt::format(__VA_ARGS__))
|
||||||
#define beammp_debugf(...) beammp_debug(fmt::format(__VA_ARGS__))
|
#define beammp_debugf(...) beammp_debug(fmt::format(__VA_ARGS__))
|
||||||
|
|||||||
+3
-2
@@ -23,6 +23,7 @@
|
|||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
#include <curl/curl.h>
|
||||||
|
|
||||||
#if defined(BEAMMP_LINUX)
|
#if defined(BEAMMP_LINUX)
|
||||||
#pragma GCC diagnostic push
|
#pragma GCC diagnostic push
|
||||||
@@ -38,8 +39,8 @@
|
|||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
namespace Http {
|
namespace Http {
|
||||||
std::string GET(const std::string& host, int port, const std::string& target, unsigned int* status = nullptr);
|
std::string GET(const std::string& url, unsigned int* status = nullptr);
|
||||||
std::string POST(const std::string& host, int port, const std::string& target, const std::string& body, const std::string& ContentType, unsigned int* status = nullptr, const httplib::Headers& headers = {});
|
std::string POST(const std::string& url, const std::string& body, const std::string& ContentType, unsigned int* status = nullptr, const std::map<std::string, std::string>& headers = {});
|
||||||
namespace Status {
|
namespace Status {
|
||||||
std::string ToString(int code);
|
std::string ToString(int code);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,9 @@
|
|||||||
#include <limits>
|
#include <limits>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
|
#undef max
|
||||||
|
#undef min
|
||||||
|
|
||||||
namespace prof {
|
namespace prof {
|
||||||
|
|
||||||
using Duration = std::chrono::duration<double, std::milli>;
|
using Duration = std::chrono::duration<double, std::milli>;
|
||||||
|
|||||||
+2
-3
@@ -68,8 +68,6 @@ struct Settings {
|
|||||||
// Keys have their TOML section name as prefix
|
// Keys have their TOML section name as prefix
|
||||||
|
|
||||||
// [Misc]
|
// [Misc]
|
||||||
Misc_SendErrorsShowMessage,
|
|
||||||
Misc_SendErrors,
|
|
||||||
Misc_ImScaredOfUpdates,
|
Misc_ImScaredOfUpdates,
|
||||||
Misc_UpdateReminderTime,
|
Misc_UpdateReminderTime,
|
||||||
|
|
||||||
@@ -86,7 +84,8 @@ struct Settings {
|
|||||||
General_LogChat,
|
General_LogChat,
|
||||||
General_ResourceFolder,
|
General_ResourceFolder,
|
||||||
General_Debug,
|
General_Debug,
|
||||||
General_AllowGuests
|
General_AllowGuests,
|
||||||
|
General_InformationPacket,
|
||||||
};
|
};
|
||||||
|
|
||||||
Sync<std::unordered_map<Key, SettingsTypeVariant>> SettingsMap;
|
Sync<std::unordered_map<Key, SettingsTypeVariant>> SettingsMap;
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ public:
|
|||||||
//~THeartbeatThread();
|
//~THeartbeatThread();
|
||||||
void operator()() override;
|
void operator()() override;
|
||||||
|
|
||||||
|
static inline std::string lastCall = "";
|
||||||
private:
|
private:
|
||||||
std::string GenerateCall();
|
std::string GenerateCall();
|
||||||
std::string GetPlayers();
|
std::string GetPlayers();
|
||||||
|
|||||||
@@ -43,5 +43,5 @@ private:
|
|||||||
int mModsLoaded = 0;
|
int mModsLoaded = 0;
|
||||||
|
|
||||||
std::mutex mModsMutex;
|
std::mutex mModsMutex;
|
||||||
nlohmann::json mMods;
|
nlohmann::json mMods = nlohmann::json::array();
|
||||||
};
|
};
|
||||||
|
|||||||
+11
-7
@@ -79,13 +79,17 @@ std::string TClient::GetCarPositionRaw(int Ident) {
|
|||||||
void TClient::Disconnect(std::string_view Reason) {
|
void TClient::Disconnect(std::string_view Reason) {
|
||||||
beammp_debugf("Disconnecting client {} for reason: {}", GetID(), Reason);
|
beammp_debugf("Disconnecting client {} for reason: {}", GetID(), Reason);
|
||||||
boost::system::error_code ec;
|
boost::system::error_code ec;
|
||||||
mSocket.shutdown(socket_base::shutdown_both, ec);
|
if (mSocket.is_open()) {
|
||||||
if (ec) {
|
mSocket.shutdown(socket_base::shutdown_both, ec);
|
||||||
beammp_debugf("Failed to shutdown client socket: {}", ec.message());
|
if (ec) {
|
||||||
}
|
beammp_debugf("Failed to shutdown client socket: {}", ec.message());
|
||||||
mSocket.close(ec);
|
}
|
||||||
if (ec) {
|
mSocket.close(ec);
|
||||||
beammp_debugf("Failed to close client socket: {}", ec.message());
|
if (ec) {
|
||||||
|
beammp_debugf("Failed to close client socket: {}", ec.message());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
beammp_debug("Socket is already closed.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -215,7 +215,7 @@ void Application::CheckForUpdates() {
|
|||||||
// checks current version against latest version
|
// checks current version against latest version
|
||||||
std::regex VersionRegex { R"(\d+\.\d+\.\d+\n*)" };
|
std::regex VersionRegex { R"(\d+\.\d+\.\d+\n*)" };
|
||||||
for (const auto& url : GetBackendUrlsInOrder()) {
|
for (const auto& url : GetBackendUrlsInOrder()) {
|
||||||
auto Response = Http::GET(url, 443, "/v/s");
|
auto Response = Http::GET(url + "/v/s");
|
||||||
bool Matches = std::regex_match(Response, VersionRegex);
|
bool Matches = std::regex_match(Response, VersionRegex);
|
||||||
if (Matches) {
|
if (Matches) {
|
||||||
auto MyVersion = ServerVersion();
|
auto MyVersion = ServerVersion();
|
||||||
|
|||||||
+69
-48
@@ -29,67 +29,88 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
using json = nlohmann::json;
|
using json = nlohmann::json;
|
||||||
struct Connection {
|
|
||||||
std::string host {};
|
|
||||||
int port {};
|
|
||||||
Connection() = default;
|
|
||||||
Connection(std::string host, int port)
|
|
||||||
: host(host)
|
|
||||||
, port(port) {};
|
|
||||||
};
|
|
||||||
constexpr uint8_t CONNECTION_AMOUNT = 10;
|
|
||||||
static thread_local uint8_t write_index = 0;
|
|
||||||
static thread_local std::array<Connection, CONNECTION_AMOUNT> connections;
|
|
||||||
static thread_local std::array<std::shared_ptr<httplib::SSLClient>, CONNECTION_AMOUNT> clients;
|
|
||||||
|
|
||||||
[[nodiscard]] static std::shared_ptr<httplib::SSLClient> getClient(Connection connectionInfo) {
|
static size_t CurlWriteCallback(void* contents, size_t size, size_t nmemb, void* userp) {
|
||||||
for (uint8_t i = 0; i < CONNECTION_AMOUNT; i++) {
|
std::string* Result = reinterpret_cast<std::string*>(userp);
|
||||||
if (connectionInfo.host == connections[i].host
|
std::string NewContents(reinterpret_cast<char*>(contents), size * nmemb);
|
||||||
&& connectionInfo.port == connections[i].port) {
|
*Result += NewContents;
|
||||||
beammp_tracef("Old client reconnected, with ip {} and port {}", connectionInfo.host, connectionInfo.port);
|
return size * nmemb;
|
||||||
return clients[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
uint8_t i = write_index;
|
|
||||||
write_index++;
|
|
||||||
write_index %= CONNECTION_AMOUNT;
|
|
||||||
clients[i] = std::make_shared<httplib::SSLClient>(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::string Http::GET(const std::string& url, unsigned int* status) {
|
||||||
std::shared_ptr<httplib::SSLClient> client = getClient({ host, port });
|
std::string Ret;
|
||||||
client->enable_server_certificate_verification(false);
|
static thread_local CURL* curl = curl_easy_init();
|
||||||
client->set_address_family(AF_INET);
|
if (curl) {
|
||||||
auto res = client->Get(target.c_str());
|
CURLcode res;
|
||||||
if (res) {
|
char errbuf[CURL_ERROR_SIZE];
|
||||||
if (status) {
|
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
|
||||||
*status = res->status;
|
curl_easy_setopt(curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, CurlWriteCallback);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)&Ret);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10); // seconds
|
||||||
|
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errbuf);
|
||||||
|
errbuf[0] = 0;
|
||||||
|
res = curl_easy_perform(curl);
|
||||||
|
if (res != CURLE_OK) {
|
||||||
|
beammp_error("GET to " + url + " failed: " + std::string(curl_easy_strerror(res)));
|
||||||
|
beammp_error("Curl error: " + std::string(errbuf));
|
||||||
|
return Http::ErrorString;
|
||||||
}
|
}
|
||||||
return res->body;
|
|
||||||
|
if (status) {
|
||||||
|
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, status);
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
beammp_error("Curl easy init failed");
|
||||||
return Http::ErrorString;
|
return Http::ErrorString;
|
||||||
}
|
}
|
||||||
|
return Ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
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::string Http::POST(const std::string& url, const std::string& body, const std::string& ContentType, unsigned int* status, const std::map<std::string, std::string>& headers) {
|
||||||
std::shared_ptr<httplib::SSLClient> client = getClient({ host, port });
|
std::string Ret;
|
||||||
client->set_read_timeout(std::chrono::seconds(10));
|
static thread_local CURL* curl = curl_easy_init();
|
||||||
beammp_assert(client->is_valid());
|
if (curl) {
|
||||||
client->enable_server_certificate_verification(false);
|
CURLcode res;
|
||||||
client->set_address_family(AF_INET);
|
char errbuf[CURL_ERROR_SIZE];
|
||||||
auto res = client->Post(target.c_str(), headers, body.c_str(), body.size(), ContentType.c_str());
|
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
|
||||||
if (res) {
|
curl_easy_setopt(curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
|
||||||
if (status) {
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, CurlWriteCallback);
|
||||||
*status = res->status;
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)&Ret);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_POST, 1);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body.c_str());
|
||||||
|
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, body.size());
|
||||||
|
struct curl_slist* list = nullptr;
|
||||||
|
list = curl_slist_append(list, ("Content-Type: " + ContentType).c_str());
|
||||||
|
|
||||||
|
for (auto [header, value] : headers) {
|
||||||
|
list = curl_slist_append(list, (header + ": " + value).c_str());
|
||||||
}
|
}
|
||||||
return res->body;
|
|
||||||
|
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10); // seconds
|
||||||
|
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errbuf);
|
||||||
|
errbuf[0] = 0;
|
||||||
|
res = curl_easy_perform(curl);
|
||||||
|
curl_slist_free_all(list);
|
||||||
|
if (res != CURLE_OK) {
|
||||||
|
beammp_error("POST to " + url + " failed: " + std::string(curl_easy_strerror(res)));
|
||||||
|
beammp_error("Curl error: " + std::string(errbuf));
|
||||||
|
return Http::ErrorString;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status) {
|
||||||
|
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, status);
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
beammp_debug("POST failed: " + httplib::to_string(res.error()));
|
beammp_error("Curl easy init failed");
|
||||||
return Http::ErrorString;
|
return Http::ErrorString;
|
||||||
}
|
}
|
||||||
|
return Ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
// RFC 2616, RFC 7231
|
// RFC 2616, RFC 7231
|
||||||
|
|||||||
+11
-1
@@ -207,7 +207,7 @@ std::pair<bool, std::string> LuaAPI::MP::SendChatMessage(int ID, const std::stri
|
|||||||
|
|
||||||
std::pair<bool, std::string> LuaAPI::MP::SendNotification(int ID, const std::string& Message, const std::string& Icon, const std::string& Category) {
|
std::pair<bool, std::string> LuaAPI::MP::SendNotification(int ID, const std::string& Message, const std::string& Icon, const std::string& Category) {
|
||||||
std::pair<bool, std::string> Result;
|
std::pair<bool, std::string> Result;
|
||||||
std::string Packet = "N" + Category + ":" + Icon + ":" + Message;
|
std::string Packet = "n" + Category + ":" + Icon + ":" + Message;
|
||||||
if (ID == -1) {
|
if (ID == -1) {
|
||||||
Engine->Network().SendToAll(nullptr, StringToVector(Packet), true, true);
|
Engine->Network().SendToAll(nullptr, StringToVector(Packet), true, true);
|
||||||
Result.first = true;
|
Result.first = true;
|
||||||
@@ -317,6 +317,14 @@ void LuaAPI::MP::Set(int ConfigID, sol::object NewValue) {
|
|||||||
beammp_lua_error("set invalid argument [2] expected string");
|
beammp_lua_error("set invalid argument [2] expected string");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 7: // Information packet
|
||||||
|
if (NewValue.is<bool>()) {
|
||||||
|
Application::Settings.set(Settings::Key::General_InformationPacket, NewValue.as<bool>());
|
||||||
|
beammp_info(std::string("Set `InformationPacket` to ") + (Application::Settings.getAsBool(Settings::Key::General_InformationPacket) ? "true" : "false"));
|
||||||
|
} else {
|
||||||
|
beammp_lua_error("set invalid argument [2] expected boolean");
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
beammp_warn("Invalid config ID \"" + std::to_string(ConfigID) + "\". Use `MP.Settings.*` enum for this.");
|
beammp_warn("Invalid config ID \"" + std::to_string(ConfigID) + "\". Use `MP.Settings.*` enum for this.");
|
||||||
break;
|
break;
|
||||||
@@ -339,6 +347,8 @@ TLuaValue LuaAPI::MP::Get(int ConfigID) {
|
|||||||
return Application::Settings.getAsString(Settings::Key::General_Name);
|
return Application::Settings.getAsString(Settings::Key::General_Name);
|
||||||
case 6: // Desc
|
case 6: // Desc
|
||||||
return Application::Settings.getAsString(Settings::Key::General_Description);
|
return Application::Settings.getAsString(Settings::Key::General_Description);
|
||||||
|
case 7: // Information packet
|
||||||
|
return Application::Settings.getAsBool(Settings::Key::General_InformationPacket);
|
||||||
default:
|
default:
|
||||||
beammp_warn("Invalid config ID \"" + std::to_string(ConfigID) + "\". Use `MP.Settings.*` enum for this.");
|
beammp_warn("Invalid config ID \"" + std::to_string(ConfigID) + "\". Use `MP.Settings.*` enum for this.");
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
+2
-4
@@ -34,8 +34,7 @@ Settings::Settings() {
|
|||||||
{ General_ResourceFolder, std::string("Resources") },
|
{ General_ResourceFolder, std::string("Resources") },
|
||||||
{ General_Debug, false },
|
{ General_Debug, false },
|
||||||
{ General_AllowGuests, true },
|
{ General_AllowGuests, true },
|
||||||
{ Misc_SendErrorsShowMessage, true },
|
{ General_InformationPacket, true },
|
||||||
{ Misc_SendErrors, true },
|
|
||||||
{ Misc_ImScaredOfUpdates, true },
|
{ Misc_ImScaredOfUpdates, true },
|
||||||
{ Misc_UpdateReminderTime, "30s" }
|
{ Misc_UpdateReminderTime, "30s" }
|
||||||
};
|
};
|
||||||
@@ -54,8 +53,7 @@ Settings::Settings() {
|
|||||||
{ { "General", "ResourceFolder" }, { General_ResourceFolder, READ_ONLY } },
|
{ { "General", "ResourceFolder" }, { General_ResourceFolder, READ_ONLY } },
|
||||||
{ { "General", "Debug" }, { General_Debug, READ_WRITE } },
|
{ { "General", "Debug" }, { General_Debug, READ_WRITE } },
|
||||||
{ { "General", "AllowGuests" }, { General_AllowGuests, READ_WRITE } },
|
{ { "General", "AllowGuests" }, { General_AllowGuests, READ_WRITE } },
|
||||||
{ { "Misc", "SendErrorsShowMessage" }, { Misc_SendErrorsShowMessage, READ_WRITE } },
|
{ { "General", "InformationPacket" }, { General_InformationPacket, READ_WRITE } },
|
||||||
{ { "Misc", "SendErrors" }, { Misc_SendErrors, READ_WRITE } },
|
|
||||||
{ { "Misc", "ImScaredOfUpdates" }, { Misc_ImScaredOfUpdates, READ_WRITE } },
|
{ { "Misc", "ImScaredOfUpdates" }, { Misc_ImScaredOfUpdates, READ_WRITE } },
|
||||||
{ { "Misc", "UpdateReminderTime" }, { Misc_UpdateReminderTime, READ_WRITE } }
|
{ { "Misc", "UpdateReminderTime" }, { Misc_UpdateReminderTime, READ_WRITE } }
|
||||||
};
|
};
|
||||||
|
|||||||
+15
-11
@@ -56,13 +56,15 @@ static constexpr std::string_view StrLogChat = "LogChat";
|
|||||||
static constexpr std::string_view EnvStrLogChat = "BEAMMP_LOG_CHAT";
|
static constexpr std::string_view EnvStrLogChat = "BEAMMP_LOG_CHAT";
|
||||||
static constexpr std::string_view StrAllowGuests = "AllowGuests";
|
static constexpr std::string_view StrAllowGuests = "AllowGuests";
|
||||||
static constexpr std::string_view EnvStrAllowGuests = "BEAMMP_ALLOW_GUESTS";
|
static constexpr std::string_view EnvStrAllowGuests = "BEAMMP_ALLOW_GUESTS";
|
||||||
|
static constexpr std::string_view StrInformationPacket = "InformationPacket";
|
||||||
|
static constexpr std::string_view EnvStrInformationPacket = "BEAMMP_INFORMATION_PACKET";
|
||||||
static constexpr std::string_view StrPassword = "Password";
|
static constexpr std::string_view StrPassword = "Password";
|
||||||
|
|
||||||
// Misc
|
// Misc
|
||||||
static constexpr std::string_view StrSendErrors = "SendErrors";
|
|
||||||
static constexpr std::string_view StrSendErrorsMessageEnabled = "SendErrorsShowMessage";
|
|
||||||
static constexpr std::string_view StrHideUpdateMessages = "ImScaredOfUpdates";
|
static constexpr std::string_view StrHideUpdateMessages = "ImScaredOfUpdates";
|
||||||
|
static constexpr std::string_view EnvStrHideUpdateMessages = "BEAMMP_IM_SCARED_OF_UPDATES";
|
||||||
static constexpr std::string_view StrUpdateReminderTime = "UpdateReminderTime";
|
static constexpr std::string_view StrUpdateReminderTime = "UpdateReminderTime";
|
||||||
|
static constexpr std::string_view EnvStrUpdateReminderTime = "BEAMMP_UPDATE_REMINDER_TIME";
|
||||||
|
|
||||||
TEST_CASE("TConfig::TConfig") {
|
TEST_CASE("TConfig::TConfig") {
|
||||||
const std::string CfgFile = "beammp_server_testconfig.toml";
|
const std::string CfgFile = "beammp_server_testconfig.toml";
|
||||||
@@ -132,6 +134,8 @@ void TConfig::FlushToFile() {
|
|||||||
SetComment(data["General"][StrLogChat.data()].comments(), " Whether to log chat messages in the console / log");
|
SetComment(data["General"][StrLogChat.data()].comments(), " Whether to log chat messages in the console / log");
|
||||||
data["General"][StrDebug.data()] = Application::Settings.getAsBool(Settings::Key::General_Debug);
|
data["General"][StrDebug.data()] = Application::Settings.getAsBool(Settings::Key::General_Debug);
|
||||||
data["General"][StrPrivate.data()] = Application::Settings.getAsBool(Settings::Key::General_Private);
|
data["General"][StrPrivate.data()] = Application::Settings.getAsBool(Settings::Key::General_Private);
|
||||||
|
SetComment(data["General"][StrInformationPacket.data()].comments(), " Whether to allow unconnected clients to get the public server information without joining");
|
||||||
|
data["General"][StrInformationPacket.data()] = Application::Settings.getAsBool(Settings::Key::General_InformationPacket);
|
||||||
data["General"][StrAllowGuests.data()] = Application::Settings.getAsBool(Settings::Key::General_AllowGuests);
|
data["General"][StrAllowGuests.data()] = Application::Settings.getAsBool(Settings::Key::General_AllowGuests);
|
||||||
SetComment(data["General"][StrAllowGuests.data()].comments(), " Whether to allow guests");
|
SetComment(data["General"][StrAllowGuests.data()].comments(), " Whether to allow guests");
|
||||||
data["General"][StrPort.data()] = Application::Settings.getAsInt(Settings::Key::General_Port);
|
data["General"][StrPort.data()] = Application::Settings.getAsInt(Settings::Key::General_Port);
|
||||||
@@ -148,12 +152,8 @@ void TConfig::FlushToFile() {
|
|||||||
// Misc
|
// Misc
|
||||||
data["Misc"][StrHideUpdateMessages.data()] = Application::Settings.getAsBool(Settings::Key::Misc_ImScaredOfUpdates);
|
data["Misc"][StrHideUpdateMessages.data()] = Application::Settings.getAsBool(Settings::Key::Misc_ImScaredOfUpdates);
|
||||||
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.");
|
||||||
data["Misc"][StrSendErrors.data()] = Application::Settings.getAsBool(Settings::Key::Misc_SendErrors);
|
|
||||||
data["Misc"][StrUpdateReminderTime.data()] = Application::Settings.getAsString(Settings::Key::Misc_UpdateReminderTime);
|
data["Misc"][StrUpdateReminderTime.data()] = Application::Settings.getAsString(Settings::Key::Misc_UpdateReminderTime);
|
||||||
SetComment(data["Misc"][StrUpdateReminderTime.data()].comments(), " Specifies the time between update reminders. You can use any of \"s, min, h, d\" at the end to specify the units seconds, minutes, hours or days. So 30d or 0.5min will print the update message every 30 days or half a minute.");
|
SetComment(data["Misc"][StrUpdateReminderTime.data()].comments(), " Specifies the time between update reminders. You can use any of \"s, min, h, d\" at the end to specify the units seconds, minutes, hours or days. So 30d or 0.5min will print the update message every 30 days or half a minute.");
|
||||||
SetComment(data["Misc"][StrSendErrors.data()].comments(), " If SendErrors is `true`, the server will send helpful info about crashes and other issues back to the BeamMP developers. This info may include your config, who is on your server at the time of the error, and similar general information. This kind of data is vital in helping us diagnose and fix issues faster. This has no impact on server performance. You can opt-out of this system by setting this to `false`");
|
|
||||||
data["Misc"][StrSendErrorsMessageEnabled.data()] = Application::Settings.getAsBool(Settings::Key::Misc_SendErrorsShowMessage);
|
|
||||||
SetComment(data["Misc"][StrSendErrorsMessageEnabled.data()].comments(), " You can turn on/off the SendErrors message you get on startup here");
|
|
||||||
std::stringstream Ss;
|
std::stringstream Ss;
|
||||||
Ss << "# This is the BeamMP-Server config file.\n"
|
Ss << "# This is the BeamMP-Server config file.\n"
|
||||||
"# Help & Documentation: `https://docs.beammp.com/server/server-maintenance/`\n"
|
"# Help & Documentation: `https://docs.beammp.com/server/server-maintenance/`\n"
|
||||||
@@ -248,7 +248,12 @@ void TConfig::ParseFromFile(std::string_view name) {
|
|||||||
// Read into new Settings Singleton
|
// Read into new Settings Singleton
|
||||||
TryReadValue(data, "General", StrDebug, EnvStrDebug, Settings::Key::General_Debug);
|
TryReadValue(data, "General", StrDebug, EnvStrDebug, Settings::Key::General_Debug);
|
||||||
TryReadValue(data, "General", StrPrivate, EnvStrPrivate, Settings::Key::General_Private);
|
TryReadValue(data, "General", StrPrivate, EnvStrPrivate, Settings::Key::General_Private);
|
||||||
TryReadValue(data, "General", StrPort, EnvStrPort, Settings::Key::General_Port);
|
TryReadValue(data, "General", StrInformationPacket, EnvStrInformationPacket, Settings::Key::General_InformationPacket);
|
||||||
|
if (Env::Get(Env::Key::PROVIDER_PORT_ENV).has_value()) {
|
||||||
|
TryReadValue(data, "General", StrPort, Env::Get(Env::Key::PROVIDER_PORT_ENV).value(), Settings::Key::General_Port);
|
||||||
|
} else {
|
||||||
|
TryReadValue(data, "General", StrPort, EnvStrPort, Settings::Key::General_Port);
|
||||||
|
}
|
||||||
TryReadValue(data, "General", StrMaxCars, EnvStrMaxCars, Settings::Key::General_MaxCars);
|
TryReadValue(data, "General", StrMaxCars, EnvStrMaxCars, Settings::Key::General_MaxCars);
|
||||||
TryReadValue(data, "General", StrMaxPlayers, EnvStrMaxPlayers, Settings::Key::General_MaxPlayers);
|
TryReadValue(data, "General", StrMaxPlayers, EnvStrMaxPlayers, Settings::Key::General_MaxPlayers);
|
||||||
TryReadValue(data, "General", StrMap, EnvStrMap, Settings::Key::General_Map);
|
TryReadValue(data, "General", StrMap, EnvStrMap, Settings::Key::General_Map);
|
||||||
@@ -260,10 +265,8 @@ void TConfig::ParseFromFile(std::string_view name) {
|
|||||||
TryReadValue(data, "General", StrLogChat, EnvStrLogChat, Settings::Key::General_LogChat);
|
TryReadValue(data, "General", StrLogChat, EnvStrLogChat, Settings::Key::General_LogChat);
|
||||||
TryReadValue(data, "General", StrAllowGuests, EnvStrAllowGuests, Settings::Key::General_AllowGuests);
|
TryReadValue(data, "General", StrAllowGuests, EnvStrAllowGuests, Settings::Key::General_AllowGuests);
|
||||||
// Misc
|
// Misc
|
||||||
TryReadValue(data, "Misc", StrSendErrors, "", Settings::Key::Misc_SendErrors);
|
TryReadValue(data, "Misc", StrHideUpdateMessages, EnvStrHideUpdateMessages, Settings::Key::Misc_ImScaredOfUpdates);
|
||||||
TryReadValue(data, "Misc", StrHideUpdateMessages, "", Settings::Key::Misc_ImScaredOfUpdates);
|
TryReadValue(data, "Misc", StrUpdateReminderTime, EnvStrUpdateReminderTime, Settings::Key::Misc_UpdateReminderTime);
|
||||||
TryReadValue(data, "Misc", StrSendErrorsMessageEnabled, "", Settings::Key::Misc_SendErrorsShowMessage);
|
|
||||||
TryReadValue(data, "Misc", StrUpdateReminderTime, "", Settings::Key::Misc_UpdateReminderTime);
|
|
||||||
|
|
||||||
} catch (const std::exception& err) {
|
} catch (const std::exception& err) {
|
||||||
beammp_error("Error parsing config file value: " + std::string(err.what()));
|
beammp_error("Error parsing config file value: " + std::string(err.what()));
|
||||||
@@ -299,6 +302,7 @@ void TConfig::PrintDebug() {
|
|||||||
}
|
}
|
||||||
beammp_debug(std::string(StrDebug) + ": " + std::string(Application::Settings.getAsBool(Settings::Key::General_Debug) ? "true" : "false"));
|
beammp_debug(std::string(StrDebug) + ": " + std::string(Application::Settings.getAsBool(Settings::Key::General_Debug) ? "true" : "false"));
|
||||||
beammp_debug(std::string(StrPrivate) + ": " + std::string(Application::Settings.getAsBool(Settings::Key::General_Private) ? "true" : "false"));
|
beammp_debug(std::string(StrPrivate) + ": " + std::string(Application::Settings.getAsBool(Settings::Key::General_Private) ? "true" : "false"));
|
||||||
|
beammp_debug(std::string(StrInformationPacket) + ": " + std::string(Application::Settings.getAsBool(Settings::Key::General_InformationPacket) ? "true" : "false"));
|
||||||
beammp_debug(std::string(StrPort) + ": " + std::to_string(Application::Settings.getAsInt(Settings::Key::General_Port)));
|
beammp_debug(std::string(StrPort) + ": " + std::to_string(Application::Settings.getAsInt(Settings::Key::General_Port)));
|
||||||
beammp_debug(std::string(StrMaxCars) + ": " + std::to_string(Application::Settings.getAsInt(Settings::Key::General_MaxCars)));
|
beammp_debug(std::string(StrMaxCars) + ": " + std::to_string(Application::Settings.getAsInt(Settings::Key::General_MaxCars)));
|
||||||
beammp_debug(std::string(StrMaxPlayers) + ": " + std::to_string(Application::Settings.getAsInt(Settings::Key::General_MaxPlayers)));
|
beammp_debug(std::string(StrMaxPlayers) + ": " + std::to_string(Application::Settings.getAsInt(Settings::Key::General_MaxPlayers)));
|
||||||
|
|||||||
+40
-33
@@ -20,14 +20,12 @@
|
|||||||
|
|
||||||
#include "ChronoWrapper.h"
|
#include "ChronoWrapper.h"
|
||||||
#include "Client.h"
|
#include "Client.h"
|
||||||
|
#include "Common.h"
|
||||||
#include "Http.h"
|
#include "Http.h"
|
||||||
// #include "SocketIO.h"
|
// #include "SocketIO.h"
|
||||||
#include <rapidjson/document.h>
|
#include <nlohmann/json.hpp>
|
||||||
#include <rapidjson/rapidjson.h>
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
namespace json = rapidjson;
|
|
||||||
|
|
||||||
void THeartbeatThread::operator()() {
|
void THeartbeatThread::operator()() {
|
||||||
RegisterThread("Heartbeat");
|
RegisterThread("Heartbeat");
|
||||||
std::string Body;
|
std::string Body;
|
||||||
@@ -61,15 +59,19 @@ void THeartbeatThread::operator()() {
|
|||||||
auto Target = "/heartbeat";
|
auto Target = "/heartbeat";
|
||||||
unsigned int ResponseCode = 0;
|
unsigned int ResponseCode = 0;
|
||||||
|
|
||||||
json::Document Doc;
|
nlohmann::json Doc;
|
||||||
bool Ok = false;
|
bool Ok = false;
|
||||||
for (const auto& Url : Application::GetBackendUrlsInOrder()) {
|
for (const auto& Url : Application::GetBackendUrlsInOrder()) {
|
||||||
T = Http::POST(Url, 443, Target, Body, "application/x-www-form-urlencoded", &ResponseCode, { { "api-v", "2" } });
|
T = Http::POST(Url + Target, Body, "application/json", &ResponseCode, { { "api-v", "2" } });
|
||||||
Doc.Parse(T.data(), T.size());
|
|
||||||
if (Doc.HasParseError() || !Doc.IsObject()) {
|
if (!Application::Settings.getAsBool(Settings::Key::General_Private)) {
|
||||||
|
beammp_debug("Backend response was: `" + T + "`");
|
||||||
|
}
|
||||||
|
|
||||||
|
Doc = nlohmann::json::parse(T, nullptr, false);
|
||||||
|
if (Doc.is_discarded() || !Doc.is_object()) {
|
||||||
if (!Application::Settings.getAsBool(Settings::Key::General_Private)) {
|
if (!Application::Settings.getAsBool(Settings::Key::General_Private)) {
|
||||||
beammp_trace("Backend response failed to parse as valid json");
|
beammp_trace("Backend response failed to parse as valid json");
|
||||||
beammp_trace("Response was: `" + T + "`");
|
|
||||||
}
|
}
|
||||||
} else if (ResponseCode != 200) {
|
} else if (ResponseCode != 200) {
|
||||||
beammp_errorf("Response code from the heartbeat: {}", ResponseCode);
|
beammp_errorf("Response code from the heartbeat: {}", ResponseCode);
|
||||||
@@ -88,18 +90,18 @@ void THeartbeatThread::operator()() {
|
|||||||
const auto MessageKey = "msg";
|
const auto MessageKey = "msg";
|
||||||
|
|
||||||
if (Ok) {
|
if (Ok) {
|
||||||
if (Doc.HasMember(StatusKey) && Doc[StatusKey].IsString()) {
|
if (Doc.contains(StatusKey) && Doc[StatusKey].is_string()) {
|
||||||
Status = Doc[StatusKey].GetString();
|
Status = Doc[StatusKey];
|
||||||
} else {
|
} else {
|
||||||
Ok = false;
|
Ok = false;
|
||||||
}
|
}
|
||||||
if (Doc.HasMember(CodeKey) && Doc[CodeKey].IsString()) {
|
if (Doc.contains(CodeKey) && Doc[CodeKey].is_string()) {
|
||||||
Code = Doc[CodeKey].GetString();
|
Code = Doc[CodeKey];
|
||||||
} else {
|
} else {
|
||||||
Ok = false;
|
Ok = false;
|
||||||
}
|
}
|
||||||
if (Doc.HasMember(MessageKey) && Doc[MessageKey].IsString()) {
|
if (Doc.contains(MessageKey) && Doc[MessageKey].is_string()) {
|
||||||
Message = Doc[MessageKey].GetString();
|
Message = Doc[MessageKey];
|
||||||
} else {
|
} else {
|
||||||
Ok = false;
|
Ok = false;
|
||||||
}
|
}
|
||||||
@@ -137,25 +139,30 @@ void THeartbeatThread::operator()() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string THeartbeatThread::GenerateCall() {
|
std::string THeartbeatThread::GenerateCall() {
|
||||||
std::stringstream Ret;
|
nlohmann::json Ret = {
|
||||||
|
{ "players", std::to_string(mServer.ClientCount()) },
|
||||||
|
{ "maxplayers", std::to_string(Application::Settings.getAsInt(Settings::Key::General_MaxPlayers)) },
|
||||||
|
{ "port", std::to_string(Application::Settings.getAsInt(Settings::Key::General_Port)) },
|
||||||
|
{ "map", Application::Settings.getAsString(Settings::Key::General_Map) },
|
||||||
|
{ "private", Application::Settings.getAsBool(Settings::Key::General_Private) ? "true" : "false" },
|
||||||
|
{ "version", Application::ServerVersionString() },
|
||||||
|
{ "clientversion", Application::ClientMinimumVersion().AsString() },
|
||||||
|
{ "name", Application::Settings.getAsString(Settings::Key::General_Name) },
|
||||||
|
{ "tags", Application::Settings.getAsString(Settings::Key::General_Tags) },
|
||||||
|
{ "guests", Application::Settings.getAsBool(Settings::Key::General_AllowGuests) ? "true" : "false" },
|
||||||
|
{ "modlist", mResourceManager.TrimmedList() },
|
||||||
|
{ "modstotalsize", std::to_string(mResourceManager.MaxModSize()) },
|
||||||
|
{ "modstotal", std::to_string(mResourceManager.ModsLoaded()) },
|
||||||
|
{ "playerslist", GetPlayers() },
|
||||||
|
{ "desc", Application::Settings.getAsString(Settings::Key::General_Description) }
|
||||||
|
};
|
||||||
|
|
||||||
Ret << "uuid=" << Application::Settings.getAsString(Settings::Key::General_AuthKey)
|
lastCall = Ret.dump();
|
||||||
<< "&players=" << mServer.ClientCount()
|
|
||||||
<< "&maxplayers=" << Application::Settings.getAsInt(Settings::Key::General_MaxPlayers)
|
// Add sensitive information here because value of lastCall is used for the information packet.
|
||||||
<< "&port=" << Application::Settings.getAsInt(Settings::Key::General_Port)
|
Ret["uuid"] = Application::Settings.getAsString(Settings::Key::General_AuthKey);
|
||||||
<< "&map=" << Application::Settings.getAsString(Settings::Key::General_Map)
|
|
||||||
<< "&private=" << (Application::Settings.getAsBool(Settings::Key::General_Private) ? "true" : "false")
|
return Ret.dump();
|
||||||
<< "&version=" << Application::ServerVersionString()
|
|
||||||
<< "&clientversion=" << std::to_string(Application::ClientMajorVersion()) + ".0" // FIXME: Wtf.
|
|
||||||
<< "&name=" << Application::Settings.getAsString(Settings::Key::General_Name)
|
|
||||||
<< "&tags=" << Application::Settings.getAsString(Settings::Key::General_Tags)
|
|
||||||
<< "&guests=" << (Application::Settings.getAsBool(Settings::Key::General_AllowGuests) ? "true" : "false")
|
|
||||||
<< "&modlist=" << mResourceManager.TrimmedList()
|
|
||||||
<< "&modstotalsize=" << mResourceManager.MaxModSize()
|
|
||||||
<< "&modstotal=" << mResourceManager.ModsLoaded()
|
|
||||||
<< "&playerslist=" << GetPlayers()
|
|
||||||
<< "&desc=" << Application::Settings.getAsString(Settings::Key::General_Description);
|
|
||||||
return Ret.str();
|
|
||||||
}
|
}
|
||||||
THeartbeatThread::THeartbeatThread(TResourceManager& ResourceManager, TServer& Server)
|
THeartbeatThread::THeartbeatThread(TResourceManager& ResourceManager, TServer& Server)
|
||||||
: mResourceManager(ResourceManager)
|
: mResourceManager(ResourceManager)
|
||||||
|
|||||||
+8
-4
@@ -80,10 +80,11 @@ TEST_CASE("TLuaEngine ctor & dtor") {
|
|||||||
|
|
||||||
void TLuaEngine::operator()() {
|
void TLuaEngine::operator()() {
|
||||||
RegisterThread("LuaEngine");
|
RegisterThread("LuaEngine");
|
||||||
Application::SetSubsystemStatus("LuaEngine", Application::Status::Good);
|
|
||||||
// lua engine main thread
|
// lua engine main thread
|
||||||
beammp_infof("Lua v{}.{}.{}", LUA_VERSION_MAJOR, LUA_VERSION_MINOR, LUA_VERSION_RELEASE);
|
beammp_infof("Lua v{}.{}.{}", LUA_VERSION_MAJOR, LUA_VERSION_MINOR, LUA_VERSION_RELEASE);
|
||||||
CollectAndInitPlugins();
|
CollectAndInitPlugins();
|
||||||
|
|
||||||
|
Application::SetSubsystemStatus("LuaEngine", Application::Status::Good);
|
||||||
// now call all onInit's
|
// now call all onInit's
|
||||||
auto Futures = TriggerEvent("onInit", "");
|
auto Futures = TriggerEvent("onInit", "");
|
||||||
WaitForAll(Futures, std::chrono::seconds(5));
|
WaitForAll(Futures, std::chrono::seconds(5));
|
||||||
@@ -880,12 +881,14 @@ TLuaEngine::StateThreadData::StateThreadData(const std::string& Name, TLuaStateI
|
|||||||
});
|
});
|
||||||
MPTable.set_function("SendChatMessage", &LuaAPI::MP::SendChatMessage);
|
MPTable.set_function("SendChatMessage", &LuaAPI::MP::SendChatMessage);
|
||||||
MPTable.set_function("SendNotification", [&](sol::variadic_args Args) {
|
MPTable.set_function("SendNotification", [&](sol::variadic_args Args) {
|
||||||
if (Args.size() == 3) {
|
if (Args.size() == 2) {
|
||||||
|
LuaAPI::MP::SendNotification(Args.get<int>(0), Args.get<std::string>(1), "", Args.get<std::string>(1));
|
||||||
|
} else if (Args.size() == 3) {
|
||||||
LuaAPI::MP::SendNotification(Args.get<int>(0), Args.get<std::string>(1), Args.get<std::string>(2), Args.get<std::string>(1));
|
LuaAPI::MP::SendNotification(Args.get<int>(0), Args.get<std::string>(1), Args.get<std::string>(2), Args.get<std::string>(1));
|
||||||
} else if (Args.size() == 4) {
|
} else if (Args.size() == 4) {
|
||||||
LuaAPI::MP::SendNotification(Args.get<int>(0), Args.get<std::string>(1), Args.get<std::string>(2), Args.get<std::string>(3));
|
LuaAPI::MP::SendNotification(Args.get<int>(0), Args.get<std::string>(1), Args.get<std::string>(2), Args.get<std::string>(3));
|
||||||
} else {
|
} else {
|
||||||
beammp_lua_error("SendNotification expects 2 or 3 arguments.");
|
beammp_lua_error("SendNotification expects 2, 3 or 4 arguments.");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
MPTable.set_function("GetPlayers", [&]() -> sol::table {
|
MPTable.set_function("GetPlayers", [&]() -> sol::table {
|
||||||
@@ -1024,7 +1027,8 @@ TLuaEngine::StateThreadData::StateThreadData(const std::string& Name, TLuaStateI
|
|||||||
"MaxPlayers", 3,
|
"MaxPlayers", 3,
|
||||||
"Map", 4,
|
"Map", 4,
|
||||||
"Name", 5,
|
"Name", 5,
|
||||||
"Description", 6);
|
"Description", 6,
|
||||||
|
"InformationPacket", 7);
|
||||||
|
|
||||||
MPTable.create_named("CallStrategy",
|
MPTable.create_named("CallStrategy",
|
||||||
"BestEffort", CallStrategy::BestEffort,
|
"BestEffort", CallStrategy::BestEffort,
|
||||||
|
|||||||
+49
-27
@@ -20,6 +20,7 @@
|
|||||||
#include "Client.h"
|
#include "Client.h"
|
||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
#include "LuaAPI.h"
|
#include "LuaAPI.h"
|
||||||
|
#include "THeartbeatThread.h"
|
||||||
#include "TLuaEngine.h"
|
#include "TLuaEngine.h"
|
||||||
#include "TScopedTimer.h"
|
#include "TScopedTimer.h"
|
||||||
#include "nlohmann/json.hpp"
|
#include "nlohmann/json.hpp"
|
||||||
@@ -85,7 +86,7 @@ TNetwork::TNetwork(TServer& Server, TPPSMonitor& PPSMonitor, TResourceManager& R
|
|||||||
void TNetwork::UDPServerMain() {
|
void TNetwork::UDPServerMain() {
|
||||||
RegisterThread("UDPServer");
|
RegisterThread("UDPServer");
|
||||||
// listen on all ipv6 addresses
|
// listen on all ipv6 addresses
|
||||||
ip::udp::endpoint UdpListenEndpoint(ip::address::from_string("::"), Application::Settings.getAsInt(Settings::Key::General_Port));
|
ip::udp::endpoint UdpListenEndpoint(ip::make_address("::"), Application::Settings.getAsInt(Settings::Key::General_Port));
|
||||||
boost::system::error_code ec;
|
boost::system::error_code ec;
|
||||||
mUDPSock.open(UdpListenEndpoint.protocol(), ec);
|
mUDPSock.open(UdpListenEndpoint.protocol(), ec);
|
||||||
if (ec) {
|
if (ec) {
|
||||||
@@ -112,9 +113,19 @@ void TNetwork::UDPServerMain() {
|
|||||||
try {
|
try {
|
||||||
ip::udp::endpoint remote_client_ep {};
|
ip::udp::endpoint remote_client_ep {};
|
||||||
std::vector<uint8_t> Data = UDPRcvFromClient(remote_client_ep);
|
std::vector<uint8_t> Data = UDPRcvFromClient(remote_client_ep);
|
||||||
auto Pos = std::find(Data.begin(), Data.end(), ':');
|
if (Data.empty()) {
|
||||||
if (Data.empty() || Pos > Data.begin() + 2)
|
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
if (Data.size() == 1 && Data.at(0) == 'P') {
|
||||||
|
mUDPSock.send_to(const_buffer("P", 1), remote_client_ep, {}, ec);
|
||||||
|
// ignore errors
|
||||||
|
(void)ec;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
auto Pos = std::find(Data.begin(), Data.end(), ':');
|
||||||
|
if (Pos > Data.begin() + 2) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
uint8_t ID = uint8_t(Data.at(0)) - 1;
|
uint8_t ID = uint8_t(Data.at(0)) - 1;
|
||||||
mServer.ForEachClient([&](std::weak_ptr<TClient> ClientPtr) -> bool {
|
mServer.ForEachClient([&](std::weak_ptr<TClient> ClientPtr) -> bool {
|
||||||
std::shared_ptr<TClient> Client;
|
std::shared_ptr<TClient> Client;
|
||||||
@@ -161,7 +172,7 @@ void TNetwork::TCPServerMain() {
|
|||||||
|
|
||||||
// listen on all ipv6 addresses
|
// listen on all ipv6 addresses
|
||||||
auto port = uint16_t(Application::Settings.getAsInt(Settings::Key::General_Port));
|
auto port = uint16_t(Application::Settings.getAsInt(Settings::Key::General_Port));
|
||||||
ip::tcp::endpoint ListenEp(ip::address::from_string("::"), port);
|
ip::tcp::endpoint ListenEp(ip::make_address("::"), port);
|
||||||
beammp_infof("Listening on 0.0.0.0:{0} and [::]:{0}", port);
|
beammp_infof("Listening on 0.0.0.0:{0} and [::]:{0}", port);
|
||||||
ip::tcp::socket Listener(mServer.IoCtx());
|
ip::tcp::socket Listener(mServer.IoCtx());
|
||||||
boost::system::error_code ec;
|
boost::system::error_code ec;
|
||||||
@@ -246,6 +257,17 @@ void TNetwork::Identify(TConnection&& RawConnection) {
|
|||||||
boost::system::error_code ec;
|
boost::system::error_code ec;
|
||||||
write(RawConnection.Socket, buffer("P"), ec);
|
write(RawConnection.Socket, buffer("P"), ec);
|
||||||
return;
|
return;
|
||||||
|
} else if (Code == 'I') {
|
||||||
|
const std::string Data = Application::Settings.getAsBool(Settings::Key::General_InformationPacket) ? THeartbeatThread::lastCall : "";
|
||||||
|
|
||||||
|
const auto Size = static_cast<int32_t>(Data.size());
|
||||||
|
std::vector<uint8_t> ToSend;
|
||||||
|
ToSend.resize(Data.size() + sizeof(Size));
|
||||||
|
std::memcpy(ToSend.data(), &Size, sizeof(Size));
|
||||||
|
std::memcpy(ToSend.data() + sizeof(Size), Data.data(), Data.size());
|
||||||
|
|
||||||
|
boost::system::error_code ec;
|
||||||
|
write(RawConnection.Socket, buffer(ToSend), ec);
|
||||||
} else {
|
} else {
|
||||||
beammp_errorf("Invalid code got in Identify: '{}'", Code);
|
beammp_errorf("Invalid code got in Identify: '{}'", Code);
|
||||||
}
|
}
|
||||||
@@ -285,6 +307,11 @@ std::shared_ptr<TClient> TNetwork::Authentication(TConnection&& RawConnection) {
|
|||||||
Client->SetIdentifier("ip", ip);
|
Client->SetIdentifier("ip", ip);
|
||||||
beammp_tracef("This thread is ip {} ({})", ip, RawConnection.SockAddr.address().to_v6().is_v4_mapped() ? "IPv4 mapped IPv6" : "IPv6");
|
beammp_tracef("This thread is ip {} ({})", ip, RawConnection.SockAddr.address().to_v6().is_v4_mapped() ? "IPv4 mapped IPv6" : "IPv6");
|
||||||
|
|
||||||
|
if (Application::GetSubsystemStatuses().at("Main") == Application::Status::Starting) {
|
||||||
|
ClientKick(*Client, "The server is still starting, please try joining again later.");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
beammp_info("Identifying new ClientConnection...");
|
beammp_info("Identifying new ClientConnection...");
|
||||||
|
|
||||||
auto Data = TCPRcv(*Client);
|
auto Data = TCPRcv(*Client);
|
||||||
@@ -293,10 +320,11 @@ std::shared_ptr<TClient> TNetwork::Authentication(TConnection&& RawConnection) {
|
|||||||
if (Data.size() > 3 && std::equal(Data.begin(), Data.begin() + VC.size(), VC.begin(), VC.end())) {
|
if (Data.size() > 3 && std::equal(Data.begin(), Data.begin() + VC.size(), VC.begin(), VC.end())) {
|
||||||
std::string ClientVersionStr(reinterpret_cast<const char*>(Data.data() + 2), Data.size() - 2);
|
std::string ClientVersionStr(reinterpret_cast<const char*>(Data.data() + 2), Data.size() - 2);
|
||||||
Version ClientVersion = Application::VersionStrToInts(ClientVersionStr + ".0");
|
Version ClientVersion = Application::VersionStrToInts(ClientVersionStr + ".0");
|
||||||
if (ClientVersion.major != Application::ClientMajorVersion()) {
|
Version MinClientVersion = Application::ClientMinimumVersion();
|
||||||
beammp_errorf("Client tried to connect with version '{}', but only versions '{}.x.x' is allowed",
|
if (Application::IsOutdated(ClientVersion, MinClientVersion)) {
|
||||||
ClientVersion.AsString(), Application::ClientMajorVersion());
|
beammp_errorf("Client tried to connect with version '{}', but only versions >= {} are allowed",
|
||||||
ClientKick(*Client, "Outdated Version!");
|
ClientVersion.AsString(), MinClientVersion.AsString());
|
||||||
|
ClientKick(*Client, fmt::format("Outdated version, launcher version >={} required to join!", MinClientVersion.AsString()));
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -331,7 +359,7 @@ std::shared_ptr<TClient> TNetwork::Authentication(TConnection&& RawConnection) {
|
|||||||
auto Target = "/pkToUser";
|
auto Target = "/pkToUser";
|
||||||
|
|
||||||
unsigned int ResponseCode = 0;
|
unsigned int ResponseCode = 0;
|
||||||
AuthResStr = Http::POST(Application::GetBackendUrlForAuth(), 443, Target, AuthReq.dump(), "application/json", &ResponseCode);
|
AuthResStr = Http::POST(Application::GetBackendUrlForAuth() + Target, AuthReq.dump(), "application/json", &ResponseCode);
|
||||||
|
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
beammp_debugf("Invalid json sent by client, kicking: {}", e.what());
|
beammp_debugf("Invalid json sent by client, kicking: {}", e.what());
|
||||||
@@ -339,6 +367,8 @@ std::shared_ptr<TClient> TNetwork::Authentication(TConnection&& RawConnection) {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
beammp_debug("Response from authentication backend: " + AuthResStr);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
nlohmann::json AuthRes = nlohmann::json::parse(AuthResStr);
|
nlohmann::json AuthRes = nlohmann::json::parse(AuthResStr);
|
||||||
|
|
||||||
@@ -415,35 +445,27 @@ std::shared_ptr<TClient> TNetwork::Authentication(TConnection&& RawConnection) {
|
|||||||
Reason = "No guests are allowed on this server! To join, sign up at: forum.beammp.com.";
|
Reason = "No guests are allowed on this server! To join, sign up at: forum.beammp.com.";
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Allowed = true;
|
if (!NotAllowed && !NotAllowedWithReason && mServer.ClientCount() >= size_t(Application::Settings.getAsInt(Settings::Key::General_MaxPlayers)) && !BypassLimit) {
|
||||||
if (NotAllowed) {
|
NotAllowedWithReason = true;
|
||||||
Allowed = false;
|
Reason = "Server full!";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NotAllowedWithReason) {
|
if (NotAllowedWithReason) {
|
||||||
Allowed = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (NotAllowed) {
|
|
||||||
ClientKick(*Client, "you are not allowed on the server!");
|
|
||||||
} else if (NotAllowedWithReason) {
|
|
||||||
ClientKick(*Client, Reason);
|
ClientKick(*Client, Reason);
|
||||||
|
} else if (NotAllowed) {
|
||||||
|
ClientKick(*Client, "you are not allowed on the server!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto PostFutures = LuaAPI::MP::Engine->TriggerEvent("postPlayerAuth", "", NotAllowed || NotAllowedWithReason, Reason, Client->GetName(), Client->GetRoles(), Client->IsGuest(), Client->GetIdentifiers());
|
||||||
|
// the post event is not cancellable so we dont wait for it
|
||||||
|
LuaAPI::MP::Engine->ReportErrors(PostFutures);
|
||||||
|
|
||||||
if (!Allowed) {
|
if (!NotAllowed && !NotAllowedWithReason) {
|
||||||
return {};
|
|
||||||
} else if (mServer.ClientCount() < size_t(Application::Settings.getAsInt(Settings::Key::General_MaxPlayers)) || BypassLimit) {
|
|
||||||
beammp_info("Identification success");
|
beammp_info("Identification success");
|
||||||
mServer.InsertClient(Client);
|
mServer.InsertClient(Client);
|
||||||
TCPClient(Client);
|
TCPClient(Client);
|
||||||
} else {
|
|
||||||
ClientKick(*Client, "Server full!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto PostFutures = LuaAPI::MP::Engine->TriggerEvent("postPlayerAuth", "", Allowed, Client->GetName(), Client->GetRoles(), Client->IsGuest(), Client->GetIdentifiers());
|
|
||||||
// the post event is not cancellable so we dont wait for it
|
|
||||||
LuaAPI::MP::Engine->ReportErrors(PostFutures);
|
|
||||||
|
|
||||||
return Client;
|
return Client;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -121,6 +121,8 @@ void TResourceManager::RefreshFiles() {
|
|||||||
}
|
}
|
||||||
EVP_MD_CTX_free(mdctx);
|
EVP_MD_CTX_free(mdctx);
|
||||||
|
|
||||||
|
stream.close();
|
||||||
|
|
||||||
std::string result;
|
std::string result;
|
||||||
for (size_t i = 0; i < sha256_len; i++) {
|
for (size_t i = 0; i < sha256_len; i++) {
|
||||||
result += fmt::format("{:02x}", sha256_value[i]);
|
result += fmt::format("{:02x}", sha256_value[i]);
|
||||||
|
|||||||
+14
-1
@@ -253,7 +253,6 @@ void TServer::GlobalParser(const std::weak_ptr<TClient>& Client, std::vector<uin
|
|||||||
HandleEvent(*LockedClient, StringPacket);
|
HandleEvent(*LockedClient, StringPacket);
|
||||||
return;
|
return;
|
||||||
case 'N':
|
case 'N':
|
||||||
beammp_trace("got 'N' packet (" + std::to_string(Packet.size()) + ")");
|
|
||||||
Network.SendToAll(LockedClient.get(), Packet, false, true);
|
Network.SendToAll(LockedClient.get(), Packet, false, true);
|
||||||
return;
|
return;
|
||||||
case 'Z': // position packet
|
case 'Z': // position packet
|
||||||
@@ -436,6 +435,20 @@ void TServer::ParseVehicle(TClient& c, const std::string& Pckt, TNetwork& Networ
|
|||||||
Network.SendToAll(&c, StringToVector(Packet), false, true);
|
Network.SendToAll(&c, StringToVector(Packet), false, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
case 'p': {
|
||||||
|
beammp_trace(std::string(("got 'Op' packet: '")) + Packet + ("' (") + std::to_string(Packet.size()) + (")"));
|
||||||
|
auto MaybePidVid = GetPidVid(Data.substr(0, Data.find(':', 1)));
|
||||||
|
if (MaybePidVid) {
|
||||||
|
std::tie(PID, VID) = MaybePidVid.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PID != -1 && VID != -1 && PID == c.GetID()) {
|
||||||
|
Data = Data.substr(Data.find('['));
|
||||||
|
LuaAPI::MP::Engine->ReportErrors(LuaAPI::MP::Engine->TriggerEvent("onVehiclePaintChanged", "", c.GetID(), VID, Data));
|
||||||
|
Network.SendToAll(&c, StringToVector(Packet), false, true);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
beammp_trace(std::string(("possibly not implemented: '") + Packet + ("' (") + std::to_string(Packet.size()) + (")")));
|
beammp_trace(std::string(("possibly not implemented: '") + Packet + ("' (") + std::to_string(Packet.size()) + (")")));
|
||||||
return;
|
return;
|
||||||
|
|||||||
+10
-5
@@ -182,10 +182,6 @@ int BeamMPServerMain(MainArguments Arguments) {
|
|||||||
|
|
||||||
TServer Server(Arguments.List);
|
TServer Server(Arguments.List);
|
||||||
|
|
||||||
auto LuaEngine = std::make_shared<TLuaEngine>();
|
|
||||||
LuaEngine->SetServer(&Server);
|
|
||||||
Application::Console().InitializeLuaConsole(*LuaEngine);
|
|
||||||
|
|
||||||
RegisterThread("Main");
|
RegisterThread("Main");
|
||||||
|
|
||||||
beammp_trace("Running in debug mode on a debug build");
|
beammp_trace("Running in debug mode on a debug build");
|
||||||
@@ -194,13 +190,16 @@ int BeamMPServerMain(MainArguments Arguments) {
|
|||||||
TPPSMonitor PPSMonitor(Server);
|
TPPSMonitor PPSMonitor(Server);
|
||||||
THeartbeatThread Heartbeat(ResourceManager, Server);
|
THeartbeatThread Heartbeat(ResourceManager, Server);
|
||||||
TNetwork Network(Server, PPSMonitor, ResourceManager);
|
TNetwork Network(Server, PPSMonitor, ResourceManager);
|
||||||
|
|
||||||
|
auto LuaEngine = std::make_shared<TLuaEngine>();
|
||||||
|
LuaEngine->SetServer(&Server);
|
||||||
|
Application::Console().InitializeLuaConsole(*LuaEngine);
|
||||||
LuaEngine->SetNetwork(&Network);
|
LuaEngine->SetNetwork(&Network);
|
||||||
PPSMonitor.SetNetwork(Network);
|
PPSMonitor.SetNetwork(Network);
|
||||||
Application::CheckForUpdates();
|
Application::CheckForUpdates();
|
||||||
|
|
||||||
TPluginMonitor PluginMonitor(fs::path(Application::Settings.getAsString(Settings::Key::General_ResourceFolder)) / "Server", LuaEngine);
|
TPluginMonitor PluginMonitor(fs::path(Application::Settings.getAsString(Settings::Key::General_ResourceFolder)) / "Server", LuaEngine);
|
||||||
|
|
||||||
Application::SetSubsystemStatus("Main", Application::Status::Good);
|
|
||||||
RegisterThread("Main(Waiting)");
|
RegisterThread("Main(Waiting)");
|
||||||
|
|
||||||
std::set<std::string> IgnoreSubsystems {
|
std::set<std::string> IgnoreSubsystems {
|
||||||
@@ -215,6 +214,10 @@ int BeamMPServerMain(MainArguments Arguments) {
|
|||||||
std::string SystemsBadList {};
|
std::string SystemsBadList {};
|
||||||
auto Statuses = Application::GetSubsystemStatuses();
|
auto Statuses = Application::GetSubsystemStatuses();
|
||||||
for (const auto& NameStatusPair : Statuses) {
|
for (const auto& NameStatusPair : Statuses) {
|
||||||
|
if (NameStatusPair.first == "Main") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (IgnoreSubsystems.count(NameStatusPair.first) > 0) {
|
if (IgnoreSubsystems.count(NameStatusPair.first) > 0) {
|
||||||
continue; // ignore
|
continue; // ignore
|
||||||
}
|
}
|
||||||
@@ -228,6 +231,8 @@ int BeamMPServerMain(MainArguments Arguments) {
|
|||||||
// remove ", "
|
// remove ", "
|
||||||
SystemsBadList = SystemsBadList.substr(0, SystemsBadList.size() - 2);
|
SystemsBadList = SystemsBadList.substr(0, SystemsBadList.size() - 2);
|
||||||
if (FullyStarted) {
|
if (FullyStarted) {
|
||||||
|
Application::SetSubsystemStatus("Main", Application::Status::Good);
|
||||||
|
|
||||||
if (!WithErrors) {
|
if (!WithErrors) {
|
||||||
beammp_info("ALL SYSTEMS STARTED SUCCESSFULLY, EVERYTHING IS OKAY");
|
beammp_info("ALL SYSTEMS STARTED SUCCESSFULLY, EVERYTHING IS OKAY");
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+2
-1
@@ -13,6 +13,7 @@
|
|||||||
"nlohmann-json",
|
"nlohmann-json",
|
||||||
"openssl",
|
"openssl",
|
||||||
"rapidjson",
|
"rapidjson",
|
||||||
"sol2"
|
"sol2",
|
||||||
|
"curl"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user