mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-04-03 06:16:04 +00:00
Prevent log spam and simplify code
This commit is contained in:
@@ -54,16 +54,6 @@ static std::optional<std::pair<int, int>> GetPidVid(const std::string& str) {
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
static std::optional<std::string> ExtractStructuredPayload(const std::string& PacketData, char BeginMarker) {
|
||||
auto FoundPos = PacketData.find(BeginMarker);
|
||||
if (FoundPos == std::string::npos) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
return PacketData.substr(FoundPos);
|
||||
}
|
||||
|
||||
TEST_CASE("GetPidVid") {
|
||||
SUBCASE("Valid singledigit") {
|
||||
const auto MaybePidVid = GetPidVid("0-1");
|
||||
@@ -130,14 +120,6 @@ TEST_CASE("GetPidVid") {
|
||||
CHECK(!MaybePidVid);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("ExtractStructuredPayload") {
|
||||
CHECK_EQ(ExtractStructuredPayload("1-2:{\"reset\":true}", '{').value(), "{\"reset\":true}");
|
||||
CHECK_EQ(ExtractStructuredPayload("1-2:[0,1,2,3]", '[').value(), "[0,1,2,3]");
|
||||
CHECK_FALSE(ExtractStructuredPayload("1-2:null", '{').has_value());
|
||||
CHECK_FALSE(ExtractStructuredPayload("1-2:null", '[').has_value());
|
||||
}
|
||||
|
||||
TServer::TServer(const std::vector<std::string_view>& Arguments) {
|
||||
beammp_info("BeamMP Server v" + Application::ServerVersionString());
|
||||
Application::SetSubsystemStatus("Server", Application::Status::Starting);
|
||||
@@ -489,13 +471,13 @@ void TServer::ParseVehicle(TClient& c, const std::string& Pckt, TNetwork& Networ
|
||||
}
|
||||
|
||||
if (PID != -1 && VID != -1 && PID == c.GetID()) {
|
||||
auto ResetData = ExtractStructuredPayload(Data, '{');
|
||||
if (!ResetData.has_value()) {
|
||||
beammp_warnf("Malformed 'Or' packet from client {}: missing '{{' in '{}'", c.GetID(), Packet);
|
||||
auto BracketPos = Data.find('{');
|
||||
if (BracketPos == std::string::npos) {
|
||||
beammp_debugf("Invalid 'Or' packet body from client {}", c.GetID());
|
||||
return;
|
||||
}
|
||||
|
||||
Data = std::move(ResetData.value());
|
||||
Data = Data.substr(BracketPos);
|
||||
LuaAPI::MP::Engine->ReportErrors(LuaAPI::MP::Engine->TriggerEvent("onVehicleReset", "", c.GetID(), VID, Data));
|
||||
Network.SendToAll(&c, StringToVector(Packet), false, true);
|
||||
}
|
||||
@@ -524,13 +506,14 @@ void TServer::ParseVehicle(TClient& c, const std::string& Pckt, TNetwork& Networ
|
||||
}
|
||||
|
||||
if (PID != -1 && VID != -1 && PID == c.GetID()) {
|
||||
auto PaintData = ExtractStructuredPayload(Data, '[');
|
||||
if (!PaintData.has_value()) {
|
||||
beammp_warnf("Malformed 'Op' packet from client {}: missing '[' in '{}'", c.GetID(), Packet);
|
||||
auto BracketPos = Data.find('[');
|
||||
if (BracketPos == std::string::npos) {
|
||||
beammp_debugf("Invalid 'Op' packet body from client {}", c.GetID());
|
||||
return;
|
||||
}
|
||||
|
||||
Data = std::move(PaintData.value());
|
||||
Data = Data.substr(BracketPos);
|
||||
|
||||
LuaAPI::MP::Engine->ReportErrors(LuaAPI::MP::Engine->TriggerEvent("onVehiclePaintChanged", "", c.GetID(), VID, Data));
|
||||
Network.SendToAll(&c, StringToVector(Packet), false, true);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user