mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-06-17 14:12:25 +00:00
add owner check to position packets
This commit is contained in:
+1
-1
@@ -43,7 +43,7 @@ private:
|
|||||||
static bool ShouldSpawn(TClient& c, const std::string& CarJson, int ID);
|
static bool ShouldSpawn(TClient& c, const std::string& CarJson, int ID);
|
||||||
static bool IsUnicycle(TClient& c, const std::string& CarJson);
|
static bool IsUnicycle(TClient& c, const std::string& CarJson);
|
||||||
static void Apply(TClient& c, int VID, const std::string& pckt);
|
static void Apply(TClient& c, int VID, const std::string& pckt);
|
||||||
static void HandlePosition(TClient& c, const std::string& Packet);
|
static bool HandlePosition(TClient& c, const std::string& Packet);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct BufferView {
|
struct BufferView {
|
||||||
|
|||||||
+14
-10
@@ -212,9 +212,11 @@ void TServer::GlobalParser(const std::weak_ptr<TClient>& Client, std::vector<uin
|
|||||||
Network.SendToAll(LockedClient.get(), Packet, false, true);
|
Network.SendToAll(LockedClient.get(), Packet, false, true);
|
||||||
return;
|
return;
|
||||||
case 'Z': // position packet
|
case 'Z': // position packet
|
||||||
PPSMonitor.IncrementInternalPPS();
|
if (HandlePosition(*LockedClient, StringPacket)){
|
||||||
Network.SendToAll(LockedClient.get(), Packet, false, false);
|
Network.SendToAll(LockedClient.get(), Packet, false, false);
|
||||||
HandlePosition(*LockedClient, StringPacket);
|
} else {
|
||||||
|
beammp_debugf("Invalid vehicle position packet received from '{}' ({}), ignoring it", LockedClient->GetName(), LockedClient->GetID());
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -433,10 +435,10 @@ void TServer::InsertClient(const std::shared_ptr<TClient>& NewClient) {
|
|||||||
(void)mClients.insert(NewClient);
|
(void)mClients.insert(NewClient);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TServer::HandlePosition(TClient& c, const std::string& Packet) {
|
bool TServer::HandlePosition(TClient& c, const std::string& Packet) {
|
||||||
if (Packet.size() < 3) {
|
if (Packet.size() < 3) {
|
||||||
// invalid packet
|
// invalid packet
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
// Zp:serverVehicleID:data
|
// Zp:serverVehicleID:data
|
||||||
// Zp:0:data
|
// Zp:0:data
|
||||||
@@ -444,13 +446,13 @@ void TServer::HandlePosition(TClient& c, const std::string& Packet) {
|
|||||||
auto NameDataSep = withoutCode.find(':', 2);
|
auto NameDataSep = withoutCode.find(':', 2);
|
||||||
if (NameDataSep == std::string::npos || NameDataSep < 2) {
|
if (NameDataSep == std::string::npos || NameDataSep < 2) {
|
||||||
// invalid packet
|
// invalid packet
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
// FIXME: ensure that -2 does what it should... it seems weird.
|
// FIXME: ensure that -2 does what it should... it seems weird.
|
||||||
std::string ServerVehicleID = withoutCode.substr(2, NameDataSep - 2);
|
std::string ServerVehicleID = withoutCode.substr(2, NameDataSep - 2);
|
||||||
if (NameDataSep + 1 > withoutCode.size()) {
|
if (NameDataSep + 1 > withoutCode.size()) {
|
||||||
// invalid packet
|
// invalid packet
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
std::string Data = withoutCode.substr(NameDataSep + 1);
|
std::string Data = withoutCode.substr(NameDataSep + 1);
|
||||||
|
|
||||||
@@ -459,9 +461,11 @@ void TServer::HandlePosition(TClient& c, const std::string& Packet) {
|
|||||||
if (MaybePidVid) {
|
if (MaybePidVid) {
|
||||||
int PID = -1;
|
int PID = -1;
|
||||||
int VID = -1;
|
int VID = -1;
|
||||||
// FIXME: check that the VID and PID are valid, so that we don't waste memory
|
|
||||||
std::tie(PID, VID) = MaybePidVid.value();
|
std::tie(PID, VID) = MaybePidVid.value();
|
||||||
|
if (PID == c.GetID()) {
|
||||||
c.SetCarPosition(VID, Data);
|
c.SetCarPosition(VID, Data);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user