mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-07-19 13:18:10 +00:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7f69e336a9 | |||
| f08dfc0585 | |||
| a9dee2bec5 | |||
| 5319c2878a | |||
| 73f494041a |
+7
-1
@@ -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, 5, 0 };
|
static inline Version mVersion { 3, 5, 1 };
|
||||||
};
|
};
|
||||||
|
|
||||||
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);
|
||||||
@@ -268,3 +268,9 @@ std::vector<uint8_t> DeComp(std::span<const uint8_t> input);
|
|||||||
|
|
||||||
std::string GetPlatformAgnosticErrorString();
|
std::string GetPlatformAgnosticErrorString();
|
||||||
#define S_DSN SU_RAW
|
#define S_DSN SU_RAW
|
||||||
|
|
||||||
|
class InvalidDataError : std::runtime_error {
|
||||||
|
public:
|
||||||
|
InvalidDataError() : std::runtime_error("Invalid data") {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
+5
-1
@@ -418,7 +418,11 @@ std::vector<uint8_t> DeComp(std::span<const uint8_t> input) {
|
|||||||
output_size = output_buffer.size();
|
output_size = output_buffer.size();
|
||||||
} else if (res != Z_OK) {
|
} else if (res != Z_OK) {
|
||||||
beammp_error("zlib uncompress() failed: " + std::to_string(res));
|
beammp_error("zlib uncompress() failed: " + std::to_string(res));
|
||||||
throw std::runtime_error("zlib uncompress() failed");
|
if (res == Z_DATA_ERROR) {
|
||||||
|
throw InvalidDataError {};
|
||||||
|
} else {
|
||||||
|
throw std::runtime_error("zlib uncompress() failed");
|
||||||
|
}
|
||||||
} else if (res == Z_OK) {
|
} else if (res == Z_OK) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -139,7 +139,7 @@ void TConfig::FlushToFile() {
|
|||||||
SetComment(data["General"][StrTags.data()].comments(), " Add custom identifying tags to your server to make it easier to find. Format should be TagA,TagB,TagC. Note the comma seperation.");
|
SetComment(data["General"][StrTags.data()].comments(), " Add custom identifying tags to your server to make it easier to find. Format should be TagA,TagB,TagC. Note the comma seperation.");
|
||||||
data["General"][StrTags.data()] = Application::Settings.getAsString(Settings::Key::General_Tags);
|
data["General"][StrTags.data()] = Application::Settings.getAsString(Settings::Key::General_Tags);
|
||||||
data["General"][StrMaxCars.data()] = Application::Settings.getAsInt(Settings::Key::General_MaxCars);
|
data["General"][StrMaxCars.data()] = Application::Settings.getAsInt(Settings::Key::General_MaxCars);
|
||||||
data["General"][StrMaxPlayers.data()] = Application::Settings.getAsInt(Settings::Key::General_MaxCars);
|
data["General"][StrMaxPlayers.data()] = Application::Settings.getAsInt(Settings::Key::General_MaxPlayers);
|
||||||
data["General"][StrMap.data()] = Application::Settings.getAsString(Settings::Key::General_Map);
|
data["General"][StrMap.data()] = Application::Settings.getAsString(Settings::Key::General_Map);
|
||||||
data["General"][StrDescription.data()] = Application::Settings.getAsString(Settings::Key::General_Description);
|
data["General"][StrDescription.data()] = Application::Settings.getAsString(Settings::Key::General_Description);
|
||||||
data["General"][StrResourceFolder.data()] = Application::Settings.getAsString(Settings::Key::General_ResourceFolder);
|
data["General"][StrResourceFolder.data()] = Application::Settings.getAsString(Settings::Key::General_ResourceFolder);
|
||||||
|
|||||||
+11
-1
@@ -546,7 +546,17 @@ std::vector<uint8_t> TNetwork::TCPRcv(TClient& c) {
|
|||||||
constexpr std::string_view ABG = "ABG:";
|
constexpr std::string_view ABG = "ABG:";
|
||||||
if (Data.size() >= ABG.size() && std::equal(Data.begin(), Data.begin() + ABG.size(), ABG.begin(), ABG.end())) {
|
if (Data.size() >= ABG.size() && std::equal(Data.begin(), Data.begin() + ABG.size(), ABG.begin(), ABG.end())) {
|
||||||
Data.erase(Data.begin(), Data.begin() + ABG.size());
|
Data.erase(Data.begin(), Data.begin() + ABG.size());
|
||||||
return DeComp(Data);
|
try {
|
||||||
|
return DeComp(Data);
|
||||||
|
} catch (const InvalidDataError& ) {
|
||||||
|
beammp_errorf("Failed to decompress packet from a client. The receive failed and the client may be disconnected as a result");
|
||||||
|
// return empty -> error
|
||||||
|
return std::vector<uint8_t>();
|
||||||
|
} catch (const std::runtime_error& e) {
|
||||||
|
beammp_errorf("Failed to decompress packet from a client: {}. The server may be out of RAM! The receive failed and the client may be disconnected as a result", e.what());
|
||||||
|
// return empty -> error
|
||||||
|
return std::vector<uint8_t>();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return Data;
|
return Data;
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-1
@@ -165,7 +165,19 @@ void TServer::GlobalParser(const std::weak_ptr<TClient>& Client, std::vector<uin
|
|||||||
constexpr std::string_view ABG = "ABG:";
|
constexpr std::string_view ABG = "ABG:";
|
||||||
if (Packet.size() >= ABG.size() && std::equal(Packet.begin(), Packet.begin() + ABG.size(), ABG.begin(), ABG.end())) {
|
if (Packet.size() >= ABG.size() && std::equal(Packet.begin(), Packet.begin() + ABG.size(), ABG.begin(), ABG.end())) {
|
||||||
Packet.erase(Packet.begin(), Packet.begin() + ABG.size());
|
Packet.erase(Packet.begin(), Packet.begin() + ABG.size());
|
||||||
Packet = DeComp(Packet);
|
try {
|
||||||
|
Packet = DeComp(Packet);
|
||||||
|
} catch (const InvalidDataError& ) {
|
||||||
|
auto LockedClient = Client.lock();
|
||||||
|
beammp_errorf("Failed to decompress packet from client {}. The client sent invalid data and will now be disconnected.", LockedClient->GetID());
|
||||||
|
Network.ClientKick(*LockedClient, "Sent invalid compressed packet (this is likely a bug on your end)");
|
||||||
|
return;
|
||||||
|
} catch (const std::runtime_error& e) {
|
||||||
|
auto LockedClient = Client.lock();
|
||||||
|
beammp_errorf("Failed to decompress packet from client {}: {}. The server might be out of RAM! The client will now be disconnected.", LockedClient->GetID(), e.what());
|
||||||
|
Network.ClientKick(*LockedClient, "Decompression failed (likely a server-side problem)");
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (Packet.empty()) {
|
if (Packet.empty()) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user