mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-07-04 00:36:14 +00:00
fix MP.GetPositionRaw
This commit is contained in:
parent
0166e488d0
commit
a4eb10b6a4
@ -53,9 +53,9 @@ std::string TClient::GetCarPositionRaw(int Ident) {
|
|||||||
try {
|
try {
|
||||||
return mVehiclePosition.at(size_t(Ident));
|
return mVehiclePosition.at(size_t(Ident));
|
||||||
} catch (const std::out_of_range& oor) {
|
} catch (const std::out_of_range& oor) {
|
||||||
|
beammp_debugf("Failed to get vehicle position for {}: {}", Ident, oor.what());
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TClient::Disconnect(std::string_view Reason) {
|
void TClient::Disconnect(std::string_view Reason) {
|
||||||
@ -146,6 +146,8 @@ std::optional<std::weak_ptr<TClient>> GetClient(TServer& Server, int ID) {
|
|||||||
MaybeClient = CPtr;
|
MaybeClient = CPtr;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
beammp_debugf("Found an expired client while looking for id {}", ID);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
@ -601,7 +601,7 @@ std::pair<sol::table, std::string> TLuaEngine::StateThreadData::Lua_GetPositionR
|
|||||||
return Result;
|
return Result;
|
||||||
} else {
|
} else {
|
||||||
// return std::make_tuple(sol::lua_nil, sol::make_object(StateView, "Client expired"));
|
// return std::make_tuple(sol::lua_nil, sol::make_object(StateView, "Client expired"));
|
||||||
Result.second = "Client expired";
|
Result.second = "No such player";
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -612,7 +612,7 @@ void TNetwork::OnDisconnect(const std::weak_ptr<TClient>& ClientPtr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int TNetwork::OpenID() {
|
int TNetwork::OpenID() {
|
||||||
int ID = 0;
|
int ID = 10;
|
||||||
bool found;
|
bool found;
|
||||||
do {
|
do {
|
||||||
found = true;
|
found = true;
|
||||||
|
@ -238,6 +238,7 @@ void TServer::GlobalParser(const std::weak_ptr<TClient>& Client, std::vector<uin
|
|||||||
PPSMonitor.IncrementInternalPPS();
|
PPSMonitor.IncrementInternalPPS();
|
||||||
Network.SendToAll(LockedClient.get(), Packet, false, false);
|
Network.SendToAll(LockedClient.get(), Packet, false, false);
|
||||||
HandlePosition(*LockedClient, StringPacket);
|
HandlePosition(*LockedClient, StringPacket);
|
||||||
|
return;
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -451,32 +452,25 @@ void TServer::HandlePosition(TClient& c, const std::string& Packet) {
|
|||||||
// invalid packet
|
// invalid packet
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Zp:serverVehicleID:data
|
// Zp:PID-VID:DATA
|
||||||
// Zp:0:data
|
|
||||||
std::string withoutCode = Packet.substr(3);
|
std::string withoutCode = Packet.substr(3);
|
||||||
auto NameDataSep = withoutCode.find(':', 2);
|
|
||||||
if (NameDataSep == std::string::npos || NameDataSep < 2) {
|
|
||||||
// invalid packet
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// FIXME: ensure that -2 does what it should... it seems weird.
|
|
||||||
std::string ServerVehicleID = withoutCode.substr(2, NameDataSep - 2);
|
|
||||||
if (NameDataSep + 1 > withoutCode.size()) {
|
|
||||||
// invalid packet
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
std::string Data = withoutCode.substr(NameDataSep + 1);
|
|
||||||
|
|
||||||
// parse veh ID
|
// parse veh ID
|
||||||
auto MaybePidVid = GetPidVid(ServerVehicleID);
|
if (auto DataBeginPos = withoutCode.find('{'); DataBeginPos != std::string::npos && DataBeginPos != 0) {
|
||||||
|
// separator is :{, so position of { minus one
|
||||||
|
auto PidVidOnly = withoutCode.substr(0, DataBeginPos-1);
|
||||||
|
auto MaybePidVid = GetPidVid(PidVidOnly);
|
||||||
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
|
// 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 (auto ClientPtr = GetClient(*this, PID); ClientPtr.has_value()) {
|
std::string Data = withoutCode.substr(DataBeginPos);
|
||||||
ClientPtr->lock()->SetCarPosition(VID, Data);
|
c.SetCarPosition(VID, Data);
|
||||||
|
} else {
|
||||||
|
// invalid packet
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user