mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-10-22 16:17:40 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5c39216c44 | ||
|
|
5efd264355 | ||
|
|
176de6b5a5 | ||
|
|
e33f47e838 |
No files matched your search
@@ -23,6 +23,7 @@
|
||||
namespace Env {
|
||||
|
||||
enum class Key {
|
||||
MAX_CONCURRENT_CONNECTIONS,
|
||||
// provider settings
|
||||
PROVIDER_UPDATE_MESSAGE,
|
||||
PROVIDER_DISABLE_CONFIG,
|
||||
|
||||
@@ -45,6 +45,9 @@ std::string_view Env::ToString(Env::Key key) {
|
||||
case Key::PROVIDER_IP_ENV:
|
||||
return "BEAMMP_PROVIDER_IP_ENV";
|
||||
break;
|
||||
case Key::MAX_CONCURRENT_CONNECTIONS:
|
||||
return "BEAMMP_MAX_CONCURRENT_CONNECTIONS";
|
||||
break;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
+25
-2
@@ -19,6 +19,7 @@
|
||||
#include "TNetwork.h"
|
||||
#include "Client.h"
|
||||
#include "Common.h"
|
||||
#include "Env.h"
|
||||
#include "LuaAPI.h"
|
||||
#include "TConnectionLimiter.h"
|
||||
#include "THeartbeatThread.h"
|
||||
@@ -45,8 +46,24 @@
|
||||
|
||||
typedef boost::asio::detail::socket_option::integer<SOL_SOCKET, SO_RCVTIMEO> rcv_timeout_option;
|
||||
|
||||
static constexpr uint8_t MAX_CONCURRENT_CONNECTIONS = 10;
|
||||
static constexpr uint8_t MAX_GLOBAL_CONNECTIONS = 128;
|
||||
static const uint8_t MAX_CONCURRENT_CONNECTIONS = []() -> uint8_t {
|
||||
if (auto EnvVar = Env::Get(Env::Key::MAX_CONCURRENT_CONNECTIONS)) {
|
||||
try {
|
||||
beammp_debugf("BEAMMP_MAX_CONCURRENT_CONNECTIONS: {}", EnvVar.value());
|
||||
if (const int value = std::stoi(std::string(EnvVar.value())); value > 0 && value <= MAX_GLOBAL_CONNECTIONS) {
|
||||
beammp_debugf("BEAMMP_MAX_CONCURRENT_CONNECTIONS Parsed: {}", value);
|
||||
return static_cast<uint8_t>(value);
|
||||
}
|
||||
|
||||
beammp_warn("Env variable BEAMMP_MAX_CONCURRENT_CONNECTIONS is out of range, using default value.");
|
||||
} catch (const std::exception&) {
|
||||
beammp_warn("Error parsing Env variable BEAMMP_MAX_CONCURRENT_CONNECTIONS, using default value.");
|
||||
}
|
||||
}
|
||||
|
||||
return 10;
|
||||
}();
|
||||
static constexpr uint8_t READ_TIMEOUT_S = 10; // seconds
|
||||
|
||||
std::vector<uint8_t> StringToVector(const std::string& Str) {
|
||||
@@ -181,7 +198,13 @@ void TNetwork::UDPServerMain() {
|
||||
if (Client->GetID() == ID) {
|
||||
if (Client->GetUDPAddr() == boost::asio::ip::udp::endpoint { } && !Client->IsUDPConnected() && !Client->GetMagic().empty()) {
|
||||
if (Data.size() != 66) {
|
||||
beammp_debugf("Invalid size for UDP value. IP: {} ID: {}", remote_client_ep.address().to_string(), ID);
|
||||
beammp_debugf("Invalid size for UDP value. IP: {} ID: {}, Size: {}", remote_client_ep.address().to_string(), ID, Data.size());
|
||||
std::stringstream hexData;
|
||||
for (auto c : Data) {
|
||||
hexData << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(c);
|
||||
hexData << " ";
|
||||
}
|
||||
beammp_debug(hexData.str());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user